blob: fc7f1c54a73f434e973b156b67aeb85aa1ae38f8 [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
Brian Salomon58389b92018-03-07 13:01:25 -050074 // Deferred version - when constructed with data the origin is always kTopLeft.
75 GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped, SkBackingFit, SkBudgeted,
Robert Phillipsfe0253f2018-03-16 16:47:25 -040076 const void* srcData, size_t srcRowBytes, GrInternalSurfaceFlags);
Brian Salomon58389b92018-03-07 13:01:25 -050077
78 // Deferred version - no data.
Brian Salomon2a4f9832018-03-03 22:43:43 -050079 GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin, GrMipMapped, SkBackingFit,
Robert Phillipsfe0253f2018-03-16 16:47:25 -040080 SkBudgeted, GrInternalSurfaceFlags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070081
82 // Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -050083 // There are two main use cases for lazily-instantiated proxies:
84 // basic knowledge - width, height, config, origin are known
85 // minimal knowledge - only config is known.
86 //
87 // The basic knowledge version is used for DDL where we know the type of proxy we are going to
88 // use, but we don't have access to the GPU yet to instantiate it.
89 //
90 // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
91 // know the final size until flush time.
Greg Daniel457469c2018-02-08 15:05:44 -050092 GrTextureProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrSurfaceDesc& desc,
Robert Phillipsfe0253f2018-03-16 16:47:25 -040093 GrSurfaceOrigin, GrMipMapped, SkBackingFit, SkBudgeted,
94 GrInternalSurfaceFlags);
Chris Dalton706a6ff2017-11-29 22:01:06 -070095
robertphillips76948d42016-05-04 12:47:41 -070096 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -040097 GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
robertphillips76948d42016-05-04 12:47:41 -070098
Robert Phillipsae7d3f32017-09-21 08:26:08 -040099 ~GrTextureProxy() override;
100
Robert Phillips5af44de2017-07-18 14:49:38 -0400101 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
102
Greg Danielb73a9f82018-05-02 15:06:47 -0400103 void setIsGLTextureRectangleOrExternal() {
104 fSurfaceFlags |= GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal;
Greg Daniele3204862018-04-16 11:24:10 -0400105 }
Greg Danielb73a9f82018-05-02 15:06:47 -0400106 bool isGLTextureRectangleOrExternal() const {
107 return fSurfaceFlags & GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal;
108 }
Greg Daniele3204862018-04-16 11:24:10 -0400109
Robert Phillips84a81202016-11-04 11:59:10 -0400110private:
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400111 GrMipMapped fMipMapped;
Brian Salomonbb5711a2017-05-17 13:49:59 -0400112
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500113 GrUniqueKey fUniqueKey;
114 GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400115
Brian Osman099fa0f2017-10-02 16:38:32 -0400116 // Only used for proxies whose contents are being prepared on a worker thread. This object
117 // stores the texture data, allowing the proxy to remain uninstantiated until flush. At that
118 // point, the proxy is instantiated, and this data is used to perform an ASAP upload.
119 std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader;
120
Brian Salomonbb5711a2017-05-17 13:49:59 -0400121 size_t onUninstantiatedGpuMemorySize() const override;
Robert Phillips8bc06d02016-11-01 17:28:40 -0400122
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400123 // Methods made available via GrTextureProxy::CacheAccess
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500124 void setUniqueKey(GrProxyProvider*, const GrUniqueKey&);
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400125 void clearUniqueKey();
126
Greg Daniel849dce12018-04-24 14:32:53 -0400127 SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700128
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400129 // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400130 // For deferred proxies that pointer will be filled in when we need to instantiate
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400131 // the deferred resource
robertphillips76948d42016-05-04 12:47:41 -0700132
133 typedef GrSurfaceProxy INHERITED;
134};
135
136#endif