blob: 3cedf74e037fa63bd04e39db6156bc4d92c9a6f8 [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
2 * Copyright 2016 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#ifndef GrRenderTargetProxy_DEFINED
9#define GrRenderTargetProxy_DEFINED
10
robertphillips76948d42016-05-04 12:47:41 -070011#include "GrSurfaceProxy.h"
Robert Phillipsc4f0a822017-06-13 08:11:36 -040012#include "GrTypesPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070013
Brian Osman32342f02017-03-04 08:12:46 -050014class GrResourceProvider;
Greg Daniela070ed72018-04-26 16:31:38 -040015class GrRenderTargetProxyPriv;
robertphillips76948d42016-05-04 12:47:41 -070016
17// This class delays the acquisition of RenderTargets until they are actually
18// required
19// Beware: the uniqueID of the RenderTargetProxy will usually be different than
20// the uniqueID of the RenderTarget it represents!
Robert Phillips84a81202016-11-04 11:59:10 -040021class GrRenderTargetProxy : virtual public GrSurfaceProxy {
robertphillips76948d42016-05-04 12:47:41 -070022public:
robertphillips76948d42016-05-04 12:47:41 -070023 GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
24 const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
25
26 // Actually instantiate the backing rendertarget, if necessary.
Robert Phillips5af44de2017-07-18 14:49:38 -040027 bool instantiate(GrResourceProvider*) override;
robertphillips76948d42016-05-04 12:47:41 -070028
Brian Salomon7c8460e2017-05-12 11:36:10 -040029 GrFSAAType fsaaType() const {
Brian Salomonbdecacf2018-02-02 20:32:49 -050030 if (fSampleCnt <= 1) {
Robert Phillipsfe0253f2018-03-16 16:47:25 -040031 SkASSERT(!this->hasMixedSamples());
Brian Salomon7c8460e2017-05-12 11:36:10 -040032 return GrFSAAType::kNone;
33 }
Robert Phillipsfe0253f2018-03-16 16:47:25 -040034 return this->hasMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA;
Brian Salomon7c8460e2017-05-12 11:36:10 -040035 }
Brian Salomonbb5711a2017-05-17 13:49:59 -040036
Robert Phillips65048132017-08-10 08:44:49 -040037 /*
38 * When instantiated does this proxy require a stencil buffer?
39 */
40 void setNeedsStencil() { fNeedsStencil = true; }
41 bool needsStencil() const { return fNeedsStencil; }
42
Brian Salomonbb5711a2017-05-17 13:49:59 -040043 /**
Brian Salomonbdecacf2018-02-02 20:32:49 -050044 * Returns the number of samples/pixel in the stencil buffer (One if non-MSAA).
Brian Salomonbb5711a2017-05-17 13:49:59 -040045 */
46 int numStencilSamples() const { return fSampleCnt; }
47
robertphillips76948d42016-05-04 12:47:41 -070048 /**
Brian Salomonbdecacf2018-02-02 20:32:49 -050049 * Returns the number of samples/pixel in the color buffer (One if non-MSAA or mixed sampled).
robertphillips76948d42016-05-04 12:47:41 -070050 */
Brian Salomon7c8460e2017-05-12 11:36:10 -040051 int numColorSamples() const {
Brian Salomonbdecacf2018-02-02 20:32:49 -050052 return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt;
Brian Salomon7c8460e2017-05-12 11:36:10 -040053 }
robertphillips76948d42016-05-04 12:47:41 -070054
Robert Phillipsec2249f2016-11-09 08:54:35 -050055 int maxWindowRectangles(const GrCaps& caps) const;
56
Greg Danielb46add82019-01-02 14:51:29 -050057 bool wrapsVkSecondaryCB() const { return fWrapsVkSecondaryCB == WrapsVkSecondaryCB::kYes; }
58
Robert Phillipse2f7d182016-12-15 09:23:05 -050059 // TODO: move this to a priv class!
60 bool refsWrappedObjects() const;
61
Greg Daniela070ed72018-04-26 16:31:38 -040062 // Provides access to special purpose functions.
63 GrRenderTargetProxyPriv rtPriv();
64 const GrRenderTargetProxyPriv rtPriv() const;
65
Robert Phillips84a81202016-11-04 11:59:10 -040066protected:
Robert Phillips0bd24dc2018-01-16 08:06:32 -050067 friend class GrProxyProvider; // for ctors
Greg Daniela070ed72018-04-26 16:31:38 -040068 friend class GrRenderTargetProxyPriv;
Robert Phillips37430132016-11-09 06:50:43 -050069
csmartdaltonf9635992016-08-10 11:09:07 -070070 // Deferred version
Greg Daniel4065d452018-11-16 15:43:41 -050071 GrRenderTargetProxy(const GrCaps&, const GrBackendFormat&, const GrSurfaceDesc&,
72 GrSurfaceOrigin, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
robertphillips76948d42016-05-04 12:47:41 -070073
Chris Dalton706a6ff2017-11-29 22:01:06 -070074 // Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050075 // There are two main use cases for lazily-instantiated proxies:
76 // basic knowledge - width, height, config, samples, origin are known
77 // minimal knowledge - only config is known.
78 //
79 // The basic knowledge version is used for DDL where we know the type of proxy we are going to
80 // use, but we don't have access to the GPU yet to instantiate it.
81 //
82 // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
83 // know the final size until flush time.
Greg Daniel457469c2018-02-08 15:05:44 -050084 GrRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType lazyType,
Greg Daniel4065d452018-11-16 15:43:41 -050085 const GrBackendFormat&, const GrSurfaceDesc&, GrSurfaceOrigin,
86 SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070087
robertphillips76948d42016-05-04 12:47:41 -070088 // Wrapped version
Greg Danielb46add82019-01-02 14:51:29 -050089 enum class WrapsVkSecondaryCB : bool { kNo = false, kYes = true };
90 GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin,
91 WrapsVkSecondaryCB wrapsVkSecondaryCB = WrapsVkSecondaryCB::kNo);
robertphillips76948d42016-05-04 12:47:41 -070092
Robert Phillips5af44de2017-07-18 14:49:38 -040093 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
94
Robert Phillips84a81202016-11-04 11:59:10 -040095private:
Greg Daniela070ed72018-04-26 16:31:38 -040096 void setHasMixedSamples() {
97 fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled;
98 }
99 bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; }
100
Greg Daniela070ed72018-04-26 16:31:38 -0400101 void setGLRTFBOIDIs0() {
102 fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0;
103 }
104 bool glRTFBOIDIs0() const {
105 return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0;
106 }
107
108
Brian Salomonbb5711a2017-05-17 13:49:59 -0400109 size_t onUninstantiatedGpuMemorySize() const override;
Greg Daniel849dce12018-04-24 14:32:53 -0400110 SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
Robert Phillips8bc06d02016-11-01 17:28:40 -0400111
Brian Osman086679b2018-09-10 16:26:51 -0400112 // WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
113 // when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes
114 // each class in the diamond require 16 byte alignment. Clang appears to layout the fields for
115 // each class to achieve the necessary alignment. However, ASAN checks the alignment of 'this'
116 // in the constructors, and always looks for the full 16 byte alignment, even if the fields in
117 // that particular class don't require it. Changing the size of this object can move the start
118 // address of other types, leading to this problem.
119
Greg Danielb46add82019-01-02 14:51:29 -0500120 int fSampleCnt;
121 bool fNeedsStencil;
122 WrapsVkSecondaryCB fWrapsVkSecondaryCB;
Robert Phillips65048132017-08-10 08:44:49 -0400123
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400124 // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
125 // For deferred proxies that pointer is filled in when we need to instantiate the
126 // deferred resource.
robertphillips76948d42016-05-04 12:47:41 -0700127
robertphillips76948d42016-05-04 12:47:41 -0700128 typedef GrSurfaceProxy INHERITED;
129};
130
131#endif