OLD | NEW |
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 Loading... |
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); |
| 254 SkShader::Context* shaderContext = fShaderContext; |
253 | 255 |
254 if ((fShader->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode) { | 256 if ((shaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode)
{ |
255 memset(device, 0xFF, width); | 257 memset(device, 0xFF, width); |
256 } else { | 258 } else { |
257 SkPMColor* span = fBuffer; | 259 SkPMColor* span = fBuffer; |
258 | 260 |
259 fShader->shadeSpan(x, y, span, width); | 261 shaderContext->shadeSpan(x, y, span, width); |
260 if (fXfermode) { | 262 if (fXfermode) { |
261 fXfermode->xferA8(device, span, width, NULL); | 263 fXfermode->xferA8(device, span, width, NULL); |
262 } else { | 264 } else { |
263 for (int i = width - 1; i >= 0; --i) { | 265 for (int i = width - 1; i >= 0; --i) { |
264 unsigned srcA = SkGetPackedA32(span[i]); | 266 unsigned srcA = SkGetPackedA32(span[i]); |
265 unsigned scale = 256 - SkAlpha255To256(srcA); | 267 unsigned scale = 256 - SkAlpha255To256(srcA); |
266 | 268 |
267 device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale)); | 269 device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale)); |
268 } | 270 } |
269 } | 271 } |
270 } | 272 } |
271 } | 273 } |
272 | 274 |
273 static inline uint8_t aa_blend8(SkPMColor src, U8CPU da, int aa) { | 275 static inline uint8_t aa_blend8(SkPMColor src, U8CPU da, int aa) { |
274 SkASSERT((unsigned)aa <= 255); | 276 SkASSERT((unsigned)aa <= 255); |
275 | 277 |
276 int src_scale = SkAlpha255To256(aa); | 278 int src_scale = SkAlpha255To256(aa); |
277 int sa = SkGetPackedA32(src); | 279 int sa = SkGetPackedA32(src); |
278 int dst_scale = 256 - SkAlphaMul(sa, src_scale); | 280 int dst_scale = 256 - SkAlphaMul(sa, src_scale); |
279 | 281 |
280 return SkToU8((sa * src_scale + da * dst_scale) >> 8); | 282 return SkToU8((sa * src_scale + da * dst_scale) >> 8); |
281 } | 283 } |
282 | 284 |
283 void SkA8_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], | 285 void SkA8_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
284 const int16_t runs[]) { | 286 const int16_t runs[]) { |
285 SkShader* shader = fShader; | 287 SkShader::Context* shaderContext = fShaderContext; |
286 SkXfermode* mode = fXfermode; | 288 SkXfermode* mode = fXfermode; |
287 uint8_t* aaExpand = fAAExpand; | 289 uint8_t* aaExpand = fAAExpand; |
288 SkPMColor* span = fBuffer; | 290 SkPMColor* span = fBuffer; |
289 uint8_t* device = fDevice.getAddr8(x, y); | 291 uint8_t* device = fDevice.getAddr8(x, y); |
290 int opaque = fShader->getFlags() & SkShader::kOpaqueAlpha_Flag; | 292 int opaque = shaderContext->getFlags() & SkShader::kOpaqueAlp
ha_Flag; |
291 | 293 |
292 for (;;) { | 294 for (;;) { |
293 int count = *runs; | 295 int count = *runs; |
294 if (count == 0) { | 296 if (count == 0) { |
295 break; | 297 break; |
296 } | 298 } |
297 int aa = *antialias; | 299 int aa = *antialias; |
298 if (aa) { | 300 if (aa) { |
299 if (opaque && aa == 255 && mode == NULL) { | 301 if (opaque && aa == 255 && mode == NULL) { |
300 memset(device, 0xFF, count); | 302 memset(device, 0xFF, count); |
301 } else { | 303 } else { |
302 shader->shadeSpan(x, y, span, count); | 304 shaderContext->shadeSpan(x, y, span, count); |
303 if (mode) { | 305 if (mode) { |
304 memset(aaExpand, aa, count); | 306 memset(aaExpand, aa, count); |
305 mode->xferA8(device, span, count, aaExpand); | 307 mode->xferA8(device, span, count, aaExpand); |
306 } else { | 308 } else { |
307 for (int i = count - 1; i >= 0; --i) { | 309 for (int i = count - 1; i >= 0; --i) { |
308 device[i] = aa_blend8(span[i], device[i], aa); | 310 device[i] = aa_blend8(span[i], device[i], aa); |
309 } | 311 } |
310 } | 312 } |
311 } | 313 } |
312 } | 314 } |
313 device += count; | 315 device += count; |
314 runs += count; | 316 runs += count; |
315 antialias += count; | 317 antialias += count; |
316 x += count; | 318 x += count; |
317 } | 319 } |
318 } | 320 } |
319 | 321 |
320 void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { | 322 void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
321 if (mask.fFormat == SkMask::kBW_Format) { | 323 if (mask.fFormat == SkMask::kBW_Format) { |
322 this->INHERITED::blitMask(mask, clip); | 324 this->INHERITED::blitMask(mask, clip); |
323 return; | 325 return; |
324 } | 326 } |
325 | 327 |
326 int x = clip.fLeft; | 328 int x = clip.fLeft; |
327 int y = clip.fTop; | 329 int y = clip.fTop; |
328 int width = clip.width(); | 330 int width = clip.width(); |
329 int height = clip.height(); | 331 int height = clip.height(); |
330 uint8_t* device = fDevice.getAddr8(x, y); | 332 uint8_t* device = fDevice.getAddr8(x, y); |
331 const uint8_t* alpha = mask.getAddr8(x, y); | 333 const uint8_t* alpha = mask.getAddr8(x, y); |
| 334 SkShader::Context* shaderContext = fShaderContext; |
332 | 335 |
333 SkPMColor* span = fBuffer; | 336 SkPMColor* span = fBuffer; |
334 | 337 |
335 while (--height >= 0) { | 338 while (--height >= 0) { |
336 fShader->shadeSpan(x, y, span, width); | 339 shaderContext->shadeSpan(x, y, span, width); |
337 if (fXfermode) { | 340 if (fXfermode) { |
338 fXfermode->xferA8(device, span, width, alpha); | 341 fXfermode->xferA8(device, span, width, alpha); |
339 } else { | 342 } else { |
340 for (int i = width - 1; i >= 0; --i) { | 343 for (int i = width - 1; i >= 0; --i) { |
341 device[i] = aa_blend8(span[i], device[i], alpha[i]); | 344 device[i] = aa_blend8(span[i], device[i], alpha[i]); |
342 } | 345 } |
343 } | 346 } |
344 | 347 |
345 y += 1; | 348 y += 1; |
346 device += fDevice.rowBytes(); | 349 device += fDevice.rowBytes(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 while (--height >= 0) { | 425 while (--height >= 0) { |
423 memcpy(dst, src, width); | 426 memcpy(dst, src, width); |
424 dst += dstRB; | 427 dst += dstRB; |
425 src += srcRB; | 428 src += srcRB; |
426 } | 429 } |
427 } | 430 } |
428 | 431 |
429 const SkBitmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) { | 432 const SkBitmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) { |
430 return NULL; | 433 return NULL; |
431 } | 434 } |
OLD | NEW |