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
|
/*
* 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 "SkCoreBlitters.h"
#include "SkColorData.h"
#include "SkShader.h"
#include "SkUtils.h"
#include "SkXfermodePriv.h"
#include "SkBlitMask.h"
#include "SkColorData.h"
#include "SkNx.h"
static void D16_S32X_src(uint16_t dst[], const SkPMColor src[], int count, uint8_t coverage) {
SkASSERT(coverage == 0xFF);
for (int i = 0; i < count; ++i) {
dst[i] = SkPixel32ToPixel16(src[i]);
}
}
static void D16_S32X_src_coverage(uint16_t dst[], const SkPMColor src[], int count,
uint8_t coverage) {
switch (coverage) {
case 0: break;
case 0xFF:
for (int i = 0; i < count; ++i) {
dst[i] = SkPixel32ToPixel16(src[i]);
}
break;
default:
unsigned scale = coverage + (coverage >> 7);
for (int i = 0; i < count; ++i) {
dst[i] = SkSrcOver32To16(SkAlphaMulQ(src[i], scale), dst[i]);
}
break;
}
}
static void D16_S32A_srcover(uint16_t dst[], const SkPMColor src[], int count, uint8_t coverage) {
SkASSERT(coverage == 0xFF);
for (int i = 0; i < count; ++i) {
dst[i] = SkSrcOver32To16(src[i], dst[i]);
}
}
static void D16_S32A_srcover_coverage(uint16_t dst[], const SkPMColor src[], int count,
uint8_t coverage) {
switch (coverage) {
case 0: break;
case 0xFF:
for (int i = 0; i < count; ++i) {
dst[i] = SkSrcOver32To16(src[i], dst[i]);
}
break;
default:
unsigned scale = coverage + (coverage >> 7);
for (int i = 0; i < count; ++i) {
dst[i] = SkSrcOver32To16(SkAlphaMulQ(src[i], scale), dst[i]);
}
break;
}
}
bool SkRGB565_Shader_Blitter::Supports(const SkPixmap& device, const SkPaint& paint) {
if (device.colorType() != kRGB_565_SkColorType) {
return false;
}
if (device.colorSpace()) {
return false;
}
if (paint.getBlendMode() != SkBlendMode::kSrcOver &&
paint.getBlendMode() != SkBlendMode::kSrc) {
return false;
}
if (paint.isLCDRenderText()) {
return false;
}
if (paint.isDither()) {
return false;
}
return true;
}
SkRGB565_Shader_Blitter::SkRGB565_Shader_Blitter(const SkPixmap& device,
const SkPaint& paint, SkShaderBase::Context* shaderContext)
: INHERITED(device, paint, shaderContext)
{
SkASSERT(shaderContext);
SkASSERT(Supports(device, paint));
fBuffer = (SkPMColor*)sk_malloc_throw(device.width() * (sizeof(SkPMColor)));
bool isOpaque = SkToBool(shaderContext->getFlags() & SkShaderBase::kOpaqueAlpha_Flag);
if (paint.getBlendMode() == SkBlendMode::kSrc || isOpaque) {
fBlend = D16_S32X_src;
fBlendCoverage = D16_S32X_src_coverage;
} else { // srcover
fBlend = isOpaque ? D16_S32X_src : D16_S32A_srcover;
fBlendCoverage = isOpaque ? D16_S32X_src_coverage : D16_S32A_srcover_coverage;
}
}
SkRGB565_Shader_Blitter::~SkRGB565_Shader_Blitter() {
sk_free(fBuffer);
}
void SkRGB565_Shader_Blitter::blitH(int x, int y, int width) {
SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width());
uint16_t* device = fDevice.writable_addr16(x, y);
SkPMColor* span = fBuffer;
fShaderContext->shadeSpan(x, y, span, width);
fBlend(device, span, width, 0xFF);
}
void SkRGB565_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha coverage[],
const int16_t runs[]) {
SkPMColor* span = fBuffer;
uint16_t* device = fDevice.writable_addr16(x, y);
auto* shaderContext = fShaderContext;
for (;;) {
int count = *runs;
if (count <= 0) {
break;
}
int aa = *coverage;
if (aa) {
shaderContext->shadeSpan(x, y, span, count);
fBlendCoverage(device, span, count, aa);
}
device += count;
runs += count;
coverage += count;
x += count;
}
}
|