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

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

Issue 207683004: Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up Created 6 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkCoreBlitters.h" 10 #include "SkCoreBlitters.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 for (int i = 0; i < width; i++) { 221 for (int i = 0; i < width; i++) {
222 device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale)); 222 device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale));
223 } 223 }
224 device += fDevice.rowBytes(); 224 device += fDevice.rowBytes();
225 } 225 }
226 } 226 }
227 } 227 }
228 228
229 /////////////////////////////////////////////////////////////////////// 229 ///////////////////////////////////////////////////////////////////////
230 230
231 SkA8_Shader_Blitter::SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint) 231 SkA8_Shader_Blitter::SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
232 : INHERITED(device, paint) { 232 SkShader::Context* shaderContext)
233 : INHERITED(device, paint, shaderContext) {
233 if ((fXfermode = paint.getXfermode()) != NULL) { 234 if ((fXfermode = paint.getXfermode()) != NULL) {
234 fXfermode->ref(); 235 fXfermode->ref();
235 SkASSERT(fShader); 236 SkASSERT(fShaderContext);
236 } 237 }
237 238
238 int width = device.width(); 239 int width = device.width();
239 fBuffer = (SkPMColor*)sk_malloc_throw(sizeof(SkPMColor) * (width + (SkAlign4 (width) >> 2))); 240 fBuffer = (SkPMColor*)sk_malloc_throw(sizeof(SkPMColor) * (width + (SkAlign4 (width) >> 2)));
240 fAAExpand = (uint8_t*)(fBuffer + width); 241 fAAExpand = (uint8_t*)(fBuffer + width);
241 } 242 }
242 243
243 SkA8_Shader_Blitter::~SkA8_Shader_Blitter() { 244 SkA8_Shader_Blitter::~SkA8_Shader_Blitter() {
244 if (fXfermode) SkSafeUnref(fXfermode); 245 if (fXfermode) SkSafeUnref(fXfermode);
245 sk_free(fBuffer); 246 sk_free(fBuffer);
246 } 247 }
247 248
248 void SkA8_Shader_Blitter::blitH(int x, int y, int width) { 249 void SkA8_Shader_Blitter::blitH(int x, int y, int width) {
249 SkASSERT(x >= 0 && y >= 0 && 250 SkASSERT(x >= 0 && y >= 0 &&
250 (unsigned)(x + width) <= (unsigned)fDevice.width()); 251 (unsigned)(x + width) <= (unsigned)fDevice.width());
251 252
252 uint8_t* device = fDevice.getAddr8(x, y); 253 uint8_t* device = fDevice.getAddr8(x, y);
253 254
254 if ((fShader->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode) { 255 if ((fShaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode ) {
255 memset(device, 0xFF, width); 256 memset(device, 0xFF, width);
256 } else { 257 } else {
257 SkPMColor* span = fBuffer; 258 SkPMColor* span = fBuffer;
258 259
259 fShader->shadeSpan(x, y, span, width); 260 fShaderContext->shadeSpan(x, y, span, width);
260 if (fXfermode) { 261 if (fXfermode) {
261 fXfermode->xferA8(device, span, width, NULL); 262 fXfermode->xferA8(device, span, width, NULL);
262 } else { 263 } else {
263 for (int i = width - 1; i >= 0; --i) { 264 for (int i = width - 1; i >= 0; --i) {
264 unsigned srcA = SkGetPackedA32(span[i]); 265 unsigned srcA = SkGetPackedA32(span[i]);
265 unsigned scale = 256 - SkAlpha255To256(srcA); 266 unsigned scale = 256 - SkAlpha255To256(srcA);
266 267
267 device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale)); 268 device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale));
268 } 269 }
269 } 270 }
270 } 271 }
271 } 272 }
272 273
273 static inline uint8_t aa_blend8(SkPMColor src, U8CPU da, int aa) { 274 static inline uint8_t aa_blend8(SkPMColor src, U8CPU da, int aa) {
274 SkASSERT((unsigned)aa <= 255); 275 SkASSERT((unsigned)aa <= 255);
275 276
276 int src_scale = SkAlpha255To256(aa); 277 int src_scale = SkAlpha255To256(aa);
277 int sa = SkGetPackedA32(src); 278 int sa = SkGetPackedA32(src);
278 int dst_scale = 256 - SkAlphaMul(sa, src_scale); 279 int dst_scale = 256 - SkAlphaMul(sa, src_scale);
279 280
280 return SkToU8((sa * src_scale + da * dst_scale) >> 8); 281 return SkToU8((sa * src_scale + da * dst_scale) >> 8);
281 } 282 }
282 283
283 void SkA8_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], 284 void SkA8_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
284 const int16_t runs[]) { 285 const int16_t runs[]) {
285 SkShader* shader = fShader; 286 SkShader::Context* shaderContext = fShaderContext;
286 SkXfermode* mode = fXfermode; 287 SkXfermode* mode = fXfermode;
287 uint8_t* aaExpand = fAAExpand; 288 uint8_t* aaExpand = fAAExpand;
288 SkPMColor* span = fBuffer; 289 SkPMColor* span = fBuffer;
289 uint8_t* device = fDevice.getAddr8(x, y); 290 uint8_t* device = fDevice.getAddr8(x, y);
290 int opaque = fShader->getFlags() & SkShader::kOpaqueAlpha_Flag; 291 int opaque = fShaderContext->getFlags() & SkShader::kOpaqueAlpha_Fla g;
scroggo 2014/03/24 21:24:46 shaderContext?
291 292
292 for (;;) { 293 for (;;) {
293 int count = *runs; 294 int count = *runs;
294 if (count == 0) { 295 if (count == 0) {
295 break; 296 break;
296 } 297 }
297 int aa = *antialias; 298 int aa = *antialias;
298 if (aa) { 299 if (aa) {
299 if (opaque && aa == 255 && mode == NULL) { 300 if (opaque && aa == 255 && mode == NULL) {
300 memset(device, 0xFF, count); 301 memset(device, 0xFF, count);
301 } else { 302 } else {
302 shader->shadeSpan(x, y, span, count); 303 shaderContext->shadeSpan(x, y, span, count);
303 if (mode) { 304 if (mode) {
304 memset(aaExpand, aa, count); 305 memset(aaExpand, aa, count);
305 mode->xferA8(device, span, count, aaExpand); 306 mode->xferA8(device, span, count, aaExpand);
306 } else { 307 } else {
307 for (int i = count - 1; i >= 0; --i) { 308 for (int i = count - 1; i >= 0; --i) {
308 device[i] = aa_blend8(span[i], device[i], aa); 309 device[i] = aa_blend8(span[i], device[i], aa);
309 } 310 }
310 } 311 }
311 } 312 }
312 } 313 }
(...skipping 13 matching lines...) Expand all
326 int x = clip.fLeft; 327 int x = clip.fLeft;
327 int y = clip.fTop; 328 int y = clip.fTop;
328 int width = clip.width(); 329 int width = clip.width();
329 int height = clip.height(); 330 int height = clip.height();
330 uint8_t* device = fDevice.getAddr8(x, y); 331 uint8_t* device = fDevice.getAddr8(x, y);
331 const uint8_t* alpha = mask.getAddr8(x, y); 332 const uint8_t* alpha = mask.getAddr8(x, y);
332 333
333 SkPMColor* span = fBuffer; 334 SkPMColor* span = fBuffer;
334 335
335 while (--height >= 0) { 336 while (--height >= 0) {
336 fShader->shadeSpan(x, y, span, width); 337 fShaderContext->shadeSpan(x, y, span, width);
scroggo 2014/03/24 21:24:46 I wonder why we chose not to cache fShader here. W
337 if (fXfermode) { 338 if (fXfermode) {
338 fXfermode->xferA8(device, span, width, alpha); 339 fXfermode->xferA8(device, span, width, alpha);
339 } else { 340 } else {
340 for (int i = width - 1; i >= 0; --i) { 341 for (int i = width - 1; i >= 0; --i) {
341 device[i] = aa_blend8(span[i], device[i], alpha[i]); 342 device[i] = aa_blend8(span[i], device[i], alpha[i]);
342 } 343 }
343 } 344 }
344 345
345 y += 1; 346 y += 1;
346 device += fDevice.rowBytes(); 347 device += fDevice.rowBytes();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 while (--height >= 0) { 423 while (--height >= 0) {
423 memcpy(dst, src, width); 424 memcpy(dst, src, width);
424 dst += dstRB; 425 dst += dstRB;
425 src += srcRB; 426 src += srcRB;
426 } 427 }
427 } 428 }
428 429
429 const SkBitmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) { 430 const SkBitmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) {
430 return NULL; 431 return NULL;
431 } 432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698