blob: fd4980ebc43b240d393f1d83abb58d92d71fa9f2 [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
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000030static const int gSurfaceSize = 10;
31static SkPMColor gSurfaceStorage[gSurfaceSize * gSurfaceSize];
32
33static 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.org995beb62013-03-28 13:49:22 +000041
42 switch (surfaceType) {
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000043 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.org8bc9edc2013-04-03 15:25:46 +000049#if SK_SUPPORT_GPU
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000050 return context ? SkSurface::NewRenderTarget(context, info) : NULL;
junov@chromium.org8bc9edc2013-04-03 15:25:46 +000051#endif
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000052 break;
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +000053 case kGpuScratch_SurfaceType:
54#if SK_SUPPORT_GPU
55 return context ? SkSurface::NewScratchRenderTarget(context, info) : NULL;
56#endif
57 break;
junov@chromium.org995beb62013-03-28 13:49:22 +000058 }
junov@chromium.org995beb62013-03-28 13:49:22 +000059 return NULL;
60}
61
reed@google.com4f7c6152014-02-06 14:11:56 +000062enum ImageType {
63 kRasterCopy_ImageType,
64 kRasterData_ImageType,
65 kGpu_ImageType,
reed@google.com4f7c6152014-02-06 14:11:56 +000066 kCodec_ImageType,
67};
reed@google.com999da9c2014-02-06 13:43:07 +000068
69static void test_image(skiatest::Reporter* reporter) {
70 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
71 size_t rowBytes = info.minRowBytes();
72 size_t size = info.getSafeSize(rowBytes);
73 void* addr = sk_malloc_throw(size);
74 SkData* data = SkData::NewFromMalloc(addr, size);
commit-bot@chromium.org5e0995e2014-02-07 12:20:04 +000075
reed@google.com999da9c2014-02-06 13:43:07 +000076 REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
77 SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
78 REPORTER_ASSERT(reporter, 2 == data->getRefCnt());
79 image->unref();
80 REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
81 data->unref();
82}
83
reed@google.com4f7c6152014-02-06 14:11:56 +000084static SkImage* createImage(ImageType imageType, GrContext* context,
85 SkColor color) {
86 const SkPMColor pmcolor = SkPreMultiplyColor(color);
87 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
88 const size_t rowBytes = info.minRowBytes();
89 const size_t size = rowBytes * info.fHeight;
90
91 void* addr = sk_malloc_throw(size);
92 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2));
93 SkAutoTUnref<SkData> data(SkData::NewFromMalloc(addr, size));
94
95 switch (imageType) {
96 case kRasterCopy_ImageType:
97 return SkImage::NewRasterCopy(info, addr, rowBytes);
98 case kRasterData_ImageType:
99 return SkImage::NewRasterData(info, data, rowBytes);
100 case kGpu_ImageType:
101 return NULL; // TODO
reed@google.com4f7c6152014-02-06 14:11:56 +0000102 case kCodec_ImageType: {
103 SkBitmap bitmap;
104 bitmap.installPixels(info, addr, rowBytes, NULL, NULL);
105 SkAutoTUnref<SkData> src(
106 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type,
107 100));
108 return SkImage::NewEncodedData(src);
109 }
110 }
111 SkASSERT(false);
112 return NULL;
113}
114
115static void test_imagepeek(skiatest::Reporter* reporter) {
116 static const struct {
117 ImageType fType;
118 bool fPeekShouldSucceed;
119 } gRec[] = {
120 { kRasterCopy_ImageType, true },
121 { kRasterData_ImageType, true },
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000122 { kGpu_ImageType, false },
reed@google.com4f7c6152014-02-06 14:11:56 +0000123 { kCodec_ImageType, false },
124 };
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000125
reed@google.com4f7c6152014-02-06 14:11:56 +0000126 const SkColor color = SK_ColorRED;
127 const SkPMColor pmcolor = SkPreMultiplyColor(color);
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000128
reed@google.com4f7c6152014-02-06 14:11:56 +0000129 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
130 SkImageInfo info;
131 size_t rowBytes;
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000132
reed@google.com4f7c6152014-02-06 14:11:56 +0000133 SkAutoTUnref<SkImage> image(createImage(gRec[i].fType, NULL, color));
134 if (!image.get()) {
135 continue; // gpu may not be enabled
136 }
137 const void* addr = image->peekPixels(&info, &rowBytes);
138 bool success = (NULL != addr);
139 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
140 if (success) {
141 REPORTER_ASSERT(reporter, 10 == info.fWidth);
142 REPORTER_ASSERT(reporter, 10 == info.fHeight);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000143 REPORTER_ASSERT(reporter, kN32_SkColorType == info.fColorType);
reed@google.com4f7c6152014-02-06 14:11:56 +0000144 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.fAlphaType ||
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000145 kOpaque_SkAlphaType == info.fAlphaType);
reed@google.com4f7c6152014-02-06 14:11:56 +0000146 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
147 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
148 }
149 }
150}
151
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000152static void test_canvaspeek(skiatest::Reporter* reporter,
153 GrContextFactory* factory) {
154 static const struct {
155 SurfaceType fType;
156 bool fPeekShouldSucceed;
157 } gRec[] = {
158 { kRaster_SurfaceType, true },
159 { kRasterDirect_SurfaceType, true },
160#if SK_SUPPORT_GPU
161 { kGpu_SurfaceType, false },
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000162 { kGpuScratch_SurfaceType, false },
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000163#endif
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000164 };
165
166 const SkColor color = SK_ColorRED;
167 const SkPMColor pmcolor = SkPreMultiplyColor(color);
168
169 GrContext* context = NULL;
170#if SK_SUPPORT_GPU
171 context = factory->get(GrContextFactory::kNative_GLContextType);
172#endif
173
174 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
175 SkImageInfo info, requestInfo;
176 size_t rowBytes;
177
178 SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context,
179 &requestInfo));
180 surface->getCanvas()->clear(color);
181
182 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes);
183 bool success = (NULL != addr);
184 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
185
186 SkImageInfo info2;
187 size_t rb2;
188 const void* addr2 = surface->peekPixels(&info2, &rb2);
189
190 if (success) {
191 REPORTER_ASSERT(reporter, requestInfo == info);
192 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes);
193 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
194
195 REPORTER_ASSERT(reporter, addr2 == addr);
196 REPORTER_ASSERT(reporter, info2 == info);
197 REPORTER_ASSERT(reporter, rb2 == rowBytes);
198 } else {
199 REPORTER_ASSERT(reporter, NULL == addr2);
200 }
201 }
202}
203
junov@chromium.org995beb62013-03-28 13:49:22 +0000204static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType surfaceType,
205 GrContext* context) {
206 // Verify that the right canvas commands trigger a copy on write
207 SkSurface* surface = createSurface(surfaceType, context);
208 SkAutoTUnref<SkSurface> aur_surface(surface);
209 SkCanvas* canvas = surface->getCanvas();
210
211 const SkRect testRect =
212 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
213 SkIntToScalar(4), SkIntToScalar(5));
214 SkMatrix testMatrix;
215 testMatrix.reset();
216 testMatrix.setScale(SkIntToScalar(2), SkIntToScalar(3));
217
218 SkPath testPath;
219 testPath.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
220 SkIntToScalar(2), SkIntToScalar(1)));
221
222 const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
223
224 SkRegion testRegion;
225 testRegion.setRect(testIRect);
226
227
228 const SkColor testColor = 0x01020304;
229 const SkPaint testPaint;
230 const SkPoint testPoints[3] = {
231 {SkIntToScalar(0), SkIntToScalar(0)},
232 {SkIntToScalar(2), SkIntToScalar(1)},
233 {SkIntToScalar(0), SkIntToScalar(2)}
234 };
235 const size_t testPointCount = 3;
236
237 SkBitmap testBitmap;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000238 testBitmap.allocN32Pixels(10, 10);
robertphillips@google.comd1ce77d2013-10-09 12:51:09 +0000239 testBitmap.eraseColor(0);
junov@chromium.org995beb62013-03-28 13:49:22 +0000240
241 SkRRect testRRect;
242 testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1);
243
244 SkString testText("Hello World");
245 const SkPoint testPoints2[] = {
246 { SkIntToScalar(0), SkIntToScalar(1) },
247 { SkIntToScalar(1), SkIntToScalar(1) },
248 { SkIntToScalar(2), SkIntToScalar(1) },
249 { SkIntToScalar(3), SkIntToScalar(1) },
250 { SkIntToScalar(4), SkIntToScalar(1) },
251 { SkIntToScalar(5), SkIntToScalar(1) },
252 { SkIntToScalar(6), SkIntToScalar(1) },
253 { SkIntToScalar(7), SkIntToScalar(1) },
254 { SkIntToScalar(8), SkIntToScalar(1) },
255 { SkIntToScalar(9), SkIntToScalar(1) },
256 { SkIntToScalar(10), SkIntToScalar(1) },
257 };
258
259#define EXPECT_COPY_ON_WRITE(command) \
260 { \
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000261 SkImage* imageBefore = surface->newImageSnapshot(); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000262 SkAutoTUnref<SkImage> aur_before(imageBefore); \
263 canvas-> command ; \
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000264 SkImage* imageAfter = surface->newImageSnapshot(); \
junov@chromium.org995beb62013-03-28 13:49:22 +0000265 SkAutoTUnref<SkImage> aur_after(imageAfter); \
266 REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
267 }
268
269 EXPECT_COPY_ON_WRITE(clear(testColor))
270 EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
271 EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
272 testPaint))
273 EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
274 EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
275 EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
276 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
277 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0))
278 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, NULL, testRect))
279 EXPECT_COPY_ON_WRITE(drawBitmapMatrix(testBitmap, testMatrix, NULL))
280 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL))
281 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL))
282 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testPaint))
283 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoints2, \
284 testPaint))
285 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testPath, NULL, \
286 testPaint))
287}
288
junov@chromium.orgaf058352013-04-03 15:03:26 +0000289static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter,
290 SurfaceType surfaceType,
291 GrContext* context) {
292 // This test succeeds by not triggering an assertion.
293 // The test verifies that the surface remains writable (usable) after
294 // acquiring and releasing a snapshot without triggering a copy on write.
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000295 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
junov@chromium.orgaf058352013-04-03 15:03:26 +0000296 SkCanvas* canvas = surface->getCanvas();
297 canvas->clear(1);
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000298 surface->newImageSnapshot()->unref(); // Create and destroy SkImage
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000299 canvas->clear(2); // Must not assert internally
junov@chromium.org995beb62013-03-28 13:49:22 +0000300}
junov@chromium.orgda904742013-05-01 22:38:16 +0000301
junov@chromium.orgb516a412013-05-01 22:49:59 +0000302#if SK_SUPPORT_GPU
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000303static void TestSurfaceInCache(skiatest::Reporter* reporter,
304 SurfaceType surfaceType,
305 GrContext* context) {
306 context->freeGpuResources();
307 REPORTER_ASSERT(reporter, 0 == context->getGpuTextureCacheResourceCount());
308 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
309 // Note: the stencil buffer is always cached, so kGpu_SurfaceType uses
310 // one cached resource, and kGpuScratch_SurfaceType uses two.
311 int expectedCachedResources = surfaceType == kGpuScratch_SurfaceType ? 2 : 1;
312 REPORTER_ASSERT(reporter, expectedCachedResources == context->getGpuTextureCacheResourceCount());
313
314 // Verify that all the cached resources are locked in cache.
skia.committer@gmail.com99e5b522014-03-21 03:02:42 +0000315 context->freeGpuResources();
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000316 REPORTER_ASSERT(reporter, expectedCachedResources == context->getGpuTextureCacheResourceCount());
317
318 // Verify that all the cached resources are unlocked upon surface release
319 surface.reset(0);
320 context->freeGpuResources();
skia.committer@gmail.com99e5b522014-03-21 03:02:42 +0000321 REPORTER_ASSERT(reporter, 0 == context->getGpuTextureCacheResourceCount());
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000322}
323
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000324static void Test_crbug263329(skiatest::Reporter* reporter,
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000325 SurfaceType surfaceType,
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000326 GrContext* context) {
327 // This is a regression test for crbug.com/263329
328 // Bug was caused by onCopyOnWrite releasing the old surface texture
329 // back to the scratch texture pool even though the texture is used
330 // by and active SkImage_Gpu.
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000331 SkAutoTUnref<SkSurface> surface1(createSurface(surfaceType, context));
332 SkAutoTUnref<SkSurface> surface2(createSurface(surfaceType, context));
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +0000333 SkCanvas* canvas1 = surface1->getCanvas();
334 SkCanvas* canvas2 = surface2->getCanvas();
335 canvas1->clear(1);
336 SkAutoTUnref<SkImage> image1(surface1->newImageSnapshot());
337 // Trigger copy on write, new backing is a scratch texture
338 canvas1->clear(2);
339 SkAutoTUnref<SkImage> image2(surface1->newImageSnapshot());
340 // Trigger copy on write, old backing should not be returned to scratch
341 // pool because it is held by image2
342 canvas1->clear(3);
343
344 canvas2->clear(4);
345 SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot());
346 // Trigger copy on write on surface2. The new backing store should not
347 // be recycling a texture that is held by an existing image.
348 canvas2->clear(5);
349 SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot());
350 REPORTER_ASSERT(reporter, image4->getTexture() != image3->getTexture());
351 // The following assertion checks crbug.com/263329
352 REPORTER_ASSERT(reporter, image4->getTexture() != image2->getTexture());
353 REPORTER_ASSERT(reporter, image4->getTexture() != image1->getTexture());
354 REPORTER_ASSERT(reporter, image3->getTexture() != image2->getTexture());
355 REPORTER_ASSERT(reporter, image3->getTexture() != image1->getTexture());
356 REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture());
357}
358
junov@chromium.orgda904742013-05-01 22:38:16 +0000359static void TestGetTexture(skiatest::Reporter* reporter,
360 SurfaceType surfaceType,
361 GrContext* context) {
362 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
363 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
364 GrTexture* texture = image->getTexture();
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000365 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceType) {
junov@chromium.orgda904742013-05-01 22:38:16 +0000366 REPORTER_ASSERT(reporter, NULL != texture);
367 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
368 } else {
369 REPORTER_ASSERT(reporter, NULL == texture);
370 }
371 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
372 REPORTER_ASSERT(reporter, image->getTexture() == texture);
373}
junov@chromium.orgb516a412013-05-01 22:49:59 +0000374#endif
junov@chromium.orgda904742013-05-01 22:38:16 +0000375
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000376static void TestSurfaceNoCanvas(skiatest::Reporter* reporter,
377 SurfaceType surfaceType,
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000378 GrContext* context,
379 SkSurface::ContentChangeMode mode) {
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000380 // Verifies the robustness of SkSurface for handling use cases where calls
381 // are made before a canvas is created.
382 {
383 // Test passes by not asserting
384 SkSurface* surface = createSurface(surfaceType, context);
385 SkAutoTUnref<SkSurface> aur_surface(surface);
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000386 surface->notifyContentWillChange(mode);
robertphillips@google.com03087072013-10-02 16:42:21 +0000387 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000388 }
389 {
390 SkSurface* surface = createSurface(surfaceType, context);
391 SkAutoTUnref<SkSurface> aur_surface(surface);
392 SkImage* image1 = surface->newImageSnapshot();
393 SkAutoTUnref<SkImage> aur_image1(image1);
robertphillips@google.com03087072013-10-02 16:42:21 +0000394 SkDEBUGCODE(image1->validate();)
395 SkDEBUGCODE(surface->validate();)
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000396 surface->notifyContentWillChange(mode);
robertphillips@google.com03087072013-10-02 16:42:21 +0000397 SkDEBUGCODE(image1->validate();)
398 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000399 SkImage* image2 = surface->newImageSnapshot();
400 SkAutoTUnref<SkImage> aur_image2(image2);
robertphillips@google.com03087072013-10-02 16:42:21 +0000401 SkDEBUGCODE(image2->validate();)
402 SkDEBUGCODE(surface->validate();)
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000403 REPORTER_ASSERT(reporter, image1 != image2);
404 }
skia.committer@gmail.com45fb8b62013-04-17 07:00:56 +0000405
junov@chromium.orgacea3ef2013-04-16 19:41:09 +0000406}
junov@chromium.org995beb62013-03-28 13:49:22 +0000407
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000408DEF_GPUTEST(Surface, reporter, factory) {
reed@google.com999da9c2014-02-06 13:43:07 +0000409 test_image(reporter);
410
junov@chromium.orgaf058352013-04-03 15:03:26 +0000411 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
junov@chromium.orgaf058352013-04-03 15:03:26 +0000412 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL);
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000413 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard_ContentChangeMode);
414 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ContentChangeMode);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000415
reed@google.com4f7c6152014-02-06 14:11:56 +0000416 test_imagepeek(reporter);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000417 test_canvaspeek(reporter, factory);
418
junov@chromium.orgb516a412013-05-01 22:49:59 +0000419#if SK_SUPPORT_GPU
junov@chromium.orgda904742013-05-01 22:38:16 +0000420 TestGetTexture(reporter, kRaster_SurfaceType, NULL);
junov@chromium.orgaf058352013-04-03 15:03:26 +0000421 if (NULL != factory) {
422 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000423 if (NULL != context) {
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000424 TestSurfaceInCache(reporter, kGpu_SurfaceType, context);
425 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context);
426 Test_crbug263329(reporter, kGpu_SurfaceType, context);
427 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000428 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000429 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000430 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000431 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000432 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000433 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000434 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000435 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000436 TestGetTexture(reporter, kGpu_SurfaceType, context);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000437 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
robertphillips@google.com3bddb382013-11-12 13:51:03 +0000438 }
junov@chromium.orgaf058352013-04-03 15:03:26 +0000439 }
junov@chromium.org995beb62013-03-28 13:49:22 +0000440#endif
441}