aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrProxyProvider.h
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-01-08 13:40:32 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-08 19:05:31 +0000
commit1afd4cdb0800e2e395b465da24eb71e0e834dafa (patch)
treed3353e7e4487a86d00002ab882f34ec24347000b /src/gpu/GrProxyProvider.h
parent5ec5d677b02c41a3c58609461cd8b62c2feaeddc (diff)
Add GrProxyProvider
This pulls all the proxy tracking & creation functionality out of the GrResourceCache and GrResourceProvider and consolidates it in the GrProxyProvider. Change-Id: I7256f7c544319a70c1bd93dd5a9ccbe5fa0a544f Reviewed-on: https://skia-review.googlesource.com/91501 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/GrProxyProvider.h')
-rw-r--r--src/gpu/GrProxyProvider.h127
1 files changed, 127 insertions, 0 deletions
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
new file mode 100644
index 0000000000..404e020b43
--- /dev/null
+++ b/src/gpu/GrProxyProvider.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrProxyProvider_DEFINED
+#define GrProxyProvider_DEFINED
+
+#include "GrResourceKey.h"
+#include "GrTextureProxy.h"
+#include "GrTypes.h"
+#include "SkRefCnt.h"
+#include "SkTDynamicHash.h"
+
+class GrCaps;
+class GrResourceProvider;
+class GrSingleOwner;
+
+/*
+ * A factory for creating GrSurfaceProxy-derived objects.
+ */
+class GrProxyProvider {
+public:
+ GrProxyProvider(GrResourceProvider*, GrResourceCache*, sk_sp<const GrCaps>, GrSingleOwner*);
+
+ ~GrProxyProvider();
+
+ /*
+ * Assigns a unique key to a proxy. The proxy will be findable via this key using
+ * findProxyByUniqueKey(). It is an error if an existing proxy already has a key.
+ */
+ void assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
+
+ /*
+ * Sets the unique key of the provided proxy to the unique key of the surface. The surface must
+ * have a valid unique key.
+ */
+ void adoptUniqueKeyFromSurface(GrTextureProxy* proxy, const GrSurface*);
+
+ /*
+ * Removes a unique key from a proxy. If the proxy has already been instantiated, it will
+ * also remove the unique key from the target GrSurface.
+ */
+ void removeUniqueKeyFromProxy(const GrUniqueKey&, GrTextureProxy*);
+
+ /*
+ * Finds a proxy by unique key.
+ */
+ sk_sp<GrTextureProxy> findProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin);
+
+ /*
+ * Finds a proxy by unique key or creates a new one that wraps a resource matching the unique
+ * key.
+ */
+ sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin);
+
+ /*
+ * Create an un-mipmapped texture proxy with data.
+ */
+ sk_sp<GrTextureProxy> createTextureProxy(const GrSurfaceDesc&, SkBudgeted, const GrMipLevel&);
+
+ /*
+ * Create a mipmapped texture proxy with data.
+ */
+ sk_sp<GrTextureProxy> createTextureProxy(const GrSurfaceDesc&, SkBudgeted,
+ const GrMipLevel texels[], int mipLevelCount,
+ SkDestinationSurfaceColorMode mipColorMode);
+
+ // 'proxy' is about to be used as a texture src or drawn to. This query can be used to
+ // determine if it is going to need a texture domain or a full clear.
+ static bool IsFunctionallyExact(GrSurfaceProxy* proxy);
+
+ /**
+ * Either the proxy attached to the unique key is being deleted (in which case we
+ * don't want it cluttering up the hash table) or the client has indicated that
+ * it will never refer to the unique key again. In either case, remove the key
+ * from the hash table.
+ * Note: this does not, by itself, alter unique key attached to the underlying GrTexture.
+ */
+ void processInvalidProxyUniqueKey(const GrUniqueKey&);
+
+ /**
+ * Same as above, but you must pass in a GrTextureProxy to save having to search for it. The
+ * GrUniqueKey of the proxy must be valid and it must match the passed in key. This function
+ * also gives the option to invalidate the GrUniqueKey on the underlying GrTexture.
+ */
+ void processInvalidProxyUniqueKey(const GrUniqueKey&, GrTextureProxy*, bool invalidateSurface);
+
+ const GrCaps* caps() const { return fCaps.get(); }
+
+ void abandon() {
+ fResourceCache = nullptr;
+ fResourceProvider = nullptr;
+ }
+
+ bool isAbandoned() const {
+ SkASSERT(SkToBool(fResourceCache) == SkToBool(fResourceProvider));
+ return !SkToBool(fResourceCache);
+ }
+
+ int numUniqueKeyProxies_TestOnly() const;
+
+ void removeAllUniqueKeys();
+
+private:
+ struct UniquelyKeyedProxyHashTraits {
+ static const GrUniqueKey& GetKey(const GrTextureProxy& p) { return p.getUniqueKey(); }
+
+ static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); }
+ };
+ typedef SkTDynamicHash<GrTextureProxy, GrUniqueKey, UniquelyKeyedProxyHashTraits> UniquelyKeyedProxyHash;
+
+ // This holds the texture proxies that have unique keys. The resourceCache does not get a ref
+ // on these proxies but they must send a message to the resourceCache when they are deleted.
+ UniquelyKeyedProxyHash fUniquelyKeyedProxies;
+
+ GrResourceProvider* fResourceProvider;
+ GrResourceCache* fResourceCache;
+ sk_sp<const GrCaps> fCaps;
+
+ // In debug builds we guard against improper thread handling
+ SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
+};
+
+#endif