| Index: tests/ApplyGammaTest.cpp
|
| diff --git a/tests/ApplyGammaTest.cpp b/tests/ApplyGammaTest.cpp
|
| index 5872422f418497d4c739b069e02c822a729d6c4b..242c96d0dba44100b8f872013063b7035f3bf4be 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<uint32_t> srcPixels(kW * kH);
|
| for (int i = 0; i < kW * kH; ++i) {
|
| srcPixels.get()[i] = i;
|
| }
|
|
|
| - SkAutoTMalloc<uint32_t> dstPixels(kW * kH);
|
| - for (int i = 0; i < kW * kH; ++i) {
|
| - dstPixels.get()[i] = ~i;
|
| - }
|
| + SkPixmap pm(ii, srcPixels.get(), kRowBytes);
|
|
|
| SkAutoTMalloc<uint32_t> 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<GrTexture> src(
|
| - context->textureProvider()->createTexture(srcDesc, SkBudgeted::kNo,
|
| - srcPixels.get(),
|
| - kRowBytes));
|
| - SkAutoTUnref<GrTexture> 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<SkImage> src(SkImage::MakeTextureFromPixmap(context, pm, SkBudgeted::kNo));
|
|
|
| - bool result = context->applyGamma(dst->asRenderTarget(), src, gamma);
|
| + sk_sp<SkSurface> 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;
|
| }
|
| }
|
| }
|
|
|