2014-07-07 22:09:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This test only works with the GPU backend.
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/core/SkYUVAIndex.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/gpu/GrSamplerState.h"
|
|
|
|
#include "include/private/GrTypesPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrClip.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrFragmentProcessor.h"
|
|
|
|
#include "src/gpu/GrPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/effects/GrYUVtoRGBEffect.h"
|
|
|
|
#include "src/gpu/ops/GrDrawOp.h"
|
|
|
|
#include "src/gpu/ops/GrFillRectOp.h"
|
2014-07-07 22:09:48 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
|
2015-02-13 21:57:09 +00:00
|
|
|
#define YSIZE 8
|
|
|
|
#define USIZE 4
|
|
|
|
#define VSIZE 4
|
|
|
|
|
2014-07-07 22:09:48 +00:00
|
|
|
namespace skiagm {
|
|
|
|
/**
|
|
|
|
* This GM directly exercises GrYUVtoRGBEffect.
|
|
|
|
*/
|
2019-02-07 22:23:36 +00:00
|
|
|
class YUVtoRGBEffect : public GpuGM {
|
2014-07-07 22:09:48 +00:00
|
|
|
public:
|
|
|
|
YUVtoRGBEffect() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-07-07 22:09:48 +00:00
|
|
|
return SkString("yuv_to_rgb_effect");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2019-03-06 17:36:47 +00:00
|
|
|
int numRows = kLastEnum_SkYUVColorSpace + 1;
|
|
|
|
return SkISize::Make(238, kDrawPad + numRows * kColorSpaceOffset);
|
2014-07-07 22:09:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2018-09-12 14:19:41 +00:00
|
|
|
SkBitmap bmp[3];
|
2015-02-13 21:57:09 +00:00
|
|
|
SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
|
2018-09-12 14:19:41 +00:00
|
|
|
bmp[0].allocPixels(yinfo);
|
2015-02-13 21:57:09 +00:00
|
|
|
SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE);
|
2018-09-12 14:19:41 +00:00
|
|
|
bmp[1].allocPixels(uinfo);
|
2015-02-13 21:57:09 +00:00
|
|
|
SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE);
|
2018-09-12 14:19:41 +00:00
|
|
|
bmp[2].allocPixels(vinfo);
|
2014-07-07 22:09:48 +00:00
|
|
|
unsigned char* pixels[3];
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2018-09-12 14:19:41 +00:00
|
|
|
pixels[i] = (unsigned char*)bmp[i].getPixels();
|
2014-07-07 22:09:48 +00:00
|
|
|
}
|
|
|
|
int color[] = {0, 85, 170};
|
|
|
|
const int limit[] = {255, 0, 255};
|
|
|
|
const int invl[] = {0, 255, 0};
|
|
|
|
const int inc[] = {1, -1, 1};
|
2015-02-13 21:57:09 +00:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
2018-09-12 14:19:41 +00:00
|
|
|
const size_t nbBytes = bmp[i].rowBytes() * bmp[i].height();
|
2015-02-13 21:57:09 +00:00
|
|
|
for (size_t j = 0; j < nbBytes; ++j) {
|
2014-07-07 22:09:48 +00:00
|
|
|
pixels[i][j] = (unsigned char)color[i];
|
|
|
|
color[i] = (color[i] == limit[i]) ? invl[i] : color[i] + inc[i];
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 14:19:41 +00:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
fImage[i] = SkImage::MakeFromBitmap(bmp[i]);
|
|
|
|
}
|
2014-07-07 22:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
|
|
|
|
SkCanvas* canvas, SkString* errorMsg) override {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
2018-10-09 16:32:31 +00:00
|
|
|
sk_sp<GrTextureProxy> proxies[3];
|
2014-10-08 15:40:09 +00:00
|
|
|
|
2018-03-04 03:43:43 +00:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
2019-08-13 20:55:41 +00:00
|
|
|
proxies[i] = proxyProvider->createTextureProxy(fImage[i], 1, SkBudgeted::kYes,
|
|
|
|
SkBackingFit::kExact);
|
2018-10-09 16:32:31 +00:00
|
|
|
if (!proxies[i]) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Failed to create proxy";
|
|
|
|
return DrawResult::kFail;
|
2017-01-23 20:30:35 +00:00
|
|
|
}
|
2014-07-07 22:09:48 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:35 +00:00
|
|
|
for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) {
|
2018-09-12 14:19:41 +00:00
|
|
|
SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fImage[0]->width()),
|
|
|
|
SkIntToScalar(fImage[0]->height()));
|
2014-10-08 15:40:09 +00:00
|
|
|
renderRect.outset(kDrawPad, kDrawPad);
|
|
|
|
|
|
|
|
SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset;
|
|
|
|
SkScalar x = kDrawPad + kTestPad;
|
|
|
|
|
|
|
|
const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
|
|
|
|
{1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
2018-10-09 16:32:31 +00:00
|
|
|
SkYUVAIndex yuvaIndices[4] = {
|
2018-10-10 15:43:01 +00:00
|
|
|
{ indices[i][0], SkColorChannel::kR },
|
|
|
|
{ indices[i][1], SkColorChannel::kR },
|
|
|
|
{ indices[i][2], SkColorChannel::kR },
|
2018-10-09 16:32:31 +00:00
|
|
|
{ -1, SkColorChannel::kA }
|
|
|
|
};
|
|
|
|
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp(
|
2018-10-09 16:32:31 +00:00
|
|
|
GrYUVtoRGBEffect::Make(proxies, yuvaIndices,
|
2018-11-02 17:36:42 +00:00
|
|
|
static_cast<SkYUVColorSpace>(space),
|
|
|
|
GrSamplerState::Filter::kNearest));
|
2014-10-08 15:40:09 +00:00
|
|
|
if (fp) {
|
2017-01-11 18:42:54 +00:00
|
|
|
GrPaint grPaint;
|
|
|
|
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
|
|
|
grPaint.addColorFragmentProcessor(std::move(fp));
|
2014-10-08 15:40:09 +00:00
|
|
|
SkMatrix viewMatrix;
|
|
|
|
viewMatrix.setTranslate(x, y);
|
2017-05-08 14:43:33 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(
|
2019-05-29 18:43:13 +00:00
|
|
|
GrFillRectOp::MakeNonAARect(context, std::move(grPaint),
|
|
|
|
viewMatrix, renderRect));
|
2014-10-08 15:40:09 +00:00
|
|
|
}
|
|
|
|
x += renderRect.width() + kTestPad;
|
|
|
|
}
|
2014-07-07 22:09:48 +00:00
|
|
|
}
|
2019-02-07 23:20:09 +00:00
|
|
|
return DrawResult::kOk;
|
2014-10-08 15:40:09 +00:00
|
|
|
}
|
2014-07-07 22:09:48 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-12 14:19:41 +00:00
|
|
|
sk_sp<SkImage> fImage[3];
|
2014-07-07 22:09:48 +00:00
|
|
|
|
2019-03-06 17:36:47 +00:00
|
|
|
static constexpr SkScalar kDrawPad = 10.f;
|
|
|
|
static constexpr SkScalar kTestPad = 10.f;
|
|
|
|
static constexpr SkScalar kColorSpaceOffset = 36.f;
|
|
|
|
|
2014-07-07 22:09:48 +00:00
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new YUVtoRGBEffect;)
|
2016-06-09 20:24:48 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
class YUVNV12toRGBEffect : public GpuGM {
|
2016-06-09 20:24:48 +00:00
|
|
|
public:
|
|
|
|
YUVNV12toRGBEffect() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("yuv_nv12_to_rgb_effect");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
2019-03-06 17:36:47 +00:00
|
|
|
int numRows = kLastEnum_SkYUVColorSpace + 1;
|
|
|
|
return SkISize::Make(48, kDrawPad + numRows * kColorSpaceOffset);
|
2016-06-09 20:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
2018-09-12 14:19:41 +00:00
|
|
|
SkBitmap bmp[2];
|
2016-06-09 20:24:48 +00:00
|
|
|
SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
|
2018-09-12 14:19:41 +00:00
|
|
|
bmp[0].allocPixels(yinfo);
|
2016-06-09 20:24:48 +00:00
|
|
|
SkImageInfo uvinfo = SkImageInfo::MakeN32Premul(USIZE, USIZE);
|
2018-09-12 14:19:41 +00:00
|
|
|
bmp[1].allocPixels(uvinfo);
|
2016-06-09 20:24:48 +00:00
|
|
|
int color[] = {0, 85, 170};
|
|
|
|
const int limit[] = {255, 0, 255};
|
|
|
|
const int invl[] = {0, 255, 0};
|
|
|
|
const int inc[] = {1, -1, 1};
|
|
|
|
|
|
|
|
{
|
2018-09-12 14:19:41 +00:00
|
|
|
unsigned char* pixels = (unsigned char*)bmp[0].getPixels();
|
|
|
|
const size_t nbBytes = bmp[0].rowBytes() * bmp[0].height();
|
2016-06-09 20:24:48 +00:00
|
|
|
for (size_t j = 0; j < nbBytes; ++j) {
|
|
|
|
pixels[j] = (unsigned char)color[0];
|
|
|
|
color[0] = (color[0] == limit[0]) ? invl[0] : color[0] + inc[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-09-12 14:19:41 +00:00
|
|
|
for (int y = 0; y < bmp[1].height(); ++y) {
|
|
|
|
uint32_t* pixels = bmp[1].getAddr32(0, y);
|
|
|
|
for (int j = 0; j < bmp[1].width(); ++j) {
|
2016-06-09 20:24:48 +00:00
|
|
|
pixels[j] = SkColorSetARGB(0, color[1], color[2], 0);
|
|
|
|
color[1] = (color[1] == limit[1]) ? invl[1] : color[1] + inc[1];
|
|
|
|
color[2] = (color[2] == limit[2]) ? invl[2] : color[2] + inc[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 14:19:41 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
fImage[i] = SkImage::MakeFromBitmap(bmp[i]);
|
|
|
|
}
|
2016-06-09 20:24:48 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
|
|
|
|
SkCanvas* canvas, SkString* errorMsg) override {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
2018-10-09 16:32:31 +00:00
|
|
|
sk_sp<GrTextureProxy> proxies[2];
|
2016-06-09 20:24:48 +00:00
|
|
|
|
2018-10-09 16:32:31 +00:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
2019-08-13 20:55:41 +00:00
|
|
|
proxies[i] = proxyProvider->createTextureProxy(fImage[i], 1, SkBudgeted::kYes,
|
|
|
|
SkBackingFit::kExact);
|
2018-10-09 16:32:31 +00:00
|
|
|
if (!proxies[i]) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Failed to create proxy";
|
|
|
|
return DrawResult::kFail;
|
2017-01-23 20:30:35 +00:00
|
|
|
}
|
2016-06-09 20:24:48 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 16:32:31 +00:00
|
|
|
SkYUVAIndex yuvaIndices[4] = {
|
2018-10-10 15:43:01 +00:00
|
|
|
{ 0, SkColorChannel::kR },
|
2018-10-09 16:32:31 +00:00
|
|
|
{ 1, SkColorChannel::kR },
|
|
|
|
{ 1, SkColorChannel::kG },
|
|
|
|
{ -1, SkColorChannel::kA }
|
|
|
|
};
|
|
|
|
|
2016-06-09 20:24:48 +00:00
|
|
|
for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) {
|
2018-09-12 14:19:41 +00:00
|
|
|
SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fImage[0]->width()),
|
|
|
|
SkIntToScalar(fImage[0]->height()));
|
2016-06-09 20:24:48 +00:00
|
|
|
renderRect.outset(kDrawPad, kDrawPad);
|
|
|
|
|
|
|
|
SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset;
|
|
|
|
SkScalar x = kDrawPad + kTestPad;
|
|
|
|
|
2016-06-23 21:07:00 +00:00
|
|
|
GrPaint grPaint;
|
2017-01-09 16:46:10 +00:00
|
|
|
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
2018-10-09 16:32:31 +00:00
|
|
|
auto fp = GrYUVtoRGBEffect::Make(proxies, yuvaIndices,
|
2018-11-02 17:36:42 +00:00
|
|
|
static_cast<SkYUVColorSpace>(space),
|
|
|
|
GrSamplerState::Filter::kNearest);
|
2016-06-09 20:24:48 +00:00
|
|
|
if (fp) {
|
|
|
|
SkMatrix viewMatrix;
|
|
|
|
viewMatrix.setTranslate(x, y);
|
2017-08-11 13:40:37 +00:00
|
|
|
grPaint.addColorFragmentProcessor(std::move(fp));
|
2019-05-29 18:43:13 +00:00
|
|
|
std::unique_ptr<GrDrawOp> op(GrFillRectOp::MakeNonAARect(
|
|
|
|
context, std::move(grPaint), viewMatrix, renderRect));
|
2017-09-13 19:25:47 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
2016-06-09 20:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 23:20:09 +00:00
|
|
|
return DrawResult::kOk;
|
2016-06-09 20:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-09-12 14:19:41 +00:00
|
|
|
sk_sp<SkImage> fImage[2];
|
2016-06-09 20:24:48 +00:00
|
|
|
|
2019-03-06 17:36:47 +00:00
|
|
|
static constexpr SkScalar kDrawPad = 10.f;
|
|
|
|
static constexpr SkScalar kTestPad = 10.f;
|
|
|
|
static constexpr SkScalar kColorSpaceOffset = 36.f;
|
|
|
|
|
2016-06-09 20:24:48 +00:00
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM(return new YUVNV12toRGBEffect;)
|
2019-04-12 19:03:02 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// This GM tests domain clamping on YUV multiplanar images where the U and V
|
|
|
|
// planes have different resolution from Y. See skbug:8959
|
|
|
|
|
|
|
|
class YUVtoRGBDomainEffect : public GpuGM {
|
|
|
|
public:
|
|
|
|
YUVtoRGBDomainEffect() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("yuv_to_rgb_domain_effect");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make((YSIZE + kTestPad) * 3 + kDrawPad, (YSIZE + kTestPad) * 2 + kDrawPad);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
SkBitmap bmp[3];
|
|
|
|
SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
|
|
|
|
bmp[0].allocPixels(yinfo);
|
|
|
|
SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE);
|
|
|
|
bmp[1].allocPixels(uinfo);
|
|
|
|
SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE);
|
|
|
|
bmp[2].allocPixels(vinfo);
|
|
|
|
|
|
|
|
int innerColor[] = {149, 43, 21};
|
|
|
|
int outerColor[] = {128, 128, 128};
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
bmp[i].eraseColor(SkColorSetARGB(outerColor[i], 0, 0, 0));
|
|
|
|
SkIRect innerRect = i == 0 ? SkIRect::MakeLTRB(2, 2, 6, 6) : SkIRect::MakeLTRB(1, 1, 3, 3);
|
|
|
|
bmp[i].erase(SkColorSetARGB(innerColor[i], 0, 0, 0), innerRect);
|
|
|
|
fImage[i] = SkImage::MakeFromBitmap(bmp[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
|
|
|
|
SkCanvas* canvas, SkString* errorMsg) override {
|
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
sk_sp<GrTextureProxy> proxies[3];
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2019-08-13 20:55:41 +00:00
|
|
|
proxies[i] = proxyProvider->createTextureProxy(fImage[i], 1, SkBudgeted::kYes,
|
|
|
|
SkBackingFit::kExact);
|
2019-04-12 19:03:02 +00:00
|
|
|
if (!proxies[i]) {
|
|
|
|
*errorMsg = "Failed to create proxy";
|
|
|
|
return DrawResult::kFail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw a 2x2 grid of the YUV images.
|
|
|
|
// Rows = kNearest, kBilerp, Cols = No clamp, clamp
|
|
|
|
static const GrSamplerState::Filter kFilters[] = {
|
|
|
|
GrSamplerState::Filter::kNearest, GrSamplerState::Filter::kBilerp };
|
|
|
|
static const SkRect kGreenRect = SkRect::MakeLTRB(2.f, 2.f, 6.f, 6.f);
|
|
|
|
|
|
|
|
SkYUVAIndex yuvaIndices[4] = {
|
|
|
|
{ SkYUVAIndex::kY_Index, SkColorChannel::kR },
|
|
|
|
{ SkYUVAIndex::kU_Index, SkColorChannel::kR },
|
|
|
|
{ SkYUVAIndex::kV_Index, SkColorChannel::kR },
|
|
|
|
{ -1, SkColorChannel::kA }
|
|
|
|
};
|
|
|
|
SkRect rect = SkRect::MakeWH(YSIZE, YSIZE);
|
|
|
|
|
|
|
|
SkScalar y = kDrawPad + kTestPad;
|
|
|
|
for (uint32_t i = 0; i < SK_ARRAY_COUNT(kFilters); ++i) {
|
|
|
|
SkScalar x = kDrawPad + kTestPad;
|
|
|
|
|
|
|
|
for (uint32_t j = 0; j < 2; ++j) {
|
|
|
|
SkMatrix ctm = SkMatrix::MakeTrans(x, y);
|
|
|
|
ctm.postScale(10.f, 10.f);
|
|
|
|
|
|
|
|
SkRect domain = kGreenRect;
|
|
|
|
if (kFilters[i] == GrSamplerState::Filter::kNearest) {
|
|
|
|
// Make a very small inset for nearest-neighbor filtering so that 0.5px
|
|
|
|
// centers don't round out beyond the green pixels.
|
|
|
|
domain.inset(0.01f, 0.01f);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkRect* domainPtr = j > 0 ? &domain : nullptr;
|
|
|
|
std::unique_ptr<GrFragmentProcessor> fp(GrYUVtoRGBEffect::Make(proxies, yuvaIndices,
|
|
|
|
kJPEG_SkYUVColorSpace, kFilters[i], SkMatrix::I(), domainPtr));
|
|
|
|
if (fp) {
|
|
|
|
GrPaint grPaint;
|
|
|
|
grPaint.addColorFragmentProcessor(std::move(fp));
|
|
|
|
renderTargetContext->drawRect(
|
|
|
|
GrNoClip(), std::move(grPaint), GrAA::kYes, ctm, rect);
|
|
|
|
}
|
|
|
|
x += rect.width() + kTestPad;
|
|
|
|
}
|
|
|
|
|
|
|
|
y += rect.height() + kTestPad;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
sk_sp<SkImage> fImage[3];
|
|
|
|
|
|
|
|
static constexpr SkScalar kDrawPad = 10.f;
|
|
|
|
static constexpr SkScalar kTestPad = 10.f;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM(return new YUVtoRGBDomainEffect;)
|
2014-07-07 22:09:48 +00:00
|
|
|
}
|