| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 67 |
| 68 SkCanvas::SaveFlags flags[] = { SkCanvas::kMatrix_SaveFlag, | 68 unsigned flags[] = { |
| 69 SkCanvas::kClip_SaveFlag, | 69 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS |
| 70 SkCanvas::kMatrixClip_SaveFlag }; | 70 SkCanvas::kMatrix_SaveFlag, |
| 71 SkCanvas::kClip_SaveFlag, |
| 72 SkCanvas::kMatrixClip_SaveFlag |
| 73 #else |
| 74 0, 0, 0 // placeholders |
| 75 #endif |
| 76 }; |
| 71 | 77 |
| 72 // columns -- flags | 78 // columns -- flags |
| 73 // rows -- permutations of setting the clip and matrix | 79 // rows -- permutations of setting the clip and matrix |
| 74 for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(flags)); ++i) { | 80 for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(flags)); ++i) { |
| 75 for (int j = 0; j < 2; ++j) { | 81 for (int j = 0; j < 2; ++j) { |
| 76 for (int k = 0; k < 2; ++k) { | 82 for (int k = 0; k < 2; ++k) { |
| 77 this->drawTestPattern(i, (2*j)+k, canvas, flags[i], | 83 this->drawTestPattern(i, (2*j)+k, canvas, flags[i], |
| 78 SkToBool(j), SkToBool(k)); | 84 SkToBool(j), SkToBool(k)); |
| 79 } | 85 } |
| 80 } | 86 } |
| 81 } | 87 } |
| 82 } | 88 } |
| 83 | 89 |
| 84 | 90 |
| 85 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipPicture_Flag;
} | 91 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipPicture_Flag;
} |
| 86 | 92 |
| 87 private: | 93 private: |
| 88 void drawTestPattern(int x, int y, SkCanvas* canvas, | 94 void drawTestPattern(int x, int y, SkCanvas* canvas, |
| 89 SkCanvas::SaveFlags flags, bool doClip, bool doScale) { | 95 unsigned flags, bool doClip, bool doScale) { |
| 90 canvas->save(); | 96 canvas->save(); |
| 91 canvas->translate(SkIntToScalar(x*WIDTH), SkIntToScalar(y*HEIGHT)); | 97 canvas->translate(SkIntToScalar(x*WIDTH), SkIntToScalar(y*HEIGHT)); |
| 92 | 98 |
| 93 canvas->drawRect(fOutlineRect, fStrokePaint); | 99 canvas->drawRect(fOutlineRect, fStrokePaint); |
| 94 canvas->save(flags); | 100 canvas->save( |
| 101 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS |
| 102 (SkCanvas::SaveFlags)flags |
| 103 #endif |
| 104 ); |
| 95 if(doClip) { | 105 if(doClip) { |
| 96 canvas->clipPath(fPath); | 106 canvas->clipPath(fPath); |
| 97 } | 107 } |
| 98 if (doScale) { | 108 if (doScale) { |
| 99 canvas->scale(SkDoubleToScalar(0.5), SkDoubleToScalar(0.5)); | 109 canvas->scale(SkDoubleToScalar(0.5), SkDoubleToScalar(0.5)); |
| 100 } | 110 } |
| 101 canvas->restore(); | 111 canvas->restore(); |
| 102 canvas->drawRect(fFillRect, fFillPaint); | 112 canvas->drawRect(fFillRect, fFillPaint); |
| 103 | 113 |
| 104 canvas->restore(); | 114 canvas->restore(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 125 | 135 |
| 126 virtual SkISize onISize() SK_OVERRIDE { | 136 virtual SkISize onISize() SK_OVERRIDE { |
| 127 return SkISize::Make(WIDTH, HEIGHT); | 137 return SkISize::Make(WIDTH, HEIGHT); |
| 128 } | 138 } |
| 129 | 139 |
| 130 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 140 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 131 | 141 |
| 132 // clear the canvas to red | 142 // clear the canvas to red |
| 133 canvas->drawColor(SK_ColorRED); | 143 canvas->drawColor(SK_ColorRED); |
| 134 | 144 |
| 135 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 145 #if defined(SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG) && defined(SK_SUPPORT_LEGACY_SAVE
FLAGS) |
| 146 |
| 136 // both rects should appear | 147 // both rects should appear |
| 137 drawTestPattern(canvas, 255, SkCanvas::kARGB_NoClipLayer_SaveFlag); | 148 drawTestPattern(canvas, 255, SkCanvas::kARGB_NoClipLayer_SaveFlag); |
| 138 | 149 |
| 139 canvas->translate(0, 2*(fRect.height() + 10)); | 150 canvas->translate(0, 2*(fRect.height() + 10)); |
| 140 | 151 |
| 141 // only the top rect should appear | 152 // only the top rect should appear |
| 142 drawTestPattern(canvas, 255, SkCanvas::kARGB_ClipLayer_SaveFlag); | 153 drawTestPattern(canvas, 255, SkCanvas::kARGB_ClipLayer_SaveFlag); |
| 143 | 154 |
| 144 canvas->translate(0, 2*(fRect.height() + 10)); | 155 canvas->translate(0, 2*(fRect.height() + 10)); |
| 145 | 156 |
| 146 // only the bottom rect should appear | 157 // only the bottom rect should appear |
| 147 drawTestPattern(canvas, 0, SkCanvas::kARGB_NoClipLayer_SaveFlag); | 158 drawTestPattern(canvas, 0, SkCanvas::kARGB_NoClipLayer_SaveFlag); |
| 148 #endif | 159 #endif |
| 149 } | 160 } |
| 150 | 161 |
| 151 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipGPU_Flag; } | 162 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipGPU_Flag; } |
| 152 | 163 |
| 153 private: | 164 private: |
| 154 // draw a rect within the layer's bounds and again outside the layer's bound
s | 165 // draw a rect within the layer's bounds and again outside the layer's bound
s |
| 155 void drawTestPattern(SkCanvas* canvas, U8CPU layerAlpha, SkCanvas::SaveFlags
flags) { | 166 void drawTestPattern(SkCanvas* canvas, U8CPU layerAlpha, unsigned flags) { |
| 156 canvas->saveLayerAlpha(&fRect, layerAlpha, flags); | 167 canvas->saveLayerAlpha(&fRect, layerAlpha |
| 168 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS |
| 169 , (SkCanvas::SaveFlags)flags |
| 170 #endif |
| 171 ); |
| 157 canvas->drawRect(fRect, fBluePaint); | 172 canvas->drawRect(fRect, fBluePaint); |
| 158 canvas->translate(0, fRect.height() + 10); | 173 canvas->translate(0, fRect.height() + 10); |
| 159 canvas->drawRect(fRect, fBluePaint); | 174 canvas->drawRect(fRect, fBluePaint); |
| 160 canvas->restore(); | 175 canvas->restore(); |
| 161 } | 176 } |
| 162 | 177 |
| 163 enum { | 178 enum { |
| 164 WIDTH = 400, | 179 WIDTH = 400, |
| 165 HEIGHT = 400, | 180 HEIGHT = 400, |
| 166 SPACER = 10, | 181 SPACER = 10, |
| 167 }; | 182 }; |
| 168 | 183 |
| 169 SkPaint fBluePaint; | 184 SkPaint fBluePaint; |
| 170 SkRect fRect; | 185 SkRect fRect; |
| 171 | 186 |
| 172 typedef GM INHERITED; | 187 typedef GM INHERITED; |
| 173 }; | 188 }; |
| 174 | 189 |
| 175 ////////////////////////////////////////////////////////////////////////////// | 190 ////////////////////////////////////////////////////////////////////////////// |
| 176 | 191 |
| 177 DEF_GM( return SkNEW(CanvasStateGM); ) | 192 DEF_GM( return SkNEW(CanvasStateGM); ) |
| 178 DEF_GM( return SkNEW(CanvasLayerStateGM); ) | 193 DEF_GM( return SkNEW(CanvasLayerStateGM); ) |
| 179 | 194 |
| 180 } // end namespace | 195 } // end namespace |
| OLD | NEW |