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

Side by Side Diff: dm/DMQuiltTask.cpp

Issue 689673003: SkTaskGroup::batch(fn, args, N) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pun fn pointers Created 6 years, 1 month 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 | include/core/SkMultiPictureDraw.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 "SkBBHFactory.h" 5 #include "SkBBHFactory.h"
6 #include "SkCommandLineFlags.h" 6 #include "SkCommandLineFlags.h"
7 #include "SkPicture.h" 7 #include "SkPicture.h"
8 #include "SkTaskGroup.h" 8 #include "SkTaskGroup.h"
9 9
10 DEFINE_bool(quilt, true, "If true, draw GM via a picture into a quilt of small t iles and compare."); 10 DEFINE_bool(quilt, true, "If true, draw GM via a picture into a quilt of small t iles and compare.");
11 DEFINE_int32(quiltTile, 256, "Dimension of (square) quilt tile."); 11 DEFINE_int32(quiltTile, 256, "Dimension of (square) quilt tile.");
12 12
13 namespace DM { 13 namespace DM {
14 14
15 static const char* kBBHs[] = { "nobbh", "rtree", "tilegrid" }; 15 static const char* kBBHs[] = { "nobbh", "rtree", "tilegrid" };
16 QuiltTask::QuiltTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, Qui ltTask::BBH bbh) 16 QuiltTask::QuiltTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, Qui ltTask::BBH bbh)
17 : CpuTask(parent) 17 : CpuTask(parent)
18 , fBBH(bbh) 18 , fBBH(bbh)
19 , fName(UnderJoin(parent.name().c_str(), kBBHs[bbh])) 19 , fName(UnderJoin(parent.name().c_str(), kBBHs[bbh]))
20 , fGM(gm) 20 , fGM(gm)
21 , fReference(reference) 21 , fReference(reference)
22 {} 22 {}
23 23
24 static int tiles_needed(int fullDimension, int tileDimension) { 24 static int tiles_needed(int fullDimension, int tileDimension) {
25 return (fullDimension + tileDimension - 1) / tileDimension; 25 return (fullDimension + tileDimension - 1) / tileDimension;
26 } 26 }
27 27
28 class Tile : public SkRunnable { 28 struct DrawTileArgs {
29 public: 29 int x, y;
30 Tile(int x, int y, const SkPicture& picture, SkBitmap* quilt) 30 const SkPicture* picture;
31 : fX(x * FLAGS_quiltTile) 31 SkBitmap* quilt;
32 , fY(y * FLAGS_quiltTile) 32 };
33 , fPicture(picture)
34 , fQuilt(quilt) {}
35 33
36 virtual void run() SK_OVERRIDE { 34 static void draw_tile(DrawTileArgs* arg) {
37 SkBitmap tile; 35 const DrawTileArgs& a = *arg;
38 fQuilt->extractSubset(&tile, SkIRect::MakeXYWH(fX, fY, FLAGS_quiltTile, FLAGS_quiltTile)); 36 SkBitmap tile;
39 SkCanvas tileCanvas(tile); 37 a.quilt->extractSubset(&tile, SkIRect::MakeXYWH(a.x, a.y, FLAGS_quiltTile, F LAGS_quiltTile));
40 38 SkCanvas tileCanvas(tile);
41 tileCanvas.translate(SkIntToScalar(-fX), SkIntToScalar(-fY)); 39 tileCanvas.translate(SkIntToScalar(-a.x), SkIntToScalar(-a.y));
42 fPicture.playback(&tileCanvas); 40 a.picture->playback(&tileCanvas);
43 tileCanvas.flush(); 41 tileCanvas.flush();
44 42 }
45 delete this;
46 }
47
48 private:
49 const int fX, fY;
50 const SkPicture& fPicture;
51 SkBitmap* fQuilt;
52 };
53 43
54 void QuiltTask::draw() { 44 void QuiltTask::draw() {
55 SkAutoTDelete<SkBBHFactory> factory; 45 SkAutoTDelete<SkBBHFactory> factory;
56 switch (fBBH) { 46 switch (fBBH) {
57 case kNone_BBH: break; 47 case kNone_BBH: break;
58 case kRTree_BBH: 48 case kRTree_BBH:
59 factory.reset(SkNEW(SkRTreeFactory)); 49 factory.reset(SkNEW(SkRTreeFactory));
60 break; 50 break;
61 case kTileGrid_BBH: { 51 case kTileGrid_BBH: {
62 const SkTileGridFactory::TileGridInfo tiles = { 52 const SkTileGridFactory::TileGridInfo tiles = {
(...skipping 18 matching lines...) Expand all
81 SkBitmap full; 71 SkBitmap full;
82 AllocatePixels(fReference, &full); 72 AllocatePixels(fReference, &full);
83 73
84 if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) { 74 if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) {
85 // Some GMs don't draw exactly the same when tiled. Draw them in one go . 75 // Some GMs don't draw exactly the same when tiled. Draw them in one go .
86 SkCanvas canvas(full); 76 SkCanvas canvas(full);
87 recorded->playback(&canvas); 77 recorded->playback(&canvas);
88 canvas.flush(); 78 canvas.flush();
89 } else { 79 } else {
90 // Draw tiles in parallel into the same bitmap, simulating aggressive im pl-side painting. 80 // Draw tiles in parallel into the same bitmap, simulating aggressive im pl-side painting.
91 SkTaskGroup tg; 81 int xTiles = tiles_needed(full.width(), FLAGS_quiltTile),
92 for (int y = 0; y < tiles_needed(full.height(), FLAGS_quiltTile); y++) { 82 yTiles = tiles_needed(full.height(), FLAGS_quiltTile);
93 for (int x = 0; x < tiles_needed(full.width(), FLAGS_quiltTile); x++ ) { 83 SkTDArray<DrawTileArgs> args;
94 // Deletes itself when done. 84 args.setCount(xTiles*yTiles);
95 tg.add(new Tile(x, y, *recorded, &full)); 85 for (int y = 0; y < yTiles; y++) {
86 for (int x = 0; x < xTiles; x++) {
87 DrawTileArgs arg = { x*FLAGS_quiltTile, y*FLAGS_quiltTile, recor ded, &full };
88 args[y*xTiles + x] = arg;
96 } 89 }
97 } 90 }
91 SkTaskGroup().batch(draw_tile, args.begin(), args.count());
98 } 92 }
99 93
100 if (!BitmapsEqual(full, fReference)) { 94 if (!BitmapsEqual(full, fReference)) {
101 this->fail(); 95 this->fail();
102 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", full))); 96 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", full)));
103 } 97 }
104 } 98 }
105 99
106 bool QuiltTask::shouldSkip() const { 100 bool QuiltTask::shouldSkip() const {
107 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { 101 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
108 return true; 102 return true;
109 } 103 }
110 return !FLAGS_quilt; 104 return !FLAGS_quilt;
111 } 105 }
112 106
113 } // namespace DM 107 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | include/core/SkMultiPictureDraw.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698