blob: 98ce0824cca6c6231b9c6619d0b91de15d045357 [file] [log] [blame]
reed395eabe2016-01-30 18:52:31 -08001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkColorPriv.h"
11#include "SkShader.h"
12#include "SkSurface.h"
13
14#include "SkColorMatrixFilter.h"
15#include "SkGradientShader.h"
16
17static SkShader* make_opaque_color() {
18 return SkShader::CreateColorShader(0xFFFF0000);
19}
20
21static SkShader* make_alpha_color() {
22 return SkShader::CreateColorShader(0x80FF0000);
23}
24
25static SkColorFilter* make_cf_null() {
26 return nullptr;
27}
28
29static SkColorFilter* make_cf0() {
30 SkColorMatrix cm;
31 cm.setSaturation(0.75f);
32 return SkColorMatrixFilter::Create(cm);
33}
34
35static void draw_into_canvas(SkCanvas* canvas) {
36 const SkRect r = SkRect::MakeWH(100, 100);
37 SkShader* (*shaders[])() { make_opaque_color, make_alpha_color };
38 SkColorFilter* (*filters[])() { make_cf_null, make_cf0 };
39
40 SkPaint paint;
41 for (auto shProc : shaders) {
42 paint.setShader(shProc())->unref();
43 for (auto cfProc : filters) {
44 SkSafeUnref(paint.setColorFilter(cfProc()));
45 canvas->drawRect(r, paint);
46 canvas->translate(120, 0);
47 }
48 }
49}
50
51DEF_SIMPLE_GM(color4f, canvas, 510, 250) {
52 canvas->translate(20, 20);
53
54 SkPaint bg;
55 // need the target to be opaque, so we can draw it to the screen
56 // even if it holds sRGB values.
57 bg.setColor(0xFFFFFFFF);
58
59 SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkColorProfileType };
60 for (auto profile : profiles) {
61 const SkImageInfo info = SkImageInfo::Make(500, 100, kN32_SkColorType, kPremul_SkAlphaType,
62 profile);
63 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
64 surface->getCanvas()->drawPaint(bg);
65 draw_into_canvas(surface->getCanvas());
66 surface->draw(canvas, 0, 0, nullptr);
67 canvas->translate(0, 120);
68 }
69}