Add new GrContext::updateBackendTexture call that takes an SkColorType.

Change-Id: Iba71698f52eba3e7a99e0712a51ce48953b995db
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304601
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Greg Daniel 2020-07-21 10:41:50 -04:00 committed by Skia Commit-Bot
parent 40a40623c8
commit 373d7dd0ed
4 changed files with 51 additions and 6 deletions

View File

@ -567,6 +567,23 @@ public:
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext);
/**
* If possible, updates a backend texture to be filled to a particular color. The data in
* GrBackendTexture and passed in color is interpreted with respect to the passed in
* SkColorType. The client should check the return value to see if the update was successful.
* The client can pass in a finishedProc to be notified when the data has been uploaded by the
* gpu and the texture can be deleted. The client is required to call GrContext::submit to send
* the upload work to the gpu. The finishedProc will always get called even if we failed to
* update the GrBackendTexture.
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
*/
bool updateBackendTexture(const GrBackendTexture&,
SkColorType skColorType,
const SkColor4f& color,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext);
/**
* If possible, updates a backend texture filled with the provided pixmap data. The client
* should check the return value to see if the update was successful. The client can pass in a

View File

@ -658,6 +658,37 @@ bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,
return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
}
bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,
SkColorType skColorType,
const SkColor4f& color,
GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) {
sk_sp<GrRefCntedCallback> finishedCallback;
if (finishedProc) {
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
}
if (!this->asDirectContext()) {
return false;
}
if (this->abandoned()) {
return false;
}
GrBackendFormat format = backendTexture.getBackendFormat();
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(this->caps(), skColorType, format);
if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, format)) {
return false;
}
GrSwizzle swizzle = this->caps()->getWriteSwizzle(format, grColorType);
GrGpu::BackendTextureData data(swizzle.applyTo(color));
return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
}
bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,
const SkPixmap srcData[],
int numLevels,

View File

@ -1003,6 +1003,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
}
}
}
// Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16
{
constexpr VkFormat format = VK_FORMAT_R4G4B4A4_UNORM_PACK16;

View File

@ -357,12 +357,8 @@ void test_color_init(GrDirectContext* dContext,
SkColor4f newColor = {color.fB , color.fR, color.fG, color.fA };
// Reupload the new data and make sure everything still works. We test with an SkColorType so
// we may actually swizzle the input during the create path. The update does not do any swizzle
// of the passed in color. So we manually do it here so we get the same expected results.
SkColor4f swizzledColor = dContext->priv().caps()->getWriteSwizzle(
backendTex.getBackendFormat(), grColorType).applyTo(newColor);
dContext->updateBackendTexture(backendTex, swizzledColor, mark_signaled, finishedBECreate);
dContext->updateBackendTexture(backendTex, skColorType, newColor, mark_signaled,
finishedBECreate);
checkBackendTexture(newColor);