Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ TEST_P(AiksTest, PaintWithFilters) {

ASSERT_TRUE(paint.HasColorFilter());

paint.color_filter = std::nullopt;
paint.color_filter = nullptr;

ASSERT_FALSE(paint.HasColorFilter());
}
Expand All @@ -1963,7 +1963,7 @@ TEST_P(AiksTest, OpacityPeepHoleApplicationTest) {
auto delegate = std::make_shared<OpacityPeepholePassDelegate>(paint, rect);
ASSERT_FALSE(delegate->CanCollapseIntoParentPass(entity_pass.get()));

paint.color_filter = std::nullopt;
paint.color_filter = nullptr;
paint.image_filter = [](const FilterInput::Ref& input,
const Matrix& effect_transform, bool is_subpass) {
return FilterContents::MakeGaussianBlur(
Expand All @@ -1975,7 +1975,7 @@ TEST_P(AiksTest, OpacityPeepHoleApplicationTest) {
delegate = std::make_shared<OpacityPeepholePassDelegate>(paint, rect);
ASSERT_FALSE(delegate->CanCollapseIntoParentPass(entity_pass.get()));

paint.image_filter = std::nullopt;
paint.image_filter = nullptr;
paint.color = Color::Red();

// Paint has no alpha, can't elide;
Expand Down
13 changes: 6 additions & 7 deletions impeller/aiks/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ std::shared_ptr<Contents> Paint::WithImageFilter(
std::shared_ptr<Contents> input,
const Matrix& effect_transform,
bool is_subpass) const {
if (image_filter.has_value()) {
const ImageFilterProc& filter = image_filter.value();
input = filter(FilterInput::Make(input), effect_transform, is_subpass);
if (image_filter) {
input =
image_filter(FilterInput::Make(input), effect_transform, is_subpass);
}
return input;
}
Expand All @@ -89,9 +89,8 @@ std::shared_ptr<Contents> Paint::WithColorFilter(
if (color_source.GetType() == ColorSource::Type::kImage) {
return input;
}
if (color_filter.has_value()) {
const ColorFilterProc& filter = color_filter.value();
auto color_filter_contents = filter(FilterInput::Make(input));
if (color_filter) {
auto color_filter_contents = color_filter(FilterInput::Make(input));
if (color_filter_contents) {
color_filter_contents->SetAbsorbOpacity(absorb_opacity);
}
Expand Down Expand Up @@ -166,7 +165,7 @@ std::shared_ptr<FilterContents> Paint::MaskBlurDescriptor::CreateMaskBlur(
}

bool Paint::HasColorFilter() const {
return color_filter.has_value();
return !!color_filter;
}

} // namespace impeller
4 changes: 2 additions & 2 deletions impeller/aiks/paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ struct Paint {
BlendMode blend_mode = BlendMode::kSourceOver;
bool invert_colors = false;

std::optional<ImageFilterProc> image_filter;
std::optional<ColorFilterProc> color_filter;
ImageFilterProc image_filter = nullptr;
ColorFilterProc color_filter = nullptr;
std::optional<MaskBlurDescriptor> mask_blur_descriptor;

/// @brief Wrap this paint's configured filters to the given contents.
Expand Down
2 changes: 1 addition & 1 deletion impeller/aiks/paint_pass_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool OpacityPeepholePassDelegate::CanCollapseIntoParentPass(
// OpacityPeepholePassDelegate will only get used if the pass's blend mode is
// SourceOver, so no need to check here.
if (paint_.color.alpha <= 0.0 || paint_.color.alpha >= 1.0 ||
paint_.image_filter.has_value() || paint_.color_filter.has_value()) {
paint_.image_filter || paint_.color_filter) {
return false;
}

Expand Down
39 changes: 19 additions & 20 deletions impeller/display_list/dl_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ void DlDispatcher::setColorSource(const flutter::DlColorSource* source) {
}
}

static std::optional<Paint::ColorFilterProc> ToColorFilterProc(
static Paint::ColorFilterProc ToColorFilterProc(
const flutter::DlColorFilter* filter) {
if (filter == nullptr) {
return std::nullopt;
return nullptr;
}
switch (filter->type()) {
case flutter::DlColorFilterType::kBlend: {
Expand Down Expand Up @@ -507,7 +507,7 @@ static std::optional<Paint::ColorFilterProc> ToColorFilterProc(
return ColorFilterContents::MakeLinearToSrgbFilter({std::move(input)});
};
}
return std::nullopt;
return nullptr;
}

// |flutter::DlOpReceiver|
Expand Down Expand Up @@ -565,10 +565,10 @@ void DlDispatcher::setMaskFilter(const flutter::DlMaskFilter* filter) {
}
}

static std::optional<Paint::ImageFilterProc> ToImageFilterProc(
static Paint::ImageFilterProc ToImageFilterProc(
const flutter::DlImageFilter* filter) {
if (filter == nullptr) {
return std::nullopt;
return nullptr;
}

switch (filter->type()) {
Expand All @@ -592,7 +592,7 @@ static std::optional<Paint::ImageFilterProc> ToImageFilterProc(
auto dilate = filter->asDilate();
FML_DCHECK(dilate);
if (dilate->radius_x() < 0 || dilate->radius_y() < 0) {
return std::nullopt;
return nullptr;
}
auto radius_x = Radius(dilate->radius_x());
auto radius_y = Radius(dilate->radius_y());
Expand All @@ -609,7 +609,7 @@ static std::optional<Paint::ImageFilterProc> ToImageFilterProc(
auto erode = filter->asErode();
FML_DCHECK(erode);
if (erode->radius_x() < 0 || erode->radius_y() < 0) {
return std::nullopt;
return nullptr;
}
auto radius_x = Radius(erode->radius_x());
auto radius_y = Radius(erode->radius_y());
Expand Down Expand Up @@ -641,17 +641,16 @@ static std::optional<Paint::ImageFilterProc> ToImageFilterProc(
auto inner = compose->inner();
auto outer_proc = ToImageFilterProc(outer.get());
auto inner_proc = ToImageFilterProc(inner.get());
if (!outer_proc.has_value()) {
if (!outer_proc) {
return inner_proc;
}
if (!inner_proc.has_value()) {
if (!inner_proc) {
return outer_proc;
}
FML_DCHECK(outer_proc.has_value() && inner_proc.has_value());
return [outer_filter = outer_proc.value(),
inner_filter = inner_proc.value()](FilterInput::Ref input,
const Matrix& effect_transform,
bool is_subpass) {
FML_DCHECK(outer_proc && inner_proc);
return [outer_filter = outer_proc, inner_filter = inner_proc](
FilterInput::Ref input, const Matrix& effect_transform,
bool is_subpass) {
auto contents =
inner_filter(std::move(input), effect_transform, is_subpass);
contents = outer_filter(FilterInput::Make(contents), effect_transform,
Expand All @@ -665,10 +664,10 @@ static std::optional<Paint::ImageFilterProc> ToImageFilterProc(
FML_DCHECK(color_filter_image_filter);
auto color_filter_proc =
ToColorFilterProc(color_filter_image_filter->color_filter().get());
if (!color_filter_proc.has_value()) {
return std::nullopt;
if (!color_filter_proc) {
return nullptr;
}
return [color_filter = color_filter_proc.value()](
return [color_filter = color_filter_proc](
FilterInput::Ref input, const Matrix& effect_transform,
bool is_subpass) { return color_filter(std::move(input)); };
break;
Expand All @@ -680,13 +679,13 @@ static std::optional<Paint::ImageFilterProc> ToImageFilterProc(
FML_DCHECK(internal_filter);

auto image_filter_proc = ToImageFilterProc(internal_filter.get());
if (!image_filter_proc.has_value()) {
return std::nullopt;
if (!image_filter_proc) {
return nullptr;
}

auto matrix = ToMatrix(local_matrix_filter->matrix());

return [matrix, filter_proc = image_filter_proc.value()](
return [matrix, filter_proc = image_filter_proc](
FilterInput::Ref input, const Matrix& effect_transform,
bool is_subpass) {
std::shared_ptr<FilterContents> filter =
Expand Down
9 changes: 4 additions & 5 deletions impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,10 @@ bool AtlasColorContents::Render(const ContentContext& renderer,
std::vector<Rect> texture_coords;
std::vector<Matrix> transforms;
std::vector<Color> colors;
if (subatlas_.has_value()) {
auto subatlas = subatlas_.value();
texture_coords = subatlas->sub_texture_coords;
colors = subatlas->sub_colors;
transforms = subatlas->sub_transforms;
if (subatlas_) {
texture_coords = subatlas_->sub_texture_coords;
colors = subatlas_->sub_colors;
transforms = subatlas_->sub_transforms;
} else {
texture_coords = parent_.GetTextureCoordinates();
transforms = parent_.GetTransforms();
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/atlas_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class AtlasColorContents final : public Contents {
const AtlasContents& parent_;
Scalar alpha_ = 1.0;
Rect coverage_;
std::optional<std::shared_ptr<SubAtlasResult>> subatlas_ = std::nullopt;
std::shared_ptr<SubAtlasResult> subatlas_;

FML_DISALLOW_COPY_AND_ASSIGN(AtlasColorContents);
};
Expand Down
23 changes: 10 additions & 13 deletions impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,16 @@ void TiledTextureContents::SetSamplerDescriptor(SamplerDescriptor desc) {
sampler_descriptor_ = std::move(desc);
}

void TiledTextureContents::SetColorFilter(
std::optional<ColorFilterProc> color_filter) {
void TiledTextureContents::SetColorFilter(ColorFilterProc color_filter) {
color_filter_ = std::move(color_filter);
}

std::optional<std::shared_ptr<Texture>>
TiledTextureContents::CreateFilterTexture(
std::shared_ptr<Texture> TiledTextureContents::CreateFilterTexture(
const ContentContext& renderer) const {
if (!color_filter_.has_value()) {
return std::nullopt;
if (!color_filter_) {
return nullptr;
}
const ColorFilterProc& filter = color_filter_.value();
auto color_filter_contents = filter(FilterInput::Make(texture_));
auto color_filter_contents = color_filter_(FilterInput::Make(texture_));
auto snapshot = color_filter_contents->RenderToSnapshot(
renderer, // renderer
Entity(), // entity
Expand All @@ -78,7 +75,7 @@ TiledTextureContents::CreateFilterTexture(
if (snapshot.has_value()) {
return snapshot.value().texture;
}
return std::nullopt;
return nullptr;
}

SamplerDescriptor TiledTextureContents::CreateDescriptor(
Expand Down Expand Up @@ -107,7 +104,7 @@ bool TiledTextureContents::IsOpaque() const {
y_tile_mode_ == Entity::TileMode::kDecal) {
return false;
}
if (color_filter_.has_value()) {
if (color_filter_) {
return false;
}
return texture_->IsOpaque();
Expand Down Expand Up @@ -170,13 +167,13 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
cmd, host_buffer.EmplaceUniform(frag_info));
}

if (color_filter_.has_value()) {
if (color_filter_) {
auto filtered_texture = CreateFilterTexture(renderer);
if (!filtered_texture.has_value()) {
if (!filtered_texture) {
return false;
}
FS::BindTextureSampler(
cmd, filtered_texture.value(),
cmd, filtered_texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
CreateDescriptor(renderer.GetDeviceCapabilities())));
} else {
Expand Down
6 changes: 3 additions & 3 deletions impeller/entity/contents/tiled_texture_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TiledTextureContents final : public ColorSourceContents {
///
/// This may not be a performance improvement if the image is tiled into a
/// much smaller size that its original texture size.
void SetColorFilter(std::optional<ColorFilterProc> color_filter);
void SetColorFilter(ColorFilterProc color_filter);

// |Contents|
std::optional<Snapshot> RenderToSnapshot(
Expand All @@ -63,7 +63,7 @@ class TiledTextureContents final : public ColorSourceContents {
const std::string& label = "Tiled Texture Snapshot") const override;

private:
std::optional<std::shared_ptr<Texture>> CreateFilterTexture(
std::shared_ptr<Texture> CreateFilterTexture(
const ContentContext& renderer) const;

SamplerDescriptor CreateDescriptor(const Capabilities& capabilities) const;
Expand All @@ -74,7 +74,7 @@ class TiledTextureContents final : public ColorSourceContents {
SamplerDescriptor sampler_descriptor_ = {};
Entity::TileMode x_tile_mode_ = Entity::TileMode::kClamp;
Entity::TileMode y_tile_mode_ = Entity::TileMode::kClamp;
std::optional<ColorFilterProc> color_filter_;
ColorFilterProc color_filter_ = nullptr;

FML_DISALLOW_COPY_AND_ASSIGN(TiledTextureContents);
};
Expand Down
16 changes: 8 additions & 8 deletions lib/ui/painting/image_decoder_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ DecompressResult ImageDecoderImpeller::DecompressTexture(

if (bitmap->dimensions() == target_size) {
auto buffer = bitmap_allocator->GetDeviceBuffer();
if (!buffer.has_value()) {
if (!buffer) {
return DecompressResult{.decode_error = "Unable to get device buffer"};
}
return DecompressResult{.device_buffer = buffer.value(),
return DecompressResult{.device_buffer = buffer,
.sk_bitmap = bitmap,
.image_info = bitmap->info()};
}
Expand Down Expand Up @@ -240,10 +240,10 @@ DecompressResult ImageDecoderImpeller::DecompressTexture(
scaled_bitmap->setImmutable();

auto buffer = scaled_allocator->GetDeviceBuffer();
if (!buffer.has_value()) {
if (!buffer) {
return DecompressResult{.decode_error = "Unable to get device buffer"};
}
return DecompressResult{.device_buffer = buffer.value(),
return DecompressResult{.device_buffer = buffer,
.sk_bitmap = scaled_bitmap,
.image_info = scaled_bitmap->info()};
}
Expand Down Expand Up @@ -508,10 +508,10 @@ ImpellerAllocator::ImpellerAllocator(
std::shared_ptr<impeller::Allocator> allocator)
: allocator_(std::move(allocator)) {}

std::optional<std::shared_ptr<impeller::DeviceBuffer>>
ImpellerAllocator::GetDeviceBuffer() const {
if (buffer_.has_value()) {
buffer_.value()->Flush();
std::shared_ptr<impeller::DeviceBuffer> ImpellerAllocator::GetDeviceBuffer()
const {
if (buffer_) {
buffer_->Flush();
}
return buffer_;
}
Expand Down
5 changes: 2 additions & 3 deletions lib/ui/painting/image_decoder_impeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ class ImpellerAllocator : public SkBitmap::Allocator {
// |Allocator|
bool allocPixelRef(SkBitmap* bitmap) override;

std::optional<std::shared_ptr<impeller::DeviceBuffer>> GetDeviceBuffer()
const;
std::shared_ptr<impeller::DeviceBuffer> GetDeviceBuffer() const;

private:
std::shared_ptr<impeller::Allocator> allocator_;
std::optional<std::shared_ptr<impeller::DeviceBuffer>> buffer_;
std::shared_ptr<impeller::DeviceBuffer> buffer_;
};

struct DecompressResult {
Expand Down