Skip to content

Commit 5bfc70e

Browse files
pwnallCQ Bot
authored andcommitted
[display][api-types] Integrate Color with PixelFormat.
Bug: 42079190 Multiply: display-api-types-cpp: 1 Multiply: display-api-types-cpp17: 1 Test: fx test //src/graphics/display/lib/api-types Change-Id: If0b3ba21a48eaceab769cb0d876b3378c42ab25b Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1176613 Fuchsia-Auto-Submit: Victor Costan <[email protected]> Reviewed-by: Yilong Li <[email protected]> Commit-Queue: Victor Costan <[email protected]>
1 parent e67d59f commit 5bfc70e

File tree

5 files changed

+111
-173
lines changed

5 files changed

+111
-173
lines changed

src/graphics/display/lib/api-types/cpp/color-test.cc

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,31 @@
77
#include <fidl/fuchsia.hardware.display.types/cpp/wire.h>
88
#include <fidl/fuchsia.images2/cpp/wire.h>
99
#include <fuchsia/hardware/display/controller/c/banjo.h>
10-
#include <lib/image-format/image_format.h>
1110

1211
#include <cstdint>
1312
#include <initializer_list>
1413

1514
#include <gmock/gmock.h>
1615
#include <gtest/gtest.h>
1716

17+
#include "src/graphics/display/lib/api-types/cpp/pixel-format.h"
18+
1819
namespace display {
1920

2021
namespace {
2122

2223
constexpr Color kRgbaGreyish({
23-
.format = fuchsia_images2::wire::PixelFormat::kR8G8B8A8,
24+
.format = PixelFormat::kR8G8B8A8,
2425
.bytes = std::initializer_list<uint8_t>{0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0},
2526
});
2627

2728
constexpr Color kRgbaGreyish2({
28-
.format = fuchsia_images2::wire::PixelFormat::kR8G8B8A8,
29+
.format = PixelFormat::kR8G8B8A8,
2930
.bytes = std::initializer_list<uint8_t>{0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0},
3031
});
3132

3233
constexpr Color kBgraGreyish2({
33-
.format = fuchsia_images2::wire::PixelFormat::kB8G8R8A8,
34+
.format = PixelFormat::kB8G8R8A8,
3435
.bytes = std::initializer_list<uint8_t>{0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0},
3536
});
3637

@@ -47,7 +48,7 @@ TEST(ColorTest, EqualityIsSymmetric) {
4748

4849
TEST(ColorTest, EqualityForDifferentContents) {
4950
static constexpr Color kRgbaFuchsia({
50-
.format = fuchsia_images2::wire::PixelFormat::kR8G8B8A8,
51+
.format = PixelFormat::kR8G8B8A8,
5152
.bytes = std::initializer_list<uint8_t>{0xff, 0x00, 0xff, 0xff, 0, 0, 0, 0},
5253
});
5354

@@ -57,7 +58,7 @@ TEST(ColorTest, EqualityForDifferentContents) {
5758

5859
TEST(ColorTest, EqualityForDifferentFormats) {
5960
static constexpr Color kBgraGreyish({
60-
.format = fuchsia_images2::wire::PixelFormat::kB8G8R8A8,
61+
.format = PixelFormat::kB8G8R8A8,
6162
.bytes = std::initializer_list<uint8_t>{0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0},
6263
});
6364
EXPECT_NE(kRgbaGreyish, kBgraGreyish);
@@ -66,10 +67,10 @@ TEST(ColorTest, EqualityForDifferentFormats) {
6667

6768
TEST(ColorTest, FromDesignatedInitializer) {
6869
static constexpr Color color({
69-
.format = fuchsia_images2::wire::PixelFormat::kR8G8B8A8,
70+
.format = PixelFormat::kR8G8B8A8,
7071
.bytes = std::initializer_list<uint8_t>{0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0},
7172
});
72-
EXPECT_EQ(fuchsia_images2::wire::PixelFormat::kR8G8B8A8, color.format());
73+
EXPECT_EQ(PixelFormat::kR8G8B8A8, color.format());
7374
EXPECT_THAT(color.bytes(), testing::ElementsAreArray(std::initializer_list<uint8_t>{
7475
0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0}));
7576
}
@@ -81,26 +82,27 @@ TEST(ColorTest, FromFidlColor) {
8182
};
8283

8384
static constexpr Color color = Color::From(fidl_color);
84-
EXPECT_EQ(fuchsia_images2::wire::PixelFormat::kR8G8B8A8, color.format());
85+
EXPECT_EQ(PixelFormat::kR8G8B8A8, color.format());
8586
EXPECT_THAT(color.bytes(), testing::ElementsAreArray(std::initializer_list<uint8_t>{
8687
0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0}));
8788
}
8889

8990
TEST(ColorTest, FromBanjoColor) {
9091
static constexpr color_t banjo_color = {
91-
.format = static_cast<uint32_t>(fuchsia_images2::wire::PixelFormat::kR8G8B8A8),
92+
.format = static_cast<fuchsia_images2_pixel_format_enum_value_t>(
93+
fuchsia_images2::wire::PixelFormat::kR8G8B8A8),
9294
.bytes = {0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0},
9395
};
9496

9597
static constexpr Color color = Color::From(banjo_color);
96-
EXPECT_EQ(fuchsia_images2::wire::PixelFormat::kR8G8B8A8, color.format());
98+
EXPECT_EQ(PixelFormat::kR8G8B8A8, color.format());
9799
EXPECT_THAT(color.bytes(), testing::ElementsAreArray(std::initializer_list<uint8_t>{
98100
0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0}));
99101
}
100102

101103
TEST(ColorTest, ToFidlColor) {
102104
static constexpr Color color({
103-
.format = fuchsia_images2::wire::PixelFormat::kR8G8B8A8,
105+
.format = PixelFormat::kR8G8B8A8,
104106
.bytes = std::initializer_list<uint8_t>{0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0},
105107
});
106108

@@ -112,12 +114,13 @@ TEST(ColorTest, ToFidlColor) {
112114

113115
TEST(ColorTest, ToBanjoColor) {
114116
static constexpr Color color({
115-
.format = fuchsia_images2::wire::PixelFormat::kR8G8B8A8,
117+
.format = PixelFormat::kR8G8B8A8,
116118
.bytes = std::initializer_list<uint8_t>{0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0},
117119
});
118120

119121
static constexpr color_t banjo_color = color.ToBanjo();
120-
EXPECT_EQ(static_cast<uint32_t>(fuchsia_images2::wire::PixelFormat::kR8G8B8A8),
122+
EXPECT_EQ(static_cast<fuchsia_images2_pixel_format_enum_value_t>(
123+
fuchsia_images2::wire::PixelFormat::kR8G8B8A8),
121124
banjo_color.format);
122125
EXPECT_THAT(banjo_color.bytes, testing::ElementsAreArray(std::initializer_list<uint8_t>{
123126
0x41, 0x42, 0x43, 0x44, 0, 0, 0, 0}));
@@ -138,62 +141,31 @@ TEST(ColorTest, IsValidBanjoRgbaGreyish) {
138141
}
139142

140143
TEST(ColorTest, SupportsFormatRgbaFormats) {
141-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kB8G8R8A8));
142-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kR8G8B8A8));
143-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kB8G8R8A8));
144-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kA2B10G10R10));
145-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kA2R10G10B10));
144+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kB8G8R8A8));
145+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kR8G8B8A8));
146+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kB8G8R8A8));
147+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kA2B10G10R10));
148+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kA2R10G10B10));
146149
}
147150

