Make testing/... and vulkan/... compatible with .clang-tidy. (flutter/engine#48161)

This commit is contained in:
Matan Lurey
2023-11-17 15:16:31 -08:00
committed by GitHub
parent 65edca6565
commit ddce052e36
13 changed files with 77 additions and 74 deletions

View File

@@ -77,11 +77,11 @@ TEST_F(PlatformViewLayerTest, ClippedPlatformViewPrerollsAndPaintsNothing) {
{MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
MockCanvas::DrawCall{
1, MockCanvas::ClipRectData{parent_clip, ClipOp::kIntersect,
MockCanvas::kHard_ClipEdgeStyle}},
MockCanvas::kHardClipEdgeStyle}},
MockCanvas::DrawCall{1, MockCanvas::SaveData{2}},
MockCanvas::DrawCall{
2, MockCanvas::ClipRectData{child_clip, ClipOp::kIntersect,
MockCanvas::kHard_ClipEdgeStyle}},
MockCanvas::kHardClipEdgeStyle}},
MockCanvas::DrawCall{2, MockCanvas::RestoreData{1}},
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}}}));
}

View File

@@ -208,21 +208,21 @@ void MockCanvas::DrawDisplayList(const sk_sp<DisplayList> display_list,
}
void MockCanvas::ClipRect(const SkRect& rect, ClipOp op, bool is_aa) {
ClipEdgeStyle style = is_aa ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
ClipEdgeStyle style = is_aa ? kSoftClipEdgeStyle : kHardClipEdgeStyle;
draw_calls_.emplace_back(
DrawCall{current_layer_, ClipRectData{rect, op, style}});
tracker_.clipRect(rect, op, is_aa);
}
void MockCanvas::ClipRRect(const SkRRect& rrect, ClipOp op, bool is_aa) {
ClipEdgeStyle style = is_aa ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
ClipEdgeStyle style = is_aa ? kSoftClipEdgeStyle : kHardClipEdgeStyle;
draw_calls_.emplace_back(
DrawCall{current_layer_, ClipRRectData{rrect, op, style}});
tracker_.clipRRect(rrect, op, is_aa);
}
void MockCanvas::ClipPath(const SkPath& path, ClipOp op, bool is_aa) {
ClipEdgeStyle style = is_aa ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
ClipEdgeStyle style = is_aa ? kSoftClipEdgeStyle : kHardClipEdgeStyle;
draw_calls_.emplace_back(
DrawCall{current_layer_, ClipPathData{path, op, style}});
tracker_.clipPath(path, op, is_aa);
@@ -501,8 +501,8 @@ bool operator==(const MockCanvas::ClipRectData& a,
static std::ostream& operator<<(std::ostream& os,
const MockCanvas::ClipEdgeStyle& style) {
return os << (style == MockCanvas::kSoft_ClipEdgeStyle ? "kSoftEdges"
: "kHardEdges");
return os << (style == MockCanvas::kSoftClipEdgeStyle ? "kSoftEdges"
: "kHardEdges");
}
std::ostream& operator<<(std::ostream& os,

View File

@@ -37,8 +37,8 @@ static constexpr SkRect kEmptyRect = SkRect::MakeEmpty();
class MockCanvas final : public DlCanvas {
public:
enum ClipEdgeStyle {
kHard_ClipEdgeStyle,
kSoft_ClipEdgeStyle,
kHardClipEdgeStyle,
kSoftClipEdgeStyle,
};
struct SaveData {

View File

@@ -21,7 +21,7 @@ namespace testing {
class StreamCapture {
public:
// Begins capturing output to the specified stream.
StreamCapture(std::ostream* ostream);
explicit StreamCapture(std::ostream* ostream);
// Stops capturing output to the specified stream, and restores the original
// output buffer, if |Stop| has not already been called.

View File

@@ -24,7 +24,7 @@ class VulkanHandle {
: handle_(handle), disposer_(disposer) {}
VulkanHandle(VulkanHandle&& other)
: handle_(other.handle_), disposer_(other.disposer_) {
: handle_(other.handle_), disposer_(std::move(other.disposer_)) {
other.handle_ = VK_NULL_HANDLE;
other.disposer_ = nullptr;
}

View File

@@ -15,7 +15,7 @@ namespace vulkan {
VulkanBackbuffer::VulkanBackbuffer(const VulkanProcTable& p_vk,
const VulkanHandle<VkDevice>& device,
const VulkanHandle<VkCommandPool>& pool)
: vk(p_vk),
: vk_(p_vk),
device_(device),
usage_command_buffer_(p_vk, device, pool),
render_command_buffer_(p_vk, device, pool),
@@ -54,14 +54,14 @@ bool VulkanBackbuffer::CreateSemaphores() {
};
auto semaphore_collect = [this](VkSemaphore semaphore) {
vk.DestroySemaphore(device_, semaphore, nullptr);
vk_.DestroySemaphore(device_, semaphore, nullptr);
};
for (size_t i = 0; i < semaphores_.size(); i++) {
VkSemaphore semaphore = VK_NULL_HANDLE;
if (VK_CALL_LOG_ERROR(vk.CreateSemaphore(device_, &create_info, nullptr,
&semaphore)) != VK_SUCCESS) {
if (VK_CALL_LOG_ERROR(vk_.CreateSemaphore(device_, &create_info, nullptr,
&semaphore)) != VK_SUCCESS) {
return false;
}
@@ -79,14 +79,14 @@ bool VulkanBackbuffer::CreateFences() {
};
auto fence_collect = [this](VkFence fence) {
vk.DestroyFence(device_, fence, nullptr);
vk_.DestroyFence(device_, fence, nullptr);
};
for (size_t i = 0; i < use_fences_.size(); i++) {
VkFence fence = VK_NULL_HANDLE;
if (VK_CALL_LOG_ERROR(vk.CreateFence(device_, &create_info, nullptr,
&fence)) != VK_SUCCESS) {
if (VK_CALL_LOG_ERROR(vk_.CreateFence(device_, &create_info, nullptr,
&fence)) != VK_SUCCESS) {
return false;
}
@@ -103,7 +103,7 @@ bool VulkanBackbuffer::WaitFences() {
fences[i] = use_fences_[i];
}
return VK_CALL_LOG_ERROR(vk.WaitForFences(
return VK_CALL_LOG_ERROR(vk_.WaitForFences(
device_, static_cast<uint32_t>(use_fences_.size()), fences, true,
std::numeric_limits<uint64_t>::max())) == VK_SUCCESS;
}
@@ -115,7 +115,7 @@ bool VulkanBackbuffer::ResetFences() {
fences[i] = use_fences_[i];
}
return VK_CALL_LOG_ERROR(vk.ResetFences(
return VK_CALL_LOG_ERROR(vk_.ResetFences(
device_, static_cast<uint32_t>(use_fences_.size()), fences)) ==
VK_SUCCESS;
}

View File

@@ -43,7 +43,7 @@ class VulkanBackbuffer {
VulkanCommandBuffer& GetRenderCommandBuffer();
private:
const VulkanProcTable& vk;
const VulkanProcTable& vk_;
const VulkanHandle<VkDevice>& device_;
std::array<VulkanHandle<VkSemaphore>, 2> semaphores_;
std::array<VulkanHandle<VkFence>, 2> use_fences_;

View File

@@ -12,7 +12,7 @@ VulkanCommandBuffer::VulkanCommandBuffer(
const VulkanProcTable& p_vk,
const VulkanHandle<VkDevice>& device,
const VulkanHandle<VkCommandPool>& pool)
: vk(p_vk), device_(device), pool_(pool), valid_(false) {
: vk_(p_vk), device_(device), pool_(pool), valid_(false) {
const VkCommandBufferAllocateInfo allocate_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = nullptr,
@@ -23,14 +23,14 @@ VulkanCommandBuffer::VulkanCommandBuffer(
VkCommandBuffer buffer = VK_NULL_HANDLE;
if (VK_CALL_LOG_ERROR(vk.AllocateCommandBuffers(device_, &allocate_info,
&buffer)) != VK_SUCCESS) {
if (VK_CALL_LOG_ERROR(vk_.AllocateCommandBuffers(device_, &allocate_info,
&buffer)) != VK_SUCCESS) {
FML_DLOG(INFO) << "Could not allocate command buffers.";
return;
}
auto buffer_collect = [this](VkCommandBuffer buffer) {
vk.FreeCommandBuffers(device_, pool_, 1, &buffer);
vk_.FreeCommandBuffers(device_, pool_, 1, &buffer);
};
handle_ = VulkanHandle<VkCommandBuffer>{buffer, buffer_collect};
@@ -56,11 +56,12 @@ bool VulkanCommandBuffer::Begin() const {
.pInheritanceInfo = nullptr,
};
return VK_CALL_LOG_ERROR(vk.BeginCommandBuffer(handle_, &info)) == VK_SUCCESS;
return VK_CALL_LOG_ERROR(vk_.BeginCommandBuffer(handle_, &info)) ==
VK_SUCCESS;
}
bool VulkanCommandBuffer::End() const {
return VK_CALL_LOG_ERROR(vk.EndCommandBuffer(handle_)) == VK_SUCCESS;
return VK_CALL_LOG_ERROR(vk_.EndCommandBuffer(handle_)) == VK_SUCCESS;
}
bool VulkanCommandBuffer::InsertPipelineBarrier(
@@ -73,10 +74,11 @@ bool VulkanCommandBuffer::InsertPipelineBarrier(
const VkBufferMemoryBarrier* buffer_memory_barriers,
uint32_t image_memory_barrier_count,
const VkImageMemoryBarrier* image_memory_barriers) const {
vk.CmdPipelineBarrier(handle_, src_stage_flags, dest_stage_flags,
dependency_flags, memory_barrier_count, memory_barriers,
buffer_memory_barrier_count, buffer_memory_barriers,
image_memory_barrier_count, image_memory_barriers);
vk_.CmdPipelineBarrier(handle_, src_stage_flags, dest_stage_flags,
dependency_flags, memory_barrier_count,
memory_barriers, buffer_memory_barrier_count,
buffer_memory_barriers, image_memory_barrier_count,
image_memory_barriers);
return true;
}

View File

@@ -41,7 +41,7 @@ class VulkanCommandBuffer {
const VkImageMemoryBarrier* image_memory_barriers) const;
private:
const VulkanProcTable& vk;
const VulkanProcTable& vk_;
const VulkanHandle<VkDevice>& device_;
const VulkanHandle<VkCommandPool>& pool_;
VulkanHandle<VkCommandBuffer> handle_;

View File

@@ -32,11 +32,11 @@ static uint32_t FindGraphicsQueueIndex(
VulkanDevice::VulkanDevice(VulkanProcTable& p_vk,
VulkanHandle<VkPhysicalDevice> physical_device,
bool enable_validation_layers)
: vk(p_vk),
: vk_(p_vk),
physical_device_(std::move(physical_device)),
graphics_queue_index_(std::numeric_limits<uint32_t>::max()),
valid_(false) {
if (!physical_device_ || !vk.AreInstanceProcsSetup()) {
if (!physical_device_ || !vk_.AreInstanceProcsSetup()) {
return;
}
@@ -60,20 +60,20 @@ VulkanDevice::VulkanDevice(VulkanProcTable& p_vk,
const char* extensions[] = {
#if FML_OS_ANDROID
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
#endif
#if OS_FUCHSIA
VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME,
VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
VK_FUCHSIA_EXTERNAL_MEMORY_EXTENSION_NAME,
VK_FUCHSIA_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
VK_FUCHSIA_BUFFER_COLLECTION_EXTENSION_NAME,
VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME,
VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
VK_FUCHSIA_EXTERNAL_MEMORY_EXTENSION_NAME,
VK_FUCHSIA_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
VK_FUCHSIA_BUFFER_COLLECTION_EXTENSION_NAME,
#endif
};
auto enabled_layers =
DeviceLayersToEnable(vk, physical_device_, enable_validation_layers);
DeviceLayersToEnable(vk_, physical_device_, enable_validation_layers);
const char* layers[enabled_layers.size()];
@@ -96,23 +96,23 @@ VulkanDevice::VulkanDevice(VulkanProcTable& p_vk,
VkDevice device = VK_NULL_HANDLE;
if (VK_CALL_LOG_ERROR(vk.CreateDevice(physical_device_, &create_info, nullptr,
&device)) != VK_SUCCESS) {
if (VK_CALL_LOG_ERROR(vk_.CreateDevice(physical_device_, &create_info,
nullptr, &device)) != VK_SUCCESS) {
FML_DLOG(INFO) << "Could not create device.";
return;
}
device_ = VulkanHandle<VkDevice>{
device, [this](VkDevice device) { vk.DestroyDevice(device, nullptr); }};
device, [this](VkDevice device) { vk_.DestroyDevice(device, nullptr); }};
if (!vk.SetupDeviceProcAddresses(device_)) {
if (!vk_.SetupDeviceProcAddresses(device_)) {
FML_DLOG(INFO) << "Could not set up device proc addresses.";
return;
}
VkQueue queue = VK_NULL_HANDLE;
vk.GetDeviceQueue(device_, graphics_queue_index_, 0, &queue);
vk_.GetDeviceQueue(device_, graphics_queue_index_, 0, &queue);
if (queue == VK_NULL_HANDLE) {
FML_DLOG(INFO) << "Could not get the device queue handle.";
@@ -133,13 +133,13 @@ VulkanDevice::VulkanDevice(VulkanProcTable& p_vk,
VulkanHandle<VkDevice> device,
uint32_t queue_family_index,
VulkanHandle<VkQueue> queue)
: vk(p_vk),
: vk_(p_vk),
physical_device_(std::move(physical_device)),
device_(std::move(device)),
queue_(std::move(queue)),
graphics_queue_index_(queue_family_index),
valid_(false) {
if (!physical_device_ || !vk.AreInstanceProcsSetup()) {
if (!physical_device_ || !vk_.AreInstanceProcsSetup()) {
return;
}
@@ -159,8 +159,8 @@ bool VulkanDevice::InitializeCommandPool() {
};
VkCommandPool command_pool = VK_NULL_HANDLE;
if (VK_CALL_LOG_ERROR(vk.CreateCommandPool(device_, &command_pool_create_info,
nullptr, &command_pool)) !=
if (VK_CALL_LOG_ERROR(vk_.CreateCommandPool(
device_, &command_pool_create_info, nullptr, &command_pool)) !=
VK_SUCCESS) {
FML_DLOG(INFO) << "Could not create the command pool.";
return false;
@@ -168,7 +168,7 @@ bool VulkanDevice::InitializeCommandPool() {
command_pool_ = VulkanHandle<VkCommandPool>{
command_pool, [this](VkCommandPool pool) {
vk.DestroyCommandPool(device_, pool, nullptr);
vk_.DestroyCommandPool(device_, pool, nullptr);
}};
return true;
@@ -183,7 +183,7 @@ bool VulkanDevice::IsValid() const {
}
bool VulkanDevice::WaitIdle() const {
return VK_CALL_LOG_ERROR(vk.DeviceWaitIdle(device_)) == VK_SUCCESS;
return VK_CALL_LOG_ERROR(vk_.DeviceWaitIdle(device_)) == VK_SUCCESS;
}
const VulkanHandle<VkDevice>& VulkanDevice::GetHandle() const {
@@ -220,7 +220,7 @@ bool VulkanDevice::GetSurfaceCapabilities(
}
bool success =
VK_CALL_LOG_ERROR(vk.GetPhysicalDeviceSurfaceCapabilitiesKHR(
VK_CALL_LOG_ERROR(vk_.GetPhysicalDeviceSurfaceCapabilitiesKHR(
physical_device_, surface.Handle(), capabilities)) == VK_SUCCESS;
if (!success) {
@@ -254,7 +254,7 @@ bool VulkanDevice::GetPhysicalDeviceFeatures(
if (features == nullptr || !physical_device_) {
return false;
}
vk.GetPhysicalDeviceFeatures(physical_device_, features);
vk_.GetPhysicalDeviceFeatures(physical_device_, features);
return true;
}
@@ -289,13 +289,13 @@ std::vector<VkQueueFamilyProperties> VulkanDevice::GetQueueFamilyProperties()
const {
uint32_t count = 0;
vk.GetPhysicalDeviceQueueFamilyProperties(physical_device_, &count, nullptr);
vk_.GetPhysicalDeviceQueueFamilyProperties(physical_device_, &count, nullptr);
std::vector<VkQueueFamilyProperties> properties;
properties.resize(count, {});
vk.GetPhysicalDeviceQueueFamilyProperties(physical_device_, &count,
properties.data());
vk_.GetPhysicalDeviceQueueFamilyProperties(physical_device_, &count,
properties.data());
return properties;
}
@@ -310,7 +310,7 @@ int VulkanDevice::ChooseSurfaceFormat(
}
uint32_t format_count = 0;
if (VK_CALL_LOG_ERROR(vk.GetPhysicalDeviceSurfaceFormatsKHR(
if (VK_CALL_LOG_ERROR(vk_.GetPhysicalDeviceSurfaceFormatsKHR(
physical_device_, surface.Handle(), &format_count, nullptr)) !=
VK_SUCCESS) {
return -1;
@@ -323,7 +323,7 @@ int VulkanDevice::ChooseSurfaceFormat(
std::vector<VkSurfaceFormatKHR> formats;
formats.resize(format_count);
if (VK_CALL_LOG_ERROR(vk.GetPhysicalDeviceSurfaceFormatsKHR(
if (VK_CALL_LOG_ERROR(vk_.GetPhysicalDeviceSurfaceFormatsKHR(
physical_device_, surface.Handle(), &format_count, formats.data())) !=
VK_SUCCESS) {
return -1;
@@ -388,7 +388,7 @@ bool VulkanDevice::QueueSubmit(
.pSignalSemaphores = signal_semaphores.data(),
};
if (VK_CALL_LOG_ERROR(vk.QueueSubmit(queue_, 1, &submit_info, fence)) !=
if (VK_CALL_LOG_ERROR(vk_.QueueSubmit(queue_, 1, &submit_info, fence)) !=
VK_SUCCESS) {
return false;
}

View File

@@ -76,7 +76,7 @@ class VulkanDevice {
[[nodiscard]] bool WaitIdle() const;
private:
VulkanProcTable& vk;
VulkanProcTable& vk_;
VulkanHandle<VkPhysicalDevice> physical_device_;
VulkanHandle<VkDevice> device_;
VulkanHandle<VkQueue> queue_;

View File

@@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include <utility>
#include "flutter/flutter_vma/flutter_skia_vma.h"
#include "flutter/vulkan/vulkan_skia_proc_table.h"
@@ -26,14 +27,14 @@ namespace vulkan {
VulkanWindow::VulkanWindow(fml::RefPtr<VulkanProcTable> proc_table,
std::unique_ptr<VulkanNativeSurface> native_surface)
: VulkanWindow(/*context/*/ nullptr,
proc_table,
std::move(proc_table),
std::move(native_surface)) {}
VulkanWindow::VulkanWindow(const sk_sp<GrDirectContext>& context,
fml::RefPtr<VulkanProcTable> proc_table,
std::unique_ptr<VulkanNativeSurface> native_surface)
: valid_(false), vk(std::move(proc_table)), skia_gr_context_(context) {
if (!vk || !vk->HasAcquiredMandatoryProcAddresses()) {
: valid_(false), vk_(std::move(proc_table)), skia_gr_context_(context) {
if (!vk_ || !vk_->HasAcquiredMandatoryProcAddresses()) {
FML_DLOG(INFO) << "Proc table has not acquired mandatory proc addresses.";
return;
}
@@ -50,10 +51,10 @@ VulkanWindow::VulkanWindow(const sk_sp<GrDirectContext>& context,
native_surface->GetExtensionName() // child extension
};
application_ = std::make_unique<VulkanApplication>(*vk, "Flutter",
application_ = std::make_unique<VulkanApplication>(*vk_, "Flutter",
std::move(extensions));
if (!application_->IsValid() || !vk->AreInstanceProcsSetup()) {
if (!application_->IsValid() || !vk_->AreInstanceProcsSetup()) {
// Make certain the application instance was created and it set up the
// instance proc table entries.
FML_DLOG(INFO) << "Instance proc addresses have not been set up.";
@@ -65,7 +66,7 @@ VulkanWindow::VulkanWindow(const sk_sp<GrDirectContext>& context,
logical_device_ = application_->AcquireFirstCompatibleLogicalDevice();
if (logical_device_ == nullptr || !logical_device_->IsValid() ||
!vk->AreDeviceProcsSetup()) {
!vk_->AreDeviceProcsSetup()) {
// Make certain the device was created and it set up the device proc table
// entries.
FML_DLOG(INFO) << "Device proc addresses have not been set up.";
@@ -77,7 +78,7 @@ VulkanWindow::VulkanWindow(const sk_sp<GrDirectContext>& context,
}
// Create the logical surface from the native platform surface.
surface_ = std::make_unique<VulkanSurface>(*vk, *application_,
surface_ = std::make_unique<VulkanSurface>(*vk_, *application_,
std::move(native_surface));
if (!surface_->IsValid()) {
@@ -89,7 +90,7 @@ VulkanWindow::VulkanWindow(const sk_sp<GrDirectContext>& context,
memory_allocator_ = flutter::FlutterSkiaVulkanMemoryAllocator::Make(
application_->GetAPIVersion(), application_->GetInstance(),
logical_device_->GetPhysicalDeviceHandle(), logical_device_->GetHandle(),
vk, true);
vk_, true);
// Create the Skia GrDirectContext.
@@ -146,7 +147,7 @@ bool VulkanWindow::CreateSkiaGrContext() {
}
bool VulkanWindow::CreateSkiaBackendContext(GrVkBackendContext* context) {
auto getProc = CreateSkiaGetProc(vk);
auto getProc = CreateSkiaGetProc(vk_);
if (getProc == nullptr) {
return false;
@@ -252,7 +253,7 @@ bool VulkanWindow::RecreateSwapchain() {
// cannot create a new one to replace it.
auto old_swapchain = std::move(swapchain_);
if (!vk->IsValid()) {
if (!vk_->IsValid()) {
return false;
}
@@ -269,7 +270,7 @@ bool VulkanWindow::RecreateSwapchain() {
}
auto swapchain = std::make_unique<VulkanSwapchain>(
*vk, *logical_device_, *surface_, skia_gr_context_.get(),
*vk_, *logical_device_, *surface_, skia_gr_context_.get(),
std::move(old_swapchain), logical_device_->GetGraphicsQueueIndex());
if (!swapchain->IsValid()) {

View File

@@ -58,7 +58,7 @@ class VulkanWindow {
private:
bool valid_;
fml::RefPtr<VulkanProcTable> vk;
fml::RefPtr<VulkanProcTable> vk_;
std::unique_ptr<VulkanApplication> application_;
std::unique_ptr<VulkanDevice> logical_device_;
std::unique_ptr<VulkanSurface> surface_;