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 "CanvasStateHelpers.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCanvasStateUtils.h" | 10 #include "SkCanvasStateUtils.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // This class calls dlopen on the library passed in to the command line flag lib
rary, and handles | 31 // This class calls dlopen on the library passed in to the command line flag lib
rary, and handles |
32 // calling dlclose when it goes out of scope. | 32 // calling dlclose when it goes out of scope. |
33 class OpenLibResult { | 33 class OpenLibResult { |
34 public: | 34 public: |
35 // If the flag library was passed to this run of the test, attempt to open i
t using dlopen and | 35 // If the flag library was passed to this run of the test, attempt to open i
t using dlopen and |
36 // report whether it succeeded. | 36 // report whether it succeeded. |
37 OpenLibResult(skiatest::Reporter* reporter) { | 37 OpenLibResult(skiatest::Reporter* reporter) { |
38 if (FLAGS_library.count() == 1) { | 38 if (FLAGS_library.count() == 1) { |
39 fHandle = dlopen(FLAGS_library[0], RTLD_LAZY | RTLD_LOCAL); | 39 fHandle = dlopen(FLAGS_library[0], RTLD_LAZY | RTLD_LOCAL); |
40 REPORTER_ASSERT_MESSAGE(reporter, fHandle != NULL, "Failed to open l
ibrary!"); | 40 REPORTER_ASSERT_MESSAGE(reporter, fHandle != nullptr, "Failed to ope
n library!"); |
41 } else { | 41 } else { |
42 fHandle = NULL; | 42 fHandle = nullptr; |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 // Automatically call dlclose when going out of scope. | 46 // Automatically call dlclose when going out of scope. |
47 ~OpenLibResult() { | 47 ~OpenLibResult() { |
48 if (fHandle) { | 48 if (fHandle) { |
49 dlclose(fHandle); | 49 dlclose(fHandle); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
(...skipping 21 matching lines...) Expand all Loading... |
74 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, | 74 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, |
75 SkCanvas::kARGB_ClipLayer_SaveFlag, | 75 SkCanvas::kARGB_ClipLayer_SaveFlag, |
76 SkCanvas::kARGB_NoClipLayer_SaveFlag | 76 SkCanvas::kARGB_NoClipLayer_SaveFlag |
77 }; | 77 }; |
78 REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); | 78 REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); |
79 | 79 |
80 bool (*drawFn)(SkCanvasState* state, float l, float t, | 80 bool (*drawFn)(SkCanvasState* state, float l, float t, |
81 float r, float b, int32_t s); | 81 float r, float b, int32_t s); |
82 | 82 |
83 OpenLibResult openLibResult(reporter); | 83 OpenLibResult openLibResult(reporter); |
84 if (openLibResult.handle() != NULL) { | 84 if (openLibResult.handle() != nullptr) { |
85 *(void**) (&drawFn) = dlsym(openLibResult.handle(), | 85 *(void**) (&drawFn) = dlsym(openLibResult.handle(), |
86 "complex_layers_draw_from_canvas_state"); | 86 "complex_layers_draw_from_canvas_state"); |
87 } else { | 87 } else { |
88 drawFn = complex_layers_draw_from_canvas_state; | 88 drawFn = complex_layers_draw_from_canvas_state; |
89 } | 89 } |
90 | 90 |
91 REPORTER_ASSERT(reporter, drawFn); | 91 REPORTER_ASSERT(reporter, drawFn); |
92 if (!drawFn) { | 92 if (!drawFn) { |
93 return; | 93 return; |
94 } | 94 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 SkCanvas::kARGB_ClipLayer_SaveFlag, | 176 SkCanvas::kARGB_ClipLayer_SaveFlag, |
177 SkCanvas::kARGB_NoClipLayer_SaveFlag, | 177 SkCanvas::kARGB_NoClipLayer_SaveFlag, |
178 }; | 178 }; |
179 REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); | 179 REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); |
180 | 180 |
181 bool (*drawFn)(SkCanvasState* state, int32_t l, int32_t t, | 181 bool (*drawFn)(SkCanvasState* state, int32_t l, int32_t t, |
182 int32_t r, int32_t b, int32_t clipOp, | 182 int32_t r, int32_t b, int32_t clipOp, |
183 int32_t regionRects, int32_t* rectCoords); | 183 int32_t regionRects, int32_t* rectCoords); |
184 | 184 |
185 OpenLibResult openLibResult(reporter); | 185 OpenLibResult openLibResult(reporter); |
186 if (openLibResult.handle() != NULL) { | 186 if (openLibResult.handle() != nullptr) { |
187 *(void**) (&drawFn) = dlsym(openLibResult.handle(), | 187 *(void**) (&drawFn) = dlsym(openLibResult.handle(), |
188 "complex_clips_draw_from_canvas_state"); | 188 "complex_clips_draw_from_canvas_state"); |
189 } else { | 189 } else { |
190 drawFn = complex_clips_draw_from_canvas_state; | 190 drawFn = complex_clips_draw_from_canvas_state; |
191 } | 191 } |
192 | 192 |
193 REPORTER_ASSERT(reporter, drawFn); | 193 REPORTER_ASSERT(reporter, drawFn); |
194 if (!drawFn) { | 194 if (!drawFn) { |
195 return; | 195 return; |
196 } | 196 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 SkCanvas canvas(bitmap); | 264 SkCanvas canvas(bitmap); |
265 | 265 |
266 canvas.setDrawFilter(&drawFilter); | 266 canvas.setDrawFilter(&drawFilter); |
267 | 267 |
268 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 268 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
269 REPORTER_ASSERT(reporter, state); | 269 REPORTER_ASSERT(reporter, state); |
270 SkCanvas* tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); | 270 SkCanvas* tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); |
271 REPORTER_ASSERT(reporter, tmpCanvas); | 271 REPORTER_ASSERT(reporter, tmpCanvas); |
272 | 272 |
273 REPORTER_ASSERT(reporter, canvas.getDrawFilter()); | 273 REPORTER_ASSERT(reporter, canvas.getDrawFilter()); |
274 REPORTER_ASSERT(reporter, NULL == tmpCanvas->getDrawFilter()); | 274 REPORTER_ASSERT(reporter, nullptr == tmpCanvas->getDrawFilter()); |
275 | 275 |
276 tmpCanvas->unref(); | 276 tmpCanvas->unref(); |
277 SkCanvasStateUtils::ReleaseCanvasState(state); | 277 SkCanvasStateUtils::ReleaseCanvasState(state); |
278 } | 278 } |
279 | 279 |
280 //////////////////////////////////////////////////////////////////////////////// | 280 //////////////////////////////////////////////////////////////////////////////// |
281 | 281 |
282 // we need this function to prevent SkError from printing to stdout | 282 // we need this function to prevent SkError from printing to stdout |
283 static void error_callback(SkError code, void* ctx) {} | 283 static void error_callback(SkError code, void* ctx) {} |
284 | 284 |
285 DEF_TEST(CanvasState_test_soft_clips, reporter) { | 285 DEF_TEST(CanvasState_test_soft_clips, reporter) { |
286 SkBitmap bitmap; | 286 SkBitmap bitmap; |
287 bitmap.allocN32Pixels(10, 10); | 287 bitmap.allocN32Pixels(10, 10); |
288 SkCanvas canvas(bitmap); | 288 SkCanvas canvas(bitmap); |
289 | 289 |
290 SkRRect roundRect; | 290 SkRRect roundRect; |
291 roundRect.setOval(SkRect::MakeWH(5, 5)); | 291 roundRect.setOval(SkRect::MakeWH(5, 5)); |
292 | 292 |
293 canvas.clipRRect(roundRect, SkRegion::kIntersect_Op, true); | 293 canvas.clipRRect(roundRect, SkRegion::kIntersect_Op, true); |
294 | 294 |
295 SkSetErrorCallback(error_callback, NULL); | 295 SkSetErrorCallback(error_callback, nullptr); |
296 | 296 |
297 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 297 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
298 REPORTER_ASSERT(reporter, !state); | 298 REPORTER_ASSERT(reporter, !state); |
299 | 299 |
300 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); | 300 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); |
301 SkClearLastError(); | 301 SkClearLastError(); |
302 } | 302 } |
303 | 303 |
304 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 304 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
305 #include "SkClipStack.h" | 305 #include "SkClipStack.h" |
306 DEF_TEST(CanvasState_test_saveLayer_clip, reporter) { | 306 DEF_TEST(CanvasState_test_saveLayer_clip, reporter) { |
307 const int WIDTH = 100; | 307 const int WIDTH = 100; |
308 const int HEIGHT = 100; | 308 const int HEIGHT = 100; |
309 const int LAYER_WIDTH = 50; | 309 const int LAYER_WIDTH = 50; |
310 const int LAYER_HEIGHT = 50; | 310 const int LAYER_HEIGHT = 50; |
311 | 311 |
312 SkBitmap bitmap; | 312 SkBitmap bitmap; |
313 bitmap.allocN32Pixels(WIDTH, HEIGHT); | 313 bitmap.allocN32Pixels(WIDTH, HEIGHT); |
314 SkCanvas canvas(bitmap); | 314 SkCanvas canvas(bitmap); |
315 | 315 |
316 SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAY
ER_HEIGHT)); | 316 SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAY
ER_HEIGHT)); |
317 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)))
; | 317 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)))
; |
318 | 318 |
319 // Check that saveLayer without the kClipToLayer_SaveFlag leaves the | 319 // Check that saveLayer without the kClipToLayer_SaveFlag leaves the |
320 // clip stack unchanged. | 320 // clip stack unchanged. |
321 canvas.saveLayer(&bounds, NULL, SkCanvas::kARGB_NoClipLayer_SaveFlag); | 321 canvas.saveLayer(&bounds, nullptr, SkCanvas::kARGB_NoClipLayer_SaveFlag); |
322 SkRect clipStackBounds; | 322 SkRect clipStackBounds; |
323 SkClipStack::BoundsType boundsType; | 323 SkClipStack::BoundsType boundsType; |
324 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); | 324 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); |
325 REPORTER_ASSERT(reporter, clipStackBounds.width() == WIDTH); | 325 REPORTER_ASSERT(reporter, clipStackBounds.width() == WIDTH); |
326 REPORTER_ASSERT(reporter, clipStackBounds.height() == HEIGHT); | 326 REPORTER_ASSERT(reporter, clipStackBounds.height() == HEIGHT); |
327 canvas.restore(); | 327 canvas.restore(); |
328 | 328 |
329 // Check that saveLayer with the kClipToLayer_SaveFlag sets the clip | 329 // Check that saveLayer with the kClipToLayer_SaveFlag sets the clip |
330 // stack to the layer bounds. | 330 // stack to the layer bounds. |
331 canvas.saveLayer(&bounds, NULL, SkCanvas::kARGB_ClipLayer_SaveFlag); | 331 canvas.saveLayer(&bounds, nullptr, SkCanvas::kARGB_ClipLayer_SaveFlag); |
332 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); | 332 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); |
333 REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH); | 333 REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH); |
334 REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); | 334 REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); |
335 | 335 |
336 canvas.restore(); | 336 canvas.restore(); |
337 } | 337 } |
338 #endif | 338 #endif |
OLD | NEW |