junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 7 | |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 8 | #include "../src/image/SkImagePriv.h" |
| 9 | #include "../src/image/SkSurface_Base.h" |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 10 | #include "SkBitmap.h" |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 11 | #include "SkBitmapDevice.h" |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 12 | #include "SkBitmapProcShader.h" |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 13 | #include "SkDeferredCanvas.h" |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 14 | #include "SkGradientShader.h" |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 15 | #include "SkShader.h" |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 16 | #include "SkSurface.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 17 | #include "Test.h" |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 18 | #include "sk_tool_utils.h" |
| 19 | |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 20 | #if SK_SUPPORT_GPU |
| 21 | #include "GrContextFactory.h" |
| 22 | #else |
| 23 | class GrContextFactory; |
| 24 | #endif |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 25 | |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 26 | static const int gWidth = 2; |
| 27 | static const int gHeight = 2; |
| 28 | |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 29 | static void create(SkBitmap* bm, SkColor color) { |
| 30 | bm->allocN32Pixels(gWidth, gHeight); |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 31 | bm->eraseColor(color); |
| 32 | } |
| 33 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 34 | static SkSurface* createSurface(SkColor color) { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 35 | SkSurface* surface = SkSurface::NewRasterN32Premul(gWidth, gHeight); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 36 | surface->getCanvas()->clear(color); |
| 37 | return surface; |
| 38 | } |
| 39 | |
| 40 | static SkPMColor read_pixel(SkSurface* surface, int x, int y) { |
| 41 | SkPMColor pixel = 0; |
| 42 | SkBitmap bitmap; |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 43 | bitmap.installPixels(SkImageInfo::MakeN32Premul(1, 1), &pixel, 4); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 44 | SkCanvas canvas(bitmap); |
| 45 | |
| 46 | SkPaint paint; |
| 47 | paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
reed@google.com | d52a997 | 2014-02-04 16:14:58 +0000 | [diff] [blame] | 48 | surface->draw(&canvas, -SkIntToScalar(x), -SkIntToScalar(y), &paint); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 49 | return pixel; |
| 50 | } |
| 51 | |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 52 | class MockSurface : public SkSurface_Base { |
| 53 | public: |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 54 | MockSurface(int width, int height) : SkSurface_Base(width, height, NULL) { |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 55 | clearCounts(); |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 56 | fBitmap.allocN32Pixels(width, height); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 57 | } |
| 58 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 59 | SkCanvas* onNewCanvas() override { |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 60 | return SkNEW_ARGS(SkCanvas, (fBitmap)); |
| 61 | } |
| 62 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 63 | SkSurface* onNewSurface(const SkImageInfo&) override { |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 64 | return NULL; |
| 65 | } |
| 66 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 67 | SkImage* onNewImageSnapshot(Budgeted) override { |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 68 | return SkNewImageFromBitmap(fBitmap, true, &this->props()); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 69 | } |
| 70 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 71 | void onCopyOnWrite(ContentChangeMode mode) override { |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 72 | if (mode == SkSurface::kDiscard_ContentChangeMode) { |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 73 | fCOWDiscardCount++; |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 74 | } else { |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 75 | fCOWRetainCount++; |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 79 | void onDiscard() override { |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 80 | fDiscardCount++; |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 81 | } |
| 82 | |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 83 | void clearCounts() { |
| 84 | fCOWDiscardCount = 0; |
| 85 | fCOWRetainCount = 0; |
| 86 | fDiscardCount = 0; |
| 87 | } |
| 88 | |
| 89 | int fCOWDiscardCount; |
| 90 | int fCOWRetainCount; |
| 91 | int fDiscardCount; |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 92 | SkBitmap fBitmap; |
| 93 | }; |
| 94 | |
| 95 | static void TestDeferredCanvasWritePixelsToSurface(skiatest::Reporter* reporter) { |
| 96 | SkAutoTUnref<MockSurface> surface(SkNEW_ARGS(MockSurface, (10, 10))); |
commit-bot@chromium.org | cb62224 | 2013-08-09 14:24:59 +0000 | [diff] [blame] | 97 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 98 | |
| 99 | SkBitmap srcBitmap; |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 100 | srcBitmap.allocPixels(SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType)); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 101 | srcBitmap.eraseColor(SK_ColorGREEN); |
| 102 | // Tests below depend on this bitmap being recognized as opaque |
| 103 | |
| 104 | // Preliminary sanity check: no copy on write if no active snapshot |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 105 | // Discard notification happens on SkSurface::onDiscard, since no |
| 106 | // active snapshot. |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 107 | surface->clearCounts(); |
| 108 | canvas->clear(SK_ColorWHITE); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 109 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 110 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 111 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 112 | |
| 113 | surface->clearCounts(); |
| 114 | canvas->flush(); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 115 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 116 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
| 117 | REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 118 | |
| 119 | // Case 1: Discard notification happens upon flushing |
| 120 | // with an Image attached. |
| 121 | surface->clearCounts(); |
| 122 | SkAutoTUnref<SkImage> image1(canvas->newImageSnapshot()); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 124 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 125 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 126 | |
| 127 | surface->clearCounts(); |
| 128 | canvas->clear(SK_ColorWHITE); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 129 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 130 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 131 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 132 | |
| 133 | surface->clearCounts(); |
| 134 | canvas->flush(); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 135 | REPORTER_ASSERT(reporter, 1 == surface->fCOWDiscardCount); |
| 136 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
| 137 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 138 | |
| 139 | // Case 2: Opaque writePixels |
| 140 | surface->clearCounts(); |
| 141 | SkAutoTUnref<SkImage> image2(canvas->newImageSnapshot()); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 142 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 143 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 145 | |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 146 | // Case 3: writePixels that partially covers the canvas |
| 147 | surface->clearCounts(); |
| 148 | SkAutoTUnref<SkImage> image3(canvas->newImageSnapshot()); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 150 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 151 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 152 | |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 153 | // Case 4: unpremultiplied opaque writePixels that entirely |
| 154 | // covers the canvas |
| 155 | surface->clearCounts(); |
| 156 | SkAutoTUnref<SkImage> image4(canvas->newImageSnapshot()); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 157 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 158 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 159 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 160 | |
| 161 | surface->clearCounts(); |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 162 | canvas->writePixels(srcBitmap, 0, 0); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 163 | REPORTER_ASSERT(reporter, 1 == surface->fCOWDiscardCount); |
| 164 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
| 165 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 166 | |
| 167 | surface->clearCounts(); |
| 168 | canvas->flush(); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 169 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 170 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 171 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 172 | |
| 173 | // Case 5: unpremultiplied opaque writePixels that partially |
| 174 | // covers the canvas |
| 175 | surface->clearCounts(); |
| 176 | SkAutoTUnref<SkImage> image5(canvas->newImageSnapshot()); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 177 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 178 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 179 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 180 | |
| 181 | surface->clearCounts(); |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 182 | canvas->writePixels(srcBitmap, 5, 0); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 183 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 184 | REPORTER_ASSERT(reporter, 1 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 185 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 186 | |
| 187 | surface->clearCounts(); |
| 188 | canvas->flush(); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 189 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 190 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 191 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 192 | |
| 193 | // Case 6: unpremultiplied opaque writePixels that entirely |
| 194 | // covers the canvas, preceded by clear |
| 195 | surface->clearCounts(); |
| 196 | SkAutoTUnref<SkImage> image6(canvas->newImageSnapshot()); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 197 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 198 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 199 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 200 | |
| 201 | surface->clearCounts(); |
| 202 | canvas->clear(SK_ColorWHITE); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 203 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 204 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 205 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 206 | |
| 207 | surface->clearCounts(); |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 208 | canvas->writePixels(srcBitmap, 0, 0); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 209 | REPORTER_ASSERT(reporter, 1 == surface->fCOWDiscardCount); |
| 210 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
| 211 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 212 | |
| 213 | surface->clearCounts(); |
| 214 | canvas->flush(); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 215 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 216 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 217 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 218 | |
| 219 | // Case 7: unpremultiplied opaque writePixels that partially |
| 220 | // covers the canvas, preceeded by a clear |
| 221 | surface->clearCounts(); |
| 222 | SkAutoTUnref<SkImage> image7(canvas->newImageSnapshot()); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 223 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 224 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 225 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 226 | |
| 227 | surface->clearCounts(); |
| 228 | canvas->clear(SK_ColorWHITE); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 229 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 230 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 231 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 232 | |
| 233 | surface->clearCounts(); |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 234 | canvas->writePixels(srcBitmap, 5, 0); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 235 | REPORTER_ASSERT(reporter, 1 == surface->fCOWDiscardCount); // because of the clear |
| 236 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
| 237 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 238 | |
| 239 | surface->clearCounts(); |
| 240 | canvas->flush(); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 241 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 242 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 243 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 244 | |
| 245 | // Case 8: unpremultiplied opaque writePixels that partially |
| 246 | // covers the canvas, preceeded by a drawREct that partially |
| 247 | // covers the canvas |
| 248 | surface->clearCounts(); |
| 249 | SkAutoTUnref<SkImage> image8(canvas->newImageSnapshot()); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 250 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 251 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 252 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 253 | |
| 254 | surface->clearCounts(); |
| 255 | SkPaint paint; |
| 256 | canvas->drawRect(SkRect::MakeLTRB(0, 0, 5, 5), paint); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 257 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 258 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 259 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 260 | |
| 261 | surface->clearCounts(); |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 262 | canvas->writePixels(srcBitmap, 5, 0); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 263 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 264 | REPORTER_ASSERT(reporter, 1 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 265 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 266 | |
| 267 | surface->clearCounts(); |
| 268 | canvas->flush(); |
kkinnunen | 8dcb8b0 | 2015-03-23 02:18:02 -0700 | [diff] [blame] | 269 | REPORTER_ASSERT(reporter, 0 == surface->fCOWDiscardCount); |
| 270 | REPORTER_ASSERT(reporter, 0 == surface->fCOWRetainCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 271 | REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 272 | } |
| 273 | |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 274 | static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) { |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 275 | SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
| 276 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 277 | |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 278 | canvas->clear(0x00000000); |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 279 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 280 | // verify that clear was deferred |
| 281 | REPORTER_ASSERT(reporter, 0xFFFFFFFF == read_pixel(surface, 0, 0)); |
| 282 | |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 283 | canvas->flush(); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 284 | |
| 285 | // verify that clear was executed |
| 286 | REPORTER_ASSERT(reporter, 0 == read_pixel(surface, 0, 0)); |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 287 | } |
| 288 | |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 289 | static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 290 | SkRect fullRect; |
| 291 | fullRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth), |
| 292 | SkIntToScalar(gHeight)); |
| 293 | SkRect partialRect; |
junov@chromium.org | b1e218e | 2012-02-13 22:27:58 +0000 | [diff] [blame] | 294 | partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 295 | SkIntToScalar(1), SkIntToScalar(1)); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 296 | |
| 297 | SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
| 298 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 299 | |
| 300 | // verify that frame is intially fresh |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 301 | REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 302 | // no clearing op since last call to isFreshFrame -> not fresh |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 303 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 304 | |
| 305 | // Verify that clear triggers a fresh frame |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 306 | canvas->clear(0x00000000); |
| 307 | REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 308 | |
| 309 | // Verify that clear with saved state triggers a fresh frame |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 310 | canvas->save(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 311 | canvas->clear(0x00000000); |
| 312 | canvas->restore(); |
| 313 | REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 314 | |
| 315 | // Verify that clear within a layer does NOT trigger a fresh frame |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 316 | canvas->saveLayer(NULL, NULL); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 317 | canvas->clear(0x00000000); |
| 318 | canvas->restore(); |
| 319 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 320 | |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 321 | // Verify that full frame rects with different forms of opaque paint |
| 322 | // trigger frames to be marked as fresh |
| 323 | { |
| 324 | SkPaint paint; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 325 | paint.setStyle(SkPaint::kFill_Style); |
| 326 | paint.setAlpha(255); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 327 | canvas->drawRect(fullRect, paint); |
| 328 | REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 329 | } |
skia.committer@gmail.com | 5b6f916 | 2012-10-12 02:01:15 +0000 | [diff] [blame] | 330 | { |
junov@chromium.org | 8cef67a | 2012-10-11 20:19:15 +0000 | [diff] [blame] | 331 | SkPaint paint; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 332 | paint.setStyle(SkPaint::kFill_Style); |
| 333 | paint.setAlpha(255); |
junov@chromium.org | 8cef67a | 2012-10-11 20:19:15 +0000 | [diff] [blame] | 334 | paint.setXfermodeMode(SkXfermode::kSrcIn_Mode); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 335 | canvas->drawRect(fullRect, paint); |
| 336 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8cef67a | 2012-10-11 20:19:15 +0000 | [diff] [blame] | 337 | } |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 338 | { |
| 339 | SkPaint paint; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 340 | paint.setStyle(SkPaint::kFill_Style); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 341 | SkBitmap bmp; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 342 | create(&bmp, 0xFFFFFFFF); |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 343 | bmp.setAlphaType(kOpaque_SkAlphaType); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 344 | SkShader* shader = SkShader::CreateBitmapShader(bmp, |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 345 | SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| 346 | paint.setShader(shader)->unref(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 347 | canvas->drawRect(fullRect, paint); |
| 348 | REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | // Verify that full frame rects with different forms of non-opaque paint |
| 352 | // do not trigger frames to be marked as fresh |
| 353 | { |
| 354 | SkPaint paint; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 355 | paint.setStyle(SkPaint::kFill_Style); |
| 356 | paint.setAlpha(254); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 357 | canvas->drawRect(fullRect, paint); |
| 358 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 359 | } |
| 360 | { |
| 361 | SkPaint paint; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 362 | paint.setStyle(SkPaint::kFill_Style); |
| 363 | // Defining a cone that partially overlaps the canvas |
| 364 | const SkPoint pt1 = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0)); |
| 365 | const SkScalar r1 = SkIntToScalar(1); |
| 366 | const SkPoint pt2 = SkPoint::Make(SkIntToScalar(10), SkIntToScalar(0)); |
| 367 | const SkScalar r2 = SkIntToScalar(5); |
| 368 | const SkColor colors[2] = {SK_ColorWHITE, SK_ColorWHITE}; |
| 369 | const SkScalar pos[2] = {0, SK_Scalar1}; |
| 370 | SkShader* shader = SkGradientShader::CreateTwoPointConical( |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 371 | pt1, r1, pt2, r2, colors, pos, 2, SkShader::kClamp_TileMode); |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 372 | paint.setShader(shader)->unref(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 373 | canvas->drawRect(fullRect, paint); |
| 374 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 375 | } |
| 376 | { |
| 377 | SkPaint paint; |
| 378 | paint.setStyle(SkPaint::kFill_Style); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 379 | SkBitmap bmp; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 380 | create(&bmp, 0xFFFFFFFF); |
reed@google.com | 383a697 | 2013-10-21 14:00:07 +0000 | [diff] [blame] | 381 | bmp.setAlphaType(kPremul_SkAlphaType); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 382 | SkShader* shader = SkShader::CreateBitmapShader(bmp, |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 383 | SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| 384 | paint.setShader(shader)->unref(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 385 | canvas->drawRect(fullRect, paint); |
| 386 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | // Verify that incomplete coverage does not trigger a fresh frame |
| 390 | { |
| 391 | SkPaint paint; |
| 392 | paint.setStyle(SkPaint::kFill_Style); |
| 393 | paint.setAlpha(255); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 394 | canvas->drawRect(partialRect, paint); |
| 395 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // Verify that incomplete coverage due to clipping does not trigger a fresh |
| 399 | // frame |
| 400 | { |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 401 | canvas->save(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 402 | canvas->clipRect(partialRect, SkRegion::kIntersect_Op, false); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 403 | SkPaint paint; |
| 404 | paint.setStyle(SkPaint::kFill_Style); |
| 405 | paint.setAlpha(255); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 406 | canvas->drawRect(fullRect, paint); |
| 407 | canvas->restore(); |
| 408 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 409 | } |
junov@chromium.org | 8f0ca06 | 2012-12-13 16:30:39 +0000 | [diff] [blame] | 410 | { |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 411 | canvas->save(); |
junov@chromium.org | 8f0ca06 | 2012-12-13 16:30:39 +0000 | [diff] [blame] | 412 | SkPaint paint; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 413 | paint.setStyle(SkPaint::kFill_Style); |
| 414 | paint.setAlpha(255); |
junov@chromium.org | 8f0ca06 | 2012-12-13 16:30:39 +0000 | [diff] [blame] | 415 | SkPath path; |
| 416 | path.addCircle(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(2)); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 417 | canvas->clipPath(path, SkRegion::kIntersect_Op, false); |
| 418 | canvas->drawRect(fullRect, paint); |
| 419 | canvas->restore(); |
| 420 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8f0ca06 | 2012-12-13 16:30:39 +0000 | [diff] [blame] | 421 | } |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 422 | |
| 423 | // Verify that stroked rect does not trigger a fresh frame |
| 424 | { |
| 425 | SkPaint paint; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 426 | paint.setStyle(SkPaint::kStroke_Style); |
| 427 | paint.setAlpha(255); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 428 | canvas->drawRect(fullRect, paint); |
| 429 | REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 430 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 431 | |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 432 | // Verify kSrcMode triggers a fresh frame even with transparent color |
| 433 | { |
| 434 | SkPaint paint; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 435 | paint.setStyle(SkPaint::kFill_Style); |
| 436 | paint.setAlpha(100); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 437 | paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 438 | canvas->drawRect(fullRect, paint); |
| 439 | REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 443 | class MockDevice : public SkBitmapDevice { |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 444 | public: |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 445 | MockDevice(const SkBitmap& bm) : SkBitmapDevice(bm) { |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 446 | fDrawBitmapCallCount = 0; |
| 447 | } |
| 448 | virtual void drawBitmap(const SkDraw&, const SkBitmap&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 449 | const SkMatrix&, const SkPaint&) override { |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 450 | fDrawBitmapCallCount++; |
| 451 | } |
| 452 | |
| 453 | int fDrawBitmapCallCount; |
| 454 | }; |
| 455 | |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 456 | class NotificationCounter : public SkDeferredCanvas::NotificationClient { |
| 457 | public: |
| 458 | NotificationCounter() { |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 459 | fPrepareForDrawCount = fStorageAllocatedChangedCount = |
| 460 | fFlushedDrawCommandsCount = fSkippedPendingDrawCommandsCount = 0; |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 461 | } |
| 462 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 463 | void prepareForDraw() override { |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 464 | fPrepareForDrawCount++; |
| 465 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 466 | void storageAllocatedForRecordingChanged(size_t) override { |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 467 | fStorageAllocatedChangedCount++; |
| 468 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 469 | void flushedDrawCommands() override { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 470 | fFlushedDrawCommandsCount++; |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 471 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 472 | void skippedPendingDrawCommands() override { |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 473 | fSkippedPendingDrawCommandsCount++; |
| 474 | } |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 475 | |
| 476 | int fPrepareForDrawCount; |
| 477 | int fStorageAllocatedChangedCount; |
| 478 | int fFlushedDrawCommandsCount; |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 479 | int fSkippedPendingDrawCommandsCount; |
robertphillips@google.com | 5990397 | 2013-02-07 21:02:23 +0000 | [diff] [blame] | 480 | |
| 481 | private: |
| 482 | typedef SkDeferredCanvas::NotificationClient INHERITED; |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 483 | }; |
| 484 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 485 | // Verifies that the deferred canvas triggers a flush when its memory |
| 486 | // limit is exceeded |
| 487 | static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 488 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 489 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 490 | |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 491 | NotificationCounter notificationCounter; |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 492 | canvas->setNotificationClient(¬ificationCounter); |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 493 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 494 | canvas->setMaxRecordingStorage(160000); |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 495 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 496 | SkBitmap sourceImage; |
| 497 | // 100 by 100 image, takes 40,000 bytes in memory |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 498 | sourceImage.allocN32Pixels(100, 100); |
henrik.smiding | 3bb195e | 2014-06-27 08:03:17 -0700 | [diff] [blame] | 499 | sourceImage.eraseColor(SK_ColorGREEN); |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 500 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 501 | for (int i = 0; i < 5; i++) { |
| 502 | sourceImage.notifyPixelsChanged(); // to force re-serialization |
| 503 | canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 504 | } |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 505 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 506 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount); |
| 507 | } |
| 508 | |
commit-bot@chromium.org | dad009b | 2014-03-27 15:48:52 +0000 | [diff] [blame] | 509 | static void TestDeferredCanvasSilentFlush(skiatest::Reporter* reporter) { |
| 510 | SkAutoTUnref<SkSurface> surface(createSurface(0)); |
| 511 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
| 512 | |
| 513 | NotificationCounter notificationCounter; |
| 514 | canvas->setNotificationClient(¬ificationCounter); |
| 515 | |
| 516 | canvas->silentFlush(); // will skip the initial clear that was recorded in createSurface |
| 517 | |
| 518 | REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount); |
| 519 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawCommandsCount); |
| 520 | } |
| 521 | |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 522 | static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 523 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 524 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
| 525 | |
| 526 | NotificationCounter notificationCounter; |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 527 | canvas->setNotificationClient(¬ificationCounter); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 528 | |
| 529 | const int imageCount = 2; |
| 530 | SkBitmap sourceImages[imageCount]; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 531 | for (int i = 0; i < imageCount; i++) { |
| 532 | sourceImages[i].allocN32Pixels(100, 100); |
henrik.smiding | 3bb195e | 2014-06-27 08:03:17 -0700 | [diff] [blame] | 533 | sourceImages[i].eraseColor(SK_ColorGREEN); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | size_t bitmapSize = sourceImages[0].getSize(); |
| 537 | |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 538 | canvas->drawBitmap(sourceImages[0], 0, 0, NULL); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 539 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fStorageAllocatedChangedCount); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 540 | // stored bitmap + drawBitmap command |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 541 | REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > bitmapSize); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 542 | |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 543 | // verify that nothing can be freed at this point |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 544 | REPORTER_ASSERT(reporter, 0 == canvas->freeMemoryIfPossible(~0U)); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 545 | |
| 546 | // verify that flush leaves image in cache |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 547 | REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount); |
| 548 | REPORTER_ASSERT(reporter, 0 == notificationCounter.fPrepareForDrawCount); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 549 | canvas->flush(); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 550 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount); |
| 551 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fPrepareForDrawCount); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 552 | REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() >= bitmapSize); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 553 | |
| 554 | // verify that after a flush, cached image can be freed |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 555 | REPORTER_ASSERT(reporter, canvas->freeMemoryIfPossible(~0U) >= bitmapSize); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 556 | |
| 557 | // Verify that caching works for avoiding multiple copies of the same bitmap |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 558 | canvas->drawBitmap(sourceImages[0], 0, 0, NULL); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 559 | REPORTER_ASSERT(reporter, 2 == notificationCounter.fStorageAllocatedChangedCount); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 560 | canvas->drawBitmap(sourceImages[0], 0, 0, NULL); |
mtklein | 6d88e6c | 2014-07-30 09:17:54 -0700 | [diff] [blame] | 561 | REPORTER_ASSERT(reporter, 2 == notificationCounter.fStorageAllocatedChangedCount); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 562 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 563 | REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() < 2 * bitmapSize); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 564 | |
| 565 | // Verify partial eviction based on bytesToFree |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 566 | canvas->drawBitmap(sourceImages[1], 0, 0, NULL); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 567 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 568 | canvas->flush(); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 569 | REPORTER_ASSERT(reporter, 2 == notificationCounter.fFlushedDrawCommandsCount); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 570 | REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > 2 * bitmapSize); |
| 571 | size_t bytesFreed = canvas->freeMemoryIfPossible(1); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 572 | REPORTER_ASSERT(reporter, 2 == notificationCounter.fFlushedDrawCommandsCount); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 573 | REPORTER_ASSERT(reporter, bytesFreed >= bitmapSize); |
| 574 | REPORTER_ASSERT(reporter, bytesFreed < 2*bitmapSize); |
| 575 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 576 | // Verifiy that partial purge works, image zero is in cache but not reffed by |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 577 | // a pending draw, while image 1 is locked-in. |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 578 | canvas->freeMemoryIfPossible(~0U); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 579 | REPORTER_ASSERT(reporter, 2 == notificationCounter.fFlushedDrawCommandsCount); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 580 | canvas->drawBitmap(sourceImages[0], 0, 0, NULL); |
| 581 | canvas->flush(); |
| 582 | canvas->drawBitmap(sourceImages[1], 0, 0, NULL); |
| 583 | bytesFreed = canvas->freeMemoryIfPossible(~0U); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 584 | // only one bitmap should have been freed. |
| 585 | REPORTER_ASSERT(reporter, bytesFreed >= bitmapSize); |
| 586 | REPORTER_ASSERT(reporter, bytesFreed < 2*bitmapSize); |
| 587 | // Clear for next test |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 588 | canvas->flush(); |
| 589 | canvas->freeMemoryIfPossible(~0U); |
| 590 | REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() < bitmapSize); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 591 | |
| 592 | // Verify the image cache is sensitive to genID bumps |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 593 | canvas->drawBitmap(sourceImages[1], 0, 0, NULL); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 594 | sourceImages[1].notifyPixelsChanged(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 595 | canvas->drawBitmap(sourceImages[1], 0, 0, NULL); |
| 596 | REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > 2*bitmapSize); |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 597 | |
| 598 | // Verify that nothing in this test caused commands to be skipped |
| 599 | REPORTER_ASSERT(reporter, 0 == notificationCounter.fSkippedPendingDrawCommandsCount); |
| 600 | } |
| 601 | |
| 602 | static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 603 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 604 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
| 605 | |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 606 | NotificationCounter notificationCounter; |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 607 | canvas->setNotificationClient(¬ificationCounter); |
| 608 | canvas->clear(0x0); |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 609 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawCommandsCount); |
| 610 | REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 611 | canvas->flush(); |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 612 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawCommandsCount); |
| 613 | REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount); |
| 614 | |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 615 | } |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 616 | |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 617 | static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) { |
| 618 | // This is a regression test for crbug.com/155875 |
| 619 | // This test covers a code path that inserts bitmaps into the bitmap heap through the |
| 620 | // flattening of SkBitmapProcShaders. The refcount in the bitmap heap is maintained through |
| 621 | // the flattening and unflattening of the shader. |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 622 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 623 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 624 | // test will fail if nbIterations is not in sync with |
| 625 | // BITMAPS_TO_KEEP in SkGPipeWrite.cpp |
| 626 | const int nbIterations = 5; |
| 627 | size_t bytesAllocated = 0; |
| 628 | for(int pass = 0; pass < 2; ++pass) { |
| 629 | for(int i = 0; i < nbIterations; ++i) { |
| 630 | SkPaint paint; |
| 631 | SkBitmap paintPattern; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 632 | paintPattern.allocN32Pixels(10, 10); |
henrik.smiding | 3bb195e | 2014-06-27 08:03:17 -0700 | [diff] [blame] | 633 | paintPattern.eraseColor(SK_ColorGREEN); |
skia.committer@gmail.com | 989a95e | 2012-10-18 02:01:23 +0000 | [diff] [blame] | 634 | paint.setShader(SkNEW_ARGS(SkBitmapProcShader, |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 635 | (paintPattern, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode)))->unref(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 636 | canvas->drawPaint(paint); |
| 637 | canvas->flush(); |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 638 | |
| 639 | // In the first pass, memory allocation should be monotonically increasing as |
| 640 | // the bitmap heap slots fill up. In the second pass memory allocation should be |
| 641 | // stable as bitmap heap slots get recycled. |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 642 | size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 643 | if (pass == 0) { |
| 644 | REPORTER_ASSERT(reporter, newBytesAllocated > bytesAllocated); |
| 645 | bytesAllocated = newBytesAllocated; |
| 646 | } else { |
skia.committer@gmail.com | 989a95e | 2012-10-18 02:01:23 +0000 | [diff] [blame] | 647 | REPORTER_ASSERT(reporter, newBytesAllocated == bytesAllocated); |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | } |
skia.committer@gmail.com | 989a95e | 2012-10-18 02:01:23 +0000 | [diff] [blame] | 651 | // All cached resources should be evictable since last canvas call was flush() |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 652 | canvas->freeMemoryIfPossible(~0U); |
| 653 | REPORTER_ASSERT(reporter, 0 == canvas->storageAllocatedForRecording()); |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 654 | } |
| 655 | |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 656 | static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter) { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 657 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); |
skia.committer@gmail.com | 1c9c0d3 | 2012-11-22 02:02:41 +0000 | [diff] [blame] | 658 | |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 659 | SkBitmap sourceImage; |
| 660 | // 100 by 100 image, takes 40,000 bytes in memory |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 661 | sourceImage.allocN32Pixels(100, 100); |
henrik.smiding | 3bb195e | 2014-06-27 08:03:17 -0700 | [diff] [blame] | 662 | sourceImage.eraseColor(SK_ColorGREEN); |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 663 | |
| 664 | // 1 under : should not store the image |
| 665 | { |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 666 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 667 | canvas->setBitmapSizeThreshold(39999); |
| 668 | canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 669 | size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 670 | REPORTER_ASSERT(reporter, newBytesAllocated == 0); |
| 671 | } |
| 672 | |
| 673 | // exact value : should store the image |
| 674 | { |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 675 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 676 | canvas->setBitmapSizeThreshold(40000); |
| 677 | canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 678 | size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 679 | REPORTER_ASSERT(reporter, newBytesAllocated > 0); |
| 680 | } |
| 681 | |
| 682 | // 1 over : should still store the image |
| 683 | { |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 684 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 685 | canvas->setBitmapSizeThreshold(40001); |
| 686 | canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 687 | size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 688 | REPORTER_ASSERT(reporter, newBytesAllocated > 0); |
| 689 | } |
| 690 | } |
| 691 | |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 692 | |
reed | 52d9ac6 | 2014-06-30 09:05:34 -0700 | [diff] [blame] | 693 | typedef const void* PixelPtr; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 694 | // Returns an opaque pointer which, either points to a GrTexture or RAM pixel |
| 695 | // buffer. Used to test pointer equality do determine whether a surface points |
| 696 | // to the same pixel data storage as before. |
reed | 52d9ac6 | 2014-06-30 09:05:34 -0700 | [diff] [blame] | 697 | static PixelPtr get_surface_ptr(SkSurface* surface, bool useGpu) { |
| 698 | #if SK_SUPPORT_GPU |
| 699 | if (useGpu) { |
| 700 | return surface->getCanvas()->internal_private_accessTopLayerRenderTarget()->asTexture(); |
| 701 | } else |
| 702 | #endif |
| 703 | { |
| 704 | return surface->peekPixels(NULL, NULL); |
| 705 | } |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFactory* factory) { |
bungeman@google.com | 2c56cb8 | 2014-02-17 17:02:17 +0000 | [diff] [blame] | 709 | SkImageInfo imageSpec = SkImageInfo::MakeN32Premul(10, 10); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 710 | bool useGpu = SkToBool(factory); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 711 | int cnt; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 712 | #if SK_SUPPORT_GPU |
| 713 | if (useGpu) { |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 714 | cnt = GrContextFactory::kGLContextTypeCnt; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 715 | } else { |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 716 | cnt = 1; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 717 | } |
| 718 | #else |
| 719 | SkASSERT(!useGpu); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 720 | cnt = 1; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 721 | #endif |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 722 | for (int i = 0; i < cnt; ++i) { |
| 723 | SkSurface* surface; |
| 724 | #if SK_SUPPORT_GPU |
| 725 | if (useGpu) { |
| 726 | GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i; |
| 727 | if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
| 728 | continue; |
| 729 | } |
| 730 | GrContext* context = factory->get(glCtxType); |
| 731 | if (NULL == context) { |
| 732 | return; |
| 733 | } |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 734 | |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 735 | surface = |
| 736 | SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, imageSpec, 0, NULL); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 737 | } else |
| 738 | #endif |
| 739 | { |
| 740 | surface = SkSurface::NewRaster(imageSpec); |
| 741 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 742 | SkASSERT(surface); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 743 | SkAutoTUnref<SkSurface> aur(surface); |
| 744 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface)); |
| 745 | |
| 746 | SkImage* image1 = canvas->newImageSnapshot(); |
| 747 | SkAutoTUnref<SkImage> aur_i1(image1); |
| 748 | PixelPtr pixels1 = get_surface_ptr(surface, useGpu); |
| 749 | // The following clear would normally trigger a copy on write, but |
| 750 | // it won't because rendering is deferred. |
| 751 | canvas->clear(SK_ColorBLACK); |
| 752 | // Obtaining a snapshot directly from the surface (as opposed to the |
| 753 | // SkDeferredCanvas) will not trigger a flush of deferred draw operations |
| 754 | // and will therefore return the same image as the previous snapshot. |
| 755 | SkImage* image2 = surface->newImageSnapshot(); |
| 756 | SkAutoTUnref<SkImage> aur_i2(image2); |
| 757 | // Images identical because of deferral |
| 758 | REPORTER_ASSERT(reporter, image1->uniqueID() == image2->uniqueID()); |
| 759 | // Now we obtain a snpshot via the deferred canvas, which triggers a flush. |
| 760 | // Because there is a pending clear, this will generate a different image. |
| 761 | SkImage* image3 = canvas->newImageSnapshot(); |
| 762 | SkAutoTUnref<SkImage> aur_i3(image3); |
| 763 | REPORTER_ASSERT(reporter, image1->uniqueID() != image3->uniqueID()); |
| 764 | // Verify that backing store is now a different buffer because of copy on |
| 765 | // write |
| 766 | PixelPtr pixels2 = get_surface_ptr(surface, useGpu); |
| 767 | REPORTER_ASSERT(reporter, pixels1 != pixels2); |
| 768 | // Verify copy-on write with a draw operation that gets deferred by |
| 769 | // the in order draw buffer. |
| 770 | SkPaint paint; |
| 771 | canvas->drawPaint(paint); |
| 772 | SkImage* image4 = canvas->newImageSnapshot(); // implicit flush |
| 773 | SkAutoTUnref<SkImage> aur_i4(image4); |
| 774 | REPORTER_ASSERT(reporter, image4->uniqueID() != image3->uniqueID()); |
| 775 | PixelPtr pixels3 = get_surface_ptr(surface, useGpu); |
| 776 | REPORTER_ASSERT(reporter, pixels2 != pixels3); |
| 777 | // Verify that a direct canvas flush with a pending draw does not trigger |
| 778 | // a copy on write when the surface is not sharing its buffer with an |
| 779 | // SkImage. |
| 780 | canvas->clear(SK_ColorWHITE); |
| 781 | canvas->flush(); |
| 782 | PixelPtr pixels4 = get_surface_ptr(surface, useGpu); |
| 783 | canvas->drawPaint(paint); |
| 784 | canvas->flush(); |
| 785 | PixelPtr pixels5 = get_surface_ptr(surface, useGpu); |
| 786 | REPORTER_ASSERT(reporter, pixels4 == pixels5); |
| 787 | } |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 788 | } |
| 789 | |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 790 | static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContextFactory* factory) { |
bungeman@google.com | 2c56cb8 | 2014-02-17 17:02:17 +0000 | [diff] [blame] | 791 | SkImageInfo imageSpec = SkImageInfo::MakeN32Premul(10, 10); |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 792 | SkSurface* surface; |
| 793 | SkSurface* alternateSurface; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 794 | bool useGpu = SkToBool(factory); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 795 | int cnt; |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 796 | #if SK_SUPPORT_GPU |
| 797 | if (useGpu) { |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 798 | cnt = GrContextFactory::kGLContextTypeCnt; |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 799 | } else { |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 800 | cnt = 1; |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 801 | } |
| 802 | #else |
| 803 | SkASSERT(!useGpu); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 804 | cnt = 1; |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 805 | #endif |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 806 | |
| 807 | for (int i = 0; i < cnt; ++i) { |
| 808 | #if SK_SUPPORT_GPU |
| 809 | if (useGpu) { |
| 810 | GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i; |
| 811 | if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
| 812 | continue; |
| 813 | } |
| 814 | GrContext* context = factory->get(glCtxType); |
| 815 | if (NULL == context) { |
| 816 | continue; |
| 817 | } |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 818 | surface = |
| 819 | SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, imageSpec, 0, NULL); |
| 820 | alternateSurface = |
| 821 | SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, imageSpec, 0, NULL); |
mtklein | 6d88e6c | 2014-07-30 09:17:54 -0700 | [diff] [blame] | 822 | } else |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 823 | #endif |
| 824 | { |
| 825 | surface = SkSurface::NewRaster(imageSpec); |
| 826 | alternateSurface = SkSurface::NewRaster(imageSpec); |
| 827 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 828 | SkASSERT(surface); |
| 829 | SkASSERT(alternateSurface); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 830 | SkAutoTUnref<SkSurface> aur1(surface); |
| 831 | SkAutoTUnref<SkSurface> aur2(alternateSurface); |
| 832 | PixelPtr pixels1 = get_surface_ptr(surface, useGpu); |
| 833 | PixelPtr pixels2 = get_surface_ptr(alternateSurface, useGpu); |
| 834 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface)); |
| 835 | SkAutoTUnref<SkImage> image1(canvas->newImageSnapshot()); |
| 836 | canvas->setSurface(alternateSurface); |
| 837 | SkAutoTUnref<SkImage> image2(canvas->newImageSnapshot()); |
| 838 | REPORTER_ASSERT(reporter, image1->uniqueID() != image2->uniqueID()); |
| 839 | // Verify that none of the above operations triggered a surface copy on write. |
| 840 | REPORTER_ASSERT(reporter, get_surface_ptr(surface, useGpu) == pixels1); |
| 841 | REPORTER_ASSERT(reporter, get_surface_ptr(alternateSurface, useGpu) == pixels2); |
| 842 | // Verify that a flushed draw command will trigger a copy on write on alternateSurface. |
| 843 | canvas->clear(SK_ColorWHITE); |
| 844 | canvas->flush(); |
| 845 | REPORTER_ASSERT(reporter, get_surface_ptr(surface, useGpu) == pixels1); |
| 846 | REPORTER_ASSERT(reporter, get_surface_ptr(alternateSurface, useGpu) != pixels2); |
| 847 | } |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 848 | } |
| 849 | |
junov@chromium.org | b1c725a | 2013-05-21 20:16:17 +0000 | [diff] [blame] | 850 | static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporter) { |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 851 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 852 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
| 853 | |
junov@chromium.org | b1c725a | 2013-05-21 20:16:17 +0000 | [diff] [blame] | 854 | NotificationCounter notificationCounter; |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 855 | canvas->setNotificationClient(¬ificationCounter); |
reed@google.com | 28183b4 | 2014-02-04 15:34:10 +0000 | [diff] [blame] | 856 | |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 857 | SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
| 858 | SkAutoTUnref<SkSurface> secondarySurface(canvas->newSurface(info)); |
| 859 | |
junov@chromium.org | b1c725a | 2013-05-21 20:16:17 +0000 | [diff] [blame] | 860 | SkRect rect = SkRect::MakeWH(5, 5); |
| 861 | SkPaint paint; |
| 862 | // After spawning a compatible canvas: |
| 863 | // 1) Verify that secondary canvas is usable and does not report to the notification client. |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 864 | surface->getCanvas()->drawRect(rect, paint); |
junov@chromium.org | b1c725a | 2013-05-21 20:16:17 +0000 | [diff] [blame] | 865 | REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 0); |
| 866 | // 2) Verify that original canvas is usable and still reports to the notification client. |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 867 | canvas->drawRect(rect, paint); |
junov@chromium.org | b1c725a | 2013-05-21 20:16:17 +0000 | [diff] [blame] | 868 | REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 1); |
| 869 | } |
| 870 | |
yunchao.he | 49005bf | 2014-09-15 22:30:38 -0700 | [diff] [blame] | 871 | static void TestDeferredCanvasGetCanvasSize(skiatest::Reporter* reporter) { |
| 872 | SkRect rect; |
| 873 | rect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth), SkIntToScalar(gHeight)); |
| 874 | SkRect clip; |
| 875 | clip.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(1), SkIntToScalar(1)); |
| 876 | |
| 877 | SkPaint paint; |
| 878 | SkISize size = SkISize::Make(gWidth, gHeight); |
| 879 | |
| 880 | SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
| 881 | SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 882 | SkSurface* newSurface = SkSurface::NewRasterN32Premul(4, 4); |
yunchao.he | 49005bf | 2014-09-15 22:30:38 -0700 | [diff] [blame] | 883 | SkAutoTUnref<SkSurface> aur(newSurface); |
| 884 | |
| 885 | for (int i = 0; i < 2; ++i) { |
| 886 | if (i == 1) { |
| 887 | canvas->setSurface(newSurface); |
| 888 | size = SkISize::Make(4, 4); |
| 889 | } |
| 890 | |
| 891 | // verify that canvas size is correctly initialized or set |
| 892 | REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 893 | |
| 894 | // Verify that clear, clip and draw the canvas will not change its size |
| 895 | canvas->clear(0x00000000); |
| 896 | canvas->clipRect(clip, SkRegion::kIntersect_Op, false); |
| 897 | canvas->drawRect(rect, paint); |
| 898 | REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 899 | |
| 900 | // Verify that flush the canvas will not change its size |
| 901 | canvas->flush(); |
| 902 | REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 903 | |
| 904 | // Verify that clear canvas with saved state will not change its size |
| 905 | canvas->save(); |
| 906 | canvas->clear(0xFFFFFFFF); |
| 907 | REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 908 | |
| 909 | // Verify that restore canvas state will not change its size |
| 910 | canvas->restore(); |
| 911 | REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 912 | |
| 913 | // Verify that clear within a layer will not change canvas size |
| 914 | canvas->saveLayer(&clip, &paint); |
| 915 | canvas->clear(0x00000000); |
| 916 | REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 917 | |
| 918 | // Verify that restore from a layer will not change canvas size |
| 919 | canvas->restore(); |
| 920 | REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 921 | } |
| 922 | } |
| 923 | |
commit-bot@chromium.org | 8cca4cc | 2014-05-07 14:33:57 +0000 | [diff] [blame] | 924 | DEF_TEST(DeferredCanvas_CPU, reporter) { |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 925 | TestDeferredCanvasFlush(reporter); |
commit-bot@chromium.org | dad009b | 2014-03-27 15:48:52 +0000 | [diff] [blame] | 926 | TestDeferredCanvasSilentFlush(reporter); |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 927 | TestDeferredCanvasFreshFrame(reporter); |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 928 | TestDeferredCanvasMemoryLimit(reporter); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 929 | TestDeferredCanvasBitmapCaching(reporter); |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 930 | TestDeferredCanvasSkip(reporter); |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 931 | TestDeferredCanvasBitmapShaderNoLeak(reporter); |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 932 | TestDeferredCanvasBitmapSizeThreshold(reporter); |
junov@chromium.org | b1c725a | 2013-05-21 20:16:17 +0000 | [diff] [blame] | 933 | TestDeferredCanvasCreateCompatibleDevice(reporter); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 934 | TestDeferredCanvasWritePixelsToSurface(reporter); |
yunchao.he | 49005bf | 2014-09-15 22:30:38 -0700 | [diff] [blame] | 935 | TestDeferredCanvasGetCanvasSize(reporter); |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 936 | TestDeferredCanvasSurface(reporter, NULL); |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 937 | TestDeferredCanvasSetSurface(reporter, NULL); |
commit-bot@chromium.org | 8cca4cc | 2014-05-07 14:33:57 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) { |
| 941 | if (factory != NULL) { |
commit-bot@chromium.org | dbf2518 | 2014-05-07 12:33:02 +0000 | [diff] [blame] | 942 | TestDeferredCanvasSurface(reporter, factory); |
| 943 | TestDeferredCanvasSetSurface(reporter, factory); |
| 944 | } |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 945 | } |