Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkDraw_text.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google Inc.
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
11#include "include/core/SkRect.h"
16#include "src/base/SkZip.h"
17#include "src/core/SkAAClip.h"
18#include "src/core/SkBlitter.h"
19#include "src/core/SkDraw.h"
20#include "src/core/SkGlyph.h"
22#include "src/core/SkMask.h"
25
26#include <cstdint>
27#include <climits>
28
29class SkCanvas;
30class SkPaint;
31namespace sktext { class GlyphRunList; }
32
33// disable warning : local variable used without having been initialized
34#if defined _WIN32
35#pragma warning ( push )
36#pragma warning ( disable : 4701 )
37#endif
38
39////////////////////////////////////////////////////////////////////////////////////////////////////
40
41static bool check_glyph_position(SkPoint position) {
42 // Prevent glyphs from being drawn outside of or straddling the edge of device space.
43 // Comparisons written a little weirdly so that NaN coordinates are treated safely.
44 auto gt = [](float a, int b) { return !(a <= (float)b); };
45 auto lt = [](float a, int b) { return !(a >= (float)b); };
46 return !(gt(position.fX, INT_MAX - (INT16_MAX + SkTo<int>(UINT16_MAX))) ||
47 lt(position.fX, INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)) ||
48 gt(position.fY, INT_MAX - (INT16_MAX + SkTo<int>(UINT16_MAX))) ||
49 lt(position.fY, INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)));
50}
51
53 // The size used for a typical blitter.
56 *fCTM,
57 paint,
58 &alloc,
59 false,
60 fRC->clipShader(),
62
63 SkAAClipBlitterWrapper wrapper{*fRC, blitter};
64 blitter = wrapper.getBlitter();
65
66 bool useRegion = fRC->isBW() && !fRC->isRect();
67
68 if (useRegion) {
69 for (auto [glyph, pos] : accepted) {
71 SkMask mask = glyph->mask(pos);
72
73 SkRegion::Cliperator clipper(fRC->bwRgn(), mask.fBounds);
74
75 if (!clipper.done()) {
76 if (SkMask::kARGB32_Format == mask.fFormat) {
77 SkBitmap bm;
79 const_cast<uint8_t*>(mask.fImage),
80 mask.fRowBytes);
81 bm.setImmutable();
82 this->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), paint);
83 } else {
84 const SkIRect& cr = clipper.rect();
85 do {
86 blitter->blitMask(mask, cr);
87 clipper.next();
88 } while (!clipper.done());
89 }
90 }
91 }
92 }
93 } else {
94 SkIRect clipBounds = fRC->isBW() ? fRC->bwRgn().getBounds()
95 : fRC->aaRgn().getBounds();
96 for (auto [glyph, pos] : accepted) {
98 SkMask mask = glyph->mask(pos);
99 SkIRect storage;
100 const SkIRect* bounds = &mask.fBounds;
101
102 // this extra test is worth it, assuming that most of the time it succeeds
103 // since we can avoid writing to storage
104 if (!clipBounds.containsNoEmptyCheck(mask.fBounds)) {
105 if (!storage.intersect(mask.fBounds, clipBounds)) {
106 continue;
107 }
108 bounds = &storage;
109 }
110
111 if (SkMask::kARGB32_Format == mask.fFormat) {
112 SkBitmap bm;
114 const_cast<uint8_t*>(mask.fImage),
115 mask.fRowBytes);
116 bm.setImmutable();
117 this->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), paint);
118 } else {
119 blitter->blitMask(mask, *bounds);
120 }
121 }
122 }
123 }
124}
125
127 SkGlyphRunListPainterCPU* glyphPainter,
128 const sktext::GlyphRunList& glyphRunList,
129 const SkPaint& paint) const {
130
131 SkDEBUGCODE(this->validate();)
132
133 if (fRC->isEmpty()) {
134 return;
135 }
136
137 glyphPainter->drawForBitmapDevice(canvas, this, glyphRunList, paint, *fCTM);
138}
139
140#if defined _WIN32
141#pragma warning ( pop )
142#endif
143
SkPoint pos
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
static bool check_glyph_position(SkPoint position)
static SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps *props)
const SkIRect & getBounds() const
Definition SkAAClip.h:33
void setImmutable()
Definition SkBitmap.cpp:400
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
Definition SkBitmap.cpp:323
static SkBlitter * Choose(const SkPixmap &dst, const SkMatrix &ctm, const SkPaint &paint, SkArenaAlloc *, bool drawCoverage, sk_sp< SkShader > clipShader, const SkSurfaceProps &props)
virtual void blitMask(const SkMask &, const SkIRect &clip)
const SkSurfaceProps * fProps
Definition SkDrawBase.h:155
const SkRasterClip * fRC
Definition SkDrawBase.h:154
SkPixmap fDst
Definition SkDrawBase.h:151
void validate() const
Definition SkDrawBase.h:160
const SkMatrix * fCTM
Definition SkDrawBase.h:153
void drawSprite(const SkBitmap &, int x, int y, const SkPaint &) const
Definition SkDraw.cpp:376
void drawGlyphRunList(SkCanvas *canvas, SkGlyphRunListPainterCPU *glyphPainter, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint) const
void paintMasks(SkZip< const SkGlyph *, SkPoint > accepted, const SkPaint &paint) const override
void drawForBitmapDevice(SkCanvas *canvas, const BitmapDevicePainter *bitmapDevice, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint, const SkMatrix &drawMatrix)
const SkAAClip & aaRgn() const
const SkRegion & bwRgn() const
sk_sp< SkShader > clipShader() const
bool isRect() const
bool isBW() const
bool isEmpty() const
const SkIRect & rect() const
Definition SkRegion.h:551
const SkIRect & getBounds() const
Definition SkRegion.h:165
Definition SkZip.h:25
const Paint & paint
static bool b
struct MyStruct a[10]
constexpr int32_t x() const
Definition SkRect.h:141
constexpr int32_t y() const
Definition SkRect.h:148
bool intersect(const SkIRect &r)
Definition SkRect.h:513
bool containsNoEmptyCheck(const SkIRect &r) const
Definition SkRect.h:499
constexpr SkISize size() const
Definition SkRect.h:172
static SkImageInfo MakeN32Premul(int width, int height)
const uint32_t fRowBytes
Definition SkMask.h:43
@ kARGB32_Format
SkPMColor.
Definition SkMask.h:30
uint8_t const *const fImage
Definition SkMask.h:41
const SkIRect fBounds
Definition SkMask.h:42
const Format fFormat
Definition SkMask.h:44
float fX
x-axis value
float fY
y-axis value