Skip to content

Commit

Permalink
Make testing/... and vulkan/... compatible with .clang-tidy. (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
matanlurey authored Nov 17, 2023
1 parent 1d2ee54 commit 66f764a
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 74 deletions.
4 changes: 2 additions & 2 deletions flow/layers/platform_view_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}));
}
Expand Down
10 changes: 5 additions & 5 deletions testing/mock_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions testing/mock_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion testing/stream_capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion vulkan/procs/vulkan_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions vulkan/vulkan_backbuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion vulkan/vulkan_backbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
22 changes: 12 additions & 10 deletions vulkan/vulkan_command_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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};
Expand All @@ -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(
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion vulkan/vulkan_command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
58 changes: 29 additions & 29 deletions vulkan/vulkan_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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()];

Expand All @@ -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.";
Expand All @@ -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;
}

Expand All @@ -159,16 +159,16 @@ 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;
}

command_pool_ = VulkanHandle<VkCommandPool>{
command_pool, [this](VkCommandPool pool) {
vk.DestroyCommandPool(device_, pool, nullptr);
vk_.DestroyCommandPool(device_, pool, nullptr);
}};

return true;
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 66f764a

Please sign in to comment.