Scroom  0.14
TiledBitmapViewData Class Reference

#include <tiledbitmapviewdata.hh>

Inheritance diagram for TiledBitmapViewData:
Inheritance graph
Collaboration diagram for TiledBitmapViewData:
Collaboration graph

Public Types

using Ptr = boost::shared_ptr< TiledBitmapViewData >
 
- Public Types inherited from TileLoadingObserver
using Ptr = boost::shared_ptr< TileLoadingObserver >
 
using WeakPtr = boost::weak_ptr< TileLoadingObserver >
 
- Public Types inherited from ProgressInterface
using Ptr = boost::shared_ptr< ProgressInterface >
 
using WeakPtr = boost::weak_ptr< ProgressInterface >
 

Public Member Functions

void setNeededTiles (Layer::Ptr const &l, int imin, int imax, int jmin, int jmax, int zoom, LayerOperations::Ptr layerOperations)
 
void resetNeededTiles ()
 
void storeVolatileStuff (const Scroom::Utils::Stuff &stuff)
 
void clearVolatileStuff ()
 
void tileLoaded (ConstTile::Ptr tile) override
 
void setIdle () override
 
void setWaiting (double progress=0.0) override
 
void setWorking (double progress) override
 
void setFinished () override
 
- Public Member Functions inherited from Scroom::Utils::Base
 Base ()=default
 
 Base (const Base &)=delete
 
 Base (Base &&)=delete
 
Baseoperator= (const Base &)=delete
 
Baseoperator= (Base &&)=delete
 
virtual ~Base ()=default
 
template<typename R >
boost::shared_ptr< R > shared_from_this ()
 
template<typename R >
boost::shared_ptr< R const > shared_from_this () const
 

Static Public Member Functions

static Ptr create (const ViewInterface::WeakPtr &viewInterface)
 

Public Attributes

ViewInterface::WeakPtr viewInterface
 
ProgressInterface::Ptr progressInterface
 
Scroom::Bookkeeping::Token token
 

Private Member Functions

 TiledBitmapViewData (const ViewInterface::WeakPtr &viewInterface)
 

Private Attributes

Layer::Ptr layer
 
int imin {0}
 
int imax {0}
 
int jmin {0}
 
int jmax {0}
 
int zoom {0}
 
LayerOperations::Ptr layerOperations
 
Scroom::Utils::StuffList stuff
 
Scroom::Utils::StuffList volatileStuff
 
bool redrawPending {false}
 
boost::mutex mut
 

Member Typedef Documentation

◆ Ptr

using TiledBitmapViewData::Ptr = boost::shared_ptr<TiledBitmapViewData>

Constructor & Destructor Documentation

◆ TiledBitmapViewData()

TiledBitmapViewData::TiledBitmapViewData ( const ViewInterface::WeakPtr viewInterface)
explicitprivate
26  : viewInterface(viewInterface_)
27  , progressInterface(viewInterface_.lock()->getProgressInterface())
28 
29 {
30 }

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ clearVolatileStuff()

void TiledBitmapViewData::clearVolatileStuff ( )
129 {
130  std::list<boost::shared_ptr<void>> oldVolatileStuff;
131  {
132  boost::unique_lock<boost::mutex> const lock(mut);
133  oldVolatileStuff.swap(volatileStuff);
134  }
135  // oldVolatileStuff gets erased here, without holding the lock. So
136  // if anyone is calling storeVolatileStuff() as a side effect, they
137  // can do so safely.
138  oldVolatileStuff.clear();
140 }
Here is the call graph for this function:

◆ create()

TiledBitmapViewData::Ptr TiledBitmapViewData::create ( const ViewInterface::WeakPtr viewInterface)
static
21 {
23 }

Referenced by TiledBitmap::open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetNeededTiles()

