Repository navigation
Expand file tree
/
Copy pathSkDraw_text.cpp
More file actions
132 lines (113 loc) · 4.98 KB
/
Copy pathSkDraw_text.cpp
File metadata and controls
132 lines (113 loc) · 4.98 KB
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
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkBitmap.h"
#include "src/base/SkUtils.h"
#include "src/core/SkDraw.h"
#include "src/core/SkFontPriv.h"
#include "src/core/SkMatrixProvider.h"
#include "src/core/SkPaintPriv.h"
#include "src/core/SkRasterClip.h"
#include "src/core/SkScalerContext.h"
#include "src/core/SkStrike.h"
#include "src/text/GlyphRun.h"
#include <climits>
// disable warning : local variable used without having been initialized
#if defined _WIN32
#pragma warning ( push )
#pragma warning ( disable : 4701 )
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
static bool check_glyph_position(SkPoint position) {
// Prevent glyphs from being drawn outside of or straddling the edge of device space.
// Comparisons written a little weirdly so that NaN coordinates are treated safely.
auto gt = [](float a, int b) { return !(a <= (float)b); };
auto lt = [](float a, int b) { return !(a >= (float)b); };
return !(gt(position.fX, INT_MAX - (INT16_MAX + SkTo<int>(UINT16_MAX))) ||
lt(position.fX, INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)) ||
gt(position.fY, INT_MAX - (INT16_MAX + SkTo<int>(UINT16_MAX))) ||
lt(position.fY, INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)));
}
void SkDraw::paintMasks(SkDrawableGlyphBuffer* accepted, const SkPaint& paint) const {
// The size used for a typical blitter.
SkSTArenaAlloc<3308> alloc;
SkBlitter* blitter = SkBlitter::Choose(fDst,
fMatrixProvider->localToDevice(),
paint,
&alloc,
false,
fRC->clipShader(),
SkSurfacePropsCopyOrDefault(fProps));
SkAAClipBlitterWrapper wrapper{*fRC, blitter};
blitter = wrapper.getBlitter();
bool useRegion = fRC->isBW() && !fRC->isRect();
if (useRegion) {
for (auto [variant, pos] : accepted->accepted()) {
const SkGlyph* glyph = variant.glyph();
if (check_glyph_position(pos)) {
SkMask mask = glyph->mask(pos);
SkRegion::Cliperator clipper(fRC->bwRgn(), mask.fBounds);
if (!clipper.done()) {
if (SkMask::kARGB32_Format == mask.fFormat) {
SkBitmap bm;
bm.installPixels(SkImageInfo::MakeN32Premul(mask.fBounds.size()),
mask.fImage,
mask.fRowBytes);
this->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), paint);
} else {
const SkIRect& cr = clipper.rect();
do {
blitter->blitMask(mask, cr);
clipper.next();
} while (!clipper.done());
}
}
}
}
} else {
SkIRect clipBounds = fRC->isBW() ? fRC->bwRgn().getBounds()
: fRC->aaRgn().getBounds();
for (auto [variant, pos] : accepted->accepted()) {
const SkGlyph* glyph = variant.glyph();
if (check_glyph_position(pos)) {
SkMask mask = glyph->mask(pos);
SkIRect storage;
const SkIRect* bounds = &mask.fBounds;
// this extra test is worth it, assuming that most of the time it succeeds
// since we can avoid writing to storage
if (!clipBounds.containsNoEmptyCheck(mask.fBounds)) {
if (!storage.intersect(mask.fBounds, clipBounds)) {
continue;
}
bounds = &storage;
}
if (SkMask::kARGB32_Format == mask.fFormat) {
SkBitmap bm;
bm.installPixels(SkImageInfo::MakeN32Premul(mask.fBounds.size()),
mask.fImage,
mask.fRowBytes);
this->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), paint);
} else {
blitter->blitMask(mask, *bounds);
}
}
}
}
}
void SkDraw::drawGlyphRunList(SkCanvas* canvas,
SkGlyphRunListPainterCPU* glyphPainter,
const sktext::GlyphRunList& glyphRunList,
const SkPaint& paint) const {
SkDEBUGCODE(this->validate();)
if (fRC->isEmpty()) {
return;
}
glyphPainter->drawForBitmapDevice(canvas, this, glyphRunList, paint,
fMatrixProvider->localToDevice());
}
#if defined _WIN32
#pragma warning ( pop )
#endif