Label external texture.

Pass an optional label parameter to GrBackendTexture and pass
it to MakeWrapped of GrGLTexture because almost all textures
that are coming clients are things where the client owns the
gl texture and passes it into Skia as a wrapped texture via a
GrBackendTexture.

Bug: chromium:1164111
Change-Id: I4bfddda956c72b53d0070595ef3268ee1a2b747f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/555597
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Aditya Kushwah 2022-07-07 11:34:16 -07:00 committed by SkCQ
parent bde135f0bc
commit cb44bf6246
6 changed files with 82 additions and 36 deletions

View File

@ -25,6 +25,8 @@
#include "include/gpu/dawn/GrDawnTypes.h"
#endif
#include <string>
class GrBackendSurfaceMutableStateImpl;
class GrVkImageLayout;
class GrGLTextureParameters;
@ -267,38 +269,44 @@ public:
GrBackendTexture(int width,
int height,
GrMipmapped,
const GrGLTextureInfo& glInfo);
const GrGLTextureInfo& glInfo,
std::string_view label = {});
#endif
#ifdef SK_VULKAN
GrBackendTexture(int width,
int height,
const GrVkImageInfo& vkInfo);
const GrVkImageInfo& vkInfo,
std::string_view label = {});
#endif
#ifdef SK_METAL
GrBackendTexture(int width,
int height,
GrMipmapped,
const GrMtlTextureInfo& mtlInfo);
const GrMtlTextureInfo& mtlInfo,
std::string_view label = {});
#endif
#ifdef SK_DIRECT3D
GrBackendTexture(int width,
int height,
const GrD3DTextureResourceInfo& d3dInfo);
const GrD3DTextureResourceInfo& d3dInfo,
std::string_view label = {});
#endif
#ifdef SK_DAWN
GrBackendTexture(int width,
int height,
const GrDawnTextureInfo& dawnInfo);
const GrDawnTextureInfo& dawnInfo,
std::string_view label = {});
#endif
GrBackendTexture(int width,
int height,
GrMipmapped,
const GrMockTextureInfo& mockInfo);
const GrMockTextureInfo& mockInfo,
std::string_view label = {});
GrBackendTexture(const GrBackendTexture& that);
@ -309,6 +317,7 @@ public:
SkISize dimensions() const { return {fWidth, fHeight}; }
int width() const { return fWidth; }
int height() const { return fHeight; }
std::string_view getLabel() const { return fLabel; }
GrMipmapped mipmapped() const { return fMipmapped; }
bool hasMipmaps() const { return fMipmapped == GrMipmapped::kYes; }
/** deprecated alias of hasMipmaps(). */
@ -398,7 +407,8 @@ private:
int height,
GrMipmapped,
const GrGLTextureInfo,
sk_sp<GrGLTextureParameters>);
sk_sp<GrGLTextureParameters>,
std::string_view label = {});
sk_sp<GrGLTextureParameters> getGLTextureParams() const;
#endif
@ -407,7 +417,8 @@ private:
GrBackendTexture(int width,
int height,
const GrVkImageInfo& vkInfo,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState);
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
std::string_view label = {});
#endif
#ifdef SK_DIRECT3D
@ -416,7 +427,8 @@ private:
GrBackendTexture(int width,
int height,
const GrD3DTextureResourceInfo& vkInfo,
sk_sp<GrD3DResourceState> state);
sk_sp<GrD3DResourceState> state,
std::string_view label = {});
sk_sp<GrD3DResourceState> getGrD3DResourceState() const;
#endif
@ -426,6 +438,7 @@ private:
bool fIsValid;
int fWidth; //<! width in pixels
int fHeight; //<! height in pixels
const std::string fLabel;
GrMipmapped fMipmapped;
GrBackendApi fBackend;
GrTextureType fTextureType;

View File

