3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef GrStencilBuffer_DEFINED
11 #define GrStencilBuffer_DEFINED
13 #include "GrClipData.h"
14 #include "GrGpuResource.h"
19 class GrStencilBuffer : public GrGpuResource {
21 SK_DECLARE_INST_COUNT(GrStencilBuffer);
23 virtual ~GrStencilBuffer() {
24 // TODO: allow SB to be purged and detach itself from rts
27 int width() const { return fWidth; }
28 int height() const { return fHeight; }
29 int bits() const { return fBits; }
30 int numSamples() const { return fSampleCnt; }
32 // called to note the last clip drawn to this buffer.
33 void setLastClip(int32_t clipStackGenID,
34 const SkIRect& clipSpaceRect,
35 const SkIPoint clipSpaceToStencilOffset) {
36 fLastClipStackGenID = clipStackGenID;
37 fLastClipStackRect = clipSpaceRect;
38 fLastClipSpaceOffset = clipSpaceToStencilOffset;
41 // called to determine if we have to render the clip into SB.
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);
50 // Places the sb in the cache. The cache takes a ref of the stencil buffer.
51 void transferToCache();
53 static GrResourceKey ComputeKey(int width, int height, int sampleCnt);
56 GrStencilBuffer(GrGpu* gpu, bool isWrapped, int width, int height, int bits, int sampleCnt)
57 : GrGpuResource(gpu, isWrapped)
61 , fSampleCnt(sampleCnt)
62 , fLastClipStackGenID(SkClipStack::kInvalidGenID) {
63 fLastClipStackRect.setEmpty();
73 int32_t fLastClipStackGenID;
74 SkIRect fLastClipStackRect;
75 SkIPoint fLastClipSpaceOffset;
77 typedef GrGpuResource INHERITED;