Skip to content

Commit

Permalink
Add internal calls for updateCompressedBackendTexture.
Browse files Browse the repository at this point in the history
This splits the creation and the updating of backend compressed textures
below the public API level. In a follow on change I will add the public
api call to updateCompressedBackendTexture.

Bug: chromium:1099255
Change-Id: Ie410cfb42046d0e0c8f4fe60055be5782f811d47
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301577
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
  • Loading branch information
egdaniel authored and Skia Commit-Bot committed Jul 10, 2020
1 parent 525e876 commit aaf738c
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 100 deletions.
36 changes: 30 additions & 6 deletions src/gpu/GrContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,30 @@ bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,

//////////////////////////////////////////////////////////////////////////////

static GrBackendTexture create_and_update_compressed_backend_texture(
GrContext* context,
SkISize dimensions,
const GrBackendFormat& backendFormat,
GrMipMapped mipMapped,
GrProtected isProtected,
sk_sp<GrRefCntedCallback> finishedCallback,
const GrGpu::BackendTextureData* data) {
GrGpu* gpu = context->priv().getGpu();

GrBackendTexture beTex = gpu->createCompressedBackendTexture(dimensions, backendFormat,
mipMapped, isProtected);
if (!beTex.isValid()) {
return {};
}

if (!context->priv().getGpu()->updateCompressedBackendTexture(
beTex, std::move(finishedCallback), data)) {
context->deleteBackendTexture(beTex);
return {};
}
return beTex;
}

GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height,
const GrBackendFormat& backendFormat,
const SkColor4f& color,
Expand All @@ -717,9 +741,9 @@ GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height
}

GrGpu::BackendTextureData data(color);
return fGpu->createCompressedBackendTexture({width, height}, backendFormat,
mipMapped, isProtected, std::move(finishedCallback),
&data);
return create_and_update_compressed_backend_texture(this, {width, height}, backendFormat,
mipMapped, isProtected,
std::move(finishedCallback), &data);
}

GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height,
Expand Down Expand Up @@ -759,9 +783,9 @@ GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height
}

GrGpu::BackendTextureData data(compressedData, dataSize);
return fGpu->createCompressedBackendTexture({width, height}, backendFormat,
mipMapped, isProtected, std::move(finishedCallback),
&data);
return create_and_update_compressed_backend_texture(this, {width, height}, backendFormat,
mipMapped, isProtected,
std::move(finishedCallback), &data);
}

GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height,
Expand Down
38 changes: 31 additions & 7 deletions src/gpu/GrGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,7 @@ bool GrGpu::updateBackendTexture(const GrBackendTexture& backendTexture,
GrBackendTexture GrGpu::createCompressedBackendTexture(SkISize dimensions,
const GrBackendFormat& format,
GrMipMapped mipMapped,
GrProtected isProtected,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData* data) {
GrProtected isProtected) {
const GrCaps* caps = this->caps();

if (!format.isValid()) {
Expand All @@ -957,12 +955,38 @@ GrBackendTexture GrGpu::createCompressedBackendTexture(SkISize dimensions,
return {};
}

if (!CompressedDataIsCorrect(dimensions, compressionType, mipMapped, data)) {
return {};
return this->onCreateCompressedBackendTexture(dimensions, format, mipMapped, isProtected);
}

bool GrGpu::updateCompressedBackendTexture(const GrBackendTexture& backendTexture,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData* data) {
SkASSERT(data);

if (!backendTexture.isValid()) {
return false;
}

GrBackendFormat format = backendTexture.getBackendFormat();

SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format);
if (compressionType == SkImage::CompressionType::kNone) {
// Uncompressed formats must go through the createBackendTexture API
return false;
}

if (backendTexture.hasMipMaps() && !this->caps()->mipMapSupport()) {
return false;
}

GrMipMapped mipMapped = backendTexture.hasMipMaps() ? GrMipMapped::kYes : GrMipMapped::kNo;

if (!CompressedDataIsCorrect(backendTexture.dimensions(), compressionType, mipMapped, data)) {
return false;
}

return this->onCreateCompressedBackendTexture(dimensions, format, mipMapped,
isProtected, std::move(finishedCallback), data);
return this->onUpdateCompressedBackendTexture(backendTexture, std::move(finishedCallback),
data);
}

GrStagingBuffer* GrGpu::findStagingBuffer(size_t size) {
Expand Down
15 changes: 10 additions & 5 deletions src/gpu/GrGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,11 @@ class GrGpu : public SkRefCnt {
GrBackendTexture createCompressedBackendTexture(SkISize dimensions,
const GrBackendFormat&,
GrMipMapped,
GrProtected,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*);
GrProtected);

bool updateCompressedBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*);

virtual bool setBackendTextureState(const GrBackendTexture&,
const GrBackendSurfaceMutableState&,
Expand Down Expand Up @@ -741,13 +743,16 @@ class GrGpu : public SkRefCnt {
GrProtected) = 0;

virtual GrBackendTexture onCreateCompressedBackendTexture(
SkISize dimensions, const GrBackendFormat&, GrMipMapped, GrProtected,
sk_sp<GrRefCntedCallback> finishedCallback, const BackendTextureData*) = 0;
SkISize dimensions, const GrBackendFormat&, GrMipMapped, GrProtected) = 0;

virtual bool onUpdateBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) = 0;

virtual bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) = 0;

