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
|
/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmap.h"
#include "SkMask.h"
#ifndef ClearLow3Bits_DEFINED
#define ClearLow3Bits_DEFINED
#define ClearLow3Bits(x) ((unsigned)(x) >> 3 << 3)
#endif
/*
SK_BLITBWMASK_NAME name of function(const SkBitmap& bitmap, const SkMask& mask, const SkIRect& clip, SK_BLITBWMASK_ARGS)
SK_BLITBWMASK_ARGS list of additional arguments to SK_BLITBWMASK_NAME, beginning with a comma
SK_BLITBWMASK_BLIT8 name of function(U8CPU byteMask, SK_BLITBWMASK_DEVTYPE* dst, int x, int y)
SK_BLITBWMASK_GETADDR either writable_addr[8,16,32]
SK_BLITBWMASK_DEVTYPE either U32 or U16 or U8
*/
static void SK_BLITBWMASK_NAME(const SkPixmap& dst, const SkMask& srcMask,
const SkIRect& clip SK_BLITBWMASK_ARGS) {
SkASSERT(clip.fRight <= srcMask.fBounds.fRight);
int cx = clip.fLeft;
int cy = clip.fTop;
int maskLeft = srcMask.fBounds.fLeft;
unsigned mask_rowBytes = srcMask.fRowBytes;
size_t bitmap_rowBytes = dst.rowBytes();
unsigned height = clip.height();
SkASSERT(mask_rowBytes != 0);
SkASSERT(bitmap_rowBytes != 0);
SkASSERT(height != 0);
const uint8_t* bits = srcMask.getAddr1(cx, cy);
SK_BLITBWMASK_DEVTYPE* device = dst.SK_BLITBWMASK_GETADDR(cx, cy);
if (cx == maskLeft && clip.fRight == srcMask.fBounds.fRight)
{
do {
SK_BLITBWMASK_DEVTYPE* dst = device;
unsigned rb = mask_rowBytes;
do {
U8CPU mask = *bits++;
SK_BLITBWMASK_BLIT8(mask, dst);
dst += 8;
} while (--rb != 0);
device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
} while (--height != 0);
}
else
{
int left_edge = cx - maskLeft;
SkASSERT(left_edge >= 0);
int rite_edge = clip.fRight - maskLeft;
SkASSERT(rite_edge > left_edge);
int left_mask = 0xFF >> (left_edge & 7);
int rite_mask = 0xFF << (8 - (rite_edge & 7));
rite_mask &= 0xFF; // only want low-8 bits of mask
int full_runs = (rite_edge >> 3) - ((left_edge + 7) >> 3);
// check for empty right mask, so we don't read off the end (or go slower than we need to)
if (rite_mask == 0)
{
SkASSERT(full_runs >= 0);
full_runs -= 1;
rite_mask = 0xFF;
}
if (left_mask == 0xFF)
full_runs -= 1;
// back up manually so we can keep in sync with our byte-aligned src
// and not trigger an assert from the getAddr## function
device -= left_edge & 7;
if (full_runs < 0)
{
left_mask &= rite_mask;
SkASSERT(left_mask != 0);
do {
U8CPU mask = *bits & left_mask;
SK_BLITBWMASK_BLIT8(mask, device);
bits += mask_rowBytes;
device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
} while (--height != 0);
}
else
{
do {
int runs = full_runs;
SK_BLITBWMASK_DEVTYPE* dst = device;
const uint8_t* b = bits;
U8CPU mask;
mask = *b++ & left_mask;
SK_BLITBWMASK_BLIT8(mask, dst);
dst += 8;
while (--runs >= 0)
{
mask = *b++;
SK_BLITBWMASK_BLIT8(mask, dst);
dst += 8;
}
mask = *b & rite_mask;
SK_BLITBWMASK_BLIT8(mask, dst);
bits += mask_rowBytes;
device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
} while (--height != 0);
}
}
}
#undef SK_BLITBWMASK_NAME
#undef SK_BLITBWMASK_ARGS
#undef SK_BLITBWMASK_BLIT8
#undef SK_BLITBWMASK_GETADDR
#undef SK_BLITBWMASK_DEVTYPE
#undef SK_BLITBWMASK_DOROWSETUP
|