reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 1 | /* |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 2 | * Copyright 2012 Google Inc. |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 7 | |
| 8 | /* Description: |
| 9 | * This test defines a series of elementatry test steps that perform |
| 10 | * a single or a small group of canvas API calls. Each test step is |
| 11 | * used in several test cases that verify that different types of SkCanvas |
| 12 | * flavors and derivatives pass it and yield consistent behavior. The |
| 13 | * test cases analyse results that are queryable through the API. They do |
| 14 | * not look at rendering results. |
| 15 | * |
| 16 | * Adding test stepss: |
| 17 | * The general pattern for creating a new test step is to write a test |
| 18 | * function of the form: |
| 19 | * |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 20 | * static void MyTestStepFunction(SkCanvas* canvas, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 21 | * skiatest::Reporter* reporter, |
| 22 | * CanvasTestStep* testStep) |
| 23 | * { |
| 24 | * canvas->someCanvasAPImethod(); |
| 25 | * (...) |
| 26 | * REPORTER_ASSERT_MESSAGE(reporter, (...), \ |
| 27 | * testStep->assertMessage()); |
| 28 | * } |
| 29 | * |
| 30 | * The definition of the test step function should be followed by an |
| 31 | * invocation of the TEST_STEP macro, which generates a class and |
| 32 | * instance for the test step: |
| 33 | * |
| 34 | * TEST_STEP(MyTestStep, MyTestStepFunction) |
| 35 | * |
| 36 | * There are also short hand macros for defining simple test steps |
| 37 | * in a single line of code. A simple test step is a one that is made |
| 38 | * of a single canvas API call. |
| 39 | * |
| 40 | * SIMPLE_TEST_STEP(MytestStep, someCanvasAPIMethod()); |
| 41 | * |
| 42 | * There is another macro called SIMPLE_TEST_STEP_WITH_ASSERT that |
| 43 | * works the same way as SIMPLE_TEST_STEP, and additionally verifies |
| 44 | * that the invoked method returns a non-zero value. |
| 45 | */ |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 46 | #include "SkBitmap.h" |
| 47 | #include "SkCanvas.h" |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 48 | #include "SkDeferredCanvas.h" |
| 49 | #include "SkDevice.h" |
| 50 | #include "SkMatrix.h" |
| 51 | #include "SkNWayCanvas.h" |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 52 | #include "SkPDFDevice.h" |
| 53 | #include "SkPDFDocument.h" |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 54 | #include "SkPaint.h" |
| 55 | #include "SkPath.h" |
| 56 | #include "SkPicture.h" |
| 57 | #include "SkPictureRecord.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 58 | #include "SkPictureRecorder.h" |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 59 | #include "SkProxyCanvas.h" |
| 60 | #include "SkRect.h" |
| 61 | #include "SkRegion.h" |
| 62 | #include "SkShader.h" |
| 63 | #include "SkStream.h" |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 64 | #include "SkSurface.h" |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 65 | #include "SkTDArray.h" |
| 66 | #include "Test.h" |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 67 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 68 | static const int kWidth = 2, kHeight = 2; |
| 69 | |
| 70 | static void createBitmap(SkBitmap* bm, SkColor color) { |
| 71 | bm->allocN32Pixels(kWidth, kHeight); |
| 72 | bm->eraseColor(color); |
| 73 | } |
| 74 | |
| 75 | static SkSurface* createSurface(SkColor color) { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 76 | SkSurface* surface = SkSurface::NewRasterN32Premul(kWidth, kHeight); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 77 | surface->getCanvas()->clear(color); |
| 78 | return surface; |
| 79 | } |
| 80 | |
| 81 | /////////////////////////////////////////////////////////////////////////////// |
| 82 | // Constants used by test steps |
| 83 | const SkPoint kTestPoints[] = { |
| 84 | {SkIntToScalar(0), SkIntToScalar(0)}, |
| 85 | {SkIntToScalar(2), SkIntToScalar(1)}, |
| 86 | {SkIntToScalar(0), SkIntToScalar(2)} |
| 87 | }; |
| 88 | const SkPoint kTestPoints2[] = { |
| 89 | { SkIntToScalar(0), SkIntToScalar(1) }, |
| 90 | { SkIntToScalar(1), SkIntToScalar(1) }, |
| 91 | { SkIntToScalar(2), SkIntToScalar(1) }, |
| 92 | { SkIntToScalar(3), SkIntToScalar(1) }, |
| 93 | { SkIntToScalar(4), SkIntToScalar(1) }, |
| 94 | { SkIntToScalar(5), SkIntToScalar(1) }, |
| 95 | { SkIntToScalar(6), SkIntToScalar(1) }, |
| 96 | { SkIntToScalar(7), SkIntToScalar(1) }, |
| 97 | { SkIntToScalar(8), SkIntToScalar(1) }, |
| 98 | { SkIntToScalar(9), SkIntToScalar(1) }, |
| 99 | { SkIntToScalar(10), SkIntToScalar(1) } |
| 100 | }; |
| 101 | |
| 102 | struct TestData { |
| 103 | public: |
| 104 | TestData() |
| 105 | : fRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 106 | SkIntToScalar(2), SkIntToScalar(1))) |
| 107 | , fMatrix(TestMatrix()) |
| 108 | , fPath(TestPath()) |
| 109 | , fNearlyZeroLengthPath(TestNearlyZeroLengthPath()) |
| 110 | , fIRect(SkIRect::MakeXYWH(0, 0, 2, 1)) |
| 111 | , fRegion(TestRegion()) |
| 112 | , fColor(0x01020304) |
| 113 | , fPoints(kTestPoints) |
| 114 | , fPointCount(3) |
| 115 | , fWidth(2) |
| 116 | , fHeight(2) |
| 117 | , fText("Hello World") |
| 118 | , fPoints2(kTestPoints2) |
| 119 | , fBitmap(TestBitmap()) |
| 120 | { } |
| 121 | |
| 122 | SkRect fRect; |
| 123 | SkMatrix fMatrix;; |
| 124 | SkPath fPath; |
| 125 | SkPath fNearlyZeroLengthPath; |
| 126 | SkIRect fIRect; |
| 127 | SkRegion fRegion; |
| 128 | SkColor fColor; |
| 129 | SkPaint fPaint; |
| 130 | const SkPoint* fPoints; |
| 131 | size_t fPointCount; |
| 132 | int fWidth; |
| 133 | int fHeight; |
| 134 | SkString fText; |
| 135 | const SkPoint* fPoints2; |
| 136 | SkBitmap fBitmap; |
| 137 | |
| 138 | private: |
| 139 | static SkMatrix TestMatrix() { |
| 140 | SkMatrix matrix; |
| 141 | matrix.reset(); |
| 142 | matrix.setScale(SkIntToScalar(2), SkIntToScalar(3)); |
| 143 | |
| 144 | return matrix; |
| 145 | } |
| 146 | static SkPath TestPath() { |
| 147 | SkPath path; |
| 148 | path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 149 | SkIntToScalar(2), SkIntToScalar(1))); |
| 150 | return path; |
| 151 | } |
| 152 | static SkPath TestNearlyZeroLengthPath() { |
| 153 | SkPath path; |
| 154 | SkPoint pt1 = { 0, 0 }; |
| 155 | SkPoint pt2 = { 0, SK_ScalarNearlyZero }; |
| 156 | SkPoint pt3 = { SkIntToScalar(1), 0 }; |
| 157 | SkPoint pt4 = { SkIntToScalar(1), SK_ScalarNearlyZero/2 }; |
| 158 | path.moveTo(pt1); |
| 159 | path.lineTo(pt2); |
| 160 | path.lineTo(pt3); |
| 161 | path.lineTo(pt4); |
| 162 | return path; |
| 163 | } |
| 164 | static SkRegion TestRegion() { |
| 165 | SkRegion region; |
| 166 | SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1); |
| 167 | region.setRect(rect); |
| 168 | return region; |
| 169 | } |
| 170 | static SkBitmap TestBitmap() { |
| 171 | SkBitmap bitmap; |
| 172 | createBitmap(&bitmap, 0x05060708); |
| 173 | return bitmap; |
| 174 | } |
| 175 | }; |
| 176 | |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 177 | static bool equal_clips(const SkCanvas& a, const SkCanvas& b) { |
| 178 | if (a.isClipEmpty()) { |
| 179 | return b.isClipEmpty(); |
| 180 | } |
| 181 | if (!a.isClipRect()) { |
| 182 | // this is liberally true, since we don't expose a way to know this exactly (for non-rects) |
| 183 | return !b.isClipRect(); |
| 184 | } |
| 185 | SkIRect ar, br; |
| 186 | a.getClipDeviceBounds(&ar); |
| 187 | b.getClipDeviceBounds(&br); |
| 188 | return ar == br; |
| 189 | } |
| 190 | |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 191 | class Canvas2CanvasClipVisitor : public SkCanvas::ClipVisitor { |
| 192 | public: |
| 193 | Canvas2CanvasClipVisitor(SkCanvas* target) : fTarget(target) {} |
| 194 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 195 | void clipRect(const SkRect& r, SkRegion::Op op, bool aa) SK_OVERRIDE { |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 196 | fTarget->clipRect(r, op, aa); |
| 197 | } |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 198 | void clipRRect(const SkRRect& r, SkRegion::Op op, bool aa) SK_OVERRIDE { |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 199 | fTarget->clipRRect(r, op, aa); |
| 200 | } |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 201 | void clipPath(const SkPath& p, SkRegion::Op op, bool aa) SK_OVERRIDE { |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 202 | fTarget->clipPath(p, op, aa); |
| 203 | } |
| 204 | |
| 205 | private: |
| 206 | SkCanvas* fTarget; |
| 207 | }; |
| 208 | |
| 209 | static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) { |
| 210 | SkISize size = canvas->getDeviceSize(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 211 | |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 212 | SkBitmap bm; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 213 | bm.setInfo(SkImageInfo::MakeN32Premul(size.width(), size.height())); |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 214 | SkCanvas c(bm); |
| 215 | |
| 216 | Canvas2CanvasClipVisitor visitor(&c); |
| 217 | canvas->replayClips(&visitor); |
| 218 | |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 219 | REPORTER_ASSERT(reporter, equal_clips(c, *canvas)); |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 220 | } |
| 221 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 222 | // Format strings that describe the test context. The %s token is where |
| 223 | // the name of the test step is inserted. The context is required for |
| 224 | // disambiguating the error in the case of failures that are reported in |
| 225 | // functions that are called multiple times in different contexts (test |
| 226 | // cases and test steps). |
| 227 | static const char* const kDefaultAssertMessageFormat = "%s"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 228 | static const char* const kCanvasDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 229 | "Drawing test step %s with SkCanvas"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 230 | static const char* const kDeferredDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 231 | "Drawing test step %s with SkDeferredCanvas"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 232 | static const char* const kProxyDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 233 | "Drawing test step %s with SkProxyCanvas"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 234 | static const char* const kNWayDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 235 | "Drawing test step %s with SkNWayCanvas"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 236 | static const char* const kDeferredPreFlushAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 237 | "test step %s, SkDeferredCanvas state consistency before flush"; |
junov@chromium.org | cff01c5 | 2012-07-18 21:50:26 +0000 | [diff] [blame] | 238 | static const char* const kDeferredPostFlushPlaybackAssertMessageFormat = |
| 239 | "test step %s, SkDeferredCanvas playback canvas state consistency after flush"; |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 240 | static const char* const kDeferredPostSilentFlushPlaybackAssertMessageFormat = |
| 241 | "test step %s, SkDeferredCanvas playback canvas state consistency after silent flush"; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 242 | static const char* const kProxyStateAssertMessageFormat = |
| 243 | "test step %s, SkProxyCanvas state consistency"; |
| 244 | static const char* const kProxyIndirectStateAssertMessageFormat = |
| 245 | "test step %s, SkProxyCanvas indirect canvas state consistency"; |
| 246 | static const char* const kNWayStateAssertMessageFormat = |
| 247 | "test step %s, SkNWayCanvas state consistency"; |
| 248 | static const char* const kNWayIndirect1StateAssertMessageFormat = |
| 249 | "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; |
| 250 | static const char* const kNWayIndirect2StateAssertMessageFormat = |
| 251 | "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 252 | static const char* const kPdfAssertMessageFormat = |
| 253 | "PDF sanity check failed %s"; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 254 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 255 | class CanvasTestStep; |
| 256 | static SkTDArray<CanvasTestStep*>& testStepArray() { |
| 257 | static SkTDArray<CanvasTestStep*> theTests; |
| 258 | return theTests; |
| 259 | } |
| 260 | |
| 261 | class CanvasTestStep { |
| 262 | public: |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 263 | CanvasTestStep(bool fEnablePdfTesting = true) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 264 | *testStepArray().append() = this; |
| 265 | fAssertMessageFormat = kDefaultAssertMessageFormat; |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 266 | this->fEnablePdfTesting = fEnablePdfTesting; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 267 | } |
djsollen@google.com | e63793a | 2012-03-21 15:39:03 +0000 | [diff] [blame] | 268 | virtual ~CanvasTestStep() { } |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 269 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 270 | virtual void draw(SkCanvas*, const TestData&, skiatest::Reporter*) = 0; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 271 | virtual const char* name() const = 0; |
| 272 | |
| 273 | const char* assertMessage() { |
| 274 | fAssertMessage.printf(fAssertMessageFormat, name()); |
| 275 | return fAssertMessage.c_str(); |
| 276 | } |
| 277 | |
| 278 | void setAssertMessageFormat(const char* format) { |
| 279 | fAssertMessageFormat = format; |
| 280 | } |
| 281 | |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 282 | bool enablePdfTesting() { return fEnablePdfTesting; } |
| 283 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 284 | private: |
| 285 | SkString fAssertMessage; |
| 286 | const char* fAssertMessageFormat; |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 287 | bool fEnablePdfTesting; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | /////////////////////////////////////////////////////////////////////////////// |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 291 | // Macros for defining test steps |
| 292 | |
| 293 | #define TEST_STEP(NAME, FUNCTION) \ |
| 294 | class NAME##_TestStep : public CanvasTestStep{ \ |
| 295 | public: \ |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 296 | virtual void draw(SkCanvas* canvas, const TestData& d, \ |
| 297 | skiatest::Reporter* reporter) { \ |
| 298 | FUNCTION (canvas, d, reporter, this); \ |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 299 | } \ |
| 300 | virtual const char* name() const {return #NAME ;} \ |
| 301 | }; \ |
| 302 | static NAME##_TestStep NAME##_TestStepInstance; |
| 303 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 304 | #define TEST_STEP_NO_PDF(NAME, FUNCTION) \ |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 305 | class NAME##_TestStep : public CanvasTestStep{ \ |
| 306 | public: \ |
| 307 | NAME##_TestStep() : CanvasTestStep(false) {} \ |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 308 | virtual void draw(SkCanvas* canvas, const TestData& d, \ |
| 309 | skiatest::Reporter* reporter) { \ |
| 310 | FUNCTION (canvas, d, reporter, this); \ |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 311 | } \ |
| 312 | virtual const char* name() const {return #NAME ;} \ |
| 313 | }; \ |
| 314 | static NAME##_TestStep NAME##_TestStepInstance; |
| 315 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 316 | #define SIMPLE_TEST_STEP(NAME, CALL) \ |
| 317 | static void NAME##TestStep(SkCanvas* canvas, const TestData& d, \ |
| 318 | skiatest::Reporter*, CanvasTestStep*) { \ |
| 319 | canvas-> CALL ; \ |
| 320 | } \ |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 321 | TEST_STEP(NAME, NAME##TestStep ) |
| 322 | |
| 323 | #define SIMPLE_TEST_STEP_WITH_ASSERT(NAME, CALL) \ |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 324 | static void NAME##TestStep(SkCanvas* canvas, const TestData& d, \ |
| 325 | skiatest::Reporter*, CanvasTestStep* testStep) { \ |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 326 | REPORTER_ASSERT_MESSAGE(reporter, canvas-> CALL , \ |
| 327 | testStep->assertMessage()); \ |
| 328 | } \ |
| 329 | TEST_STEP(NAME, NAME##TestStep ) |
| 330 | |
| 331 | |
| 332 | /////////////////////////////////////////////////////////////////////////////// |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 333 | // Basic test steps for most virtual methods in SkCanvas that draw or affect |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 334 | // the state of the canvas. |
| 335 | |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 336 | SIMPLE_TEST_STEP(Translate, translate(SkIntToScalar(1), SkIntToScalar(2))); |
| 337 | SIMPLE_TEST_STEP(Scale, scale(SkIntToScalar(1), SkIntToScalar(2))); |
| 338 | SIMPLE_TEST_STEP(Rotate, rotate(SkIntToScalar(1))); |
| 339 | SIMPLE_TEST_STEP(Skew, skew(SkIntToScalar(1), SkIntToScalar(2))); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 340 | SIMPLE_TEST_STEP(Concat, concat(d.fMatrix)); |
| 341 | SIMPLE_TEST_STEP(SetMatrix, setMatrix(d.fMatrix)); |
| 342 | SIMPLE_TEST_STEP(ClipRect, clipRect(d.fRect)); |
| 343 | SIMPLE_TEST_STEP(ClipPath, clipPath(d.fPath)); |
| 344 | SIMPLE_TEST_STEP(ClipRegion, clipRegion(d.fRegion, SkRegion::kReplace_Op)); |
| 345 | SIMPLE_TEST_STEP(Clear, clear(d.fColor)); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 346 | SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(d.fText.c_str())); |
| 347 | SIMPLE_TEST_STEP(AddComment, addComment(d.fText.c_str(), d.fText.c_str())); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 348 | SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 349 | |
| 350 | /////////////////////////////////////////////////////////////////////////////// |
| 351 | // Complex test steps |
| 352 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 353 | static void SaveMatrixClipStep(SkCanvas* canvas, const TestData& d, |
| 354 | skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 355 | int saveCount = canvas->getSaveCount(); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 356 | canvas->save(); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 357 | canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 358 | canvas->clipRegion(d.fRegion); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 359 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 360 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 361 | testStep->assertMessage()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 362 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 363 | testStep->assertMessage()); |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 364 | // REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, testStep->assertMessage()); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 365 | } |
| 366 | TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); |
| 367 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 368 | static void SaveLayerStep(SkCanvas* canvas, const TestData& d, |
| 369 | skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 370 | int saveCount = canvas->getSaveCount(); |
| 371 | canvas->saveLayer(NULL, NULL); |
| 372 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 373 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 374 | testStep->assertMessage()); |
| 375 | } |
| 376 | TEST_STEP(SaveLayer, SaveLayerStep); |
| 377 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 378 | static void BoundedSaveLayerStep(SkCanvas* canvas, const TestData& d, |
| 379 | skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 380 | int saveCount = canvas->getSaveCount(); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 381 | canvas->saveLayer(&d.fRect, NULL); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 382 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 383 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 384 | testStep->assertMessage()); |
| 385 | } |
| 386 | TEST_STEP(BoundedSaveLayer, BoundedSaveLayerStep); |
| 387 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 388 | static void PaintSaveLayerStep(SkCanvas* canvas, const TestData& d, |
| 389 | skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 390 | int saveCount = canvas->getSaveCount(); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 391 | canvas->saveLayer(NULL, &d.fPaint); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 392 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 393 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 394 | testStep->assertMessage()); |
| 395 | } |
| 396 | TEST_STEP(PaintSaveLayer, PaintSaveLayerStep); |
| 397 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 398 | static void TwoClipOpsStep(SkCanvas* canvas, const TestData& d, |
| 399 | skiatest::Reporter*, CanvasTestStep*) { |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 400 | // This test exercises a functionality in SkPicture that leads to the |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 401 | // recording of restore offset placeholders. This test will trigger an |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 402 | // assertion at playback time if the placeholders are not properly |
| 403 | // filled when the recording ends. |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 404 | canvas->clipRect(d.fRect); |
| 405 | canvas->clipRegion(d.fRegion); |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 406 | } |
| 407 | TEST_STEP(TwoClipOps, TwoClipOpsStep); |
| 408 | |
epoger@google.com | 94fa43c | 2012-04-11 17:51:01 +0000 | [diff] [blame] | 409 | // exercise fix for http://code.google.com/p/skia/issues/detail?id=560 |
| 410 | // ('SkPathStroker::lineTo() fails for line with length SK_ScalarNearlyZero') |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 411 | static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas, const TestData& d, |
| 412 | skiatest::Reporter*, CanvasTestStep*) { |
epoger@google.com | 94fa43c | 2012-04-11 17:51:01 +0000 | [diff] [blame] | 413 | SkPaint paint; |
| 414 | paint.setStrokeWidth(SkIntToScalar(1)); |
| 415 | paint.setStyle(SkPaint::kStroke_Style); |
| 416 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 417 | canvas->drawPath(d.fNearlyZeroLengthPath, paint); |
epoger@google.com | 94fa43c | 2012-04-11 17:51:01 +0000 | [diff] [blame] | 418 | } |
| 419 | TEST_STEP(DrawNearlyZeroLengthPath, DrawNearlyZeroLengthPathTestStep); |
| 420 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 421 | static void DrawVerticesShaderTestStep(SkCanvas* canvas, const TestData& d, |
| 422 | skiatest::Reporter*, CanvasTestStep*) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 423 | SkPoint pts[4]; |
| 424 | pts[0].set(0, 0); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 425 | pts[1].set(SkIntToScalar(d.fWidth), 0); |
| 426 | pts[2].set(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight)); |
| 427 | pts[3].set(0, SkIntToScalar(d.fHeight)); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 428 | SkPaint paint; |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 429 | SkShader* shader = SkShader::CreateBitmapShader(d.fBitmap, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 430 | SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| 431 | paint.setShader(shader)->unref(); |
| 432 | canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, |
| 433 | NULL, NULL, NULL, 0, paint); |
| 434 | } |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 435 | // NYI: issue 240. |
| 436 | TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 437 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 438 | static void DrawPictureTestStep(SkCanvas* canvas, const TestData& d, |
| 439 | skiatest::Reporter*, CanvasTestStep*) { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 440 | SkPictureRecorder recorder; |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 441 | SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight), |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 442 | NULL, 0); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 443 | testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 444 | testCanvas->clipRect(d.fRect); |
| 445 | testCanvas->drawRect(d.fRect, d.fPaint); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 446 | SkAutoTUnref<SkPicture> testPicture(recorder.endRecording()); |
| 447 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 448 | canvas->drawPicture(testPicture); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 449 | } |
| 450 | TEST_STEP(DrawPicture, DrawPictureTestStep); |
| 451 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 452 | static void SaveRestoreTestStep(SkCanvas* canvas, const TestData& d, |
| 453 | skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 454 | int baseSaveCount = canvas->getSaveCount(); |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 455 | int n = canvas->save(); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 456 | REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount == n, testStep->assertMessage()); |
| 457 | REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount(), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 458 | testStep->assertMessage()); |
| 459 | canvas->save(); |
| 460 | canvas->save(); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 461 | REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 3 == canvas->getSaveCount(), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 462 | testStep->assertMessage()); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 463 | canvas->restoreToCount(baseSaveCount + 1); |
| 464 | REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount(), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 465 | testStep->assertMessage()); |
| 466 | |
| 467 | // should this pin to 1, or be a no-op, or crash? |
| 468 | canvas->restoreToCount(0); |
| 469 | REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(), |
| 470 | testStep->assertMessage()); |
| 471 | } |
| 472 | TEST_STEP(SaveRestore, SaveRestoreTestStep); |
| 473 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 474 | static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, const TestData& d, |
| 475 | skiatest::Reporter*, CanvasTestStep*) { |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 476 | // This test step challenges the TestDeferredCanvasStateConsistency |
| 477 | // test cases because the opaque paint can trigger an optimization |
| 478 | // that discards previously recorded commands. The challenge is to maintain |
| 479 | // correct clip and matrix stack state. |
| 480 | canvas->resetMatrix(); |
| 481 | canvas->rotate(SkIntToScalar(30)); |
| 482 | canvas->save(); |
| 483 | canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
| 484 | canvas->save(); |
| 485 | canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
| 486 | SkPaint paint; |
| 487 | paint.setColor(0xFFFFFFFF); |
| 488 | canvas->drawPaint(paint); |
| 489 | canvas->restore(); |
| 490 | canvas->restore(); |
| 491 | } |
| 492 | TEST_STEP(NestedSaveRestoreWithSolidPaint, \ |
| 493 | NestedSaveRestoreWithSolidPaintTestStep); |
| 494 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 495 | static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, const TestData& d, |
| 496 | skiatest::Reporter*, CanvasTestStep*) { |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 497 | // This test step challenges the TestDeferredCanvasStateConsistency |
| 498 | // test case because the canvas flush on a deferred canvas will |
| 499 | // reset the recording session. The challenge is to maintain correct |
| 500 | // clip and matrix stack state on the playback canvas. |
| 501 | canvas->resetMatrix(); |
| 502 | canvas->rotate(SkIntToScalar(30)); |
| 503 | canvas->save(); |
| 504 | canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
| 505 | canvas->save(); |
| 506 | canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 507 | canvas->drawRect(d.fRect,d.fPaint); |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 508 | canvas->flush(); |
| 509 | canvas->restore(); |
| 510 | canvas->restore(); |
| 511 | } |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 512 | TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 513 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 514 | static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData& d, |
| 515 | const SkCanvas* canvas1, const SkCanvas* canvas2, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 516 | CanvasTestStep* testStep) { |
| 517 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == |
| 518 | canvas2->getDeviceSize(), testStep->assertMessage()); |
| 519 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == |
| 520 | canvas2->getSaveCount(), testStep->assertMessage()); |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 521 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 522 | SkRect bounds1, bounds2; |
| 523 | REPORTER_ASSERT_MESSAGE(reporter, |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 524 | canvas1->getClipBounds(&bounds1) == canvas2->getClipBounds(&bounds2), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 525 | testStep->assertMessage()); |
| 526 | REPORTER_ASSERT_MESSAGE(reporter, bounds1 == bounds2, |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 527 | testStep->assertMessage()); |
| 528 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 529 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDrawFilter() == |
| 530 | canvas2->getDrawFilter(), testStep->assertMessage()); |
| 531 | SkIRect deviceBounds1, deviceBounds2; |
| 532 | REPORTER_ASSERT_MESSAGE(reporter, |
| 533 | canvas1->getClipDeviceBounds(&deviceBounds1) == |
| 534 | canvas2->getClipDeviceBounds(&deviceBounds2), |
| 535 | testStep->assertMessage()); |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 536 | REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, testStep->assertMessage()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 537 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() == |
| 538 | canvas2->getTotalMatrix(), testStep->assertMessage()); |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 539 | REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep->assertMessage()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 540 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 541 | SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); |
| 542 | SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); |
| 543 | while (!layerIter1.done() && !layerIter2.done()) { |
| 544 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.matrix() == |
| 545 | layerIter2.matrix(), testStep->assertMessage()); |
| 546 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.clip() == |
| 547 | layerIter2.clip(), testStep->assertMessage()); |
| 548 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.paint() == |
| 549 | layerIter2.paint(), testStep->assertMessage()); |
| 550 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.x() == |
| 551 | layerIter2.x(), testStep->assertMessage()); |
| 552 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.y() == |
| 553 | layerIter2.y(), testStep->assertMessage()); |
| 554 | layerIter1.next(); |
| 555 | layerIter2.next(); |
| 556 | } |
| 557 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.done(), |
| 558 | testStep->assertMessage()); |
| 559 | REPORTER_ASSERT_MESSAGE(reporter, layerIter2.done(), |
| 560 | testStep->assertMessage()); |
piotaixr | 76993ed | 2014-10-27 15:31:34 -0700 | [diff] [blame] | 561 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 562 | } |
| 563 | |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 564 | static void TestPdfDevice(skiatest::Reporter* reporter, |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 565 | const TestData& d, |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 566 | CanvasTestStep* testStep) { |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 567 | SkISize pageSize = SkISize::Make(d.fWidth, d.fHeight); |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 568 | SkPDFDevice device(pageSize, pageSize, SkMatrix::I()); |
| 569 | SkCanvas canvas(&device); |
| 570 | testStep->setAssertMessageFormat(kPdfAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 571 | testStep->draw(&canvas, d, reporter); |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 572 | SkPDFDocument doc; |
| 573 | doc.appendPage(&device); |
| 574 | SkDynamicMemoryWStream stream; |
| 575 | doc.emitPDF(&stream); |
| 576 | } |
| 577 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 578 | // The following class groups static functions that need to access |
| 579 | // the privates members of SkDeferredCanvas |
| 580 | class SkDeferredCanvasTester { |
| 581 | public: |
| 582 | static void TestDeferredCanvasStateConsistency( |
| 583 | skiatest::Reporter* reporter, |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 584 | const TestData& d, |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 585 | CanvasTestStep* testStep, |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 586 | const SkCanvas& referenceCanvas, bool silent) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 587 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 588 | SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
| 589 | SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(surface.get())); |
| 590 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 591 | testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 592 | testStep->draw(deferredCanvas, d, reporter); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 593 | testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 594 | AssertCanvasStatesEqual(reporter, d, deferredCanvas, &referenceCanvas, testStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 595 | |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 596 | if (silent) { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 597 | deferredCanvas->silentFlush(); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 598 | } else { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 599 | deferredCanvas->flush(); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 600 | } |
| 601 | |
skia.committer@gmail.com | 4c5ea44 | 2012-09-21 02:01:01 +0000 | [diff] [blame] | 602 | testStep->setAssertMessageFormat( |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 603 | silent ? kDeferredPostSilentFlushPlaybackAssertMessageFormat : |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 604 | kDeferredPostFlushPlaybackAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 605 | AssertCanvasStatesEqual(reporter, d, deferredCanvas->immediateCanvas(), |
| 606 | &referenceCanvas, testStep); |
junov@chromium.org | cff01c5 | 2012-07-18 21:50:26 +0000 | [diff] [blame] | 607 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 608 | // Verified that deferred canvas state is not affected by flushing |
| 609 | // pending draw operations |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 610 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 611 | // The following test code is commented out because it currently fails. |
| 612 | // Issue: http://code.google.com/p/skia/issues/detail?id=496 |
| 613 | /* |
| 614 | testStep->setAssertMessageFormat(kDeferredPostFlushAssertMessageFormat); |
| 615 | AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas, |
| 616 | testStep); |
| 617 | */ |
| 618 | } |
| 619 | }; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 620 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 621 | // unused |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 622 | static void TestProxyCanvasStateConsistency( |
| 623 | skiatest::Reporter* reporter, |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 624 | const TestData& d, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 625 | CanvasTestStep* testStep, |
| 626 | const SkCanvas& referenceCanvas) { |
| 627 | |
| 628 | SkBitmap indirectStore; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 629 | createBitmap(&indirectStore, 0xFFFFFFFF); |
reed | 2a8ca93 | 2014-06-26 22:12:09 -0700 | [diff] [blame] | 630 | SkCanvas indirectCanvas(indirectStore); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 631 | SkProxyCanvas proxyCanvas(&indirectCanvas); |
| 632 | testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 633 | testStep->draw(&proxyCanvas, d, reporter); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 634 | // Verify that the SkProxyCanvas reports consitent state |
| 635 | testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 636 | AssertCanvasStatesEqual(reporter, d, &proxyCanvas, &referenceCanvas, testStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 637 | // Verify that the indirect canvas reports consitent state |
| 638 | testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 639 | AssertCanvasStatesEqual(reporter, d, &indirectCanvas, &referenceCanvas, testStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 640 | } |
| 641 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 642 | // unused |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 643 | static void TestNWayCanvasStateConsistency( |
| 644 | skiatest::Reporter* reporter, |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 645 | const TestData& d, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 646 | CanvasTestStep* testStep, |
| 647 | const SkCanvas& referenceCanvas) { |
| 648 | |
| 649 | SkBitmap indirectStore1; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 650 | createBitmap(&indirectStore1, 0xFFFFFFFF); |
reed | 2a8ca93 | 2014-06-26 22:12:09 -0700 | [diff] [blame] | 651 | SkCanvas indirectCanvas1(indirectStore1); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 652 | |
| 653 | SkBitmap indirectStore2; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 654 | createBitmap(&indirectStore2, 0xFFFFFFFF); |
reed | 2a8ca93 | 2014-06-26 22:12:09 -0700 | [diff] [blame] | 655 | SkCanvas indirectCanvas2(indirectStore2); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 656 | |
djsollen@google.com | f0a062b | 2012-05-01 16:50:25 +0000 | [diff] [blame] | 657 | SkISize canvasSize = referenceCanvas.getDeviceSize(); |
| 658 | SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 659 | nWayCanvas.addCanvas(&indirectCanvas1); |
| 660 | nWayCanvas.addCanvas(&indirectCanvas2); |
| 661 | |
| 662 | testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 663 | testStep->draw(&nWayCanvas, d, reporter); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 664 | // Verify that the SkProxyCanvas reports consitent state |
| 665 | testStep->setAssertMessageFormat(kNWayStateAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 666 | AssertCanvasStatesEqual(reporter, d, &nWayCanvas, &referenceCanvas, testStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 667 | // Verify that the indirect canvases report consitent state |
| 668 | testStep->setAssertMessageFormat(kNWayIndirect1StateAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 669 | AssertCanvasStatesEqual(reporter, d, &indirectCanvas1, &referenceCanvas, testStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 670 | testStep->setAssertMessageFormat(kNWayIndirect2StateAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 671 | AssertCanvasStatesEqual(reporter, d, &indirectCanvas2, &referenceCanvas, testStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /* |
| 675 | * This sub-test verifies that the test step passes when executed |
| 676 | * with SkCanvas and with classes derrived from SkCanvas. It also verifies |
| 677 | * that the all canvas derivatives report the same state as an SkCanvas |
| 678 | * after having executed the test step. |
| 679 | */ |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 680 | static void TestOverrideStateConsistency(skiatest::Reporter* reporter, const TestData& d, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 681 | CanvasTestStep* testStep) { |
| 682 | SkBitmap referenceStore; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 683 | createBitmap(&referenceStore, 0xFFFFFFFF); |
reed | 2a8ca93 | 2014-06-26 22:12:09 -0700 | [diff] [blame] | 684 | SkCanvas referenceCanvas(referenceStore); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 685 | testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 686 | testStep->draw(&referenceCanvas, d, reporter); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 687 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 688 | SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, d, testStep, referenceCanvas, false); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 689 | |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 690 | SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, d, testStep, referenceCanvas, true); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 691 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 692 | // The following test code is disabled because SkProxyCanvas is |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 693 | // missing a lot of virtual overrides on get* methods, which are used |
| 694 | // to verify canvas state. |
| 695 | // Issue: http://code.google.com/p/skia/issues/detail?id=500 |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 696 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 697 | if (false) { // avoid bit rot, suppress warning |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 698 | TestProxyCanvasStateConsistency(reporter, d, testStep, referenceCanvas); |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | // The following test code is disabled because SkNWayCanvas does not |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 702 | // report correct clipping and device bounds information |
| 703 | // Issue: http://code.google.com/p/skia/issues/detail?id=501 |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 704 | |
| 705 | if (false) { // avoid bit rot, suppress warning |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 706 | TestNWayCanvasStateConsistency(reporter, d, testStep, referenceCanvas); |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 707 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 708 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 709 | if (false) { // avoid bit rot, suppress warning |
| 710 | test_clipVisitor(reporter, &referenceCanvas); |
| 711 | } |
reed@google.com | 7c20293 | 2011-12-14 18:48:05 +0000 | [diff] [blame] | 712 | } |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 713 | |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 714 | static void test_newraster(skiatest::Reporter* reporter) { |
| 715 | SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 716 | const size_t minRowBytes = info.minRowBytes(); |
| 717 | const size_t size = info.getSafeSize(minRowBytes); |
| 718 | SkAutoMalloc storage(size); |
| 719 | SkPMColor* baseAddr = static_cast<SkPMColor*>(storage.get()); |
| 720 | sk_bzero(baseAddr, size); |
| 721 | |
| 722 | SkCanvas* canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes); |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 723 | REPORTER_ASSERT(reporter, canvas); |
| 724 | |
| 725 | SkImageInfo info2; |
| 726 | size_t rowBytes; |
| 727 | const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowBytes); |
| 728 | REPORTER_ASSERT(reporter, addr); |
| 729 | REPORTER_ASSERT(reporter, info == info2); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 730 | REPORTER_ASSERT(reporter, minRowBytes == rowBytes); |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 731 | for (int y = 0; y < info.height(); ++y) { |
| 732 | for (int x = 0; x < info.width(); ++x) { |
| 733 | REPORTER_ASSERT(reporter, 0 == addr[x]); |
| 734 | } |
| 735 | addr = (const SkPMColor*)((const char*)addr + rowBytes); |
| 736 | } |
| 737 | SkDELETE(canvas); |
| 738 | |
| 739 | // now try a deliberately bad info |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 740 | info = info.makeWH(-1, info.height()); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 741 | REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes)); |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 742 | |
| 743 | // too big |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 744 | info = info.makeWH(1 << 30, 1 << 30); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 745 | REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes)); |
skia.committer@gmail.com | 0e53075 | 2014-02-28 03:02:05 +0000 | [diff] [blame] | 746 | |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 747 | // not a valid pixel type |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 748 | info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType()); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 749 | REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes)); |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 750 | |
| 751 | // We should succeed with a zero-sized valid info |
| 752 | info = SkImageInfo::MakeN32Premul(0, 0); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 753 | canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes); |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 754 | REPORTER_ASSERT(reporter, canvas); |
| 755 | SkDELETE(canvas); |
| 756 | } |
| 757 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 758 | DEF_TEST(Canvas, reporter) { |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 759 | TestData d; |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 760 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 761 | for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 762 | TestOverrideStateConsistency(reporter, d, testStepArray()[testStep]); |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 763 | if (testStepArray()[testStep]->enablePdfTesting()) { |
piotaixr | f05f5a7 | 2014-10-03 13:26:55 -0700 | [diff] [blame] | 764 | TestPdfDevice(reporter, d, testStepArray()[testStep]); |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 765 | } |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 766 | } |
junov@chromium.org | cd62ecf | 2012-08-02 17:43:25 +0000 | [diff] [blame] | 767 | |
commit-bot@chromium.org | 3107b6a | 2014-02-27 20:32:51 +0000 | [diff] [blame] | 768 | test_newraster(reporter); |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 769 | } |
reed | f0090cb | 2014-11-26 08:55:51 -0800 | [diff] [blame] | 770 | |
| 771 | DEF_TEST(Canvas_SaveState, reporter) { |
| 772 | SkCanvas canvas(10, 10); |
| 773 | REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); |
| 774 | |
| 775 | int n = canvas.save(); |
| 776 | REPORTER_ASSERT(reporter, 1 == n); |
| 777 | REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); |
| 778 | |
| 779 | n = canvas.saveLayer(NULL, NULL); |
| 780 | REPORTER_ASSERT(reporter, 2 == n); |
| 781 | REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); |
| 782 | |
| 783 | canvas.restore(); |
| 784 | REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); |
| 785 | canvas.restore(); |
| 786 | REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); |
| 787 | } |