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