• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
11 #include "GrSamplerState.h"
12 #include "GrSurfaceProxy.h"
13 
14 class GrCaps;
15 class GrDeferredProxyUploader;
16 class GrProxyProvider;
17 class GrResourceProvider;
18 class GrTextureOpList;
19 class GrTextureProxyPriv;
20 
21 // This class delays the acquisition of textures until they are actually required
22 class GrTextureProxy : virtual public GrSurfaceProxy {
23 public:
asTextureProxy()24     GrTextureProxy* asTextureProxy() override { return this; }
asTextureProxy()25     const GrTextureProxy* asTextureProxy() const override { return this; }
26 
27     // Actually instantiate the backing texture, if necessary
28     bool instantiate(GrResourceProvider*) override;
29 
30     GrSamplerState::Filter highestFilterMode() const;
31 
32     // 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;
38 
39     /**
40      * Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one.
41      */
getUniqueKey()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 
64     // Provides access to special purpose functions.
65     GrTextureProxyPriv texPriv();
66     const GrTextureProxyPriv texPriv() const;
67 
68 protected:
69     // DDL TODO: rm the GrSurfaceProxy friending
70     friend class GrSurfaceProxy; // for ctors
71     friend class GrProxyProvider; // for ctors
72     friend class GrTextureProxyPriv;
73 
74     // Deferred version
75     GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped, SkBackingFit, SkBudgeted,
76                    const void* srcData, size_t srcRowBytes, uint32_t flags);
77 
78     // Lazy-callback version
79     // 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.
88     GrTextureProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrSurfaceDesc& desc,
89                    GrMipMapped, SkBackingFit fit, SkBudgeted budgeted, uint32_t flags);
90 
91     // Wrapped version
92     GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
93 
94     ~GrTextureProxy() override;
95 
96     sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
97 
98 private:
99     GrMipMapped fMipMapped;
100 
101     GrUniqueKey      fUniqueKey;
102     GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid
103 
104     // Only used for proxies whose contents are being prepared on a worker thread. This object
105     // stores the texture data, allowing the proxy to remain uninstantiated until flush. At that
106     // point, the proxy is instantiated, and this data is used to perform an ASAP upload.
107     std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader;
108 
109     size_t onUninstantiatedGpuMemorySize() const override;
110 
111     // Methods made available via GrTextureProxy::CacheAccess
112     void setUniqueKey(GrProxyProvider*, const GrUniqueKey&);
113     void clearUniqueKey();
114 
115     SkDEBUGCODE(void validateLazySurface(const GrSurface*) override;)
116 
117     // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
118     // For deferred proxies that pointer will be filled in when we need to instantiate
119     // the deferred resource
120 
121     typedef GrSurfaceProxy INHERITED;
122 };
123 
124 #endif
125