1/*
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
9#ifndef GrStencilAttachment_DEFINED
10#define GrStencilAttachment_DEFINED
11
12#include "src/core/SkClipStack.h"
13#include "src/gpu/GrGpuResource.h"
14
15class GrRenderTarget;
16class GrResourceKey;
17
18class GrStencilAttachment : public GrGpuResource {
19public:
20 ~GrStencilAttachment() override {
21 // TODO: allow SB to be purged and detach itself from rts
22 }
23
24 int width() const { return fWidth; }
25 int height() const { return fHeight; }
26 int bits() const { return fBits; }
27 int numSamples() const { return fSampleCnt; }
28
29 bool hasPerformedInitialClear() const { return fHasPerformedInitialClear; }
30 void markHasPerformedInitialClear() { fHasPerformedInitialClear = true; }
31
32 // 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.
34 static void ComputeSharedStencilAttachmentKey(int width, int height, int sampleCnt,
35 GrUniqueKey* key);
36
37protected:
38 GrStencilAttachment(GrGpu* gpu, int width, int height, int bits, int sampleCnt)
39 : INHERITED(gpu)
40 , fWidth(width)
41 , fHeight(height)
42 , fBits(bits)
43 , fSampleCnt(sampleCnt) {
44 }
45
46private:
47 const char* getResourceType() const override { return "Stencil"; }
48
49 int fWidth;
50 int fHeight;
51 int fBits;
52 int fSampleCnt;
53 bool fHasPerformedInitialClear = false;
54
55 typedef GrGpuResource INHERITED;
56};
57
58#endif
59