blob: d38c5574936ca4fe7b3a7093d77a54a32d43c8cb [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +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
9#ifndef GrGLRenderTarget_DEFINED
10#define GrGLRenderTarget_DEFINED
11
12#include "GrGLIRect.h"
13#include "GrRenderTarget.h"
bsalomon@google.com81712882012-11-01 17:12:34 +000014#include "SkScalar.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000015
csmartdaltonf9635992016-08-10 11:09:07 -070016class GrGLCaps;
bsalomon861e1032014-12-16 07:33:49 -080017class GrGLGpu;
egdanielec00d942015-09-14 12:56:10 -070018class GrGLStencilAttachment;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000019
20class GrGLRenderTarget : public GrRenderTarget {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000021public:
Robert Phillipscb2e2352017-08-30 16:44:40 -040022 bool alwaysClearStencil() const override { return 0 == fRTFBOID; }
23
egdanield803f272015-03-18 13:01:52 -070024 // set fTexFBOID to this value to indicate that it is multisampled but
25 // Gr doesn't know how to resolve it.
26 enum { kUnresolvableFBOID = 0 };
27
bsalomonb15b4c12014-10-29 12:41:57 -070028 struct IDDesc {
csmartdaltonf9635992016-08-10 11:09:07 -070029 GrGLuint fRTFBOID;
30 GrBackendObjectOwnership fRTFBOOwnership;
31 GrGLuint fTexFBOID;
32 GrGLuint fMSColorRenderbufferID;
33 bool fIsMixedSampled;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000034 };
35
bungeman6bd52842016-10-27 09:30:08 -070036 static sk_sp<GrGLRenderTarget> MakeWrapped(GrGLGpu*,
37 const GrSurfaceDesc&,
38 const IDDesc&,
39 int stencilBits);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000040
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000041 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
42 const GrGLIRect& getViewport() const { return fViewport; }
43
Brian Osman1a9e8f32017-02-24 09:31:16 -050044 // The following two functions return the same ID when a texture/render target is not
45 // multisampled, and different IDs when it is multisampled.
egdanield803f272015-03-18 13:01:52 -070046 // FBO ID used to render into
47 GrGLuint renderFBOID() const { return fRTFBOID; }
48 // FBO ID that has texture ID attached.
49 GrGLuint textureFBOID() const { return fTexFBOID; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000050
rmistry@google.comfbfcd562012-08-23 18:09:54 +000051 // override of GrRenderTarget
mtklein36352bf2015-03-25 18:17:31 -070052 ResolveType getResolveType() const override {
Brian Salomon7c8460e2017-05-12 11:36:10 -040053 if (GrFSAAType::kUnifiedMSAA != this->fsaaType() || fRTFBOID == fTexFBOID) {
54 // catches FBO 0 and non unified-MSAA case
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000055 return kAutoResolves_ResolveType;
egdanield803f272015-03-18 13:01:52 -070056 } else if (kUnresolvableFBOID == fTexFBOID) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000057 return kCantResolve_ResolveType;
58 } else {
59 return kCanResolve_ResolveType;
60 }
61 }
62
joshualitt81793412015-07-08 12:54:04 -070063 GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; }
64
kkinnunen2e6055b2016-04-22 01:48:29 -070065 bool canAttemptStencilAttachment() const override;
bsalomon6bc1b5f2015-02-23 09:06:38 -080066
ericrk0a5fa482015-09-15 14:16:10 -070067 // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
68 // components seperately.
69 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
70
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000071protected:
kkinnunen2e6055b2016-04-22 01:48:29 -070072 // Constructor for subclasses.
73 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
bsalomon37dd3312014-11-03 08:47:23 -080074
75 void init(const GrSurfaceDesc&, const IDDesc&);
76
mtklein36352bf2015-03-25 18:17:31 -070077 void onAbandon() override;
78 void onRelease() override;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000079
Robert Phillipsd6214d42016-11-07 08:23:48 -050080 int numSamplesOwnedPerPixel() const { return fNumSamplesOwnedPerPixel; }
bsalomon69ed47f2014-11-12 11:13:39 -080081
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000082private:
kkinnunen2e6055b2016-04-22 01:48:29 -070083 // Constructor for instances wrapping backend objects.
egdanielec00d942015-09-14 12:56:10 -070084 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*);
85
Robert Phillipsc4f0a822017-06-13 08:11:36 -040086 static GrRenderTargetFlags ComputeFlags(const GrGLCaps&, const IDDesc&);
csmartdaltonf9635992016-08-10 11:09:07 -070087
egdanielec00d942015-09-14 12:56:10 -070088 GrGLGpu* getGLGpu() const;
89 bool completeStencilAttachment() override;
90
Robert Phillipsd6214d42016-11-07 08:23:48 -050091 size_t onGpuMemorySize() const override;
92
ericrk0a5fa482015-09-15 14:16:10 -070093 int msaaSamples() const;
94 // The number total number of samples, including both MSAA and resolve texture samples.
95 int totalSamples() const;
96
cdaltond4727922015-11-10 12:49:06 -080097 GrGLuint fRTFBOID;
98 GrGLuint fTexFBOID;
99 GrGLuint fMSColorRenderbufferID;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000100
kkinnunen2e6055b2016-04-22 01:48:29 -0700101 GrBackendObjectOwnership fRTFBOOwnership;
hendrikw9a0c7ab2014-12-09 14:26:47 -0800102
bsalomon@google.com2d0bade2012-10-26 19:01:17 +0000103 // when we switch to this render target we want to set the viewport to
bsalomon37dd3312014-11-03 08:47:23 -0800104 // only render to content area (as opposed to the whole allocation) and
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000105 // we want the rendering to be at top left (GL has origin in bottom left)
cdaltond4727922015-11-10 12:49:06 -0800106 GrGLIRect fViewport;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000107
Robert Phillips29e52f12016-11-03 10:19:14 -0400108 // The RenderTarget needs to be able to report its VRAM footprint even after abandon and
109 // release have potentially zeroed out the IDs (e.g., so the cache can reset itself). Since
110 // the IDs are just required for the computation in totalSamples we cache that result here.
111 int fNumSamplesOwnedPerPixel;
cdaltond4727922015-11-10 12:49:06 -0800112
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000113 typedef GrRenderTarget INHERITED;
114};
115
116#endif