Scroom  0.14
TileViewState Class Reference

#include <tileviewstate.hh>

Inheritance diagram for TileViewState:
Inheritance graph
Collaboration diagram for TileViewState:
Collaboration graph

Public Types

enum  State {
  INIT, LOADED, COMPUTING_BASE, BASE_COMPUTED,
  COMPUTING_ZOOM, ZOOM_COMPUTED, DONE
}
 
using Ptr = boost::shared_ptr< TileViewState >
 
using WeakPtr = boost::weak_ptr< TileViewState >
 
- Public Types inherited from Scroom::Utils::Observable< TileLoadingObserver >
using Observer = boost::shared_ptr< TileLoadingObserver >
 
using Ptr = boost::shared_ptr< Observable< TileLoadingObserver > >
 
- Public Types inherited from TileLoadingObserver
using Ptr = boost::shared_ptr< TileLoadingObserver >
 
using WeakPtr = boost::weak_ptr< TileLoadingObserver >
 

Public Member Functions

 ~TileViewState () override
 
 TileViewState (const TileViewState &)=delete
 
 TileViewState (TileViewState &&)=delete
 
TileViewState operator= (const TileViewState &)=delete
 
TileViewState operator= (TileViewState &&)=delete
 
Scroom::Utils::Stuff getCacheResult ()
 
void setViewData (const boost::shared_ptr< TiledBitmapViewData > &tbvd)
 
void setZoom (LayerOperations::Ptr lo, int zoom)
 
void tileLoaded (ConstTile::Ptr tile) override
 
- Public Member Functions inherited from Scroom::Utils::Observable< TileLoadingObserver >
 Observable ()
 
 Observable (const Observable &)=delete
 
 Observable (Observable &&)=delete
 
 ~Observable () override
 
Observable operator= (const Observable &)=delete
 
Observable operator= (Observable &&)=delete
 
Scroom::Bookkeeping::Token registerStrongObserver (Observer const &observer)
 
Scroom::Bookkeeping::Token registerObserver (ObserverWeak const &observer)
 

Static Public Member Functions

static Ptr create (const boost::shared_ptr< CompressedTile > &parent)
 

Private Member Functions

 TileViewState (boost::shared_ptr< CompressedTile > parent)
 
void kick ()
 
void process (const ThreadPool::WeakQueue::Ptr &wq)
 
void computeBase (const ThreadPool::WeakQueue::Ptr &wq, const ConstTile::Ptr &tile_, const LayerOperations::Ptr &lo_)
 
void computeZoom (const ThreadPool::WeakQueue::Ptr &wq, const ConstTile::Ptr &tile, const LayerOperations::Ptr &lo, Scroom::Utils::Stuff baseCache, int zoom)
 
void reportDone (const ThreadPool::WeakQueue::Ptr &wq, const ConstTile::Ptr &tile)
 
void clear ()
 

Private Attributes

boost::shared_ptr< CompressedTileparent
 
boost::mutex mut
 
State state {INIT}
 
State desiredState {LOADED}
 
ThreadPool::Queue::Ptr queue
 
ThreadPool::WeakQueue::Ptr weakQueue
 
Scroom::Utils::Stuff r
 
ConstTile::Ptr tile
 
boost::weak_ptr< TiledBitmapViewDatatbvd
 
LayerOperations::Ptr lo
 
int zoom {0}
 
Scroom::Utils::StuffWeak lifeTimeManager
 
Scroom::Utils::Stuff baseCache
 
Scroom::Utils::Stuff zoomCache
 
ThreadPool::Ptr cpuBound
 

Additional Inherited Members

- Protected Member Functions inherited from Scroom::Utils::Observable< TileLoadingObserver >
std::list< ObservergetObservers ()
 
virtual void observerAdded (Observer const &observer, Scroom::Bookkeeping::Token const &token)
 

Member Typedef Documentation

◆ Ptr

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

◆ WeakPtr

using TileViewState::WeakPtr = boost::weak_ptr<TileViewState>

Member Enumeration Documentation

◆ State

Enumerator
INIT 
LOADED 
COMPUTING_BASE 
BASE_COMPUTED 
COMPUTING_ZOOM 
ZOOM_COMPUTED 
DONE 
31  {
32  INIT,
33  LOADED,
38  DONE
39  };

Constructor & Destructor Documentation

◆ ~TileViewState()

TileViewState::~TileViewState ( )
override
25 { r.reset(); }

◆ TileViewState() [1/3]

TileViewState::TileViewState ( const TileViewState )
delete

Referenced by create().

