Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: tests/ApplyGammaTest.cpp

Issue 2178353005: Remove use of MakeRenderTargetDirect from view system (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix Mac Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/views/mac/SkNSView.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <initializer_list> 8 #include <initializer_list>
9 #include "Test.h" 9 #include "Test.h"
10 10
11 #if SK_SUPPORT_GPU 11 #if SK_SUPPORT_GPU
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrDrawContext.h"
13 #include "GrTexture.h" 14 #include "GrTexture.h"
14 #include "GrTextureProvider.h" 15 #include "GrTextureProvider.h"
15 16
17 #include "SkCanvas.h"
18 #include "SkPixmap.h"
19 #include "SkSurface.h"
16 #include "SkUtils.h" 20 #include "SkUtils.h"
17 21
18 // using anonymous namespace because these functions are used as template param s. 22 // using anonymous namespace because these functions are used as template param s.
19 namespace { 23 namespace {
20 /** convert 0..1 linear value to 0..1 srgb */ 24 /** convert 0..1 linear value to 0..1 srgb */
21 float linear_to_srgb(float linear) { 25 float linear_to_srgb(float linear) {
22 if (linear <= 0.0031308) { 26 if (linear <= 0.0031308) {
23 return linear * 12.92f; 27 return linear * 12.92f;
24 } else { 28 } else {
25 return 1.055f * powf(linear, 1.f / 2.4f) - 0.055f; 29 return 1.055f * powf(linear, 1.f / 2.4f) - 0.055f;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 GrContext* context = ctxInfo.grContext(); 75 GrContext* context = ctxInfo.grContext();
72 static const int kW = 10; 76 static const int kW = 10;
73 static const int kH = 10; 77 static const int kH = 10;
74 static const size_t kRowBytes = sizeof(uint32_t) * kW; 78 static const size_t kRowBytes = sizeof(uint32_t) * kW;
75 79
76 GrSurfaceDesc baseDesc; 80 GrSurfaceDesc baseDesc;
77 baseDesc.fConfig = kRGBA_8888_GrPixelConfig; 81 baseDesc.fConfig = kRGBA_8888_GrPixelConfig;
78 baseDesc.fWidth = kW; 82 baseDesc.fWidth = kW;
79 baseDesc.fHeight = kH; 83 baseDesc.fHeight = kH;
80 84
85 const SkImageInfo ii = SkImageInfo::MakeN32Premul(kW, kH);
86
81 SkAutoTMalloc<uint32_t> srcPixels(kW * kH); 87 SkAutoTMalloc<uint32_t> srcPixels(kW * kH);
82 for (int i = 0; i < kW * kH; ++i) { 88 for (int i = 0; i < kW * kH; ++i) {
83 srcPixels.get()[i] = i; 89 srcPixels.get()[i] = i;
84 } 90 }
85 91
86 SkAutoTMalloc<uint32_t> dstPixels(kW * kH); 92 SkPixmap pm(ii, srcPixels.get(), kRowBytes);
87 for (int i = 0; i < kW * kH; ++i) {
88 dstPixels.get()[i] = ~i;
89 }
90 93
91 SkAutoTMalloc<uint32_t> read(kW * kH); 94 SkAutoTMalloc<uint32_t> read(kW * kH);
92 95
93 // We allow more error on GPUs with lower precision shader variables. 96 // We allow more error on GPUs with lower precision shader variables.
94 float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f; 97 float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f;
95 98
96 for (auto sOrigin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { 99 for (auto dOrigin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
97 for (auto dOrigin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOri gin }) { 100 for (auto gamma : { 1.0f, 1.0f / 1.8f, 1.0f / 2.2f }) {
98 for (auto sFlags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFla gs }) { 101 sk_sp<SkImage> src(SkImage::MakeTextureFromPixmap(context, pm, SkBud geted::kNo));
99 for (auto gamma : { 1.0f, 1.0f / 1.8f, 1.0f / 2.2f }) {
100 GrSurfaceDesc srcDesc = baseDesc;
101 srcDesc.fOrigin = sOrigin;
102 srcDesc.fFlags = sFlags;
103 GrSurfaceDesc dstDesc = baseDesc;
104 dstDesc.fOrigin = dOrigin;
105 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag;
106 102
107 SkAutoTUnref<GrTexture> src( 103 sk_sp<SkSurface> dst(SkSurface::MakeRenderTarget(context, SkBudgeted ::kNo,
108 context->textureProvider()->createTexture(srcDesc, SkBud geted::kNo, 104 ii, 0, dOrigin, nul lptr));
109 srcPixels.get( ),
110 kRowBytes));
111 SkAutoTUnref<GrTexture> dst(
112 context->textureProvider()->createTexture(dstDesc, SkBud geted::kNo,
113 dstPixels.get( ),
114 kRowBytes));
115 if (!src || !dst) {
116 ERRORF(reporter, "Could not create surfaces for copy sur face test.");
117 continue;
118 }
119 105
120 bool result = context->applyGamma(dst->asRenderTarget(), src , gamma); 106 if (!src || !dst) {
107 ERRORF(reporter, "Could not create surfaces for copy surface tes t.");
108 continue;
109 }
121 110
122 // To make the copied src rect correct we would apply any ds t clipping 111 SkCanvas* dstCanvas = dst->getCanvas();
123 // back to the src rect, but we don't use it again so don't bother.
124 if (!result) {
125 ERRORF(reporter, "Unexpected failure from applyGamma.");
126 continue;
127 }
128 112
129 sk_memset32(read.get(), 0, kW * kH); 113 dstCanvas->clear(SK_ColorRED);
130 if (!dst->readPixels(0, 0, kW, kH, baseDesc.fConfig, read.ge t(), kRowBytes)) { 114 dstCanvas->flush();
131 ERRORF(reporter, "Error calling readPixels");
132 continue;
133 }
134 115
135 bool abort = false; 116 // Temporary code until applyGamma is replaced
136 // Validate that pixels were copied/transformed correctly. 117 GrDrawContext* dc = dstCanvas->internal_private_accessTopLayerDrawCo ntext();
137 for (int y = 0; y < kH && !abort; ++y) { 118 GrRenderTarget* rt = dc->accessRenderTarget();
138 for (int x = 0; x < kW && !abort; ++x) { 119 GrTexture* texture = src->getTexture();
139 uint32_t r = read.get()[y * kW + x]; 120 SkASSERT(texture);
140 uint32_t s = srcPixels.get()[y * kW + x]; 121
141 uint32_t expected; 122 bool result = context->applyGamma(rt, texture, gamma);
142 if (!check_gamma(s, r, gamma, error, &expected)) { 123
143 ERRORF(reporter, "Expected dst %d,%d to contain 0x%08x " 124 // To make the copied src rect correct we would apply any dst clippi ng
144 "from src 0x%08x and gamma %f. Got %08x", 125 // back to the src rect, but we don't use it again so don't bother.
145 x, y, expected, s, gamma, r); 126 if (!result) {
146 abort = true; 127 ERRORF(reporter, "Unexpected failure from applyGamma.");
147 break; 128 continue;
148 } 129 }
149 } 130
131 sk_memset32(read.get(), 0, kW * kH);
132 if (!dstCanvas->readPixels(ii, read.get(), kRowBytes, 0, 0)) {
133 ERRORF(reporter, "Error calling readPixels");
134 continue;
135 }
136
137 bool abort = false;
138 // Validate that pixels were copied/transformed correctly.
139 for (int y = 0; y < kH && !abort; ++y) {
140 for (int x = 0; x < kW && !abort; ++x) {
141 uint32_t r = read.get()[y * kW + x];
142 uint32_t s = srcPixels.get()[y * kW + x];
143 uint32_t expected;
144 if (!check_gamma(s, r, gamma, error, &expected)) {
145 ERRORF(reporter, "Expected dst %d,%d to contain 0x%08x "
146 "from src 0x%08x and gamma %f. Got %08x",
147 x, y, expected, s, gamma, r);
148 abort = true;
149 break;
150 } 150 }
151 } 151 }
152 } 152 }
153 } 153 }
154 } 154 }
155 } 155 }
156 #endif 156 #endif
OLDNEW
« no previous file with comments | « src/views/mac/SkNSView.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698