OLD | NEW |
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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 protected: | 57 protected: |
58 virtual SkString onShortName() SK_OVERRIDE { | 58 virtual SkString onShortName() SK_OVERRIDE { |
59 return SkString("canvas-state"); | 59 return SkString("canvas-state"); |
60 } | 60 } |
61 | 61 |
62 virtual SkISize onISize() SK_OVERRIDE { | 62 virtual SkISize onISize() SK_OVERRIDE { |
63 return SkISize::Make(WIDTH*3, HEIGHT*4); | 63 return SkISize::Make(WIDTH*3, HEIGHT*4); |
64 } | 64 } |
65 | 65 |
66 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 66 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
67 | |
68 SkCanvas::SaveFlags flags[] = { SkCanvas::kMatrix_SaveFlag, | |
69 SkCanvas::kClip_SaveFlag, | |
70 SkCanvas::kMatrixClip_SaveFlag }; | |
71 | |
72 // columns -- flags | |
73 // rows -- permutations of setting the clip and matrix | 67 // rows -- permutations of setting the clip and matrix |
74 for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(flags)); ++i) { | 68 for (int j = 0; j < 2; ++j) { |
75 for (int j = 0; j < 2; ++j) { | 69 for (int k = 0; k < 2; ++k) { |
76 for (int k = 0; k < 2; ++k) { | 70 this->drawTestPattern((2*j)+k, canvas, SkToBool(j), SkToBool(k))
; |
77 this->drawTestPattern(i, (2*j)+k, canvas, flags[i], | |
78 SkToBool(j), SkToBool(k)); | |
79 } | |
80 } | 71 } |
81 } | 72 } |
82 } | 73 } |
83 | 74 |
84 | 75 |
85 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipPicture_Flag;
} | 76 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipPicture_Flag;
} |
86 | 77 |
87 private: | 78 private: |
88 void drawTestPattern(int x, int y, SkCanvas* canvas, | 79 void drawTestPattern(int y, SkCanvas* canvas, bool doClip, bool doScale) { |
89 SkCanvas::SaveFlags flags, bool doClip, bool doScale) { | |
90 canvas->save(); | 80 canvas->save(); |
91 canvas->translate(SkIntToScalar(x*WIDTH), SkIntToScalar(y*HEIGHT)); | 81 canvas->translate(0, SkIntToScalar(y*HEIGHT)); |
92 | 82 |
93 canvas->drawRect(fOutlineRect, fStrokePaint); | 83 canvas->drawRect(fOutlineRect, fStrokePaint); |
94 canvas->save(flags); | 84 canvas->save(); |
95 if(doClip) { | 85 if(doClip) { |
96 canvas->clipPath(fPath); | 86 canvas->clipPath(fPath); |
97 } | 87 } |
98 if (doScale) { | 88 if (doScale) { |
99 canvas->scale(SkDoubleToScalar(0.5), SkDoubleToScalar(0.5)); | 89 canvas->scale(SkDoubleToScalar(0.5), SkDoubleToScalar(0.5)); |
100 } | 90 } |
101 canvas->restore(); | 91 canvas->restore(); |
102 canvas->drawRect(fFillRect, fFillPaint); | 92 canvas->drawRect(fFillRect, fFillPaint); |
103 | 93 |
104 canvas->restore(); | 94 canvas->restore(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 161 |
172 typedef GM INHERITED; | 162 typedef GM INHERITED; |
173 }; | 163 }; |
174 | 164 |
175 ////////////////////////////////////////////////////////////////////////////// | 165 ////////////////////////////////////////////////////////////////////////////// |
176 | 166 |
177 DEF_GM( return SkNEW(CanvasStateGM); ) | 167 DEF_GM( return SkNEW(CanvasStateGM); ) |
178 DEF_GM( return SkNEW(CanvasLayerStateGM); ) | 168 DEF_GM( return SkNEW(CanvasLayerStateGM); ) |
179 | 169 |
180 } // end namespace | 170 } // end namespace |
OLD | NEW |