Add GrContextThreadSafeProxy and remove most friends of GrContextThreadSafeProxy
A step towards removing GrCaps from GrContext.h Also adds operator== to GrContextThreadSafeProxy. Change-Id: Ic0bae12299dfb0ac8817d9f1c56a1219d6df97d9 Reviewed-on: https://skia-review.googlesource.com/127329 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
ce4cf72e34
commit
52aacd602f
@ -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",
|
||||
|
@ -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; }
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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
|
||||
|
49
src/gpu/GrContextThreadSafeProxyPriv.h
Normal file
49
src/gpu/GrContextThreadSafeProxyPriv.h
Normal file
@ -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
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user