• 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 GrStencilAttachment_DEFINED
11 #define GrStencilAttachment_DEFINED
12 
13 #include "GrClip.h"
14 #include "GrGpuResource.h"
15 
16 class GrRenderTarget;
17 class GrResourceKey;
18 
19 class GrStencilAttachment : public GrGpuResource {
20 public:
21 
22 
~GrStencilAttachment()23     virtual ~GrStencilAttachment() {
24         // TODO: allow SB to be purged and detach itself from rts
25     }
26 
width()27     int width() const { return fWidth; }
height()28     int height() const { return fHeight; }
bits()29     int bits() const { return fBits; }
numSamples()30     int numSamples() const { return fSampleCnt; }
31 
32     // called to note the last clip drawn to this buffer.
setLastClip(int32_t clipStackGenID,const SkIRect & clipSpaceRect,const SkIPoint clipSpaceToStencilOffset)33     void setLastClip(int32_t clipStackGenID,
34                      const SkIRect& clipSpaceRect,
35                      const SkIPoint clipSpaceToStencilOffset) {
36         fLastClipStackGenID = clipStackGenID;
37         fLastClipStackRect = clipSpaceRect;
38         fLastClipSpaceOffset = clipSpaceToStencilOffset;
39     }
40 
41     // called to determine if we have to render the clip into SB.
mustRenderClip(int32_t clipStackGenID,const SkIRect & clipSpaceRect,const SkIPoint clipSpaceToStencilOffset)42     bool mustRenderClip(int32_t clipStackGenID,
43                         const SkIRect& clipSpaceRect,
44                         const SkIPoint clipSpaceToStencilOffset) const {
45         return fLastClipStackGenID != clipStackGenID ||
46                fLastClipSpaceOffset != clipSpaceToStencilOffset ||
47                !fLastClipStackRect.contains(clipSpaceRect);
48     }
49 
50     // We create a unique stencil buffer at each width, height and sampleCnt and share it for
51     // all render targets that require a stencil with those params.
52     static void ComputeSharedStencilAttachmentKey(int width, int height, int sampleCnt,
53                                                   GrUniqueKey* key);
54 
55 protected:
GrStencilAttachment(GrGpu * gpu,LifeCycle lifeCycle,int width,int height,int bits,int sampleCnt)56     GrStencilAttachment(GrGpu* gpu, LifeCycle lifeCycle, int width, int height, int bits,
57                         int sampleCnt)
58         : GrGpuResource(gpu, lifeCycle)
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 GrGpuResource INHERITED;
79 };
80 
81 #endif
82