michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef GrStencilBuffer_DEFINED michael@0: #define GrStencilBuffer_DEFINED michael@0: michael@0: #include "GrClipData.h" michael@0: #include "GrResource.h" michael@0: michael@0: class GrRenderTarget; michael@0: class GrResourceEntry; michael@0: class GrResourceKey; michael@0: michael@0: class GrStencilBuffer : public GrResource { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(GrStencilBuffer); michael@0: michael@0: virtual ~GrStencilBuffer() { michael@0: // TODO: allow SB to be purged and detach itself from rts michael@0: } michael@0: michael@0: int width() const { return fWidth; } michael@0: int height() const { return fHeight; } michael@0: int bits() const { return fBits; } michael@0: int numSamples() const { return fSampleCnt; } michael@0: michael@0: // called to note the last clip drawn to this buffer. michael@0: void setLastClip(int32_t clipStackGenID, michael@0: const SkIRect& clipSpaceRect, michael@0: const SkIPoint clipSpaceToStencilOffset) { michael@0: fLastClipStackGenID = clipStackGenID; michael@0: fLastClipStackRect = clipSpaceRect; michael@0: fLastClipSpaceOffset = clipSpaceToStencilOffset; michael@0: } michael@0: michael@0: // called to determine if we have to render the clip into SB. michael@0: bool mustRenderClip(int32_t clipStackGenID, michael@0: const SkIRect& clipSpaceRect, michael@0: const SkIPoint clipSpaceToStencilOffset) const { michael@0: return fLastClipStackGenID != clipStackGenID || michael@0: fLastClipSpaceOffset != clipSpaceToStencilOffset || michael@0: !fLastClipStackRect.contains(clipSpaceRect); michael@0: } michael@0: michael@0: // Places the sb in the cache. The cache takes a ref of the stencil buffer. michael@0: void transferToCache(); michael@0: michael@0: static GrResourceKey ComputeKey(int width, int height, int sampleCnt); michael@0: michael@0: protected: michael@0: GrStencilBuffer(GrGpu* gpu, bool isWrapped, int width, int height, int bits, int sampleCnt) michael@0: : GrResource(gpu, isWrapped) michael@0: , fWidth(width) michael@0: , fHeight(height) michael@0: , fBits(bits) michael@0: , fSampleCnt(sampleCnt) michael@0: , fLastClipStackGenID(SkClipStack::kInvalidGenID) { michael@0: fLastClipStackRect.setEmpty(); michael@0: } michael@0: michael@0: private: michael@0: michael@0: int fWidth; michael@0: int fHeight; michael@0: int fBits; michael@0: int fSampleCnt; michael@0: michael@0: int32_t fLastClipStackGenID; michael@0: SkIRect fLastClipStackRect; michael@0: SkIPoint fLastClipSpaceOffset; michael@0: michael@0: typedef GrResource INHERITED; michael@0: }; michael@0: michael@0: #endif