blob: 2ed22db32158af34ada30477d58f7a89a61f5c1a [file] [log] [blame]
sugoi24dcac22014-07-07 15:09:48 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// This test only works with the GPU backend.
9
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "gm/gm.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkBitmap.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040012#include "include/core/SkBlendMode.h"
13#include "include/core/SkColor.h"
14#include "include/core/SkImage.h"
15#include "include/core/SkImageInfo.h"
16#include "include/core/SkMatrix.h"
17#include "include/core/SkRect.h"
18#include "include/core/SkRefCnt.h"
19#include "include/core/SkScalar.h"
20#include "include/core/SkSize.h"
21#include "include/core/SkString.h"
22#include "include/core/SkTypes.h"
23#include "include/core/SkYUVAIndex.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "include/gpu/GrContext.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040025#include "include/private/GrTypesPriv.h"
Greg Daniel6f5441a2020-01-28 17:02:49 -050026#include "src/gpu/GrBitmapTextureMaker.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/GrClip.h"
28#include "src/gpu/GrContextPriv.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040029#include "src/gpu/GrFragmentProcessor.h"
30#include "src/gpu/GrPaint.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040031#include "src/gpu/GrRenderTargetContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050032#include "src/gpu/GrRenderTargetContextPriv.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040033#include "src/gpu/GrSamplerState.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040034#include "src/gpu/GrTextureProxy.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040035#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050036#include "src/gpu/effects/GrYUVtoRGBEffect.h"
37#include "src/gpu/ops/GrDrawOp.h"
38#include "src/gpu/ops/GrFillRectOp.h"
sugoi24dcac22014-07-07 15:09:48 -070039
Ben Wagner7fde8e12019-05-01 17:28:53 -040040#include <memory>
41#include <utility>
42
43class SkCanvas;
44
sugoi4ccce7e2015-02-13 13:57:09 -080045#define YSIZE 8
46#define USIZE 4
47#define VSIZE 4
48
sugoi24dcac22014-07-07 15:09:48 -070049namespace skiagm {
50/**
51 * This GM directly exercises GrYUVtoRGBEffect.
52 */
Chris Dalton3a778372019-02-07 15:23:36 -070053class YUVtoRGBEffect : public GpuGM {
sugoi24dcac22014-07-07 15:09:48 -070054public:
55 YUVtoRGBEffect() {
56 this->setBGColor(0xFFFFFFFF);
57 }
58
59protected:
mtklein36352bf2015-03-25 18:17:31 -070060 SkString onShortName() override {
sugoi24dcac22014-07-07 15:09:48 -070061 return SkString("yuv_to_rgb_effect");
62 }
63
mtklein36352bf2015-03-25 18:17:31 -070064 SkISize onISize() override {
Robert Phillips0a22ba82019-03-06 12:36:47 -050065 int numRows = kLastEnum_SkYUVColorSpace + 1;
66 return SkISize::Make(238, kDrawPad + numRows * kColorSpaceOffset);
sugoi24dcac22014-07-07 15:09:48 -070067 }
68
mtklein36352bf2015-03-25 18:17:31 -070069 void onOnceBeforeDraw() override {
sugoi4ccce7e2015-02-13 13:57:09 -080070 SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
Greg Daniel6f5441a2020-01-28 17:02:49 -050071 fBitmaps[0].allocPixels(yinfo);
sugoi4ccce7e2015-02-13 13:57:09 -080072 SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE);
Greg Daniel6f5441a2020-01-28 17:02:49 -050073 fBitmaps[1].allocPixels(uinfo);
sugoi4ccce7e2015-02-13 13:57:09 -080074 SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE);
Greg Daniel6f5441a2020-01-28 17:02:49 -050075 fBitmaps[2].allocPixels(vinfo);
sugoi24dcac22014-07-07 15:09:48 -070076 unsigned char* pixels[3];
77 for (int i = 0; i < 3; ++i) {
Greg Daniel6f5441a2020-01-28 17:02:49 -050078 pixels[i] = (unsigned char*)fBitmaps[i].getPixels();
sugoi24dcac22014-07-07 15:09:48 -070079 }
80 int color[] = {0, 85, 170};
81 const int limit[] = {255, 0, 255};
82 const int invl[] = {0, 255, 0};
83 const int inc[] = {1, -1, 1};
sugoi4ccce7e2015-02-13 13:57:09 -080084 for (int i = 0; i < 3; ++i) {
Greg Daniel6f5441a2020-01-28 17:02:49 -050085 const size_t nbBytes = fBitmaps[i].rowBytes() * fBitmaps[i].height();
sugoi4ccce7e2015-02-13 13:57:09 -080086 for (size_t j = 0; j < nbBytes; ++j) {
sugoi24dcac22014-07-07 15:09:48 -070087 pixels[i][j] = (unsigned char)color[i];
88 color[i] = (color[i] == limit[i]) ? invl[i] : color[i] + inc[i];
89 }
90 }
Brian Osman2700abc2018-09-12 10:19:41 -040091 for (int i = 0; i < 3; ++i) {
Greg Daniel6f5441a2020-01-28 17:02:49 -050092 fBitmaps[i].setImmutable();
Brian Osman2700abc2018-09-12 10:19:41 -040093 }
sugoi24dcac22014-07-07 15:09:48 -070094 }
95
Chris Dalton50e24d72019-02-07 16:20:09 -070096 DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
97 SkCanvas* canvas, SkString* errorMsg) override {
Greg Danielc7672092020-02-06 14:32:54 -050098 GrSurfaceProxyView views[3];
bsalomonbcf0a522014-10-08 08:40:09 -070099
Brian Salomon2a4f9832018-03-03 22:43:43 -0500100 for (int i = 0; i < 3; ++i) {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500101 GrBitmapTextureMaker maker(context, fBitmaps[i]);
Greg Danielc7672092020-02-06 14:32:54 -0500102 std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
103 if (!views[i]) {
Chris Dalton50e24d72019-02-07 16:20:09 -0700104 *errorMsg = "Failed to create proxy";
105 return DrawResult::kFail;
Robert Phillipsbc7a4fb2017-01-23 15:30:35 -0500106 }
sugoi24dcac22014-07-07 15:09:48 -0700107 }
108
Robert Phillipsbc7a4fb2017-01-23 15:30:35 -0500109 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500110 SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBitmaps[0].width()),
111 SkIntToScalar(fBitmaps[0].height()));
bsalomonbcf0a522014-10-08 08:40:09 -0700112 renderRect.outset(kDrawPad, kDrawPad);
sugoi24dcac22014-07-07 15:09:48 -0700113
bsalomonbcf0a522014-10-08 08:40:09 -0700114 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset;
115 SkScalar x = kDrawPad + kTestPad;
sugoi24dcac22014-07-07 15:09:48 -0700116
bsalomonbcf0a522014-10-08 08:40:09 -0700117 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
118 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
sugoi24dcac22014-07-07 15:09:48 -0700119
bsalomonbcf0a522014-10-08 08:40:09 -0700120 for (int i = 0; i < 6; ++i) {
Robert Phillips94ade752018-10-09 12:32:31 -0400121 SkYUVAIndex yuvaIndices[4] = {
Robert Phillips6ba8c832018-10-10 11:43:01 -0400122 { indices[i][0], SkColorChannel::kR },
123 { indices[i][1], SkColorChannel::kR },
124 { indices[i][2], SkColorChannel::kR },
Robert Phillips94ade752018-10-09 12:32:31 -0400125 { -1, SkColorChannel::kA }
126 };
Brian Salomonca6b2f42020-01-24 11:31:21 -0500127 const auto& caps = *context->priv().caps();
128 std::unique_ptr<GrFragmentProcessor> fp(GrYUVtoRGBEffect::Make(
Greg Danielc7672092020-02-06 14:32:54 -0500129 views, yuvaIndices, static_cast<SkYUVColorSpace>(space),
Brian Salomonca6b2f42020-01-24 11:31:21 -0500130 GrSamplerState::Filter::kNearest, caps));
bsalomonbcf0a522014-10-08 08:40:09 -0700131 if (fp) {
Brian Salomon82f44312017-01-11 13:42:54 -0500132 GrPaint grPaint;
133 grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
134 grPaint.addColorFragmentProcessor(std::move(fp));
bsalomonbcf0a522014-10-08 08:40:09 -0700135 SkMatrix viewMatrix;
136 viewMatrix.setTranslate(x, y);
Brian Salomonac70f842017-05-08 10:43:33 -0400137 renderTargetContext->priv().testingOnly_addDrawOp(
Michael Ludwigaa1b6b32019-05-29 14:43:13 -0400138 GrFillRectOp::MakeNonAARect(context, std::move(grPaint),
139 viewMatrix, renderRect));
bsalomonbcf0a522014-10-08 08:40:09 -0700140 }
141 x += renderRect.width() + kTestPad;
142 }
sugoi24dcac22014-07-07 15:09:48 -0700143 }
Chris Dalton50e24d72019-02-07 16:20:09 -0700144 return DrawResult::kOk;
bsalomonbcf0a522014-10-08 08:40:09 -0700145 }
sugoi24dcac22014-07-07 15:09:48 -0700146
147private:
Greg Daniel6f5441a2020-01-28 17:02:49 -0500148 SkBitmap fBitmaps[3];
sugoi24dcac22014-07-07 15:09:48 -0700149
Robert Phillips0a22ba82019-03-06 12:36:47 -0500150 static constexpr SkScalar kDrawPad = 10.f;
151 static constexpr SkScalar kTestPad = 10.f;
152 static constexpr SkScalar kColorSpaceOffset = 36.f;
153
sugoi24dcac22014-07-07 15:09:48 -0700154 typedef GM INHERITED;
155};
156
halcanary385fe4d2015-08-26 13:07:48 -0700157DEF_GM(return new YUVtoRGBEffect;)
jbaumanb445a572016-06-09 13:24:48 -0700158
159//////////////////////////////////////////////////////////////////////////////
160
Chris Dalton3a778372019-02-07 15:23:36 -0700161class YUVNV12toRGBEffect : public GpuGM {
jbaumanb445a572016-06-09 13:24:48 -0700162public:
163 YUVNV12toRGBEffect() {
164 this->setBGColor(0xFFFFFFFF);
165 }
166
167protected:
168 SkString onShortName() override {
169 return SkString("yuv_nv12_to_rgb_effect");
170 }
171
172 SkISize onISize() override {
Robert Phillips0a22ba82019-03-06 12:36:47 -0500173 int numRows = kLastEnum_SkYUVColorSpace + 1;
174 return SkISize::Make(48, kDrawPad + numRows * kColorSpaceOffset);
jbaumanb445a572016-06-09 13:24:48 -0700175 }
176
177 void onOnceBeforeDraw() override {
178 SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
Greg Daniel6f5441a2020-01-28 17:02:49 -0500179 fBitmaps[0].allocPixels(yinfo);
jbaumanb445a572016-06-09 13:24:48 -0700180 SkImageInfo uvinfo = SkImageInfo::MakeN32Premul(USIZE, USIZE);
Greg Daniel6f5441a2020-01-28 17:02:49 -0500181 fBitmaps[1].allocPixels(uvinfo);
jbaumanb445a572016-06-09 13:24:48 -0700182 int color[] = {0, 85, 170};
183 const int limit[] = {255, 0, 255};
184 const int invl[] = {0, 255, 0};
185 const int inc[] = {1, -1, 1};
186
187 {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500188 unsigned char* pixels = (unsigned char*)fBitmaps[0].getPixels();
189 const size_t nbBytes = fBitmaps[0].rowBytes() * fBitmaps[0].height();
jbaumanb445a572016-06-09 13:24:48 -0700190 for (size_t j = 0; j < nbBytes; ++j) {
191 pixels[j] = (unsigned char)color[0];
192 color[0] = (color[0] == limit[0]) ? invl[0] : color[0] + inc[0];
193 }
194 }
195
196 {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500197 for (int y = 0; y < fBitmaps[1].height(); ++y) {
198 uint32_t* pixels = fBitmaps[1].getAddr32(0, y);
199 for (int j = 0; j < fBitmaps[1].width(); ++j) {
jbaumanb445a572016-06-09 13:24:48 -0700200 pixels[j] = SkColorSetARGB(0, color[1], color[2], 0);
201 color[1] = (color[1] == limit[1]) ? invl[1] : color[1] + inc[1];
202 color[2] = (color[2] == limit[2]) ? invl[2] : color[2] + inc[2];
203 }
204 }
205 }
Brian Osman2700abc2018-09-12 10:19:41 -0400206
207 for (int i = 0; i < 2; ++i) {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500208 fBitmaps[i].setImmutable();
Brian Osman2700abc2018-09-12 10:19:41 -0400209 }
jbaumanb445a572016-06-09 13:24:48 -0700210 }
211
Chris Dalton50e24d72019-02-07 16:20:09 -0700212 DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
213 SkCanvas* canvas, SkString* errorMsg) override {
Greg Danielc7672092020-02-06 14:32:54 -0500214 GrSurfaceProxyView views[2];
jbaumanb445a572016-06-09 13:24:48 -0700215
Robert Phillips94ade752018-10-09 12:32:31 -0400216 for (int i = 0; i < 2; ++i) {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500217 GrBitmapTextureMaker maker(context, fBitmaps[i]);
Greg Danielc7672092020-02-06 14:32:54 -0500218 std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
219 if (!views[i]) {
Chris Dalton50e24d72019-02-07 16:20:09 -0700220 *errorMsg = "Failed to create proxy";
221 return DrawResult::kFail;
Robert Phillipsbc7a4fb2017-01-23 15:30:35 -0500222 }
jbaumanb445a572016-06-09 13:24:48 -0700223 }
224
Robert Phillips94ade752018-10-09 12:32:31 -0400225 SkYUVAIndex yuvaIndices[4] = {
Robert Phillips6ba8c832018-10-10 11:43:01 -0400226 { 0, SkColorChannel::kR },
Robert Phillips94ade752018-10-09 12:32:31 -0400227 { 1, SkColorChannel::kR },
228 { 1, SkColorChannel::kG },
229 { -1, SkColorChannel::kA }
230 };
231
jbaumanb445a572016-06-09 13:24:48 -0700232 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500233 SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBitmaps[0].width()),
234 SkIntToScalar(fBitmaps[0].height()));
jbaumanb445a572016-06-09 13:24:48 -0700235 renderRect.outset(kDrawPad, kDrawPad);
236
237 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset;
238 SkScalar x = kDrawPad + kTestPad;
239
robertphillips28a838e2016-06-23 14:07:00 -0700240 GrPaint grPaint;
Brian Salomona1633922017-01-09 11:46:10 -0500241 grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
Brian Salomonca6b2f42020-01-24 11:31:21 -0500242 const auto& caps = *context->priv().caps();
Greg Danielc7672092020-02-06 14:32:54 -0500243 auto fp = GrYUVtoRGBEffect::Make(views, yuvaIndices,
Jim Van Verth30e0d7f2018-11-02 13:36:42 -0400244 static_cast<SkYUVColorSpace>(space),
Brian Salomonca6b2f42020-01-24 11:31:21 -0500245 GrSamplerState::Filter::kNearest, caps);
jbaumanb445a572016-06-09 13:24:48 -0700246 if (fp) {
247 SkMatrix viewMatrix;
248 viewMatrix.setTranslate(x, y);
Brian Salomonaff329b2017-08-11 09:40:37 -0400249 grPaint.addColorFragmentProcessor(std::move(fp));
Michael Ludwigaa1b6b32019-05-29 14:43:13 -0400250 std::unique_ptr<GrDrawOp> op(GrFillRectOp::MakeNonAARect(
251 context, std::move(grPaint), viewMatrix, renderRect));
Robert Phillips09dfc472017-09-13 15:25:47 -0400252 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
jbaumanb445a572016-06-09 13:24:48 -0700253 }
254 }
Chris Dalton50e24d72019-02-07 16:20:09 -0700255 return DrawResult::kOk;
jbaumanb445a572016-06-09 13:24:48 -0700256 }
257
258private:
Greg Daniel6f5441a2020-01-28 17:02:49 -0500259 SkBitmap fBitmaps[2];
jbaumanb445a572016-06-09 13:24:48 -0700260
Robert Phillips0a22ba82019-03-06 12:36:47 -0500261 static constexpr SkScalar kDrawPad = 10.f;
262 static constexpr SkScalar kTestPad = 10.f;
263 static constexpr SkScalar kColorSpaceOffset = 36.f;
264
jbaumanb445a572016-06-09 13:24:48 -0700265 typedef GM INHERITED;
266};
267
268DEF_GM(return new YUVNV12toRGBEffect;)
Michael Ludwiga6a84002019-04-12 15:03:02 -0400269
270//////////////////////////////////////////////////////////////////////////////
271
272// This GM tests domain clamping on YUV multiplanar images where the U and V
273// planes have different resolution from Y. See skbug:8959
274
275class YUVtoRGBDomainEffect : public GpuGM {
276public:
277 YUVtoRGBDomainEffect() {
278 this->setBGColor(0xFFFFFFFF);
279 }
280
281protected:
282 SkString onShortName() override {
283 return SkString("yuv_to_rgb_domain_effect");
284 }
285
286 SkISize onISize() override {
287 return SkISize::Make((YSIZE + kTestPad) * 3 + kDrawPad, (YSIZE + kTestPad) * 2 + kDrawPad);
288 }
289
290 void onOnceBeforeDraw() override {
Michael Ludwiga6a84002019-04-12 15:03:02 -0400291 SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
Greg Daniel6f5441a2020-01-28 17:02:49 -0500292 fBitmaps[0].allocPixels(yinfo);
Michael Ludwiga6a84002019-04-12 15:03:02 -0400293 SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE);
Greg Daniel6f5441a2020-01-28 17:02:49 -0500294 fBitmaps[1].allocPixels(uinfo);
Michael Ludwiga6a84002019-04-12 15:03:02 -0400295 SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE);
Greg Daniel6f5441a2020-01-28 17:02:49 -0500296 fBitmaps[2].allocPixels(vinfo);
Michael Ludwiga6a84002019-04-12 15:03:02 -0400297
298 int innerColor[] = {149, 43, 21};
299 int outerColor[] = {128, 128, 128};
300 for (int i = 0; i < 3; ++i) {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500301 fBitmaps[i].eraseColor(SkColorSetARGB(outerColor[i], 0, 0, 0));
Michael Ludwiga6a84002019-04-12 15:03:02 -0400302 SkIRect innerRect = i == 0 ? SkIRect::MakeLTRB(2, 2, 6, 6) : SkIRect::MakeLTRB(1, 1, 3, 3);
Greg Daniel6f5441a2020-01-28 17:02:49 -0500303 fBitmaps[i].erase(SkColorSetARGB(innerColor[i], 0, 0, 0), innerRect);
304 fBitmaps[i].setImmutable();
Michael Ludwiga6a84002019-04-12 15:03:02 -0400305 }
306 }
307
308 DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
309 SkCanvas* canvas, SkString* errorMsg) override {
Greg Danielc7672092020-02-06 14:32:54 -0500310 GrSurfaceProxyView views[3];
Michael Ludwiga6a84002019-04-12 15:03:02 -0400311
312 for (int i = 0; i < 3; ++i) {
Greg Daniel6f5441a2020-01-28 17:02:49 -0500313 GrBitmapTextureMaker maker(context, fBitmaps[i]);
Greg Danielc7672092020-02-06 14:32:54 -0500314 std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
315 if (!views[i]) {
Michael Ludwiga6a84002019-04-12 15:03:02 -0400316 *errorMsg = "Failed to create proxy";
317 return DrawResult::kFail;
318 }
319 }
320
321 // Draw a 2x2 grid of the YUV images.
322 // Rows = kNearest, kBilerp, Cols = No clamp, clamp
323 static const GrSamplerState::Filter kFilters[] = {
324 GrSamplerState::Filter::kNearest, GrSamplerState::Filter::kBilerp };
325 static const SkRect kGreenRect = SkRect::MakeLTRB(2.f, 2.f, 6.f, 6.f);
326
327 SkYUVAIndex yuvaIndices[4] = {
328 { SkYUVAIndex::kY_Index, SkColorChannel::kR },
329 { SkYUVAIndex::kU_Index, SkColorChannel::kR },
330 { SkYUVAIndex::kV_Index, SkColorChannel::kR },
331 { -1, SkColorChannel::kA }
332 };
333 SkRect rect = SkRect::MakeWH(YSIZE, YSIZE);
334
335 SkScalar y = kDrawPad + kTestPad;
336 for (uint32_t i = 0; i < SK_ARRAY_COUNT(kFilters); ++i) {
337 SkScalar x = kDrawPad + kTestPad;
338
339 for (uint32_t j = 0; j < 2; ++j) {
340 SkMatrix ctm = SkMatrix::MakeTrans(x, y);
341 ctm.postScale(10.f, 10.f);
342
343 SkRect domain = kGreenRect;
344 if (kFilters[i] == GrSamplerState::Filter::kNearest) {
345 // Make a very small inset for nearest-neighbor filtering so that 0.5px
346 // centers don't round out beyond the green pixels.
347 domain.inset(0.01f, 0.01f);
348 }
349
350 const SkRect* domainPtr = j > 0 ? &domain : nullptr;
Brian Salomonca6b2f42020-01-24 11:31:21 -0500351 const auto& caps = *context->priv().caps();
352 std::unique_ptr<GrFragmentProcessor> fp(
Greg Danielc7672092020-02-06 14:32:54 -0500353 GrYUVtoRGBEffect::Make(views, yuvaIndices, kJPEG_SkYUVColorSpace,
Brian Salomonca6b2f42020-01-24 11:31:21 -0500354 kFilters[i], caps, SkMatrix::I(), domainPtr));
Michael Ludwiga6a84002019-04-12 15:03:02 -0400355 if (fp) {
356 GrPaint grPaint;
357 grPaint.addColorFragmentProcessor(std::move(fp));
358 renderTargetContext->drawRect(
359 GrNoClip(), std::move(grPaint), GrAA::kYes, ctm, rect);
360 }
361 x += rect.width() + kTestPad;
362 }
363
364 y += rect.height() + kTestPad;
365 }
366
367 return DrawResult::kOk;
368 }
369
370private:
Greg Daniel6f5441a2020-01-28 17:02:49 -0500371 SkBitmap fBitmaps[3];
Michael Ludwiga6a84002019-04-12 15:03:02 -0400372
373 static constexpr SkScalar kDrawPad = 10.f;
374 static constexpr SkScalar kTestPad = 10.f;
375
376 typedef GM INHERITED;
377};
378
379DEF_GM(return new YUVtoRGBDomainEffect;)
sugoi24dcac22014-07-07 15:09:48 -0700380}