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

Side by Side Diff: gm/multipicturedraw.cpp

Issue 513983002: Try out scalar picture sizes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT again Created 6 years, 3 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 | « gm/gmmain.cpp ('k') | gm/optimizations.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 9
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 SkPaint fill; 45 SkPaint fill;
46 fill.setStyle(SkPaint::kFill_Style); 46 fill.setStyle(SkPaint::kFill_Style);
47 fill.setColor(fillColor); 47 fill.setColor(fillColor);
48 48
49 SkPaint stroke; 49 SkPaint stroke;
50 stroke.setStyle(SkPaint::kStroke_Style); 50 stroke.setStyle(SkPaint::kStroke_Style);
51 stroke.setStrokeWidth(3); 51 stroke.setStrokeWidth(3);
52 52
53 SkPictureRecorder recorder; 53 SkPictureRecorder recorder;
54 54
55 SkCanvas* canvas = recorder.beginRecording(kPicWidth, kPicHeight); 55 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
56 SkIntToScalar(kPicHeight));
56 57
57 SkScalar xPos, yPos = 0; 58 SkScalar xPos, yPos = 0;
58 59
59 for (int y = 0; y < kNumHexY; ++y) { 60 for (int y = 0; y < kNumHexY; ++y) {
60 xPos = 0; 61 xPos = 0;
61 62
62 for (int x = 0; x < kNumHexX; ++x) { 63 for (int x = 0; x < kNumHexX; ++x) {
63 canvas->saveLayer(NULL, NULL); 64 canvas->saveLayer(NULL, NULL);
64 canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0 )); 65 canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0 ));
65 canvas->drawPath(hex, fill); 66 canvas->drawPath(hex, fill);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 105
105 // Just a single picture with no clip 106 // Just a single picture with no clip
106 static void no_clip(SkCanvas* canvas, const SkPicture* pictures[2]) { 107 static void no_clip(SkCanvas* canvas, const SkPicture* pictures[2]) {
107 canvas->drawPicture(pictures[0]); 108 canvas->drawPicture(pictures[0]);
108 } 109 }
109 110
110 // Two pictures with a rect clip on the second one 111 // Two pictures with a rect clip on the second one
111 static void rect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) { 112 static void rect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) {
112 canvas->drawPicture(pictures[0]); 113 canvas->drawPicture(pictures[0]);
113 114
114 SkRect rect = SkRect::MakeWH(SkIntToScalar(kPicWidth), SkIntToScalar(kPicHei ght)); 115 SkRect rect = pictures[0]->cullRect();
115 rect.inset(kInset, kInset); 116 rect.inset(kInset, kInset);
116 117
117 canvas->clipRect(rect); 118 canvas->clipRect(rect);
118 119
119 canvas->drawPicture(pictures[1]); 120 canvas->drawPicture(pictures[1]);
120 } 121 }
121 122
122 // Two pictures with a round rect clip on the second one 123 // Two pictures with a round rect clip on the second one
123 static void rrect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) { 124 static void rrect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) {
124 canvas->drawPicture(pictures[0]); 125 canvas->drawPicture(pictures[0]);
125 126
126 SkRect rect = SkRect::MakeWH(SkIntToScalar(kPicWidth), SkIntToScalar(kPicHei ght)); 127 SkRect rect = pictures[0]->cullRect();
127 rect.inset(kInset, kInset); 128 rect.inset(kInset, kInset);
128 129
129 SkRRect rrect; 130 SkRRect rrect;
130 rrect.setRectXY(rect, kInset, kInset); 131 rrect.setRectXY(rect, kInset, kInset);
131 132
132 canvas->clipRRect(rrect); 133 canvas->clipRRect(rrect);
133 134
134 canvas->drawPicture(pictures[1]); 135 canvas->drawPicture(pictures[1]);
135 } 136 }
136 137
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 }; 169 };
169 170
170 static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen, 171 static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen,
171 const SkPicture* pictures[2], 172 const SkPicture* pictures[2],
172 SkCanvas* dest, const SkMatrix& xform) { 173 SkCanvas* dest, const SkMatrix& xform) {
173 SkAutoTUnref<SkPicture> composite; 174 SkAutoTUnref<SkPicture> composite;
174 175
175 { 176 {
176 SkPictureRecorder recorder; 177 SkPictureRecorder recorder;
177 178
178 SkCanvas* pictureCanvas = recorder.beginRecording(kPicWidth, kPicHeight) ; 179 SkCanvas* pictureCanvas = recorder.beginRecording(SkIntToScalar(kPicWidt h),
180 SkIntToScalar(kPicHeig ht));
179 181
180 (*pfGen)(pictureCanvas, pictures); 182 (*pfGen)(pictureCanvas, pictures);
181 183
182 composite.reset(recorder.endRecording()); 184 composite.reset(recorder.endRecording());
183 } 185 }
184 186
185 mpd->add(dest, composite, &xform); 187 mpd->add(dest, composite, &xform);
186 } 188 }
187 189
188 typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, 190 typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 protected: 294 protected:
293 Content fContent; 295 Content fContent;
294 Layout fLayout; 296 Layout fLayout;
295 const SkPicture* fPictures[2]; 297 const SkPicture* fPictures[2];
296 298
297 virtual void onOnceBeforeDraw() SK_OVERRIDE { 299 virtual void onOnceBeforeDraw() SK_OVERRIDE {
298 fPictures[0] = make_picture(SK_ColorWHITE); 300 fPictures[0] = make_picture(SK_ColorWHITE);
299 fPictures[1] = make_picture(SK_ColorGRAY); 301 fPictures[1] = make_picture(SK_ColorGRAY);
300 } 302 }
301 303
302 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE{ 304 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
303 SkMultiPictureDraw mpd; 305 SkMultiPictureDraw mpd;
304 SkTArray<ComposeStep> composeSteps; 306 SkTArray<ComposeStep> composeSteps;
305 307
306 // Fill up the MultiPictureDraw 308 // Fill up the MultiPictureDraw
307 (*gLayoutMthds[fLayout])(canvas, &mpd, 309 (*gLayoutMthds[fLayout])(canvas, &mpd,
308 gContentMthds[fContent], 310 gContentMthds[fContent],
309 fPictures, &composeSteps); 311 fPictures, &composeSteps);
310 312
311 mpd.draw(); 313 mpd.draw();
312 314
313 // Compose all the drawn canvases into the final canvas 315 // Compose all the drawn canvases into the final canvas
314 for (int i = 0; i < composeSteps.count(); ++i) { 316 for (int i = 0; i < composeSteps.count(); ++i) {
315 const ComposeStep& step = composeSteps[i]; 317 const ComposeStep& step = composeSteps[i];
316 318
317 SkAutoTUnref<SkImage> image(step.fSurf->newImageSnapshot()); 319 SkAutoTUnref<SkImage> image(step.fSurf->newImageSnapshot());
318 320
319 image->draw(canvas, step.fX, step.fY, step.fPaint); 321 image->draw(canvas, step.fX, step.fY, step.fPaint);
320 } 322 }
321 } 323 }
322 324
323 virtual SkISize onISize() SK_OVERRIDE{ return SkISize::Make(kPicWidth, k PicHeight); } 325 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(kPicWidth, kPicHeight); }
324 326
325 virtual SkString onShortName() SK_OVERRIDE{ 327 virtual SkString onShortName() SK_OVERRIDE {
326 static const char* gContentNames[] = { 328 static const char* gContentNames[] = {
327 "noclip", "rectclip", "rrectclip", "pathclip", "invpathclip" 329 "noclip", "rectclip", "rrectclip", "pathclip", "invpathclip"
328 }; 330 };
329 static const char* gLayoutNames[] = { "simple", "tiled" }; 331 static const char* gLayoutNames[] = { "simple", "tiled" };
330 332
331 SkASSERT(SK_ARRAY_COUNT(gLayoutNames) == kLayoutCnt); 333 SkASSERT(SK_ARRAY_COUNT(gLayoutNames) == kLayoutCnt);
332 SkASSERT(SK_ARRAY_COUNT(gContentNames) == kContentCnt); 334 SkASSERT(SK_ARRAY_COUNT(gContentNames) == kContentCnt);
333 335
334 SkString name("multipicturedraw_"); 336 SkString name("multipicturedraw_");
335 337
(...skipping 24 matching lines...) Expand all
360 MultiPictureDraw::kTiled_Layout) );) 362 MultiPictureDraw::kTiled_Layout) );)
361 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kRectClipMulti _Content, 363 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kRectClipMulti _Content,
362 MultiPictureDraw::kTiled_Layout) );) 364 MultiPictureDraw::kTiled_Layout) );)
363 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kRRectClipMult i_Content, 365 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kRRectClipMult i_Content,
364 MultiPictureDraw::kTiled_Layout) );) 366 MultiPictureDraw::kTiled_Layout) );)
365 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kPathClipMulti _Content, 367 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kPathClipMulti _Content,
366 MultiPictureDraw::kTiled_Layout) );) 368 MultiPictureDraw::kTiled_Layout) );)
367 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kInvPathClipMu lti_Content, 369 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kInvPathClipMu lti_Content,
368 MultiPictureDraw::kTiled_Layout) );) 370 MultiPictureDraw::kTiled_Layout) );)
369 } 371 }
OLDNEW
« no previous file with comments | « gm/gmmain.cpp ('k') | gm/optimizations.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698