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 | |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 13 | #include "GrClip.h" |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 14 | #include "GrGpuResource.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 15 | |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 16 | class GrRenderTarget; |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 17 | class GrResourceKey; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 18 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 19 | class GrStencilBuffer : public GrGpuResource { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 20 | public: |
robertphillips@google.com | 7fa1876 | 2012-09-11 13:02:31 +0000 | [diff] [blame] | 21 | SK_DECLARE_INST_COUNT(GrStencilBuffer); |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 23 | virtual ~GrStencilBuffer() { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 24 | // TODO: allow SB to be purged and detach itself from rts |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 25 | } |
| 26 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 27 | int width() const { return fWidth; } |
| 28 | int height() const { return fHeight; } |
| 29 | int bits() const { return fBits; } |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 30 | int numSamples() const { return fSampleCnt; } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 31 | |
| 32 | // called to note the last clip drawn to this buffer. |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 33 | void setLastClip(int32_t clipStackGenID, |
| 34 | const SkIRect& clipSpaceRect, |
| 35 | const SkIPoint clipSpaceToStencilOffset) { |
| 36 | fLastClipStackGenID = clipStackGenID; |
| 37 | fLastClipStackRect = clipSpaceRect; |
| 38 | fLastClipSpaceOffset = clipSpaceToStencilOffset; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // 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] | 42 | bool mustRenderClip(int32_t clipStackGenID, |
| 43 | const SkIRect& clipSpaceRect, |
| 44 | const SkIPoint clipSpaceToStencilOffset) const { |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 45 | return fLastClipStackGenID != clipStackGenID || |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 46 | fLastClipSpaceOffset != clipSpaceToStencilOffset || |
| 47 | !fLastClipStackRect.contains(clipSpaceRect); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 48 | } |
| 49 | |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 50 | // We create a unique stencil buffer at each width, height and sampleCnt and share it for |
| 51 | // all render targets that require a stencil with those params. |
| 52 | static void ComputeSharedStencilBufferKey(int width, int height, int sampleCnt, |
| 53 | GrUniqueKey* key); |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 54 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 55 | protected: |
kkinnunen | 36c57df | 2015-01-27 00:30:18 -0800 | [diff] [blame] | 56 | GrStencilBuffer(GrGpu* gpu, LifeCycle lifeCycle, int width, int height, int bits, int sampleCnt) |
| 57 | : GrGpuResource(gpu, lifeCycle) |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 58 | , fWidth(width) |
| 59 | , fHeight(height) |
| 60 | , fBits(bits) |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 61 | , fSampleCnt(sampleCnt) |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 62 | , fLastClipStackGenID(SkClipStack::kInvalidGenID) { |
| 63 | fLastClipStackRect.setEmpty(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | private: |
bsalomon@google.com | eefe6f1 | 2011-08-09 17:57:12 +0000 | [diff] [blame] | 67 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 68 | int fWidth; |
| 69 | int fHeight; |
| 70 | int fBits; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 71 | int fSampleCnt; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 72 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 73 | int32_t fLastClipStackGenID; |
| 74 | SkIRect fLastClipStackRect; |
| 75 | SkIPoint fLastClipSpaceOffset; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 76 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 77 | typedef GrGpuResource INHERITED; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | #endif |