blob: 0589935f39dc3fc5f94b671931af79efcdaa80e7 [file] [log] [blame]
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001
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
joshualitt44701df2015-02-23 14:44:57 -080013#include "GrClip.h"
bsalomon6d3fe022014-07-25 08:35:45 -070014#include "GrGpuResource.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000015
bsalomon@google.com558a75b2011-08-08 17:01:14 +000016class GrRenderTarget;
robertphillips@google.com46a86002012-08-08 10:42:44 +000017class GrResourceKey;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000018
bsalomon6d3fe022014-07-25 08:35:45 -070019class GrStencilBuffer : public GrGpuResource {
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000020public:
robertphillips@google.com7fa18762012-09-11 13:02:31 +000021 SK_DECLARE_INST_COUNT(GrStencilBuffer);
robertphillips@google.com46a86002012-08-08 10:42:44 +000022
bsalomon@google.com558a75b2011-08-08 17:01:14 +000023 virtual ~GrStencilBuffer() {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000024 // TODO: allow SB to be purged and detach itself from rts
bsalomon@google.com558a75b2011-08-08 17:01:14 +000025 }
26
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000027 int width() const { return fWidth; }
28 int height() const { return fHeight; }
29 int bits() const { return fBits; }
bsalomon@google.com558a75b2011-08-08 17:01:14 +000030 int numSamples() const { return fSampleCnt; }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000031
32 // called to note the last clip drawn to this buffer.
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000033 void setLastClip(int32_t clipStackGenID,
34 const SkIRect& clipSpaceRect,
35 const SkIPoint clipSpaceToStencilOffset) {
36 fLastClipStackGenID = clipStackGenID;
37 fLastClipStackRect = clipSpaceRect;
38 fLastClipSpaceOffset = clipSpaceToStencilOffset;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000039 }
40
41 // called to determine if we have to render the clip into SB.
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000042 bool mustRenderClip(int32_t clipStackGenID,
43 const SkIRect& clipSpaceRect,
44 const SkIPoint clipSpaceToStencilOffset) const {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +000045 return fLastClipStackGenID != clipStackGenID ||
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000046 fLastClipSpaceOffset != clipSpaceToStencilOffset ||
47 !fLastClipStackRect.contains(clipSpaceRect);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000048 }
49
bsalomon02a44a42015-02-19 09:09:00 -080050 // 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.com46a86002012-08-08 10:42:44 +000054
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000055protected:
kkinnunen36c57df2015-01-27 00:30:18 -080056 GrStencilBuffer(GrGpu* gpu, LifeCycle lifeCycle, int width, int height, int bits, int sampleCnt)
57 : GrGpuResource(gpu, lifeCycle)
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000058 , fWidth(width)
59 , fHeight(height)
60 , fBits(bits)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000061 , fSampleCnt(sampleCnt)
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000062 , fLastClipStackGenID(SkClipStack::kInvalidGenID) {
63 fLastClipStackRect.setEmpty();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000064 }
65
66private:
bsalomon@google.comeefe6f12011-08-09 17:57:12 +000067
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000068 int fWidth;
69 int fHeight;
70 int fBits;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000071 int fSampleCnt;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000072
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000073 int32_t fLastClipStackGenID;
74 SkIRect fLastClipStackRect;
75 SkIPoint fLastClipSpaceOffset;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000076
bsalomon6d3fe022014-07-25 08:35:45 -070077 typedef GrGpuResource INHERITED;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000078};
79
80#endif