GrStencilBuffer.h revision 728302281920727b96e6cec0bfc7575900f34a8b
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
10#ifndef GrStencilBuffer_DEFINED
11#define GrStencilBuffer_DEFINED
12
13#include "GrClipData.h"
14#include "GrResource.h"
15
16class GrRenderTarget;
17class GrResourceEntry;
18class GrResourceKey;
19
20class GrStencilBuffer : public GrResource {
21public:
22    SK_DECLARE_INST_COUNT(GrStencilBuffer);
23
24    virtual ~GrStencilBuffer() {
25        // TODO: allow SB to be purged and detach itself from rts
26    }
27
28    int width() const { return fWidth; }
29    int height() const { return fHeight; }
30    int bits() const { return fBits; }
31    int numSamples() const { return fSampleCnt; }
32
33    // called to note the last clip drawn to this buffer.
34    void setLastClip(int32_t clipStackGenID,
35                     const SkIRect& clipSpaceRect,
36                     const SkIPoint clipSpaceToStencilOffset) {
37        fLastClipStackGenID = clipStackGenID;
38        fLastClipStackRect = clipSpaceRect;
39        fLastClipSpaceOffset = clipSpaceToStencilOffset;
40    }
41
42    // called to determine if we have to render the clip into SB.
43    bool mustRenderClip(int32_t clipStackGenID,
44                        const SkIRect& clipSpaceRect,
45                        const SkIPoint clipSpaceToStencilOffset) const {
46        return SkClipStack::kInvalidGenID == clipStackGenID ||
47               fLastClipStackGenID != clipStackGenID ||
48               fLastClipSpaceOffset != clipSpaceToStencilOffset ||
49               !fLastClipStackRect.contains(clipSpaceRect);
50    }
51
52    // Places the sb in the cache. The cache takes a ref of the stencil buffer.
53    void transferToCache();
54
55    static GrResourceKey ComputeKey(int width, int height, int sampleCnt);
56
57protected:
58    GrStencilBuffer(GrGpu* gpu, bool isWrapped, int width, int height, int bits, int sampleCnt)
59        : GrResource(gpu, isWrapped)
60        , fWidth(width)
61        , fHeight(height)
62        , fBits(bits)
63        , fSampleCnt(sampleCnt)
64        , fLastClipStackGenID(SkClipStack::kInvalidGenID) {
65        fLastClipStackRect.setEmpty();
66    }
67
68private:
69
70    int fWidth;
71    int fHeight;
72    int fBits;
73    int fSampleCnt;
74
75    int32_t     fLastClipStackGenID;
76    SkIRect     fLastClipStackRect;
77    SkIPoint    fLastClipSpaceOffset;
78
79    typedef GrResource INHERITED;
80};
81
82#endif
83