blob: 950a78aa1ba3584fc0c518454d16a5c525b36fbe [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
Robert Phillipsae7d3f32017-09-21 08:26:08 -040039 /**
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 Phillips420c4cf2017-09-28 09:00:45 -040064 // Provides access to special purpose functions.
65 GrTextureProxyPriv texPriv();
66 const GrTextureProxyPriv texPriv() const;
67
Robert Phillips84a81202016-11-04 11:59:10 -040068protected:
Robert Phillips0bd24dc2018-01-16 08:06:32 -050069 // DDL TODO: rm the GrSurfaceProxy friending
Robert Phillips37430132016-11-09 06:50:43 -050070 friend class GrSurfaceProxy; // for ctors
Robert Phillips0bd24dc2018-01-16 08:06:32 -050071 friend class GrProxyProvider; // for ctors
Brian Osman099fa0f2017-10-02 16:38:32 -040072 friend class GrTextureProxyPriv;
Robert Phillips37430132016-11-09 06:50:43 -050073
robertphillips8abb3702016-08-31 14:04:06 -070074 // Deferred version
Brian Salomon2a4f9832018-03-03 22:43:43 -050075 GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin, GrMipMapped, SkBackingFit,
76 SkBudgeted, const void* srcData, size_t srcRowBytes, uint32_t flags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070077
78 // Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050079 // There are two main use cases for lazily-instantiated proxies:
80 // basic knowledge - width, height, config, origin are known
81 // minimal knowledge - only config is known.
82 //
83 // The basic knowledge version is used for DDL where we know the type of proxy we are going to
84 // use, but we don't have access to the GPU yet to instantiate it.
85 //
86 // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
87 // know the final size until flush time.
Greg Daniel457469c2018-02-08 15:05:44 -050088 GrTextureProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrSurfaceDesc& desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -050089 GrSurfaceOrigin, GrMipMapped, SkBackingFit fit, SkBudgeted budgeted,
90 uint32_t flags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070091
robertphillips76948d42016-05-04 12:47:41 -070092 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -040093 GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
robertphillips76948d42016-05-04 12:47:41 -070094
Robert Phillipsae7d3f32017-09-21 08:26:08 -040095 ~GrTextureProxy() override;
96
Robert Phillips5af44de2017-07-18 14:49:38 -040097 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
98
Robert Phillips84a81202016-11-04 11:59:10 -040099private:
Greg Daniele252f082017-10-23 16:05:23 -0400100 GrMipMapped fMipMapped;
Brian Salomonbb5711a2017-05-17 13:49:59 -0400101
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500102 GrUniqueKey fUniqueKey;
103 GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400104
Brian Osman099fa0f2017-10-02 16:38:32 -0400105 // Only used for proxies whose contents are being prepared on a worker thread. This object
106 // stores the texture data, allowing the proxy to remain uninstantiated until flush. At that
107 // point, the proxy is instantiated, and this data is used to perform an ASAP upload.
108 std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader;
109
Brian Salomonbb5711a2017-05-17 13:49:59 -0400110 size_t onUninstantiatedGpuMemorySize() const override;
Robert Phillips8bc06d02016-11-01 17:28:40 -0400111
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400112 // Methods made available via GrTextureProxy::CacheAccess
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500113 void setUniqueKey(GrProxyProvider*, const GrUniqueKey&);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400114 void clearUniqueKey();
115
Robert Phillipse8fabb22018-02-04 14:33:21 -0500116 SkDEBUGCODE(void validateLazySurface(const GrSurface*) override;)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700117
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400118 // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400119 // For deferred proxies that pointer will be filled in when we need to instantiate
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400120 // the deferred resource
robertphillips76948d42016-05-04 12:47:41 -0700121
122 typedef GrSurfaceProxy INHERITED;
123};
124
125#endif