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 | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 23 | GR_DECLARE_RESOURCE_CACHE_TYPE() |
| 24 | |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 25 | virtual ~GrStencilBuffer() { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 26 | // TODO: allow SB to be purged and detach itself from rts |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 27 | } |
| 28 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 29 | int width() const { return fWidth; } |
| 30 | int height() const { return fHeight; } |
| 31 | int bits() const { return fBits; } |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 32 | int numSamples() const { return fSampleCnt; } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 33 | |
| 34 | // called to note the last clip drawn to this buffer. |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 35 | void setLastClip(const GrClipData& clipData, int width, int height) { |
| 36 | // the clip stack needs to be copied separately (and deeply) since |
| 37 | // it could change beneath the stencil buffer |
| 38 | fLastClipStack = *clipData.fClipStack; |
| 39 | fLastClipData.fClipStack = &fLastClipStack; |
| 40 | fLastClipData.fOrigin = clipData.fOrigin; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 41 | fLastClipWidth = width; |
| 42 | fLastClipHeight = height; |
| 43 | GrAssert(width <= fWidth); |
| 44 | GrAssert(height <= fHeight); |
| 45 | } |
| 46 | |
| 47 | // called to determine if we have to render the clip into SB. |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 48 | bool mustRenderClip(const GrClipData& clipData, int width, int height) const { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 49 | // The clip is in device space. That is it doesn't scale to fit a |
| 50 | // smaller RT. It is just truncated on the right / bottom edges. |
| 51 | // Note that this assumes that the viewport origin never moves within |
| 52 | // the stencil buffer. This is valid today. |
| 53 | return width > fLastClipWidth || |
| 54 | height > fLastClipHeight || |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 55 | clipData != fLastClipData; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 56 | } |
| 57 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 58 | const GrClipData& getLastClip() const { |
| 59 | return fLastClipData; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 60 | } |
| 61 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame^] | 62 | // Places the sb in the cache. The cache takes a ref of the stencil buffer. |
| 63 | void transferToCache(); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 64 | |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 65 | static GrResourceKey ComputeKey(int width, int height, int sampleCnt); |
| 66 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 67 | protected: |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 68 | GrStencilBuffer(GrGpu* gpu, int width, int height, int bits, int sampleCnt) |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 69 | : GrResource(gpu) |
| 70 | , fWidth(width) |
| 71 | , fHeight(height) |
| 72 | , fBits(bits) |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 73 | , fSampleCnt(sampleCnt) |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 74 | , fLastClipStack() |
| 75 | , fLastClipData() |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 76 | , fLastClipWidth(-1) |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 77 | , fLastClipHeight(-1) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | private: |
bsalomon@google.com | eefe6f1 | 2011-08-09 17:57:12 +0000 | [diff] [blame] | 81 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 82 | int fWidth; |
| 83 | int fHeight; |
| 84 | int fBits; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 85 | int fSampleCnt; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 86 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 87 | SkClipStack fLastClipStack; |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 88 | GrClipData fLastClipData; |
| 89 | int fLastClipWidth; |
| 90 | int fLastClipHeight; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 92 | typedef GrResource INHERITED; |
| 93 | }; |
| 94 | |
| 95 | #endif |