Here is the caller graph for this function:

◆ TileViewState() [2/3]

TileViewState::TileViewState ( TileViewState &&  )
delete

◆ TileViewState() [3/3]

TileViewState::TileViewState ( boost::shared_ptr< CompressedTile parent)
explicitprivate
37  : parent(std::move(parent_))
38  , cpuBound(CpuBound())
39 {
40 }

Member Function Documentation

◆ clear()

void TileViewState::clear ( )
private
229 {
230  boost::mutex::scoped_lock const l(mut);
231 
232  if(state >= LOADED)
233  {
234  state = LOADED;
235  }
236 
237  queue.reset();
238  weakQueue.reset();
239  lifeTimeManager.reset();
240  baseCache.reset();
241  zoomCache.reset();
242 
243  kick();
244 }

Referenced by setViewData().

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

◆ computeBase()

void TileViewState::computeBase ( const ThreadPool::WeakQueue::Ptr wq,
const ConstTile::Ptr tile_,
const LayerOperations::Ptr lo_ 
)
private
188 {
189  Scroom::Utils::Stuff const baseCache_ = lo_->cache(tile_);
190 
191  boost::mutex::scoped_lock const l(mut);
192  TiledBitmapViewData::Ptr const tbvd_ = tbvd.lock();
193 
194  if(tbvd_ && desiredState >= BASE_COMPUTED && weakQueue == wq)
195  {
196  baseCache = baseCache_;
198  }
199 }

Referenced by process().

Here is the caller graph for this function:

◆ computeZoom()

void TileViewState::computeZoom ( const ThreadPool::WeakQueue::Ptr wq,
const ConstTile::Ptr tile,
const LayerOperations::Ptr lo,
Scroom::Utils::Stuff  baseCache,
int  zoom 
)
private
206 {
207  Scroom::Utils::Stuff const zoomCache_ = lo_->cacheZoom(tile_, zoom_, baseCache_);
208 
209  boost::mutex::scoped_lock const l(mut);
210  TiledBitmapViewData::Ptr const tbvd_ = tbvd.lock();
211  if(tbvd_ && desiredState >= ZOOM_COMPUTED && zoom == zoom_ && weakQueue == wq)
212  {
213  zoomCache = zoomCache_;
215  }
216 }

Referenced by process().

Here is the caller graph for this function:

◆ create()

TileViewState::Ptr TileViewState::create ( const boost::shared_ptr< CompressedTile > &  parent)
static
28 {
30 
31  result->r = parent->registerObserver(result);
32 
33  return result;
34 }

Referenced by CompressedTile::getViewState().

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

◆ getCacheResult()

Scroom::Utils::Stuff TileViewState::getCacheResult ( )
61 {
62  boost::mutex::scoped_lock const l(mut);
63  return zoomCache;
64 }

◆ kick()

void TileViewState::kick ( )
private

Kick the internal state machine into making some progress

112 {
113  if(state >= LOADED && !tile)
114  {
115  defect_message("PANIC: State LOADED and no tile shouldn't happen.");
116  }
117 
118  TiledBitmapViewData::Ptr const tbvd_ = tbvd.lock();
119 
120  if(state >= LOADED && desiredState >= state && !queue && tbvd_)
121  {
123  weakQueue = queue->getWeak();
124 
125  cpuBound->schedule(boost::bind(&TileViewState::process, shared_from_this<TileViewState>(), weakQueue), LOAD_PRIO, queue);
126  }
127 }

Referenced by clear(), setViewData(), setZoom(), and tileLoaded().

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

◆ operator=() [1/2]

TileViewState TileViewState::operator= ( const TileViewState )
delete

◆ operator=() [2/2]

TileViewState TileViewState::operator= ( TileViewState &&  )
delete

◆ process()

void TileViewState::process ( const ThreadPool::WeakQueue::Ptr wq)
private

Asynchronously do work to make the state machine progress

