Skip to content

Commit e695cbc

Browse files
committed
Build the mock context without captured state or a chained temporary
clang-tidy traced a stack address escaping through the builder's callback. Plain function pointers carry no stack state, and a named builder keeps the reference it returns out of the caller.
1 parent c0056d2 commit e695cbc

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

‎engine/src/flutter/impeller/renderer/backend/vulkan/texture_vk_unittests.cc‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,30 @@ namespace testing {
1919
namespace {
2020

2121
// Qualcomm devices generate corrupt mip levels; ARM ones do not.
22+
constexpr std::string_view kAdrenoName = "Adreno (TM) 750";
23+
constexpr std::string_view kMaliName = "Mali-G51";
2224
constexpr uint32_t kQualcommVendorID = 0x168C;
2325
constexpr uint32_t kARMVendorID = 0x13B5;
2426

25-
std::shared_ptr<ContextVK> MakeContext(std::string_view device_name,
26-
uint32_t vendor_id) {
27-
return MockVulkanContextBuilder()
28-
.SetPhysicalPropertiesCallback(
29-
[device_name, vendor_id](VkPhysicalDevice device,
30-
VkPhysicalDeviceProperties* prop) {
31-
prop->vendorID = vendor_id;
32-
device_name.copy(prop->deviceName, device_name.size());
33-
prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
34-
})
35-
.Build();
27+
void SetAdrenoProperties(VkPhysicalDevice device,
28+
VkPhysicalDeviceProperties* prop) {
29+
prop->vendorID = kQualcommVendorID;
30+
kAdrenoName.copy(prop->deviceName, kAdrenoName.size());
31+
prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
32+
}
33+
34+
void SetMaliProperties(VkPhysicalDevice device,
35+
VkPhysicalDeviceProperties* prop) {
36+
prop->vendorID = kARMVendorID;
37+
kMaliName.copy(prop->deviceName, kMaliName.size());
38+
prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
39+
}
40+
41+
std::shared_ptr<ContextVK> MakeContext(
42+
void (*set_properties)(VkPhysicalDevice, VkPhysicalDeviceProperties*)) {
43+
MockVulkanContextBuilder builder;
44+
builder.SetPhysicalPropertiesCallback(set_properties);
45+
return builder.Build();
3646
}
3747

3848
std::shared_ptr<Texture> MakeTexture(const std::shared_ptr<ContextVK>& context,
@@ -49,7 +59,7 @@ std::shared_ptr<Texture> MakeTexture(const std::shared_ptr<ContextVK>& context,
4959
} // namespace
5060

5161
TEST(TextureVKTest, SampledViewDropsMipsGeneratedByABrokenDriver) {
52-
auto const context = MakeContext("Adreno (TM) 750", kQualcommVendorID);
62+
auto const context = MakeContext(SetAdrenoProperties);
5363
auto texture = MakeTexture(context, /*mip_count=*/4u);
5464
ASSERT_TRUE(texture);
5565
auto& texture_vk = TextureVK::Cast(*texture);
@@ -64,7 +74,7 @@ TEST(TextureVKTest, SampledViewDropsMipsGeneratedByABrokenDriver) {
6474
}
6575

6676
TEST(TextureVKTest, SampledViewKeepsMipsOnAWorkingDriver) {
67-
auto const context = MakeContext("Mali-G51", kARMVendorID);
77+
auto const context = MakeContext(SetMaliProperties);
6878
auto texture = MakeTexture(context, /*mip_count=*/4u);
6979
ASSERT_TRUE(texture);
7080
auto& texture_vk = TextureVK::Cast(*texture);
@@ -74,7 +84,7 @@ TEST(TextureVKTest, SampledViewKeepsMipsOnAWorkingDriver) {
7484
}
7585

7686
TEST(TextureVKTest, SampledViewIsTheFullViewWithoutMips) {
77-
auto const context = MakeContext("Adreno (TM) 750", kQualcommVendorID);
87+
auto const context = MakeContext(SetAdrenoProperties);
7888
auto texture = MakeTexture(context, /*mip_count=*/1u);
7989
ASSERT_TRUE(texture);
8090
auto& texture_vk = TextureVK::Cast(*texture);

0 commit comments

Comments
 (0)