// called when the 3D context state is unknown. Subclass should emit any
// assumed 3D context state and dirty any state cache.
virtual void onResetContext(uint32_t resetBits) = 0;
Expand Down
9 changes: 7 additions & 2 deletions src/gpu/d3d/GrD3DGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,7 @@ bool GrD3DGpu::onUpdateBackendTexture(const GrBackendTexture& backendTexture,

GrBackendTexture GrD3DGpu::onCreateCompressedBackendTexture(
SkISize dimensions, const GrBackendFormat& format, GrMipMapped mipMapped,
GrProtected isProtected, sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData* data) {
GrProtected isProtected) {
this->handleDirtyContext();

const GrD3DCaps& caps = this->d3dCaps();
Expand Down Expand Up @@ -1101,6 +1100,12 @@ GrBackendTexture GrD3DGpu::onCreateCompressedBackendTexture(
return GrBackendTexture(dimensions.width(), dimensions.height(), info);
}

bool GrD3DGpu::onUpdateCompressedBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) {
return false;
}

void GrD3DGpu::deleteBackendTexture(const GrBackendTexture& tex) {
SkASSERT(GrBackendApi::kDirect3D == tex.fBackend);
// Nothing to do here, will get cleaned up when the GrBackendTexture object goes away
Expand Down
8 changes: 5 additions & 3 deletions src/gpu/d3d/GrD3DGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ class GrD3DGpu : public GrGpu {
GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
const GrBackendFormat&,
GrMipMapped,
GrProtected,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) override;
GrProtected) override;

bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) override;

bool submitDirectCommandList(SyncQueue sync);

Expand Down
9 changes: 7 additions & 2 deletions src/gpu/dawn/GrDawnGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,16 @@ bool GrDawnGpu::onUpdateBackendTexture(const GrBackendTexture& backendTexture,
}

GrBackendTexture GrDawnGpu::onCreateCompressedBackendTexture(
SkISize dimensions, const GrBackendFormat&, GrMipMapped, GrProtected,
sk_sp<GrRefCntedCallback> finishedCallback, const BackendTextureData*) {
SkISize dimensions, const GrBackendFormat&, GrMipMapped, GrProtected) {
return {};
}

bool GrDawnGpu::onUpdateCompressedBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) {
return false;
}

void GrDawnGpu::deleteBackendTexture(const GrBackendTexture& tex) {
GrDawnTextureInfo info;
if (tex.getDawnTextureInfo(&info)) {
Expand Down
8 changes: 5 additions & 3 deletions src/gpu/dawn/GrDawnGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ class GrDawnGpu : public GrGpu {
GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
const GrBackendFormat&,
GrMipMapped,
GrProtected,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) override;
GrProtected) override;

bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) override;

sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
const void* data) override;
Expand Down
97 changes: 61 additions & 36 deletions src/gpu/gl/GrGLGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,12 +1392,19 @@ sk_sp<GrTexture> GrGLGpu::onCreateCompressedTexture(SkISize dimensions,
desc.fOwnership = GrBackendObjectOwnership::kOwned;
desc.fFormat = format.asGLFormat();
desc.fID = this->createCompressedTexture2D(desc.fSize, compression, desc.fFormat,
mipMapped, &initialState,
data, dataSize);
mipMapped, &initialState);
if (!desc.fID) {
return nullptr;
}

if (data) {
if (!this->uploadCompressedTexData(compression, desc.fFormat, dimensions, mipMapped,
GR_GL_TEXTURE_2D, data, dataSize)) {
GL_CALL(DeleteTextures(1, &desc.fID));
return nullptr;
}
}

// Unbind this texture from the scratch texture unit.
this->bindTextureToScratchUnit(GR_GL_TEXTURE_2D, 0);

