1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkSpriteBlitter.h"
#include "SkArenaAlloc.h"
#include "SkBlitRow.h"
#include "SkColorFilter.h"
#include "SkColorData.h"
#include "SkTemplates.h"
#include "SkUtils.h"
#include "SkXfermodePriv.h"
///////////////////////////////////////////////////////////////////////////////
static void S32_src(uint16_t dst[], const SkPMColor src[], int count) {
for (int i = 0; i < count; ++i) {
dst[i] = SkPixel32ToPixel16(src[i]);
}
}
static void S32_srcover(uint16_t dst[], const SkPMColor src[], int count) {
for (int i = 0; i < count; ++i) {
dst[i] = SkSrcOver32To16(src[i], dst[i]);
}
}
class Sprite_D16_S32 : public SkSpriteBlitter {
public:
Sprite_D16_S32(const SkPixmap& src, SkBlendMode mode) : INHERITED(src) {
SkASSERT(src.colorType() == kN32_SkColorType);
SkASSERT(mode == SkBlendMode::kSrc || mode == SkBlendMode::kSrcOver);
fUseSrcOver = (mode == SkBlendMode::kSrcOver) && !src.isOpaque();
}
void blitRect(int x, int y, int width, int height) override {
SkASSERT(width > 0 && height > 0);
uint16_t* SK_RESTRICT dst = fDst.writable_addr16(x, y);
const uint32_t* SK_RESTRICT src = fSource.addr32(x - fLeft, y - fTop);
size_t dstRB = fDst.rowBytes();
size_t srcRB = fSource.rowBytes();
do {
if (fUseSrcOver) {
S32_srcover(dst, src, width);
} else {
S32_src(dst, src, width);
}
dst = (uint16_t* SK_RESTRICT)((char*)dst + dstRB);
src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB);
} while (--height != 0);
}
private:
bool fUseSrcOver;
typedef SkSpriteBlitter INHERITED;
};
SkSpriteBlitter* SkSpriteBlitter::ChooseL565(const SkPixmap& source, const SkPaint& paint,
SkArenaAlloc* allocator) {
SkASSERT(allocator != nullptr);
if (paint.getColorFilter() != nullptr) {
return nullptr;
}
if (paint.getMaskFilter() != nullptr) {
return nullptr;
}
U8CPU alpha = paint.getAlpha();
if (alpha != 0xFF) {
return nullptr;
}
if (source.colorType() == kN32_SkColorType) {
switch (paint.getBlendMode()) {
case SkBlendMode::kSrc:
case SkBlendMode::kSrcOver:
return allocator->make<Sprite_D16_S32>(source, paint.getBlendMode());
default:
break;
}
}
return nullptr;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
static unsigned div255(unsigned a, unsigned b) {
return (a * b * 257 + 127) >> 16;
}
static void S32_src_da8(uint8_t dst[], const SkPMColor src[], int count) {
for (int i = 0; i < count; ++i) {
dst[i] = SkGetPackedA32(src[i]);
}
}
static void S32_srcover_da8(uint8_t dst[], const SkPMColor src[], int count) {
for (int i = 0; i < count; ++i) {
SkPMColor c = src[i];
if (c) {
unsigned a = SkGetPackedA32(c);
if (a == 0xFF) {
dst[i] = 0xFF;
} else {
dst[i] = a + div255(255 - a, dst[i]);
}
}
}
}
class Sprite_D8_S32 : public SkSpriteBlitter {
public:
Sprite_D8_S32(const SkPixmap& src, SkBlendMode mode) : INHERITED(src) {
SkASSERT(src.colorType() == kN32_SkColorType);
SkASSERT(mode == SkBlendMode::kSrc || mode == SkBlendMode::kSrcOver);
fUseSrcOver = (mode == SkBlendMode::kSrcOver) && !src.isOpaque();
}
void blitRect(int x, int y, int width, int height) override {
SkASSERT(width > 0 && height > 0);
uint8_t* SK_RESTRICT dst = fDst.writable_addr8(x, y);
const uint32_t* SK_RESTRICT src = fSource.addr32(x - fLeft, y - fTop);
size_t dstRB = fDst.rowBytes();
size_t srcRB = fSource.rowBytes();
do {
if (fUseSrcOver) {
S32_srcover_da8(dst, src, width);
} else {
S32_src_da8(dst, src, width);
}
dst = (uint8_t* SK_RESTRICT)((char*)dst + dstRB);
src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB);
} while (--height != 0);
}
private:
bool fUseSrcOver;
typedef SkSpriteBlitter INHERITED;
};
SkSpriteBlitter* SkSpriteBlitter::ChooseLA8(const SkPixmap& source, const SkPaint& paint,
SkArenaAlloc* allocator) {
SkASSERT(allocator != nullptr);
if (paint.getColorFilter() != nullptr) {
return nullptr;
}
if (paint.getMaskFilter() != nullptr) {
return nullptr;
}
U8CPU alpha = paint.getAlpha();
if (alpha != 0xFF) {
return nullptr;
}
if (source.colorType() == kN32_SkColorType) {
switch (paint.getBlendMode()) {
case SkBlendMode::kSrc:
case SkBlendMode::kSrcOver:
return allocator->make<Sprite_D8_S32>(source, paint.getBlendMode());
default:
break;
}
}
return nullptr;
}
|