130 {
131  for(;;)
132  {
133  boost::mutex::scoped_lock l(mut);
134 
135  if(wq == weakQueue && state < desiredState)
136  {
137  boost::function<void()> fn;
138 
139  switch(state)
140  {
141  case LOADED:
142  fn = boost::bind(&TileViewState::computeBase, shared_from_this<TileViewState>(), wq, tile, lo);
144  break;
145 
146  case BASE_COMPUTED:
147  fn = boost::bind(&TileViewState::computeZoom, shared_from_this<TileViewState>(), wq, tile, lo, baseCache, zoom);
149  break;
150 
151  case ZOOM_COMPUTED:
152  state = DONE;
153  fn = boost::bind(&TileViewState::reportDone, shared_from_this<TileViewState>(), wq, tile);
154  break;
155 
156  case INIT:
157  case COMPUTING_BASE:
158  case COMPUTING_ZOOM:
159  case DONE:
160  default:
161  defect_message(fmt::format("PANIC: Don't know what to do in state {}", state));
162  return;
163  }
164 
165  l.unlock();
166  fn();
167  }
168  else
169  {
170  break;
171  }
172  }
173 
174  {
175  boost::mutex::scoped_lock const l(mut);
176 
177  if(wq == weakQueue)
178  {
179  queue.reset();
180  weakQueue.reset();
181  }
182  }
183 }

Referenced by kick().

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

◆ reportDone()

void TileViewState::reportDone ( const ThreadPool::WeakQueue::Ptr wq,
const ConstTile::Ptr tile 
)
private
219 {
220  UNUSED(wq);
221 
223  {
224  observer->tileLoaded(tile_);
225  }
226 }

Referenced by process().

Here is the caller graph for this function:

◆ setViewData()

void TileViewState::setViewData ( const boost::shared_ptr< TiledBitmapViewData > &  tbvd)
67 {
68  boost::mutex::scoped_lock const l(mut);
69  tbvd = tbvd_;
70 
71  Scroom::Utils::Stuff lifeTimeManager_ = lifeTimeManager.lock();
72  if(!lifeTimeManager_)
73  {
74  lifeTimeManager_ = boost::shared_ptr<void>(reinterpret_cast<void*>(0xDEAD),
75  boost::bind(&TileViewState::clear, shared_from_this<TileViewState>()));
76  lifeTimeManager = lifeTimeManager_;
77  }
78  tbvd_->storeVolatileStuff(lifeTimeManager_);
79 
80  kick();
81 }
Here is the call graph for this function:

◆ setZoom()

void TileViewState::setZoom ( LayerOperations::Ptr  lo,
int  zoom 
)
84 {
85  bool mustKick = false;
86 
87  boost::mutex::scoped_lock const l(mut);
88  if(desiredState != DONE || zoom_ != zoom)
89  {
90  zoom = zoom_;
91  lo = std::move(lo_);
93  mustKick = true;
94 
95  // Abort any zoom currently in progress
96  if(state >= BASE_COMPUTED)
97  {
98  queue.reset();
99  weakQueue.reset();
100  zoomCache.reset();
102  }
103  }
104 
105  if(mustKick)
106  {
107  kick();
108  }
109 }
Here is the call graph for this function:

◆ tileLoaded()

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

The Tile has been loaded.

Implements TileLoadingObserver.

43 {
44  boost::mutex::scoped_lock const l(mut);
45 
46  tile = tile_;
47 
48  // Abort any zoom currently in progress
49  if(state > LOADED)
50  {
51  queue.reset();
52  weakQueue.reset();
53  zoomCache.reset();
54  }
55  state = LOADED;
56 
57  kick();
58 }
Here is the call graph for this function:

Member Data Documentation

◆ baseCache

Scroom::Utils::Stuff TileViewState::baseCache
private

Referenced by clear(), computeBase(), and process().

◆ cpuBound

ThreadPool::Ptr TileViewState::cpuBound
private

Referenced by kick().

◆ desiredState

State TileViewState::desiredState {LOADED}
private

◆ lifeTimeManager

Scroom::Utils::StuffWeak TileViewState::lifeTimeManager
private

Referenced by clear(), and setViewData().

◆ lo

LayerOperations::Ptr TileViewState::lo
private

Referenced by process(), and setZoom().

◆ mut

boost::mutex TileViewState::mut
private

◆ parent

boost::shared_ptr<CompressedTile> TileViewState::parent
private

Referenced by create().

◆ queue

ThreadPool::Queue::Ptr TileViewState::queue
private

Referenced by clear(), kick(), process(), setZoom(), and tileLoaded().

◆ r

Scroom::Utils::Stuff TileViewState::r
private

Referenced by ~TileViewState().

◆ state

State TileViewState::state {INIT}
private

◆ tbvd

boost::weak_ptr<TiledBitmapViewData> TileViewState::tbvd
private

◆ tile

ConstTile::Ptr TileViewState::tile
private

Referenced by kick(), process(), and tileLoaded().

◆ weakQueue

ThreadPool::WeakQueue::Ptr TileViewState::weakQueue
private

◆ zoom

int TileViewState::zoom {0}
private

Referenced by computeZoom(), process(), and setZoom().

