* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/GrOnFlushResourceProvider.h"
#include "include/private/GrRecordingContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrSurfaceProxy.h"
sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
sk_sp<GrSurfaceProxy> proxy,
GrColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
if (!this->instatiateProxy(proxy.get())) {
return nullptr;
}
sk_sp<GrRenderTargetContext> renderTargetContext(fDrawingMgr->makeRenderTargetContext(
std::move(proxy), colorType, std::move(colorSpace), props, false));
if (!renderTargetContext) {
return nullptr;
}
renderTargetContext->discard();
return renderTargetContext;
}
bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key,
GrTextureProxy* proxy) {
auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
return proxyProvider->assignUniqueKeyToProxy(key, proxy);
}
void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) {
auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
proxyProvider->removeUniqueKeyFromProxy(proxy);
}
void GrOnFlushResourceProvider::processInvalidUniqueKey(const GrUniqueKey& key) {
auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
proxyProvider->processInvalidUniqueKey(key, nullptr,
GrProxyProvider::InvalidateGPUResource::kYes);
}
sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey(
const GrUniqueKey& key, GrColorType colorType, GrSurfaceOrigin origin) {
auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
return proxyProvider->findOrCreateProxyByUniqueKey(key, colorType, origin);
}
bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) {
SkASSERT(proxy->priv().ignoredByResourceAllocator());
auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
if (!direct) {
return false;
}
auto resourceProvider = direct->priv().resourceProvider();
if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) {
return proxy->priv().doLazyInstantiation(resourceProvider);
}
return proxy->instantiate(resourceProvider);
}
sk_sp<GrGpuBuffer> GrOnFlushResourceProvider::makeBuffer(GrGpuBufferType intendedType, size_t size,
const void* data) {
auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
if (!direct) {
return nullptr;
}
auto resourceProvider = direct->priv().resourceProvider();
return sk_sp<GrGpuBuffer>(
resourceProvider->createBuffer(size, intendedType, kDynamic_GrAccessPattern, data));
}
sk_sp<const GrGpuBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(
GrGpuBufferType intendedType, size_t size, const void* data, const GrUniqueKey& key) {
auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
if (!direct) {
return nullptr;
}
auto resourceProvider = direct->priv().resourceProvider();
sk_sp<const GrGpuBuffer> buffer =
resourceProvider->findOrMakeStaticBuffer(intendedType, size, data, key);
SkASSERT(!buffer || !buffer->resourcePriv().hasPendingIO_debugOnly());
return buffer;
}
uint32_t GrOnFlushResourceProvider::contextID() const {
return fDrawingMgr->getContext()->priv().contextID();
}
const GrCaps* GrOnFlushResourceProvider::caps() const {
return fDrawingMgr->getContext()->priv().caps();
}