blob: f578bf80b1fae4a5704df90afcb29108d6bf05d2 [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 GrGLStencilAttachment_DEFINED
10#define GrGLStencilAttachment_DEFINED
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000011
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000012#include "gl/GrGLInterface.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070013#include "GrStencilAttachment.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000014
egdaniel8dc7c3a2015-04-16 11:22:42 -070015class GrGLStencilAttachment : public GrStencilAttachment {
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000016public:
caryclark@google.comcf6285b2012-06-06 12:09:01 +000017 static const GrGLenum kUnknownInternalFormat = ~0U;
18 static const GrGLuint kUnknownBitCount = ~0U;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000019 struct Format {
20 GrGLenum fInternalFormat;
21 GrGLuint fStencilBits;
22 GrGLuint fTotalBits;
23 bool fPacked;
24 };
25
kkinnunen36c57df2015-01-27 00:30:18 -080026 struct IDDesc {
kkinnunen2e6055b2016-04-22 01:48:29 -070027 IDDesc() : fRenderbufferID(0) {}
kkinnunen36c57df2015-01-27 00:30:18 -080028 GrGLuint fRenderbufferID;
kkinnunen36c57df2015-01-27 00:30:18 -080029 };
30
egdaniel8dc7c3a2015-04-16 11:22:42 -070031 GrGLStencilAttachment(GrGpu* gpu,
kkinnunen2e6055b2016-04-22 01:48:29 -070032 const IDDesc& idDesc,
33 int width, int height,
34 int sampleCnt,
35 const Format& format)
36 : GrStencilAttachment(gpu, width, height, format.fStencilBits, sampleCnt)
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000037 , fFormat(format)
kkinnunen36c57df2015-01-27 00:30:18 -080038 , fRenderbufferID(idDesc.fRenderbufferID) {
kkinnunen2e6055b2016-04-22 01:48:29 -070039 this->registerWithCache(SkBudgeted::kYes);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000040 }
41
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000042 GrGLuint renderbufferID() const {
43 return fRenderbufferID;
44 }
45
bsalomon@google.com0b77d682011-08-19 13:28:54 +000046 const Format& format() const { return fFormat; }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000047
48protected:
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000049 // overrides of GrResource
mtklein36352bf2015-03-25 18:17:31 -070050 void onRelease() override;
51 void onAbandon() override;
ericrk0a5fa482015-09-15 14:16:10 -070052 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
53 const SkString& dumpName) const override;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000054
55private:
mtklein36352bf2015-03-25 18:17:31 -070056 size_t onGpuMemorySize() const override;
bsalomon69ed47f2014-11-12 11:13:39 -080057
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000058 Format fFormat;
59 // may be zero for external SBs associated with external RTs
60 // (we don't require the client to give us the id, just tell
61 // us how many bits of stencil there are).
62 GrGLuint fRenderbufferID;
63
egdaniel8dc7c3a2015-04-16 11:22:42 -070064 typedef GrStencilAttachment INHERITED;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000065};
66
67#endif