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