Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: gm/color4f.cpp

Issue 1820303002: Revert of switch colorfilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/blurroundrect.cpp ('k') | gm/colorcube.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkShader.h" 11 #include "SkShader.h"
12 #include "SkSurface.h" 12 #include "SkSurface.h"
13 13
14 #include "SkColorMatrixFilter.h" 14 #include "SkColorMatrixFilter.h"
15 #include "SkGradientShader.h" 15 #include "SkGradientShader.h"
16 16
17 static sk_sp<SkShader> make_opaque_color() { 17 static sk_sp<SkShader> make_opaque_color() {
18 return SkShader::MakeColorShader(0xFFFF0000); 18 return SkShader::MakeColorShader(0xFFFF0000);
19 } 19 }
20 20
21 static sk_sp<SkShader> make_alpha_color() { 21 static sk_sp<SkShader> make_alpha_color() {
22 return SkShader::MakeColorShader(0x80FF0000); 22 return SkShader::MakeColorShader(0x80FF0000);
23 } 23 }
24 24
25 static sk_sp<SkColorFilter> make_cf_null() { 25 static SkColorFilter* make_cf_null() {
26 return nullptr; 26 return nullptr;
27 } 27 }
28 28
29 static sk_sp<SkColorFilter> make_cf0() { 29 static SkColorFilter* make_cf0() {
30 SkColorMatrix cm; 30 SkColorMatrix cm;
31 cm.setSaturation(0.75f); 31 cm.setSaturation(0.75f);
32 return SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat); 32 return SkColorMatrixFilter::Create(cm);
33 } 33 }
34 34
35 static sk_sp<SkColorFilter> make_cf1() { 35 static SkColorFilter* make_cf1() {
36 SkColorMatrix cm; 36 SkColorMatrix cm;
37 cm.setSaturation(0.75f); 37 cm.setSaturation(0.75f);
38 auto a(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); 38 SkAutoTUnref<SkColorFilter> a(SkColorMatrixFilter::Create(cm));
39 // CreateComposedFilter will try to concat these two matrices, resulting in a single 39 // CreateComposedFilter will try to concat these two matrices, resulting in a single
40 // filter (which is good for speed). For this test, we want to force a real compose of 40 // filter (which is good for speed). For this test, we want to force a real compose of
41 // these two, so our inner filter has a scale-up, which disables the optimiz ation of 41 // these two, so our inner filter has a scale-up, which disables the optimiz ation of
42 // combining the two matrices. 42 // combining the two matrices.
43 cm.setScale(1.1f, 0.9f, 1); 43 cm.setScale(1.1f, 0.9f, 1);
44 auto b(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); 44 SkAutoTUnref<SkColorFilter> b(SkColorMatrixFilter::Create(cm));
45 return SkColorFilter::MakeComposeFilter(a, b); 45 return SkColorFilter::CreateComposeFilter(a, b);
46 } 46 }
47 47
48 static sk_sp<SkColorFilter> make_cf2() { 48 static SkColorFilter* make_cf2() {
49 return SkColorFilter::MakeModeFilter(0x8044CC88, SkXfermode::kSrcATop_Mode); 49 return SkColorFilter::CreateModeFilter(0x8044CC88, SkXfermode::kSrcATop_Mode );
50 } 50 }
51 51
52 static void draw_into_canvas(SkCanvas* canvas) { 52 static void draw_into_canvas(SkCanvas* canvas) {
53 const SkRect r = SkRect::MakeWH(50, 100); 53 const SkRect r = SkRect::MakeWH(50, 100);
54 sk_sp<SkShader> (*shaders[])() { make_opaque_color, make_alpha_color }; 54 sk_sp<SkShader> (*shaders[])() { make_opaque_color, make_alpha_color };
55 sk_sp<SkColorFilter> (*filters[])() { make_cf_null, make_cf0, make_cf1, make _cf2 }; 55 SkColorFilter* (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 } ;
56 56
57 SkPaint paint; 57 SkPaint paint;
58 for (auto shProc : shaders) { 58 for (auto shProc : shaders) {
59 paint.setShader(shProc()); 59 paint.setShader(shProc());
60 for (auto cfProc : filters) { 60 for (auto cfProc : filters) {
61 paint.setColorFilter(cfProc()); 61 SkSafeUnref(paint.setColorFilter(cfProc()));
62 canvas->drawRect(r, paint); 62 canvas->drawRect(r, paint);
63 canvas->translate(60, 0); 63 canvas->translate(60, 0);
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68 DEF_SIMPLE_GM(color4f, canvas, 1024, 260) { 68 DEF_SIMPLE_GM(color4f, canvas, 1024, 260) {
69 canvas->translate(10, 10); 69 canvas->translate(10, 10);
70 70
71 SkPaint bg; 71 SkPaint bg;
72 // need the target to be opaque, so we can draw it to the screen 72 // need the target to be opaque, so we can draw it to the screen
73 // even if it holds sRGB values. 73 // even if it holds sRGB values.
74 bg.setColor(0xFFFFFFFF); 74 bg.setColor(0xFFFFFFFF);
75 75
76 SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkCo lorProfileType }; 76 SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkCo lorProfileType };
77 for (auto profile : profiles) { 77 for (auto profile : profiles) {
78 const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType, 78 const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType,
79 profile); 79 profile);
80 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 80 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
81 surface->getCanvas()->drawPaint(bg); 81 surface->getCanvas()->drawPaint(bg);
82 draw_into_canvas(surface->getCanvas()); 82 draw_into_canvas(surface->getCanvas());
83 surface->draw(canvas, 0, 0, nullptr); 83 surface->draw(canvas, 0, 0, nullptr);
84 canvas->translate(0, 120); 84 canvas->translate(0, 120);
85 } 85 }
86 } 86 }
OLDNEW
« no previous file with comments | « gm/blurroundrect.cpp ('k') | gm/colorcube.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698