change composeshader_alpha to exercise srcover as well
BUG=skia: R=scroggo@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/263083011 git-svn-id: http://skia.googlecode.com/svn/trunk@14572 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
6b392b6111
commit
58e428729b
@ -15,32 +15,33 @@
|
||||
#include "SkString.h"
|
||||
#include "SkXfermode.h"
|
||||
|
||||
static SkShader* make_shader(SkXfermode::Mode mode) {
|
||||
SkPoint pts[2];
|
||||
SkColor colors[2];
|
||||
|
||||
pts[0].set(0, 0);
|
||||
pts[1].set(SkIntToScalar(100), 0);
|
||||
colors[0] = SK_ColorRED;
|
||||
colors[1] = SK_ColorBLUE;
|
||||
SkAutoTUnref<SkShader> shaderA(SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
||||
SkShader::kClamp_TileMode));
|
||||
|
||||
pts[0].set(0, 0);
|
||||
pts[1].set(0, SkIntToScalar(100));
|
||||
colors[0] = SK_ColorBLACK;
|
||||
colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
|
||||
SkAutoTUnref<SkShader> shaderB(SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
||||
SkShader::kClamp_TileMode));
|
||||
|
||||
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode));
|
||||
|
||||
return SkNEW_ARGS(SkComposeShader, (shaderA, shaderB, xfer));
|
||||
}
|
||||
|
||||
class ComposeShaderGM : public skiagm::GM {
|
||||
public:
|
||||
ComposeShaderGM() {
|
||||
SkPoint pts[2];
|
||||
SkColor colors[2];
|
||||
|
||||
pts[0].set(0, 0);
|
||||
pts[1].set(SkIntToScalar(100), 0);
|
||||
colors[0] = SK_ColorRED;
|
||||
colors[1] = SK_ColorBLUE;
|
||||
SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
||||
SkShader::kClamp_TileMode);
|
||||
|
||||
pts[0].set(0, 0);
|
||||
pts[1].set(0, SkIntToScalar(100));
|
||||
colors[0] = SK_ColorBLACK;
|
||||
colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
|
||||
SkShader* shaderB = SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
||||
SkShader::kClamp_TileMode);
|
||||
|
||||
SkXfermode* mode = SkXfermode::Create(SkXfermode::kDstIn_Mode);
|
||||
|
||||
fShader = new SkComposeShader(shaderA, shaderB, mode);
|
||||
shaderA->unref();
|
||||
shaderB->unref();
|
||||
mode->unref();
|
||||
fShader = make_shader(SkXfermode::kDstIn_Mode);
|
||||
}
|
||||
|
||||
virtual ~ComposeShaderGM() {
|
||||
@ -77,7 +78,7 @@ private:
|
||||
typedef GM INHERITED ;
|
||||
};
|
||||
|
||||
class ComposeShaderAlphaGM : public ComposeShaderGM {
|
||||
class ComposeShaderAlphaGM : public skiagm::GM {
|
||||
public:
|
||||
ComposeShaderAlphaGM() {}
|
||||
|
||||
@ -87,24 +88,35 @@ protected:
|
||||
}
|
||||
|
||||
virtual SkISize onISize() SK_OVERRIDE {
|
||||
return SkISize::Make(120, 1024);
|
||||
return SkISize::Make(220, 750);
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||
SkAutoTUnref<SkShader> shader0(make_shader(SkXfermode::kDstIn_Mode));
|
||||
SkAutoTUnref<SkShader> shader1(make_shader(SkXfermode::kSrcOver_Mode));
|
||||
SkShader* shaders[] = { shader0.get(), shader1.get() };
|
||||
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorGREEN);
|
||||
|
||||
const SkRect r = SkRect::MakeXYWH(5, 5, 100, 100);
|
||||
for (int alpha = 0xFF; alpha > 0; alpha -= 0x20) {
|
||||
paint.setAlpha(0xFF);
|
||||
paint.setShader(NULL);
|
||||
canvas->drawRect(r, paint);
|
||||
|
||||
paint.setAlpha(alpha);
|
||||
paint.setShader(fShader);
|
||||
canvas->drawRect(r, paint);
|
||||
|
||||
canvas->translate(r.width() + 5, 0);
|
||||
|
||||
for (size_t y = 0; y < SK_ARRAY_COUNT(shaders); ++y) {
|
||||
SkShader* shader = shaders[y];
|
||||
canvas->save();
|
||||
for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) {
|
||||
paint.setAlpha(0xFF);
|
||||
paint.setShader(NULL);
|
||||
canvas->drawRect(r, paint);
|
||||
|
||||
paint.setAlpha(alpha);
|
||||
paint.setShader(shader);
|
||||
canvas->drawRect(r, paint);
|
||||
|
||||
canvas->translate(r.width() + 5, 0);
|
||||
}
|
||||
canvas->restore();
|
||||
canvas->translate(0, r.height() + 5);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user