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

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: addressing comments 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') | src/core/SkPictureRecord.cpp » ('J')
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 {
robertphillips 2013/08/13 13:45:55 Should the width & height here be computed from WI
31 return make_isize(1200, 900); 63 return SkISize::Make(450, 600);
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); 67 // [0,0] -- red triangle
36 SkCanvas* rec = pict->beginRecording(1200, 900); 68 // test that we don't drop the clip since we are not setting the clip bi t
robertphillips 2013/08/13 13:45:55 this-> on all these?
37 SkPath p; 69 drawTestPattern(0, 0, canvas, SkCanvas::kMatrix_SaveFlag, true, false);
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 70
51 canvas->setAllowSimplifyClip(true); 71 // [1,0] -- red box
52 canvas->save(); 72 // test that we drop the clip since we are setting the clip bit
53 canvas->drawPicture(*pict); 73 drawTestPattern(1, 0, canvas, SkCanvas::kClip_SaveFlag, true, false);
54 canvas->restore();
55 74
56 canvas->setAllowSimplifyClip(false); 75 // [0,1] -- red box in uppper left
57 canvas->save(); 76 // test that we don't drop the matrix since we are not setting the matri x bit
58 canvas->translate(SkIntToScalar(1200 / 2), 0); 77 drawTestPattern(0, 1, canvas, SkCanvas::kClip_SaveFlag, false, true);
59 canvas->drawPicture(*pict); 78
60 canvas->restore(); 79 // [1,1] -- red box
61 SkSafeUnref(pict); 80 // test that we drop the matrix since we are setting the matrix bit
81 drawTestPattern(1, 1, canvas, SkCanvas::kMatrix_SaveFlag, false, true);
82
83 // [0,2] -- red box in upper left
84 // test that we drop the clip but not matrix
85 drawTestPattern(0, 2, canvas, SkCanvas::kClip_SaveFlag, true, true);
86
87 // [1,2] -- red triangle
88 // test that we drop the matrix but not the clip
89 drawTestPattern(1, 2, canvas, SkCanvas::kMatrix_SaveFlag, true, true);
62 } 90 }
63 91
64 private: 92 private:
93 void drawTestPattern(int x, int y, SkCanvas* canvas,
94 SkCanvas::SaveFlags flags, bool doClip, bool doScale) {
95 canvas->save();
96 canvas->translate(x*WIDTH, y*HEIGHT);
97
98 // [0,0] -- red triangle
99 // test that we don't drop the clip since we are not setting the clip bi t
100 canvas->drawRect(fOutlineRect, fStrokePaint);
101 canvas->save(flags);
102 if(doClip) {
103 canvas->clipPath(fPath);
104 }
105 if (doScale) {
106 canvas->scale(0.5, 0.5);
107 }
108 canvas->restore();
109 canvas->drawRect(fFillRect, fFillPaint);
110
111 canvas->restore();
112 }
113
65 typedef GM INHERITED; 114 typedef GM INHERITED;
66 }; 115 };
67 116
68 ////////////////////////////////////////////////////////////////////////////// 117 //////////////////////////////////////////////////////////////////////////////
69 118
70 static GM* MyFactory(void*) { return new PathOpsSkpClipGM; } 119 DEF_GM( return SkNEW(CanvasStateGM); )
71 static GMRegistry reg(MyFactory);
72 120
73 } 121 } // end namespace
OLDNEW
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | src/core/SkPictureRecord.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698