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

Unified Diff: tests/DeferredCanvasTest.cpp

Issue 15896005: Adding setSurface public API method to SkDeferredCanvas (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 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/utils/SkDeferredCanvas.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DeferredCanvasTest.cpp
===================================================================
--- tests/DeferredCanvasTest.cpp (revision 9270)
+++ tests/DeferredCanvasTest.cpp (working copy)
@@ -548,6 +548,51 @@
REPORTER_ASSERT(reporter, pixels4 == pixels5);
}
+static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContextFactory* factory) {
+ SkImage::Info imageSpec = {
+ 10, // width
+ 10, // height
+ SkImage::kPMColor_ColorType,
+ SkImage::kPremul_AlphaType
+ };
+ SkSurface* surface;
+ SkSurface* alternateSurface;
+ bool useGpu = NULL != factory;
+#if SK_SUPPORT_GPU
+ if (useGpu) {
+ GrContext* context = factory->get(GrContextFactory::kNative_GLContextType);
+ surface = SkSurface::NewRenderTarget(context, imageSpec);
+ alternateSurface = SkSurface::NewRenderTarget(context, imageSpec);
+ } else {
+ surface = SkSurface::NewRaster(imageSpec);
+ alternateSurface = SkSurface::NewRaster(imageSpec);
+ }
+#else
+ SkASSERT(!useGpu);
+ surface = SkSurface::NewRaster(imageSpec);
+ alternateSurface = SkSurface::NewRaster(imageSpec);
+#endif
+ SkASSERT(NULL != surface);
+ SkASSERT(NULL != alternateSurface);
+ SkAutoTUnref<SkSurface> aur1(surface);
+ SkAutoTUnref<SkSurface> aur2(alternateSurface);
+ PixelPtr pixels1 = getSurfacePixelPtr(surface, useGpu);
+ PixelPtr pixels2 = getSurfacePixelPtr(alternateSurface, useGpu);
+ SkDeferredCanvas canvas(surface);
+ SkAutoTUnref<SkImage> image1(canvas.newImageSnapshot());
+ canvas.setSurface(alternateSurface);
+ SkAutoTUnref<SkImage> image2(canvas.newImageSnapshot());
+ REPORTER_ASSERT(reporter, image1->uniqueID() != image2->uniqueID());
+ // Verify that none of the above operations triggered a surface copy on write.
+ REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1);
+ REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) == pixels2);
+ // Verify that a flushed draw command will trigger a copy on write on alternateSurface.
+ canvas.clear(SK_ColorWHITE);
+ canvas.flush();
+ REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1);
+ REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) != pixels2);
+}
+
static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporter) {
SkBitmap store;
store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
@@ -581,8 +626,10 @@
TestDeferredCanvasBitmapSizeThreshold(reporter);
TestDeferredCanvasCreateCompatibleDevice(reporter);
TestDeferredCanvasSurface(reporter, NULL);
+ TestDeferredCanvasSetSurface(reporter, NULL);
if (NULL != factory) {
TestDeferredCanvasSurface(reporter, factory);
+ TestDeferredCanvasSetSurface(reporter, factory);
}
}
« no previous file with comments | « src/utils/SkDeferredCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698