mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
In http://review.skia.org/892736 and http://review.skia.org/893856, Skia moved its Ganesh headers to align with the Graphite ones. This updates Flutter to use those moved files. All changes are mechanical and there is no API difference between the headers (indeed, the old ones simply `#include` the new ones). ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
148 lines
3.9 KiB
C++
148 lines
3.9 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "vulkan_backbuffer.h"
|
|
|
|
#include <limits>
|
|
|
|
#include "flutter/vulkan/procs/vulkan_proc_table.h"
|
|
#include "third_party/skia/include/gpu/ganesh/vk/GrVkTypes.h"
|
|
#include "vulkan/vulkan.h"
|
|
|
|
namespace vulkan {
|
|
|
|
VulkanBackbuffer::VulkanBackbuffer(const VulkanProcTable& p_vk,
|
|
const VulkanHandle<VkDevice>& device,
|
|
const VulkanHandle<VkCommandPool>& pool)
|
|
: vk_(p_vk),
|
|
device_(device),
|
|
usage_command_buffer_(p_vk, device, pool),
|
|
render_command_buffer_(p_vk, device, pool),
|
|
valid_(false) {
|
|
if (!usage_command_buffer_.IsValid() || !render_command_buffer_.IsValid()) {
|
|
FML_DLOG(INFO) << "Command buffers were not valid.";
|
|
return;
|
|
}
|
|
|
|
if (!CreateSemaphores()) {
|
|
FML_DLOG(INFO) << "Could not create semaphores.";
|
|
return;
|
|
}
|
|
|
|
if (!CreateFences()) {
|
|
FML_DLOG(INFO) << "Could not create fences.";
|
|
return;
|
|
}
|
|
|
|
valid_ = true;
|
|
}
|
|
|
|
VulkanBackbuffer::~VulkanBackbuffer() {
|
|
[[maybe_unused]] auto result = WaitFences();
|
|
}
|
|
|
|
bool VulkanBackbuffer::IsValid() const {
|
|
return valid_;
|
|
}
|
|
|
|
bool VulkanBackbuffer::CreateSemaphores() {
|
|
const VkSemaphoreCreateInfo create_info = {
|
|
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
|
.pNext = nullptr,
|
|
.flags = 0,
|
|
};
|
|
|
|
auto semaphore_collect = [this](VkSemaphore semaphore) {
|
|
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) {
|
|
return false;
|
|
}
|
|
|
|
semaphores_[i] = VulkanHandle<VkSemaphore>{semaphore, semaphore_collect};
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool VulkanBackbuffer::CreateFences() {
|
|
const VkFenceCreateInfo create_info = {
|
|
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
|
.pNext = nullptr,
|
|
.flags = VK_FENCE_CREATE_SIGNALED_BIT,
|
|
};
|
|
|
|
auto fence_collect = [this](VkFence fence) {
|
|
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) {
|
|
return false;
|
|
}
|
|
|
|
use_fences_[i] = VulkanHandle<VkFence>{fence, fence_collect};
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool VulkanBackbuffer::WaitFences() {
|
|
VkFence fences[std::tuple_size_v<decltype(use_fences_)>];
|
|
|
|
for (size_t i = 0; i < use_fences_.size(); i++) {
|
|
fences[i] = use_fences_[i];
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
bool VulkanBackbuffer::ResetFences() {
|
|
VkFence fences[std::tuple_size_v<decltype(use_fences_)>];
|
|
|
|
for (size_t i = 0; i < use_fences_.size(); i++) {
|
|
fences[i] = use_fences_[i];
|
|
}
|
|
|
|
return VK_CALL_LOG_ERROR(vk_.ResetFences(
|
|
device_, static_cast<uint32_t>(use_fences_.size()), fences)) ==
|
|
VK_SUCCESS;
|
|
}
|
|
|
|
const VulkanHandle<VkFence>& VulkanBackbuffer::GetUsageFence() const {
|
|
return use_fences_[0];
|
|
}
|
|
|
|
const VulkanHandle<VkFence>& VulkanBackbuffer::GetRenderFence() const {
|
|
return use_fences_[1];
|
|
}
|
|
|
|
const VulkanHandle<VkSemaphore>& VulkanBackbuffer::GetUsageSemaphore() const {
|
|
return semaphores_[0];
|
|
}
|
|
|
|
const VulkanHandle<VkSemaphore>& VulkanBackbuffer::GetRenderSemaphore() const {
|
|
return semaphores_[1];
|
|
}
|
|
|
|
VulkanCommandBuffer& VulkanBackbuffer::GetUsageCommandBuffer() {
|
|
return usage_command_buffer_;
|
|
}
|
|
|
|
VulkanCommandBuffer& VulkanBackbuffer::GetRenderCommandBuffer() {
|
|
return render_command_buffer_;
|
|
}
|
|
|
|
} // namespace vulkan
|