Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
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 = std::shared_ptr< TileViewState >
 
using WeakPtr = std::weak_ptr< TileViewState >
 
- Public Types inherited from Scroom::Utils::Observable< TileLoadingObserver >
using Observer = std::shared_ptr< TileLoadingObserver >
 
using Ptr = std::shared_ptr< Observable< TileLoadingObserver > >
 
- Public Types inherited from TileLoadingObserver
using Ptr = std::shared_ptr< TileLoadingObserver >
 
using WeakPtr = std::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 std::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)
 
- 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 std::shared_ptr< CompressedTile > &parent)
 

Private Member Functions

 TileViewState (std::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

std::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
 
std::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 = std::shared_ptr<TileViewState>

◆ WeakPtr

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

Member Enumeration Documentation

◆ State

Enumerator
INIT 
LOADED 
COMPUTING_BASE 
BASE_COMPUTED 
COMPUTING_ZOOM 
ZOOM_COMPUTED 
DONE 
33 {
34 INIT,
35 LOADED,
40 DONE
41 };
@ INIT
Definition tileviewstate.hh:34
@ ZOOM_COMPUTED
Definition tileviewstate.hh:39
@ BASE_COMPUTED
Definition tileviewstate.hh:37
@ DONE
Definition tileviewstate.hh:40
@ LOADED
Definition tileviewstate.hh:35
@ COMPUTING_BASE
Definition tileviewstate.hh:36
@ COMPUTING_ZOOM
Definition tileviewstate.hh:38

Constructor & Destructor Documentation

◆ ~TileViewState()

TileViewState::~TileViewState ( )
override
24{ r.reset(); }
Scroom::Utils::Stuff r
Definition tileviewstate.hh:50

◆ TileViewState() [1/3]

TileViewState::TileViewState ( const TileViewState )
delete

◆ TileViewState() [2/3]

TileViewState::TileViewState ( TileViewState &&  )
delete

◆ TileViewState() [3/3]

TileViewState::TileViewState ( std::shared_ptr< CompressedTile parent)
explicitprivate
36 : parent(std::move(parent_))
38{
39}
ThreadPool::Ptr cpuBound
Definition tileviewstate.hh:58
std::shared_ptr< CompressedTile > parent
Definition tileviewstate.hh:44
ThreadPool::Ptr CpuBound()
Definition threadpoolimpl.cc:455

Member Function Documentation

◆ clear()

void TileViewState::clear ( )
private
234{
235 boost::mutex::scoped_lock const l(mut);
236
237 if(state >= LOADED)
238 {
239 state = LOADED;
240 }
241
242 queue.reset();
243 weakQueue.reset();
244 lifeTimeManager.reset();
245 baseCache.reset();
246 zoomCache.reset();
247
248 kick();
249}
boost::mutex mut
Definition tileviewstate.hh:45
State state
Definition tileviewstate.hh:46
ThreadPool::Queue::Ptr queue
Definition tileviewstate.hh:48
ThreadPool::WeakQueue::Ptr weakQueue
Definition tileviewstate.hh:49
Scroom::Utils::StuffWeak lifeTimeManager
Definition tileviewstate.hh:55
Scroom::Utils::Stuff baseCache
Definition tileviewstate.hh:56
void kick()
Definition tileviewstate.cc:111
Scroom::Utils::Stuff zoomCache
Definition tileviewstate.hh:57
PageList const l
Definition compression-tests.cc:33
Here is the call graph for this function:

◆ computeBase()

void TileViewState::computeBase ( const ThreadPool::WeakQueue::Ptr wq,
const ConstTile::Ptr tile_,
const LayerOperations::Ptr lo_ 
)
private
193{
194 Scroom::Utils::Stuff const baseCache_ = lo_->cache(tile_);
195
196 boost::mutex::scoped_lock const l(mut);
197 TiledBitmapViewData::Ptr const tbvd_ = tbvd.lock();
198
199 if(tbvd_ && desiredState >= BASE_COMPUTED && weakQueue == wq)
200 {
201 baseCache = baseCache_;
203 }
204}
std::weak_ptr< TiledBitmapViewData > tbvd
Definition tileviewstate.hh:52
State desiredState
Definition tileviewstate.hh:47
std::shared_ptr< TiledBitmapViewData > Ptr
Definition tiledbitmapviewdata.hh:25
std::shared_ptr< void > Stuff
Definition stuff.hh:17

◆ computeZoom()

void TileViewState::computeZoom ( const ThreadPool::WeakQueue::Ptr wq,
const ConstTile::Ptr tile,
const LayerOperations::Ptr lo,
Scroom::Utils::Stuff  baseCache,
int  zoom 
)
private
213{
214 Scroom::Utils::Stuff const zoomCache_ = lo_->cacheZoom(tile_, zoom_, baseCache_);
215
216 boost::mutex::scoped_lock const l(mut);
217 TiledBitmapViewData::Ptr const tbvd_ = tbvd.lock();
218 if(tbvd_ && desiredState >= ZOOM_COMPUTED && zoom == zoom_ && weakQueue == wq)
219 {
220 zoomCache = zoomCache_;
222 }
223}
int zoom
Definition tileviewstate.hh:54

◆ create()

TileViewState::Ptr TileViewState::create ( const std::shared_ptr< CompressedTile > &  parent)
static
27{
29
30 result->r = parent->registerObserver(result);
31
32 return result;
33}
Definition tileviewstate.hh:27
std::shared_ptr< TileViewState > Ptr
Definition tileviewstate.hh:29
SampleIterator< const uint8_t > result
Definition sampleiterator-tests.cc:94

Referenced by CompressedTile::getViewState().

Here is the caller graph for this function:

◆ getCacheResult()

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

◆ 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(
126 [me = shared_from_this<TileViewState>(), weakQueue = weakQueue] { me->process(weakQueue); }, LOAD_PRIO, queue
127 );
128 }
129}
#define defect_message(m)
Definition assertions.hh:49
static Ptr createAsync()
Definition threadpoolimpl.cc:382
ConstTile::Ptr tile
Definition tileviewstate.hh:51
#define LOAD_PRIO
Definition local.hh:10

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