148151
TEST(ColorTest, SupportsFormatRgbFormats) {
149-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kB8G8R8));
150-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kR5G6B5));
151-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kR3G3B2));
152-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kR8G8B8));
152+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kB8G8R8));
153+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kR5G6B5));
154+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kR3G3B2));
155+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kR8G8B8));
153156
}
154157

155158
TEST(ColorTest, SupportsFormatImplicitColorChannels) {
156-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kL8));
157-
EXPECT_TRUE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kR8));
158-
}
159-
160-
TEST(ColorTest, SupportsFormatUnspecifiedAlpha) {
161-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kB8G8R8X8));
162-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kR8G8B8X8));
163-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kR2G2B2X2));
159+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kL8));
160+
EXPECT_TRUE(Color::SupportsFormat(PixelFormat::kR8));
164161
}
165162

166163
TEST(ColorTest, SupportsFormatMultiPlanar) {
167-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kI420));
168-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kM420));
169-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kNv12));
170-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kYuy2));
171-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kYv12));
172-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kP010));
173-
}
174-
175-
TEST(ColorTest, SupportsFormatInvalid) {
176-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kInvalid));
177-
EXPECT_FALSE(Color::SupportsFormat(fuchsia_images2::wire::PixelFormat::kMjpeg));
178-
}
179-
180-
TEST(ColorTest, EncodingSizeMatchesImageFormat) {
181-
static constexpr std::array kSupportedFormats = {
182-
fuchsia_images2::PixelFormat::kR8G8B8A8, fuchsia_images2::PixelFormat::kB8G8R8A8,
183-
fuchsia_images2::PixelFormat::kB8G8R8, fuchsia_images2::PixelFormat::kR5G6B5,
184-
fuchsia_images2::PixelFormat::kR3G3B2, fuchsia_images2::PixelFormat::kL8,
185-
fuchsia_images2::PixelFormat::kR8, fuchsia_images2::PixelFormat::kA2R10G10B10,
186-
fuchsia_images2::PixelFormat::kA2B10G10R10, fuchsia_images2::PixelFormat::kR8G8B8,
187-
};
188-
189-
for (fuchsia_images2::PixelFormat format : kSupportedFormats) {
190-
SCOPED_TRACE(::testing::Message() << "Format code: " << static_cast<uint32_t>(format));
191-
ASSERT_TRUE(Color::SupportsFormat(format));
192-
const PixelFormatAndModifier sysmem_format(format,
193-
fuchsia_images2::wire::PixelFormatModifier::kLinear);
194-
EXPECT_EQ(ImageFormatBitsPerPixel(sysmem_format),
195-
static_cast<uint32_t>(Color::EncodingSize(format) * 8));
196-
}
164+
EXPECT_FALSE(Color::SupportsFormat(PixelFormat::kI420));
165+
EXPECT_FALSE(Color::SupportsFormat(PixelFormat::kNv12));
166+
EXPECT_FALSE(Color::SupportsFormat(PixelFormat::kYuy2));
167+
EXPECT_FALSE(Color::SupportsFormat(PixelFormat::kYv12));
168+
EXPECT_FALSE(Color::SupportsFormat(PixelFormat::kP010));
197169
}
198170

199171
} // namespace

src/graphics/display/lib/api-types/cpp/color.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
#include <fidl/fuchsia.hardware.display.engine/cpp/wire.h>
88
#include <fuchsia/hardware/display/controller/c/banjo.h>
99

10-
#include <tuple>
11-
1210
namespace display {
1311

12+
// static
1413
void Color::StaticAsserts() {
15-
static_assert(std::tuple_size_v<decltype(bytes_)> == sizeof(color_t::bytes),
14+
static_assert(kBytesElements == sizeof(color_t::bytes),
1615
"Banjo color_t bytes size doesn't match Color");
17-
static_assert(std::tuple_size_v<decltype(bytes_)> ==
18-
decltype(fuchsia_hardware_display_types::wire::Color::bytes)::size(),
19-
"FIDL fuchsia.hardware.display.types/Color bytes size doesn't match Color");
16+
static_assert(
17+
kBytesElements == decltype(fuchsia_hardware_display_types::wire::Color::bytes)::size(),
18+
"FIDL fuchsia.hardware.display.types/Color bytes size doesn't match Color");
2019
}
2120

2221
} // namespace display

0 commit comments

Comments
 (0)