@ -462,10 +462,12 @@ GrBackendTexture::GrBackendTexture() : fIsValid(false) {}
#ifdef SK_DAWN
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrDawnTextureInfo& dawnInfo)
const GrDawnTextureInfo& dawnInfo,
std::string_view label)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fLabel(label)
, fMipmapped(GrMipmapped(dawnInfo.fLevelCount > 1))
, fBackend(GrBackendApi::kDawn)
, fTextureType(GrTextureType::k2D)
@ -473,11 +475,17 @@ GrBackendTexture::GrBackendTexture(int width,
#endif
#ifdef SK_VULKAN
GrBackendTexture::GrBackendTexture(int width, int height, const GrVkImageInfo& vkInfo)
: GrBackendTexture(width, height, vkInfo,
sk_sp<GrBackendSurfaceMutableStateImpl>(
new GrBackendSurfaceMutableStateImpl(
vkInfo.fImageLayout, vkInfo.fCurrentQueueFamily))) {}
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrVkImageInfo& vkInfo,
std::string_view label)
: GrBackendTexture(
width,
height,
vkInfo,
sk_sp<GrBackendSurfaceMutableStateImpl>(new GrBackendSurfaceMutableStateImpl(
vkInfo.fImageLayout, vkInfo.fCurrentQueueFamily)),
label) {}
static const VkImageUsageFlags kDefaultUsageFlags =
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
@ -508,10 +516,12 @@ static GrTextureType vk_image_info_to_texture_type(const GrVkImageInfo& info) {
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrVkImageInfo& vkInfo,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState)
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
std::string_view label)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fLabel(label)
, fMipmapped(GrMipmapped(vkInfo.fLevelCount > 1))
, fBackend(GrBackendApi::kVulkan)
, fTextureType(vk_image_info_to_texture_type(vkInfo))
@ -524,10 +534,12 @@ GrBackendTexture::GrBackendTexture(int width,
int height,
GrMipmapped mipmapped,
const GrGLTextureInfo glInfo,
sk_sp<GrGLTextureParameters> params)
sk_sp<GrGLTextureParameters> params,
std::string_view label)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fLabel(label)
, fMipmapped(mipmapped)
, fBackend(GrBackendApi::kOpenGL)
, fTextureType(gl_target_to_gr_target(glInfo.fTarget))
@ -545,10 +557,12 @@ sk_sp<GrGLTextureParameters> GrBackendTexture::getGLTextureParams() const {
GrBackendTexture::GrBackendTexture(int width,
int height,
GrMipmapped mipmapped,
const GrMtlTextureInfo& mtlInfo)
const GrMtlTextureInfo& mtlInfo,
std::string_view label)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fLabel(label)
, fMipmapped(mipmapped)
, fBackend(GrBackendApi::kMetal)
, fTextureType(GrTextureType::k2D)
@ -556,19 +570,26 @@ GrBackendTexture::GrBackendTexture(int width,
#endif
#ifdef SK_DIRECT3D
GrBackendTexture::GrBackendTexture(int width, int height, const GrD3DTextureResourceInfo& d3dInfo)
: GrBackendTexture(
width, height, d3dInfo,
sk_sp<GrD3DResourceState>(new GrD3DResourceState(
static_cast<D3D12_RESOURCE_STATES>(d3dInfo.fResourceState)))) {}
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrD3DTextureResourceInfo& d3dInfo,
std::string_view label)
: GrBackendTexture(width,
height,
d3dInfo,
sk_sp<GrD3DResourceState>(new GrD3DResourceState(
static_cast<D3D12_RESOURCE_STATES>(d3dInfo.fResourceState))),
label) {}
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrD3DTextureResourceInfo& d3dInfo,
sk_sp<GrD3DResourceState> state)
sk_sp<GrD3DResourceState> state,
std::string_view label)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fLabel(label)
, fMipmapped(GrMipmapped(d3dInfo.fLevelCount > 1))
, fBackend(GrBackendApi::kDirect3D)
, fTextureType(GrTextureType::k2D)
@ -579,8 +600,10 @@ GrBackendTexture::GrBackendTexture(int width,
GrBackendTexture::GrBackendTexture(int width,
int height,
GrMipmapped mipmapped,
const GrGLTextureInfo& glInfo)
: GrBackendTexture(width, height, mipmapped, glInfo, sk_make_sp<GrGLTextureParameters>()) {
const GrGLTextureInfo& glInfo,
std::string_view label)
: GrBackendTexture(
width, height, mipmapped, glInfo, sk_make_sp<GrGLTextureParameters>(), label) {
// Make no assumptions about client's texture's parameters.
this->glTextureParametersModified();
}
@ -589,10 +612,12 @@ GrBackendTexture::GrBackendTexture(int width,
GrBackendTexture::GrBackendTexture(int width,
int height,
GrMipmapped mipmapped,
const GrMockTextureInfo& mockInfo)
const GrMockTextureInfo& mockInfo,
std::string_view label)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fLabel(label)
, fMipmapped(mipmapped)
, fBackend(GrBackendApi::kMock)
, fTextureType(GrTextureType::k2D)

View File

@ -702,7 +702,10 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe
: GrMipmapStatus::kNotAllocated;
auto texture = GrGLTexture::MakeWrapped(this, mipmapStatus, desc,
backendTex.getGLTextureParams(), cacheable, ioType);
backendTex.getGLTextureParams(),
cacheable,
ioType,
backendTex.getLabel());
if (this->glCaps().isFormatRenderable(backendTex.getBackendFormat(), 1)) {
// Pessimistically assume this external texture may have been bound to a FBO.
texture->baseLevelWasBoundToFBO();
@ -757,7 +760,7 @@ sk_sp<GrTexture> GrGLGpu::onWrapCompressedBackendTexture(const GrBackendTexture&
auto texture = GrGLTexture::MakeWrapped(this, mipmapStatus, desc,
backendTex.getGLTextureParams(), cacheable,
kRead_GrIOType);
kRead_GrIOType, backendTex.getLabel());
return std::move(texture);
}

View File

@ -146,10 +146,10 @@ sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu,
const Desc& desc,
sk_sp<GrGLTextureParameters> parameters,
GrWrapCacheable cacheable,
GrIOType ioType) {
GrIOType ioType,
std::string_view label) {
return sk_sp<GrGLTexture>(new GrGLTexture(
gpu, desc, mipmapStatus, std::move(parameters), cacheable, ioType,
/*label=*/"GLTextureMakeWrapped"));
gpu, desc, mipmapStatus, std::move(parameters), cacheable, ioType, label));
}
bool GrGLTexture::onStealBackendTexture(GrBackendTexture* backendTexture,

View File

@ -54,7 +54,8 @@ public:
GrMipmapStatus,
const Desc&,
sk_sp<GrGLTextureParameters>,
GrWrapCacheable, GrIOType);
GrWrapCacheable, GrIOType,
std::string_view label);
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;

View File

@ -117,9 +117,13 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLTexture, report
auto params = sk_make_sp<GrGLTextureParameters>();
auto texture =
GrGLTexture::MakeWrapped(gpu, GrMipmapStatus::kNotAllocated, desc, std::move(params),
GrWrapCacheable::kNo, kRead_GrIOType);
auto texture = GrGLTexture::MakeWrapped(gpu,
GrMipmapStatus::kNotAllocated,
desc,
std::move(params),
GrWrapCacheable::kNo,
kRead_GrIOType,
/*label=*/{});
ValidateMemoryDumps(reporter, dContext, 2, texture->gpuMemorySize(), false /* isOwned */);
}