reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 8 | |
| 9 | /* Description: |
| 10 | * This test defines a series of elementatry test steps that perform |
| 11 | * a single or a small group of canvas API calls. Each test step is |
| 12 | * used in several test cases that verify that different types of SkCanvas |
| 13 | * flavors and derivatives pass it and yield consistent behavior. The |
| 14 | * test cases analyse results that are queryable through the API. They do |
| 15 | * not look at rendering results. |
| 16 | * |
| 17 | * Adding test stepss: |
| 18 | * The general pattern for creating a new test step is to write a test |
| 19 | * function of the form: |
| 20 | * |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 21 | * static void MyTestStepFunction(SkCanvas* canvas, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 22 | * skiatest::Reporter* reporter, |
| 23 | * CanvasTestStep* testStep) |
| 24 | * { |
| 25 | * canvas->someCanvasAPImethod(); |
| 26 | * (...) |
| 27 | * REPORTER_ASSERT_MESSAGE(reporter, (...), \ |
| 28 | * testStep->assertMessage()); |
| 29 | * } |
| 30 | * |
| 31 | * The definition of the test step function should be followed by an |
| 32 | * invocation of the TEST_STEP macro, which generates a class and |
| 33 | * instance for the test step: |
| 34 | * |
| 35 | * TEST_STEP(MyTestStep, MyTestStepFunction) |
| 36 | * |
| 37 | * There are also short hand macros for defining simple test steps |
| 38 | * in a single line of code. A simple test step is a one that is made |
| 39 | * of a single canvas API call. |
| 40 | * |
| 41 | * SIMPLE_TEST_STEP(MytestStep, someCanvasAPIMethod()); |
| 42 | * |
| 43 | * There is another macro called SIMPLE_TEST_STEP_WITH_ASSERT that |
| 44 | * works the same way as SIMPLE_TEST_STEP, and additionally verifies |
| 45 | * that the invoked method returns a non-zero value. |
| 46 | */ |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 47 | #include "SkBitmap.h" |
| 48 | #include "SkCanvas.h" |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 49 | #include "SkDeferredCanvas.h" |
| 50 | #include "SkDevice.h" |
| 51 | #include "SkMatrix.h" |
| 52 | #include "SkNWayCanvas.h" |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 53 | #include "SkPDFDevice.h" |
| 54 | #include "SkPDFDocument.h" |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 55 | #include "SkPaint.h" |
| 56 | #include "SkPath.h" |
| 57 | #include "SkPicture.h" |
| 58 | #include "SkPictureRecord.h" |
| 59 | #include "SkProxyCanvas.h" |
| 60 | #include "SkRect.h" |
| 61 | #include "SkRegion.h" |
| 62 | #include "SkShader.h" |
| 63 | #include "SkStream.h" |
| 64 | #include "SkTDArray.h" |
| 65 | #include "Test.h" |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 66 | |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 67 | class Canvas2CanvasClipVisitor : public SkCanvas::ClipVisitor { |
| 68 | public: |
| 69 | Canvas2CanvasClipVisitor(SkCanvas* target) : fTarget(target) {} |
| 70 | |
| 71 | virtual void clipRect(const SkRect& r, SkRegion::Op op, bool aa) { |
| 72 | fTarget->clipRect(r, op, aa); |
| 73 | } |
| 74 | virtual void clipPath(const SkPath& p, SkRegion::Op op, bool aa) { |
| 75 | fTarget->clipPath(p, op, aa); |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | SkCanvas* fTarget; |
| 80 | }; |
| 81 | |
| 82 | static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) { |
| 83 | SkISize size = canvas->getDeviceSize(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 84 | |
reed@google.com | 90c07ea | 2012-04-13 13:50:27 +0000 | [diff] [blame] | 85 | SkBitmap bm; |
| 86 | bm.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
| 87 | SkCanvas c(bm); |
| 88 | |
| 89 | Canvas2CanvasClipVisitor visitor(&c); |
| 90 | canvas->replayClips(&visitor); |
| 91 | |
| 92 | REPORTER_ASSERT(reporter, c.getTotalClip() == canvas->getTotalClip()); |
| 93 | } |
| 94 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 95 | static const int kWidth = 2; |
| 96 | static const int kHeight = 2; |
reed@google.com | 7c20293 | 2011-12-14 18:48:05 +0000 | [diff] [blame] | 97 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 98 | // Format strings that describe the test context. The %s token is where |
| 99 | // the name of the test step is inserted. The context is required for |
| 100 | // disambiguating the error in the case of failures that are reported in |
| 101 | // functions that are called multiple times in different contexts (test |
| 102 | // cases and test steps). |
| 103 | static const char* const kDefaultAssertMessageFormat = "%s"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 104 | static const char* const kCanvasDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 105 | "Drawing test step %s with SkCanvas"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 106 | static const char* const kPictureDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 107 | "Drawing test step %s with SkPicture"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 108 | static const char* const kPictureSecondDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 109 | "Duplicate draw of test step %s with SkPicture"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 110 | static const char* const kDeferredDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 111 | "Drawing test step %s with SkDeferredCanvas"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 112 | static const char* const kProxyDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 113 | "Drawing test step %s with SkProxyCanvas"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 114 | static const char* const kNWayDrawAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 115 | "Drawing test step %s with SkNWayCanvas"; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 116 | static const char* const kDeferredPreFlushAssertMessageFormat = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 117 | "test step %s, SkDeferredCanvas state consistency before flush"; |
junov@chromium.org | cff01c5 | 2012-07-18 21:50:26 +0000 | [diff] [blame] | 118 | static const char* const kDeferredPostFlushPlaybackAssertMessageFormat = |
| 119 | "test step %s, SkDeferredCanvas playback canvas state consistency after flush"; |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 120 | static const char* const kDeferredPostSilentFlushPlaybackAssertMessageFormat = |
| 121 | "test step %s, SkDeferredCanvas playback canvas state consistency after silent flush"; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 122 | static const char* const kPictureResourceReuseMessageFormat = |
| 123 | "test step %s, SkPicture duplicate flattened object test"; |
| 124 | static const char* const kProxyStateAssertMessageFormat = |
| 125 | "test step %s, SkProxyCanvas state consistency"; |
| 126 | static const char* const kProxyIndirectStateAssertMessageFormat = |
| 127 | "test step %s, SkProxyCanvas indirect canvas state consistency"; |
| 128 | static const char* const kNWayStateAssertMessageFormat = |
| 129 | "test step %s, SkNWayCanvas state consistency"; |
| 130 | static const char* const kNWayIndirect1StateAssertMessageFormat = |
| 131 | "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; |
| 132 | static const char* const kNWayIndirect2StateAssertMessageFormat = |
| 133 | "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 134 | static const char* const kPdfAssertMessageFormat = |
| 135 | "PDF sanity check failed %s"; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 136 | |
| 137 | static void createBitmap(SkBitmap* bm, SkBitmap::Config config, SkColor color) { |
| 138 | bm->setConfig(config, kWidth, kHeight); |
| 139 | bm->allocPixels(); |
| 140 | bm->eraseColor(color); |
| 141 | } |
| 142 | |
| 143 | class CanvasTestStep; |
| 144 | static SkTDArray<CanvasTestStep*>& testStepArray() { |
| 145 | static SkTDArray<CanvasTestStep*> theTests; |
| 146 | return theTests; |
| 147 | } |
| 148 | |
| 149 | class CanvasTestStep { |
| 150 | public: |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 151 | CanvasTestStep(bool fEnablePdfTesting = true) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 152 | *testStepArray().append() = this; |
| 153 | fAssertMessageFormat = kDefaultAssertMessageFormat; |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 154 | this->fEnablePdfTesting = fEnablePdfTesting; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 155 | } |
djsollen@google.com | e63793a | 2012-03-21 15:39:03 +0000 | [diff] [blame] | 156 | virtual ~CanvasTestStep() { } |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 157 | |
| 158 | virtual void draw(SkCanvas*, skiatest::Reporter*) = 0; |
| 159 | virtual const char* name() const = 0; |
| 160 | |
| 161 | const char* assertMessage() { |
| 162 | fAssertMessage.printf(fAssertMessageFormat, name()); |
| 163 | return fAssertMessage.c_str(); |
| 164 | } |
| 165 | |
| 166 | void setAssertMessageFormat(const char* format) { |
| 167 | fAssertMessageFormat = format; |
| 168 | } |
| 169 | |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 170 | bool enablePdfTesting() { return fEnablePdfTesting; } |
| 171 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 172 | private: |
| 173 | SkString fAssertMessage; |
| 174 | const char* fAssertMessageFormat; |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 175 | bool fEnablePdfTesting; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | /////////////////////////////////////////////////////////////////////////////// |
| 179 | // Constants used by test steps |
| 180 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 181 | const SkRect kTestRect = |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 182 | SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 183 | SkIntToScalar(2), SkIntToScalar(1)); |
| 184 | static SkMatrix testMatrix() { |
| 185 | SkMatrix matrix; |
| 186 | matrix.reset(); |
| 187 | matrix.setScale(SkIntToScalar(2), SkIntToScalar(3)); |
| 188 | return matrix; |
| 189 | } |
| 190 | const SkMatrix kTestMatrix = testMatrix(); |
| 191 | static SkPath testPath() { |
| 192 | SkPath path; |
| 193 | path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 194 | SkIntToScalar(2), SkIntToScalar(1))); |
| 195 | return path; |
| 196 | } |
| 197 | const SkPath kTestPath = testPath(); |
| 198 | static SkRegion testRegion() { |
| 199 | SkRegion region; |
| 200 | SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1); |
| 201 | region.setRect(rect); |
| 202 | return region; |
| 203 | } |
| 204 | const SkIRect kTestIRect = SkIRect::MakeXYWH(0, 0, 2, 1); |
| 205 | const SkRegion kTestRegion = testRegion(); |
| 206 | const SkColor kTestColor = 0x01020304; |
| 207 | const SkPaint kTestPaint; |
| 208 | const SkPoint kTestPoints[3] = { |
| 209 | {SkIntToScalar(0), SkIntToScalar(0)}, |
| 210 | {SkIntToScalar(2), SkIntToScalar(1)}, |
| 211 | {SkIntToScalar(0), SkIntToScalar(2)} |
| 212 | }; |
| 213 | const size_t kTestPointCount = 3; |
| 214 | static SkBitmap testBitmap() { |
| 215 | SkBitmap bitmap; |
| 216 | createBitmap(&bitmap, SkBitmap::kARGB_8888_Config, 0x05060708); |
| 217 | return bitmap; |
| 218 | } |
| 219 | SkBitmap kTestBitmap; // cannot be created during static init |
| 220 | SkString kTestText("Hello World"); |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 221 | SkPoint kTestPoints2[] = { |
| 222 | { SkIntToScalar(0), SkIntToScalar(1) }, |
| 223 | { SkIntToScalar(1), SkIntToScalar(1) }, |
| 224 | { SkIntToScalar(2), SkIntToScalar(1) }, |
| 225 | { SkIntToScalar(3), SkIntToScalar(1) }, |
| 226 | { SkIntToScalar(4), SkIntToScalar(1) }, |
| 227 | { SkIntToScalar(5), SkIntToScalar(1) }, |
| 228 | { SkIntToScalar(6), SkIntToScalar(1) }, |
| 229 | { SkIntToScalar(7), SkIntToScalar(1) }, |
| 230 | { SkIntToScalar(8), SkIntToScalar(1) }, |
| 231 | { SkIntToScalar(9), SkIntToScalar(1) }, |
| 232 | { SkIntToScalar(10), SkIntToScalar(1) }, |
| 233 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 234 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 235 | |
| 236 | /////////////////////////////////////////////////////////////////////////////// |
| 237 | // Macros for defining test steps |
| 238 | |
| 239 | #define TEST_STEP(NAME, FUNCTION) \ |
| 240 | class NAME##_TestStep : public CanvasTestStep{ \ |
| 241 | public: \ |
| 242 | virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ |
| 243 | FUNCTION (canvas, reporter, this); \ |
| 244 | } \ |
| 245 | virtual const char* name() const {return #NAME ;} \ |
| 246 | }; \ |
| 247 | static NAME##_TestStep NAME##_TestStepInstance; |
| 248 | |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 249 | #define TEST_STEP_NO_PDF(NAME, FUNCTION) \ |
| 250 | class NAME##_TestStep : public CanvasTestStep{ \ |
| 251 | public: \ |
| 252 | NAME##_TestStep() : CanvasTestStep(false) {} \ |
| 253 | virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ |
| 254 | FUNCTION (canvas, reporter, this); \ |
| 255 | } \ |
| 256 | virtual const char* name() const {return #NAME ;} \ |
| 257 | }; \ |
| 258 | static NAME##_TestStep NAME##_TestStepInstance; |
| 259 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 260 | #define SIMPLE_TEST_STEP(NAME, CALL) \ |
| 261 | static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter*, \ |
| 262 | CanvasTestStep*) { \ |
| 263 | canvas-> CALL ; \ |
| 264 | } \ |
| 265 | TEST_STEP(NAME, NAME##TestStep ) |
| 266 | |
| 267 | #define SIMPLE_TEST_STEP_WITH_ASSERT(NAME, CALL) \ |
| 268 | static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter* reporter, \ |
| 269 | CanvasTestStep* testStep) { \ |
| 270 | REPORTER_ASSERT_MESSAGE(reporter, canvas-> CALL , \ |
| 271 | testStep->assertMessage()); \ |
| 272 | } \ |
| 273 | TEST_STEP(NAME, NAME##TestStep ) |
| 274 | |
| 275 | |
| 276 | /////////////////////////////////////////////////////////////////////////////// |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 277 | // 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] | 278 | // the state of the canvas. |
| 279 | |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 280 | SIMPLE_TEST_STEP_WITH_ASSERT(Translate, |
| 281 | translate(SkIntToScalar(1), SkIntToScalar(2))); |
| 282 | SIMPLE_TEST_STEP_WITH_ASSERT(Scale, |
| 283 | scale(SkIntToScalar(1), SkIntToScalar(2))); |
| 284 | SIMPLE_TEST_STEP_WITH_ASSERT(Rotate, rotate(SkIntToScalar(1))); |
| 285 | SIMPLE_TEST_STEP_WITH_ASSERT(Skew, |
| 286 | skew(SkIntToScalar(1), SkIntToScalar(2))); |
| 287 | SIMPLE_TEST_STEP_WITH_ASSERT(Concat, concat(kTestMatrix)); |
| 288 | SIMPLE_TEST_STEP(SetMatrix, setMatrix(kTestMatrix)); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 289 | SIMPLE_TEST_STEP(ClipRect, clipRect(kTestRect)); |
| 290 | SIMPLE_TEST_STEP(ClipPath, clipPath(kTestPath)); |
| 291 | SIMPLE_TEST_STEP(ClipRegion, |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 292 | clipRegion(kTestRegion, SkRegion::kReplace_Op)); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 293 | SIMPLE_TEST_STEP(Clear, clear(kTestColor)); |
| 294 | SIMPLE_TEST_STEP(DrawPaint, drawPaint(kTestPaint)); |
| 295 | SIMPLE_TEST_STEP(DrawPointsPoints, drawPoints(SkCanvas::kPoints_PointMode, |
| 296 | kTestPointCount, kTestPoints, kTestPaint)); |
| 297 | SIMPLE_TEST_STEP(DrawPointsLiness, drawPoints(SkCanvas::kLines_PointMode, |
| 298 | kTestPointCount, kTestPoints, kTestPaint)); |
| 299 | SIMPLE_TEST_STEP(DrawPointsPolygon, drawPoints(SkCanvas::kPolygon_PointMode, |
| 300 | kTestPointCount, kTestPoints, kTestPaint)); |
| 301 | SIMPLE_TEST_STEP(DrawRect, drawRect(kTestRect, kTestPaint)); |
| 302 | SIMPLE_TEST_STEP(DrawPath, drawPath(kTestPath, kTestPaint)); |
junov@chromium.org | 87f982c | 2012-02-23 21:34:34 +0000 | [diff] [blame] | 303 | SIMPLE_TEST_STEP(DrawBitmap, drawBitmap(kTestBitmap, 0, 0)); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 304 | SIMPLE_TEST_STEP(DrawBitmapPaint, drawBitmap(kTestBitmap, 0, 0, &kTestPaint)); |
| 305 | SIMPLE_TEST_STEP(DrawBitmapRect, drawBitmapRect(kTestBitmap, NULL, kTestRect, |
| 306 | NULL)); |
| 307 | SIMPLE_TEST_STEP(DrawBitmapRectSrcRect, drawBitmapRect(kTestBitmap, |
| 308 | &kTestIRect, kTestRect, NULL)); |
| 309 | SIMPLE_TEST_STEP(DrawBitmapRectPaint, drawBitmapRect(kTestBitmap, NULL, |
| 310 | kTestRect, &kTestPaint)); |
| 311 | SIMPLE_TEST_STEP(DrawBitmapMatrix, drawBitmapMatrix(kTestBitmap, kTestMatrix, |
| 312 | NULL)); |
| 313 | SIMPLE_TEST_STEP(DrawBitmapMatrixPaint, drawBitmapMatrix(kTestBitmap, |
| 314 | kTestMatrix, &kTestPaint)); |
| 315 | SIMPLE_TEST_STEP(DrawBitmapNine, drawBitmapNine(kTestBitmap, kTestIRect, |
| 316 | kTestRect, NULL)); |
| 317 | SIMPLE_TEST_STEP(DrawBitmapNinePaint, drawBitmapNine(kTestBitmap, kTestIRect, |
| 318 | kTestRect, &kTestPaint)); |
junov@chromium.org | 87f982c | 2012-02-23 21:34:34 +0000 | [diff] [blame] | 319 | SIMPLE_TEST_STEP(DrawSprite, drawSprite(kTestBitmap, 0, 0, NULL)); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 320 | SIMPLE_TEST_STEP(DrawSpritePaint, drawSprite(kTestBitmap, 0, 0, &kTestPaint)); |
| 321 | SIMPLE_TEST_STEP(DrawText, drawText(kTestText.c_str(), kTestText.size(), |
| 322 | 0, 1, kTestPaint)); |
| 323 | SIMPLE_TEST_STEP(DrawPosText, drawPosText(kTestText.c_str(), |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 324 | kTestText.size(), kTestPoints2, kTestPaint)); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 325 | SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(kTestText.c_str(), |
| 326 | kTestText.size(), kTestPath, NULL, kTestPaint)); |
| 327 | SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(), |
| 328 | kTestText.size(), kTestPath, &kTestMatrix, kTestPaint)); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 329 | SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size())); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 330 | SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(kTestText.c_str())); |
| 331 | SIMPLE_TEST_STEP(AddComment, addComment(kTestText.c_str(), kTestText.c_str())); |
| 332 | SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 333 | |
| 334 | /////////////////////////////////////////////////////////////////////////////// |
| 335 | // Complex test steps |
| 336 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 337 | // Save/restore calls cannot be in isolated simple test steps because the test |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 338 | // cases that use SkPicture require that save and restore calls be balanced. |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 339 | static void SaveMatrixStep(SkCanvas* canvas, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 340 | skiatest::Reporter* reporter, |
| 341 | CanvasTestStep* testStep) { |
| 342 | int saveCount = canvas->getSaveCount(); |
| 343 | canvas->save(SkCanvas::kMatrix_SaveFlag); |
| 344 | canvas->clipRegion(kTestRegion); |
| 345 | canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
| 346 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 347 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 348 | testStep->assertMessage()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 349 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 350 | testStep->assertMessage()); |
| 351 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() == kTestRegion, |
| 352 | testStep->assertMessage()); |
| 353 | } |
| 354 | TEST_STEP(SaveMatrix, SaveMatrixStep); |
| 355 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 356 | static void SaveClipStep(SkCanvas* canvas, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 357 | skiatest::Reporter* reporter, |
| 358 | CanvasTestStep* testStep) { |
| 359 | int saveCount = canvas->getSaveCount(); |
| 360 | canvas->save(SkCanvas::kClip_SaveFlag); |
| 361 | canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
| 362 | canvas->clipRegion(kTestRegion); |
| 363 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 364 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 365 | testStep->assertMessage()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 366 | REPORTER_ASSERT_MESSAGE(reporter, !canvas->getTotalMatrix().isIdentity(), |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 367 | testStep->assertMessage()); |
| 368 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, |
| 369 | testStep->assertMessage()); |
| 370 | } |
| 371 | TEST_STEP(SaveClip, SaveClipStep); |
| 372 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 373 | static void SaveMatrixClipStep(SkCanvas* canvas, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 374 | skiatest::Reporter* reporter, |
| 375 | CanvasTestStep* testStep) { |
| 376 | int saveCount = canvas->getSaveCount(); |
| 377 | canvas->save(SkCanvas::kMatrixClip_SaveFlag); |
| 378 | canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
| 379 | canvas->clipRegion(kTestRegion); |
| 380 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 381 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 382 | testStep->assertMessage()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 383 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 384 | testStep->assertMessage()); |
| 385 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, |
| 386 | testStep->assertMessage()); |
| 387 | } |
| 388 | TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); |
| 389 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 390 | static void SaveLayerStep(SkCanvas* canvas, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 391 | skiatest::Reporter* reporter, |
| 392 | CanvasTestStep* testStep) { |
| 393 | int saveCount = canvas->getSaveCount(); |
| 394 | canvas->saveLayer(NULL, NULL); |
| 395 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 396 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 397 | testStep->assertMessage()); |
| 398 | } |
| 399 | TEST_STEP(SaveLayer, SaveLayerStep); |
| 400 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 401 | static void BoundedSaveLayerStep(SkCanvas* canvas, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 402 | skiatest::Reporter* reporter, |
| 403 | CanvasTestStep* testStep) { |
| 404 | int saveCount = canvas->getSaveCount(); |
| 405 | canvas->saveLayer(&kTestRect, NULL); |
| 406 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 407 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 408 | testStep->assertMessage()); |
| 409 | } |
| 410 | TEST_STEP(BoundedSaveLayer, BoundedSaveLayerStep); |
| 411 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 412 | static void PaintSaveLayerStep(SkCanvas* canvas, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 413 | skiatest::Reporter* reporter, |
| 414 | CanvasTestStep* testStep) { |
| 415 | int saveCount = canvas->getSaveCount(); |
| 416 | canvas->saveLayer(NULL, &kTestPaint); |
| 417 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 418 | REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 419 | testStep->assertMessage()); |
| 420 | } |
| 421 | TEST_STEP(PaintSaveLayer, PaintSaveLayerStep); |
| 422 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 423 | static void TwoClipOpsStep(SkCanvas* canvas, |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 424 | skiatest::Reporter*, |
| 425 | CanvasTestStep*) { |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 426 | // This test exercises a functionality in SkPicture that leads to the |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 427 | // recording of restore offset placeholders. This test will trigger an |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 428 | // assertion at playback time if the placeholders are not properly |
| 429 | // filled when the recording ends. |
| 430 | canvas->clipRect(kTestRect); |
| 431 | canvas->clipRegion(kTestRegion); |
| 432 | } |
| 433 | TEST_STEP(TwoClipOps, TwoClipOpsStep); |
| 434 | |
epoger@google.com | 94fa43c | 2012-04-11 17:51:01 +0000 | [diff] [blame] | 435 | // exercise fix for http://code.google.com/p/skia/issues/detail?id=560 |
| 436 | // ('SkPathStroker::lineTo() fails for line with length SK_ScalarNearlyZero') |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 437 | static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas, |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 438 | skiatest::Reporter*, |
| 439 | CanvasTestStep*) { |
epoger@google.com | 94fa43c | 2012-04-11 17:51:01 +0000 | [diff] [blame] | 440 | SkPaint paint; |
| 441 | paint.setStrokeWidth(SkIntToScalar(1)); |
| 442 | paint.setStyle(SkPaint::kStroke_Style); |
| 443 | |
| 444 | SkPath path; |
| 445 | SkPoint pt1 = { 0, 0 }; |
| 446 | SkPoint pt2 = { 0, SK_ScalarNearlyZero }; |
| 447 | SkPoint pt3 = { SkIntToScalar(1), 0 }; |
| 448 | SkPoint pt4 = { SkIntToScalar(1), SK_ScalarNearlyZero/2 }; |
| 449 | path.moveTo(pt1); |
| 450 | path.lineTo(pt2); |
| 451 | path.lineTo(pt3); |
| 452 | path.lineTo(pt4); |
| 453 | |
| 454 | canvas->drawPath(path, paint); |
| 455 | } |
| 456 | TEST_STEP(DrawNearlyZeroLengthPath, DrawNearlyZeroLengthPathTestStep); |
| 457 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 458 | static void DrawVerticesShaderTestStep(SkCanvas* canvas, |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 459 | skiatest::Reporter*, |
| 460 | CanvasTestStep*) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 461 | SkPoint pts[4]; |
| 462 | pts[0].set(0, 0); |
| 463 | pts[1].set(SkIntToScalar(kWidth), 0); |
| 464 | pts[2].set(SkIntToScalar(kWidth), SkIntToScalar(kHeight)); |
| 465 | pts[3].set(0, SkIntToScalar(kHeight)); |
| 466 | SkPaint paint; |
| 467 | SkShader* shader = SkShader::CreateBitmapShader(kTestBitmap, |
| 468 | SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| 469 | paint.setShader(shader)->unref(); |
| 470 | canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, |
| 471 | NULL, NULL, NULL, 0, paint); |
| 472 | } |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 473 | // NYI: issue 240. |
| 474 | TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 475 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 476 | static void DrawPictureTestStep(SkCanvas* canvas, |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 477 | skiatest::Reporter*, |
| 478 | CanvasTestStep*) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 479 | SkPicture* testPicture = SkNEW_ARGS(SkPicture, ()); |
| 480 | SkAutoUnref aup(testPicture); |
| 481 | SkCanvas* testCanvas = testPicture->beginRecording(kWidth, kHeight); |
| 482 | testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); |
| 483 | testCanvas->clipRect(kTestRect); |
| 484 | testCanvas->drawRect(kTestRect, kTestPaint); |
| 485 | canvas->drawPicture(*testPicture); |
| 486 | } |
| 487 | TEST_STEP(DrawPicture, DrawPictureTestStep); |
| 488 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 489 | static void SaveRestoreTestStep(SkCanvas* canvas, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 490 | skiatest::Reporter* reporter, |
| 491 | CanvasTestStep* testStep) { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 492 | int baseSaveCount = canvas->getSaveCount(); |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 493 | int n = canvas->save(); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 494 | REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount == n, testStep->assertMessage()); |
| 495 | REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount(), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 496 | testStep->assertMessage()); |
| 497 | canvas->save(); |
| 498 | canvas->save(); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 499 | REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 3 == canvas->getSaveCount(), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 500 | testStep->assertMessage()); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 501 | canvas->restoreToCount(baseSaveCount + 1); |
| 502 | REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount(), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 503 | testStep->assertMessage()); |
| 504 | |
| 505 | // should this pin to 1, or be a no-op, or crash? |
| 506 | canvas->restoreToCount(0); |
| 507 | REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(), |
| 508 | testStep->assertMessage()); |
| 509 | } |
| 510 | TEST_STEP(SaveRestore, SaveRestoreTestStep); |
| 511 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 512 | static void DrawLayerTestStep(SkCanvas* canvas, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 513 | skiatest::Reporter* reporter, |
| 514 | CanvasTestStep* testStep) { |
| 515 | REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), |
| 516 | testStep->assertMessage()); |
| 517 | canvas->save(); |
| 518 | REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), |
| 519 | testStep->assertMessage()); |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 520 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 521 | |
reed@google.com | 7c20293 | 2011-12-14 18:48:05 +0000 | [diff] [blame] | 522 | const SkRect* bounds = NULL; // null means include entire bounds |
| 523 | const SkPaint* paint = NULL; |
| 524 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 525 | canvas->saveLayer(bounds, paint); |
| 526 | REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(), |
| 527 | testStep->assertMessage()); |
| 528 | canvas->restore(); |
| 529 | REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), |
| 530 | testStep->assertMessage()); |
reed@google.com | 7c20293 | 2011-12-14 18:48:05 +0000 | [diff] [blame] | 531 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 532 | canvas->saveLayer(bounds, paint); |
| 533 | canvas->saveLayer(bounds, paint); |
| 534 | REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(), |
| 535 | testStep->assertMessage()); |
| 536 | canvas->restore(); |
| 537 | REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(), |
| 538 | testStep->assertMessage()); |
| 539 | canvas->restore(); |
reed@google.com | 7c20293 | 2011-12-14 18:48:05 +0000 | [diff] [blame] | 540 | // now layer count should be 0 |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 541 | REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), |
| 542 | testStep->assertMessage()); |
| 543 | } |
| 544 | TEST_STEP(DrawLayer, DrawLayerTestStep); |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 545 | |
| 546 | static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 547 | skiatest::Reporter*, |
| 548 | CanvasTestStep*) { |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 549 | // This test step challenges the TestDeferredCanvasStateConsistency |
| 550 | // test cases because the opaque paint can trigger an optimization |
| 551 | // that discards previously recorded commands. The challenge is to maintain |
| 552 | // correct clip and matrix stack state. |
| 553 | canvas->resetMatrix(); |
| 554 | canvas->rotate(SkIntToScalar(30)); |
| 555 | canvas->save(); |
| 556 | canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
| 557 | canvas->save(); |
| 558 | canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
| 559 | SkPaint paint; |
| 560 | paint.setColor(0xFFFFFFFF); |
| 561 | canvas->drawPaint(paint); |
| 562 | canvas->restore(); |
| 563 | canvas->restore(); |
| 564 | } |
| 565 | TEST_STEP(NestedSaveRestoreWithSolidPaint, \ |
| 566 | NestedSaveRestoreWithSolidPaintTestStep); |
| 567 | |
| 568 | static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 569 | skiatest::Reporter*, |
| 570 | CanvasTestStep*) { |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 571 | // This test step challenges the TestDeferredCanvasStateConsistency |
| 572 | // test case because the canvas flush on a deferred canvas will |
| 573 | // reset the recording session. The challenge is to maintain correct |
| 574 | // clip and matrix stack state on the playback canvas. |
| 575 | canvas->resetMatrix(); |
| 576 | canvas->rotate(SkIntToScalar(30)); |
| 577 | canvas->save(); |
| 578 | canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
| 579 | canvas->save(); |
| 580 | canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
| 581 | canvas->drawRect(kTestRect,kTestPaint); |
| 582 | canvas->flush(); |
| 583 | canvas->restore(); |
| 584 | canvas->restore(); |
| 585 | } |
| 586 | TEST_STEP(NestedSaveRestoreWithFlush, \ |
| 587 | NestedSaveRestoreWithFlushTestStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 588 | |
| 589 | static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 590 | const SkCanvas* canvas1, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 591 | const SkCanvas* canvas2, |
| 592 | CanvasTestStep* testStep) { |
| 593 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == |
| 594 | canvas2->getDeviceSize(), testStep->assertMessage()); |
| 595 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == |
| 596 | canvas2->getSaveCount(), testStep->assertMessage()); |
| 597 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->isDrawingToLayer() == |
| 598 | canvas2->isDrawingToLayer(), testStep->assertMessage()); |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 599 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 600 | SkRect bounds1, bounds2; |
| 601 | REPORTER_ASSERT_MESSAGE(reporter, |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 602 | canvas1->getClipBounds(&bounds1) == canvas2->getClipBounds(&bounds2), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 603 | testStep->assertMessage()); |
| 604 | REPORTER_ASSERT_MESSAGE(reporter, bounds1 == bounds2, |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 605 | testStep->assertMessage()); |
| 606 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 607 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDrawFilter() == |
| 608 | canvas2->getDrawFilter(), testStep->assertMessage()); |
| 609 | SkIRect deviceBounds1, deviceBounds2; |
| 610 | REPORTER_ASSERT_MESSAGE(reporter, |
| 611 | canvas1->getClipDeviceBounds(&deviceBounds1) == |
| 612 | canvas2->getClipDeviceBounds(&deviceBounds2), |
| 613 | testStep->assertMessage()); |
| 614 | REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, |
| 615 | testStep->assertMessage()); |
| 616 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getBounder() == |
| 617 | canvas2->getBounder(), testStep->assertMessage()); |
| 618 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() == |
| 619 | canvas2->getTotalMatrix(), testStep->assertMessage()); |
| 620 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getClipType() == |
| 621 | canvas2->getClipType(), testStep->assertMessage()); |
| 622 | REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalClip() == |
| 623 | canvas2->getTotalClip(), testStep->assertMessage()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 624 | |
| 625 | // The following test code is commented out because the test fails when |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 626 | // the canvas is an SkPictureRecord or SkDeferredCanvas |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 627 | // Issue: http://code.google.com/p/skia/issues/detail?id=498 |
| 628 | // Also, creating a LayerIter on an SkProxyCanvas crashes |
| 629 | // Issue: http://code.google.com/p/skia/issues/detail?id=499 |
| 630 | /* |
| 631 | SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); |
| 632 | SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); |
| 633 | while (!layerIter1.done() && !layerIter2.done()) { |
| 634 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.matrix() == |
| 635 | layerIter2.matrix(), testStep->assertMessage()); |
| 636 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.clip() == |
| 637 | layerIter2.clip(), testStep->assertMessage()); |
| 638 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.paint() == |
| 639 | layerIter2.paint(), testStep->assertMessage()); |
| 640 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.x() == |
| 641 | layerIter2.x(), testStep->assertMessage()); |
| 642 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.y() == |
| 643 | layerIter2.y(), testStep->assertMessage()); |
| 644 | layerIter1.next(); |
| 645 | layerIter2.next(); |
| 646 | } |
| 647 | REPORTER_ASSERT_MESSAGE(reporter, layerIter1.done(), |
| 648 | testStep->assertMessage()); |
| 649 | REPORTER_ASSERT_MESSAGE(reporter, layerIter2.done(), |
| 650 | testStep->assertMessage()); |
| 651 | */ |
| 652 | } |
| 653 | |
| 654 | // The following class groups static functions that need to access |
| 655 | // the privates members of SkPictureRecord |
| 656 | class SkPictureTester { |
| 657 | private: |
reed@google.com | e2589ae | 2012-07-10 19:38:01 +0000 | [diff] [blame] | 658 | static int EQ(const SkFlatData* a, const SkFlatData* b) { |
| 659 | return *a == *b; |
| 660 | } |
| 661 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 662 | static void AssertFlattenedObjectsEqual( |
| 663 | SkPictureRecord* referenceRecord, |
| 664 | SkPictureRecord* testRecord, |
| 665 | skiatest::Reporter* reporter, |
| 666 | CanvasTestStep* testStep) { |
| 667 | |
| 668 | REPORTER_ASSERT_MESSAGE(reporter, |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 669 | referenceRecord->fBitmapHeap->count() == |
| 670 | testRecord->fBitmapHeap->count(), testStep->assertMessage()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 671 | REPORTER_ASSERT_MESSAGE(reporter, |
| 672 | referenceRecord->fMatrices.count() == |
| 673 | testRecord->fMatrices.count(), testStep->assertMessage()); |
| 674 | for (int i = 0; i < referenceRecord->fMatrices.count(); ++i) { |
| 675 | REPORTER_ASSERT_MESSAGE(reporter, |
reed@google.com | e2589ae | 2012-07-10 19:38:01 +0000 | [diff] [blame] | 676 | EQ(referenceRecord->fMatrices[i], testRecord->fMatrices[i]), |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 677 | testStep->assertMessage()); |
| 678 | } |
| 679 | REPORTER_ASSERT_MESSAGE(reporter, |
| 680 | referenceRecord->fPaints.count() == |
| 681 | testRecord->fPaints.count(), testStep->assertMessage()); |
| 682 | for (int i = 0; i < referenceRecord->fPaints.count(); ++i) { |
| 683 | REPORTER_ASSERT_MESSAGE(reporter, |
reed@google.com | e2589ae | 2012-07-10 19:38:01 +0000 | [diff] [blame] | 684 | EQ(referenceRecord->fPaints[i], testRecord->fPaints[i]), |
| 685 | testStep->assertMessage()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 686 | } |
| 687 | REPORTER_ASSERT_MESSAGE(reporter, |
| 688 | referenceRecord->fRegions.count() == |
| 689 | testRecord->fRegions.count(), testStep->assertMessage()); |
| 690 | for (int i = 0; i < referenceRecord->fRegions.count(); ++i) { |
| 691 | REPORTER_ASSERT_MESSAGE(reporter, |
reed@google.com | e2589ae | 2012-07-10 19:38:01 +0000 | [diff] [blame] | 692 | EQ(referenceRecord->fRegions[i], testRecord->fRegions[i]), |
| 693 | testStep->assertMessage()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 694 | } |
| 695 | REPORTER_ASSERT_MESSAGE(reporter, |
| 696 | !referenceRecord->fPathHeap == |
| 697 | !testRecord->fPathHeap, |
| 698 | testStep->assertMessage()); |
junov@chromium.org | dadcfdc | 2012-02-23 14:59:22 +0000 | [diff] [blame] | 699 | // The following tests are commented out because they currently |
| 700 | // fail. Issue: http://code.google.com/p/skia/issues/detail?id=507 |
| 701 | /* |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 702 | if (referenceRecord->fPathHeap) { |
| 703 | REPORTER_ASSERT_MESSAGE(reporter, |
| 704 | referenceRecord->fPathHeap->count() == |
| 705 | testRecord->fPathHeap->count(), |
| 706 | testStep->assertMessage()); |
| 707 | for (int i = 0; i < referenceRecord->fPathHeap->count(); ++i) { |
| 708 | REPORTER_ASSERT_MESSAGE(reporter, |
| 709 | (*referenceRecord->fPathHeap)[i] == |
| 710 | (*testRecord->fPathHeap)[i], testStep->assertMessage()); |
| 711 | } |
| 712 | } |
junov@chromium.org | dadcfdc | 2012-02-23 14:59:22 +0000 | [diff] [blame] | 713 | */ |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 714 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | public: |
| 718 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 719 | static void TestPictureFlattenedObjectReuse(skiatest::Reporter* reporter, |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 720 | CanvasTestStep* testStep, |
| 721 | uint32_t recordFlags) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 722 | // Verify that when a test step is executed twice, no extra resources |
| 723 | // are flattened during the second execution |
| 724 | testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat); |
| 725 | SkPicture referencePicture; |
| 726 | SkCanvas* referenceCanvas = referencePicture.beginRecording(kWidth, |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 727 | kHeight, recordFlags); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 728 | testStep->draw(referenceCanvas, reporter); |
| 729 | SkPicture testPicture; |
junov@chromium.org | dadcfdc | 2012-02-23 14:59:22 +0000 | [diff] [blame] | 730 | SkCanvas* testCanvas = testPicture.beginRecording(kWidth, |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 731 | kHeight, recordFlags); |
junov@chromium.org | dadcfdc | 2012-02-23 14:59:22 +0000 | [diff] [blame] | 732 | testStep->draw(testCanvas, reporter); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 733 | testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat); |
junov@chromium.org | dadcfdc | 2012-02-23 14:59:22 +0000 | [diff] [blame] | 734 | testStep->draw(testCanvas, reporter); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 735 | |
| 736 | SkPictureRecord* referenceRecord = static_cast<SkPictureRecord*>( |
| 737 | referenceCanvas); |
| 738 | SkPictureRecord* testRecord = static_cast<SkPictureRecord*>( |
| 739 | testCanvas); |
| 740 | testStep->setAssertMessageFormat(kPictureResourceReuseMessageFormat); |
| 741 | AssertFlattenedObjectsEqual(referenceRecord, testRecord, |
junov@chromium.org | 76b9c4b | 2012-02-22 21:24:41 +0000 | [diff] [blame] | 742 | reporter, testStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 743 | } |
| 744 | }; |
| 745 | |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 746 | static void TestPdfDevice(skiatest::Reporter* reporter, |
| 747 | CanvasTestStep* testStep) { |
| 748 | SkISize pageSize = SkISize::Make(kWidth, kHeight); |
| 749 | SkPDFDevice device(pageSize, pageSize, SkMatrix::I()); |
| 750 | SkCanvas canvas(&device); |
| 751 | testStep->setAssertMessageFormat(kPdfAssertMessageFormat); |
| 752 | testStep->draw(&canvas, reporter); |
| 753 | SkPDFDocument doc; |
| 754 | doc.appendPage(&device); |
| 755 | SkDynamicMemoryWStream stream; |
| 756 | doc.emitPDF(&stream); |
| 757 | } |
| 758 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 759 | // The following class groups static functions that need to access |
| 760 | // the privates members of SkDeferredCanvas |
| 761 | class SkDeferredCanvasTester { |
| 762 | public: |
| 763 | static void TestDeferredCanvasStateConsistency( |
| 764 | skiatest::Reporter* reporter, |
| 765 | CanvasTestStep* testStep, |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 766 | const SkCanvas& referenceCanvas, bool silent) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 767 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 768 | SkBitmap deferredStore; |
| 769 | createBitmap(&deferredStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 770 | SkBitmapDevice deferredDevice(deferredStore); |
commit-bot@chromium.org | cb62224 | 2013-08-09 14:24:59 +0000 | [diff] [blame] | 771 | SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(&deferredDevice)); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 772 | testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 773 | testStep->draw(deferredCanvas, reporter); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 774 | testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 775 | AssertCanvasStatesEqual(reporter, deferredCanvas, &referenceCanvas, |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 776 | testStep); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 777 | |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 778 | if (silent) { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 779 | deferredCanvas->silentFlush(); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 780 | } else { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 781 | deferredCanvas->flush(); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 782 | } |
| 783 | |
skia.committer@gmail.com | 4c5ea44 | 2012-09-21 02:01:01 +0000 | [diff] [blame] | 784 | testStep->setAssertMessageFormat( |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 785 | silent ? kDeferredPostSilentFlushPlaybackAssertMessageFormat : |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 786 | kDeferredPostFlushPlaybackAssertMessageFormat); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 787 | AssertCanvasStatesEqual(reporter, |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 788 | deferredCanvas->immediateCanvas(), |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 789 | &referenceCanvas, testStep); |
junov@chromium.org | cff01c5 | 2012-07-18 21:50:26 +0000 | [diff] [blame] | 790 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 791 | // Verified that deferred canvas state is not affected by flushing |
| 792 | // pending draw operations |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 793 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 794 | // The following test code is commented out because it currently fails. |
| 795 | // Issue: http://code.google.com/p/skia/issues/detail?id=496 |
| 796 | /* |
| 797 | testStep->setAssertMessageFormat(kDeferredPostFlushAssertMessageFormat); |
| 798 | AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas, |
| 799 | testStep); |
| 800 | */ |
| 801 | } |
| 802 | }; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 803 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 804 | // unused |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 805 | static void TestProxyCanvasStateConsistency( |
| 806 | skiatest::Reporter* reporter, |
| 807 | CanvasTestStep* testStep, |
| 808 | const SkCanvas& referenceCanvas) { |
| 809 | |
| 810 | SkBitmap indirectStore; |
| 811 | createBitmap(&indirectStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 812 | SkBitmapDevice indirectDevice(indirectStore); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 813 | SkCanvas indirectCanvas(&indirectDevice); |
| 814 | SkProxyCanvas proxyCanvas(&indirectCanvas); |
| 815 | testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat); |
| 816 | testStep->draw(&proxyCanvas, reporter); |
| 817 | // Verify that the SkProxyCanvas reports consitent state |
| 818 | testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat); |
| 819 | AssertCanvasStatesEqual(reporter, &proxyCanvas, &referenceCanvas, |
| 820 | testStep); |
| 821 | // Verify that the indirect canvas reports consitent state |
| 822 | testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat); |
| 823 | AssertCanvasStatesEqual(reporter, &indirectCanvas, &referenceCanvas, |
| 824 | testStep); |
| 825 | } |
| 826 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 827 | // unused |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 828 | static void TestNWayCanvasStateConsistency( |
| 829 | skiatest::Reporter* reporter, |
| 830 | CanvasTestStep* testStep, |
| 831 | const SkCanvas& referenceCanvas) { |
| 832 | |
| 833 | SkBitmap indirectStore1; |
| 834 | createBitmap(&indirectStore1, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 835 | SkBitmapDevice indirectDevice1(indirectStore1); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 836 | SkCanvas indirectCanvas1(&indirectDevice1); |
| 837 | |
| 838 | SkBitmap indirectStore2; |
| 839 | createBitmap(&indirectStore2, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 840 | SkBitmapDevice indirectDevice2(indirectStore2); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 841 | SkCanvas indirectCanvas2(&indirectDevice2); |
| 842 | |
djsollen@google.com | f0a062b | 2012-05-01 16:50:25 +0000 | [diff] [blame] | 843 | SkISize canvasSize = referenceCanvas.getDeviceSize(); |
| 844 | SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height()); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 845 | nWayCanvas.addCanvas(&indirectCanvas1); |
| 846 | nWayCanvas.addCanvas(&indirectCanvas2); |
| 847 | |
| 848 | testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat); |
| 849 | testStep->draw(&nWayCanvas, reporter); |
| 850 | // Verify that the SkProxyCanvas reports consitent state |
| 851 | testStep->setAssertMessageFormat(kNWayStateAssertMessageFormat); |
| 852 | AssertCanvasStatesEqual(reporter, &nWayCanvas, &referenceCanvas, |
| 853 | testStep); |
| 854 | // Verify that the indirect canvases report consitent state |
| 855 | testStep->setAssertMessageFormat(kNWayIndirect1StateAssertMessageFormat); |
| 856 | AssertCanvasStatesEqual(reporter, &indirectCanvas1, &referenceCanvas, |
| 857 | testStep); |
| 858 | testStep->setAssertMessageFormat(kNWayIndirect2StateAssertMessageFormat); |
| 859 | AssertCanvasStatesEqual(reporter, &indirectCanvas2, &referenceCanvas, |
| 860 | testStep); |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * This sub-test verifies that the test step passes when executed |
| 865 | * with SkCanvas and with classes derrived from SkCanvas. It also verifies |
| 866 | * that the all canvas derivatives report the same state as an SkCanvas |
| 867 | * after having executed the test step. |
| 868 | */ |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 869 | static void TestOverrideStateConsistency(skiatest::Reporter* reporter, |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 870 | CanvasTestStep* testStep) { |
| 871 | SkBitmap referenceStore; |
| 872 | createBitmap(&referenceStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 873 | SkBitmapDevice referenceDevice(referenceStore); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 874 | SkCanvas referenceCanvas(&referenceDevice); |
| 875 | testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); |
| 876 | testStep->draw(&referenceCanvas, reporter); |
| 877 | |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 878 | SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testStep, referenceCanvas, false); |
| 879 | |
| 880 | SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testStep, referenceCanvas, true); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 881 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 882 | // The following test code is disabled because SkProxyCanvas is |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 883 | // missing a lot of virtual overrides on get* methods, which are used |
| 884 | // to verify canvas state. |
| 885 | // Issue: http://code.google.com/p/skia/issues/detail?id=500 |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 886 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 887 | if (false) { // avoid bit rot, suppress warning |
| 888 | TestProxyCanvasStateConsistency(reporter, testStep, referenceCanvas); |
| 889 | } |
| 890 | |
| 891 | // The following test code is disabled because SkNWayCanvas does not |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 892 | // report correct clipping and device bounds information |
| 893 | // Issue: http://code.google.com/p/skia/issues/detail?id=501 |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 894 | |
| 895 | if (false) { // avoid bit rot, suppress warning |
| 896 | TestNWayCanvasStateConsistency(reporter, testStep, referenceCanvas); |
| 897 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 898 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 899 | if (false) { // avoid bit rot, suppress warning |
| 900 | test_clipVisitor(reporter, &referenceCanvas); |
| 901 | } |
reed@google.com | 7c20293 | 2011-12-14 18:48:05 +0000 | [diff] [blame] | 902 | } |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 903 | |
| 904 | static void TestCanvas(skiatest::Reporter* reporter) { |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 905 | // Init global here because bitmap pixels cannot be alocated during |
| 906 | // static initialization |
| 907 | kTestBitmap = testBitmap(); |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 908 | |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 909 | for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
| 910 | TestOverrideStateConsistency(reporter, testStepArray()[testStep]); |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 911 | SkPictureTester::TestPictureFlattenedObjectReuse(reporter, |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 912 | testStepArray()[testStep], 0); |
edisonn@google.com | 7790912 | 2012-10-18 15:58:23 +0000 | [diff] [blame] | 913 | if (testStepArray()[testStep]->enablePdfTesting()) { |
| 914 | TestPdfDevice(reporter, testStepArray()[testStep]); |
| 915 | } |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 916 | } |
junov@chromium.org | cd62ecf | 2012-08-02 17:43:25 +0000 | [diff] [blame] | 917 | |
| 918 | // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap is a global) |
| 919 | kTestBitmap.reset(); |
reed@google.com | 37f3ae0 | 2011-11-28 16:06:04 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | #include "TestClassDef.h" |
| 923 | DEFINE_TESTCLASS("Canvas", TestCanvasClass, TestCanvas) |