mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add support for more pixel formats.
This commit is contained in:
parent
0f6b0b86d8
commit
6684140013
@ -15,6 +15,8 @@ namespace impeller {
|
||||
|
||||
enum class PixelFormat {
|
||||
kUnknown,
|
||||
kPixelFormat_R8G8B8A8_UNormInt,
|
||||
kPixelFormat_R8G8B8A8_UNormInt_SRGB,
|
||||
kPixelFormat_B8G8R8A8_UNormInt,
|
||||
kPixelFormat_B8G8R8A8_UNormInt_SRGB,
|
||||
kPixelFormat_D32_Float_S8_UNormInt,
|
||||
@ -97,8 +99,9 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
|
||||
switch (format) {
|
||||
case PixelFormat::kUnknown:
|
||||
return 0u;
|
||||
case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt:
|
||||
case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt_SRGB:
|
||||
case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt:
|
||||
return 4u;
|
||||
case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt_SRGB:
|
||||
return 4u;
|
||||
case PixelFormat::kPixelFormat_D32_Float_S8_UNormInt:
|
||||
|
||||
@ -27,6 +27,10 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
|
||||
return MTLPixelFormatBGRA8Unorm_sRGB;
|
||||
case PixelFormat::kPixelFormat_D32_Float_S8_UNormInt:
|
||||
return MTLPixelFormatDepth32Float_Stencil8;
|
||||
case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt:
|
||||
return MTLPixelFormatRGBA8Unorm;
|
||||
case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt_SRGB:
|
||||
return MTLPixelFormatRGBA8Unorm_sRGB;
|
||||
}
|
||||
return MTLPixelFormatInvalid;
|
||||
};
|
||||
|
||||
@ -23,6 +23,10 @@ Texture::Texture(TextureDescriptor desc, id<MTLTexture> texture)
|
||||
|
||||
Texture::~Texture() = default;
|
||||
|
||||
void Texture::SetLabel(const std::string_view& label) {
|
||||
[texture_ setLabel:@(label.data())];
|
||||
}
|
||||
|
||||
bool Texture::SetContents(const uint8_t* contents, size_t length) {
|
||||
if (!IsValid() || !contents) {
|
||||
return false;
|
||||
|
||||
@ -18,7 +18,7 @@ std::optional<PixelFormat> FormatForImageResultComponents(
|
||||
case ImageResult::Components::RGB:
|
||||
return std::nullopt;
|
||||
case ImageResult::Components::RGBA:
|
||||
return PixelFormat::kPixelFormat_B8G8R8A8_UNormInt;
|
||||
return PixelFormat::kPixelFormat_R8G8B8A8_UNormInt;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ TEST_F(PrimitivesTest, CanCreateBoxPrimitive) {
|
||||
auto texture = context->GetPermanentsAllocator()->CreateTexture(
|
||||
StorageMode::kHostVisible, texture_descriptor.value());
|
||||
ASSERT_TRUE(texture);
|
||||
texture->SetLabel("Bay Bridge");
|
||||
auto uploaded = texture->SetContents(result.GetAllocation()->GetMapping(),
|
||||
result.GetAllocation()->GetSize());
|
||||
ASSERT_TRUE(uploaded);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user