Move "matches" from GrContextThreadSafeProxy to GrContext_Base

This makes the "matches" functionality available to all the context flavors and uses it for SkImages

Change-Id: I1e3d55f19a7752a9da8789e93a848b7a7a64d180
Reviewed-on: https://skia-review.googlesource.com/c/190227
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2019-02-07 13:25:07 -05:00 committed by Skia Commit-Bot
parent e8345793c6
commit fe0963c350
15 changed files with 25 additions and 24 deletions

View File

@ -8,14 +8,10 @@
#ifndef GrContextThreadSafeProxy_DEFINED
#define GrContextThreadSafeProxy_DEFINED
#include "GrContextOptions.h"
#include "SkRefCnt.h"
#include "../private/GrContext_Base.h"
class GrBackendFormat;
class GrCaps;
class GrContextThreadSafeProxyPriv;
class GrSkSLFPFactoryCache;
struct SkImageInfo;
class SkSurfaceCharacterization;
@ -27,8 +23,6 @@ class SK_API GrContextThreadSafeProxy : public GrContext_Base {
public:
~GrContextThreadSafeProxy() override;
bool matches(GrContext_Base* 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.,

View File

@ -46,6 +46,10 @@ protected:
*/
uint32_t contextID() const { return fContextID; }
bool matches(GrContext_Base* candidate) const {
return candidate->contextID() == this->contextID();
}
/*
* The options in effect for this context
*/

View File

@ -192,7 +192,7 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(GrContext* context,
#if SK_SUPPORT_GPU
if (sk_sp<GrTextureProxy> proxy = as_IB(image)->asTextureProxyRef()) {
if (as_IB(image)->contextID() != context->priv().contextID()) {
if (!as_IB(image)->context()->priv().matches(context)) {
return nullptr;
}

View File

@ -18,6 +18,8 @@ public:
// from GrContext_Base
uint32_t contextID() const { return fContext->contextID(); }
bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
const GrContextOptions& options() const { return fContext->options(); }
const GrCaps* caps() const { return fContext->caps(); }

View File

@ -32,6 +32,8 @@ public:
// from GrContext_Base
uint32_t contextID() const { return fContext->contextID(); }
bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
const GrContextOptions& options() const { return fContext->options(); }
const GrCaps* caps() const { return fContext->caps(); }

View File

@ -28,10 +28,6 @@ bool GrContextThreadSafeProxy::init(sk_sp<const GrCaps> caps,
return INHERITED::init(std::move(caps), std::move(FPFactoryCache));
}
bool GrContextThreadSafeProxy::matches(GrContext_Base* context) const {
return context->priv().contextID() == this->contextID();
}
SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
size_t cacheMaxResourceBytes,
const SkImageInfo& ii, const GrBackendFormat& backendFormat,

View File

@ -20,6 +20,8 @@ public:
// from GrContext_Base
uint32_t contextID() const { return fProxy->contextID(); }
bool matches(GrContext_Base* candidate) const { return fProxy->matches(candidate); }
const GrContextOptions& options() const { return fProxy->options(); }
const GrCaps* caps() const { return fProxy->caps(); }

View File

@ -18,6 +18,8 @@ public:
// from GrContext_Base
uint32_t contextID() const { return fContext->contextID(); }
bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
const GrContextOptions& options() const { return fContext->options(); }
const GrCaps* caps() const { return fContext->caps(); }

View File

@ -18,6 +18,8 @@ public:
// from GrContext_Base
uint32_t contextID() const { return fContext->contextID(); }
bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
const GrContextOptions& options() const { return fContext->options(); }
const GrCaps* caps() const { return fContext->caps(); }

View File

@ -50,8 +50,7 @@ public:
int srcX, int srcY, CachingHint) const = 0;
virtual GrContext* context() const { return nullptr; }
// TODO: remove this contextID and use GrContext_Base::matches
virtual uint32_t contextID() const { return 0; }
#if SK_SUPPORT_GPU
virtual GrTextureProxy* peekProxy() const { return nullptr; }
virtual sk_sp<GrTextureProxy> asTextureProxyRef() const { return nullptr; }

View File

@ -350,10 +350,12 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, SkColorSpace* dstCo
if (!context) {
return nullptr;
}
if (uint32_t incumbentID = as_IB(this)->contextID()) {
if (incumbentID != context->priv().contextID()) {
if (this->isTextureBacked()) {
if (!as_IB(this)->context()->priv().matches(context)) {
return nullptr;
}
sk_sp<GrTextureProxy> proxy = as_IB(this)->asTextureProxyRef();
SkASSERT(proxy);
if (GrMipMapped::kNo == mipMapped || proxy->mipMapped() == mipMapped) {

View File

@ -35,7 +35,7 @@ public:
return fProxy;
}
virtual bool onIsTextureBacked() const override { return SkToBool(fProxy.get()); }
bool onIsTextureBacked() const override { return SkToBool(fProxy.get()); }
sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>) const final;

View File

@ -33,7 +33,7 @@ SkImage_GpuBase::~SkImage_GpuBase() {}
#if GR_TEST_UTILS
void SkImage_GpuBase::resetContext(sk_sp<GrContext> newContext) {
SkASSERT(fContext->priv().contextID() == newContext->priv().contextID());
SkASSERT(fContext->priv().matches(newContext.get()));
fContext = newContext;
}
#endif
@ -60,10 +60,6 @@ bool SkImage_GpuBase::ValidateBackendTexture(GrContext* ctx, const GrBackendText
//////////////////////////////////////////////////////////////////////////////////////////////////
uint32_t SkImage_GpuBase::contextID() const {
return fContext->priv().contextID();
}
bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
if (!fContext->priv().resourceProvider()) {
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
@ -211,7 +207,7 @@ bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels,
sk_sp<GrTextureProxy> SkImage_GpuBase::asTextureProxyRef(GrContext* context,
const GrSamplerState& params,
SkScalar scaleAdjust[2]) const {
if (context->priv().contextID() != fContext->priv().contextID()) {
if (!fContext->priv().matches(context)) {
SkASSERT(0);
return nullptr;
}

View File

@ -25,7 +25,6 @@ public:
~SkImage_GpuBase() override;
GrContext* context() const final { return fContext.get(); }
uint32_t contextID() const final;
bool getROPixels(SkBitmap*, CachingHint) const final;
sk_sp<SkImage> onMakeSubset(const SkIRect& subset) const final;

View File

@ -10,6 +10,7 @@
#include "GrBackendSurface.h"
#include "GrCaps.h"
#include "GrContextPriv.h"
#include "GrContextThreadSafeProxyPriv.h"
#include "GrRenderTarget.h"
#include "GrRenderTargetContextPriv.h"
#include "GrRenderTargetProxyPriv.h"
@ -240,7 +241,7 @@ bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& characterizati
return false;
}
return characterization.contextInfo() && characterization.contextInfo()->matches(ctx) &&
return characterization.contextInfo() && characterization.contextInfo()->priv().matches(ctx) &&
characterization.cacheMaxResourceBytes() <= maxResourceBytes &&
characterization.origin() == rtc->origin() &&
characterization.config() == rtc->colorSpaceInfo().config() &&