Index: tests/SurfaceTest.cpp |
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp |
index 0114fb66fc85b6be9fc0404aaa1c0511cec1ea33..c2ccda4beb9d5a9fd3b94706b33a4c8f437255bd 100644 |
--- a/tests/SurfaceTest.cpp |
+++ b/tests/SurfaceTest.cpp |
@@ -30,7 +30,10 @@ enum SurfaceType { |
kRasterDirect_SurfaceType, |
kGpu_SurfaceType, |
kGpuScratch_SurfaceType, |
+ |
+ kLastSurfaceType = kGpuScratch_SurfaceType |
}; |
+static const int kSurfaceTypeCnt = kLastSurfaceType + 1; |
static void release_storage(void* pixels, void* context) { |
SkASSERT(pixels == context); |
@@ -38,8 +41,9 @@ static void release_storage(void* pixels, void* context) { |
} |
robertphillips
2015/06/23 19:48:09
create_surface ?
bsalomon
2015/06/25 21:47:18
Done.
|
static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context, |
+ SkAlphaType at = kPremul_SkAlphaType, |
SkImageInfo* requestedInfo = NULL) { |
- static const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
+ const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
if (requestedInfo) { |
*requestedInfo = info; |
@@ -418,7 +422,7 @@ static void test_canvaspeek(skiatest::Reporter* reporter, |
size_t rowBytes; |
SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context, |
robertphillips
2015/06/23 19:48:09
tab over ?
bsalomon
2015/06/25 21:47:18
Done.
|
- &requestInfo)); |
+ kPremul_SkAlphaType, &requestInfo)); |
surface->getCanvas()->clear(color); |
const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes); |
@@ -485,7 +489,7 @@ static void test_accessPixels(skiatest::Reporter* reporter, GrContextFactory* fa |
SkImageInfo info, requestInfo; |
SkAutoTUnref<SkSurface> surface(createSurface(gRec[j].fType, context, |
robertphillips
2015/06/23 19:48:09
tab over ?
bsalomon
2015/06/25 21:47:18
Done.
|
- &requestInfo)); |
+ kPremul_SkAlphaType, &requestInfo)); |
SkCanvas* canvas = surface->getCanvas(); |
canvas->clear(0); |
@@ -501,6 +505,31 @@ static void test_accessPixels(skiatest::Reporter* reporter, GrContextFactory* fa |
} |
} |
+static void test_snap_alphatype(skiatest::Reporter* reporter, GrContextFactory* factory) { |
+ GrContext* context = NULL; |
+#if SK_SUPPORT_GPU |
+ context = factory->get(GrContextFactory::kNative_GLContextType); |
+ if (NULL == context) { |
+ return; |
+ } |
+#endif |
+ for (int opaque = 0; opaque < 2; ++opaque) { |
+ SkAlphaType atype = SkToBool(opaque) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
+ for (int st = 0; st < kSurfaceTypeCnt; ++st) { |
+ SurfaceType stype = (SurfaceType)st; |
+ SkAutoTUnref<SkSurface> surface(createSurface(stype, context, atype)); |
+ REPORTER_ASSERT(reporter, surface); |
+ if (surface) { |
+ SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
+ REPORTER_ASSERT(reporter, image); |
+ if (image) { |
+ REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(opaque)); |
+ } |
+ } |
+ } |
+ } |
+} |
+ |
static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType surfaceType, |
GrContext* context) { |
// Verify that the right canvas commands trigger a copy on write |
@@ -740,6 +769,8 @@ DEF_GPUTEST(Surface, reporter, factory) { |
test_accessPixels(reporter, factory); |
+ test_snap_alphatype(reporter, factory); |
+ |
#if SK_SUPPORT_GPU |
TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
if (factory) { |