bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 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 | |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 13 | #include "GrClipData.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 14 | #include "GrResource.h" |
| 15 | |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 16 | class GrRenderTarget; |
| 17 | class GrResourceEntry; |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 18 | class GrResourceKey; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 19 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 20 | class GrStencilBuffer : public GrResource { |
| 21 | public: |
robertphillips@google.com | 7fa1876 | 2012-09-11 13:02:31 +0000 | [diff] [blame] | 22 | SK_DECLARE_INST_COUNT(GrStencilBuffer); |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 23 | |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 24 | virtual ~GrStencilBuffer() { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 25 | // TODO: allow SB to be purged and detach itself from rts |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 26 | } |
| 27 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 28 | int width() const { return fWidth; } |
| 29 | int height() const { return fHeight; } |
| 30 | int bits() const { return fBits; } |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 31 | int numSamples() const { return fSampleCnt; } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 32 | |
| 33 | // called to note the last clip drawn to this buffer. |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 34 | void setLastClip(int32_t clipStackGenID, |
| 35 | const SkIRect& clipSpaceRect, |
| 36 | const SkIPoint clipSpaceToStencilOffset) { |
| 37 | fLastClipStackGenID = clipStackGenID; |
| 38 | fLastClipStackRect = clipSpaceRect; |
| 39 | fLastClipSpaceOffset = clipSpaceToStencilOffset; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | // called to determine if we have to render the clip into SB. |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 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); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 50 | } |
| 51 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 52 | // Places the sb in the cache. The cache takes a ref of the stencil buffer. |
| 53 | void transferToCache(); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 54 | |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 55 | static GrResourceKey ComputeKey(int width, int height, int sampleCnt); |
| 56 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 57 | protected: |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 58 | GrStencilBuffer(GrGpu* gpu, bool isWrapped, int width, int height, int bits, int sampleCnt) |
| 59 | : GrResource(gpu, isWrapped) |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 60 | , fWidth(width) |
| 61 | , fHeight(height) |
| 62 | , fBits(bits) |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 63 | , fSampleCnt(sampleCnt) |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 64 | , fLastClipStackGenID(SkClipStack::kInvalidGenID) { |
| 65 | fLastClipStackRect.setEmpty(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | private: |
bsalomon@google.com | eefe6f1 | 2011-08-09 17:57:12 +0000 | [diff] [blame] | 69 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 70 | int fWidth; |
| 71 | int fHeight; |
| 72 | int fBits; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 73 | int fSampleCnt; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 74 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 75 | int32_t fLastClipStackGenID; |
| 76 | SkIRect fLastClipStackRect; |
| 77 | SkIPoint fLastClipSpaceOffset; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 78 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 79 | typedef GrResource INHERITED; |
| 80 | }; |
| 81 | |
| 82 | #endif |