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; |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 15 | class GrResourceCache; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 16 | class GrResourceProvider; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 17 | class GrTextureOpList; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 18 | |
| 19 | // This class delays the acquisition of textures until they are actually required |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 20 | class GrTextureProxy : virtual public GrSurfaceProxy { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 21 | public: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 22 | GrTextureProxy* asTextureProxy() override { return this; } |
| 23 | const GrTextureProxy* asTextureProxy() const override { return this; } |
| 24 | |
| 25 | // Actually instantiate the backing texture, if necessary |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 26 | bool instantiate(GrResourceProvider*) override; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 27 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 28 | GrSamplerState::Filter highestFilterMode() const; |
Robert Phillips | 49081d1 | 2017-05-08 13:41:35 -0400 | [diff] [blame] | 29 | |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 30 | GrSLType imageStorageType() const { |
| 31 | if (GrPixelConfigIsSint(this->config())) { |
| 32 | return kIImageStorage2D_GrSLType; |
| 33 | } else { |
| 34 | return kImageStorage2D_GrSLType; |
| 35 | } |
| 36 | } |
| 37 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 38 | bool isMipMapped() const { return fIsMipMapped; } |
| 39 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 40 | /** |
| 41 | * Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one. |
| 42 | */ |
| 43 | const GrUniqueKey& getUniqueKey() const { |
| 44 | #ifdef SK_DEBUG |
| 45 | if (fTarget && fUniqueKey.isValid()) { |
| 46 | SkASSERT(fTarget->getUniqueKey().isValid()); |
| 47 | // It is possible for a non-keyed proxy to have a uniquely keyed resource assigned to |
| 48 | // it. This just means that a future user of the resource will be filling it with unique |
| 49 | // data. However, if the proxy has a unique key its attached resource should also |
| 50 | // have that key. |
| 51 | SkASSERT(fUniqueKey == fTarget->getUniqueKey()); |
| 52 | } |
| 53 | #endif |
| 54 | |
| 55 | return fUniqueKey; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Internal-only helper class used for manipulations of the resource by the cache. |
| 60 | */ |
| 61 | class CacheAccess; |
| 62 | inline CacheAccess cacheAccess(); |
| 63 | inline const CacheAccess cacheAccess() const; |
| 64 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 65 | protected: |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 66 | friend class GrSurfaceProxy; // for ctors |
| 67 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 68 | // Deferred version |
| 69 | GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit, SkBudgeted, |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 70 | const void* srcData, size_t srcRowBytes, uint32_t flags); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 71 | // Wrapped version |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 72 | GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 73 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 74 | ~GrTextureProxy() override; |
| 75 | |
Brian Salomon | 081e0e6 | 2017-05-17 14:27:58 -0400 | [diff] [blame] | 76 | SkDestinationSurfaceColorMode mipColorMode() const { return fMipColorMode; } |
| 77 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 78 | sk_sp<GrSurface> createSurface(GrResourceProvider*) const override; |
| 79 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 80 | private: |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 81 | bool fIsMipMapped; |
Brian Salomon | 081e0e6 | 2017-05-17 14:27:58 -0400 | [diff] [blame] | 82 | SkDestinationSurfaceColorMode fMipColorMode; |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 83 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 84 | GrUniqueKey fUniqueKey; |
| 85 | GrResourceCache* fCache; // only set when fUniqueKey is valid |
| 86 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 87 | size_t onUninstantiatedGpuMemorySize() const override; |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 88 | |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 89 | // Methods made available via GrTextureProxy::CacheAccess |
| 90 | void setUniqueKey(GrResourceCache*, const GrUniqueKey&); |
| 91 | void clearUniqueKey(); |
| 92 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 93 | // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy. |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 94 | // 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] | 95 | // the deferred resource |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 96 | |
| 97 | typedef GrSurfaceProxy INHERITED; |
| 98 | }; |
| 99 | |
| 100 | #endif |