OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "Test.h" | 9 #include "Test.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkCanvasStateUtils.h" | 12 #include "SkCanvasStateUtils.h" |
13 #include "SkDrawFilter.h" | 13 #include "SkDrawFilter.h" |
| 14 #include "SkError.h" |
14 #include "SkPaint.h" | 15 #include "SkPaint.h" |
15 #include "SkRect.h" | 16 #include "SkRect.h" |
16 #include "SkRRect.h" | 17 #include "SkRRect.h" |
17 | 18 |
18 static void test_complex_layers(skiatest::Reporter* reporter) { | 19 static void test_complex_layers(skiatest::Reporter* reporter) { |
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), |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 199 |
199 REPORTER_ASSERT(reporter, NULL != canvas.getDrawFilter()); | 200 REPORTER_ASSERT(reporter, NULL != canvas.getDrawFilter()); |
200 REPORTER_ASSERT(reporter, NULL == tmpCanvas->getDrawFilter()); | 201 REPORTER_ASSERT(reporter, NULL == tmpCanvas->getDrawFilter()); |
201 | 202 |
202 tmpCanvas->unref(); | 203 tmpCanvas->unref(); |
203 SkCanvasStateUtils::ReleaseCanvasState(state); | 204 SkCanvasStateUtils::ReleaseCanvasState(state); |
204 } | 205 } |
205 | 206 |
206 //////////////////////////////////////////////////////////////////////////////// | 207 //////////////////////////////////////////////////////////////////////////////// |
207 | 208 |
| 209 // we need this function to prevent SkError from printing to stdout |
| 210 static void error_callback(SkError code, void* ctx) {} |
| 211 |
208 static void test_soft_clips(skiatest::Reporter* reporter) { | 212 static void test_soft_clips(skiatest::Reporter* reporter) { |
209 SkBitmapDevice device(SkBitmap::kARGB_8888_Config, 10, 10); | 213 SkBitmapDevice device(SkBitmap::kARGB_8888_Config, 10, 10); |
210 SkCanvas canvas(&device); | 214 SkCanvas canvas(&device); |
211 | 215 |
212 SkRRect roundRect; | 216 SkRRect roundRect; |
213 roundRect.setOval(SkRect::MakeWH(5, 5)); | 217 roundRect.setOval(SkRect::MakeWH(5, 5)); |
214 | 218 |
215 canvas.clipRRect(roundRect, SkRegion::kIntersect_Op, true); | 219 canvas.clipRRect(roundRect, SkRegion::kIntersect_Op, true); |
216 | 220 |
| 221 SkSetErrorCallback(error_callback, NULL); |
| 222 |
217 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 223 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
218 REPORTER_ASSERT(reporter, !state); | 224 REPORTER_ASSERT(reporter, !state); |
| 225 |
| 226 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); |
| 227 SkClearLastError(); |
219 } | 228 } |
220 | 229 |
221 //////////////////////////////////////////////////////////////////////////////// | 230 //////////////////////////////////////////////////////////////////////////////// |
222 | 231 |
223 static void test_canvas_state_utils(skiatest::Reporter* reporter) { | 232 static void test_canvas_state_utils(skiatest::Reporter* reporter) { |
224 test_complex_layers(reporter); | 233 test_complex_layers(reporter); |
225 test_complex_clips(reporter); | 234 test_complex_clips(reporter); |
226 test_draw_filters(reporter); | 235 test_draw_filters(reporter); |
227 test_soft_clips(reporter); | 236 test_soft_clips(reporter); |
228 } | 237 } |
229 | 238 |
230 #include "TestClassDef.h" | 239 #include "TestClassDef.h" |
231 DEFINE_TESTCLASS("CanvasState", TestCanvasStateClass, test_canvas_state_utils) | 240 DEFINE_TESTCLASS("CanvasState", TestCanvasStateClass, test_canvas_state_utils) |
OLD | NEW |