Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions impeller/aiks/experimental_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@
#include "fml/logging.h"
#include "impeller/aiks/canvas.h"
#include "impeller/aiks/paint_pass_delegate.h"
#include "impeller/base/validation.h"
#include "impeller/entity/contents/framebuffer_blend_contents.h"
#include "impeller/entity/contents/text_contents.h"
#include "impeller/entity/entity.h"
#include "impeller/geometry/color.h"

namespace impeller {

static void ApplyFramebufferBlend(Entity& entity) {
auto src_contents = entity.GetContents();
auto contents = std::make_shared<FramebufferBlendContents>();
contents->SetChildContents(src_contents);
contents->SetBlendMode(entity.GetBlendMode());
entity.SetContents(std::move(contents));
entity.SetBlendMode(BlendMode::kSource);
}

static const constexpr RenderTarget::AttachmentConfig kDefaultStencilConfig =
RenderTarget::AttachmentConfig{
.storage_mode = StorageMode::kDeviceTransient,
Expand Down Expand Up @@ -223,6 +236,16 @@ bool ExperimentalCanvas::Restore() {
element_entity.SetBlendMode(save_layer_state.paint.blend_mode);
element_entity.SetTransform(Matrix::MakeTranslation(
Vector3(save_layer_state.coverage.GetOrigin())));

if (element_entity.GetBlendMode() > Entity::kLastPipelineBlendMode) {
if (renderer_.GetDeviceCapabilities().SupportsFramebufferFetch()) {
ApplyFramebufferBlend(element_entity);
} else {
VALIDATION_LOG << "Emulated advanced blends are currently unsupported.";
element_entity.SetBlendMode(BlendMode::kSourceOver);
}
}

element_entity.Render(renderer_, *render_passes_.back());
}

Expand Down Expand Up @@ -274,6 +297,16 @@ void ExperimentalCanvas::AddRenderEntityToCurrentPass(Entity entity,
FML_CHECK(current_depth_ <= transform_stack_.back().clip_depth)
<< current_depth_ << " <=? " << transform_stack_.back().clip_depth;
entity.SetClipDepth(current_depth_);

if (entity.GetBlendMode() > Entity::kLastPipelineBlendMode) {
if (renderer_.GetDeviceCapabilities().SupportsFramebufferFetch()) {
ApplyFramebufferBlend(entity);
} else {
VALIDATION_LOG << "Emulated advanced blends are currently unsupported.";
return;
}
}

entity.Render(renderer_, *render_passes_.back());
}

Expand Down