15#include <QMutexLocker>
28 bool *shouldUseCache)
override
30 Q_UNUSED(hasDabInCache);
35 *shouldUseCache =
false;
97 : m_d(new
Private(cs, resourcesFactory))
107 if (startSearchIndex < 0) {
108 startSearchIndex =
jobs.size() - 1;
118 for (
int i = startSearchIndex; i >= 0; i--) {
128 qreal opacity, qreal flow)
130 QMutexLocker l(&
m_d->mutex);
132 const int seqNo =
m_d->nextSeqNoToUse++;
140 const int lastDabJobIndex =
m_d->lastDabJobInQueue;
144 bool shouldUseCache =
false;
145 m_d->cacheInterface->getDabType(lastDabJobIndex >= 0, resources, request, &job->generationInfo, &shouldUseCache);
147 m_d->putResourcesToCache(resources);
165 job->originalDevice =
m_d->jobs[lastDabJobIndex]->originalDevice;
168 job->originalDevice =
m_d->jobs[lastDabJobIndex]->originalDevice;
169 job->postprocessedDevice =
m_d->jobs[lastDabJobIndex]->postprocessedDevice;
170 m_d->avgExecutionTime(0);
175 m_d->jobs.append(job);
183 m_d->lastDabJobInQueue =
m_d->jobs.size() - 1;
184 m_d->cleanPaintedDabs();
195 QMutexLocker l(&
m_d->mutex);
203 std::lower_bound(
m_d->jobs.begin(),
m_d->jobs.end(), seqNo,
217 for (
auto it = finishedJobIt + 1; it !=
m_d->jobs.end(); ++it) {
229 j->originalDevice = finishedJob->originalDevice;
230 j->postprocessedDevice = finishedJob->postprocessedDevice;
232 m_d->avgExecutionTime(0);
236 j->originalDevice = finishedJob->originalDevice;
243 if (usecsTime >= 0) {
244 m_d->avgExecutionTime(usecsTime);
247 return dependentJobs;
252 const int nextToBePainted = lastPaintedJob + 1;
253 const int lastSourceJob = calculateLastDabJobIndex(qMin(nextToBePainted, jobs.size() - 1));
255 if (lastPaintedJob >= 0) {
256 int numRemovedJobs = 0;
257 int numRemovedJobsBeforeLastSource = 0;
259 auto it = jobs.begin();
260 for (
int i = 0; i <= lastPaintedJob; i++) {
269 if (i < lastDabJobInQueue) {
270 numRemovedJobsBeforeLastSource++;
280 lastPaintedJob -= numRemovedJobs;
281 lastDabJobInQueue -= numRemovedJobsBeforeLastSource;
289 QMutexLocker l(&
m_d->mutex);
292 if (
m_d->jobs.isEmpty())
return renderedDabs;
295 m_d->jobs.isEmpty() ||
298 const int copyJobAfterInclusive =
299 returnMutableDabs && !
m_d->dabsHaveSeparateOriginal() ?
300 m_d->lastDabJobInQueue :
301 std::numeric_limits<int>::max();
303 if (oneTimeLimit < 0) {
304 oneTimeLimit = std::numeric_limits<int>::max();
307 for (
int i = 0; i <
m_d->jobs.size() && oneTimeLimit > 0; i++, oneTimeLimit--) {
312 if (i <= m_d->lastPaintedJob)
continue;
317 if (i >= copyJobAfterInclusive) {
321 dab.
device = resultDevice;
322 dab.
offset = j->dstDabOffset();
330 renderedDabs.append(dab);
332 m_d->lastPaintedJob = i;
335 m_d->cleanPaintedDabs();
338 *someDabsLeft =
m_d->hasPreparedDabsImpl();
346 const int nextToBePainted = lastPaintedJob + 1;
349 nextToBePainted >= 0 &&
350 nextToBePainted < jobs.size() &&
357 QMutexLocker l(&
m_d->mutex);
358 return m_d->hasPreparedDabsImpl();
363 m_d->cacheInterface.reset(interface);
377 QMutexLocker l(&
m_d->mutex);
378 return m_d->avgExecutionTime.rollingMean() / 1000.0;
383 QMutexLocker l(&
m_d->mutex);
384 return qRound(
m_d->avgDabSize.rollingMean());
391 const bool result = cacheInterface->hasSeparateOriginal(resources);
403 if (!cachedResources.isEmpty()) {
404 resources = cachedResources.takeLast();
406 resources = resourcesFactory();
414 cachedResources << resources;
420 QMutexLocker l(&
m_d->mutex);
421 return m_d->fetchResourcesFromCache();
426 QMutexLocker l(&
m_d->mutex);
427 m_d->putResourcesToCache(resources);
432 QMutexLocker l(&
m_d->mutex);
434 return m_d->jobs.size();
QSharedPointer< KisDabRenderingJob > KisDabRenderingJobSP
QList< KisRenderedDab > takeReadyDabs(bool returnMutableDabs=false, int oneTimeLimit=-1, bool *someDabsLeft=0)
void setCacheInterface(CacheInterface *interface)
KisDabCacheUtils::DabRenderingResources * fetchResourcesFromCache()
KisDabRenderingJobSP addDab(const KisDabCacheUtils::DabRequestInfo &request, qreal opacity, qreal flow)
const QScopedPointer< Private > m_d
int averageDabSize() const
KisFixedPaintDeviceSP fetchCachedPaintDevice()
KisDabRenderingQueue(const KoColorSpace *cs, KisDabCacheUtils::ResourcesFactory resourcesFactory)
QList< KisDabRenderingJobSP > notifyJobFinished(int seqNo, int usecsTime=-1)
bool hasPreparedDabs() const
int testingGetQueueSize() const
void putResourcesToCache(KisDabCacheUtils::DabRenderingResources *resources)
qreal averageExecutionTime() const
static qreal blendAverageOpacity(qreal opacity, qreal averageOpacity)
A simple wrapper class that hides boost includes from QtCreator preventing it from crashing when one ...
#define KIS_SAFE_ASSERT_RECOVER_BREAK(cond)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define KIS_ASSERT_RECOVER_NOOP(cond)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
auto maxDimension(Size size) -> decltype(size.width())
std::function< DabRenderingResources *()> ResourcesFactory
auto mem_less(MemTypeNoRef Class::*ptr, MemType &&value)
mem_less is an unary functor that compares a member of the object to a given value
virtual void syncResourcesToSeqNo(int seqNo, const KisPaintInformation &info)
void getDabType(bool hasDabInCache, KisDabCacheUtils::DabRenderingResources *resources, const KisDabCacheUtils::DabRequestInfo &request, KisDabCacheUtils::DabGenerationInfo *di, bool *shouldUseCache) override
bool hasSeparateOriginal(KisDabCacheUtils::DabRenderingResources *resources) const override
KisDabCacheUtils::DabRenderingResources * fetchResourcesFromCache()
Private(const KoColorSpace *_colorSpace, KisDabCacheUtils::ResourcesFactory _resourcesFactory)
const KoColorSpace * colorSpace
QList< KisDabRenderingJobSP > jobs
KisRollingMeanAccumulatorWrapper avgDabSize
QList< KisDabCacheUtils::DabRenderingResources * > cachedResources
int calculateLastDabJobIndex(int startSearchIndex)
KisRollingMeanAccumulatorWrapper avgExecutionTime
KisDabCacheUtils::ResourcesFactory resourcesFactory
bool hasPreparedDabsImpl() const
QSharedPointer< KisOptimizedByteArray::MemoryAllocator > paintDeviceAllocator
QScopedPointer< CacheInterface > cacheInterface
bool dabsHaveSeparateOriginal()
void putResourcesToCache(KisDabCacheUtils::DabRenderingResources *resources)
KisFixedPaintDeviceSP device