robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/GrTypesPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrSurfaceProxy.h" |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrSwizzle.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 14 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 15 | class GrResourceProvider; |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 16 | class GrRenderTargetProxyPriv; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 17 | |
| 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 Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 22 | class GrRenderTargetProxy : virtual public GrSurfaceProxy { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 23 | public: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 24 | GrRenderTargetProxy* asRenderTargetProxy() override { return this; } |
| 25 | const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; } |
| 26 | |
| 27 | // Actually instantiate the backing rendertarget, if necessary. |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 28 | bool instantiate(GrResourceProvider*) override; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 29 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 30 | GrFSAAType fsaaType() const { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 31 | if (fSampleCnt <= 1) { |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 32 | SkASSERT(!this->hasMixedSamples()); |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 33 | return GrFSAAType::kNone; |
| 34 | } |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 35 | return this->hasMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 36 | } |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 37 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 38 | /* |
| 39 | * When instantiated does this proxy require a stencil buffer? |
| 40 | */ |
| 41 | void setNeedsStencil() { fNeedsStencil = true; } |
| 42 | bool needsStencil() const { return fNeedsStencil; } |
| 43 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 44 | /** |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 45 | * Returns the number of samples/pixel in the stencil buffer (One if non-MSAA). |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 46 | */ |
| 47 | int numStencilSamples() const { return fSampleCnt; } |
| 48 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 49 | /** |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 50 | * Returns the number of samples/pixel in the color buffer (One if non-MSAA or mixed sampled). |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 51 | */ |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 52 | int numColorSamples() const { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 53 | return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 54 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 55 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 56 | int maxWindowRectangles(const GrCaps& caps) const; |
| 57 | |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 58 | const GrSwizzle& outputSwizzle() const { return fOutputSwizzle; } |
| 59 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 60 | bool wrapsVkSecondaryCB() const { return fWrapsVkSecondaryCB == WrapsVkSecondaryCB::kYes; } |
| 61 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 62 | // TODO: move this to a priv class! |
| 63 | bool refsWrappedObjects() const; |
| 64 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 65 | // Provides access to special purpose functions. |
| 66 | GrRenderTargetProxyPriv rtPriv(); |
| 67 | const GrRenderTargetProxyPriv rtPriv() const; |
| 68 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 69 | protected: |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 70 | friend class GrProxyProvider; // for ctors |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 71 | friend class GrRenderTargetProxyPriv; |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 72 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 73 | // Deferred version |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 74 | GrRenderTargetProxy(const GrCaps&, const GrBackendFormat&, const GrSurfaceDesc&, |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 75 | GrSurfaceOrigin, const GrSwizzle& textureSwizzle, |
| 76 | const GrSwizzle& outputSwizzle, SkBackingFit, SkBudgeted, |
| 77 | GrInternalSurfaceFlags); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 78 | |
Greg Daniel | b085fa9 | 2019-03-05 16:55:12 -0500 | [diff] [blame] | 79 | enum class WrapsVkSecondaryCB : bool { kNo = false, kYes = true }; |
| 80 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 81 | // Lazy-callback version |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 82 | // There are two main use cases for lazily-instantiated proxies: |
| 83 | // basic knowledge - width, height, config, samples, origin are known |
| 84 | // minimal knowledge - only config is known. |
| 85 | // |
| 86 | // The basic knowledge version is used for DDL where we know the type of proxy we are going to |
| 87 | // use, but we don't have access to the GPU yet to instantiate it. |
| 88 | // |
| 89 | // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not |
| 90 | // know the final size until flush time. |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 91 | GrRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType lazyType, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 92 | const GrBackendFormat&, const GrSurfaceDesc&, GrSurfaceOrigin, |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 93 | const GrSwizzle& textureSwizzle, const GrSwizzle& outputSwizzle, |
Greg Daniel | b085fa9 | 2019-03-05 16:55:12 -0500 | [diff] [blame] | 94 | SkBackingFit, SkBudgeted, GrInternalSurfaceFlags, |
| 95 | WrapsVkSecondaryCB wrapsVkSecondaryCB); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 96 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 97 | // Wrapped version |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 98 | GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin, const GrSwizzle& textureSwizzle, |
| 99 | const GrSwizzle& outputSwizzle, |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 100 | WrapsVkSecondaryCB wrapsVkSecondaryCB = WrapsVkSecondaryCB::kNo); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 101 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 102 | sk_sp<GrSurface> createSurface(GrResourceProvider*) const override; |
| 103 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 104 | private: |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 105 | void setHasMixedSamples() { |
| 106 | fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled; |
| 107 | } |
| 108 | bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; } |
| 109 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 110 | void setGLRTFBOIDIs0() { |
| 111 | fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 112 | } |
| 113 | bool glRTFBOIDIs0() const { |
| 114 | return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 115 | } |
| 116 | |
| 117 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 118 | size_t onUninstantiatedGpuMemorySize() const override; |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 119 | SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;) |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 120 | |
Brian Osman | 086679b | 2018-09-10 16:26:51 -0400 | [diff] [blame] | 121 | // WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings |
| 122 | // when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes |
| 123 | // each class in the diamond require 16 byte alignment. Clang appears to layout the fields for |
| 124 | // each class to achieve the necessary alignment. However, ASAN checks the alignment of 'this' |
| 125 | // in the constructors, and always looks for the full 16 byte alignment, even if the fields in |
| 126 | // that particular class don't require it. Changing the size of this object can move the start |
| 127 | // address of other types, leading to this problem. |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 128 | int fSampleCnt; |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 129 | GrSwizzle fOutputSwizzle; |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 130 | bool fNeedsStencil; |
| 131 | WrapsVkSecondaryCB fWrapsVkSecondaryCB; |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 132 | // This is to fix issue in large comment above. Without the padding we end 6 bytes into a 16 |
| 133 | // byte range, so the GrTextureProxy ends up starting 8 byte aligned by not 16. We add the |
| 134 | // padding here to get us right up to the 16 byte alignment (technically any padding of 3-10 |
| 135 | // bytes would work since it always goes up to 8 byte alignment, but we use 10 to more explicit |
| 136 | // about what we're doing). |
| 137 | char fDummyPadding[10]; |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 138 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 139 | // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class. |
| 140 | // For deferred proxies that pointer is filled in when we need to instantiate the |
| 141 | // deferred resource. |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 142 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 143 | typedef GrSurfaceProxy INHERITED; |
| 144 | }; |
| 145 | |
| 146 | #endif |