2016-05-04 19:47:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrTextureProxy_DEFINED
|
|
|
|
#define GrTextureProxy_DEFINED
|
|
|
|
|
2017-09-07 16:36:34 +00:00
|
|
|
#include "GrSamplerState.h"
|
2016-05-04 19:47:41 +00:00
|
|
|
#include "GrSurfaceProxy.h"
|
|
|
|
|
2016-11-04 15:59:10 +00:00
|
|
|
class GrCaps;
|
2017-10-02 20:38:32 +00:00
|
|
|
class GrDeferredProxyUploader;
|
2018-01-08 18:40:32 +00:00
|
|
|
class GrProxyProvider;
|
2017-03-04 13:12:46 +00:00
|
|
|
class GrResourceProvider;
|
2016-11-23 14:37:01 +00:00
|
|
|
class GrTextureOpList;
|
2017-09-28 13:00:45 +00:00
|
|
|
class GrTextureProxyPriv;
|
2016-05-04 19:47:41 +00:00
|
|
|
|
|
|
|
// This class delays the acquisition of textures until they are actually required
|
2016-11-04 15:59:10 +00:00
|
|
|
class GrTextureProxy : virtual public GrSurfaceProxy {
|
2016-05-04 19:47:41 +00:00
|
|
|
public:
|
|
|
|
GrTextureProxy* asTextureProxy() override { return this; }
|
|
|
|
const GrTextureProxy* asTextureProxy() const override { return this; }
|
|
|
|
|
|
|
|
// Actually instantiate the backing texture, if necessary
|
2017-06-05 13:26:07 +00:00
|
|
|
bool instantiate(GrResourceProvider*) override;
|
2016-05-04 19:47:41 +00:00
|
|
|
|
2017-09-07 16:36:34 +00:00
|
|
|
GrSamplerState::Filter highestFilterMode() const;
|
2017-05-08 17:41:35 +00:00
|
|
|
|
2018-02-09 15:49:23 +00:00
|
|
|
// If we are instantiated and have a target, return the mip state of that target. Otherwise
|
|
|
|
// returns the proxy's mip state from creation time. This is useful for lazy proxies which may
|
|
|
|
// claim to not need mips at creation time, but the instantiation happens to give us a mipped
|
|
|
|
// target. In that case we should use that for our benefit to avoid possible copies/mip
|
|
|
|
// generation later.
|
|
|
|
GrMipMapped mipMapped() const;
|
2017-05-17 17:49:59 +00:00
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
// Returns the GrMipMapped value of the proxy from creation time regardless of whether it has
|
|
|
|
// been instantiated or not.
|
|
|
|
GrMipMapped proxyMipMapped() const { return fMipMapped; }
|
|
|
|
|
|
|
|
/** If true then the texture does not support MIP maps and only supports clamp wrap mode. */
|
2018-11-16 20:43:41 +00:00
|
|
|
bool hasRestrictedSampling() const {
|
|
|
|
return GrTextureTypeHasRestrictedSampling(this->textureType());
|
|
|
|
}
|
2018-11-30 15:12:43 +00:00
|
|
|
|
|
|
|
// Returns true if the passed in proxies can be used as dynamic state together when flushing
|
|
|
|
// draws to the gpu.
|
|
|
|
static bool ProxiesAreCompatibleAsDynamicState(const GrTextureProxy* first,
|
|
|
|
const GrTextureProxy* second);
|
|
|
|
|
2017-09-21 12:26:08 +00:00
|
|
|
/**
|
|
|
|
* Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one.
|
|
|
|
*/
|
|
|
|
const GrUniqueKey& getUniqueKey() const {
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
if (fTarget && fUniqueKey.isValid()) {
|
|
|
|
SkASSERT(fTarget->getUniqueKey().isValid());
|
|
|
|
// It is possible for a non-keyed proxy to have a uniquely keyed resource assigned to
|
|
|
|
// it. This just means that a future user of the resource will be filling it with unique
|
|
|
|
// data. However, if the proxy has a unique key its attached resource should also
|
|
|
|
// have that key.
|
|
|
|
SkASSERT(fUniqueKey == fTarget->getUniqueKey());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return fUniqueKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal-only helper class used for manipulations of the resource by the cache.
|
|
|
|
*/
|
|
|
|
class CacheAccess;
|
|
|
|
inline CacheAccess cacheAccess();
|
|
|
|
inline const CacheAccess cacheAccess() const;
|
|
|
|
|
2017-09-28 13:00:45 +00:00
|
|
|
// Provides access to special purpose functions.
|
|
|
|
GrTextureProxyPriv texPriv();
|
|
|
|
const GrTextureProxyPriv texPriv() const;
|
|
|
|
|
2016-11-04 15:59:10 +00:00
|
|
|
protected:
|
2018-01-16 13:06:32 +00:00
|
|
|
// DDL TODO: rm the GrSurfaceProxy friending
|
2016-11-09 11:50:43 +00:00
|
|
|
friend class GrSurfaceProxy; // for ctors
|
2018-01-16 13:06:32 +00:00
|
|
|
friend class GrProxyProvider; // for ctors
|
2017-10-02 20:38:32 +00:00
|
|
|
friend class GrTextureProxyPriv;
|
2016-11-09 11:50:43 +00:00
|
|
|
|
2018-03-07 18:01:25 +00:00
|
|
|
// Deferred version - when constructed with data the origin is always kTopLeft.
|
2018-11-16 20:43:41 +00:00
|
|
|
GrTextureProxy(const GrBackendFormat&, const GrSurfaceDesc& srcDesc, GrMipMapped, SkBackingFit,
|
2018-07-30 17:13:17 +00:00
|
|
|
SkBudgeted, const void* srcData, size_t srcRowBytes, GrInternalSurfaceFlags);
|
2018-03-07 18:01:25 +00:00
|
|
|
|
|
|
|
// Deferred version - no data.
|
2018-11-16 20:43:41 +00:00
|
|
|
GrTextureProxy(const GrBackendFormat&, const GrSurfaceDesc& srcDesc, GrSurfaceOrigin,
|
|
|
|
GrMipMapped, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
|
2017-11-30 05:01:06 +00:00
|
|
|
|
|
|
|
// Lazy-callback version
|
2018-01-10 22:06:31 +00:00
|
|
|
// There are two main use cases for lazily-instantiated proxies:
|
|
|
|
// basic knowledge - width, height, config, origin are known
|
|
|
|
// minimal knowledge - only config is known.
|
|
|
|
//
|
|
|
|
// The basic knowledge version is used for DDL where we know the type of proxy we are going to
|
|
|
|
// use, but we don't have access to the GPU yet to instantiate it.
|
|
|
|
//
|
|
|
|
// The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
|
|
|
|
// know the final size until flush time.
|
2018-11-16 20:43:41 +00:00
|
|
|
GrTextureProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrBackendFormat&,
|
|
|
|
const GrSurfaceDesc& desc, GrSurfaceOrigin, GrMipMapped, SkBackingFit,
|
|
|
|
SkBudgeted, GrInternalSurfaceFlags);
|
2017-11-30 05:01:06 +00:00
|
|
|
|
2016-05-04 19:47:41 +00:00
|
|
|
// Wrapped version
|
2017-07-25 14:16:35 +00:00
|
|
|
GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
|
2016-05-04 19:47:41 +00:00
|
|
|
|
2017-09-21 12:26:08 +00:00
|
|
|
~GrTextureProxy() override;
|
|
|
|
|
2017-07-18 18:49:38 +00:00
|
|
|
sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
|
2018-04-16 15:24:10 +00:00
|
|
|
|
2016-11-04 15:59:10 +00:00
|
|
|
private:
|
2018-09-10 20:26:51 +00:00
|
|
|
// WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
|
|
|
|
// when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes
|
|
|
|
// each class in the diamond require 16 byte alignment. Clang appears to layout the fields for
|
|
|
|
// each class to achieve the necessary alignment. However, ASAN checks the alignment of 'this'
|
|
|
|
// in the constructors, and always looks for the full 16 byte alignment, even if the fields in
|
|
|
|
// that particular class don't require it. Changing the size of this object can move the start
|
|
|
|
// address of other types, leading to this problem.
|
|
|
|
|
2018-03-16 20:47:25 +00:00
|
|
|
GrMipMapped fMipMapped;
|
2017-05-17 17:49:59 +00:00
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
GrUniqueKey fUniqueKey;
|
|
|
|
GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2017-10-02 20:38:32 +00:00
|
|
|
// Only used for proxies whose contents are being prepared on a worker thread. This object
|
|
|
|
// stores the texture data, allowing the proxy to remain uninstantiated until flush. At that
|
|
|
|
// point, the proxy is instantiated, and this data is used to perform an ASAP upload.
|
|
|
|
std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader;
|
|
|
|
|
2017-05-17 17:49:59 +00:00
|
|
|
size_t onUninstantiatedGpuMemorySize() const override;
|
2016-11-01 21:28:40 +00:00
|
|
|
|
2017-09-21 12:26:08 +00:00
|
|
|
// Methods made available via GrTextureProxy::CacheAccess
|
2018-01-08 18:40:32 +00:00
|
|
|
void setUniqueKey(GrProxyProvider*, const GrUniqueKey&);
|
2017-09-21 12:26:08 +00:00
|
|
|
void clearUniqueKey();
|
|
|
|
|
2018-04-24 18:32:53 +00:00
|
|
|
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
|
2017-11-30 05:01:06 +00:00
|
|
|
|
2016-10-28 17:25:24 +00:00
|
|
|
// For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
|
2017-03-15 17:02:45 +00:00
|
|
|
// For deferred proxies that pointer will be filled in when we need to instantiate
|
2016-10-28 17:25:24 +00:00
|
|
|
// the deferred resource
|
2016-05-04 19:47:41 +00:00
|
|
|
|
|
|
|
typedef GrSurfaceProxy INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|