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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkColorFilter.h"
|
|
|
|
#include "include/core/SkColorSpace.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/effects/SkColorMatrix.h"
|
2016-01-31 02:52:31 +00:00
|
|
|
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> make_opaque_color() {
|
2019-04-09 17:55:36 +00:00
|
|
|
return SkShaders::Color(0xFFFF0000);
|
2016-01-31 02:52:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> make_alpha_color() {
|
2019-04-09 17:55:36 +00:00
|
|
|
return SkShaders::Color(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);
|
2019-04-22 02:17:03 +00:00
|
|
|
return SkColorFilters::Matrix(cm);
|
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);
|
2019-04-22 02:17:03 +00:00
|
|
|
auto a = SkColorFilters::Matrix(cm);
|
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);
|
2019-04-22 02:17:03 +00:00
|
|
|
return a->makeComposed(SkColorFilters::Matrix(cm));
|
2016-02-04 19:35:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 17:17:23 +00:00
|
|
|
static sk_sp<SkColorFilter> make_cf2() {
|
2019-04-08 20:23:20 +00:00
|
|
|
return SkColorFilters::Blend(0x8044CC88, SkBlendMode::kSrcATop);
|
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);
|
|
|
|
|
2016-06-20 15:25:02 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpaces[]{
|
|
|
|
nullptr,
|
2017-02-07 18:56:11 +00:00
|
|
|
SkColorSpace::MakeSRGB()
|
2016-06-20 15:25:02 +00:00
|
|
|
};
|
2020-07-31 00:24:57 +00:00
|
|
|
for (const sk_sp<SkColorSpace>& colorSpace : colorSpaces) {
|
2016-02-08 20:56:56 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType,
|
2016-06-20 15:25:02 +00:00
|
|
|
colorSpace);
|
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());
|
2021-01-06 13:43:51 +00:00
|
|
|
surface->draw(canvas, 0, 0);
|
2016-01-31 02:52:31 +00:00
|
|
|
canvas->translate(0, 120);
|
|
|
|
}
|
|
|
|
}
|
2016-05-04 20:09:39 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-25 15:45:14 +00:00
|
|
|
DEF_SIMPLE_GM(color4shader, canvas, 360, 480) {
|
2016-05-04 20:09:39 +00:00
|
|
|
canvas->translate(10, 10);
|
|
|
|
|
2017-02-07 18:56:11 +00:00
|
|
|
auto srgb = SkColorSpace::MakeSRGB();
|
2017-12-12 19:09:31 +00:00
|
|
|
auto spin = srgb->makeColorSpin(); // RGB -> GBR
|
2016-05-04 20:09:39 +00:00
|
|
|
|
|
|
|
const SkColor4f colors[] {
|
|
|
|
{ 1, 0, 0, 1 },
|
2016-06-24 13:31:47 +00:00
|
|
|
{ 0, 1, 0, 1 },
|
|
|
|
{ 0, 0, 1, 1 },
|
|
|
|
{ 0.5, 0.5, 0.5, 1 },
|
2016-05-04 20:09:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
SkRect r = SkRect::MakeWH(100, 100);
|
|
|
|
|
|
|
|
for (const auto& c4 : colors) {
|
|
|
|
sk_sp<SkShader> shaders[] {
|
2019-04-09 17:55:36 +00:00
|
|
|
SkShaders::Color(c4, nullptr),
|
|
|
|
SkShaders::Color(c4, srgb),
|
|
|
|
SkShaders::Color(c4, spin),
|
2016-05-04 20:09:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
for (const auto& s : shaders) {
|
|
|
|
paint.setShader(s);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->translate(r.width() * 6 / 5, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, r.height() * 6 / 5);
|
|
|
|
}
|
|
|
|
}
|