132{
133 for(;;)
134 {
135 boost::mutex::scoped_lock l(mut);
136
137 if(wq == weakQueue && state < desiredState)
138 {
139 boost::function<void()> fn;
140
141 switch(state)
142 {
143 case LOADED:
144 fn = [me = shared_from_this<TileViewState>(), wq, tile = tile, lo = lo] { me->computeBase(wq, tile, lo); };
146 break;
147
148 case BASE_COMPUTED:
149 fn = [me = shared_from_this<TileViewState>(), wq, tile = tile, lo = lo, baseCache = baseCache, zoom = zoom]
150 { me->computeZoom(wq, tile, lo, baseCache, zoom); };
152 break;
153
154 case ZOOM_COMPUTED:
155 state = DONE;
156 fn = [me = shared_from_this<TileViewState>(), wq, tile = tile] { me->reportDone(wq, tile); };
157 break;
158
159 case INIT:
160 case COMPUTING_BASE:
161 case COMPUTING_ZOOM:
162 case DONE:
163 default:
164 defect_message(fmt::format("PANIC: Don't know what to do in state {}", state));
165 return;
166 }
167
168 l.unlock();
169 fn();
170 }
171 else
172 {
173 break;
174 }
175 }
176
177 {
178 boost::mutex::scoped_lock const l(mut);
179
180 if(wq == weakQueue)
181 {
182 queue.reset();
183 weakQueue.reset();
184 }
185 }
186}
LayerOperations::Ptr lo
Definition tileviewstate.hh:53
() void(clear(nullptr)+(5 *clear(nullptr)) *5)
Here is the call graph for this function:

◆ reportDone()

void TileViewState::reportDone ( const ThreadPool::WeakQueue::Ptr wq,
const ConstTile::Ptr tile 
)
private
226{
228 {
229 observer->tileLoaded(tile_);
230 }
231}
Observable()
Definition observable.hh:171
std::list< Observer > getObservers()
Definition observable.hh:196
Definition tiledbitmaplayer.hh:80
std::shared_ptr< TileLoadingObserver > Ptr
Definition tiledbitmaplayer.hh:82
Definition blockallocator.hh:18
TestObserver::Ptr observer
Definition observable-tests.cc:91
Here is the call graph for this function:

◆ setViewData()

void TileViewState::setViewData ( const std::shared_ptr< TiledBitmapViewData > &  tbvd)
66{
67 boost::mutex::scoped_lock const l(mut);
68 tbvd = tbvd_;
69
70 Scroom::Utils::Stuff lifeTimeManager_ = lifeTimeManager.lock();
71 if(!lifeTimeManager_)
72 {
73 lifeTimeManager_ = std::shared_ptr<void>(
74 reinterpret_cast<void*>(0xDEAD), [me = shared_from_this<TileViewState>()](auto p [[maybe_unused]]) { me->clear(); }
75 );
76 lifeTimeManager = lifeTimeManager_;
77 }
78 tbvd_->storeVolatileStuff(lifeTimeManager_);
79
80 kick();
81}
PresentationInterfaceStub::Ptr const p
Definition determine-size-test.cc:172
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.

42{
43 boost::mutex::scoped_lock const l(mut);
44
45 tile = tile_;
46
47 // Abort any zoom currently in progress
48 if(state > LOADED)
49 {
50 queue.reset();
51 weakQueue.reset();
52 zoomCache.reset();
53 }
54 state = LOADED;
55
56 kick();
57}
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

std::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

std::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
54{0};

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

◆ zoomCache

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

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