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