Merge GrContext::init into GrDirectContext ...
And minor cleanups associated with the initialization of these classes. Change-Id: Ida0372d0b1a0b8bf5b309814de5418e47ea34fdb Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324122 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
This commit is contained in:
parent
f9b0042423
commit
48d8724097
@ -47,10 +47,14 @@ class SkSurfaceProps;
|
|||||||
class SkTaskGroup;
|
class SkTaskGroup;
|
||||||
class SkTraceMemoryDump;
|
class SkTraceMemoryDump;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This deprecated class is being merged into GrDirectContext and removed.
|
||||||
|
* Do not add new subclasses, new API, or attempt to instantiate one.
|
||||||
|
* If new API requires direct GPU access, add it to GrDirectContext.
|
||||||
|
* Otherwise, add it to GrRecordingContext.
|
||||||
|
*/
|
||||||
class SK_API GrContext : public GrRecordingContext {
|
class SK_API GrContext : public GrRecordingContext {
|
||||||
public:
|
public:
|
||||||
~GrContext() override;
|
|
||||||
|
|
||||||
// TODO: Remove this from public after migrating Chrome.
|
// TODO: Remove this from public after migrating Chrome.
|
||||||
sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
|
sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
|
||||||
|
|
||||||
@ -680,8 +684,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
GrContext(sk_sp<GrContextThreadSafeProxy>);
|
GrContext(sk_sp<GrContextThreadSafeProxy>);
|
||||||
|
|
||||||
bool init() override;
|
|
||||||
|
|
||||||
virtual GrAtlasManager* onGetAtlasManager() = 0;
|
virtual GrAtlasManager* onGetAtlasManager() = 0;
|
||||||
virtual GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() = 0;
|
virtual GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() = 0;
|
||||||
|
|
||||||
@ -695,8 +697,8 @@ private:
|
|||||||
std::unique_ptr<SkTaskGroup> fTaskGroup;
|
std::unique_ptr<SkTaskGroup> fTaskGroup;
|
||||||
std::unique_ptr<GrStrikeCache> fStrikeCache;
|
std::unique_ptr<GrStrikeCache> fStrikeCache;
|
||||||
sk_sp<GrGpu> fGpu;
|
sk_sp<GrGpu> fGpu;
|
||||||
GrResourceCache* fResourceCache;
|
std::unique_ptr<GrResourceCache> fResourceCache;
|
||||||
GrResourceProvider* fResourceProvider;
|
std::unique_ptr<GrResourceProvider> fResourceProvider;
|
||||||
|
|
||||||
bool fDidTestPMConversions;
|
bool fDidTestPMConversions;
|
||||||
// true if the PM/UPM conversion succeeded; false otherwise
|
// true if the PM/UPM conversion succeeded; false otherwise
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include "src/gpu/GrResourceCache.h"
|
#include "src/gpu/GrResourceCache.h"
|
||||||
#include "src/gpu/GrResourceProvider.h"
|
#include "src/gpu/GrResourceProvider.h"
|
||||||
#include "src/gpu/GrSemaphore.h"
|
#include "src/gpu/GrSemaphore.h"
|
||||||
#include "src/gpu/GrShaderUtils.h"
|
|
||||||
#include "src/gpu/GrSoftwarePathRenderer.h"
|
#include "src/gpu/GrSoftwarePathRenderer.h"
|
||||||
#include "src/gpu/GrThreadSafeCache.h"
|
#include "src/gpu/GrThreadSafeCache.h"
|
||||||
#include "src/gpu/GrTracing.h"
|
#include "src/gpu/GrTracing.h"
|
||||||
@ -51,59 +50,7 @@
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
GrContext::GrContext(sk_sp<GrContextThreadSafeProxy> proxy) : INHERITED(std::move(proxy)) {
|
GrContext::GrContext(sk_sp<GrContextThreadSafeProxy> proxy) : INHERITED(std::move(proxy)) { }
|
||||||
fResourceCache = nullptr;
|
|
||||||
fResourceProvider = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
GrContext::~GrContext() {
|
|
||||||
ASSERT_SINGLE_OWNER
|
|
||||||
|
|
||||||
this->destroyDrawingManager();
|
|
||||||
fMappedBufferManager.reset();
|
|
||||||
delete fResourceProvider;
|
|
||||||
delete fResourceCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GrContext::init() {
|
|
||||||
ASSERT_SINGLE_OWNER
|
|
||||||
SkASSERT(this->proxyProvider());
|
|
||||||
|
|
||||||
if (!INHERITED::init()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkASSERT(this->getTextBlobCache());
|
|
||||||
SkASSERT(this->threadSafeCache());
|
|
||||||
|
|
||||||
if (fGpu) {
|
|
||||||
fStrikeCache = std::make_unique<GrStrikeCache>();
|
|
||||||
fResourceCache = new GrResourceCache(this->caps(), this->singleOwner(), this->contextID());
|
|
||||||
fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner());
|
|
||||||
fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fResourceCache) {
|
|
||||||
fResourceCache->setProxyProvider(this->proxyProvider());
|
|
||||||
fResourceCache->setThreadSafeCache(this->threadSafeCache());
|
|
||||||
}
|
|
||||||
|
|
||||||
fDidTestPMConversions = false;
|
|
||||||
|
|
||||||
// DDL TODO: we need to think through how the task group & persistent cache
|
|
||||||
// get passed on to/shared between all the DDLRecorders created with this context.
|
|
||||||
if (this->options().fExecutor) {
|
|
||||||
fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
|
|
||||||
}
|
|
||||||
|
|
||||||
fPersistentCache = this->options().fPersistentCache;
|
|
||||||
fShaderErrorHandler = this->options().fShaderErrorHandler;
|
|
||||||
if (!fShaderErrorHandler) {
|
|
||||||
fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
|
sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
|
||||||
return INHERITED::threadSafeProxy();
|
return INHERITED::threadSafeProxy();
|
||||||
|
@ -101,10 +101,10 @@ public:
|
|||||||
|
|
||||||
SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
|
SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
|
||||||
|
|
||||||
GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; }
|
GrResourceProvider* resourceProvider() { return fContext->fResourceProvider.get(); }
|
||||||
const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; }
|
const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider.get(); }
|
||||||
|
|
||||||
GrResourceCache* getResourceCache() { return fContext->fResourceCache; }
|
GrResourceCache* getResourceCache() { return fContext->fResourceCache.get(); }
|
||||||
|
|
||||||
GrGpu* getGpu() { return fContext->fGpu.get(); }
|
GrGpu* getGpu() { return fContext->fGpu.get(); }
|
||||||
const GrGpu* getGpu() const { return fContext->fGpu.get(); }
|
const GrGpu* getGpu() const { return fContext->fGpu.get(); }
|
||||||
|
@ -9,9 +9,13 @@
|
|||||||
#include "include/gpu/GrDirectContext.h"
|
#include "include/gpu/GrDirectContext.h"
|
||||||
|
|
||||||
#include "include/gpu/GrContextThreadSafeProxy.h"
|
#include "include/gpu/GrContextThreadSafeProxy.h"
|
||||||
|
#include "src/core/SkTaskGroup.h"
|
||||||
|
#include "src/gpu/GrClientMappedBufferManager.h"
|
||||||
#include "src/gpu/GrContextPriv.h"
|
#include "src/gpu/GrContextPriv.h"
|
||||||
#include "src/gpu/GrContextThreadSafeProxyPriv.h"
|
#include "src/gpu/GrContextThreadSafeProxyPriv.h"
|
||||||
#include "src/gpu/GrGpu.h"
|
#include "src/gpu/GrGpu.h"
|
||||||
|
#include "src/gpu/GrResourceProvider.h"
|
||||||
|
#include "src/gpu/GrShaderUtils.h"
|
||||||
|
|
||||||
#include "src/gpu/effects/GrSkSLFP.h"
|
#include "src/gpu/effects/GrSkSLFP.h"
|
||||||
#include "src/gpu/gl/GrGLGpu.h"
|
#include "src/gpu/gl/GrGLGpu.h"
|
||||||
@ -45,16 +49,27 @@ static const bool kDefaultReduceOpsTaskSplitting = false;
|
|||||||
static const bool kDefaultReduceOpsTaskSplitting = false;
|
static const bool kDefaultReduceOpsTaskSplitting = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner())
|
||||||
|
|
||||||
GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options)
|
GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options)
|
||||||
: INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) {
|
: INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GrDirectContext::~GrDirectContext() {
|
GrDirectContext::~GrDirectContext() {
|
||||||
|
ASSERT_SINGLE_OWNER
|
||||||
// this if-test protects against the case where the context is being destroyed
|
// this if-test protects against the case where the context is being destroyed
|
||||||
// before having been fully created
|
// before having been fully created
|
||||||
if (this->priv().getGpu()) {
|
if (fGpu) {
|
||||||
this->flushAndSubmit();
|
this->flushAndSubmit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->destroyDrawingManager();
|
||||||
|
fMappedBufferManager.reset();
|
||||||
|
|
||||||
|
// Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll.
|
||||||
|
if (fResourceCache) {
|
||||||
|
fResourceCache->releaseAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrDirectContext::abandonContext() {
|
void GrDirectContext::abandonContext() {
|
||||||
@ -84,16 +99,42 @@ void GrDirectContext::freeGpuResources() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GrDirectContext::init() {
|
bool GrDirectContext::init() {
|
||||||
const GrGpu* gpu = this->priv().getGpu();
|
ASSERT_SINGLE_OWNER
|
||||||
if (!gpu) {
|
if (!fGpu) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fThreadSafeProxy->priv().init(gpu->refCaps());
|
fThreadSafeProxy->priv().init(fGpu->refCaps());
|
||||||
if (!INHERITED::init()) {
|
if (!INHERITED::init()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkASSERT(this->getTextBlobCache());
|
||||||
|
SkASSERT(this->threadSafeCache());
|
||||||
|
|
||||||
|
fStrikeCache = std::make_unique<GrStrikeCache>();
|
||||||
|
fResourceCache = std::make_unique<GrResourceCache>(this->caps(), this->singleOwner(),
|
||||||
|
this->contextID());
|
||||||
|
fResourceCache->setProxyProvider(this->proxyProvider());
|
||||||
|
fResourceCache->setThreadSafeCache(this->threadSafeCache());
|
||||||
|
fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(),
|
||||||
|
this->singleOwner());
|
||||||
|
fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID());
|
||||||
|
|
||||||
|
fDidTestPMConversions = false;
|
||||||
|
|
||||||
|
// DDL TODO: we need to think through how the task group & persistent cache
|
||||||
|
// get passed on to/shared between all the DDLRecorders created with this context.
|
||||||
|
if (this->options().fExecutor) {
|
||||||
|
fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
|
||||||
|
}
|
||||||
|
|
||||||
|
fPersistentCache = this->options().fPersistentCache;
|
||||||
|
fShaderErrorHandler = this->options().fShaderErrorHandler;
|
||||||
|
if (!fShaderErrorHandler) {
|
||||||
|
fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
|
||||||
|
}
|
||||||
|
|
||||||
bool reduceOpsTaskSplitting = kDefaultReduceOpsTaskSplitting;
|
bool reduceOpsTaskSplitting = kDefaultReduceOpsTaskSplitting;
|
||||||
if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) {
|
if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) {
|
||||||
reduceOpsTaskSplitting = false;
|
reduceOpsTaskSplitting = false;
|
||||||
|
@ -685,7 +685,7 @@ void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) {
|
|||||||
|
|
||||||
void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) {
|
void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) {
|
||||||
int* index = resource->cacheAccess().accessCacheIndex();
|
int* index = resource->cacheAccess().accessCacheIndex();
|
||||||
// Fill the whole we will create in the array with the tail object, adjust its index, and
|
// Fill the hole we will create in the array with the tail object, adjust its index, and
|
||||||
// then pop the array
|
// then pop the array
|
||||||
GrGpuResource* tail = *(fNonpurgeableResources.end() - 1);
|
GrGpuResource* tail = *(fNonpurgeableResources.end() - 1);
|
||||||
SkASSERT(fNonpurgeableResources[*index] == resource);
|
SkASSERT(fNonpurgeableResources[*index] == resource);
|
||||||
|
Loading…
Reference in New Issue
Block a user