From 022e2ec22b41d63ee50ddc2042ae329ef5bfb5e1 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Thu, 29 Jun 2023 13:58:53 -0700 Subject: [PATCH] [Impeller] Remove all double empties --- impeller/aiks/aiks_unittests.cc | 6 +-- impeller/aiks/paint.cc | 13 +++---- impeller/aiks/paint.h | 4 +- impeller/aiks/paint_pass_delegate.cc | 2 +- impeller/display_list/dl_dispatcher.cc | 39 +++++++++---------- impeller/entity/contents/atlas_contents.cc | 9 ++--- impeller/entity/contents/atlas_contents.h | 2 +- .../entity/contents/tiled_texture_contents.cc | 23 +++++------ .../entity/contents/tiled_texture_contents.h | 6 +-- lib/ui/painting/image_decoder_impeller.cc | 16 ++++---- lib/ui/painting/image_decoder_impeller.h | 5 +-- 11 files changed, 59 insertions(+), 66 deletions(-) diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 0c13711c27f61..709dc2eb9de95 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -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()); } @@ -1963,7 +1963,7 @@ TEST_P(AiksTest, OpacityPeepHoleApplicationTest) { auto delegate = std::make_shared(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( @@ -1975,7 +1975,7 @@ TEST_P(AiksTest, OpacityPeepHoleApplicationTest) { delegate = std::make_shared(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; diff --git a/impeller/aiks/paint.cc b/impeller/aiks/paint.cc index 3a921289ccdd9..c9dfc31d1dacf 100644 --- a/impeller/aiks/paint.cc +++ b/impeller/aiks/paint.cc @@ -74,9 +74,9 @@ std::shared_ptr Paint::WithImageFilter( std::shared_ptr 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; } @@ -89,9 +89,8 @@ std::shared_ptr 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); } @@ -166,7 +165,7 @@ std::shared_ptr Paint::MaskBlurDescriptor::CreateMaskBlur( } bool Paint::HasColorFilter() const { - return color_filter.has_value(); + return !!color_filter; } } // namespace impeller diff --git a/impeller/aiks/paint.h b/impeller/aiks/paint.h index b1f793905c8de..c355cf26a0037 100644 --- a/impeller/aiks/paint.h +++ b/impeller/aiks/paint.h @@ -61,8 +61,8 @@ struct Paint { BlendMode blend_mode = BlendMode::kSourceOver; bool invert_colors = false; - std::optional image_filter; - std::optional color_filter; + ImageFilterProc image_filter = nullptr; + ColorFilterProc color_filter = nullptr; std::optional mask_blur_descriptor; /// @brief Wrap this paint's configured filters to the given contents. diff --git a/impeller/aiks/paint_pass_delegate.cc b/impeller/aiks/paint_pass_delegate.cc index baf550d3fe127..8f6867b379396 100644 --- a/impeller/aiks/paint_pass_delegate.cc +++ b/impeller/aiks/paint_pass_delegate.cc @@ -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; } diff --git a/impeller/display_list/dl_dispatcher.cc b/impeller/display_list/dl_dispatcher.cc index ec9fa3021a37f..041423ce770a1 100644 --- a/impeller/display_list/dl_dispatcher.cc +++ b/impeller/display_list/dl_dispatcher.cc @@ -474,10 +474,10 @@ void DlDispatcher::setColorSource(const flutter::DlColorSource* source) { } } -static std::optional ToColorFilterProc( +static Paint::ColorFilterProc ToColorFilterProc( const flutter::DlColorFilter* filter) { if (filter == nullptr) { - return std::nullopt; + return nullptr; } switch (filter->type()) { case flutter::DlColorFilterType::kBlend: { @@ -507,7 +507,7 @@ static std::optional ToColorFilterProc( return ColorFilterContents::MakeLinearToSrgbFilter({std::move(input)}); }; } - return std::nullopt; + return nullptr; } // |flutter::DlOpReceiver| @@ -565,10 +565,10 @@ void DlDispatcher::setMaskFilter(const flutter::DlMaskFilter* filter) { } } -static std::optional ToImageFilterProc( +static Paint::ImageFilterProc ToImageFilterProc( const flutter::DlImageFilter* filter) { if (filter == nullptr) { - return std::nullopt; + return nullptr; } switch (filter->type()) { @@ -592,7 +592,7 @@ static std::optional 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()); @@ -609,7 +609,7 @@ static std::optional 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()); @@ -641,17 +641,16 @@ static std::optional 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, @@ -665,10 +664,10 @@ static std::optional 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; @@ -680,13 +679,13 @@ static std::optional 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 filter = diff --git a/impeller/entity/contents/atlas_contents.cc b/impeller/entity/contents/atlas_contents.cc index 930012b592282..b88fee0c20561 100644 --- a/impeller/entity/contents/atlas_contents.cc +++ b/impeller/entity/contents/atlas_contents.cc @@ -389,11 +389,10 @@ bool AtlasColorContents::Render(const ContentContext& renderer, std::vector texture_coords; std::vector transforms; std::vector 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(); diff --git a/impeller/entity/contents/atlas_contents.h b/impeller/entity/contents/atlas_contents.h index 44a31e12be215..76e102e17924a 100644 --- a/impeller/entity/contents/atlas_contents.h +++ b/impeller/entity/contents/atlas_contents.h @@ -149,7 +149,7 @@ class AtlasColorContents final : public Contents { const AtlasContents& parent_; Scalar alpha_ = 1.0; Rect coverage_; - std::optional> subatlas_ = std::nullopt; + std::shared_ptr subatlas_; FML_DISALLOW_COPY_AND_ASSIGN(AtlasColorContents); }; diff --git a/impeller/entity/contents/tiled_texture_contents.cc b/impeller/entity/contents/tiled_texture_contents.cc index d2d9ee02f3d8d..2f2874dd3350f 100644 --- a/impeller/entity/contents/tiled_texture_contents.cc +++ b/impeller/entity/contents/tiled_texture_contents.cc @@ -55,19 +55,16 @@ void TiledTextureContents::SetSamplerDescriptor(SamplerDescriptor desc) { sampler_descriptor_ = std::move(desc); } -void TiledTextureContents::SetColorFilter( - std::optional color_filter) { +void TiledTextureContents::SetColorFilter(ColorFilterProc color_filter) { color_filter_ = std::move(color_filter); } -std::optional> -TiledTextureContents::CreateFilterTexture( +std::shared_ptr 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 @@ -78,7 +75,7 @@ TiledTextureContents::CreateFilterTexture( if (snapshot.has_value()) { return snapshot.value().texture; } - return std::nullopt; + return nullptr; } SamplerDescriptor TiledTextureContents::CreateDescriptor( @@ -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(); @@ -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 { diff --git a/impeller/entity/contents/tiled_texture_contents.h b/impeller/entity/contents/tiled_texture_contents.h index 589f5e2b08b2b..f027c057915a3 100644 --- a/impeller/entity/contents/tiled_texture_contents.h +++ b/impeller/entity/contents/tiled_texture_contents.h @@ -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 color_filter); + void SetColorFilter(ColorFilterProc color_filter); // |Contents| std::optional RenderToSnapshot( @@ -63,7 +63,7 @@ class TiledTextureContents final : public ColorSourceContents { const std::string& label = "Tiled Texture Snapshot") const override; private: - std::optional> CreateFilterTexture( + std::shared_ptr CreateFilterTexture( const ContentContext& renderer) const; SamplerDescriptor CreateDescriptor(const Capabilities& capabilities) const; @@ -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 color_filter_; + ColorFilterProc color_filter_ = nullptr; FML_DISALLOW_COPY_AND_ASSIGN(TiledTextureContents); }; diff --git a/lib/ui/painting/image_decoder_impeller.cc b/lib/ui/painting/image_decoder_impeller.cc index c0776b0caa35e..37f025b7d5061 100644 --- a/lib/ui/painting/image_decoder_impeller.cc +++ b/lib/ui/painting/image_decoder_impeller.cc @@ -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()}; } @@ -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()}; } @@ -508,10 +508,10 @@ ImpellerAllocator::ImpellerAllocator( std::shared_ptr allocator) : allocator_(std::move(allocator)) {} -std::optional> -ImpellerAllocator::GetDeviceBuffer() const { - if (buffer_.has_value()) { - buffer_.value()->Flush(); +std::shared_ptr ImpellerAllocator::GetDeviceBuffer() + const { + if (buffer_) { + buffer_->Flush(); } return buffer_; } diff --git a/lib/ui/painting/image_decoder_impeller.h b/lib/ui/painting/image_decoder_impeller.h index 595acd652f055..f3e350bd30a37 100644 --- a/lib/ui/painting/image_decoder_impeller.h +++ b/lib/ui/painting/image_decoder_impeller.h @@ -29,12 +29,11 @@ class ImpellerAllocator : public SkBitmap::Allocator { // |Allocator| bool allocPixelRef(SkBitmap* bitmap) override; - std::optional> GetDeviceBuffer() - const; + std::shared_ptr GetDeviceBuffer() const; private: std::shared_ptr allocator_; - std::optional> buffer_; + std::shared_ptr buffer_; }; struct DecompressResult {