mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Rework the confusingly named renderer subsystem instances.
This commit is contained in:
parent
a6e70d371a
commit
e4abf082ad
@ -3,7 +3,10 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
config("impeller_public_config") {
|
||||
include_dirs = [ ".." ]
|
||||
include_dirs = [
|
||||
"..",
|
||||
".",
|
||||
]
|
||||
}
|
||||
|
||||
is_host = is_mac || is_linux || is_win
|
||||
|
||||
@ -6,8 +6,8 @@ import("../tools/impeller.gni")
|
||||
|
||||
impeller_component("aiks") {
|
||||
sources = [
|
||||
"aiks_renderer.cc",
|
||||
"aiks_renderer.h",
|
||||
"aiks_context.cc",
|
||||
"aiks_context.h",
|
||||
"canvas.cc",
|
||||
"canvas.h",
|
||||
"image.cc",
|
||||
|
||||
@ -2,39 +2,39 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/aiks/aiks_renderer.h"
|
||||
#include "impeller/aiks/aiks_context.h"
|
||||
|
||||
#include "impeller/aiks/picture.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
AiksRenderer::AiksRenderer(std::shared_ptr<Context> context)
|
||||
AiksContext::AiksContext(std::shared_ptr<Context> context)
|
||||
: context_(std::move(context)) {
|
||||
if (!context_ || !context_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
content_renderer_ = std::make_unique<ContentRenderer>(context_);
|
||||
if (!content_renderer_->IsValid()) {
|
||||
content_context_ = std::make_unique<ContentContext>(context_);
|
||||
if (!content_context_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
AiksRenderer::~AiksRenderer() = default;
|
||||
AiksContext::~AiksContext() = default;
|
||||
|
||||
bool AiksRenderer::IsValid() const {
|
||||
bool AiksContext::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool AiksRenderer::Render(const Picture& picture, RenderPass& parent_pass) {
|
||||
bool AiksContext::Render(const Picture& picture, RenderPass& parent_pass) {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (picture.pass) {
|
||||
return picture.pass->Render(*content_renderer_, parent_pass);
|
||||
return picture.pass->Render(*content_context_, parent_pass);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -7,7 +7,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/entity/content_renderer.h"
|
||||
#include "impeller/entity/content_context.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
|
||||
namespace impeller {
|
||||
@ -15,11 +15,11 @@ namespace impeller {
|
||||
struct Picture;
|
||||
class RenderPass;
|
||||
|
||||
class AiksRenderer {
|
||||
class AiksContext {
|
||||
public:
|
||||
AiksRenderer(std::shared_ptr<Context> context);
|
||||
AiksContext(std::shared_ptr<Context> context);
|
||||
|
||||
~AiksRenderer();
|
||||
~AiksContext();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
@ -27,10 +27,10 @@ class AiksRenderer {
|
||||
|
||||
private:
|
||||
std::shared_ptr<Context> context_;
|
||||
std::unique_ptr<ContentRenderer> content_renderer_;
|
||||
std::unique_ptr<ContentContext> content_context_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(AiksRenderer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(AiksContext);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
#include "impeller/aiks/aiks_playground.h"
|
||||
|
||||
#include "impeller/aiks/aiks_renderer.h"
|
||||
#include "impeller/aiks/aiks_context.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@ -13,7 +13,7 @@ AiksPlayground::AiksPlayground() = default;
|
||||
AiksPlayground::~AiksPlayground() = default;
|
||||
|
||||
bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) {
|
||||
AiksRenderer renderer(GetContext());
|
||||
AiksContext renderer(GetContext());
|
||||
|
||||
if (!renderer.IsValid()) {
|
||||
return false;
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "flutter/display_list/display_list.h"
|
||||
#include "flutter/display_list/display_list_dispatcher.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/aiks/canvas.h"
|
||||
#include "impeller/aiks/paint.h"
|
||||
|
||||
@ -21,8 +21,8 @@ impeller_shaders("entity_shaders") {
|
||||
|
||||
impeller_component("entity") {
|
||||
sources = [
|
||||
"content_renderer.cc",
|
||||
"content_renderer.h",
|
||||
"content_context.cc",
|
||||
"content_context.h",
|
||||
"contents.cc",
|
||||
"contents.h",
|
||||
"entity.cc",
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/entity/content_renderer.h"
|
||||
#include "impeller/entity/content_context.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
ContentRenderer::ContentRenderer(std::shared_ptr<Context> context)
|
||||
ContentContext::ContentContext(std::shared_ptr<Context> context)
|
||||
: context_(std::move(context)) {
|
||||
if (!context_ || !context_->IsValid()) {
|
||||
return;
|
||||
@ -46,13 +46,13 @@ ContentRenderer::ContentRenderer(std::shared_ptr<Context> context)
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
ContentRenderer::~ContentRenderer() = default;
|
||||
ContentContext::~ContentContext() = default;
|
||||
|
||||
bool ContentRenderer::IsValid() const {
|
||||
bool ContentContext::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> ContentRenderer::GetContext() const {
|
||||
std::shared_ptr<Context> ContentContext::GetContext() const {
|
||||
return context_;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ using SolidStrokePipeline =
|
||||
// to redirect writing to the stencil instead of color attachments.
|
||||
using ClipPipeline = PipelineT<SolidFillVertexShader, SolidFillFragmentShader>;
|
||||
|
||||
class ContentRenderer {
|
||||
class ContentContext {
|
||||
public:
|
||||
struct Options {
|
||||
SampleCount sample_count = SampleCount::kCount1;
|
||||
@ -51,9 +51,9 @@ class ContentRenderer {
|
||||
};
|
||||
};
|
||||
|
||||
ContentRenderer(std::shared_ptr<Context> context);
|
||||
ContentContext(std::shared_ptr<Context> context);
|
||||
|
||||
~ContentRenderer();
|
||||
~ContentContext();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
@ -128,7 +128,7 @@ class ContentRenderer {
|
||||
|
||||
bool is_valid_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ContentRenderer);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ContentContext);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
@ -7,7 +7,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "impeller/entity/content_renderer.h"
|
||||
#include "impeller/entity/content_context.h"
|
||||
#include "impeller/entity/entity.h"
|
||||
#include "impeller/geometry/path_builder.h"
|
||||
#include "impeller/geometry/vector.h"
|
||||
@ -19,8 +19,8 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
static ContentRenderer::Options OptionsFromPass(const RenderPass& pass) {
|
||||
ContentRenderer::Options opts;
|
||||
static ContentContext::Options OptionsFromPass(const RenderPass& pass) {
|
||||
ContentContext::Options opts;
|
||||
opts.sample_count = pass.GetRenderTarget().GetSampleCount();
|
||||
return opts;
|
||||
}
|
||||
@ -60,7 +60,7 @@ const std::vector<Color>& LinearGradientContents::GetColors() const {
|
||||
return colors_;
|
||||
}
|
||||
|
||||
bool LinearGradientContents::Render(const ContentRenderer& renderer,
|
||||
bool LinearGradientContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
using VS = GradientFillPipeline::VertexShader;
|
||||
@ -137,7 +137,7 @@ static VertexBuffer CreateSolidFillVertices(const Path& path,
|
||||
return vtx_builder.CreateVertexBuffer(buffer);
|
||||
}
|
||||
|
||||
bool SolidColorContents::Render(const ContentRenderer& renderer,
|
||||
bool SolidColorContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
if (color_.IsTransparent()) {
|
||||
@ -194,7 +194,7 @@ void TextureContents::SetOpacity(Scalar opacity) {
|
||||
opacity_ = opacity;
|
||||
}
|
||||
|
||||
bool TextureContents::Render(const ContentRenderer& renderer,
|
||||
bool TextureContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
if (texture_ == nullptr) {
|
||||
@ -328,7 +328,7 @@ static VertexBuffer CreateSolidStrokeVertices(const Path& path,
|
||||
return vtx_builder.CreateVertexBuffer(buffer);
|
||||
}
|
||||
|
||||
bool SolidStrokeContents::Render(const ContentRenderer& renderer,
|
||||
bool SolidStrokeContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
if (color_.IsTransparent() || stroke_size_ <= 0.0) {
|
||||
@ -377,7 +377,7 @@ ClipContents::ClipContents() = default;
|
||||
|
||||
ClipContents::~ClipContents() = default;
|
||||
|
||||
bool ClipContents::Render(const ContentRenderer& renderer,
|
||||
bool ClipContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
using VS = ClipPipeline::VertexShader;
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class ContentRenderer;
|
||||
class ContentContext;
|
||||
class Entity;
|
||||
class Surface;
|
||||
class RenderPass;
|
||||
@ -26,7 +26,7 @@ class Contents {
|
||||
|
||||
virtual ~Contents();
|
||||
|
||||
virtual bool Render(const ContentRenderer& renderer,
|
||||
virtual bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const = 0;
|
||||
|
||||
@ -41,7 +41,7 @@ class LinearGradientContents final : public Contents {
|
||||
~LinearGradientContents() override;
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
@ -72,7 +72,7 @@ class SolidColorContents final : public Contents {
|
||||
const Color& GetColor() const;
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
@ -99,7 +99,7 @@ class TextureContents final : public Contents {
|
||||
const IRect& GetSourceRect() const;
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
@ -126,7 +126,7 @@ class SolidStrokeContents final : public Contents {
|
||||
Scalar GetStrokeSize() const;
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
@ -144,7 +144,7 @@ class ClipContents final : public Contents {
|
||||
~ClipContents();
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
#include "impeller/entity/entity.h"
|
||||
|
||||
#include "impeller/entity/content_renderer.h"
|
||||
#include "impeller/entity/content_context.h"
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
|
||||
namespace impeller {
|
||||
@ -65,7 +65,7 @@ void Entity::IncrementStencilDepth(uint32_t increment) {
|
||||
stencil_depth_ += increment;
|
||||
}
|
||||
|
||||
bool Entity::Render(ContentRenderer& renderer, RenderPass& parent_pass) const {
|
||||
bool Entity::Render(ContentContext& renderer, RenderPass& parent_pass) const {
|
||||
if (!contents_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ class Entity {
|
||||
|
||||
uint32_t GetStencilDepth() const;
|
||||
|
||||
bool Render(ContentRenderer& renderer, RenderPass& parent_pass) const;
|
||||
bool Render(ContentContext& renderer, RenderPass& parent_pass) const;
|
||||
|
||||
private:
|
||||
Matrix transformation_;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
#include "impeller/entity/entity_pass.h"
|
||||
|
||||
#include "impeller/entity/content_renderer.h"
|
||||
#include "impeller/entity/content_context.h"
|
||||
#include "impeller/geometry/path_builder.h"
|
||||
#include "impeller/renderer/command_buffer.h"
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
@ -97,7 +97,7 @@ EntityPass* EntityPass::AddSubpass(std::unique_ptr<EntityPass> pass) {
|
||||
return subpasses_.emplace_back(std::move(pass)).get();
|
||||
}
|
||||
|
||||
bool EntityPass::Render(ContentRenderer& renderer,
|
||||
bool EntityPass::Render(ContentContext& renderer,
|
||||
RenderPass& parent_pass) const {
|
||||
for (const auto& entity : entities_) {
|
||||
if (!entity.Render(renderer, parent_pass)) {
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class ContentRenderer;
|
||||
class ContentContext;
|
||||
|
||||
class EntityPass {
|
||||
public:
|
||||
@ -45,7 +45,7 @@ class EntityPass {
|
||||
|
||||
EntityPass* GetSuperpass() const;
|
||||
|
||||
bool Render(ContentRenderer& renderer, RenderPass& parent_pass) const;
|
||||
bool Render(ContentContext& renderer, RenderPass& parent_pass) const;
|
||||
|
||||
void IterateAllEntities(std::function<bool(Entity&)> iterator);
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
#include "impeller/entity/entity_playground.h"
|
||||
|
||||
#include "impeller/entity/content_renderer.h"
|
||||
#include "impeller/entity/content_context.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@ -13,12 +13,12 @@ EntityPlayground::EntityPlayground() = default;
|
||||
EntityPlayground::~EntityPlayground() = default;
|
||||
|
||||
bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
|
||||
ContentRenderer renderer(GetContext());
|
||||
if (!renderer.IsValid()) {
|
||||
ContentContext context_context(GetContext());
|
||||
if (!context_context.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
Renderer::RenderCallback callback = [&](RenderPass& pass) -> bool {
|
||||
return entity.Render(renderer, pass);
|
||||
return entity.Render(context_context, pass);
|
||||
};
|
||||
return Playground::OpenPlaygroundHere(callback);
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <Metal/Metal.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/renderer/backend/metal/allocator_mtl.h"
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
#include "impeller/renderer/renderer.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "impeller/base/validation.h"
|
||||
#include "impeller/renderer/command_buffer.h"
|
||||
@ -11,11 +13,10 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
constexpr size_t kMaxFramesInFlight = 3u;
|
||||
|
||||
Renderer::Renderer(std::shared_ptr<Context> context)
|
||||
: frames_in_flight_sema_(
|
||||
std::make_shared<fml::Semaphore>(kMaxFramesInFlight)),
|
||||
Renderer::Renderer(std::shared_ptr<Context> context,
|
||||
size_t max_frames_in_flight)
|
||||
: frames_in_flight_sema_(std::make_shared<fml::Semaphore>(
|
||||
std::max<std::size_t>(1u, max_frames_in_flight))),
|
||||
context_(std::move(context)) {
|
||||
if (!context_->IsValid()) {
|
||||
return;
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "fml/synchronization/semaphore.h"
|
||||
#include "flutter/fml/synchronization/semaphore.h"
|
||||
#include "impeller/geometry/size.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
|
||||
@ -21,9 +21,12 @@ class RenderPass;
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
static constexpr size_t kDefaultMaxFramesInFlight = 3u;
|
||||
|
||||
using RenderCallback = std::function<bool(RenderPass& pass)>;
|
||||
|
||||
Renderer(std::shared_ptr<Context> context);
|
||||
Renderer(std::shared_ptr<Context> context,
|
||||
size_t max_frames_in_flight = kDefaultMaxFramesInFlight);
|
||||
|
||||
~Renderer();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user