forked from firka/flutter
Added wide gamut colors to offscreen buffers (flutter/engine#39482)
* Added wide gamut support for offscreen buffers. * bdero
This commit is contained in:
@@ -124,6 +124,7 @@ struct TexImage2DData {
|
||||
case PixelFormat::kR8G8UNormInt:
|
||||
case PixelFormat::kB10G10R10XRSRGB:
|
||||
case PixelFormat::kB10G10R10XR:
|
||||
case PixelFormat::kB10G10R10A10XR:
|
||||
return;
|
||||
}
|
||||
is_valid_ = true;
|
||||
@@ -171,6 +172,7 @@ struct TexImage2DData {
|
||||
case PixelFormat::kR8G8UNormInt:
|
||||
case PixelFormat::kB10G10R10XRSRGB:
|
||||
case PixelFormat::kB10G10R10XR:
|
||||
case PixelFormat::kB10G10R10A10XR:
|
||||
return;
|
||||
}
|
||||
is_valid_ = true;
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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:
|
||||
@@ -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();
|
||||
}
|
||||
return MTLPixelFormatInvalid;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -138,6 +138,7 @@ constexpr vk::Format ToVKImageFormat(PixelFormat format) {
|
||||
switch (format) {
|
||||
case PixelFormat::kUnknown:
|
||||
case PixelFormat::kB10G10R10XR:
|
||||
case PixelFormat::kB10G10R10A10XR:
|
||||
case PixelFormat::kB10G10R10XRSRGB:
|
||||
return vk::Format::eUndefined;
|
||||
case PixelFormat::kA8UNormInt:
|
||||
|
||||
@@ -91,6 +91,7 @@ enum class PixelFormat {
|
||||
kR16G16B16A16Float,
|
||||
kB10G10R10XR,
|
||||
kB10G10R10XRSRGB,
|
||||
kB10G10R10A10XR,
|
||||
// Depth and stencil formats.
|
||||
kS8UInt,
|
||||
kD32FloatS8UInt,
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -260,6 +260,7 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
|
||||
}
|
||||
|
||||
RenderTarget target;
|
||||
PixelFormat pixel_format = context.GetColorAttachmentPixelFormat();
|
||||
|
||||
// Create MSAA color texture.
|
||||
|
||||
@@ -267,7 +268,7 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
|
||||
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);
|
||||
|
||||
@@ -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) |
|
||||
|
||||
@@ -87,7 +87,9 @@ static BOOL IsWideGamutSupported() {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user