| 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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkCanvasStateUtils.h" | 10 #include "SkCanvasStateUtils.h" |
| 11 #include "SkDrawFilter.h" | 11 #include "SkDrawFilter.h" |
| 12 #include "SkError.h" | 12 #include "SkError.h" |
| 13 #include "SkPaint.h" | 13 #include "SkPaint.h" |
| 14 #include "SkRRect.h" | 14 #include "SkRRect.h" |
| 15 #include "SkRect.h" | 15 #include "SkRect.h" |
| 16 #include "Test.h" | 16 #include "Test.h" |
| 17 | 17 |
| 18 static void test_complex_layers(skiatest::Reporter* reporter) { | 18 static void test_complex_layers(skiatest::Reporter* reporter) { |
| 19 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 19 const int WIDTH = 400; | 20 const int WIDTH = 400; |
| 20 const int HEIGHT = 400; | 21 const int HEIGHT = 400; |
| 21 const int SPACER = 10; | 22 const int SPACER = 10; |
| 22 | 23 |
| 23 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER), | 24 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER), |
| 24 SkIntToScalar(WIDTH-(2*SPACER)), | 25 SkIntToScalar(WIDTH-(2*SPACER)), |
| 25 SkIntToScalar((HEIGHT-(2*SPACER)) / 7)); | 26 SkIntToScalar((HEIGHT-(2*SPACER)) / 7)); |
| 26 | 27 |
| 27 const SkColorType colorTypes[] = { | 28 const SkColorType colorTypes[] = { |
| 28 kRGB_565_SkColorType, kPMColor_SkColorType | 29 kRGB_565_SkColorType, kPMColor_SkColorType |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 canvas.translate(0, 2*(rect.height() + SPACER)); | 81 canvas.translate(0, 2*(rect.height() + SPACER)); |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 | 84 |
| 84 // now we memcmp the two bitmaps | 85 // now we memcmp the two bitmaps |
| 85 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); | 86 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); |
| 86 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), | 87 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), |
| 87 bitmaps[1].getPixels(), | 88 bitmaps[1].getPixels(), |
| 88 bitmaps[0].getSize())); | 89 bitmaps[0].getSize())); |
| 89 } | 90 } |
| 91 #endif |
| 90 } | 92 } |
| 91 | 93 |
| 92 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
| 93 | 95 |
| 94 static void test_complex_clips(skiatest::Reporter* reporter) { | 96 static void test_complex_clips(skiatest::Reporter* reporter) { |
| 95 | 97 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 96 const int WIDTH = 400; | 98 const int WIDTH = 400; |
| 97 const int HEIGHT = 400; | 99 const int HEIGHT = 400; |
| 98 const int SPACER = 10; | 100 const int SPACER = 10; |
| 99 | 101 |
| 100 SkIRect layerRect = SkIRect::MakeWH(WIDTH, HEIGHT / 4); | 102 SkIRect layerRect = SkIRect::MakeWH(WIDTH, HEIGHT / 4); |
| 101 layerRect.inset(2*SPACER, 2*SPACER); | 103 layerRect.inset(2*SPACER, 2*SPACER); |
| 102 | 104 |
| 103 SkIRect clipRect = layerRect; | 105 SkIRect clipRect = layerRect; |
| 104 clipRect.fRight = clipRect.fLeft + (clipRect.width() / 2) - (2*SPACER); | 106 clipRect.fRight = clipRect.fLeft + (clipRect.width() / 2) - (2*SPACER); |
| 105 clipRect.outset(SPACER, SPACER); | 107 clipRect.outset(SPACER, SPACER); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 canvas.translate(0, SkIntToScalar(2*(layerRect.height() + (SPACER)))
); | 170 canvas.translate(0, SkIntToScalar(2*(layerRect.height() + (SPACER)))
); |
| 169 localRegion.translate(0, 2*(layerRect.height() + SPACER)); | 171 localRegion.translate(0, 2*(layerRect.height() + SPACER)); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 | 174 |
| 173 // now we memcmp the two bitmaps | 175 // now we memcmp the two bitmaps |
| 174 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); | 176 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); |
| 175 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), | 177 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), |
| 176 bitmaps[1].getPixels(), | 178 bitmaps[1].getPixels(), |
| 177 bitmaps[0].getSize())); | 179 bitmaps[0].getSize())); |
| 180 #endif |
| 178 } | 181 } |
| 179 | 182 |
| 180 //////////////////////////////////////////////////////////////////////////////// | 183 //////////////////////////////////////////////////////////////////////////////// |
| 181 | 184 |
| 182 class TestDrawFilter : public SkDrawFilter { | 185 class TestDrawFilter : public SkDrawFilter { |
| 183 public: | 186 public: |
| 184 virtual bool filter(SkPaint*, Type) SK_OVERRIDE { return true; } | 187 virtual bool filter(SkPaint*, Type) SK_OVERRIDE { return true; } |
| 185 }; | 188 }; |
| 186 | 189 |
| 187 static void test_draw_filters(skiatest::Reporter* reporter) { | 190 static void test_draw_filters(skiatest::Reporter* reporter) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 SkSetErrorCallback(error_callback, NULL); | 225 SkSetErrorCallback(error_callback, NULL); |
| 223 | 226 |
| 224 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 227 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
| 225 REPORTER_ASSERT(reporter, !state); | 228 REPORTER_ASSERT(reporter, !state); |
| 226 | 229 |
| 227 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); | 230 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); |
| 228 SkClearLastError(); | 231 SkClearLastError(); |
| 229 } | 232 } |
| 230 | 233 |
| 231 static void test_saveLayer_clip(skiatest::Reporter* reporter) { | 234 static void test_saveLayer_clip(skiatest::Reporter* reporter) { |
| 235 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 232 const int WIDTH = 100; | 236 const int WIDTH = 100; |
| 233 const int HEIGHT = 100; | 237 const int HEIGHT = 100; |
| 234 const int LAYER_WIDTH = 50; | 238 const int LAYER_WIDTH = 50; |
| 235 const int LAYER_HEIGHT = 50; | 239 const int LAYER_HEIGHT = 50; |
| 236 | 240 |
| 237 SkBitmap bitmap; | 241 SkBitmap bitmap; |
| 238 bitmap.allocN32Pixels(WIDTH, HEIGHT); | 242 bitmap.allocN32Pixels(WIDTH, HEIGHT); |
| 239 SkCanvas canvas(bitmap); | 243 SkCanvas canvas(bitmap); |
| 240 | 244 |
| 241 SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAY
ER_HEIGHT)); | 245 SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAY
ER_HEIGHT)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 252 canvas.restore(); | 256 canvas.restore(); |
| 253 | 257 |
| 254 // Check that saveLayer with the kClipToLayer_SaveFlag sets the clip | 258 // Check that saveLayer with the kClipToLayer_SaveFlag sets the clip |
| 255 // stack to the layer bounds. | 259 // stack to the layer bounds. |
| 256 canvas.saveLayer(&bounds, NULL, SkCanvas::kARGB_ClipLayer_SaveFlag); | 260 canvas.saveLayer(&bounds, NULL, SkCanvas::kARGB_ClipLayer_SaveFlag); |
| 257 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); | 261 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); |
| 258 REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH); | 262 REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH); |
| 259 REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); | 263 REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); |
| 260 | 264 |
| 261 canvas.restore(); | 265 canvas.restore(); |
| 266 #endif |
| 262 } | 267 } |
| 263 | 268 |
| 264 DEF_TEST(CanvasState, reporter) { | 269 DEF_TEST(CanvasState, reporter) { |
| 265 test_complex_layers(reporter); | 270 test_complex_layers(reporter); |
| 266 test_complex_clips(reporter); | 271 test_complex_clips(reporter); |
| 267 test_draw_filters(reporter); | 272 test_draw_filters(reporter); |
| 268 test_soft_clips(reporter); | 273 test_soft_clips(reporter); |
| 269 test_saveLayer_clip(reporter); | 274 test_saveLayer_clip(reporter); |
| 270 } | 275 } |
| OLD | NEW |