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 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 11 | #include "GrSurfaceProxy.h" |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 12 | #include "GrTypesPriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 13 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 14 | class GrResourceProvider; |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 15 | class GrRenderTargetProxyPriv; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 16 | |
| 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 Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 21 | class GrRenderTargetProxy : virtual public GrSurfaceProxy { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 22 | public: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 23 | GrRenderTargetProxy* asRenderTargetProxy() override { return this; } |
| 24 | const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; } |
| 25 | |
| 26 | // Actually instantiate the backing rendertarget, if necessary. |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 27 | bool instantiate(GrResourceProvider*) override; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 28 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 29 | GrFSAAType fsaaType() const { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 30 | if (fSampleCnt <= 1) { |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 31 | SkASSERT(!this->hasMixedSamples()); |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 32 | return GrFSAAType::kNone; |
| 33 | } |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 34 | return this->hasMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 35 | } |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 36 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 37 | /* |
| 38 | * When instantiated does this proxy require a stencil buffer? |
| 39 | */ |
| 40 | void setNeedsStencil() { fNeedsStencil = true; } |
| 41 | bool needsStencil() const { return fNeedsStencil; } |
| 42 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 43 | /** |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 44 | * 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] | 45 | */ |
| 46 | int numStencilSamples() const { return fSampleCnt; } |
| 47 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 48 | /** |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 49 | * 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] | 50 | */ |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 51 | int numColorSamples() const { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 52 | return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 53 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 54 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 55 | int maxWindowRectangles(const GrCaps& caps) const; |
| 56 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 57 | bool wrapsVkSecondaryCB() const { return fWrapsVkSecondaryCB == WrapsVkSecondaryCB::kYes; } |
| 58 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 59 | // TODO: move this to a priv class! |
| 60 | bool refsWrappedObjects() const; |
| 61 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 62 | // Provides access to special purpose functions. |
| 63 | GrRenderTargetProxyPriv rtPriv(); |
| 64 | const GrRenderTargetProxyPriv rtPriv() const; |
| 65 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 66 | protected: |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 67 | friend class GrProxyProvider; // for ctors |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 68 | friend class GrRenderTargetProxyPriv; |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 69 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 70 | // Deferred version |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 71 | GrRenderTargetProxy(const GrCaps&, const GrBackendFormat&, const GrSurfaceDesc&, |
| 72 | GrSurfaceOrigin, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 73 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 74 | // Lazy-callback version |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 75 | // 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 Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 84 | GrRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType lazyType, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 85 | const GrBackendFormat&, const GrSurfaceDesc&, GrSurfaceOrigin, |
| 86 | SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 87 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 88 | // Wrapped version |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 89 | enum class WrapsVkSecondaryCB : bool { kNo = false, kYes = true }; |
| 90 | GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin, |
| 91 | WrapsVkSecondaryCB wrapsVkSecondaryCB = WrapsVkSecondaryCB::kNo); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 92 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 93 | sk_sp<GrSurface> createSurface(GrResourceProvider*) const override; |
| 94 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 95 | private: |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 96 | void setHasMixedSamples() { |
| 97 | fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled; |
| 98 | } |
| 99 | bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; } |
| 100 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 101 | void setGLRTFBOIDIs0() { |
| 102 | fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 103 | } |
| 104 | bool glRTFBOIDIs0() const { |
| 105 | return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 106 | } |
| 107 | |
| 108 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 109 | size_t onUninstantiatedGpuMemorySize() const override; |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 110 | SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;) |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 111 | |
Brian Osman | 086679b | 2018-09-10 16:26:51 -0400 | [diff] [blame] | 112 | // 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 Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 120 | int fSampleCnt; |
| 121 | bool fNeedsStencil; |
| 122 | WrapsVkSecondaryCB fWrapsVkSecondaryCB; |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 123 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 124 | // 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. |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 127 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 128 | typedef GrSurfaceProxy INHERITED; |
| 129 | }; |
| 130 | |
| 131 | #endif |