Commit 667b1023 authored by Christopher Cameron's avatar Christopher Cameron Committed by Chromium LUCI CQ

CanvasResourceParams: Use Skia types directly

Change CanvasResourceParams to use
- SkColorType instead of CanvasPixelFormat
- SkAlphaType instead of OpacityMode
This will allow us to cull CanvasPixelFormat down to just the types
that users can specify.

Bug: 1157747
Change-Id: I70b23024d6fda00d031e013610347eebae896d92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2589354
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarYi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837471}
parent fbc09554
...@@ -263,9 +263,8 @@ std::unique_ptr<CanvasResourceProvider> CreateProviderForVideoElement( ...@@ -263,9 +263,8 @@ std::unique_ptr<CanvasResourceProvider> CreateProviderForVideoElement(
return CanvasResourceProvider::CreateSharedImageProvider( return CanvasResourceProvider::CreateSharedImageProvider(
IntSize(video->videoWidth(), video->videoHeight()), kLow_SkFilterQuality, IntSize(video->videoWidth(), video->videoHeight()), kLow_SkFilterQuality,
CanvasResourceParams(CanvasColorSpace::kSRGB, CanvasResourceParams(CanvasColorSpace::kSRGB, kN32_SkColorType,
CanvasColorParams::GetNativeCanvasPixelFormat(), kPremul_SkAlphaType), // Default canvas settings,
kNonOpaque), // Default canvas settings,
CanvasResourceProvider::ShouldInitialize::kCallClear, CanvasResourceProvider::ShouldInitialize::kCallClear,
SharedGpuContext::ContextProviderWrapper(), RasterMode::kGPU, SharedGpuContext::ContextProviderWrapper(), RasterMode::kGPU,
false, // Origin of GL texture is bottom left on screen false, // Origin of GL texture is bottom left on screen
......
...@@ -86,7 +86,7 @@ CanvasColorParams::CanvasColorParams(const SkImageInfo& info) ...@@ -86,7 +86,7 @@ CanvasColorParams::CanvasColorParams(const SkImageInfo& info)
: CanvasColorParams(info.refColorSpace(), info.colorType()) {} : CanvasColorParams(info.refColorSpace(), info.colorType()) {}
CanvasResourceParams CanvasColorParams::GetAsResourceParams() const { CanvasResourceParams CanvasColorParams::GetAsResourceParams() const {
return CanvasResourceParams(color_space_, pixel_format_, opacity_mode_); return CanvasResourceParams(color_space_, GetSkColorType(), GetSkAlphaType());
} }
SkColorType CanvasColorParams::GetSkColorType() const { SkColorType CanvasColorParams::GetSkColorType() const {
......
...@@ -41,43 +41,26 @@ gfx::ColorSpace CanvasColorSpaceToGfxColorSpace(CanvasColorSpace color_space) { ...@@ -41,43 +41,26 @@ gfx::ColorSpace CanvasColorSpaceToGfxColorSpace(CanvasColorSpace color_space) {
CanvasResourceParams::CanvasResourceParams() = default; CanvasResourceParams::CanvasResourceParams() = default;
CanvasResourceParams::CanvasResourceParams(CanvasColorSpace color_space, CanvasResourceParams::CanvasResourceParams(CanvasColorSpace color_space,
CanvasPixelFormat pixel_format, SkColorType color_type,
OpacityMode opacity_mode) SkAlphaType alpha_type)
: color_space_(color_space), : color_space_(color_space),
pixel_format_(pixel_format), color_type_(color_type),
opacity_mode_(opacity_mode) {} alpha_type_(alpha_type) {}
CanvasResourceParams::CanvasResourceParams(const SkImageInfo& info) CanvasResourceParams::CanvasResourceParams(const SkImageInfo& info)
: CanvasResourceParams(info.refColorSpace(), info.colorType()) {} : CanvasResourceParams(info.refColorSpace(), info.colorType()) {
// TODO(https://crbug.com/1157747): This ignores |info|'s SkAlphaType.
SkColorType CanvasResourceParams::GetSkColorType() const {
switch (pixel_format_) {
case CanvasPixelFormat::kF16:
return kRGBA_F16_SkColorType;
case CanvasPixelFormat::kRGBA8:
return kRGBA_8888_SkColorType;
case CanvasPixelFormat::kBGRA8:
return kBGRA_8888_SkColorType;
case CanvasPixelFormat::kRGBX8:
return kRGB_888x_SkColorType;
}
NOTREACHED();
return kN32_SkColorType;
}
SkAlphaType CanvasResourceParams::GetSkAlphaType() const {
return opacity_mode_ == kOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
} }
const SkSurfaceProps* CanvasResourceParams::GetSkSurfaceProps() const { const SkSurfaceProps* CanvasResourceParams::GetSkSurfaceProps() const {
static const SkSurfaceProps disable_lcd_props(0, kUnknown_SkPixelGeometry); static const SkSurfaceProps disable_lcd_props(0, kUnknown_SkPixelGeometry);
if (opacity_mode_ == kOpaque) if (alpha_type_ == kOpaque_SkAlphaType)
return nullptr; return nullptr;
return &disable_lcd_props; return &disable_lcd_props;
} }
uint8_t CanvasResourceParams::BytesPerPixel() const { uint8_t CanvasResourceParams::BytesPerPixel() const {
return SkColorTypeBytesPerPixel(GetSkColorType()); return SkColorTypeBytesPerPixel(color_type_);
} }
gfx::ColorSpace CanvasResourceParams::GetSamplerGfxColorSpace() const { gfx::ColorSpace CanvasResourceParams::GetSamplerGfxColorSpace() const {
...@@ -99,7 +82,7 @@ sk_sp<SkColorSpace> CanvasResourceParams::GetSkColorSpace() const { ...@@ -99,7 +82,7 @@ sk_sp<SkColorSpace> CanvasResourceParams::GetSkColorSpace() const {
} }
gfx::BufferFormat CanvasResourceParams::GetBufferFormat() const { gfx::BufferFormat CanvasResourceParams::GetBufferFormat() const {
switch (GetSkColorType()) { switch (color_type_) {
case kRGBA_F16_SkColorType: case kRGBA_F16_SkColorType:
return gfx::BufferFormat::RGBA_F16; return gfx::BufferFormat::RGBA_F16;
case kRGBA_8888_SkColorType: case kRGBA_8888_SkColorType:
...@@ -116,8 +99,8 @@ gfx::BufferFormat CanvasResourceParams::GetBufferFormat() const { ...@@ -116,8 +99,8 @@ gfx::BufferFormat CanvasResourceParams::GetBufferFormat() const {
} }
GLenum CanvasResourceParams::GLUnsizedInternalFormat() const { GLenum CanvasResourceParams::GLUnsizedInternalFormat() const {
// TODO(junov): try GL_RGB when opacity_mode_ == kOpaque // TODO(junov): try GL_RGB when alpha_type_ == kOpaque
switch (GetSkColorType()) { switch (color_type_) {
case kRGBA_F16_SkColorType: case kRGBA_F16_SkColorType:
return GL_RGBA; return GL_RGBA;
case kRGBA_8888_SkColorType: case kRGBA_8888_SkColorType:
...@@ -134,7 +117,7 @@ GLenum CanvasResourceParams::GLUnsizedInternalFormat() const { ...@@ -134,7 +117,7 @@ GLenum CanvasResourceParams::GLUnsizedInternalFormat() const {
} }
GLenum CanvasResourceParams::GLSizedInternalFormat() const { GLenum CanvasResourceParams::GLSizedInternalFormat() const {
switch (GetSkColorType()) { switch (color_type_) {
case kRGBA_F16_SkColorType: case kRGBA_F16_SkColorType:
return GL_RGBA16F; return GL_RGBA16F;
case kRGBA_8888_SkColorType: case kRGBA_8888_SkColorType:
...@@ -151,7 +134,7 @@ GLenum CanvasResourceParams::GLSizedInternalFormat() const { ...@@ -151,7 +134,7 @@ GLenum CanvasResourceParams::GLSizedInternalFormat() const {
} }
GLenum CanvasResourceParams::GLType() const { GLenum CanvasResourceParams::GLType() const {
switch (GetSkColorType()) { switch (color_type_) {
case kRGBA_F16_SkColorType: case kRGBA_F16_SkColorType:
return GL_HALF_FLOAT_OES; return GL_HALF_FLOAT_OES;
case kRGBA_8888_SkColorType: case kRGBA_8888_SkColorType:
...@@ -173,14 +156,12 @@ CanvasResourceParams::CanvasResourceParams( ...@@ -173,14 +156,12 @@ CanvasResourceParams::CanvasResourceParams(
const sk_sp<SkColorSpace> sk_color_space, const sk_sp<SkColorSpace> sk_color_space,
SkColorType sk_color_type) { SkColorType sk_color_type) {
color_space_ = CanvasColorSpaceFromSkColorSpace(sk_color_space.get()); color_space_ = CanvasColorSpaceFromSkColorSpace(sk_color_space.get());
pixel_format_ = GetNativeCanvasPixelFormat(); color_type_ = kN32_SkColorType;
if (sk_color_type == kRGBA_F16_SkColorType ||
if (sk_color_type == kRGBA_F16_SkColorType) sk_color_type == kRGBA_8888_SkColorType ||
pixel_format_ = CanvasPixelFormat::kF16; sk_color_type == kRGB_888x_SkColorType) {
else if (sk_color_type == kRGBA_8888_SkColorType) color_type_ = sk_color_type;
pixel_format_ = CanvasPixelFormat::kRGBA8; }
else if (sk_color_type == kRGB_888x_SkColorType)
pixel_format_ = CanvasPixelFormat::kRGBX8;
} }
} // namespace blink } // namespace blink
...@@ -31,26 +31,16 @@ class PLATFORM_EXPORT CanvasResourceParams { ...@@ -31,26 +31,16 @@ class PLATFORM_EXPORT CanvasResourceParams {
public: public:
// The default constructor will create an output-blended 8-bit surface. // The default constructor will create an output-blended 8-bit surface.
CanvasResourceParams(); CanvasResourceParams();
CanvasResourceParams(CanvasColorSpace, CanvasPixelFormat, OpacityMode); CanvasResourceParams(CanvasColorSpace, SkColorType, SkAlphaType);
explicit CanvasResourceParams(const SkImageInfo&); explicit CanvasResourceParams(const SkImageInfo&);
static CanvasPixelFormat GetNativeCanvasPixelFormat() {
if (kN32_SkColorType == kRGBA_8888_SkColorType)
return CanvasPixelFormat::kRGBA8;
else if (kN32_SkColorType == kBGRA_8888_SkColorType)
return CanvasPixelFormat::kBGRA8;
}
CanvasColorSpace ColorSpace() const { return color_space_; } CanvasColorSpace ColorSpace() const { return color_space_; }
CanvasPixelFormat PixelFormat() const { return pixel_format_; }
OpacityMode GetOpacityMode() const { return opacity_mode_; }
void SetCanvasColorSpace(CanvasColorSpace c) { color_space_ = c; } void SetCanvasColorSpace(CanvasColorSpace c) { color_space_ = c; }
void SetCanvasPixelFormat(CanvasPixelFormat f) { pixel_format_ = f; } void SetSkColorType(SkColorType color_type) { color_type_ = color_type; }
void SetOpacityMode(OpacityMode m) { opacity_mode_ = m; }
// The pixel format to use for allocating SkSurfaces. // The pixel format to use for allocating SkSurfaces.
SkColorType GetSkColorType() const; SkColorType GetSkColorType() const { return color_type_; }
uint8_t BytesPerPixel() const; uint8_t BytesPerPixel() const;
// The color space in which pixels read from the canvas via a shader will be // The color space in which pixels read from the canvas via a shader will be
...@@ -61,7 +51,7 @@ class PLATFORM_EXPORT CanvasResourceParams { ...@@ -61,7 +51,7 @@ class PLATFORM_EXPORT CanvasResourceParams {
// Return the color space of the underlying data for the canvas. // Return the color space of the underlying data for the canvas.
gfx::ColorSpace GetStorageGfxColorSpace() const; gfx::ColorSpace GetStorageGfxColorSpace() const;
sk_sp<SkColorSpace> GetSkColorSpace() const; sk_sp<SkColorSpace> GetSkColorSpace() const;
SkAlphaType GetSkAlphaType() const; SkAlphaType GetSkAlphaType() const { return alpha_type_; }
const SkSurfaceProps* GetSkSurfaceProps() const; const SkSurfaceProps* GetSkSurfaceProps() const;
// Gpu memory buffer parameters // Gpu memory buffer parameters
...@@ -77,8 +67,8 @@ class PLATFORM_EXPORT CanvasResourceParams { ...@@ -77,8 +67,8 @@ class PLATFORM_EXPORT CanvasResourceParams {
SkColorType color_type); SkColorType color_type);
CanvasColorSpace color_space_ = CanvasColorSpace::kSRGB; CanvasColorSpace color_space_ = CanvasColorSpace::kSRGB;
CanvasPixelFormat pixel_format_ = GetNativeCanvasPixelFormat(); SkColorType color_type_ = kN32_SkColorType;
OpacityMode opacity_mode_ = kNonOpaque; SkAlphaType alpha_type_ = kPremul_SkAlphaType;
}; };
} // namespace blink } // namespace blink
......
...@@ -173,8 +173,7 @@ class CanvasResourceProviderSharedBitmap : public CanvasResourceProviderBitmap { ...@@ -173,8 +173,7 @@ class CanvasResourceProviderSharedBitmap : public CanvasResourceProviderBitmap {
if (!IsBitmapFormatSupported(params.TransferableResourceFormat())) { if (!IsBitmapFormatSupported(params.TransferableResourceFormat())) {
// If the rendering format is not supported, downgrate to 8-bits. // If the rendering format is not supported, downgrate to 8-bits.
// TODO(junov): Should we try 12-12-12-12 and 10-10-10-2? // TODO(junov): Should we try 12-12-12-12 and 10-10-10-2?
params.SetCanvasPixelFormat( params.SetSkColorType(kN32_SkColorType);
CanvasResourceParams::GetNativeCanvasPixelFormat());
} }
return CanvasResourceSharedBitmap::Create(Size(), params, CreateWeakPtr(), return CanvasResourceSharedBitmap::Create(Size(), params, CreateWeakPtr(),
...@@ -218,12 +217,14 @@ class CanvasResourceProviderSharedImage : public CanvasResourceProvider { ...@@ -218,12 +217,14 @@ class CanvasResourceProviderSharedImage : public CanvasResourceProvider {
filter_quality, filter_quality,
// TODO(khushalsagar): The software path seems to be assuming N32 // TODO(khushalsagar): The software path seems to be assuming N32
// somewhere in the later pipeline but for offscreen canvas only. // somewhere in the later pipeline but for offscreen canvas only.
// TODO(https://crbug.com/1157747): This is RGBA, but the above
// comment suggests N32. See if this can be N32.
CanvasResourceParams(params.ColorSpace(), CanvasResourceParams(params.ColorSpace(),
is_accelerated && params.PixelFormat() != is_accelerated && params.GetSkColorType() !=
CanvasPixelFormat::kF16 kRGBA_F16_SkColorType
? CanvasPixelFormat::kRGBA8 ? kRGBA_8888_SkColorType
: params.PixelFormat(), : params.GetSkColorType(),
params.GetOpacityMode()), params.GetSkAlphaType()),
is_origin_top_left, is_origin_top_left,
std::move(context_provider_wrapper), std::move(context_provider_wrapper),
nullptr /* resource_dispatcher */), nullptr /* resource_dispatcher */),
...@@ -493,9 +494,10 @@ class CanvasResourceProviderSharedImage : public CanvasResourceProvider { ...@@ -493,9 +494,10 @@ class CanvasResourceProviderSharedImage : public CanvasResourceProvider {
} }
WillDrawInternal(true); WillDrawInternal(true);
gpu::raster::RasterInterface* ri = RasterInterface(); gpu::raster::RasterInterface* ri = RasterInterface();
SkColor background_color = ColorParams().GetOpacityMode() == kOpaque SkColor background_color =
? SK_ColorBLACK ColorParams().GetSkAlphaType() == kOpaque_SkAlphaType
: SK_ColorTRANSPARENT; ? SK_ColorBLACK
: SK_ColorTRANSPARENT;
auto list = base::MakeRefCounted<cc::DisplayItemList>( auto list = base::MakeRefCounted<cc::DisplayItemList>(
cc::DisplayItemList::kTopLevelDisplayItemList); cc::DisplayItemList::kTopLevelDisplayItemList);
...@@ -1281,7 +1283,7 @@ void CanvasResourceProvider::Clear() { ...@@ -1281,7 +1283,7 @@ void CanvasResourceProvider::Clear() {
// send them directly through to Skia so that they're not replayed for // send them directly through to Skia so that they're not replayed for
// printing operations. See crbug.com/1003114 // printing operations. See crbug.com/1003114
DCHECK(IsValid()); DCHECK(IsValid());
if (params_.GetOpacityMode() == kOpaque) if (params_.GetSkAlphaType() == kOpaque_SkAlphaType)
Canvas()->clear(SK_ColorBLACK); Canvas()->clear(SK_ColorBLACK);
else else
Canvas()->clear(SK_ColorTRANSPARENT); Canvas()->clear(SK_ColorTRANSPARENT);
......
...@@ -684,10 +684,10 @@ scoped_refptr<CanvasResource> DrawingBuffer::ExportLowLatencyCanvasResource( ...@@ -684,10 +684,10 @@ scoped_refptr<CanvasResource> DrawingBuffer::ExportLowLatencyCanvasResource(
switch (canvas_resource_buffer->format) { switch (canvas_resource_buffer->format) {
case viz::RGBA_8888: case viz::RGBA_8888:
case viz::RGBX_8888: case viz::RGBX_8888:
resource_params.SetCanvasPixelFormat(CanvasPixelFormat::kRGBA8); resource_params.SetSkColorType(kRGBA_8888_SkColorType);
break; break;
case viz::RGBA_F16: case viz::RGBA_F16:
resource_params.SetCanvasPixelFormat(CanvasPixelFormat::kF16); resource_params.SetSkColorType(kRGBA_F16_SkColorType);
break; break;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -719,13 +719,13 @@ scoped_refptr<CanvasResource> DrawingBuffer::ExportCanvasResource() { ...@@ -719,13 +719,13 @@ scoped_refptr<CanvasResource> DrawingBuffer::ExportCanvasResource() {
CanvasResourceParams resource_params; CanvasResourceParams resource_params;
switch (out_resource.format) { switch (out_resource.format) {
case viz::RGBA_8888: case viz::RGBA_8888:
resource_params.SetCanvasPixelFormat(CanvasPixelFormat::kRGBA8); resource_params.SetSkColorType(kRGBA_8888_SkColorType);
break; break;
case viz::RGBX_8888: case viz::RGBX_8888:
resource_params.SetCanvasPixelFormat(CanvasPixelFormat::kRGBX8); resource_params.SetSkColorType(kRGB_888x_SkColorType);
break; break;
case viz::RGBA_F16: case viz::RGBA_F16:
resource_params.SetCanvasPixelFormat(CanvasPixelFormat::kF16); resource_params.SetSkColorType(kRGBA_F16_SkColorType);
break; break;
default: default:
NOTREACHED(); NOTREACHED();
......
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