Expand All @@ -1414,8 +1421,7 @@ sk_sp<GrTexture> GrGLGpu::onCreateCompressedTexture(SkISize dimensions,

GrBackendTexture GrGLGpu::onCreateCompressedBackendTexture(
SkISize dimensions, const GrBackendFormat& format, GrMipMapped mipMapped,
GrProtected isProtected, sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData* data) {
GrProtected isProtected) {
// We don't support protected textures in GL.
if (isProtected == GrProtected::kYes) {
return {};
Expand All @@ -1430,34 +1436,13 @@ GrBackendTexture GrGLGpu::onCreateCompressedBackendTexture(

SkImage::CompressionType compression = GrBackendFormatToCompressionType(format);

const char* rawData = nullptr;
size_t rawDataSize = 0;
SkAutoMalloc am;
SkASSERT(!data || data->type() != BackendTextureData::Type::kPixmaps);
if (data && data->type() == BackendTextureData::Type::kCompressed) {
rawData = (const char*) data->compressedData();
rawDataSize = data->compressedSize();
} else if (data && data->type() == BackendTextureData::Type::kColor) {
SkASSERT(compression != SkImage::CompressionType::kNone);

rawDataSize = SkCompressedDataSize(compression, dimensions, nullptr,
mipMapped == GrMipMapped::kYes);

am.reset(rawDataSize);

GrFillInCompressedData(compression, dimensions, mipMapped, (char*)am.get(), data->color());

rawData = (const char*) am.get();
}

GrGLTextureInfo info;
GrGLTextureParameters::SamplerOverriddenState initialState;

info.fTarget = GR_GL_TEXTURE_2D;
info.fFormat = GrGLFormatToEnum(glFormat);
info.fID = this->createCompressedTexture2D(dimensions, compression, glFormat,
mipMapped, &initialState,
rawData, rawDataSize);
mipMapped, &initialState);
if (!info.fID) {
return {};
}
Expand All @@ -1474,6 +1459,55 @@ GrBackendTexture GrGLGpu::onCreateCompressedBackendTexture(
std::move(parameters));
}

bool GrGLGpu::onUpdateCompressedBackendTexture(const GrBackendTexture& backendTexture,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData* data) {
SkASSERT(data && data->type() != BackendTextureData::Type::kPixmaps);

GrGLTextureInfo info;
SkAssertResult(backendTexture.getGLTextureInfo(&info));

GrBackendFormat format = backendTexture.getBackendFormat();
GrGLFormat glFormat = format.asGLFormat();
if (glFormat == GrGLFormat::kUnknown) {
return false;
}
SkImage::CompressionType compression = GrBackendFormatToCompressionType(format);

GrMipMapped mipMapped = backendTexture.hasMipMaps() ? GrMipMapped::kYes : GrMipMapped::kNo;

const char* rawData = nullptr;
size_t rawDataSize = 0;
SkAutoMalloc am;
if (data->type() == BackendTextureData::Type::kCompressed) {
rawData = (const char*)data->compressedData();
rawDataSize = data->compressedSize();
} else {
SkASSERT(data->type() == BackendTextureData::Type::kColor);
SkASSERT(compression != SkImage::CompressionType::kNone);

rawDataSize = SkCompressedDataSize(compression, backendTexture.dimensions(), nullptr,
backendTexture.hasMipMaps());

am.reset(rawDataSize);

GrFillInCompressedData(compression, backendTexture.dimensions(), mipMapped, (char*)am.get(),
data->color());

rawData = (const char*)am.get();
}

this->bindTextureToScratchUnit(info.fTarget, info.fID);
bool result = this->uploadCompressedTexData(
compression, glFormat, backendTexture.dimensions(), mipMapped, GR_GL_TEXTURE_2D,
rawData, rawDataSize);

// Unbind this texture from the scratch texture unit.
this->bindTextureToScratchUnit(info.fTarget, 0);

return result;
}

namespace {

const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
Expand Down Expand Up @@ -1581,8 +1615,7 @@ GrGLuint GrGLGpu::createCompressedTexture2D(
SkImage::CompressionType compression,
GrGLFormat format,
GrMipMapped mipMapped,
GrGLTextureParameters::SamplerOverriddenState* initialState,
const void* data, size_t dataSize) {
GrGLTextureParameters::SamplerOverriddenState* initialState) {
if (format == GrGLFormat::kUnknown) {
return 0;
}
Expand All @@ -1596,14 +1629,6 @@ GrGLuint GrGLGpu::createCompressedTexture2D(

*initialState = set_initial_texture_params(this->glInterface(), GR_GL_TEXTURE_2D);

if (data) {
if (!this->uploadCompressedTexData(compression, format, dimensions, mipMapped,
GR_GL_TEXTURE_2D, data, dataSize)) {
GL_CALL(DeleteTextures(1, &id));
return 0;
}
}

return id;
}

Expand Down
11 changes: 6 additions & 5 deletions src/gpu/gl/GrGLGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,16 @@ class GrGLGpu final : public GrGpu {
GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
const GrBackendFormat&,
GrMipMapped,
GrProtected,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) override;
GrProtected) override;

bool onUpdateBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) override;

bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
sk_sp<GrRefCntedCallback> finishedCallback,
const BackendTextureData*) override;

void onResetContext(uint32_t resetBits) override;

void onResetTextureBindings() override;
Expand Down Expand Up @@ -271,8 +273,7 @@ class GrGLGpu final : public GrGpu {
SkImage::CompressionType compression,
GrGLFormat,
GrMipMapped,
GrGLTextureParameters::SamplerOverriddenState*,
const void* data, size_t dataSize);
GrGLTextureParameters::SamplerOverriddenState*);

bool onReadPixels(GrSurface*, int left, int top, int width, int height,
GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
Expand Down
Loading

0 comments on commit aaf738c

Please sign in to comment.