diff --git a/engine/src/flutter/ci/builders/mac_unopt.json b/engine/src/flutter/ci/builders/mac_unopt.json index 934cdf23b2..f8841ade4a 100644 --- a/engine/src/flutter/ci/builders/mac_unopt.json +++ b/engine/src/flutter/ci/builders/mac_unopt.json @@ -305,6 +305,87 @@ "script": "flutter/testing/scenario_app/run_ios_tests.sh" } ] + }, + { + "cas_archive": false, + "drone_dimensions": + [ + "os=Mac-13", + "device_type=none" + ], + "gclient_variables": + { + "download_android_deps": false, + "use_rbe": true + }, + "gn": + [ + "--ios", + "--runtime-mode", + "release", + "--no-stripped", + "--no-lto", + "--xcode-symlinks", + "--rbe", + "--no-goma", + "--slimpeller" + ], + "name": "ci/macos/ios_release_slimpeller", + "description": "Builds a Slimpeller release mode engine that targets iOS from a macOS host.", + "ninja": + { + "config": "ios_release_slimpeller", + "targets": + [] + }, + "properties": + { + "$flutter/osx_sdk": + { + "sdk_version": "15a240d" + } + } + }, + { + "cas_archive": false, + "drone_dimensions": + [ + "os=Mac-13", + "device_type=none" + ], + "gclient_variables": + { + "download_android_deps": false, + "use_rbe": true + }, + "gn": + [ + "--ios", + "--runtime-mode", + "debug", + "--unoptimized", + "--no-stripped", + "--no-lto", + "--xcode-symlinks", + "--rbe", + "--no-goma", + "--slimpeller" + ], + "name": "ci/macos/ios_debug_unopt_slimpeller", + "description": "Builds an unoptimized debug mode engine with Slimpeller that targets iOS from a macOS host.", + "ninja": + { + "config": "ios_debug_unopt_slimpeller", + "targets": + [] + }, + "properties": + { + "$flutter/osx_sdk": + { + "sdk_version": "15a240d" + } + } } ] } diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index f2ee74a6b9..b5e1ce6b66 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -39877,6 +39877,7 @@ ORIGIN: ../../../flutter/common/graphics/persistent_cache.cc + ../../../flutter/ ORIGIN: ../../../flutter/common/graphics/persistent_cache.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/common/graphics/texture.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/common/graphics/texture.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/common/macros.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/common/settings.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/common/settings.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/common/task_runners.cc + ../../../flutter/LICENSE @@ -42752,6 +42753,7 @@ FILE: ../../../flutter/common/graphics/persistent_cache.cc FILE: ../../../flutter/common/graphics/persistent_cache.h FILE: ../../../flutter/common/graphics/texture.cc FILE: ../../../flutter/common/graphics/texture.h +FILE: ../../../flutter/common/macros.h FILE: ../../../flutter/common/settings.cc FILE: ../../../flutter/common/settings.h FILE: ../../../flutter/common/task_runners.cc diff --git a/engine/src/flutter/common/BUILD.gn b/engine/src/flutter/common/BUILD.gn index c276e4dbea..5eecc637f9 100644 --- a/engine/src/flutter/common/BUILD.gn +++ b/engine/src/flutter/common/BUILD.gn @@ -10,6 +10,7 @@ config("flutter_config") { source_set("common") { sources = [ + "macros.h", "settings.cc", "settings.h", "task_runners.cc", diff --git a/engine/src/flutter/common/graphics/persistent_cache.cc b/engine/src/flutter/common/graphics/persistent_cache.cc index 0d24125d1f..1efd458f35 100644 --- a/engine/src/flutter/common/graphics/persistent_cache.cc +++ b/engine/src/flutter/common/graphics/persistent_cache.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/common/graphics/persistent_cache.h" #include @@ -483,3 +485,5 @@ PersistentCache::GetSkpsFromAssetManager() const { } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/common/graphics/persistent_cache.h b/engine/src/flutter/common/graphics/persistent_cache.h index 0b60091f0b..a216060fa6 100644 --- a/engine/src/flutter/common/graphics/persistent_cache.h +++ b/engine/src/flutter/common/graphics/persistent_cache.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_COMMON_GRAPHICS_PERSISTENT_CACHE_H_ #define FLUTTER_COMMON_GRAPHICS_PERSISTENT_CACHE_H_ +#if !SLIMPELLER + #include #include #include @@ -179,4 +181,6 @@ class PersistentCache : public GrContextOptions::PersistentCache { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_COMMON_GRAPHICS_PERSISTENT_CACHE_H_ diff --git a/engine/src/flutter/common/macros.h b/engine/src/flutter/common/macros.h new file mode 100644 index 0000000000..162e2652a2 --- /dev/null +++ b/engine/src/flutter/common/macros.h @@ -0,0 +1,20 @@ +// 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_COMMON_MACROS_H_ +#define FLUTTER_COMMON_MACROS_H_ + +#if SLIMPELLER + +#define ONLY_IN_SLIMPELLER(code) code +#define NOT_SLIMPELLER(code) + +#else // SLIMPELLER + +#define ONLY_IN_SLIMPELLER(code) +#define NOT_SLIMPELLER(code) code + +#endif // SLIMPELLER + +#endif // FLUTTER_COMMON_MACROS_H_ diff --git a/engine/src/flutter/display_list/skia/dl_sk_canvas.cc b/engine/src/flutter/display_list/skia/dl_sk_canvas.cc index bc40ef13fa..07dc33f706 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_canvas.cc +++ b/engine/src/flutter/display_list/skia/dl_sk_canvas.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/display_list/skia/dl_sk_canvas.h" #include "flutter/display_list/skia/dl_sk_conversions.h" @@ -352,3 +354,5 @@ void DlSkCanvasAdapter::Flush() { } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/display_list/skia/dl_sk_canvas.h b/engine/src/flutter/display_list/skia/dl_sk_canvas.h index f085d35ae8..cb9ba4466b 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_canvas.h +++ b/engine/src/flutter/display_list/skia/dl_sk_canvas.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_DISPLAY_LIST_SKIA_DL_SK_CANVAS_H_ #define FLUTTER_DISPLAY_LIST_SKIA_DL_SK_CANVAS_H_ +#if !SLIMPELLER + #include "flutter/display_list/dl_canvas.h" #include "flutter/display_list/skia/dl_sk_types.h" #include "impeller/typographer/text_frame.h" @@ -163,4 +165,6 @@ class DlSkCanvasAdapter final : public virtual DlCanvas { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_DISPLAY_LIST_SKIA_DL_SK_CANVAS_H_ diff --git a/engine/src/flutter/flow/compositor_context.cc b/engine/src/flutter/flow/compositor_context.cc index 2c7593c162..0a94e0f530 100644 --- a/engine/src/flutter/flow/compositor_context.cc +++ b/engine/src/flutter/flow/compositor_context.cc @@ -224,12 +224,16 @@ bool CompositorContext::ShouldPerformPartialRepaint( void CompositorContext::OnGrContextCreated() { texture_registry_->OnGrContextCreated(); +#if !SLIMPELLER raster_cache_.Clear(); +#endif // !SLIMPELLER } void CompositorContext::OnGrContextDestroyed() { texture_registry_->OnGrContextDestroyed(); +#if !SLIMPELLER raster_cache_.Clear(); +#endif // !SLIMPELLER } } // namespace flutter diff --git a/engine/src/flutter/flow/compositor_context.h b/engine/src/flutter/flow/compositor_context.h index 453259cd67..d558fac535 100644 --- a/engine/src/flutter/flow/compositor_context.h +++ b/engine/src/flutter/flow/compositor_context.h @@ -9,6 +9,7 @@ #include #include "flutter/common/graphics/texture.h" +#include "flutter/common/macros.h" #include "flutter/flow/diff_context.h" #include "flutter/flow/embedded_views.h" #include "flutter/flow/layer_snapshot_store.h" @@ -182,7 +183,9 @@ class CompositorContext { void OnGrContextDestroyed(); +#if !SLIMPELLER RasterCache& raster_cache() { return raster_cache_; } +#endif // !SLIMPELLER std::shared_ptr texture_registry() { return texture_registry_; @@ -195,7 +198,7 @@ class CompositorContext { LayerSnapshotStore& snapshot_store() { return layer_snapshot_store_; } private: - RasterCache raster_cache_; + NOT_SLIMPELLER(RasterCache raster_cache_); std::shared_ptr texture_registry_; Stopwatch raster_time_; Stopwatch ui_time_; diff --git a/engine/src/flutter/flow/diff_context.cc b/engine/src/flutter/flow/diff_context.cc index 8bfec18230..3f3c816d1a 100644 --- a/engine/src/flutter/flow/diff_context.cc +++ b/engine/src/flutter/flow/diff_context.cc @@ -3,7 +3,9 @@ // found in the LICENSE file. #include "flutter/flow/diff_context.h" + #include "flutter/flow/layers/layer.h" +#include "flutter/flow/raster_cache_util.h" namespace flutter { diff --git a/engine/src/flutter/flow/frame_timings.cc b/engine/src/flutter/flow/frame_timings.cc index 07a398a81c..9d451f40cc 100644 --- a/engine/src/flutter/flow/frame_timings.cc +++ b/engine/src/flutter/flow/frame_timings.cc @@ -206,12 +206,14 @@ FrameTiming FrameTimingsRecorder::RecordRasterEnd(const RasterCache* cache) { raster_end_ = fml::TimePoint::Now(); raster_end_wall_time_ = fml::TimePoint::CurrentWallTime(); if (cache) { +#if !SLIMPELLER const RasterCacheMetrics& layer_metrics = cache->layer_metrics(); const RasterCacheMetrics& picture_metrics = cache->picture_metrics(); layer_cache_count_ = layer_metrics.total_count(); layer_cache_bytes_ = layer_metrics.total_bytes(); picture_cache_count_ = picture_metrics.total_count(); picture_cache_bytes_ = picture_metrics.total_bytes(); +#endif // !SLIMPELLER } else { layer_cache_count_ = layer_cache_bytes_ = picture_cache_count_ = picture_cache_bytes_ = 0; diff --git a/engine/src/flutter/flow/layers/cacheable_layer.cc b/engine/src/flutter/flow/layers/cacheable_layer.cc index 7cdfacfb7d..19d53f8ff2 100644 --- a/engine/src/flutter/flow/layers/cacheable_layer.cc +++ b/engine/src/flutter/flow/layers/cacheable_layer.cc @@ -12,25 +12,35 @@ AutoCache::AutoCache(RasterCacheItem* raster_cache_item, : raster_cache_item_(raster_cache_item), context_(context), matrix_(matrix) { +#if !SLIMPELLER if (IsCacheEnabled()) { raster_cache_item->PrerollSetup(context, matrix); } +#endif // !SLIMPELLER } bool AutoCache::IsCacheEnabled() { +#if SLIMPELLER + return false; +#else // SLIMPELLER return raster_cache_item_ && context_ && context_->raster_cache; +#endif // SLIMPELLER } AutoCache::~AutoCache() { +#if !SLIMPELLER if (IsCacheEnabled()) { raster_cache_item_->PrerollFinalize(context_, matrix_); } +#endif // !SLIMPELLER } CacheableContainerLayer::CacheableContainerLayer(int layer_cached_threshold, bool can_cache_children) { +#if !SLIMPELLER layer_raster_cache_item_ = LayerRasterCacheItem::Make( this, layer_cached_threshold, can_cache_children); +#endif // !SLIMPELLER } } // namespace flutter diff --git a/engine/src/flutter/flow/layers/cacheable_layer.h b/engine/src/flutter/flow/layers/cacheable_layer.h index 856ce47546..db62edde6f 100644 --- a/engine/src/flutter/flow/layers/cacheable_layer.h +++ b/engine/src/flutter/flow/layers/cacheable_layer.h @@ -9,6 +9,7 @@ #include "flutter/flow/layers/container_layer.h" #include "flutter/flow/layers/layer_raster_cache_item.h" +#include "flutter/flow/raster_cache_util.h" namespace flutter { @@ -25,7 +26,7 @@ class AutoCache { private: inline bool IsCacheEnabled(); RasterCacheItem* raster_cache_item_ = nullptr; - PrerollContext* context_ = nullptr; + [[maybe_unused]] PrerollContext* context_ = nullptr; const SkMatrix matrix_; }; @@ -36,12 +37,14 @@ class CacheableContainerLayer : public ContainerLayer { RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer, bool can_cache_children = false); +#if !SLIMPELLER const LayerRasterCacheItem* raster_cache_item() const { return layer_raster_cache_item_.get(); } protected: std::unique_ptr layer_raster_cache_item_; +#endif // !SLIMPELLER }; } // namespace flutter diff --git a/engine/src/flutter/flow/layers/clip_shape_layer.h b/engine/src/flutter/flow/layers/clip_shape_layer.h index 45106713ec..8f26bf4229 100644 --- a/engine/src/flutter/flow/layers/clip_shape_layer.h +++ b/engine/src/flutter/flow/layers/clip_shape_layer.h @@ -44,12 +44,14 @@ class ClipShapeLayer : public CacheableContainerLayer { void Preroll(PrerollContext* context) override { bool uses_save_layer = UsesSaveLayer(); +#if !SLIMPELLER // We can use the raster_cache for children only when the use_save_layer is // true so if use_save_layer is false we pass the layer_raster_item is // nullptr which mean we don't do raster cache logic. AutoCache cache = AutoCache(uses_save_layer ? layer_raster_cache_item_.get() : nullptr, context, context->state_stack.transform_3x3()); +#endif // !SLIMPELLER Layer::AutoPrerollSaveLayerState save = Layer::AutoPrerollSaveLayerState::Create(context, UsesSaveLayer()); @@ -83,6 +85,7 @@ class ClipShapeLayer : public CacheableContainerLayer { return; } +#if !SLIMPELLER if (context.raster_cache) { mutator.integralTransform(); auto restore_apply = context.state_stack.applyState( @@ -94,6 +97,7 @@ class ClipShapeLayer : public CacheableContainerLayer { return; } } +#endif // !SLIMPELLER mutator.saveLayer(paint_bounds()); PaintChildren(context); diff --git a/engine/src/flutter/flow/layers/color_filter_layer.cc b/engine/src/flutter/flow/layers/color_filter_layer.cc index 056efa7472..19173b088d 100644 --- a/engine/src/flutter/flow/layers/color_filter_layer.cc +++ b/engine/src/flutter/flow/layers/color_filter_layer.cc @@ -39,8 +39,10 @@ void ColorFilterLayer::Diff(DiffContext* context, const Layer* old_layer) { void ColorFilterLayer::Preroll(PrerollContext* context) { Layer::AutoPrerollSaveLayerState save = Layer::AutoPrerollSaveLayerState::Create(context); +#if !SLIMPELLER AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, context->state_stack.transform_3x3()); +#endif // !SLIMPELLER ContainerLayer::Preroll(context); @@ -66,6 +68,7 @@ void ColorFilterLayer::Paint(PaintContext& context) const { auto mutator = context.state_stack.save(); +#if !SLIMPELLER if (context.raster_cache) { // Always apply the integral transform in the presence of a raster cache // whether or not we will draw from the cache @@ -81,11 +84,13 @@ void ColorFilterLayer::Paint(PaintContext& context) const { } } } +#endif // !SLIMPELLER // Now apply the color filter and then try rendering children either from // cache or directly. mutator.applyColorFilter(paint_bounds(), filter_); +#if !SLIMPELLER if (context.raster_cache && layer_raster_cache_item_->IsCacheChildren()) { DlPaint paint; if (layer_raster_cache_item_->Draw(context, @@ -93,6 +98,7 @@ void ColorFilterLayer::Paint(PaintContext& context) const { return; } } +#endif // !SLIMPELLER PaintChildren(context); } diff --git a/engine/src/flutter/flow/layers/display_list_layer.cc b/engine/src/flutter/flow/layers/display_list_layer.cc index 543af526be..f4510e830a 100644 --- a/engine/src/flutter/flow/layers/display_list_layer.cc +++ b/engine/src/flutter/flow/layers/display_list_layer.cc @@ -22,8 +22,10 @@ DisplayListLayer::DisplayListLayer(const SkPoint& offset, : offset_(offset), display_list_(std::move(display_list)) { if (display_list_) { bounds_ = display_list_->bounds().makeOffset(offset_.x(), offset_.y()); +#if !SLIMPELLER display_list_raster_cache_item_ = DisplayListRasterCacheItem::Make( display_list_, offset_, is_complex, will_change); +#endif // !SLIMPELLER } } @@ -95,8 +97,10 @@ bool DisplayListLayer::Compare(DiffContext::Statistics& statistics, void DisplayListLayer::Preroll(PrerollContext* context) { DisplayList* disp_list = display_list(); +#if !SLIMPELLER AutoCache cache = AutoCache(display_list_raster_cache_item_.get(), context, context->state_stack.transform_3x3()); +#endif // !SLIMPELLER if (disp_list->can_apply_group_opacity()) { context->renderable_state_flags = LayerStateStack::kCallerCanApplyOpacity; } @@ -110,6 +114,7 @@ void DisplayListLayer::Paint(PaintContext& context) const { auto mutator = context.state_stack.save(); mutator.translate(offset_.x(), offset_.y()); +#if !SLIMPELLER if (context.raster_cache) { // Always apply the integral transform in the presence of a raster cache // whether or not we successfully draw from the cache @@ -124,9 +129,12 @@ void DisplayListLayer::Paint(PaintContext& context) const { } } } +#endif // !SLIMPELLER SkScalar opacity = context.state_stack.outstanding_opacity(); +#if !SLIMPELLER + // Leaf layer tracing was never supported in the Impeller backend. if (context.enable_leaf_layer_tracing) { const auto canvas_size = context.canvas->GetBaseLayerSize(); auto offscreen_surface = @@ -156,6 +164,7 @@ void DisplayListLayer::Paint(PaintContext& context) const { raster_data, device_bounds); context.layer_snapshot_store->Add(snapshot_data); } +#endif // !SLIMPELLER context.canvas->DrawDisplayList(display_list_, opacity); } diff --git a/engine/src/flutter/flow/layers/display_list_layer.h b/engine/src/flutter/flow/layers/display_list_layer.h index d7efe4e8ee..71c54c852e 100644 --- a/engine/src/flutter/flow/layers/display_list_layer.h +++ b/engine/src/flutter/flow/layers/display_list_layer.h @@ -7,6 +7,7 @@ #include +#include "flutter/common/macros.h" #include "flutter/display_list/display_list.h" #include "flutter/flow/layers/display_list_raster_cache_item.h" #include "flutter/flow/layers/layer.h" @@ -37,6 +38,7 @@ class DisplayListLayer : public Layer { void Paint(PaintContext& context) const override; +#if !SLIMPELLER const DisplayListRasterCacheItem* raster_cache_item() const { return display_list_raster_cache_item_.get(); } @@ -45,9 +47,11 @@ class DisplayListLayer : public Layer { return RasterCacheKeyID(display_list()->unique_id(), RasterCacheKeyType::kDisplayList); } +#endif // !SLIMPELLER private: - std::unique_ptr display_list_raster_cache_item_; + NOT_SLIMPELLER(std::unique_ptr + display_list_raster_cache_item_); SkPoint offset_; SkRect bounds_; diff --git a/engine/src/flutter/flow/layers/display_list_raster_cache_item.cc b/engine/src/flutter/flow/layers/display_list_raster_cache_item.cc index c0675785f7..418b5598b0 100644 --- a/engine/src/flutter/flow/layers/display_list_raster_cache_item.cc +++ b/engine/src/flutter/flow/layers/display_list_raster_cache_item.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/flow/layers/display_list_raster_cache_item.h" #include @@ -174,3 +176,5 @@ bool DisplayListRasterCacheItem::TryToPrepareRasterCache( display_list_->rtree()); } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/flow/layers/display_list_raster_cache_item.h b/engine/src/flutter/flow/layers/display_list_raster_cache_item.h index e8d8d47c0e..4bb59d705e 100644 --- a/engine/src/flutter/flow/layers/display_list_raster_cache_item.h +++ b/engine/src/flutter/flow/layers/display_list_raster_cache_item.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_FLOW_LAYERS_DISPLAY_LIST_RASTER_CACHE_ITEM_H_ #define FLUTTER_FLOW_LAYERS_DISPLAY_LIST_RASTER_CACHE_ITEM_H_ +#if !SLIMPELLER + #include #include @@ -59,4 +61,10 @@ class DisplayListRasterCacheItem : public RasterCacheItem { } // namespace flutter +#else // !SLIMPELLER + +class DisplayListRasterCacheItem; + +#endif // !SLIMPELLER + #endif // FLUTTER_FLOW_LAYERS_DISPLAY_LIST_RASTER_CACHE_ITEM_H_ diff --git a/engine/src/flutter/flow/layers/image_filter_layer.cc b/engine/src/flutter/flow/layers/image_filter_layer.cc index 834df45ce8..31c1f3a8e0 100644 --- a/engine/src/flutter/flow/layers/image_filter_layer.cc +++ b/engine/src/flutter/flow/layers/image_filter_layer.cc @@ -56,8 +56,10 @@ void ImageFilterLayer::Preroll(PrerollContext* context) { Layer::AutoPrerollSaveLayerState save = Layer::AutoPrerollSaveLayerState::Create(context); +#if !SLIMPELLER AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, context->state_stack.transform_3x3()); +#endif // !SLIMPELLER SkRect child_bounds = SkRect::MakeEmpty(); @@ -85,15 +87,20 @@ void ImageFilterLayer::Preroll(PrerollContext* context) { set_paint_bounds(child_bounds); +#if !SLIMPELLER // CacheChildren only when the transformed_filter_ doesn't equal null. // So in here we reset the LayerRasterCacheItem cache state. layer_raster_cache_item_->MarkNotCacheChildren(); +#endif // !SLIMPELLER transformed_filter_ = filter_->makeWithLocalMatrix(context->state_stack.transform_3x3()); + +#if !SLIMPELLER if (transformed_filter_) { layer_raster_cache_item_->MarkCacheChildren(); } +#endif // !SLIMPELLER } void ImageFilterLayer::Paint(PaintContext& context) const { @@ -101,6 +108,7 @@ void ImageFilterLayer::Paint(PaintContext& context) const { auto mutator = context.state_stack.save(); +#if !SLIMPELLER if (context.raster_cache) { // Try drawing the layer cache item from the cache before applying the // image filter if it was cached with the filter applied. @@ -112,10 +120,13 @@ void ImageFilterLayer::Paint(PaintContext& context) const { } } } +#endif // !SLIMPELLER // Only apply the offset if not being raster-cached to avoid the offset being // applied twice. mutator.translate(offset_); + +#if !SLIMPELLER if (context.raster_cache) { mutator.integralTransform(); } @@ -132,6 +143,7 @@ void ImageFilterLayer::Paint(PaintContext& context) const { return; } } +#endif // !SLIMPELLER // Now apply the image filter and then try rendering the children. mutator.applyImageFilter(child_paint_bounds(), filter_); diff --git a/engine/src/flutter/flow/layers/layer.h b/engine/src/flutter/flow/layers/layer.h index 943bb968c7..77af3b9d66 100644 --- a/engine/src/flutter/flow/layers/layer.h +++ b/engine/src/flutter/flow/layers/layer.h @@ -11,6 +11,7 @@ #include #include "flutter/common/graphics/texture.h" +#include "flutter/common/macros.h" #include "flutter/display_list/dl_canvas.h" #include "flutter/flow/diff_context.h" #include "flutter/flow/embedded_views.h" @@ -52,7 +53,7 @@ static constexpr SkRect kGiantRect = SkRect::MakeLTRB(-1E9F, -1E9F, 1E9F, 1E9F); enum Clip { kNone, kHardEdge, kAntiAlias, kAntiAliasWithSaveLayer }; struct PrerollContext { - RasterCache* raster_cache; + NOT_SLIMPELLER(RasterCache* raster_cache); GrDirectContext* gr_context; ExternalViewEmbedder* view_embedder; LayerStateStack& state_stack; @@ -111,7 +112,7 @@ struct PaintContext { const Stopwatch& raster_time; const Stopwatch& ui_time; std::shared_ptr texture_registry; - const RasterCache* raster_cache; + NOT_SLIMPELLER(const RasterCache* raster_cache); // Snapshot store to collect leaf layer snapshots. The store is non-null // only when leaf layer tracing is enabled. @@ -249,9 +250,11 @@ class Layer { uint64_t unique_id() const { return unique_id_; } +#if !SLIMPELLER virtual RasterCacheKeyID caching_key_id() const { return RasterCacheKeyID(unique_id_, RasterCacheKeyType::kLayer); } +#endif // !SLIMPELLER virtual const ContainerLayer* as_container_layer() const { return nullptr; } virtual const DisplayListLayer* as_display_list_layer() const { return nullptr; diff --git a/engine/src/flutter/flow/layers/layer_raster_cache_item.cc b/engine/src/flutter/flow/layers/layer_raster_cache_item.cc index 2ffa251a62..59c375db2a 100644 --- a/engine/src/flutter/flow/layers/layer_raster_cache_item.cc +++ b/engine/src/flutter/flow/layers/layer_raster_cache_item.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/flow/layers/layer_raster_cache_item.h" #include "flutter/flow/layers/container_layer.h" #include "flutter/flow/raster_cache_item.h" @@ -196,3 +198,5 @@ bool LayerRasterCacheItem::Draw(const PaintContext& context, } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/flow/layers/layer_raster_cache_item.h b/engine/src/flutter/flow/layers/layer_raster_cache_item.h index a99faa7ad4..5e2dddfae0 100644 --- a/engine/src/flutter/flow/layers/layer_raster_cache_item.h +++ b/engine/src/flutter/flow/layers/layer_raster_cache_item.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_FLOW_LAYERS_LAYER_RASTER_CACHE_ITEM_H_ #define FLUTTER_FLOW_LAYERS_LAYER_RASTER_CACHE_ITEM_H_ +#if !SLIMPELLER + #include #include @@ -69,4 +71,6 @@ class LayerRasterCacheItem : public RasterCacheItem { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_FLOW_LAYERS_LAYER_RASTER_CACHE_ITEM_H_ diff --git a/engine/src/flutter/flow/layers/layer_tree.cc b/engine/src/flutter/flow/layers/layer_tree.cc index 2440558bce..d0d74ee2ff 100644 --- a/engine/src/flutter/flow/layers/layer_tree.cc +++ b/engine/src/flutter/flow/layers/layer_tree.cc @@ -40,23 +40,23 @@ bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame, LayerStateStack state_stack; state_stack.set_preroll_delegate(cull_rect, frame.root_surface_transformation()); - RasterCache* cache = - ignore_raster_cache ? nullptr : &frame.context().raster_cache(); + raster_cache_items_.clear(); PrerollContext context = { - // clang-format off - .raster_cache = cache, - .gr_context = frame.gr_context(), - .view_embedder = frame.view_embedder(), - .state_stack = state_stack, - .dst_color_space = sk_ref_sp(color_space), - .surface_needs_readback = false, - .raster_time = frame.context().raster_time(), - .ui_time = frame.context().ui_time(), - .texture_registry = frame.context().texture_registry(), - .raster_cached_entries = &raster_cache_items_, - // clang-format on +#if !SLIMPELLER + .raster_cache = + ignore_raster_cache ? nullptr : &frame.context().raster_cache(), +#endif // !SLIMPELLER + .gr_context = frame.gr_context(), + .view_embedder = frame.view_embedder(), + .state_stack = state_stack, + .dst_color_space = sk_ref_sp(color_space), + .surface_needs_readback = false, + .raster_time = frame.context().raster_time(), + .ui_time = frame.context().ui_time(), + .texture_registry = frame.context().texture_registry(), + .raster_cached_entries = &raster_cache_items_, }; root_layer_->Preroll(&context); @@ -64,6 +64,7 @@ bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame, return context.surface_needs_readback; } +#if !SLIMPELLER void LayerTree::TryToRasterCache( const std::vector& raster_cached_items, const PaintContext* paint_context, @@ -91,6 +92,7 @@ void LayerTree::TryToRasterCache( i++; } } +#endif // !SLIMPELLER void LayerTree::Paint(CompositorContext::ScopedFrame& frame, bool ignore_raster_cache) const { @@ -114,8 +116,12 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame, } SkColorSpace* color_space = GetColorSpace(frame.canvas()); + +#if !SLIMPELLER RasterCache* cache = ignore_raster_cache ? nullptr : &frame.context().raster_cache(); +#endif // !SLIMPELLER + PaintContext context = { // clang-format off .state_stack = state_stack, @@ -126,7 +132,9 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame, .raster_time = frame.context().raster_time(), .ui_time = frame.context().ui_time(), .texture_registry = frame.context().texture_registry(), +#if !SLIMPELLER .raster_cache = cache, +#endif // !SLIMPELLER .layer_snapshot_store = snapshot_store, .enable_leaf_layer_tracing = enable_leaf_layer_tracing_, .impeller_enabled = !!frame.aiks_context(), @@ -134,10 +142,12 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame, // clang-format on }; +#if !SLIMPELLER if (cache) { cache->EvictUnusedCacheEntries(); TryToRasterCache(raster_cache_items_, &context, ignore_raster_cache); } +#endif // !SLIMPELLER if (root_layer_->needs_painting(context)) { root_layer_->Paint(context); @@ -158,8 +168,10 @@ sk_sp LayerTree::Flatten( // No root surface transformation. So assume identity. preroll_state_stack.set_preroll_delegate(bounds); PrerollContext preroll_context{ - // clang-format off + // clang-format off +#if !SLIMPELLER .raster_cache = nullptr, +#endif // !SLIMPELLER .gr_context = gr_context, .view_embedder = nullptr, .state_stack = preroll_state_stack, @@ -183,7 +195,9 @@ sk_sp LayerTree::Flatten( .raster_time = unused_stopwatch, .ui_time = unused_stopwatch, .texture_registry = texture_registry, +#if !SLIMPELLER .raster_cache = nullptr, +#endif // !SLIMPELLER .layer_snapshot_store = nullptr, .enable_leaf_layer_tracing = false, // clang-format on diff --git a/engine/src/flutter/flow/layers/layer_tree.h b/engine/src/flutter/flow/layers/layer_tree.h index 2f0619e813..859d9554d3 100644 --- a/engine/src/flutter/flow/layers/layer_tree.h +++ b/engine/src/flutter/flow/layers/layer_tree.h @@ -35,10 +35,12 @@ class LayerTree { bool ignore_raster_cache = false, SkRect cull_rect = kGiantRect); +#if !SLIMPELLER static void TryToRasterCache( const std::vector& raster_cached_entries, const PaintContext* paint_context, bool ignore_raster_cache = false); +#endif // !SLIMPELLER void Paint(CompositorContext::ScopedFrame& frame, bool ignore_raster_cache = false) const; diff --git a/engine/src/flutter/flow/layers/offscreen_surface.cc b/engine/src/flutter/flow/layers/offscreen_surface.cc index 58046292d2..191ed0449b 100644 --- a/engine/src/flutter/flow/layers/offscreen_surface.cc +++ b/engine/src/flutter/flow/layers/offscreen_surface.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/flow/layers/offscreen_surface.h" #include "third_party/skia/include/core/SkColorSpace.h" @@ -87,3 +89,5 @@ bool OffscreenSurface::IsValid() const { } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/flow/layers/offscreen_surface.h b/engine/src/flutter/flow/layers/offscreen_surface.h index 6dabfb9eda..6e84307b81 100644 --- a/engine/src/flutter/flow/layers/offscreen_surface.h +++ b/engine/src/flutter/flow/layers/offscreen_surface.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_FLOW_LAYERS_OFFSCREEN_SURFACE_H_ #define FLUTTER_FLOW_LAYERS_OFFSCREEN_SURFACE_H_ +#if !SLIMPELLER + #include "flutter/fml/logging.h" #include "flutter/fml/macros.h" @@ -41,4 +43,6 @@ class OffscreenSurface { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_FLOW_LAYERS_OFFSCREEN_SURFACE_H_ diff --git a/engine/src/flutter/flow/layers/opacity_layer.cc b/engine/src/flutter/flow/layers/opacity_layer.cc index 144b29bcf1..303df63192 100644 --- a/engine/src/flutter/flow/layers/opacity_layer.cc +++ b/engine/src/flutter/flow/layers/opacity_layer.cc @@ -39,8 +39,11 @@ void OpacityLayer::Preroll(PrerollContext* context) { mutator.translate(offset_); mutator.applyOpacity(SkRect(), DlColor::toOpacity(alpha_)); +#if !SLIMPELLER AutoCache auto_cache = AutoCache(layer_raster_cache_item_.get(), context, context->state_stack.transform_3x3()); +#endif // !SLIMPELLER + Layer::AutoPrerollSaveLayerState save = Layer::AutoPrerollSaveLayerState::Create(context); @@ -56,12 +59,14 @@ void OpacityLayer::Preroll(PrerollContext* context) { set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY)); +#if !SLIMPELLER if (children_can_accept_opacity()) { // For opacity layer, we can use raster_cache children only when the // children can't accept opacity so if the children_can_accept_opacity we // should tell the AutoCache object don't do raster_cache. auto_cache.ShouldNotBeCached(); } +#endif // !SLIMPELLER } void OpacityLayer::Paint(PaintContext& context) const { @@ -69,12 +74,16 @@ void OpacityLayer::Paint(PaintContext& context) const { auto mutator = context.state_stack.save(); mutator.translate(offset_.fX, offset_.fY); + +#if !SLIMPELLER if (context.raster_cache) { mutator.integralTransform(); } +#endif // !SLIMPELLER mutator.applyOpacity(child_paint_bounds(), opacity()); +#if !SLIMPELLER if (!children_can_accept_opacity()) { DlPaint paint; if (layer_raster_cache_item_->Draw(context, @@ -82,6 +91,7 @@ void OpacityLayer::Paint(PaintContext& context) const { return; } } +#endif // !SLIMPELLER PaintChildren(context); } diff --git a/engine/src/flutter/flow/layers/shader_mask_layer.cc b/engine/src/flutter/flow/layers/shader_mask_layer.cc index bf7b81f400..b2953d2aa5 100644 --- a/engine/src/flutter/flow/layers/shader_mask_layer.cc +++ b/engine/src/flutter/flow/layers/shader_mask_layer.cc @@ -37,9 +37,10 @@ void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) { void ShaderMaskLayer::Preroll(PrerollContext* context) { Layer::AutoPrerollSaveLayerState save = Layer::AutoPrerollSaveLayerState::Create(context); +#if !SLIMPELLER AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, context->state_stack.transform_3x3()); - +#endif // !SLIMPELLER ContainerLayer::Preroll(context); // We always paint with a saveLayer (or a cached rendering), // so we can always apply opacity in any of those cases. @@ -51,6 +52,7 @@ void ShaderMaskLayer::Paint(PaintContext& context) const { auto mutator = context.state_stack.save(); +#if !SLIMPELLER if (context.raster_cache) { mutator.integralTransform(); @@ -60,6 +62,7 @@ void ShaderMaskLayer::Paint(PaintContext& context) const { return; } } +#endif // !SLIMPELLER auto shader_rect = SkRect::MakeWH(mask_rect_.width(), mask_rect_.height()); mutator.saveLayer(paint_bounds()); diff --git a/engine/src/flutter/flow/raster_cache.cc b/engine/src/flutter/flow/raster_cache.cc index d8aaef97ee..73a0be1610 100644 --- a/engine/src/flutter/flow/raster_cache.cc +++ b/engine/src/flutter/flow/raster_cache.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/flow/raster_cache.h" #include @@ -309,3 +311,5 @@ RasterCacheMetrics& RasterCache::GetMetricsForKind(RasterCacheKeyKind kind) { } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/flow/raster_cache.h b/engine/src/flutter/flow/raster_cache.h index 4906fe3554..e638f29675 100644 --- a/engine/src/flutter/flow/raster_cache.h +++ b/engine/src/flutter/flow/raster_cache.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_FLOW_RASTER_CACHE_H_ #define FLUTTER_FLOW_RASTER_CACHE_H_ +#if !SLIMPELLER + #include #include @@ -274,4 +276,10 @@ class RasterCache { } // namespace flutter +#else // !SLIMPELLER + +class RasterCache; + +#endif // !SLIMPELLER + #endif // FLUTTER_FLOW_RASTER_CACHE_H_ diff --git a/engine/src/flutter/flow/raster_cache_item.h b/engine/src/flutter/flow/raster_cache_item.h index e88abd3f07..664fd6180b 100644 --- a/engine/src/flutter/flow/raster_cache_item.h +++ b/engine/src/flutter/flow/raster_cache_item.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_FLOW_RASTER_CACHE_ITEM_H_ #define FLUTTER_FLOW_RASTER_CACHE_ITEM_H_ +#if !SLIMPELLER + #include #include #include @@ -74,4 +76,6 @@ class RasterCacheItem { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_FLOW_RASTER_CACHE_ITEM_H_ diff --git a/engine/src/flutter/flow/raster_cache_key.cc b/engine/src/flutter/flow/raster_cache_key.cc index ce091ea7a8..01fa11b911 100644 --- a/engine/src/flutter/flow/raster_cache_key.cc +++ b/engine/src/flutter/flow/raster_cache_key.cc @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/flow/raster_cache_key.h" #include #include "flutter/flow/layers/container_layer.h" #include "flutter/flow/layers/display_list_layer.h" #include "flutter/flow/layers/layer.h" -namespace flutter { -// +namespace flutter { std::optional> RasterCacheKeyID::LayerChildrenIds( const Layer* layer) { @@ -27,3 +28,5 @@ std::optional> RasterCacheKeyID::LayerChildrenIds( } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/flow/raster_cache_key.h b/engine/src/flutter/flow/raster_cache_key.h index 64292b6e89..6ca1db2905 100644 --- a/engine/src/flutter/flow/raster_cache_key.h +++ b/engine/src/flutter/flow/raster_cache_key.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_FLOW_RASTER_CACHE_KEY_H_ #define FLUTTER_FLOW_RASTER_CACHE_KEY_H_ +#if !SLIMPELLER + #include #include #include @@ -128,4 +130,6 @@ class RasterCacheKey { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_FLOW_RASTER_CACHE_KEY_H_ diff --git a/engine/src/flutter/flow/skia_gpu_object.h b/engine/src/flutter/flow/skia_gpu_object.h index 0d4cc516c2..725b98c5b2 100644 --- a/engine/src/flutter/flow/skia_gpu_object.h +++ b/engine/src/flutter/flow/skia_gpu_object.h @@ -8,6 +8,7 @@ #include #include +#include "flutter/common/macros.h" #include "flutter/fml/memory/ref_counted.h" #include "flutter/fml/memory/weak_ptr.h" #include "flutter/fml/task_runner.h" @@ -40,6 +41,7 @@ class UnrefQueue : public fml::RefCountedThreadSafe> { } } +#if !SLIMPELLER void DeleteTexture(const GrBackendTexture& texture) { // drain_immediate_ should only be used on Impeller. FML_DCHECK(!drain_immediate_); @@ -51,6 +53,7 @@ class UnrefQueue : public fml::RefCountedThreadSafe> { [strong = fml::Ref(this)]() { strong->Drain(); }, drain_delay_); } } +#endif // !SLIMPELLER // Usually, the drain is called automatically. However, during IO manager // shutdown (when the platform side reference to the OpenGL context is about @@ -60,14 +63,20 @@ class UnrefQueue : public fml::RefCountedThreadSafe> { void Drain() { TRACE_EVENT0("flutter", "SkiaUnrefQueue::Drain"); std::deque skia_objects; - std::deque textures; + + NOT_SLIMPELLER(std::deque textures); + { std::scoped_lock lock(mutex_); objects_.swap(skia_objects); - textures_.swap(textures); + NOT_SLIMPELLER(textures_.swap(textures)); drain_pending_ = false; } - DoDrain(skia_objects, textures, context_); + DoDrain(skia_objects, +#if !SLIMPELLER + textures, +#endif // !SLIMPELLER + context_); } void UpdateResourceContext(sk_sp context) { @@ -79,7 +88,7 @@ class UnrefQueue : public fml::RefCountedThreadSafe> { const fml::TimeDelta drain_delay_; std::mutex mutex_; std::deque objects_; - std::deque textures_; + NOT_SLIMPELLER(std::deque textures_); bool drain_pending_ = false; sk_sp context_; // Enabled when there is an impeller context, which removes the usage of @@ -105,21 +114,31 @@ class UnrefQueue : public fml::RefCountedThreadSafe> { ResourceContext* raw_context = context_.release(); fml::TaskRunner::RunNowOrPostTask( task_runner_, [objects = std::move(objects_), - textures = std::move(textures_), raw_context]() mutable { +#if !SLIMPELLER + textures = std::move(textures_), +#endif // !SLIMPELLER + raw_context]() mutable { sk_sp context(raw_context); - DoDrain(objects, textures, context); + DoDrain(objects, +#if !SLIMPELLER + textures, +#endif // !SLIMPELLER + context); context.reset(); }); } // static static void DoDrain(const std::deque& skia_objects, +#if !SLIMPELLER const std::deque& textures, +#endif // !SLIMPELLER sk_sp context) { for (SkRefCnt* skia_object : skia_objects) { skia_object->unref(); } +#if !SLIMPELLER if (context) { for (const GrBackendTexture& texture : textures) { context->deleteBackendTexture(texture); @@ -131,6 +150,7 @@ class UnrefQueue : public fml::RefCountedThreadSafe> { context->flushAndSubmit(GrSyncCpu::kYes); } +#endif // !SLIMPELLER } FML_FRIEND_REF_COUNTED_THREAD_SAFE(UnrefQueue); @@ -141,8 +161,7 @@ class UnrefQueue : public fml::RefCountedThreadSafe> { using SkiaUnrefQueue = UnrefQueue; /// An object whose deallocation needs to be performed on an specific unref -/// queue. The template argument U need to have a call operator that returns -/// that unref queue. +/// queue. template class SkiaGPUObject { public: diff --git a/engine/src/flutter/flow/surface_frame.cc b/engine/src/flutter/flow/surface_frame.cc index 7f7e8a8da8..60855ce0e0 100644 --- a/engine/src/flutter/flow/surface_frame.cc +++ b/engine/src/flutter/flow/surface_frame.cc @@ -27,8 +27,13 @@ SurfaceFrame::SurfaceFrame(sk_sp surface, context_result_(std::move(context_result)) { FML_DCHECK(submit_callback_); if (surface_) { +#if !SLIMPELLER adapter_.set_canvas(surface_->getCanvas()); canvas_ = &adapter_; +#else // !SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; + return; +#endif // !SLIMPELLER } else if (display_list_fallback) { FML_DCHECK(!frame_size.isEmpty()); // The root frame of a surface will be filled by the layer_tree which diff --git a/engine/src/flutter/flow/surface_frame.h b/engine/src/flutter/flow/surface_frame.h index 1abf75e573..d88e9a21b6 100644 --- a/engine/src/flutter/flow/surface_frame.h +++ b/engine/src/flutter/flow/surface_frame.h @@ -102,7 +102,9 @@ class SurfaceFrame { private: bool submitted_ = false; +#if !SLIMPELLER DlSkCanvasAdapter adapter_; +#endif // !SLIMPELLER sk_sp dl_builder_; sk_sp surface_; DlCanvas* canvas_ = nullptr; diff --git a/engine/src/flutter/lib/ui/compositing/scene.cc b/engine/src/flutter/lib/ui/compositing/scene.cc index f20aed41a8..7cdd7295cf 100644 --- a/engine/src/flutter/lib/ui/compositing/scene.cc +++ b/engine/src/flutter/lib/ui/compositing/scene.cc @@ -85,6 +85,10 @@ static sk_sp CreateDeferredImage( } #endif // IMPELLER_SUPPORTS_RENDERING +#if SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; + return nullptr; +#else // SLIMPELLER const auto& frame_size = layer_tree->frame_size(); const SkImageInfo image_info = SkImageInfo::Make(frame_size.width(), frame_size.height(), @@ -92,6 +96,7 @@ static sk_sp CreateDeferredImage( return DlDeferredImageGPUSkia::MakeFromLayerTree( image_info, std::move(layer_tree), std::move(snapshot_delegate), raster_task_runner, std::move(unref_queue)); +#endif // SLIMPELLER } void Scene::RasterizeToImage(uint32_t width, diff --git a/engine/src/flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.cc b/engine/src/flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.cc index 0cec39c737..3e13ae4cd5 100644 --- a/engine/src/flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.cc +++ b/engine/src/flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.h" #include "flutter/fml/make_copyable.h" @@ -226,3 +228,5 @@ void DlDeferredImageGPUSkia::ImageWrapper::DeleteTexture() { } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.h b/engine/src/flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.h index cec6c974d6..29c46472f0 100644 --- a/engine/src/flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.h +++ b/engine/src/flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_LIB_UI_PAINTING_DISPLAY_LIST_DEFERRED_IMAGE_GPU_SKIA_H_ #define FLUTTER_LIB_UI_PAINTING_DISPLAY_LIST_DEFERRED_IMAGE_GPU_SKIA_H_ +#if !SLIMPELLER + #include #include @@ -148,4 +150,6 @@ class DlDeferredImageGPUSkia final : public DlImage { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_LIB_UI_PAINTING_DISPLAY_LIST_DEFERRED_IMAGE_GPU_SKIA_H_ diff --git a/engine/src/flutter/lib/ui/painting/image_decoder.cc b/engine/src/flutter/lib/ui/painting/image_decoder.cc index b598de3823..82cd37360f 100644 --- a/engine/src/flutter/lib/ui/painting/image_decoder.cc +++ b/engine/src/flutter/lib/ui/painting/image_decoder.cc @@ -28,11 +28,16 @@ std::unique_ptr ImageDecoder::Make( gpu_disabled_switch); } #endif // IMPELLER_SUPPORTS_RENDERING +#if !SLIMPELLER return std::make_unique( runners, // std::move(concurrent_task_runner), // std::move(io_manager) // ); +#else // !SLIMPELLER + FML_LOG(FATAL) << "Could not setup an image decoder."; + return nullptr; +#endif // !SLIMPELLER } ImageDecoder::ImageDecoder( diff --git a/engine/src/flutter/lib/ui/painting/image_decoder_skia.cc b/engine/src/flutter/lib/ui/painting/image_decoder_skia.cc index 6584a1c32f..f3f26fe0a9 100644 --- a/engine/src/flutter/lib/ui/painting/image_decoder_skia.cc +++ b/engine/src/flutter/lib/ui/painting/image_decoder_skia.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/lib/ui/painting/image_decoder_skia.h" #include @@ -329,3 +331,5 @@ void ImageDecoderSkia::Decode(fml::RefPtr descriptor_ref_ptr, } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/lib/ui/painting/image_decoder_skia.h b/engine/src/flutter/lib/ui/painting/image_decoder_skia.h index aca9fad94d..611300707f 100644 --- a/engine/src/flutter/lib/ui/painting/image_decoder_skia.h +++ b/engine/src/flutter/lib/ui/painting/image_decoder_skia.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_SKIA_H_ #define FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_SKIA_H_ +#if !SLIMPELLER + #include "flutter/fml/macros.h" #include "flutter/lib/ui/painting/image_decoder.h" @@ -37,4 +39,6 @@ class ImageDecoderSkia final : public ImageDecoder { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_SKIA_H_ diff --git a/engine/src/flutter/lib/ui/painting/image_encoding.cc b/engine/src/flutter/lib/ui/painting/image_encoding.cc index 69d3bd38f8..db60335007 100644 --- a/engine/src/flutter/lib/ui/painting/image_encoding.cc +++ b/engine/src/flutter/lib/ui/painting/image_encoding.cc @@ -147,9 +147,14 @@ void EncodeImageAndInvokeDataCallback( return; } #endif // IMPELLER_SUPPORTS_RENDERING +#if !SLIMPELLER ConvertImageToRasterSkia(image, encode_task, raster_task_runner, io_task_runner, resource_context, snapshot_delegate, is_gpu_disabled_sync_switch); + +#else // !SLIMPELLER + FML_LOG(FATAL) << "Unsupported renderer."; +#endif // !SLIMPELLER } } // namespace diff --git a/engine/src/flutter/lib/ui/painting/image_encoding_skia.cc b/engine/src/flutter/lib/ui/painting/image_encoding_skia.cc index 7996c2b20b..7efcc76989 100644 --- a/engine/src/flutter/lib/ui/painting/image_encoding_skia.cc +++ b/engine/src/flutter/lib/ui/painting/image_encoding_skia.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/lib/ui/painting/image_encoding.h" #include "flutter/lib/ui/painting/image_encoding_impl.h" @@ -100,3 +102,5 @@ void ConvertImageToRasterSkia( } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/lib/ui/painting/image_encoding_skia.h b/engine/src/flutter/lib/ui/painting/image_encoding_skia.h index 48cac8eabc..42953d4ccd 100644 --- a/engine/src/flutter/lib/ui/painting/image_encoding_skia.h +++ b/engine/src/flutter/lib/ui/painting/image_encoding_skia.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_ENCODING_SKIA_H_ #define FLUTTER_LIB_UI_PAINTING_IMAGE_ENCODING_SKIA_H_ +#if !SLIMPELLER + #include "flutter/common/task_runners.h" #include "flutter/display_list/image/dl_image.h" #include "flutter/fml/synchronization/sync_switch.h" @@ -23,4 +25,6 @@ void ConvertImageToRasterSkia( } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_LIB_UI_PAINTING_IMAGE_ENCODING_SKIA_H_ diff --git a/engine/src/flutter/lib/ui/painting/multi_frame_codec.cc b/engine/src/flutter/lib/ui/painting/multi_frame_codec.cc index 32d1bd0695..2a7e3111f2 100644 --- a/engine/src/flutter/lib/ui/painting/multi_frame_codec.cc +++ b/engine/src/flutter/lib/ui/painting/multi_frame_codec.cc @@ -154,6 +154,7 @@ MultiFrameCodec::State::GetNextFrameImage( } #endif // IMPELLER_SUPPORTS_RENDERING +#if !SLIMPELLER sk_sp skImage; gpu_disable_sync_switch->Execute( fml::SyncSwitch::Handlers() @@ -179,6 +180,9 @@ MultiFrameCodec::State::GetNextFrameImage( return std::make_pair(DlImageGPU::Make({skImage, std::move(unref_queue)}), std::string()); +#else // !SLIMPELLER + return std::make_pair(nullptr, "Unsupported backend."); +#endif // !SLIMPELLER } void MultiFrameCodec::State::GetNextFrameAndInvokeCallback( diff --git a/engine/src/flutter/lib/ui/painting/picture.cc b/engine/src/flutter/lib/ui/painting/picture.cc index 7cddcccd28..019ec84506 100644 --- a/engine/src/flutter/lib/ui/painting/picture.cc +++ b/engine/src/flutter/lib/ui/painting/picture.cc @@ -71,11 +71,16 @@ static sk_sp CreateDeferredImage( } #endif // IMPELLER_SUPPORTS_RENDERING +#if SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; + return nullptr; +#else // SLIMPELLER const SkImageInfo image_info = SkImageInfo::Make( width, height, kRGBA_8888_SkColorType, kPremul_SkAlphaType); return DlDeferredImageGPUSkia::Make( image_info, std::move(display_list), std::move(snapshot_delegate), raster_task_runner, std::move(unref_queue)); +#endif // !SLIMPELLER } // static diff --git a/engine/src/flutter/lib/ui/snapshot_delegate.h b/engine/src/flutter/lib/ui/snapshot_delegate.h index e2dd521653..a750847568 100644 --- a/engine/src/flutter/lib/ui/snapshot_delegate.h +++ b/engine/src/flutter/lib/ui/snapshot_delegate.h @@ -24,16 +24,25 @@ class SnapshotDelegate { /// @brief A data structure used by the Skia implementation of deferred /// GPU based images. struct GpuImageResult { - GpuImageResult(const GrBackendTexture& p_texture, - sk_sp p_context, - sk_sp p_image = nullptr, - const std::string& p_error = "") - : texture(p_texture), + GpuImageResult( +#if !SLIMPELLER + const GrBackendTexture& p_texture, +#endif // !SLIMPELLER + sk_sp p_context, + sk_sp p_image = nullptr, + const std::string& p_error = "") + : +#if !SLIMPELLER + texture(p_texture), +#endif // !SLIMPELLER context(std::move(p_context)), image(std::move(p_image)), - error(p_error) {} + error(p_error) { + } +#if !SLIMPELLER const GrBackendTexture texture; +#endif // !SLIMPELLER // If texture.isValid() == true, this is a pointer to a GrDirectContext that // can be used to create an image from the texture. sk_sp context; diff --git a/engine/src/flutter/shell/common/context_options.cc b/engine/src/flutter/shell/common/context_options.cc index 3ae89865de..bef8615f8d 100644 --- a/engine/src/flutter/shell/common/context_options.cc +++ b/engine/src/flutter/shell/common/context_options.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/shell/common/context_options.h" #include "flutter/common/graphics/persistent_cache.h" @@ -41,3 +43,5 @@ GrContextOptions MakeDefaultContextOptions(ContextType type, }; } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/shell/common/context_options.h b/engine/src/flutter/shell/common/context_options.h index bae0b2fb8e..4882801923 100644 --- a/engine/src/flutter/shell/common/context_options.h +++ b/engine/src/flutter/shell/common/context_options.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_ #define FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_ +#if !SLIMPELLER + #include #include "flutter/fml/macros.h" @@ -40,4 +42,6 @@ GrContextOptions MakeDefaultContextOptions( } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_ diff --git a/engine/src/flutter/shell/common/rasterizer.cc b/engine/src/flutter/shell/common/rasterizer.cc index 587bb99c6b..00964a4ac1 100644 --- a/engine/src/flutter/shell/common/rasterizer.cc +++ b/engine/src/flutter/shell/common/rasterizer.cc @@ -47,7 +47,8 @@ namespace flutter { // The rasterizer will tell Skia to purge cached resources that have not been // used within this interval. -static constexpr std::chrono::milliseconds kSkiaCleanupExpiration(15000); +[[maybe_unused]] static constexpr std::chrono::milliseconds + kSkiaCleanupExpiration(15000); Rasterizer::Rasterizer(Delegate& delegate, MakeGpuImageBehavior gpu_image_behavior) @@ -121,9 +122,11 @@ void Rasterizer::Teardown() { auto context_switch = surface_->MakeRenderContextCurrent(); if (context_switch->GetResult()) { compositor_context_->OnGrContextDestroyed(); +#if !SLIMPELLER if (auto* context = surface_->GetContext()) { context->purgeUnlockedResources(GrPurgeResourceOptions::kAllResources); } +#endif // !SLIMPELLER } surface_.reset(); } @@ -165,6 +168,7 @@ void Rasterizer::DisableThreadMergerIfNeeded() { } void Rasterizer::NotifyLowMemoryWarning() const { +#if !SLIMPELLER if (!surface_) { FML_DLOG(INFO) << "Rasterizer::NotifyLowMemoryWarning called with no surface."; @@ -181,6 +185,7 @@ void Rasterizer::NotifyLowMemoryWarning() const { return; } context->performDeferredCleanup(std::chrono::milliseconds(0)); +#endif // !SLIMPELLER } void Rasterizer::CollectView(int64_t view_id) { @@ -323,6 +328,7 @@ DrawStatus Rasterizer::ToDrawStatus(DoDrawStatus status) { FML_UNREACHABLE(); } +#if !SLIMPELLER namespace { std::unique_ptr MakeBitmapImage( const sk_sp& display_list, @@ -352,10 +358,15 @@ std::unique_ptr MakeBitmapImage( image ? "" : "Unable to create image"); } } // namespace +#endif // !SLIMPELLER std::unique_ptr Rasterizer::MakeSkiaGpuImage( sk_sp display_list, const SkImageInfo& image_info) { +#if SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; + return nullptr; +#else // SLIMPELLER TRACE_EVENT0("flutter", "Rasterizer::MakeGpuImage"); FML_DCHECK(display_list); @@ -420,6 +431,7 @@ std::unique_ptr Rasterizer::MakeSkiaGpuImage( texture, sk_ref_sp(context), nullptr, ""); })); return result; +#endif // !SLIMPELLER } void Rasterizer::MakeRasterSnapshot( @@ -470,8 +482,10 @@ Rasterizer::DoDrawResult Rasterizer::DoDraw( return DoDrawResult{DoDrawStatus::kNotSetUp}; } +#if !SLIMPELLER PersistentCache* persistent_cache = PersistentCache::GetCacheForProcess(); persistent_cache->ResetStoredNewShaders(); +#endif // !SLIMPELLER DoDrawResult result = DrawToSurfaces(*frame_timings_recorder, std::move(tasks)); @@ -481,12 +495,14 @@ Rasterizer::DoDrawResult Rasterizer::DoDraw( return DoDrawResult{DoDrawStatus::kGpuUnavailable}; } +#if !SLIMPELLER if (persistent_cache->IsDumpingSkp() && persistent_cache->StoredNewShaders()) { auto screenshot = ScreenshotLastLayerTree(ScreenshotType::SkiaPicture, false); persistent_cache->DumpSkp(*screenshot.data); } +#endif // !SLIMPELLER // TODO(liyuqian): in Fuchsia, the rasterization doesn't finish when // Rasterizer::DoDraw finishes. Future work is needed to adapt the timestamp @@ -655,12 +671,16 @@ std::unique_ptr Rasterizer::DrawToSurfacesUnsafe( } // TODO(dkwingsmt): Pass in raster cache(s) for all views. // See https://github.com/flutter/flutter/issues/135530, item 4. - frame_timings_recorder.RecordRasterEnd(&compositor_context_->raster_cache()); + frame_timings_recorder.RecordRasterEnd( + NOT_SLIMPELLER(&compositor_context_->raster_cache())); + FireNextFrameCallbackIfPresent(); +#if !SLIMPELLER if (surface_->GetContext()) { surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration); } +#endif // !SLIMPELLER if (resubmitted_tasks.empty()) { return nullptr; @@ -717,7 +737,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( surface_->GetAiksContext().get() // aiks context ); if (compositor_frame) { - compositor_context_->raster_cache().BeginFrame(); + NOT_SLIMPELLER(compositor_context_->raster_cache().BeginFrame()); std::unique_ptr damage; // when leaf layer tracing is enabled we wish to repaint the whole frame @@ -777,11 +797,13 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( frame->Submit(); } +#if !SLIMPELLER // Do not update raster cache metrics for kResubmit because that status // indicates that the frame was not actually painted. if (frame_status != RasterStatus::kResubmit) { compositor_context_->raster_cache().EndFrame(); } +#endif // !SLIMPELLER if (frame_status == RasterStatus::kResubmit) { return DrawSurfaceStatus::kRetry; @@ -801,6 +823,9 @@ Rasterizer::ViewRecord& Rasterizer::EnsureViewRecord(int64_t view_id) { static sk_sp ScreenshotLayerTreeAsPicture( flutter::LayerTree* tree, flutter::CompositorContext& compositor_context) { +#if SLIMPELLER + return nullptr; +#else // SLIMPELLER FML_DCHECK(tree != nullptr); SkPictureRecorder recorder; recorder.beginRecording( @@ -830,6 +855,7 @@ static sk_sp ScreenshotLayerTreeAsPicture( #endif return recorder.finishRecordingAsPicture()->serialize(&procs); +#endif // SLIMPELLER } static void RenderFrameForScreenshot( @@ -955,6 +981,10 @@ Rasterizer::ScreenshotLayerTreeAsImage( } #endif // IMPELLER_SUPPORTS_RENDERING +#if SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; + return {nullptr, ScreenshotFormat::kUnknown}; +#else // SLIMPELLER GrDirectContext* surface_context = GetGrContext(); // Attempt to create a snapshot surface depending on whether we have access // to a valid GPU rendering context. @@ -984,6 +1014,7 @@ Rasterizer::ScreenshotLayerTreeAsImage( return std::make_pair(snapshot_surface->GetRasterData(compressed), ScreenshotFormat::kUnknown); +#endif // !SLIMPELLER } Rasterizer::Screenshot Rasterizer::ScreenshotLastLayerTree( @@ -1080,6 +1111,7 @@ void Rasterizer::FireNextFrameCallbackIfPresent() { } void Rasterizer::SetResourceCacheMaxBytes(size_t max_bytes, bool from_user) { +#if !SLIMPELLER user_override_resource_cache_bytes_ |= from_user; if (!from_user && user_override_resource_cache_bytes_) { @@ -1102,9 +1134,13 @@ void Rasterizer::SetResourceCacheMaxBytes(size_t max_bytes, bool from_user) { context->setResourceCacheLimit(max_bytes); } +#endif // !SLIMPELLER } std::optional Rasterizer::GetResourceCacheMaxBytes() const { +#if SLIMPELLER + return std::nullopt; +#else // SLIMPELLER if (!surface_) { return std::nullopt; } @@ -1113,6 +1149,7 @@ std::optional Rasterizer::GetResourceCacheMaxBytes() const { return context->getResourceCacheLimit(); } return std::nullopt; +#endif // SLIMPELLER } Rasterizer::Screenshot::Screenshot() {} diff --git a/engine/src/flutter/shell/common/rasterizer.h b/engine/src/flutter/shell/common/rasterizer.h index 1dc7106ff3..0834311e8d 100644 --- a/engine/src/flutter/shell/common/rasterizer.h +++ b/engine/src/flutter/shell/common/rasterizer.h @@ -747,7 +747,7 @@ class Rasterizer final : public SnapshotDelegate, bool is_torn_down_ = false; Delegate& delegate_; - MakeGpuImageBehavior gpu_image_behavior_; + [[maybe_unused]] MakeGpuImageBehavior gpu_image_behavior_; std::weak_ptr impeller_context_; std::unique_ptr surface_; std::unique_ptr snapshot_surface_producer_; diff --git a/engine/src/flutter/shell/common/run_configuration.cc b/engine/src/flutter/shell/common/run_configuration.cc index 759fe757e3..6c835ec5e0 100644 --- a/engine/src/flutter/shell/common/run_configuration.cc +++ b/engine/src/flutter/shell/common/run_configuration.cc @@ -41,7 +41,9 @@ RunConfiguration::RunConfiguration( std::unique_ptr configuration) : RunConfiguration(std::move(configuration), std::make_shared()) { +#if !SLIMPELLER PersistentCache::SetAssetManager(asset_manager_); +#endif // !SLIMPELLER } RunConfiguration::RunConfiguration( @@ -49,7 +51,9 @@ RunConfiguration::RunConfiguration( std::shared_ptr asset_manager) : isolate_configuration_(std::move(configuration)), asset_manager_(std::move(asset_manager)) { +#if !SLIMPELLER PersistentCache::SetAssetManager(asset_manager_); +#endif // !SLIMPELLER } RunConfiguration::RunConfiguration(RunConfiguration&&) = default; diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 9cb5735c6a..7b5d208534 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -142,7 +142,9 @@ void PerformInitializationTasks(Settings& settings) { } }); +#if !SLIMPELLER PersistentCache::SetCacheSkSL(settings.cache_sksl); +#endif // !SLIMPELLER } } // namespace @@ -525,8 +527,10 @@ Shell::Shell(DartVMRef vm, } Shell::~Shell() { +#if !SLIMPELLER PersistentCache::GetCacheForProcess()->RemoveWorkerTaskRunner( task_runners_.GetIOTaskRunner()); +#endif // !SLIMPELLER vm_->GetServiceProtocol()->RemoveHandler(this); @@ -779,6 +783,7 @@ bool Shell::Setup(std::unique_ptr platform_view, is_set_up_ = true; +#if !SLIMPELLER PersistentCache::GetCacheForProcess()->AddWorkerTaskRunner( task_runners_.GetIOTaskRunner()); @@ -788,6 +793,7 @@ bool Shell::Setup(std::unique_ptr platform_view, if (settings_.purge_persistent_cache) { PersistentCache::GetCacheForProcess()->Purge(); } +#endif // !SLIMPELLER return true; } @@ -1886,6 +1892,7 @@ bool Shell::OnServiceProtocolGetSkSLs( response->AddMember("type", "GetSkSLs", response->GetAllocator()); rapidjson::Value shaders_json(rapidjson::kObjectType); +#if !SLIMPELLER PersistentCache* persistent_cache = PersistentCache::GetCacheForProcess(); std::vector sksls = persistent_cache->LoadSkSLs(); for (const auto& sksl : sksls) { @@ -1904,6 +1911,7 @@ bool Shell::OnServiceProtocolGetSkSLs( rapidjson::Value shader_key(encode_result.second, response->GetAllocator()); shaders_json.AddMember(shader_key, shader_value, response->GetAllocator()); } +#endif // !SLIMPELLER response->AddMember("SkSLs", shaders_json, response->GetAllocator()); return true; } @@ -1912,15 +1920,22 @@ bool Shell::OnServiceProtocolEstimateRasterCacheMemory( const ServiceProtocol::Handler::ServiceProtocolMap& params, rapidjson::Document* response) { FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread()); + + uint64_t layer_cache_byte_size = 0u; + uint64_t picture_cache_byte_size = 0u; + +#if !SLIMPELLER const auto& raster_cache = rasterizer_->compositor_context()->raster_cache(); + layer_cache_byte_size = raster_cache.EstimateLayerCacheByteSize(); + picture_cache_byte_size = raster_cache.EstimatePictureCacheByteSize(); +#endif // !SLIMPELLER + response->SetObject(); response->AddMember("type", "EstimateRasterCacheMemory", response->GetAllocator()); - response->AddMember("layerBytes", - raster_cache.EstimateLayerCacheByteSize(), + response->AddMember("layerBytes", layer_cache_byte_size, response->GetAllocator()); - response->AddMember("pictureBytes", - raster_cache.EstimatePictureCacheByteSize(), + response->AddMember("pictureBytes", picture_cache_byte_size, response->GetAllocator()); return true; } diff --git a/engine/src/flutter/shell/common/snapshot_controller.cc b/engine/src/flutter/shell/common/snapshot_controller.cc index e84323cab5..ebde42d9cf 100644 --- a/engine/src/flutter/shell/common/snapshot_controller.cc +++ b/engine/src/flutter/shell/common/snapshot_controller.cc @@ -20,7 +20,13 @@ std::unique_ptr SnapshotController::Make( return std::make_unique(delegate); } #endif // IMPELLER_SUPPORTS_RENDERING +#if !SLIMPELLER return std::make_unique(delegate); +#else // !SLIMPELLER + FML_LOG(FATAL) + << "Cannot create a Skia snapshot controller in an Impeller build."; + return nullptr; +#endif // !SLIMPELLER } SnapshotController::SnapshotController(const Delegate& delegate) diff --git a/engine/src/flutter/shell/common/snapshot_controller_skia.cc b/engine/src/flutter/shell/common/snapshot_controller_skia.cc index 682a5e123c..5397368935 100644 --- a/engine/src/flutter/shell/common/snapshot_controller_skia.cc +++ b/engine/src/flutter/shell/common/snapshot_controller_skia.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/shell/common/snapshot_controller_skia.h" #include "display_list/image/dl_image.h" @@ -171,3 +173,5 @@ void SnapshotControllerSkia::CacheRuntimeStage( const std::shared_ptr& runtime_stage) {} } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/shell/common/snapshot_controller_skia.h b/engine/src/flutter/shell/common/snapshot_controller_skia.h index e7a22e22fe..a9c755ce21 100644 --- a/engine/src/flutter/shell/common/snapshot_controller_skia.h +++ b/engine/src/flutter/shell/common/snapshot_controller_skia.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_COMMON_SNAPSHOT_CONTROLLER_SKIA_H_ #define FLUTTER_SHELL_COMMON_SNAPSHOT_CONTROLLER_SKIA_H_ +#if !SLIMPELLER + #include "flutter/shell/common/snapshot_controller.h" #include "third_party/skia/include/core/SkSurface.h" @@ -38,4 +40,6 @@ class SnapshotControllerSkia : public SnapshotController { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_SHELL_COMMON_SNAPSHOT_CONTROLLER_SKIA_H_ diff --git a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.h b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.h index 21a229ac9b..f6f4601ce0 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.h +++ b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_SKIA_H_ #define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_SKIA_H_ +#if !SLIMPELLER + #include "flutter/common/graphics/msaa_sample_count.h" #include "flutter/flow/surface.h" #include "flutter/fml/macros.h" @@ -71,4 +73,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetalSkia : public Surface { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_SKIA_H_ diff --git a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm index 9e666d2a4f..8c6dc133e5 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm +++ b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include "flutter/shell/gpu/gpu_surface_metal_skia.h" #import @@ -272,3 +274,5 @@ bool GPUSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled() const { } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h index e1eed1df61..0e7c5ceb0f 100644 --- a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h +++ b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_FLUTTERDARWINCONTEXTMETALSKIA_H_ #define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_FLUTTERDARWINCONTEXTMETALSKIA_H_ +#if !SLIMPELLER + #import #import #import @@ -75,4 +77,6 @@ NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END +#endif // !SLIMPELLER + #endif // FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_FLUTTERDARWINCONTEXTMETALSKIA_H_ diff --git a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm index 1f78745585..514659cb27 100644 --- a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm +++ b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h" #include "flutter/common/graphics/persistent_cache.h" @@ -106,3 +108,5 @@ FLUTTER_ASSERT_ARC } @end + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm index 578d9e9fd2..b08430ca27 100644 --- a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm +++ b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm @@ -295,6 +295,9 @@ FLUTTER_ASSERT_ARC grContext:(nonnull GrDirectContext*)grContext width:(size_t)width height:(size_t)height { +#if SLIMPELLER + return nullptr; +#else // SLIMPELLER GrMtlTextureInfo ySkiaTextureInfo; ySkiaTextureInfo.fTexture = sk_cfp{(__bridge_retained const void*)yTex}; @@ -315,12 +318,17 @@ FLUTTER_ASSERT_ARC return SkImages::TextureFromYUVATextures(grContext, yuvaBackendTextures, /*imageColorSpace=*/nullptr, /*releaseProc*/ nullptr, /*releaseContext*/ nullptr); +#endif // SLIMPELLER } + (sk_sp)wrapRGBATexture:(id)rgbaTex grContext:(nonnull GrDirectContext*)grContext width:(size_t)width height:(size_t)height { +#if SLIMPELLER + return nullptr; +#else // SLIMPELLER + GrMtlTextureInfo skiaTextureInfo; skiaTextureInfo.fTexture = sk_cfp{(__bridge_retained const void*)rgbaTex}; @@ -331,5 +339,6 @@ FLUTTER_ASSERT_ARC kBGRA_8888_SkColorType, kPremul_SkAlphaType, /*colorSpace=*/nullptr, /*releaseProc*/ nullptr, /*releaseContext*/ nullptr); +#endif // SLIMPELLER } @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm index 07d55a2cb9..f425b7e2e1 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm @@ -34,7 +34,13 @@ std::unique_ptr IOSContext::Create( case IOSRenderingAPI::kMetal: switch (backend) { case IOSRenderingBackend::kSkia: +#if !SLIMPELLER return std::make_unique(msaa_samples); + +#else // !SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; + return nullptr; +#endif // !SLIMPELLER case IOSRenderingBackend::kImpeller: return std::make_unique(is_gpu_disabled_sync_switch); } diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.h b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.h index 42b6a8285f..32e67e4744 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.h +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_SKIA_H_ #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_SKIA_H_ +#if !SLIMPELLER + #include #include "flutter/fml/macros.h" @@ -51,4 +53,6 @@ class IOSContextMetalSkia final : public IOSContext { } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_SKIA_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm index f58ea7c8db..9bdfa1a405 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #import "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h" #include "flutter/common/graphics/persistent_cache.h" @@ -58,3 +60,5 @@ std::unique_ptr IOSContextMetalSkia::CreateExternalTexture( } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_surface.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_surface.mm index 3e7050b77e..33a71c090a 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_surface.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_surface.mm @@ -22,10 +22,15 @@ std::unique_ptr IOSSurface::Create(std::shared_ptr conte if ([layer.get() isKindOfClass:[CAMetalLayer class]]) { switch (context->GetBackend()) { case IOSRenderingBackend::kSkia: +#if !SLIMPELLER return std::make_unique( fml::scoped_nsobject((CAMetalLayer*)layer.get()), // Metal layer std::move(context) // context ); +#else // !SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; + return nullptr; +#endif // !SLIMPELLER break; case IOSRenderingBackend::kImpeller: return std::make_unique( diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h index 685be041e3..65549762c4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_SKIA_H_ #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_SKIA_H_ +#if !SLIMPELLER + #include "flutter/fml/macros.h" #include "flutter/shell/gpu/gpu_surface_metal_delegate.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" @@ -61,4 +63,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetalSkia final : public IOSSurf } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_SKIA_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm index cb9d30e136..b16daf45e6 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h" #include "flutter/shell/gpu/gpu_surface_metal_delegate.h" @@ -117,3 +119,5 @@ bool IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled() const { } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/shell/platform/embedder/embedder.cc b/engine/src/flutter/shell/platform/embedder/embedder.cc index 95ca543275..d81373edaa 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder.cc @@ -550,6 +550,7 @@ InferMetalPlatformViewCreationCallback( config->metal.present_command_queue), metal_dispatch_table, view_embedder); } else { +#if !SLIMPELLER flutter::EmbedderSurfaceMetal::MetalDispatchTable metal_dispatch_table = { .present = metal_present, .get_texture = metal_get_texture, @@ -559,6 +560,9 @@ InferMetalPlatformViewCreationCallback( const_cast( config->metal.present_command_queue), metal_dispatch_table, view_embedder); +#else // !SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; +#endif // !SLIMPELLER } // The static leak checker gets confused by the use of fml::MakeCopyable. @@ -913,7 +917,7 @@ static sk_sp MakeSkSurfaceFromBackingStore( GrDirectContext* context, const FlutterBackingStoreConfig& config, const FlutterMetalBackingStore* metal) { -#ifdef SHELL_ENABLE_METAL +#if defined(SHELL_ENABLE_METAL) && !SLIMPELLER GrMtlTextureInfo texture_info; if (!metal->texture.texture) { FML_LOG(ERROR) << "Embedder supplied null Metal texture."; @@ -1774,6 +1778,7 @@ FlutterEngineResult FlutterEngineInitialize(size_t version, icu_data_path = SAFE_ACCESS(args, icu_data_path, nullptr); } +#if !SLIMPELLER if (SAFE_ACCESS(args, persistent_cache_path, nullptr) != nullptr) { std::string persistent_cache_path = SAFE_ACCESS(args, persistent_cache_path, nullptr); @@ -1783,6 +1788,7 @@ FlutterEngineResult FlutterEngineInitialize(size_t version, if (SAFE_ACCESS(args, is_persistent_cache_read_only, false)) { flutter::PersistentCache::gIsReadOnly = true; } +#endif // !SLIMPELLER fml::CommandLine command_line; if (SAFE_ACCESS(args, command_line_argc, 0) != 0 && diff --git a/engine/src/flutter/shell/platform/embedder/embedder_external_view.cc b/engine/src/flutter/shell/platform/embedder/embedder_external_view.cc index 642216f680..c549039183 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_external_view.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder_external_view.cc @@ -133,6 +133,10 @@ bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target, } #endif // IMPELLER_SUPPORTS_RENDERING +#if SLIMPELLER + FML_LOG(FATAL) << "Impeller opt-out unavailable."; + return false; +#else // SLIMPELLER auto skia_surface = render_target.GetSkiaSurface(); if (!skia_surface) { return false; @@ -153,6 +157,7 @@ bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target, slice_->render_into(&dl_canvas); dl_canvas.RestoreToCount(restore_count); dl_canvas.Flush(); +#endif // !SLIMPELLER return true; } diff --git a/engine/src/flutter/shell/platform/embedder/embedder_external_view_embedder.cc b/engine/src/flutter/shell/platform/embedder/embedder_external_view_embedder.cc index 75631cb351..01c813c802 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_external_view_embedder.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder_external_view_embedder.cc @@ -466,15 +466,18 @@ void EmbedderExternalViewEmbedder::SubmitFlutterView( auto deferred_cleanup_render_targets = render_target_cache.ClearAllRenderTargetsInCache(); +#if !SLIMPELLER // The OpenGL context could have been trampled by the embedder at this point // as it attempted to collect old render targets and create new ones. Tell // Skia to not rely on existing bindings. if (context) { context->resetContext(kAll_GrBackendState); } +#endif // !SLIMPELLER builder.Render(); +#if !SLIMPELLER // We are going to be transferring control back over to the embedder there // the context may be trampled upon again. Flush all operations to the // underlying rendering API. @@ -483,6 +486,7 @@ void EmbedderExternalViewEmbedder::SubmitFlutterView( if (context) { context->flushAndSubmit(); } +#endif // !SLIMPELLER { auto presentation_time_optional = frame->submit_info().presentation_time; diff --git a/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.h b/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.h index d835218103..3671889bb6 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.h +++ b/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_METAL_H_ #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_METAL_H_ +#if !SLIMPELLER + #include "flutter/fml/macros.h" #include "flutter/shell/gpu/gpu_surface_metal_delegate.h" #include "flutter/shell/gpu/gpu_surface_metal_skia.h" @@ -15,6 +17,9 @@ namespace flutter { +// TODO(148235): This class is Skia specific and there is another on +// specifically for Impeller called EmbedderSurfaceMetalImpeller. Rename this to +// EmbedderSurfaceMetalSkia to avoid confusion. class EmbedderSurfaceMetal final : public EmbedderSurface, public GPUSurfaceMetalDelegate { public: @@ -67,4 +72,6 @@ class EmbedderSurfaceMetal final : public EmbedderSurface, } // namespace flutter +#endif // !SLIMPELLER + #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_METAL_H_ diff --git a/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.mm b/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.mm index b7582d01b5..58c08e47d4 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.mm +++ b/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.mm @@ -2,13 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if !SLIMPELLER + #include #include "flutter/shell/platform/embedder/embedder_surface_metal.h" +#include "flutter/common/graphics/msaa_sample_count.h" #include "flutter/fml/logging.h" #include "flutter/shell/gpu/gpu_surface_metal_delegate.h" -#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h" +#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h" #include "third_party/skia/include/gpu/GrDirectContext.h" FLUTTER_ASSERT_NOT_ARC @@ -80,3 +83,5 @@ bool EmbedderSurfaceMetal::PresentTexture(GPUMTLTextureInfo texture) const { } } // namespace flutter + +#endif // !SLIMPELLER diff --git a/engine/src/flutter/tools/gn b/engine/src/flutter/tools/gn index 99bb954651..e8ec2d0505 100755 --- a/engine/src/flutter/tools/gn +++ b/engine/src/flutter/tools/gn @@ -392,6 +392,9 @@ def to_gn_args(args): if args.target_os != 'ios': raise Exception('--simulator is only supported for iOS') + if args.slimpeller and args.target_os != 'ios': + raise Exception('--slimpeller is only supported for iOS.') + runtime_mode = args.runtime_mode gn_args = {} @@ -441,6 +444,10 @@ def to_gn_args(args): gn_args['is_clang'] = True else: gn_args['is_clang'] = args.clang + if args.slimpeller: + gn_args['skia_enable_graphite'] = False + gn_args['skia_enable_ganesh'] = False + gn_args['slimpeller'] = True if args.target_os == 'android' or args.target_os == 'ios': gn_args['skia_gl_standard'] = 'gles'