Scroom  0.14
layercoordinator.hh
Go to the documentation of this file.
1 /*
2  * Scroom - Generic viewer for 2D data
3  * Copyright (C) 2009-2022 Kees-Jan Dijkzeul
4  *
5  * SPDX-License-Identifier: LGPL-2.1
6  */
7 
8 #pragma once
9 
10 #include <map>
11 #include <utility>
12 
13 #include <boost/enable_shared_from_this.hpp>
14 #include <boost/shared_ptr.hpp>
15 #include <boost/thread.hpp>
16 
18 
21  , public virtual Scroom::Utils::Base
22 {
23 private:
26  std::map<CompressedTile::Ptr, std::pair<int, int>> sourceTiles;
29  boost::mutex mut;
31 
32 public:
33  using Ptr = boost::shared_ptr<LayerCoordinator>;
34 
36 
37  ~LayerCoordinator() override;
38  LayerCoordinator(const LayerCoordinator&) = delete;
42 
43  void addSourceTile(int x, int y, const CompressedTile::Ptr& tile);
44 
45 private:
47 
48  void reduceSourceTile(const CompressedTile::Ptr& tile, ConstTile::Ptr const& tileData);
49 
50 public:
53  void tileFinished(const CompressedTile::Ptr& tile) override;
54 };
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(basic_jobcounting)
Definition: threadpool-queue-tests.cc:39
CompressedTile::viewStates
std::map< ViewInterface::WeakPtr, boost::weak_ptr< TileViewState > > viewStates
Definition: tiledbitmaplayer.hh:127
local.hh
A::create
static Ptr create(Semaphore *s)
Definition: threadpool-tests.cc:49
CompressedTile::getState
TileState getState()
Definition: compressedtile.cc:176
TileLoadingObserver::Ptr
boost::shared_ptr< TileLoadingObserver > Ptr
Definition: tiledbitmaplayer.hh:83
DataFetcher::threadPool
ThreadPool::Ptr threadPool
Definition: layer.cc:51
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(work_gets_done)
Definition: threadpool-tests.cc:137
LayerCoordinator
Definition: layercoordinator.hh:19
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(destroy_threadpool_with_nonempty_queue)
Definition: threadpool-destruction-tests.cc:36
TileInitialisationObserver::Ptr
boost::shared_ptr< TileInitialisationObserver > Ptr
Definition: tiledbitmaplayer.hh:52
TileInitialisationObserver::tileFinished
virtual void tileFinished(const boost::shared_ptr< CompressedTile > &tile)
TileInitialisationObserver.
Definition: compressedtile.cc:289
UNUSED
#define UNUSED(x)
Definition: unused.hh:10
CompressedTile::x
const int x
Definition: tiledbitmaplayer.hh:112
Layer::getHorTileCount
int getHorTileCount() const
Definition: layer.cc:124
TileStateInternal
TileStateInternal
Definition: tiledbitmaplayer.hh:34
Scroom::MemoryBlobs::PageProvider::Ptr
boost::shared_ptr< PageProvider > Ptr
Definition: memoryblobs.hh:41
ThreadPool::Ptr
boost::shared_ptr< ThreadPool > Ptr
Definition: threadpool.hh:169
TILE_UNLOADED
@ TILE_UNLOADED
Definition: tiledbitmapinterface.hh:35
global.hh
Scroom::Utils::StuffList
std::list< Stuff > StuffList
Definition: stuff.hh:20
ThreadPool::Queue::Ptr
boost::shared_ptr< Queue > Ptr
Definition: threadpool.hh:82
long_timeout
const millisec long_timeout(2000)
CompressedTile::close
void close(ViewInterface::WeakPtr vi) override
Definition: compressedtile.cc:284
Layer::width
int width
Definition: tiledbitmaplayer.hh:251
Scroom::Utils
Definition: assertions.hh:14
short_timeout
const millisec short_timeout(250)
threadpool.hh
CompressedTile::tile
Tile::WeakPtr tile
Definition: tiledbitmaplayer.hh:118
PipetteCommonOperationsCMYK
Definition: layeroperations.hh:33
Layer::Ptr
boost::shared_ptr< Layer > Ptr
Definition: tiledbitmaplayer.hh:247
DataFetcher::horTileCount
int horTileCount
Definition: layer.cc:47
Layer::tiles
CompressedTileGrid tiles
Definition: tiledbitmaplayer.hh:255
LayerCoordinator::registrations
Scroom::Utils::StuffList registrations
Definition: layercoordinator.hh:27
helpers.hh
LayerCoordinator::addSourceTile
void addSourceTile(int x, int y, const CompressedTile::Ptr &tile)
Definition: layercoordinator.cc:37
clear
boost::function< void()> clear(Semaphore *s)
Definition: helpers.cc:29
DataFetcher::DataFetcher
DataFetcher(Layer::Ptr layer, int height, int horTileCount, int verTileCount, SourcePresentation::Ptr sp, ThreadPool::WeakQueue::Ptr queue, std::function< void()> on_finished)
DataFetcher.
Definition: layer.cc:192
Layer::verTileCount
int verTileCount
Definition: tiledbitmaplayer.hh:254
B::operator()
R operator()()
Definition: threadpool-tests.cc:68
Layer::close
void close(ViewInterface::WeakPtr vi) override
Definition: layer.cc:173
LayerCoordinator::targetTileData
Tile::Ptr targetTileData
Definition: layercoordinator.hh:25
OperationsCMYK16::create
static Ptr create()
Definition: cmyklayeroperations.cc:123
ThreadPool::WeakQueue::Ptr
boost::shared_ptr< WeakQueue > Ptr
Definition: threadpool.hh:137
createProvider
static Scroom::MemoryBlobs::PageProvider::Ptr createProvider(double width, double height, int bpp)
Definition: layer.cc:25
CompressedTile::constTile
ConstTile::WeakPtr constTile
Definition: tiledbitmaplayer.hh:119
CompressedTile::cleanupState
void cleanupState()
Definition: compressedtile.cc:261
CompressedTile::create
static Ptr create(int depth, int x, int y, int bpp, const Scroom::MemoryBlobs::PageProvider::Ptr &provider, TileStateInternal state=TSI_UNINITIALIZED)
Definition: compressedtile.cc:32
has_exactly_n_threads
bool has_exactly_n_threads(ThreadPool *pool, int count)
Definition: threadpool-tests.cc:126
LayerCoordinator::unfinishedSourceTiles
int unfinishedSourceTiles
Definition: layercoordinator.hh:30
OperationsCMYK32::reduce
void reduce(Tile::Ptr target, ConstTile::Ptr source, int x, int y) override
Definition: cmyklayeroperations.cc:72
OperationsCMYK8::OperationsCMYK8
OperationsCMYK8()
Definition: cmyklayeroperations.cc:218
Scroom
Definition: assertions.hh:14
ThreadPool
Definition: threadpool.hh:46
CompressedTile::getTileSync
Tile::Ptr getTileSync()
Definition: compressedtile.cc:55
Layer::fetchData
void fetchData(SourcePresentation::Ptr sp, const ThreadPool::WeakQueue::Ptr &queue, std::function< void()> on_finished)
Definition: layer.cc:148
Tile
Definition: tile.hh:18
Scroom::MemoryBlocks::RawPageData::Ptr
boost::shared_ptr< uint8_t > Ptr
Definition: blockallocator.hh:23
Scroom::Detail::ThreadPool
Definition: async-deleter.hh:21
short_timeout
const millisec short_timeout(250)
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(sample.expectedColors, originalColormap->colors.size())
CompressedTile::getConstTileAsync
ConstTile::Ptr getConstTileAsync()
Definition: compressedtile.cc:84
ConstTile::Ptr
boost::shared_ptr< ConstTile > Ptr
Definition: tile.hh:47
Layer::height
int height
Definition: tiledbitmaplayer.hh:252
CompressedTile::getConstTileSync
ConstTile::Ptr getConstTileSync()
Definition: compressedtile.cc:44
Sequentially
ThreadPool::Ptr Sequentially()
Definition: threadpoolimpl.cc:459
SourcePresentation::Ptr
boost::shared_ptr< SourcePresentation > Ptr
Definition: tiledbitmapinterface.hh:198
Layer::outOfBounds
CompressedTile::Ptr outOfBounds
Definition: tiledbitmaplayer.hh:256
LayerCoordinator::LayerCoordinator
LayerCoordinator(const LayerCoordinator &)=delete
destroy
boost::function< void()> destroy(boost::shared_ptr< void > p)
Definition: helpers.cc:31
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(try_P)
Definition: semaphore-tests.cc:37
Scroom::Semaphore::try_P
bool try_P()
Definition: semaphore.hh:48
Layer::getTileLine
CompressedTileLine & getTileLine(int j)
Definition: layer.cc:138
Scroom::MemoryBlobs::PageProvider::create
static Ptr create(size_t blockCount, size_t blockSize)
Definition: memoryblobs.cc:37
TSI_LOADING_SYNCHRONOUSLY
@ TSI_LOADING_SYNCHRONOUSLY
Definition: tiledbitmaplayer.hh:39
CompressedTile::do_load
ConstTile::Ptr do_load()
Definition: compressedtile.cc:130
OperationsCMYK8::cache
Scroom::Utils::Stuff cache(const ConstTile::Ptr &tile) override
Definition: cmyklayeroperations.cc:228
require
#define require(expr)
Definition: assertions.hh:28
QueueJumper::create
static Ptr create()
QueueJumper.
Definition: threadpoolimpl.cc:419
TileViewState::Ptr
boost::shared_ptr< TileViewState > Ptr
Definition: tileviewstate.hh:27
CompressedTile::open
void open(ViewInterface::WeakPtr vi) override
Definition: compressedtile.cc:279
Scroom::Semaphore::P
void P()
Definition: semaphore.hh:38
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(queueimpl_jobs_get_executed)
Definition: threadpool-queueimpl-tests.cc:35
Layer::lineOutOfBounds
CompressedTileLine lineOutOfBounds
Definition: tiledbitmaplayer.hh:257
Scroom::Bitmap::BitmapSurface::create
static Ptr create(int width, int height, cairo_format_t format)
Definition: bitmap-helpers.cc:13
Layer::pageProvider
Scroom::MemoryBlobs::PageProvider::Ptr pageProvider
Definition: tiledbitmaplayer.hh:258
OperationsCMYK16::cache
Scroom::Utils::Stuff cache(const ConstTile::Ptr &tile) override
Definition: cmyklayeroperations.cc:135
PipetteCommonOperationsCMYK::Ptr
boost::shared_ptr< PipetteCommonOperationsCMYK > Ptr
Definition: layeroperations.hh:41
DataFetcher::verTileCount
int verTileCount
Definition: layer.cc:48
A::A
A(Semaphore *s_)
Definition: threadpool-tests.cc:42
DataFetcher::layer
Layer::Ptr layer
Definition: layer.cc:45
OperationsCMYK16::OperationsCMYK16
OperationsCMYK16()
Definition: cmyklayeroperations.cc:125
TILE_LOADED
@ TILE_LOADED
Definition: tiledbitmapinterface.hh:36
LayerCoordinator::sourceTiles
std::map< CompressedTile::Ptr, std::pair< int, int > > sourceTiles
Definition: layercoordinator.hh:26
Layer::horTileCount
int horTileCount
Definition: tiledbitmaplayer.hh:253
Layer::depth
int depth
Definition: tiledbitmaplayer.hh:250
ThreadPool::Queue::create
static Ptr create()
ThreadPool::Queue.
Definition: threadpoolimpl.cc:377
bitmap-helpers.hh
current
static unsigned int current
Definition: measure-framerate-callbacks.cc:17
OperationsCMYK16::getBpp
int getBpp() override
Definition: cmyklayeroperations.cc:130
B::create
static Ptr create(Semaphore *s, R result)
Definition: threadpool-tests.cc:74
OperationsCMYK4::create
static Ptr create()
Definition: cmyklayeroperations.cc:306
Scroom::Utils::ceil
Point< T > ceil(Point< T > p)
Definition: point.hh:228
OperationsCMYK4::reduce
void reduce(Tile::Ptr target, ConstTile::Ptr source, int x, int y) override
Definition: cmyklayeroperations.cc:370
CompressedTile::stateData
boost::mutex stateData
Definition: tiledbitmaplayer.hh:122
QueueJumper::Ptr
boost::shared_ptr< QueueJumper > Ptr
Definition: threadpool.hh:537
layeroperations.hh
LayerCoordinator::mut
boost::mutex mut
Definition: layercoordinator.hh:29
CompressedTile::depth
const int depth
Definition: tiledbitmaplayer.hh:111
long_timeout
const millisec long_timeout(2000)
TileState
TileState
Definition: tiledbitmapinterface.hh:32
short_timeout
const millisec short_timeout(250)
Layer::getTile
CompressedTile::Ptr getTile(int i, int j)
Definition: layer.cc:128
CompressedTile::provider
Scroom::MemoryBlobs::PageProvider::Ptr provider
Definition: tiledbitmaplayer.hh:120
A::operator()
void operator()()
Definition: threadpool-tests.cc:47
TILE_OUT_OF_BOUNDS
@ TILE_OUT_OF_BOUNDS
Definition: tiledbitmapinterface.hh:37
long_timeout
const millisec long_timeout(2000)
B::Ptr
boost::shared_ptr< B< R > > Ptr
Definition: threadpool-tests.cc:60
A::Ptr
boost::shared_ptr< A > Ptr
Definition: boost-bind.cc:27
OperationsCMYK32::getBpp
int getBpp() override
Definition: cmyklayeroperations.cc:37
CpuBound
ThreadPool::Ptr CpuBound()
Definition: threadpoolimpl.cc:452
Layer::registerObserver
Scroom::Bookkeeping::Token registerObserver(const TileInitialisationObserver::Ptr &observer)
Definition: layer.cc:110
memoryblobs.hh
Scroom::Semaphore
Definition: semaphore.hh:15
long_timeout
const millisec long_timeout(2000)
ViewInterface::WeakPtr
boost::weak_ptr< ViewInterface > WeakPtr
Definition: viewinterface.hh:194
anonymous_namespace{cmyklayeroperations.cc}::shared_malloc
boost::shared_ptr< unsigned char > shared_malloc(size_t size)
Definition: cmyklayeroperations.cc:24
OperationsCMYK16::reduce
void reduce(Tile::Ptr target, ConstTile::Ptr source, int x, int y) override
Definition: cmyklayeroperations.cc:165
CompressedTile::CompressedTile
CompressedTile(int depth, int x, int y, int bpp, const Scroom::MemoryBlobs::PageProvider::Ptr &provider, TileStateInternal state)
CompressedTile.
Definition: compressedtile.cc:21
LayerCoordinator::create
static Ptr create(CompressedTile::Ptr targetTile, LayerOperations::Ptr lo)
Definition: layercoordinator.cc:19
Scroom::Detail::ThreadPool::QueueLock
Definition: queue.hh:63
LayerCoordinator::~LayerCoordinator
~LayerCoordinator() override
Definition: layercoordinator.cc:31
B::result
R result
Definition: threadpool-tests.cc:57
ThreadPool::create
static ThreadPool::Ptr create(bool completeAllJobsBeforeDestruction=false)
Definition: threadpoolimpl.cc:228
OperationsCMYK32::create
static Ptr create()
Definition: cmyklayeroperations.cc:30
layercoordinator.hh
CompressedTile::notifyObservers
void notifyObservers(const ConstTile::Ptr &tile)
Definition: compressedtile.cc:271
DataFetcher::sp
SourcePresentation::Ptr sp
Definition: layer.cc:50
no_op
R no_op(Semaphore *s, R result)
Definition: threadpool-tests.cc:78
TSI_UNINITIALIZED
@ TSI_UNINITIALIZED
Definition: tiledbitmaplayer.hh:36
tiledbitmaplayer.hh
tiledbitmapinterface.hh
Scroom::Detail::ThreadPool::QueueImpl::Ptr
boost::shared_ptr< QueueImpl > Ptr
Definition: queue.hh:25
PRIO_HIGH
@ PRIO_HIGH
Definition: threadpool.hh:28
Scroom::Utils::Base
Definition: utilities.hh:30
test_count_equals
void test_count_equals(Semaphore *s, int i)
Definition: semaphore-tests.cc:24
tile.hh
stuff.hh
BOOST_REQUIRE
BOOST_REQUIRE(originalColormap)
CompressedTile::state
TileStateInternal state
Definition: tiledbitmaplayer.hh:117
Tile::Ptr
boost::shared_ptr< Tile > Ptr
Definition: tile.hh:21
OperationsCMYK32::cache
Scroom::Utils::Stuff cache(const ConstTile::Ptr &tile) override
Definition: cmyklayeroperations.cc:42
OperationsCMYK8::getBpp
int getBpp() override
Definition: cmyklayeroperations.cc:223
LayerCoordinator::operator=
LayerCoordinator operator=(const LayerCoordinator &)=delete
pass
boost::function< void()> pass(Semaphore *s)
Definition: helpers.cc:27
CompressedTile::bpp
const int bpp
Definition: tiledbitmaplayer.hh:114
LayerCoordinator::tileFinished
void tileFinished(const CompressedTile::Ptr &tile) override
TileInitialisationObserver.
Definition: layercoordinator.cc:49
CompressedTile::observerAdded
void observerAdded(TileInitialisationObserver::Ptr const &observer, Scroom::Bookkeeping::Token const &token) override
Definition: compressedtile.cc:208
Scroom::Utils::Stuff
boost::shared_ptr< void > Stuff
Definition: stuff.hh:18
OperationsCMYK4::cache
Scroom::Utils::Stuff cache(const ConstTile::Ptr &tile) override
Definition: cmyklayeroperations.cc:322
OperationsCMYK32::OperationsCMYK32
OperationsCMYK32()
Definition: cmyklayeroperations.cc:32
Scroom::Utils::Observable
Definition: observable.hh:24
A::create
static Ptr create(int &i)
Definition: boost-bind.cc:38
Scroom::MemoryBlobs
Definition: memoryblobs.hh:23
Layer::open
void open(ViewInterface::WeakPtr vi) override
Definition: layer.cc:157
viewinterface.hh
Layer::getVerTileCount
int getVerTileCount() const
Definition: layer.cc:126
DataFetcher::currentRow
int currentRow
Definition: layer.cc:49
TileInitialisationObserver::tileCreated
virtual void tileCreated(const boost::shared_ptr< CompressedTile > &tile)
Definition: compressedtile.cc:291
TSI_OUT_OF_BOUNDS
@ TSI_OUT_OF_BOUNDS
Definition: tiledbitmaplayer.hh:38
TILE_UNINITIALIZED
@ TILE_UNINITIALIZED
Definition: tiledbitmapinterface.hh:34
LayerCoordinator::Ptr
boost::shared_ptr< LayerCoordinator > Ptr
Definition: layercoordinator.hh:33
CompressedTile::data
Scroom::MemoryBlobs::Blob::Ptr data
Definition: tiledbitmaplayer.hh:121
OperationsCMYK4::OperationsCMYK4
OperationsCMYK4()
Definition: cmyklayeroperations.cc:308
A
Definition: boost-bind.cc:21
DataFetcher::on_finished
std::function< void()> on_finished
Definition: layer.cc:53
b
static void b(const B::Ptr &)
Definition: gtkhelper-tests.cc:32
LayerCoordinator::lo
LayerOperations::Ptr lo
Definition: layercoordinator.hh:28
function-additor.hh
CompressedTile::Ptr
boost::shared_ptr< CompressedTile > Ptr
Definition: tiledbitmaplayer.hh:108
TILESIZE
#define TILESIZE
Definition: tiledbitmaplayer.hh:28
TileViewState::create
static Ptr create(const boost::shared_ptr< CompressedTile > &parent)
Definition: tileviewstate.cc:27
DataFetcher::operator()
void operator()()
Definition: layer.cc:210
LayerOperations::Ptr
boost::shared_ptr< LayerOperations > Ptr
Definition: tiledbitmapinterface.hh:53
LayerCoordinator::targetTile
CompressedTile::Ptr targetTile
Definition: layercoordinator.hh:24
Scroom::MemoryBlobs::Blob
Definition: memoryblobs.hh:75
Layer::create
static Ptr create(int depth, int layerWidth, int layerHeight, int bpp, Scroom::MemoryBlobs::PageProvider::Ptr provider)
Definition: layer.cc:98
ThreadPool::add
ThreadPtr add()
Definition: threadpoolimpl.cc:238
A::s
Semaphore * s
Definition: threadpool-tests.cc:37
OperationsCMYK8::reduce
void reduce(Tile::Ptr target, ConstTile::Ptr source, int x, int y) override
Definition: cmyklayeroperations.cc:259
CompressedTile::tileData
boost::mutex tileData
Definition: tiledbitmaplayer.hh:123
CompressedTileLine
std::vector< CompressedTile::Ptr > CompressedTileLine
Definition: tiledbitmaplayer.hh:237
TSI_LOADING_ASYNCHRONOUSLY
@ TSI_LOADING_ASYNCHRONOUSLY
Definition: tiledbitmaplayer.hh:40
short_timeout
const millisec short_timeout(250)
ThreadPool::Queue::WeakPtr
boost::weak_ptr< Queue > WeakPtr
Definition: threadpool.hh:83
DATAFETCH_PRIO
#define DATAFETCH_PRIO
Definition: local.hh:11
Scroom::Semaphore::V
void V()
Definition: semaphore.hh:77
DataFetcher
Definition: layer.cc:42
queue.hh
PRIO_NORMAL
@ PRIO_NORMAL
Definition: threadpool.hh:29
OperationsCMYK4::getBpp
int getBpp() override
Definition: cmyklayeroperations.cc:313
ThreadPool::schedule
void schedule(boost::function< void()> const &fn, int priority=defaultPriority, const Queue::Ptr &queue=defaultQueue())
Definition: threadpoolimpl.cc:342
CompressedTile::y
const int y
Definition: tiledbitmaplayer.hh:113
Scroom::Bookkeeping::Token
Definition: bookkeeping.hh:37
has_at_least_n_threads
bool has_at_least_n_threads(ThreadPool *pool, int count_)
Definition: threadpool-tests.cc:86
TileInitialisationObserver
Definition: tiledbitmaplayer.hh:49
unused.hh
CompressedTile::getViewState
boost::shared_ptr< TileViewState > getViewState(const ViewInterface::WeakPtr &vi)
Definition: compressedtile.cc:163
TSI_NORMAL
@ TSI_NORMAL
Definition: tiledbitmaplayer.hh:37
B::B
B(Semaphore *s_, R result_)
Definition: threadpool-tests.cc:62
DataFetcher::height
int height
Definition: layer.cc:46
LOAD_PRIO
#define LOAD_PRIO
Definition: local.hh:10
CompressedTile::reportFinished
void reportFinished()
Definition: compressedtile.cc:116
tileviewstate.hh
Scroom::Bookkeeping::Token::add
void add(const Stuff &s) const
Definition: bookkeepingimpl.hh:191
CompressedTile::queue
ThreadPool::Queue::WeakPtr queue
Definition: tiledbitmaplayer.hh:125
semaphore.hh
B::s
Semaphore * s
Definition: threadpool-tests.cc:56
REDUCE_PRIO
#define REDUCE_PRIO
Definition: local.hh:12
DataFetcher::queue
ThreadPool::WeakQueue::Ptr queue
Definition: layer.cc:52
CompressedTile::initialize
Tile::Ptr initialize()
Definition: compressedtile.cc:90
ConstTile
Definition: tile.hh:44
threadpoolimpl.hh
create
void create(NewPresentationInterface *interface)
Definition: loader.cc:175
OperationsCMYK8::create
static Ptr create()
Definition: cmyklayeroperations.cc:216
Layer::Layer
Layer(int depth, int layerWidth, int layerHeight, int bpp, Scroom::MemoryBlobs::PageProvider::Ptr provider)
Layer.
Definition: layer.cc:70
LayerCoordinator::reduceSourceTile
void reduceSourceTile(const CompressedTile::Ptr &tile, ConstTile::Ptr const &tileData)
Helpers.
Definition: layercoordinator.cc:61
B
Definition: threadpool-tests.cc:53