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

Side by Side Diff: tests/SkColor4fTest.cpp

Issue 1785473002: SkImage now has makeShader to return sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use build guard for impl of newShader 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 | « tests/ImageNewShaderTest.cpp ('k') | no next file » | 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 2016 Google Inc. 2 * Copyright 2016 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 "SkColor.h" 8 #include "SkColor.h"
9 #include "SkColorMatrixFilter.h" 9 #include "SkColorMatrixFilter.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 }; 91 };
92 return SkColorMatrixFilter::Create(mx); 92 return SkColorMatrixFilter::Create(mx);
93 } 93 }
94 94
95 static SkColorFilter* make_compose_cf() { 95 static SkColorFilter* make_compose_cf() {
96 SkAutoTUnref<SkColorFilter> cf0(make_mode_cf()); 96 SkAutoTUnref<SkColorFilter> cf0(make_mode_cf());
97 SkAutoTUnref<SkColorFilter> cf1(make_mx_cf()); 97 SkAutoTUnref<SkColorFilter> cf1(make_mx_cf());
98 return SkColorFilter::CreateComposeFilter(cf0, cf1); 98 return SkColorFilter::CreateComposeFilter(cf0, cf1);
99 } 99 }
100 100
101 static SkShader* make_color_sh() { return SkShader::CreateColorShader(0xFFBB8855 ); } 101 static sk_sp<SkShader> make_color_sh() { return SkShader::MakeColorShader(0xFFBB 8855); }
102 102
103 static SkShader* make_image_sh() { 103 static sk_sp<SkShader> make_image_sh() {
104 const SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); 104 const SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
105 const SkPMColor pixels[] { 105 const SkPMColor pixels[] {
106 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55), 106 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
107 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55), 107 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
108 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55), 108 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
109 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55), 109 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
110 }; 110 };
111 SkAutoTUnref<SkImage> image(SkImage::NewRasterCopy(info, pixels, sizeof(SkPM Color) * 2)); 111 SkAutoTUnref<SkImage> image(SkImage::NewRasterCopy(info, pixels, sizeof(SkPM Color) * 2));
112 return image->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode ); 112 return image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMod e);
113 } 113 }
114 114
115 static SkShader* make_grad_sh() { 115 static sk_sp<SkShader> make_grad_sh() {
116 #if 0 116 #if 0
117 const SkPoint pts[] {{ 0, 0 }, { 100, 100 }}; 117 const SkPoint pts[] {{ 0, 0 }, { 100, 100 }};
118 const SkColor colors[] { SK_ColorRED, SK_ColorBLUE }; 118 const SkColor colors[] { SK_ColorRED, SK_ColorBLUE };
119 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl amp_TileMode); 119 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl amp_TileMode);
120 #else 120 #else
121 // TODO: need to convert new gradient code to enforce PM4f --> RGBA order 121 // TODO: need to convert new gradient code to enforce PM4f --> RGBA order
122 return make_color_sh(); 122 return make_color_sh();
123 #endif 123 #endif
124 } 124 }
125 125
126 static SkShader* make_cf_sh() { 126 static sk_sp<SkShader> make_cf_sh() {
127 SkAutoTUnref<SkColorFilter> filter(make_mx_cf()); 127 SkAutoTUnref<SkColorFilter> filter(make_mx_cf());
128 SkAutoTUnref<SkShader> shader(make_color_sh()); 128 sk_sp<SkShader> shader(make_color_sh());
129 return shader->newWithColorFilter(filter); 129 return sk_sp<SkShader>(shader->newWithColorFilter(filter));
130 } 130 }
131 131
132 static bool compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int c ount, 132 static bool compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int c ount,
133 float tolerance = 1.0f/255) { 133 float tolerance = 1.0f/255) {
134 for (int i = 0; i < count; ++i) { 134 for (int i = 0; i < count; ++i) {
135 SkPM4f c0 = SkPM4f::FromPMColor(span4b[i]); 135 SkPM4f c0 = SkPM4f::FromPMColor(span4b[i]);
136 SkPM4f c1 = span4f[i]; 136 SkPM4f c1 = span4f[i];
137 if (!nearly_equal(c0, c1, tolerance)) { 137 if (!nearly_equal(c0, c1, tolerance)) {
138 return false; 138 return false;
139 } 139 }
140 } 140 }
141 return true; 141 return true;
142 } 142 }
143 143
144 DEF_TEST(Color4f_shader, reporter) { 144 DEF_TEST(Color4f_shader, reporter) {
145 struct { 145 struct {
146 SkShader* (*fFact)(); 146 sk_sp<SkShader> (*fFact)();
147 bool fSupports4f; 147 bool fSupports4f;
148 float fTolerance; 148 float fTolerance;
149 } recs[] = { 149 } recs[] = {
150 { make_color_sh, true, 1.0f/255 }, 150 { make_color_sh, true, 1.0f/255 },
151 // PMColor 4f gradients are interpolated in 255-multiplied values, so we need a 151 // PMColor 4f gradients are interpolated in 255-multiplied values, so we need a
152 // slightly relaxed tolerance to accommodate the cumulative precision de viation. 152 // slightly relaxed tolerance to accommodate the cumulative precision de viation.
153 { make_grad_sh, true, 1.001f/255 }, 153 { make_grad_sh, true, 1.001f/255 },
154 { make_image_sh, false, 1.0f/255 }, 154 { make_image_sh, false, 1.0f/255 },
155 { make_cf_sh, true, 1.0f/255 }, 155 { make_cf_sh, true, 1.0f/255 },
156 }; 156 };
157 157
158 SkPaint paint; 158 SkPaint paint;
159 for (const auto& rec : recs) { 159 for (const auto& rec : recs) {
160 uint32_t storage[300]; 160 uint32_t storage[300];
161 paint.setShader(rec.fFact())->unref(); 161 paint.setShader(rec.fFact());
162 // Encourage 4f context selection. At some point we may need 162 // Encourage 4f context selection. At some point we may need
163 // to instantiate two separate contexts for optimal 4b/4f selection. 163 // to instantiate two separate contexts for optimal 4b/4f selection.
164 const SkShader::ContextRec contextRec(paint, SkMatrix::I(), nullptr, 164 const SkShader::ContextRec contextRec(paint, SkMatrix::I(), nullptr,
165 SkShader::ContextRec::kPM4f_DstTyp e); 165 SkShader::ContextRec::kPM4f_DstTyp e);
166 SkASSERT(paint.getShader()->contextSize(contextRec) <= sizeof(storage)); 166 SkASSERT(paint.getShader()->contextSize(contextRec) <= sizeof(storage));
167 SkShader::Context* ctx = paint.getShader()->createContext(contextRec, st orage); 167 SkShader::Context* ctx = paint.getShader()->createContext(contextRec, st orage);
168 if (rec.fSupports4f) { 168 if (rec.fSupports4f) {
169 const int N = 100; 169 const int N = 100;
170 SkPM4f buffer4f[N]; 170 SkPM4f buffer4f[N];
171 ctx->shadeSpan4f(0, 0, buffer4f, N); 171 ctx->shadeSpan4f(0, 0, buffer4f, N);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // 244 //
245 DEF_TEST(Color4f_xfermode_proc4f, reporter) { 245 DEF_TEST(Color4f_xfermode_proc4f, reporter) {
246 // TODO: extend xfermodes so that all cases can be tested. 246 // TODO: extend xfermodes so that all cases can be tested.
247 // 247 //
248 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; + +mode) { 248 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; + +mode) {
249 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode); 249 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode);
250 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode); 250 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode);
251 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f)); 251 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f));
252 } 252 }
253 } 253 }
OLDNEW
« no previous file with comments | « tests/ImageNewShaderTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698