Skip to content

Commit

Permalink
[fuchsia] Remove MessageLoopHandler dependency (flutter#4618)
Browse files Browse the repository at this point in the history
Instead, use the underlying libasync wait primitives.
  • Loading branch information
abarth authored Jan 30, 2018
1 parent c92e3df commit d68d19f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
28 changes: 17 additions & 11 deletions content_handler/vulkan_surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <async/default.h>

#include "flutter/content_handler/vulkan_surface.h"
#include "flutter/common/threads.h"
#include "third_party/skia/include/core/SkCanvas.h"
Expand All @@ -19,7 +21,8 @@ VulkanSurface::VulkanSurface(vulkan::VulkanProvider& vulkan_provider,
const SkISize& size)
: vulkan_provider_(vulkan_provider),
backend_context_(std::move(backend_context)),
session_(session) {
session_(session),
wait_(this) {
ASSERT_IS_GPU_THREAD;

FXL_DCHECK(session_);
Expand All @@ -40,8 +43,10 @@ VulkanSurface::VulkanSurface(vulkan::VulkanProvider& vulkan_provider,
return;
}

event_handler_key_ = fsl::MessageLoop::GetCurrent()->AddHandler(
this, release_event_.get(), ZX_EVENT_SIGNALED);
wait_.set_object(release_event_.get());
wait_.set_trigger(ZX_EVENT_SIGNALED);
async_ = async_get_default();
wait_.Begin(async_);

// Probably not necessary as the events should be in the unsignalled state
// already.
Expand All @@ -52,9 +57,10 @@ VulkanSurface::VulkanSurface(vulkan::VulkanProvider& vulkan_provider,

VulkanSurface::~VulkanSurface() {
ASSERT_IS_GPU_THREAD;
if (event_handler_key_ != 0) {
fsl::MessageLoop::GetCurrent()->RemoveHandler(event_handler_key_);
event_handler_key_ = 0;
if (async_) {
wait_.Cancel(async_);
wait_.set_object(ZX_HANDLE_INVALID);
async_ = nullptr;
}
}

Expand Down Expand Up @@ -398,13 +404,13 @@ void VulkanSurface::Reset() {
}
}

void VulkanSurface::OnHandleReady(zx_handle_t handle,
zx_signals_t pending,
uint64_t count) {
async_wait_result_t VulkanSurface::OnHandleReady(async_t* async,
zx_status_t status,
const zx_packet_signal_t* signal) {
ASSERT_IS_GPU_THREAD;
FXL_DCHECK(pending & ZX_EVENT_SIGNALED);
FXL_DCHECK(handle == release_event_.get());
FXL_DCHECK(signal->observed & ZX_EVENT_SIGNALED);
Reset();
return ASYNC_WAIT_AGAIN;
}

} // namespace flutter_runner
54 changes: 27 additions & 27 deletions content_handler/vulkan_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

#pragma once

#include <async/cpp/wait.h>
#include <zx/event.h>
#include <zx/vmo.h>

#include <memory>

#include "flutter/flow/scene_update_context.h"
#include "flutter/vulkan/vulkan_command_buffer.h"
#include "flutter/vulkan/vulkan_handle.h"
#include "flutter/vulkan/vulkan_proc_table.h"
#include "flutter/vulkan/vulkan_provider.h"
#include "lib/fsl/tasks/message_loop.h"
#include "lib/fsl/tasks/message_loop_handler.h"
#include "lib/fxl/macros.h"
#include "lib/ui/scenic/client/resources.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
#include "zx/event.h"
#include "zx/vmo.h"

namespace flutter_runner {

class VulkanSurface : public flow::SceneUpdateContext::SurfaceProducerSurface,
public fsl::MessageLoopHandler {
class VulkanSurface : public flow::SceneUpdateContext::SurfaceProducerSurface {
public:
VulkanSurface(vulkan::VulkanProvider& vulkan_provider,
sk_sp<GrContext> context,
Expand Down Expand Up @@ -70,27 +70,9 @@ class VulkanSurface : public flow::SceneUpdateContext::SurfaceProducerSurface,
}

private:
vulkan::VulkanProvider& vulkan_provider_;
sk_sp<GrVkBackendContext> backend_context_;
scenic_lib::Session* session_;
vulkan::VulkanHandle<VkImage> vk_image_;
vulkan::VulkanHandle<VkDeviceMemory> vk_memory_;
vulkan::VulkanHandle<VkFence> command_buffer_fence_;
sk_sp<SkSurface> sk_surface_;
std::unique_ptr<scenic_lib::Image> session_image_;
zx::event acquire_event_;
vulkan::VulkanHandle<VkSemaphore> acquire_semaphore_;
std::unique_ptr<vulkan::VulkanCommandBuffer> command_buffer_;
zx::event release_event_;
fsl::MessageLoop::HandlerKey event_handler_key_ = 0;
std::function<void(void)> pending_on_writes_committed_;
size_t age_ = 0;
bool valid_ = false;

// |fsl::MessageLoopHandler|
void OnHandleReady(zx_handle_t handle,
zx_signals_t pending,
uint64_t count) override;
async_wait_result_t OnHandleReady(async_t* async,
zx_status_t status,
const zx_packet_signal_t* signal);

bool AllocateDeviceMemory(sk_sp<GrContext> context,
const SkISize& size,
Expand All @@ -111,6 +93,24 @@ class VulkanSurface : public flow::SceneUpdateContext::SurfaceProducerSurface,
vulkan::VulkanHandle<VkSemaphore> SemaphoreFromEvent(
const zx::event& event) const;

vulkan::VulkanProvider& vulkan_provider_;
sk_sp<GrVkBackendContext> backend_context_;
scenic_lib::Session* session_;
vulkan::VulkanHandle<VkImage> vk_image_;
vulkan::VulkanHandle<VkDeviceMemory> vk_memory_;
vulkan::VulkanHandle<VkFence> command_buffer_fence_;
sk_sp<SkSurface> sk_surface_;
std::unique_ptr<scenic_lib::Image> session_image_;
zx::event acquire_event_;
vulkan::VulkanHandle<VkSemaphore> acquire_semaphore_;
std::unique_ptr<vulkan::VulkanCommandBuffer> command_buffer_;
zx::event release_event_;
async_t* async_;
async::WaitMethod<VulkanSurface, &VulkanSurface::OnHandleReady> wait_;
std::function<void()> pending_on_writes_committed_;
size_t age_ = 0;
bool valid_ = false;

FXL_DISALLOW_COPY_AND_ASSIGN(VulkanSurface);
};

Expand Down

0 comments on commit d68d19f

Please sign in to comment.