diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index f697e110945bb..600bd350394a3 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -248,10 +248,6 @@ FILE: ../../../flutter/assets/asset_manager.h FILE: ../../../flutter/assets/asset_resolver.h FILE: ../../../flutter/common/task_runners.cc FILE: ../../../flutter/common/task_runners.h -FILE: ../../../flutter/flow/layers/default_layer_builder.cc -FILE: ../../../flutter/flow/layers/default_layer_builder.h -FILE: ../../../flutter/flow/layers/layer_builder.cc -FILE: ../../../flutter/flow/layers/layer_builder.h FILE: ../../../flutter/flow/skia_gpu_object.cc FILE: ../../../flutter/flow/skia_gpu_object.h FILE: ../../../flutter/runtime/dart_isolate.cc diff --git a/flow/BUILD.gn b/flow/BUILD.gn index e311926fe25fe..dd4a292dd9d66 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -22,12 +22,8 @@ source_set("flow") { "layers/color_filter_layer.h", "layers/container_layer.cc", "layers/container_layer.h", - "layers/default_layer_builder.cc", - "layers/default_layer_builder.h", "layers/layer.cc", "layers/layer.h", - "layers/layer_builder.cc", - "layers/layer_builder.h", "layers/layer_tree.cc", "layers/layer_tree.h", "layers/opacity_layer.cc", diff --git a/flow/layers/default_layer_builder.cc b/flow/layers/default_layer_builder.cc deleted file mode 100644 index c6f4b80e82564..0000000000000 --- a/flow/layers/default_layer_builder.cc +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright 2017 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 "flutter/flow/layers/default_layer_builder.h" - -#include "flutter/flow/layers/backdrop_filter_layer.h" -#include "flutter/flow/layers/clip_path_layer.h" -#include "flutter/flow/layers/clip_rect_layer.h" -#include "flutter/flow/layers/clip_rrect_layer.h" -#include "flutter/flow/layers/color_filter_layer.h" -#include "flutter/flow/layers/container_layer.h" -#include "flutter/flow/layers/layer.h" -#include "flutter/flow/layers/layer_tree.h" -#include "flutter/flow/layers/opacity_layer.h" -#include "flutter/flow/layers/performance_overlay_layer.h" -#include "flutter/flow/layers/physical_shape_layer.h" -#include "flutter/flow/layers/picture_layer.h" -#include "flutter/flow/layers/shader_mask_layer.h" -#include "flutter/flow/layers/texture_layer.h" -#include "flutter/flow/layers/transform_layer.h" - -#if defined(OS_FUCHSIA) -#include "flutter/flow/layers/child_scene_layer.h" -#endif // defined(OS_FUCHSIA) - -namespace flow { - -static const SkRect kGiantRect = SkRect::MakeLTRB(-1E9F, -1E9F, 1E9F, 1E9F); - -DefaultLayerBuilder::DefaultLayerBuilder() { - cull_rects_.push(kGiantRect); -} - -DefaultLayerBuilder::~DefaultLayerBuilder() = default; - -void DefaultLayerBuilder::PushTransform(const SkMatrix& sk_matrix) { - SkMatrix inverse_sk_matrix; - SkRect cullRect; - // Perspective projections don't produce rectangles that are useful for - // culling for some reason. - if (!sk_matrix.hasPerspective() && sk_matrix.invert(&inverse_sk_matrix)) { - inverse_sk_matrix.mapRect(&cullRect, cull_rects_.top()); - } else { - cullRect = kGiantRect; - } - auto layer = std::make_unique(); - layer->set_transform(sk_matrix); - PushLayer(std::move(layer), cullRect); -} - -void DefaultLayerBuilder::PushClipRect(const SkRect& clipRect, - Clip clip_behavior) { - SkRect cullRect; - if (!cullRect.intersect(clipRect, cull_rects_.top())) { - cullRect = SkRect::MakeEmpty(); - } - auto layer = std::make_unique(clip_behavior); - layer->set_clip_rect(clipRect); - PushLayer(std::move(layer), cullRect); -} - -void DefaultLayerBuilder::PushClipRoundedRect(const SkRRect& rrect, - Clip clip_behavior) { - SkRect cullRect; - if (!cullRect.intersect(rrect.rect(), cull_rects_.top())) { - cullRect = SkRect::MakeEmpty(); - } - auto layer = std::make_unique(clip_behavior); - layer->set_clip_rrect(rrect); - PushLayer(std::move(layer), cullRect); -} - -void DefaultLayerBuilder::PushClipPath(const SkPath& path, Clip clip_behavior) { - FML_DCHECK(clip_behavior != Clip::none); - SkRect cullRect; - if (!cullRect.intersect(path.getBounds(), cull_rects_.top())) { - cullRect = SkRect::MakeEmpty(); - } - auto layer = std::make_unique(clip_behavior); - layer->set_clip_path(path); - PushLayer(std::move(layer), cullRect); -} - -void DefaultLayerBuilder::PushOpacity(int alpha) { - auto layer = std::make_unique(); - layer->set_alpha(alpha); - PushLayer(std::move(layer), cull_rects_.top()); -} - -void DefaultLayerBuilder::PushColorFilter(SkColor color, - SkBlendMode blend_mode) { - auto layer = std::make_unique(); - layer->set_color(color); - layer->set_blend_mode(blend_mode); - PushLayer(std::move(layer), cull_rects_.top()); -} - -void DefaultLayerBuilder::PushBackdropFilter(sk_sp filter) { - auto layer = std::make_unique(); - layer->set_filter(filter); - PushLayer(std::move(layer), cull_rects_.top()); -} - -void DefaultLayerBuilder::PushShaderMask(sk_sp shader, - const SkRect& rect, - SkBlendMode blend_mode) { - auto layer = std::make_unique(); - layer->set_shader(shader); - layer->set_mask_rect(rect); - layer->set_blend_mode(blend_mode); - PushLayer(std::move(layer), cull_rects_.top()); -} - -void DefaultLayerBuilder::PushPhysicalShape(const SkPath& sk_path, - double elevation, - SkColor color, - SkColor shadow_color, - SkScalar device_pixel_ratio, - Clip clip_behavior) { - SkRect cullRect; - if (!cullRect.intersect(sk_path.getBounds(), cull_rects_.top())) { - cullRect = SkRect::MakeEmpty(); - } - auto layer = std::make_unique(clip_behavior); - layer->set_path(sk_path); - layer->set_elevation(elevation); - layer->set_color(color); - layer->set_shadow_color(shadow_color); - layer->set_device_pixel_ratio(device_pixel_ratio); - PushLayer(std::move(layer), cullRect); -} - -void DefaultLayerBuilder::PushPerformanceOverlay(uint64_t enabled_options, - const SkRect& rect) { - if (!current_layer_) { - return; - } - auto layer = std::make_unique(enabled_options); - layer->set_paint_bounds(rect); - current_layer_->Add(std::move(layer)); -} - -void DefaultLayerBuilder::PushPicture(const SkPoint& offset, - SkiaGPUObject picture, - bool picture_is_complex, - bool picture_will_change) { - if (!current_layer_) { - return; - } - SkRect pictureRect = picture.get()->cullRect(); - pictureRect.offset(offset.x(), offset.y()); - if (!SkRect::Intersects(pictureRect, cull_rects_.top())) { - return; - } - auto layer = std::make_unique(); - layer->set_offset(offset); - layer->set_picture(std::move(picture)); - layer->set_is_complex(picture_is_complex); - layer->set_will_change(picture_will_change); - current_layer_->Add(std::move(layer)); -} - -void DefaultLayerBuilder::PushTexture(const SkPoint& offset, - const SkSize& size, - int64_t texture_id, - bool freeze) { - if (!current_layer_) { - return; - } - auto layer = std::make_unique(); - layer->set_offset(offset); - layer->set_size(size); - layer->set_texture_id(texture_id); - layer->set_freeze(freeze); - current_layer_->Add(std::move(layer)); -} - -#if defined(OS_FUCHSIA) -void DefaultLayerBuilder::PushChildScene( - const SkPoint& offset, - const SkSize& size, - fml::RefPtr export_token_holder, - bool hit_testable) { - if (!current_layer_) { - return; - } - SkRect sceneRect = - SkRect::MakeXYWH(offset.x(), offset.y(), size.width(), size.height()); - if (!SkRect::Intersects(sceneRect, cull_rects_.top())) { - return; - } - auto layer = std::make_unique(); - layer->set_offset(offset); - layer->set_size(size); - layer->set_export_node_holder(std::move(export_token_holder)); - layer->set_hit_testable(hit_testable); - current_layer_->Add(std::move(layer)); -} -#endif // defined(OS_FUCHSIA) - -void DefaultLayerBuilder::Pop() { - if (!current_layer_) { - return; - } - cull_rects_.pop(); - current_layer_ = current_layer_->parent(); -} - -std::unique_ptr DefaultLayerBuilder::TakeLayer() { - return std::move(root_layer_); -} - -void DefaultLayerBuilder::PushLayer(std::unique_ptr layer, - const SkRect& cullRect) { - FML_DCHECK(layer); - - cull_rects_.push(cullRect); - - if (!root_layer_) { - root_layer_ = std::move(layer); - current_layer_ = root_layer_.get(); - return; - } - - if (!current_layer_) { - return; - } - - flow::ContainerLayer* newLayer = layer.get(); - current_layer_->Add(std::move(layer)); - current_layer_ = newLayer; -} - -} // namespace flow diff --git a/flow/layers/default_layer_builder.h b/flow/layers/default_layer_builder.h deleted file mode 100644 index 2601344668ed7..0000000000000 --- a/flow/layers/default_layer_builder.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2017 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_FLOW_LAYERS_DEFAULT_LAYER_BUILDER_H_ -#define FLUTTER_FLOW_LAYERS_DEFAULT_LAYER_BUILDER_H_ - -#include - -#include "flutter/flow/layers/container_layer.h" -#include "flutter/flow/layers/layer_builder.h" -#include "flutter/fml/macros.h" - -namespace flow { - -class DefaultLayerBuilder final : public LayerBuilder { - public: - DefaultLayerBuilder(); - - // |flow::LayerBuilder| - ~DefaultLayerBuilder() override; - - // |flow::LayerBuilder| - void PushTransform(const SkMatrix& matrix) override; - - // |flow::LayerBuilder| - void PushClipRect(const SkRect& rect, - Clip clip_behavior = Clip::antiAlias) override; - - // |flow::LayerBuilder| - void PushClipRoundedRect(const SkRRect& rect, - Clip clip_behavior = Clip::antiAlias) override; - - // |flow::LayerBuilder| - void PushClipPath(const SkPath& path, - Clip clip_behavior = Clip::antiAlias) override; - - // |flow::LayerBuilder| - void PushOpacity(int alpha) override; - - // |flow::LayerBuilder| - void PushColorFilter(SkColor color, SkBlendMode blend_mode) override; - - // |flow::LayerBuilder| - void PushBackdropFilter(sk_sp filter) override; - - // |flow::LayerBuilder| - void PushShaderMask(sk_sp shader, - const SkRect& rect, - SkBlendMode blend_mode) override; - - // |flow::LayerBuilder| - void PushPhysicalShape(const SkPath& path, - double elevation, - SkColor color, - SkColor shadow_color, - SkScalar device_pixel_ratio, - Clip clip_behavior) override; - - // |flow::LayerBuilder| - void PushPerformanceOverlay(uint64_t enabled_options, - const SkRect& rect) override; - - // |flow::LayerBuilder| - void PushPicture(const SkPoint& offset, - SkiaGPUObject picture, - bool picture_is_complex, - bool picture_will_change) override; - - // |flow::LayerBuilder| - void PushTexture(const SkPoint& offset, - const SkSize& size, - int64_t texture_id, - bool freeze) override; - -#if defined(OS_FUCHSIA) - // |flow::LayerBuilder| - void PushChildScene(const SkPoint& offset, - const SkSize& size, - fml::RefPtr export_token_holder, - bool hit_testable) override; -#endif // defined(OS_FUCHSIA) - - // |flow::LayerBuilder| - void Pop() override; - - // |flow::LayerBuilder| - std::unique_ptr TakeLayer() override; - - private: - std::unique_ptr root_layer_; - flow::ContainerLayer* current_layer_ = nullptr; - - std::stack cull_rects_; - - void PushLayer(std::unique_ptr layer, - const SkRect& cullRect); - - FML_DISALLOW_COPY_AND_ASSIGN(DefaultLayerBuilder); -}; - -} // namespace flow - -#endif // FLUTTER_FLOW_LAYERS_DEFAULT_LAYER_BUILDER_H_ diff --git a/flow/layers/layer_builder.cc b/flow/layers/layer_builder.cc deleted file mode 100644 index 1d2243d5dfc39..0000000000000 --- a/flow/layers/layer_builder.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2017 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 "flutter/flow/layers/layer_builder.h" -#include "flutter/flow/layers/default_layer_builder.h" - -namespace flow { - -std::unique_ptr LayerBuilder::Create() { - return std::make_unique(); -} - -LayerBuilder::LayerBuilder() = default; - -LayerBuilder::~LayerBuilder() = default; - -int LayerBuilder::GetRasterizerTracingThreshold() const { - return rasterizer_tracing_threshold_; -} - -bool LayerBuilder::GetCheckerboardRasterCacheImages() const { - return checkerboard_raster_cache_images_; -} - -bool LayerBuilder::GetCheckerboardOffscreenLayers() const { - return checkerboard_offscreen_layers_; -} - -void LayerBuilder::SetRasterizerTracingThreshold(uint32_t frameInterval) { - rasterizer_tracing_threshold_ = frameInterval; -} - -void LayerBuilder::SetCheckerboardRasterCacheImages(bool checkerboard) { - checkerboard_raster_cache_images_ = checkerboard; -} - -void LayerBuilder::SetCheckerboardOffscreenLayers(bool checkerboard) { - checkerboard_offscreen_layers_ = checkerboard; -} - -} // namespace flow diff --git a/flow/layers/layer_builder.h b/flow/layers/layer_builder.h deleted file mode 100644 index 8fa83e222f9ca..0000000000000 --- a/flow/layers/layer_builder.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2017 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_FLOW_LAYERS_LAYER_BUILDER_H_ -#define FLUTTER_FLOW_LAYERS_LAYER_BUILDER_H_ - -#include - -#include "flutter/flow/layers/layer.h" -#include "flutter/flow/skia_gpu_object.h" -#include "flutter/fml/macros.h" -#include "third_party/skia/include/core/SkBlendMode.h" -#include "third_party/skia/include/core/SkColor.h" -#include "third_party/skia/include/core/SkImageFilter.h" -#include "third_party/skia/include/core/SkMatrix.h" -#include "third_party/skia/include/core/SkPath.h" -#include "third_party/skia/include/core/SkPicture.h" -#include "third_party/skia/include/core/SkRRect.h" -#include "third_party/skia/include/core/SkRect.h" -#include "third_party/skia/include/core/SkShader.h" - -namespace flow { - -class LayerBuilder { - public: - static std::unique_ptr Create(); - - LayerBuilder(); - - virtual ~LayerBuilder(); - - virtual void PushTransform(const SkMatrix& matrix) = 0; - - virtual void PushClipRect(const SkRect& rect, - Clip clip_behavior = Clip::antiAlias) = 0; - - virtual void PushClipRoundedRect(const SkRRect& rect, - Clip clip_behavior = Clip::antiAlias) = 0; - - virtual void PushClipPath(const SkPath& path, - Clip clip_behavior = Clip::antiAlias) = 0; - - virtual void PushOpacity(int alpha) = 0; - - virtual void PushColorFilter(SkColor color, SkBlendMode blend_mode) = 0; - - virtual void PushBackdropFilter(sk_sp filter) = 0; - - virtual void PushShaderMask(sk_sp shader, - const SkRect& rect, - SkBlendMode blend_mode) = 0; - - virtual void PushPhysicalShape(const SkPath& path, - double elevation, - SkColor color, - SkColor shadow_color, - SkScalar device_pixel_ratio, - Clip clip_behavior) = 0; - - virtual void PushPerformanceOverlay(uint64_t enabled_options, - const SkRect& rect) = 0; - - virtual void PushPicture(const SkPoint& offset, - SkiaGPUObject picture, - bool picture_is_complex, - bool picture_will_change) = 0; - - virtual void PushTexture(const SkPoint& offset, - const SkSize& size, - int64_t texture_id, - bool freeze) = 0; - -#if defined(OS_FUCHSIA) - virtual void PushChildScene( - const SkPoint& offset, - const SkSize& size, - fml::RefPtr export_token_holder, - bool hit_testable) = 0; -#endif // defined(OS_FUCHSIA) - - virtual void Pop() = 0; - - virtual std::unique_ptr TakeLayer() = 0; - - int GetRasterizerTracingThreshold() const; - - bool GetCheckerboardRasterCacheImages() const; - - bool GetCheckerboardOffscreenLayers() const; - - void SetRasterizerTracingThreshold(uint32_t frameInterval); - - void SetCheckerboardRasterCacheImages(bool checkerboard); - - void SetCheckerboardOffscreenLayers(bool checkerboard); - - private: - int rasterizer_tracing_threshold_ = 0; - bool checkerboard_raster_cache_images_ = false; - bool checkerboard_offscreen_layers_ = false; - - FML_DISALLOW_COPY_AND_ASSIGN(LayerBuilder); -}; - -} // namespace flow - -#endif // FLUTTER_FLOW_LAYERS_LAYER_BUILDER_H_ diff --git a/lib/ui/compositing/scene_builder.cc b/lib/ui/compositing/scene_builder.cc index 61a3c60ddee3e..81414b96a9a9a 100644 --- a/lib/ui/compositing/scene_builder.cc +++ b/lib/ui/compositing/scene_builder.cc @@ -4,6 +4,21 @@ #include "flutter/lib/ui/compositing/scene_builder.h" +#include "flutter/flow/layers/backdrop_filter_layer.h" +#include "flutter/flow/layers/clip_path_layer.h" +#include "flutter/flow/layers/clip_rect_layer.h" +#include "flutter/flow/layers/clip_rrect_layer.h" +#include "flutter/flow/layers/color_filter_layer.h" +#include "flutter/flow/layers/container_layer.h" +#include "flutter/flow/layers/layer.h" +#include "flutter/flow/layers/layer_tree.h" +#include "flutter/flow/layers/opacity_layer.h" +#include "flutter/flow/layers/performance_overlay_layer.h" +#include "flutter/flow/layers/physical_shape_layer.h" +#include "flutter/flow/layers/picture_layer.h" +#include "flutter/flow/layers/shader_mask_layer.h" +#include "flutter/flow/layers/texture_layer.h" +#include "flutter/flow/layers/transform_layer.h" #include "flutter/fml/build_config.h" #include "flutter/lib/ui/painting/matrix.h" #include "flutter/lib/ui/painting/shader.h" @@ -51,12 +66,28 @@ void SceneBuilder::RegisterNatives(tonic::DartLibraryNatives* natives) { FOR_EACH_BINDING(DART_REGISTER_NATIVE)}); } -SceneBuilder::SceneBuilder() : layer_builder_(flow::LayerBuilder::Create()) {} +static const SkRect kGiantRect = SkRect::MakeLTRB(-1E9F, -1E9F, 1E9F, 1E9F); + +SceneBuilder::SceneBuilder() { + cull_rects_.push(kGiantRect); +} SceneBuilder::~SceneBuilder() = default; void SceneBuilder::pushTransform(const tonic::Float64List& matrix4) { - layer_builder_->PushTransform(ToSkMatrix(matrix4)); + SkMatrix sk_matrix = ToSkMatrix(matrix4); + SkMatrix inverse_sk_matrix; + SkRect cullRect; + // Perspective projections don't produce rectangles that are useful for + // culling for some reason. + if (!sk_matrix.hasPerspective() && sk_matrix.invert(&inverse_sk_matrix)) { + inverse_sk_matrix.mapRect(&cullRect, cull_rects_.top()); + } else { + cullRect = kGiantRect; + } + auto layer = std::make_unique(); + layer->set_transform(sk_matrix); + PushLayer(std::move(layer), cullRect); } void SceneBuilder::pushClipRect(double left, @@ -64,31 +95,57 @@ void SceneBuilder::pushClipRect(double left, double top, double bottom, int clipBehavior) { - layer_builder_->PushClipRect(SkRect::MakeLTRB(left, top, right, bottom), - static_cast(clipBehavior)); + SkRect clipRect = SkRect::MakeLTRB(left, top, right, bottom); + flow::Clip clip_behavior = static_cast(clipBehavior); + SkRect cullRect; + if (!cullRect.intersect(clipRect, cull_rects_.top())) { + cullRect = SkRect::MakeEmpty(); + } + auto layer = std::make_unique(clip_behavior); + layer->set_clip_rect(clipRect); + PushLayer(std::move(layer), cullRect); } void SceneBuilder::pushClipRRect(const RRect& rrect, int clipBehavior) { - layer_builder_->PushClipRoundedRect(rrect.sk_rrect, - static_cast(clipBehavior)); + flow::Clip clip_behavior = static_cast(clipBehavior); + SkRect cullRect; + if (!cullRect.intersect(rrect.sk_rrect.rect(), cull_rects_.top())) { + cullRect = SkRect::MakeEmpty(); + } + auto layer = std::make_unique(clip_behavior); + layer->set_clip_rrect(rrect.sk_rrect); + PushLayer(std::move(layer), cullRect); } void SceneBuilder::pushClipPath(const CanvasPath* path, int clipBehavior) { - layer_builder_->PushClipPath(path->path(), - static_cast(clipBehavior)); + flow::Clip clip_behavior = static_cast(clipBehavior); + FML_DCHECK(clip_behavior != flow::Clip::none); + SkRect cullRect; + if (!cullRect.intersect(path->path().getBounds(), cull_rects_.top())) { + cullRect = SkRect::MakeEmpty(); + } + auto layer = std::make_unique(clip_behavior); + layer->set_clip_path(path->path()); + PushLayer(std::move(layer), cullRect); } void SceneBuilder::pushOpacity(int alpha) { - layer_builder_->PushOpacity(alpha); + auto layer = std::make_unique(); + layer->set_alpha(alpha); + PushLayer(std::move(layer), cull_rects_.top()); } void SceneBuilder::pushColorFilter(int color, int blendMode) { - layer_builder_->PushColorFilter(static_cast(color), - static_cast(blendMode)); + auto layer = std::make_unique(); + layer->set_color(static_cast(color)); + layer->set_blend_mode(static_cast(blendMode)); + PushLayer(std::move(layer), cull_rects_.top()); } void SceneBuilder::pushBackdropFilter(ImageFilter* filter) { - layer_builder_->PushBackdropFilter(filter->filter()); + auto layer = std::make_unique(); + layer->set_filter(filter->filter()); + PushLayer(std::move(layer), cull_rects_.top()); } void SceneBuilder::pushShaderMask(Shader* shader, @@ -97,41 +154,63 @@ void SceneBuilder::pushShaderMask(Shader* shader, double maskRectTop, double maskRectBottom, int blendMode) { - layer_builder_->PushShaderMask( - shader->shader(), - SkRect::MakeLTRB(maskRectLeft, maskRectTop, maskRectRight, - maskRectBottom), - static_cast(blendMode)); + SkRect rect = SkRect::MakeLTRB(maskRectLeft, maskRectTop, maskRectRight, + maskRectBottom); + auto layer = std::make_unique(); + layer->set_shader(shader->shader()); + layer->set_mask_rect(rect); + layer->set_blend_mode(static_cast(blendMode)); + PushLayer(std::move(layer), cull_rects_.top()); } void SceneBuilder::pushPhysicalShape(const CanvasPath* path, double elevation, int color, int shadow_color, - int clip_behavior) { - layer_builder_->PushPhysicalShape( - path->path(), // - elevation, // - static_cast(color), // - static_cast(shadow_color), - UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio, - static_cast(clip_behavior)); + int clipBehavior) { + const SkPath& sk_path = path->path(); + flow::Clip clip_behavior = static_cast(clipBehavior); + SkRect cullRect; + if (!cullRect.intersect(sk_path.getBounds(), cull_rects_.top())) { + cullRect = SkRect::MakeEmpty(); + } + auto layer = std::make_unique(clip_behavior); + layer->set_path(sk_path); + layer->set_elevation(elevation); + layer->set_color(static_cast(color)); + layer->set_shadow_color(static_cast(shadow_color)); + layer->set_device_pixel_ratio( + UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio); + PushLayer(std::move(layer), cullRect); } void SceneBuilder::pop() { - layer_builder_->Pop(); + if (!current_layer_) { + return; + } + cull_rects_.pop(); + current_layer_ = current_layer_->parent(); } void SceneBuilder::addPicture(double dx, double dy, Picture* picture, int hints) { - layer_builder_->PushPicture( - SkPoint::Make(dx, dy), // - UIDartState::CreateGPUObject(picture->picture()), // - !!(hints & 1), // picture is complex - !!(hints & 2) // picture will change - ); + if (!current_layer_) { + return; + } + SkPoint offset = SkPoint::Make(dx, dy); + SkRect pictureRect = picture->picture()->cullRect(); + pictureRect.offset(offset.x(), offset.y()); + if (!SkRect::Intersects(pictureRect, cull_rects_.top())) { + return; + } + auto layer = std::make_unique(); + layer->set_offset(offset); + layer->set_picture(UIDartState::CreateGPUObject(picture->picture())); + layer->set_is_complex(!!(hints & 1)); + layer->set_will_change(!!(hints & 2)); + current_layer_->Add(std::move(layer)); } void SceneBuilder::addTexture(double dx, @@ -140,8 +219,15 @@ void SceneBuilder::addTexture(double dx, double height, int64_t textureId, bool freeze) { - layer_builder_->PushTexture(SkPoint::Make(dx, dy), - SkSize::Make(width, height), textureId, freeze); + if (!current_layer_) { + return; + } + auto layer = std::make_unique(); + layer->set_offset(SkPoint::Make(dx, dy)); + layer->set_size(SkSize::Make(width, height)); + layer->set_texture_id(textureId); + layer->set_freeze(freeze); + current_layer_->Add(std::move(layer)); } void SceneBuilder::addChildScene(double dx, @@ -151,10 +237,19 @@ void SceneBuilder::addChildScene(double dx, SceneHost* sceneHost, bool hitTestable) { #if defined(OS_FUCHSIA) - layer_builder_->PushChildScene(SkPoint::Make(dx, dy), // - SkSize::Make(width, height), // - sceneHost->export_node_holder(), // - hitTestable); + if (!current_layer_) { + return; + } + SkRect sceneRect = SkRect::MakeXYWH(dx, dy, width, height); + if (!SkRect::Intersects(sceneRect, cull_rects_.top())) { + return; + } + auto layer = std::make_unique(); + layer->set_offset(SkPoint::Make(dx, dy)); + layer->set_size(SkSize::Make(width, height)); + layer->set_export_node_holder(sceneHost->export_node_holder()); + layer->set_hit_testable(hitTestable); + current_layer_->Add(std::move(layer)); #endif // defined(OS_FUCHSIA) } @@ -163,30 +258,54 @@ void SceneBuilder::addPerformanceOverlay(uint64_t enabledOptions, double right, double top, double bottom) { - layer_builder_->PushPerformanceOverlay( - enabledOptions, SkRect::MakeLTRB(left, top, right, bottom)); + if (!current_layer_) { + return; + } + SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); + auto layer = std::make_unique(enabledOptions); + layer->set_paint_bounds(rect); + current_layer_->Add(std::move(layer)); } void SceneBuilder::setRasterizerTracingThreshold(uint32_t frameInterval) { - layer_builder_->SetRasterizerTracingThreshold(frameInterval); + rasterizer_tracing_threshold_ = frameInterval; } void SceneBuilder::setCheckerboardRasterCacheImages(bool checkerboard) { - layer_builder_->SetCheckerboardRasterCacheImages(checkerboard); + checkerboard_raster_cache_images_ = checkerboard; } void SceneBuilder::setCheckerboardOffscreenLayers(bool checkerboard) { - layer_builder_->SetCheckerboardOffscreenLayers(checkerboard); + checkerboard_offscreen_layers_ = checkerboard; } fml::RefPtr SceneBuilder::build() { - fml::RefPtr scene = - Scene::create(layer_builder_->TakeLayer(), - layer_builder_->GetRasterizerTracingThreshold(), - layer_builder_->GetCheckerboardRasterCacheImages(), - layer_builder_->GetCheckerboardOffscreenLayers()); + fml::RefPtr scene = Scene::create( + std::move(root_layer_), rasterizer_tracing_threshold_, + checkerboard_raster_cache_images_, checkerboard_offscreen_layers_); ClearDartWrapper(); return scene; } +void SceneBuilder::PushLayer(std::unique_ptr layer, + const SkRect& cullRect) { + FML_DCHECK(layer); + + cull_rects_.push(cullRect); + + if (!root_layer_) { + root_layer_ = std::move(layer); + current_layer_ = root_layer_.get(); + return; + } + + if (!current_layer_) { + return; + } + + flow::ContainerLayer* newLayer = layer.get(); + current_layer_->Add(std::move(layer)); + current_layer_ = newLayer; +} + } // namespace blink diff --git a/lib/ui/compositing/scene_builder.h b/lib/ui/compositing/scene_builder.h index 0ad46b36138a1..fc7bcc6a956f7 100644 --- a/lib/ui/compositing/scene_builder.h +++ b/lib/ui/compositing/scene_builder.h @@ -9,7 +9,6 @@ #include #include -#include "flutter/flow/layers/layer_builder.h" #include "flutter/lib/ui/compositing/scene.h" #include "flutter/lib/ui/compositing/scene_host.h" #include "flutter/lib/ui/dart_wrapper.h" @@ -92,7 +91,19 @@ class SceneBuilder : public RefCountedDartWrappable { private: SceneBuilder(); - std::unique_ptr layer_builder_; + std::unique_ptr root_layer_; + flow::ContainerLayer* current_layer_ = nullptr; + + std::stack cull_rects_; + + int rasterizer_tracing_threshold_ = 0; + bool checkerboard_raster_cache_images_ = false; + bool checkerboard_offscreen_layers_ = false; + + void PushLayer(std::unique_ptr layer, + const SkRect& cullRect); + + FML_DISALLOW_COPY_AND_ASSIGN(SceneBuilder); }; } // namespace blink