blob: 610e3370f6a47133544e77aa32a67f27271809d6 [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"
junov@chromium.org995beb62013-03-28 13:49:22 +000014#include "Test.h"
15
16#if SK_SUPPORT_GPU
17#include "GrContextFactory.h"
18#else
19class GrContextFactory;
20class GrContext;
21#endif
22
23enum SurfaceType {
24 kRaster_SurfaceType,
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000025 kRasterDirect_SurfaceType,
junov@chromium.org995beb62013-03-28 13:49:22 +000026 kGpu_SurfaceType,
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +000027 kGpuScratch_SurfaceType,
junov@chromium.org995beb62013-03-28 13:49:22 +000028};
29
reed982542d2014-06-27 06:48:14 -070030static void release_storage(void* pixels, void* context) {
31 SkASSERT(pixels == context);
32 sk_free(pixels);
33}
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000034
35static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context,
36 SkImageInfo* requestedInfo = NULL) {
reed982542d2014-06-27 06:48:14 -070037 static const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000038
39 if (requestedInfo) {
40 *requestedInfo = info;
41 }
junov@chromium.org995beb62013-03-28 13:49:22 +000042
43 switch (surfaceType) {
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000044 case kRaster_SurfaceType:
45 return SkSurface::NewRaster(info);
reed982542d2014-06-27 06:48:14 -070046 case kRasterDirect_SurfaceType: {
47 const size_t rowBytes = info.minRowBytes();
48 void* storage = sk_malloc_throw(info.getSafeSize(rowBytes));
49 return SkSurface::NewRasterDirectReleaseProc(info, storage, rowBytes,
50 release_storage, storage);
51 }
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000052 case kGpu_SurfaceType:
junov@chromium.org8bc9edc2013-04-03 15:25:46 +000053#if SK_SUPPORT_GPU
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000054 return context ? SkSurface::NewRenderTarget(context, info) : NULL;
junov@chromium.org8bc9edc2013-04-03 15:25:46 +000055#endif
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000056 break;
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +000057 case kGpuScratch_SurfaceType:
58#if SK_SUPPORT_GPU
59 return context ? SkSurface::NewScratchRenderTarget(context, info) : NULL;
60#endif
61 break;
junov@chromium.org995beb62013-03-28 13:49:22 +000062 }
junov@chromium.org995beb62013-03-28 13:49:22 +000063 return NULL;
64}
65
reed@google.com4f7c6152014-02-06 14:11:56 +000066enum ImageType {
67 kRasterCopy_ImageType,
68 kRasterData_ImageType,
69 kGpu_ImageType,
reed@google.com4f7c6152014-02-06 14:11:56 +000070 kCodec_ImageType,
71};
reed@google.com999da9c2014-02-06 13:43:07 +000072
73static void test_image(skiatest::Reporter* reporter) {
74 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
75 size_t rowBytes = info.minRowBytes();
76 size_t size = info.getSafeSize(rowBytes);
77 void* addr = sk_malloc_throw(size);
78 SkData* data = SkData::NewFromMalloc(addr, size);
commit-bot@chromium.org5e0995e2014-02-07 12:20:04 +000079
reed@google.com999da9c2014-02-06 13:43:07 +000080 REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
81 SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
82 REPORTER_ASSERT(reporter, 2 == data->getRefCnt());
83 image->unref();
84 REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
85 data->unref();
86}
87
reed@google.com4f7c6152014-02-06 14:11:56 +000088static SkImage* createImage(ImageType imageType, GrContext* context,
89 SkColor color) {
90 const SkPMColor pmcolor = SkPreMultiplyColor(color);
91 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
92 const size_t rowBytes = info.minRowBytes();
93 const size_t size = rowBytes * info.fHeight;
94
95 void* addr = sk_malloc_throw(size);
96 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2));
97 SkAutoTUnref<SkData> data(SkData::NewFromMalloc(addr, size));
98
99 switch (imageType) {
100 case kRasterCopy_ImageType:
101 return SkImage::NewRasterCopy(info, addr, rowBytes);
102 case kRasterData_ImageType:
103 return SkImage::NewRasterData(info, data, rowBytes);
104 case kGpu_ImageType:
105 return NULL; // TODO
reed@google.com4f7c6152014-02-06 14:11:56 +0000106 case kCodec_ImageType: {
107 SkBitmap bitmap;
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +0000108 bitmap.installPixels(info, addr, rowBytes);
reed@google.com4f7c6152014-02-06 14:11:56 +0000109 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
119static 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 },
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000126 { kGpu_ImageType, false },
reed@google.com4f7c6152014-02-06 14:11:56 +0000127 { kCodec_ImageType, false },
128 };
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000129
reed@google.com4f7c6152014-02-06 14:11:56 +0000130 const SkColor color = SK_ColorRED;
131 const SkPMColor pmcolor = SkPreMultiplyColor(color);
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000132
reed@google.com4f7c6152014-02-06 14:11:56 +0000133 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
134 SkImageInfo info;
135 size_t rowBytes;
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000136
reed@google.com4f7c6152014-02-06 14:11:56 +0000137 SkAutoTUnref<SkImage> image(createImage(gRec[i].fType, NULL, color));
138 if (!image.get()) {
139 continue; // gpu may not be enabled
140 }
141 const void* addr = image->peekPixels(&info, &rowBytes);
142 bool success = (NULL != addr);
143 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
144 if (success) {
145 REPORTER_ASSERT(reporter, 10 == info.fWidth);
146 REPORTER_ASSERT(reporter, 10 == info.fHeight);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000147 REPORTER_ASSERT(reporter, kN32_SkColorType == info.fColorType);
reed@google.com4f7c6152014-02-06 14:11:56 +0000148 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.fAlphaType ||
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000149 kOpaque_SkAlphaType == info.fAlphaType);
reed@google.com4f7c6152014-02-06 14:11:56 +0000150 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
151 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
152 }
153 }
154}
155
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000156static void test_canvaspeek(skiatest::Reporter* reporter,
157 GrContextFactory* factory) {
158 static const struct {
159 SurfaceType fType;
160 bool fPeekShouldSucceed;
161 } gRec[] = {
162 { kRaster_SurfaceType, true },
163 { kRasterDirect_SurfaceType, true },
164#if SK_SUPPORT_GPU
165 { kGpu_SurfaceType, false },
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000166 { kGpuScratch_SurfaceType, false },
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000167#endif
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000168 };
169
170 const SkColor color = SK_ColorRED;
171 const SkPMColor pmcolor = SkPreMultiplyColor(color);
172
173 GrContext* context = NULL;
174#if SK_SUPPORT_GPU
175 context = factory->get(GrContextFactory::kNative_GLContextType);
176#endif
177
178 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
179 SkImageInfo info, requestInfo;
180 size_t rowBytes;
181
182 SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context,
183 &requestInfo));
184 surface->getCanvas()->clear(color);
185
186 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes);
187 bool success = (NULL != addr);
188 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
189
190 SkImageInfo info2;
191 size_t rb2;
192 const void* addr2 = surface->peekPixels(&info2, &rb2);
193
194 if (success) {
195 REPORTER_ASSERT(reporter, requestInfo == info);
196 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes);
197 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
198
199 REPORTER_ASSERT(reporter, addr2 == addr);
200 REPORTER_ASSERT(reporter, info2 == info);
201 REPORTER_ASSERT(reporter, rb2 == rowBytes);
202 } else {
203 REPORTER_ASSERT(reporter, NULL == addr2);
204 }
205 }
206}
207
junov@chromium.org995beb62013-03-28 13:49:22 +0000208static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType surfaceType,
209 GrContext* context) {
210 // Verify that the right canvas commands trigger a copy on write
211 SkSurface* surface = createSurface(surfaceType, context);
212 SkAutoTUnref<SkSurface> aur_surface(surface);
213 SkCanvas* canvas = surface->getCanvas();
214
215 const SkRect testRect =
216 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
217 SkIntToScalar(4), SkIntToScalar(5));
218 SkMatrix testMatrix;
219 testMatrix.reset();
220 testMatrix.setScale(SkIntToScalar(2), SkIntToScalar(3));
221
222 SkPath testPath;
223 testPath.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
224 SkIntToScalar(2), SkIntToScalar(1)));
225
226 const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
227
228 SkRegion testRegion;
229 testRegion.setRect(testIRect);
230
231
232 const SkColor testColor = 0x01020304;
233 const SkPaint testPaint;
234 const SkPoint testPoints[3] = {
235 {SkIntToScalar(0), SkIntToScalar(0)},
236 {SkIntToScalar(2), SkIntToScalar(1)},
237 {SkIntToScalar(0), SkIntToScalar(2)}
238 };
239 const size_t testPointCount = 3;
240
241 SkBitmap testBitmap;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000242 testBitmap.allocN32Pixels(10, 10);
robertphillips@google.comd1ce77d2013-10-09 12:51:09 +0000243 testBitmap.eraseColor(0);
junov@chromium.org995beb62013-03-28 13:49:22 +0000244
245 SkRRect testRRect;
246 testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1);
247
248 SkString testText("Hello World");
249 const SkPoint testPoints2[] = {
250 { SkIntToScalar(0), SkIntToScalar(1) },
251 { SkIntToScalar(1), SkIntToScalar(1) },
252 { SkIntToScalar(2), SkIntToScalar(1) },
253 { SkIntToScalar(3), SkIntToScalar(1) },
254 { SkIntToScalar(4), SkIntToScalar(1) },
255 { SkIntToScalar(5), SkIntToScalar(1) },
256 { SkIntToScalar(6), SkIntToScalar(1) },
257 { SkIntToScalar(7), SkIntToScalar(1) },
258 { SkIntToScalar(8), SkIntToScalar(1) },
259 { SkIntToScalar(9), SkIntToScalar(1) },
260 { SkIntToScalar(10), SkIntToScalar(1) },
261 };
262
263#define EXPECT_COPY_ON_WRITE(command) \
264 { \
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000265 SkImage* imageBefore = surface->newImageSnapshot(); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000266 SkAutoTUnref<SkImage> aur_before(imageBefore); \
267 canvas-> command ; \
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000268 SkImage* imageAfter = surface->newImageSnapshot(); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000269 SkAutoTUnref<SkImage> aur_after(imageAfter); \
270 REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
271 }
272
273 EXPECT_COPY_ON_WRITE(clear(testColor))
274 EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
275 EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
276 testPaint))
277 EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
278 EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
279 EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
280 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
281 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0))
282 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, NULL, testRect))
283 EXPECT_COPY_ON_WRITE(drawBitmapMatrix(testBitmap, testMatrix, NULL))
284 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL))
285 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL))
286 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testPaint))
287 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoints2, \
288 testPaint))
289 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testPath, NULL, \
290 testPaint))
291}
292
junov@chromium.orgaf058352013-04-03 15:03:26 +0000293static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter,
294 SurfaceType surfaceType,
295 GrContext* context) {
296 // This test succeeds by not triggering an assertion.
297 // The test verifies that the surface remains writable (usable) after
298 // acquiring and releasing a snapshot without triggering a copy on write.
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000299 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
junov@chromium.orgaf058352013-04-03 15:03:26 +0000300 SkCanvas* canvas = surface->getCanvas();
301 canvas->clear(1);
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000302 surface->newImageSnapshot()->unref(); // Create and destroy SkImage
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000303 canvas->clear(2); // Must not assert internally
junov@chromium.org995beb62013-03-28 13:49:22 +0000304}
junov@chromium.orgda904742013-05-01 22:38:16 +0000305
junov@chromium.orgb516a412013-05-01 22:49:59 +0000306#if SK_SUPPORT_GPU
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000307static void TestSurfaceInCache(skiatest::Reporter* reporter,
308 SurfaceType surfaceType,
309 GrContext* context) {
310 context->freeGpuResources();
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000311 int resourceCount;
312
313 context->getResourceCacheUsage(&resourceCount, NULL);
314 REPORTER_ASSERT(reporter, 0 == resourceCount);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000315 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
316 // Note: the stencil buffer is always cached, so kGpu_SurfaceType uses
317 // one cached resource, and kGpuScratch_SurfaceType uses two.
318 int expectedCachedResources = surfaceType == kGpuScratch_SurfaceType ? 2 : 1;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000319 context->getResourceCacheUsage(&resourceCount, NULL);
320 REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000321
322 // Verify that all the cached resources are locked in cache.
skia.committer@gmail.com99e5b522014-03-21 03:02:42 +0000323 context->freeGpuResources();
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000324 context->getResourceCacheUsage(&resourceCount, NULL);
325 REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000326
327 // Verify that all the cached resources are unlocked upon surface release
328 surface.reset(0);
329 context->freeGpuResources();
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000330 context->getResourceCacheUsage(&resourceCount, NULL);
331 REPORTER_ASSERT(reporter, 0 == resourceCount);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000332}
333
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000334static void Test_crbug263329(skiatest::Reporter* reporter,
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000335 SurfaceType surfaceType,
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000336 GrContext* context) {
337 // This is a regression test for crbug.com/263329
338 // Bug was caused by onCopyOnWrite releasing the old surface texture
339 // back to the scratch texture pool even though the texture is used
340 // by and active SkImage_Gpu.
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000341 SkAutoTUnref<SkSurface> surface1(createSurface(surfaceType, context));
342 SkAutoTUnref<SkSurface> surface2(createSurface(surfaceType, context));
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000343 SkCanvas* canvas1 = surface1->getCanvas();
344 SkCanvas* canvas2 = surface2->getCanvas();
345 canvas1->clear(1);
346 SkAutoTUnref<SkImage> image1(surface1->newImageSnapshot());
347 // Trigger copy on write, new backing is a scratch texture
348 canvas1->clear(2);
349 SkAutoTUnref<SkImage> image2(surface1->newImageSnapshot());
350 // Trigger copy on write, old backing should not be returned to scratch
351 // pool because it is held by image2
352 canvas1->clear(3);
353
354 canvas2->clear(4);
355 SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot());
356 // Trigger copy on write on surface2. The new backing store should not
357 // be recycling a texture that is held by an existing image.
358 canvas2->clear(5);
359 SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot());
360 REPORTER_ASSERT(reporter, image4->getTexture() != image3->getTexture());
361 // The following assertion checks crbug.com/263329
362 REPORTER_ASSERT(reporter, image4->getTexture() != image2->getTexture());
363 REPORTER_ASSERT(reporter, image4->getTexture() != image1->getTexture());
364 REPORTER_ASSERT(reporter, image3->getTexture() != image2->getTexture());
365 REPORTER_ASSERT(reporter, image3->getTexture() != image1->getTexture());
366 REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture());
367}
368
junov@chromium.orgda904742013-05-01 22:38:16 +0000369static void TestGetTexture(skiatest::Reporter* reporter,
370 SurfaceType surfaceType,
371 GrContext* context) {
372 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
373 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
374 GrTexture* texture = image->getTexture();
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000375 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceType) {
junov@chromium.orgda904742013-05-01 22:38:16 +0000376 REPORTER_ASSERT(reporter, NULL != texture);
377 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
378 } else {
379 REPORTER_ASSERT(reporter, NULL == texture);
380 }
381 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
382 REPORTER_ASSERT(reporter, image->getTexture() == texture);
383}
junov@chromium.orgb516a412013-05-01 22:49:59 +0000384#endif
junov@chromium.orgda904742013-05-01 22:38:16 +0000385
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000386static void TestSurfaceNoCanvas(skiatest::Reporter* reporter,
387 SurfaceType surfaceType,
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000388 GrContext* context,
389 SkSurface::ContentChangeMode mode) {
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000390 // Verifies the robustness of SkSurface for handling use cases where calls
391 // are made before a canvas is created.
392 {
393 // Test passes by not asserting
394 SkSurface* surface = createSurface(surfaceType, context);
395 SkAutoTUnref<SkSurface> aur_surface(surface);
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000396 surface->notifyContentWillChange(mode);
robertphillips@google.com03087072013-10-02 16:42:21 +0000397 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000398 }
399 {
400 SkSurface* surface = createSurface(surfaceType, context);
401 SkAutoTUnref<SkSurface> aur_surface(surface);
402 SkImage* image1 = surface->newImageSnapshot();
403 SkAutoTUnref<SkImage> aur_image1(image1);
robertphillips@google.com03087072013-10-02 16:42:21 +0000404 SkDEBUGCODE(image1->validate();)
405 SkDEBUGCODE(surface->validate();)
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000406 surface->notifyContentWillChange(mode);
robertphillips@google.com03087072013-10-02 16:42:21 +0000407 SkDEBUGCODE(image1->validate();)
408 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000409 SkImage* image2 = surface->newImageSnapshot();
410 SkAutoTUnref<SkImage> aur_image2(image2);
robertphillips@google.com03087072013-10-02 16:42:21 +0000411 SkDEBUGCODE(image2->validate();)
412 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000413 REPORTER_ASSERT(reporter, image1 != image2);
414 }
skia.committer@gmail.com45fb8b62013-04-17 07:00:56 +0000415
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000416}
junov@chromium.org995beb62013-03-28 13:49:22 +0000417
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000418DEF_GPUTEST(Surface, reporter, factory) {
reed@google.com999da9c2014-02-06 13:43:07 +0000419 test_image(reporter);
420
junov@chromium.orgaf058352013-04-03 15:03:26 +0000421 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
junov@chromium.orgaf058352013-04-03 15:03:26 +0000422 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL);
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000423 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard_ContentChangeMode);
424 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ContentChangeMode);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000425
reed@google.com4f7c6152014-02-06 14:11:56 +0000426 test_imagepeek(reporter);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000427 test_canvaspeek(reporter, factory);
428
junov@chromium.orgb516a412013-05-01 22:49:59 +0000429#if SK_SUPPORT_GPU
junov@chromium.orgda904742013-05-01 22:38:16 +0000430 TestGetTexture(reporter, kRaster_SurfaceType, NULL);
junov@chromium.orgaf058352013-04-03 15:03:26 +0000431 if (NULL != factory) {
432 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000433 if (NULL != context) {
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000434 TestSurfaceInCache(reporter, kGpu_SurfaceType, context);
435 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context);
436 Test_crbug263329(reporter, kGpu_SurfaceType, context);
437 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000438 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000439 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000440 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000441 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000442 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000443 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000444 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000445 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000446 TestGetTexture(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000447 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000448 }
junov@chromium.orgaf058352013-04-03 15:03:26 +0000449 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000450#endif
451}