void TiledBitmapViewData::resetNeededTiles ( )
66 {
67  boost::unique_lock<boost::mutex> lock(mut);
68 
69  // If we just cleared out oldStuff, old tiles would be unloaded, and
70  // we might still need them. So create a backup to throw away later
71  std::list<boost::shared_ptr<void>> oldStuff;
72  oldStuff.swap(stuff);
73  std::list<boost::shared_ptr<void>> oldVolatileStuff;
74  oldVolatileStuff.swap(volatileStuff);
75 
76  lock.unlock();
77  // The stuff list contains both registrations and references to needed tiles.
78  // Registering an observer can result in tileLoaded() being called immediately
79  // if the tile was already loaded. Hence, we cannot hold the lock while registering
80  // observers.
81 
82  std::list<boost::shared_ptr<void>> newStuff;
83  // If we don't hold the lock, we cannot add to the stuff list directly. Hence,
84  // temporarily add registrations to the newStuff list, and add the newStuff to
85  // stuff later.
86 
87  for(int i = imin; i < imax; i++)
88  {
89  for(int j = jmin; j < jmax; j++)
90  {
91  CompressedTile::Ptr const tile = layer->getTile(i, j);
92 
93  TileViewState::Ptr const tileViewState = tile->getViewState(viewInterface);
94  tileViewState->setViewData(shared_from_this<TiledBitmapViewData>());
95  tileViewState->setZoom(layerOperations, zoom);
96  newStuff.emplace_back(tileViewState);
97  newStuff.emplace_back(tileViewState->registerObserver(shared_from_this<TiledBitmapViewData>()));
98  }
99  }
100 
101  // At this point, everything we need is either in the stuff list, or the newStuff list.
102  // Hence, this is an excellent time to clear the oldStuff list. We cannot clear the
103  // oldStuff list while holding the lock, because that would result in deadlock (see
104  // ticket #35)
105  oldStuff.clear();
106  oldVolatileStuff.clear();
107 
108  // Re-acquire the lock
109  lock.lock();
110  stuff.splice(stuff.end(), newStuff, newStuff.begin(), newStuff.end());
111 }

Referenced by clearVolatileStuff(), and setNeededTiles().

Here is the caller graph for this function:

◆ setFinished()

void TiledBitmapViewData::setFinished ( )
overridevirtual

Implements ProgressInterface.

163 { progressInterface->setFinished(); }

◆ setIdle()

void TiledBitmapViewData::setIdle ( )
overridevirtual

Implements ProgressInterface.

157 { progressInterface->setIdle(); }

◆ setNeededTiles()

void TiledBitmapViewData::setNeededTiles ( Layer::Ptr const &  l,
int  imin,
int  imax,
int  jmin,
int  jmax,
int  zoom,
LayerOperations::Ptr  layerOperations 
)
39 {
40  boost::unique_lock<boost::mutex> lock(mut);
41 
42  if(layer == l && imin <= imin_ && imax >= imax_ && jmin <= jmin_ && jmax >= jmax_ && zoom == zoom_)
43  {
44  // Nothing to do...
45  }
46  else
47  {
48  layer = l;
49  imin = imin_;
50  imax = imax_;
51  jmin = jmin_;
52  jmax = jmax_;
53  zoom = zoom_;
54  layerOperations = std::move(layerOperations_);
55 
56  // Get data for new tiles
57  redrawPending = true; // if it isn't already
58  lock.unlock();
60  lock.lock();
61  }
62  redrawPending = false;
63 }
Here is the call graph for this function:

◆ setWaiting()

void TiledBitmapViewData::setWaiting ( double  progress = 0.0)
overridevirtual

Implements ProgressInterface.

159 { progressInterface->setWaiting(progress); }

◆ setWorking()

void TiledBitmapViewData::setWorking ( double  progress)
overridevirtual

Implements ProgressInterface.

161 { progressInterface->setWorking(progress); }

◆ storeVolatileStuff()

void TiledBitmapViewData::storeVolatileStuff ( const Scroom::Utils::Stuff stuff)
123 {
124  boost::unique_lock<boost::mutex> const lock(mut);
125  volatileStuff.push_back(stuff_);
126 }

◆ tileLoaded()

void TiledBitmapViewData::tileLoaded ( ConstTile::Ptr  tile)
overridevirtual

The Tile has been loaded.

Implements TileLoadingObserver.

143 {
144  boost::unique_lock<boost::mutex> const lock(mut);
145  stuff.emplace_back(tile);
146 
147  if(!redrawPending)
148  {
149  // We're not sure about whether gdk_threads_enter() has been
150  // called or not, so we have no choice but to invalidate on
151  // another thread.
153  redrawPending = true;
154  }
155 }
Here is the call graph for this function:

Member Data Documentation

◆ imax

int TiledBitmapViewData::imax {0}
private

Referenced by resetNeededTiles(), and setNeededTiles().

◆ imin

int TiledBitmapViewData::imin {0}
private

Referenced by resetNeededTiles(), and setNeededTiles().

◆ jmax

int TiledBitmapViewData::jmax {0}
private

