blob: d1365efd420c10af802bd173fd534a4d443871cd [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
bsalomon861e1032014-12-16 07:33:49 -080016class GrGLGpu;
egdanielec00d942015-09-14 12:56:10 -070017class GrGLStencilAttachment;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000018
19class GrGLRenderTarget : public GrRenderTarget {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000020public:
egdanield803f272015-03-18 13:01:52 -070021 // set fTexFBOID to this value to indicate that it is multisampled but
22 // Gr doesn't know how to resolve it.
23 enum { kUnresolvableFBOID = 0 };
24
bsalomonb15b4c12014-10-29 12:41:57 -070025 struct IDDesc {
vbuzinovdded6962015-06-12 08:59:45 -070026 GrGLuint fRTFBOID;
27 GrGLuint fTexFBOID;
28 GrGLuint fMSColorRenderbufferID;
29 GrGpuResource::LifeCycle fLifeCycle;
30 GrRenderTarget::SampleConfig fSampleConfig;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000031 };
32
egdanielec00d942015-09-14 12:56:10 -070033 static GrGLRenderTarget* CreateWrapped(GrGLGpu*,
34 const GrSurfaceDesc&,
35 const IDDesc&,
36 int stencilBits);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000037
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000038 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
39 const GrGLIRect& getViewport() const { return fViewport; }
40
egdanield803f272015-03-18 13:01:52 -070041 // The following two functions return the same ID when a
42 // texture/render target is multisampled, and different IDs when
43 // it is.
44 // FBO ID used to render into
45 GrGLuint renderFBOID() const { return fRTFBOID; }
46 // FBO ID that has texture ID attached.
47 GrGLuint textureFBOID() const { return fTexFBOID; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000048
rmistry@google.comfbfcd562012-08-23 18:09:54 +000049 // override of GrRenderTarget
mtklein36352bf2015-03-25 18:17:31 -070050 ResolveType getResolveType() const override {
vbuzinovdded6962015-06-12 08:59:45 -070051 if (!this->isUnifiedMultisampled() ||
egdanield803f272015-03-18 13:01:52 -070052 fRTFBOID == fTexFBOID) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000053 // catches FBO 0 and non MSAA case
54 return kAutoResolves_ResolveType;
egdanield803f272015-03-18 13:01:52 -070055 } else if (kUnresolvableFBOID == fTexFBOID) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000056 return kCantResolve_ResolveType;
57 } else {
58 return kCanResolve_ResolveType;
59 }
60 }
61
joshualitt81793412015-07-08 12:54:04 -070062 GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; }
63
bsalomon6bc1b5f2015-02-23 09:06:38 -080064 /** When we don't own the FBO ID we don't attempt to modify its attachments. */
bsalomon6dc6f5f2015-06-18 09:12:16 -070065 bool canAttemptStencilAttachment() const override {
66 return kCached_LifeCycle == fRTLifecycle || kUncached_LifeCycle == fRTLifecycle;
67 }
bsalomon6bc1b5f2015-02-23 09:06:38 -080068
ericrk0a5fa482015-09-15 14:16:10 -070069 // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
70 // components seperately.
71 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
72
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000073protected:
bsalomon37dd3312014-11-03 08:47:23 -080074 // The public constructor registers this object with the cache. However, only the most derived
75 // class should register with the cache. This constructor does not do the registration and
76 // rather moves that burden onto the derived class.
77 enum Derived { kDerived };
bsalomon861e1032014-12-16 07:33:49 -080078 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
bsalomon37dd3312014-11-03 08:47:23 -080079
80 void init(const GrSurfaceDesc&, const IDDesc&);
81
mtklein36352bf2015-03-25 18:17:31 -070082 void onAbandon() override;
83 void onRelease() override;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000084
bsalomon69ed47f2014-11-12 11:13:39 -080085 // In protected because subclass GrGLTextureRenderTarget calls this version.
mtklein36352bf2015-03-25 18:17:31 -070086 size_t onGpuMemorySize() const override;
bsalomon69ed47f2014-11-12 11:13:39 -080087
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000088private:
egdanielec00d942015-09-14 12:56:10 -070089 // This ctor is used only for creating wrapped render targets and is only called for the static
90 // create function CreateWrapped(...).
91 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*);
92
93 GrGLGpu* getGLGpu() const;
94 bool completeStencilAttachment() override;
95
ericrk0a5fa482015-09-15 14:16:10 -070096 // The total size of the resource (including all pixels) for a single sample.
97 size_t totalBytesPerSample() const;
98 int msaaSamples() const;
99 // The number total number of samples, including both MSAA and resolve texture samples.
100 int totalSamples() const;
101
cdaltond4727922015-11-10 12:49:06 -0800102 GrGLuint fRTFBOID;
103 GrGLuint fTexFBOID;
104 GrGLuint fMSColorRenderbufferID;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000105
hendrikw9a0c7ab2014-12-09 14:26:47 -0800106 // We track this separately from GrGpuResource because this may be both a texture and a render
107 // target, and the texture may be wrapped while the render target is not.
cdaltond4727922015-11-10 12:49:06 -0800108 LifeCycle fRTLifecycle;
hendrikw9a0c7ab2014-12-09 14:26:47 -0800109
bsalomon@google.com2d0bade2012-10-26 19:01:17 +0000110 // when we switch to this render target we want to set the viewport to
bsalomon37dd3312014-11-03 08:47:23 -0800111 // only render to content area (as opposed to the whole allocation) and
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000112 // we want the rendering to be at top left (GL has origin in bottom left)
cdaltond4727922015-11-10 12:49:06 -0800113 GrGLIRect fViewport;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000114
senorblancod2981212015-04-30 12:06:10 -0700115 // onGpuMemorySize() needs to know the VRAM footprint of the FBO(s). However, abandon and
116 // release zero out the IDs and the cache needs to know the size even after those actions.
cdaltond4727922015-11-10 12:49:06 -0800117 size_t fGpuMemorySize;
118
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000119 typedef GrRenderTarget INHERITED;
120};
121
122#endif