From ecf3dbe8f2987a08b21be1aff61b7fbfbb69640a Mon Sep 17 00:00:00 2001 From: robertphillips Date: Thu, 28 Jul 2016 15:17:34 -0700 Subject: Remove use of MakeRenderTargetDirect from view system Here is the CL that sent me down the SkGammaColorFilter path GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2178353005 Review-Url: https://codereview.chromium.org/2178353005 --- tests/ApplyGammaTest.cpp | 108 +++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 54 deletions(-) (limited to 'tests/ApplyGammaTest.cpp') diff --git a/tests/ApplyGammaTest.cpp b/tests/ApplyGammaTest.cpp index 5872422f41..8db8fe09f6 100644 --- a/tests/ApplyGammaTest.cpp +++ b/tests/ApplyGammaTest.cpp @@ -10,9 +10,13 @@ #if SK_SUPPORT_GPU #include "GrContext.h" +#include "GrDrawContext.h" #include "GrTexture.h" #include "GrTextureProvider.h" +#include "SkCanvas.h" +#include "SkPixmap.h" +#include "SkSurface.h" #include "SkUtils.h" // using anonymous namespace because these functions are used as template params. @@ -78,75 +82,71 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ApplyGamma, reporter, ctxInfo) { baseDesc.fWidth = kW; baseDesc.fHeight = kH; + const SkImageInfo ii = SkImageInfo::MakeN32Premul(kW, kH); + SkAutoTMalloc srcPixels(kW * kH); for (int i = 0; i < kW * kH; ++i) { srcPixels.get()[i] = i; } - SkAutoTMalloc dstPixels(kW * kH); - for (int i = 0; i < kW * kH; ++i) { - dstPixels.get()[i] = ~i; - } + SkPixmap pm(ii, srcPixels.get(), kRowBytes); SkAutoTMalloc read(kW * kH); // We allow more error on GPUs with lower precision shader variables. float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f; - for (auto sOrigin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { - for (auto dOrigin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { - for (auto sFlags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) { - for (auto gamma : { 1.0f, 1.0f / 1.8f, 1.0f / 2.2f }) { - GrSurfaceDesc srcDesc = baseDesc; - srcDesc.fOrigin = sOrigin; - srcDesc.fFlags = sFlags; - GrSurfaceDesc dstDesc = baseDesc; - dstDesc.fOrigin = dOrigin; - dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; - - SkAutoTUnref src( - context->textureProvider()->createTexture(srcDesc, SkBudgeted::kNo, - srcPixels.get(), - kRowBytes)); - SkAutoTUnref dst( - context->textureProvider()->createTexture(dstDesc, SkBudgeted::kNo, - dstPixels.get(), - kRowBytes)); - if (!src || !dst) { - ERRORF(reporter, "Could not create surfaces for copy surface test."); - continue; - } + for (auto dOrigin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { + for (auto gamma : { 1.0f, 1.0f / 1.8f, 1.0f / 2.2f }) { + sk_sp src(SkImage::MakeTextureFromPixmap(context, pm, SkBudgeted::kNo)); - bool result = context->applyGamma(dst->asRenderTarget(), src, gamma); + sk_sp dst(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, + ii, 0, dOrigin, nullptr)); - // To make the copied src rect correct we would apply any dst clipping - // back to the src rect, but we don't use it again so don't bother. - if (!result) { - ERRORF(reporter, "Unexpected failure from applyGamma."); - continue; - } + if (!src || !dst) { + ERRORF(reporter, "Could not create surfaces for copy surface test."); + continue; + } - sk_memset32(read.get(), 0, kW * kH); - if (!dst->readPixels(0, 0, kW, kH, baseDesc.fConfig, read.get(), kRowBytes)) { - ERRORF(reporter, "Error calling readPixels"); - continue; - } + SkCanvas* dstCanvas = dst->getCanvas(); + + dstCanvas->clear(SK_ColorRED); + dstCanvas->flush(); + + // Temporary code until applyGamma is replaced + GrDrawContext* dc = dstCanvas->internal_private_accessTopLayerDrawContext(); + GrRenderTarget* rt = dc->accessRenderTarget(); + GrTexture* texture = src->getTexture(); + SkASSERT(texture); + + bool result = context->applyGamma(rt, texture, gamma); + + // To make the copied src rect correct we would apply any dst clipping + // back to the src rect, but we don't use it again so don't bother. + if (!result) { + ERRORF(reporter, "Unexpected failure from applyGamma."); + continue; + } + + sk_memset32(read.get(), 0, kW * kH); + if (!dstCanvas->readPixels(ii, read.get(), kRowBytes, 0, 0)) { + ERRORF(reporter, "Error calling readPixels"); + continue; + } - bool abort = false; - // Validate that pixels were copied/transformed correctly. - for (int y = 0; y < kH && !abort; ++y) { - for (int x = 0; x < kW && !abort; ++x) { - uint32_t r = read.get()[y * kW + x]; - uint32_t s = srcPixels.get()[y * kW + x]; - uint32_t expected; - if (!check_gamma(s, r, gamma, error, &expected)) { - ERRORF(reporter, "Expected dst %d,%d to contain 0x%08x " - "from src 0x%08x and gamma %f. Got %08x", - x, y, expected, s, gamma, r); - abort = true; - break; - } - } + bool abort = false; + // Validate that pixels were copied/transformed correctly. + for (int y = 0; y < kH && !abort; ++y) { + for (int x = 0; x < kW && !abort; ++x) { + uint32_t r = read.get()[y * kW + x]; + uint32_t s = srcPixels.get()[y * kW + x]; + uint32_t expected; + if (!check_gamma(s, r, gamma, error, &expected)) { + ERRORF(reporter, "Expected dst %d,%d to contain 0x%08x " + "from src 0x%08x and gamma %f. Got %08x", + x, y, expected, s, gamma, r); + abort = true; + break; } } } -- cgit v1.2.3