SkAAClip.h revision 1c04bf97b6245b55ac58c2f3902f8ca95ca91c3d
1
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef SkAAClip_DEFINED
10#define SkAAClip_DEFINED
11
12#include "SkBlitter.h"
13#include "SkRegion.h"
14
15class SkAAClip {
16public:
17    SkAAClip();
18    SkAAClip(const SkAAClip&);
19    ~SkAAClip();
20
21    SkAAClip& operator=(const SkAAClip&);
22    friend bool operator==(const SkAAClip&, const SkAAClip&);
23    friend bool operator!=(const SkAAClip& a, const SkAAClip& b) {
24        return !(a == b);
25    }
26
27    void swap(SkAAClip&);
28
29    bool isEmpty() const { return NULL == fRunHead; }
30    const SkIRect& getBounds() const { return fBounds; }
31
32    bool setEmpty();
33    bool setRect(const SkIRect&);
34    bool setRect(const SkRect&);
35    bool setPath(const SkPath&, const SkRegion* clip = NULL);
36    bool set(const SkAAClip&);
37
38    bool op(const SkAAClip&, const SkAAClip&, SkRegion::Op);
39
40    // Helpers for op()
41    bool op(const SkIRect&, SkRegion::Op);
42    bool op(const SkRect&, SkRegion::Op);
43    bool op(const SkAAClip&, SkRegion::Op);
44
45    bool offset(int dx, int dy);
46    bool offset(int dx, int dy, SkAAClip* dst) const;
47
48    /**
49     *  Allocates a mask the size of the aaclip, and expands its data into
50     *  the mask, using kA8_Format
51     */
52    void copyToMask(SkMask*) const;
53
54    // called internally
55
56    bool quickContains(int left, int top, int right, int bottom) const;
57    const uint8_t* findRow(int y, int* lastYForRow) const;
58    const uint8_t* findX(const uint8_t data[], int x, int* initialCount) const;
59
60    class Iter;
61    struct RunHead;
62    struct YOffset;
63    class Builder;
64
65private:
66    SkIRect  fBounds;
67    RunHead* fRunHead;
68
69    void freeRuns();
70
71    friend class Builder;
72    class BuilderBlitter;
73    friend class BuilderBlitter;
74};
75
76///////////////////////////////////////////////////////////////////////////////
77
78class SkAAClipBlitter : public SkBlitter {
79public:
80    SkAAClipBlitter() : fRuns(NULL) {}
81    virtual ~SkAAClipBlitter();
82
83    void init(SkBlitter* blitter, const SkAAClip* aaclip) {
84        SkASSERT(aaclip && !aaclip->isEmpty());
85        fBlitter = blitter;
86        fAAClip = aaclip;
87        fAAClipBounds = aaclip->getBounds();
88    }
89
90    virtual void blitH(int x, int y, int width) SK_OVERRIDE;
91    virtual void blitAntiH(int x, int y, const SkAlpha[],
92                           const int16_t runs[]) SK_OVERRIDE;
93    virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
94    virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
95    virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE;
96    virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE;
97
98private:
99    SkBlitter*      fBlitter;
100    const SkAAClip* fAAClip;
101    SkIRect         fAAClipBounds;
102
103    // lazily allocated
104    int16_t*        fRuns;
105    SkAlpha*        fAA;    // points into fRuns allocation
106
107    void ensureRunsAndAA();
108};
109
110#endif
111