Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
TiledBitmapViewData Class Reference

#include <tiledbitmapviewdata.hh>

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

Public Types

using Ptr = std::shared_ptr< TiledBitmapViewData >
 
- Public Types inherited from TileLoadingObserver
using Ptr = std::shared_ptr< TileLoadingObserver >
 
using WeakPtr = std::weak_ptr< TileLoadingObserver >
 
- Public Types inherited from ProgressInterface
using Ptr = std::shared_ptr< ProgressInterface >
 
using WeakPtr = std::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 >
std::shared_ptr< R > shared_from_this ()
 
template<typename R >
std::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

Constructor & Destructor Documentation

◆ TiledBitmapViewData()

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

Member Function Documentation

◆ clearVolatileStuff()

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

◆ create()

TiledBitmapViewData::Ptr TiledBitmapViewData::create ( const ViewInterface::WeakPtr viewInterface)
static
21{
23}
Definition tiledbitmapviewdata.hh:23
std::shared_ptr< TiledBitmapViewData > Ptr
Definition tiledbitmapviewdata.hh:25

Referenced by TiledBitmap::open().

Here is the caller graph for this function:

◆ resetNeededTiles()

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

Referenced by clearVolatileStuff(), and setNeededTiles().

Here is the caller graph for this function:

◆ setFinished()

void TiledBitmapViewData::setFinished ( )
overridevirtual

Implements ProgressInterface.

165{ progressInterface->setFinished(); }

◆ setIdle()

void TiledBitmapViewData::setIdle ( )
overridevirtual

Implements ProgressInterface.

159{ progressInterface->setIdle(); }

◆ setNeededTiles()

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

◆ setWaiting()

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

Implements ProgressInterface.

161{ progressInterface->setWaiting(progress); }
stub progress
Definition progressinterfaceconversion-tests.cc:65

◆ setWorking()

void TiledBitmapViewData::setWorking ( double  progress)
overridevirtual

Implements ProgressInterface.

163{ progressInterface->setWorking(progress); }

◆ storeVolatileStuff()

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

◆ tileLoaded()

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

The Tile has been loaded.

Implements TileLoadingObserver.

145{
146 boost::unique_lock<boost::mutex> const lock(mut);
147 stuff.emplace_back(tile);
148
149 if(!redrawPending)
150 {
151 // We're not sure about whether gdk_threads_enter() has been
152 // called or not, so we have no choice but to invalidate on
153 // another thread.
155 redrawPending = true;
156 }
157}
void async_on_ui_thread(T f)
Definition gtk-helpers.hh:42
static void invalidate_view(const ViewInterface::WeakPtr &vi)
Definition tiledbitmapviewdata.cc:115
Here is the call graph for this function:

Member Data Documentation

◆ imax

int TiledBitmapViewData::imax {0}
private
35{0};

Referenced by resetNeededTiles(), and setNeededTiles().

◆ imin

int TiledBitmapViewData::imin {0}
private
34{0};

Referenced by resetNeededTiles(), and setNeededTiles().

◆ jmax

int TiledBitmapViewData::jmax {0}
private
37{0};

Referenced by resetNeededTiles(), and setNeededTiles().

◆ jmin

int TiledBitmapViewData::jmin {0}
private
36{0};

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
58{false};

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
38{0};

Referenced by resetNeededTiles(), and setNeededTiles().


The documentation for this class was generated from the following files: