Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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>
17
18class SkPath;
19class SkRegion;
20enum class SkClipOp;
21struct SkMask;
22struct SkMaskBuilder;
23
24class SkAAClip {
25public:
26 SkAAClip();
27 SkAAClip(const SkAAClip&);
28 ~SkAAClip();
29
31
32 bool isEmpty() const { return nullptr == fRunHead; }
33 const SkIRect& getBounds() const { return fBounds; }
34
35 // Returns true iff the clip is not empty, and is just a hard-edged rect (no partial alpha).
36 // If true, getBounds() can be used in place of this clip.
37 bool isRect() const;
38
39 bool setEmpty();
40 bool setRect(const SkIRect&);
41 bool setPath(const SkPath&, const SkIRect& bounds, bool doAA = true);
42 bool setRegion(const SkRegion&);
43
44 bool op(const SkIRect&, SkClipOp);
45 bool op(const SkRect&, SkClipOp, bool doAA);
46 bool op(const SkAAClip&, SkClipOp);
47
48 bool translate(int dx, int dy, SkAAClip* dst) const;
49
50 /**
51 * Allocates a mask the size of the aaclip, and expands its data into
52 * the mask, using kA8_Format. Used for tests and visualization purposes.
53 */
54 void copyToMask(SkMaskBuilder*) const;
55
56 bool quickContains(const SkIRect& r) const {
57 return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom);
58 }
59
60#ifdef SK_DEBUG
61 void validate() const;
62 void debug(bool compress_y=false) const;
63#else
64 void validate() const {}
65 void debug(bool compress_y=false) const {}
66#endif
67
68private:
69 class Builder;
70 struct RunHead;
71 friend class SkAAClipBlitter;
72
74 RunHead* fRunHead;
75
76 void freeRuns();
77
78 bool quickContains(int left, int top, int right, int bottom) const;
79
80 bool trimBounds();
81 bool trimTopBottom();
82 bool trimLeftRight();
83
84 // For SkAAClipBlitter and quickContains
85 const uint8_t* findRow(int y, int* lastYForRow = nullptr) const;
86 const uint8_t* findX(const uint8_t data[], int x, int* initialCount = nullptr) const;
87};
88
89///////////////////////////////////////////////////////////////////////////////
90
91class SkAAClipBlitter : public SkBlitter {
92public:
93 SkAAClipBlitter() : fScanlineScratch(nullptr) {}
94 ~SkAAClipBlitter() override;
95
96 void init(SkBlitter* blitter, const SkAAClip* aaclip) {
97 SkASSERT(aaclip && !aaclip->isEmpty());
98 fBlitter = blitter;
99 fAAClip = aaclip;
100 fAAClipBounds = aaclip->getBounds();
101 }
102
103 void blitH(int x, int y, int width) override;
104 void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]) override;
105 void blitV(int x, int y, int height, SkAlpha alpha) override;
106 void blitRect(int x, int y, int width, int height) override;
107 void blitMask(const SkMask&, const SkIRect& clip) override;
108
109private:
110 SkBlitter* fBlitter;
111 const SkAAClip* fAAClip;
112 SkIRect fAAClipBounds;
113
114 // point into fScanlineScratch
115 int16_t* fRuns;
116 SkAlpha* fAA;
117
118 enum {
119 kSize = 32 * 32
120 };
121 SkAutoSMalloc<kSize> fGrayMaskScratch; // used for blitMask
122 void* fScanlineScratch; // enough for a mask at 32bit, or runs+aa
123
124 void ensureRunsAndAA();
125};
126
127#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:3824
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:96
void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]) override
void blitRect(int x, int y, int width, int height) override
Blit a solid rectangle one or more pixels wide.
void blitH(int x, int y, int width) override
Blit a horizontal run of one or more pixels.
~SkAAClipBlitter() override
void blitMask(const SkMask &, const SkIRect &clip) override
void blitV(int x, int y, int height, SkAlpha alpha) override
Blit a vertical run of pixels with a constant alpha value.
void validate() const
Definition SkAAClip.h:64
void debug(bool compress_y=false) const
Definition SkAAClip.h:65
bool setEmpty()
SkAAClip & operator=(const SkAAClip &)
bool setRect(const SkIRect &)
bool translate(int dx, int dy, SkAAClip *dst) const
const SkIRect & getBounds() const
Definition SkAAClip.h:33
bool setPath(const SkPath &, const SkIRect &bounds, bool doAA=true)
bool op(const SkIRect &, SkClipOp)
void copyToMask(SkMaskBuilder *) const
Definition SkAAClip.cpp:851
bool quickContains(const SkIRect &r) const
Definition SkAAClip.h:56
bool isEmpty() const
Definition SkAAClip.h:32
bool isRect() const
bool setRegion(const SkRegion &)
double y
double x
int32_t height
int32_t width
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