3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #ifndef SkAAClip_DEFINED
10 #define SkAAClip_DEFINED
12 #include "SkBlitter.h"
18 SkAAClip(const SkAAClip&);
21 SkAAClip& operator=(const SkAAClip&);
22 friend bool operator==(const SkAAClip&, const SkAAClip&);
23 friend bool operator!=(const SkAAClip& a, const SkAAClip& b) {
29 bool isEmpty() const { return NULL == fRunHead; }
30 const SkIRect& getBounds() const { return fBounds; }
32 // Returns true iff the clip is not empty, and is just a hard-edged rect (no partial alpha).
33 // If true, getBounds() can be used in place of this clip.
37 bool setRect(const SkIRect&);
38 bool setRect(const SkRect&, bool doAA = true);
39 bool setPath(const SkPath&, const SkRegion* clip = NULL, bool doAA = true);
40 bool setRegion(const SkRegion&);
41 bool set(const SkAAClip&);
43 bool op(const SkAAClip&, const SkAAClip&, SkRegion::Op);
46 bool op(const SkIRect&, SkRegion::Op);
47 bool op(const SkRect&, SkRegion::Op, bool doAA);
48 bool op(const SkAAClip&, SkRegion::Op);
50 bool translate(int dx, int dy, SkAAClip* dst) const;
51 bool translate(int dx, int dy) {
52 return this->translate(dx, dy, this);
56 * Allocates a mask the size of the aaclip, and expands its data into
57 * the mask, using kA8_Format
59 void copyToMask(SkMask*) const;
63 bool quickContains(int left, int top, int right, int bottom) const;
64 bool quickContains(const SkIRect& r) const {
65 return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom);
68 const uint8_t* findRow(int y, int* lastYForRow = NULL) const;
69 const uint8_t* findX(const uint8_t data[], int x, int* initialCount = NULL) const;
77 void validate() const;
78 void debug(bool compress_y=false) const;
80 void validate() const {}
81 void debug(bool compress_y=false) const {}
95 friend class BuilderBlitter;
98 ///////////////////////////////////////////////////////////////////////////////
100 class SkAAClipBlitter : public SkBlitter {
102 SkAAClipBlitter() : fScanlineScratch(NULL) {}
103 virtual ~SkAAClipBlitter();
105 void init(SkBlitter* blitter, const SkAAClip* aaclip) {
106 SkASSERT(aaclip && !aaclip->isEmpty());
109 fAAClipBounds = aaclip->getBounds();
112 void blitH(int x, int y, int width) SK_OVERRIDE;
113 virtual void blitAntiH(int x, int y, const SkAlpha[],
114 const int16_t runs[]) SK_OVERRIDE;
115 void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
116 void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
117 void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE;
118 const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE;
122 const SkAAClip* fAAClip;
123 SkIRect fAAClipBounds;
125 // point into fScanlineScratch
132 SkAutoSMalloc<kSize> fGrayMaskScratch; // used for blitMask
133 void* fScanlineScratch; // enough for a mask at 32bit, or runs+aa
135 void ensureRunsAndAA();