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

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

Issue 249643002: Revert of 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: Created 6 years, 8 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 | « src/core/SkBlitter.cpp ('k') | src/core/SkBlitter_ARGB32.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 /* 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 SkShader::Context* shaderContext) 232 : INHERITED(device, paint) {
233 : INHERITED(device, paint, shaderContext) {
234 if ((fXfermode = paint.getXfermode()) != NULL) { 233 if ((fXfermode = paint.getXfermode()) != NULL) {
235 fXfermode->ref(); 234 fXfermode->ref();
236 SkASSERT(fShaderContext); 235 SkASSERT(fShader);
237 } 236 }
238 237
239 int width = device.width(); 238 int width = device.width();
240 fBuffer = (SkPMColor*)sk_malloc_throw(sizeof(SkPMColor) * (width + (SkAlign4 (width) >> 2))); 239 fBuffer = (SkPMColor*)sk_malloc_throw(sizeof(SkPMColor) * (width + (SkAlign4 (width) >> 2)));
241 fAAExpand = (uint8_t*)(fBuffer + width); 240 fAAExpand = (uint8_t*)(fBuffer + width);
242 } 241 }
243 242
244 SkA8_Shader_Blitter::~SkA8_Shader_Blitter() { 243 SkA8_Shader_Blitter::~SkA8_Shader_Blitter() {
245 if (fXfermode) SkSafeUnref(fXfermode); 244 if (fXfermode) SkSafeUnref(fXfermode);
246 sk_free(fBuffer); 245 sk_free(fBuffer);
247 } 246 }
248 247
249 void SkA8_Shader_Blitter::blitH(int x, int y, int width) { 248 void SkA8_Shader_Blitter::blitH(int x, int y, int width) {
250 SkASSERT(x >= 0 && y >= 0 && 249 SkASSERT(x >= 0 && y >= 0 &&
251 (unsigned)(x + width) <= (unsigned)fDevice.width()); 250 (unsigned)(x + width) <= (unsigned)fDevice.width());
252 251
253 uint8_t* device = fDevice.getAddr8(x, y); 252 uint8_t* device = fDevice.getAddr8(x, y);
254 SkShader::Context* shaderContext = fShaderContext;
255 253
256 if ((shaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode) { 254 if ((fShader->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode) {
257 memset(device, 0xFF, width); 255 memset(device, 0xFF, width);
258 } else { 256 } else {
259 SkPMColor* span = fBuffer; 257 SkPMColor* span = fBuffer;
260 258
261 shaderContext->shadeSpan(x, y, span, width); 259 fShader->shadeSpan(x, y, span, width);
262 if (fXfermode) { 260 if (fXfermode) {
263 fXfermode->xferA8(device, span, width, NULL); 261 fXfermode->xferA8(device, span, width, NULL);
264 } else { 262 } else {
265 for (int i = width - 1; i >= 0; --i) { 263 for (int i = width - 1; i >= 0; --i) {
266 unsigned srcA = SkGetPackedA32(span[i]); 264 unsigned srcA = SkGetPackedA32(span[i]);
267 unsigned scale = 256 - SkAlpha255To256(srcA); 265 unsigned scale = 256 - SkAlpha255To256(srcA);
268 266
269 device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale)); 267 device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale));
270 } 268 }
271 } 269 }
272 } 270 }
273 } 271 }
274 272
275 static inline uint8_t aa_blend8(SkPMColor src, U8CPU da, int aa) { 273 static inline uint8_t aa_blend8(SkPMColor src, U8CPU da, int aa) {
276 SkASSERT((unsigned)aa <= 255); 274 SkASSERT((unsigned)aa <= 255);
277 275
278 int src_scale = SkAlpha255To256(aa); 276 int src_scale = SkAlpha255To256(aa);
279 int sa = SkGetPackedA32(src); 277 int sa = SkGetPackedA32(src);
280 int dst_scale = 256 - SkAlphaMul(sa, src_scale); 278 int dst_scale = 256 - SkAlphaMul(sa, src_scale);
281 279
282 return SkToU8((sa * src_scale + da * dst_scale) >> 8); 280 return SkToU8((sa * src_scale + da * dst_scale) >> 8);
283 } 281 }
284 282
285 void SkA8_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], 283 void SkA8_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
286 const int16_t runs[]) { 284 const int16_t runs[]) {
287 SkShader::Context* shaderContext = fShaderContext; 285 SkShader* shader = fShader;
288 SkXfermode* mode = fXfermode; 286 SkXfermode* mode = fXfermode;
289 uint8_t* aaExpand = fAAExpand; 287 uint8_t* aaExpand = fAAExpand;
290 SkPMColor* span = fBuffer; 288 SkPMColor* span = fBuffer;
291 uint8_t* device = fDevice.getAddr8(x, y); 289 uint8_t* device = fDevice.getAddr8(x, y);
292 int opaque = shaderContext->getFlags() & SkShader::kOpaqueAlp ha_Flag; 290 int opaque = fShader->getFlags() & SkShader::kOpaqueAlpha_Flag;
293 291
294 for (;;) { 292 for (;;) {
295 int count = *runs; 293 int count = *runs;
296 if (count == 0) { 294 if (count == 0) {
297 break; 295 break;
298 } 296 }
299 int aa = *antialias; 297 int aa = *antialias;
300 if (aa) { 298 if (aa) {
301 if (opaque && aa == 255 && mode == NULL) { 299 if (opaque && aa == 255 && mode == NULL) {
302 memset(device, 0xFF, count); 300 memset(device, 0xFF, count);
303 } else { 301 } else {
304 shaderContext->shadeSpan(x, y, span, count); 302 shader->shadeSpan(x, y, span, count);
305 if (mode) { 303 if (mode) {
306 memset(aaExpand, aa, count); 304 memset(aaExpand, aa, count);
307 mode->xferA8(device, span, count, aaExpand); 305 mode->xferA8(device, span, count, aaExpand);
308 } else { 306 } else {
309 for (int i = count - 1; i >= 0; --i) { 307 for (int i = count - 1; i >= 0; --i) {
310 device[i] = aa_blend8(span[i], device[i], aa); 308 device[i] = aa_blend8(span[i], device[i], aa);
311 } 309 }
312 } 310 }
313 } 311 }
314 } 312 }
315 device += count; 313 device += count;
316 runs += count; 314 runs += count;
317 antialias += count; 315 antialias += count;
318 x += count; 316 x += count;
319 } 317 }
320 } 318 }
321 319
322 void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { 320 void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) {
323 if (mask.fFormat == SkMask::kBW_Format) { 321 if (mask.fFormat == SkMask::kBW_Format) {
324 this->INHERITED::blitMask(mask, clip); 322 this->INHERITED::blitMask(mask, clip);
325 return; 323 return;
326 } 324 }
327 325
328 int x = clip.fLeft; 326 int x = clip.fLeft;
329 int y = clip.fTop; 327 int y = clip.fTop;
330 int width = clip.width(); 328 int width = clip.width();
331 int height = clip.height(); 329 int height = clip.height();
332 uint8_t* device = fDevice.getAddr8(x, y); 330 uint8_t* device = fDevice.getAddr8(x, y);
333 const uint8_t* alpha = mask.getAddr8(x, y); 331 const uint8_t* alpha = mask.getAddr8(x, y);
334 SkShader::Context* shaderContext = fShaderContext;
335 332
336 SkPMColor* span = fBuffer; 333 SkPMColor* span = fBuffer;
337 334
338 while (--height >= 0) { 335 while (--height >= 0) {
339 shaderContext->shadeSpan(x, y, span, width); 336 fShader->shadeSpan(x, y, span, width);
340 if (fXfermode) { 337 if (fXfermode) {
341 fXfermode->xferA8(device, span, width, alpha); 338 fXfermode->xferA8(device, span, width, alpha);
342 } else { 339 } else {
343 for (int i = width - 1; i >= 0; --i) { 340 for (int i = width - 1; i >= 0; --i) {
344 device[i] = aa_blend8(span[i], device[i], alpha[i]); 341 device[i] = aa_blend8(span[i], device[i], alpha[i]);
345 } 342 }
346 } 343 }
347 344
348 y += 1; 345 y += 1;
349 device += fDevice.rowBytes(); 346 device += fDevice.rowBytes();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 while (--height >= 0) { 422 while (--height >= 0) {
426 memcpy(dst, src, width); 423 memcpy(dst, src, width);
427 dst += dstRB; 424 dst += dstRB;
428 src += srcRB; 425 src += srcRB;
429 } 426 }
430 } 427 }
431 428
432 const SkBitmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) { 429 const SkBitmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) {
433 return NULL; 430 return NULL;
434 } 431 }
OLDNEW
« no previous file with comments | « src/core/SkBlitter.cpp ('k') | src/core/SkBlitter_ARGB32.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698