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

Commit fd23012

Browse files
committed
Added wide gamut support for offscreen buffers.
1 parent 4c4a539 commit fd23012

File tree

7 files changed

+43
-4
lines changed

7 files changed

+43
-4
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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212

1313
namespace impeller {
1414

15+
namespace {
16+
PixelFormat OffscreenFormatForSurfaceFormat(PixelFormat pixel_format) {
17+
if (pixel_format == PixelFormat::kB10G10R10XR) {
18+
return PixelFormat::kB10G10R10A10XR;
19+
} else {
20+
return pixel_format;
21+
}
22+
}
23+
} // namespace
24+
1525
RenderTarget::RenderTarget() = default;
1626

1727
RenderTarget::~RenderTarget() = default;
@@ -196,9 +206,12 @@ RenderTarget RenderTarget::CreateOffscreen(const Context& context,
196206
return {};
197207
}
198208

209+
PixelFormat pixel_format =
210+
OffscreenFormatForSurfaceFormat(context.GetColorAttachmentPixelFormat());
211+
199212
TextureDescriptor color_tex0;
200213
color_tex0.storage_mode = color_storage_mode;
201-
color_tex0.format = context.GetColorAttachmentPixelFormat();
214+
color_tex0.format = pixel_format;
202215
color_tex0.size = size;
203216
color_tex0.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget) |
204217
static_cast<uint64_t>(TextureUsage::kShaderRead);
@@ -257,13 +270,16 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
257270
return {};
258271
}
259272

273+
PixelFormat pixel_format =
274+
OffscreenFormatForSurfaceFormat(context.GetColorAttachmentPixelFormat());
275+
260276
// Create MSAA color texture.
261277

262278
TextureDescriptor color0_tex_desc;
263279
color0_tex_desc.storage_mode = color_storage_mode;
264280
color0_tex_desc.type = TextureType::kTexture2DMultisample;
265281
color0_tex_desc.sample_count = SampleCount::kCount4;
266-
color0_tex_desc.format = context.GetColorAttachmentPixelFormat();
282+
color0_tex_desc.format = pixel_format;
267283
color0_tex_desc.size = size;
268284
color0_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
269285

@@ -280,7 +296,7 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
280296

281297
TextureDescriptor color0_resolve_tex_desc;
282298
color0_resolve_tex_desc.storage_mode = color_resolve_storage_mode;
283-
color0_resolve_tex_desc.format = context.GetColorAttachmentPixelFormat();
299+
color0_resolve_tex_desc.format = pixel_format;
284300
color0_resolve_tex_desc.size = size;
285301
color0_resolve_tex_desc.usage =
286302
static_cast<uint64_t>(TextureUsage::kRenderTarget) |

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ - (void)layoutSubviews {
8181
layer.colorspace = srgb;
8282
CFRelease(srgb);
8383
if (self.opaque) {
84-
layer.pixelFormat = MTLPixelFormatBGR10_XR;
84+
/// TODO(gaaclarke): Switch to MTLPixelFormatBGR10_XR to save memory.
85+
layer.pixelFormat = MTLPixelFormatBGRA10_XR;
8586
} else {
8687
layer.pixelFormat = MTLPixelFormatBGRA10_XR;
8788
}

0 commit comments

Comments
 (0)