diff options
Diffstat (limited to 'tests/DeferredCanvasTest.cpp')
-rw-r--r-- | tests/DeferredCanvasTest.cpp | 196 |
1 files changed, 113 insertions, 83 deletions
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp index cc8a1f2c53..b960fe3607 100644 --- a/tests/DeferredCanvasTest.cpp +++ b/tests/DeferredCanvasTest.cpp @@ -681,68 +681,83 @@ static PixelPtr get_surface_ptr(SkSurface* surface, bool useGpu) { static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFactory* factory) { SkImageInfo imageSpec = SkImageInfo::MakeN32Premul(10, 10); - SkSurface* surface; bool useGpu = NULL != factory; + int cnt; #if SK_SUPPORT_GPU if (useGpu) { - GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); - if (NULL == context) { - return; - } - - surface = SkSurface::NewRenderTarget(context, imageSpec); + cnt = GrContextFactory::kGLContextTypeCnt; } else { - surface = SkSurface::NewRaster(imageSpec); + cnt = 1; } #else SkASSERT(!useGpu); - surface = SkSurface::NewRaster(imageSpec); + cnt = 1; #endif - SkASSERT(NULL != surface); - SkAutoTUnref<SkSurface> aur(surface); - SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface)); - - SkImage* image1 = canvas->newImageSnapshot(); - SkAutoTUnref<SkImage> aur_i1(image1); - PixelPtr pixels1 = get_surface_ptr(surface, useGpu); - // The following clear would normally trigger a copy on write, but - // it won't because rendering is deferred. - canvas->clear(SK_ColorBLACK); - // Obtaining a snapshot directly from the surface (as opposed to the - // SkDeferredCanvas) will not trigger a flush of deferred draw operations - // and will therefore return the same image as the previous snapshot. - SkImage* image2 = surface->newImageSnapshot(); - SkAutoTUnref<SkImage> aur_i2(image2); - // Images identical because of deferral - REPORTER_ASSERT(reporter, image1->uniqueID() == image2->uniqueID()); - // Now we obtain a snpshot via the deferred canvas, which triggers a flush. - // Because there is a pending clear, this will generate a different image. - SkImage* image3 = canvas->newImageSnapshot(); - SkAutoTUnref<SkImage> aur_i3(image3); - REPORTER_ASSERT(reporter, image1->uniqueID() != image3->uniqueID()); - // Verify that backing store is now a different buffer because of copy on - // write - PixelPtr pixels2 = get_surface_ptr(surface, useGpu); - REPORTER_ASSERT(reporter, pixels1 != pixels2); - // Verify copy-on write with a draw operation that gets deferred by - // the in order draw buffer. - SkPaint paint; - canvas->drawPaint(paint); - SkImage* image4 = canvas->newImageSnapshot(); // implicit flush - SkAutoTUnref<SkImage> aur_i4(image4); - REPORTER_ASSERT(reporter, image4->uniqueID() != image3->uniqueID()); - PixelPtr pixels3 = get_surface_ptr(surface, useGpu); - REPORTER_ASSERT(reporter, pixels2 != pixels3); - // Verify that a direct canvas flush with a pending draw does not trigger - // a copy on write when the surface is not sharing its buffer with an - // SkImage. - canvas->clear(SK_ColorWHITE); - canvas->flush(); - PixelPtr pixels4 = get_surface_ptr(surface, useGpu); - canvas->drawPaint(paint); - canvas->flush(); - PixelPtr pixels5 = get_surface_ptr(surface, useGpu); - REPORTER_ASSERT(reporter, pixels4 == pixels5); + for (int i = 0; i < cnt; ++i) { + SkSurface* surface; +#if SK_SUPPORT_GPU + if (useGpu) { + GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i; + if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { + continue; + } + GrContext* context = factory->get(glCtxType); + if (NULL == context) { + return; + } + + surface = SkSurface::NewRenderTarget(context, imageSpec); + } else +#endif + { + surface = SkSurface::NewRaster(imageSpec); + } + SkASSERT(NULL != surface); + SkAutoTUnref<SkSurface> aur(surface); + SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface)); + + SkImage* image1 = canvas->newImageSnapshot(); + SkAutoTUnref<SkImage> aur_i1(image1); + PixelPtr pixels1 = get_surface_ptr(surface, useGpu); + // The following clear would normally trigger a copy on write, but + // it won't because rendering is deferred. + canvas->clear(SK_ColorBLACK); + // Obtaining a snapshot directly from the surface (as opposed to the + // SkDeferredCanvas) will not trigger a flush of deferred draw operations + // and will therefore return the same image as the previous snapshot. + SkImage* image2 = surface->newImageSnapshot(); + SkAutoTUnref<SkImage> aur_i2(image2); + // Images identical because of deferral + REPORTER_ASSERT(reporter, image1->uniqueID() == image2->uniqueID()); + // Now we obtain a snpshot via the deferred canvas, which triggers a flush. + // Because there is a pending clear, this will generate a different image. + SkImage* image3 = canvas->newImageSnapshot(); + SkAutoTUnref<SkImage> aur_i3(image3); + REPORTER_ASSERT(reporter, image1->uniqueID() != image3->uniqueID()); + // Verify that backing store is now a different buffer because of copy on + // write + PixelPtr pixels2 = get_surface_ptr(surface, useGpu); + REPORTER_ASSERT(reporter, pixels1 != pixels2); + // Verify copy-on write with a draw operation that gets deferred by + // the in order draw buffer. + SkPaint paint; + canvas->drawPaint(paint); + SkImage* image4 = canvas->newImageSnapshot(); // implicit flush + SkAutoTUnref<SkImage> aur_i4(image4); + REPORTER_ASSERT(reporter, image4->uniqueID() != image3->uniqueID()); + PixelPtr pixels3 = get_surface_ptr(surface, useGpu); + REPORTER_ASSERT(reporter, pixels2 != pixels3); + // Verify that a direct canvas flush with a pending draw does not trigger + // a copy on write when the surface is not sharing its buffer with an + // SkImage. + canvas->clear(SK_ColorWHITE); + canvas->flush(); + PixelPtr pixels4 = get_surface_ptr(surface, useGpu); + canvas->drawPaint(paint); + canvas->flush(); + PixelPtr pixels5 = get_surface_ptr(surface, useGpu); + REPORTER_ASSERT(reporter, pixels4 == pixels5); + } } static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContextFactory* factory) { @@ -750,42 +765,57 @@ static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContext SkSurface* surface; SkSurface* alternateSurface; bool useGpu = NULL != factory; + int cnt; #if SK_SUPPORT_GPU if (useGpu) { - GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); - if (NULL == context) { - return; - } - surface = SkSurface::NewRenderTarget(context, imageSpec); - alternateSurface = SkSurface::NewRenderTarget(context, imageSpec); + cnt = GrContextFactory::kGLContextTypeCnt; } else { - surface = SkSurface::NewRaster(imageSpec); - alternateSurface = SkSurface::NewRaster(imageSpec); + cnt = 1; } #else SkASSERT(!useGpu); - surface = SkSurface::NewRaster(imageSpec); - alternateSurface = SkSurface::NewRaster(imageSpec); + cnt = 1; #endif - SkASSERT(NULL != surface); - SkASSERT(NULL != alternateSurface); - SkAutoTUnref<SkSurface> aur1(surface); - SkAutoTUnref<SkSurface> aur2(alternateSurface); - PixelPtr pixels1 = get_surface_ptr(surface, useGpu); - PixelPtr pixels2 = get_surface_ptr(alternateSurface, useGpu); - SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(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, get_surface_ptr(surface, useGpu) == pixels1); - REPORTER_ASSERT(reporter, get_surface_ptr(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, get_surface_ptr(surface, useGpu) == pixels1); - REPORTER_ASSERT(reporter, get_surface_ptr(alternateSurface, useGpu) != pixels2); + + for (int i = 0; i < cnt; ++i) { +#if SK_SUPPORT_GPU + if (useGpu) { + GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i; + if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { + continue; + } + GrContext* context = factory->get(glCtxType); + if (NULL == context) { + continue; + } + surface = SkSurface::NewRenderTarget(context, imageSpec); + alternateSurface = SkSurface::NewRenderTarget(context, imageSpec); + } else +#endif + { + surface = SkSurface::NewRaster(imageSpec); + alternateSurface = SkSurface::NewRaster(imageSpec); + } + SkASSERT(NULL != surface); + SkASSERT(NULL != alternateSurface); + SkAutoTUnref<SkSurface> aur1(surface); + SkAutoTUnref<SkSurface> aur2(alternateSurface); + PixelPtr pixels1 = get_surface_ptr(surface, useGpu); + PixelPtr pixels2 = get_surface_ptr(alternateSurface, useGpu); + SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(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, get_surface_ptr(surface, useGpu) == pixels1); + REPORTER_ASSERT(reporter, get_surface_ptr(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, get_surface_ptr(surface, useGpu) == pixels1); + REPORTER_ASSERT(reporter, get_surface_ptr(alternateSurface, useGpu) != pixels2); + } } static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporter) { |