blob: 4df0263f42d3b0e82a894d0fcc73b1bfa6171533 [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;
Brian Osman099fa0f2017-10-02 16:38:32 -040015class GrDeferredProxyUploader;
Robert Phillips1afd4cd2018-01-08 13:40:32 -050016class GrProxyProvider;
Brian Osman32342f02017-03-04 08:12:46 -050017class GrResourceProvider;
Brian Osman45580d32016-11-23 09:37:01 -050018class GrTextureOpList;
Robert Phillips420c4cf2017-09-28 09:00:45 -040019class GrTextureProxyPriv;
robertphillips76948d42016-05-04 12:47:41 -070020
21// This class delays the acquisition of textures until they are actually required
Robert Phillips84a81202016-11-04 11:59:10 -040022class GrTextureProxy : virtual public GrSurfaceProxy {
robertphillips76948d42016-05-04 12:47:41 -070023public:
robertphillips76948d42016-05-04 12:47:41 -070024 GrTextureProxy* asTextureProxy() override { return this; }
25 const GrTextureProxy* asTextureProxy() const override { return this; }
26
27 // Actually instantiate the backing texture, if necessary
Robert Phillipseee4d6e2017-06-05 09:26:07 -040028 bool instantiate(GrResourceProvider*) override;
robertphillips76948d42016-05-04 12:47:41 -070029
Brian Salomon2bbdcc42017-09-07 12:36:34 -040030 GrSamplerState::Filter highestFilterMode() const;
Robert Phillips49081d12017-05-08 13:41:35 -040031
Greg Daniel3b2ebbb2018-02-09 10:49:23 -050032 // 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 Salomonbb5711a2017-05-17 13:49:59 -040038
Brian Salomonfd98c2c2018-07-31 17:25:29 -040039 // 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 Phillipsae7d3f32017-09-21 08:26:08 -040046 /**
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 Phillips420c4cf2017-09-28 09:00:45 -040071 // Provides access to special purpose functions.
72 GrTextureProxyPriv texPriv();
73 const GrTextureProxyPriv texPriv() const;
74
Robert Phillips84a81202016-11-04 11:59:10 -040075protected:
Robert Phillips0bd24dc2018-01-16 08:06:32 -050076 // DDL TODO: rm the GrSurfaceProxy friending
Robert Phillips37430132016-11-09 06:50:43 -050077 friend class GrSurfaceProxy; // for ctors
Robert Phillips0bd24dc2018-01-16 08:06:32 -050078 friend class GrProxyProvider; // for ctors
Brian Osman099fa0f2017-10-02 16:38:32 -040079 friend class GrTextureProxyPriv;
Robert Phillips37430132016-11-09 06:50:43 -050080
Brian Salomon58389b92018-03-07 13:01:25 -050081 // Deferred version - when constructed with data the origin is always kTopLeft.
Brian Salomon7226c232018-07-30 13:13:17 -040082 GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped, GrTextureType, SkBackingFit,
83 SkBudgeted, const void* srcData, size_t srcRowBytes, GrInternalSurfaceFlags);
Brian Salomon58389b92018-03-07 13:01:25 -050084
85 // Deferred version - no data.
Brian Salomon7226c232018-07-30 13:13:17 -040086 GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin, GrMipMapped, GrTextureType,
87 SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070088
89 // Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050090 // 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 Daniel457469c2018-02-08 15:05:44 -050099 GrTextureProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrSurfaceDesc& desc,
Brian Salomon7226c232018-07-30 13:13:17 -0400100 GrSurfaceOrigin, GrMipMapped, GrTextureType, SkBackingFit, SkBudgeted,
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400101 GrInternalSurfaceFlags);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700102
robertphillips76948d42016-05-04 12:47:41 -0700103 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -0400104 GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
robertphillips76948d42016-05-04 12:47:41 -0700105
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400106 ~GrTextureProxy() override;
107
Robert Phillips5af44de2017-07-18 14:49:38 -0400108 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
109
Robert Phillips84a81202016-11-04 11:59:10 -0400110private:
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400111 GrMipMapped fMipMapped;
Brian Salomon7226c232018-07-30 13:13:17 -0400112 GrTextureType fTextureType;
Brian Salomonbb5711a2017-05-17 13:49:59 -0400113
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500114 GrUniqueKey fUniqueKey;
115 GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400116
Brian Osman099fa0f2017-10-02 16:38:32 -0400117 // 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 Salomonbb5711a2017-05-17 13:49:59 -0400122 size_t onUninstantiatedGpuMemorySize() const override;
Robert Phillips8bc06d02016-11-01 17:28:40 -0400123
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400124 // Methods made available via GrTextureProxy::CacheAccess
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500125 void setUniqueKey(GrProxyProvider*, const GrUniqueKey&);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400126 void clearUniqueKey();
127
Greg Daniel849dce12018-04-24 14:32:53 -0400128 SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700129
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400130 // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400131 // For deferred proxies that pointer will be filled in when we need to instantiate
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400132 // the deferred resource
robertphillips76948d42016-05-04 12:47:41 -0700133
134 typedef GrSurfaceProxy INHERITED;
135};
136
137#endif