junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 8 | #include "SkCanvas.h" |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 9 | #include "SkData.h" |
| 10 | #include "SkImageEncoder.h" |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 11 | #include "SkRRect.h" |
| 12 | #include "SkSurface.h" |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 13 | #include "SkUtils.h" |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 14 | #include "Test.h" |
| 15 | |
| 16 | #if SK_SUPPORT_GPU |
| 17 | #include "GrContextFactory.h" |
| 18 | #else |
| 19 | class GrContextFactory; |
| 20 | class GrContext; |
| 21 | #endif |
| 22 | |
| 23 | enum SurfaceType { |
| 24 | kRaster_SurfaceType, |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 25 | kRasterDirect_SurfaceType, |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 26 | kGpu_SurfaceType, |
| 27 | kPicture_SurfaceType |
| 28 | }; |
| 29 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 30 | static const int gSurfaceSize = 10; |
| 31 | static SkPMColor gSurfaceStorage[gSurfaceSize * gSurfaceSize]; |
| 32 | |
| 33 | static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context, |
| 34 | SkImageInfo* requestedInfo = NULL) { |
| 35 | static const SkImageInfo info = SkImageInfo::MakeN32Premul(gSurfaceSize, |
| 36 | gSurfaceSize); |
| 37 | |
| 38 | if (requestedInfo) { |
| 39 | *requestedInfo = info; |
| 40 | } |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 41 | |
| 42 | switch (surfaceType) { |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 43 | case kRaster_SurfaceType: |
| 44 | return SkSurface::NewRaster(info); |
| 45 | case kRasterDirect_SurfaceType: |
| 46 | return SkSurface::NewRasterDirect(info, gSurfaceStorage, |
| 47 | info.minRowBytes()); |
| 48 | case kGpu_SurfaceType: |
junov@chromium.org | 8bc9edc | 2013-04-03 15:25:46 +0000 | [diff] [blame] | 49 | #if SK_SUPPORT_GPU |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 50 | return context ? SkSurface::NewRenderTarget(context, info) : NULL; |
junov@chromium.org | 8bc9edc | 2013-04-03 15:25:46 +0000 | [diff] [blame] | 51 | #endif |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 52 | break; |
| 53 | case kPicture_SurfaceType: |
| 54 | return SkSurface::NewPicture(info.fWidth, info.fHeight); |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 55 | } |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 56 | return NULL; |
| 57 | } |
| 58 | |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 59 | enum ImageType { |
| 60 | kRasterCopy_ImageType, |
| 61 | kRasterData_ImageType, |
| 62 | kGpu_ImageType, |
| 63 | kPicture_ImageType, |
| 64 | kCodec_ImageType, |
| 65 | }; |
reed@google.com | 999da9c | 2014-02-06 13:43:07 +0000 | [diff] [blame] | 66 | |
| 67 | static void test_image(skiatest::Reporter* reporter) { |
| 68 | SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 69 | size_t rowBytes = info.minRowBytes(); |
| 70 | size_t size = info.getSafeSize(rowBytes); |
| 71 | void* addr = sk_malloc_throw(size); |
| 72 | SkData* data = SkData::NewFromMalloc(addr, size); |
commit-bot@chromium.org | 5e0995e | 2014-02-07 12:20:04 +0000 | [diff] [blame] | 73 | |
reed@google.com | 999da9c | 2014-02-06 13:43:07 +0000 | [diff] [blame] | 74 | REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); |
| 75 | SkImage* image = SkImage::NewRasterData(info, data, rowBytes); |
| 76 | REPORTER_ASSERT(reporter, 2 == data->getRefCnt()); |
| 77 | image->unref(); |
| 78 | REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); |
| 79 | data->unref(); |
| 80 | } |
| 81 | |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 82 | static SkImage* createImage(ImageType imageType, GrContext* context, |
| 83 | SkColor color) { |
| 84 | const SkPMColor pmcolor = SkPreMultiplyColor(color); |
| 85 | const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
| 86 | const size_t rowBytes = info.minRowBytes(); |
| 87 | const size_t size = rowBytes * info.fHeight; |
| 88 | |
| 89 | void* addr = sk_malloc_throw(size); |
| 90 | sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2)); |
| 91 | SkAutoTUnref<SkData> data(SkData::NewFromMalloc(addr, size)); |
| 92 | |
| 93 | switch (imageType) { |
| 94 | case kRasterCopy_ImageType: |
| 95 | return SkImage::NewRasterCopy(info, addr, rowBytes); |
| 96 | case kRasterData_ImageType: |
| 97 | return SkImage::NewRasterData(info, data, rowBytes); |
| 98 | case kGpu_ImageType: |
| 99 | return NULL; // TODO |
| 100 | case kPicture_ImageType: { |
| 101 | SkAutoTUnref<SkSurface> surf(SkSurface::NewPicture(info.fWidth, |
| 102 | info.fHeight)); |
| 103 | surf->getCanvas()->drawColor(SK_ColorRED); |
| 104 | return surf->newImageSnapshot(); |
| 105 | } |
| 106 | case kCodec_ImageType: { |
| 107 | SkBitmap bitmap; |
| 108 | bitmap.installPixels(info, addr, rowBytes, NULL, NULL); |
| 109 | SkAutoTUnref<SkData> src( |
| 110 | SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, |
| 111 | 100)); |
| 112 | return SkImage::NewEncodedData(src); |
| 113 | } |
| 114 | } |
| 115 | SkASSERT(false); |
| 116 | return NULL; |
| 117 | } |
| 118 | |
| 119 | static void test_imagepeek(skiatest::Reporter* reporter) { |
| 120 | static const struct { |
| 121 | ImageType fType; |
| 122 | bool fPeekShouldSucceed; |
| 123 | } gRec[] = { |
| 124 | { kRasterCopy_ImageType, true }, |
| 125 | { kRasterData_ImageType, true }, |
| 126 | { kGpu_ImageType, false }, |
| 127 | { kPicture_ImageType, false }, |
| 128 | { kCodec_ImageType, false }, |
| 129 | }; |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 130 | |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 131 | const SkColor color = SK_ColorRED; |
| 132 | const SkPMColor pmcolor = SkPreMultiplyColor(color); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 133 | |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 134 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 135 | SkImageInfo info; |
| 136 | size_t rowBytes; |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 137 | |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 138 | SkAutoTUnref<SkImage> image(createImage(gRec[i].fType, NULL, color)); |
| 139 | if (!image.get()) { |
| 140 | continue; // gpu may not be enabled |
| 141 | } |
| 142 | const void* addr = image->peekPixels(&info, &rowBytes); |
| 143 | bool success = (NULL != addr); |
| 144 | REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); |
| 145 | if (success) { |
| 146 | REPORTER_ASSERT(reporter, 10 == info.fWidth); |
| 147 | REPORTER_ASSERT(reporter, 10 == info.fHeight); |
| 148 | REPORTER_ASSERT(reporter, kPMColor_SkColorType == info.fColorType); |
| 149 | REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.fAlphaType || |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 150 | kOpaque_SkAlphaType == info.fAlphaType); |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 151 | REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); |
| 152 | REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 157 | static void test_canvaspeek(skiatest::Reporter* reporter, |
| 158 | GrContextFactory* factory) { |
| 159 | static const struct { |
| 160 | SurfaceType fType; |
| 161 | bool fPeekShouldSucceed; |
| 162 | } gRec[] = { |
| 163 | { kRaster_SurfaceType, true }, |
| 164 | { kRasterDirect_SurfaceType, true }, |
| 165 | #if SK_SUPPORT_GPU |
| 166 | { kGpu_SurfaceType, false }, |
| 167 | #endif |
| 168 | { kPicture_SurfaceType, false }, |
| 169 | }; |
| 170 | |
| 171 | const SkColor color = SK_ColorRED; |
| 172 | const SkPMColor pmcolor = SkPreMultiplyColor(color); |
| 173 | |
| 174 | GrContext* context = NULL; |
| 175 | #if SK_SUPPORT_GPU |
| 176 | context = factory->get(GrContextFactory::kNative_GLContextType); |
| 177 | #endif |
| 178 | |
| 179 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 180 | SkImageInfo info, requestInfo; |
| 181 | size_t rowBytes; |
| 182 | |
| 183 | SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context, |
| 184 | &requestInfo)); |
| 185 | surface->getCanvas()->clear(color); |
| 186 | |
| 187 | const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes); |
| 188 | bool success = (NULL != addr); |
| 189 | REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); |
| 190 | |
| 191 | SkImageInfo info2; |
| 192 | size_t rb2; |
| 193 | const void* addr2 = surface->peekPixels(&info2, &rb2); |
| 194 | |
| 195 | if (success) { |
| 196 | REPORTER_ASSERT(reporter, requestInfo == info); |
| 197 | REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes); |
| 198 | REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); |
| 199 | |
| 200 | REPORTER_ASSERT(reporter, addr2 == addr); |
| 201 | REPORTER_ASSERT(reporter, info2 == info); |
| 202 | REPORTER_ASSERT(reporter, rb2 == rowBytes); |
| 203 | } else { |
| 204 | REPORTER_ASSERT(reporter, NULL == addr2); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 209 | static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType surfaceType, |
| 210 | GrContext* context) { |
| 211 | // Verify that the right canvas commands trigger a copy on write |
| 212 | SkSurface* surface = createSurface(surfaceType, context); |
| 213 | SkAutoTUnref<SkSurface> aur_surface(surface); |
| 214 | SkCanvas* canvas = surface->getCanvas(); |
| 215 | |
| 216 | const SkRect testRect = |
| 217 | SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 218 | SkIntToScalar(4), SkIntToScalar(5)); |
| 219 | SkMatrix testMatrix; |
| 220 | testMatrix.reset(); |
| 221 | testMatrix.setScale(SkIntToScalar(2), SkIntToScalar(3)); |
| 222 | |
| 223 | SkPath testPath; |
| 224 | testPath.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 225 | SkIntToScalar(2), SkIntToScalar(1))); |
| 226 | |
| 227 | const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1); |
| 228 | |
| 229 | SkRegion testRegion; |
| 230 | testRegion.setRect(testIRect); |
| 231 | |
| 232 | |
| 233 | const SkColor testColor = 0x01020304; |
| 234 | const SkPaint testPaint; |
| 235 | const SkPoint testPoints[3] = { |
| 236 | {SkIntToScalar(0), SkIntToScalar(0)}, |
| 237 | {SkIntToScalar(2), SkIntToScalar(1)}, |
| 238 | {SkIntToScalar(0), SkIntToScalar(2)} |
| 239 | }; |
| 240 | const size_t testPointCount = 3; |
| 241 | |
| 242 | SkBitmap testBitmap; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 243 | testBitmap.allocN32Pixels(10, 10); |
robertphillips@google.com | d1ce77d | 2013-10-09 12:51:09 +0000 | [diff] [blame] | 244 | testBitmap.eraseColor(0); |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 245 | |
| 246 | SkRRect testRRect; |
| 247 | testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1); |
| 248 | |
| 249 | SkString testText("Hello World"); |
| 250 | const SkPoint testPoints2[] = { |
| 251 | { SkIntToScalar(0), SkIntToScalar(1) }, |
| 252 | { SkIntToScalar(1), SkIntToScalar(1) }, |
| 253 | { SkIntToScalar(2), SkIntToScalar(1) }, |
| 254 | { SkIntToScalar(3), SkIntToScalar(1) }, |
| 255 | { SkIntToScalar(4), SkIntToScalar(1) }, |
| 256 | { SkIntToScalar(5), SkIntToScalar(1) }, |
| 257 | { SkIntToScalar(6), SkIntToScalar(1) }, |
| 258 | { SkIntToScalar(7), SkIntToScalar(1) }, |
| 259 | { SkIntToScalar(8), SkIntToScalar(1) }, |
| 260 | { SkIntToScalar(9), SkIntToScalar(1) }, |
| 261 | { SkIntToScalar(10), SkIntToScalar(1) }, |
| 262 | }; |
| 263 | |
| 264 | #define EXPECT_COPY_ON_WRITE(command) \ |
| 265 | { \ |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 266 | SkImage* imageBefore = surface->newImageSnapshot(); \ |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 267 | SkAutoTUnref<SkImage> aur_before(imageBefore); \ |
| 268 | canvas-> command ; \ |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 269 | SkImage* imageAfter = surface->newImageSnapshot(); \ |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 270 | SkAutoTUnref<SkImage> aur_after(imageAfter); \ |
| 271 | REPORTER_ASSERT(reporter, imageBefore != imageAfter); \ |
| 272 | } |
| 273 | |
| 274 | EXPECT_COPY_ON_WRITE(clear(testColor)) |
| 275 | EXPECT_COPY_ON_WRITE(drawPaint(testPaint)) |
| 276 | EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \ |
| 277 | testPaint)) |
| 278 | EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint)) |
| 279 | EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint)) |
| 280 | EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint)) |
| 281 | EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint)) |
| 282 | EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0)) |
| 283 | EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, NULL, testRect)) |
| 284 | EXPECT_COPY_ON_WRITE(drawBitmapMatrix(testBitmap, testMatrix, NULL)) |
| 285 | EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL)) |
| 286 | EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL)) |
| 287 | EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testPaint)) |
| 288 | EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoints2, \ |
| 289 | testPaint)) |
| 290 | EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testPath, NULL, \ |
| 291 | testPaint)) |
| 292 | } |
| 293 | |
junov@chromium.org | af05835 | 2013-04-03 15:03:26 +0000 | [diff] [blame] | 294 | static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter, |
| 295 | SurfaceType surfaceType, |
| 296 | GrContext* context) { |
| 297 | // This test succeeds by not triggering an assertion. |
| 298 | // The test verifies that the surface remains writable (usable) after |
| 299 | // acquiring and releasing a snapshot without triggering a copy on write. |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 300 | SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); |
junov@chromium.org | af05835 | 2013-04-03 15:03:26 +0000 | [diff] [blame] | 301 | SkCanvas* canvas = surface->getCanvas(); |
| 302 | canvas->clear(1); |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 303 | surface->newImageSnapshot()->unref(); // Create and destroy SkImage |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 304 | canvas->clear(2); // Must not assert internally |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 305 | } |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 306 | |
junov@chromium.org | b516a41 | 2013-05-01 22:49:59 +0000 | [diff] [blame] | 307 | #if SK_SUPPORT_GPU |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 308 | static void Test_crbug263329(skiatest::Reporter* reporter, |
| 309 | GrContext* context) { |
| 310 | // This is a regression test for crbug.com/263329 |
| 311 | // Bug was caused by onCopyOnWrite releasing the old surface texture |
| 312 | // back to the scratch texture pool even though the texture is used |
| 313 | // by and active SkImage_Gpu. |
| 314 | SkAutoTUnref<SkSurface> surface1(createSurface(kGpu_SurfaceType, context)); |
| 315 | SkAutoTUnref<SkSurface> surface2(createSurface(kGpu_SurfaceType, context)); |
| 316 | SkCanvas* canvas1 = surface1->getCanvas(); |
| 317 | SkCanvas* canvas2 = surface2->getCanvas(); |
| 318 | canvas1->clear(1); |
| 319 | SkAutoTUnref<SkImage> image1(surface1->newImageSnapshot()); |
| 320 | // Trigger copy on write, new backing is a scratch texture |
| 321 | canvas1->clear(2); |
| 322 | SkAutoTUnref<SkImage> image2(surface1->newImageSnapshot()); |
| 323 | // Trigger copy on write, old backing should not be returned to scratch |
| 324 | // pool because it is held by image2 |
| 325 | canvas1->clear(3); |
| 326 | |
| 327 | canvas2->clear(4); |
| 328 | SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot()); |
| 329 | // Trigger copy on write on surface2. The new backing store should not |
| 330 | // be recycling a texture that is held by an existing image. |
| 331 | canvas2->clear(5); |
| 332 | SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot()); |
| 333 | REPORTER_ASSERT(reporter, image4->getTexture() != image3->getTexture()); |
| 334 | // The following assertion checks crbug.com/263329 |
| 335 | REPORTER_ASSERT(reporter, image4->getTexture() != image2->getTexture()); |
| 336 | REPORTER_ASSERT(reporter, image4->getTexture() != image1->getTexture()); |
| 337 | REPORTER_ASSERT(reporter, image3->getTexture() != image2->getTexture()); |
| 338 | REPORTER_ASSERT(reporter, image3->getTexture() != image1->getTexture()); |
| 339 | REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture()); |
| 340 | } |
| 341 | |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 342 | static void TestGetTexture(skiatest::Reporter* reporter, |
| 343 | SurfaceType surfaceType, |
| 344 | GrContext* context) { |
| 345 | SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); |
| 346 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 347 | GrTexture* texture = image->getTexture(); |
| 348 | if (surfaceType == kGpu_SurfaceType) { |
| 349 | REPORTER_ASSERT(reporter, NULL != texture); |
| 350 | REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |
| 351 | } else { |
| 352 | REPORTER_ASSERT(reporter, NULL == texture); |
| 353 | } |
| 354 | surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 355 | REPORTER_ASSERT(reporter, image->getTexture() == texture); |
| 356 | } |
junov@chromium.org | b516a41 | 2013-05-01 22:49:59 +0000 | [diff] [blame] | 357 | #endif |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 358 | |
junov@chromium.org | acea3ef | 2013-04-16 19:41:09 +0000 | [diff] [blame] | 359 | static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, |
| 360 | SurfaceType surfaceType, |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 361 | GrContext* context, |
| 362 | SkSurface::ContentChangeMode mode) { |
junov@chromium.org | acea3ef | 2013-04-16 19:41:09 +0000 | [diff] [blame] | 363 | // Verifies the robustness of SkSurface for handling use cases where calls |
| 364 | // are made before a canvas is created. |
| 365 | { |
| 366 | // Test passes by not asserting |
| 367 | SkSurface* surface = createSurface(surfaceType, context); |
| 368 | SkAutoTUnref<SkSurface> aur_surface(surface); |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 369 | surface->notifyContentWillChange(mode); |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 370 | SkDEBUGCODE(surface->validate();) |
junov@chromium.org | acea3ef | 2013-04-16 19:41:09 +0000 | [diff] [blame] | 371 | } |
| 372 | { |
| 373 | SkSurface* surface = createSurface(surfaceType, context); |
| 374 | SkAutoTUnref<SkSurface> aur_surface(surface); |
| 375 | SkImage* image1 = surface->newImageSnapshot(); |
| 376 | SkAutoTUnref<SkImage> aur_image1(image1); |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 377 | SkDEBUGCODE(image1->validate();) |
| 378 | SkDEBUGCODE(surface->validate();) |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 379 | surface->notifyContentWillChange(mode); |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 380 | SkDEBUGCODE(image1->validate();) |
| 381 | SkDEBUGCODE(surface->validate();) |
junov@chromium.org | acea3ef | 2013-04-16 19:41:09 +0000 | [diff] [blame] | 382 | SkImage* image2 = surface->newImageSnapshot(); |
| 383 | SkAutoTUnref<SkImage> aur_image2(image2); |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 384 | SkDEBUGCODE(image2->validate();) |
| 385 | SkDEBUGCODE(surface->validate();) |
junov@chromium.org | acea3ef | 2013-04-16 19:41:09 +0000 | [diff] [blame] | 386 | REPORTER_ASSERT(reporter, image1 != image2); |
| 387 | } |
skia.committer@gmail.com | 45fb8b6 | 2013-04-17 07:00:56 +0000 | [diff] [blame] | 388 | |
junov@chromium.org | acea3ef | 2013-04-16 19:41:09 +0000 | [diff] [blame] | 389 | } |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 390 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 391 | DEF_GPUTEST(Surface, reporter, factory) { |
reed@google.com | 999da9c | 2014-02-06 13:43:07 +0000 | [diff] [blame] | 392 | test_image(reporter); |
| 393 | |
junov@chromium.org | af05835 | 2013-04-03 15:03:26 +0000 | [diff] [blame] | 394 | TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
| 395 | TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); |
| 396 | TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL); |
| 397 | TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL); |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 398 | TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard_ContentChangeMode); |
| 399 | TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ContentChangeMode); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 400 | |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 401 | test_imagepeek(reporter); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame^] | 402 | test_canvaspeek(reporter, factory); |
| 403 | |
junov@chromium.org | b516a41 | 2013-05-01 22:49:59 +0000 | [diff] [blame] | 404 | #if SK_SUPPORT_GPU |
junov@chromium.org | da90474 | 2013-05-01 22:38:16 +0000 | [diff] [blame] | 405 | TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
| 406 | TestGetTexture(reporter, kPicture_SurfaceType, NULL); |
junov@chromium.org | af05835 | 2013-04-03 15:03:26 +0000 | [diff] [blame] | 407 | if (NULL != factory) { |
| 408 | GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); |
robertphillips@google.com | 3bddb38 | 2013-11-12 13:51:03 +0000 | [diff] [blame] | 409 | if (NULL != context) { |
| 410 | Test_crbug263329(reporter, context); |
| 411 | TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
| 412 | TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, context); |
| 413 | TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode); |
| 414 | TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRetain_ContentChangeMode); |
| 415 | TestGetTexture(reporter, kGpu_SurfaceType, context); |
| 416 | } |
junov@chromium.org | af05835 | 2013-04-03 15:03:26 +0000 | [diff] [blame] | 417 | } |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 418 | #endif |
| 419 | } |