Migrate flush & misc methods to GrDirectContext
More cut and paste work.
Change-Id: I0dfc822ae168e15c6734a6c079bb930fc0fa9e60
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325618
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 183cd59..575adf9 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -48,114 +48,10 @@
#define RETURN_FALSE_IF_ABANDONED if (this->abandoned()) { return false; }
#define RETURN_NULL_IF_ABANDONED if (this->abandoned()) { return nullptr; }
-////////////////////////////////////////////////////////////////////////////////
-
GrContext::GrContext(sk_sp<GrContextThreadSafeProxy> proxy) : INHERITED(std::move(proxy)) { }
GrContext::~GrContext() = default;
-size_t GrContext::ComputeImageSize(sk_sp<SkImage> image, GrMipmapped mipMapped, bool useNextPow2) {
- if (!image->isTextureBacked()) {
- return 0;
- }
- SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image.get()));
- GrTextureProxy* proxy = gpuImage->peekProxy();
- if (!proxy) {
- return 0;
- }
-
- int colorSamplesPerPixel = 1;
- return GrSurface::ComputeSize(proxy->backendFormat(), image->dimensions(),
- colorSamplesPerPixel, mipMapped, useNextPow2);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool GrContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[],
- bool deleteSemaphoresAfterWait) {
- if (!fGpu || fGpu->caps()->semaphoreSupport()) {
- return false;
- }
- GrWrapOwnership ownership =
- deleteSemaphoresAfterWait ? kAdopt_GrWrapOwnership : kBorrow_GrWrapOwnership;
- for (int i = 0; i < numSemaphores; ++i) {
- std::unique_ptr<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore(
- waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, ownership);
- // If we failed to wrap the semaphore it means the client didn't give us a valid semaphore
- // to begin with. Therefore, it is fine to not wait on it.
- if (sema) {
- fGpu->waitSemaphore(sema.get());
- }
- }
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-GrSemaphoresSubmitted GrContext::flush(const GrFlushInfo& info) {
- ASSERT_SINGLE_OWNER
- if (this->abandoned()) {
- if (info.fFinishedProc) {
- info.fFinishedProc(info.fFinishedContext);
- }
- if (info.fSubmittedProc) {
- info.fSubmittedProc(info.fSubmittedContext, false);
- }
- return GrSemaphoresSubmitted::kNo;
- }
-
- bool flushed = this->drawingManager()->flush(
- nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr);
-
- if (!flushed || (!this->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
- return GrSemaphoresSubmitted::kNo;
- }
- return GrSemaphoresSubmitted::kYes;
-}
-
-bool GrContext::submit(bool syncCpu) {
- ASSERT_SINGLE_OWNER
- if (this->abandoned()) {
- return false;
- }
-
- if (!fGpu) {
- return false;
- }
-
- return fGpu->submitToGpu(syncCpu);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-void GrContext::checkAsyncWorkCompletion() {
- if (fGpu) {
- fGpu->checkFinishProcs();
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-void GrContext::storeVkPipelineCacheData() {
- if (fGpu) {
- fGpu->storeVkPipelineCacheData();
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-bool GrContext::supportsDistanceFieldText() const {
- return this->caps()->shaderCaps()->supportsDistanceFieldText();
-}
-
-//////////////////////////////////////////////////////////////////////////////
-void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
- ASSERT_SINGLE_OWNER
- fResourceCache->dumpMemoryStatistics(traceMemoryDump);
- traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes",
- this->getTextBlobCache()->usedBytes());
-}
-
-//////////////////////////////////////////////////////////////////////////////
GrBackendTexture GrContext::createBackendTexture(int width, int height,
const GrBackendFormat& backendFormat,
GrMipmapped mipMapped,
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index 5967304..476da52 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -173,7 +173,7 @@
}
void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
- fContext->flushAndSubmit();
+ fContext->asDirectContext()->flushAndSubmit();
fContext->drawingManager()->testingOnly_removeOnFlushCallbackObject(cb);
}
#endif
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index f2e8f3f..78fa9ab 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -8,6 +8,7 @@
#include "include/gpu/GrDirectContext.h"
+#include "include/core/SkTraceMemoryDump.h"
#include "include/gpu/GrContextThreadSafeProxy.h"
#include "src/core/SkTaskGroup.h"
#include "src/gpu/GrClientMappedBufferManager.h"
@@ -17,6 +18,7 @@
#include "src/gpu/GrGpu.h"
#include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrShaderUtils.h"
+#include "src/image/SkImage_GpuBase.h"
#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
#include "src/gpu/effects/GrSkSLFP.h"
@@ -330,6 +332,25 @@
fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
}
+////////////////////////////////////////////////////////////////////////////////
+bool GrDirectContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[],
+ bool deleteSemaphoresAfterWait) {
+ if (!fGpu || fGpu->caps()->semaphoreSupport()) {
+ return false;
+ }
+ GrWrapOwnership ownership =
+ deleteSemaphoresAfterWait ? kAdopt_GrWrapOwnership : kBorrow_GrWrapOwnership;
+ for (int i = 0; i < numSemaphores; ++i) {
+ std::unique_ptr<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore(
+ waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, ownership);
+ // If we failed to wrap the semaphore it means the client didn't give us a valid semaphore
+ // to begin with. Therefore, it is fine to not wait on it.
+ if (sema) {
+ fGpu->waitSemaphore(sema.get());
+ }
+ }
+ return true;
+}
GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() {
if (!fSmallPathAtlasMgr) {
@@ -345,6 +366,89 @@
return fSmallPathAtlasMgr.get();
}
+////////////////////////////////////////////////////////////////////////////////
+
+GrSemaphoresSubmitted GrDirectContext::flush(const GrFlushInfo& info) {
+ ASSERT_SINGLE_OWNER
+ if (this->abandoned()) {
+ if (info.fFinishedProc) {
+ info.fFinishedProc(info.fFinishedContext);
+ }
+ if (info.fSubmittedProc) {
+ info.fSubmittedProc(info.fSubmittedContext, false);
+ }
+ return GrSemaphoresSubmitted::kNo;
+ }
+
+ bool flushed = this->drawingManager()->flush(
+ nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr);
+
+ if (!flushed || (!this->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
+ return GrSemaphoresSubmitted::kNo;
+ }
+ return GrSemaphoresSubmitted::kYes;
+}
+
+bool GrDirectContext::submit(bool syncCpu) {
+ ASSERT_SINGLE_OWNER
+ if (this->abandoned()) {
+ return false;
+ }
+
+ if (!fGpu) {
+ return false;
+ }
+
+ return fGpu->submitToGpu(syncCpu);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+void GrDirectContext::checkAsyncWorkCompletion() {
+ if (fGpu) {
+ fGpu->checkFinishProcs();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+void GrDirectContext::storeVkPipelineCacheData() {
+ if (fGpu) {
+ fGpu->storeVkPipelineCacheData();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+bool GrDirectContext::supportsDistanceFieldText() const {
+ return this->caps()->shaderCaps()->supportsDistanceFieldText();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+void GrDirectContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
+ ASSERT_SINGLE_OWNER
+ fResourceCache->dumpMemoryStatistics(traceMemoryDump);
+ traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes",
+ this->getTextBlobCache()->usedBytes());
+}
+
+size_t GrDirectContext::ComputeImageSize(sk_sp<SkImage> image, GrMipmapped mipMapped,
+ bool useNextPow2) {
+ if (!image->isTextureBacked()) {
+ return 0;
+ }
+ SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image.get()));
+ GrTextureProxy* proxy = gpuImage->peekProxy();
+ if (!proxy) {
+ return 0;
+ }
+
+ int colorSamplesPerPixel = 1;
+ return GrSurface::ComputeSize(proxy->backendFormat(), image->dimensions(),
+ colorSamplesPerPixel, mipMapped, useNextPow2);
+}
+
#ifdef SK_GL
/*************************************************************************************************/
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index d41c61d..d3ac74b 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -203,6 +203,7 @@
SkDEBUGCODE(void validate() const);
friend class GrContext; // access to: flush & cleanup
+ friend class GrDirectContext; // access to: flush & cleanup
friend class GrContextPriv; // access to: flush
friend class GrOnFlushResourceProvider; // this is just a shallow wrapper around this class
friend class GrRecordingContext; // access to: ctor