mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
68 lines
1.5 KiB
Plaintext
68 lines
1.5 KiB
Plaintext
// 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/renderer/command_buffer.h"
|
|
|
|
namespace impeller {
|
|
|
|
CommandBuffer::CommandBuffer(id<MTLCommandQueue> queue)
|
|
: buffer_([queue commandBuffer]) {
|
|
if (!buffer_) {
|
|
return;
|
|
}
|
|
is_valid_ = true;
|
|
}
|
|
|
|
CommandBuffer::~CommandBuffer() = default;
|
|
|
|
bool CommandBuffer::IsValid() const {
|
|
return is_valid_;
|
|
}
|
|
|
|
static CommandBuffer::CommitResult ToCommitResult(
|
|
MTLCommandBufferStatus status) {
|
|
switch (status) {
|
|
case MTLCommandBufferStatusCompleted:
|
|
return CommandBuffer::CommitResult::kCompleted;
|
|
case MTLCommandBufferStatusEnqueued:
|
|
return CommandBuffer::CommitResult::kPending;
|
|
default:
|
|
break;
|
|
}
|
|
return CommandBuffer::CommitResult::kError;
|
|
}
|
|
|
|
void CommandBuffer::Commit(CommitCallback callback) {
|
|
if (!callback) {
|
|
callback = [](auto) {};
|
|
}
|
|
|
|
if (!buffer_) {
|
|
callback(CommitResult::kError);
|
|
return;
|
|
}
|
|
|
|
[buffer_ addCompletedHandler:^(id<MTLCommandBuffer> buffer) {
|
|
callback(ToCommitResult(buffer.status));
|
|
}];
|
|
[buffer_ commit];
|
|
buffer_ = nil;
|
|
}
|
|
|
|
std::shared_ptr<RenderPass> CommandBuffer::CreateRenderPass(
|
|
const RenderPassDescriptor& desc) const {
|
|
if (!buffer_) {
|
|
return nullptr;
|
|
}
|
|
|
|
auto pass = std::shared_ptr<RenderPass>(new RenderPass(buffer_, desc));
|
|
if (!pass->IsValid()) {
|
|
return nullptr;
|
|
}
|
|
|
|
return pass;
|
|
}
|
|
|
|
} // namespace impeller
|