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

Commit a8b3d1a

Browse files
authored
Added wide gamut colors to offscreen buffers (#39482)
* Added wide gamut support for offscreen buffers. * bdero
1 parent 9af56b3 commit a8b3d1a

File tree

7 files changed

+30
-5
lines changed

7 files changed

+30
-5
lines changed

impeller/renderer/backend/gles/texture_gles.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct TexImage2DData {
124124
case PixelFormat::kR8G8UNormInt:
125125
case PixelFormat::kB10G10R10XRSRGB:
126126
case PixelFormat::kB10G10R10XR:
127+
case PixelFormat::kB10G10R10A10XR:
127128
return;
128129
}
129130
is_valid_ = true;
@@ -171,6 +172,7 @@ struct TexImage2DData {
171172
case PixelFormat::kR8G8UNormInt:
172173
case PixelFormat::kB10G10R10XRSRGB:
173174
case PixelFormat::kB10G10R10XR:
175+
case PixelFormat::kB10G10R10A10XR:
174176
return;
175177
}
176178
is_valid_ = true;
@@ -318,6 +320,7 @@ static std::optional<GLenum> ToRenderBufferFormat(PixelFormat format) {
318320
case PixelFormat::kB8G8R8A8UNormIntSRGB:
319321
case PixelFormat::kB10G10R10XRSRGB:
320322
case PixelFormat::kB10G10R10XR:
323+
case PixelFormat::kB10G10R10A10XR:
321324
return std::nullopt;
322325
}
323326
FML_UNREACHABLE();

impeller/renderer/backend/metal/formats_mtl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ constexpr PixelFormat FromMTLPixelFormat(MTLPixelFormat format) {
4141
return PixelFormat::kB10G10R10XRSRGB;
4242
case MTLPixelFormatBGR10_XR:
4343
return PixelFormat::kB10G10R10XR;
44+
case MTLPixelFormatBGRA10_XR:
45+
return PixelFormat::kB10G10R10A10XR;
4446
default:
4547
return PixelFormat::kUnknown;
4648
}
@@ -56,6 +58,10 @@ MTLPixelFormat SafeMTLPixelFormatBGR10_XR_sRGB();
5658
/// Returns PixelFormat::kUnknown if MTLPixelFormatBGR10_XR isn't supported.
5759
MTLPixelFormat SafeMTLPixelFormatBGR10_XR();
5860

61+
/// Safe accessor for MTLPixelFormatBGRA10_XR.
62+
/// Returns PixelFormat::kUnknown if MTLPixelFormatBGR10_XR isn't supported.
63+
MTLPixelFormat SafeMTLPixelFormatBGRA10_XR();
64+
5965
constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
6066
switch (format) {
6167
case PixelFormat::kUnknown:
@@ -86,6 +92,8 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
8692
return SafeMTLPixelFormatBGR10_XR_sRGB();
8793
case PixelFormat::kB10G10R10XR:
8894
return SafeMTLPixelFormatBGR10_XR();
95+
case PixelFormat::kB10G10R10A10XR:
96+
return SafeMTLPixelFormatBGRA10_XR();
8997
}
9098
return MTLPixelFormatInvalid;
9199
};

impeller/renderer/backend/metal/formats_mtl.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,12 @@ MTLPixelFormat SafeMTLPixelFormatBGR10_XR() {
120120
}
121121
}
122122

123+
MTLPixelFormat SafeMTLPixelFormatBGRA10_XR() {
124+
if (@available(iOS 10, macOS 11.0, *)) {
125+
return MTLPixelFormatBGRA10_XR;
126+
} else {
127+
return MTLPixelFormatInvalid;
128+
}
129+
}
130+
123131
} // namespace impeller

impeller/renderer/backend/vulkan/formats_vk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ constexpr vk::Format ToVKImageFormat(PixelFormat format) {
138138
switch (format) {
139139
case PixelFormat::kUnknown:
140140
case PixelFormat::kB10G10R10XR:
141+
case PixelFormat::kB10G10R10A10XR:
141142
case PixelFormat::kB10G10R10XRSRGB:
142143
return vk::Format::eUndefined;
143144
case PixelFormat::kA8UNormInt:

impeller/renderer/formats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ enum class PixelFormat {
9191
kR16G16B16A16Float,
9292
kB10G10R10XR,
9393
kB10G10R10XRSRGB,
94+
kB10G10R10A10XR,
9495
// Depth and stencil formats.
9596
kS8UInt,
9697
kD32FloatS8UInt,
@@ -296,6 +297,7 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
296297
case PixelFormat::kD32FloatS8UInt:
297298
return 5u;
298299
case PixelFormat::kR16G16B16A16Float:
300+
case PixelFormat::kB10G10R10A10XR:
299301
return 8u;
300302
case PixelFormat::kR32G32B32A32Float:
301303
return 16u;

impeller/renderer/render_target.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ RenderTarget RenderTarget::CreateOffscreen(
202202
}
203203

204204
RenderTarget target;
205-
205+
PixelFormat pixel_format = context.GetColorAttachmentPixelFormat();
206206
TextureDescriptor color_tex0;
207207
color_tex0.storage_mode = color_attachment_config.storage_mode;
208-
color_tex0.format = context.GetColorAttachmentPixelFormat();
208+
color_tex0.format = pixel_format;
209209
color_tex0.size = size;
210210
color_tex0.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget) |
211211
static_cast<uint64_t>(TextureUsage::kShaderRead);
@@ -260,14 +260,15 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
260260
}
261261

262262
RenderTarget target;
263+
PixelFormat pixel_format = context.GetColorAttachmentPixelFormat();
263264

264265
// Create MSAA color texture.
265266

266267
TextureDescriptor color0_tex_desc;
267268
color0_tex_desc.storage_mode = color_attachment_config.storage_mode;
268269
color0_tex_desc.type = TextureType::kTexture2DMultisample;
269270
color0_tex_desc.sample_count = SampleCount::kCount4;
270-
color0_tex_desc.format = context.GetColorAttachmentPixelFormat();
271+
color0_tex_desc.format = pixel_format;
271272
color0_tex_desc.size = size;
272273
color0_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
273274

@@ -285,7 +286,7 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
285286
TextureDescriptor color0_resolve_tex_desc;
286287
color0_resolve_tex_desc.storage_mode =
287288
color_attachment_config.resolve_storage_mode;
288-
color0_resolve_tex_desc.format = context.GetColorAttachmentPixelFormat();
289+
color0_resolve_tex_desc.format = pixel_format;
289290
color0_resolve_tex_desc.size = size;
290291
color0_resolve_tex_desc.usage =
291292
static_cast<uint64_t>(TextureUsage::kRenderTarget) |

shell/platform/darwin/ios/framework/Source/FlutterView.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ - (void)layoutSubviews {
8787
layer.colorspace = srgb;
8888
CFRelease(srgb);
8989
if (self.opaque) {
90-
layer.pixelFormat = MTLPixelFormatBGR10_XR;
90+
// TODO(https://github.com/flutter/flutter/issues/120641): Switch to
91+
// MTLPixelFormatBGR10_XR to save memory.
92+
layer.pixelFormat = MTLPixelFormatBGRA10_XR;
9193
} else {
9294
layer.pixelFormat = MTLPixelFormatBGRA10_XR;
9395
}

0 commit comments

Comments
 (0)