Commit 6a29fa96 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Remove CanvasColorParams from WebGPU

Some WebGPU ImageBitmap helper functions use CanvasColorParams
to determine the pixel format and color space of an ImageBitmap.

But ImageBitmap already has a SkImageInfo, which specifies these
things.

So we're specifying the same thing twice, in two potentially
incompatible ways. Remove one.

Bug: 1119507
Change-Id: Iadeedb9bb09831d69e6012763eb5039cd8840a0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2373450Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarKai Ninomiya <kainino@chromium.org>
Reviewed-by: default avatarYi Xu <yiyix@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803963}
parent 2937cf33
......@@ -100,15 +100,16 @@ bool IsValidCopyIB2TDestinationFormat(WGPUTextureFormat dawn_texture_format) {
}
bool CanUploadThroughGPU(StaticBitmapImage* image,
const CanvasColorParams& color_param,
GPUTexture* dest_texture) {
// Cannot handle top left origin image
if (image->CurrentFrameOrientation().Orientation() !=
ImageOrientationEnum::kOriginBottomLeft) {
return false;
}
// Cannot handle source and dest texture have uncompatible format
if (!AreCompatibleFormatForImageBitmapGPUCopy(color_param.GetSkColorType(),
SkImageInfo image_info = image->PaintImageForCurrentFrame().GetSkImageInfo();
if (!AreCompatibleFormatForImageBitmapGPUCopy(image_info.colorType(),
dest_texture->Format())) {
return false;
}
......@@ -371,14 +372,10 @@ void GPUQueue::copyImageBitmapToTexture(
return;
}
const CanvasColorParams& color_params =
source->imageBitmap()->GetCanvasColorParams();
// TODO(shaobo.yan@intel.com): Implement GPU copy path
// Try GPU path first.
if (image->IsTextureBacked()) { // Try GPU uploading path.
if (CanUploadThroughGPU(image.get(), color_params,
destination->texture())) {
if (CanUploadThroughGPU(image.get(), destination->texture())) {
if (CopyContentFromGPU(image.get(), origin_in_image_bitmap,
dawn_copy_size, dawn_destination)) {
return;
......@@ -388,16 +385,14 @@ void GPUQueue::copyImageBitmapToTexture(
image = image->MakeUnaccelerated();
}
// CPU path is the fallback path and should always work.
if (!CopyContentFromCPU(image.get(), color_params, origin_in_image_bitmap,
dawn_copy_size, dawn_destination,
destination->texture()->Format())) {
if (!CopyContentFromCPU(image.get(), origin_in_image_bitmap, dawn_copy_size,
dawn_destination, destination->texture()->Format())) {
exception_state.ThrowTypeError("Failed to copy content from imageBitmap.");
return;
}
}
bool GPUQueue::CopyContentFromCPU(StaticBitmapImage* image,
const CanvasColorParams& color_params,
const WGPUOrigin3D& origin,
const WGPUExtent3D& copy_size,
const WGPUTextureCopyView& destination,
......@@ -426,7 +421,7 @@ bool GPUQueue::CopyContentFromCPU(StaticBitmapImage* image,
if (!CopyBytesFromImageBitmapForWebGPU(
image, base::span<uint8_t>(static_cast<uint8_t*>(data), size),
image_data_rect, color_params, dest_texture_format)) {
image_data_rect, dest_texture_format)) {
// Release the buffer.
GetProcs().bufferRelease(buffer);
return false;
......
......@@ -11,7 +11,6 @@
namespace blink {
class CanvasColorParams;
class DawnTextureFromImageBitmap;
class ExceptionState;
class GPUBuffer;
......@@ -77,7 +76,6 @@ class GPUQueue : public DawnObject<WGPUQueue> {
private:
bool CopyContentFromCPU(StaticBitmapImage* image,
const CanvasColorParams& color_params,
const WGPUOrigin3D& origin,
const WGPUExtent3D& copy_size,
const WGPUTextureCopyView& destination,
......
......@@ -37,6 +37,11 @@ gfx::ColorSpace CanvasColorSpaceToGfxColorSpace(CanvasColorSpace color_space) {
} // namespace
sk_sp<SkColorSpace> CanvasColorSpaceToSkColorSpace(
CanvasColorSpace color_space) {
return CanvasColorSpaceToGfxColorSpace(color_space).ToSkColorSpace();
}
CanvasColorParams::CanvasColorParams() = default;
CanvasColorParams::CanvasColorParams(CanvasColorSpace color_space,
......@@ -104,7 +109,7 @@ sk_sp<SkColorSpace> CanvasColorParams::GetSkColorSpace() const {
static_assert(kN32_SkColorType == kRGBA_8888_SkColorType ||
kN32_SkColorType == kBGRA_8888_SkColorType,
"Unexpected kN32_SkColorType value.");
return CanvasColorSpaceToGfxColorSpace(color_space_).ToSkColorSpace();
return CanvasColorSpaceToSkColorSpace(color_space_);
}
gfx::BufferFormat CanvasColorParams::GetBufferFormat() const {
......
......@@ -15,10 +15,6 @@
class SkSurfaceProps;
namespace cc {
class PaintCanvas;
}
namespace gfx {
class ColorSpace;
}
......@@ -37,6 +33,9 @@ enum class CanvasPixelFormat {
kF16,
};
sk_sp<SkColorSpace> PLATFORM_EXPORT
CanvasColorSpaceToSkColorSpace(CanvasColorSpace color_space);
class PLATFORM_EXPORT CanvasColorParams {
DISALLOW_NEW();
......@@ -65,10 +64,7 @@ class PLATFORM_EXPORT CanvasColorParams {
// conversion to be used in the passed canvas color settings.
bool NeedsColorConversion(const CanvasColorParams&) const;
// The SkColorSpace to use in the SkImageInfo for allocated SkSurfaces. This
// is nullptr in legacy rendering mode and when the surface is supposed to be
// in sRGB (for which we wrap the canvas into a PaintCanvas along with an
// SkColorSpaceXformCanvas).
// The SkColorSpace to use in the SkImageInfo for SkImages and SkSurfaces.
sk_sp<SkColorSpace> GetSkColorSpaceForSkSurfaces() const;
// The pixel format to use for allocating SkSurfaces.
......
......@@ -75,7 +75,6 @@ bool CopyBytesFromImageBitmapForWebGPU(
scoped_refptr<StaticBitmapImage> image,
base::span<uint8_t> dst,
const IntRect& rect,
const CanvasColorParams& color_params,
const WGPUTextureFormat destination_format) {
DCHECK(image);
DCHECK_GT(dst.size(), static_cast<size_t>(0));
......@@ -91,6 +90,7 @@ bool CopyBytesFromImageBitmapForWebGPU(
if (sk_color_type == kUnknown_SkColorType) {
return false;
}
PaintImage paint_image = image->PaintImageForCurrentFrame();
// Read pixel request dst info.
// Keep premulalpha config and color space from imageBitmap and using dest
......@@ -98,9 +98,9 @@ bool CopyBytesFromImageBitmapForWebGPU(
SkImageInfo info = SkImageInfo::Make(
rect.Width(), rect.Height(), sk_color_type,
image->IsPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType,
color_params.GetSkColorSpaceForSkSurfaces());
paint_image.GetSkImageInfo().refColorSpace());
bool read_pixels_successful = image->PaintImageForCurrentFrame().readPixels(
bool read_pixels_successful = paint_image.readPixels(
info, dst.data(), wgpu_info.wgpu_bytes_per_row, rect.X(), rect.Y());
if (!read_pixels_successful) {
......
......@@ -20,7 +20,6 @@ struct WebGPUImageUploadSizeInfo {
uint32_t wgpu_bytes_per_row;
};
class CanvasColorParams;
class IntRect;
class StaticBitmapImage;
......@@ -32,7 +31,6 @@ bool PLATFORM_EXPORT
CopyBytesFromImageBitmapForWebGPU(scoped_refptr<StaticBitmapImage> image,
base::span<uint8_t> dst,
const IntRect& rect,
const CanvasColorParams& color_params,
const WGPUTextureFormat destination_format);
uint64_t PLATFORM_EXPORT
......
......@@ -184,19 +184,6 @@ base::span<const uint8_t> GetSrcPixelContent(SkColorType format) {
}
}
CanvasPixelFormat SkColorTypeToCanvasPixelFormat(SkColorType format) {
switch (format) {
case SkColorType::kRGBA_8888_SkColorType:
return CanvasPixelFormat::kRGBA8;
case SkColorType::kBGRA_8888_SkColorType:
return CanvasPixelFormat::kBGRA8;
case SkColorType::kRGBA_F16_SkColorType:
return CanvasPixelFormat::kF16;
default:
NOTREACHED();
return CanvasPixelFormat::kRGBA8;
}
}
} // anonymous namespace
class WebGPUImageBitmapHandlerTest : public testing::Test {
......@@ -206,17 +193,16 @@ class WebGPUImageBitmapHandlerTest : public testing::Test {
void VerifyCopyBytesForCanvasColorParams(uint64_t width,
uint64_t height,
SkImageInfo info,
CanvasColorParams param,
IntRect copy_rect,
WGPUTextureFormat color_type) {
const uint64_t content_length = width * height * param.BytesPerPixel();
const uint64_t content_length = width * height * info.bytesPerPixel();
std::vector<uint8_t> contents(content_length, 0);
// Initialize contents.
for (size_t i = 0; i < content_length; ++i) {
contents[i] = i % std::numeric_limits<uint8_t>::max();
}
VerifyCopyBytes(width, height, info, param, copy_rect, color_type,
VerifyCopyBytes(width, height, info, copy_rect, color_type,
base::span<uint8_t>(contents.data(), content_length),
base::span<uint8_t>(contents.data(), content_length));
}
......@@ -224,13 +210,12 @@ class WebGPUImageBitmapHandlerTest : public testing::Test {
void VerifyCopyBytes(uint64_t width,
uint64_t height,
SkImageInfo info,
CanvasColorParams param,
IntRect copy_rect,
WGPUTextureFormat color_type,
base::span<const uint8_t> contents,
base::span<const uint8_t> expected_value) {
uint64_t bytes_per_pixel = DawnTextureFormatBytesPerPixel(color_type);
ASSERT_EQ(contents.size(), width * height * param.BytesPerPixel());
ASSERT_EQ(contents.size(), width * height * info.bytesPerPixel());
sk_sp<SkData> image_pixels =
SkData::MakeWithCopy(contents.data(), contents.size());
scoped_refptr<StaticBitmapImage> image =
......@@ -243,7 +228,7 @@ class WebGPUImageBitmapHandlerTest : public testing::Test {
std::vector<uint8_t> results(result_length, 0);
bool success = CopyBytesFromImageBitmapForWebGPU(
image, base::span<uint8_t>(results.data(), result_length), copy_rect,
param, color_type);
color_type);
ASSERT_EQ(success, true);
// Compare content and results
......@@ -293,16 +278,12 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyColorConvert) {
for (SkColorType src_color_type : srcSkColorFormat) {
for (WGPUTextureFormat dst_color_type : kDstWebGPUTextureFormat) {
for (CanvasColorSpace color_space : kColorSpaces) {
CanvasColorParams color_param(
color_space, SkColorTypeToCanvasPixelFormat(src_color_type),
OpacityMode::kNonOpaque);
SkImageInfo info =
SkImageInfo::Make(kImageWidth, kImageHeight, src_color_type,
SkAlphaType::kUnpremul_SkAlphaType,
color_param.GetSkColorSpaceForSkSurfaces());
VerifyCopyBytes(kImageWidth, kImageHeight, info, color_param,
image_data_rect, dst_color_type,
GetSrcPixelContent(src_color_type),
CanvasColorSpaceToSkColorSpace(color_space));
VerifyCopyBytes(kImageWidth, kImageHeight, info, image_data_rect,
dst_color_type, GetSrcPixelContent(src_color_type),
GetDstContent(dst_color_type));
}
}
......@@ -313,8 +294,6 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyColorConvert) {
TEST_F(WebGPUImageBitmapHandlerTest, VerifyGetWGPUResourceInfo) {
uint64_t kImageWidth = 63;
uint64_t kImageHeight = 1;
CanvasColorParams param(CanvasColorSpace::kSRGB, CanvasPixelFormat::kRGBA8,
OpacityMode::kNonOpaque);
// Prebaked expected values.
uint32_t expected_bytes_per_row = 256;
......@@ -336,11 +315,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesFromImageBitmapForWebGPU) {
SkAlphaType::kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());
IntRect image_data_rect(0, 0, kImageWidth, kImageHeight);
CanvasColorParams color_params(CanvasColorSpace::kSRGB,
CanvasPixelFormat::kRGBA8,
OpacityMode::kNonOpaque);
VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info,
color_params, image_data_rect,
image_data_rect,
WGPUTextureFormat_RGBA8Unorm);
}
......@@ -353,11 +329,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesFromSubImageBitmap) {
SkAlphaType::kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());
IntRect image_data_rect(2, 2, 60, 2);
CanvasColorParams color_params(CanvasColorSpace::kSRGB,
CanvasPixelFormat::kRGBA8,
OpacityMode::kNonOpaque);
VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info,
color_params, image_data_rect,
image_data_rect,
WGPUTextureFormat_RGBA8Unorm);
}
......@@ -370,11 +343,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesWithPremultiplyAlpha) {
SkAlphaType::kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
IntRect image_data_rect(0, 0, 2, 1);
CanvasColorParams color_params(
CanvasColorSpace::kSRGB, CanvasPixelFormat::kRGBA8, OpacityMode::kOpaque);
VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info,
color_params, image_data_rect,
image_data_rect,
WGPUTextureFormat_RGBA8Unorm);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment