[Impeller] delete impeller image class. (flutter/engine#54767)

This class does nothing but wrap impeller::Texture. Lets just use impeller::Texture.
This commit is contained in:
Jonah Williams
2024-08-25 17:20:32 -07:00
committed by GitHub
parent 85442ec532
commit 5cfb3bbf9d
18 changed files with 42 additions and 114 deletions

View File

@@ -42629,8 +42629,6 @@ ORIGIN: ../../../flutter/impeller/aiks/color_source.cc + ../../../flutter/LICENS
ORIGIN: ../../../flutter/impeller/aiks/color_source.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/experimental_canvas.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/experimental_canvas.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/image.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/image.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/image_filter.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/image_filter.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/paint.cc + ../../../flutter/LICENSE
@@ -45518,8 +45516,6 @@ FILE: ../../../flutter/impeller/aiks/color_source.cc
FILE: ../../../flutter/impeller/aiks/color_source.h
FILE: ../../../flutter/impeller/aiks/experimental_canvas.cc
FILE: ../../../flutter/impeller/aiks/experimental_canvas.h
FILE: ../../../flutter/impeller/aiks/image.cc
FILE: ../../../flutter/impeller/aiks/image.h
FILE: ../../../flutter/impeller/aiks/image_filter.cc
FILE: ../../../flutter/impeller/aiks/image_filter.h
FILE: ../../../flutter/impeller/aiks/paint.cc

View File

@@ -118,9 +118,8 @@ sk_sp<DlImage> DlMetalSurfaceProvider::MakeImpellerImage(
flutter::DlBlendMode::kSrc);
list->Dispatch(dispatcher);
auto picture = dispatcher.EndRecordingAsPicture();
std::shared_ptr<impeller::Image> image =
std::shared_ptr<impeller::Texture> texture =
picture.ToImage(*aiks_context_, {width, height});
std::shared_ptr<impeller::Texture> texture = image->GetTexture();
return impeller::DlImageImpeller::Make(texture);
#endif // EXPERIMENTAL_CANVAS

View File

@@ -16,8 +16,6 @@ impeller_component("aiks") {
"color_source.h",
"experimental_canvas.cc",
"experimental_canvas.h",
"image.cc",
"image.h",
"image_filter.cc",
"image_filter.h",
"paint.cc",

View File

@@ -84,7 +84,7 @@ TEST_P(AiksTest, ColorWheel) {
}
};
std::shared_ptr<Image> color_wheel_image;
std::shared_ptr<Texture> color_wheel_image;
Matrix color_wheel_transform;
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
@@ -131,7 +131,7 @@ TEST_P(AiksTest, ColorWheel) {
if (!snapshot.has_value() || !snapshot->texture) {
return std::nullopt;
}
color_wheel_image = std::make_shared<Image>(snapshot->texture);
color_wheel_image = snapshot->texture;
color_wheel_transform = snapshot->transform;
}

View File

@@ -16,7 +16,6 @@
#include "gtest/gtest.h"
#include "impeller/aiks/canvas.h"
#include "impeller/aiks/color_filter.h"
#include "impeller/aiks/image.h"
#include "impeller/aiks/image_filter.h"
#include "impeller/aiks/testing/context_spy.h"
#include "impeller/core/device_buffer.h"
@@ -126,7 +125,7 @@ TEST_P(AiksTest, DrawPaintAbsorbsClears) {
std::shared_ptr<Context> real_context = GetContext();
std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
AiksContext renderer(mock_context, nullptr);
std::shared_ptr<Image> image = picture.ToImage(renderer, {300, 300});
std::shared_ptr<Texture> image = picture.ToImage(renderer, {300, 300});
ASSERT_EQ(spy->render_passes_.size(), 1llu);
std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
@@ -150,7 +149,7 @@ TEST_P(AiksTest,
std::shared_ptr<Context> real_context = GetContext();
std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
AiksContext renderer(mock_context, nullptr);
std::shared_ptr<Image> image = picture.ToImage(renderer, {300, 300});
std::shared_ptr<Texture> image = picture.ToImage(renderer, {300, 300});
ASSERT_EQ(spy->render_passes_.size(),
GetBackend() == PlaygroundBackend::kOpenGLES ? 4llu : 3llu);
@@ -171,7 +170,7 @@ TEST_P(AiksTest, DrawRectAbsorbsClears) {
std::shared_ptr<Context> real_context = GetContext();
std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
AiksContext renderer(mock_context, nullptr);
std::shared_ptr<Image> image = picture.ToImage(renderer, {300, 300});
std::shared_ptr<Texture> image = picture.ToImage(renderer, {300, 300});
ASSERT_EQ(spy->render_passes_.size(), 1llu);
std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
@@ -191,7 +190,7 @@ TEST_P(AiksTest, DrawRectAbsorbsClearsNegativeRRect) {
std::shared_ptr<Context> real_context = GetContext();
std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
AiksContext renderer(mock_context, nullptr);
std::shared_ptr<Image> image = picture.ToImage(renderer, {300, 300});
std::shared_ptr<Texture> image = picture.ToImage(renderer, {300, 300});
ASSERT_EQ(spy->render_passes_.size(), 1llu);
std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
@@ -211,7 +210,7 @@ TEST_P(AiksTest, DrawRectAbsorbsClearsNegativeRotation) {
std::shared_ptr<Context> real_context = GetContext();
std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
AiksContext renderer(mock_context, nullptr);
std::shared_ptr<Image> image = picture.ToImage(renderer, {300, 300});
std::shared_ptr<Texture> image = picture.ToImage(renderer, {300, 300});
ASSERT_EQ(spy->render_passes_.size(), 1llu);
std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
@@ -231,7 +230,7 @@ TEST_P(AiksTest, DrawRectAbsorbsClearsNegative) {
std::shared_ptr<Context> real_context = GetContext();
std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
AiksContext renderer(mock_context, nullptr);
std::shared_ptr<Image> image = picture.ToImage(renderer, {301, 301});
std::shared_ptr<Texture> image = picture.ToImage(renderer, {301, 301});
ASSERT_EQ(spy->render_passes_.size(), 1llu);
std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
@@ -255,7 +254,7 @@ TEST_P(AiksTest, ClipRectElidesNoOpClips) {
std::shared_ptr<Context> real_context = GetContext();
std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
AiksContext renderer(mock_context, nullptr);
std::shared_ptr<Image> image = picture.ToImage(renderer, {300, 300});
std::shared_ptr<Texture> image = picture.ToImage(renderer, {300, 300});
ASSERT_EQ(spy->render_passes_.size(), 1llu);
std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];

View File

@@ -719,7 +719,7 @@ void Canvas::DrawPoints(std::vector<Point> points,
AddRenderEntityToCurrentPass(std::move(entity));
}
void Canvas::DrawImage(const std::shared_ptr<Image>& image,
void Canvas::DrawImage(const std::shared_ptr<Texture>& image,
Point offset,
const Paint& paint,
SamplerDescriptor sampler) {
@@ -733,7 +733,7 @@ void Canvas::DrawImage(const std::shared_ptr<Image>& image,
DrawImageRect(image, source, dest, paint, std::move(sampler));
}
void Canvas::DrawImageRect(const std::shared_ptr<Image>& image,
void Canvas::DrawImageRect(const std::shared_ptr<Texture>& image,
Rect source,
Rect dest,
const Paint& paint,
@@ -750,7 +750,7 @@ void Canvas::DrawImageRect(const std::shared_ptr<Image>& image,
}
auto texture_contents = TextureContents::MakeRect(dest);
texture_contents->SetTexture(image->GetTexture());
texture_contents->SetTexture(image);
texture_contents->SetSourceRect(source);
texture_contents->SetStrictSourceRect(src_rect_constraint ==
SourceRectConstraint::kStrict);
@@ -991,7 +991,7 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
AddRenderEntityToCurrentPass(std::move(entity));
}
void Canvas::DrawAtlas(const std::shared_ptr<Image>& atlas,
void Canvas::DrawAtlas(const std::shared_ptr<Texture>& atlas,
std::vector<Matrix> transforms,
std::vector<Rect> texture_coordinates,
std::vector<Color> colors,
@@ -1007,7 +1007,7 @@ void Canvas::DrawAtlas(const std::shared_ptr<Image>& atlas,
contents->SetColors(std::move(colors));
contents->SetTransforms(std::move(transforms));
contents->SetTextureCoordinates(std::move(texture_coordinates));
contents->SetTexture(atlas->GetTexture());
contents->SetTexture(atlas);
contents->SetSamplerDescriptor(std::move(sampler));
contents->SetBlendMode(blend_mode);
contents->SetCullRect(cull_rect);

View File

@@ -11,7 +11,6 @@
#include <optional>
#include <vector>
#include "impeller/aiks/image.h"
#include "impeller/aiks/image_filter.h"
#include "impeller/aiks/paint.h"
#include "impeller/aiks/picture.h"
@@ -129,13 +128,13 @@ class Canvas {
const Paint& paint,
PointStyle point_style);
void DrawImage(const std::shared_ptr<Image>& image,
void DrawImage(const std::shared_ptr<Texture>& image,
Point offset,
const Paint& paint,
SamplerDescriptor sampler = {});
void DrawImageRect(
const std::shared_ptr<Image>& image,
const std::shared_ptr<Texture>& image,
Rect source,
Rect dest,
const Paint& paint,
@@ -167,7 +166,7 @@ class Canvas {
BlendMode blend_mode,
const Paint& paint);
void DrawAtlas(const std::shared_ptr<Image>& atlas,
void DrawAtlas(const std::shared_ptr<Texture>& atlas,
std::vector<Matrix> transforms,
std::vector<Rect> texture_coordinates,
std::vector<Color> colors,

View File

@@ -1,21 +0,0 @@
// 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/aiks/image.h"
namespace impeller {
Image::Image(std::shared_ptr<Texture> texture) : texture_(std::move(texture)) {}
Image::~Image() = default;
ISize Image::GetSize() const {
return texture_ ? texture_->GetSize() : ISize{};
}
std::shared_ptr<Texture> Image::GetTexture() const {
return texture_;
}
} // namespace impeller

View File

@@ -1,34 +0,0 @@
// 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.
#ifndef FLUTTER_IMPELLER_AIKS_IMAGE_H_
#define FLUTTER_IMPELLER_AIKS_IMAGE_H_
#include <memory>
#include "impeller/core/texture.h"
namespace impeller {
class Image {
public:
explicit Image(std::shared_ptr<Texture> texture);
~Image();
ISize GetSize() const;
std::shared_ptr<Texture> GetTexture() const;
private:
const std::shared_ptr<Texture> texture_;
Image(const Image&) = delete;
Image& operator=(const Image&) = delete;
};
} // namespace impeller
#endif // FLUTTER_IMPELLER_AIKS_IMAGE_H_

View File

@@ -28,13 +28,12 @@ std::optional<Snapshot> Picture::Snapshot(AiksContext& context) {
.transform = Matrix::MakeTranslation(coverage->GetOrigin())};
}
std::shared_ptr<Image> Picture::ToImage(AiksContext& context,
ISize size) const {
std::shared_ptr<Texture> Picture::ToImage(AiksContext& context,
ISize size) const {
if (size.IsEmpty()) {
return nullptr;
}
auto texture = RenderToTexture(context, size);
return texture ? std::make_shared<Image>(texture) : nullptr;
return RenderToTexture(context, size);
}
std::shared_ptr<Texture> Picture::RenderToTexture(

View File

@@ -9,7 +9,6 @@
#include <optional>
#include "impeller/aiks/aiks_context.h"
#include "impeller/aiks/image.h"
#include "impeller/entity/entity_pass.h"
namespace impeller {
@@ -19,7 +18,7 @@ struct Picture {
std::optional<Snapshot> Snapshot(AiksContext& context);
std::shared_ptr<Image> ToImage(AiksContext& context, ISize size) const;
std::shared_ptr<Texture> ToImage(AiksContext& context, ISize size) const;
private:
std::shared_ptr<Texture> RenderToTexture(

View File

@@ -1017,12 +1017,11 @@ void DlDispatcherBase::drawImageRect(
flutter::DlImageSampling sampling,
bool render_with_attributes,
SrcRectConstraint constraint = SrcRectConstraint::kFast) {
GetCanvas().DrawImageRect(
std::make_shared<Image>(image->impeller_texture()), // image
skia_conversions::ToRect(src), // source rect
skia_conversions::ToRect(dst), // destination rect
render_with_attributes ? paint_ : Paint(), // paint
ToSamplerDescriptor(sampling) // sampling
GetCanvas().DrawImageRect(image->impeller_texture(), // image
skia_conversions::ToRect(src), // source rect
skia_conversions::ToRect(dst), // destination rect
render_with_attributes ? paint_ : Paint(), // paint
ToSamplerDescriptor(sampling) // sampling
);
}
@@ -1034,7 +1033,7 @@ void DlDispatcherBase::drawImageNine(const sk_sp<flutter::DlImage> image,
bool render_with_attributes) {
NinePatchConverter converter = {};
converter.DrawNinePatch(
std::make_shared<Image>(image->impeller_texture()),
image->impeller_texture(),
Rect::MakeLTRB(center.fLeft, center.fTop, center.fRight, center.fBottom),
skia_conversions::ToRect(dst), ToSamplerDescriptor(filter), &GetCanvas(),
&paint_);
@@ -1050,12 +1049,11 @@ void DlDispatcherBase::drawAtlas(const sk_sp<flutter::DlImage> atlas,
flutter::DlImageSampling sampling,
const SkRect* cull_rect,
bool render_with_attributes) {
GetCanvas().DrawAtlas(std::make_shared<Image>(atlas->impeller_texture()),
skia_conversions::ToRSXForms(xform, count),
skia_conversions::ToRects(tex, count),
ToColors(colors, count), ToBlendMode(mode),
ToSamplerDescriptor(sampling),
skia_conversions::ToRect(cull_rect), paint_);
GetCanvas().DrawAtlas(
atlas->impeller_texture(), skia_conversions::ToRSXForms(xform, count),
skia_conversions::ToRects(tex, count), ToColors(colors, count),
ToBlendMode(mode), ToSamplerDescriptor(sampling),
skia_conversions::ToRect(cull_rect), paint_);
}
// |flutter::DlOpReceiver|

View File

@@ -57,7 +57,7 @@ std::vector<double> NinePatchConverter::InitSlices(double img0,
// clang-format on
}
void NinePatchConverter::DrawNinePatch(const std::shared_ptr<Image>& image,
void NinePatchConverter::DrawNinePatch(const std::shared_ptr<Texture>& image,
Rect center,
Rect dst,
const SamplerDescriptor& sampler,

View File

@@ -8,7 +8,6 @@
#include <memory>
#include "impeller/aiks/canvas.h"
#include "impeller/aiks/image.h"
#include "impeller/aiks/paint.h"
#include "impeller/core/sampler_descriptor.h"
@@ -21,7 +20,7 @@ class NinePatchConverter {
~NinePatchConverter();
void DrawNinePatch(const std::shared_ptr<Image>& image,
void DrawNinePatch(const std::shared_ptr<Texture>& image,
Rect center,
Rect dst,
const SamplerDescriptor& sampler,

View File

@@ -27,11 +27,10 @@ std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(
bool scale_content) {
Vector2 content_scale =
scale_content ? playground_->GetContentScale() : Vector2{1, 1};
std::shared_ptr<Image> image = picture.ToImage(
std::shared_ptr<Texture> image = picture.ToImage(
aiks_context,
ISize(size.width * content_scale.x, size.height * content_scale.y));
std::shared_ptr<Texture> texture = image->GetTexture();
return MakeScreenshot(aiks_context, texture);
return MakeScreenshot(aiks_context, image);
}
std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(

View File

@@ -112,11 +112,10 @@ std::unique_ptr<Screenshot> VulkanScreenshotter::MakeScreenshot(
bool scale_content) {
Vector2 content_scale =
scale_content ? playground_->GetContentScale() : Vector2{1, 1};
std::shared_ptr<Image> image = picture.ToImage(
std::shared_ptr<Texture> image = picture.ToImage(
aiks_context,
ISize(size.width * content_scale.x, size.height * content_scale.y));
std::shared_ptr<Texture> texture = image->GetTexture();
return ReadTexture(aiks_context.GetContext(), texture);
return ReadTexture(aiks_context.GetContext(), image);
}
std::unique_ptr<Screenshot> VulkanScreenshotter::MakeScreenshot(

View File

@@ -935,10 +935,9 @@ ScreenshotLayerTreeAsImageImpeller(
impeller::DlDispatcher dispatcher;
builder.Build()->Dispatch(dispatcher);
const auto& picture = dispatcher.EndRecordingAsPicture();
const auto& image = picture.ToImage(
texture = picture.ToImage(
*aiks_context,
impeller::ISize(tree->frame_size().fWidth, tree->frame_size().fHeight));
texture = image->GetTexture();
#endif // EXPERIMENTAL_CANVAS
impeller::DeviceBufferDescriptor buffer_desc;

View File

@@ -92,10 +92,10 @@ sk_sp<DlImage> DoMakeRasterSnapshot(
display_list->Dispatch(dispatcher);
impeller::Picture picture = dispatcher.EndRecordingAsPicture();
std::shared_ptr<impeller::Image> image =
std::shared_ptr<impeller::Texture> image =
picture.ToImage(*context, render_target_size);
if (image) {
return impeller::DlImageImpeller::Make(image->GetTexture(),
return impeller::DlImageImpeller::Make(image,
DlImage::OwningContext::kRaster);
}
#endif // EXPERIMENTAL_CANVAS