aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ApplyGammaTest.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-07-28 15:17:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-28 15:17:34 -0700
commitecf3dbe8f2987a08b21be1aff61b7fbfbb69640a (patch)
tree99358f3174597d234b1fdba3528dfdc513a09101 /tests/ApplyGammaTest.cpp
parent99fb670977b5566e901cb4b95531a000ed0ec8a9 (diff)
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
Diffstat (limited to 'tests/ApplyGammaTest.cpp')
-rw-r--r--tests/ApplyGammaTest.cpp108
1 files changed, 54 insertions, 54 deletions
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<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;
}
}
}