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