Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Added wide gamut colors to offscreen buffers #39482

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions impeller/renderer/backend/gles/texture_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct TexImage2DData {
case PixelFormat::kR8G8UNormInt:
case PixelFormat::kB10G10R10XRSRGB:
case PixelFormat::kB10G10R10XR:
case PixelFormat::kB10G10R10A10XR:
return;
}
is_valid_ = true;
Expand Down Expand Up @@ -171,6 +172,7 @@ struct TexImage2DData {
case PixelFormat::kR8G8UNormInt:
case PixelFormat::kB10G10R10XRSRGB:
case PixelFormat::kB10G10R10XR:
case PixelFormat::kB10G10R10A10XR:
return;
}
is_valid_ = true;
Expand Down Expand Up @@ -318,6 +320,7 @@ static std::optional<GLenum> ToRenderBufferFormat(PixelFormat format) {
case PixelFormat::kB8G8R8A8UNormIntSRGB:
case PixelFormat::kB10G10R10XRSRGB:
case PixelFormat::kB10G10R10XR:
case PixelFormat::kB10G10R10A10XR:
return std::nullopt;
}
FML_UNREACHABLE();
Expand Down
8 changes: 8 additions & 0 deletions impeller/renderer/backend/metal/formats_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ constexpr PixelFormat FromMTLPixelFormat(MTLPixelFormat format) {
return PixelFormat::kB10G10R10XRSRGB;
case MTLPixelFormatBGR10_XR:
return PixelFormat::kB10G10R10XR;
case MTLPixelFormatBGRA10_XR:
return PixelFormat::kB10G10R10A10XR;
default:
return PixelFormat::kUnknown;
}
Expand All @@ -56,6 +58,10 @@ MTLPixelFormat SafeMTLPixelFormatBGR10_XR_sRGB();
/// Returns PixelFormat::kUnknown if MTLPixelFormatBGR10_XR isn't supported.
MTLPixelFormat SafeMTLPixelFormatBGR10_XR();

/// Safe accessor for MTLPixelFormatBGRA10_XR.
/// Returns PixelFormat::kUnknown if MTLPixelFormatBGR10_XR isn't supported.
MTLPixelFormat SafeMTLPixelFormatBGRA10_XR();

constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
switch (format) {
case PixelFormat::kUnknown:
Expand Down Expand Up @@ -86,6 +92,8 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
return SafeMTLPixelFormatBGR10_XR_sRGB();
case PixelFormat::kB10G10R10XR:
return SafeMTLPixelFormatBGR10_XR();
case PixelFormat::kB10G10R10A10XR:
return SafeMTLPixelFormatBGRA10_XR();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add reverse conversion to ToMTLBlendFactor below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reverse for this is in FromMTLPixelFormat. I think that's what you were thinking, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yup, disregard

}
return MTLPixelFormatInvalid;
};
Expand Down
8 changes: 8 additions & 0 deletions impeller/renderer/backend/metal/formats_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ MTLPixelFormat SafeMTLPixelFormatBGR10_XR() {
}
}

MTLPixelFormat SafeMTLPixelFormatBGRA10_XR() {
if (@available(iOS 10, macOS 11.0, *)) {
return MTLPixelFormatBGRA10_XR;
} else {
return MTLPixelFormatInvalid;
}
}

} // namespace impeller
1 change: 1 addition & 0 deletions impeller/renderer/backend/vulkan/formats_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ constexpr vk::Format ToVKImageFormat(PixelFormat format) {
switch (format) {
case PixelFormat::kUnknown:
case PixelFormat::kB10G10R10XR:
case PixelFormat::kB10G10R10A10XR:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add reverse conversion to ToPixelFormat below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reverse for this yet since it's mapped to vk::Format::eUndefined. I don't think this format will ever be used with vulkan as far as I know.

case PixelFormat::kB10G10R10XRSRGB:
return vk::Format::eUndefined;
case PixelFormat::kA8UNormInt:
Expand Down
2 changes: 2 additions & 0 deletions impeller/renderer/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ enum class PixelFormat {
kR16G16B16A16Float,
kB10G10R10XR,
kB10G10R10XRSRGB,
kB10G10R10A10XR,
// Depth and stencil formats.
kS8UInt,
kD32FloatS8UInt,
Expand Down Expand Up @@ -296,6 +297,7 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
case PixelFormat::kD32FloatS8UInt:
return 5u;
case PixelFormat::kR16G16B16A16Float:
case PixelFormat::kB10G10R10A10XR:
return 8u;
case PixelFormat::kR32G32B32A32Float:
return 16u;
Expand Down
9 changes: 5 additions & 4 deletions impeller/renderer/render_target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ RenderTarget RenderTarget::CreateOffscreen(
}

RenderTarget target;

PixelFormat pixel_format = context.GetColorAttachmentPixelFormat();
TextureDescriptor color_tex0;
color_tex0.storage_mode = color_attachment_config.storage_mode;
color_tex0.format = context.GetColorAttachmentPixelFormat();
color_tex0.format = pixel_format;
color_tex0.size = size;
color_tex0.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget) |
static_cast<uint64_t>(TextureUsage::kShaderRead);
Expand Down Expand Up @@ -260,14 +260,15 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
}

RenderTarget target;
PixelFormat pixel_format = context.GetColorAttachmentPixelFormat();

// Create MSAA color texture.

TextureDescriptor color0_tex_desc;
color0_tex_desc.storage_mode = color_attachment_config.storage_mode;
color0_tex_desc.type = TextureType::kTexture2DMultisample;
color0_tex_desc.sample_count = SampleCount::kCount4;
color0_tex_desc.format = context.GetColorAttachmentPixelFormat();
color0_tex_desc.format = pixel_format;
color0_tex_desc.size = size;
color0_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);

Expand All @@ -285,7 +286,7 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
TextureDescriptor color0_resolve_tex_desc;
color0_resolve_tex_desc.storage_mode =
color_attachment_config.resolve_storage_mode;
color0_resolve_tex_desc.format = context.GetColorAttachmentPixelFormat();
color0_resolve_tex_desc.format = pixel_format;
color0_resolve_tex_desc.size = size;
color0_resolve_tex_desc.usage =
static_cast<uint64_t>(TextureUsage::kRenderTarget) |
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/darwin/ios/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ - (void)layoutSubviews {
layer.colorspace = srgb;
CFRelease(srgb);
if (self.opaque) {
layer.pixelFormat = MTLPixelFormatBGR10_XR;
// TODO(https://github.com/flutter/flutter/issues/120641): Switch to
// MTLPixelFormatBGR10_XR to save memory.
layer.pixelFormat = MTLPixelFormatBGRA10_XR;
} else {
layer.pixelFormat = MTLPixelFormatBGRA10_XR;
}
Expand Down