2016-01-31 02:52:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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 "SkColorPriv.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkSurface.h"
|
|
|
|
|
|
|
|
#include "SkColorMatrixFilter.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> make_opaque_color() {
|
|
|
|
return SkShader::MakeColorShader(0xFFFF0000);
|
2016-01-31 02:52:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> make_alpha_color() {
|
|
|
|
return SkShader::MakeColorShader(0x80FF0000);
|
2016-01-31 02:52:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 17:17:23 +00:00
|
|
|
static sk_sp<SkColorFilter> make_cf_null() {
|
2016-01-31 02:52:31 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-03-22 17:17:23 +00:00
|
|
|
static sk_sp<SkColorFilter> make_cf0() {
|
2016-01-31 02:52:31 +00:00
|
|
|
SkColorMatrix cm;
|
|
|
|
cm.setSaturation(0.75f);
|
2016-03-22 17:17:23 +00:00
|
|
|
return SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat);
|
2016-01-31 02:52:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 17:17:23 +00:00
|
|
|
static sk_sp<SkColorFilter> make_cf1() {
|
2016-02-04 19:35:27 +00:00
|
|
|
SkColorMatrix cm;
|
|
|
|
cm.setSaturation(0.75f);
|
2016-03-22 17:17:23 +00:00
|
|
|
auto a(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
2016-02-04 19:35:27 +00:00
|
|
|
// CreateComposedFilter will try to concat these two matrices, resulting in a single
|
|
|
|
// filter (which is good for speed). For this test, we want to force a real compose of
|
|
|
|
// these two, so our inner filter has a scale-up, which disables the optimization of
|
|
|
|
// combining the two matrices.
|
|
|
|
cm.setScale(1.1f, 0.9f, 1);
|
2016-03-22 17:17:23 +00:00
|
|
|
auto b(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
|
|
|
return SkColorFilter::MakeComposeFilter(a, b);
|
2016-02-04 19:35:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 17:17:23 +00:00
|
|
|
static sk_sp<SkColorFilter> make_cf2() {
|
|
|
|
return SkColorFilter::MakeModeFilter(0x8044CC88, SkXfermode::kSrcATop_Mode);
|
2016-02-08 20:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 02:52:31 +00:00
|
|
|
static void draw_into_canvas(SkCanvas* canvas) {
|
2016-02-08 20:56:56 +00:00
|
|
|
const SkRect r = SkRect::MakeWH(50, 100);
|
2016-03-09 17:50:50 +00:00
|
|
|
sk_sp<SkShader> (*shaders[])() { make_opaque_color, make_alpha_color };
|
2016-03-22 17:17:23 +00:00
|
|
|
sk_sp<SkColorFilter> (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 };
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-01-31 02:52:31 +00:00
|
|
|
SkPaint paint;
|
|
|
|
for (auto shProc : shaders) {
|
2016-03-09 17:50:50 +00:00
|
|
|
paint.setShader(shProc());
|
2016-01-31 02:52:31 +00:00
|
|
|
for (auto cfProc : filters) {
|
2016-03-22 17:17:23 +00:00
|
|
|
paint.setColorFilter(cfProc());
|
2016-01-31 02:52:31 +00:00
|
|
|
canvas->drawRect(r, paint);
|
2016-02-08 20:56:56 +00:00
|
|
|
canvas->translate(60, 0);
|
2016-01-31 02:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-08 20:56:56 +00:00
|
|
|
DEF_SIMPLE_GM(color4f, canvas, 1024, 260) {
|
|
|
|
canvas->translate(10, 10);
|
2016-01-31 02:52:31 +00:00
|
|
|
|
|
|
|
SkPaint bg;
|
|
|
|
// need the target to be opaque, so we can draw it to the screen
|
|
|
|
// even if it holds sRGB values.
|
|
|
|
bg.setColor(0xFFFFFFFF);
|
|
|
|
|
|
|
|
SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkColorProfileType };
|
|
|
|
for (auto profile : profiles) {
|
2016-02-08 20:56:56 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType,
|
2016-01-31 02:52:31 +00:00
|
|
|
profile);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRaster(info));
|
2016-01-31 02:52:31 +00:00
|
|
|
surface->getCanvas()->drawPaint(bg);
|
|
|
|
draw_into_canvas(surface->getCanvas());
|
|
|
|
surface->draw(canvas, 0, 0, nullptr);
|
|
|
|
canvas->translate(0, 120);
|
|
|
|
}
|
|
|
|
}
|