blob: 3aee3de361c2580b403662433cd036e931a442bb [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 Daniele252f082017-10-23 16:05:23 -040032 GrMipMapped mipMapped() const { return fMipMapped; }
Brian Salomonbb5711a2017-05-17 13:49:59 -040033
Robert Phillipsae7d3f32017-09-21 08:26:08 -040034 /**
35 * Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one.
36 */
37 const GrUniqueKey& getUniqueKey() const {
38#ifdef SK_DEBUG
39 if (fTarget && fUniqueKey.isValid()) {
40 SkASSERT(fTarget->getUniqueKey().isValid());
41 // It is possible for a non-keyed proxy to have a uniquely keyed resource assigned to
42 // it. This just means that a future user of the resource will be filling it with unique
43 // data. However, if the proxy has a unique key its attached resource should also
44 // have that key.
45 SkASSERT(fUniqueKey == fTarget->getUniqueKey());
46 }
47#endif
48
49 return fUniqueKey;
50 }
51
52 /**
53 * Internal-only helper class used for manipulations of the resource by the cache.
54 */
55 class CacheAccess;
56 inline CacheAccess cacheAccess();
57 inline const CacheAccess cacheAccess() const;
58
Robert Phillips420c4cf2017-09-28 09:00:45 -040059 // Provides access to special purpose functions.
60 GrTextureProxyPriv texPriv();
61 const GrTextureProxyPriv texPriv() const;
62
Robert Phillips84a81202016-11-04 11:59:10 -040063protected:
Robert Phillips0bd24dc2018-01-16 08:06:32 -050064 // DDL TODO: rm the GrSurfaceProxy friending
Robert Phillips37430132016-11-09 06:50:43 -050065 friend class GrSurfaceProxy; // for ctors
Robert Phillips0bd24dc2018-01-16 08:06:32 -050066 friend class GrProxyProvider; // for ctors
Brian Osman099fa0f2017-10-02 16:38:32 -040067 friend class GrTextureProxyPriv;
Robert Phillips37430132016-11-09 06:50:43 -050068
robertphillips8abb3702016-08-31 14:04:06 -070069 // Deferred version
70 GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit, SkBudgeted,
Robert Phillipsc787e492017-02-28 11:26:32 -050071 const void* srcData, size_t srcRowBytes, uint32_t flags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070072
73 // Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050074 // There are two main use cases for lazily-instantiated proxies:
75 // basic knowledge - width, height, config, origin are known
76 // minimal knowledge - only config is known.
77 //
78 // The basic knowledge version is used for DDL where we know the type of proxy we are going to
79 // use, but we don't have access to the GPU yet to instantiate it.
80 //
81 // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
82 // know the final size until flush time.
83 GrTextureProxy(LazyInstantiateCallback&&, const GrSurfaceDesc& desc, GrMipMapped,
84 SkBackingFit fit, SkBudgeted budgeted, uint32_t flags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070085
robertphillips76948d42016-05-04 12:47:41 -070086 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -040087 GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
robertphillips76948d42016-05-04 12:47:41 -070088
Robert Phillipsae7d3f32017-09-21 08:26:08 -040089 ~GrTextureProxy() override;
90
Greg Daniel65fa8ca2018-01-10 17:06:31 -050091 SkDestinationSurfaceColorMode mipColorMode() const {
92 SkASSERT(LazyState::kNot == this->lazyInstantiationState());
93 return fMipColorMode;
94 }
Brian Salomon081e0e62017-05-17 14:27:58 -040095
Robert Phillips5af44de2017-07-18 14:49:38 -040096 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
97
Robert Phillips84a81202016-11-04 11:59:10 -040098private:
Greg Daniele252f082017-10-23 16:05:23 -040099 GrMipMapped fMipMapped;
Brian Salomon081e0e62017-05-17 14:27:58 -0400100 SkDestinationSurfaceColorMode fMipColorMode;
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