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) { ...@@ -100,15 +100,16 @@ bool IsValidCopyIB2TDestinationFormat(WGPUTextureFormat dawn_texture_format) {
} }
bool CanUploadThroughGPU(StaticBitmapImage* image, bool CanUploadThroughGPU(StaticBitmapImage* image,
const CanvasColorParams& color_param,
GPUTexture* dest_texture) { GPUTexture* dest_texture) {
// Cannot handle top left origin image // Cannot handle top left origin image
if (image->CurrentFrameOrientation().Orientation() != if (image->CurrentFrameOrientation().Orientation() !=
ImageOrientationEnum::kOriginBottomLeft) { ImageOrientationEnum::kOriginBottomLeft) {
return false; return false;
} }
// Cannot handle source and dest texture have uncompatible format // 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())) { dest_texture->Format())) {
return false; return false;
} }
...@@ -371,14 +372,10 @@ void GPUQueue::copyImageBitmapToTexture( ...@@ -371,14 +372,10 @@ void GPUQueue::copyImageBitmapToTexture(
return; return;
} }
const CanvasColorParams& color_params =
source->imageBitmap()->GetCanvasColorParams();
// TODO(shaobo.yan@intel.com): Implement GPU copy path // TODO(shaobo.yan@intel.com): Implement GPU copy path
// Try GPU path first. // Try GPU path first.
if (image->IsTextureBacked()) { // Try GPU uploading path. if (image->IsTextureBacked()) { // Try GPU uploading path.
if (CanUploadThroughGPU(image.get(), color_params, if (CanUploadThroughGPU(image.get(), destination->texture())) {
destination->texture())) {
if (CopyContentFromGPU(image.get(), origin_in_image_bitmap, if (CopyContentFromGPU(image.get(), origin_in_image_bitmap,
dawn_copy_size, dawn_destination)) { dawn_copy_size, dawn_destination)) {
return; return;
...@@ -388,16 +385,14 @@ void GPUQueue::copyImageBitmapToTexture( ...@@ -388,16 +385,14 @@ void GPUQueue::copyImageBitmapToTexture(
image = image->MakeUnaccelerated(); image = image->MakeUnaccelerated();
} }
// CPU path is the fallback path and should always work. // CPU path is the fallback path and should always work.
if (!CopyContentFromCPU(image.get(), color_params, origin_in_image_bitmap, if (!CopyContentFromCPU(image.get(), origin_in_image_bitmap, dawn_copy_size,
dawn_copy_size, dawn_destination, dawn_destination, destination->texture()->Format())) {
destination->texture()->Format())) {
exception_state.ThrowTypeError("Failed to copy content from imageBitmap."); exception_state.ThrowTypeError("Failed to copy content from imageBitmap.");
return; return;
} }
} }
bool GPUQueue::CopyContentFromCPU(StaticBitmapImage* image, bool GPUQueue::CopyContentFromCPU(StaticBitmapImage* image,
const CanvasColorParams& color_params,
const WGPUOrigin3D& origin, const WGPUOrigin3D& origin,
const WGPUExtent3D& copy_size, const WGPUExtent3D& copy_size,
const WGPUTextureCopyView& destination, const WGPUTextureCopyView& destination,
...@@ -426,7 +421,7 @@ bool GPUQueue::CopyContentFromCPU(StaticBitmapImage* image, ...@@ -426,7 +421,7 @@ bool GPUQueue::CopyContentFromCPU(StaticBitmapImage* image,
if (!CopyBytesFromImageBitmapForWebGPU( if (!CopyBytesFromImageBitmapForWebGPU(
image, base::span<uint8_t>(static_cast<uint8_t*>(data), size), 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. // Release the buffer.
GetProcs().bufferRelease(buffer); GetProcs().bufferRelease(buffer);
return false; return false;
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace blink { namespace blink {
class CanvasColorParams;
class DawnTextureFromImageBitmap; class DawnTextureFromImageBitmap;
class ExceptionState; class ExceptionState;
class GPUBuffer; class GPUBuffer;
...@@ -77,7 +76,6 @@ class GPUQueue : public DawnObject<WGPUQueue> { ...@@ -77,7 +76,6 @@ class GPUQueue : public DawnObject<WGPUQueue> {
private: private:
bool CopyContentFromCPU(StaticBitmapImage* image, bool CopyContentFromCPU(StaticBitmapImage* image,
const CanvasColorParams& color_params,
const WGPUOrigin3D& origin, const WGPUOrigin3D& origin,
const WGPUExtent3D& copy_size, const WGPUExtent3D& copy_size,
const WGPUTextureCopyView& destination, const WGPUTextureCopyView& destination,
......
...@@ -37,6 +37,11 @@ gfx::ColorSpace CanvasColorSpaceToGfxColorSpace(CanvasColorSpace color_space) { ...@@ -37,6 +37,11 @@ gfx::ColorSpace CanvasColorSpaceToGfxColorSpace(CanvasColorSpace color_space) {
} // namespace } // namespace
sk_sp<SkColorSpace> CanvasColorSpaceToSkColorSpace(
CanvasColorSpace color_space) {
return CanvasColorSpaceToGfxColorSpace(color_space).ToSkColorSpace();
}
CanvasColorParams::CanvasColorParams() = default; CanvasColorParams::CanvasColorParams() = default;
CanvasColorParams::CanvasColorParams(CanvasColorSpace color_space, CanvasColorParams::CanvasColorParams(CanvasColorSpace color_space,
...@@ -104,7 +109,7 @@ sk_sp<SkColorSpace> CanvasColorParams::GetSkColorSpace() const { ...@@ -104,7 +109,7 @@ sk_sp<SkColorSpace> CanvasColorParams::GetSkColorSpace() const {
static_assert(kN32_SkColorType == kRGBA_8888_SkColorType || static_assert(kN32_SkColorType == kRGBA_8888_SkColorType ||
kN32_SkColorType == kBGRA_8888_SkColorType, kN32_SkColorType == kBGRA_8888_SkColorType,
"Unexpected kN32_SkColorType value."); "Unexpected kN32_SkColorType value.");
return CanvasColorSpaceToGfxColorSpace(color_space_).ToSkColorSpace(); return CanvasColorSpaceToSkColorSpace(color_space_);
} }
gfx::BufferFormat CanvasColorParams::GetBufferFormat() const { gfx::BufferFormat CanvasColorParams::GetBufferFormat() const {
......
...@@ -15,10 +15,6 @@ ...@@ -15,10 +15,6 @@
class SkSurfaceProps; class SkSurfaceProps;
namespace cc {
class PaintCanvas;
}
namespace gfx { namespace gfx {
class ColorSpace; class ColorSpace;
} }
...@@ -37,6 +33,9 @@ enum class CanvasPixelFormat { ...@@ -37,6 +33,9 @@ enum class CanvasPixelFormat {
kF16, kF16,
}; };
sk_sp<SkColorSpace> PLATFORM_EXPORT
CanvasColorSpaceToSkColorSpace(CanvasColorSpace color_space);
class PLATFORM_EXPORT CanvasColorParams { class PLATFORM_EXPORT CanvasColorParams {
DISALLOW_NEW(); DISALLOW_NEW();
...@@ -65,10 +64,7 @@ class PLATFORM_EXPORT CanvasColorParams { ...@@ -65,10 +64,7 @@ class PLATFORM_EXPORT CanvasColorParams {
// conversion to be used in the passed canvas color settings. // conversion to be used in the passed canvas color settings.
bool NeedsColorConversion(const CanvasColorParams&) const; bool NeedsColorConversion(const CanvasColorParams&) const;
// The SkColorSpace to use in the SkImageInfo for allocated SkSurfaces. This // The SkColorSpace to use in the SkImageInfo for SkImages and SkSurfaces.
// 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).
sk_sp<SkColorSpace> GetSkColorSpaceForSkSurfaces() const; sk_sp<SkColorSpace> GetSkColorSpaceForSkSurfaces() const;
// The pixel format to use for allocating SkSurfaces. // The pixel format to use for allocating SkSurfaces.
......
...@@ -75,7 +75,6 @@ bool CopyBytesFromImageBitmapForWebGPU( ...@@ -75,7 +75,6 @@ bool CopyBytesFromImageBitmapForWebGPU(
scoped_refptr<StaticBitmapImage> image, scoped_refptr<StaticBitmapImage> image,
base::span<uint8_t> dst, base::span<uint8_t> dst,
const IntRect& rect, const IntRect& rect,
const CanvasColorParams& color_params,
const WGPUTextureFormat destination_format) { const WGPUTextureFormat destination_format) {
DCHECK(image); DCHECK(image);
DCHECK_GT(dst.size(), static_cast<size_t>(0)); DCHECK_GT(dst.size(), static_cast<size_t>(0));
...@@ -91,6 +90,7 @@ bool CopyBytesFromImageBitmapForWebGPU( ...@@ -91,6 +90,7 @@ bool CopyBytesFromImageBitmapForWebGPU(
if (sk_color_type == kUnknown_SkColorType) { if (sk_color_type == kUnknown_SkColorType) {
return false; return false;
} }
PaintImage paint_image = image->PaintImageForCurrentFrame();
// Read pixel request dst info. // Read pixel request dst info.
// Keep premulalpha config and color space from imageBitmap and using dest // Keep premulalpha config and color space from imageBitmap and using dest
...@@ -98,9 +98,9 @@ bool CopyBytesFromImageBitmapForWebGPU( ...@@ -98,9 +98,9 @@ bool CopyBytesFromImageBitmapForWebGPU(
SkImageInfo info = SkImageInfo::Make( SkImageInfo info = SkImageInfo::Make(
rect.Width(), rect.Height(), sk_color_type, rect.Width(), rect.Height(), sk_color_type,
image->IsPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, 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()); info, dst.data(), wgpu_info.wgpu_bytes_per_row, rect.X(), rect.Y());
if (!read_pixels_successful) { if (!read_pixels_successful) {
......
...@@ -20,7 +20,6 @@ struct WebGPUImageUploadSizeInfo { ...@@ -20,7 +20,6 @@ struct WebGPUImageUploadSizeInfo {
uint32_t wgpu_bytes_per_row; uint32_t wgpu_bytes_per_row;
}; };
class CanvasColorParams;
class IntRect; class IntRect;
class StaticBitmapImage; class StaticBitmapImage;
...@@ -32,7 +31,6 @@ bool PLATFORM_EXPORT ...@@ -32,7 +31,6 @@ bool PLATFORM_EXPORT
CopyBytesFromImageBitmapForWebGPU(scoped_refptr<StaticBitmapImage> image, CopyBytesFromImageBitmapForWebGPU(scoped_refptr<StaticBitmapImage> image,
base::span<uint8_t> dst, base::span<uint8_t> dst,
const IntRect& rect, const IntRect& rect,
const CanvasColorParams& color_params,
const WGPUTextureFormat destination_format); const WGPUTextureFormat destination_format);
uint64_t PLATFORM_EXPORT uint64_t PLATFORM_EXPORT
......
...@@ -184,19 +184,6 @@ base::span<const uint8_t> GetSrcPixelContent(SkColorType format) { ...@@ -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 } // anonymous namespace
class WebGPUImageBitmapHandlerTest : public testing::Test { class WebGPUImageBitmapHandlerTest : public testing::Test {
...@@ -206,17 +193,16 @@ class WebGPUImageBitmapHandlerTest : public testing::Test { ...@@ -206,17 +193,16 @@ class WebGPUImageBitmapHandlerTest : public testing::Test {
void VerifyCopyBytesForCanvasColorParams(uint64_t width, void VerifyCopyBytesForCanvasColorParams(uint64_t width,
uint64_t height, uint64_t height,
SkImageInfo info, SkImageInfo info,
CanvasColorParams param,
IntRect copy_rect, IntRect copy_rect,
WGPUTextureFormat color_type) { 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); std::vector<uint8_t> contents(content_length, 0);
// Initialize contents. // Initialize contents.
for (size_t i = 0; i < content_length; ++i) { for (size_t i = 0; i < content_length; ++i) {
contents[i] = i % std::numeric_limits<uint8_t>::max(); 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),
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 { ...@@ -224,13 +210,12 @@ class WebGPUImageBitmapHandlerTest : public testing::Test {
void VerifyCopyBytes(uint64_t width, void VerifyCopyBytes(uint64_t width,
uint64_t height, uint64_t height,
SkImageInfo info, SkImageInfo info,
CanvasColorParams param,
IntRect copy_rect, IntRect copy_rect,
WGPUTextureFormat color_type, WGPUTextureFormat color_type,
base::span<const uint8_t> contents, base::span<const uint8_t> contents,
base::span<const uint8_t> expected_value) { base::span<const uint8_t> expected_value) {
uint64_t bytes_per_pixel = DawnTextureFormatBytesPerPixel(color_type); 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 = sk_sp<SkData> image_pixels =
SkData::MakeWithCopy(contents.data(), contents.size()); SkData::MakeWithCopy(contents.data(), contents.size());
scoped_refptr<StaticBitmapImage> image = scoped_refptr<StaticBitmapImage> image =
...@@ -243,7 +228,7 @@ class WebGPUImageBitmapHandlerTest : public testing::Test { ...@@ -243,7 +228,7 @@ class WebGPUImageBitmapHandlerTest : public testing::Test {
std::vector<uint8_t> results(result_length, 0); std::vector<uint8_t> results(result_length, 0);
bool success = CopyBytesFromImageBitmapForWebGPU( bool success = CopyBytesFromImageBitmapForWebGPU(
image, base::span<uint8_t>(results.data(), result_length), copy_rect, image, base::span<uint8_t>(results.data(), result_length), copy_rect,
param, color_type); color_type);
ASSERT_EQ(success, true); ASSERT_EQ(success, true);
// Compare content and results // Compare content and results
...@@ -293,16 +278,12 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyColorConvert) { ...@@ -293,16 +278,12 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyColorConvert) {
for (SkColorType src_color_type : srcSkColorFormat) { for (SkColorType src_color_type : srcSkColorFormat) {
for (WGPUTextureFormat dst_color_type : kDstWebGPUTextureFormat) { for (WGPUTextureFormat dst_color_type : kDstWebGPUTextureFormat) {
for (CanvasColorSpace color_space : kColorSpaces) { for (CanvasColorSpace color_space : kColorSpaces) {
CanvasColorParams color_param(
color_space, SkColorTypeToCanvasPixelFormat(src_color_type),
OpacityMode::kNonOpaque);
SkImageInfo info = SkImageInfo info =
SkImageInfo::Make(kImageWidth, kImageHeight, src_color_type, SkImageInfo::Make(kImageWidth, kImageHeight, src_color_type,
SkAlphaType::kUnpremul_SkAlphaType, SkAlphaType::kUnpremul_SkAlphaType,
color_param.GetSkColorSpaceForSkSurfaces()); CanvasColorSpaceToSkColorSpace(color_space));
VerifyCopyBytes(kImageWidth, kImageHeight, info, color_param, VerifyCopyBytes(kImageWidth, kImageHeight, info, image_data_rect,
image_data_rect, dst_color_type, dst_color_type, GetSrcPixelContent(src_color_type),
GetSrcPixelContent(src_color_type),
GetDstContent(dst_color_type)); GetDstContent(dst_color_type));
} }
} }
...@@ -313,8 +294,6 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyColorConvert) { ...@@ -313,8 +294,6 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyColorConvert) {
TEST_F(WebGPUImageBitmapHandlerTest, VerifyGetWGPUResourceInfo) { TEST_F(WebGPUImageBitmapHandlerTest, VerifyGetWGPUResourceInfo) {
uint64_t kImageWidth = 63; uint64_t kImageWidth = 63;
uint64_t kImageHeight = 1; uint64_t kImageHeight = 1;
CanvasColorParams param(CanvasColorSpace::kSRGB, CanvasPixelFormat::kRGBA8,
OpacityMode::kNonOpaque);
// Prebaked expected values. // Prebaked expected values.
uint32_t expected_bytes_per_row = 256; uint32_t expected_bytes_per_row = 256;
...@@ -336,11 +315,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesFromImageBitmapForWebGPU) { ...@@ -336,11 +315,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesFromImageBitmapForWebGPU) {
SkAlphaType::kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); SkAlphaType::kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());
IntRect image_data_rect(0, 0, kImageWidth, kImageHeight); IntRect image_data_rect(0, 0, kImageWidth, kImageHeight);
CanvasColorParams color_params(CanvasColorSpace::kSRGB,
CanvasPixelFormat::kRGBA8,
OpacityMode::kNonOpaque);
VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info, VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info,
color_params, image_data_rect, image_data_rect,
WGPUTextureFormat_RGBA8Unorm); WGPUTextureFormat_RGBA8Unorm);
} }
...@@ -353,11 +329,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesFromSubImageBitmap) { ...@@ -353,11 +329,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesFromSubImageBitmap) {
SkAlphaType::kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); SkAlphaType::kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());
IntRect image_data_rect(2, 2, 60, 2); IntRect image_data_rect(2, 2, 60, 2);
CanvasColorParams color_params(CanvasColorSpace::kSRGB,
CanvasPixelFormat::kRGBA8,
OpacityMode::kNonOpaque);
VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info, VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info,
color_params, image_data_rect, image_data_rect,
WGPUTextureFormat_RGBA8Unorm); WGPUTextureFormat_RGBA8Unorm);
} }
...@@ -370,11 +343,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesWithPremultiplyAlpha) { ...@@ -370,11 +343,8 @@ TEST_F(WebGPUImageBitmapHandlerTest, VerifyCopyBytesWithPremultiplyAlpha) {
SkAlphaType::kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); SkAlphaType::kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
IntRect image_data_rect(0, 0, 2, 1); IntRect image_data_rect(0, 0, 2, 1);
CanvasColorParams color_params(
CanvasColorSpace::kSRGB, CanvasPixelFormat::kRGBA8, OpacityMode::kOpaque);
VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info, VerifyCopyBytesForCanvasColorParams(kImageWidth, kImageHeight, info,
color_params, image_data_rect, image_data_rect,
WGPUTextureFormat_RGBA8Unorm); 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