blob: 3b89a5aa21123e1a16af4e3b3d93ac89b1aee66b [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 {
bsalomon02a44a42015-02-19 09:09:00 -080027 IDDesc() : fRenderbufferID(0), fLifeCycle(kCached_LifeCycle) {}
kkinnunen36c57df2015-01-27 00:30:18 -080028 GrGLuint fRenderbufferID;
29 GrGpuResource::LifeCycle fLifeCycle;
30 };
31
egdaniel8dc7c3a2015-04-16 11:22:42 -070032 GrGLStencilAttachment(GrGpu* gpu,
kkinnunen36c57df2015-01-27 00:30:18 -080033 const IDDesc& idDesc,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000034 int width, int height,
bsalomon@google.com558a75b2011-08-08 17:01:14 +000035 int sampleCnt,
rmistry@google.comfbfcd562012-08-23 18:09:54 +000036 const Format& format)
egdaniel8dc7c3a2015-04-16 11:22:42 -070037 : GrStencilAttachment(gpu, idDesc.fLifeCycle, width, height, format.fStencilBits, sampleCnt)
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000038 , fFormat(format)
kkinnunen36c57df2015-01-27 00:30:18 -080039 , fRenderbufferID(idDesc.fRenderbufferID) {
bsalomon16961262014-08-26 14:01:07 -070040 this->registerWithCache();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000041 }
42
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000043 GrGLuint renderbufferID() const {
44 return fRenderbufferID;
45 }
46
bsalomon@google.com0b77d682011-08-19 13:28:54 +000047 const Format& format() const { return fFormat; }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000048
49protected:
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000050 // overrides of GrResource
mtklein36352bf2015-03-25 18:17:31 -070051 void onRelease() override;
52 void onAbandon() override;
ericrk0a5fa482015-09-15 14:16:10 -070053 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
54 const SkString& dumpName) const override;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000055
56private:
mtklein36352bf2015-03-25 18:17:31 -070057 size_t onGpuMemorySize() const override;
bsalomon69ed47f2014-11-12 11:13:39 -080058
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000059 Format fFormat;
60 // may be zero for external SBs associated with external RTs
61 // (we don't require the client to give us the id, just tell
62 // us how many bits of stencil there are).
63 GrGLuint fRenderbufferID;
64
egdaniel8dc7c3a2015-04-16 11:22:42 -070065 typedef GrStencilAttachment INHERITED;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000066};
67
68#endif