Chromium Code Reviews| Index: tests/CanvasStateTest.cpp |
| diff --git a/tests/CanvasStateTest.cpp b/tests/CanvasStateTest.cpp |
| index d8549f63eee10b498e0b581736b038db60749638..2ae522d53b3622c3a969d6c8a73032308b1db5b4 100644 |
| --- a/tests/CanvasStateTest.cpp |
| +++ b/tests/CanvasStateTest.cpp |
| @@ -5,15 +5,27 @@ |
| * found in the LICENSE file. |
| */ |
| +#include "CanvasStateHelpers.h" |
| #include "SkCanvas.h" |
| #include "SkCanvasStateUtils.h" |
| +#include "SkCommandLineFlags.h" |
| #include "SkDrawFilter.h" |
| #include "SkError.h" |
| #include "SkPaint.h" |
| #include "SkRRect.h" |
| #include "SkRect.h" |
| +#include "SkTemplates.h" |
| #include "Test.h" |
| +#include <dlfcn.h> |
| + |
| +DEFINE_string(library, "", "Support library to use for CanvasState test. If empty (the default), " |
| + "the test will be run without crossing a library boundary. Otherwise, " |
| + "it is expected to be a full path to a shared library file, which will" |
| + " be dynamically loaded. Functions from the library will be called to " |
| + "test SkCanvasState."); |
| + |
| + |
| static void test_complex_layers(skiatest::Reporter* reporter) { |
| #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| const int WIDTH = 400; |
| @@ -35,6 +47,27 @@ static void test_complex_layers(skiatest::Reporter* reporter) { |
| }; |
| REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); |
| + bool (*drawFn)(SkCanvasState* state, float l, float t, |
| + float r, float b, int32_t s); |
| + void* handle; |
| + if (FLAGS_library.count() == 1) { |
| + handle = dlopen(FLAGS_library[0], RTLD_LAZY | RTLD_LOCAL); |
| + REPORTER_ASSERT(reporter, handle); |
| + if (!handle) { |
| + return; |
| + } |
| + *(void**) (&drawFn) = dlsym(handle, "complex_layers_draw_from_canvas_state"); |
| + } else { |
| + drawFn = complex_layers_draw_from_canvas_state; |
| + handle = NULL; |
| + } |
| + |
| + SkAutoTCallIProc<void, dlclose> autoClose(handle); |
| + REPORTER_ASSERT(reporter, drawFn); |
| + if (!drawFn) { |
| + return; |
| + } |
| + |
| for (size_t i = 0; i < SK_ARRAY_COUNT(colorTypes); ++i) { |
| SkBitmap bitmaps[2]; |
| for (int j = 0; j < 2; ++j) { |
| @@ -50,27 +83,23 @@ static void test_complex_layers(skiatest::Reporter* reporter) { |
| // draw a rect within the layer's bounds and again outside the layer's bounds |
| canvas.saveLayerAlpha(&rect, layerAlpha[k], flags[k]); |
| - SkCanvasState* state = NULL; |
| - SkCanvas* tmpCanvas = NULL; |
| if (j) { |
| - state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
| + // Capture from the first Skia. |
| + SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
| REPORTER_ASSERT(reporter, state); |
| - tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); |
| - REPORTER_ASSERT(reporter, tmpCanvas); |
| - } else { |
| - tmpCanvas = SkRef(&canvas); |
| - } |
| - SkPaint bluePaint; |
| - bluePaint.setColor(SK_ColorBLUE); |
| - bluePaint.setStyle(SkPaint::kFill_Style); |
| + // And draw to it in the second Skia. |
| + bool success = complex_layers_draw_from_canvas_state(state, |
| + rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, SPACER); |
| + REPORTER_ASSERT(reporter, success); |
| - tmpCanvas->drawRect(rect, bluePaint); |
| - tmpCanvas->translate(0, rect.height() + SPACER); |
| - tmpCanvas->drawRect(rect, bluePaint); |
| - |
| - tmpCanvas->unref(); |
| - SkCanvasStateUtils::ReleaseCanvasState(state); |
| + // And release it in the *first* Skia. |
| + SkCanvasStateUtils::ReleaseCanvasState(state); |
| + } else { |
| + // Draw in the first Skia. |
| + complex_layers_draw(&canvas, rect.fLeft, rect.fTop, |
| + rect.fRight, rect.fBottom, SPACER); |
| + } |
| canvas.restore(); |
| @@ -124,6 +153,28 @@ static void test_complex_clips(skiatest::Reporter* reporter) { |
| }; |
| REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); |
| + // Will using an SkRegion work at all? |
| + bool (*drawFn)(SkCanvasState* state, int32_t l, int32_t t, |
| + int32_t r, int32_t b, int32_t clipOp, const SkRegion*); |
| + void* handle; |
|
djsollen
2014/07/18 14:11:54
move this duplicate setup code into a function if
scroggo
2014/07/18 19:31:02
I've moved the call to dlopen into its own functio
|
| + if (FLAGS_library.count() == 1) { |
| + handle = dlopen(FLAGS_library[0], RTLD_LAZY | RTLD_LOCAL); |
| + REPORTER_ASSERT(reporter, handle); |
| + if (!handle) { |
| + return; |
| + } |
| + *(void**) (&drawFn) = dlsym(handle, "test_complex_clips_draw_from_canvas_state"); |
| + } else { |
| + drawFn = test_complex_clips_draw_from_canvas_state; |
| + handle = NULL; |
| + } |
| + |
| + SkAutoTCallIProc<void, dlclose> autoClose(handle); |
| + REPORTER_ASSERT(reporter, drawFn); |
| + if (!drawFn) { |
| + return; |
| + } |
| + |
| SkBitmap bitmaps[2]; |
| for (int i = 0; i < 2; ++i) { |
| bitmaps[i].allocN32Pixels(WIDTH, HEIGHT); |
| @@ -138,27 +189,21 @@ static void test_complex_clips(skiatest::Reporter* reporter) { |
| SkRect layerBounds = SkRect::Make(layerRect); |
| canvas.saveLayerAlpha(&layerBounds, 128, flags[j]); |
| - SkCanvasState* state = NULL; |
| - SkCanvas* tmpCanvas = NULL; |
| if (i) { |
| - state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
| + SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
| REPORTER_ASSERT(reporter, state); |
| - tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); |
| - REPORTER_ASSERT(reporter, tmpCanvas); |
| - } else { |
| - tmpCanvas = SkRef(&canvas); |
| - } |
| - |
| - tmpCanvas->save(); |
| - tmpCanvas->clipRect(SkRect::Make(clipRect), clipOps[j]); |
| - tmpCanvas->drawColor(SK_ColorBLUE); |
| - tmpCanvas->restore(); |
| - tmpCanvas->clipRegion(localRegion, clipOps[j]); |
| - tmpCanvas->drawColor(SK_ColorBLUE); |
| + bool success = drawFn(state, clipRect.fLeft, clipRect.fTop, |
| + clipRect.fRight, clipRect.fBottom, clipOps[j], |
| + &localRegion); |
|
scroggo
2014/07/17 21:32:37
Note that I'm passing a pointer to an SkRegion acr
scroggo
2014/07/18 19:31:02
Done. Thanks!
|
| + REPORTER_ASSERT(reporter, success); |
| - tmpCanvas->unref(); |
| - SkCanvasStateUtils::ReleaseCanvasState(state); |
| + SkCanvasStateUtils::ReleaseCanvasState(state); |
| + } else { |
| + test_complex_clips_draw(&canvas, clipRect.fLeft, clipRect.fTop, |
| + clipRect.fRight, clipRect.fBottom, clipOps[j], |
| + localRegion); |
| + } |
| canvas.restore(); |