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

Side by Side Diff: src/core/SkRasterPipelineBlitter.cpp

Issue 2172343002: Have SkRasterPipelineBlitter take over for 565 when it can. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | 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 "SkBlitter.h" 8 #include "SkBlitter.h"
9 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 23 matching lines...) Expand all
34 34
35 void blitH (int x, int y, int w) override; 35 void blitH (int x, int y, int w) override;
36 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override; 36 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
37 void blitMask (const SkMask&, const SkIRect& clip) override; 37 void blitMask (const SkMask&, const SkIRect& clip) override;
38 38
39 // TODO: The default implementations of the other blits look fine, 39 // TODO: The default implementations of the other blits look fine,
40 // but some of them like blitV could probably benefit from custom 40 // but some of them like blitV could probably benefit from custom
41 // blits using something like a SkRasterPipeline::runFew() method. 41 // blits using something like a SkRasterPipeline::runFew() method.
42 42
43 private: 43 private:
44 void append_load_d(SkRasterPipeline*, const void*) const;
45 void append_store (SkRasterPipeline*, void*) const;
46
44 SkPixmap fDst; 47 SkPixmap fDst;
45 SkRasterPipeline fShader, fColorFilter, fXfermode; 48 SkRasterPipeline fShader, fColorFilter, fXfermode;
46 SkPM4f fPaintColor; 49 SkPM4f fPaintColor;
47 50
48 typedef SkBlitter INHERITED; 51 typedef SkBlitter INHERITED;
49 }; 52 };
50 53
51 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, 54 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
52 const SkPaint& paint, 55 const SkPaint& paint,
53 SkTBlitterAllocator* alloc) { 56 SkTBlitterAllocator* alloc) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 auto ptr = st->ctx<const uint8_t*>() + x; 120 auto ptr = st->ctx<const uint8_t*>() + x;
118 Sk4f c = *ptr * (1/255.0f); 121 Sk4f c = *ptr * (1/255.0f);
119 122
120 r = lerp(dr, r, c); 123 r = lerp(dr, r, c);
121 g = lerp(dg, g, c); 124 g = lerp(dg, g, c);
122 b = lerp(db, b, c); 125 b = lerp(db, b, c);
123 a = lerp(da, a, c); 126 a = lerp(da, a, c);
124 st->next(x, r,g,b,a, dr,dg,db,da); 127 st->next(x, r,g,b,a, dr,dg,db,da);
125 } 128 }
126 129
127 static void upscale_lcd16(const Sk4h& lcd16, Sk4f* r, Sk4f* g, Sk4f* b) { 130 static void from_565(const Sk4h& _565, Sk4f* r, Sk4f* g, Sk4f* b) {
128 Sk4i _32_bit = SkNx_cast<int>(lcd16); 131 Sk4i _32_bit = SkNx_cast<int>(_565);
129 132
130 *r = SkNx_cast<float>(_32_bit & SK_R16_MASK_IN_PLACE) * (1.0f / SK_R16_MASK_ IN_PLACE); 133 *r = SkNx_cast<float>(_32_bit & SK_R16_MASK_IN_PLACE) * (1.0f / SK_R16_MASK_ IN_PLACE);
131 *g = SkNx_cast<float>(_32_bit & SK_G16_MASK_IN_PLACE) * (1.0f / SK_G16_MASK_ IN_PLACE); 134 *g = SkNx_cast<float>(_32_bit & SK_G16_MASK_IN_PLACE) * (1.0f / SK_G16_MASK_ IN_PLACE);
132 *b = SkNx_cast<float>(_32_bit & SK_B16_MASK_IN_PLACE) * (1.0f / SK_B16_MASK_ IN_PLACE); 135 *b = SkNx_cast<float>(_32_bit & SK_B16_MASK_IN_PLACE) * (1.0f / SK_B16_MASK_ IN_PLACE);
133 } 136 }
134 137
138 static Sk4h to_565(const Sk4f& r, const Sk4f& g, const Sk4f& b) {
139 return SkNx_cast<uint16_t>( Sk4f_round(r * SK_R16_MASK) << SK_R16_SHIFT
140 | Sk4f_round(g * SK_G16_MASK) << SK_G16_SHIFT
141 | Sk4f_round(b * SK_B16_MASK) << SK_B16_SHIFT);
142 }
143
135 // s' = d(1-c) + sc, 4 pixels at a time for 565 coverage. 144 // s' = d(1-c) + sc, 4 pixels at a time for 565 coverage.
136 static void SK_VECTORCALL lerp_lcd16(SkRasterPipeline::Stage* st, size_t x, 145 static void SK_VECTORCALL lerp_lcd16(SkRasterPipeline::Stage* st, size_t x,
137 Sk4f r, Sk4f g, Sk4f b, Sk4f a, 146 Sk4f r, Sk4f g, Sk4f b, Sk4f a,
138 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { 147 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) {
139 auto ptr = st->ctx<const uint16_t*>() + x; 148 auto ptr = st->ctx<const uint16_t*>() + x;
140 Sk4f cr, cg, cb; 149 Sk4f cr, cg, cb;
141 upscale_lcd16(Sk4h::Load(ptr), &cr, &cg, &cb); 150 from_565(Sk4h::Load(ptr), &cr, &cg, &cb);
142 151
143 r = lerp(dr, r, cr); 152 r = lerp(dr, r, cr);
144 g = lerp(dg, g, cg); 153 g = lerp(dg, g, cg);
145 b = lerp(db, b, cb); 154 b = lerp(db, b, cb);
146 a = 1.0f; 155 a = 1.0f;
147 st->next(x, r,g,b,a, dr,dg,db,da); 156 st->next(x, r,g,b,a, dr,dg,db,da);
148 } 157 }
149 158
150 // Tail variant of lerp_lcd16() handling 1 pixel at a time. 159 // Tail variant of lerp_lcd16() handling 1 pixel at a time.
151 static void SK_VECTORCALL lerp_lcd16_1(SkRasterPipeline::Stage* st, size_t x, 160 static void SK_VECTORCALL lerp_lcd16_1(SkRasterPipeline::Stage* st, size_t x,
152 Sk4f r, Sk4f g, Sk4f b, Sk4f a, 161 Sk4f r, Sk4f g, Sk4f b, Sk4f a,
153 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { 162 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) {
154 auto ptr = st->ctx<const uint16_t*>() + x; 163 auto ptr = st->ctx<const uint16_t*>() + x;
155 Sk4f cr, cg, cb; 164 Sk4f cr, cg, cb;
156 upscale_lcd16({*ptr,0,0,0}, &cr, &cg, &cb); 165 from_565({*ptr,0,0,0}, &cr, &cg, &cb);
157 166
158 r = lerp(dr, r, cr); 167 r = lerp(dr, r, cr);
159 g = lerp(dg, g, cg); 168 g = lerp(dg, g, cg);
160 b = lerp(db, b, cb); 169 b = lerp(db, b, cb);
161 a = 1.0f; 170 a = 1.0f;
162 st->next(x, r,g,b,a, dr,dg,db,da); 171 st->next(x, r,g,b,a, dr,dg,db,da);
163 } 172 }
164 173
174 // Load 4 565 dst pixels.
175 static void SK_VECTORCALL load_d_565(SkRasterPipeline::Stage* st, size_t x,
176 Sk4f r, Sk4f g, Sk4f b, Sk4f a,
177 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) {
178 auto ptr = st->ctx<const uint16_t*>() + x;
179
180 from_565(Sk4h::Load(ptr), &dr,&dg,&db);
181 da = 1.0f;
182 st->next(x, r,g,b,a, dr,dg,db,da);
183 }
184
185 // Load 1 565 dst pixel.
186 static void SK_VECTORCALL load_d_565_1(SkRasterPipeline::Stage* st, size_t x,
187 Sk4f r, Sk4f g, Sk4f b, Sk4f a,
188 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) {
189 auto ptr = st->ctx<const uint16_t*>() + x;
190
191 from_565({*ptr,0,0,0}, &dr,&dg,&db);
192 da = 1.0f;
193 st->next(x, r,g,b,a, dr,dg,db,da);
194 }
195
196 // Store 4 565 pixels.
197 static void SK_VECTORCALL store_565(SkRasterPipeline::Stage* st, size_t x,
198 Sk4f r, Sk4f g, Sk4f b, Sk4f a,
199 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) {
200 auto ptr = st->ctx<uint16_t*>() + x;
201 to_565(r,g,b).store(ptr);
202 }
203
204 // Store 1 565 pixel.
205 static void SK_VECTORCALL store_565_1(SkRasterPipeline::Stage* st, size_t x,
206 Sk4f r, Sk4f g, Sk4f b, Sk4f a,
207 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) {
208 auto ptr = st->ctx<uint16_t*>() + x;
209 *ptr = to_565(r,g,b)[0];
210 }
211
165 // Load 4 8-bit sRGB pixels from SkPMColor order to RGBA. 212 // Load 4 8-bit sRGB pixels from SkPMColor order to RGBA.
166 static void SK_VECTORCALL load_d_srgb(SkRasterPipeline::Stage* st, size_t x, 213 static void SK_VECTORCALL load_d_srgb(SkRasterPipeline::Stage* st, size_t x,
167 Sk4f r, Sk4f g, Sk4f b, Sk4f a, 214 Sk4f r, Sk4f g, Sk4f b, Sk4f a,
168 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { 215 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) {
169 auto ptr = st->ctx<const uint32_t*>() + x; 216 auto ptr = st->ctx<const uint32_t*>() + x;
170 217
171 dr = { sk_linear_from_srgb[(ptr[0] >> SK_R32_SHIFT) & 0xff], 218 dr = { sk_linear_from_srgb[(ptr[0] >> SK_R32_SHIFT) & 0xff],
172 sk_linear_from_srgb[(ptr[1] >> SK_R32_SHIFT) & 0xff], 219 sk_linear_from_srgb[(ptr[1] >> SK_R32_SHIFT) & 0xff],
173 sk_linear_from_srgb[(ptr[2] >> SK_R32_SHIFT) & 0xff], 220 sk_linear_from_srgb[(ptr[2] >> SK_R32_SHIFT) & 0xff],
174 sk_linear_from_srgb[(ptr[3] >> SK_R32_SHIFT) & 0xff] }; 221 sk_linear_from_srgb[(ptr[3] >> SK_R32_SHIFT) & 0xff] };
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 262 }
216 263
217 // Tail variant of store_srgb() handling 1 pixel at a time. 264 // Tail variant of store_srgb() handling 1 pixel at a time.
218 static void SK_VECTORCALL store_srgb_1(SkRasterPipeline::Stage* st, size_t x, 265 static void SK_VECTORCALL store_srgb_1(SkRasterPipeline::Stage* st, size_t x,
219 Sk4f r, Sk4f g, Sk4f b, Sk4f a, 266 Sk4f r, Sk4f g, Sk4f b, Sk4f a,
220 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { 267 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) {
221 auto dst = st->ctx<uint32_t*>() + x; 268 auto dst = st->ctx<uint32_t*>() + x;
222 *dst = Sk4f_toS32(swizzle_rb_if_bgra({ r[0], g[0], b[0], a[0] })); 269 *dst = Sk4f_toS32(swizzle_rb_if_bgra({ r[0], g[0], b[0], a[0] }));
223 } 270 }
224 271
272 static bool supported(const SkImageInfo& info) {
273 // TODO: f16, more?
274 switch (info.colorType()) {
275 case kN32_SkColorType: return info.gammaCloseToSRGB();
276 case kRGB_565_SkColorType: return true;
277 default: return false;
278 }
279 }
225 280
226 template <typename Effect> 281 template <typename Effect>
227 static bool append_effect_stages(const Effect* effect, SkRasterPipeline* pipelin e) { 282 static bool append_effect_stages(const Effect* effect, SkRasterPipeline* pipelin e) {
228 return !effect || effect->appendStages(pipeline); 283 return !effect || effect->appendStages(pipeline);
229 } 284 }
230 285
231 286
232 SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, 287 SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
233 const SkPaint& paint, 288 const SkPaint& paint,
234 SkTBlitterAllocator* alloc) { 289 SkTBlitterAllocator* alloc) {
235 if (!dst.info().gammaCloseToSRGB()) { 290 if (!supported(dst.info())) {
236 return nullptr; // TODO: f16, etc. 291 return nullptr;
237 } 292 }
238 if (paint.getShader()) { 293 if (paint.getShader()) {
239 return nullptr; // TODO: need to work out how shaders and their context s work 294 return nullptr; // TODO: need to work out how shaders and their context s work
240 } 295 }
241 296
242 SkRasterPipeline shader, colorFilter, xfermode; 297 SkRasterPipeline shader, colorFilter, xfermode;
243 if (!append_effect_stages(paint.getColorFilter(), &colorFilter) || 298 if (!append_effect_stages(paint.getColorFilter(), &colorFilter) ||
244 !append_effect_stages(paint.getXfermode(), &xfermode )) { 299 !append_effect_stages(paint.getXfermode(), &xfermode )) {
245 return nullptr; 300 return nullptr;
246 } 301 }
247 302
303 uint32_t paintColor = paint.getColor();
304
305 SkColor4f color;
306 if (dst.info().colorSpace()) {
307 color = SkColor4f::FromColor(paintColor);
308 } else {
309 swizzle_rb(SkNx_cast<float>(Sk4b::Load(&paintColor)) * (1/255.0f)).store (&color);
310 }
311
248 auto blitter = alloc->createT<SkRasterPipelineBlitter>( 312 auto blitter = alloc->createT<SkRasterPipelineBlitter>(
249 dst, 313 dst,
250 shader, colorFilter, xfermode, 314 shader, colorFilter, xfermode,
251 SkColor4f::FromColor(paint.getColor()).premul()); 315 color.premul());
252 316
253 if (!paint.getShader()) { 317 if (!paint.getShader()) {
254 blitter->fShader.append(constant_color, &blitter->fPaintColor); 318 blitter->fShader.append(constant_color, &blitter->fPaintColor);
255 } 319 }
256 if (!paint.getXfermode()) { 320 if (!paint.getXfermode()) {
257 blitter->fXfermode.append(srcover); 321 blitter->fXfermode.append(srcover);
258 } 322 }
259 323
260 return blitter; 324 return blitter;
261 } 325 }
262 326
327 void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p, const void* dst ) const {
328 SkASSERT(supported(fDst.info()));
329
330 switch (fDst.info().colorType()) {
331 case kN32_SkColorType:
332 if (fDst.info().gammaCloseToSRGB()) {
333 p->append(load_d_srgb, load_d_srgb_1, dst);
334 }
335 break;
336 case kRGB_565_SkColorType:
337 p->append(load_d_565, load_d_565_1, dst);
338 break;
339 default: break;
340 }
341 }
342
343 void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p, void* dst) const {
344 SkASSERT(supported(fDst.info()));
345
346 switch (fDst.info().colorType()) {
347 case kN32_SkColorType:
348 if (fDst.info().gammaCloseToSRGB()) {
349 p->append(store_srgb, store_srgb_1, dst);
350 }
351 break;
352 case kRGB_565_SkColorType:
353 p->append(store_565, store_565_1, dst);
354 break;
355 default: break;
356 }
357 }
358
263 void SkRasterPipelineBlitter::blitH(int x, int y, int w) { 359 void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
264 auto dst = fDst.writable_addr(0,y); 360 auto dst = fDst.writable_addr(0,y);
265 361
266 SkRasterPipeline p; 362 SkRasterPipeline p;
267 p.extend(fShader); 363 p.extend(fShader);
268 p.extend(fColorFilter); 364 p.extend(fColorFilter);
269 p.append(load_d_srgb, load_d_srgb_1, dst); 365 this->append_load_d(&p, dst);
270 p.extend(fXfermode); 366 p.extend(fXfermode);
271 p.append(store_srgb, store_srgb_1, dst); 367 this->append_store(&p, dst);
272 368
273 p.run(x, w); 369 p.run(x, w);
274 } 370 }
275 371
276 void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) { 372 void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
277 auto dst = fDst.writable_addr(0,y); 373 auto dst = fDst.writable_addr(0,y);
278 float coverage; 374 float coverage;
279 375
280 SkRasterPipeline p; 376 SkRasterPipeline p;
281 p.extend(fShader); 377 p.extend(fShader);
282 p.extend(fColorFilter); 378 p.extend(fColorFilter);
283 p.append(load_d_srgb, load_d_srgb_1, dst); 379 this->append_load_d(&p, dst);
284 p.extend(fXfermode); 380 p.extend(fXfermode);
285 p.append(lerp_constant_float, &coverage); 381 p.append(lerp_constant_float, &coverage);
286 p.append(store_srgb, store_srgb_1, dst); 382 this->append_store(&p, dst);
287 383
288 for (int16_t run = *runs; run > 0; run = *runs) { 384 for (int16_t run = *runs; run > 0; run = *runs) {
289 coverage = *aa * (1/255.0f); 385 coverage = *aa * (1/255.0f);
290 p.run(x, run); 386 p.run(x, run);
291 387
292 x += run; 388 x += run;
293 runs += run; 389 runs += run;
294 aa += run; 390 aa += run;
295 } 391 }
296 } 392 }
297 393
298 void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { 394 void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
299 if (mask.fFormat == SkMask::kBW_Format) { 395 if (mask.fFormat == SkMask::kBW_Format) {
300 // TODO: native BW masks? 396 // TODO: native BW masks?
301 return INHERITED::blitMask(mask, clip); 397 return INHERITED::blitMask(mask, clip);
302 } 398 }
303 399
304 int x = clip.left(); 400 int x = clip.left();
305 for (int y = clip.top(); y < clip.bottom(); y++) { 401 for (int y = clip.top(); y < clip.bottom(); y++) {
306 auto dst = fDst.writable_addr(0,y); 402 auto dst = fDst.writable_addr(0,y);
307 403
308 SkRasterPipeline p; 404 SkRasterPipeline p;
309 p.extend(fShader); 405 p.extend(fShader);
310 p.extend(fColorFilter); 406 p.extend(fColorFilter);
311 p.append(load_d_srgb, load_d_srgb_1, dst); 407 this->append_load_d(&p, dst);
312 p.extend(fXfermode); 408 p.extend(fXfermode);
313 switch (mask.fFormat) { 409 switch (mask.fFormat) {
314 case SkMask::kA8_Format: 410 case SkMask::kA8_Format:
315 p.append(lerp_a8, lerp_a8_1, mask.getAddr8(x,y)-x); 411 p.append(lerp_a8, lerp_a8_1, mask.getAddr8(x,y)-x);
316 break; 412 break;
317 case SkMask::kLCD16_Format: 413 case SkMask::kLCD16_Format:
318 p.append(lerp_lcd16, lerp_lcd16_1, mask.getAddrLCD16(x,y)-x); 414 p.append(lerp_lcd16, lerp_lcd16_1, mask.getAddrLCD16(x,y)-x);
319 break; 415 break;
320 default: break; 416 default: break;
321 } 417 }
322 p.append(store_srgb, store_srgb_1, dst); 418 this->append_store(&p, dst);
323 419
324 p.run(x, clip.width()); 420 p.run(x, clip.width());
325 } 421 }
326 } 422 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698