[Impeller] Remove all double empties (flutter/engine#43345)
Unwrap optionals that already have an empty state that must be checked, like `std::optional<std::shared_ptr<T>>` and `std::optional<std::function<T>>`.
This commit is contained in:
@@ -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<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(
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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: {
|
||||
@@ -507,7 +507,7 @@ static std::optional<Paint::ColorFilterProc> 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<Paint::ImageFilterProc> 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<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());
|
||||
@@ -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());
|
||||
@@ -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,
|
||||
@@ -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;
|
||||
@@ -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 =
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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<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_;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user