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

Side by Side Diff: dm/DMQuiltTask.cpp

Issue 788243008: Sketch DM refactor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: better failure messages, disable a few things temporarily to try to go green Created 5 years, 11 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 | « dm/DMQuiltTask.h ('k') | dm/DMReporter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "DMQuiltTask.h"
2 #include "DMUtil.h"
3 #include "DMWriteTask.h"
4
5 #include "SkBBHFactory.h"
6 #include "SkCommandLineFlags.h"
7 #include "SkPicture.h"
8 #include "SkTaskGroup.h"
9
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.");
12
13 namespace DM {
14
15 static const char* kBBHs[] = { "nobbh", "rtree", "tilegrid" };
16 QuiltTask::QuiltTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, Qui ltTask::BBH bbh)
17 : CpuTask(parent)
18 , fBBH(bbh)
19 , fName(UnderJoin(parent.name().c_str(), kBBHs[bbh]))
20 , fGM(gm)
21 , fReference(reference)
22 {}
23
24 static int tiles_needed(int fullDimension, int tileDimension) {
25 return (fullDimension + tileDimension - 1) / tileDimension;
26 }
27
28 struct DrawTileArgs {
29 int x, y;
30 const SkPicture* picture;
31 SkBitmap* quilt;
32 };
33
34 static void draw_tile(DrawTileArgs* arg) {
35 const DrawTileArgs& a = *arg;
36 SkBitmap tile;
37 a.quilt->extractSubset(&tile, SkIRect::MakeXYWH(a.x, a.y, FLAGS_quiltTile, F LAGS_quiltTile));
38 SkCanvas tileCanvas(tile);
39 tileCanvas.translate(SkIntToScalar(-a.x), SkIntToScalar(-a.y));
40 a.picture->playback(&tileCanvas);
41 tileCanvas.flush();
42 }
43
44 void QuiltTask::draw() {
45 SkAutoTDelete<SkBBHFactory> factory;
46 switch (fBBH) {
47 case kNone_BBH: break;
48 case kRTree_BBH:
49 factory.reset(SkNEW(SkRTreeFactory));
50 break;
51 }
52
53 // A couple GMs draw wrong when using a bounding box hierarchy.
54 // This almost certainly means we have a bug to fix, but for now
55 // just draw without a bounding box hierarchy.
56 if (fGM->getFlags() & skiagm::GM::kNoBBH_Flag) {
57 factory.reset(NULL);
58 }
59
60 SkAutoTUnref<const SkPicture> recorded(RecordPicture(fGM.get(), factory.get( )));
61
62 SkBitmap full;
63 AllocatePixels(fReference, &full);
64
65 if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) {
66 // Some GMs don't draw exactly the same when tiled. Draw them in one go .
67 SkCanvas canvas(full);
68 recorded->playback(&canvas);
69 canvas.flush();
70 } else {
71 // Draw tiles in parallel into the same bitmap, simulating aggressive im pl-side painting.
72 int xTiles = tiles_needed(full.width(), FLAGS_quiltTile),
73 yTiles = tiles_needed(full.height(), FLAGS_quiltTile);
74 SkTDArray<DrawTileArgs> args;
75 args.setCount(xTiles*yTiles);
76 for (int y = 0; y < yTiles; y++) {
77 for (int x = 0; x < xTiles; x++) {
78 DrawTileArgs arg = { x*FLAGS_quiltTile, y*FLAGS_quiltTile, recor ded, &full };
79 args[y*xTiles + x] = arg;
80 }
81 }
82 SkTaskGroup().batch(draw_tile, args.begin(), args.count());
83 }
84
85 if (!BitmapsEqual(full, fReference)) {
86 this->fail();
87 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", full)));
88 }
89 }
90
91 bool QuiltTask::shouldSkip() const {
92 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
93 return true;
94 }
95 return !FLAGS_quilt;
96 }
97
98 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMQuiltTask.h ('k') | dm/DMReporter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698