Use platform agnostic semaphores in the renderer.

This commit is contained in:
Chinmay Garde 2021-11-01 14:03:14 -07:00 committed by Dan Field
parent 0c66998e1c
commit b84b8ca09f
3 changed files with 9 additions and 5 deletions

View File

@ -75,7 +75,7 @@ impeller_component("renderer") {
"render_pass_descriptor.h",
"render_pass_descriptor.cc",
"renderer.h",
"renderer.mm",
"renderer.cc",
"sampler.h",
"sampler.cc",
"sampler_descriptor.h",

View File

@ -13,7 +13,8 @@ namespace impeller {
constexpr size_t kMaxFramesInFlight = 3u;
Renderer::Renderer(std::shared_ptr<Context> context)
: frames_in_flight_sema_(::dispatch_semaphore_create(kMaxFramesInFlight)),
: frames_in_flight_sema_(
std::make_shared<fml::Semaphore>(kMaxFramesInFlight)),
context_(std::move(context)) {
if (!context_->IsValid()) {
return;
@ -58,11 +59,13 @@ bool Renderer::Render(const Surface& surface,
return false;
}
::dispatch_semaphore_wait(frames_in_flight_sema_, DISPATCH_TIME_FOREVER);
if (!frames_in_flight_sema_->Wait()) {
return false;
}
command_buffer->Commit(
[sema = frames_in_flight_sema_](CommandBuffer::CommitResult result) {
::dispatch_semaphore_signal(sema);
sema->Signal();
if (result != CommandBuffer::CommitResult::kCompleted) {
FML_LOG(ERROR) << "Could not commit command buffer.";
}

View File

@ -10,6 +10,7 @@
#include <memory>
#include "flutter/fml/macros.h"
#include "fml/synchronization/semaphore.h"
#include "impeller/geometry/size.h"
#include "impeller/renderer/context.h"
@ -34,7 +35,7 @@ class Renderer {
std::shared_ptr<Context> GetContext() const;
private:
dispatch_semaphore_t frames_in_flight_sema_ = nullptr;
std::shared_ptr<fml::Semaphore> frames_in_flight_sema_;
std::shared_ptr<Context> context_;
bool is_valid_ = false;