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 
8 #include "SkCoreBlitters.h"
9 #include "SkColorData.h"
10 #include "SkShader.h"
11 #include "SkXfermodePriv.h"
12 
13 SkA8_Coverage_Blitter::SkA8_Coverage_Blitter(const SkPixmap& device,
14                              const SkPaint& paint) : SkRasterBlitter(device) {
15     SkASSERT(nullptr == paint.getShader());
16     SkASSERT(paint.isSrcOver());
17     SkASSERT(nullptr == paint.getColorFilter());
18 }
19 
20 void SkA8_Coverage_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
21                                       const int16_t runs[]) {
22     uint8_t* device = fDevice.writable_addr8(x, y);
23     SkDEBUGCODE(int totalCount = 0;)
24 
25     for (;;) {
26         int count = runs[0];
27         SkASSERT(count >= 0);
28         if (count == 0) {
29             return;
30         }
31         if (antialias[0]) {
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) {
44     memset(fDevice.writable_addr8(x, y), 0xFF, width);
45 }
46 
47 void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
48     if (0 == alpha) {
49         return;
50     }
51 
52     uint8_t* dst = fDevice.writable_addr8(x, y);
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) {
61     uint8_t* dst = fDevice.writable_addr8(x, y);
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 
77     uint8_t* dst = fDevice.writable_addr8(x, y);
78     const uint8_t* src = mask.getAddr8(x, y);
79     const size_t srcRB = mask.fRowBytes;
80     const size_t dstRB = fDevice.rowBytes();
81 
82     while (--height >= 0) {
83         memcpy(dst, src, width);
84         dst += dstRB;
85         src += srcRB;
86     }
87 }
88 
89 const SkPixmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) {
90     return nullptr;
91 }
92