◆ zoomCache

Scroom::Utils::Stuff TileViewState::zoomCache
private

The documentation for this class was generated from the following files:
TileLoadingObserver::Ptr
boost::shared_ptr< TileLoadingObserver > Ptr
Definition: tiledbitmaplayer.hh:83
TileViewState::TileViewState
TileViewState(const TileViewState &)=delete
TileViewState::cpuBound
ThreadPool::Ptr cpuBound
Definition: tileviewstate.hh:56
UNUSED
#define UNUSED(x)
Definition: unused.hh:10
TileViewState::INIT
@ INIT
Definition: tileviewstate.hh:32
ThreadPool::Queue::createAsync
static Ptr createAsync()
Definition: threadpoolimpl.cc:379
TileViewState::computeBase
void computeBase(const ThreadPool::WeakQueue::Ptr &wq, const ConstTile::Ptr &tile_, const LayerOperations::Ptr &lo_)
Definition: tileviewstate.cc:185
TileViewState::desiredState
State desiredState
Definition: tileviewstate.hh:45
TiledBitmapViewData::Ptr
boost::shared_ptr< TiledBitmapViewData > Ptr
Definition: tiledbitmapviewdata.hh:25
TileViewState::tile
ConstTile::Ptr tile
Definition: tileviewstate.hh:49
TileViewState::Ptr
boost::shared_ptr< TileViewState > Ptr
Definition: tileviewstate.hh:27
TileViewState::r
Scroom::Utils::Stuff r
Definition: tileviewstate.hh:48
TileViewState::kick
void kick()
Definition: tileviewstate.cc:111
TileViewState::COMPUTING_ZOOM
@ COMPUTING_ZOOM
Definition: tileviewstate.hh:36
TileViewState::zoom
int zoom
Definition: tileviewstate.hh:52
TileViewState::mut
boost::mutex mut
Definition: tileviewstate.hh:43
TileViewState::process
void process(const ThreadPool::WeakQueue::Ptr &wq)
Definition: tileviewstate.cc:129
TileViewState::baseCache
Scroom::Utils::Stuff baseCache
Definition: tileviewstate.hh:54
TileViewState::queue
ThreadPool::Queue::Ptr queue
Definition: tileviewstate.hh:46
TileViewState::parent
boost::shared_ptr< CompressedTile > parent
Definition: tileviewstate.hh:42
CpuBound
ThreadPool::Ptr CpuBound()
Definition: threadpoolimpl.cc:452
TileViewState::LOADED
@ LOADED
Definition: tileviewstate.hh:33
TileViewState::COMPUTING_BASE
@ COMPUTING_BASE
Definition: tileviewstate.hh:34
TileViewState::lifeTimeManager
Scroom::Utils::StuffWeak lifeTimeManager
Definition: tileviewstate.hh:53
TileViewState::BASE_COMPUTED
@ BASE_COMPUTED
Definition: tileviewstate.hh:35
TileViewState::clear
void clear()
Definition: tileviewstate.cc:228
TileViewState::reportDone
void reportDone(const ThreadPool::WeakQueue::Ptr &wq, const ConstTile::Ptr &tile)
Definition: tileviewstate.cc:218
Scroom::Utils::Stuff
boost::shared_ptr< void > Stuff
Definition: stuff.hh:18
Scroom::Utils::Observable
Definition: observable.hh:24
TileViewState::computeZoom
void computeZoom(const ThreadPool::WeakQueue::Ptr &wq, const ConstTile::Ptr &tile, const LayerOperations::Ptr &lo, Scroom::Utils::Stuff baseCache, int zoom)
Definition: tileviewstate.cc:201
TileViewState::weakQueue
ThreadPool::WeakQueue::Ptr weakQueue
Definition: tileviewstate.hh:47
TileViewState::DONE
@ DONE
Definition: tileviewstate.hh:38
TileViewState::tbvd
boost::weak_ptr< TiledBitmapViewData > tbvd
Definition: tileviewstate.hh:50
defect_message
#define defect_message(m)
Definition: assertions.hh:43
TileViewState::zoomCache
Scroom::Utils::Stuff zoomCache
Definition: tileviewstate.hh:55
TileViewState::lo
LayerOperations::Ptr lo
Definition: tileviewstate.hh:51
TileViewState::state
State state
Definition: tileviewstate.hh:44
LOAD_PRIO
#define LOAD_PRIO
Definition: local.hh:10
TileViewState::ZOOM_COMPUTED
@ ZOOM_COMPUTED
Definition: tileviewstate.hh:37