From e904c09a3a9c701e8d91f2f6ee161feda7615d90 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Thu, 17 Jul 2014 10:50:59 -0700 Subject: Fix alpha textures in NV ES3 contexts on Windows. Make unit tests iterate over all the rendering GL context types rather than using kNative. Fix the extension printing when gStartupSpew is set. R=jvanverth@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/398183002 --- tests/DeferredCanvasTest.cpp | 196 +++++++++++++++++++++++++------------------ 1 file changed, 113 insertions(+), 83 deletions(-) (limited to 'tests/DeferredCanvasTest.cpp') 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 aur(surface); - SkAutoTUnref canvas(SkDeferredCanvas::Create(surface)); - - SkImage* image1 = canvas->newImageSnapshot(); - SkAutoTUnref 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 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 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 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 aur(surface); + SkAutoTUnref canvas(SkDeferredCanvas::Create(surface)); + + SkImage* image1 = canvas->newImageSnapshot(); + SkAutoTUnref 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 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 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 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 aur1(surface); - SkAutoTUnref aur2(alternateSurface); - PixelPtr pixels1 = get_surface_ptr(surface, useGpu); - PixelPtr pixels2 = get_surface_ptr(alternateSurface, useGpu); - SkAutoTUnref canvas(SkDeferredCanvas::Create(surface)); - SkAutoTUnref image1(canvas->newImageSnapshot()); - canvas->setSurface(alternateSurface); - SkAutoTUnref 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 aur1(surface); + SkAutoTUnref aur2(alternateSurface); + PixelPtr pixels1 = get_surface_ptr(surface, useGpu); + PixelPtr pixels2 = get_surface_ptr(alternateSurface, useGpu); + SkAutoTUnref canvas(SkDeferredCanvas::Create(surface)); + SkAutoTUnref image1(canvas->newImageSnapshot()); + canvas->setSurface(alternateSurface); + SkAutoTUnref 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) { -- cgit v1.2.3