aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkThreadedBMPDevice.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkThreadedBMPDevice.h')
-rw-r--r--src/core/SkThreadedBMPDevice.h70
1 files changed, 32 insertions, 38 deletions
diff --git a/src/core/SkThreadedBMPDevice.h b/src/core/SkThreadedBMPDevice.h
index aa2276bd27..f0cb531920 100644
--- a/src/core/SkThreadedBMPDevice.h
+++ b/src/core/SkThreadedBMPDevice.h
@@ -8,34 +8,10 @@
#ifndef SkThreadedBMPDevice_DEFINED
#define SkThreadedBMPDevice_DEFINED
-#include "SkTaskGroup.h"
-#include "SkDraw.h"
#include "SkBitmapDevice.h"
+#include "SkDraw.h"
+#include "SkTaskGroup2D.h"
-class TiledDrawScheduler {
-public:
- using WorkFunc = std::function<void(int, int)>;
-
- virtual ~TiledDrawScheduler() {}
-
- virtual void signal() = 0; // signal that one more draw is available for all tiles
-
- // Tell scheduler that no more draw calls will be added (no signal will be called).
- virtual void finish() = 0;
-
- // Handle the next draw available. This method will block until
- // (1) the next draw is finished, or
- // (2) the finish is called
- // The method will return true for case (1) and false for case (2).
- // When there's no draw available and we haven't called finish, we will just wait.
- // In many cases, the parameter tileIndex specifies the tile that the next draw should happen.
- // However, for some schedulers, that tileIndex may only be a hint and the scheduler is free
- // to find another tile to draw. In that case, tileIndex will be changed to the actual tileIndex
- // where the draw happens.
- virtual bool next(int& tileIndex) = 0;
-};
-
-///////////////////////////////////////////////////////////////////////////////
class SkThreadedBMPDevice : public SkBitmapDevice {
public:
// When threads = 0, we make fThreadCnt = tiles. Otherwise fThreadCnt = threads.
@@ -43,7 +19,7 @@ public:
SkThreadedBMPDevice(const SkBitmap& bitmap, int tiles, int threads = 0,
SkExecutor* executor = nullptr);
- ~SkThreadedBMPDevice() override { finishThreads(); }
+ ~SkThreadedBMPDevice() override { fQueue.finish(); }
protected:
void drawPaint(const SkPaint& paint) override;
@@ -67,23 +43,44 @@ protected:
void flush() override;
private:
+ struct DrawState;
+
struct DrawElement {
SkIRect fDrawBounds;
std::function<void(const SkIRect& threadBounds)> fDrawFn;
};
- struct DrawState;
+ class DrawQueue {
+ public:
+ static constexpr int MAX_QUEUE_SIZE = 100000;
+
+ DrawQueue(SkThreadedBMPDevice* device) : fDevice(device) {}
+ void reset();
+
+ // For ~SkThreadedBMPDevice() to shutdown tasks, we use this instead of reset because reset
+ // will start new tasks.
+ void finish() { fTasks->finish(); }
+
+ SK_ALWAYS_INLINE void push(DrawElement&& element) {
+ if (fSize == MAX_QUEUE_SIZE) {
+ this->reset();
+ }
+ SkASSERT(fSize < MAX_QUEUE_SIZE);
+ fElements[fSize++] = std::move(element);
+ fTasks->addColumn();
+ }
+
+ private:
+ SkThreadedBMPDevice* fDevice;
+ std::unique_ptr<SkTaskGroup2D> fTasks;
+ DrawElement fElements[MAX_QUEUE_SIZE];
+ int fSize;
+ };
SkIRect transformDrawBounds(const SkRect& drawBounds) const;
- void startThreads();
- void finishThreads();
-
- static constexpr int MAX_QUEUE_SIZE = 100000;
-
const int fTileCnt;
const int fThreadCnt;
- std::unique_ptr<TiledDrawScheduler> fScheduler;
SkTArray<SkIRect> fTileBounds;
/**
@@ -95,10 +92,7 @@ private:
SkExecutor* fExecutor = nullptr;
std::unique_ptr<SkExecutor> fInternalExecutor;
- std::unique_ptr<SkTaskGroup> fTaskGroup; // generated from fExecutor
-
- DrawElement fQueue[MAX_QUEUE_SIZE];
- int fQueueSize;
+ DrawQueue fQueue;
typedef SkBitmapDevice INHERITED;
};