#include "include/gpu/ganesh/GrDirectContext.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkSize.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTextureCompressionType.h"
#include "include/core/SkTraceMemoryDump.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/ganesh/GrBackendSemaphore.h"
#include "include/gpu/ganesh/GrBackendSurface.h"
#include "include/gpu/ganesh/GrContextThreadSafeProxy.h"
#include "include/private/base/SingleOwner.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/base/SkAutoMalloc.h"
#include "src/core/SkCompressedDataUtils.h"
#include "src/core/SkMipmap.h"
#include "src/core/SkTaskGroup.h"
#include "src/core/SkTraceEvent.h"
#include "src/gpu/DataUtils.h"
#include "src/gpu/GpuTypesPriv.h"
#include "src/gpu/RefCntedCallback.h"
#include "src/gpu/Swizzle.h"
#include "src/gpu/ganesh/Device.h"
#include "src/gpu/ganesh/GrBackendUtils.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrClientMappedBufferManager.h"
#include "src/gpu/ganesh/GrColorInfo.h"
#include "src/gpu/ganesh/GrContextThreadSafeProxyPriv.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrDrawOpAtlas.h"
#include "src/gpu/ganesh/GrDrawingManager.h"
#include "src/gpu/ganesh/GrGpu.h"
#include "src/gpu/ganesh/GrPixmap.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrRenderTargetProxy.h"
#include "src/gpu/ganesh/GrResourceCache.h"
#include "src/gpu/ganesh/GrResourceProvider.h"
#include "src/gpu/ganesh/GrSemaphore.h"
#include "src/gpu/ganesh/GrShaderCaps.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/GrThreadSafePipelineBuilder.h"
#include "src/gpu/ganesh/SurfaceContext.h"
#include "src/gpu/ganesh/image/SkImage_GaneshBase.h"
#include "src/gpu/ganesh/mock/GrMockGpu.h"
#include "src/gpu/ganesh/ops/SmallPathAtlasMgr.h"
#include "src/gpu/ganesh/surface/SkSurface_Ganesh.h"
#include "src/gpu/ganesh/text/GrAtlasManager.h"
#include "src/image/SkImage_Base.h"
#include "src/image/SkSurface_Base.h"
#include "src/text/gpu/StrikeCache.h"
#include "src/text/gpu/TextBlobRedrawCoordinator.h"
#include <array>
#include <atomic>
#include <forward_list>
#include <memory>
#include <utility>
#ifdef SK_DIRECT3D
#include "src/gpu/ganesh/d3d/GrD3DGpu.h"
#endif
usingnamespaceskia_private;
#define ASSERT_SINGLE_OWNER …
StrikeCache;
GrDirectContext::DirectContextID GrDirectContext::DirectContextID::Next() { … }
GrDirectContext::GrDirectContext(GrBackendApi backend,
const GrContextOptions& options,
sk_sp<GrContextThreadSafeProxy> proxy)
: … { … }
GrDirectContext::~GrDirectContext() { … }
sk_sp<GrContextThreadSafeProxy> GrDirectContext::threadSafeProxy() { … }
void GrDirectContext::resetGLTextureBindings() { … }
void GrDirectContext::resetContext(uint32_t state) { … }
void GrDirectContext::abandonContext() { … }
bool GrDirectContext::abandoned() { … }
bool GrDirectContext::isDeviceLost() { … }
bool GrDirectContext::oomed() { … }
void GrDirectContext::releaseResourcesAndAbandonContext() { … }
void GrDirectContext::freeGpuResources() { … }
bool GrDirectContext::init() { … }
void GrDirectContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { … }
size_t GrDirectContext::getResourceCachePurgeableBytes() const { … }
void GrDirectContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const { … }
size_t GrDirectContext::getResourceCacheLimit() const { … }
void GrDirectContext::setResourceCacheLimits(int unused, size_t maxResourceBytes) { … }
void GrDirectContext::setResourceCacheLimit(size_t maxResourceBytes) { … }
void GrDirectContext::purgeUnlockedResources(GrPurgeResourceOptions opts) { … }
void GrDirectContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed,
GrPurgeResourceOptions opts) { … }
void GrDirectContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) { … }
bool GrDirectContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[],
bool deleteSemaphoresAfterWait) { … }
#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
skgpu::ganesh::SmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() { … }
#endif
GrSemaphoresSubmitted GrDirectContext::flush(const GrFlushInfo& info) { … }
bool GrDirectContext::submit(GrSyncCpu sync) { … }
GrSemaphoresSubmitted GrDirectContext::flush(const sk_sp<const SkImage>& image,
const GrFlushInfo& flushInfo) { … }
void GrDirectContext::flush(const sk_sp<const SkImage>& image) { … }
void GrDirectContext::flushAndSubmit(const sk_sp<const SkImage>& image) { … }
GrSemaphoresSubmitted GrDirectContext::flush(SkSurface* surface,
SkSurfaces::BackendSurfaceAccess access,
const GrFlushInfo& info) { … }
GrSemaphoresSubmitted GrDirectContext::flush(SkSurface* surface,
const GrFlushInfo& info,
const skgpu::MutableTextureState* newState) { … }
void GrDirectContext::flushAndSubmit(SkSurface* surface, GrSyncCpu sync) { … }
void GrDirectContext::flush(SkSurface* surface) { … }
void GrDirectContext::checkAsyncWorkCompletion() { … }
void GrDirectContext::syncAllOutstandingGpuWork(bool shouldExecuteWhileAbandoned) { … }
void GrDirectContext::storeVkPipelineCacheData() { … }
bool GrDirectContext::supportsDistanceFieldText() const { … }
void GrDirectContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { … }
GrBackendTexture GrDirectContext::createBackendTexture(int width,
int height,
const GrBackendFormat& backendFormat,
skgpu::Mipmapped mipmapped,
GrRenderable renderable,
GrProtected isProtected,
std::string_view label) { … }
GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap& srcData,
GrSurfaceOrigin textureOrigin,
GrRenderable renderable,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext,
std::string_view label) { … }
GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap& srcData,
GrRenderable renderable,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext,
std::string_view label) { … }
GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap srcData[],
int numLevels,
GrRenderable renderable,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext,
std::string_view label) { … }
GrBackendTexture GrDirectContext::createBackendTexture(int width,
int height,
SkColorType skColorType,
skgpu::Mipmapped mipmapped,
GrRenderable renderable,
GrProtected isProtected,
std::string_view label) { … }
static GrBackendTexture create_and_clear_backend_texture(
GrDirectContext* dContext,
SkISize dimensions,
const GrBackendFormat& backendFormat,
skgpu::Mipmapped mipmapped,
GrRenderable renderable,
GrProtected isProtected,
sk_sp<skgpu::RefCntedCallback> finishedCallback,
std::array<float, 4> color,
std::string_view label) { … }
static bool update_texture_with_pixmaps(GrDirectContext* context,
const SkPixmap src[],
int numLevels,
const GrBackendTexture& backendTexture,
GrSurfaceOrigin textureOrigin,
sk_sp<skgpu::RefCntedCallback> finishedCallback) { … }
GrBackendTexture GrDirectContext::createBackendTexture(int width,
int height,
const GrBackendFormat& backendFormat,
const SkColor4f& color,
skgpu::Mipmapped mipmapped,
GrRenderable renderable,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext,
std::string_view label) { … }
GrBackendTexture GrDirectContext::createBackendTexture(int width,
int height,
SkColorType skColorType,
const SkColor4f& color,
skgpu::Mipmapped mipmapped,
GrRenderable renderable,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext,
std::string_view label) { … }
GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap srcData[],
int numProvidedLevels,
GrSurfaceOrigin textureOrigin,
GrRenderable renderable,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext,
std::string_view label) { … }
bool GrDirectContext::updateBackendTexture(const GrBackendTexture& texture,
const SkPixmap srcData[],
int numLevels,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
const SkColor4f& color,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
SkColorType skColorType,
const SkColor4f& color,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
const SkPixmap srcData[],
int numLevels,
GrSurfaceOrigin textureOrigin,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
static GrBackendTexture create_and_update_compressed_backend_texture(
GrDirectContext* dContext,
SkISize dimensions,
const GrBackendFormat& backendFormat,
skgpu::Mipmapped mipmapped,
GrProtected isProtected,
sk_sp<skgpu::RefCntedCallback> finishedCallback,
const void* data,
size_t size) { … }
GrBackendTexture GrDirectContext::createCompressedBackendTexture(
int width,
int height,
const GrBackendFormat& backendFormat,
const SkColor4f& color,
skgpu::Mipmapped mipmapped,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
GrBackendTexture GrDirectContext::createCompressedBackendTexture(
int width,
int height,
SkTextureCompressionType compression,
const SkColor4f& color,
skgpu::Mipmapped mipmapped,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
GrBackendTexture GrDirectContext::createCompressedBackendTexture(
int width,
int height,
const GrBackendFormat& backendFormat,
const void* compressedData,
size_t dataSize,
skgpu::Mipmapped mipmapped,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
GrBackendTexture GrDirectContext::createCompressedBackendTexture(
int width,
int height,
SkTextureCompressionType compression,
const void* data,
size_t dataSize,
skgpu::Mipmapped mipmapped,
GrProtected isProtected,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& backendTexture,
const SkColor4f& color,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& backendTexture,
const void* compressedData,
size_t dataSize,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
bool GrDirectContext::setBackendTextureState(const GrBackendTexture& backendTexture,
const skgpu::MutableTextureState& state,
skgpu::MutableTextureState* previousState,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
bool GrDirectContext::setBackendRenderTargetState(const GrBackendRenderTarget& backendRenderTarget,
const skgpu::MutableTextureState& state,
skgpu::MutableTextureState* previousState,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
void GrDirectContext::deleteBackendTexture(const GrBackendTexture& backendTex) { … }
bool GrDirectContext::precompileShader(const SkData& key, const SkData& data) { … }
#if defined(SK_ENABLE_DUMP_GPU)
#include "include/core/SkString.h"
#include "src/gpu/ganesh/GrUtil.h"
#include "src/utils/SkJSONWriter.h"
SkString GrDirectContext::dump() const {
SkDynamicMemoryWStream stream;
SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
writer.beginObject();
writer.appendCString("backend", GrBackendApiToStr(this->backend()));
writer.appendName("caps");
this->caps()->dumpJSON(&writer);
writer.appendName("gpu");
this->fGpu->dumpJSON(&writer);
writer.appendName("context");
this->dumpJSON(&writer);
writer.endObject();
writer.flush();
stream.write8(0);
SkString result(stream.bytesWritten());
stream.copyToAndReset(result.data());
return result;
}
#endif
sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) { … }
sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions,
const GrContextOptions& options) { … }
#ifdef SK_DIRECT3D
sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) {
GrContextOptions defaultOptions;
return MakeDirect3D(backendContext, defaultOptions);
}
sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext,
const GrContextOptions& options) {
sk_sp<GrDirectContext> direct(new GrDirectContext(
GrBackendApi::kDirect3D,
options,
GrContextThreadSafeProxyPriv::Make(GrBackendApi::kDirect3D, options)));
direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get());
if (!direct->init()) {
return nullptr;
}
return direct;
}
#endif