aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gn/gpu.gni1
-rw-r--r--include/core/SkSurfaceCharacterization.h19
-rw-r--r--include/gpu/GrContext.h18
-rw-r--r--src/core/SkSurfaceCharacterization.cpp21
-rw-r--r--src/gpu/GrContextThreadSafeProxyPriv.h49
-rw-r--r--src/gpu/GrDDLContext.cpp8
6 files changed, 88 insertions, 28 deletions
diff --git a/gn/gpu.gni b/gn/gpu.gni
index 8b79484fc5..8f0d04b8ae 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -71,6 +71,7 @@ skia_gpu_sources = [
"$_src/gpu/GrColorSpaceXform.h",
"$_src/gpu/GrContext.cpp",
"$_src/gpu/GrContextPriv.h",
+ "$_src/gpu/GrContextThreadSafeProxyPriv.h",
"$_src/gpu/GrCoordTransform.h",
"$_src/gpu/GrDDLContext.cpp",
"$_src/gpu/GrDefaultGeoProcFactory.cpp",
diff --git a/include/core/SkSurfaceCharacterization.h b/include/core/SkSurfaceCharacterization.h
index e8efdcf2a9..2abd5b6555 100644
--- a/include/core/SkSurfaceCharacterization.h
+++ b/include/core/SkSurfaceCharacterization.h
@@ -54,24 +54,7 @@ public:
return !(*this == other);
}
- SkSurfaceCharacterization createResized(int width, int height) const {
- const GrCaps* caps = fContextInfo->caps();
- if (!caps) {
- return SkSurfaceCharacterization();
- }
-
- if (width <= 0 || height <= 0 ||
- width > caps->maxRenderTargetSize() || height > caps->maxRenderTargetSize()) {
- return SkSurfaceCharacterization();
- }
-
- return SkSurfaceCharacterization(fContextInfo,
- fCacheMaxResourceBytes,
- fImageInfo.makeWH(width, height),
- fOrigin, fConfig, fFSAAType, fStencilCnt,
- fIsTextureable, fIsMipMapped, fUsesGLFBO0,
- fSurfaceProps);
- }
+ SkSurfaceCharacterization createResized(int width, int height) const;
GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 1acd30c127..89e805286e 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -21,6 +21,7 @@ class GrBackendFormat;
class GrBackendSemaphore;
class GrContextPriv;
class GrContextThreadSafeProxy;
+class GrContextThreadSafeProxyPriv;
class GrDrawingManager;
struct GrDrawOpAtlasConfig;
class GrFragmentProcessor;
@@ -398,8 +399,17 @@ public:
const SkSurfaceProps& surfaceProps,
bool isMipMapped, bool willUseGLFBO0 = false);
- const GrCaps* caps() const { return fCaps.get(); }
- sk_sp<const GrCaps> refCaps() const { return fCaps; }
+ 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
@@ -419,9 +429,7 @@ private:
const GrContextOptions fOptions;
friend class GrDirectContext; // To construct this object
- friend class GrContextPriv; // for access to 'fOptions' in MakeDDL
- friend class GrDDLContext; // to implement the GrDDLContext ctor (access to all members)
- friend class SkSurfaceCharacterization; // for access to 'fContextUniqueID' for operator==
+ friend class GrContextThreadSafeProxyPriv;
typedef SkRefCnt INHERITED;
};
diff --git a/src/core/SkSurfaceCharacterization.cpp b/src/core/SkSurfaceCharacterization.cpp
index 930e96fc39..74160d2b94 100644
--- a/src/core/SkSurfaceCharacterization.cpp
+++ b/src/core/SkSurfaceCharacterization.cpp
@@ -8,12 +8,14 @@
#include "SkSurfaceCharacterization.h"
#if SK_SUPPORT_GPU
+#include "GrContextThreadSafeProxyPriv.h"
+
bool SkSurfaceCharacterization::operator==(const SkSurfaceCharacterization& other) const {
if (!this->isValid() || !other.isValid()) {
return false;
}
- if (fContextInfo->fContextUniqueID != other.fContextInfo->fContextUniqueID) {
+ if (fContextInfo != other.fContextInfo) {
return false;
}
@@ -29,4 +31,21 @@ bool SkSurfaceCharacterization::operator==(const SkSurfaceCharacterization& othe
fSurfaceProps == other.fSurfaceProps;
}
+SkSurfaceCharacterization SkSurfaceCharacterization::createResized(int width, int height) const {
+ const GrCaps* caps = fContextInfo->priv().caps();
+ if (!caps) {
+ return SkSurfaceCharacterization();
+ }
+
+ if (width <= 0 || height <= 0 || width > caps->maxRenderTargetSize() ||
+ height > caps->maxRenderTargetSize()) {
+ return SkSurfaceCharacterization();
+ }
+
+ return SkSurfaceCharacterization(fContextInfo, fCacheMaxResourceBytes,
+ fImageInfo.makeWH(width, height), fOrigin, fConfig, fFSAAType,
+ fStencilCnt, fIsTextureable, fIsMipMapped, fUsesGLFBO0,
+ fSurfaceProps);
+}
+
#endif
diff --git a/src/gpu/GrContextThreadSafeProxyPriv.h b/src/gpu/GrContextThreadSafeProxyPriv.h
new file mode 100644
index 0000000000..8e299c8180
--- /dev/null
+++ b/src/gpu/GrContextThreadSafeProxyPriv.h
@@ -0,0 +1,49 @@
+/*
+ * 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 GrContextThreadSafeProxyPriv_DEFINED
+#define GrContextThreadSafeProxyPriv_DEFINED
+
+#include "GrContext.h"
+
+/**
+ * Class that adds methods to GrContextThreadSafeProxy that are only intended for use internal to
+ * Skia. This class is purely a privileged window into GrContextThreadSafeProxy. It should never
+ * have additional data members or virtual methods.
+ */
+class GrContextThreadSafeProxyPriv {
+public:
+ const GrContextOptions& contextOptions() { return fProxy->fOptions; }
+
+ const GrCaps* caps() const { return fProxy->fCaps.get(); }
+ sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; }
+ uint32_t contextUniqueID() const { return fProxy->fContextUniqueID; }
+ GrBackend backend() const { return fProxy->fBackend; }
+
+private:
+ explicit GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy) : fProxy(proxy) {}
+ GrContextThreadSafeProxyPriv(const GrContextThreadSafeProxy&) = delete;
+ GrContextThreadSafeProxyPriv& operator=(const GrContextThreadSafeProxyPriv&) = delete;
+
+ // No taking addresses of this type.
+ const GrContextThreadSafeProxyPriv* operator&() const = delete;
+ GrContextThreadSafeProxyPriv* operator&() = delete;
+
+ GrContextThreadSafeProxy* fProxy;
+
+ friend class GrContextThreadSafeProxy; // to construct/copy this type.
+};
+
+inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() {
+ return GrContextThreadSafeProxyPriv(this);
+}
+
+inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const {
+ return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this));
+}
+
+#endif
diff --git a/src/gpu/GrDDLContext.cpp b/src/gpu/GrDDLContext.cpp
index 9a91ab8526..5ed65ea5f0 100644
--- a/src/gpu/GrDDLContext.cpp
+++ b/src/gpu/GrDDLContext.cpp
@@ -6,8 +6,8 @@
*/
#include "GrContext.h"
-
#include "GrContextPriv.h"
+#include "GrContextThreadSafeProxyPriv.h"
/**
* The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
@@ -16,8 +16,8 @@
class SK_API GrDDLContext : public GrContext {
public:
GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
- : INHERITED(proxy->fBackend, proxy->fContextUniqueID) {
- fCaps = proxy->fCaps;
+ : INHERITED(proxy->priv().backend(), proxy->priv().contextUniqueID()) {
+ fCaps = proxy->priv().refCaps();
fThreadSafeProxy = std::move(proxy);
}
@@ -66,7 +66,7 @@ sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& p
// Note: we aren't creating a Gpu here. This causes the resource provider & cache to
// also not be created
- if (!context->init(proxy->fOptions)) {
+ if (!context->init(proxy->priv().contextOptions())) {
return nullptr;
}
return context;