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 GrTextureProxy_DEFINED |
| 9 | #define GrTextureProxy_DEFINED |
| 10 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 11 | #include "GrSamplerState.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 12 | #include "GrSurfaceProxy.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 13 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 14 | class GrCaps; |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 15 | class GrDeferredProxyUploader; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 16 | class GrProxyProvider; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 17 | class GrResourceProvider; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 18 | class GrTextureOpList; |
Robert Phillips | 420c4cf | 2017-09-28 09:00:45 -0400 | [diff] [blame] | 19 | class GrTextureProxyPriv; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 20 | |
| 21 | // This class delays the acquisition of textures until they are actually required |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 22 | class GrTextureProxy : 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 | GrTextureProxy* asTextureProxy() override { return this; } |
| 25 | const GrTextureProxy* asTextureProxy() const override { return this; } |
| 26 | |
| 27 | // Actually instantiate the backing texture, if necessary |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 28 | bool instantiate(GrResourceProvider*) override; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 29 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 30 | GrSamplerState::Filter highestFilterMode() const; |
Robert Phillips | 49081d1 | 2017-05-08 13:41:35 -0400 | [diff] [blame] | 31 | |
Greg Daniel | 3b2ebbb | 2018-02-09 10:49:23 -0500 | [diff] [blame] | 32 | // If we are instantiated and have a target, return the mip state of that target. Otherwise |
| 33 | // returns the proxy's mip state from creation time. This is useful for lazy proxies which may |
| 34 | // claim to not need mips at creation time, but the instantiation happens to give us a mipped |
| 35 | // target. In that case we should use that for our benefit to avoid possible copies/mip |
| 36 | // generation later. |
| 37 | GrMipMapped mipMapped() const; |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 38 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 39 | // Returns the GrMipMapped value of the proxy from creation time regardless of whether it has |
| 40 | // been instantiated or not. |
| 41 | GrMipMapped proxyMipMapped() const { return fMipMapped; } |
| 42 | |
| 43 | GrTextureType textureType() const { return fTextureType; } |
| 44 | /** If true then the texture does not support MIP maps and only supports clamp wrap mode. */ |
| 45 | bool hasRestrictedSampling() const { return GrTextureTypeHasRestrictedSampling(fTextureType); } |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 46 | /** |
| 47 | * Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one. |
| 48 | */ |
| 49 | const GrUniqueKey& getUniqueKey() const { |
| 50 | #ifdef SK_DEBUG |
| 51 | if (fTarget && fUniqueKey.isValid()) { |
| 52 | SkASSERT(fTarget->getUniqueKey().isValid()); |
| 53 | // It is possible for a non-keyed proxy to have a uniquely keyed resource assigned to |
| 54 | // it. This just means that a future user of the resource will be filling it with unique |
| 55 | // data. However, if the proxy has a unique key its attached resource should also |
| 56 | // have that key. |
| 57 | SkASSERT(fUniqueKey == fTarget->getUniqueKey()); |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | return fUniqueKey; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Internal-only helper class used for manipulations of the resource by the cache. |
| 66 | */ |
| 67 | class CacheAccess; |
| 68 | inline CacheAccess cacheAccess(); |
| 69 | inline const CacheAccess cacheAccess() const; |
| 70 | |
Robert Phillips | 420c4cf | 2017-09-28 09:00:45 -0400 | [diff] [blame] | 71 | // Provides access to special purpose functions. |
| 72 | GrTextureProxyPriv texPriv(); |
| 73 | const GrTextureProxyPriv texPriv() const; |
| 74 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 75 | protected: |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 76 | // DDL TODO: rm the GrSurfaceProxy friending |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 77 | friend class GrSurfaceProxy; // for ctors |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 78 | friend class GrProxyProvider; // for ctors |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 79 | friend class GrTextureProxyPriv; |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 80 | |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 81 | // Deferred version - when constructed with data the origin is always kTopLeft. |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 82 | GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped, GrTextureType, SkBackingFit, |
| 83 | SkBudgeted, const void* srcData, size_t srcRowBytes, GrInternalSurfaceFlags); |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 84 | |
| 85 | // Deferred version - no data. |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 86 | GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin, GrMipMapped, GrTextureType, |
| 87 | SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 88 | |
| 89 | // Lazy-callback version |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 90 | // There are two main use cases for lazily-instantiated proxies: |
| 91 | // basic knowledge - width, height, config, origin are known |
| 92 | // minimal knowledge - only config is known. |
| 93 | // |
| 94 | // The basic knowledge version is used for DDL where we know the type of proxy we are going to |
| 95 | // use, but we don't have access to the GPU yet to instantiate it. |
| 96 | // |
| 97 | // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not |
| 98 | // know the final size until flush time. |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 99 | GrTextureProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrSurfaceDesc& desc, |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 100 | GrSurfaceOrigin, GrMipMapped, GrTextureType, SkBackingFit, SkBudgeted, |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 101 | GrInternalSurfaceFlags); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 102 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 103 | // Wrapped version |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 104 | GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 105 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 106 | ~GrTextureProxy() override; |
| 107 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 108 | sk_sp<GrSurface> createSurface(GrResourceProvider*) const override; |
| 109 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 110 | private: |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 111 | GrMipMapped fMipMapped; |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 112 | GrTextureType fTextureType; |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 113 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 114 | GrUniqueKey fUniqueKey; |
| 115 | GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 116 | |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 117 | // Only used for proxies whose contents are being prepared on a worker thread. This object |
| 118 | // stores the texture data, allowing the proxy to remain uninstantiated until flush. At that |
| 119 | // point, the proxy is instantiated, and this data is used to perform an ASAP upload. |
| 120 | std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader; |
| 121 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 122 | size_t onUninstantiatedGpuMemorySize() const override; |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 123 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 124 | // Methods made available via GrTextureProxy::CacheAccess |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 125 | void setUniqueKey(GrProxyProvider*, const GrUniqueKey&); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 126 | void clearUniqueKey(); |
| 127 | |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 128 | SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 129 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 130 | // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy. |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 131 | // For deferred proxies that pointer will be filled in when we need to instantiate |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 132 | // the deferred resource |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 133 | |
| 134 | typedef GrSurfaceProxy INHERITED; |
| 135 | }; |
| 136 | |
| 137 | #endif |