2013-03-28 13:49:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-01-10 22:08:27 +00:00
|
|
|
|
2013-03-28 13:49:22 +00:00
|
|
|
#include "SkCanvas.h"
|
2014-02-06 14:11:56 +00:00
|
|
|
#include "SkData.h"
|
|
|
|
#include "SkImageEncoder.h"
|
2013-03-28 13:49:22 +00:00
|
|
|
#include "SkRRect.h"
|
|
|
|
#include "SkSurface.h"
|
2014-02-06 14:11:56 +00:00
|
|
|
#include "SkUtils.h"
|
2013-03-28 13:49:22 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContextFactory.h"
|
|
|
|
#else
|
|
|
|
class GrContextFactory;
|
|
|
|
class GrContext;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum SurfaceType {
|
|
|
|
kRaster_SurfaceType,
|
2014-02-13 17:14:46 +00:00
|
|
|
kRasterDirect_SurfaceType,
|
2013-03-28 13:49:22 +00:00
|
|
|
kGpu_SurfaceType,
|
2014-03-19 21:19:16 +00:00
|
|
|
kGpuScratch_SurfaceType,
|
2013-03-28 13:49:22 +00:00
|
|
|
};
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static const int gSurfaceSize = 10;
|
|
|
|
static SkPMColor gSurfaceStorage[gSurfaceSize * gSurfaceSize];
|
|
|
|
|
|
|
|
static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context,
|
|
|
|
SkImageInfo* requestedInfo = NULL) {
|
|
|
|
static const SkImageInfo info = SkImageInfo::MakeN32Premul(gSurfaceSize,
|
|
|
|
gSurfaceSize);
|
|
|
|
|
|
|
|
if (requestedInfo) {
|
|
|
|
*requestedInfo = info;
|
|
|
|
}
|
2013-03-28 13:49:22 +00:00
|
|
|
|
|
|
|
switch (surfaceType) {
|
2014-02-13 17:14:46 +00:00
|
|
|
case kRaster_SurfaceType:
|
|
|
|
return SkSurface::NewRaster(info);
|
|
|
|
case kRasterDirect_SurfaceType:
|
|
|
|
return SkSurface::NewRasterDirect(info, gSurfaceStorage,
|
|
|
|
info.minRowBytes());
|
|
|
|
case kGpu_SurfaceType:
|
2013-04-03 15:25:46 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-02-13 17:14:46 +00:00
|
|
|
return context ? SkSurface::NewRenderTarget(context, info) : NULL;
|
2014-03-19 21:19:16 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case kGpuScratch_SurfaceType:
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
return context ? SkSurface::NewScratchRenderTarget(context, info) : NULL;
|
2013-04-03 15:25:46 +00:00
|
|
|
#endif
|
2014-02-13 17:14:46 +00:00
|
|
|
break;
|
2013-03-28 13:49:22 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-06 14:11:56 +00:00
|
|
|
enum ImageType {
|
|
|
|
kRasterCopy_ImageType,
|
|
|
|
kRasterData_ImageType,
|
|
|
|
kGpu_ImageType,
|
|
|
|
kCodec_ImageType,
|
|
|
|
};
|
2014-02-06 13:43:07 +00:00
|
|
|
|
|
|
|
static void test_image(skiatest::Reporter* reporter) {
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
|
|
|
|
size_t rowBytes = info.minRowBytes();
|
|
|
|
size_t size = info.getSafeSize(rowBytes);
|
|
|
|
void* addr = sk_malloc_throw(size);
|
|
|
|
SkData* data = SkData::NewFromMalloc(addr, size);
|
2014-02-07 12:20:04 +00:00
|
|
|
|
2014-02-06 13:43:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
|
|
|
|
SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == data->getRefCnt());
|
|
|
|
image->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
|
|
|
|
data->unref();
|
|
|
|
}
|
|
|
|
|
2014-02-06 14:11:56 +00:00
|
|
|
static SkImage* createImage(ImageType imageType, GrContext* context,
|
|
|
|
SkColor color) {
|
|
|
|
const SkPMColor pmcolor = SkPreMultiplyColor(color);
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
|
|
|
|
const size_t rowBytes = info.minRowBytes();
|
|
|
|
const size_t size = rowBytes * info.fHeight;
|
|
|
|
|
|
|
|
void* addr = sk_malloc_throw(size);
|
|
|
|
sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2));
|
|
|
|
SkAutoTUnref<SkData> data(SkData::NewFromMalloc(addr, size));
|
|
|
|
|
|
|
|
switch (imageType) {
|
|
|
|
case kRasterCopy_ImageType:
|
|
|
|
return SkImage::NewRasterCopy(info, addr, rowBytes);
|
|
|
|
case kRasterData_ImageType:
|
|
|
|
return SkImage::NewRasterData(info, data, rowBytes);
|
|
|
|
case kGpu_ImageType:
|
|
|
|
return NULL; // TODO
|
|
|
|
case kCodec_ImageType: {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(info, addr, rowBytes, NULL, NULL);
|
|
|
|
SkAutoTUnref<SkData> src(
|
|
|
|
SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type,
|
|
|
|
100));
|
|
|
|
return SkImage::NewEncodedData(src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkASSERT(false);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_imagepeek(skiatest::Reporter* reporter) {
|
|
|
|
static const struct {
|
|
|
|
ImageType fType;
|
|
|
|
bool fPeekShouldSucceed;
|
|
|
|
} gRec[] = {
|
|
|
|
{ kRasterCopy_ImageType, true },
|
|
|
|
{ kRasterData_ImageType, true },
|
2014-03-19 21:19:16 +00:00
|
|
|
{ kGpu_ImageType, false },
|
2014-02-06 14:11:56 +00:00
|
|
|
{ kCodec_ImageType, false },
|
|
|
|
};
|
2014-02-14 03:02:05 +00:00
|
|
|
|
2014-02-06 14:11:56 +00:00
|
|
|
const SkColor color = SK_ColorRED;
|
|
|
|
const SkPMColor pmcolor = SkPreMultiplyColor(color);
|
2014-02-14 03:02:05 +00:00
|
|
|
|
2014-02-06 14:11:56 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
|
|
|
|
SkImageInfo info;
|
|
|
|
size_t rowBytes;
|
2014-02-14 03:02:05 +00:00
|
|
|
|
2014-02-06 14:11:56 +00:00
|
|
|
SkAutoTUnref<SkImage> image(createImage(gRec[i].fType, NULL, color));
|
|
|
|
if (!image.get()) {
|
|
|
|
continue; // gpu may not be enabled
|
|
|
|
}
|
|
|
|
const void* addr = image->peekPixels(&info, &rowBytes);
|
|
|
|
bool success = (NULL != addr);
|
|
|
|
REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
|
|
|
|
if (success) {
|
|
|
|
REPORTER_ASSERT(reporter, 10 == info.fWidth);
|
|
|
|
REPORTER_ASSERT(reporter, 10 == info.fHeight);
|
2014-04-11 17:15:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, kN32_SkColorType == info.fColorType);
|
2014-02-06 14:11:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.fAlphaType ||
|
2014-02-13 17:14:46 +00:00
|
|
|
kOpaque_SkAlphaType == info.fAlphaType);
|
2014-02-06 14:11:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
|
|
|
|
REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void test_canvaspeek(skiatest::Reporter* reporter,
|
|
|
|
GrContextFactory* factory) {
|
|
|
|
static const struct {
|
|
|
|
SurfaceType fType;
|
|
|
|
bool fPeekShouldSucceed;
|
|
|
|
} gRec[] = {
|
|
|
|
{ kRaster_SurfaceType, true },
|
|
|
|
{ kRasterDirect_SurfaceType, true },
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
{ kGpu_SurfaceType, false },
|
2014-03-19 21:19:16 +00:00
|
|
|
{ kGpuScratch_SurfaceType, false },
|
2014-02-13 17:14:46 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
const SkColor color = SK_ColorRED;
|
|
|
|
const SkPMColor pmcolor = SkPreMultiplyColor(color);
|
|
|
|
|
|
|
|
GrContext* context = NULL;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
context = factory->get(GrContextFactory::kNative_GLContextType);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
|
|
|
|
SkImageInfo info, requestInfo;
|
|
|
|
size_t rowBytes;
|
|
|
|
|
|
|
|
SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context,
|
|
|
|
&requestInfo));
|
|
|
|
surface->getCanvas()->clear(color);
|
|
|
|
|
|
|
|
const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes);
|
|
|
|
bool success = (NULL != addr);
|
|
|
|
REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
|
|
|
|
|
|
|
|
SkImageInfo info2;
|
|
|
|
size_t rb2;
|
|
|
|
const void* addr2 = surface->peekPixels(&info2, &rb2);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
REPORTER_ASSERT(reporter, requestInfo == info);
|
|
|
|
REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes);
|
|
|
|
REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, addr2 == addr);
|
|
|
|
REPORTER_ASSERT(reporter, info2 == info);
|
|
|
|
REPORTER_ASSERT(reporter, rb2 == rowBytes);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, NULL == addr2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 13:49:22 +00:00
|
|
|
static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType surfaceType,
|
|
|
|
GrContext* context) {
|
|
|
|
// Verify that the right canvas commands trigger a copy on write
|
|
|
|
SkSurface* surface = createSurface(surfaceType, context);
|
|
|
|
SkAutoTUnref<SkSurface> aur_surface(surface);
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
|
|
|
const SkRect testRect =
|
|
|
|
SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(4), SkIntToScalar(5));
|
|
|
|
SkMatrix testMatrix;
|
|
|
|
testMatrix.reset();
|
|
|
|
testMatrix.setScale(SkIntToScalar(2), SkIntToScalar(3));
|
|
|
|
|
|
|
|
SkPath testPath;
|
|
|
|
testPath.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(2), SkIntToScalar(1)));
|
|
|
|
|
|
|
|
const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
|
|
|
|
|
|
|
|
SkRegion testRegion;
|
|
|
|
testRegion.setRect(testIRect);
|
|
|
|
|
|
|
|
|
|
|
|
const SkColor testColor = 0x01020304;
|
|
|
|
const SkPaint testPaint;
|
|
|
|
const SkPoint testPoints[3] = {
|
|
|
|
{SkIntToScalar(0), SkIntToScalar(0)},
|
|
|
|
{SkIntToScalar(2), SkIntToScalar(1)},
|
|
|
|
{SkIntToScalar(0), SkIntToScalar(2)}
|
|
|
|
};
|
|
|
|
const size_t testPointCount = 3;
|
|
|
|
|
|
|
|
SkBitmap testBitmap;
|
2014-02-13 14:41:43 +00:00
|
|
|
testBitmap.allocN32Pixels(10, 10);
|
2013-10-09 12:51:09 +00:00
|
|
|
testBitmap.eraseColor(0);
|
2013-03-28 13:49:22 +00:00
|
|
|
|
|
|
|
SkRRect testRRect;
|
|
|
|
testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1);
|
|
|
|
|
|
|
|
SkString testText("Hello World");
|
|
|
|
const SkPoint testPoints2[] = {
|
|
|
|
{ SkIntToScalar(0), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(1), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(2), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(3), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(4), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(5), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(6), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(7), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(8), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(9), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(10), SkIntToScalar(1) },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EXPECT_COPY_ON_WRITE(command) \
|
|
|
|
{ \
|
2013-04-12 20:20:50 +00:00
|
|
|
SkImage* imageBefore = surface->newImageSnapshot(); \
|
2013-03-28 13:49:22 +00:00
|
|
|
SkAutoTUnref<SkImage> aur_before(imageBefore); \
|
|
|
|
canvas-> command ; \
|
2013-04-12 20:20:50 +00:00
|
|
|
SkImage* imageAfter = surface->newImageSnapshot(); \
|
2013-03-28 13:49:22 +00:00
|
|
|
SkAutoTUnref<SkImage> aur_after(imageAfter); \
|
|
|
|
REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_COPY_ON_WRITE(clear(testColor))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
|
|
|
|
testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, NULL, testRect))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawBitmapMatrix(testBitmap, testMatrix, NULL))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoints2, \
|
|
|
|
testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testPath, NULL, \
|
|
|
|
testPaint))
|
|
|
|
}
|
|
|
|
|
2013-04-03 15:03:26 +00:00
|
|
|
static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter,
|
|
|
|
SurfaceType surfaceType,
|
|
|
|
GrContext* context) {
|
|
|
|
// This test succeeds by not triggering an assertion.
|
|
|
|
// The test verifies that the surface remains writable (usable) after
|
|
|
|
// acquiring and releasing a snapshot without triggering a copy on write.
|
2013-07-25 23:29:40 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
|
2013-04-03 15:03:26 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
canvas->clear(1);
|
2013-04-12 20:20:50 +00:00
|
|
|
surface->newImageSnapshot()->unref(); // Create and destroy SkImage
|
2013-07-25 23:29:40 +00:00
|
|
|
canvas->clear(2); // Must not assert internally
|
2013-03-28 13:49:22 +00:00
|
|
|
}
|
2013-05-01 22:38:16 +00:00
|
|
|
|
2013-05-01 22:49:59 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-03-19 21:19:16 +00:00
|
|
|
static void TestSurfaceInCache(skiatest::Reporter* reporter,
|
|
|
|
SurfaceType surfaceType,
|
|
|
|
GrContext* context) {
|
|
|
|
context->freeGpuResources();
|
2014-05-09 14:29:32 +00:00
|
|
|
int resourceCount;
|
|
|
|
|
|
|
|
context->getResourceCacheUsage(&resourceCount, NULL);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == resourceCount);
|
2014-03-19 21:19:16 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
|
|
|
|
// Note: the stencil buffer is always cached, so kGpu_SurfaceType uses
|
|
|
|
// one cached resource, and kGpuScratch_SurfaceType uses two.
|
|
|
|
int expectedCachedResources = surfaceType == kGpuScratch_SurfaceType ? 2 : 1;
|
2014-05-09 14:29:32 +00:00
|
|
|
context->getResourceCacheUsage(&resourceCount, NULL);
|
|
|
|
REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount);
|
2014-03-19 21:19:16 +00:00
|
|
|
|
|
|
|
// Verify that all the cached resources are locked in cache.
|
2014-03-21 03:02:42 +00:00
|
|
|
context->freeGpuResources();
|
2014-05-09 14:29:32 +00:00
|
|
|
context->getResourceCacheUsage(&resourceCount, NULL);
|
|
|
|
REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount);
|
2014-03-19 21:19:16 +00:00
|
|
|
|
|
|
|
// Verify that all the cached resources are unlocked upon surface release
|
|
|
|
surface.reset(0);
|
|
|
|
context->freeGpuResources();
|
2014-05-09 14:29:32 +00:00
|
|
|
context->getResourceCacheUsage(&resourceCount, NULL);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == resourceCount);
|
2014-03-19 21:19:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 23:29:40 +00:00
|
|
|
static void Test_crbug263329(skiatest::Reporter* reporter,
|
2014-03-19 21:19:16 +00:00
|
|
|
SurfaceType surfaceType,
|
2013-07-25 23:29:40 +00:00
|
|
|
GrContext* context) {
|
|
|
|
// This is a regression test for crbug.com/263329
|
|
|
|
// Bug was caused by onCopyOnWrite releasing the old surface texture
|
|
|
|
// back to the scratch texture pool even though the texture is used
|
|
|
|
// by and active SkImage_Gpu.
|
2014-03-19 21:19:16 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface1(createSurface(surfaceType, context));
|
|
|
|
SkAutoTUnref<SkSurface> surface2(createSurface(surfaceType, context));
|
2013-07-25 23:29:40 +00:00
|
|
|
SkCanvas* canvas1 = surface1->getCanvas();
|
|
|
|
SkCanvas* canvas2 = surface2->getCanvas();
|
|
|
|
canvas1->clear(1);
|
|
|
|
SkAutoTUnref<SkImage> image1(surface1->newImageSnapshot());
|
|
|
|
// Trigger copy on write, new backing is a scratch texture
|
|
|
|
canvas1->clear(2);
|
|
|
|
SkAutoTUnref<SkImage> image2(surface1->newImageSnapshot());
|
|
|
|
// Trigger copy on write, old backing should not be returned to scratch
|
|
|
|
// pool because it is held by image2
|
|
|
|
canvas1->clear(3);
|
|
|
|
|
|
|
|
canvas2->clear(4);
|
|
|
|
SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot());
|
|
|
|
// Trigger copy on write on surface2. The new backing store should not
|
|
|
|
// be recycling a texture that is held by an existing image.
|
|
|
|
canvas2->clear(5);
|
|
|
|
SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot());
|
|
|
|
REPORTER_ASSERT(reporter, image4->getTexture() != image3->getTexture());
|
|
|
|
// The following assertion checks crbug.com/263329
|
|
|
|
REPORTER_ASSERT(reporter, image4->getTexture() != image2->getTexture());
|
|
|
|
REPORTER_ASSERT(reporter, image4->getTexture() != image1->getTexture());
|
|
|
|
REPORTER_ASSERT(reporter, image3->getTexture() != image2->getTexture());
|
|
|
|
REPORTER_ASSERT(reporter, image3->getTexture() != image1->getTexture());
|
|
|
|
REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture());
|
|
|
|
}
|
|
|
|
|
2013-05-01 22:38:16 +00:00
|
|
|
static void TestGetTexture(skiatest::Reporter* reporter,
|
|
|
|
SurfaceType surfaceType,
|
|
|
|
GrContext* context) {
|
|
|
|
SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
|
|
|
|
SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
|
|
|
|
GrTexture* texture = image->getTexture();
|
2014-03-19 21:19:16 +00:00
|
|
|
if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceType) {
|
2013-05-01 22:38:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, NULL != texture);
|
|
|
|
REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, NULL == texture);
|
|
|
|
}
|
|
|
|
surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
|
|
|
|
REPORTER_ASSERT(reporter, image->getTexture() == texture);
|
|
|
|
}
|
2013-05-01 22:49:59 +00:00
|
|
|
#endif
|
2013-05-01 22:38:16 +00:00
|
|
|
|
2013-04-16 19:41:09 +00:00
|
|
|
static void TestSurfaceNoCanvas(skiatest::Reporter* reporter,
|
|
|
|
SurfaceType surfaceType,
|
2013-04-22 14:28:01 +00:00
|
|
|
GrContext* context,
|
|
|
|
SkSurface::ContentChangeMode mode) {
|
2013-04-16 19:41:09 +00:00
|
|
|
// Verifies the robustness of SkSurface for handling use cases where calls
|
|
|
|
// are made before a canvas is created.
|
|
|
|
{
|
|
|
|
// Test passes by not asserting
|
|
|
|
SkSurface* surface = createSurface(surfaceType, context);
|
|
|
|
SkAutoTUnref<SkSurface> aur_surface(surface);
|
2013-04-22 14:28:01 +00:00
|
|
|
surface->notifyContentWillChange(mode);
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(surface->validate();)
|
2013-04-16 19:41:09 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkSurface* surface = createSurface(surfaceType, context);
|
|
|
|
SkAutoTUnref<SkSurface> aur_surface(surface);
|
|
|
|
SkImage* image1 = surface->newImageSnapshot();
|
|
|
|
SkAutoTUnref<SkImage> aur_image1(image1);
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(image1->validate();)
|
|
|
|
SkDEBUGCODE(surface->validate();)
|
2013-04-22 14:28:01 +00:00
|
|
|
surface->notifyContentWillChange(mode);
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(image1->validate();)
|
|
|
|
SkDEBUGCODE(surface->validate();)
|
2013-04-16 19:41:09 +00:00
|
|
|
SkImage* image2 = surface->newImageSnapshot();
|
|
|
|
SkAutoTUnref<SkImage> aur_image2(image2);
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(image2->validate();)
|
|
|
|
SkDEBUGCODE(surface->validate();)
|
2013-04-16 19:41:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, image1 != image2);
|
|
|
|
}
|
2013-04-17 07:00:56 +00:00
|
|
|
|
2013-04-16 19:41:09 +00:00
|
|
|
}
|
2013-03-28 13:49:22 +00:00
|
|
|
|
2014-01-10 22:08:27 +00:00
|
|
|
DEF_GPUTEST(Surface, reporter, factory) {
|
2014-02-06 13:43:07 +00:00
|
|
|
test_image(reporter);
|
|
|
|
|
2013-04-03 15:03:26 +00:00
|
|
|
TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
|
|
|
|
TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL);
|
2013-04-22 14:28:01 +00:00
|
|
|
TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard_ContentChangeMode);
|
|
|
|
TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ContentChangeMode);
|
2014-02-13 17:14:46 +00:00
|
|
|
|
2014-02-06 14:11:56 +00:00
|
|
|
test_imagepeek(reporter);
|
2014-02-13 17:14:46 +00:00
|
|
|
test_canvaspeek(reporter, factory);
|
|
|
|
|
2013-05-01 22:49:59 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-05-01 22:38:16 +00:00
|
|
|
TestGetTexture(reporter, kRaster_SurfaceType, NULL);
|
2013-04-03 15:03:26 +00:00
|
|
|
if (NULL != factory) {
|
|
|
|
GrContext* context = factory->get(GrContextFactory::kNative_GLContextType);
|
2013-11-12 13:51:03 +00:00
|
|
|
if (NULL != context) {
|
2014-03-19 21:19:16 +00:00
|
|
|
TestSurfaceInCache(reporter, kGpu_SurfaceType, context);
|
|
|
|
TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context);
|
|
|
|
Test_crbug263329(reporter, kGpu_SurfaceType, context);
|
|
|
|
Test_crbug263329(reporter, kGpuScratch_SurfaceType, context);
|
2013-11-12 13:51:03 +00:00
|
|
|
TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context);
|
2014-03-19 21:19:16 +00:00
|
|
|
TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, context);
|
2013-11-12 13:51:03 +00:00
|
|
|
TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, context);
|
2014-03-19 21:19:16 +00:00
|
|
|
TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_SurfaceType, context);
|
2013-11-12 13:51:03 +00:00
|
|
|
TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
|
2014-03-19 21:19:16 +00:00
|
|
|
TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
|
2013-11-12 13:51:03 +00:00
|
|
|
TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
|
2014-03-19 21:19:16 +00:00
|
|
|
TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
|
2013-11-12 13:51:03 +00:00
|
|
|
TestGetTexture(reporter, kGpu_SurfaceType, context);
|
2014-03-19 21:19:16 +00:00
|
|
|
TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
|
2013-11-12 13:51:03 +00:00
|
|
|
}
|
2013-04-03 15:03:26 +00:00
|
|
|
}
|
2013-03-28 13:49:22 +00:00
|
|
|
#endif
|
|
|
|
}
|