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

Unified Diff: tests/SurfaceTest.cpp

Issue 1121813002: new image from backend desc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: set samplecount to 0 (for now) Created 5 years, 7 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 23a7f94f246f10e9cec299ed78565b6996c56ae4..a3ac216786c262882f2d59be04f7a23385779f16 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -617,3 +617,69 @@ DEF_GPUTEST(Surface, reporter, factory) {
}
#endif
}
+
+#if SK_SUPPORT_GPU
+static SkImage* make_desc_image(GrContext* ctx, int w, int h, GrBackendObject texID, bool doCopy) {
+ GrBackendTextureDesc desc;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ // need to be a rendertarget for now...
+ desc.fFlags = kRenderTarget_GrBackendTextureFlag;
+ desc.fWidth = w;
+ desc.fHeight = h;
+ desc.fSampleCnt = 0;
+ desc.fTextureHandle = texID;
+ return doCopy ? SkImage::NewFromTextureCopy(ctx, desc) : SkImage::NewFromTexture(ctx, desc);
+}
+
+static void test_image_color(skiatest::Reporter* reporter, SkImage* image, SkPMColor expected) {
+ const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
+ SkPMColor pixel;
+ REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0, 0));
+ REPORTER_ASSERT(reporter, pixel == expected);
+}
+
+DEF_GPUTEST(SkImage_NewFromTexture, reporter, factory) {
+ GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
+ if (!ctx) {
+ REPORTER_ASSERT(reporter, false);
+ return;
+ }
+ GrTextureProvider* provider = ctx->textureProvider();
+
+ const int w = 10;
+ const int h = 10;
+ SkPMColor storage[w * h];
+ const SkPMColor expected0 = SkPreMultiplyColor(SK_ColorRED);
+ sk_memset32(storage, expected0, w * h);
+
+ GrSurfaceDesc desc;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag; // needs to be a rendertarget for readpixels();
+ desc.fOrigin = kDefault_GrSurfaceOrigin;
+ desc.fWidth = w;
+ desc.fHeight = h;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fSampleCnt = 0;
+
+ SkAutoTUnref<GrTexture> tex(provider->createTexture(desc, false, storage, w * 4));
+ if (!tex) {
+ REPORTER_ASSERT(reporter, false);
+ return;
+ }
+
+ GrBackendObject srcTex = tex->getTextureHandle();
+ SkAutoTUnref<SkImage> refImg(make_desc_image(ctx, w, h, srcTex, false));
+ SkAutoTUnref<SkImage> cpyImg(make_desc_image(ctx, w, h, srcTex, true));
+
+ test_image_color(reporter, refImg, expected0);
+ test_image_color(reporter, cpyImg, expected0);
+
+ // Now lets jam new colors into our "external" texture, and see if the images notice
+ const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE);
+ sk_memset32(storage, expected1, w * h);
+ tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kFlushWrites_PixelOp);
+
+ // We expect the ref'd image to see the new color, but cpy'd one should still see the old color
+ test_image_color(reporter, refImg, expected1);
+ test_image_color(reporter, cpyImg, expected0);
+}
+#endif
« 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