Remove SkSurface::MakeFromBackendTextureAsRenderTarget

Bug: skia:9832
Change-Id: I4cb6f8abdb58ac37e9304a4c484e6cac4a25f0d2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324890
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-10-09 17:19:25 -04:00 committed by Skia Commit-Bot
parent 61a591ca18
commit 30c9b4cfb0
24 changed files with 3 additions and 343 deletions

View File

@ -249,17 +249,6 @@ public:
RenderTargetReleaseProc releaseProc = nullptr,
ReleaseContext releaseContext = nullptr);
#if GR_TEST_UTILS
// TODO: Remove this.
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrRecordingContext* context,
const GrBackendTexture& backendTexture,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps);
#endif
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
/** Private.
Creates SkSurface from Android hardware buffer.

View File

@ -337,28 +337,6 @@ sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget
return rt;
}
sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& backendTex,
int sampleCnt) {
this->handleDirtyContext();
const GrCaps* caps = this->caps();
int maxSize = caps->maxTextureSize();
if (backendTex.width() > maxSize || backendTex.height() > maxSize) {
return nullptr;
}
if (!caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) {
return nullptr;
}
auto rt = this->onWrapBackendTextureAsRenderTarget(backendTex, sampleCnt);
if (rt && sampleCnt > 1 && !this->caps()->msaaResolvesAutomatically()) {
rt->setRequiresManualMSAAResolve();
}
return rt;
}
sk_sp<GrRenderTarget> GrGpu::wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo,
const GrVkDrawableInfo& vkInfo) {
return this->onWrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo);

View File

@ -174,11 +174,6 @@ public:
*/
sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&);
/**
* Implements GrResourceProvider::wrapBackendTextureAsRenderTarget
*/
sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, int sampleCnt);
/**
* Implements GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget
*/
@ -806,8 +801,6 @@ private:
GrWrapOwnership,
GrWrapCacheable) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) = 0;
virtual sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&);

View File

@ -630,33 +630,6 @@ sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendRenderTarget(
return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(std::move(rt), UseAllocator::kNo));
}
sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendTextureAsRenderTarget(
const GrBackendTexture& backendTex, int sampleCnt) {
if (this->isAbandoned()) {
return nullptr;
}
// This is only supported on a direct GrContext.
auto direct = fImageContext->asDirectContext();
if (!direct) {
return nullptr;
}
GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
sk_sp<GrRenderTarget> rt =
resourceProvider->wrapBackendTextureAsRenderTarget(backendTex, sampleCnt);
if (!rt) {
return nullptr;
}
SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable
SkASSERT(!rt->getUniqueKey().isValid());
// This proxy should be unbudgeted because we're just wrapping an external resource
SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
return sk_sp<GrSurfaceProxy>(new GrRenderTargetProxy(std::move(rt), UseAllocator::kNo));
}
sk_sp<GrRenderTargetProxy> GrProxyProvider::wrapVulkanSecondaryCBAsRenderTarget(
const SkImageInfo& imageInfo, const GrVkDrawableInfo& vkInfo) {
if (this->isAbandoned()) {

View File

@ -137,11 +137,6 @@ public:
sk_sp<GrSurfaceProxy> wrapBackendRenderTarget(const GrBackendRenderTarget&,
sk_sp<GrRefCntedCallback> releaseHelper);
/*
* Create a render target proxy that wraps a backend texture
*/
sk_sp<GrSurfaceProxy> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, int sampleCnt);
sk_sp<GrRenderTargetProxy> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&);

View File

