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 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 57 protected: GrStencilBuffer(GrGpu * gpu,bool isWrapped,int width,int height,int bits,int sampleCnt)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 68 private: 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