Flutter Engine
The Flutter Engine
SkAAClip.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 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
8#ifndef SkAAClip_DEFINED
9#define SkAAClip_DEFINED
10
12#include "include/core/SkRect.h"
15#include "src/core/SkBlitter.h"
16#include <cstdint>
18
19class SkPath;
20class SkRegion;
21enum class SkClipOp;
22struct SkMask;
23struct SkMaskBuilder;
24
25class SkAAClip {
26public:
27 SkAAClip();
28 SkAAClip(const SkAAClip&);
29 ~SkAAClip();
30
32
33 bool isEmpty() const { return nullptr == fRunHead; }
34 const SkIRect& getBounds() const { return fBounds; }
35
36 // Returns true iff the clip is not empty, and is just a hard-edged rect (no partial alpha).
37 // If true, getBounds() can be used in place of this clip.
38 bool isRect() const;
39
40 bool setEmpty();
41 bool setRect(const SkIRect&);
42 bool setPath(const SkPath&, const SkIRect& bounds, bool doAA = true);
43 bool setRegion(const SkRegion&);
44
45 bool op(const SkIRect&, SkClipOp);
46 bool op(const SkRect&, SkClipOp, bool doAA);
47 bool op(const SkAAClip&, SkClipOp);
48
49 bool translate(int dx, int dy, SkAAClip* dst) const;
50
51 /**
52 * Allocates a mask the size of the aaclip, and expands its data into
53 * the mask, using kA8_Format. Used for tests and visualization purposes.
54 */
55 void copyToMask(SkMaskBuilder*) const;
56
57 bool quickContains(const SkIRect& r) const {
58 return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom);
59 }
60
61#ifdef SK_DEBUG
62 void validate() const;
63 void debug(bool compress_y=false) const;
64#else
65 void validate() const {}
66 void debug(bool compress_y=false) const {}
67#endif
68
69private:
70 class Builder;
71 struct RunHead;
72 friend class SkAAClipBlitter;
73
75 RunHead* fRunHead;
76
77 void freeRuns();
78
79 bool quickContains(int left, int top, int right, int bottom) const;
80
81 bool trimBounds();
82 bool trimTopBottom();
83 bool trimLeftRight();
84
85 // For SkAAClipBlitter and quickContains
86 const uint8_t* findRow(int y, int* lastYForRow = nullptr) const;
87 const uint8_t* findX(const uint8_t data[], int x, int* initialCount = nullptr) const;
88};
89
90///////////////////////////////////////////////////////////////////////////////
91
92class SkAAClipBlitter : public SkBlitter {
93public:
94 SkAAClipBlitter() : fScanlineScratch(nullptr) {}
95 ~SkAAClipBlitter() override;
96
97 void init(SkBlitter* blitter, const SkAAClip* aaclip) {
98 SkASSERT(aaclip && !aaclip->isEmpty());
99 fBlitter = blitter;
100 fAAClip = aaclip;
101 fAAClipBounds = aaclip->getBounds();
102 }
103
104 void blitH(int x, int y, int width) override;
105 void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]) override;
106 void blitV(int x, int y, int height, SkAlpha alpha) override;
107 void blitRect(int x, int y, int width, int height) override;
108 void blitMask(const SkMask&, const SkIRect& clip) override;
109
110private:
111 SkBlitter* fBlitter;
112 const SkAAClip* fAAClip;
113 SkIRect fAAClipBounds;
114
115 // point into fScanlineScratch
116 int16_t* fRuns;
117 SkAlpha* fAA;
118
119 enum {
120 kSize = 32 * 32
121 };
122 SkAutoSMalloc<kSize> fGrayMaskScratch; // used for blitMask
123 void* fScanlineScratch; // enough for a mask at 32bit, or runs+aa
124
125 void ensureRunsAndAA();
126};
127
128#endif
const SkRect fBounds
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkClipOp
Definition: SkClipOp.h:13
uint8_t SkAlpha
Definition: SkColor.h:26
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
void init(SkBlitter *blitter, const SkAAClip *aaclip)
Definition: SkAAClip.h:97
void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]) override
Definition: SkAAClip.cpp:1735
void blitRect(int x, int y, int width, int height) override
Blit a solid rectangle one or more pixels wide.
Definition: SkAAClip.cpp:1776
void blitH(int x, int y, int width) override
Blit a horizontal run of one or more pixels.
Definition: SkAAClip.cpp:1665
~SkAAClipBlitter() override
Definition: SkAAClip.cpp:1649
void blitMask(const SkMask &, const SkIRect &clip) override
Definition: SkAAClip.cpp:1909
void blitV(int x, int y, int height, SkAlpha alpha) override
Blit a vertical run of pixels with a constant alpha value.
Definition: SkAAClip.cpp:1748
void validate() const
Definition: SkAAClip.h:65
void debug(bool compress_y=false) const
Definition: SkAAClip.h:66
bool setEmpty()
Definition: SkAAClip.cpp:1264
SkAAClip & operator=(const SkAAClip &)
Definition: SkAAClip.cpp:1249
bool setRect(const SkIRect &)
Definition: SkAAClip.cpp:1271
bool translate(int dx, int dy, SkAAClip *dst) const
Definition: SkAAClip.cpp:1524
const SkIRect & getBounds() const
Definition: SkAAClip.h:34
bool setPath(const SkPath &, const SkIRect &bounds, bool doAA=true)
Definition: SkAAClip.cpp:1401
bool op(const SkIRect &, SkClipOp)
Definition: SkAAClip.cpp:1459
void copyToMask(SkMaskBuilder *) const
Definition: SkAAClip.cpp:851
bool quickContains(const SkIRect &r) const
Definition: SkAAClip.h:57
bool isEmpty() const
Definition: SkAAClip.h:33
bool isRect() const
Definition: SkAAClip.cpp:1285
bool setRegion(const SkRegion &)
Definition: SkAAClip.cpp:1313
Definition: SkPath.h:59
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
DlVertices::Builder Builder
dst
Definition: cp.py:12
int32_t height
int32_t width
Definition: SkRect.h:32
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35
Definition: SkMask.h:25
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63