aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar Yuqian Li <liyuqian@google.com>2017-09-01 14:24:40 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-01 18:47:59 +0000
commitba0ce4b4c6a0aa9ee81fc85fd2407788dae9c1da (patch)
tree911550803de0c693b13a0419406762f1fb1fe969 /samplecode
parentda65a0489ae429f026bad32c9a0ef2010f40e175 (diff)
Let SampleApp provide the thread pool
Otherwise, creating a new thread pool each frame could be a major bottleneck. Somehow, creating new thread pool each frame is good for measuring FPS, so that behavior is maintained when fMeasureFPS is true. I'm still doing experiments with my own schedulers. Once they get more stable, I'll probably apply their changes to the SkExecutor. Bug: skia: Change-Id: Iead96034e0d0abdebb5069dec41215990f71f693 Reviewed-on: https://skia-review.googlesource.com/41845 Commit-Queue: Yuqian Li <liyuqian@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleApp.cpp5
-rw-r--r--samplecode/SampleApp.h11
2 files changed, 13 insertions, 3 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index faceea47b1..fcc7feec96 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -1096,7 +1096,10 @@ void SampleWindow::draw(SkCanvas* canvas) {
std::unique_ptr<SkThreadedBMPDevice> tDev;
std::unique_ptr<SkCanvas> tCanvas;
if (fTiles > 0 && fDeviceType == kRaster_DeviceType) {
- tDev.reset(new SkThreadedBMPDevice(this->getBitmap(), fTiles, fThreads));
+ // Temporary hack: let the device create/destroy the thread pool between each frame somehow
+ // makes it faster when we draw the same path 100 times when fMeasureFPS is true.
+ SkExecutor* executor = fMeasureFPS ? nullptr : fExecutor.get();
+ tDev.reset(new SkThreadedBMPDevice(this->getBitmap(), fTiles, fThreads, executor));
tCanvas.reset(new SkCanvas(tDev.get()));
canvas = tCanvas.get();
}
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index 6ddb5c5a0d..52f041ac75 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -8,6 +8,7 @@
#ifndef SampleApp_DEFINED
#define SampleApp_DEFINED
+#include "SkExecutor.h"
#include "SkOSMenu.h"
#include "SkPath.h"
#include "SkPicture.h"
@@ -158,9 +159,10 @@ public:
int getColorConfigIndex() const { return fColorConfigIndex; }
int getTiles() const { return fTiles; }
- void setTiles(int tiles) { fTiles = tiles; }
+ void setTiles(int tiles) { fTiles = tiles; this->resetExecutor(); }
int getThreads() const { return fThreads; }
- void setThreads(int threads) { fThreads = threads; }
+ void setThreads(int threads) { fThreads = threads; this->resetExecutor(); }
+
protected:
void onDraw(SkCanvas* canvas) override;
@@ -250,6 +252,7 @@ private:
int fTiles = 0;
int fThreads = 0;
+ std::unique_ptr<SkExecutor> fExecutor;
void loadView(SkView*);
void updateTitle();
@@ -267,6 +270,10 @@ private:
SkSize tileSize() const;
bool sendAnimatePulse();
+ void resetExecutor() {
+ fExecutor = SkExecutor::MakeFIFOThreadPool(fThreads == 0 ? fTiles : fThreads);
+ }
+
typedef SkOSWindow INHERITED;
};