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

Side by Side Diff: gm/canvasstate.cpp

Issue 22875008: Prevent picture recording from over optimizing the culling of clips. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('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 2013 Google Inc. 2 * Copyright 2013 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 #include "SkBitmap.h"
10 #include "SkCanvas.h" 9 #include "SkCanvas.h"
11 #include "SkClipStack.h" 10 #include "SkPaint.h"
12 #include "SkDevice.h"
13 #include "SkPath.h" 11 #include "SkPath.h"
14 #include "SkPathOps.h"
15 #include "SkPicture.h"
16 #include "SkRect.h" 12 #include "SkRect.h"
17 13
18 namespace skiagm { 14 namespace skiagm {
19 15
20 class PathOpsSkpClipGM : public GM { 16 /*
17 * This GM exercises the flags to SkCanvas::save(). The canvas' save() and
18 * restore actions can be limited to only a portion of the canvas' state through
19 * the use of flags when calling save.
20 */
21 class CanvasStateGM : public GM {
22 SkSize fSize;
23 enum {
24 WIDTH = 150,
25 HEIGHT = 150,
26 };
27
28 SkPaint fFillPaint;
29 SkPaint fStrokePaint;
30
31 SkPath fPath;
32
33 SkRect fOutlineRect;
34 SkRect fFillRect;
35
36
21 public: 37 public:
22 PathOpsSkpClipGM() { 38 CanvasStateGM() {
39 fSize.set(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT));
40
41 fFillPaint.setColor(SK_ColorRED);
42 fFillPaint.setStyle(SkPaint::kFill_Style);
43
44 fStrokePaint.setColor(SK_ColorBLUE);
45 fStrokePaint.setStyle(SkPaint::kStroke_Style);
46 fStrokePaint.setStrokeWidth(1);
47
48 fPath.moveTo(25, 25);
49 fPath.lineTo(125, 25);
50 fPath.lineTo(75, 125);
51 fPath.close();
52
53 fOutlineRect = SkRect::MakeXYWH(1, 1, WIDTH-2, HEIGHT-2);
54 fFillRect = SkRect::MakeXYWH(10, 10, WIDTH-20, HEIGHT-20);
23 } 55 }
24 56
25 protected: 57 protected:
26 virtual SkString onShortName() SK_OVERRIDE { 58 virtual SkString onShortName() SK_OVERRIDE {
27 return SkString("pathopsskpclip"); 59 return SkString("canvas-state");
28 } 60 }
29 61
30 virtual SkISize onISize() SK_OVERRIDE { 62 virtual SkISize onISize() SK_OVERRIDE {
31 return make_isize(1200, 900); 63 return SkISize::Make(WIDTH*3, HEIGHT*4);
32 } 64 }
33 65
34 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 66 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
35 SkPicture* pict = SkNEW(SkPicture);
36 SkCanvas* rec = pict->beginRecording(1200, 900);
37 SkPath p;
38 SkRect r = {
39 SkIntToScalar(100),
40 SkIntToScalar(200),
41 SkIntToScalar(400),
42 SkIntToScalar(700)
43 };
44 p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50));
45 rec->clipPath(p, SkRegion::kIntersect_Op, true);
46 rec->translate(SkIntToScalar(250), SkIntToScalar(250));
47 rec->clipPath(p, SkRegion::kIntersect_Op, true);
48 rec->drawColor(0xffff0000);
49 pict->endRecording();
50 67
51 canvas->setAllowSimplifyClip(true); 68 SkCanvas::SaveFlags flags[] = { SkCanvas::kMatrix_SaveFlag,
52 canvas->save(); 69 SkCanvas::kClip_SaveFlag,
53 canvas->drawPicture(*pict); 70 SkCanvas::kMatrixClip_SaveFlag };
54 canvas->restore();
55 71
56 canvas->setAllowSimplifyClip(false); 72 // columns -- flags
57 canvas->save(); 73 // rows -- permutations of setting the clip and matrix
58 canvas->translate(SkIntToScalar(1200 / 2), 0); 74 for (size_t i = 0; i < SK_ARRAY_COUNT(flags); ++i) {
59 canvas->drawPicture(*pict); 75 for (int j = 0; j < 2; ++j) {
60 canvas->restore(); 76 for (int k = 0; k < 2; ++k) {
61 SkSafeUnref(pict); 77 this->drawTestPattern(i, (2*j)+k, canvas, flags[i], j, k);
78 }
79 }
80 }
62 } 81 }
63 82
83
84 virtual uint32_t onGetFlags() SK_OVERRIDE const { return kSkipPicture_Flag; }
85
64 private: 86 private:
87 void drawTestPattern(int x, int y, SkCanvas* canvas,
88 SkCanvas::SaveFlags flags, bool doClip, bool doScale) {
89 canvas->save();
90 canvas->translate(x*WIDTH, y*HEIGHT);
91
92 canvas->drawRect(fOutlineRect, fStrokePaint);
93 canvas->save(flags);
94 if(doClip) {
95 canvas->clipPath(fPath);
96 }
97 if (doScale) {
98 canvas->scale(0.5, 0.5);
99 }
100 canvas->restore();
101 canvas->drawRect(fFillRect, fFillPaint);
102
103 canvas->restore();
104 }
105
65 typedef GM INHERITED; 106 typedef GM INHERITED;
66 }; 107 };
67 108
68 ////////////////////////////////////////////////////////////////////////////// 109 //////////////////////////////////////////////////////////////////////////////
69 110
70 static GM* MyFactory(void*) { return new PathOpsSkpClipGM; } 111 DEF_GM( return SkNEW(CanvasStateGM); )
71 static GMRegistry reg(MyFactory);
72 112
73 } 113 } // end namespace
OLDNEW
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698