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