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