Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: tests/SurfaceTest.cpp

Issue 1210303003: add getTextureHandle to SkSurface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak dox Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SurfaceTest.cpp
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index c45e94e883cd3fd9402e35029bd1cd1775aca39b..817906070ad62183e8264efe55e08e348dfbe61b 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -223,7 +223,30 @@ struct ReleaseDataContext {
}
};
-static SkImage* create_image(ImageType imageType, GrContext* context, SkColor color,
+static void test_texture_handle(skiatest::Reporter* reporter, SkSurface* surf) {
+ SkAutoTUnref<SkImage> image0(surf->newImageSnapshot());
+ GrBackendObject obj = surf->getTextureHandle(SkSurface::kFlushRead_TextureHandleAccess);
+ REPORTER_ASSERT(reporter, obj != 0);
+ SkAutoTUnref<SkImage> image1(surf->newImageSnapshot());
+ // just read access should not affect the snapshot
+ REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID());
+
+ obj = surf->getTextureHandle(SkSurface::kFlushWrite_TextureHandleAccess);
+ REPORTER_ASSERT(reporter, obj != 0);
+ SkAutoTUnref<SkImage> image2(surf->newImageSnapshot());
+ // expect a new image, since we claimed we would write
+ REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID());
+
+ obj = surf->getTextureHandle(SkSurface::kDiscardWrite_TextureHandleAccess);
+ REPORTER_ASSERT(reporter, obj != 0);
+ SkAutoTUnref<SkImage> image3(surf->newImageSnapshot());
+ // expect a new(er) image, since we claimed we would write
+ REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID());
+ REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID());
+}
+
+static SkImage* create_image(skiatest::Reporter* reporter,
+ ImageType imageType, GrContext* context, SkColor color,
ReleaseDataContext* releaseContext) {
const SkPMColor pmcolor = SkPreMultiplyColor(color);
const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
@@ -248,6 +271,10 @@ static SkImage* create_image(ImageType imageType, GrContext* context, SkColor co
SkAutoTUnref<SkSurface> surf(
SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0));
surf->getCanvas()->clear(color);
+ // test our backing texture while were here...
+ test_texture_handle(reporter, surf);
+ // redraw so our returned image looks as expected.
+ surf->getCanvas()->clear(color);
return surf->newImageSnapshot();
}
case kCodec_ImageType: {
@@ -351,7 +378,7 @@ static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto
size_t rowBytes;
releaseCtx.fData = NULL;
- SkAutoTUnref<SkImage> image(create_image(gRec[i].fType, ctx, color, &releaseCtx));
+ SkAutoTUnref<SkImage> image(create_image(reporter, gRec[i].fType, ctx, color, &releaseCtx));
if (!image.get()) {
SkDebugf("failed to createImage[%d] %s\n", i, gRec[i].fName);
continue; // gpu may not be enabled
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698