blob: 4c36ad7815c4d853f8f27715337416432f23b255 [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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 Salomon2bbdcc42017-09-07 12:36:34 -040011#include "GrSamplerState.h"
robertphillips76948d42016-05-04 12:47:41 -070012#include "GrSurfaceProxy.h"
robertphillips76948d42016-05-04 12:47:41 -070013
Robert Phillips84a81202016-11-04 11:59:10 -040014class GrCaps;
Robert Phillipsae7d3f32017-09-21 08:26:08 -040015class GrResourceCache;
Brian Osman32342f02017-03-04 08:12:46 -050016class GrResourceProvider;
Brian Osman45580d32016-11-23 09:37:01 -050017class GrTextureOpList;
robertphillips76948d42016-05-04 12:47:41 -070018
19// This class delays the acquisition of textures until they are actually required
Robert Phillips84a81202016-11-04 11:59:10 -040020class GrTextureProxy : virtual public GrSurfaceProxy {
robertphillips76948d42016-05-04 12:47:41 -070021public:
robertphillips76948d42016-05-04 12:47:41 -070022 GrTextureProxy* asTextureProxy() override { return this; }
23 const GrTextureProxy* asTextureProxy() const override { return this; }
24
25 // Actually instantiate the backing texture, if necessary
Robert Phillipseee4d6e2017-06-05 09:26:07 -040026 bool instantiate(GrResourceProvider*) override;
robertphillips76948d42016-05-04 12:47:41 -070027
Brian Salomon2bbdcc42017-09-07 12:36:34 -040028 GrSamplerState::Filter highestFilterMode() const;
Robert Phillips49081d12017-05-08 13:41:35 -040029
Robert Phillips8a02f652017-05-12 14:49:16 -040030 GrSLType imageStorageType() const {
31 if (GrPixelConfigIsSint(this->config())) {
32 return kIImageStorage2D_GrSLType;
33 } else {
34 return kImageStorage2D_GrSLType;
35 }
36 }
37
Brian Salomonbb5711a2017-05-17 13:49:59 -040038 bool isMipMapped() const { return fIsMipMapped; }
39
Robert Phillipsae7d3f32017-09-21 08:26:08 -040040 /**
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 Phillips84a81202016-11-04 11:59:10 -040065protected:
Robert Phillips37430132016-11-09 06:50:43 -050066 friend class GrSurfaceProxy; // for ctors
67
robertphillips8abb3702016-08-31 14:04:06 -070068 // Deferred version
69 GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit, SkBudgeted,
Robert Phillipsc787e492017-02-28 11:26:32 -050070 const void* srcData, size_t srcRowBytes, uint32_t flags);
robertphillips76948d42016-05-04 12:47:41 -070071 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -040072 GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
robertphillips76948d42016-05-04 12:47:41 -070073
Robert Phillipsae7d3f32017-09-21 08:26:08 -040074 ~GrTextureProxy() override;
75
Brian Salomon081e0e62017-05-17 14:27:58 -040076 SkDestinationSurfaceColorMode mipColorMode() const { return fMipColorMode; }
77
Robert Phillips5af44de2017-07-18 14:49:38 -040078 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
79
Robert Phillips84a81202016-11-04 11:59:10 -040080private:
Brian Salomonbb5711a2017-05-17 13:49:59 -040081 bool fIsMipMapped;
Brian Salomon081e0e62017-05-17 14:27:58 -040082 SkDestinationSurfaceColorMode fMipColorMode;
Brian Salomonbb5711a2017-05-17 13:49:59 -040083
Robert Phillipsae7d3f32017-09-21 08:26:08 -040084 GrUniqueKey fUniqueKey;
85 GrResourceCache* fCache; // only set when fUniqueKey is valid
86
Brian Salomonbb5711a2017-05-17 13:49:59 -040087 size_t onUninstantiatedGpuMemorySize() const override;
Robert Phillips8bc06d02016-11-01 17:28:40 -040088
Robert Phillipsae7d3f32017-09-21 08:26:08 -040089 // Methods made available via GrTextureProxy::CacheAccess
90 void setUniqueKey(GrResourceCache*, const GrUniqueKey&);
91 void clearUniqueKey();
92
Robert Phillipsc7635fa2016-10-28 13:25:24 -040093 // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
Robert Phillipsa4c41b32017-03-15 13:02:45 -040094 // For deferred proxies that pointer will be filled in when we need to instantiate
Robert Phillipsc7635fa2016-10-28 13:25:24 -040095 // the deferred resource
robertphillips76948d42016-05-04 12:47:41 -070096
97 typedef GrSurfaceProxy INHERITED;
98};
99
100#endif