blob: 45b6aad04d87ccd22022eefd4ce92cd5223814a2 [file] [log] [blame]
// 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/entity/contents/filters/matrix_filter_contents.h"
namespace impeller {
MatrixFilterContents::MatrixFilterContents() = default;
MatrixFilterContents::~MatrixFilterContents() = default;
void MatrixFilterContents::SetMatrix(Matrix matrix) {
matrix_ = matrix;
}
void MatrixFilterContents::SetSamplerDescriptor(SamplerDescriptor desc) {
sampler_descriptor_ = std::move(desc);
}
std::optional<Entity> MatrixFilterContents::RenderFilter(
const FilterInput::Vector& inputs,
const ContentContext& renderer,
const Entity& entity,
const Matrix& effect_transform,
const Rect& coverage) const {
auto snapshot = inputs[0]->GetSnapshot(renderer, entity);
if (!snapshot.has_value()) {
return std::nullopt;
}
snapshot->transform = entity.GetTransformation() * //
matrix_ * //
entity.GetTransformation().Invert() * //
snapshot->transform;
snapshot->sampler_descriptor = sampler_descriptor_;
return Contents::EntityFromSnapshot(snapshot, entity.GetBlendMode(),
entity.GetStencilDepth());
}
std::optional<Rect> MatrixFilterContents::GetFilterCoverage(
const FilterInput::Vector& inputs,
const Entity& entity,
const Matrix& effect_transform) const {
if (inputs.empty()) {
return std::nullopt;
}
auto coverage = inputs[0]->GetCoverage(entity);
if (!coverage.has_value()) {
return std::nullopt;
}
auto transform = inputs[0]->GetTransform(entity) * //
matrix_ * //
inputs[0]->GetTransform(entity).Invert();
return coverage->TransformBounds(transform);
}
} // namespace impeller