Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7d18d70

Browse files
[Impeller] Support external textures on iOS (#36498)
1 parent 490b06d commit 7d18d70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+435
-211
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,8 +2407,10 @@ FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStan
24072407
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h
24082408
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_codecs_unittest.mm
24092409
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm
2410-
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h
2411-
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
2410+
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h
2411+
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm
2412+
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h
2413+
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm
24122414
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h
24132415
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm
24142416
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/Flutter.h

common/graphics/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ source_set("graphics") {
2121
# additions here could result in added app sizes across embeddings.
2222
deps = [
2323
"//flutter/assets",
24+
"//flutter/display_list",
2425
"//flutter/fml",
2526
"//flutter/shell/version:version",
2627
"//third_party/boringssl",

common/graphics/texture.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <map>
99

10+
#include "flutter/display_list/display_list_builder.h"
11+
#include "flutter/display_list/display_list_paint.h"
1012
#include "flutter/fml/macros.h"
1113
#include "flutter/fml/synchronization/waitable_event.h"
1214
#include "third_party/skia/include/core/SkCanvas.h"
@@ -33,16 +35,22 @@ class ContextListener {
3335

3436
class Texture : public ContextListener {
3537
public:
38+
struct PaintContext {
39+
SkCanvas* canvas = nullptr;
40+
DisplayListBuilder* builder = nullptr;
41+
GrDirectContext* gr_context = nullptr;
42+
const SkPaint* sk_paint = nullptr;
43+
const DlPaint* dl_paint = nullptr;
44+
};
45+
3646
explicit Texture(int64_t id); // Called from UI or raster thread.
3747
virtual ~Texture(); // Called from raster thread.
3848

3949
// Called from raster thread.
40-
virtual void Paint(SkCanvas& canvas,
50+
virtual void Paint(PaintContext& context,
4151
const SkRect& bounds,
4252
bool freeze,
43-
GrDirectContext* context,
44-
const SkSamplingOptions& sampling,
45-
const SkPaint* paint = nullptr) = 0;
53+
const SkSamplingOptions& sampling) = 0;
4654

4755
// Called on raster thread.
4856
virtual void MarkNewFrameAvailable() = 0;

flow/layers/texture_layer.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ void TextureLayer::Paint(PaintContext& context) const {
6262
return;
6363
}
6464
AutoCachePaint cache_paint(context);
65-
texture->Paint(*context.leaf_nodes_canvas, paint_bounds(), freeze_,
66-
context.gr_context, ToSk(sampling_), cache_paint.sk_paint());
65+
Texture::PaintContext ctx{
66+
.canvas = context.leaf_nodes_canvas,
67+
.builder = context.leaf_nodes_builder,
68+
.gr_context = context.gr_context,
69+
.sk_paint = cache_paint.sk_paint(),
70+
.dl_paint = cache_paint.dl_paint(),
71+
};
72+
texture->Paint(ctx, paint_bounds(), freeze_, ToSk(sampling_));
6773
}
6874

6975
} // namespace flutter

flow/testing/mock_texture.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
// found in the LICENSE file.
44

55
#include "flutter/flow/testing/mock_texture.h"
6+
#include "flutter/flow/layers/layer.h"
67
#include "flutter/flow/testing/skia_gpu_object_layer_test.h"
78

89
namespace flutter {
910
namespace testing {
1011

1112
MockTexture::MockTexture(int64_t textureId) : Texture(textureId) {}
1213

13-
void MockTexture::Paint(SkCanvas& canvas,
14+
void MockTexture::Paint(PaintContext& context,
1415
const SkRect& bounds,
1516
bool freeze,
16-
GrDirectContext* context,
17-
const SkSamplingOptions& sampling,
18-
const SkPaint* paint) {
19-
paint_calls_.emplace_back(
20-
PaintCall{canvas, bounds, freeze, context, sampling, paint});
17+
const SkSamplingOptions& sampling) {
18+
paint_calls_.emplace_back(PaintCall{*(context.canvas), bounds, freeze,
19+
context.gr_context, sampling,
20+
context.sk_paint});
2121
}
2222

2323
bool operator==(const MockTexture::PaintCall& a,

flow/testing/mock_texture.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ class MockTexture : public Texture {
2828
explicit MockTexture(int64_t textureId);
2929

3030
// Called from raster thread.
31-
void Paint(SkCanvas& canvas,
31+
void Paint(PaintContext& context,
3232
const SkRect& bounds,
3333
bool freeze,
34-
GrDirectContext* context,
35-
const SkSamplingOptions& sampling,
36-
const SkPaint* paint = nullptr) override;
34+
const SkSamplingOptions& sampling) override;
3735

3836
void OnGrContextCreated() override { gr_context_created_ = true; }
3937
void OnGrContextDestroyed() override { gr_context_destroyed_ = true; }

flow/testing/mock_texture_unittests.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ TEST(MockTextureTest, PaintCalls) {
3434
MockTexture::PaintCall{canvas, paint_bounds1, false, nullptr, sampling},
3535
MockTexture::PaintCall{canvas, paint_bounds2, true, nullptr, sampling}};
3636
auto texture = std::make_shared<MockTexture>(0);
37-
38-
texture->Paint(canvas, paint_bounds1, false, nullptr, sampling);
39-
texture->Paint(canvas, paint_bounds2, true, nullptr, sampling);
37+
Texture::PaintContext context{
38+
.canvas = &canvas,
39+
};
40+
texture->Paint(context, paint_bounds1, false, sampling);
41+
texture->Paint(context, paint_bounds2, true, sampling);
4042
EXPECT_EQ(texture->paint_calls(), expected_paint_calls);
4143
}
4244

@@ -49,9 +51,11 @@ TEST(MockTextureTest, PaintCallsWithLinearSampling) {
4951
MockTexture::PaintCall{canvas, paint_bounds1, false, nullptr, sampling},
5052
MockTexture::PaintCall{canvas, paint_bounds2, true, nullptr, sampling}};
5153
auto texture = std::make_shared<MockTexture>(0);
52-
53-
texture->Paint(canvas, paint_bounds1, false, nullptr, sampling);
54-
texture->Paint(canvas, paint_bounds2, true, nullptr, sampling);
54+
Texture::PaintContext context{
55+
.canvas = &canvas,
56+
};
57+
texture->Paint(context, paint_bounds1, false, sampling);
58+
texture->Paint(context, paint_bounds2, true, sampling);
5559
EXPECT_EQ(texture->paint_calls(), expected_paint_calls);
5660
}
5761

impeller/display_list/display_list_dispatcher.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ void DisplayListDispatcher::drawImageRect(
10711071
std::make_shared<Image>(image->impeller_texture()), // image
10721072
ToRect(src), // source rect
10731073
ToRect(dst), // destination rect
1074-
paint_, // paint
1074+
render_with_attributes ? paint_ : Paint(), // paint
10751075
ToSamplerDescriptor(sampling) // sampling
10761076
);
10771077
}

impeller/renderer/backend/metal/context_mtl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ namespace impeller {
2323
class ContextMTL final : public Context,
2424
public BackendCast<ContextMTL, Context> {
2525
public:
26-
static std::shared_ptr<Context> Create(
26+
static std::shared_ptr<ContextMTL> Create(
2727
const std::vector<std::string>& shader_library_paths);
2828

29-
static std::shared_ptr<Context> Create(
29+
static std::shared_ptr<ContextMTL> Create(
3030
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
3131
const std::string& label);
3232

impeller/renderer/backend/metal/context_mtl.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
return ::MTLCreateSystemDefaultDevice();
153153
}
154154

155-
std::shared_ptr<Context> ContextMTL::Create(
155+
std::shared_ptr<ContextMTL> ContextMTL::Create(
156156
const std::vector<std::string>& shader_library_paths) {
157157
auto device = CreateMetalDevice();
158158
auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
@@ -164,7 +164,7 @@
164164
return context;
165165
}
166166

167-
std::shared_ptr<Context> ContextMTL::Create(
167+
std::shared_ptr<ContextMTL> ContextMTL::Create(
168168
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
169169
const std::string& label) {
170170
auto device = CreateMetalDevice();

0 commit comments

Comments
 (0)