@ -256,25 +256,6 @@ std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromBackendTex
origin, surfaceProps);
}
std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromBackendTextureAsRenderTarget(
GrRecordingContext* context,
GrColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const GrBackendTexture& tex,
int sampleCnt,
GrSurfaceOrigin origin,
const SkSurfaceProps* surfaceProps) {
SkASSERT(sampleCnt > 0);
sk_sp<GrSurfaceProxy> proxy(
context->priv().proxyProvider()->wrapBackendTextureAsRenderTarget(tex, sampleCnt));
if (!proxy) {
return nullptr;
}
return GrRenderTargetContext::Make(context, colorType, std::move(colorSpace), std::move(proxy),
origin, surfaceProps);
}
std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromBackendRenderTarget(
GrRecordingContext* context,
GrColorType colorType,

View File

@ -123,10 +123,6 @@ public:
int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps*,
sk_sp<GrRefCntedCallback> releaseHelper);
static std::unique_ptr<GrRenderTargetContext> MakeFromBackendTextureAsRenderTarget(
GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendTexture&,
int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps*);
static std::unique_ptr<GrRenderTargetContext> MakeFromBackendRenderTarget(
GrRecordingContext*,
GrColorType,

View File

@ -526,14 +526,6 @@ bool GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt, int numSten
return false;
}
sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget(
const GrBackendTexture& tex, int sampleCnt) {
if (this->isAbandoned()) {
return nullptr;
}
return fGpu->wrapBackendTextureAsRenderTarget(tex, sampleCnt);
}
std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore(
bool isOwned) {
return this->isAbandoned() ? nullptr : fGpu->makeSemaphore(isOwned);

View File

@ -263,17 +263,6 @@ public:
*/
bool attachStencilAttachment(GrRenderTarget* rt, int numStencilSamples);
/**
* Wraps an existing texture with a GrRenderTarget object. This is useful when the provided
* texture has a format that cannot be textured from by Skia, but we want to raster to it.
*
* The texture is wrapped as borrowed. The texture object will not be freed once the
* render target is destroyed.
*
* @return GrRenderTarget object or NULL on failure.
*/
sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, int sampleCnt);
/**
* Assigns a unique key to a resource. If the key is associated with another resource that
* association is removed and replaced by this resource.

View File

@ -95,9 +95,9 @@ void GrTextureRenderTargetProxy::initSurfaceFlags(const GrCaps& caps) {
// multisampled-render-to-texture extension.
//
// NOTE: This is the only instance where we need to set the manual resolve flag on a proxy.
// Any other proxies that require manual resolve (e.g., wrapBackendTextureAsRenderTarget())
// will be wrapped, and the wrapped version of the GrSurface constructor will automatically
// get the manual resolve flag when copying the target GrSurface's flags.
// Any other proxies that require manual resolve (e.g., wrapRenderableBackendTexture() with
// a sample count) will be wrapped, and the wrapped version of the GrSurface constructor
// will automatically get the manual resolve flag when copying the target GrSurface's flags.
fSurfaceFlags |= GrInternalSurfaceFlags::kRequiresManualMSAAResolve;
}
}

View File

@ -918,44 +918,6 @@ sk_sp<GrRenderTarget> GrD3DGpu::onWrapBackendRenderTarget(const GrBackendRenderT
return std::move(tgt);
}
sk_sp<GrRenderTarget> GrD3DGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
int sampleCnt) {
GrD3DTextureResourceInfo textureInfo;
if (!tex.getD3DTextureResourceInfo(&textureInfo)) {
return nullptr;
}
if (!check_resource_info(textureInfo)) {
return nullptr;
}
// If sampleCnt is > 1 we will create an intermediate MSAA VkImage and then resolve into
// the wrapped VkImage. We don't yet support rendering directly to client-provided MSAA texture.
if (textureInfo.fSampleCount != 1) {
return nullptr;
}
if (!check_rt_resource_info(this->d3dCaps(), textureInfo, sampleCnt)) {
return nullptr;
}
// TODO: support protected context
if (tex.isProtected()) {
return nullptr;
}
sampleCnt = this->d3dCaps().getRenderTargetSampleCount(sampleCnt, textureInfo.fFormat);
if (!sampleCnt) {
return nullptr;
}
sk_sp<GrD3DResourceState> state = tex.getGrD3DResourceState();
SkASSERT(state);
return GrD3DRenderTarget::MakeWrappedRenderTarget(this, tex.dimensions(), sampleCnt,
textureInfo, std::move(state));
}
sk_sp<GrGpuBuffer> GrD3DGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type,
GrAccessPattern accessPattern, const void* data) {
sk_sp<GrD3DBuffer> buffer = GrD3DBuffer::Make(this, sizeInBytes, type, accessPattern);

View File

@ -169,9 +169,6 @@ private:
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
const void*) override;

View File

@ -289,23 +289,6 @@ sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendRenderTarget(const GrBackendRender
return GrDawnRenderTarget::MakeWrapped(this, dimensions, sampleCnt, info);
}
sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
int sampleCnt) {
GrDawnTextureInfo textureInfo;
if (!tex.getDawnTextureInfo(&textureInfo) || !textureInfo.fTexture) {
return nullptr;
}
SkISize dimensions = { tex.width(), tex.height() };
sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, tex.getBackendFormat());
if (sampleCnt < 1) {
return nullptr;
}
GrDawnRenderTargetInfo info(textureInfo);
return GrDawnRenderTarget::MakeWrapped(this, dimensions, sampleCnt, info);
}
sk_sp<GrAttachment> GrDawnGpu::makeStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
SkISize dimensions,
int numStencilSamples) {

View File

@ -146,9 +146,6 @@ private:
GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
GrBackendTexture onCreateBackendTexture(SkISize dimensions,
const GrBackendFormat&,
GrRenderable,

View File

@ -801,27 +801,6 @@ sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTa
backendRT.stencilBits());
}
sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
int sampleCnt) {
GrGLTexture::Desc desc;
// We do not check whether texture rectangle is supported by Skia - if the caller provided us
// with a texture rectangle,we assume the necessary support exists.
if (!check_backend_texture(tex, this->glCaps(), &desc, true)) {
return nullptr;
}
if (!this->glCaps().isFormatRenderable(desc.fFormat, sampleCnt)) {
return nullptr;
}
const int sampleCount = this->glCaps().getRenderTargetSampleCount(sampleCnt, desc.fFormat);
GrGLRenderTarget::IDs rtIDs;
if (!this->createRenderTargetObjects(desc, sampleCount, &rtIDs)) {
return nullptr;
}
return GrGLRenderTarget::MakeWrapped(this, desc.fSize, desc.fFormat, sampleCount, rtIDs, 0);
}
static bool check_write_and_transfer_input(GrGLTexture* glTex) {
if (!glTex) {
return false;

View File

@ -255,8 +255,6 @@ private:
GrWrapOwnership,
GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
// Given a GL format return the index into the stencil format array on GrGLCaps to a
// compatible stencil format, or negative if there is no compatible stencil format.

View File

@ -250,20 +250,6 @@ sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRender
isProtected, info));
}
sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
int sampleCnt) {
GrMockTextureInfo texInfo;
SkAssertResult(tex.getMockTextureInfo(&texInfo));
SkASSERT(texInfo.compressionType() == SkImage::CompressionType::kNone);
// The client gave us the texture ID but we supply the render target ID.
GrMockRenderTargetInfo rtInfo(texInfo.colorType(), NextInternalRenderTargetID());
auto isProtected = GrProtected(tex.isProtected());
return sk_sp<GrRenderTarget>(new GrMockRenderTarget(
this, GrMockRenderTarget::kWrapped, tex.dimensions(), sampleCnt, isProtected, rtInfo));
}
sk_sp<GrGpuBuffer> GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type,
GrAccessPattern accessPattern, const void*) {
return sk_sp<GrGpuBuffer>(new GrMockBuffer(this, sizeInBytes, type, accessPattern));

View File

@ -96,9 +96,6 @@ private:
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
const void*) override;

View File

@ -189,9 +189,6 @@ private:
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t, GrGpuBufferType, GrAccessPattern,
const void*) override;

View File

@ -782,31 +782,6 @@ sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendRenderTarget(const GrBackendRenderT
backendRT.sampleCnt(), mtlTexture);
}
sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendTextureAsRenderTarget(
const GrBackendTexture& backendTex, int sampleCnt) {
id<MTLTexture> mtlTexture = get_texture_from_backend(backendTex);
if (!mtlTexture) {
return nullptr;
}
MTLPixelFormat format = mtlTexture.pixelFormat;
if (!this->mtlCaps().isFormatRenderable(format, sampleCnt)) {
return nullptr;
}
if (@available(macOS 10.11, iOS 9.0, *)) {
SkASSERT(MTLTextureUsageRenderTarget & mtlTexture.usage);
}
sampleCnt = this->mtlCaps().getRenderTargetSampleCount(sampleCnt, format);
if (!sampleCnt) {
return nullptr;
}
return GrMtlRenderTarget::MakeWrappedRenderTarget(this, backendTex.dimensions(), sampleCnt,
mtlTexture);
}
bool GrMtlGpu::onRegenerateMipMapLevels(GrTexture* texture) {
GrMtlTexture* grMtlTexture = static_cast<GrMtlTexture*>(texture);
id<MTLTexture> mtlTexture = grMtlTexture->mtlTexture();

View File

@ -1393,43 +1393,6 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTa
return std::move(tgt);
}
sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
int sampleCnt) {
GrVkImageInfo imageInfo;
if (!tex.getVkImageInfo(&imageInfo)) {
return nullptr;
}
if (!check_image_info(this->vkCaps(), imageInfo, false, this->queueIndex())) {
return nullptr;
}
// See comment below about intermediate MSAA buffer.
if (imageInfo.fSampleCount != 1) {
return nullptr;
}
// If sampleCnt is > 1 we will create an intermediate MSAA VkImage and then resolve into
// the wrapped VkImage.
bool resolveOnly = sampleCnt > 1;
if (!check_rt_image_info(this->vkCaps(), imageInfo, resolveOnly)) {
return nullptr;
}
if (tex.isProtected() && (fProtectedContext == GrProtected::kNo)) {
return nullptr;
}
sampleCnt = this->vkCaps().getRenderTargetSampleCount(sampleCnt, imageInfo.fFormat);
if (!sampleCnt) {
return nullptr;
}
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState = tex.getMutableState();
SkASSERT(mutableState);
return GrVkRenderTarget::MakeWrappedRenderTarget(this, tex.dimensions(), sampleCnt, imageInfo,
std::move(mutableState));
}
sk_sp<GrRenderTarget> GrVkGpu::onWrapVulkanSecondaryCBAsRenderTarget(
const SkImageInfo& imageInfo, const GrVkDrawableInfo& vkInfo) {
int maxSize = this->caps()->maxTextureSize();

View File

@ -253,9 +253,6 @@ private:
GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&) override;

View File

@ -641,42 +641,6 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrRecordingContext* cont
return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
#if GR_TEST_UTILS
sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrRecordingContext* context,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
if (!context) {
return nullptr;
}
sampleCnt = std::max(1, sampleCnt);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(), colorType,
tex.getBackendFormat());
if (grColorType == GrColorType::kUnknown) {
return nullptr;
}
if (!validate_backend_texture(context->priv().caps(), tex, sampleCnt, grColorType, false)) {
return nullptr;
}
auto rtc = GrRenderTargetContext::MakeFromBackendTextureAsRenderTarget(
context, grColorType, std::move(colorSpace), tex, sampleCnt, origin, props);
if (!rtc) {
return nullptr;
}
auto device = SkGpuDevice::Make(context, std::move(rtc), SkGpuDevice::kUninit_InitContents);
if (!device) {
return nullptr;
}
return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
#endif
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
sk_sp<SkSurface> SkSurface::MakeFromAHardwareBuffer(GrDirectContext* dContext,
AHardwareBuffer* hardwareBuffer,

View File

@ -263,27 +263,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
}
#endif
// Tests wrapBackendRenderTarget with a GrBackendTexture
{
GrBackendTexture backendTex;
CreateBackendTexture(direct, &backendTex, kWidthHeight, kWidthHeight, colorType,
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes,
GrProtected::kNo);
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTextureAsRenderTarget(
backendTex, supportedNumSamples);
if (!sProxy) {
direct->deleteBackendTexture(backendTex);
continue; // This can fail on Mesa
}
check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo);
check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
supportedNumSamples, SkBackingFit::kExact,
caps.maxWindowRectangles());
direct->deleteBackendTexture(backendTex);
}
// Tests wrapBackendTexture that is only renderable
{
GrBackendTexture backendTex;