blob: 93ba3c2b9e508d541d09ea75e00bcc192d1e91c9 [file] [log] [blame]
junov@chromium.org995beb62013-03-28 13:49:22 +00001/*
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.org4ee16bf2014-01-10 22:08:27 +00007
junov@chromium.org995beb62013-03-28 13:49:22 +00008#include "SkCanvas.h"
reed@google.com4f7c6152014-02-06 14:11:56 +00009#include "SkData.h"
10#include "SkImageEncoder.h"
junov@chromium.org995beb62013-03-28 13:49:22 +000011#include "SkRRect.h"
12#include "SkSurface.h"
reed@google.com4f7c6152014-02-06 14:11:56 +000013#include "SkUtils.h"
mtklein4ae94ff2014-07-08 06:48:17 -070014#include "RefCntIs.h"
junov@chromium.org995beb62013-03-28 13:49:22 +000015#include "Test.h"
16
17#if SK_SUPPORT_GPU
18#include "GrContextFactory.h"
19#else
20class GrContextFactory;
21class GrContext;
22#endif
23
24enum SurfaceType {
25 kRaster_SurfaceType,
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000026 kRasterDirect_SurfaceType,
junov@chromium.org995beb62013-03-28 13:49:22 +000027 kGpu_SurfaceType,
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +000028 kGpuScratch_SurfaceType,
junov@chromium.org995beb62013-03-28 13:49:22 +000029};
30
reed982542d2014-06-27 06:48:14 -070031static void release_storage(void* pixels, void* context) {
32 SkASSERT(pixels == context);
33 sk_free(pixels);
34}
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000035
36static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context,
37 SkImageInfo* requestedInfo = NULL) {
reed982542d2014-06-27 06:48:14 -070038 static const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000039
40 if (requestedInfo) {
41 *requestedInfo = info;
42 }
junov@chromium.org995beb62013-03-28 13:49:22 +000043
44 switch (surfaceType) {
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000045 case kRaster_SurfaceType:
46 return SkSurface::NewRaster(info);
reed982542d2014-06-27 06:48:14 -070047 case kRasterDirect_SurfaceType: {
48 const size_t rowBytes = info.minRowBytes();
49 void* storage = sk_malloc_throw(info.getSafeSize(rowBytes));
50 return SkSurface::NewRasterDirectReleaseProc(info, storage, rowBytes,
51 release_storage, storage);
52 }
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000053 case kGpu_SurfaceType:
junov@chromium.org8bc9edc2013-04-03 15:25:46 +000054#if SK_SUPPORT_GPU
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000055 return context ? SkSurface::NewRenderTarget(context, info) : NULL;
junov@chromium.org8bc9edc2013-04-03 15:25:46 +000056#endif
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000057 break;
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +000058 case kGpuScratch_SurfaceType:
59#if SK_SUPPORT_GPU
60 return context ? SkSurface::NewScratchRenderTarget(context, info) : NULL;
61#endif
62 break;
junov@chromium.org995beb62013-03-28 13:49:22 +000063 }
junov@chromium.org995beb62013-03-28 13:49:22 +000064 return NULL;
65}
66
reed@google.com4f7c6152014-02-06 14:11:56 +000067enum ImageType {
68 kRasterCopy_ImageType,
69 kRasterData_ImageType,
70 kGpu_ImageType,
reed@google.com4f7c6152014-02-06 14:11:56 +000071 kCodec_ImageType,
72};
reed@google.com999da9c2014-02-06 13:43:07 +000073
74static void test_image(skiatest::Reporter* reporter) {
75 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
76 size_t rowBytes = info.minRowBytes();
77 size_t size = info.getSafeSize(rowBytes);
78 void* addr = sk_malloc_throw(size);
79 SkData* data = SkData::NewFromMalloc(addr, size);
commit-bot@chromium.org5e0995e2014-02-07 12:20:04 +000080
mtklein4ae94ff2014-07-08 06:48:17 -070081 REPORTER_ASSERT(reporter, RefCntIs(*data, 1));
reed@google.com999da9c2014-02-06 13:43:07 +000082 SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
mtklein4ae94ff2014-07-08 06:48:17 -070083 REPORTER_ASSERT(reporter, RefCntIs(*data, 2));
reed@google.com999da9c2014-02-06 13:43:07 +000084 image->unref();
mtklein4ae94ff2014-07-08 06:48:17 -070085 REPORTER_ASSERT(reporter, RefCntIs(*data, 1));
reed@google.com999da9c2014-02-06 13:43:07 +000086 data->unref();
87}
88
reed@google.com4f7c6152014-02-06 14:11:56 +000089static SkImage* createImage(ImageType imageType, GrContext* context,
90 SkColor color) {
91 const SkPMColor pmcolor = SkPreMultiplyColor(color);
92 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
93 const size_t rowBytes = info.minRowBytes();
94 const size_t size = rowBytes * info.fHeight;
95
96 void* addr = sk_malloc_throw(size);
97 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2));
98 SkAutoTUnref<SkData> data(SkData::NewFromMalloc(addr, size));
99
100 switch (imageType) {
101 case kRasterCopy_ImageType:
102 return SkImage::NewRasterCopy(info, addr, rowBytes);
103 case kRasterData_ImageType:
104 return SkImage::NewRasterData(info, data, rowBytes);
105 case kGpu_ImageType:
106 return NULL; // TODO
reed@google.com4f7c6152014-02-06 14:11:56 +0000107 case kCodec_ImageType: {
108 SkBitmap bitmap;
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +0000109 bitmap.installPixels(info, addr, rowBytes);
reed@google.com4f7c6152014-02-06 14:11:56 +0000110 SkAutoTUnref<SkData> src(
111 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type,
112 100));
113 return SkImage::NewEncodedData(src);
114 }
115 }
116 SkASSERT(false);
117 return NULL;
118}
119
120static void test_imagepeek(skiatest::Reporter* reporter) {
121 static const struct {
122 ImageType fType;
123 bool fPeekShouldSucceed;
124 } gRec[] = {
125 { kRasterCopy_ImageType, true },
126 { kRasterData_ImageType, true },
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000127 { kGpu_ImageType, false },
reed@google.com4f7c6152014-02-06 14:11:56 +0000128 { kCodec_ImageType, false },
129 };
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000130
reed@google.com4f7c6152014-02-06 14:11:56 +0000131 const SkColor color = SK_ColorRED;
132 const SkPMColor pmcolor = SkPreMultiplyColor(color);
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000133
reed@google.com4f7c6152014-02-06 14:11:56 +0000134 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
135 SkImageInfo info;
136 size_t rowBytes;
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000137
reed@google.com4f7c6152014-02-06 14:11:56 +0000138 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);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000148 REPORTER_ASSERT(reporter, kN32_SkColorType == info.fColorType);
reed@google.com4f7c6152014-02-06 14:11:56 +0000149 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.fAlphaType ||
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000150 kOpaque_SkAlphaType == info.fAlphaType);
reed@google.com4f7c6152014-02-06 14:11:56 +0000151 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
152 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
153 }
154 }
155}
156
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000157static 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 },
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000167 { kGpuScratch_SurfaceType, false },
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000168#endif
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000169 };
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.org995beb62013-03-28 13:49:22 +0000209static 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.orgdeee4962014-02-13 14:41:43 +0000243 testBitmap.allocN32Pixels(10, 10);
robertphillips@google.comd1ce77d2013-10-09 12:51:09 +0000244 testBitmap.eraseColor(0);
junov@chromium.org995beb62013-03-28 13:49:22 +0000245
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.org5ee449a2013-04-12 20:20:50 +0000266 SkImage* imageBefore = surface->newImageSnapshot(); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000267 SkAutoTUnref<SkImage> aur_before(imageBefore); \
268 canvas-> command ; \
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000269 SkImage* imageAfter = surface->newImageSnapshot(); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000270 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.orgaf058352013-04-03 15:03:26 +0000294static 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.org4d24b742013-07-25 23:29:40 +0000300 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
junov@chromium.orgaf058352013-04-03 15:03:26 +0000301 SkCanvas* canvas = surface->getCanvas();
302 canvas->clear(1);
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000303 surface->newImageSnapshot()->unref(); // Create and destroy SkImage
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000304 canvas->clear(2); // Must not assert internally
junov@chromium.org995beb62013-03-28 13:49:22 +0000305}
junov@chromium.orgda904742013-05-01 22:38:16 +0000306
junov@chromium.orgb516a412013-05-01 22:49:59 +0000307#if SK_SUPPORT_GPU
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000308static void TestSurfaceInCache(skiatest::Reporter* reporter,
309 SurfaceType surfaceType,
310 GrContext* context) {
311 context->freeGpuResources();
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000312 int resourceCount;
313
314 context->getResourceCacheUsage(&resourceCount, NULL);
315 REPORTER_ASSERT(reporter, 0 == resourceCount);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000316 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
317 // Note: the stencil buffer is always cached, so kGpu_SurfaceType uses
318 // one cached resource, and kGpuScratch_SurfaceType uses two.
319 int expectedCachedResources = surfaceType == kGpuScratch_SurfaceType ? 2 : 1;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000320 context->getResourceCacheUsage(&resourceCount, NULL);
321 REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000322
323 // Verify that all the cached resources are locked in cache.
skia.committer@gmail.com99e5b522014-03-21 03:02:42 +0000324 context->freeGpuResources();
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000325 context->getResourceCacheUsage(&resourceCount, NULL);
326 REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000327
328 // Verify that all the cached resources are unlocked upon surface release
329 surface.reset(0);
330 context->freeGpuResources();
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000331 context->getResourceCacheUsage(&resourceCount, NULL);
332 REPORTER_ASSERT(reporter, 0 == resourceCount);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000333}
334
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000335static void Test_crbug263329(skiatest::Reporter* reporter,
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000336 SurfaceType surfaceType,
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000337 GrContext* context) {
338 // This is a regression test for crbug.com/263329
339 // Bug was caused by onCopyOnWrite releasing the old surface texture
340 // back to the scratch texture pool even though the texture is used
341 // by and active SkImage_Gpu.
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000342 SkAutoTUnref<SkSurface> surface1(createSurface(surfaceType, context));
343 SkAutoTUnref<SkSurface> surface2(createSurface(surfaceType, context));
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000344 SkCanvas* canvas1 = surface1->getCanvas();
345 SkCanvas* canvas2 = surface2->getCanvas();
346 canvas1->clear(1);
347 SkAutoTUnref<SkImage> image1(surface1->newImageSnapshot());
348 // Trigger copy on write, new backing is a scratch texture
349 canvas1->clear(2);
350 SkAutoTUnref<SkImage> image2(surface1->newImageSnapshot());
351 // Trigger copy on write, old backing should not be returned to scratch
352 // pool because it is held by image2
353 canvas1->clear(3);
354
355 canvas2->clear(4);
356 SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot());
357 // Trigger copy on write on surface2. The new backing store should not
358 // be recycling a texture that is held by an existing image.
359 canvas2->clear(5);
360 SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot());
361 REPORTER_ASSERT(reporter, image4->getTexture() != image3->getTexture());
362 // The following assertion checks crbug.com/263329
363 REPORTER_ASSERT(reporter, image4->getTexture() != image2->getTexture());
364 REPORTER_ASSERT(reporter, image4->getTexture() != image1->getTexture());
365 REPORTER_ASSERT(reporter, image3->getTexture() != image2->getTexture());
366 REPORTER_ASSERT(reporter, image3->getTexture() != image1->getTexture());
367 REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture());
368}
369
junov@chromium.orgda904742013-05-01 22:38:16 +0000370static void TestGetTexture(skiatest::Reporter* reporter,
371 SurfaceType surfaceType,
372 GrContext* context) {
373 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
374 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
375 GrTexture* texture = image->getTexture();
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000376 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceType) {
junov@chromium.orgda904742013-05-01 22:38:16 +0000377 REPORTER_ASSERT(reporter, NULL != texture);
378 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
379 } else {
380 REPORTER_ASSERT(reporter, NULL == texture);
381 }
382 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
383 REPORTER_ASSERT(reporter, image->getTexture() == texture);
384}
junov@chromium.orgb516a412013-05-01 22:49:59 +0000385#endif
junov@chromium.orgda904742013-05-01 22:38:16 +0000386
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000387static void TestSurfaceNoCanvas(skiatest::Reporter* reporter,
388 SurfaceType surfaceType,
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000389 GrContext* context,
390 SkSurface::ContentChangeMode mode) {
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000391 // Verifies the robustness of SkSurface for handling use cases where calls
392 // are made before a canvas is created.
393 {
394 // Test passes by not asserting
395 SkSurface* surface = createSurface(surfaceType, context);
396 SkAutoTUnref<SkSurface> aur_surface(surface);
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000397 surface->notifyContentWillChange(mode);
robertphillips@google.com03087072013-10-02 16:42:21 +0000398 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000399 }
400 {
401 SkSurface* surface = createSurface(surfaceType, context);
402 SkAutoTUnref<SkSurface> aur_surface(surface);
403 SkImage* image1 = surface->newImageSnapshot();
404 SkAutoTUnref<SkImage> aur_image1(image1);
robertphillips@google.com03087072013-10-02 16:42:21 +0000405 SkDEBUGCODE(image1->validate();)
406 SkDEBUGCODE(surface->validate();)
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000407 surface->notifyContentWillChange(mode);
robertphillips@google.com03087072013-10-02 16:42:21 +0000408 SkDEBUGCODE(image1->validate();)
409 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000410 SkImage* image2 = surface->newImageSnapshot();
411 SkAutoTUnref<SkImage> aur_image2(image2);
robertphillips@google.com03087072013-10-02 16:42:21 +0000412 SkDEBUGCODE(image2->validate();)
413 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000414 REPORTER_ASSERT(reporter, image1 != image2);
415 }
skia.committer@gmail.com45fb8b62013-04-17 07:00:56 +0000416
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000417}
junov@chromium.org995beb62013-03-28 13:49:22 +0000418
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000419DEF_GPUTEST(Surface, reporter, factory) {
reed@google.com999da9c2014-02-06 13:43:07 +0000420 test_image(reporter);
421
junov@chromium.orgaf058352013-04-03 15:03:26 +0000422 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
junov@chromium.orgaf058352013-04-03 15:03:26 +0000423 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL);
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000424 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard_ContentChangeMode);
425 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ContentChangeMode);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000426
reed@google.com4f7c6152014-02-06 14:11:56 +0000427 test_imagepeek(reporter);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000428 test_canvaspeek(reporter, factory);
429
junov@chromium.orgb516a412013-05-01 22:49:59 +0000430#if SK_SUPPORT_GPU
junov@chromium.orgda904742013-05-01 22:38:16 +0000431 TestGetTexture(reporter, kRaster_SurfaceType, NULL);
junov@chromium.orgaf058352013-04-03 15:03:26 +0000432 if (NULL != factory) {
433 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000434 if (NULL != context) {
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000435 TestSurfaceInCache(reporter, kGpu_SurfaceType, context);
436 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context);
437 Test_crbug263329(reporter, kGpu_SurfaceType, context);
438 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000439 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000440 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000441 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000442 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000443 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000444 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000445 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000446 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000447 TestGetTexture(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000448 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000449 }
junov@chromium.orgaf058352013-04-03 15:03:26 +0000450 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000451#endif
452}