Referenced by resetNeededTiles(), and setNeededTiles().

◆ jmin

int TiledBitmapViewData::jmin {0}
private

Referenced by resetNeededTiles(), and setNeededTiles().

◆ layer

Layer::Ptr TiledBitmapViewData::layer
private

Referenced by resetNeededTiles(), and setNeededTiles().

◆ layerOperations

LayerOperations::Ptr TiledBitmapViewData::layerOperations
private

Referenced by resetNeededTiles(), and setNeededTiles().

◆ mut

boost::mutex TiledBitmapViewData::mut
private

Protect stuff and redrawPending

Referenced by clearVolatileStuff(), resetNeededTiles(), setNeededTiles(), storeVolatileStuff(), and tileLoaded().

◆ progressInterface

ProgressInterface::Ptr TiledBitmapViewData::progressInterface

◆ redrawPending

bool TiledBitmapViewData::redrawPending {false}
private

Referenced by setNeededTiles(), and tileLoaded().

◆ stuff

Scroom::Utils::StuffList TiledBitmapViewData::stuff
private

References to things we want to keep around.

This includes

  • observer registrations
  • tiles that have been loaded

Referenced by resetNeededTiles(), and tileLoaded().

◆ token

Scroom::Bookkeeping::Token TiledBitmapViewData::token

◆ viewInterface

ViewInterface::WeakPtr TiledBitmapViewData::viewInterface

◆ volatileStuff

Scroom::Utils::StuffList TiledBitmapViewData::volatileStuff
private

References to things the user should be able to throw away on request

This includes

  • pre-drawn bitmaps to make redraws go faster

Referenced by clearVolatileStuff(), resetNeededTiles(), and storeVolatileStuff().

◆ zoom

int TiledBitmapViewData::zoom {0}
private

Referenced by resetNeededTiles(), and setNeededTiles().


The documentation for this class was generated from the following files:
TiledBitmapViewData::resetNeededTiles
void resetNeededTiles()
Definition: tiledbitmapviewdata.cc:65
TiledBitmapViewData::viewInterface
ViewInterface::WeakPtr viewInterface
Definition: tiledbitmapviewdata.hh:28
Scroom::GtkHelpers::async_on_ui_thread
void async_on_ui_thread(T f)
Definition: gtk-helpers.hh:42
TiledBitmapViewData::mut
boost::mutex mut
Definition: tiledbitmapviewdata.hh:61
TiledBitmapViewData::progressInterface
ProgressInterface::Ptr progressInterface
Definition: tiledbitmapviewdata.hh:29
TiledBitmapViewData::volatileStuff
Scroom::Utils::StuffList volatileStuff
Definition: tiledbitmapviewdata.hh:56
TiledBitmapViewData::Ptr
boost::shared_ptr< TiledBitmapViewData > Ptr
Definition: tiledbitmapviewdata.hh:25
TileViewState::Ptr
boost::shared_ptr< TileViewState > Ptr
Definition: tileviewstate.hh:27
TiledBitmapViewData::layer
Layer::Ptr layer
Definition: tiledbitmapviewdata.hh:33
TiledBitmapViewData::redrawPending
bool redrawPending
Definition: tiledbitmapviewdata.hh:58
TiledBitmapViewData::imin
int imin
Definition: tiledbitmapviewdata.hh:34
invalidate_view
static void invalidate_view(const ViewInterface::WeakPtr &vi)
Definition: tiledbitmapviewdata.cc:113
TiledBitmapViewData::imax
int imax
Definition: tiledbitmapviewdata.hh:35
TiledBitmapViewData::stuff
Scroom::Utils::StuffList stuff
Definition: tiledbitmapviewdata.hh:48
TiledBitmapViewData::layerOperations
LayerOperations::Ptr layerOperations
Definition: tiledbitmapviewdata.hh:39
CompressedTile::Ptr
boost::shared_ptr< CompressedTile > Ptr
Definition: tiledbitmaplayer.hh:108
TiledBitmapViewData::TiledBitmapViewData
TiledBitmapViewData(const ViewInterface::WeakPtr &viewInterface)
Definition: tiledbitmapviewdata.cc:25
TiledBitmapViewData::jmin
int jmin
Definition: tiledbitmapviewdata.hh:36
TiledBitmapViewData::zoom
int zoom
Definition: tiledbitmapviewdata.hh:38
TiledBitmapViewData::jmax
int jmax
Definition: tiledbitmapviewdata.hh:37