blob: e8c56cca4d9a8038d1689877e6a2041900ba4bbb [file] [log] [blame]
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
egdaniel8dc7c3a2015-04-16 11:22:42 -07009#ifndef GrStencilAttachment_DEFINED
10#define GrStencilAttachment_DEFINED
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000011
bsalomon6d3fe022014-07-25 08:35:45 -070012#include "GrGpuResource.h"
csmartdaltonc6f411e2016-08-05 22:32:12 -070013#include "SkClipStack.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000014
bsalomon@google.com558a75b2011-08-08 17:01:14 +000015class GrRenderTarget;
robertphillips@google.com46a86002012-08-08 10:42:44 +000016class GrResourceKey;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000017
egdaniel8dc7c3a2015-04-16 11:22:42 -070018class GrStencilAttachment : public GrGpuResource {
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000019public:
Robert Phillipscb2e2352017-08-30 16:44:40 -040020 ~GrStencilAttachment() override {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000021 // TODO: allow SB to be purged and detach itself from rts
bsalomon@google.com558a75b2011-08-08 17:01:14 +000022 }
23
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000024 int width() const { return fWidth; }
25 int height() const { return fHeight; }
26 int bits() const { return fBits; }
bsalomon@google.com558a75b2011-08-08 17:01:14 +000027 int numSamples() const { return fSampleCnt; }
Robert Phillipscb2e2352017-08-30 16:44:40 -040028 bool isDirty() const { return fIsDirty; }
29
30 void cleared() { fIsDirty = false; }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000031
bsalomon02a44a42015-02-19 09:09:00 -080032 // We create a unique stencil buffer at each width, height and sampleCnt and share it for
33 // all render targets that require a stencil with those params.
egdaniel8dc7c3a2015-04-16 11:22:42 -070034 static void ComputeSharedStencilAttachmentKey(int width, int height, int sampleCnt,
35 GrUniqueKey* key);
robertphillips@google.com46a86002012-08-08 10:42:44 +000036
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000037protected:
robertphillips55fdccc2016-06-06 06:16:20 -070038 GrStencilAttachment(GrGpu* gpu, int width, int height, int bits, int sampleCnt)
Robert Phillipscb2e2352017-08-30 16:44:40 -040039 : INHERITED(gpu)
40 , fWidth(width)
41 , fHeight(height)
42 , fBits(bits)
43 , fSampleCnt(sampleCnt)
44 , fIsDirty(true) {
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000045 }
46
47private:
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040048 const char* getResourceType() const override { return "Stencil"; }
bsalomon@google.comeefe6f12011-08-09 17:57:12 +000049
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000050 int fWidth;
51 int fHeight;
52 int fBits;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000053 int fSampleCnt;
Robert Phillipscb2e2352017-08-30 16:44:40 -040054 bool fIsDirty;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000055
bsalomon6d3fe022014-07-25 08:35:45 -070056 typedef GrGpuResource INHERITED;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000057};
58
59#endif