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