Updated SkLumaXfermode GM (take two).
Added AA & gradient combinations. Review URL: https://codereview.chromium.org/23190041 git-svn-id: http://skia.googlecode.com/svn/trunk@10897 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
181fcb4a21
commit
a17093f992
111
gm/lumamode.cpp
111
gm/lumamode.cpp
@ -7,48 +7,65 @@
|
|||||||
|
|
||||||
#include "gm.h"
|
#include "gm.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
|
#include "SkGradientShader.h"
|
||||||
#include "SkLumaXfermode.h"
|
#include "SkLumaXfermode.h"
|
||||||
|
|
||||||
static void show_scene(SkCanvas* canvas, SkXfermode* mode, const char* label) {
|
static SkScalar kSize = 80;
|
||||||
|
static SkScalar kInset = 10;
|
||||||
|
static SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0xff, 0);
|
||||||
|
static SkColor kColor2 = SkColorSetARGB(0xff, 0x80, 0xff, 0);
|
||||||
|
|
||||||
|
static void draw_label(SkCanvas* canvas, const char* label,
|
||||||
|
const SkPoint& offset) {
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
paint.setAntiAlias(true);
|
size_t len = strlen(label);
|
||||||
SkRect r, c, bounds = { 10, 10, 110, 110 };
|
|
||||||
|
SkScalar width = paint.measureText(label, len);
|
||||||
|
canvas->drawText(label, len, offset.x() - width / 2, offset.y(),
|
||||||
|
paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_scene(SkCanvas* canvas, SkXfermode* mode, bool aa,
|
||||||
|
SkShader* s1, SkShader* s2) {
|
||||||
|
SkPaint paint;
|
||||||
|
paint.setAntiAlias(aa);
|
||||||
|
SkRect r, c, bounds = SkRect::MakeWH(kSize, kSize);
|
||||||
|
|
||||||
c = bounds;
|
c = bounds;
|
||||||
c.fRight = bounds.centerX();
|
c.fRight = bounds.centerX();
|
||||||
r = bounds;
|
canvas->drawRect(bounds, paint);
|
||||||
r.fBottom = bounds.centerY();
|
|
||||||
canvas->drawRect(r, paint);
|
|
||||||
|
|
||||||
SkScalar tw = paint.measureText(label, strlen(label));
|
|
||||||
canvas->drawText(label, strlen(label), bounds.centerX() - tw / 2,
|
|
||||||
bounds.bottom() + 15, paint);
|
|
||||||
|
|
||||||
canvas->saveLayer(&bounds, NULL);
|
canvas->saveLayer(&bounds, NULL);
|
||||||
|
|
||||||
r = bounds;
|
r = bounds;
|
||||||
r.inset(20, 0);
|
r.inset(kInset, 0);
|
||||||
paint.setColor(0x80FFFF00);
|
paint.setShader(s1);
|
||||||
|
paint.setColor(s1 ? SK_ColorBLACK : SkColorSetA(kColor1, 0x80));
|
||||||
canvas->drawOval(r, paint);
|
canvas->drawOval(r, paint);
|
||||||
|
if (!s1) {
|
||||||
canvas->save();
|
canvas->save();
|
||||||
canvas->clipRect(c);
|
canvas->clipRect(c);
|
||||||
paint.setColor(0xFFFFFF00);
|
paint.setColor(s1 ? SK_ColorBLACK : kColor1);
|
||||||
canvas->drawOval(r, paint);
|
canvas->drawOval(r, paint);
|
||||||
canvas->restore();
|
canvas->restore();
|
||||||
|
}
|
||||||
|
|
||||||
SkPaint xferPaint;
|
SkPaint xferPaint;
|
||||||
xferPaint.setXfermode(mode);
|
xferPaint.setXfermode(mode);
|
||||||
canvas->saveLayer(&bounds, &xferPaint);
|
canvas->saveLayer(&bounds, &xferPaint);
|
||||||
|
|
||||||
r = bounds;
|
r = bounds;
|
||||||
r.inset(0, 20);
|
r.inset(0, kInset);
|
||||||
paint.setColor(0x8080FF00);
|
paint.setShader(s2);
|
||||||
|
paint.setColor(s2 ? SK_ColorBLACK : SkColorSetA(kColor2, 0x80));
|
||||||
canvas->drawOval(r, paint);
|
canvas->drawOval(r, paint);
|
||||||
|
if (!s2) {
|
||||||
canvas->save();
|
canvas->save();
|
||||||
canvas->clipRect(c);
|
canvas->clipRect(c);
|
||||||
paint.setColor(0xFF80FF00);
|
paint.setColor(s2 ? SK_ColorBLACK : kColor2);
|
||||||
canvas->drawOval(r, paint);
|
canvas->drawOval(r, paint);
|
||||||
canvas->restore();
|
canvas->restore();
|
||||||
|
}
|
||||||
|
|
||||||
canvas->restore();
|
canvas->restore();
|
||||||
canvas->restore();
|
canvas->restore();
|
||||||
@ -56,7 +73,27 @@ static void show_scene(SkCanvas* canvas, SkXfermode* mode, const char* label) {
|
|||||||
|
|
||||||
class LumaXfermodeGM : public skiagm::GM {
|
class LumaXfermodeGM : public skiagm::GM {
|
||||||
public:
|
public:
|
||||||
LumaXfermodeGM() {}
|
LumaXfermodeGM() {
|
||||||
|
fSrcInXfer.reset(SkLumaMaskXfermode::Create(SkXfermode::kSrcIn_Mode));
|
||||||
|
fDstInXfer.reset(SkLumaMaskXfermode::Create(SkXfermode::kDstIn_Mode));
|
||||||
|
|
||||||
|
SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) };
|
||||||
|
SkColor g2Colors[] = { kColor2, SkColorSetA(kColor2, 0x20) };
|
||||||
|
SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } };
|
||||||
|
SkPoint g2Points[] = { { 0, 0 }, { kSize, 0 } };
|
||||||
|
SkScalar pos[] = { 0.2f, 1.0f };
|
||||||
|
|
||||||
|
fGr1.reset(SkGradientShader::CreateLinear(g1Points,
|
||||||
|
g1Colors,
|
||||||
|
pos,
|
||||||
|
SK_ARRAY_COUNT(g1Colors),
|
||||||
|
SkShader::kClamp_TileMode));
|
||||||
|
fGr2.reset(SkGradientShader::CreateLinear(g2Points,
|
||||||
|
g2Colors,
|
||||||
|
pos,
|
||||||
|
SK_ARRAY_COUNT(g2Colors),
|
||||||
|
SkShader::kClamp_TileMode));
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual SkString onShortName() SK_OVERRIDE {
|
virtual SkString onShortName() SK_OVERRIDE {
|
||||||
@ -64,20 +101,44 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual SkISize onISize() SK_OVERRIDE {
|
virtual SkISize onISize() SK_OVERRIDE {
|
||||||
return SkISize::Make(450, 140);
|
return SkISize::Make(600, 420);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||||
show_scene(canvas, NULL, "SrcOver");
|
SkXfermode* modes[] = { NULL, fSrcInXfer, fDstInXfer };
|
||||||
canvas->translate(150, 0);
|
struct {
|
||||||
SkAutoTUnref<SkXfermode> src_in(SkLumaMaskXfermode::Create(SkXfermode::kSrcIn_Mode));
|
SkShader* fShader1;
|
||||||
show_scene(canvas, src_in.get(), "SrcInLuma");
|
SkShader* fShader2;
|
||||||
canvas->translate(150, 0);
|
} shaders[] = {
|
||||||
SkAutoTUnref<SkXfermode> dst_in(SkLumaMaskXfermode::Create(SkXfermode::kDstIn_Mode));
|
{ NULL, NULL },
|
||||||
show_scene(canvas, dst_in.get(), "DstInLuma");
|
{ NULL, fGr2 },
|
||||||
|
{ fGr1, NULL },
|
||||||
|
{ fGr1, fGr2 },
|
||||||
|
};
|
||||||
|
|
||||||
|
SkScalar gridStep = kSize + 2 * kInset;
|
||||||
|
draw_label(canvas, "SrcOver", SkPoint::Make(gridStep, 20));
|
||||||
|
draw_label(canvas, "SrcInLuma", SkPoint::Make(gridStep * 3, 20));
|
||||||
|
draw_label(canvas, "DstInLuma", SkPoint::Make(gridStep * 5, 20));
|
||||||
|
for (size_t i = 0; i < SK_ARRAY_COUNT(shaders); ++i) {
|
||||||
|
canvas->save();
|
||||||
|
canvas->translate(kInset, gridStep * i + 30);
|
||||||
|
for (size_t m = 0; m < SK_ARRAY_COUNT(modes); ++m) {
|
||||||
|
draw_scene(canvas, modes[m], true, shaders[i].fShader1,
|
||||||
|
shaders[i].fShader2);
|
||||||
|
canvas->translate(gridStep, 0);
|
||||||
|
draw_scene(canvas, modes[m], false, shaders[i].fShader1,
|
||||||
|
shaders[i].fShader2);
|
||||||
|
canvas->translate(gridStep, 0);
|
||||||
|
}
|
||||||
|
canvas->restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
SkAutoTUnref<SkShader> fGr1, fGr2;
|
||||||
|
SkAutoTUnref<SkXfermode> fSrcInXfer, fDstInXfer;
|
||||||
|
|
||||||
typedef skiagm::GM INHERITED;
|
typedef skiagm::GM INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user