mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Wire up render loop.
This commit is contained in:
parent
6b6a8d35fd
commit
edab9d7ef2
@ -30,8 +30,8 @@ source_set("impeller") {
|
||||
"compositor/renderer.mm",
|
||||
"compositor/shader_library.h",
|
||||
"compositor/shader_library.mm",
|
||||
"compositor/surface.cc",
|
||||
"compositor/surface.h",
|
||||
"compositor/surface.mm",
|
||||
]
|
||||
|
||||
geometry_sources = [
|
||||
|
||||
@ -18,11 +18,14 @@ class Context {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
id<MTLCommandQueue> GetRenderQueue() const;
|
||||
|
||||
id<MTLCommandQueue> GetTransferQueue() const;
|
||||
|
||||
private:
|
||||
id<MTLDevice> device_;
|
||||
id<MTLCommandQueue> render_queue_;
|
||||
id<MTLCommandQueue> transfer_queue_;
|
||||
|
||||
bool is_valid_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Context);
|
||||
|
||||
@ -32,4 +32,12 @@ bool Context::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
id<MTLCommandQueue> Context::GetRenderQueue() const {
|
||||
return render_queue_;
|
||||
}
|
||||
|
||||
id<MTLCommandQueue> Context::GetTransferQueue() const {
|
||||
return transfer_queue_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@ -4,8 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "context.h"
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/context.h"
|
||||
#include "impeller/compositor/surface.h"
|
||||
#include "impeller/geometry/size.h"
|
||||
|
||||
namespace impeller {
|
||||
@ -23,7 +26,8 @@ class Renderer {
|
||||
bool Render();
|
||||
|
||||
private:
|
||||
Context context_;
|
||||
std::shared_ptr<Context> context_;
|
||||
std::unique_ptr<Surface> surface_;
|
||||
Size size_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
|
||||
@ -2,14 +2,20 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "renderer.h"
|
||||
#include "impeller/compositor/renderer.h"
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
Renderer::Renderer() {
|
||||
if (!context_.IsValid()) {
|
||||
Renderer::Renderer()
|
||||
: context_(std::make_shared<Context>()),
|
||||
surface_(std::make_unique<Surface>(context_)) {
|
||||
if (!context_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!surface_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -40,7 +46,7 @@ bool Renderer::Render() {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return surface_->Render();
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@ -4,17 +4,30 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dispatch/dispatch.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/context.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class Surface {
|
||||
public:
|
||||
Surface();
|
||||
Surface(std::shared_ptr<Context> context);
|
||||
|
||||
~Surface();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool Render() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Context> context_;
|
||||
dispatch_semaphore_t frames_in_flight_sema_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Surface);
|
||||
};
|
||||
|
||||
|
||||
52
engine/src/flutter/impeller/impeller/compositor/surface.mm
Normal file
52
engine/src/flutter/impeller/impeller/compositor/surface.mm
Normal file
@ -0,0 +1,52 @@
|
||||
// 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 "impeller/compositor/surface.h"
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
constexpr size_t kMaxFramesInFlight = 3u;
|
||||
|
||||
Surface::Surface(std::shared_ptr<Context> context)
|
||||
: context_(std::move(context)),
|
||||
frames_in_flight_sema_(::dispatch_semaphore_create(kMaxFramesInFlight)) {
|
||||
if (!context_ || !context_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
Surface::~Surface() = default;
|
||||
|
||||
bool Surface::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool Surface::Render() const {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto command_buffer = [context_->GetRenderQueue() commandBuffer];
|
||||
|
||||
if (!command_buffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
::dispatch_semaphore_wait(frames_in_flight_sema_, DISPATCH_TIME_FOREVER);
|
||||
|
||||
__block dispatch_semaphore_t block_sema = frames_in_flight_sema_;
|
||||
[command_buffer addCompletedHandler:^(id<MTLCommandBuffer> buffer) {
|
||||
::dispatch_semaphore_signal(block_sema);
|
||||
}];
|
||||
|
||||
[command_buffer commit];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
Loading…
x
Reference in New Issue
Block a user