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