Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: dm/DMQuiltTask.cpp

Issue 371853005: Move threadpool code from include/utils to tools/threadpool. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: gyp Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | dm/DMTask.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "DMQuiltTask.h" 1 #include "DMQuiltTask.h"
2 #include "DMUtil.h" 2 #include "DMUtil.h"
3 #include "DMWriteTask.h" 3 #include "DMWriteTask.h"
4 4
5 #include "SkCommandLineFlags.h" 5 #include "SkCommandLineFlags.h"
6 #include "SkPicture.h" 6 #include "SkPicture.h"
7 #include "SkThreadPool.h" 7 #include "ThreadPool.h"
8 8
9 DEFINE_bool(quilt, true, "If true, draw into a quilt of small tiles and compare. "); 9 DEFINE_bool(quilt, true, "If true, draw into a quilt of small tiles and compare. ");
10 DEFINE_int32(quiltTile, 16, "Dimension of (square) quilt tile."); 10 DEFINE_int32(quiltTile, 16, "Dimension of (square) quilt tile.");
11 DEFINE_bool(quiltThreaded, false, "If true, draw quilt tiles with multiple threa ds."); 11 DEFINE_bool(quiltThreaded, false, "If true, draw quilt tiles with multiple threa ds.");
12 12
13 namespace DM { 13 namespace DM {
14 14
15 QuiltTask::QuiltTask(const Task& parent, skiagm::GM* gm, SkBitmap reference) 15 QuiltTask::QuiltTask(const Task& parent, skiagm::GM* gm, SkBitmap reference)
16 : CpuTask(parent) 16 : CpuTask(parent)
17 , fName(UnderJoin(parent.name().c_str(), "quilt")) 17 , fName(UnderJoin(parent.name().c_str(), "quilt"))
18 , fGM(gm) 18 , fGM(gm)
19 , fReference(reference) 19 , fReference(reference)
20 {} 20 {}
21 21
22 static int tiles_needed(int fullDimension, int tileDimension) { 22 static int tiles_needed(int fullDimension, int tileDimension) {
23 return (fullDimension + tileDimension - 1) / tileDimension; 23 return (fullDimension + tileDimension - 1) / tileDimension;
24 } 24 }
25 25
26 class Tile : public SkRunnable { 26 class Tile : public Runnable {
27 public: 27 public:
28 Tile(int x, int y, SkColorType colorType, 28 Tile(int x, int y, SkColorType colorType,
29 const SkPicture& picture, SkCanvas* canvas, SkMutex* mutex) 29 const SkPicture& picture, SkCanvas* canvas, SkMutex* mutex)
30 : fX(x) 30 : fX(x)
31 , fY(y) 31 , fY(y)
32 , fColorType(colorType) 32 , fColorType(colorType)
33 , fPicture(picture) 33 , fPicture(picture)
34 , fCanvas(canvas) 34 , fCanvas(canvas)
35 , fMutex(mutex) {} 35 , fMutex(mutex) {}
36 36
(...skipping 26 matching lines...) Expand all
63 }; 63 };
64 64
65 void QuiltTask::draw() { 65 void QuiltTask::draw() {
66 SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get())); 66 SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get()));
67 67
68 SkBitmap full; 68 SkBitmap full;
69 AllocatePixels(fReference, &full); 69 AllocatePixels(fReference, &full);
70 SkCanvas fullCanvas(full); 70 SkCanvas fullCanvas(full);
71 SkMutex mutex; // Guards fullCanvas. 71 SkMutex mutex; // Guards fullCanvas.
72 72
73 SkThreadPool pool(FLAGS_quiltThreaded ? SkThreadPool::kThreadPerCore : 0); 73 ThreadPool pool(FLAGS_quiltThreaded ? ThreadPool::kThreadPerCore : 0);
74 74
75 for (int y = 0; y < tiles_needed(full.height(), FLAGS_quiltTile); y++) { 75 for (int y = 0; y < tiles_needed(full.height(), FLAGS_quiltTile); y++) {
76 for (int x = 0; x < tiles_needed(full.width(), FLAGS_quiltTile); x++) { 76 for (int x = 0; x < tiles_needed(full.width(), FLAGS_quiltTile); x++) {
77 // Deletes itself when done. 77 // Deletes itself when done.
78 pool.add(new Tile(x, y, fReference.colorType(), *recorded, &fullCanv as, &mutex)); 78 pool.add(new Tile(x, y, fReference.colorType(), *recorded, &fullCanv as, &mutex));
79 } 79 }
80 } 80 }
81 81
82 pool.wait(); 82 pool.wait();
83 fullCanvas.flush(); 83 fullCanvas.flush();
84 84
85 if (!BitmapsEqual(full, fReference)) { 85 if (!BitmapsEqual(full, fReference)) {
86 this->fail(); 86 this->fail();
87 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full))); 87 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full)));
88 } 88 }
89 } 89 }
90 90
91 bool QuiltTask::shouldSkip() const { 91 bool QuiltTask::shouldSkip() const {
92 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { 92 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
93 return true; 93 return true;
94 } 94 }
95 if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) { 95 if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) {
96 return true; 96 return true;
97 } 97 }
98 return !FLAGS_quilt; 98 return !FLAGS_quilt;
99 } 99 }
100 100
101 } // namespace DM 101 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | dm/DMTask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698