mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Multi-encodable render passes.
This commit is contained in:
parent
f8eab3f6fa
commit
be69b42bf9
@ -80,19 +80,10 @@ MTLDepthStencilDescriptor* ToMTLDepthStencilDescriptor(
|
||||
static bool ConfigureRenderPassAttachment(
|
||||
RenderPassAttachment& attachment,
|
||||
MTLRenderPassAttachmentDescriptor* desc) {
|
||||
if (!attachment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!desc.texture) {
|
||||
return false;
|
||||
}
|
||||
|
||||
attachment.texture = std::make_shared<Texture>(desc.texture);
|
||||
attachment.load_action = FromMTLLoadAction(desc.loadAction);
|
||||
attachment.store_action = FromMTLStoreAction(desc.storeAction);
|
||||
|
||||
return true;
|
||||
return attachment;
|
||||
}
|
||||
|
||||
static ColorRenderPassAttachment FromMTLRenderPassColorAttachmentDescriptor(
|
||||
|
||||
@ -68,10 +68,13 @@ class RenderPass {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool Encode() const;
|
||||
|
||||
private:
|
||||
friend class CommandBuffer;
|
||||
|
||||
id<MTLRenderCommandEncoder> pass_ = nil;
|
||||
id<MTLCommandBuffer> buffer_ = nil;
|
||||
MTLRenderPassDescriptor* desc_ = nil;
|
||||
bool is_valid_ = false;
|
||||
|
||||
RenderPass(id<MTLCommandBuffer> buffer, const RenderPassDescriptor& desc);
|
||||
|
||||
@ -114,17 +114,11 @@ MTLRenderPassDescriptor* RenderPassDescriptor::ToMTLRenderPassDescriptor()
|
||||
}
|
||||
|
||||
RenderPass::RenderPass(id<MTLCommandBuffer> buffer,
|
||||
const RenderPassDescriptor& desc) {
|
||||
auto descriptor = desc.ToMTLRenderPassDescriptor();
|
||||
if (!descriptor) {
|
||||
const RenderPassDescriptor& desc)
|
||||
: buffer_(buffer), desc_(desc.ToMTLRenderPassDescriptor()) {
|
||||
if (!buffer_ || !desc_) {
|
||||
return;
|
||||
}
|
||||
|
||||
pass_ = [buffer renderCommandEncoderWithDescriptor:descriptor];
|
||||
if (!pass_) {
|
||||
return;
|
||||
}
|
||||
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
@ -134,4 +128,16 @@ bool RenderPass::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool RenderPass::Encode() const {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
auto pass = [buffer_ renderCommandEncoderWithDescriptor:desc_];
|
||||
if (!pass) {
|
||||
return false;
|
||||
}
|
||||
[pass endEncoding];
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@ -43,6 +43,13 @@ bool Renderer::Render(const Surface& surface) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto render_pass =
|
||||
command_buffer->CreateRenderPass(surface.GetRenderPassDescriptor());
|
||||
if (!render_pass) {
|
||||
return false;
|
||||
}
|
||||
render_pass->Encode();
|
||||
|
||||
::dispatch_semaphore_wait(frames_in_flight_sema_, DISPATCH_TIME_FOREVER);
|
||||
|
||||
command_buffer->Commit(
|
||||
|
||||
@ -22,6 +22,8 @@ class Surface {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
const RenderPassDescriptor& GetRenderPassDescriptor() const;
|
||||
|
||||
private:
|
||||
RenderPassDescriptor desc_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
Surface::Surface(RenderPassDescriptor desc) {
|
||||
if (desc.HasColorAttachment(0)) {
|
||||
Surface::Surface(RenderPassDescriptor desc) : desc_(std::move(desc)) {
|
||||
if (!desc_.HasColorAttachment(0)) {
|
||||
return;
|
||||
}
|
||||
is_valid_ = true;
|
||||
@ -21,4 +21,8 @@ bool Surface::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
const RenderPassDescriptor& Surface::GetRenderPassDescriptor() const {
|
||||
return desc_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <Metal/Metal.h>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/geometry/size.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@ -16,6 +17,8 @@ class Texture {
|
||||
|
||||
~Texture();
|
||||
|
||||
Size GetSize() const;
|
||||
|
||||
id<MTLTexture> GetMTLTexture() const;
|
||||
|
||||
private:
|
||||
|
||||
@ -10,6 +10,11 @@ Texture::Texture(id<MTLTexture> texture) : texture_(texture) {}
|
||||
|
||||
Texture::~Texture() = default;
|
||||
|
||||
Size Texture::GetSize() const {
|
||||
return {static_cast<double>(texture_.width),
|
||||
static_cast<double>(texture_.height)};
|
||||
}
|
||||
|
||||
id<MTLTexture> Texture::GetMTLTexture() const {
|
||||
return texture_;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
namespace impeller {
|
||||
@ -16,6 +17,11 @@ struct Size {
|
||||
|
||||
constexpr Size(double width, double height) : width(width), height(height) {}
|
||||
|
||||
static constexpr Size Infinite() {
|
||||
return Size{std::numeric_limits<double>::max(),
|
||||
std::numeric_limits<double>::max()};
|
||||
}
|
||||
|
||||
/*
|
||||
* Operator overloads
|
||||
*/
|
||||
@ -46,6 +52,13 @@ struct Size {
|
||||
};
|
||||
}
|
||||
|
||||
constexpr Size Intersection(const Size& o) const {
|
||||
return {
|
||||
std::min(width, o.width),
|
||||
std::min(height, o.height),
|
||||
};
|
||||
}
|
||||
|
||||
constexpr bool IsZero() const { return width * height == 0.0; }
|
||||
|
||||
constexpr bool IsPositive() const { return width * height > 0.0; }
|
||||
|
||||
@ -230,6 +230,7 @@ static const size_t kAlignedUniformsSize = (sizeof(Uniforms) & ~0xFF) + 0x100;
|
||||
if (!renderer_->Render(surface)) {
|
||||
FML_LOG(ERROR) << "Could not render.";
|
||||
}
|
||||
|
||||
/// Per frame updates here
|
||||
dispatch_semaphore_wait(_inFlightSemaphore, DISPATCH_TIME_FOREVER);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user