Revert "Split GrContextThreadSafeProxy into its own files"
This reverts commit f8397f2b3f00ca17da3c028a287097b5d79cd315.
Reason for revert: Breaking Flutter build!
Original change's description:
> Split GrContextThreadSafeProxy into its own files
>
> This just shuffles stuff around.
>
> Change-Id: Ieab35f50945efe87512d7077cb994132f0e0b6ef
> Reviewed-on: https://skia-review.googlesource.com/c/186874
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
TBR=bsalomon@google.com,robertphillips@google.com
Change-Id: I236add95d8a0066037854b5532a7db131d93d603
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/187783
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/gn/gpu.gni b/gn/gpu.gni
index 47106aa..0e805b3 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -15,7 +15,6 @@
"$_include/gpu/GrConfig.h",
"$_include/gpu/GrContextOptions.h",
"$_include/gpu/GrContext.h",
- "$_include/gpu/GrContextThreadSafeProxy.h",
"$_include/gpu/GrDriverBugWorkarounds.h",
"$_include/gpu/GrGpuResource.h",
"$_include/gpu/GrRenderTarget.h",
@@ -72,7 +71,6 @@
"$_src/gpu/GrColorSpaceXform.h",
"$_src/gpu/GrContext.cpp",
"$_src/gpu/GrContextPriv.h",
- "$_src/gpu/GrContextThreadSafeProxy.cpp",
"$_src/gpu/GrContextThreadSafeProxyPriv.h",
"$_src/gpu/GrCoordTransform.h",
"$_src/gpu/GrDDLContext.cpp",
diff --git a/include/core/SkSurfaceCharacterization.h b/include/core/SkSurfaceCharacterization.h
index 9955cd1..8f4c0a3 100644
--- a/include/core/SkSurfaceCharacterization.h
+++ b/include/core/SkSurfaceCharacterization.h
@@ -17,7 +17,7 @@
class SkColorSpace;
#if SK_SUPPORT_GPU
-#include "GrContextThreadSafeProxy.h"
+#include "GrContext.h"
/** \class SkSurfaceCharacterization
A surface characterization contains all the information Ganesh requires to makes its internal
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 54564ae..3b83873 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -13,6 +13,7 @@
#include "SkTypes.h"
#include "../private/GrAuditTrail.h"
#include "../private/GrSingleOwner.h"
+#include "../private/GrSkSLFPFactoryCache.h"
#include "GrContextOptions.h"
// We shouldn't need this but currently Android is relying on this being include transitively.
@@ -24,6 +25,7 @@
class GrCaps;
class GrContextPriv;
class GrContextThreadSafeProxy;
+class GrContextThreadSafeProxyPriv;
class GrDrawingManager;
class GrFragmentProcessor;
struct GrGLInterface;
@@ -37,7 +39,6 @@
class GrResourceCache;
class GrResourceProvider;
class GrSamplerState;
-class GrSkSLFPFactoryCache;
class GrSurfaceProxy;
class GrSwizzle;
class GrTextBlobCache;
@@ -46,6 +47,7 @@
struct GrVkBackendContext;
class SkImage;
+class SkSurfaceCharacterization;
class SkSurfaceProps;
class SkTaskGroup;
class SkTraceMemoryDump;
@@ -357,4 +359,83 @@
typedef SkRefCnt INHERITED;
};
+/**
+ * Can be used to perform actions related to the generating GrContext in a thread safe manner. The
+ * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext.
+ */
+class SK_API GrContextThreadSafeProxy : public SkRefCnt {
+public:
+ ~GrContextThreadSafeProxy();
+
+ bool matches(GrContext* context) const { return context->uniqueID() == fContextUniqueID; }
+
+ /**
+ * Create a surface characterization for a DDL that will be replayed into the GrContext
+ * that created this proxy. On failure the resulting characterization will be invalid (i.e.,
+ * "!c.isValid()").
+ *
+ * @param cacheMaxResourceBytes The max resource bytes limit that will be in effect when the
+ * DDL created with this characterization is replayed.
+ * Note: the contract here is that the DDL will be created as
+ * if it had a full 'cacheMaxResourceBytes' to use. If replayed
+ * into a GrContext that already has locked GPU memory, the
+ * replay can exceed the budget. To rephrase, all resource
+ * allocation decisions are made at record time and at playback
+ * time the budget limits will be ignored.
+ * @param ii The image info specifying properties of the SkSurface that
+ * the DDL created with this characterization will be replayed
+ * into.
+ * Note: Ganesh doesn't make use of the SkImageInfo's alphaType
+ * @param backendFormat Information about the format of the GPU surface that will
+ * back the SkSurface upon replay
+ * @param sampleCount The sample count of the SkSurface that the DDL created with
+ * this characterization will be replayed into
+ * @param origin The origin of the SkSurface that the DDL created with this
+ * characterization will be replayed into
+ * @param surfaceProps The surface properties of the SkSurface that the DDL created
+ * with this characterization will be replayed into
+ * @param isMipMapped Will the surface the DDL will be replayed into have space
+ * allocated for mipmaps?
+ * @param willUseGLFBO0 Will the surface the DDL will be replayed into be backed by GL
+ * FBO 0. This flag is only valid if using an GL backend.
+ */
+ SkSurfaceCharacterization createCharacterization(
+ size_t cacheMaxResourceBytes,
+ const SkImageInfo& ii, const GrBackendFormat& backendFormat,
+ int sampleCount, GrSurfaceOrigin origin,
+ const SkSurfaceProps& surfaceProps,
+ bool isMipMapped, bool willUseGLFBO0 = false);
+
+ bool operator==(const GrContextThreadSafeProxy& that) const {
+ // Each GrContext should only ever have a single thread-safe proxy.
+ SkASSERT((this == &that) == (fContextUniqueID == that.fContextUniqueID));
+ return this == &that;
+ }
+
+ bool operator!=(const GrContextThreadSafeProxy& that) const { return !(*this == that); }
+
+ // Provides access to functions that aren't part of the public API.
+ GrContextThreadSafeProxyPriv priv();
+ const GrContextThreadSafeProxyPriv priv() const;
+
+private:
+ // DDL TODO: need to add unit tests for backend & maybe options
+ GrContextThreadSafeProxy(sk_sp<const GrCaps> caps,
+ uint32_t uniqueID,
+ GrBackendApi backend,
+ const GrContextOptions& options,
+ sk_sp<GrSkSLFPFactoryCache> cache);
+
+ sk_sp<const GrCaps> fCaps;
+ const uint32_t fContextUniqueID;
+ const GrBackendApi fBackend;
+ const GrContextOptions fOptions;
+ sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
+
+ friend class GrDirectContext; // To construct this object
+ friend class GrContextThreadSafeProxyPriv;
+
+ typedef SkRefCnt INHERITED;
+};
+
#endif
diff --git a/include/gpu/GrContextThreadSafeProxy.h b/include/gpu/GrContextThreadSafeProxy.h
deleted file mode 100644
index 7a67843..0000000
--- a/include/gpu/GrContextThreadSafeProxy.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2019 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrContextThreadSafeProxy_DEFINED
-#define GrContextThreadSafeProxy_DEFINED
-
-#include "GrContextOptions.h"
-#include "SkRefCnt.h"
-
-class GrBackendFormat;
-class GrCaps;
-class GrContext;
-class GrContextThreadSafeProxyPriv;
-class GrSkSLFPFactoryCache;
-struct SkImageInfo;
-class SkSurfaceCharacterization;
-
-/**
- * Can be used to perform actions related to the generating GrContext in a thread safe manner. The
- * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext.
- */
-class SK_API GrContextThreadSafeProxy : public SkRefCnt {
-public:
- ~GrContextThreadSafeProxy() override;
-
- bool matches(GrContext* context) const;
-
- /**
- * Create a surface characterization for a DDL that will be replayed into the GrContext
- * that created this proxy. On failure the resulting characterization will be invalid (i.e.,
- * "!c.isValid()").
- *
- * @param cacheMaxResourceBytes The max resource bytes limit that will be in effect when the
- * DDL created with this characterization is replayed.
- * Note: the contract here is that the DDL will be created as
- * if it had a full 'cacheMaxResourceBytes' to use. If replayed
- * into a GrContext that already has locked GPU memory, the
- * replay can exceed the budget. To rephrase, all resource
- * allocation decisions are made at record time and at playback
- * time the budget limits will be ignored.
- * @param ii The image info specifying properties of the SkSurface that
- * the DDL created with this characterization will be replayed
- * into.
- * Note: Ganesh doesn't make use of the SkImageInfo's alphaType
- * @param backendFormat Information about the format of the GPU surface that will
- * back the SkSurface upon replay
- * @param sampleCount The sample count of the SkSurface that the DDL created with
- * this characterization will be replayed into
- * @param origin The origin of the SkSurface that the DDL created with this
- * characterization will be replayed into
- * @param surfaceProps The surface properties of the SkSurface that the DDL created
- * with this characterization will be replayed into
- * @param isMipMapped Will the surface the DDL will be replayed into have space
- * allocated for mipmaps?
- * @param willUseGLFBO0 Will the surface the DDL will be replayed into be backed by GL
- * FBO 0. This flag is only valid if using an GL backend.
- */
- SkSurfaceCharacterization createCharacterization(
- size_t cacheMaxResourceBytes,
- const SkImageInfo& ii, const GrBackendFormat& backendFormat,
- int sampleCount, GrSurfaceOrigin origin,
- const SkSurfaceProps& surfaceProps,
- bool isMipMapped, bool willUseGLFBO0 = false);
-
- bool operator==(const GrContextThreadSafeProxy& that) const {
- // Each GrContext should only ever have a single thread-safe proxy.
- SkASSERT((this == &that) == (fContextUniqueID == that.fContextUniqueID));
- return this == &that;
- }
-
- bool operator!=(const GrContextThreadSafeProxy& that) const { return !(*this == that); }
-
- // Provides access to functions that aren't part of the public API.
- GrContextThreadSafeProxyPriv priv();
- const GrContextThreadSafeProxyPriv priv() const;
-
-private:
- // DDL TODO: need to add unit tests for backend & maybe options
- GrContextThreadSafeProxy(sk_sp<const GrCaps> caps,
- uint32_t uniqueID,
- GrBackendApi backend,
- const GrContextOptions& options,
- sk_sp<GrSkSLFPFactoryCache> cache);
-
- sk_sp<const GrCaps> fCaps;
- const uint32_t fContextUniqueID;
- const GrBackendApi fBackend;
- const GrContextOptions fOptions;
- sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
-
- friend class GrDirectContext; // To construct this object
- friend class GrContextThreadSafeProxyPriv;
-
- typedef SkRefCnt INHERITED;
-};
-
-#endif
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 657b7da..d122a4d 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -169,6 +169,76 @@
//////////////////////////////////////////////////////////////////////////////
+GrContextThreadSafeProxy::GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, uint32_t uniqueID,
+ GrBackendApi backend,
+ const GrContextOptions& options,
+ sk_sp<GrSkSLFPFactoryCache> cache)
+ : fCaps(std::move(caps))
+ , fContextUniqueID(uniqueID)
+ , fBackend(backend)
+ , fOptions(options)
+ , fFPFactoryCache(std::move(cache)) {}
+
+GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
+
+sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
+ return fThreadSafeProxy;
+}
+
+SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
+ size_t cacheMaxResourceBytes,
+ const SkImageInfo& ii, const GrBackendFormat& backendFormat,
+ int sampleCnt, GrSurfaceOrigin origin,
+ const SkSurfaceProps& surfaceProps,
+ bool isMipMapped, bool willUseGLFBO0) {
+ if (!backendFormat.isValid()) {
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
+ // The willUseGLFBO0 flags can only be used for a GL backend.
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ if (!fCaps->mipMapSupport()) {
+ isMipMapped = false;
+ }
+
+ GrPixelConfig config = fCaps->getConfigFromBackendFormat(backendFormat, ii.colorType());
+ if (config == kUnknown_GrPixelConfig) {
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ if (!SkSurface_Gpu::Valid(fCaps.get(), config, ii.colorSpace())) {
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ sampleCnt = fCaps->getRenderTargetSampleCount(sampleCnt, config);
+ if (!sampleCnt) {
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ GrFSAAType FSAAType = GrFSAAType::kNone;
+ if (sampleCnt > 1) {
+ FSAAType = fCaps->usesMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA;
+ }
+
+ // This surface characterization factory assumes that the resulting characterization is
+ // textureable.
+ if (!fCaps->isConfigTexturable(config)) {
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
+ cacheMaxResourceBytes, ii,
+ origin, config, FSAAType, sampleCnt,
+ SkSurfaceCharacterization::Textureable(true),
+ SkSurfaceCharacterization::MipMapped(isMipMapped),
+ SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
+ SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
+ surfaceProps);
+}
+
void GrContext::abandonContext() {
ASSERT_SINGLE_OWNER
@@ -1070,8 +1140,6 @@
return renderTargetContext;
}
-sk_sp<GrSkSLFPFactoryCache> GrContextPriv::getFPFactoryCache() { return fContext->fFPFactoryCache; }
-
std::unique_ptr<GrFragmentProcessor> GrContext::createPMToUPMEffect(
std::unique_ptr<GrFragmentProcessor> fp) {
ASSERT_SINGLE_OWNER
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 24309ec..468a599 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -279,7 +279,9 @@
GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; }
- sk_sp<GrSkSLFPFactoryCache> getFPFactoryCache();
+ sk_sp<GrSkSLFPFactoryCache> getFPFactoryCache() {
+ return fContext->fFPFactoryCache;
+ }
/** This is only useful for debug purposes */
SkDEBUGCODE(GrSingleOwner* debugSingleOwner() const { return &fContext->fSingleOwner; } )
diff --git a/src/gpu/GrContextThreadSafeProxy.cpp b/src/gpu/GrContextThreadSafeProxy.cpp
deleted file mode 100644
index cfa4b33..0000000
--- a/src/gpu/GrContextThreadSafeProxy.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2019 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrContextThreadSafeProxy.h"
-#include "GrContextThreadSafeProxyPriv.h"
-
-#include "GrCaps.h"
-#include "GrContext.h"
-#include "GrSkSLFPFactoryCache.h"
-#include "SkSurface_Gpu.h"
-#include "SkSurfaceCharacterization.h"
-
-GrContextThreadSafeProxy::GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, uint32_t uniqueID,
- GrBackendApi backend,
- const GrContextOptions& options,
- sk_sp<GrSkSLFPFactoryCache> cache)
- : fCaps(std::move(caps))
- , fContextUniqueID(uniqueID)
- , fBackend(backend)
- , fOptions(options)
- , fFPFactoryCache(std::move(cache)) {}
-
-GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
-
-sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
- return fThreadSafeProxy;
-}
-
-bool GrContextThreadSafeProxy::matches(GrContext* context) const {
- return context->uniqueID() == fContextUniqueID;
-}
-
-SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
- size_t cacheMaxResourceBytes,
- const SkImageInfo& ii, const GrBackendFormat& backendFormat,
- int sampleCnt, GrSurfaceOrigin origin,
- const SkSurfaceProps& surfaceProps,
- bool isMipMapped, bool willUseGLFBO0) {
- if (!backendFormat.isValid()) {
- return SkSurfaceCharacterization(); // return an invalid characterization
- }
-
- if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
- // The willUseGLFBO0 flags can only be used for a GL backend.
- return SkSurfaceCharacterization(); // return an invalid characterization
- }
-
- if (!fCaps->mipMapSupport()) {
- isMipMapped = false;
- }
-
- GrPixelConfig config = fCaps->getConfigFromBackendFormat(backendFormat, ii.colorType());
- if (config == kUnknown_GrPixelConfig) {
- return SkSurfaceCharacterization(); // return an invalid characterization
- }
-
- if (!SkSurface_Gpu::Valid(fCaps.get(), config, ii.colorSpace())) {
- return SkSurfaceCharacterization(); // return an invalid characterization
- }
-
- sampleCnt = fCaps->getRenderTargetSampleCount(sampleCnt, config);
- if (!sampleCnt) {
- return SkSurfaceCharacterization(); // return an invalid characterization
- }
-
- GrFSAAType FSAAType = GrFSAAType::kNone;
- if (sampleCnt > 1) {
- FSAAType = fCaps->usesMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA;
- }
-
- // This surface characterization factory assumes that the resulting characterization is
- // textureable.
- if (!fCaps->isConfigTexturable(config)) {
- return SkSurfaceCharacterization(); // return an invalid characterization
- }
-
- return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
- cacheMaxResourceBytes, ii,
- origin, config, FSAAType, sampleCnt,
- SkSurfaceCharacterization::Textureable(true),
- SkSurfaceCharacterization::MipMapped(isMipMapped),
- SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
- SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
- surfaceProps);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() const {
- return fProxy->fFPFactoryCache;
-}
diff --git a/src/gpu/GrContextThreadSafeProxyPriv.h b/src/gpu/GrContextThreadSafeProxyPriv.h
index 298ad78..1d251e4 100644
--- a/src/gpu/GrContextThreadSafeProxyPriv.h
+++ b/src/gpu/GrContextThreadSafeProxyPriv.h
@@ -8,7 +8,7 @@
#ifndef GrContextThreadSafeProxyPriv_DEFINED
#define GrContextThreadSafeProxyPriv_DEFINED
-#include "GrContextThreadSafeProxy.h"
+#include "GrContext.h"
/**
* Class that adds methods to GrContextThreadSafeProxy that are only intended for use internal to
@@ -23,7 +23,7 @@
sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; }
uint32_t contextUniqueID() const { return fProxy->fContextUniqueID; }
GrBackendApi backend() const { return fProxy->fBackend; }
- sk_sp<GrSkSLFPFactoryCache> fpFactoryCache() const;
+ sk_sp<GrSkSLFPFactoryCache> fpFactoryCache() const { return fProxy->fFPFactoryCache; }
private:
explicit GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy) : fProxy(proxy) {}
diff --git a/src/gpu/GrDDLContext.cpp b/src/gpu/GrDDLContext.cpp
index 5461bd9..eb5ed29 100644
--- a/src/gpu/GrDDLContext.cpp
+++ b/src/gpu/GrDDLContext.cpp
@@ -9,7 +9,6 @@
#include "GrCaps.h"
#include "GrContextPriv.h"
#include "GrContextThreadSafeProxyPriv.h"
-#include "GrSkSLFPFactoryCache.h"
/**
* The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index 9e6075c..c46d84e 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -9,7 +9,6 @@
#include "GrContext.h"
#include "GrContextPriv.h"
-#include "GrContextThreadSafeProxy.h"
#include "GrGpu.h"
#include "effects/GrSkSLFP.h"
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index cd7b906..37d3b22 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -9,12 +9,12 @@
#define SkImage_GpuBase_DEFINED
#include "GrBackendSurface.h"
-#include "GrContext.h"
#include "GrTypesPriv.h"
#include "SkDeferredDisplayListRecorder.h"
#include "SkImage_Base.h"
#include "SkYUVAIndex.h"
+class GrContext;
class SkColorSpace;
class SkImage_GpuBase : public SkImage_Base {
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 0197500..907adfa 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -33,7 +33,6 @@
#include "sk_tool_utils.h"
#include "GrContextPriv.h"
-#include "GrContextThreadSafeProxy.h"
#include "GrGpu.h"
#include "GrResourceCache.h"
#include "GrTexture.h"