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