blob: 77ad84d87991c12313b086dbac004f876cdba6c1 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/private/GrTypesPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrSurfaceProxy.h"
Greg Daniel2c19e7f2019-06-18 13:29:21 -040013#include "src/gpu/GrSwizzle.h"
robertphillips76948d42016-05-04 12:47:41 -070014
Brian Osman32342f02017-03-04 08:12:46 -050015class GrResourceProvider;
Greg Daniela070ed72018-04-26 16:31:38 -040016class GrRenderTargetProxyPriv;
robertphillips76948d42016-05-04 12:47:41 -070017
18// This class delays the acquisition of RenderTargets until they are actually
19// required
20// Beware: the uniqueID of the RenderTargetProxy will usually be different than
21// the uniqueID of the RenderTarget it represents!
Robert Phillips84a81202016-11-04 11:59:10 -040022class GrRenderTargetProxy : virtual public GrSurfaceProxy {
robertphillips76948d42016-05-04 12:47:41 -070023public:
robertphillips76948d42016-05-04 12:47:41 -070024 GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
25 const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
26
27 // Actually instantiate the backing rendertarget, if necessary.
Robert Phillips10d17212019-04-24 14:09:10 -040028 bool instantiate(GrResourceProvider*) override;
robertphillips76948d42016-05-04 12:47:41 -070029
Robert Phillips65048132017-08-10 08:44:49 -040030 /*
31 * When instantiated does this proxy require a stencil buffer?
32 */
33 void setNeedsStencil() { fNeedsStencil = true; }
34 bool needsStencil() const { return fNeedsStencil; }
35
Brian Salomonbb5711a2017-05-17 13:49:59 -040036 /**
Chris Dalton6ce447a2019-06-23 18:07:38 -060037 * Returns the number of samples/pixel in the color buffer (One if non-MSAA).
Brian Salomonbb5711a2017-05-17 13:49:59 -040038 */
Chris Dalton6ce447a2019-06-23 18:07:38 -060039 int numSamples() const { return fSampleCnt; }
robertphillips76948d42016-05-04 12:47:41 -070040
Robert Phillipsec2249f2016-11-09 08:54:35 -050041 int maxWindowRectangles(const GrCaps& caps) const;
42
Greg Daniel2c19e7f2019-06-18 13:29:21 -040043 const GrSwizzle& outputSwizzle() const { return fOutputSwizzle; }
44
Greg Danielb46add82019-01-02 14:51:29 -050045 bool wrapsVkSecondaryCB() const { return fWrapsVkSecondaryCB == WrapsVkSecondaryCB::kYes; }
46
Robert Phillipse2f7d182016-12-15 09:23:05 -050047 // TODO: move this to a priv class!
48 bool refsWrappedObjects() const;
49
Greg Daniela070ed72018-04-26 16:31:38 -040050 // Provides access to special purpose functions.
51 GrRenderTargetProxyPriv rtPriv();
52 const GrRenderTargetProxyPriv rtPriv() const;
53
Robert Phillips84a81202016-11-04 11:59:10 -040054protected:
Robert Phillips0bd24dc2018-01-16 08:06:32 -050055 friend class GrProxyProvider; // for ctors
Greg Daniela070ed72018-04-26 16:31:38 -040056 friend class GrRenderTargetProxyPriv;
Robert Phillips37430132016-11-09 06:50:43 -050057
csmartdaltonf9635992016-08-10 11:09:07 -070058 // Deferred version
Greg Daniel4065d452018-11-16 15:43:41 -050059 GrRenderTargetProxy(const GrCaps&, const GrBackendFormat&, const GrSurfaceDesc&,
Greg Daniel2c19e7f2019-06-18 13:29:21 -040060 GrSurfaceOrigin, const GrSwizzle& textureSwizzle,
61 const GrSwizzle& outputSwizzle, SkBackingFit, SkBudgeted,
62 GrInternalSurfaceFlags);
robertphillips76948d42016-05-04 12:47:41 -070063
Greg Danielb085fa92019-03-05 16:55:12 -050064 enum class WrapsVkSecondaryCB : bool { kNo = false, kYes = true };
65
Chris Dalton706a6ff2017-11-29 22:01:06 -070066 // Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050067 // There are two main use cases for lazily-instantiated proxies:
68 // basic knowledge - width, height, config, samples, origin are known
69 // minimal knowledge - only config is known.
70 //
71 // The basic knowledge version is used for DDL where we know the type of proxy we are going to
72 // use, but we don't have access to the GPU yet to instantiate it.
73 //
74 // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
75 // know the final size until flush time.
Greg Daniel457469c2018-02-08 15:05:44 -050076 GrRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType lazyType,
Greg Daniel4065d452018-11-16 15:43:41 -050077 const GrBackendFormat&, const GrSurfaceDesc&, GrSurfaceOrigin,
Greg Daniel2c19e7f2019-06-18 13:29:21 -040078 const GrSwizzle& textureSwizzle, const GrSwizzle& outputSwizzle,
Greg Danielb085fa92019-03-05 16:55:12 -050079 SkBackingFit, SkBudgeted, GrInternalSurfaceFlags,
80 WrapsVkSecondaryCB wrapsVkSecondaryCB);
Chris Dalton706a6ff2017-11-29 22:01:06 -070081
robertphillips76948d42016-05-04 12:47:41 -070082 // Wrapped version
Greg Daniel2c19e7f2019-06-18 13:29:21 -040083 GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin, const GrSwizzle& textureSwizzle,
84 const GrSwizzle& outputSwizzle,
Greg Danielb46add82019-01-02 14:51:29 -050085 WrapsVkSecondaryCB wrapsVkSecondaryCB = WrapsVkSecondaryCB::kNo);
robertphillips76948d42016-05-04 12:47:41 -070086
Robert Phillips5af44de2017-07-18 14:49:38 -040087 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
88
Robert Phillips84a81202016-11-04 11:59:10 -040089private:
Greg Daniela070ed72018-04-26 16:31:38 -040090 void setGLRTFBOIDIs0() {
91 fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0;
92 }
93 bool glRTFBOIDIs0() const {
94 return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0;
95 }
96
97
Brian Salomonbb5711a2017-05-17 13:49:59 -040098 size_t onUninstantiatedGpuMemorySize() const override;
Greg Daniel849dce12018-04-24 14:32:53 -040099 SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
Robert Phillips8bc06d02016-11-01 17:28:40 -0400100
Brian Osman086679b2018-09-10 16:26:51 -0400101 // WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
102 // when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes
103 // each class in the diamond require 16 byte alignment. Clang appears to layout the fields for
104 // each class to achieve the necessary alignment. However, ASAN checks the alignment of 'this'
105 // in the constructors, and always looks for the full 16 byte alignment, even if the fields in
106 // that particular class don't require it. Changing the size of this object can move the start
107 // address of other types, leading to this problem.
Greg Danielb46add82019-01-02 14:51:29 -0500108 int fSampleCnt;
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400109 GrSwizzle fOutputSwizzle;
Greg Danielb46add82019-01-02 14:51:29 -0500110 bool fNeedsStencil;
111 WrapsVkSecondaryCB fWrapsVkSecondaryCB;
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400112 // This is to fix issue in large comment above. Without the padding we end 6 bytes into a 16
113 // byte range, so the GrTextureProxy ends up starting 8 byte aligned by not 16. We add the
114 // padding here to get us right up to the 16 byte alignment (technically any padding of 3-10
115 // bytes would work since it always goes up to 8 byte alignment, but we use 10 to more explicit
116 // about what we're doing).
117 char fDummyPadding[10];
Robert Phillips65048132017-08-10 08:44:49 -0400118
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400119 // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
120 // For deferred proxies that pointer is filled in when we need to instantiate the
121 // deferred resource.
robertphillips76948d42016-05-04 12:47:41 -0700122
robertphillips76948d42016-05-04 12:47:41 -0700123 typedef GrSurfaceProxy INHERITED;
124};
125
126#endif