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.
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
|
|
|
#include "GrContext.h"
|
|
|
|
#include "GrTest.h"
|
|
|
|
#include "effects/GrYUVtoRGBEffect.h"
|
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkGr.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
class YUVtoRGBEffect : public GM {
|
|
|
|
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 {
|
2015-07-20 22:00:03 +00:00
|
|
|
return SkISize::Make(238, 120);
|
2014-07-07 22:09:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2015-02-13 21:57:09 +00:00
|
|
|
SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
|
|
|
|
fBmp[0].allocPixels(yinfo);
|
|
|
|
SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE);
|
|
|
|
fBmp[1].allocPixels(uinfo);
|
|
|
|
SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE);
|
|
|
|
fBmp[2].allocPixels(vinfo);
|
2014-07-07 22:09:48 +00:00
|
|
|
unsigned char* pixels[3];
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
pixels[i] = (unsigned char*)fBmp[i].getPixels();
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
const size_t nbBytes = fBmp[i].rowBytes() * fBmp[i].height();
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-07-07 22:09:48 +00:00
|
|
|
GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget();
|
|
|
|
if (NULL == rt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GrContext* context = rt->getContext();
|
|
|
|
if (NULL == context) {
|
2015-01-31 15:51:14 +00:00
|
|
|
this->drawGpuOnlyMessage(canvas);
|
2014-07-07 22:09:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrTestTarget tt;
|
|
|
|
context->getTestTarget(&tt);
|
|
|
|
if (NULL == tt.target()) {
|
|
|
|
SkDEBUGFAIL("Couldn't get Gr test target.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-08 15:40:09 +00:00
|
|
|
SkAutoTUnref<GrTexture> texture[3];
|
|
|
|
texture[0].reset(GrRefCachedBitmapTexture(context, fBmp[0], NULL));
|
|
|
|
texture[1].reset(GrRefCachedBitmapTexture(context, fBmp[1], NULL));
|
|
|
|
texture[2].reset(GrRefCachedBitmapTexture(context, fBmp[2], NULL));
|
|
|
|
|
|
|
|
if (!texture[0] || !texture[1] || !texture[2]) {
|
2014-07-07 22:09:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const SkScalar kDrawPad = 10.f;
|
|
|
|
static const SkScalar kTestPad = 10.f;
|
2015-02-13 21:57:09 +00:00
|
|
|
static const SkScalar kColorSpaceOffset = 36.f;
|
|
|
|
SkISize sizes[3] = {{YSIZE, YSIZE}, {USIZE, USIZE}, {VSIZE, VSIZE}};
|
2014-09-13 00:45:58 +00:00
|
|
|
|
|
|
|
for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace;
|
|
|
|
++space) {
|
2014-10-08 15:40:09 +00:00
|
|
|
SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBmp[0].width()),
|
|
|
|
SkIntToScalar(fBmp[0].height()));
|
|
|
|
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) {
|
2015-07-09 14:31:31 +00:00
|
|
|
GrPipelineBuilder pipelineBuilder;
|
2014-10-08 15:40:09 +00:00
|
|
|
SkAutoTUnref<GrFragmentProcessor> fp(
|
2015-07-09 14:31:31 +00:00
|
|
|
GrYUVtoRGBEffect::Create(pipelineBuilder.getProcessorDataManager(),
|
|
|
|
texture[indices[i][0]],
|
2015-02-13 21:57:09 +00:00
|
|
|
texture[indices[i][1]],
|
|
|
|
texture[indices[i][2]],
|
|
|
|
sizes,
|
|
|
|
static_cast<SkYUVColorSpace>(space)));
|
2014-10-08 15:40:09 +00:00
|
|
|
if (fp) {
|
|
|
|
SkMatrix viewMatrix;
|
|
|
|
viewMatrix.setTranslate(x, y);
|
2015-01-22 18:16:09 +00:00
|
|
|
pipelineBuilder.setRenderTarget(rt);
|
2015-08-26 13:48:27 +00:00
|
|
|
pipelineBuilder.addColorProcessor(fp);
|
2015-08-21 17:53:34 +00:00
|
|
|
tt.target()->drawNonAARect(pipelineBuilder,
|
|
|
|
GrColor_WHITE,
|
|
|
|
viewMatrix,
|
|
|
|
renderRect);
|
2014-10-08 15:40:09 +00:00
|
|
|
}
|
|
|
|
x += renderRect.width() + kTestPad;
|
|
|
|
}
|
2014-07-07 22:09:48 +00:00
|
|
|
}
|
2014-10-08 15:40:09 +00:00
|
|
|
}
|
2014-07-07 22:09:48 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkBitmap fBmp[3];
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM( return SkNEW(YUVtoRGBEffect); )
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|