epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SkCoreBlitters.h" |
Cary Clark | a4083c9 | 2017-09-15 11:59:23 -0400 | [diff] [blame] | 9 | #include "SkColorData.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #include "SkShader.h" |
Mike Reed | d470673 | 2016-11-15 16:44:34 -0500 | [diff] [blame] | 11 | #include "SkXfermodePriv.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 13 | SkA8_Coverage_Blitter::SkA8_Coverage_Blitter(const SkPixmap& device, |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 14 | const SkPaint& paint) : SkRasterBlitter(device) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 15 | SkASSERT(nullptr == paint.getShader()); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 16 | SkASSERT(paint.isSrcOver()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 17 | SkASSERT(nullptr == paint.getColorFilter()); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void SkA8_Coverage_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
| 21 | const int16_t runs[]) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 22 | uint8_t* device = fDevice.writable_addr8(x, y); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 23 | SkDEBUGCODE(int totalCount = 0;) |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 24 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 25 | for (;;) { |
| 26 | int count = runs[0]; |
| 27 | SkASSERT(count >= 0); |
| 28 | if (count == 0) { |
| 29 | return; |
| 30 | } |
reed@google.com | b95d9f5 | 2013-11-08 17:50:14 +0000 | [diff] [blame] | 31 | if (antialias[0]) { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 32 | memset(device, antialias[0], count); |
| 33 | } |
| 34 | runs += count; |
| 35 | antialias += count; |
| 36 | device += count; |
| 37 | |
| 38 | SkDEBUGCODE(totalCount += count;) |
| 39 | } |
| 40 | SkASSERT(fDevice.width() == totalCount); |
| 41 | } |
| 42 | |
| 43 | void SkA8_Coverage_Blitter::blitH(int x, int y, int width) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 44 | memset(fDevice.writable_addr8(x, y), 0xFF, width); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 48 | if (0 == alpha) { |
| 49 | return; |
| 50 | } |
reed@google.com | b95d9f5 | 2013-11-08 17:50:14 +0000 | [diff] [blame] | 51 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 52 | uint8_t* dst = fDevice.writable_addr8(x, y); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 53 | const size_t dstRB = fDevice.rowBytes(); |
| 54 | while (--height >= 0) { |
| 55 | *dst = alpha; |
| 56 | dst += dstRB; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void SkA8_Coverage_Blitter::blitRect(int x, int y, int width, int height) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 61 | uint8_t* dst = fDevice.writable_addr8(x, y); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 62 | const size_t dstRB = fDevice.rowBytes(); |
| 63 | while (--height >= 0) { |
| 64 | memset(dst, 0xFF, width); |
| 65 | dst += dstRB; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void SkA8_Coverage_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 70 | SkASSERT(SkMask::kA8_Format == mask.fFormat); |
| 71 | |
| 72 | int x = clip.fLeft; |
| 73 | int y = clip.fTop; |
| 74 | int width = clip.width(); |
| 75 | int height = clip.height(); |
| 76 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 77 | uint8_t* dst = fDevice.writable_addr8(x, y); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 78 | const uint8_t* src = mask.getAddr8(x, y); |
| 79 | const size_t srcRB = mask.fRowBytes; |
| 80 | const size_t dstRB = fDevice.rowBytes(); |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 81 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 82 | while (--height >= 0) { |
| 83 | memcpy(dst, src, width); |
| 84 | dst += dstRB; |
| 85 | src += srcRB; |
| 86 | } |
| 87 | } |
| 88 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 89 | const SkPixmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 90 | return nullptr; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 91 | } |