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 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 39 | /** |
| 40 | * Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one. |
| 41 | */ |
| 42 | const GrUniqueKey& getUniqueKey() const { |
| 43 | #ifdef SK_DEBUG |
| 44 | if (fTarget && fUniqueKey.isValid()) { |
| 45 | SkASSERT(fTarget->getUniqueKey().isValid()); |
| 46 | // It is possible for a non-keyed proxy to have a uniquely keyed resource assigned to |
| 47 | // it. This just means that a future user of the resource will be filling it with unique |
| 48 | // data. However, if the proxy has a unique key its attached resource should also |
| 49 | // have that key. |
| 50 | SkASSERT(fUniqueKey == fTarget->getUniqueKey()); |
| 51 | } |
| 52 | #endif |
| 53 | |
| 54 | return fUniqueKey; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Internal-only helper class used for manipulations of the resource by the cache. |
| 59 | */ |
| 60 | class CacheAccess; |
| 61 | inline CacheAccess cacheAccess(); |
| 62 | inline const CacheAccess cacheAccess() const; |
| 63 | |
Robert Phillips | 420c4cf | 2017-09-28 09:00:45 -0400 | [diff] [blame] | 64 | // Provides access to special purpose functions. |
| 65 | GrTextureProxyPriv texPriv(); |
| 66 | const GrTextureProxyPriv texPriv() const; |
| 67 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 68 | protected: |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 69 | // DDL TODO: rm the GrSurfaceProxy friending |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 70 | friend class GrSurfaceProxy; // for ctors |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 71 | friend class GrProxyProvider; // for ctors |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 72 | friend class GrTextureProxyPriv; |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 73 | |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 74 | // Deferred version - when constructed with data the origin is always kTopLeft. |
| 75 | GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped, SkBackingFit, SkBudgeted, |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 76 | const void* srcData, size_t srcRowBytes, GrInternalSurfaceFlags); |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 77 | |
| 78 | // Deferred version - no data. |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 79 | GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin, GrMipMapped, SkBackingFit, |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 80 | SkBudgeted, GrInternalSurfaceFlags); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 81 | |
| 82 | // Lazy-callback version |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 83 | // There are two main use cases for lazily-instantiated proxies: |
| 84 | // basic knowledge - width, height, config, origin are known |
| 85 | // minimal knowledge - only config is known. |
| 86 | // |
| 87 | // The basic knowledge version is used for DDL where we know the type of proxy we are going to |
| 88 | // use, but we don't have access to the GPU yet to instantiate it. |
| 89 | // |
| 90 | // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not |
| 91 | // know the final size until flush time. |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 92 | GrTextureProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrSurfaceDesc& desc, |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 93 | GrSurfaceOrigin, GrMipMapped, SkBackingFit, SkBudgeted, |
| 94 | GrInternalSurfaceFlags); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 95 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 96 | // Wrapped version |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 97 | GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 98 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 99 | ~GrTextureProxy() override; |
| 100 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 101 | sk_sp<GrSurface> createSurface(GrResourceProvider*) const override; |
| 102 | |
Greg Daniel | b73a9f8 | 2018-05-02 15:06:47 -0400 | [diff] [blame] | 103 | void setIsGLTextureRectangleOrExternal() { |
| 104 | fSurfaceFlags |= GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal; |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 105 | } |
Greg Daniel | b73a9f8 | 2018-05-02 15:06:47 -0400 | [diff] [blame] | 106 | bool isGLTextureRectangleOrExternal() const { |
| 107 | return fSurfaceFlags & GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal; |
| 108 | } |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 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 | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 112 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 113 | GrUniqueKey fUniqueKey; |
| 114 | GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 115 | |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 116 | // Only used for proxies whose contents are being prepared on a worker thread. This object |
| 117 | // stores the texture data, allowing the proxy to remain uninstantiated until flush. At that |
| 118 | // point, the proxy is instantiated, and this data is used to perform an ASAP upload. |
| 119 | std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader; |
| 120 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 121 | size_t onUninstantiatedGpuMemorySize() const override; |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 122 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 123 | // Methods made available via GrTextureProxy::CacheAccess |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 124 | void setUniqueKey(GrProxyProvider*, const GrUniqueKey&); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 125 | void clearUniqueKey(); |
| 126 | |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 127 | SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 128 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 129 | // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy. |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 130 | // 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] | 131 | // the deferred resource |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 132 | |
| 133 | typedef GrSurfaceProxy INHERITED; |
| 134 | }; |
| 135 | |
| 136 | #endif |