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 "CanvasStateHelpers.h" | |
8 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
9 #include "SkCanvasStateUtils.h" | 10 #include "SkCanvasStateUtils.h" |
11 #include "SkCommandLineFlags.h" | |
10 #include "SkDrawFilter.h" | 12 #include "SkDrawFilter.h" |
11 #include "SkError.h" | 13 #include "SkError.h" |
12 #include "SkPaint.h" | 14 #include "SkPaint.h" |
13 #include "SkRRect.h" | 15 #include "SkRRect.h" |
14 #include "SkRect.h" | 16 #include "SkRect.h" |
15 #include "Test.h" | 17 #include "Test.h" |
16 | 18 |
17 static void test_complex_layers(skiatest::Reporter* reporter) { | 19 // dlopen and the library flag are only used for tests which require this flag. |
18 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 20 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
21 #include <dlfcn.h> | |
22 | |
23 DEFINE_string(library, "", "Support library to use for CanvasState test. If empt y (the default), " | |
24 "the test will be run without crossing a library boun dary. Otherwise, " | |
25 "it is expected to be a full path to a shared library file, which will" | |
26 " be dynamically loaded. Functions from the library w ill be called to " | |
27 "test SkCanvasState."); | |
28 | |
29 | |
30 // This class calls dlopen on the library passed in to the command line flag lib rary, and handles | |
31 // calling dlclose when it goes out of scope. | |
32 class OpenLibResult { | |
33 public: | |
34 // If the flag library was passed to this run of the test, attempt to open i t using dlopen and | |
35 // report whether it succeeded. | |
36 OpenLibResult(skiatest::Reporter* reporter) { | |
37 if (FLAGS_library.count() == 1) { | |
38 fLibRequired = true; | |
39 fHandle = dlopen(FLAGS_library[0], RTLD_LAZY | RTLD_LOCAL); | |
40 REPORTER_ASSERT_MESSAGE(reporter, fHandle != NULL, "Failed to open l ibrary!"); | |
41 } else { | |
42 fLibRequired = false; | |
43 fHandle = NULL; | |
44 } | |
45 } | |
46 | |
47 // Automatically call dlclose when going out of scope. | |
48 ~OpenLibResult() { | |
49 if (fHandle) { | |
50 dlclose(fHandle); | |
51 } | |
52 } | |
53 | |
54 // Whether the flag library was used. | |
55 bool libRequired() const { | |
56 return fLibRequired; | |
57 } | |
58 | |
59 // Pointer to the shared library object. | |
60 void* handle() { return fHandle; } | |
61 | |
62 private: | |
63 bool fLibRequired; | |
64 void* fHandle; | |
65 }; | |
66 | |
67 DEF_TEST(CanvasState_test_complex_layers, reporter) { | |
19 const int WIDTH = 400; | 68 const int WIDTH = 400; |
20 const int HEIGHT = 400; | 69 const int HEIGHT = 400; |
21 const int SPACER = 10; | 70 const int SPACER = 10; |
22 | 71 |
23 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER), | 72 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER), |
24 SkIntToScalar(WIDTH-(2*SPACER)), | 73 SkIntToScalar(WIDTH-(2*SPACER)), |
25 SkIntToScalar((HEIGHT-(2*SPACER)) / 7)); | 74 SkIntToScalar((HEIGHT-(2*SPACER)) / 7)); |
26 | 75 |
27 const SkColorType colorTypes[] = { | 76 const SkColorType colorTypes[] = { |
28 kRGB_565_SkColorType, kN32_SkColorType | 77 kRGB_565_SkColorType, kN32_SkColorType |
29 }; | 78 }; |
30 | 79 |
31 const int layerAlpha[] = { 255, 255, 0 }; | 80 const int layerAlpha[] = { 255, 255, 0 }; |
32 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, | 81 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, |
33 SkCanvas::kARGB_ClipLayer_SaveFlag, | 82 SkCanvas::kARGB_ClipLayer_SaveFlag, |
34 SkCanvas::kARGB_NoClipLayer_SaveFlag | 83 SkCanvas::kARGB_NoClipLayer_SaveFlag |
35 }; | 84 }; |
36 REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); | 85 REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); |
37 | 86 |
87 bool (*drawFn)(SkCanvasState* state, float l, float t, | |
88 float r, float b, int32_t s); | |
89 | |
90 OpenLibResult openLibResult(reporter); | |
91 if (openLibResult.handle() != NULL) { | |
92 *(void**) (&drawFn) = dlsym(openLibResult.handle(), | |
93 "complex_layers_draw_from_canvas_state"); | |
94 } else { | |
95 // If the caller intended to open the library, but the library could | |
96 // not be opened, the rest of the test is not meaningful. | |
97 if (openLibResult.libRequired()) { | |
djsollen
2014/07/22 17:24:42
I assumed that in this case we could still test th
scroggo
2014/07/22 18:12:01
Done.
| |
98 return; | |
99 } | |
100 drawFn = complex_layers_draw_from_canvas_state; | |
101 } | |
102 | |
103 REPORTER_ASSERT(reporter, drawFn); | |
104 if (!drawFn) { | |
105 return; | |
106 } | |
107 | |
38 for (size_t i = 0; i < SK_ARRAY_COUNT(colorTypes); ++i) { | 108 for (size_t i = 0; i < SK_ARRAY_COUNT(colorTypes); ++i) { |
39 SkBitmap bitmaps[2]; | 109 SkBitmap bitmaps[2]; |
40 for (int j = 0; j < 2; ++j) { | 110 for (int j = 0; j < 2; ++j) { |
41 bitmaps[j].allocPixels(SkImageInfo::Make(WIDTH, HEIGHT, | 111 bitmaps[j].allocPixels(SkImageInfo::Make(WIDTH, HEIGHT, |
42 colorTypes[i], | 112 colorTypes[i], |
43 kPremul_SkAlphaType)); | 113 kPremul_SkAlphaType)); |
44 | 114 |
45 SkCanvas canvas(bitmaps[j]); | 115 SkCanvas canvas(bitmaps[j]); |
46 | 116 |
47 canvas.drawColor(SK_ColorRED); | 117 canvas.drawColor(SK_ColorRED); |
48 | 118 |
49 for (size_t k = 0; k < SK_ARRAY_COUNT(layerAlpha); ++k) { | 119 for (size_t k = 0; k < SK_ARRAY_COUNT(layerAlpha); ++k) { |
50 // draw a rect within the layer's bounds and again outside the l ayer's bounds | 120 // draw a rect within the layer's bounds and again outside the l ayer's bounds |
51 canvas.saveLayerAlpha(&rect, layerAlpha[k], flags[k]); | 121 canvas.saveLayerAlpha(&rect, layerAlpha[k], flags[k]); |
52 | 122 |
53 SkCanvasState* state = NULL; | |
54 SkCanvas* tmpCanvas = NULL; | |
55 if (j) { | 123 if (j) { |
56 state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 124 // Capture from the first Skia. |
125 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasStat e(&canvas); | |
57 REPORTER_ASSERT(reporter, state); | 126 REPORTER_ASSERT(reporter, state); |
58 tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state) ; | 127 |
59 REPORTER_ASSERT(reporter, tmpCanvas); | 128 // And draw to it in the second Skia. |
129 bool success = complex_layers_draw_from_canvas_state(state, | |
130 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, SP ACER); | |
131 REPORTER_ASSERT(reporter, success); | |
132 | |
133 // And release it in the *first* Skia. | |
134 SkCanvasStateUtils::ReleaseCanvasState(state); | |
60 } else { | 135 } else { |
61 tmpCanvas = SkRef(&canvas); | 136 // Draw in the first Skia. |
137 complex_layers_draw(&canvas, rect.fLeft, rect.fTop, | |
138 rect.fRight, rect.fBottom, SPACER); | |
62 } | 139 } |
63 | 140 |
64 SkPaint bluePaint; | |
65 bluePaint.setColor(SK_ColorBLUE); | |
66 bluePaint.setStyle(SkPaint::kFill_Style); | |
67 | |
68 tmpCanvas->drawRect(rect, bluePaint); | |
69 tmpCanvas->translate(0, rect.height() + SPACER); | |
70 tmpCanvas->drawRect(rect, bluePaint); | |
71 | |
72 tmpCanvas->unref(); | |
73 SkCanvasStateUtils::ReleaseCanvasState(state); | |
74 | |
75 canvas.restore(); | 141 canvas.restore(); |
76 | 142 |
77 // translate the canvas for the next iteration | 143 // translate the canvas for the next iteration |
78 canvas.translate(0, 2*(rect.height() + SPACER)); | 144 canvas.translate(0, 2*(rect.height() + SPACER)); |
79 } | 145 } |
80 } | 146 } |
81 | 147 |
82 // now we memcmp the two bitmaps | 148 // now we memcmp the two bitmaps |
83 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); | 149 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); |
84 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), | 150 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), |
85 bitmaps[1].getPixels(), | 151 bitmaps[1].getPixels(), |
86 bitmaps[0].getSize())); | 152 bitmaps[0].getSize())); |
87 } | 153 } |
154 } | |
88 #endif | 155 #endif |
89 } | |
90 | 156 |
91 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
92 | 158 |
93 static void test_complex_clips(skiatest::Reporter* reporter) { | |
94 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 159 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
160 DEF_TEST(CanvasState_test_complex_clips, reporter) { | |
95 const int WIDTH = 400; | 161 const int WIDTH = 400; |
96 const int HEIGHT = 400; | 162 const int HEIGHT = 400; |
97 const int SPACER = 10; | 163 const int SPACER = 10; |
98 | 164 |
99 SkIRect layerRect = SkIRect::MakeWH(WIDTH, HEIGHT / 4); | 165 SkIRect layerRect = SkIRect::MakeWH(WIDTH, HEIGHT / 4); |
100 layerRect.inset(2*SPACER, 2*SPACER); | 166 layerRect.inset(2*SPACER, 2*SPACER); |
101 | 167 |
102 SkIRect clipRect = layerRect; | 168 SkIRect clipRect = layerRect; |
103 clipRect.fRight = clipRect.fLeft + (clipRect.width() / 2) - (2*SPACER); | 169 clipRect.fRight = clipRect.fLeft + (clipRect.width() / 2) - (2*SPACER); |
104 clipRect.outset(SPACER, SPACER); | 170 clipRect.outset(SPACER, SPACER); |
(...skipping 12 matching lines...) Expand all Loading... | |
117 const SkRegion::Op clipOps[] = { SkRegion::kIntersect_Op, | 183 const SkRegion::Op clipOps[] = { SkRegion::kIntersect_Op, |
118 SkRegion::kIntersect_Op, | 184 SkRegion::kIntersect_Op, |
119 SkRegion::kReplace_Op, | 185 SkRegion::kReplace_Op, |
120 }; | 186 }; |
121 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, | 187 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, |
122 SkCanvas::kARGB_ClipLayer_SaveFlag, | 188 SkCanvas::kARGB_ClipLayer_SaveFlag, |
123 SkCanvas::kARGB_NoClipLayer_SaveFlag, | 189 SkCanvas::kARGB_NoClipLayer_SaveFlag, |
124 }; | 190 }; |
125 REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); | 191 REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); |
126 | 192 |
193 bool (*drawFn)(SkCanvasState* state, int32_t l, int32_t t, | |
194 int32_t r, int32_t b, int32_t clipOp, | |
195 int32_t regionRects, int32_t* rectCoords); | |
196 | |
197 OpenLibResult openLibResult(reporter); | |
198 if (openLibResult.handle() != NULL) { | |
199 *(void**) (&drawFn) = dlsym(openLibResult.handle(), | |
200 "complex_clips_draw_from_canvas_state"); | |
201 } else { | |
202 // If the caller intended to open the library, but the library could | |
203 // not be opened, the rest of the test is not meaningful. | |
204 if (openLibResult.libRequired()) { | |
205 return; | |
206 } | |
207 drawFn = complex_clips_draw_from_canvas_state; | |
208 } | |
209 | |
210 REPORTER_ASSERT(reporter, drawFn); | |
211 if (!drawFn) { | |
212 return; | |
213 } | |
214 | |
127 SkBitmap bitmaps[2]; | 215 SkBitmap bitmaps[2]; |
128 for (int i = 0; i < 2; ++i) { | 216 for (int i = 0; i < 2; ++i) { |
129 bitmaps[i].allocN32Pixels(WIDTH, HEIGHT); | 217 bitmaps[i].allocN32Pixels(WIDTH, HEIGHT); |
130 | 218 |
131 SkCanvas canvas(bitmaps[i]); | 219 SkCanvas canvas(bitmaps[i]); |
132 | 220 |
133 canvas.drawColor(SK_ColorRED); | 221 canvas.drawColor(SK_ColorRED); |
134 | 222 |
135 SkRegion localRegion = clipRegion; | 223 SkRegion localRegion = clipRegion; |
136 | 224 |
137 for (size_t j = 0; j < SK_ARRAY_COUNT(flags); ++j) { | 225 for (size_t j = 0; j < SK_ARRAY_COUNT(flags); ++j) { |
138 SkRect layerBounds = SkRect::Make(layerRect); | 226 SkRect layerBounds = SkRect::Make(layerRect); |
139 canvas.saveLayerAlpha(&layerBounds, 128, flags[j]); | 227 canvas.saveLayerAlpha(&layerBounds, 128, flags[j]); |
140 | 228 |
141 SkCanvasState* state = NULL; | |
142 SkCanvas* tmpCanvas = NULL; | |
143 if (i) { | 229 if (i) { |
144 state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 230 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&c anvas); |
145 REPORTER_ASSERT(reporter, state); | 231 REPORTER_ASSERT(reporter, state); |
146 tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); | 232 |
147 REPORTER_ASSERT(reporter, tmpCanvas); | 233 SkRegion::Iterator iter(localRegion); |
234 SkTDArray<int32_t> rectCoords; | |
235 for (; !iter.done(); iter.next()) { | |
236 const SkIRect& rect = iter.rect(); | |
237 *rectCoords.append() = rect.fLeft; | |
238 *rectCoords.append() = rect.fTop; | |
239 *rectCoords.append() = rect.fRight; | |
240 *rectCoords.append() = rect.fBottom; | |
241 } | |
242 bool success = drawFn(state, clipRect.fLeft, clipRect.fTop, | |
243 clipRect.fRight, clipRect.fBottom, clipOps [j], | |
244 rectCoords.count() / 4, rectCoords.begin() ); | |
245 REPORTER_ASSERT(reporter, success); | |
246 | |
247 SkCanvasStateUtils::ReleaseCanvasState(state); | |
148 } else { | 248 } else { |
149 tmpCanvas = SkRef(&canvas); | 249 complex_clips_draw(&canvas, clipRect.fLeft, clipRect.fTop, |
250 clipRect.fRight, clipRect.fBottom, clipOps[j] , | |
251 localRegion); | |
150 } | 252 } |
151 | 253 |
152 tmpCanvas->save(); | |
153 tmpCanvas->clipRect(SkRect::Make(clipRect), clipOps[j]); | |
154 tmpCanvas->drawColor(SK_ColorBLUE); | |
155 tmpCanvas->restore(); | |
156 | |
157 tmpCanvas->clipRegion(localRegion, clipOps[j]); | |
158 tmpCanvas->drawColor(SK_ColorBLUE); | |
159 | |
160 tmpCanvas->unref(); | |
161 SkCanvasStateUtils::ReleaseCanvasState(state); | |
162 | |
163 canvas.restore(); | 254 canvas.restore(); |
164 | 255 |
165 // translate the canvas and region for the next iteration | 256 // translate the canvas and region for the next iteration |
166 canvas.translate(0, SkIntToScalar(2*(layerRect.height() + (SPACER))) ); | 257 canvas.translate(0, SkIntToScalar(2*(layerRect.height() + (SPACER))) ); |
167 localRegion.translate(0, 2*(layerRect.height() + SPACER)); | 258 localRegion.translate(0, 2*(layerRect.height() + SPACER)); |
168 } | 259 } |
169 } | 260 } |
170 | 261 |
171 // now we memcmp the two bitmaps | 262 // now we memcmp the two bitmaps |
172 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); | 263 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); |
173 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), | 264 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), |
174 bitmaps[1].getPixels(), | 265 bitmaps[1].getPixels(), |
175 bitmaps[0].getSize())); | 266 bitmaps[0].getSize())); |
267 } | |
176 #endif | 268 #endif |
177 } | |
178 | 269 |
179 //////////////////////////////////////////////////////////////////////////////// | 270 //////////////////////////////////////////////////////////////////////////////// |
180 | 271 |
181 class TestDrawFilter : public SkDrawFilter { | 272 class TestDrawFilter : public SkDrawFilter { |
182 public: | 273 public: |
183 virtual bool filter(SkPaint*, Type) SK_OVERRIDE { return true; } | 274 virtual bool filter(SkPaint*, Type) SK_OVERRIDE { return true; } |
184 }; | 275 }; |
185 | 276 |
186 static void test_draw_filters(skiatest::Reporter* reporter) { | 277 DEF_TEST(CanvasState_test_draw_filters, reporter) { |
187 TestDrawFilter drawFilter; | 278 TestDrawFilter drawFilter; |
188 SkBitmap bitmap; | 279 SkBitmap bitmap; |
189 bitmap.allocN32Pixels(10, 10); | 280 bitmap.allocN32Pixels(10, 10); |
190 SkCanvas canvas(bitmap); | 281 SkCanvas canvas(bitmap); |
191 | 282 |
192 canvas.setDrawFilter(&drawFilter); | 283 canvas.setDrawFilter(&drawFilter); |
193 | 284 |
194 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 285 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
195 REPORTER_ASSERT(reporter, state); | 286 REPORTER_ASSERT(reporter, state); |
196 SkCanvas* tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); | 287 SkCanvas* tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); |
197 REPORTER_ASSERT(reporter, tmpCanvas); | 288 REPORTER_ASSERT(reporter, tmpCanvas); |
198 | 289 |
199 REPORTER_ASSERT(reporter, NULL != canvas.getDrawFilter()); | 290 REPORTER_ASSERT(reporter, NULL != canvas.getDrawFilter()); |
200 REPORTER_ASSERT(reporter, NULL == tmpCanvas->getDrawFilter()); | 291 REPORTER_ASSERT(reporter, NULL == tmpCanvas->getDrawFilter()); |
201 | 292 |
202 tmpCanvas->unref(); | 293 tmpCanvas->unref(); |
203 SkCanvasStateUtils::ReleaseCanvasState(state); | 294 SkCanvasStateUtils::ReleaseCanvasState(state); |
204 } | 295 } |
205 | 296 |
206 //////////////////////////////////////////////////////////////////////////////// | 297 //////////////////////////////////////////////////////////////////////////////// |
207 | 298 |
208 // we need this function to prevent SkError from printing to stdout | 299 // we need this function to prevent SkError from printing to stdout |
209 static void error_callback(SkError code, void* ctx) {} | 300 static void error_callback(SkError code, void* ctx) {} |
210 | 301 |
211 static void test_soft_clips(skiatest::Reporter* reporter) { | 302 DEF_TEST(CanvasState_test_soft_clips, reporter) { |
212 SkBitmap bitmap; | 303 SkBitmap bitmap; |
213 bitmap.allocN32Pixels(10, 10); | 304 bitmap.allocN32Pixels(10, 10); |
214 SkCanvas canvas(bitmap); | 305 SkCanvas canvas(bitmap); |
215 | 306 |
216 SkRRect roundRect; | 307 SkRRect roundRect; |
217 roundRect.setOval(SkRect::MakeWH(5, 5)); | 308 roundRect.setOval(SkRect::MakeWH(5, 5)); |
218 | 309 |
219 canvas.clipRRect(roundRect, SkRegion::kIntersect_Op, true); | 310 canvas.clipRRect(roundRect, SkRegion::kIntersect_Op, true); |
220 | 311 |
221 SkSetErrorCallback(error_callback, NULL); | 312 SkSetErrorCallback(error_callback, NULL); |
222 | 313 |
223 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 314 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
224 REPORTER_ASSERT(reporter, !state); | 315 REPORTER_ASSERT(reporter, !state); |
225 | 316 |
226 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); | 317 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); |
227 SkClearLastError(); | 318 SkClearLastError(); |
228 } | 319 } |
229 | 320 |
230 static void test_saveLayer_clip(skiatest::Reporter* reporter) { | |
231 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 321 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
322 DEF_TEST(CanvasState_test_saveLayer_clip, reporter) { | |
232 const int WIDTH = 100; | 323 const int WIDTH = 100; |
233 const int HEIGHT = 100; | 324 const int HEIGHT = 100; |
234 const int LAYER_WIDTH = 50; | 325 const int LAYER_WIDTH = 50; |
235 const int LAYER_HEIGHT = 50; | 326 const int LAYER_HEIGHT = 50; |
236 | 327 |
237 SkBitmap bitmap; | 328 SkBitmap bitmap; |
238 bitmap.allocN32Pixels(WIDTH, HEIGHT); | 329 bitmap.allocN32Pixels(WIDTH, HEIGHT); |
239 SkCanvas canvas(bitmap); | 330 SkCanvas canvas(bitmap); |
240 | 331 |
241 SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAY ER_HEIGHT)); | 332 SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAY ER_HEIGHT)); |
(...skipping 10 matching lines...) Expand all Loading... | |
252 canvas.restore(); | 343 canvas.restore(); |
253 | 344 |
254 // Check that saveLayer with the kClipToLayer_SaveFlag sets the clip | 345 // Check that saveLayer with the kClipToLayer_SaveFlag sets the clip |
255 // stack to the layer bounds. | 346 // stack to the layer bounds. |
256 canvas.saveLayer(&bounds, NULL, SkCanvas::kARGB_ClipLayer_SaveFlag); | 347 canvas.saveLayer(&bounds, NULL, SkCanvas::kARGB_ClipLayer_SaveFlag); |
257 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); | 348 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); |
258 REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH); | 349 REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH); |
259 REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); | 350 REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); |
260 | 351 |
261 canvas.restore(); | 352 canvas.restore(); |
353 } | |
262 #endif | 354 #endif |
263 } | |
264 | |
265 DEF_TEST(CanvasState, reporter) { | |
266 test_complex_layers(reporter); | |
267 test_complex_clips(reporter); | |
268 test_draw_filters(reporter); | |
269 test_soft_clips(reporter); | |
270 test_saveLayer_clip(reporter); | |
271 } | |
OLD | NEW |