Make GrContextThreadSafeProxy not a GrContext_Base
Once this API is retracted, we can rename it to something more sane.
The code base has some `fContextInfo` ivars of this type, suggesting it
was previously named ContextInfo. It could be a ContextGroup or something else.
Bug: skia:10318
Change-Id: I3471e2172f46163f98a94780f0d7eb3431894cda
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293556
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
diff --git a/src/gpu/GrContext_Base.cpp b/src/gpu/GrContext_Base.cpp
index 24a7f20..3426299 100644
--- a/src/gpu/GrContext_Base.cpp
+++ b/src/gpu/GrContext_Base.cpp
@@ -13,52 +13,31 @@
#include "src/gpu/GrShaderUtils.h"
#include "src/gpu/effects/GrSkSLFP.h"
-static int32_t next_id() {
- static std::atomic<int32_t> nextID{1};
- int32_t id;
- do {
- id = nextID++;
- } while (id == SK_InvalidGenID);
- return id;
-}
-
-GrContext_Base::GrContext_Base(GrBackendApi backend,
- const GrContextOptions& options,
- uint32_t contextID)
- : fBackend(backend)
- , fOptions(options)
- , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) {
+GrContext_Base::GrContext_Base(sk_sp<GrContextThreadSafeProxy> proxy)
+ : fThreadSafeProxy(std::move(proxy)) {
}
GrContext_Base::~GrContext_Base() { }
-bool GrContext_Base::init(sk_sp<const GrCaps> caps) {
- SkASSERT(caps);
- // We either are a thread safe proxy and we don't have one, or we aren't and we do.
- SkASSERT((nullptr == this->asThreadSafeProxy()) != (nullptr == fThreadSafeProxy));
+bool GrContext_Base::init() {
+ SkASSERT(fThreadSafeProxy->isValid());
- fCaps = std::move(caps);
return true;
}
-const GrCaps* GrContext_Base::caps() const { return fCaps.get(); }
-sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; }
+uint32_t GrContext_Base::contextID() const { return fThreadSafeProxy->priv().contextID(); }
+GrBackendApi GrContext_Base::backend() const { return fThreadSafeProxy->priv().backend(); }
+
+const GrContextOptions& GrContext_Base::options() const {
+ return fThreadSafeProxy->priv().options();
+}
+
+const GrCaps* GrContext_Base::caps() const { return fThreadSafeProxy->priv().caps(); }
+sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fThreadSafeProxy->priv().refCaps(); }
GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType,
GrRenderable renderable) const {
- const GrCaps* caps = this->caps();
-
- GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
-
- GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, renderable);
- if (!format.isValid()) {
- return GrBackendFormat();
- }
-
- SkASSERT(renderable == GrRenderable::kNo ||
- caps->isFormatAsColorTypeRenderable(grColorType, format));
-
- return format;
+ return fThreadSafeProxy->defaultBackendFormat(skColorType, renderable);
}
GrBackendFormat GrContext_Base::compressedBackendFormat(SkImage::CompressionType c) const {
@@ -70,6 +49,8 @@
return format;
}
+sk_sp<GrContextThreadSafeProxy> GrContext_Base::threadSafeProxy() { return fThreadSafeProxy; }
+
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
return fContext->refCaps();