add inital gm for colorfilters
BUG=skia: R=djsollen@google.com Review URL: https://codereview.chromium.org/140393005 git-svn-id: http://skia.googlecode.com/svn/trunk@13346 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
4736ed1a0a
commit
d5808bd35a
88
gm/colorfilters.cpp
Normal file
88
gm/colorfilters.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkGradientShader.h"
|
||||
|
||||
static SkShader* make_shader(const SkRect& bounds) {
|
||||
const SkPoint pts[] = {
|
||||
{ bounds.left(), bounds.top() },
|
||||
{ bounds.right(), bounds.bottom() },
|
||||
};
|
||||
const SkColor colors[] = {
|
||||
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK,
|
||||
SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
|
||||
};
|
||||
return SkGradientShader::CreateLinear(pts,
|
||||
colors, NULL, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode);
|
||||
}
|
||||
|
||||
typedef void (*InstallPaint)(SkPaint*, uint32_t, uint32_t);
|
||||
|
||||
static void install_nothing(SkPaint* paint, uint32_t, uint32_t) {
|
||||
paint->setColorFilter(NULL);
|
||||
}
|
||||
|
||||
static void install_lighting(SkPaint* paint, uint32_t mul, uint32_t add) {
|
||||
paint->setColorFilter(SkColorFilter::CreateLightingFilter(mul, add))->unref();
|
||||
}
|
||||
|
||||
class ColorFiltersGM : public skiagm::GM {
|
||||
public:
|
||||
ColorFiltersGM() {
|
||||
fName.set("lightingcolorfilter");
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString onShortName() {
|
||||
return fName;
|
||||
}
|
||||
|
||||
virtual SkISize onISize() {
|
||||
return SkISize::Make(640, 480);
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||
SkPaint paint;
|
||||
SkRect r;
|
||||
r.setWH(600, 50);
|
||||
paint.setShader(make_shader(r))->unref();
|
||||
|
||||
const struct {
|
||||
InstallPaint fProc;
|
||||
uint32_t fData0, fData1;
|
||||
} rec[] = {
|
||||
{ install_nothing, 0, 0 },
|
||||
{ install_lighting, 0xFF0000, 0 },
|
||||
{ install_lighting, 0x00FF00, 0 },
|
||||
{ install_lighting, 0x0000FF, 0 },
|
||||
{ install_lighting, 0x000000, 0xFF0000 },
|
||||
{ install_lighting, 0x000000, 0x00FF00 },
|
||||
{ install_lighting, 0x000000, 0x0000FF },
|
||||
};
|
||||
|
||||
canvas->translate(10, 10);
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
|
||||
rec[i].fProc(&paint, rec[i].fData0, rec[i].fData1);
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->translate(0, r.height() + 10);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SkString fName;
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_GM( return SkNEW(ColorFiltersGM); )
|
||||
|
@ -43,6 +43,7 @@
|
||||
'../gm/clippedbitmapshaders.cpp',
|
||||
'../gm/coloremoji.cpp',
|
||||
'../gm/colorfilterimagefilter.cpp',
|
||||
'../gm/colorfilters.cpp',
|
||||
'../gm/colormatrix.cpp',
|
||||
'../gm/colortype.cpp',
|
||||
'../gm/complexclip.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user