From c40bc44b52aac80e60c1b406e26c2eac924d0a7b Mon Sep 17 00:00:00 2001 From: davidhicks980 <59215665+davidhicks980@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:49:18 -0400 Subject: [PATCH 01/12] Change "there own" to "their own" in Flutter-GPU docs (#54921) Changed the word "there" to "their" in Flutter GPU doc... which I think is correct, but I could be wrong. Thanks! - [] I listed at least one issue that this PR fixes in the description above. - [] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- docs/impeller/Flutter-GPU.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/impeller/Flutter-GPU.md b/docs/impeller/Flutter-GPU.md index 4dc848ef49127..6f698e5a10245 100644 --- a/docs/impeller/Flutter-GPU.md +++ b/docs/impeller/Flutter-GPU.md @@ -12,7 +12,7 @@ Currently, our best getting started resource is [this article](https://medium.co There is also an experimental 3D rendering package powered by Flutter GPU called [Flutter Scene](https://pub.dev/packages/flutter_scene). -Flutter GPU is a low level API for building rendering packages from scratch. Graphics programming has a steep learning curve, and it's likely that most users will opt to use a higher level rendering package rather than build there own. +Flutter GPU is a low level API for building rendering packages from scratch. Graphics programming has a steep learning curve, and it's likely that most users will opt to use a higher level rendering package rather than build their own. ## Distribution From 7f2718dec797a48d3f20761b186696bfdf92dfe7 Mon Sep 17 00:00:00 2001 From: skia-flutter-autoroll Date: Fri, 6 Sep 2024 13:03:27 -0400 Subject: [PATCH 02/12] Roll Skia from 6ad117bd2efe to 8f62a6a4a299 (1 revision) (#55001) https://skia.googlesource.com/skia.git/+log/6ad117bd2efe..8f62a6a4a299 2024-09-06 michaelludwig@google.com [graphite] Move SkSL compilation into MtlGraphics|ComputePipeline::Make If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/skia-flutter-autoroll Please CC brianosman@google.com,codefu@google.com,jlavrova@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Skia: https://bugs.chromium.org/p/skia/issues/entry To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md --- DEPS | 2 +- ci/licenses_golden/licenses_skia | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index fc13f793b3fcf..29c994a1ded88 100644 --- a/DEPS +++ b/DEPS @@ -14,7 +14,7 @@ vars = { 'flutter_git': 'https://flutter.googlesource.com', 'skia_git': 'https://skia.googlesource.com', 'llvm_git': 'https://llvm.googlesource.com', - 'skia_revision': '6ad117bd2efebf44fee0f59bd85e5c70b6721cb1', + 'skia_revision': '8f62a6a4a2996da0359684857b925541e8117c7e', # WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY # See `lib/web_ui/README.md` for how to roll CanvasKit to a new version. diff --git a/ci/licenses_golden/licenses_skia b/ci/licenses_golden/licenses_skia index e780ca2cb133b..201d795042f2d 100644 --- a/ci/licenses_golden/licenses_skia +++ b/ci/licenses_golden/licenses_skia @@ -1,4 +1,4 @@ -Signature: 58053a8420a7f1de9211979af347a49a +Signature: a76fecb4dbcac3523b2cf610095fc217 ==================================================================================================== LIBRARY: etc1 From 0563637c277bbb1d80119782c9c0ddfdfa05593e Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 6 Sep 2024 11:53:53 -0700 Subject: [PATCH 03/12] [impeller] fake image for fake tests. (#54974) Simulator only change to allow toImage and toByteData to not fail when there is no metal context w/ impeller. --- display_list/image/dl_image.h | 6 ++++- impeller/display_list/dl_image_impeller.cc | 28 ++++++++++++++++++-- impeller/display_list/dl_image_impeller.h | 22 +++++++++++++-- lib/ui/painting/image.cc | 3 +-- lib/ui/painting/image_encoding.cc | 8 ++++++ lib/ui/painting/picture.cc | 1 - shell/common/snapshot_controller_impeller.cc | 17 +++++++++++- 7 files changed, 76 insertions(+), 9 deletions(-) diff --git a/display_list/image/dl_image.h b/display_list/image/dl_image.h index aecb58b8f7631..7f0828171e3ae 100644 --- a/display_list/image/dl_image.h +++ b/display_list/image/dl_image.h @@ -9,7 +9,7 @@ #include #include -#include "flutter/fml/macros.h" +#include "flutter/fml/build_config.h" #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkRefCnt.h" @@ -118,6 +118,10 @@ class DlImage : public SkRefCnt { /// image. virtual std::optional get_error() const; +#if FML_OS_IOS_SIMULATOR + virtual bool IsFakeImage() const { return false; } +#endif // FML_OS_IOS_SIMULATOR + bool Equals(const DlImage* other) const { if (!other) { return false; diff --git a/impeller/display_list/dl_image_impeller.cc b/impeller/display_list/dl_image_impeller.cc index e5af07f6a2ffc..88127ab9818c9 100644 --- a/impeller/display_list/dl_image_impeller.cc +++ b/impeller/display_list/dl_image_impeller.cc @@ -9,6 +9,17 @@ namespace impeller { +#if FML_OS_IOS_SIMULATOR +sk_sp DlImageImpeller::Make(std::shared_ptr texture, + OwningContext owning_context, + bool is_fake_image) { + if (!texture && !is_fake_image) { + return nullptr; + } + return sk_sp( + new DlImageImpeller(std::move(texture), owning_context, is_fake_image)); +} +#else sk_sp DlImageImpeller::Make(std::shared_ptr texture, OwningContext owning_context) { if (!texture) { @@ -17,6 +28,7 @@ sk_sp DlImageImpeller::Make(std::shared_ptr texture, return sk_sp( new DlImageImpeller(std::move(texture), owning_context)); } +#endif // FML_OS_IOS_SIMULATOR sk_sp DlImageImpeller::MakeFromYUVTextures( AiksContext* aiks_context, @@ -45,8 +57,20 @@ sk_sp DlImageImpeller::MakeFromYUVTextures( } DlImageImpeller::DlImageImpeller(std::shared_ptr texture, - OwningContext owning_context) - : texture_(std::move(texture)), owning_context_(owning_context) {} + OwningContext owning_context +#ifdef FML_OS_IOS_SIMULATOR + , + bool is_fake_image +#endif // FML_OS_IOS_SIMULATOR + ) + : texture_(std::move(texture)), + owning_context_(owning_context) +#ifdef FML_OS_IOS_SIMULATOR + , + is_fake_image_(is_fake_image) +#endif // #ifdef FML_OS_IOS_SIMULATOR +{ +} // |DlImage| DlImageImpeller::~DlImageImpeller() = default; diff --git a/impeller/display_list/dl_image_impeller.h b/impeller/display_list/dl_image_impeller.h index 920c21fc8f138..0faf2f1491a5b 100644 --- a/impeller/display_list/dl_image_impeller.h +++ b/impeller/display_list/dl_image_impeller.h @@ -16,7 +16,12 @@ class DlImageImpeller final : public flutter::DlImage { public: static sk_sp Make( std::shared_ptr texture, - OwningContext owning_context = OwningContext::kIO); + OwningContext owning_context = OwningContext::kIO +#if FML_OS_IOS_SIMULATOR + , + bool is_fake_image = false +#endif // FML_OS_IOS_SIMULATOR + ); static sk_sp MakeFromYUVTextures( AiksContext* aiks_context, @@ -51,12 +56,25 @@ class DlImageImpeller final : public flutter::DlImage { // |DlImage| OwningContext owning_context() const override { return owning_context_; } +#if FML_OS_IOS_SIMULATOR + // |DlImage| + bool IsFakeImage() const override { return is_fake_image_; } +#endif // FML_OS_IOS_SIMULATOR + private: std::shared_ptr texture_; OwningContext owning_context_; +#if FML_OS_IOS_SIMULATOR + bool is_fake_image_ = false; +#endif // FML_OS_IOS_SIMULATOR explicit DlImageImpeller(std::shared_ptr texture, - OwningContext owning_context = OwningContext::kIO); + OwningContext owning_context = OwningContext::kIO +#if FML_OS_IOS_SIMULATOR + , + bool is_fake_image = false +#endif // FML_OS_IOS_SIMULATOR + ); DlImageImpeller(const DlImageImpeller&) = delete; diff --git a/lib/ui/painting/image.cc b/lib/ui/painting/image.cc index b31ceb71ed73a..dba1a2aa410ec 100644 --- a/lib/ui/painting/image.cc +++ b/lib/ui/painting/image.cc @@ -52,8 +52,7 @@ int CanvasImage::colorSpace() { return ImageEncodingImpeller::GetColorSpace(image_->impeller_texture()); #endif // IMPELLER_SUPPORTS_RENDERING } - - return -1; + return ColorSpace::kSRGB; } } // namespace flutter diff --git a/lib/ui/painting/image_encoding.cc b/lib/ui/painting/image_encoding.cc index 152551ee26ffb..da88fe41b8315 100644 --- a/lib/ui/painting/image_encoding.cc +++ b/lib/ui/painting/image_encoding.cc @@ -178,6 +178,14 @@ Dart_Handle EncodeImage(CanvasImage* canvas_image, auto callback = std::make_unique( tonic::DartState::Current(), callback_handle); +#if IMPELLER_SUPPORTS_RENDERING && FML_OS_IOS_SIMULATOR + if (canvas_image->image()->IsFakeImage()) { + sk_sp data = SkData::MakeEmpty(); + InvokeDataCallback(std::move(callback), data); + return Dart_Null(); + } +#endif // IMPELLER_SUPPORTS_RENDERING && FML_OS_IOS_SIMULATOR + const auto& task_runners = UIDartState::Current()->GetTaskRunners(); // The static leak checker gets confused by the use of fml::MakeCopyable. diff --git a/lib/ui/painting/picture.cc b/lib/ui/painting/picture.cc index 019ec845065d3..a8a0e957a828d 100644 --- a/lib/ui/painting/picture.cc +++ b/lib/ui/painting/picture.cc @@ -207,7 +207,6 @@ Dart_Handle Picture::DoRasterizeToImage(const sk_sp& display_list, height, ui_task, layer_tree = std::move(layer_tree)]() mutable { auto picture_bounds = SkISize::Make(width, height); - sk_sp image; sk_sp snapshot_display_list = display_list; if (layer_tree) { FML_DCHECK(picture_bounds == layer_tree->frame_size()); diff --git a/shell/common/snapshot_controller_impeller.cc b/shell/common/snapshot_controller_impeller.cc index 1dfbd3ff55ba9..2b06c04e4d113 100644 --- a/shell/common/snapshot_controller_impeller.cc +++ b/shell/common/snapshot_controller_impeller.cc @@ -7,6 +7,7 @@ #include #include "flutter/flow/surface.h" +#include "flutter/fml/build_config.h" #include "flutter/fml/trace_event.h" #include "flutter/impeller/display_list/dl_dispatcher.h" #include "flutter/impeller/display_list/dl_image_impeller.h" @@ -126,7 +127,6 @@ void SnapshotControllerImpeller::MakeRasterSnapshot( sk_sp display_list, SkISize picture_size, std::function&)> callback) { - sk_sp result; std::shared_ptr sync_switch = GetDelegate().GetIsGpuDisabledSyncSwitch(); sync_switch->Execute( @@ -143,10 +143,25 @@ void SnapshotControllerImpeller::MakeRasterSnapshot( }, [callback]() { callback(nullptr); }); } else { +#if FML_OS_IOS_SIMULATOR + callback(impeller::DlImageImpeller::Make( + nullptr, DlImage::OwningContext::kRaster, + /*is_fake_image=*/true)); +#else callback(nullptr); + +#endif // FML_OS_IOS_SIMULATOR } }) .SetIfFalse([&] { +#if FML_OS_IOS_SIMULATOR + if (!GetDelegate().GetAiksContext()) { + callback(impeller::DlImageImpeller::Make( + nullptr, DlImage::OwningContext::kRaster, + /*is_fake_image=*/true)); + return; + } +#endif callback(DoMakeRasterSnapshot(display_list, picture_size, GetDelegate().GetAiksContext())); })); From e562f3f214546236cfe91d76d159a528e4e5f70b Mon Sep 17 00:00:00 2001 From: skia-flutter-autoroll Date: Fri, 6 Sep 2024 15:39:52 -0400 Subject: [PATCH 04/12] Roll Skia from 8f62a6a4a299 to f38ea0134dba (4 revisions) (#55008) https://skia.googlesource.com/skia.git/+log/8f62a6a4a299..f38ea0134dba 2024-09-06 michaelludwig@google.com [graphite] Centralize handling of viewport/rtAdjust values 2024-09-06 egdaniel@google.com [Vulkan] Fix deletion of fences on failed submits. 2024-09-06 egdaniel@google.com [Vulkan] Add AHARDWAREBUFFER_FORMAT_R10G10B10A10_UNORM checks to switch statements. 2024-09-06 robertphillips@google.com [graphite] Move lingering Viewer flag handling to SetTestOptions If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/skia-flutter-autoroll Please CC brianosman@google.com,codefu@google.com,jlavrova@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Skia: https://bugs.chromium.org/p/skia/issues/entry To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md --- DEPS | 2 +- ci/licenses_golden/licenses_skia | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index 29c994a1ded88..47503ac317d1d 100644 --- a/DEPS +++ b/DEPS @@ -14,7 +14,7 @@ vars = { 'flutter_git': 'https://flutter.googlesource.com', 'skia_git': 'https://skia.googlesource.com', 'llvm_git': 'https://llvm.googlesource.com', - 'skia_revision': '8f62a6a4a2996da0359684857b925541e8117c7e', + 'skia_revision': 'f38ea0134dbae0419ae222741a3aa28686ee6c32', # WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY # See `lib/web_ui/README.md` for how to roll CanvasKit to a new version. diff --git a/ci/licenses_golden/licenses_skia b/ci/licenses_golden/licenses_skia index 201d795042f2d..d214cecaa99e4 100644 --- a/ci/licenses_golden/licenses_skia +++ b/ci/licenses_golden/licenses_skia @@ -1,4 +1,4 @@ -Signature: a76fecb4dbcac3523b2cf610095fc217 +Signature: e9f2ec144619a4150597f940fa724684 ==================================================================================================== LIBRARY: etc1 From 397987aedeb4ed41ec945fcbe9d347e579513bf4 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 6 Sep 2024 13:33:22 -0700 Subject: [PATCH 05/12] [Impeller] opt into exp canvas. (#54913) Switch back to new canvas implementation, which allows us to complete the display list/impeller interop arc of work. While we're at it, switch the subpass size rounding logic to round out if there is no image filter. Fixes https://github.com/flutter/flutter/issues/152366 Part of https://github.com/flutter/flutter/issues/142054 --- common/config.gni | 2 +- impeller/aiks/canvas.h | 5 + impeller/aiks/experimental_canvas.cc | 189 ++++++++++++++++--------- impeller/aiks/experimental_canvas.h | 13 +- impeller/display_list/dl_dispatcher.cc | 8 +- testing/dart/painting_test.dart | 1 + 6 files changed, 145 insertions(+), 73 deletions(-) diff --git a/common/config.gni b/common/config.gni index 4f8f690811c38..6c2354e7c9128 100644 --- a/common/config.gni +++ b/common/config.gni @@ -37,7 +37,7 @@ declare_args() { slimpeller = false # Opt into new DL dispatcher that skips AIKS layer - experimental_canvas = false + experimental_canvas = true } # feature_defines_list --------------------------------------------------------- diff --git a/impeller/aiks/canvas.h b/impeller/aiks/canvas.h index dbc3a1952dd73..0b0c3554c451d 100644 --- a/impeller/aiks/canvas.h +++ b/impeller/aiks/canvas.h @@ -37,6 +37,11 @@ struct CanvasStackEntry { size_t num_clips = 0u; Scalar distributed_opacity = 1.0f; Entity::RenderingMode rendering_mode = Entity::RenderingMode::kDirect; + // Whether all entities in the current save should be skipped. + bool skipping = false; + // Whether subpass coverage was rounded out to pixel coverage, or if false + // truncated. + bool did_round_out = false; }; enum class PointStyle { diff --git a/impeller/aiks/experimental_canvas.cc b/impeller/aiks/experimental_canvas.cc index 0ea88adc32511..b262e8dbb3a77 100644 --- a/impeller/aiks/experimental_canvas.cc +++ b/impeller/aiks/experimental_canvas.cc @@ -3,7 +3,10 @@ // found in the LICENSE file. #include "impeller/aiks/experimental_canvas.h" + #include +#include + #include "fml/logging.h" #include "fml/trace_event.h" #include "impeller/aiks/canvas.h" @@ -61,7 +64,6 @@ static void ApplyFramebufferBlend(Entity& entity) { static std::shared_ptr FlipBackdrop( std::vector& render_passes, Point global_pass_position, - size_t current_clip_depth, EntityPassClipStack& clip_coverage_stack, ContentContext& renderer) { auto rendering_config = std::move(render_passes.back()); @@ -137,21 +139,16 @@ static std::shared_ptr FlipBackdrop( // Restore any clips that were recorded before the backdrop filter was // applied. - clip_coverage_stack.ActivateClipReplay(); - - // If there are any pending clips to replay, render any that may affect - // the entity we're about to render. - while (const EntityPassClipStack::ReplayResult* next_replay_clip = - clip_coverage_stack.GetNextReplayResult(current_clip_depth)) { - auto& replay_entity = next_replay_clip->entity; + auto& replay_entities = clip_coverage_stack.GetReplayEntities(); + for (const auto& replay : replay_entities) { SetClipScissor( - next_replay_clip->clip_coverage, + replay.clip_coverage, *render_passes.back().inline_pass_context->GetRenderPass(0).pass, global_pass_position); - if (!replay_entity.Render( + if (!replay.entity.Render( renderer, *render_passes.back().inline_pass_context->GetRenderPass(0).pass)) { - VALIDATION_LOG << "Failed to render entity for clip replay."; + VALIDATION_LOG << "Failed to render entity for clip restore."; } } @@ -296,41 +293,43 @@ void ExperimentalCanvas::SetupRenderPass() { } } +void ExperimentalCanvas::SkipUntilMatchingRestore(size_t total_content_depth) { + auto entry = CanvasStackEntry{}; + entry.skipping = true; + entry.clip_depth = current_depth_ + total_content_depth; + transform_stack_.push_back(entry); +} + void ExperimentalCanvas::Save(uint32_t total_content_depth) { + if (IsSkipping()) { + return SkipUntilMatchingRestore(total_content_depth); + } + auto entry = CanvasStackEntry{}; entry.transform = transform_stack_.back().transform; entry.cull_rect = transform_stack_.back().cull_rect; entry.clip_depth = current_depth_ + total_content_depth; entry.distributed_opacity = transform_stack_.back().distributed_opacity; - FML_CHECK(entry.clip_depth <= transform_stack_.back().clip_depth) + FML_DCHECK(entry.clip_depth <= transform_stack_.back().clip_depth) << entry.clip_depth << " <=? " << transform_stack_.back().clip_depth << " after allocating " << total_content_depth; entry.clip_height = transform_stack_.back().clip_height; entry.rendering_mode = Entity::RenderingMode::kDirect; - transform_stack_.emplace_back(entry); + transform_stack_.push_back(entry); } -void ExperimentalCanvas::SaveLayer( - const Paint& paint, - std::optional bounds, - const std::shared_ptr& backdrop_filter, - ContentBoundsPromise bounds_promise, - uint32_t total_content_depth, - bool can_distribute_opacity) { - TRACE_EVENT0("flutter", "Canvas::saveLayer"); - +std::optional ExperimentalCanvas::ComputeCoverageLimit() const { if (!clip_coverage_stack_.HasCoverage()) { // The current clip is empty. This means the pass texture won't be // visible, so skip it. - Save(total_content_depth); - return; + return std::nullopt; } auto maybe_current_clip_coverage = clip_coverage_stack_.CurrentClipCoverage(); if (!maybe_current_clip_coverage.has_value()) { - Save(total_content_depth); - return; + return std::nullopt; } + auto current_clip_coverage = maybe_current_clip_coverage.value(); // The maximum coverage of the subpass. Subpasses textures should never @@ -343,8 +342,28 @@ void ExperimentalCanvas::SaveLayer( .Intersection(current_clip_coverage); if (!maybe_coverage_limit.has_value() || maybe_coverage_limit->IsEmpty()) { - Save(total_content_depth); - return; + return std::nullopt; + } + + return maybe_coverage_limit->Intersection( + Rect::MakeSize(render_target_.GetRenderTargetSize())); +} + +void ExperimentalCanvas::SaveLayer( + const Paint& paint, + std::optional bounds, + const std::shared_ptr& backdrop_filter, + ContentBoundsPromise bounds_promise, + uint32_t total_content_depth, + bool can_distribute_opacity) { + TRACE_EVENT0("flutter", "Canvas::saveLayer"); + if (IsSkipping()) { + return SkipUntilMatchingRestore(total_content_depth); + } + + auto maybe_coverage_limit = ComputeCoverageLimit(); + if (!maybe_coverage_limit.has_value()) { + return SkipUntilMatchingRestore(total_content_depth); } auto coverage_limit = maybe_coverage_limit.value(); @@ -356,10 +375,9 @@ void ExperimentalCanvas::SaveLayer( return; } - std::shared_ptr filter_contents; - if (paint.image_filter) { - filter_contents = paint.image_filter->GetFilterContents(); - } + std::shared_ptr filter_contents = paint.WithImageFilter( + Rect(), transform_stack_.back().transform, + Entity::RenderingMode::kSubpassPrependSnapshotTransform); std::optional maybe_subpass_coverage = ComputeSaveLayerCoverage( bounds.value_or(Rect::MakeMaximum()), @@ -371,13 +389,32 @@ void ExperimentalCanvas::SaveLayer( /*flood_input_coverage=*/!!backdrop_filter // ); - if (!maybe_subpass_coverage.has_value() || - maybe_subpass_coverage->IsEmpty()) { - Save(total_content_depth); - return; + if (!maybe_subpass_coverage.has_value()) { + return SkipUntilMatchingRestore(total_content_depth); } + auto subpass_coverage = maybe_subpass_coverage.value(); + // When an image filter is present, clamp to avoid flicking due to nearest + // sampled image. For other cases, round out to ensure than any geometry is + // not cut off. + // + // See also this bug: https://github.com/flutter/flutter/issues/144213 + // + // TODO(jonahwilliams): this could still round out for filters that use decal + // sampling mode. + ISize subpass_size; + bool did_round_out = false; + if (paint.image_filter) { + subpass_size = ISize(subpass_coverage.GetSize()); + } else { + did_round_out = true; + subpass_size = ISize(IRect::RoundOut(subpass_coverage).GetSize()); + } + if (subpass_size.IsEmpty()) { + return SkipUntilMatchingRestore(total_content_depth); + } + // Backdrop filter state, ignored if there is no BDF. std::shared_ptr backdrop_filter_contents; Point local_position = {0, 0}; @@ -393,11 +430,10 @@ void ExperimentalCanvas::SaveLayer( return filter; }; - auto input_texture = FlipBackdrop(render_passes_, // - GetGlobalPassPosition(), // - std::numeric_limits::max(), // - clip_coverage_stack_, // - renderer_ // + auto input_texture = FlipBackdrop(render_passes_, // + GetGlobalPassPosition(), // + clip_coverage_stack_, // + renderer_ // ); if (!input_texture) { // Validation failures are logged in FlipBackdrop. @@ -419,23 +455,24 @@ void ExperimentalCanvas::SaveLayer( paint_copy.color.alpha *= transform_stack_.back().distributed_opacity; transform_stack_.back().distributed_opacity = 1.0; - render_passes_.push_back(LazyRenderingConfig( - renderer_, // - CreateRenderTarget(renderer_, // - ISize(subpass_coverage.GetSize()), // - Color::BlackTransparent() // - ))); + render_passes_.push_back( + LazyRenderingConfig(renderer_, // + CreateRenderTarget(renderer_, // + subpass_size, // + Color::BlackTransparent() // + ))); save_layer_state_.push_back(SaveLayerState{paint_copy, subpass_coverage}); CanvasStackEntry entry; entry.transform = transform_stack_.back().transform; entry.cull_rect = transform_stack_.back().cull_rect; entry.clip_depth = current_depth_ + total_content_depth; - FML_CHECK(entry.clip_depth <= transform_stack_.back().clip_depth) + FML_DCHECK(entry.clip_depth <= transform_stack_.back().clip_depth) << entry.clip_depth << " <=? " << transform_stack_.back().clip_depth << " after allocating " << total_content_depth; entry.clip_height = transform_stack_.back().clip_height; entry.rendering_mode = Entity::RenderingMode::kSubpassAppendSnapshotTransform; + entry.did_round_out = did_round_out; transform_stack_.emplace_back(entry); // The current clip aiks clip culling can not handle image filters. @@ -484,10 +521,15 @@ bool ExperimentalCanvas::Restore() { // to be overly conservative, but we need to jump the depth to // the clip depth so that the next rendering op will get a // larger depth (it will pre-increment the current_depth_ value). - FML_CHECK(current_depth_ <= transform_stack_.back().clip_depth) + FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth) << current_depth_ << " <=? " << transform_stack_.back().clip_depth; current_depth_ = transform_stack_.back().clip_depth; + if (IsSkipping()) { + transform_stack_.pop_back(); + return true; + } + if (transform_stack_.back().rendering_mode == Entity::RenderingMode::kSubpassAppendSnapshotTransform || transform_stack_.back().rendering_mode == @@ -499,12 +541,13 @@ bool ExperimentalCanvas::Restore() { SaveLayerState save_layer_state = save_layer_state_.back(); save_layer_state_.pop_back(); + auto global_pass_position = GetGlobalPassPosition(); std::shared_ptr contents = PaintPassDelegate(save_layer_state.paint) .CreateContentsForSubpassTarget( lazy_render_pass.inline_pass_context->GetTexture(), - Matrix::MakeTranslation(Vector3{-GetGlobalPassPosition()}) * + Matrix::MakeTranslation(Vector3{-global_pass_position}) * transform_stack_.back().transform); lazy_render_pass.inline_pass_context->EndPass(); @@ -514,16 +557,19 @@ bool ExperimentalCanvas::Restore() { // sampling, so aligning here is important for avoiding visual nearest // sampling errors caused by limited floating point precision when // straddling a half pixel boundary. - // - // We do this in lieu of expanding/rounding out the subpass coverage in - // order to keep the bounds wrapping consistently tight around subpass - // elements. Which is necessary to avoid intense flickering in cases - // where a subpass texture has a large blur filter with clamp sampling. - // - // See also this bug: https://github.com/flutter/flutter/issues/144213 - Point subpass_texture_position = - (save_layer_state.coverage.GetOrigin() - GetGlobalPassPosition()) - .Round(); + Point subpass_texture_position; + if (transform_stack_.back().did_round_out) { + // Subpass coverage was rounded out, origin potentially moved "down" by + // as much as a pixel. + subpass_texture_position = + (save_layer_state.coverage.GetOrigin() - global_pass_position) + .Floor(); + } else { + // Subpass coverage was truncated. Pick the closest phyiscal pixel. + subpass_texture_position = + (save_layer_state.coverage.GetOrigin() - global_pass_position) + .Round(); + } Entity element_entity; element_entity.SetClipDepth(++current_depth_); @@ -545,9 +591,9 @@ bool ExperimentalCanvas::Restore() { // to the render target texture so far need to execute before it's bound // for blending (otherwise the blend pass will end up executing before // all the previous commands in the active pass). - auto input_texture = FlipBackdrop( - render_passes_, GetGlobalPassPosition(), - element_entity.GetClipDepth(), clip_coverage_stack_, renderer_); + auto input_texture = + FlipBackdrop(render_passes_, GetGlobalPassPosition(), + clip_coverage_stack_, renderer_); if (!input_texture) { return false; } @@ -670,6 +716,10 @@ void ExperimentalCanvas::DrawTextFrame( void ExperimentalCanvas::AddRenderEntityToCurrentPass(Entity entity, bool reuse_depth) { + if (IsSkipping()) { + return; + } + entity.SetTransform( Matrix::MakeTranslation(Vector3(-GetGlobalPassPosition())) * entity.GetTransform()); @@ -708,7 +758,7 @@ void ExperimentalCanvas::AddRenderEntityToCurrentPass(Entity entity, // We can render at a depth up to and including the depth of the currently // active clips and we will still be clipped out, but we cannot render at // a depth that is greater than the current clips or we will not be clipped. - FML_CHECK(current_depth_ <= transform_stack_.back().clip_depth) + FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth) << current_depth_ << " <=? " << transform_stack_.back().clip_depth; entity.SetClipDepth(current_depth_); @@ -725,9 +775,8 @@ void ExperimentalCanvas::AddRenderEntityToCurrentPass(Entity entity, // to the render target texture so far need to execute before it's bound // for blending (otherwise the blend pass will end up executing before // all the previous commands in the active pass). - auto input_texture = - FlipBackdrop(render_passes_, GetGlobalPassPosition(), - entity.GetClipDepth(), clip_coverage_stack_, renderer_); + auto input_texture = FlipBackdrop(render_passes_, GetGlobalPassPosition(), + clip_coverage_stack_, renderer_); if (!input_texture) { return; } @@ -763,6 +812,10 @@ void ExperimentalCanvas::AddRenderEntityToCurrentPass(Entity entity, } void ExperimentalCanvas::AddClipEntityToCurrentPass(Entity entity) { + if (IsSkipping()) { + return; + } + auto transform = entity.GetTransform(); entity.SetTransform( Matrix::MakeTranslation(Vector3(-GetGlobalPassPosition())) * transform); @@ -777,7 +830,7 @@ void ExperimentalCanvas::AddClipEntityToCurrentPass(Entity entity) { // to know if a clip will actually be used in advance of storing it in // the DisplayList buffer. // See https://github.com/flutter/flutter/issues/147021 - FML_CHECK(current_depth_ <= transform_stack_.back().clip_depth) + FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth) << current_depth_ << " <=? " << transform_stack_.back().clip_depth; entity.SetClipDepth(transform_stack_.back().clip_depth); diff --git a/impeller/aiks/experimental_canvas.h b/impeller/aiks/experimental_canvas.h index debb4baf088fc..282c71b536410 100644 --- a/impeller/aiks/experimental_canvas.h +++ b/impeller/aiks/experimental_canvas.h @@ -87,6 +87,10 @@ class ExperimentalCanvas : public Canvas { }; private: + /// @brief Compute the current coverage limit in screen space, or + /// std::nullopt. + std::optional ComputeCoverageLimit() const; + // clip depth of the previous save or 0. size_t GetClipHeightFloor() const { if (transform_stack_.size() > 1) { @@ -95,6 +99,13 @@ class ExperimentalCanvas : public Canvas { return 0; } + /// @brief Whether all entites should be skipped until a corresponding + /// restore. + bool IsSkipping() { return transform_stack_.back().skipping; } + + /// @brief Skip all rendering/clipping entities until next restore. + void SkipUntilMatchingRestore(size_t total_content_depth); + ContentContext& renderer_; RenderTarget& render_target_; const bool requires_readback_; @@ -108,7 +119,7 @@ class ExperimentalCanvas : public Canvas { void AddClipEntityToCurrentPass(Entity entity) override; bool BlitToOnscreen(); - Point GetGlobalPassPosition() { + Point GetGlobalPassPosition() const { if (save_layer_state_.empty()) { return Point(0, 0); } diff --git a/impeller/display_list/dl_dispatcher.cc b/impeller/display_list/dl_dispatcher.cc index 18be21f0a4999..2ab56520b3f8c 100644 --- a/impeller/display_list/dl_dispatcher.cc +++ b/impeller/display_list/dl_dispatcher.cc @@ -54,8 +54,9 @@ namespace impeller { // The watchdog object allocated here will automatically double-check // the depth usage at any exit point to the function, or any other // point at which it falls out of scope. -#define AUTO_DEPTH_WATCHER(d) \ - DepthWatcher _watcher(__FILE__, __LINE__, GetCanvas(), d) +#define AUTO_DEPTH_WATCHER(d) \ + DepthWatcher _watcher(__FILE__, __LINE__, GetCanvas(), \ + paint_.mask_blur_descriptor.has_value(), d) // While the AUTO_DEPTH_WATCHER macro will check the depth usage at // any exit point from the dispatch function, sometimes the dispatch @@ -75,11 +76,12 @@ struct DepthWatcher { DepthWatcher(const std::string& file, int line, const impeller::Canvas& canvas, + bool has_mask_blur, int allowed) : file_(file), line_(line), canvas_(canvas), - allowed_(allowed), + allowed_(has_mask_blur ? allowed + 1 : allowed), old_depth_(canvas.GetOpDepth()), old_max_(canvas.GetMaxOpDepth()) {} diff --git a/testing/dart/painting_test.dart b/testing/dart/painting_test.dart index 5c90cc6512107..fc39f9fdb7dc6 100644 --- a/testing/dart/painting_test.dart +++ b/testing/dart/painting_test.dart @@ -89,6 +89,7 @@ void main() { final SceneBuilder sceneBuilder = SceneBuilder(); final Picture redClippedPicture = makePicture((Canvas canvas) { + canvas.drawPaint(Paint()..color = const Color(0xFFFFFFFF)); canvas.clipRect(const Rect.fromLTRB(10, 10, 200, 200)); canvas.clipRect(const Rect.fromLTRB(11, 10, 300, 200)); canvas.drawPaint(Paint()..color = const Color(0xFFFF0000)); From f0bb98a236d5a1f59793723a45b558100768e4e8 Mon Sep 17 00:00:00 2001 From: skia-flutter-autoroll Date: Fri, 6 Sep 2024 17:34:35 -0400 Subject: [PATCH 06/12] Roll Skia from f38ea0134dba to 4786936b4c0c (4 revisions) (#55013) https://skia.googlesource.com/skia.git/+log/f38ea0134dba..4786936b4c0c 2024-09-06 jvanverth@google.com Revert "[graphite] Swap shape inversion for ClipOps." 2024-09-06 kjlubick@google.com Update to Bazel 7 2024-09-06 lukasza@chromium.org [rust png] Implement `SkPngRustCodec::onGetRepetitionCount`. 2024-09-06 michaelludwig@google.com [graphite] Add replayTranslation and dstCopyOffset to intrinsic uniforms If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/skia-flutter-autoroll Please CC brianosman@google.com,codefu@google.com,jlavrova@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Skia: https://bugs.chromium.org/p/skia/issues/entry To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md --- DEPS | 2 +- ci/licenses_golden/licenses_skia | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index 47503ac317d1d..cf8e8da5b99c0 100644 --- a/DEPS +++ b/DEPS @@ -14,7 +14,7 @@ vars = { 'flutter_git': 'https://flutter.googlesource.com', 'skia_git': 'https://skia.googlesource.com', 'llvm_git': 'https://llvm.googlesource.com', - 'skia_revision': 'f38ea0134dbae0419ae222741a3aa28686ee6c32', + 'skia_revision': '4786936b4c0c29fece10661592581ddce5940df0', # WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY # See `lib/web_ui/README.md` for how to roll CanvasKit to a new version. diff --git a/ci/licenses_golden/licenses_skia b/ci/licenses_golden/licenses_skia index d214cecaa99e4..4a203f8028e0f 100644 --- a/ci/licenses_golden/licenses_skia +++ b/ci/licenses_golden/licenses_skia @@ -1,4 +1,4 @@ -Signature: e9f2ec144619a4150597f940fa724684 +Signature: 2b06f6ab3cfdd8b8e019140092055d20 ==================================================================================================== LIBRARY: etc1 @@ -328,6 +328,8 @@ TYPE: LicenseType.bsd FILE: ../../../flutter/third_party/skia/.bazelignore FILE: ../../../flutter/third_party/skia/.bazelproject FILE: ../../../flutter/third_party/skia/Cargo.toml +FILE: ../../../flutter/third_party/skia/MODULE.bazel +FILE: ../../../flutter/third_party/skia/MODULE.bazel.lock FILE: ../../../flutter/third_party/skia/OWNERS_build_files.android FILE: ../../../flutter/third_party/skia/RELEASE_NOTES.md FILE: ../../../flutter/third_party/skia/go.mod From 51d93f8d96cfb959127ed80eb2759b02031f2bfe Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Fri, 6 Sep 2024 15:16:05 -0700 Subject: [PATCH 07/12] [DisplayList] use DlScalar, DlPoint, DlRect exclusively in DlOpReceiver methods (#54982) Wean the DlOpReceiver interface and implementations off of using the SkScalar, Sk[I]Rect, and SkPoint objects in favor of our own DL/Impeller versions. The start of an ongoing effort to eventually compartmentalize all use of Skia interfaces into a single backend rendering module that is one of 2 semi-pluggable renderers. --- display_list/benchmarking/dl_complexity_gl.cc | 61 +++--- display_list/benchmarking/dl_complexity_gl.h | 38 ++-- .../benchmarking/dl_complexity_helper.h | 10 +- .../benchmarking/dl_complexity_metal.cc | 61 +++--- .../benchmarking/dl_complexity_metal.h | 38 ++-- display_list/display_list.h | 2 + display_list/display_list_unittests.cc | 53 +++-- display_list/dl_builder.cc | 174 +++++++-------- display_list/dl_builder.h | 122 +++++------ display_list/dl_canvas.h | 48 ++--- display_list/dl_op_receiver.h | 84 ++++---- display_list/dl_op_records.h | 162 +++++++------- display_list/dl_paint.h | 4 +- display_list/geometry/dl_geometry_types.h | 32 +++ display_list/image/dl_image.h | 8 + display_list/skia/dl_sk_canvas.cc | 2 +- display_list/skia/dl_sk_canvas.h | 2 +- display_list/skia/dl_sk_dispatcher.cc | 107 +++++----- display_list/skia/dl_sk_dispatcher.h | 74 +++---- display_list/testing/dl_test_snippets.cc | 171 +++++++++------ display_list/testing/dl_test_snippets.h | 13 +- display_list/utils/dl_accumulation_rect.cc | 6 + display_list/utils/dl_accumulation_rect.h | 1 + display_list/utils/dl_receiver_utils.h | 70 +++---- impeller/display_list/dl_dispatcher.cc | 198 +++++++++--------- impeller/display_list/dl_dispatcher.h | 148 ++++++------- impeller/display_list/skia_conversions.cc | 23 ++ impeller/display_list/skia_conversions.h | 3 + impeller/geometry/rect.h | 8 + impeller/geometry/rect_unittests.cc | 43 ++++ shell/common/dl_op_spy.cc | 46 ++-- shell/common/dl_op_spy.h | 46 ++-- testing/display_list_testing.cc | 91 ++++---- testing/display_list_testing.h | 144 ++++++------- testing/mock_canvas.cc | 2 +- testing/mock_canvas.h | 2 +- third_party/txt/tests/paragraph_unittests.cc | 8 +- 37 files changed, 1133 insertions(+), 972 deletions(-) diff --git a/display_list/benchmarking/dl_complexity_gl.cc b/display_list/benchmarking/dl_complexity_gl.cc index 0f400f20c9951..28ca569e0cc7e 100644 --- a/display_list/benchmarking/dl_complexity_gl.cc +++ b/display_list/benchmarking/dl_complexity_gl.cc @@ -49,7 +49,7 @@ unsigned int DisplayListGLComplexityCalculator::GLHelper::BatchedComplexity() { } void DisplayListGLComplexityCalculator::GLHelper::saveLayer( - const SkRect& bounds, + const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) { if (IsComplex()) { @@ -64,8 +64,8 @@ void DisplayListGLComplexityCalculator::GLHelper::saveLayer( save_layer_count_++; } -void DisplayListGLComplexityCalculator::GLHelper::drawLine(const SkPoint& p0, - const SkPoint& p1) { +void DisplayListGLComplexityCalculator::GLHelper::drawLine(const DlPoint& p0, + const DlPoint& p1) { if (IsComplex()) { return; } @@ -89,7 +89,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawLine(const SkPoint& p0, // Use an approximation for the distance to avoid floating point or // sqrt() calls. - SkScalar distance = abs(p0.x() - p1.x()) + abs(p0.y() - p1.y()); + DlScalar distance = abs(p0.x - p1.x) + abs(p0.y - p1.y); // The baseline complexity is for a hairline stroke with no AA. // m = 1/40 @@ -107,10 +107,10 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDashedLine( DlScalar off_length) { // Dashing is slightly more complex than a regular drawLine, but this // op is so rare it is not worth measuring the difference. - drawLine(ToSkPoint(p0), ToSkPoint(p1)); + drawLine(p0, p1); } -void DisplayListGLComplexityCalculator::GLHelper::drawRect(const SkRect& rect) { +void DisplayListGLComplexityCalculator::GLHelper::drawRect(const DlRect& rect) { if (IsComplex()) { return; } @@ -126,14 +126,14 @@ void DisplayListGLComplexityCalculator::GLHelper::drawRect(const SkRect& rect) { // currently use it anywhere in Flutter. if (DrawStyle() == DlDrawStyle::kFill) { // No real difference for AA with filled styles - unsigned int area = rect.width() * rect.height(); + unsigned int area = rect.GetWidth() * rect.GetHeight(); // m = 1/3500 // c = 0 complexity = area * 2 / 175; } else { // Take the average of the width and height. - unsigned int length = (rect.width() + rect.height()) / 2; + unsigned int length = (rect.GetWidth() + rect.GetHeight()) / 2; if (IsAntiAliased()) { // m = 1/30 @@ -160,7 +160,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawRect(const SkRect& rect) { } void DisplayListGLComplexityCalculator::GLHelper::drawOval( - const SkRect& bounds) { + const DlRect& bounds) { if (IsComplex()) { return; } @@ -169,7 +169,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawOval( // // Filled styles and stroked styles with AA scale linearly with the bounding // box area. - unsigned int area = bounds.width() * bounds.height(); + unsigned int area = bounds.GetWidth() * bounds.GetHeight(); unsigned int complexity; @@ -187,7 +187,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawOval( complexity = area / 20; } else { // Take the average of the width and height. - unsigned int length = (bounds.width() + bounds.height()) / 2; + unsigned int length = (bounds.GetWidth() + bounds.GetHeight()) / 2; // m = 1/75 // c = 0 @@ -199,8 +199,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawOval( } void DisplayListGLComplexityCalculator::GLHelper::drawCircle( - const SkPoint& center, - SkScalar radius) { + const DlPoint& center, + DlScalar radius) { if (IsComplex()) { return; } @@ -372,9 +372,9 @@ void DisplayListGLComplexityCalculator::GLHelper::drawPath(const SkPath& path) { } void DisplayListGLComplexityCalculator::GLHelper::drawArc( - const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) { if (IsComplex()) { return; @@ -383,7 +383,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawArc( // Stroked styles without AA scale linearly with the log of the diameter. // Stroked styles with AA scale linearly with the area. // Filled styles scale lienarly with the area. - unsigned int area = oval_bounds.width() * oval_bounds.height(); + unsigned int area = oval_bounds.GetWidth() * oval_bounds.GetHeight(); unsigned int complexity; // These values were worked out by creating a straight line graph (y=mx+c) @@ -398,7 +398,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawArc( // c = 12 complexity = (area + 45600) / 171; } else { - unsigned int diameter = (oval_bounds.width() + oval_bounds.height()) / 2; + unsigned int diameter = + (oval_bounds.GetWidth() + oval_bounds.GetHeight()) / 2; // m = 15 // c = -100 // This should never go negative though, so use std::max to ensure @@ -426,7 +427,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawArc( void DisplayListGLComplexityCalculator::GLHelper::drawPoints( DlCanvas::PointMode mode, uint32_t count, - const SkPoint points[]) { + const DlPoint points[]) { if (IsComplex()) { return; } @@ -514,7 +515,7 @@ void DisplayListGLComplexityCalculator::GLHelper::drawVertices( void DisplayListGLComplexityCalculator::GLHelper::drawImage( const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) { if (IsComplex()) { @@ -594,8 +595,8 @@ void DisplayListGLComplexityCalculator::GLHelper::ImageRect( void DisplayListGLComplexityCalculator::GLHelper::drawImageNine( const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) { if (IsComplex()) { @@ -619,13 +620,13 @@ void DisplayListGLComplexityCalculator::GLHelper::drawImageNine( void DisplayListGLComplexityCalculator::GLHelper::drawDisplayList( const sk_sp display_list, - SkScalar opacity) { + DlScalar opacity) { if (IsComplex()) { return; } GLHelper helper(Ceiling() - CurrentComplexityScore()); if (opacity < SK_Scalar1 && !display_list->can_apply_group_opacity()) { - auto bounds = display_list->bounds(); + auto bounds = display_list->GetBounds(); helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr); } display_list->Dispatch(helper); @@ -634,8 +635,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDisplayList( void DisplayListGLComplexityCalculator::GLHelper::drawTextBlob( const sk_sp blob, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { if (IsComplex()) { return; } @@ -650,15 +651,15 @@ void DisplayListGLComplexityCalculator::GLHelper::drawTextBlob( void DisplayListGLComplexityCalculator::GLHelper::drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) {} + DlScalar x, + DlScalar y) {} void DisplayListGLComplexityCalculator::GLHelper::drawShadow( const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { if (IsComplex()) { return; } diff --git a/display_list/benchmarking/dl_complexity_gl.h b/display_list/benchmarking/dl_complexity_gl.h index 119b47d2e31a1..53849599db0ba 100644 --- a/display_list/benchmarking/dl_complexity_gl.h +++ b/display_list/benchmarking/dl_complexity_gl.h @@ -35,52 +35,52 @@ class DisplayListGLComplexityCalculator explicit GLHelper(unsigned int ceiling) : ComplexityCalculatorHelper(ceiling) {} - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override; - void drawLine(const SkPoint& p0, const SkPoint& p1) override; + void drawLine(const DlPoint& p0, const DlPoint& p1) override; void drawDashedLine(const DlPoint& p0, const DlPoint& p1, DlScalar on_length, DlScalar off_length) override; - void drawRect(const SkRect& rect) override; - void drawOval(const SkRect& bounds) override; - void drawCircle(const SkPoint& center, SkScalar radius) override; + void drawRect(const DlRect& rect) override; + void drawOval(const DlRect& bounds) override; + void drawCircle(const DlPoint& center, DlScalar radius) override; void drawRRect(const SkRRect& rrect) override; void drawDRRect(const SkRRect& outer, const SkRRect& inner) override; void drawPath(const SkPath& path) override; - void drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + void drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) override; void drawPoints(DlCanvas::PointMode mode, uint32_t count, - const SkPoint points[]) override; + const DlPoint points[]) override; void drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) override; void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) override; void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) override; void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override; + DlScalar opacity) override; void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override; + DlScalar dpr) override; protected: void ImageRect(const SkISize& size, diff --git a/display_list/benchmarking/dl_complexity_helper.h b/display_list/benchmarking/dl_complexity_helper.h index 3b4e8dc06f6d9..8393151d32113 100644 --- a/display_list/benchmarking/dl_complexity_helper.h +++ b/display_list/benchmarking/dl_complexity_helper.h @@ -145,8 +145,8 @@ class ComplexityCalculatorHelper void drawImageRect( const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint = SrcRectConstraint::kFast) override { @@ -159,12 +159,12 @@ class ComplexityCalculatorHelper void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) override { if (IsComplex()) { return; @@ -172,7 +172,7 @@ class ComplexityCalculatorHelper // This API just does a series of drawImage calls from the atlas // This is equivalent to calling drawImageRect lots of times for (int i = 0; i < count; i++) { - ImageRect(SkISize::Make(tex[i].width(), tex[i].height()), true, + ImageRect(SkISize::Make(tex[i].GetWidth(), tex[i].GetHeight()), true, render_with_attributes, true); } } diff --git a/display_list/benchmarking/dl_complexity_metal.cc b/display_list/benchmarking/dl_complexity_metal.cc index 20a5af86a4608..6f69eb8a2d7a5 100644 --- a/display_list/benchmarking/dl_complexity_metal.cc +++ b/display_list/benchmarking/dl_complexity_metal.cc @@ -63,7 +63,7 @@ DisplayListMetalComplexityCalculator::MetalHelper::BatchedComplexity() { } void DisplayListMetalComplexityCalculator::MetalHelper::saveLayer( - const SkRect& bounds, + const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) { if (IsComplex()) { @@ -79,8 +79,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::saveLayer( } void DisplayListMetalComplexityCalculator::MetalHelper::drawLine( - const SkPoint& p0, - const SkPoint& p1) { + const DlPoint& p0, + const DlPoint& p1) { if (IsComplex()) { return; } @@ -100,7 +100,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawLine( // Use an approximation for the distance to avoid floating point or // sqrt() calls. - SkScalar distance = abs(p0.x() - p1.x()) + abs(p0.y() - p1.y()); + DlScalar distance = abs(p0.x - p1.x) + abs(p0.y - p1.y); // The baseline complexity is for a hairline stroke with no AA. // m = 1/45 @@ -118,11 +118,11 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawDashedLine( DlScalar off_length) { // Dashing is slightly more complex than a regular drawLine, but this // op is so rare it is not worth measuring the difference. - drawLine(ToSkPoint(p0), ToSkPoint(p1)); + drawLine(p0, p1); } void DisplayListMetalComplexityCalculator::MetalHelper::drawRect( - const SkRect& rect) { + const DlRect& rect) { if (IsComplex()) { return; } @@ -140,14 +140,14 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawRect( // currently use it anywhere in Flutter. if (DrawStyle() == DlDrawStyle::kFill) { // No real difference for AA with filled styles. - unsigned int area = rect.width() * rect.height(); + unsigned int area = rect.GetWidth() * rect.GetHeight(); // m = 1/9000 // c = 0 complexity = area / 225; } else { // Take the average of the width and height. - unsigned int length = (rect.width() + rect.height()) / 2; + unsigned int length = (rect.GetWidth() + rect.GetHeight()) / 2; // There is a penalty for AA being *disabled*. if (IsAntiAliased()) { @@ -165,7 +165,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawRect( } void DisplayListMetalComplexityCalculator::MetalHelper::drawOval( - const SkRect& bounds) { + const DlRect& bounds) { if (IsComplex()) { return; } @@ -174,7 +174,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawOval( // // Filled styles and stroked styles with AA scale linearly with the bounding // box area. - unsigned int area = bounds.width() * bounds.height(); + unsigned int area = bounds.GetWidth() * bounds.GetHeight(); unsigned int complexity; @@ -192,7 +192,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawOval( complexity = area * 2 / 75; } else { // Take the average of the width and height. - unsigned int length = (bounds.width() + bounds.height()) / 2; + unsigned int length = (bounds.GetWidth() + bounds.GetHeight()) / 2; // m = 1/80 // c = 0 @@ -204,8 +204,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawOval( } void DisplayListMetalComplexityCalculator::MetalHelper::drawCircle( - const SkPoint& center, - SkScalar radius) { + const DlPoint& center, + DlScalar radius) { if (IsComplex()) { return; } @@ -362,9 +362,9 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawPath( } void DisplayListMetalComplexityCalculator::MetalHelper::drawArc( - const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) { if (IsComplex()) { return; @@ -373,8 +373,9 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawArc( // Stroked styles without AA scale linearly with the diameter. // Stroked styles with AA scale linearly with the area except for small // values. Filled styles scale linearly with the area. - unsigned int diameter = (oval_bounds.width() + oval_bounds.height()) / 2; - unsigned int area = oval_bounds.width() * oval_bounds.height(); + unsigned int diameter = + (oval_bounds.GetWidth() + oval_bounds.GetHeight()) / 2; + unsigned int area = oval_bounds.GetWidth() * oval_bounds.GetHeight(); unsigned int complexity; @@ -412,7 +413,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawArc( void DisplayListMetalComplexityCalculator::MetalHelper::drawPoints( DlCanvas::PointMode mode, uint32_t count, - const SkPoint points[]) { + const DlPoint points[]) { if (IsComplex()) { return; } @@ -466,7 +467,7 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawVertices( void DisplayListMetalComplexityCalculator::MetalHelper::drawImage( const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) { if (IsComplex()) { @@ -543,8 +544,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::ImageRect( void DisplayListMetalComplexityCalculator::MetalHelper::drawImageNine( const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) { if (IsComplex()) { @@ -563,13 +564,13 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawImageNine( void DisplayListMetalComplexityCalculator::MetalHelper::drawDisplayList( const sk_sp display_list, - SkScalar opacity) { + DlScalar opacity) { if (IsComplex()) { return; } MetalHelper helper(Ceiling() - CurrentComplexityScore()); if (opacity < SK_Scalar1 && !display_list->can_apply_group_opacity()) { - auto bounds = display_list->bounds(); + auto bounds = display_list->GetBounds(); helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr); } display_list->Dispatch(helper); @@ -578,8 +579,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawDisplayList( void DisplayListMetalComplexityCalculator::MetalHelper::drawTextBlob( const sk_sp blob, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { if (IsComplex()) { return; } @@ -594,15 +595,15 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawTextBlob( void DisplayListMetalComplexityCalculator::MetalHelper::drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) {} + DlScalar x, + DlScalar y) {} void DisplayListMetalComplexityCalculator::MetalHelper::drawShadow( const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { if (IsComplex()) { return; } diff --git a/display_list/benchmarking/dl_complexity_metal.h b/display_list/benchmarking/dl_complexity_metal.h index 2038001a1802d..8c428cd571737 100644 --- a/display_list/benchmarking/dl_complexity_metal.h +++ b/display_list/benchmarking/dl_complexity_metal.h @@ -35,52 +35,52 @@ class DisplayListMetalComplexityCalculator explicit MetalHelper(unsigned int ceiling) : ComplexityCalculatorHelper(ceiling) {} - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override; - void drawLine(const SkPoint& p0, const SkPoint& p1) override; + void drawLine(const DlPoint& p0, const DlPoint& p1) override; void drawDashedLine(const DlPoint& p0, const DlPoint& p1, DlScalar on_length, DlScalar off_length) override; - void drawRect(const SkRect& rect) override; - void drawOval(const SkRect& bounds) override; - void drawCircle(const SkPoint& center, SkScalar radius) override; + void drawRect(const DlRect& rect) override; + void drawOval(const DlRect& bounds) override; + void drawCircle(const DlPoint& center, DlScalar radius) override; void drawRRect(const SkRRect& rrect) override; void drawDRRect(const SkRRect& outer, const SkRRect& inner) override; void drawPath(const SkPath& path) override; - void drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + void drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) override; void drawPoints(DlCanvas::PointMode mode, uint32_t count, - const SkPoint points[]) override; + const DlPoint points[]) override; void drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) override; void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) override; void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) override; void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override; + DlScalar opacity) override; void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override; + DlScalar dpr) override; protected: void ImageRect(const SkISize& size, diff --git a/display_list/display_list.h b/display_list/display_list.h index 303cb581ab5db..2ab41f130a6b3 100644 --- a/display_list/display_list.h +++ b/display_list/display_list.h @@ -10,6 +10,7 @@ #include "flutter/display_list/dl_blend_mode.h" #include "flutter/display_list/dl_sampling_options.h" +#include "flutter/display_list/geometry/dl_geometry_types.h" #include "flutter/display_list/geometry/dl_rtree.h" #include "flutter/fml/logging.h" @@ -320,6 +321,7 @@ class DisplayList : public SkRefCnt { uint32_t unique_id() const { return unique_id_; } const SkRect& bounds() const { return bounds_; } + const DlRect& GetBounds() const { return ToDlRect(bounds_); } bool has_rtree() const { return rtree_ != nullptr; } sk_sp rtree() const { return rtree_; } diff --git a/display_list/display_list_unittests.cc b/display_list/display_list_unittests.cc index 796028b1f31a3..8d67422f00c91 100644 --- a/display_list/display_list_unittests.cc +++ b/display_list/display_list_unittests.cc @@ -285,7 +285,7 @@ TEST_F(DisplayListTest, Iteration) { TEST_F(DisplayListTest, InvalidIndices) { DisplayListBuilder builder; - builder.DrawRect(kTestBounds, DlPaint()); + builder.DrawRect(kTestSkBounds, DlPaint()); auto dl = builder.Build(); DisplayListGeneralReceiver receiver; @@ -306,7 +306,7 @@ TEST_F(DisplayListTest, InvalidIndices) { TEST_F(DisplayListTest, ValidIndices) { DisplayListBuilder builder; - builder.DrawRect(kTestBounds, DlPaint()); + builder.DrawRect(kTestSkBounds, DlPaint()); auto dl = builder.Build(); DisplayListGeneralReceiver receiver; @@ -318,10 +318,10 @@ TEST_F(DisplayListTest, ValidIndices) { } TEST_F(DisplayListTest, BuilderCanBeReused) { - DisplayListBuilder builder(kTestBounds); - builder.DrawRect(kTestBounds, DlPaint()); + DisplayListBuilder builder(kTestSkBounds); + builder.DrawRect(kTestSkBounds, DlPaint()); auto dl = builder.Build(); - builder.DrawRect(kTestBounds, DlPaint()); + builder.DrawRect(kTestSkBounds, DlPaint()); auto dl2 = builder.Build(); ASSERT_TRUE(dl->Equals(dl2)); } @@ -1474,13 +1474,13 @@ class SaveLayerExpector : public virtual DlOpReceiver, return *this; } - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override { FML_UNREACHABLE(); } - virtual void saveLayer(const SkRect& bounds, + virtual void saveLayer(const DlRect& bounds, const SaveLayerOptions& options, uint32_t total_content_depth, DlBlendMode max_content_blend_mode, @@ -3718,15 +3718,18 @@ class SaveLayerBoundsExpector : public virtual DlOpReceiver, public: explicit SaveLayerBoundsExpector() {} - SaveLayerBoundsExpector& addComputedExpectation(const SkRect& bounds) { + SaveLayerBoundsExpector& addComputedExpectation(const DlRect& bounds) { expected_.emplace_back(BoundsExpectation{ .bounds = bounds, .options = SaveLayerOptions(), }); return *this; } + SaveLayerBoundsExpector& addComputedExpectation(const SkRect& bounds) { + return addComputedExpectation(ToDlRect(bounds)); + } - SaveLayerBoundsExpector& addSuppliedExpectation(const SkRect& bounds, + SaveLayerBoundsExpector& addSuppliedExpectation(const DlRect& bounds, bool clipped = false) { SaveLayerOptions options; options = options.with_bounds_from_caller(); @@ -3739,8 +3742,12 @@ class SaveLayerBoundsExpector : public virtual DlOpReceiver, }); return *this; } + SaveLayerBoundsExpector& addSuppliedExpectation(const SkRect& bounds, + bool clipped = false) { + return addSuppliedExpectation(ToDlRect(bounds), clipped); + } - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override { ASSERT_LT(save_layer_count_, expected_.size()); @@ -3751,10 +3758,10 @@ class SaveLayerBoundsExpector : public virtual DlOpReceiver, EXPECT_EQ(options.content_is_clipped(), expected.options.content_is_clipped()) << "expected bounds index " << save_layer_count_; - if (!SkScalarNearlyEqual(bounds.fLeft, expected.bounds.fLeft) || - !SkScalarNearlyEqual(bounds.fTop, expected.bounds.fTop) || - !SkScalarNearlyEqual(bounds.fRight, expected.bounds.fRight) || - !SkScalarNearlyEqual(bounds.fBottom, expected.bounds.fBottom)) { + if (!SkScalarNearlyEqual(bounds.GetLeft(), expected.bounds.GetLeft()) || + !SkScalarNearlyEqual(bounds.GetTop(), expected.bounds.GetTop()) || + !SkScalarNearlyEqual(bounds.GetRight(), expected.bounds.GetRight()) || + !SkScalarNearlyEqual(bounds.GetBottom(), expected.bounds.GetBottom())) { EXPECT_EQ(bounds, expected.bounds) << "expected bounds index " << save_layer_count_; } @@ -3767,7 +3774,7 @@ class SaveLayerBoundsExpector : public virtual DlOpReceiver, private: struct BoundsExpectation { - const SkRect bounds; + const DlRect bounds; const SaveLayerOptions options; }; @@ -4205,7 +4212,7 @@ class DepthExpector : public virtual DlOpReceiver, index_++; } - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, SaveLayerOptions options, const DlImageFilter* backdrop) override { // This method should not be called since we override the variant with @@ -4213,7 +4220,7 @@ class DepthExpector : public virtual DlOpReceiver, FAIL() << "saveLayer(no depth parameter) method should not be called"; } - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions& options, uint32_t total_content_depth, DlBlendMode max_content_mode, @@ -4609,7 +4616,7 @@ TEST_F(DisplayListTest, DrawDisplayListForwardsBackdropFlag) { #define CLIP_EXPECTOR(name) ClipExpector name(__FILE__, __LINE__) struct ClipExpectation { - std::variant shape; + std::variant shape; bool is_oval; ClipOp clip_op; bool is_aa; @@ -4632,7 +4639,7 @@ ::std::ostream& operator<<(::std::ostream& os, const ClipExpectation& expect) { os << "Expectation("; switch (expect.shape.index()) { case 0: - os << std::get(expect.shape); + os << std::get(expect.shape); if (expect.is_oval) { os << " (oval)"; } @@ -4674,7 +4681,7 @@ class ClipExpector : public virtual DlOpReceiver, ClipOp clip_op = ClipOp::kIntersect, bool is_aa = false) { clip_expectations_.push_back({ - .shape = rect, + .shape = ToDlRect(rect), .is_oval = false, .clip_op = clip_op, .is_aa = is_aa, @@ -4686,7 +4693,7 @@ class ClipExpector : public virtual DlOpReceiver, ClipOp clip_op = ClipOp::kIntersect, bool is_aa = false) { clip_expectations_.push_back({ - .shape = rect, + .shape = ToDlRect(rect), .is_oval = true, .clip_op = clip_op, .is_aa = is_aa, @@ -4718,12 +4725,12 @@ class ClipExpector : public virtual DlOpReceiver, return *this; } - void clipRect(const SkRect& rect, + void clipRect(const DlRect& rect, DlCanvas::ClipOp clip_op, bool is_aa) override { check(rect, clip_op, is_aa); } - void clipOval(const SkRect& bounds, + void clipOval(const DlRect& bounds, DlCanvas::ClipOp clip_op, bool is_aa) override { check(bounds, clip_op, is_aa, true); diff --git a/display_list/dl_builder.cc b/display_list/dl_builder.cc index cc5211d148832..d1f3707ca80d1 100644 --- a/display_list/dl_builder.cc +++ b/display_list/dl_builder.cc @@ -415,7 +415,7 @@ void DisplayListBuilder::Save() { FML_DCHECK(current_info().has_deferred_save_op); } -void DisplayListBuilder::saveLayer(const SkRect& bounds, +void DisplayListBuilder::saveLayer(const DlRect& bounds, const SaveLayerOptions in_options, const DlImageFilter* backdrop) { SaveLayerOptions options = in_options.without_optimizations(); @@ -523,12 +523,12 @@ void DisplayListBuilder::saveLayer(const SkRect& bounds, // Accumulate options to store in the SaveLayer op record. { - SkRect record_bounds; + DlRect record_bounds; if (in_options.bounds_from_caller()) { options = options.with_bounds_from_caller(); record_bounds = bounds; } else { - FML_DCHECK(record_bounds.isEmpty()); + FML_DCHECK(record_bounds.IsEmpty()); } if (backdrop) { @@ -552,12 +552,12 @@ void DisplayListBuilder::SaveLayer(const SkRect* bounds, const DlPaint* paint, const DlImageFilter* backdrop) { SaveLayerOptions options; - SkRect temp_bounds; + DlRect temp_bounds; if (bounds) { options = options.with_bounds_from_caller(); - temp_bounds = *bounds; + temp_bounds = ToDlRect(*bounds); } else { - temp_bounds.setEmpty(); + FML_DCHECK(temp_bounds.IsEmpty()); } if (paint != nullptr) { options = options.with_renders_with_attributes(); @@ -615,9 +615,10 @@ void DisplayListBuilder::RestoreLayer() { layer_op->type == DisplayListOpType::kSaveLayerBackdrop); if (layer_op->options.bounds_from_caller()) { - if (!content_bounds.isEmpty() && !layer_op->rect.contains(content_bounds)) { + SkRect user_bounds = ToSkRect(layer_op->rect); + if (!content_bounds.isEmpty() && !user_bounds.contains(content_bounds)) { layer_op->options = layer_op->options.with_content_is_clipped(); - if (!content_bounds.intersect(layer_op->rect)) { + if (!content_bounds.intersect(user_bounds)) { // Should never happen because we prune ops that don't intersect the // supplied bounds so content_bounds would already be empty and we // wouldn't come into this control block due to the empty test above. @@ -625,7 +626,7 @@ void DisplayListBuilder::RestoreLayer() { } } } - layer_op->rect = content_bounds; + layer_op->rect = ToDlRect(content_bounds); layer_op->max_blend_mode = current_layer().max_blend_mode; if (current_layer().contains_backdrop_filter) { @@ -807,7 +808,7 @@ void DisplayListBuilder::RestoreToCount(int restore_count) { } } -void DisplayListBuilder::Translate(SkScalar tx, SkScalar ty) { +void DisplayListBuilder::Translate(DlScalar tx, DlScalar ty) { if (std::isfinite(tx) && std::isfinite(ty) && (tx != 0.0 || ty != 0.0)) { checkForDeferredSave(); Push(0, tx, ty); @@ -815,7 +816,7 @@ void DisplayListBuilder::Translate(SkScalar tx, SkScalar ty) { layer_local_state().translate(tx, ty); } } -void DisplayListBuilder::Scale(SkScalar sx, SkScalar sy) { +void DisplayListBuilder::Scale(DlScalar sx, DlScalar sy) { if (std::isfinite(sx) && std::isfinite(sy) && (sx != 1.0 || sy != 1.0)) { checkForDeferredSave(); Push(0, sx, sy); @@ -823,7 +824,7 @@ void DisplayListBuilder::Scale(SkScalar sx, SkScalar sy) { layer_local_state().scale(sx, sy); } } -void DisplayListBuilder::Rotate(SkScalar degrees) { +void DisplayListBuilder::Rotate(DlScalar degrees) { if (SkScalarMod(degrees, 360.0) != 0.0) { checkForDeferredSave(); Push(0, degrees); @@ -831,7 +832,7 @@ void DisplayListBuilder::Rotate(SkScalar degrees) { layer_local_state().rotate(degrees); } } -void DisplayListBuilder::Skew(SkScalar sx, SkScalar sy) { +void DisplayListBuilder::Skew(DlScalar sx, DlScalar sy) { if (std::isfinite(sx) && std::isfinite(sy) && (sx != 0.0 || sy != 0.0)) { checkForDeferredSave(); Push(0, sx, sy); @@ -844,8 +845,8 @@ void DisplayListBuilder::Skew(SkScalar sx, SkScalar sy) { // 2x3 2D affine subset of a 4x4 transform in row major order void DisplayListBuilder::Transform2DAffine( - SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) { + DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) { if (std::isfinite(mxx) && std::isfinite(myx) && std::isfinite(mxy) && std::isfinite(myy) && std::isfinite(mxt) && std::isfinite(myt)) { @@ -866,10 +867,10 @@ void DisplayListBuilder::Transform2DAffine( } // full 4x4 transform in row major order void DisplayListBuilder::TransformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) { + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) { if ( mxz == 0 && myz == 0 && mzx == 0 && mzy == 0 && mzz == 1 && mzt == 0 && @@ -967,10 +968,10 @@ void DisplayListBuilder::ClipRect(const SkRect& rect, checkForDeferredSave(); switch (clip_op) { case ClipOp::kIntersect: - Push(0, rect, is_aa); + Push(0, ToDlRect(rect), is_aa); break; case ClipOp::kDifference: - Push(0, rect, is_aa); + Push(0, ToDlRect(rect), is_aa); break; } } @@ -999,10 +1000,10 @@ void DisplayListBuilder::ClipOval(const SkRect& bounds, checkForDeferredSave(); switch (clip_op) { case ClipOp::kIntersect: - Push(0, bounds, is_aa); + Push(0, ToDlRect(bounds), is_aa); break; case ClipOp::kDifference: - Push(0, bounds, is_aa); + Push(0, ToDlRect(bounds), is_aa); break; } } @@ -1108,8 +1109,8 @@ void DisplayListBuilder::DrawColor(DlColor color, DlBlendMode mode) { UpdateLayerResult(result, mode); } } -void DisplayListBuilder::drawLine(const SkPoint& p0, const SkPoint& p1) { - SkRect bounds = SkRect::MakeLTRB(p0.fX, p0.fY, p1.fX, p1.fY).makeSorted(); +void DisplayListBuilder::drawLine(const DlPoint& p0, const DlPoint& p1) { + SkRect bounds = SkRect::MakeLTRB(p0.x, p0.y, p1.x, p1.y).makeSorted(); DisplayListAttributeFlags flags = (bounds.width() > 0.0f && bounds.height() > 0.0f) ? kDrawLineFlags : kDrawHVLineFlags; @@ -1124,7 +1125,7 @@ void DisplayListBuilder::DrawLine(const SkPoint& p0, const SkPoint& p1, const DlPaint& paint) { SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawLineFlags); - drawLine(p0, p1); + drawLine(ToDlPoint(p0), ToDlPoint(p1)); } void DisplayListBuilder::drawDashedLine(const DlPoint& p0, const DlPoint& p1, @@ -1149,11 +1150,11 @@ void DisplayListBuilder::DrawDashedLine(const DlPoint& p0, SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawLineFlags); drawDashedLine(p0, p1, on_length, off_length); } -void DisplayListBuilder::drawRect(const SkRect& rect) { +void DisplayListBuilder::drawRect(const DlRect& rect) { DisplayListAttributeFlags flags = kDrawRectFlags; OpResult result = PaintResult(current_, flags); if (result != OpResult::kNoEffect && - AccumulateOpBounds(rect.makeSorted(), flags)) { + AccumulateOpBounds(ToSkRect(rect.GetPositive()), flags)) { Push(0, rect); CheckLayerOpacityCompatibility(); UpdateLayerResult(result); @@ -1161,13 +1162,13 @@ void DisplayListBuilder::drawRect(const SkRect& rect) { } void DisplayListBuilder::DrawRect(const SkRect& rect, const DlPaint& paint) { SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawRectFlags); - drawRect(rect); + drawRect(ToDlRect(rect)); } -void DisplayListBuilder::drawOval(const SkRect& bounds) { +void DisplayListBuilder::drawOval(const DlRect& bounds) { DisplayListAttributeFlags flags = kDrawOvalFlags; OpResult result = PaintResult(current_, flags); if (result != OpResult::kNoEffect && - AccumulateOpBounds(bounds.makeSorted(), flags)) { + AccumulateOpBounds(ToSkRect(bounds.GetPositive()), flags)) { Push(0, bounds); CheckLayerOpacityCompatibility(); UpdateLayerResult(result); @@ -1175,14 +1176,14 @@ void DisplayListBuilder::drawOval(const SkRect& bounds) { } void DisplayListBuilder::DrawOval(const SkRect& bounds, const DlPaint& paint) { SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawOvalFlags); - drawOval(bounds); + drawOval(ToDlRect(bounds)); } -void DisplayListBuilder::drawCircle(const SkPoint& center, SkScalar radius) { +void DisplayListBuilder::drawCircle(const DlPoint& center, DlScalar radius) { DisplayListAttributeFlags flags = kDrawCircleFlags; OpResult result = PaintResult(current_, flags); if (result != OpResult::kNoEffect) { - SkRect bounds = SkRect::MakeLTRB(center.fX - radius, center.fY - radius, - center.fX + radius, center.fY + radius); + SkRect bounds = SkRect::MakeLTRB(center.x - radius, center.y - radius, + center.x + radius, center.y + radius); if (AccumulateOpBounds(bounds, flags)) { Push(0, center, radius); CheckLayerOpacityCompatibility(); @@ -1191,16 +1192,16 @@ void DisplayListBuilder::drawCircle(const SkPoint& center, SkScalar radius) { } } void DisplayListBuilder::DrawCircle(const SkPoint& center, - SkScalar radius, + DlScalar radius, const DlPaint& paint) { SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawCircleFlags); - drawCircle(center, radius); + drawCircle(ToDlPoint(center), radius); } void DisplayListBuilder::drawRRect(const SkRRect& rrect) { if (rrect.isRect()) { - drawRect(rrect.rect()); + drawRect(ToDlRect(rrect.rect())); } else if (rrect.isOval()) { - drawOval(rrect.rect()); + drawOval(ToDlRect(rrect.rect())); } else { DisplayListAttributeFlags flags = kDrawRRectFlags; OpResult result = PaintResult(current_, flags); @@ -1252,9 +1253,9 @@ void DisplayListBuilder::DrawPath(const SkPath& path, const DlPaint& paint) { drawPath(path); } -void DisplayListBuilder::drawArc(const SkRect& bounds, - SkScalar start, - SkScalar sweep, +void DisplayListBuilder::drawArc(const DlRect& bounds, + DlScalar start, + DlScalar sweep, bool useCenter) { DisplayListAttributeFlags flags = // useCenter // @@ -1264,7 +1265,8 @@ void DisplayListBuilder::drawArc(const SkRect& bounds, // This could be tighter if we compute where the start and end // angles are and then also consider the quadrants swept and // the center if specified. - if (result != OpResult::kNoEffect && AccumulateOpBounds(bounds, flags)) { + if (result != OpResult::kNoEffect && + AccumulateOpBounds(ToSkRect(bounds), flags)) { Push(0, bounds, start, sweep, useCenter); if (useCenter) { CheckLayerOpacityHairlineCompatibility(); @@ -1275,13 +1277,13 @@ void DisplayListBuilder::drawArc(const SkRect& bounds, } } void DisplayListBuilder::DrawArc(const SkRect& bounds, - SkScalar start, - SkScalar sweep, + DlScalar start, + DlScalar sweep, bool useCenter, const DlPaint& paint) { SetAttributesFromPaint( paint, useCenter ? kDrawArcWithCenterFlags : kDrawArcNoCenterFlags); - drawArc(bounds, start, sweep, useCenter); + drawArc(ToDlRect(bounds), start, sweep, useCenter); } DisplayListAttributeFlags DisplayListBuilder::FlagsForPointMode( @@ -1298,7 +1300,7 @@ DisplayListAttributeFlags DisplayListBuilder::FlagsForPointMode( } void DisplayListBuilder::drawPoints(PointMode mode, uint32_t count, - const SkPoint pts[]) { + const DlPoint pts[]) { if (count == 0) { return; } @@ -1353,7 +1355,7 @@ void DisplayListBuilder::DrawPoints(PointMode mode, const SkPoint pts[], const DlPaint& paint) { SetAttributesFromPaint(paint, FlagsForPointMode(mode)); - drawPoints(mode, count, pts); + drawPoints(mode, count, ToDlPoints(pts)); } void DisplayListBuilder::drawVertices( const std::shared_ptr& vertices, @@ -1389,7 +1391,7 @@ void DisplayListBuilder::DrawVertices( } void DisplayListBuilder::drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) { DisplayListAttributeFlags flags = render_with_attributes // @@ -1399,7 +1401,7 @@ void DisplayListBuilder::drawImage(const sk_sp image, if (result == OpResult::kNoEffect) { return; } - SkRect bounds = SkRect::MakeXYWH(point.fX, point.fY, // + SkRect bounds = SkRect::MakeXYWH(point.x, point.y, // image->width(), image->height()); if (AccumulateOpBounds(bounds, flags)) { render_with_attributes @@ -1411,20 +1413,20 @@ void DisplayListBuilder::drawImage(const sk_sp image, } } void DisplayListBuilder::DrawImage(const sk_sp& image, - const SkPoint point, + const SkPoint& point, DlImageSampling sampling, const DlPaint* paint) { if (paint != nullptr) { SetAttributesFromPaint(*paint, DisplayListOpFlags::kDrawImageWithPaintFlags); - drawImage(image, point, sampling, true); + drawImage(image, ToDlPoint(point), sampling, true); } else { - drawImage(image, point, sampling, false); + drawImage(image, ToDlPoint(point), sampling, false); } } void DisplayListBuilder::drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) { @@ -1432,7 +1434,8 @@ void DisplayListBuilder::drawImageRect(const sk_sp image, ? kDrawImageRectWithPaintFlags : kDrawImageRectFlags; OpResult result = PaintResult(current_, flags); - if (result != OpResult::kNoEffect && AccumulateOpBounds(dst, flags)) { + if (result != OpResult::kNoEffect && + AccumulateOpBounds(ToSkRect(dst), flags)) { Push(0, image, src, dst, sampling, render_with_attributes, constraint); CheckLayerOpacityCompatibility(render_with_attributes); @@ -1449,21 +1452,24 @@ void DisplayListBuilder::DrawImageRect(const sk_sp& image, if (paint != nullptr) { SetAttributesFromPaint(*paint, DisplayListOpFlags::kDrawImageRectWithPaintFlags); - drawImageRect(image, src, dst, sampling, true, constraint); + drawImageRect(image, ToDlRect(src), ToDlRect(dst), sampling, true, + constraint); } else { - drawImageRect(image, src, dst, sampling, false, constraint); + drawImageRect(image, ToDlRect(src), ToDlRect(dst), sampling, false, + constraint); } } void DisplayListBuilder::drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) { DisplayListAttributeFlags flags = render_with_attributes ? kDrawImageNineWithPaintFlags : kDrawImageNineFlags; OpResult result = PaintResult(current_, flags); - if (result != OpResult::kNoEffect && AccumulateOpBounds(dst, flags)) { + if (result != OpResult::kNoEffect && + AccumulateOpBounds(ToSkRect(dst), flags)) { render_with_attributes ? Push(0, image, center, dst, filter) : Push(0, image, center, dst, filter); @@ -1480,19 +1486,19 @@ void DisplayListBuilder::DrawImageNine(const sk_sp& image, if (paint != nullptr) { SetAttributesFromPaint(*paint, DisplayListOpFlags::kDrawImageNineWithPaintFlags); - drawImageNine(image, center, dst, filter, true); + drawImageNine(image, ToDlIRect(center), ToDlRect(dst), filter, true); } else { - drawImageNine(image, center, dst, filter, false); + drawImageNine(image, ToDlIRect(center), ToDlRect(dst), filter, false); } } void DisplayListBuilder::drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) { DisplayListAttributeFlags flags = render_with_attributes // ? kDrawAtlasWithPaintFlags @@ -1504,7 +1510,7 @@ void DisplayListBuilder::drawAtlas(const sk_sp atlas, SkPoint quad[4]; AccumulationRect accumulator; for (int i = 0; i < count; i++) { - const SkRect& src = tex[i]; + const SkRect& src = ToSkRect(tex[i]); xform[i].toQuad(src.width(), src.height(), quad); for (int j = 0; j < 4; j++) { accumulator.accumulate(quad[j]); @@ -1571,16 +1577,16 @@ void DisplayListBuilder::DrawAtlas(const sk_sp& atlas, if (paint != nullptr) { SetAttributesFromPaint(*paint, DisplayListOpFlags::kDrawAtlasWithPaintFlags); - drawAtlas(atlas, xform, tex, colors, count, mode, sampling, cull_rect, - true); + drawAtlas(atlas, xform, ToDlRects(tex), colors, count, mode, sampling, + ToDlRect(cull_rect), true); } else { - drawAtlas(atlas, xform, tex, colors, count, mode, sampling, cull_rect, - false); + drawAtlas(atlas, xform, ToDlRects(tex), colors, count, mode, sampling, + ToDlRect(cull_rect), false); } } void DisplayListBuilder::DrawDisplayList(const sk_sp display_list, - SkScalar opacity) { + DlScalar opacity) { if (!std::isfinite(opacity) || opacity <= SK_ScalarNearlyZero || display_list->op_count() == 0 || display_list->bounds().isEmpty() || current_info().is_nop) { @@ -1650,8 +1656,8 @@ void DisplayListBuilder::DrawDisplayList(const sk_sp display_list, } } void DisplayListBuilder::drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { DisplayListAttributeFlags flags = kDrawTextBlobFlags; OpResult result = PaintResult(current_, flags); if (result == OpResult::kNoEffect) { @@ -1677,8 +1683,8 @@ void DisplayListBuilder::drawTextBlob(const sk_sp blob, } } void DisplayListBuilder::DrawTextBlob(const sk_sp& blob, - SkScalar x, - SkScalar y, + DlScalar x, + DlScalar y, const DlPaint& paint) { SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawTextBlobFlags); drawTextBlob(blob, x, y); @@ -1686,8 +1692,8 @@ void DisplayListBuilder::DrawTextBlob(const sk_sp& blob, void DisplayListBuilder::drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { DisplayListAttributeFlags flags = kDrawTextBlobFlags; OpResult result = PaintResult(current_, flags); if (result == OpResult::kNoEffect) { @@ -1718,8 +1724,8 @@ void DisplayListBuilder::drawTextFrame( void DisplayListBuilder::DrawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y, + DlScalar x, + DlScalar y, const DlPaint& paint) { SetAttributesFromPaint(paint, DisplayListOpFlags::kDrawTextBlobFlags); drawTextFrame(text_frame, x, y); @@ -1727,9 +1733,9 @@ void DisplayListBuilder::DrawTextFrame( void DisplayListBuilder::DrawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { OpResult result = PaintResult(DlPaint(color)); if (result != OpResult::kNoEffect) { SkRect shadow_bounds = @@ -1760,7 +1766,7 @@ bool DisplayListBuilder::AdjustBoundsForPaint(SkRect& bounds, if (is_stroked) { // Determine the max multiplier to the stroke width first. - SkScalar pad = 1.0f; + DlScalar pad = 1.0f; if (current_.getStrokeJoin() == DlStrokeJoin::kMiter && special_flags.may_have_acute_joins()) { pad = std::max(pad, current_.getStrokeMiter()); @@ -1769,7 +1775,7 @@ bool DisplayListBuilder::AdjustBoundsForPaint(SkRect& bounds, special_flags.may_have_diagonal_caps()) { pad = std::max(pad, SK_ScalarSqrt2); } - SkScalar min_stroke_width = 0.01; + DlScalar min_stroke_width = 0.01; pad *= std::max(current_.getStrokeWidth() * 0.5f, min_stroke_width); bounds.outset(pad, pad); } @@ -1781,7 +1787,7 @@ bool DisplayListBuilder::AdjustBoundsForPaint(SkRect& bounds, switch (filter->type()) { case DlMaskFilterType::kBlur: { FML_DCHECK(filter->asBlur()); - SkScalar mask_sigma_pad = filter->asBlur()->sigma() * 3.0; + DlScalar mask_sigma_pad = filter->asBlur()->sigma() * 3.0; bounds.outset(mask_sigma_pad, mask_sigma_pad); } } diff --git a/display_list/dl_builder.h b/display_list/dl_builder.h index d4944d491dc54..f6a7069033385 100644 --- a/display_list/dl_builder.h +++ b/display_list/dl_builder.h @@ -60,26 +60,26 @@ class DisplayListBuilder final : public virtual DlCanvas, void RestoreToCount(int restore_count) override; // |DlCanvas| - void Translate(SkScalar tx, SkScalar ty) override; + void Translate(DlScalar tx, DlScalar ty) override; // |DlCanvas| - void Scale(SkScalar sx, SkScalar sy) override; + void Scale(DlScalar sx, DlScalar sy) override; // |DlCanvas| - void Rotate(SkScalar degrees) override; + void Rotate(DlScalar degrees) override; // |DlCanvas| - void Skew(SkScalar sx, SkScalar sy) override; + void Skew(DlScalar sx, DlScalar sy) override; // clang-format off // 2x3 2D affine subset of a 4x4 transform in row major order // |DlCanvas| - void Transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) override; + void Transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) override; // full 4x4 transform in row major order // |DlCanvas| void TransformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override; + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override; // clang-format on // |DlCanvas| void TransformReset() override; @@ -170,7 +170,7 @@ class DisplayListBuilder final : public virtual DlCanvas, void DrawOval(const SkRect& bounds, const DlPaint& paint) override; // |DlCanvas| void DrawCircle(const SkPoint& center, - SkScalar radius, + DlScalar radius, const DlPaint& paint) override; // |DlCanvas| void DrawRRect(const SkRRect& rrect, const DlPaint& paint) override; @@ -182,8 +182,8 @@ class DisplayListBuilder final : public virtual DlCanvas, void DrawPath(const SkPath& path, const DlPaint& paint) override; // |DlCanvas| void DrawArc(const SkRect& bounds, - SkScalar start, - SkScalar sweep, + DlScalar start, + DlScalar sweep, bool useCenter, const DlPaint& paint) override; // |DlCanvas| @@ -197,7 +197,7 @@ class DisplayListBuilder final : public virtual DlCanvas, const DlPaint& paint) override; // |DlCanvas| void DrawImage(const sk_sp& image, - const SkPoint point, + const SkPoint& point, DlImageSampling sampling, const DlPaint* paint = nullptr) override; // |DlCanvas| @@ -227,28 +227,28 @@ class DisplayListBuilder final : public virtual DlCanvas, const DlPaint* paint = nullptr) override; // |DlCanvas| void DrawDisplayList(const sk_sp display_list, - SkScalar opacity = SK_Scalar1) override; + DlScalar opacity = SK_Scalar1) override; // |DlCanvas| void DrawTextBlob(const sk_sp& blob, - SkScalar x, - SkScalar y, + DlScalar x, + DlScalar y, const DlPaint& paint) override; void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void DrawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y, + DlScalar x, + DlScalar y, const DlPaint& paint) override; // |DlCanvas| void DrawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override; + DlScalar dpr) override; // |DlCanvas| void Flush() override {} @@ -361,35 +361,35 @@ class DisplayListBuilder final : public virtual DlCanvas, void save() override { Save(); } // Only the |renders_with_attributes()| option will be accepted here. Any // other flags will be ignored and calculated anew as the DisplayList is - // built. Alternatively, use the |saveLayer(SkRect, bool)| method. + // built. Alternatively, use the |saveLayer(DlRect, bool)| method. // |DlOpReceiver| - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override; // |DlOpReceiver| void restore() override { Restore(); } // |DlOpReceiver| - void translate(SkScalar tx, SkScalar ty) override { Translate(tx, ty); } + void translate(DlScalar tx, DlScalar ty) override { Translate(tx, ty); } // |DlOpReceiver| - void scale(SkScalar sx, SkScalar sy) override { Scale(sx, sy); } + void scale(DlScalar sx, DlScalar sy) override { Scale(sx, sy); } // |DlOpReceiver| - void rotate(SkScalar degrees) override { Rotate(degrees); } + void rotate(DlScalar degrees) override { Rotate(degrees); } // |DlOpReceiver| - void skew(SkScalar sx, SkScalar sy) override { Skew(sx, sy); } + void skew(DlScalar sx, DlScalar sy) override { Skew(sx, sy); } // clang-format off // |DlOpReceiver| - void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) override { + void transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) override { Transform2DAffine(mxx, mxy, mxt, myx, myy, myt); } // |DlOpReceiver| void transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override { + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override { TransformFullPerspective(mxx, mxy, mxz, mxt, myx, myy, myz, myt, mzx, mzy, mzz, mzt, @@ -400,12 +400,12 @@ class DisplayListBuilder final : public virtual DlCanvas, void transformReset() override { TransformReset(); } // |DlOpReceiver| - void clipRect(const SkRect& rect, ClipOp clip_op, bool is_aa) override { - ClipRect(rect, clip_op, is_aa); + void clipRect(const DlRect& rect, ClipOp clip_op, bool is_aa) override { + ClipRect(ToSkRect(rect), clip_op, is_aa); } // |DlOpReceiver| - void clipOval(const SkRect& bounds, ClipOp clip_op, bool is_aa) override { - ClipOval(bounds, clip_op, is_aa); + void clipOval(const DlRect& bounds, ClipOp clip_op, bool is_aa) override { + ClipOval(ToSkRect(bounds), clip_op, is_aa); } // |DlOpReceiver| void clipRRect(const SkRRect& rrect, ClipOp clip_op, bool is_aa) override { @@ -423,18 +423,18 @@ class DisplayListBuilder final : public virtual DlCanvas, DrawColor(color, mode); } // |DlOpReceiver| - void drawLine(const SkPoint& p0, const SkPoint& p1) override; + void drawLine(const DlPoint& p0, const DlPoint& p1) override; // |DlOpReceiver| void drawDashedLine(const DlPoint& p0, const DlPoint& p1, DlScalar on_length, DlScalar off_length) override; // |DlOpReceiver| - void drawRect(const SkRect& rect) override; + void drawRect(const DlRect& rect) override; // |DlOpReceiver| - void drawOval(const SkRect& bounds) override; + void drawOval(const DlRect& bounds) override; // |DlOpReceiver| - void drawCircle(const SkPoint& center, SkScalar radius) override; + void drawCircle(const DlPoint& center, DlScalar radius) override; // |DlOpReceiver| void drawRRect(const SkRRect& rrect) override; // |DlOpReceiver| @@ -442,61 +442,61 @@ class DisplayListBuilder final : public virtual DlCanvas, // |DlOpReceiver| void drawPath(const SkPath& path) override; // |DlOpReceiver| - void drawArc(const SkRect& bounds, - SkScalar start, - SkScalar sweep, + void drawArc(const DlRect& bounds, + DlScalar start, + DlScalar sweep, bool useCenter) override; // |DlOpReceiver| - void drawPoints(PointMode mode, uint32_t count, const SkPoint pts[]) override; + void drawPoints(PointMode mode, uint32_t count, const DlPoint pts[]) override; // |DlOpReceiver| void drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) override; // |DlOpReceiver| void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) override; // |DlOpReceiver| void drawImageRect( const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint = SrcRectConstraint::kFast) override; // |DlOpReceiver| void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) override; // |DlOpReceiver| void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cullRect, + const DlRect* cullRect, bool render_with_attributes) override; // |DlOpReceiver| void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override { + DlScalar opacity) override { DrawDisplayList(display_list, opacity); } // |DlOpReceiver| void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; // |DlOpReceiver| void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override { + DlScalar dpr) override { DrawShadow(path, color, elevation, transparent_occluder, dpr); } @@ -766,8 +766,8 @@ class DisplayListBuilder final : public virtual DlCanvas, void onSetStrokeCap(DlStrokeCap cap); void onSetStrokeJoin(DlStrokeJoin join); void onSetDrawStyle(DlDrawStyle style); - void onSetStrokeWidth(SkScalar width); - void onSetStrokeMiter(SkScalar limit); + void onSetStrokeWidth(DlScalar width); + void onSetStrokeMiter(DlScalar limit); void onSetColor(DlColor color); void onSetBlendMode(DlBlendMode mode); void onSetColorSource(const DlColorSource* source); diff --git a/display_list/dl_canvas.h b/display_list/dl_canvas.h index 8fa4ad923f307..f21e54a1013bd 100644 --- a/display_list/dl_canvas.h +++ b/display_list/dl_canvas.h @@ -66,22 +66,22 @@ class DlCanvas { virtual int GetSaveCount() const = 0; virtual void RestoreToCount(int restore_count) = 0; - virtual void Translate(SkScalar tx, SkScalar ty) = 0; - virtual void Scale(SkScalar sx, SkScalar sy) = 0; - virtual void Rotate(SkScalar degrees) = 0; - virtual void Skew(SkScalar sx, SkScalar sy) = 0; + virtual void Translate(DlScalar tx, DlScalar ty) = 0; + virtual void Scale(DlScalar sx, DlScalar sy) = 0; + virtual void Rotate(DlScalar degrees) = 0; + virtual void Skew(DlScalar sx, DlScalar sy) = 0; // clang-format off // 2x3 2D affine subset of a 4x4 transform in row major order - virtual void Transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) = 0; + virtual void Transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) = 0; // full 4x4 transform in row major order virtual void TransformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) = 0; + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) = 0; // clang-format on virtual void TransformReset() = 0; virtual void Transform(const SkMatrix* matrix) = 0; @@ -144,7 +144,7 @@ class DlCanvas { virtual void DrawRect(const SkRect& rect, const DlPaint& paint) = 0; virtual void DrawOval(const SkRect& bounds, const DlPaint& paint) = 0; virtual void DrawCircle(const SkPoint& center, - SkScalar radius, + DlScalar radius, const DlPaint& paint) = 0; virtual void DrawRRect(const SkRRect& rrect, const DlPaint& paint) = 0; virtual void DrawDRRect(const SkRRect& outer, @@ -152,8 +152,8 @@ class DlCanvas { const DlPaint& paint) = 0; virtual void DrawPath(const SkPath& path, const DlPaint& paint) = 0; virtual void DrawArc(const SkRect& bounds, - SkScalar start, - SkScalar sweep, + DlScalar start, + DlScalar sweep, bool useCenter, const DlPaint& paint) = 0; virtual void DrawPoints(PointMode mode, @@ -164,7 +164,7 @@ class DlCanvas { DlBlendMode mode, const DlPaint& paint) = 0; virtual void DrawImage(const sk_sp& image, - const SkPoint point, + const SkPoint& point, DlImageSampling sampling, const DlPaint* paint = nullptr) = 0; virtual void DrawImageRect( @@ -205,32 +205,32 @@ class DlCanvas { const SkRect* cullRect, const DlPaint* paint = nullptr) = 0; virtual void DrawDisplayList(const sk_sp display_list, - SkScalar opacity = SK_Scalar1) = 0; + DlScalar opacity = SK_Scalar1) = 0; virtual void DrawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y, + DlScalar x, + DlScalar y, const DlPaint& paint) = 0; virtual void DrawTextBlob(const sk_sp& blob, - SkScalar x, - SkScalar y, + DlScalar x, + DlScalar y, const DlPaint& paint) = 0; virtual void DrawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) = 0; + DlScalar dpr) = 0; virtual void Flush() = 0; - static constexpr SkScalar kShadowLightHeight = 600; - static constexpr SkScalar kShadowLightRadius = 800; + static constexpr DlScalar kShadowLightHeight = 600; + static constexpr DlScalar kShadowLightRadius = 800; static SkRect ComputeShadowBounds(const SkPath& path, float elevation, - SkScalar dpr, + DlScalar dpr, const SkMatrix& ctm); }; diff --git a/display_list/dl_op_receiver.h b/display_list/dl_op_receiver.h index dc85e379e4176..6f0ebae917907 100644 --- a/display_list/dl_op_receiver.h +++ b/display_list/dl_op_receiver.h @@ -93,7 +93,7 @@ class DlOpReceiver { using SrcRectConstraint = DlCanvas::SrcRectConstraint; public: - // MaxDrawPointsCount * sizeof(SkPoint) must be less than 1 << 32 + // MaxDrawPointsCount * sizeof(DlPoint) must be less than 1 << 32 static constexpr int kMaxDrawPointsCount = ((1 << 29) - 1); // --------------------------------------------------------------------- @@ -129,9 +129,9 @@ class DlOpReceiver { virtual void drawPath(const CacheablePath& cache) { FML_UNREACHABLE(); } virtual void drawShadow(const CacheablePath& cache, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { FML_UNREACHABLE(); } // --------------------------------------------------------------------- @@ -181,12 +181,12 @@ class DlOpReceiver { // specified in calling a |DisplayListBuilder| as they will be ignored. // The |backdrop| filter, if not null, is used to initialize the new // layer before further rendering happens. - virtual void saveLayer(const SkRect& bounds, + virtual void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop = nullptr) = 0; // Optional variant of saveLayer() that passes the total depth count of // all rendering operations that occur until the next restore() call. - virtual void saveLayer(const SkRect& bounds, + virtual void saveLayer(const DlRect& bounds, const SaveLayerOptions& options, uint32_t total_content_depth, DlBlendMode max_content_blend_mode, @@ -210,25 +210,25 @@ class DlOpReceiver { // public DisplayListBuilder/DlCanvas public interfaces where possible, // as tracked in: // https://github.com/flutter/flutter/issues/144070 - virtual void saveLayer(const SkRect* bounds, + virtual void saveLayer(const DlRect* bounds, const SaveLayerOptions options, const DlImageFilter* backdrop = nullptr) final { if (bounds) { saveLayer(*bounds, options.with_bounds_from_caller(), backdrop); } else { - saveLayer(SkRect(), options.without_bounds_from_caller(), backdrop); + saveLayer(DlRect(), options.without_bounds_from_caller(), backdrop); } } // --------------------------------------------------------------------- - virtual void translate(SkScalar tx, SkScalar ty) = 0; - virtual void scale(SkScalar sx, SkScalar sy) = 0; - virtual void rotate(SkScalar degrees) = 0; - virtual void skew(SkScalar sx, SkScalar sy) = 0; + virtual void translate(DlScalar tx, DlScalar ty) = 0; + virtual void scale(DlScalar sx, DlScalar sy) = 0; + virtual void rotate(DlScalar degrees) = 0; + virtual void skew(DlScalar sx, DlScalar sy) = 0; // The transform methods all assume the following math for transforming // an arbitrary 3D homogenous point (x, y, z, w). - // All coordinates in the rendering methods (and SkPoint and SkRect objects) + // All coordinates in the rendering methods (and DlPoint and DlRect objects) // represent a simplified coordinate (x, y, 0, 1). // x' = x * mxx + y * mxy + z * mxz + w * mxt // y' = x * myx + y * myy + z * myz + w * myt @@ -309,8 +309,8 @@ class DlOpReceiver { // [ myx myy 0 myt ] // [ 0 0 1 0 ] // [ 0 0 0 1 ] - virtual void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) = 0; + virtual void transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) = 0; // |transformFullPerspective| is equivalent to concatenating the internal // 4x4 transform with the following row major transform matrix: // [ mxx mxy mxz mxt ] @@ -318,17 +318,17 @@ class DlOpReceiver { // [ mzx mzy mzz mzt ] // [ mwx mwy mwz mwt ] virtual void transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) = 0; + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) = 0; // clang-format on // Clears the transformation stack. virtual void transformReset() = 0; - virtual void clipRect(const SkRect& rect, ClipOp clip_op, bool is_aa) = 0; - virtual void clipOval(const SkRect& bounds, ClipOp clip_op, bool is_aa) = 0; + virtual void clipRect(const DlRect& rect, ClipOp clip_op, bool is_aa) = 0; + virtual void clipOval(const DlRect& bounds, ClipOp clip_op, bool is_aa) = 0; virtual void clipRRect(const SkRRect& rrect, ClipOp clip_op, bool is_aa) = 0; virtual void clipPath(const SkPath& path, ClipOp clip_op, bool is_aa) = 0; @@ -341,65 +341,65 @@ class DlOpReceiver { // stream, or assume default attributes. virtual void drawColor(DlColor color, DlBlendMode mode) = 0; virtual void drawPaint() = 0; - virtual void drawLine(const SkPoint& p0, const SkPoint& p1) = 0; + virtual void drawLine(const DlPoint& p0, const DlPoint& p1) = 0; virtual void drawDashedLine(const DlPoint& p0, const DlPoint& p1, DlScalar on_length, DlScalar off_length) = 0; - virtual void drawRect(const SkRect& rect) = 0; - virtual void drawOval(const SkRect& bounds) = 0; - virtual void drawCircle(const SkPoint& center, SkScalar radius) = 0; + virtual void drawRect(const DlRect& rect) = 0; + virtual void drawOval(const DlRect& bounds) = 0; + virtual void drawCircle(const DlPoint& center, DlScalar radius) = 0; virtual void drawRRect(const SkRRect& rrect) = 0; virtual void drawDRRect(const SkRRect& outer, const SkRRect& inner) = 0; virtual void drawPath(const SkPath& path) = 0; - virtual void drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + virtual void drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) = 0; virtual void drawPoints(PointMode mode, uint32_t count, - const SkPoint points[]) = 0; + const DlPoint points[]) = 0; virtual void drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) = 0; virtual void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) = 0; virtual void drawImageRect( const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint = SrcRectConstraint::kFast) = 0; virtual void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) = 0; virtual void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) = 0; virtual void drawDisplayList(const sk_sp display_list, - SkScalar opacity = SK_Scalar1) = 0; + DlScalar opacity = SK_Scalar1) = 0; virtual void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) = 0; + DlScalar x, + DlScalar y) = 0; virtual void drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) = 0; + DlScalar x, + DlScalar y) = 0; virtual void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) = 0; + DlScalar dpr) = 0; }; } // namespace flutter diff --git a/display_list/dl_op_records.h b/display_list/dl_op_records.h index 3cd38e23d12b9..9bc5385195543 100644 --- a/display_list/dl_op_records.h +++ b/display_list/dl_op_records.h @@ -305,10 +305,10 @@ struct SaveOp final : SaveOpBase { // The base struct for all saveLayer() ops // 16 byte SaveOpBase + 20 byte payload packs into 36 bytes struct SaveLayerOpBase : SaveOpBase { - SaveLayerOpBase(const SaveLayerOptions& options, const SkRect& rect) + SaveLayerOpBase(const SaveLayerOptions& options, const DlRect& rect) : SaveOpBase(options), rect(rect) {} - SkRect rect; + DlRect rect; DlBlendMode max_blend_mode = DlBlendMode::kClear; }; // 36 byte SaveLayerOpBase with no additional data packs into 40 bytes @@ -316,7 +316,7 @@ struct SaveLayerOpBase : SaveOpBase { struct SaveLayerOp final : SaveLayerOpBase { static constexpr auto kType = DisplayListOpType::kSaveLayer; - SaveLayerOp(const SaveLayerOptions& options, const SkRect& rect) + SaveLayerOp(const SaveLayerOptions& options, const DlRect& rect) : SaveLayerOpBase(options, rect) {} void dispatch(DlOpReceiver& receiver) const { @@ -329,7 +329,7 @@ struct SaveLayerBackdropOp final : SaveLayerOpBase { static constexpr auto kType = DisplayListOpType::kSaveLayerBackdrop; SaveLayerBackdropOp(const SaveLayerOptions& options, - const SkRect& rect, + const DlRect& rect, const DlImageFilter* backdrop) : SaveLayerOpBase(options, rect), backdrop(backdrop->shared()) {} @@ -369,10 +369,10 @@ struct TransformClipOpBase : DLOp { struct TranslateOp final : TransformClipOpBase { static constexpr auto kType = DisplayListOpType::kTranslate; - TranslateOp(SkScalar tx, SkScalar ty) : tx(tx), ty(ty) {} + TranslateOp(DlScalar tx, DlScalar ty) : tx(tx), ty(ty) {} - const SkScalar tx; - const SkScalar ty; + const DlScalar tx; + const DlScalar ty; void dispatch(DlOpReceiver& receiver) const { // receiver.translate(tx, ty); @@ -383,10 +383,10 @@ struct TranslateOp final : TransformClipOpBase { struct ScaleOp final : TransformClipOpBase { static constexpr auto kType = DisplayListOpType::kScale; - ScaleOp(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {} + ScaleOp(DlScalar sx, DlScalar sy) : sx(sx), sy(sy) {} - const SkScalar sx; - const SkScalar sy; + const DlScalar sx; + const DlScalar sy; void dispatch(DlOpReceiver& receiver) const { // receiver.scale(sx, sy); @@ -396,9 +396,9 @@ struct ScaleOp final : TransformClipOpBase { struct RotateOp final : TransformClipOpBase { static constexpr auto kType = DisplayListOpType::kRotate; - explicit RotateOp(SkScalar degrees) : degrees(degrees) {} + explicit RotateOp(DlScalar degrees) : degrees(degrees) {} - const SkScalar degrees; + const DlScalar degrees; void dispatch(DlOpReceiver& receiver) const { // receiver.rotate(degrees); @@ -409,10 +409,10 @@ struct RotateOp final : TransformClipOpBase { struct SkewOp final : TransformClipOpBase { static constexpr auto kType = DisplayListOpType::kSkew; - SkewOp(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {} + SkewOp(DlScalar sx, DlScalar sy) : sx(sx), sy(sy) {} - const SkScalar sx; - const SkScalar sy; + const DlScalar sx; + const DlScalar sy; void dispatch(DlOpReceiver& receiver) const { // receiver.skew(sx, sy); @@ -424,13 +424,13 @@ struct Transform2DAffineOp final : TransformClipOpBase { static constexpr auto kType = DisplayListOpType::kTransform2DAffine; // clang-format off - Transform2DAffineOp(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) + Transform2DAffineOp(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) : mxx(mxx), mxy(mxy), mxt(mxt), myx(myx), myy(myy), myt(myt) {} // clang-format on - const SkScalar mxx, mxy, mxt; - const SkScalar myx, myy, myt; + const DlScalar mxx, mxy, mxt; + const DlScalar myx, myy, myt; void dispatch(DlOpReceiver& receiver) const { receiver.transform2DAffine(mxx, mxy, mxt, // @@ -444,20 +444,20 @@ struct TransformFullPerspectiveOp final : TransformClipOpBase { // clang-format off TransformFullPerspectiveOp( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) : mxx(mxx), mxy(mxy), mxz(mxz), mxt(mxt), myx(myx), myy(myy), myz(myz), myt(myt), mzx(mzx), mzy(mzy), mzz(mzz), mzt(mzt), mwx(mwx), mwy(mwy), mwz(mwz), mwt(mwt) {} // clang-format on - const SkScalar mxx, mxy, mxz, mxt; - const SkScalar myx, myy, myz, myt; - const SkScalar mzx, mzy, mzz, mzt; - const SkScalar mwx, mwy, mwz, mwt; + const DlScalar mxx, mxy, mxz, mxt; + const DlScalar myx, myy, myz, myt; + const DlScalar mzx, mzy, mzz, mzt; + const DlScalar mwx, mwy, mwz, mwt; void dispatch(DlOpReceiver& receiver) const { receiver.transformFullPerspective(mxx, mxy, mxz, mxt, // @@ -479,7 +479,7 @@ struct TransformResetOp final : TransformClipOpBase { }; // 4 byte header + 4 byte common payload packs into minimum 8 bytes -// SkRect is 16 more bytes, which packs efficiently into 24 bytes total +// DlRect is 16 more bytes, which packs efficiently into 24 bytes total // SkRRect is 52 more bytes, which rounds up to 56 bytes (4 bytes unused) // which packs into 64 bytes total // CacheablePath is 128 more bytes, which packs efficiently into 136 bytes total @@ -492,22 +492,22 @@ struct TransformResetOp final : TransformClipOpBase { struct Clip##clipop##shapename##Op final : TransformClipOpBase { \ static constexpr auto kType = DisplayListOpType::kClip##clipop##shapename; \ \ - Clip##clipop##shapename##Op(Sk##shapetype shape, bool is_aa) \ + Clip##clipop##shapename##Op(shapetype shape, bool is_aa) \ : is_aa(is_aa), shape(shape) {} \ \ const bool is_aa; \ - const Sk##shapetype shape; \ + const shapetype shape; \ \ void dispatch(DlOpReceiver& receiver) const { \ receiver.clip##shapename(shape, DlCanvas::ClipOp::k##clipop, is_aa); \ } \ }; -DEFINE_CLIP_SHAPE_OP(Rect, Rect, Intersect) -DEFINE_CLIP_SHAPE_OP(Oval, Rect, Intersect) -DEFINE_CLIP_SHAPE_OP(RRect, RRect, Intersect) -DEFINE_CLIP_SHAPE_OP(Rect, Rect, Difference) -DEFINE_CLIP_SHAPE_OP(Oval, Rect, Difference) -DEFINE_CLIP_SHAPE_OP(RRect, RRect, Difference) +DEFINE_CLIP_SHAPE_OP(Rect, DlRect, Intersect) +DEFINE_CLIP_SHAPE_OP(Oval, DlRect, Intersect) +DEFINE_CLIP_SHAPE_OP(RRect, SkRRect, Intersect) +DEFINE_CLIP_SHAPE_OP(Rect, DlRect, Difference) +DEFINE_CLIP_SHAPE_OP(Oval, DlRect, Difference) +DEFINE_CLIP_SHAPE_OP(RRect, SkRRect, Difference) #undef DEFINE_CLIP_SHAPE_OP #define DEFINE_CLIP_PATH_OP(clipop) \ @@ -570,9 +570,9 @@ struct DrawColorOp final : DrawOpBase { }; // The common data is a 4 byte header with an unused 4 bytes -// SkRect is 16 more bytes, using 20 bytes which rounds up to 24 bytes total +// DlRect is 16 more bytes, using 20 bytes which rounds up to 24 bytes total // (4 bytes unused) -// SkOval is same as SkRect +// SkOval is same as DlRect // SkRRect is 52 more bytes, which packs efficiently into 56 bytes total #define DEFINE_DRAW_1ARG_OP(op_name, arg_type, arg_name) \ struct Draw##op_name##Op final : DrawOpBase { \ @@ -586,8 +586,8 @@ struct DrawColorOp final : DrawOpBase { receiver.draw##op_name(arg_name); \ } \ }; -DEFINE_DRAW_1ARG_OP(Rect, SkRect, rect) -DEFINE_DRAW_1ARG_OP(Oval, SkRect, oval) +DEFINE_DRAW_1ARG_OP(Rect, DlRect, rect) +DEFINE_DRAW_1ARG_OP(Oval, DlRect, oval) DEFINE_DRAW_1ARG_OP(RRect, SkRRect, rrect) #undef DEFINE_DRAW_1ARG_OP @@ -615,9 +615,9 @@ struct DrawPathOp final : DrawOpBase { }; // The common data is a 4 byte header with an unused 4 bytes -// 2 x SkPoint is 16 more bytes, using 20 bytes rounding up to 24 bytes total +// 2 x DlPoint is 16 more bytes, using 20 bytes rounding up to 24 bytes total // (4 bytes unused) -// SkPoint + SkScalar is 12 more bytes, packing efficiently into 16 bytes total +// DlPoint + DlScalar is 12 more bytes, packing efficiently into 16 bytes total // 2 x SkRRect is 104 more bytes, using 108 and rounding up to 112 bytes total // (4 bytes unused) #define DEFINE_DRAW_2ARG_OP(op_name, type1, name1, type2, name2) \ @@ -634,8 +634,8 @@ struct DrawPathOp final : DrawOpBase { receiver.draw##op_name(name1, name2); \ } \ }; -DEFINE_DRAW_2ARG_OP(Line, SkPoint, p0, SkPoint, p1) -DEFINE_DRAW_2ARG_OP(Circle, SkPoint, center, SkScalar, radius) +DEFINE_DRAW_2ARG_OP(Line, DlPoint, p0, DlPoint, p1) +DEFINE_DRAW_2ARG_OP(Circle, DlPoint, center, DlScalar, radius) DEFINE_DRAW_2ARG_OP(DRRect, SkRRect, outer, SkRRect, inner) #undef DEFINE_DRAW_2ARG_OP @@ -651,8 +651,8 @@ struct DrawDashedLineOp final : DrawOpBase { const DlPoint p0; const DlPoint p1; - const SkScalar on_length; - const SkScalar off_length; + const DlScalar on_length; + const DlScalar off_length; void dispatch(DlOpReceiver& receiver) const { receiver.drawDashedLine(p0, p1, on_length, off_length); @@ -663,12 +663,12 @@ struct DrawDashedLineOp final : DrawOpBase { struct DrawArcOp final : DrawOpBase { static constexpr auto kType = DisplayListOpType::kDrawArc; - DrawArcOp(SkRect bounds, SkScalar start, SkScalar sweep, bool center) + DrawArcOp(DlRect bounds, DlScalar start, DlScalar sweep, bool center) : bounds(bounds), start(start), sweep(sweep), center(center) {} - const SkRect bounds; - const SkScalar start; - const SkScalar sweep; + const DlRect bounds; + const DlScalar start; + const DlScalar sweep; const bool center; void dispatch(DlOpReceiver& receiver) const { @@ -678,7 +678,7 @@ struct DrawArcOp final : DrawOpBase { // 4 byte header + 4 byte fixed payload packs efficiently into 8 bytes // But then there is a list of points following the structure which -// is guaranteed to be a multiple of 8 bytes (SkPoint is 8 bytes) +// is guaranteed to be a multiple of 8 bytes (DlPoint is 8 bytes) // so this op will always pack efficiently // The point type is packed into 3 different OpTypes to avoid expanding // the fixed payload beyond the 8 bytes @@ -691,7 +691,7 @@ struct DrawArcOp final : DrawOpBase { const uint32_t count; \ \ void dispatch(DlOpReceiver& receiver) const { \ - const SkPoint* pts = reinterpret_cast(this + 1); \ + const DlPoint* pts = reinterpret_cast(this + 1); \ receiver.drawPoints(DlCanvas::PointMode::mode, count, pts); \ } \ }; @@ -723,11 +723,11 @@ struct DrawVerticesOp final : DrawOpBase { static constexpr auto kType = DisplayListOpType::k##name; \ \ name##Op(const sk_sp& image, \ - const SkPoint& point, \ + const DlPoint& point, \ DlImageSampling sampling) \ : point(point), sampling(sampling), image(std::move(image)) {} \ \ - const SkPoint point; \ + const DlPoint point; \ const DlImageSampling sampling; \ const sk_sp image; \ \ @@ -752,8 +752,8 @@ struct DrawImageRectOp final : DrawOpBase { static constexpr auto kType = DisplayListOpType::kDrawImageRect; DrawImageRectOp(const sk_sp& image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, DlCanvas::SrcRectConstraint constraint) @@ -764,8 +764,8 @@ struct DrawImageRectOp final : DrawOpBase { constraint(constraint), image(image) {} - const SkRect src; - const SkRect dst; + const DlRect src; + const DlRect dst; const DlImageSampling sampling; const bool render_with_attributes; const DlCanvas::SrcRectConstraint constraint; @@ -793,13 +793,13 @@ struct DrawImageRectOp final : DrawOpBase { static constexpr uint32_t kDepthInc = 9; \ \ name##Op(const sk_sp& image, \ - const SkIRect& center, \ - const SkRect& dst, \ + const DlIRect& center, \ + const DlRect& dst, \ DlFilterMode mode) \ : center(center), dst(dst), mode(mode), image(std::move(image)) {} \ \ - const SkIRect center; \ - const SkRect dst; \ + const DlIRect center; \ + const DlRect dst; \ const DlFilterMode mode; \ const sk_sp image; \ \ @@ -823,7 +823,7 @@ DEFINE_DRAW_IMAGE_NINE_OP(DrawImageNineWithAttr, true) // (4 bytes unused) // Each of these is then followed by a number of lists. // SkRSXform list is a multiple of 16 bytes so it is always packed well -// SkRect list is also a multiple of 16 bytes so it also packs well +// DlRect list is also a multiple of 16 bytes so it also packs well // DlColor list only packs well if the count is even, otherwise there // can be 4 unusued bytes at the end. struct DrawAtlasBaseOp : DrawOpBase { @@ -855,7 +855,7 @@ struct DrawAtlasBaseOp : DrawOpBase { render_with_attributes == other->render_with_attributes && sampling == other->sampling && atlas->Equals(other->atlas)); if (ret) { - size_t bytes = count * (sizeof(SkRSXform) + sizeof(SkRect)); + size_t bytes = count * (sizeof(SkRSXform) + sizeof(DlRect)); if (has_colors) { bytes += count * sizeof(DlColor); } @@ -885,7 +885,7 @@ struct DrawAtlasOp final : DrawAtlasBaseOp { void dispatch(DlOpReceiver& receiver) const { const SkRSXform* xform = reinterpret_cast(this + 1); - const SkRect* tex = reinterpret_cast(xform + count); + const DlRect* tex = reinterpret_cast(xform + count); const DlColor* colors = has_colors ? reinterpret_cast(tex + count) : nullptr; const DlBlendMode mode = static_cast(mode_index); @@ -914,7 +914,7 @@ struct DrawAtlasCulledOp final : DrawAtlasBaseOp { DlBlendMode mode, DlImageSampling sampling, bool has_colors, - const SkRect& cull_rect, + const DlRect& cull_rect, bool render_with_attributes) : DrawAtlasBaseOp(atlas, count, @@ -924,11 +924,11 @@ struct DrawAtlasCulledOp final : DrawAtlasBaseOp { render_with_attributes), cull_rect(cull_rect) {} - const SkRect cull_rect; + const DlRect cull_rect; void dispatch(DlOpReceiver& receiver) const { const SkRSXform* xform = reinterpret_cast(this + 1); - const SkRect* tex = reinterpret_cast(xform + count); + const DlRect* tex = reinterpret_cast(xform + count); const DlColor* colors = has_colors ? reinterpret_cast(tex + count) : nullptr; const DlBlendMode mode = static_cast(mode_index); @@ -952,10 +952,10 @@ struct DrawDisplayListOp final : DrawOpBase { static constexpr auto kType = DisplayListOpType::kDrawDisplayList; explicit DrawDisplayListOp(const sk_sp& display_list, - SkScalar opacity) + DlScalar opacity) : opacity(opacity), display_list(display_list) {} - SkScalar opacity; + DlScalar opacity; const sk_sp display_list; void dispatch(DlOpReceiver& receiver) const { @@ -975,11 +975,11 @@ struct DrawDisplayListOp final : DrawOpBase { struct DrawTextBlobOp final : DrawOpBase { static constexpr auto kType = DisplayListOpType::kDrawTextBlob; - DrawTextBlobOp(const sk_sp& blob, SkScalar x, SkScalar y) + DrawTextBlobOp(const sk_sp& blob, DlScalar x, DlScalar y) : x(x), y(y), blob(blob) {} - const SkScalar x; - const SkScalar y; + const DlScalar x; + const DlScalar y; const sk_sp blob; void dispatch(DlOpReceiver& receiver) const { @@ -991,12 +991,12 @@ struct DrawTextFrameOp final : DrawOpBase { static constexpr auto kType = DisplayListOpType::kDrawTextFrame; DrawTextFrameOp(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) + DlScalar x, + DlScalar y) : x(x), y(y), text_frame(text_frame) {} - const SkScalar x; - const SkScalar y; + const DlScalar x; + const DlScalar y; const std::shared_ptr text_frame; void dispatch(DlOpReceiver& receiver) const { @@ -1011,13 +1011,13 @@ struct DrawTextFrameOp final : DrawOpBase { \ Draw##name##Op(const SkPath& path, \ DlColor color, \ - SkScalar elevation, \ - SkScalar dpr) \ + DlScalar elevation, \ + DlScalar dpr) \ : color(color), elevation(elevation), dpr(dpr), cached_path(path) {} \ \ const DlColor color; \ - const SkScalar elevation; \ - const SkScalar dpr; \ + const DlScalar elevation; \ + const DlScalar dpr; \ const DlOpReceiver::CacheablePath cached_path; \ \ void dispatch(DlOpReceiver& receiver) const { \ diff --git a/display_list/dl_paint.h b/display_list/dl_paint.h index 83e6dd8b0f362..62bf15a04c52f 100644 --- a/display_list/dl_paint.h +++ b/display_list/dl_paint.h @@ -74,8 +74,8 @@ class DlPaint { uint8_t getAlpha() const { return color_.argb() >> 24; } DlPaint& setAlpha(uint8_t alpha) { return setColor(color_.withAlpha(alpha)); } - SkScalar getOpacity() const { return color_.getAlphaF(); } - DlPaint& setOpacity(SkScalar opacity) { + DlScalar getOpacity() const { return color_.getAlphaF(); } + DlPaint& setOpacity(DlScalar opacity) { setAlpha(SkScalarRoundToInt(opacity * 0xff)); return *this; } diff --git a/display_list/geometry/dl_geometry_types.h b/display_list/geometry/dl_geometry_types.h index 4d7132e3b7d62..d50cb367e4f1e 100644 --- a/display_list/geometry/dl_geometry_types.h +++ b/display_list/geometry/dl_geometry_types.h @@ -39,10 +39,26 @@ inline const DlPoint& ToDlPoint(const SkPoint& point) { return *reinterpret_cast(&point); } +inline const DlPoint* ToDlPoints(const SkPoint* points) { + return points == nullptr ? nullptr : reinterpret_cast(points); +} + inline const DlRect& ToDlRect(const SkRect& rect) { return *reinterpret_cast(&rect); } +inline const DlIRect& ToDlIRect(const SkIRect& rect) { + return *reinterpret_cast(&rect); +} + +inline const DlRect* ToDlRect(const SkRect* rect) { + return rect == nullptr ? nullptr : reinterpret_cast(rect); +} + +inline const DlRect* ToDlRects(const SkRect* rects) { + return rects == nullptr ? nullptr : reinterpret_cast(rects); +} + inline const DlISize& ToDlISize(const SkISize& size) { return *reinterpret_cast(&size); } @@ -68,10 +84,26 @@ inline const SkPoint& ToSkPoint(const DlPoint& point) { return *reinterpret_cast(&point); } +inline const SkPoint* ToSkPoints(const DlPoint* points) { + return points == nullptr ? nullptr : reinterpret_cast(points); +} + inline const SkRect& ToSkRect(const DlRect& rect) { return *reinterpret_cast(&rect); } +inline const SkIRect& ToSkIRect(const DlIRect& rect) { + return *reinterpret_cast(&rect); +} + +inline const SkRect* ToSkRect(const DlRect* rect) { + return rect == nullptr ? nullptr : reinterpret_cast(rect); +} + +inline const SkRect* ToSkRects(const DlRect* rects) { + return rects == nullptr ? nullptr : reinterpret_cast(rects); +} + inline const SkISize& ToSkISize(const DlISize& size) { return *reinterpret_cast(&size); } diff --git a/display_list/image/dl_image.h b/display_list/image/dl_image.h index 7f0828171e3ae..fb84c30c4c781 100644 --- a/display_list/image/dl_image.h +++ b/display_list/image/dl_image.h @@ -9,7 +9,9 @@ #include #include +#include "flutter/display_list/geometry/dl_geometry_types.h" #include "flutter/fml/build_config.h" +#include "flutter/fml/macros.h" #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkRefCnt.h" @@ -107,6 +109,12 @@ class DlImage : public SkRefCnt { /// SkIRect bounds() const; + //---------------------------------------------------------------------------- + /// @return The bounds of the pixel grid with 0, 0 as origin. A + /// convenience method that calls |DlImage::dimensions|. + /// + DlIRect GetBounds() const { return ToDlIRect(bounds()); } + //---------------------------------------------------------------------------- /// @return Specifies which context was used to create this image. The /// image must be collected on the same task runner as its diff --git a/display_list/skia/dl_sk_canvas.cc b/display_list/skia/dl_sk_canvas.cc index 7f4da8d3feba8..73191964230f8 100644 --- a/display_list/skia/dl_sk_canvas.cc +++ b/display_list/skia/dl_sk_canvas.cc @@ -268,7 +268,7 @@ void DlSkCanvasAdapter::DrawVertices( } void DlSkCanvasAdapter::DrawImage(const sk_sp& image, - const SkPoint point, + const SkPoint& point, DlImageSampling sampling, const DlPaint* paint) { SkOptionalPaint sk_paint(paint); diff --git a/display_list/skia/dl_sk_canvas.h b/display_list/skia/dl_sk_canvas.h index 5ceebe561ef6b..9a0865b1dec60 100644 --- a/display_list/skia/dl_sk_canvas.h +++ b/display_list/skia/dl_sk_canvas.h @@ -123,7 +123,7 @@ class DlSkCanvasAdapter final : public virtual DlCanvas { DlBlendMode mode, const DlPaint& paint) override; void DrawImage(const sk_sp& image, - const SkPoint point, + const SkPoint& point, DlImageSampling sampling, const DlPaint* paint = nullptr) override; void DrawImageRect( diff --git a/display_list/skia/dl_sk_dispatcher.cc b/display_list/skia/dl_sk_dispatcher.cc index 9dcd34758804d..c4edaad31ea1a 100644 --- a/display_list/skia/dl_sk_dispatcher.cc +++ b/display_list/skia/dl_sk_dispatcher.cc @@ -44,7 +44,7 @@ void DlSkCanvasDispatcher::restore() { canvas_->restore(); restore_opacity(); } -void DlSkCanvasDispatcher::saveLayer(const SkRect& bounds, +void DlSkCanvasDispatcher::saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) { if (!options.content_is_clipped() && options.can_distribute_opacity() && @@ -68,7 +68,8 @@ void DlSkCanvasDispatcher::saveLayer(const SkRect& bounds, TRACE_EVENT0("flutter", "Canvas::saveLayer"); const SkPaint* paint = safe_paint(options.renders_with_attributes()); const sk_sp sk_backdrop = ToSk(backdrop); - const SkRect* sl_bounds = options.bounds_from_caller() ? &bounds : nullptr; + const SkRect* sl_bounds = + options.bounds_from_caller() ? &ToSkRect(bounds) : nullptr; canvas_->saveLayer( SkCanvas::SaveLayerRec(sl_bounds, paint, sk_backdrop.get(), 0)); // saveLayer will apply the current opacity on behalf of the children @@ -77,23 +78,23 @@ void DlSkCanvasDispatcher::saveLayer(const SkRect& bounds, } } -void DlSkCanvasDispatcher::translate(SkScalar tx, SkScalar ty) { +void DlSkCanvasDispatcher::translate(DlScalar tx, DlScalar ty) { canvas_->translate(tx, ty); } -void DlSkCanvasDispatcher::scale(SkScalar sx, SkScalar sy) { +void DlSkCanvasDispatcher::scale(DlScalar sx, DlScalar sy) { canvas_->scale(sx, sy); } -void DlSkCanvasDispatcher::rotate(SkScalar degrees) { +void DlSkCanvasDispatcher::rotate(DlScalar degrees) { canvas_->rotate(degrees); } -void DlSkCanvasDispatcher::skew(SkScalar sx, SkScalar sy) { +void DlSkCanvasDispatcher::skew(DlScalar sx, DlScalar sy) { canvas_->skew(sx, sy); } // clang-format off // 2x3 2D affine subset of a 4x4 transform in row major order void DlSkCanvasDispatcher::transform2DAffine( - SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) { + DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) { // Internally concat(SkMatrix) gets redirected to concat(SkM44) // so we just jump directly to the SkM44 version canvas_->concat(SkM44(mxx, mxy, 0, mxt, @@ -103,10 +104,10 @@ void DlSkCanvasDispatcher::transform2DAffine( } // full 4x4 transform in row major order void DlSkCanvasDispatcher::transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) { + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) { canvas_->concat(SkM44(mxx, mxy, mxz, mxt, myx, myy, myz, myt, mzx, mzy, mzz, mzt, @@ -117,15 +118,15 @@ void DlSkCanvasDispatcher::transformReset() { canvas_->setMatrix(original_transform_); } -void DlSkCanvasDispatcher::clipRect(const SkRect& rect, +void DlSkCanvasDispatcher::clipRect(const DlRect& rect, ClipOp clip_op, bool is_aa) { - canvas_->clipRect(rect, ToSk(clip_op), is_aa); + canvas_->clipRect(ToSkRect(rect), ToSk(clip_op), is_aa); } -void DlSkCanvasDispatcher::clipOval(const SkRect& bounds, +void DlSkCanvasDispatcher::clipOval(const DlRect& bounds, ClipOp clip_op, bool is_aa) { - canvas_->clipRRect(SkRRect::MakeOval(bounds), ToSk(clip_op), is_aa); + canvas_->clipRRect(SkRRect::MakeOval(ToSkRect(bounds)), ToSk(clip_op), is_aa); } void DlSkCanvasDispatcher::clipRRect(const SkRRect& rrect, ClipOp clip_op, @@ -155,8 +156,8 @@ void DlSkCanvasDispatcher::drawColor(DlColor color, DlBlendMode mode) { color4f.fA *= opacity(); canvas_->drawColor(color4f, ToSk(mode)); } -void DlSkCanvasDispatcher::drawLine(const SkPoint& p0, const SkPoint& p1) { - canvas_->drawLine(p0, p1, paint()); +void DlSkCanvasDispatcher::drawLine(const DlPoint& p0, const DlPoint& p1) { + canvas_->drawLine(ToSkPoint(p0), ToSkPoint(p1), paint()); } void DlSkCanvasDispatcher::drawDashedLine(const DlPoint& p0, const DlPoint& p1, @@ -167,14 +168,14 @@ void DlSkCanvasDispatcher::drawDashedLine(const DlPoint& p0, dash_paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.0f)); canvas_->drawLine(ToSkPoint(p0), ToSkPoint(p1), dash_paint); } -void DlSkCanvasDispatcher::drawRect(const SkRect& rect) { - canvas_->drawRect(rect, paint()); +void DlSkCanvasDispatcher::drawRect(const DlRect& rect) { + canvas_->drawRect(ToSkRect(rect), paint()); } -void DlSkCanvasDispatcher::drawOval(const SkRect& bounds) { - canvas_->drawOval(bounds, paint()); +void DlSkCanvasDispatcher::drawOval(const DlRect& bounds) { + canvas_->drawOval(ToSkRect(bounds), paint()); } -void DlSkCanvasDispatcher::drawCircle(const SkPoint& center, SkScalar radius) { - canvas_->drawCircle(center, radius, paint()); +void DlSkCanvasDispatcher::drawCircle(const DlPoint& center, DlScalar radius) { + canvas_->drawCircle(ToSkPoint(center), radius, paint()); } void DlSkCanvasDispatcher::drawRRect(const SkRRect& rrect) { canvas_->drawRRect(rrect, paint()); @@ -186,16 +187,16 @@ void DlSkCanvasDispatcher::drawDRRect(const SkRRect& outer, void DlSkCanvasDispatcher::drawPath(const SkPath& path) { canvas_->drawPath(path, paint()); } -void DlSkCanvasDispatcher::drawArc(const SkRect& bounds, - SkScalar start, - SkScalar sweep, +void DlSkCanvasDispatcher::drawArc(const DlRect& bounds, + DlScalar start, + DlScalar sweep, bool useCenter) { - canvas_->drawArc(bounds, start, sweep, useCenter, paint()); + canvas_->drawArc(ToSkRect(bounds), start, sweep, useCenter, paint()); } void DlSkCanvasDispatcher::drawPoints(PointMode mode, uint32_t count, - const SkPoint pts[]) { - canvas_->drawPoints(ToSk(mode), count, pts, paint()); + const DlPoint pts[]) { + canvas_->drawPoints(ToSk(mode), count, ToSkPoints(pts), paint()); } void DlSkCanvasDispatcher::drawVertices( const std::shared_ptr& vertices, @@ -203,25 +204,25 @@ void DlSkCanvasDispatcher::drawVertices( canvas_->drawVertices(ToSk(vertices), ToSk(mode), paint()); } void DlSkCanvasDispatcher::drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) { - canvas_->drawImage(image ? image->skia_image() : nullptr, point.fX, point.fY, + canvas_->drawImage(image ? image->skia_image() : nullptr, point.x, point.y, ToSk(sampling), safe_paint(render_with_attributes)); } void DlSkCanvasDispatcher::drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) { - canvas_->drawImageRect(image ? image->skia_image() : nullptr, src, dst, - ToSk(sampling), safe_paint(render_with_attributes), - ToSk(constraint)); + canvas_->drawImageRect(image ? image->skia_image() : nullptr, ToSkRect(src), + ToSkRect(dst), ToSk(sampling), + safe_paint(render_with_attributes), ToSk(constraint)); } void DlSkCanvasDispatcher::drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) { if (!image) { @@ -231,17 +232,17 @@ void DlSkCanvasDispatcher::drawImageNine(const sk_sp image, if (!skia_image) { return; } - canvas_->drawImageNine(skia_image.get(), center, dst, ToSk(filter), - safe_paint(render_with_attributes)); + canvas_->drawImageNine(skia_image.get(), ToSkIRect(center), ToSkRect(dst), + ToSk(filter), safe_paint(render_with_attributes)); } void DlSkCanvasDispatcher::drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cullRect, + const DlRect* cullRect, bool render_with_attributes) { if (!atlas) { return; @@ -255,13 +256,13 @@ void DlSkCanvasDispatcher::drawAtlas(const sk_sp atlas, for (int i = 0; i < count; ++i) { sk_colors.push_back(colors[i].argb()); } - canvas_->drawAtlas(skia_atlas.get(), xform, tex, sk_colors.data(), count, - ToSk(mode), ToSk(sampling), cullRect, + canvas_->drawAtlas(skia_atlas.get(), xform, ToSkRects(tex), sk_colors.data(), + count, ToSk(mode), ToSk(sampling), ToSkRect(cullRect), safe_paint(render_with_attributes)); } void DlSkCanvasDispatcher::drawDisplayList( const sk_sp display_list, - SkScalar opacity) { + DlScalar opacity) { const int restore_count = canvas_->getSaveCount(); // Compute combined opacity and figure out whether we can apply it @@ -289,15 +290,15 @@ void DlSkCanvasDispatcher::drawDisplayList( canvas_->restoreToCount(restore_count); } void DlSkCanvasDispatcher::drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { canvas_->drawTextBlob(blob, x, y, paint()); } void DlSkCanvasDispatcher::drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { FML_CHECK(false); } @@ -306,7 +307,7 @@ void DlSkCanvasDispatcher::DrawShadow(SkCanvas* canvas, DlColor color, float elevation, bool transparentOccluder, - SkScalar dpr) { + DlScalar dpr) { const SkScalar kAmbientAlpha = 0.039f; const SkScalar kSpotAlpha = 0.25f; @@ -329,9 +330,9 @@ void DlSkCanvasDispatcher::DrawShadow(SkCanvas* canvas, void DlSkCanvasDispatcher::drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { DrawShadow(canvas_, path, color, elevation, transparent_occluder, dpr); } diff --git a/display_list/skia/dl_sk_dispatcher.h b/display_list/skia/dl_sk_dispatcher.h index 384f722633677..918bfb4ff2a49 100644 --- a/display_list/skia/dl_sk_dispatcher.h +++ b/display_list/skia/dl_sk_dispatcher.h @@ -20,7 +20,7 @@ namespace flutter { class DlSkCanvasDispatcher : public virtual DlOpReceiver, public DlSkPaintDispatchHelper { public: - explicit DlSkCanvasDispatcher(SkCanvas* canvas, SkScalar opacity = SK_Scalar1) + explicit DlSkCanvasDispatcher(SkCanvas* canvas, DlScalar opacity = SK_Scalar1) : DlSkPaintDispatchHelper(opacity), canvas_(canvas), original_transform_(canvas->getLocalToDevice()) {} @@ -29,96 +29,96 @@ class DlSkCanvasDispatcher : public virtual DlOpReceiver, void save() override; void restore() override; - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override; - void translate(SkScalar tx, SkScalar ty) override; - void scale(SkScalar sx, SkScalar sy) override; - void rotate(SkScalar degrees) override; - void skew(SkScalar sx, SkScalar sy) override; + void translate(DlScalar tx, DlScalar ty) override; + void scale(DlScalar sx, DlScalar sy) override; + void rotate(DlScalar degrees) override; + void skew(DlScalar sx, DlScalar sy) override; // clang-format off // 2x3 2D affine subset of a 4x4 transform in row major order - void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) override; + void transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) override; // full 4x4 transform in row major order void transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override; + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override; // clang-format on void transformReset() override; - void clipRect(const SkRect& rect, ClipOp clip_op, bool is_aa) override; - void clipOval(const SkRect& bounds, ClipOp clip_op, bool is_aa) override; + void clipRect(const DlRect& rect, ClipOp clip_op, bool is_aa) override; + void clipOval(const DlRect& bounds, ClipOp clip_op, bool is_aa) override; void clipRRect(const SkRRect& rrect, ClipOp clip_op, bool is_aa) override; void clipPath(const SkPath& path, ClipOp clip_op, bool is_aa) override; void drawPaint() override; void drawColor(DlColor color, DlBlendMode mode) override; - void drawLine(const SkPoint& p0, const SkPoint& p1) override; + void drawLine(const DlPoint& p0, const DlPoint& p1) override; void drawDashedLine(const DlPoint& p0, const DlPoint& p1, DlScalar on_length, DlScalar off_length) override; - void drawRect(const SkRect& rect) override; - void drawOval(const SkRect& bounds) override; - void drawCircle(const SkPoint& center, SkScalar radius) override; + void drawRect(const DlRect& rect) override; + void drawOval(const DlRect& bounds) override; + void drawCircle(const DlPoint& center, DlScalar radius) override; void drawRRect(const SkRRect& rrect) override; void drawDRRect(const SkRRect& outer, const SkRRect& inner) override; void drawPath(const SkPath& path) override; - void drawArc(const SkRect& bounds, - SkScalar start, - SkScalar sweep, + void drawArc(const DlRect& bounds, + DlScalar start, + DlScalar sweep, bool useCenter) override; - void drawPoints(PointMode mode, uint32_t count, const SkPoint pts[]) override; + void drawPoints(PointMode mode, uint32_t count, const DlPoint pts[]) override; void drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) override; void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) override; void drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) override; void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) override; void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cullRect, + const DlRect* cullRect, bool render_with_attributes) override; void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override; + DlScalar opacity) override; void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override; + DlScalar dpr) override; static void DrawShadow(SkCanvas* canvas, const SkPath& path, DlColor color, float elevation, bool transparentOccluder, - SkScalar dpr); + DlScalar dpr); private: SkCanvas* canvas_; diff --git a/display_list/testing/dl_test_snippets.cc b/display_list/testing/dl_test_snippets.cc index d3ffa455082af..38cdc133f9185 100644 --- a/display_list/testing/dl_test_snippets.cc +++ b/display_list/testing/dl_test_snippets.cc @@ -282,25 +282,28 @@ std::vector CreateAllSaveRestoreOps() { {5, 96, 2, [](DlOpReceiver& r) { r.save(); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({5, 5, 15, 15}); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(5, 5, 15, 15)); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, {5, 120, 3, [](DlOpReceiver& r) { r.saveLayer(nullptr, SaveLayerOptions::kNoAttributes); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({5, 5, 15, 15}); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(5, 5, 15, 15)); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, {5, 120, 3, [](DlOpReceiver& r) { r.saveLayer(nullptr, SaveLayerOptions::kWithAttributes); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({5, 5, 15, 15}); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(5, 5, 15, 15)); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, // For saveLayer calls with bounds, we need at least one unclipped @@ -310,34 +313,38 @@ std::vector CreateAllSaveRestoreOps() { [](DlOpReceiver& r) { r.saveLayer(&kTestBounds, SaveLayerOptions::kNoAttributes); r.drawRect(kTestBounds); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, {5, 120, 3, [](DlOpReceiver& r) { r.saveLayer(&kTestBounds, SaveLayerOptions::kWithAttributes); r.drawRect(kTestBounds); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, {5, 136, 3, [](DlOpReceiver& r) { r.saveLayer(nullptr, SaveLayerOptions::kNoAttributes, &kTestCFImageFilter1); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({5, 5, 15, 15}); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(5, 5, 15, 15)); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, {5, 136, 3, [](DlOpReceiver& r) { r.saveLayer(nullptr, SaveLayerOptions::kWithAttributes, &kTestCFImageFilter1); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({5, 5, 15, 15}); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(5, 5, 15, 15)); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, {5, 136, 3, @@ -345,8 +352,9 @@ std::vector CreateAllSaveRestoreOps() { r.saveLayer(&kTestBounds, SaveLayerOptions::kNoAttributes, &kTestCFImageFilter1); r.drawRect(kTestBounds); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, {5, 136, 3, @@ -354,8 +362,9 @@ std::vector CreateAllSaveRestoreOps() { r.saveLayer(&kTestBounds, SaveLayerOptions::kWithAttributes, &kTestCFImageFilter1); r.drawRect(kTestBounds); - r.clipRect({0, 0, 25, 25}, DlCanvas::ClipOp::kIntersect, true); - r.drawRect({10, 10, 20, 20}); + r.clipRect(DlRect::MakeLTRB(0, 0, 25, 25), + DlCanvas::ClipOp::kIntersect, true); + r.drawRect(DlRect::MakeLTRB(10, 10, 20, 20)); r.restore(); }}, }}, @@ -433,8 +442,8 @@ std::vector CreateAllClipOps() { }}, {1, 24, 0, [](DlOpReceiver& r) { - r.clipRect(kTestBounds.makeOffset(1, 1), - DlCanvas::ClipOp::kIntersect, true); + r.clipRect(kTestBounds.Shift(1, 1), DlCanvas::ClipOp::kIntersect, + true); }}, {1, 24, 0, [](DlOpReceiver& r) { @@ -457,8 +466,8 @@ std::vector CreateAllClipOps() { }}, {1, 24, 0, [](DlOpReceiver& r) { - r.clipOval(kTestBounds.makeOffset(1, 1), - DlCanvas::ClipOp::kIntersect, true); + r.clipOval(kTestBounds.Shift(1, 1), DlCanvas::ClipOp::kIntersect, + true); }}, {1, 24, 0, [](DlOpReceiver& r) { @@ -621,38 +630,38 @@ std::vector CreateAllRenderingOps() { { {1, 24, 1, [](DlOpReceiver& r) { - r.drawRect({0, 0, 10, 10}); + r.drawRect(DlRect::MakeLTRB(0, 0, 10, 10)); }}, {1, 24, 1, [](DlOpReceiver& r) { - r.drawRect({0, 1, 10, 10}); + r.drawRect(DlRect::MakeLTRB(0, 1, 10, 10)); }}, {1, 24, 1, [](DlOpReceiver& r) { - r.drawRect({0, 0, 20, 10}); + r.drawRect(DlRect::MakeLTRB(0, 0, 20, 10)); }}, {1, 24, 1, [](DlOpReceiver& r) { - r.drawRect({0, 0, 10, 20}); + r.drawRect(DlRect::MakeLTRB(0, 0, 10, 20)); }}, }}, {"DrawOval", { {1, 24, 1, [](DlOpReceiver& r) { - r.drawOval({0, 0, 10, 10}); + r.drawOval(DlRect::MakeLTRB(0, 0, 10, 10)); }}, {1, 24, 1, [](DlOpReceiver& r) { - r.drawOval({0, 1, 10, 10}); + r.drawOval(DlRect::MakeLTRB(0, 1, 10, 10)); }}, {1, 24, 1, [](DlOpReceiver& r) { - r.drawOval({0, 0, 20, 10}); + r.drawOval(DlRect::MakeLTRB(0, 0, 20, 10)); }}, {1, 24, 1, [](DlOpReceiver& r) { - r.drawOval({0, 0, 10, 20}); + r.drawOval(DlRect::MakeLTRB(0, 0, 10, 20)); }}, }}, {"DrawCircle", @@ -702,7 +711,7 @@ std::vector CreateAllRenderingOps() { [](DlOpReceiver& r) { r.drawArc(kTestBounds, 45, 270, false); }}, {1, 32, 1, [](DlOpReceiver& r) { - r.drawArc(kTestBounds.makeOffset(1, 1), 45, 270, false); + r.drawArc(kTestBounds.Shift(1, 1), 45, 270, false); }}, {1, 32, 1, [](DlOpReceiver& r) { r.drawArc(kTestBounds, 30, 270, false); }}, @@ -716,22 +725,22 @@ std::vector CreateAllRenderingOps() { {1, 8 + TestPointCount * 8, 1, [](DlOpReceiver& r) { r.drawPoints(DlCanvas::PointMode::kPoints, TestPointCount, - kTestPoints); + ToDlPoints(kTestPoints)); }}, {1, 8 + (TestPointCount - 1) * 8, 1, [](DlOpReceiver& r) { r.drawPoints(DlCanvas::PointMode::kPoints, TestPointCount - 1, - kTestPoints); + ToDlPoints(kTestPoints)); }}, {1, 8 + TestPointCount * 8, 1, [](DlOpReceiver& r) { r.drawPoints(DlCanvas::PointMode::kLines, TestPointCount, - kTestPoints); + ToDlPoints(kTestPoints)); }}, {1, 8 + TestPointCount * 8, 1, [](DlOpReceiver& r) { r.drawPoints(DlCanvas::PointMode::kPolygon, TestPointCount, - kTestPoints); + ToDlPoints(kTestPoints)); }}, }}, {"DrawVertices", @@ -785,50 +794,57 @@ std::vector CreateAllRenderingOps() { { {1, 56, 1, [](DlOpReceiver& r) { - r.drawImageRect(TestImage1, {10, 10, 20, 20}, {10, 10, 80, 80}, + r.drawImageRect(TestImage1, DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 80, 80), kNearestSampling, false, DlCanvas::SrcRectConstraint::kFast); }}, {1, 56, 1, [](DlOpReceiver& r) { - r.drawImageRect(TestImage1, {10, 10, 20, 20}, {10, 10, 80, 80}, + r.drawImageRect(TestImage1, DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 80, 80), kNearestSampling, true, DlCanvas::SrcRectConstraint::kFast); }}, {1, 56, 1, [](DlOpReceiver& r) { - r.drawImageRect(TestImage1, {10, 10, 20, 20}, {10, 10, 80, 80}, + r.drawImageRect(TestImage1, DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 80, 80), kNearestSampling, false, DlCanvas::SrcRectConstraint::kStrict); }}, {1, 56, 1, [](DlOpReceiver& r) { - r.drawImageRect(TestImage1, {10, 10, 25, 20}, {10, 10, 80, 80}, + r.drawImageRect(TestImage1, DlRect::MakeLTRB(10, 10, 25, 20), + DlRect::MakeLTRB(10, 10, 80, 80), kNearestSampling, false, DlCanvas::SrcRectConstraint::kFast); }}, {1, 56, 1, [](DlOpReceiver& r) { - r.drawImageRect(TestImage1, {10, 10, 20, 20}, {10, 10, 85, 80}, + r.drawImageRect(TestImage1, DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 85, 80), kNearestSampling, false, DlCanvas::SrcRectConstraint::kFast); }}, {1, 56, 1, [](DlOpReceiver& r) { - r.drawImageRect(TestImage1, {10, 10, 20, 20}, {10, 10, 80, 80}, - kLinearSampling, false, - DlCanvas::SrcRectConstraint::kFast); + r.drawImageRect(TestImage1, DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 80, 80), kLinearSampling, + false, DlCanvas::SrcRectConstraint::kFast); }}, {1, 56, 1, [](DlOpReceiver& r) { - r.drawImageRect(TestImage2, {10, 10, 15, 15}, {10, 10, 80, 80}, + r.drawImageRect(TestImage2, DlRect::MakeLTRB(10, 10, 15, 15), + DlRect::MakeLTRB(10, 10, 80, 80), kNearestSampling, false, DlCanvas::SrcRectConstraint::kFast); }}, {1, 56, 1, [](DlOpReceiver& r) { auto dl_image = DlImage::Make(TestSkImage); - r.drawImageRect(dl_image, {10, 10, 15, 15}, {10, 10, 80, 80}, + r.drawImageRect(dl_image, DlRect::MakeLTRB(10, 10, 15, 15), + DlRect::MakeLTRB(10, 10, 80, 80), kNearestSampling, false, DlCanvas::SrcRectConstraint::kFast); }}, @@ -837,38 +853,45 @@ std::vector CreateAllRenderingOps() { { {1, 48, 9, [](DlOpReceiver& r) { - r.drawImageNine(TestImage1, {10, 10, 20, 20}, {10, 10, 80, 80}, + r.drawImageNine(TestImage1, DlIRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 80, 80), DlFilterMode::kNearest, false); }}, {1, 48, 9, [](DlOpReceiver& r) { - r.drawImageNine(TestImage1, {10, 10, 20, 20}, {10, 10, 80, 80}, + r.drawImageNine(TestImage1, DlIRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 80, 80), DlFilterMode::kNearest, true); }}, {1, 48, 9, [](DlOpReceiver& r) { - r.drawImageNine(TestImage1, {10, 10, 25, 20}, {10, 10, 80, 80}, + r.drawImageNine(TestImage1, DlIRect::MakeLTRB(10, 10, 25, 20), + DlRect::MakeLTRB(10, 10, 80, 80), DlFilterMode::kNearest, false); }}, {1, 48, 9, [](DlOpReceiver& r) { - r.drawImageNine(TestImage1, {10, 10, 20, 20}, {10, 10, 85, 80}, + r.drawImageNine(TestImage1, DlIRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 85, 80), DlFilterMode::kNearest, false); }}, {1, 48, 9, [](DlOpReceiver& r) { - r.drawImageNine(TestImage1, {10, 10, 20, 20}, {10, 10, 80, 80}, + r.drawImageNine(TestImage1, DlIRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(10, 10, 80, 80), DlFilterMode::kLinear, false); }}, {1, 48, 9, [](DlOpReceiver& r) { - r.drawImageNine(TestImage2, {10, 10, 15, 15}, {10, 10, 80, 80}, + r.drawImageNine(TestImage2, DlIRect::MakeLTRB(10, 10, 15, 15), + DlRect::MakeLTRB(10, 10, 80, 80), DlFilterMode::kNearest, false); }}, {1, 48, 9, [](DlOpReceiver& r) { auto dl_image = DlImage::Make(TestSkImage); - r.drawImageNine(dl_image, {10, 10, 15, 15}, {10, 10, 80, 80}, + r.drawImageNine(dl_image, DlIRect::MakeLTRB(10, 10, 15, 15), + DlRect::MakeLTRB(10, 10, 80, 80), DlFilterMode::kNearest, false); }}, }}, @@ -877,7 +900,8 @@ std::vector CreateAllRenderingOps() { {1, 48 + 32 + 8, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; r.drawAtlas(TestImage1, xforms, texs, nullptr, 2, DlBlendMode::kSrcIn, kNearestSampling, nullptr, false); @@ -885,14 +909,16 @@ std::vector CreateAllRenderingOps() { {1, 48 + 32 + 8, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; r.drawAtlas(TestImage1, xforms, texs, nullptr, 2, DlBlendMode::kSrcIn, kNearestSampling, nullptr, true); }}, {1, 48 + 32 + 8, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{0, 1, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; r.drawAtlas(TestImage1, xforms, texs, nullptr, 2, DlBlendMode::kSrcIn, kNearestSampling, nullptr, false); @@ -900,7 +926,8 @@ std::vector CreateAllRenderingOps() { {1, 48 + 32 + 8, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 25, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 25, 30, 30)}; r.drawAtlas(TestImage1, xforms, texs, nullptr, 2, DlBlendMode::kSrcIn, kNearestSampling, nullptr, false); @@ -908,14 +935,16 @@ std::vector CreateAllRenderingOps() { {1, 48 + 32 + 8, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; r.drawAtlas(TestImage1, xforms, texs, nullptr, 2, DlBlendMode::kSrcIn, kLinearSampling, nullptr, false); }}, {1, 48 + 32 + 8, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; r.drawAtlas(TestImage1, xforms, texs, nullptr, 2, DlBlendMode::kDstIn, kNearestSampling, nullptr, false); @@ -923,8 +952,9 @@ std::vector CreateAllRenderingOps() { {1, 64 + 32 + 8, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; - static SkRect cull_rect = {0, 0, 200, 200}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; + static DlRect cull_rect = DlRect::MakeLTRB(0, 0, 200, 200); r.drawAtlas(TestImage2, xforms, texs, nullptr, 2, DlBlendMode::kSrcIn, kNearestSampling, &cull_rect, false); @@ -932,7 +962,8 @@ std::vector CreateAllRenderingOps() { {1, 128, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; static DlColor colors[] = {DlColor::kBlue(), DlColor::kGreen()}; r.drawAtlas(TestImage1, xforms, texs, colors, 2, DlBlendMode::kSrcIn, kNearestSampling, nullptr, @@ -941,9 +972,10 @@ std::vector CreateAllRenderingOps() { {1, 144, 1, [](DlOpReceiver& r) { static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; static DlColor colors[] = {DlColor::kBlue(), DlColor::kGreen()}; - static SkRect cull_rect = {0, 0, 200, 200}; + static DlRect cull_rect = DlRect::MakeLTRB(0, 0, 200, 200); r.drawAtlas(TestImage1, xforms, texs, colors, 2, DlBlendMode::kSrcIn, kNearestSampling, &cull_rect, false); @@ -952,7 +984,8 @@ std::vector CreateAllRenderingOps() { [](DlOpReceiver& r) { auto dl_image = DlImage::Make(TestSkImage); static SkRSXform xforms[] = {{1, 0, 0, 0}, {0, 1, 0, 0}}; - static SkRect texs[] = {{10, 10, 20, 20}, {20, 20, 30, 30}}; + static DlRect texs[] = {DlRect::MakeLTRB(10, 10, 20, 20), + DlRect::MakeLTRB(20, 20, 30, 30)}; r.drawAtlas(dl_image, xforms, texs, nullptr, 2, DlBlendMode::kSrcIn, kNearestSampling, nullptr, false); diff --git a/display_list/testing/dl_test_snippets.h b/display_list/testing/dl_test_snippets.h index 733ce67364034..2647a6bab37b3 100644 --- a/display_list/testing/dl_test_snippets.h +++ b/display_list/testing/dl_test_snippets.h @@ -176,13 +176,14 @@ static const DlBlurMaskFilter kTestMaskFilter2(DlBlurStyle::kNormal, 5.0); static const DlBlurMaskFilter kTestMaskFilter3(DlBlurStyle::kSolid, 3.0); static const DlBlurMaskFilter kTestMaskFilter4(DlBlurStyle::kInner, 3.0); static const DlBlurMaskFilter kTestMaskFilter5(DlBlurStyle::kOuter, 3.0); -constexpr SkRect kTestBounds = SkRect::MakeLTRB(10, 10, 50, 60); -static const SkRRect kTestRRect = SkRRect::MakeRectXY(kTestBounds, 5, 5); -static const SkRRect kTestRRectRect = SkRRect::MakeRect(kTestBounds); +constexpr DlRect kTestBounds = DlRect::MakeLTRB(10, 10, 50, 60); +constexpr SkRect kTestSkBounds = SkRect::MakeLTRB(10, 10, 50, 60); +static const SkRRect kTestRRect = SkRRect::MakeRectXY(kTestSkBounds, 5, 5); +static const SkRRect kTestRRectRect = SkRRect::MakeRect(kTestSkBounds); static const SkRRect kTestInnerRRect = - SkRRect::MakeRectXY(kTestBounds.makeInset(5, 5), 2, 2); -static const SkPath kTestPathRect = SkPath::Rect(kTestBounds); -static const SkPath kTestPathOval = SkPath::Oval(kTestBounds); + SkRRect::MakeRectXY(kTestSkBounds.makeInset(5, 5), 2, 2); +static const SkPath kTestPathRect = SkPath::Rect(kTestSkBounds); +static const SkPath kTestPathOval = SkPath::Oval(kTestSkBounds); static const SkPath kTestPathRRect = SkPath::RRect(kTestRRect); static const SkPath kTestPath1 = SkPath::Polygon({{0, 0}, {10, 10}, {10, 0}, {0, 10}}, true); diff --git a/display_list/utils/dl_accumulation_rect.cc b/display_list/utils/dl_accumulation_rect.cc index c0b6a48829f3d..344047aea4ba2 100644 --- a/display_list/utils/dl_accumulation_rect.cc +++ b/display_list/utils/dl_accumulation_rect.cc @@ -72,6 +72,12 @@ void AccumulationRect::accumulate(AccumulationRect& ar) { } } +DlRect AccumulationRect::GetBounds() const { + return (max_x_ >= min_x_ && max_y_ >= min_y_) + ? DlRect::MakeLTRB(min_x_, min_y_, max_x_, max_y_) + : DlRect(); +} + SkRect AccumulationRect::bounds() const { return (max_x_ >= min_x_ && max_y_ >= min_y_) ? SkRect::MakeLTRB(min_x_, min_y_, max_x_, max_y_) diff --git a/display_list/utils/dl_accumulation_rect.h b/display_list/utils/dl_accumulation_rect.h index 09ed6adf16068..ec6b37827d54f 100644 --- a/display_list/utils/dl_accumulation_rect.h +++ b/display_list/utils/dl_accumulation_rect.h @@ -36,6 +36,7 @@ class AccumulationRect { bool is_empty() const { return min_x_ >= max_x_ || min_y_ >= max_y_; } bool is_not_empty() const { return min_x_ < max_x_ && min_y_ < max_y_; } + DlRect GetBounds() const; SkRect bounds() const; void reset(); diff --git a/display_list/utils/dl_receiver_utils.h b/display_list/utils/dl_receiver_utils.h index bb6ce6539f653..397e4015d1857 100644 --- a/display_list/utils/dl_receiver_utils.h +++ b/display_list/utils/dl_receiver_utils.h @@ -41,10 +41,10 @@ class IgnoreAttributeDispatchHelper : public virtual DlOpReceiver { // A utility class that will ignore all DlOpReceiver methods relating // to setting a clip. class IgnoreClipDispatchHelper : public virtual DlOpReceiver { - void clipRect(const SkRect& rect, + void clipRect(const DlRect& rect, DlCanvas::ClipOp clip_op, bool is_aa) override {} - void clipOval(const SkRect& bounds, + void clipOval(const DlRect& bounds, DlCanvas::ClipOp clip_op, bool is_aa) override {} void clipRRect(const SkRRect& rrect, @@ -59,20 +59,20 @@ class IgnoreClipDispatchHelper : public virtual DlOpReceiver { // to modifying the transform. class IgnoreTransformDispatchHelper : public virtual DlOpReceiver { public: - void translate(SkScalar tx, SkScalar ty) override {} - void scale(SkScalar sx, SkScalar sy) override {} - void rotate(SkScalar degrees) override {} - void skew(SkScalar sx, SkScalar sy) override {} + void translate(DlScalar tx, DlScalar ty) override {} + void scale(DlScalar sx, DlScalar sy) override {} + void rotate(DlScalar degrees) override {} + void skew(DlScalar sx, DlScalar sy) override {} // clang-format off // 2x3 2D affine subset of a 4x4 transform in row major order - void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) override {} + void transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) override {} // full 4x4 transform in row major order void transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override {} + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override {} // clang-format on void transformReset() override {} }; @@ -80,69 +80,69 @@ class IgnoreTransformDispatchHelper : public virtual DlOpReceiver { class IgnoreDrawDispatchHelper : public virtual DlOpReceiver { public: void save() override {} - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override {} void restore() override {} void drawColor(DlColor color, DlBlendMode mode) override {} void drawPaint() override {} - void drawLine(const SkPoint& p0, const SkPoint& p1) override {} + void drawLine(const DlPoint& p0, const DlPoint& p1) override {} void drawDashedLine(const DlPoint& p0, const DlPoint& p1, DlScalar on_length, DlScalar off_length) override {} - void drawRect(const SkRect& rect) override {} - void drawOval(const SkRect& bounds) override {} - void drawCircle(const SkPoint& center, SkScalar radius) override {} + void drawRect(const DlRect& rect) override {} + void drawOval(const DlRect& bounds) override {} + void drawCircle(const DlPoint& center, DlScalar radius) override {} void drawRRect(const SkRRect& rrect) override {} void drawDRRect(const SkRRect& outer, const SkRRect& inner) override {} void drawPath(const SkPath& path) override {} - void drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + void drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) override {} void drawPoints(DlCanvas::PointMode mode, uint32_t count, - const SkPoint points[]) override {} + const DlPoint points[]) override {} void drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) override {} void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) override {} void drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) override {} void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) override {} void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) override {} void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override {} + DlScalar opacity) override {} void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override {} + DlScalar x, + DlScalar y) override {} void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override {} + DlScalar x, + DlScalar y) override {} void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override {} + DlScalar dpr) override {} }; } // namespace flutter diff --git a/impeller/display_list/dl_dispatcher.cc b/impeller/display_list/dl_dispatcher.cc index 2ab56520b3f8c..37c3daf3e3d67 100644 --- a/impeller/display_list/dl_dispatcher.cc +++ b/impeller/display_list/dl_dispatcher.cc @@ -281,14 +281,14 @@ void DlDispatcherBase::setColor(flutter::DlColor color) { } // |flutter::DlOpReceiver| -void DlDispatcherBase::setStrokeWidth(SkScalar width) { +void DlDispatcherBase::setStrokeWidth(DlScalar width) { AUTO_DEPTH_WATCHER(0u); paint_.stroke_width = width; } // |flutter::DlOpReceiver| -void DlDispatcherBase::setStrokeMiter(SkScalar limit) { +void DlDispatcherBase::setStrokeMiter(DlScalar limit) { AUTO_DEPTH_WATCHER(0u); paint_.stroke_miter = limit; @@ -412,10 +412,10 @@ void DlDispatcherBase::setColorSource(const flutter::DlColorSource* source) { source->asConicalGradient(); FML_DCHECK(conical_gradient); Point center = skia_conversions::ToPoint(conical_gradient->end_center()); - SkScalar radius = conical_gradient->end_radius(); + DlScalar radius = conical_gradient->end_radius(); Point focus_center = skia_conversions::ToPoint(conical_gradient->start_center()); - SkScalar focus_radius = conical_gradient->start_radius(); + DlScalar focus_radius = conical_gradient->start_radius(); std::vector colors; std::vector stops; skia_conversions::ConvertStops(conical_gradient, colors, stops); @@ -713,7 +713,7 @@ void DlDispatcherBase::save(uint32_t total_content_depth) { } // |flutter::DlOpReceiver| -void DlDispatcherBase::saveLayer(const SkRect& bounds, +void DlDispatcherBase::saveLayer(const DlRect& bounds, const flutter::SaveLayerOptions& options, uint32_t total_content_depth, flutter::DlBlendMode max_content_mode, @@ -728,7 +728,7 @@ void DlDispatcherBase::saveLayer(const SkRect& bounds, // If the content is unbounded but has developer specified bounds, we take // the original bounds so that we clip the content as expected. if (!options.content_is_unbounded() || options.bounds_from_caller()) { - impeller_bounds = skia_conversions::ToRect(bounds); + impeller_bounds = bounds; } GetCanvas().SaveLayer( @@ -745,40 +745,40 @@ void DlDispatcherBase::restore() { } // |flutter::DlOpReceiver| -void DlDispatcherBase::translate(SkScalar tx, SkScalar ty) { +void DlDispatcherBase::translate(DlScalar tx, DlScalar ty) { AUTO_DEPTH_WATCHER(0u); GetCanvas().Translate({tx, ty, 0.0}); } // |flutter::DlOpReceiver| -void DlDispatcherBase::scale(SkScalar sx, SkScalar sy) { +void DlDispatcherBase::scale(DlScalar sx, DlScalar sy) { AUTO_DEPTH_WATCHER(0u); GetCanvas().Scale({sx, sy, 1.0}); } // |flutter::DlOpReceiver| -void DlDispatcherBase::rotate(SkScalar degrees) { +void DlDispatcherBase::rotate(DlScalar degrees) { AUTO_DEPTH_WATCHER(0u); GetCanvas().Rotate(Degrees{degrees}); } // |flutter::DlOpReceiver| -void DlDispatcherBase::skew(SkScalar sx, SkScalar sy) { +void DlDispatcherBase::skew(DlScalar sx, DlScalar sy) { AUTO_DEPTH_WATCHER(0u); GetCanvas().Skew(sx, sy); } // |flutter::DlOpReceiver| -void DlDispatcherBase::transform2DAffine(SkScalar mxx, - SkScalar mxy, - SkScalar mxt, - SkScalar myx, - SkScalar myy, - SkScalar myt) { +void DlDispatcherBase::transform2DAffine(DlScalar mxx, + DlScalar mxy, + DlScalar mxt, + DlScalar myx, + DlScalar myy, + DlScalar myt) { AUTO_DEPTH_WATCHER(0u); // clang-format off @@ -792,22 +792,22 @@ void DlDispatcherBase::transform2DAffine(SkScalar mxx, } // |flutter::DlOpReceiver| -void DlDispatcherBase::transformFullPerspective(SkScalar mxx, - SkScalar mxy, - SkScalar mxz, - SkScalar mxt, - SkScalar myx, - SkScalar myy, - SkScalar myz, - SkScalar myt, - SkScalar mzx, - SkScalar mzy, - SkScalar mzz, - SkScalar mzt, - SkScalar mwx, - SkScalar mwy, - SkScalar mwz, - SkScalar mwt) { +void DlDispatcherBase::transformFullPerspective(DlScalar mxx, + DlScalar mxy, + DlScalar mxz, + DlScalar mxt, + DlScalar myx, + DlScalar myy, + DlScalar myz, + DlScalar myt, + DlScalar mzx, + DlScalar mzy, + DlScalar mzz, + DlScalar mzt, + DlScalar mwx, + DlScalar mwy, + DlScalar mwz, + DlScalar mwt) { AUTO_DEPTH_WATCHER(0u); // The order of arguments is row-major but Impeller matrices are @@ -842,23 +842,21 @@ static Entity::ClipOperation ToClipOperation( } // |flutter::DlOpReceiver| -void DlDispatcherBase::clipRect(const SkRect& rect, +void DlDispatcherBase::clipRect(const DlRect& rect, ClipOp clip_op, bool is_aa) { AUTO_DEPTH_WATCHER(0u); - GetCanvas().ClipRect(skia_conversions::ToRect(rect), - ToClipOperation(clip_op)); + GetCanvas().ClipRect(rect, ToClipOperation(clip_op)); } // |flutter::DlOpReceiver| -void DlDispatcherBase::clipOval(const SkRect& bounds, +void DlDispatcherBase::clipOval(const DlRect& bounds, ClipOp clip_op, bool is_aa) { AUTO_DEPTH_WATCHER(0u); - GetCanvas().ClipOval(skia_conversions::ToRect(bounds), - ToClipOperation(clip_op)); + GetCanvas().ClipOval(bounds, ToClipOperation(clip_op)); } // |flutter::DlOpReceiver| @@ -937,11 +935,10 @@ void DlDispatcherBase::drawPaint() { } // |flutter::DlOpReceiver| -void DlDispatcherBase::drawLine(const SkPoint& p0, const SkPoint& p1) { +void DlDispatcherBase::drawLine(const DlPoint& p0, const DlPoint& p1) { AUTO_DEPTH_WATCHER(1u); - GetCanvas().DrawLine(skia_conversions::ToPoint(p0), - skia_conversions::ToPoint(p1), paint_); + GetCanvas().DrawLine(p0, p1, paint_); } void DlDispatcherBase::drawDashedLine(const DlPoint& p0, @@ -981,29 +978,29 @@ void DlDispatcherBase::drawDashedLine(const DlPoint& p0, stroke_paint.style = Paint::Style::kStroke; GetCanvas().DrawPath(builder.TakePath(), stroke_paint); } else { - drawLine(flutter::ToSkPoint(p0), flutter::ToSkPoint(p1)); + drawLine(p0, p1); } } // |flutter::DlOpReceiver| -void DlDispatcherBase::drawRect(const SkRect& rect) { +void DlDispatcherBase::drawRect(const DlRect& rect) { AUTO_DEPTH_WATCHER(1u); - GetCanvas().DrawRect(skia_conversions::ToRect(rect), paint_); + GetCanvas().DrawRect(rect, paint_); } // |flutter::DlOpReceiver| -void DlDispatcherBase::drawOval(const SkRect& bounds) { +void DlDispatcherBase::drawOval(const DlRect& bounds) { AUTO_DEPTH_WATCHER(1u); - GetCanvas().DrawOval(skia_conversions::ToRect(bounds), paint_); + GetCanvas().DrawOval(bounds, paint_); } // |flutter::DlOpReceiver| -void DlDispatcherBase::drawCircle(const SkPoint& center, SkScalar radius) { +void DlDispatcherBase::drawCircle(const DlPoint& center, DlScalar radius) { AUTO_DEPTH_WATCHER(1u); - GetCanvas().DrawCircle(skia_conversions::ToPoint(center), radius, paint_); + GetCanvas().DrawCircle(center, radius, paint_); } // |flutter::DlOpReceiver| @@ -1070,22 +1067,22 @@ void DlDispatcherBase::SimplifyOrDrawPath(Canvas& canvas, } // |flutter::DlOpReceiver| -void DlDispatcherBase::drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, +void DlDispatcherBase::drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) { AUTO_DEPTH_WATCHER(1u); PathBuilder builder; - builder.AddArc(skia_conversions::ToRect(oval_bounds), Degrees(start_degrees), - Degrees(sweep_degrees), use_center); + builder.AddArc(oval_bounds, Degrees(start_degrees), Degrees(sweep_degrees), + use_center); GetCanvas().DrawPath(builder.TakePath(), paint_); } // |flutter::DlOpReceiver| void DlDispatcherBase::drawPoints(PointMode mode, uint32_t count, - const SkPoint points[]) { + const DlPoint points[]) { AUTO_DEPTH_WATCHER(1u); Paint paint = paint_; @@ -1104,16 +1101,16 @@ void DlDispatcherBase::drawPoints(PointMode mode, } break; case flutter::DlCanvas::PointMode::kLines: for (uint32_t i = 1; i < count; i += 2) { - Point p0 = skia_conversions::ToPoint(points[i - 1]); - Point p1 = skia_conversions::ToPoint(points[i]); + Point p0 = points[i - 1]; + Point p1 = points[i]; GetCanvas().DrawLine(p0, p1, paint); } break; case flutter::DlCanvas::PointMode::kPolygon: if (count > 1) { - Point p0 = skia_conversions::ToPoint(points[0]); + Point p0 = points[0]; for (uint32_t i = 1; i < count; i++) { - Point p1 = skia_conversions::ToPoint(points[i]); + Point p1 = points[i]; GetCanvas().DrawLine(p0, p1, paint); p0 = p1; } @@ -1134,7 +1131,7 @@ void DlDispatcherBase::drawVertices( // |flutter::DlOpReceiver| void DlDispatcherBase::drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, flutter::DlImageSampling sampling, bool render_with_attributes) { AUTO_DEPTH_WATCHER(1u); @@ -1149,9 +1146,8 @@ void DlDispatcherBase::drawImage(const sk_sp image, } const auto size = texture->GetSize(); - const auto src = SkRect::MakeWH(size.width, size.height); - const auto dest = - SkRect::MakeXYWH(point.fX, point.fY, size.width, size.height); + const auto src = DlRect::MakeWH(size.width, size.height); + const auto dest = DlRect::MakeXYWH(point.x, point.y, size.width, size.height); drawImageRect(image, // image src, // source rect @@ -1165,16 +1161,16 @@ void DlDispatcherBase::drawImage(const sk_sp image, // |flutter::DlOpReceiver| void DlDispatcherBase::drawImageRect( const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, flutter::DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint = SrcRectConstraint::kFast) { AUTO_DEPTH_WATCHER(1u); - GetCanvas().DrawImageRect(image->impeller_texture(), // image - skia_conversions::ToRect(src), // source rect - skia_conversions::ToRect(dst), // destination rect + GetCanvas().DrawImageRect(image->impeller_texture(), // image + src, // source rect + dst, // destination rect render_with_attributes ? paint_ : Paint(), // paint ToSamplerDescriptor(sampling) // sampling ); @@ -1182,29 +1178,29 @@ void DlDispatcherBase::drawImageRect( // |flutter::DlOpReceiver| void DlDispatcherBase::drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, flutter::DlFilterMode filter, bool render_with_attributes) { AUTO_DEPTH_WATCHER(9u); NinePatchConverter converter = {}; - converter.DrawNinePatch( - image->impeller_texture(), - Rect::MakeLTRB(center.fLeft, center.fTop, center.fRight, center.fBottom), - skia_conversions::ToRect(dst), ToSamplerDescriptor(filter), &GetCanvas(), - &paint_); + converter.DrawNinePatch(image->impeller_texture(), + Rect::MakeLTRB(center.GetLeft(), center.GetTop(), + center.GetRight(), center.GetBottom()), + dst, ToSamplerDescriptor(filter), &GetCanvas(), + &paint_); } // |flutter::DlOpReceiver| void DlDispatcherBase::drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const flutter::DlColor colors[], int count, flutter::DlBlendMode mode, flutter::DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) { AUTO_DEPTH_WATCHER(1u); @@ -1218,7 +1214,7 @@ void DlDispatcherBase::drawAtlas(const sk_sp atlas, // |flutter::DlOpReceiver| void DlDispatcherBase::drawDisplayList( const sk_sp display_list, - SkScalar opacity) { + DlScalar opacity) { AUTO_DEPTH_WATCHER(display_list->total_depth()); // Save all values that must remain untouched after the operation. @@ -1282,8 +1278,8 @@ void DlDispatcherBase::drawDisplayList( // |flutter::DlOpReceiver| void DlDispatcherBase::drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { // When running with Impeller enabled Skia text blobs are converted to // Impeller text frames in paragraph_skia.cc UNIMPLEMENTED; @@ -1292,8 +1288,8 @@ void DlDispatcherBase::drawTextBlob(const sk_sp blob, // |flutter::DlOpReceiver| void DlDispatcherBase::drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { AUTO_DEPTH_WATCHER(1u); GetCanvas().DrawTextFrame(text_frame, // @@ -1305,18 +1301,18 @@ void DlDispatcherBase::drawTextFrame( // |flutter::DlOpReceiver| void DlDispatcherBase::drawShadow(const SkPath& path, const flutter::DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { UNIMPLEMENTED; } // |flutter::DlOpReceiver| void DlDispatcherBase::drawShadow(const CacheablePath& cache, const flutter::DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { AUTO_DEPTH_WATCHER(1u); Color spot_color = skia_conversions::ToColor(color); @@ -1425,7 +1421,7 @@ void TextFrameDispatcher::save() { stack_.emplace_back(matrix_); } -void TextFrameDispatcher::saveLayer(const SkRect& bounds, +void TextFrameDispatcher::saveLayer(const DlRect& bounds, const flutter::SaveLayerOptions options, const flutter::DlImageFilter* backdrop) { save(); @@ -1436,26 +1432,26 @@ void TextFrameDispatcher::restore() { stack_.pop_back(); } -void TextFrameDispatcher::translate(SkScalar tx, SkScalar ty) { +void TextFrameDispatcher::translate(DlScalar tx, DlScalar ty) { matrix_ = matrix_.Translate({tx, ty}); } -void TextFrameDispatcher::scale(SkScalar sx, SkScalar sy) { +void TextFrameDispatcher::scale(DlScalar sx, DlScalar sy) { matrix_ = matrix_.Scale({sx, sy, 1.0f}); } -void TextFrameDispatcher::rotate(SkScalar degrees) { +void TextFrameDispatcher::rotate(DlScalar degrees) { matrix_ = matrix_ * Matrix::MakeRotationZ(Degrees(degrees)); } -void TextFrameDispatcher::skew(SkScalar sx, SkScalar sy) { +void TextFrameDispatcher::skew(DlScalar sx, DlScalar sy) { matrix_ = matrix_ * Matrix::MakeSkew(sx, sy); } // clang-format off // 2x3 2D affine subset of a 4x4 transform in row major order - void TextFrameDispatcher::transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) { + void TextFrameDispatcher::transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) { matrix_ = matrix_ * Matrix::MakeColumn( mxx, myx, 0.0f, 0.0f, mxy, myy, 0.0f, 0.0f, @@ -1466,10 +1462,10 @@ void TextFrameDispatcher::skew(SkScalar sx, SkScalar sy) { // full 4x4 transform in row major order void TextFrameDispatcher::transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) { + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) { matrix_ = matrix_ * Matrix::MakeColumn( mxx, myx, mzx, mwx, mxy, myy, mzy, mwy, @@ -1485,8 +1481,8 @@ void TextFrameDispatcher::transformReset() { void TextFrameDispatcher::drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { GlyphProperties properties; if (paint_.style == Paint::Style::kStroke) { properties.stroke = true; @@ -1511,7 +1507,7 @@ void TextFrameDispatcher::drawTextFrame( void TextFrameDispatcher::drawDisplayList( const sk_sp display_list, - SkScalar opacity) { + DlScalar opacity) { [[maybe_unused]] size_t stack_depth = stack_.size(); save(); Paint old_paint = paint_; @@ -1533,12 +1529,12 @@ void TextFrameDispatcher::setColor(flutter::DlColor color) { } // |flutter::DlOpReceiver| -void TextFrameDispatcher::setStrokeWidth(SkScalar width) { +void TextFrameDispatcher::setStrokeWidth(DlScalar width) { paint_.stroke_width = width; } // |flutter::DlOpReceiver| -void TextFrameDispatcher::setStrokeMiter(SkScalar limit) { +void TextFrameDispatcher::setStrokeMiter(DlScalar limit) { paint_.stroke_miter = limit; } diff --git a/impeller/display_list/dl_dispatcher.h b/impeller/display_list/dl_dispatcher.h index 38f2aaafce419..d8e4bad38a377 100644 --- a/impeller/display_list/dl_dispatcher.h +++ b/impeller/display_list/dl_dispatcher.h @@ -19,6 +19,8 @@ namespace impeller { using DlScalar = flutter::DlScalar; using DlPoint = flutter::DlPoint; +using DlRect = flutter::DlRect; +using DlIRect = flutter::DlIRect; class DlDispatcherBase : public flutter::DlOpReceiver { public: @@ -37,10 +39,10 @@ class DlDispatcherBase : public flutter::DlOpReceiver { void setColor(flutter::DlColor color) override; // |flutter::DlOpReceiver| - void setStrokeWidth(SkScalar width) override; + void setStrokeWidth(DlScalar width) override; // |flutter::DlOpReceiver| - void setStrokeMiter(SkScalar limit) override; + void setStrokeMiter(DlScalar limit) override; // |flutter::DlOpReceiver| void setStrokeCap(flutter::DlStrokeCap cap) override; @@ -70,7 +72,7 @@ class DlDispatcherBase : public flutter::DlOpReceiver { void save(uint32_t total_content_depth) override; // |flutter::DlOpReceiver| - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const flutter::SaveLayerOptions& options, uint32_t total_content_depth, flutter::DlBlendMode max_content_mode, @@ -80,51 +82,51 @@ class DlDispatcherBase : public flutter::DlOpReceiver { void restore() override; // |flutter::DlOpReceiver| - void translate(SkScalar tx, SkScalar ty) override; + void translate(DlScalar tx, DlScalar ty) override; // |flutter::DlOpReceiver| - void scale(SkScalar sx, SkScalar sy) override; + void scale(DlScalar sx, DlScalar sy) override; // |flutter::DlOpReceiver| - void rotate(SkScalar degrees) override; + void rotate(DlScalar degrees) override; // |flutter::DlOpReceiver| - void skew(SkScalar sx, SkScalar sy) override; + void skew(DlScalar sx, DlScalar sy) override; // |flutter::DlOpReceiver| - void transform2DAffine(SkScalar mxx, - SkScalar mxy, - SkScalar mxt, - SkScalar myx, - SkScalar myy, - SkScalar myt) override; + void transform2DAffine(DlScalar mxx, + DlScalar mxy, + DlScalar mxt, + DlScalar myx, + DlScalar myy, + DlScalar myt) override; // |flutter::DlOpReceiver| - void transformFullPerspective(SkScalar mxx, - SkScalar mxy, - SkScalar mxz, - SkScalar mxt, - SkScalar myx, - SkScalar myy, - SkScalar myz, - SkScalar myt, - SkScalar mzx, - SkScalar mzy, - SkScalar mzz, - SkScalar mzt, - SkScalar mwx, - SkScalar mwy, - SkScalar mwz, - SkScalar mwt) override; + void transformFullPerspective(DlScalar mxx, + DlScalar mxy, + DlScalar mxz, + DlScalar mxt, + DlScalar myx, + DlScalar myy, + DlScalar myz, + DlScalar myt, + DlScalar mzx, + DlScalar mzy, + DlScalar mzz, + DlScalar mzt, + DlScalar mwx, + DlScalar mwy, + DlScalar mwz, + DlScalar mwt) override; // |flutter::DlOpReceiver| void transformReset() override; // |flutter::DlOpReceiver| - void clipRect(const SkRect& rect, ClipOp clip_op, bool is_aa) override; + void clipRect(const DlRect& rect, ClipOp clip_op, bool is_aa) override; // |flutter::DlOpReceiver| - void clipOval(const SkRect& bounds, ClipOp clip_op, bool is_aa) override; + void clipOval(const DlRect& bounds, ClipOp clip_op, bool is_aa) override; // |flutter::DlOpReceiver| void clipRRect(const SkRRect& rrect, ClipOp clip_op, bool is_aa) override; @@ -144,7 +146,7 @@ class DlDispatcherBase : public flutter::DlOpReceiver { void drawPaint() override; // |flutter::DlOpReceiver| - void drawLine(const SkPoint& p0, const SkPoint& p1) override; + void drawLine(const DlPoint& p0, const DlPoint& p1) override; // |flutter::DlOpReceiver| void drawDashedLine(const DlPoint& p0, @@ -153,13 +155,13 @@ class DlDispatcherBase : public flutter::DlOpReceiver { DlScalar off_length) override; // |flutter::DlOpReceiver| - void drawRect(const SkRect& rect) override; + void drawRect(const DlRect& rect) override; // |flutter::DlOpReceiver| - void drawOval(const SkRect& bounds) override; + void drawOval(const DlRect& bounds) override; // |flutter::DlOpReceiver| - void drawCircle(const SkPoint& center, SkScalar radius) override; + void drawCircle(const DlPoint& center, DlScalar radius) override; // |flutter::DlOpReceiver| void drawRRect(const SkRRect& rrect) override; @@ -174,15 +176,15 @@ class DlDispatcherBase : public flutter::DlOpReceiver { void drawPath(const CacheablePath& cache) override; // |flutter::DlOpReceiver| - void drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + void drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) override; // |flutter::DlOpReceiver| void drawPoints(PointMode mode, uint32_t count, - const SkPoint points[]) override; + const DlPoint points[]) override; // |flutter::DlOpReceiver| void drawVertices(const std::shared_ptr& vertices, @@ -190,63 +192,63 @@ class DlDispatcherBase : public flutter::DlOpReceiver { // |flutter::DlOpReceiver| void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, flutter::DlImageSampling sampling, bool render_with_attributes) override; // |flutter::DlOpReceiver| void drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, flutter::DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) override; // |flutter::DlOpReceiver| void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, flutter::DlFilterMode filter, bool render_with_attributes) override; // |flutter::DlOpReceiver| void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const flutter::DlColor colors[], int count, flutter::DlBlendMode mode, flutter::DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) override; // |flutter::DlOpReceiver| void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override; + DlScalar opacity) override; // |flutter::DlOpReceiver| void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; // |flutter::DlOpReceiver| void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; // |flutter::DlOpReceiver| void drawShadow(const SkPath& path, const flutter::DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override; + DlScalar dpr) override; // |flutter::DlOpReceiver| void drawShadow(const CacheablePath& cache, const flutter::DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override; + DlScalar dpr) override; virtual Canvas& GetCanvas() = 0; @@ -282,7 +284,7 @@ class DlDispatcher : public DlDispatcherBase { using DlDispatcherBase::save; // |flutter::DlOpReceiver| - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const flutter::SaveLayerOptions options, const flutter::DlImageFilter* backdrop) override { // This dispatcher is used from test cases that might not supply @@ -319,7 +321,7 @@ class ExperimentalDlDispatcher : public DlDispatcherBase { using DlDispatcherBase::save; // |flutter::DlOpReceiver| - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const flutter::SaveLayerOptions options, const flutter::DlImageFilter* backdrop) override { // This dispatcher should never be used with the saveLayer() variant @@ -345,40 +347,40 @@ class TextFrameDispatcher : public flutter::IgnoreAttributeDispatchHelper, const Matrix& initial_matrix); void save() override; - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const flutter::SaveLayerOptions options, const flutter::DlImageFilter* backdrop) override; void restore() override; - void translate(SkScalar tx, SkScalar ty) override; + void translate(DlScalar tx, DlScalar ty) override; - void scale(SkScalar sx, SkScalar sy) override; + void scale(DlScalar sx, DlScalar sy) override; - void rotate(SkScalar degrees) override; + void rotate(DlScalar degrees) override; - void skew(SkScalar sx, SkScalar sy) override; + void skew(DlScalar sx, DlScalar sy) override; // clang-format off // 2x3 2D affine subset of a 4x4 transform in row major order - void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) override; + void transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) override; // full 4x4 transform in row major order void transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override; + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override; void transformReset() override; void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override; + DlScalar opacity) override; // |flutter::DlOpReceiver| void setDrawStyle(flutter::DlDrawStyle style) override; @@ -387,10 +389,10 @@ class TextFrameDispatcher : public flutter::IgnoreAttributeDispatchHelper, void setColor(flutter::DlColor color) override; // |flutter::DlOpReceiver| - void setStrokeWidth(SkScalar width) override; + void setStrokeWidth(DlScalar width) override; // |flutter::DlOpReceiver| - void setStrokeMiter(SkScalar limit) override; + void setStrokeMiter(DlScalar limit) override; // |flutter::DlOpReceiver| void setStrokeCap(flutter::DlStrokeCap cap) override; diff --git a/impeller/display_list/skia_conversions.cc b/impeller/display_list/skia_conversions.cc index 57dc07cbc2157..5457f678da5e3 100644 --- a/impeller/display_list/skia_conversions.cc +++ b/impeller/display_list/skia_conversions.cc @@ -38,6 +38,13 @@ std::optional ToRect(const SkRect* rect) { return Rect::MakeLTRB(rect->fLeft, rect->fTop, rect->fRight, rect->fBottom); } +std::optional ToRect(const flutter::DlRect* rect) { + if (rect == nullptr) { + return std::nullopt; + } + return *rect; +} + std::vector ToRects(const SkRect tex[], int count) { auto result = std::vector(); for (int i = 0; i < count; i++) { @@ -46,6 +53,14 @@ std::vector ToRects(const SkRect tex[], int count) { return result; } +std::vector ToRects(const flutter::DlRect tex[], int count) { + auto result = std::vector(); + for (int i = 0; i < count; i++) { + result.push_back(tex[i]); + } + return result; +} + std::vector ToPoints(const SkPoint points[], int count) { std::vector result(count); for (auto i = 0; i < count; i++) { @@ -54,6 +69,14 @@ std::vector ToPoints(const SkPoint points[], int count) { return result; } +std::vector ToPoints(const flutter::DlPoint points[], int count) { + std::vector result(count); + for (auto i = 0; i < count; i++) { + result[i] = points[i]; + } + return result; +} + PathBuilder::RoundingRadii ToRoundingRadii(const SkRRect& rrect) { using Corner = SkRRect::Corner; PathBuilder::RoundingRadii radii; diff --git a/impeller/display_list/skia_conversions.h b/impeller/display_list/skia_conversions.h index a52f31236eec9..edc9aec391309 100644 --- a/impeller/display_list/skia_conversions.h +++ b/impeller/display_list/skia_conversions.h @@ -34,10 +34,13 @@ bool IsNearlySimpleRRect(const SkRRect& rr); Rect ToRect(const SkRect& rect); std::optional ToRect(const SkRect* rect); +std::optional ToRect(const flutter::DlRect* rect); std::vector ToRects(const SkRect tex[], int count); +std::vector ToRects(const flutter::DlRect tex[], int count); std::vector ToPoints(const SkPoint points[], int count); +std::vector ToPoints(const flutter::DlPoint points[], int count); Point ToPoint(const SkPoint& point); diff --git a/impeller/geometry/rect.h b/impeller/geometry/rect.h index 289f879e78b4d..86344e2b6b4f5 100644 --- a/impeller/geometry/rect.h +++ b/impeller/geometry/rect.h @@ -137,6 +137,10 @@ struct TRect { return TRect(x, y, saturated::Add(x, width), saturated::Add(y, height)); } + constexpr static TRect MakeWH(Type width, Type height) { + return TRect(0, 0, width, height); + } + constexpr static TRect MakeOriginSize(const TPoint& origin, const TSize& size) { return MakeXYWH(origin.x, origin.y, size.width, size.height); @@ -529,6 +533,10 @@ struct TRect { } } + [[nodiscard]] constexpr TRect IntersectionOrEmpty(const TRect& o) const { + return Intersection(o).value_or(TRect()); + } + [[nodiscard]] constexpr bool IntersectsWithRect(const TRect& o) const { return !IsEmpty() && // !o.IsEmpty() && // diff --git a/impeller/geometry/rect_unittests.cc b/impeller/geometry/rect_unittests.cc index 5634de40854ed..401c64fc23f0d 100644 --- a/impeller/geometry/rect_unittests.cc +++ b/impeller/geometry/rect_unittests.cc @@ -130,6 +130,37 @@ TEST(RectTest, IRectSimpleXYWH) { EXPECT_FALSE(rect.IsEmpty()); } +TEST(RectTest, RectSimpleWH) { + // Using fractional-power-of-2 friendly values for equality tests + Rect rect = Rect::MakeWH(15.5f, 15.125f); + + EXPECT_EQ(rect.GetLeft(), 0.0f); + EXPECT_EQ(rect.GetTop(), 0.0f); + EXPECT_EQ(rect.GetRight(), 15.5f); + EXPECT_EQ(rect.GetBottom(), 15.125f); + EXPECT_EQ(rect.GetX(), 0.0f); + EXPECT_EQ(rect.GetY(), 0.0f); + EXPECT_EQ(rect.GetWidth(), 15.5f); + EXPECT_EQ(rect.GetHeight(), 15.125f); + EXPECT_FALSE(rect.IsEmpty()); + EXPECT_TRUE(rect.IsFinite()); +} + +TEST(RectTest, IRectSimpleWH) { + // Using fractional-power-of-2 friendly values for equality tests + IRect rect = IRect::MakeWH(15, 25); + + EXPECT_EQ(rect.GetLeft(), 0); + EXPECT_EQ(rect.GetTop(), 0); + EXPECT_EQ(rect.GetRight(), 15); + EXPECT_EQ(rect.GetBottom(), 25); + EXPECT_EQ(rect.GetX(), 0); + EXPECT_EQ(rect.GetY(), 0); + EXPECT_EQ(rect.GetWidth(), 15); + EXPECT_EQ(rect.GetHeight(), 25); + EXPECT_FALSE(rect.IsEmpty()); +} + TEST(RectTest, RectOverflowXYWH) { auto min = std::numeric_limits::lowest(); auto max = std::numeric_limits::max(); @@ -1604,18 +1635,28 @@ TEST(RectTest, RectIntersection) { // unflipped a vs flipped (empty) b yields a EXPECT_FALSE(a.Intersection(flip_lr(b)).has_value()) << label; + EXPECT_TRUE(a.IntersectionOrEmpty(flip_lr(b)).IsEmpty()) << label; EXPECT_FALSE(a.Intersection(flip_tb(b)).has_value()) << label; + EXPECT_TRUE(a.IntersectionOrEmpty(flip_tb(b)).IsEmpty()) << label; EXPECT_FALSE(a.Intersection(flip_lrtb(b)).has_value()) << label; + EXPECT_TRUE(a.IntersectionOrEmpty(flip_lrtb(b)).IsEmpty()) << label; // flipped (empty) a vs unflipped b yields b EXPECT_FALSE(flip_lr(a).Intersection(b).has_value()) << label; + EXPECT_TRUE(flip_lr(a).IntersectionOrEmpty(b).IsEmpty()) << label; EXPECT_FALSE(flip_tb(a).Intersection(b).has_value()) << label; + EXPECT_TRUE(flip_tb(a).IntersectionOrEmpty(b).IsEmpty()) << label; EXPECT_FALSE(flip_lrtb(a).Intersection(b).has_value()) << label; + EXPECT_TRUE(flip_lrtb(a).IntersectionOrEmpty(b).IsEmpty()) << label; // flipped (empty) a vs flipped (empty) b yields empty EXPECT_FALSE(flip_lr(a).Intersection(flip_lr(b)).has_value()) << label; + EXPECT_TRUE(flip_lr(a).IntersectionOrEmpty(flip_lr(b)).IsEmpty()) << label; EXPECT_FALSE(flip_tb(a).Intersection(flip_tb(b)).has_value()) << label; + EXPECT_TRUE(flip_tb(a).IntersectionOrEmpty(flip_tb(b)).IsEmpty()) << label; EXPECT_FALSE(flip_lrtb(a).Intersection(flip_lrtb(b)).has_value()) << label; + EXPECT_TRUE(flip_lrtb(a).IntersectionOrEmpty(flip_lrtb(b)).IsEmpty()) + << label; }; auto test_non_empty = [&check_nans, &check_empty_flips]( @@ -1645,7 +1686,9 @@ TEST(RectTest, RectIntersection) { auto label = stream.str(); EXPECT_FALSE(a.Intersection(b).has_value()) << label; + EXPECT_TRUE(a.IntersectionOrEmpty(b).IsEmpty()) << label; EXPECT_FALSE(b.Intersection(a).has_value()) << label; + EXPECT_TRUE(b.IntersectionOrEmpty(a).IsEmpty()) << label; check_empty_flips(a, b, label); check_nans(a, b, label); }; diff --git a/shell/common/dl_op_spy.cc b/shell/common/dl_op_spy.cc index ba3b429756051..b386344952faf 100644 --- a/shell/common/dl_op_spy.cc +++ b/shell/common/dl_op_spy.cc @@ -29,7 +29,7 @@ void DlOpSpy::setColorSource(const DlColorSource* source) { will_draw_ = true; } void DlOpSpy::save() {} -void DlOpSpy::saveLayer(const SkRect& bounds, +void DlOpSpy::saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) {} void DlOpSpy::restore() {} @@ -41,7 +41,7 @@ void DlOpSpy::drawPaint() { } // TODO(cyanglaz): check whether the shape (line, rect, oval, etc) needs to be // evaluated. https://github.com/flutter/flutter/issues/123803 -void DlOpSpy::drawLine(const SkPoint& p0, const SkPoint& p1) { +void DlOpSpy::drawLine(const DlPoint& p0, const DlPoint& p1) { did_draw_ |= will_draw_; } void DlOpSpy::drawDashedLine(const DlPoint& p0, @@ -50,13 +50,13 @@ void DlOpSpy::drawDashedLine(const DlPoint& p0, DlScalar off_length) { did_draw_ |= will_draw_; } -void DlOpSpy::drawRect(const SkRect& rect) { +void DlOpSpy::drawRect(const DlRect& rect) { did_draw_ |= will_draw_; } -void DlOpSpy::drawOval(const SkRect& bounds) { +void DlOpSpy::drawOval(const DlRect& bounds) { did_draw_ |= will_draw_; } -void DlOpSpy::drawCircle(const SkPoint& center, SkScalar radius) { +void DlOpSpy::drawCircle(const DlPoint& center, DlScalar radius) { did_draw_ |= will_draw_; } void DlOpSpy::drawRRect(const SkRRect& rrect) { @@ -68,15 +68,15 @@ void DlOpSpy::drawDRRect(const SkRRect& outer, const SkRRect& inner) { void DlOpSpy::drawPath(const SkPath& path) { did_draw_ |= will_draw_; } -void DlOpSpy::drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, +void DlOpSpy::drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) { did_draw_ |= will_draw_; } void DlOpSpy::drawPoints(PointMode mode, uint32_t count, - const SkPoint points[]) { + const DlPoint points[]) { did_draw_ |= will_draw_; } void DlOpSpy::drawVertices(const std::shared_ptr& vertices, @@ -89,39 +89,39 @@ void DlOpSpy::drawVertices(const std::shared_ptr& vertices, // Drawing a completely transparent image is not a valid use case, thus, such // case is ignored. void DlOpSpy::drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) { did_draw_ = true; } void DlOpSpy::drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) { did_draw_ = true; } void DlOpSpy::drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) { did_draw_ = true; } void DlOpSpy::drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) { did_draw_ = true; } void DlOpSpy::drawDisplayList(const sk_sp display_list, - SkScalar opacity) { + DlScalar opacity) { if (did_draw_ || opacity == 0) { return; } @@ -130,23 +130,23 @@ void DlOpSpy::drawDisplayList(const sk_sp display_list, did_draw_ |= receiver.did_draw(); } void DlOpSpy::drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { did_draw_ |= will_draw_; } void DlOpSpy::drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { did_draw_ |= will_draw_; } void DlOpSpy::drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { did_draw_ |= !color.isTransparent(); } diff --git a/shell/common/dl_op_spy.h b/shell/common/dl_op_spy.h index 490e09c60f8ec..f51297ce7cf38 100644 --- a/shell/common/dl_op_spy.h +++ b/shell/common/dl_op_spy.h @@ -39,70 +39,70 @@ class DlOpSpy final : public virtual DlOpReceiver, void setColor(DlColor color) override; void setColorSource(const DlColorSource* source) override; void save() override; - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override; void restore() override; void drawColor(DlColor color, DlBlendMode mode) override; void drawPaint() override; - void drawLine(const SkPoint& p0, const SkPoint& p1) override; + void drawLine(const DlPoint& p0, const DlPoint& p1) override; void drawDashedLine(const DlPoint& p0, const DlPoint& p1, DlScalar on_length, DlScalar off_length) override; - void drawRect(const SkRect& rect) override; - void drawOval(const SkRect& bounds) override; - void drawCircle(const SkPoint& center, SkScalar radius) override; + void drawRect(const DlRect& rect) override; + void drawOval(const DlRect& bounds) override; + void drawCircle(const DlPoint& center, DlScalar radius) override; void drawRRect(const SkRRect& rrect) override; void drawDRRect(const SkRRect& outer, const SkRRect& inner) override; void drawPath(const SkPath& path) override; - void drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + void drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) override; void drawPoints(PointMode mode, uint32_t count, - const SkPoint points[]) override; + const DlPoint points[]) override; void drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) override; void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) override; void drawImageRect( const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint = SrcRectConstraint::kFast) override; void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) override; void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) override; void drawDisplayList(const sk_sp display_list, - SkScalar opacity = SK_Scalar1) override; + DlScalar opacity = SK_Scalar1) override; void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override; + DlScalar dpr) override; // Indicates if the attributes are set to values that will modify the // destination. For now, the test only checks if there is a non-transparent diff --git a/testing/display_list_testing.cc b/testing/display_list_testing.cc index 0663aea860de9..dc0205b0d3505 100644 --- a/testing/display_list_testing.cc +++ b/testing/display_list_testing.cc @@ -195,15 +195,6 @@ static std::ostream& operator<<(std::ostream& os, const SkPoint& point) { return os << "SkPoint(" << point.fX << ", " << point.fY << ")"; } -static std::ostream& operator<<(std::ostream& os, const SkIRect& rect) { - return os << "SkIRect(" - << "left: " << rect.fLeft << ", " - << "top: " << rect.fTop << ", " - << "right: " << rect.fRight << ", " - << "bottom: " << rect.fBottom - << ")"; -} - static std::ostream& operator<<(std::ostream& os, const SkRect& rect) { return os << "SkRect(" << "left: " << rect.fLeft << ", " @@ -213,10 +204,6 @@ static std::ostream& operator<<(std::ostream& os, const SkRect& rect) { << ")"; } -static std::ostream& operator<<(std::ostream& os, const SkRect* rect) { - return rect ? (os << "&" << *rect) : os << "no rect"; -} - static std::ostream& operator<<(std::ostream& os, const SkRRect& rrect) { return os << "SkRRect(" << rrect.rect() << ", " @@ -456,10 +443,10 @@ void DisplayListStreamDispatcher::setDrawStyle(DlDrawStyle style) { void DisplayListStreamDispatcher::setColor(DlColor color) { startl() << "setColor(" << color << ");" << std::endl; } -void DisplayListStreamDispatcher::setStrokeWidth(SkScalar width) { +void DisplayListStreamDispatcher::setStrokeWidth(DlScalar width) { startl() << "setStrokeWidth(" << width << ");" << std::endl; } -void DisplayListStreamDispatcher::setStrokeMiter(SkScalar limit) { +void DisplayListStreamDispatcher::setStrokeMiter(DlScalar limit) { startl() << "setStrokeMiter(" << limit << ");" << std::endl; } void DisplayListStreamDispatcher::setStrokeCap(DlStrokeCap cap) { @@ -722,7 +709,7 @@ void DisplayListStreamDispatcher::save() { startl() << "{" << std::endl; indent(); } -void DisplayListStreamDispatcher::saveLayer(const SkRect& bounds, +void DisplayListStreamDispatcher::saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) { startl() << "saveLayer(" << bounds << ", " << options; @@ -745,21 +732,21 @@ void DisplayListStreamDispatcher::restore() { startl() << "restore();" << std::endl; } -void DisplayListStreamDispatcher::translate(SkScalar tx, SkScalar ty) { +void DisplayListStreamDispatcher::translate(DlScalar tx, DlScalar ty) { startl() << "translate(" << tx << ", " << ty << ");" << std::endl; } -void DisplayListStreamDispatcher::scale(SkScalar sx, SkScalar sy) { +void DisplayListStreamDispatcher::scale(DlScalar sx, DlScalar sy) { startl() << "scale(" << sx << ", " << sy << ");" << std::endl; } -void DisplayListStreamDispatcher::rotate(SkScalar degrees) { +void DisplayListStreamDispatcher::rotate(DlScalar degrees) { startl() << "rotate(" << degrees << ");" << std::endl; } -void DisplayListStreamDispatcher::skew(SkScalar sx, SkScalar sy) { +void DisplayListStreamDispatcher::skew(DlScalar sx, DlScalar sy) { startl() << "skew(" << sx << ", " << sy << ");" << std::endl; } void DisplayListStreamDispatcher::transform2DAffine( - SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) { + DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) { startl() << "transform2DAffine(" << std::endl; indent(); { @@ -774,10 +761,10 @@ void DisplayListStreamDispatcher::transform2DAffine( startl() << ");" << std::endl; } void DisplayListStreamDispatcher::transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) { + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) { startl() << "transformFullPerspective(" << std::endl; indent(); { @@ -801,7 +788,7 @@ void DisplayListStreamDispatcher::transformReset() { startl() << "transformReset();" << std::endl; } -void DisplayListStreamDispatcher::clipRect(const SkRect& rect, ClipOp clip_op, +void DisplayListStreamDispatcher::clipRect(const DlRect& rect, ClipOp clip_op, bool is_aa) { startl() << "clipRect(" << rect << ", " @@ -809,7 +796,7 @@ void DisplayListStreamDispatcher::clipRect(const SkRect& rect, ClipOp clip_op, << "isaa: " << is_aa << ");" << std::endl; } -void DisplayListStreamDispatcher::clipOval(const SkRect& bounds, ClipOp clip_op, +void DisplayListStreamDispatcher::clipOval(const DlRect& bounds, ClipOp clip_op, bool is_aa) { startl() << "clipOval(" << bounds << ", " @@ -844,8 +831,8 @@ void DisplayListStreamDispatcher::drawColor(DlColor color, DlBlendMode mode) { void DisplayListStreamDispatcher::drawPaint() { startl() << "drawPaint();" << std::endl; } -void DisplayListStreamDispatcher::drawLine(const SkPoint& p0, - const SkPoint& p1) { +void DisplayListStreamDispatcher::drawLine(const DlPoint& p0, + const DlPoint& p1) { startl() << "drawLine(" << p0 << ", " << p1 << ");" << std::endl; } void DisplayListStreamDispatcher::drawDashedLine(const DlPoint& p0, @@ -859,14 +846,14 @@ void DisplayListStreamDispatcher::drawDashedLine(const DlPoint& p0, << off_length << ");" << std::endl; } -void DisplayListStreamDispatcher::drawRect(const SkRect& rect) { +void DisplayListStreamDispatcher::drawRect(const DlRect& rect) { startl() << "drawRect(" << rect << ");" << std::endl; } -void DisplayListStreamDispatcher::drawOval(const SkRect& bounds) { +void DisplayListStreamDispatcher::drawOval(const DlRect& bounds) { startl() << "drawOval(" << bounds << ");" << std::endl; } -void DisplayListStreamDispatcher::drawCircle(const SkPoint& center, - SkScalar radius) { +void DisplayListStreamDispatcher::drawCircle(const DlPoint& center, + DlScalar radius) { startl() << "drawCircle(" << center << ", " << radius << ");" << std::endl; } void DisplayListStreamDispatcher::drawRRect(const SkRRect& rrect) { @@ -880,9 +867,9 @@ void DisplayListStreamDispatcher::drawDRRect(const SkRRect& outer, void DisplayListStreamDispatcher::drawPath(const SkPath& path) { startl() << "drawPath(" << path << ");" << std::endl; } -void DisplayListStreamDispatcher::drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, +void DisplayListStreamDispatcher::drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) { startl() << "drawArc(" << oval_bounds << ", " @@ -893,7 +880,7 @@ void DisplayListStreamDispatcher::drawArc(const SkRect& oval_bounds, } void DisplayListStreamDispatcher::drawPoints(PointMode mode, uint32_t count, - const SkPoint points[]) { + const DlPoint points[]) { startl() << "drawPoints(" << mode << ", "; out_array("points", count, points) << ");" << std::endl; @@ -910,7 +897,7 @@ void DisplayListStreamDispatcher::drawVertices(const std::shared_ptr << "), " << mode << ");" << std::endl; } void DisplayListStreamDispatcher::drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) { startl() << "drawImage(" << image.get() << "," << std::endl; @@ -920,8 +907,8 @@ void DisplayListStreamDispatcher::drawImage(const sk_sp image, << ");" << std::endl; } void DisplayListStreamDispatcher::drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) { @@ -934,8 +921,8 @@ void DisplayListStreamDispatcher::drawImageRect(const sk_sp image, << ");" << std::endl; } void DisplayListStreamDispatcher::drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) { startl() << "drawImageNine(" << image.get() << "," << std::endl; @@ -947,12 +934,12 @@ void DisplayListStreamDispatcher::drawImageNine(const sk_sp image, } void DisplayListStreamDispatcher::drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) { startl() << "drawAtlas(" << atlas.get() << ", "; out_array("xforms", count, xform) << ", "; @@ -963,7 +950,7 @@ void DisplayListStreamDispatcher::drawAtlas(const sk_sp atlas, << ");" << std::endl; } void DisplayListStreamDispatcher::drawDisplayList( - const sk_sp display_list, SkScalar opacity) { + const sk_sp display_list, DlScalar opacity) { startl() << "drawDisplayList(" << "ID: " << display_list->unique_id() << ", " << "bounds: " << display_list->bounds() << ", " @@ -971,8 +958,8 @@ void DisplayListStreamDispatcher::drawDisplayList( << ");" << std::endl; } void DisplayListStreamDispatcher::drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { startl() << "drawTextBlob(" << blob.get() << ", " << x << ", " << y << ");" << std::endl; @@ -980,8 +967,8 @@ void DisplayListStreamDispatcher::drawTextBlob(const sk_sp blob, void DisplayListStreamDispatcher::drawTextFrame( const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) { + DlScalar x, + DlScalar y) { startl() << "drawTextFrame(" << text_frame.get() << ", " << x << ", " << y << ");" << std::endl; @@ -989,9 +976,9 @@ void DisplayListStreamDispatcher::drawTextFrame( void DisplayListStreamDispatcher::drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) { + DlScalar dpr) { startl() << "drawShadow(" << path << ", " << color << ", " diff --git a/testing/display_list_testing.h b/testing/display_list_testing.h index 3ce9ec2bfe65e..dbc1c67bf1981 100644 --- a/testing/display_list_testing.h +++ b/testing/display_list_testing.h @@ -95,8 +95,8 @@ class DisplayListStreamDispatcher final : public DlOpReceiver { void setAntiAlias(bool aa) override; void setDrawStyle(DlDrawStyle style) override; void setColor(DlColor color) override; - void setStrokeWidth(SkScalar width) override; - void setStrokeMiter(SkScalar limit) override; + void setStrokeWidth(DlScalar width) override; + void setStrokeMiter(DlScalar limit) override; void setStrokeCap(DlStrokeCap cap) override; void setStrokeJoin(DlStrokeJoin join) override; void setColorSource(const DlColorSource* source) override; @@ -107,90 +107,90 @@ class DisplayListStreamDispatcher final : public DlOpReceiver { void setImageFilter(const DlImageFilter* filter) override; void save() override; - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override; void restore() override; - void translate(SkScalar tx, SkScalar ty) override; - void scale(SkScalar sx, SkScalar sy) override; - void rotate(SkScalar degrees) override; - void skew(SkScalar sx, SkScalar sy) override; + void translate(DlScalar tx, DlScalar ty) override; + void scale(DlScalar sx, DlScalar sy) override; + void rotate(DlScalar degrees) override; + void skew(DlScalar sx, DlScalar sy) override; // clang-format off - void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) override; + void transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) override; void transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override; + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override; // clang-format on void transformReset() override; - void clipRect(const SkRect& rect, ClipOp clip_op, bool is_aa) override; - void clipOval(const SkRect& bounds, ClipOp clip_op, bool is_aa) override; + void clipRect(const DlRect& rect, ClipOp clip_op, bool is_aa) override; + void clipOval(const DlRect& bounds, ClipOp clip_op, bool is_aa) override; void clipRRect(const SkRRect& rrect, ClipOp clip_op, bool is_aa) override; void clipPath(const SkPath& path, ClipOp clip_op, bool is_aa) override; void drawColor(DlColor color, DlBlendMode mode) override; void drawPaint() override; - void drawLine(const SkPoint& p0, const SkPoint& p1) override; + void drawLine(const DlPoint& p0, const DlPoint& p1) override; void drawDashedLine(const DlPoint& p0, const DlPoint& p1, DlScalar on_length, DlScalar off_length) override; - void drawRect(const SkRect& rect) override; - void drawOval(const SkRect& bounds) override; - void drawCircle(const SkPoint& center, SkScalar radius) override; + void drawRect(const DlRect& rect) override; + void drawOval(const DlRect& bounds) override; + void drawCircle(const DlPoint& center, DlScalar radius) override; void drawRRect(const SkRRect& rrect) override; void drawDRRect(const SkRRect& outer, const SkRRect& inner) override; void drawPath(const SkPath& path) override; - void drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + void drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) override; void drawPoints(PointMode mode, uint32_t count, - const SkPoint points[]) override; + const DlPoint points[]) override; void drawVertices(const std::shared_ptr& vertices, DlBlendMode mode) override; void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) override; void drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) override; void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) override; void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) override; void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override; + DlScalar opacity) override; void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override; + DlScalar x, + DlScalar y) override; void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override; + DlScalar dpr) override; private: std::ostream& os_; @@ -318,30 +318,30 @@ class DisplayListGeneralReceiver : public DlOpReceiver { } } - void translate(SkScalar tx, SkScalar ty) override { + void translate(DlScalar tx, DlScalar ty) override { RecordByType(DisplayListOpType::kTranslate); } - void scale(SkScalar sx, SkScalar sy) override { + void scale(DlScalar sx, DlScalar sy) override { RecordByType(DisplayListOpType::kScale); } - void rotate(SkScalar degrees) override { + void rotate(DlScalar degrees) override { RecordByType(DisplayListOpType::kRotate); } - void skew(SkScalar sx, SkScalar sy) override { + void skew(DlScalar sx, DlScalar sy) override { RecordByType(DisplayListOpType::kSkew); } // clang-format off // 2x3 2D affine subset of a 4x4 transform in row major order - void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myt) override { + void transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myt) override { RecordByType(DisplayListOpType::kTransform2DAffine); } // full 4x4 transform in row major order void transformFullPerspective( - SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, - SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, - SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, - SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override { + DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, + DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, + DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, + DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override { RecordByType(DisplayListOpType::kTransformFullPerspective); } // clang-format on @@ -349,7 +349,7 @@ class DisplayListGeneralReceiver : public DlOpReceiver { RecordByType(DisplayListOpType::kTransformReset); } - void clipRect(const SkRect& rect, + void clipRect(const DlRect& rect, DlCanvas::ClipOp clip_op, bool is_aa) override { switch (clip_op) { @@ -361,7 +361,7 @@ class DisplayListGeneralReceiver : public DlOpReceiver { break; } } - void clipOval(const SkRect& bounds, + void clipOval(const DlRect& bounds, DlCanvas::ClipOp clip_op, bool is_aa) override { switch (clip_op) { @@ -399,7 +399,7 @@ class DisplayListGeneralReceiver : public DlOpReceiver { } void save() override { RecordByType(DisplayListOpType::kSave); } - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, const SaveLayerOptions options, const DlImageFilter* backdrop) override { if (backdrop) { @@ -414,7 +414,7 @@ class DisplayListGeneralReceiver : public DlOpReceiver { RecordByType(DisplayListOpType::kDrawColor); } void drawPaint() override { RecordByType(DisplayListOpType::kDrawPaint); } - void drawLine(const SkPoint& p0, const SkPoint& p1) override { + void drawLine(const DlPoint& p0, const DlPoint& p1) override { RecordByType(DisplayListOpType::kDrawLine); } void drawDashedLine(const DlPoint& p0, @@ -423,13 +423,13 @@ class DisplayListGeneralReceiver : public DlOpReceiver { DlScalar off_length) override { RecordByType(DisplayListOpType::kDrawDashedLine); } - void drawRect(const SkRect& rect) override { + void drawRect(const DlRect& rect) override { RecordByType(DisplayListOpType::kDrawRect); } - void drawOval(const SkRect& bounds) override { + void drawOval(const DlRect& bounds) override { RecordByType(DisplayListOpType::kDrawOval); } - void drawCircle(const SkPoint& center, SkScalar radius) override { + void drawCircle(const DlPoint& center, DlScalar radius) override { RecordByType(DisplayListOpType::kDrawCircle); } void drawRRect(const SkRRect& rrect) override { @@ -441,15 +441,15 @@ class DisplayListGeneralReceiver : public DlOpReceiver { void drawPath(const SkPath& path) override { RecordByType(DisplayListOpType::kDrawPath); } - void drawArc(const SkRect& oval_bounds, - SkScalar start_degrees, - SkScalar sweep_degrees, + void drawArc(const DlRect& oval_bounds, + DlScalar start_degrees, + DlScalar sweep_degrees, bool use_center) override { RecordByType(DisplayListOpType::kDrawArc); } void drawPoints(DlCanvas::PointMode mode, uint32_t count, - const SkPoint points[]) override { + const DlPoint points[]) override { switch (mode) { case DlCanvas::PointMode::kPoints: RecordByType(DisplayListOpType::kDrawPoints); @@ -467,7 +467,7 @@ class DisplayListGeneralReceiver : public DlOpReceiver { RecordByType(DisplayListOpType::kDrawVertices); } void drawImage(const sk_sp image, - const SkPoint point, + const DlPoint& point, DlImageSampling sampling, bool render_with_attributes) override { if (render_with_attributes) { @@ -477,16 +477,16 @@ class DisplayListGeneralReceiver : public DlOpReceiver { } } void drawImageRect(const sk_sp image, - const SkRect& src, - const SkRect& dst, + const DlRect& src, + const DlRect& dst, DlImageSampling sampling, bool render_with_attributes, SrcRectConstraint constraint) override { RecordByType(DisplayListOpType::kDrawImageRect); } void drawImageNine(const sk_sp image, - const SkIRect& center, - const SkRect& dst, + const DlIRect& center, + const DlRect& dst, DlFilterMode filter, bool render_with_attributes) override { if (render_with_attributes) { @@ -497,12 +497,12 @@ class DisplayListGeneralReceiver : public DlOpReceiver { } void drawAtlas(const sk_sp atlas, const SkRSXform xform[], - const SkRect tex[], + const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, - const SkRect* cull_rect, + const DlRect* cull_rect, bool render_with_attributes) override { if (cull_rect) { RecordByType(DisplayListOpType::kDrawAtlasCulled); @@ -511,24 +511,24 @@ class DisplayListGeneralReceiver : public DlOpReceiver { } } void drawDisplayList(const sk_sp display_list, - SkScalar opacity) override { + DlScalar opacity) override { RecordByType(DisplayListOpType::kDrawDisplayList); } void drawTextBlob(const sk_sp blob, - SkScalar x, - SkScalar y) override { + DlScalar x, + DlScalar y) override { RecordByType(DisplayListOpType::kDrawTextBlob); } void drawTextFrame(const std::shared_ptr& text_frame, - SkScalar x, - SkScalar y) override { + DlScalar x, + DlScalar y) override { RecordByType(DisplayListOpType::kDrawTextFrame); } void drawShadow(const SkPath& path, const DlColor color, - const SkScalar elevation, + const DlScalar elevation, bool transparent_occluder, - SkScalar dpr) override { + DlScalar dpr) override { if (transparent_occluder) { RecordByType(DisplayListOpType::kDrawShadowTransparentOccluder); } else { diff --git a/testing/mock_canvas.cc b/testing/mock_canvas.cc index 03627f722fbaa..521bb1f311c1f 100644 --- a/testing/mock_canvas.cc +++ b/testing/mock_canvas.cc @@ -187,7 +187,7 @@ void MockCanvas::DrawShadow(const SkPath& path, } void MockCanvas::DrawImage(const sk_sp& image, - SkPoint point, + const SkPoint& point, const DlImageSampling options, const DlPaint* paint) { if (paint) { diff --git a/testing/mock_canvas.h b/testing/mock_canvas.h index 7384d5ecf578a..16b89ebbc85fa 100644 --- a/testing/mock_canvas.h +++ b/testing/mock_canvas.h @@ -255,7 +255,7 @@ class MockCanvas final : public DlCanvas { const DlPaint& paint) override; void DrawImage(const sk_sp& image, - const SkPoint point, + const SkPoint& point, DlImageSampling sampling, const DlPaint* paint = nullptr) override; void DrawImageRect( diff --git a/third_party/txt/tests/paragraph_unittests.cc b/third_party/txt/tests/paragraph_unittests.cc index 3bbc6250422f5..a02899b7d925a 100644 --- a/third_party/txt/tests/paragraph_unittests.cc +++ b/third_party/txt/tests/paragraph_unittests.cc @@ -50,7 +50,7 @@ class DlOpRecorder final : public virtual DlOpReceiver, int blobCount() const { return blobs_.size(); } private: - void drawLine(const SkPoint& p0, const SkPoint& p1) override { + void drawLine(const DlPoint& p0, const DlPoint& p1) override { lines_.emplace_back(p0, p1); } @@ -73,15 +73,15 @@ class DlOpRecorder final : public virtual DlOpReceiver, blobs_.push_back(blob); } - void drawRect(const SkRect& rect) override { rects_.push_back(rect); } + void drawRect(const DlRect& rect) override { rects_.push_back(rect); } void drawPath(const SkPath& path) override { paths_.push_back(path); } std::vector> text_frames_; std::vector> blobs_; - std::vector> lines_; + std::vector> lines_; std::vector> dashed_lines_; - std::vector rects_; + std::vector rects_; std::vector paths_; }; From 0fad4601a1fbc87d3ac68965c2a3cf5baecdebcf Mon Sep 17 00:00:00 2001 From: Yegor Date: Fri, 6 Sep 2024 15:21:54 -0700 Subject: [PATCH 08/12] [skwasm] use temporary RawPaint objects (#54917) Same as https://github.com/flutter/engine/pull/54818, but for Skwasm. Addresses the `Paint` issue in https://github.com/flutter/flutter/issues/153678 in Skwasm --- .../src/engine/skwasm/skwasm_impl/canvas.dart | 156 ++++++++------ .../src/engine/skwasm/skwasm_impl/paint.dart | 204 ++++++++---------- .../engine/skwasm/skwasm_impl/paragraph.dart | 8 +- .../skwasm/skwasm_impl/raw/raw_paint.dart | 69 ++---- lib/web_ui/skwasm/paint.cpp | 82 ++----- 5 files changed, 227 insertions(+), 292 deletions(-) diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart index e33a515d281b9..f04e502fd75ea 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart @@ -29,27 +29,29 @@ class SkwasmCanvas implements SceneCanvas { @override void saveLayer(ui.Rect? bounds, ui.Paint paint) { - paint as SkwasmPaint; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); if (bounds != null) { withStackScope((StackScope s) { - canvasSaveLayer(_handle, s.convertRectToNative(bounds), paint.handle, nullptr); + canvasSaveLayer(_handle, s.convertRectToNative(bounds), paintHandle, nullptr); }); } else { - canvasSaveLayer(_handle, nullptr, paint.handle, nullptr); + canvasSaveLayer(_handle, nullptr, paintHandle, nullptr); } + paintDispose(paintHandle); } @override void saveLayerWithFilter(ui.Rect? bounds, ui.Paint paint, ui.ImageFilter imageFilter) { final SkwasmImageFilter nativeFilter = SkwasmImageFilter.fromUiFilter(imageFilter); - paint as SkwasmPaint; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); if (bounds != null) { withStackScope((StackScope s) { - canvasSaveLayer(_handle, s.convertRectToNative(bounds), paint.handle, nativeFilter.handle); + canvasSaveLayer(_handle, s.convertRectToNative(bounds), paintHandle, nativeFilter.handle); }); } else { - canvasSaveLayer(_handle, nullptr, paint.handle, nativeFilter.handle); + canvasSaveLayer(_handle, nullptr, paintHandle, nativeFilter.handle); } + paintDispose(paintHandle); } @override @@ -111,71 +113,78 @@ class SkwasmCanvas implements SceneCanvas { @override void drawLine(ui.Offset p1, ui.Offset p2, ui.Paint paint) { - paint as SkwasmPaint; - canvasDrawLine(_handle, p1.dx, p1.dy, p2.dx, p2.dy, paint.handle); + final paintHandle = (paint as SkwasmPaint).toRawPaint(); + canvasDrawLine(_handle, p1.dx, p1.dy, p2.dx, p2.dy, paintHandle); + paintDispose(paintHandle); } @override void drawPaint(ui.Paint paint) { - paint as SkwasmPaint; - canvasDrawPaint(_handle, paint.handle); + final paintHandle = (paint as SkwasmPaint).toRawPaint(); + canvasDrawPaint(_handle, paintHandle); + paintDispose(paintHandle); } @override void drawRect(ui.Rect rect, ui.Paint paint) { - paint as SkwasmPaint; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); withStackScope((StackScope s) { canvasDrawRect( _handle, s.convertRectToNative(rect), - paint.handle + paintHandle ); }); + paintDispose(paintHandle); } @override void drawRRect(ui.RRect rrect, ui.Paint paint) { - paint as SkwasmPaint; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); withStackScope((StackScope s) { canvasDrawRRect( _handle, s.convertRRectToNative(rrect), - paint.handle + paintHandle ); }); + paintDispose(paintHandle); } @override void drawDRRect(ui.RRect outer, ui.RRect inner, ui.Paint paint) { - paint as SkwasmPaint; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); withStackScope((StackScope s) { canvasDrawDRRect( _handle, s.convertRRectToNative(outer), s.convertRRectToNative(inner), - paint.handle + paintHandle ); }); + paintDispose(paintHandle); } @override void drawOval(ui.Rect rect, ui.Paint paint) { - paint as SkwasmPaint; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); withStackScope((StackScope s) { - canvasDrawOval(_handle, s.convertRectToNative(rect), paint.handle); + canvasDrawOval(_handle, s.convertRectToNative(rect), paintHandle); }); + paintDispose(paintHandle); } @override void drawCircle(ui.Offset center, double radius, ui.Paint paint) { - paint as SkwasmPaint; - canvasDrawCircle(_handle, center.dx, center.dy, radius, paint.handle); + final paintHandle = (paint as SkwasmPaint).toRawPaint(); + canvasDrawCircle(_handle, center.dx, center.dy, radius, paintHandle); + paintDispose(paintHandle); } @override void drawArc(ui.Rect rect, double startAngle, double sweepAngle, bool useCenter, ui.Paint paint) { - paint as SkwasmPaint; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); withStackScope((StackScope s) { canvasDrawArc( _handle, @@ -183,64 +192,79 @@ class SkwasmCanvas implements SceneCanvas { ui.toDegrees(startAngle), ui.toDegrees(sweepAngle), useCenter, - paint.handle + paintHandle, ); }); + paintDispose(paintHandle); } @override void drawPath(ui.Path path, ui.Paint paint) { - paint as SkwasmPaint; path as SkwasmPath; - canvasDrawPath(_handle, path.handle, paint.handle); + final paintHandle = (paint as SkwasmPaint).toRawPaint(); + canvasDrawPath(_handle, path.handle, paintHandle); + paintDispose(paintHandle); } @override - void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) => + void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) { + final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawImage( _handle, (image as SkwasmImage).handle, offset.dx, offset.dy, - (paint as SkwasmPaint).handle, + paintHandle, paint.filterQuality.index, ); + paintDispose(paintHandle); + } @override void drawImageRect( ui.Image image, ui.Rect src, ui.Rect dst, - ui.Paint paint) => withStackScope((StackScope scope) { - final Pointer sourceRect = scope.convertRectToNative(src); - final Pointer destRect = scope.convertRectToNative(dst); - canvasDrawImageRect( - _handle, - (image as SkwasmImage).handle, - sourceRect, - destRect, - (paint as SkwasmPaint).handle, - paint.filterQuality.index, - ); - }); + ui.Paint paint, + ) { + withStackScope((StackScope scope) { + final Pointer sourceRect = scope.convertRectToNative(src); + final Pointer destRect = scope.convertRectToNative(dst); + final paintHandle = (paint as SkwasmPaint).toRawPaint(); + canvasDrawImageRect( + _handle, + (image as SkwasmImage).handle, + sourceRect, + destRect, + paintHandle, + paint.filterQuality.index, + ); + paintDispose(paintHandle); + }); + } @override void drawImageNine( ui.Image image, ui.Rect center, ui.Rect dst, - ui.Paint paint) => withStackScope((StackScope scope) { - final Pointer centerRect = scope.convertIRectToNative(center); - final Pointer destRect = scope.convertRectToNative(dst); - canvasDrawImageNine( - _handle, - (image as SkwasmImage).handle, - centerRect, - destRect, - (paint as SkwasmPaint).handle, - paint.filterQuality.index, - ); - }); + ui.Paint paint, + ) { + withStackScope((StackScope scope) { + final Pointer centerRect = scope.convertIRectToNative(center); + final Pointer destRect = scope.convertRectToNative(dst); + final paintHandle = (paint as SkwasmPaint).toRawPaint(); + canvasDrawImageNine( + _handle, + (image as SkwasmImage).handle, + centerRect, + destRect, + paintHandle, + paint.filterQuality.index, + ); + paintDispose(paintHandle); + }); + } @override void drawPicture(ui.Picture picture) { @@ -264,13 +288,15 @@ class SkwasmCanvas implements SceneCanvas { ui.Paint paint ) => withStackScope((StackScope scope) { final RawPointArray rawPoints = scope.convertPointArrayToNative(points); + final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawPoints( _handle, pointMode.index, rawPoints, points.length, - (paint as SkwasmPaint).handle, + paintHandle, ); + paintDispose(paintHandle); }); @override @@ -280,13 +306,15 @@ class SkwasmCanvas implements SceneCanvas { ui.Paint paint ) => withStackScope((StackScope scope) { final RawPointArray rawPoints = scope.convertDoublesToNative(points); + final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawPoints( _handle, pointMode.index, rawPoints, points.length ~/ 2, - (paint as SkwasmPaint).handle, + paintHandle, ); + paintDispose(paintHandle); }); @override @@ -294,12 +322,16 @@ class SkwasmCanvas implements SceneCanvas { ui.Vertices vertices, ui.BlendMode blendMode, ui.Paint paint, - ) => canvasDrawVertices( - _handle, - (vertices as SkwasmVertices).handle, - blendMode.index, - (paint as SkwasmPaint).handle, - ); + ) { + final paintHandle = (paint as SkwasmPaint).toRawPaint(); + canvasDrawVertices( + _handle, + (vertices as SkwasmVertices).handle, + blendMode.index, + paintHandle, + ); + paintDispose(paintHandle); + } @override void drawAtlas( @@ -319,6 +351,7 @@ class SkwasmCanvas implements SceneCanvas { final RawRect rawCullRect = cullRect != null ? scope.convertRectToNative(cullRect) : nullptr; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawAtlas( _handle, (atlas as SkwasmImage).handle, @@ -328,8 +361,9 @@ class SkwasmCanvas implements SceneCanvas { transforms.length, (blendMode ?? ui.BlendMode.src).index, rawCullRect, - (paint as SkwasmPaint).handle, + paintHandle, ); + paintDispose(paintHandle); }); @override @@ -350,6 +384,7 @@ class SkwasmCanvas implements SceneCanvas { final RawRect rawCullRect = cullRect != null ? scope.convertRectToNative(cullRect) : nullptr; + final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawAtlas( _handle, (atlas as SkwasmImage).handle, @@ -359,8 +394,9 @@ class SkwasmCanvas implements SceneCanvas { rstTransforms.length ~/ 4, (blendMode ?? ui.BlendMode.src).index, rawCullRect, - (paint as SkwasmPaint).handle, + paintHandle, ); + paintDispose(paintHandle); }); @override diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart index 507bf94c63ca6..0abe010e5e69a 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart @@ -8,31 +8,73 @@ import 'package:ui/src/engine.dart'; import 'package:ui/src/engine/skwasm/skwasm_impl.dart'; import 'package:ui/ui.dart' as ui; -class SkwasmPaint extends SkwasmObjectWrapper implements ui.Paint { - SkwasmPaint() : super(paintCreate(), _registry); - - // Must be kept in sync with the default in paint.cc. - static const double _kStrokeMiterLimitDefault = 4.0; - - // Must be kept in sync with the default in paint.cc. - static const int _kColorDefault = 0xFF000000; - - // Must be kept in sync with the default in paint.cc. - static final int _kBlendModeDefault = ui.BlendMode.srcOver.index; - - static final SkwasmFinalizationRegistry _registry = - SkwasmFinalizationRegistry(paintDispose); - - ui.BlendMode _cachedBlendMode = ui.BlendMode.srcOver; +class SkwasmPaint implements ui.Paint { + SkwasmPaint(); + + /// Creates the C++ side paint object based on the current state of this + /// paint object, and returns it with ownership. + /// + /// It is the responsibility of the caller to dispose of the returned handle + /// when it's no longer needed. + PaintHandle toRawPaint() { + final rawPaint = paintCreate( + isAntiAlias, + blendMode.index, + _colorValue, + style.index, + strokeWidth, + strokeCap.index, + strokeJoin.index, + strokeMiterLimit, + ); + + _maybeSetEffectiveColorFilter(rawPaint); + + final shaderHandle = _shader?.handle; + if (shaderHandle != null) { + paintSetShader(rawPaint, shaderHandle); + } - SkwasmShader? _shader; - ui.ImageFilter? _imageFilter; + final localMaskFilter = maskFilter; + if (localMaskFilter != null) { + final nativeFilter = SkwasmMaskFilter.fromUiMaskFilter(localMaskFilter); + paintSetMaskFilter(rawPaint, nativeFilter.handle); + nativeFilter.dispose(); + } - EngineColorFilter? _colorFilter; + final filter = imageFilter; + if (filter != null) { + final nativeImageFilter = SkwasmImageFilter.fromUiFilter(filter); + paintSetImageFilter(rawPaint, nativeImageFilter.handle); + nativeImageFilter.dispose(); + } - ui.MaskFilter? _maskFilter; + return rawPaint; + } - bool _invertColors = false; + /// If `invertColors` is true or `colorFilter` is not null, sets the + /// appropriate Skia color filter. Otherwise, does nothing. + void _maybeSetEffectiveColorFilter(Pointer handle) { + final nativeFilter = _colorFilter != null + ? SkwasmColorFilter.fromEngineColorFilter(_colorFilter!) + : null; + if (invertColors) { + if (nativeFilter != null) { + final composedFilter = SkwasmColorFilter.composed( + _invertColorFilter, + nativeFilter, + ); + nativeFilter.dispose(); + paintSetColorFilter(handle, composedFilter.handle); + composedFilter.dispose(); + } else { + paintSetColorFilter(handle, _invertColorFilter.handle); + } + } else if (nativeFilter != null) { + paintSetColorFilter(handle, nativeFilter.handle); + nativeFilter.dispose(); + } + } static final SkwasmColorFilter _invertColorFilter = SkwasmColorFilter.fromEngineColorFilter( const EngineColorFilter.matrix([ @@ -44,143 +86,71 @@ class SkwasmPaint extends SkwasmObjectWrapper implements ui.Paint { ); @override - ui.BlendMode get blendMode { - return _cachedBlendMode; - } - - @override - set blendMode(ui.BlendMode blendMode) { - if (_cachedBlendMode != blendMode) { - _cachedBlendMode = blendMode; - paintSetBlendMode(handle, blendMode.index); - } - } - - @override - ui.PaintingStyle get style => ui.PaintingStyle.values[paintGetStyle(handle)]; - - @override - set style(ui.PaintingStyle style) => paintSetStyle(handle, style.index); + ui.BlendMode blendMode = _kBlendModeDefault; - @override - double get strokeWidth => paintGetStrokeWidth(handle); - - @override - set strokeWidth(double width) => paintSetStrokeWidth(handle, width); - - @override - ui.StrokeCap get strokeCap => ui.StrokeCap.values[paintGetStrokeCap(handle)]; + // Must be kept in sync with the default in paint.cc. + static const ui.BlendMode _kBlendModeDefault = ui.BlendMode.srcOver; @override - set strokeCap(ui.StrokeCap cap) => paintSetStrokeCap(handle, cap.index); + ui.PaintingStyle style = ui.PaintingStyle.fill; @override - ui.StrokeJoin get strokeJoin => ui.StrokeJoin.values[paintGetStrokeJoin(handle)]; + double strokeWidth = 0.0; @override - set strokeJoin(ui.StrokeJoin join) => paintSetStrokeJoin(handle, join.index); + ui.StrokeCap strokeCap = ui.StrokeCap.butt; @override - bool get isAntiAlias => paintGetAntiAlias(handle); + ui.StrokeJoin strokeJoin = ui.StrokeJoin.miter; @override - set isAntiAlias(bool value) => paintSetAntiAlias(handle, value); + bool isAntiAlias = true; @override - ui.Color get color => ui.Color(paintGetColorInt(handle)); - + ui.Color get color => ui.Color(_colorValue); @override - set color(ui.Color color) => paintSetColorInt(handle, color.value); + set color(ui.Color value) { + _colorValue = value.value; + } - @override - double get strokeMiterLimit => paintGetMiterLimit(handle); + static const int _kColorDefault = 0xFF000000; + int _colorValue = _kColorDefault; @override - set strokeMiterLimit(double limit) => paintSetMiterLimit(handle, limit); + double strokeMiterLimit = _kStrokeMiterLimitDefault; + static const double _kStrokeMiterLimitDefault = 4.0; @override ui.Shader? get shader => _shader; @override set shader(ui.Shader? uiShader) { - final SkwasmShader? skwasmShader = uiShader as SkwasmShader?; - _shader = skwasmShader; - final ShaderHandle shaderHandle = - skwasmShader != null ? skwasmShader.handle : nullptr; - paintSetShader(handle, shaderHandle); + uiShader as SkwasmShader?; + _shader = uiShader; } + SkwasmShader? _shader; @override ui.FilterQuality filterQuality = ui.FilterQuality.none; @override - ui.ImageFilter? get imageFilter => _imageFilter; - - @override - set imageFilter(ui.ImageFilter? filter) { - _imageFilter = filter; - - final SkwasmImageFilter? nativeImageFilter = filter != null - ? SkwasmImageFilter.fromUiFilter(filter) - : null; - paintSetImageFilter(handle, nativeImageFilter != null ? nativeImageFilter.handle : nullptr); - } + ui.ImageFilter? imageFilter; @override ui.ColorFilter? get colorFilter => _colorFilter; - void _setEffectiveColorFilter() { - final SkwasmColorFilter? nativeFilter = _colorFilter != null - ? SkwasmColorFilter.fromEngineColorFilter(_colorFilter!) : null; - if (_invertColors) { - if (nativeFilter != null) { - final SkwasmColorFilter composedFilter = SkwasmColorFilter.composed(_invertColorFilter, nativeFilter); - nativeFilter.dispose(); - paintSetColorFilter(handle, composedFilter.handle); - composedFilter.dispose(); - } else { - paintSetColorFilter(handle, _invertColorFilter.handle); - } - } else if (nativeFilter != null) { - paintSetColorFilter(handle, nativeFilter.handle); - nativeFilter.dispose(); - } else { - paintSetColorFilter(handle, nullptr); - } - } - @override set colorFilter(ui.ColorFilter? filter) { _colorFilter = filter as EngineColorFilter?; - _setEffectiveColorFilter(); } - @override - ui.MaskFilter? get maskFilter => _maskFilter; - - @override - set maskFilter(ui.MaskFilter? filter) { - _maskFilter = filter; - if (filter == null) { - paintSetMaskFilter(handle, nullptr); - } else { - final SkwasmMaskFilter nativeFilter = SkwasmMaskFilter.fromUiMaskFilter(filter); - paintSetMaskFilter(handle, nativeFilter.handle); - nativeFilter.dispose(); - } - } + EngineColorFilter? _colorFilter; @override - bool get invertColors => _invertColors; + ui.MaskFilter? maskFilter; @override - set invertColors(bool invertColors) { - if (_invertColors == invertColors) { - return; - } - _invertColors = invertColors; - _setEffectiveColorFilter(); - } + bool invertColors = false; @override String toString() { @@ -217,7 +187,7 @@ class SkwasmPaint extends SkwasmObjectWrapper implements ui.Paint { result.write('$semicolon$color'); semicolon = '; '; } - if (blendMode.index != _kBlendModeDefault) { + if (blendMode.index != _kBlendModeDefault.index) { result.write('$semicolon$blendMode'); semicolon = '; '; } diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart index 98dad74623e9f..88cb9fdc54096 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart @@ -398,10 +398,14 @@ class SkwasmTextStyle implements ui.TextStyle { skStringFree(localeHandle); } if (background != null) { - textStyleSetBackground(handle, (background! as SkwasmPaint).handle); + final backgroundPaint = (background! as SkwasmPaint).toRawPaint(); + textStyleSetBackground(handle, backgroundPaint); + paintDispose(backgroundPaint); } if (foreground != null) { - textStyleSetForeground(handle, (foreground! as SkwasmPaint).handle); + final foregroundPaint = (foreground! as SkwasmPaint).toRawPaint(); + textStyleSetForeground(handle, foregroundPaint); + paintDispose(foregroundPaint); } if (shadows != null) { for (final ui.Shadow shadow in shadows!) { diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_paint.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_paint.dart index 307e6968d517a..b74f14aff13ac 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_paint.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_paint.dart @@ -13,57 +13,32 @@ final class RawPaint extends Opaque {} typedef PaintHandle = Pointer; -@Native(symbol: 'paint_create', isLeaf: true) -external PaintHandle paintCreate(); +typedef _PaintCreateInitSignature = PaintHandle Function( + Bool, + Int, + Int, + Int, + Float, + Int, + Int, + Float, +); + +@Native<_PaintCreateInitSignature>(symbol: 'paint_create', isLeaf: true) +external PaintHandle paintCreate( + bool isAntiAlias, + int blendMode, + int color, + int style, + double strokeWidth, + int strokeCap, + int strokeJoin, + double strokeMiterLimit, +); @Native(symbol: 'paint_dispose', isLeaf: true) external void paintDispose(PaintHandle paint); -@Native(symbol: 'paint_setBlendMode', isLeaf: true) -external void paintSetBlendMode(PaintHandle paint, int blendMode); - -@Native(symbol: 'paint_setStyle', isLeaf: true) -external void paintSetStyle(PaintHandle paint, int paintStyle); - -@Native(symbol: 'paint_getStyle', isLeaf: true) -external int paintGetStyle(PaintHandle paint); - -@Native(symbol: 'paint_setStrokeWidth', isLeaf: true) -external void paintSetStrokeWidth(PaintHandle paint, double strokeWidth); - -@Native(symbol: 'paint_getStrokeWidth', isLeaf: true) -external double paintGetStrokeWidth(PaintHandle paint); - -@Native(symbol: 'paint_setStrokeCap', isLeaf: true) -external void paintSetStrokeCap(PaintHandle paint, int cap); - -@Native(symbol: 'paint_getStrokeCap', isLeaf: true) -external int paintGetStrokeCap(PaintHandle paint); - -@Native(symbol: 'paint_setStrokeJoin', isLeaf: true) -external void paintSetStrokeJoin(PaintHandle paint, int join); - -@Native(symbol: 'paint_getStrokeJoin', isLeaf: true) -external int paintGetStrokeJoin(PaintHandle paint); - -@Native(symbol: 'paint_setAntiAlias', isLeaf: true) -external void paintSetAntiAlias(PaintHandle paint, bool antiAlias); - -@Native(symbol: 'paint_getAntiAlias', isLeaf: true) -external bool paintGetAntiAlias(PaintHandle paint); - -@Native(symbol: 'paint_setColorInt', isLeaf: true) -external void paintSetColorInt(PaintHandle paint, int color); - -@Native(symbol: 'paint_getColorInt', isLeaf: true) -external int paintGetColorInt(PaintHandle paint); - -@Native(symbol: 'paint_setMiterLimit', isLeaf: true) -external void paintSetMiterLimit(PaintHandle paint, double miterLimit); - -@Native(symbol: 'paint_getMiterLimit', isLeaf: true) -external double paintGetMiterLimit(PaintHandle paint); - @Native(symbol: 'paint_setShader', isLeaf: true) external void paintSetShader(PaintHandle handle, ShaderHandle shader); diff --git a/lib/web_ui/skwasm/paint.cpp b/lib/web_ui/skwasm/paint.cpp index 8bba9a5f8a819..1c131a561553f 100644 --- a/lib/web_ui/skwasm/paint.cpp +++ b/lib/web_ui/skwasm/paint.cpp @@ -12,11 +12,23 @@ using namespace Skwasm; -SKWASM_EXPORT SkPaint* paint_create() { +SKWASM_EXPORT SkPaint* paint_create(bool isAntiAlias, + SkBlendMode blendMode, + SkColor color, + SkPaint::Style style, + SkScalar strokeWidth, + SkPaint::Cap strokeCap, + SkPaint::Join strokeJoin, + SkScalar strokeMiterLimit) { auto paint = new SkPaint(); - - // Antialias defaults to true in flutter. - paint->setAntiAlias(true); + paint->setAntiAlias(isAntiAlias); + paint->setBlendMode(blendMode); + paint->setStyle(style); + paint->setStrokeWidth(strokeWidth); + paint->setStrokeCap(strokeCap); + paint->setStrokeJoin(strokeJoin); + paint->setColor(color); + paint->setStrokeMiter(strokeMiterLimit); return paint; } @@ -24,68 +36,6 @@ SKWASM_EXPORT void paint_dispose(SkPaint* paint) { delete paint; } -SKWASM_EXPORT void paint_setBlendMode(SkPaint* paint, SkBlendMode mode) { - paint->setBlendMode(mode); -} - -// No getter for blend mode, as it's non trivial. Cache on the dart side. - -SKWASM_EXPORT void paint_setStyle(SkPaint* paint, SkPaint::Style style) { - paint->setStyle(style); -} - -SKWASM_EXPORT SkPaint::Style paint_getStyle(SkPaint* paint) { - return paint->getStyle(); -} - -SKWASM_EXPORT void paint_setStrokeWidth(SkPaint* paint, SkScalar width) { - paint->setStrokeWidth(width); -} - -SKWASM_EXPORT SkScalar paint_getStrokeWidth(SkPaint* paint) { - return paint->getStrokeWidth(); -} - -SKWASM_EXPORT void paint_setStrokeCap(SkPaint* paint, SkPaint::Cap cap) { - paint->setStrokeCap(cap); -} - -SKWASM_EXPORT SkPaint::Cap paint_getStrokeCap(SkPaint* paint) { - return paint->getStrokeCap(); -} - -SKWASM_EXPORT void paint_setStrokeJoin(SkPaint* paint, SkPaint::Join join) { - paint->setStrokeJoin(join); -} - -SKWASM_EXPORT SkPaint::Join paint_getStrokeJoin(SkPaint* paint) { - return paint->getStrokeJoin(); -} - -SKWASM_EXPORT void paint_setAntiAlias(SkPaint* paint, bool antiAlias) { - paint->setAntiAlias(antiAlias); -} - -SKWASM_EXPORT bool paint_getAntiAlias(SkPaint* paint) { - return paint->isAntiAlias(); -} - -SKWASM_EXPORT void paint_setColorInt(SkPaint* paint, SkColor colorInt) { - paint->setColor(colorInt); -} - -SKWASM_EXPORT SkColor paint_getColorInt(SkPaint* paint) { - return paint->getColor(); -} - -SKWASM_EXPORT void paint_setMiterLimit(SkPaint* paint, SkScalar miterLimit) { - paint->setStrokeMiter(miterLimit); -} - -SKWASM_EXPORT SkScalar paint_getMiterLimit(SkPaint* paint) { - return paint->getStrokeMiter(); -} - SKWASM_EXPORT void paint_setShader(SkPaint* paint, SkShader* shader) { paint->setShader(sk_ref_sp(shader)); } From 8fc5c6576d1bf4ca8f57b3ffe3410c35d8225008 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 6 Sep 2024 15:24:36 -0700 Subject: [PATCH 09/12] [multiple] Avoid new `unreachable_switch_default` warning. (#54996) The Dart analyzer will soon be changed so that if the `default` clause of a `switch` statement is determined to be unreachable by the exhaustiveness checker, a new warning of type `unreachable_switch_default` will be issued. This parallels the behavior of the existing `unreachable_switch_case` warning, which is issued whenever a `case` clause of a `switch` statement is determined to be unreachable. Before adding the new warning to the analyzer, code in the engine needs to first be updated to eliminate these unreachable `default` clauses, so that the warning won't cause builds to break. For more information, see https://github.com/dart-lang/sdk/issues/54575. --- lib/web_ui/lib/src/engine/canvaskit/color_filter.dart | 2 -- lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart | 2 -- lib/web_ui/lib/src/engine/html/bitmap_canvas.dart | 2 -- lib/web_ui/lib/src/engine/html/shaders/shader.dart | 2 -- lib/web_ui/lib/src/engine/text/paragraph.dart | 2 -- lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart | 1 - 6 files changed, 11 deletions(-) diff --git a/lib/web_ui/lib/src/engine/canvaskit/color_filter.dart b/lib/web_ui/lib/src/engine/canvaskit/color_filter.dart index dea9b30130d8f..71c4123b4581a 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/color_filter.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/color_filter.dart @@ -266,7 +266,5 @@ CkColorFilter? createCkColorFilter(EngineColorFilter colorFilter) { return const CkLinearToSrgbGammaColorFilter(); case ColorFilterType.srgbToLinearGamma: return const CkSrgbToLinearGammaColorFilter(); - default: - throw StateError('Unknown mode $colorFilter.type for ColorFilter.'); } } diff --git a/lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart b/lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart index a2d7ab4bd8ae9..a99216b763748 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart @@ -844,8 +844,6 @@ class Mutator { return matrix == typedOther.matrix; case MutatorType.opacity: return alpha == typedOther.alpha; - default: - return false; } } diff --git a/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart b/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart index 0dcd004bd557a..5d21eed1cf5dd 100644 --- a/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart +++ b/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart @@ -1337,7 +1337,6 @@ String? stringForStrokeCap(ui.StrokeCap? strokeCap) { case ui.StrokeCap.round: return 'round'; case ui.StrokeCap.square: - default: return 'square'; } } @@ -1349,7 +1348,6 @@ String stringForStrokeJoin(ui.StrokeJoin strokeJoin) { case ui.StrokeJoin.bevel: return 'bevel'; case ui.StrokeJoin.miter: - default: return 'miter'; } } diff --git a/lib/web_ui/lib/src/engine/html/shaders/shader.dart b/lib/web_ui/lib/src/engine/html/shaders/shader.dart index 826d3cace3cb0..126c14770ded3 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/shader.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/shader.dart @@ -914,7 +914,5 @@ EngineHtmlColorFilter? createHtmlColorFilter(EngineColorFilter? colorFilter) { throw UnimplementedError('ColorFilter.linearToSrgbGamma not implemented for HTML renderer'); case ColorFilterType.srgbToLinearGamma: throw UnimplementedError('ColorFilter.srgbToLinearGamma not implemented for HTML renderer.'); - default: - throw StateError('Unknown mode $colorFilter.type for ColorFilter.'); } } diff --git a/lib/web_ui/lib/src/engine/text/paragraph.dart b/lib/web_ui/lib/src/engine/text/paragraph.dart index a042c67b72788..dbb88918ddfb7 100644 --- a/lib/web_ui/lib/src/engine/text/paragraph.dart +++ b/lib/web_ui/lib/src/engine/text/paragraph.dart @@ -1118,8 +1118,6 @@ String? _decorationStyleToCssString(ui.TextDecorationStyle decorationStyle) { return 'solid'; case ui.TextDecorationStyle.wavy: return 'wavy'; - default: - return null; } } diff --git a/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart b/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart index 8a81829c3cc41..b230fcfaa4973 100644 --- a/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart +++ b/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart @@ -75,7 +75,6 @@ class TextCapitalizationConfig { case TextCapitalization.sentences: autocapitalize = 'sentences'; case TextCapitalization.none: - default: autocapitalize = 'off'; } if (domInstanceOfString(domElement, 'HTMLInputElement')) { From 2f1c8b84ec993ebf9abea90f7880e499b3d159dc Mon Sep 17 00:00:00 2001 From: skia-flutter-autoroll Date: Fri, 6 Sep 2024 18:47:24 -0400 Subject: [PATCH 10/12] Roll Skia from 4786936b4c0c to 06cd203d0607 (2 revisions) (#55014) https://skia.googlesource.com/skia.git/+log/4786936b4c0c..06cd203d0607 2024-09-06 kjlubick@google.com Move SkMSec out of public API 2024-09-06 bungeman@google.com Replace "exec_tools" with "tools" If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/skia-flutter-autoroll Please CC brianosman@google.com,codefu@google.com,jlavrova@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Skia: https://bugs.chromium.org/p/skia/issues/entry To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md --- DEPS | 2 +- ci/licenses_golden/licenses_skia | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index cf8e8da5b99c0..0fe403b3ff44a 100644 --- a/DEPS +++ b/DEPS @@ -14,7 +14,7 @@ vars = { 'flutter_git': 'https://flutter.googlesource.com', 'skia_git': 'https://skia.googlesource.com', 'llvm_git': 'https://llvm.googlesource.com', - 'skia_revision': '4786936b4c0c29fece10661592581ddce5940df0', + 'skia_revision': '06cd203d0607e1c7b3e25d9f08eb2c67c11c268c', # WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY # See `lib/web_ui/README.md` for how to roll CanvasKit to a new version. diff --git a/ci/licenses_golden/licenses_skia b/ci/licenses_golden/licenses_skia index 4a203f8028e0f..884325901afcf 100644 --- a/ci/licenses_golden/licenses_skia +++ b/ci/licenses_golden/licenses_skia @@ -1,4 +1,4 @@ -Signature: 2b06f6ab3cfdd8b8e019140092055d20 +Signature: ad383f342858989e58ceab94d1a03ae2 ==================================================================================================== LIBRARY: etc1 @@ -404,6 +404,7 @@ FILE: ../../../flutter/third_party/skia/relnotes/filter-color.md FILE: ../../../flutter/third_party/skia/relnotes/ganesh-move.md FILE: ../../../flutter/third_party/skia/relnotes/grglconfig.md FILE: ../../../flutter/third_party/skia/relnotes/macro.md +FILE: ../../../flutter/third_party/skia/relnotes/skmsec.md FILE: ../../../flutter/third_party/skia/src/gpu/gpu_workaround_list.txt FILE: ../../../flutter/third_party/skia/src/ports/fontations/Cargo.toml FILE: ../../../flutter/third_party/skia/src/sksl/generated/sksl_compute.minified.sksl From 6dbd735740df66927187422c89d379aab9db4229 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 6 Sep 2024 16:48:09 -0700 Subject: [PATCH 11/12] [engine] reland: always post tasks for platform channel responses. (#55006) Reland of https://github.com/flutter/engine/pull/54975 Fixes the initial route behavior for iOS. Previously the initial route setting would _always_ be posted as a task, which after merging the threads would fire after isolate creation, thus it would not actually update the initial route setting. Fixed Engine constructor so that it reads the initial route from the settings. --- shell/common/engine.cc | 1 + shell/common/engine_unittests.cc | 21 +++++++++++++++++++ shell/common/shell.cc | 8 +++---- .../ios/framework/Source/FlutterEngine.mm | 14 ++++++------- .../ios/framework/Source/FlutterEngineTest.mm | 14 ++++++------- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/shell/common/engine.cc b/shell/common/engine.cc index ac628eb929465..37f71f4496d87 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -61,6 +61,7 @@ Engine::Engine( task_runners_(task_runners), weak_factory_(this) { pointer_data_dispatcher_ = dispatcher_maker(*this); + initial_route_ = settings_.route; } Engine::Engine(Delegate& delegate, diff --git a/shell/common/engine_unittests.cc b/shell/common/engine_unittests.cc index 7a822c5dca1b7..8e0108eaccc03 100644 --- a/shell/common/engine_unittests.cc +++ b/shell/common/engine_unittests.cc @@ -252,6 +252,27 @@ TEST_F(EngineTest, Create) { }); } +TEST_F(EngineTest, CreateWithRoute) { + PostUITaskSync([this] { + auto settings = settings_; + settings.route = "/testo"; + auto engine = std::make_unique( + /*delegate=*/delegate_, + /*dispatcher_maker=*/dispatcher_maker_, + /*image_decoder_task_runner=*/image_decoder_task_runner_, + /*task_runners=*/task_runners_, + /*settings=*/settings, + /*animator=*/std::move(animator_), + /*io_manager=*/io_manager_, + /*font_collection=*/std::make_shared(), + /*runtime_controller=*/std::move(runtime_controller_), + /*gpu_disabled_switch=*/std::make_shared()); + + EXPECT_TRUE(engine); + EXPECT_EQ(engine->InitialRoute(), "/testo"); + }); +} + TEST_F(EngineTest, DispatchPlatformMessageUnknown) { PostUITaskSync([this] { MockRuntimeDelegate client; diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 79c532640a969..a23bc5498efe6 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -1076,10 +1076,10 @@ void Shell::OnPlatformViewDispatchPlatformMessage( // The static leak checker gets confused by the use of fml::MakeCopyable. // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) - fml::TaskRunner::RunNowOrPostTask( - task_runners_.GetUITaskRunner(), - fml::MakeCopyable([engine = engine_->GetWeakPtr(), - message = std::move(message)]() mutable { + // This logic must always explicitly post a task so that we are guaranteed + // to wake up the UI message loop to flush tasks. + task_runners_.GetUITaskRunner()->PostTask(fml::MakeCopyable( + [engine = engine_->GetWeakPtr(), message = std::move(message)]() mutable { if (engine) { engine->DispatchPlatformMessage(std::move(message)); } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index b1ca5e66ae6d1..3b65f469820a8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -602,13 +602,6 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMethodCodec sharedInstance]]); - if ([_initialRoute length] > 0) { - // Flutter isn't ready to receive this method call yet but the channel buffer will cache this. - [_navigationChannel invokeMethod:@"setInitialRoute" arguments:_initialRoute]; - [_initialRoute release]; - _initialRoute = nil; - } - _restorationChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/restoration" binaryMessenger:self.binaryMessenger @@ -904,6 +897,13 @@ - (BOOL)createShell:(NSString*)entrypoint _isGpuDisabled = [UIApplication sharedApplication].applicationState == UIApplicationStateBackground; #endif + // Override the setting route, as the dart project or function may have specified + // different values. During construction, the Engine constuctor will read the + // value of settings.route to determine the initial route value. + if (self.initialRoute) { + settings.route = [self.initialRoute UTF8String]; + self.initialRoute = nil; + } // Create the shell. This is a blocking operation. std::unique_ptr shell = flutter::Shell::Create( diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm index 5779d4b496126..3b4702269bf85 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm @@ -201,17 +201,17 @@ - (void)testRunningInitialRouteSendsNavigationMessage { // Run with an initial route. [engine runWithEntrypoint:FlutterDefaultDartEntrypoint initialRoute:@"test"]; - // Now check that an encoded method call has been made on the binary messenger to set the - // initial route to "test". + // Initial route is set directly in the shell/engine and should not send a platform + // channel message as it will arrive too late. FlutterMethodCall* setInitialRouteMethodCall = [FlutterMethodCall methodCallWithMethodName:@"setInitialRoute" arguments:@"test"]; NSData* encodedSetInitialRouteMethod = [[FlutterJSONMethodCodec sharedInstance] encodeMethodCall:setInitialRouteMethodCall]; - OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/navigation" + OCMReject([mockBinaryMessenger sendOnChannel:@"flutter/navigation" message:encodedSetInitialRouteMethod]); } -- (void)testInitialRouteSettingsSendsNavigationMessage { +- (void)testInitialRouteSettingsDoesNotSendNavigationMessage { id mockBinaryMessenger = OCMClassMock([FlutterBinaryMessengerRelay class]); auto settings = FLTDefaultSettingsForBundle(); @@ -221,13 +221,13 @@ - (void)testInitialRouteSettingsSendsNavigationMessage { [engine setBinaryMessenger:mockBinaryMessenger]; [engine run]; - // Now check that an encoded method call has been made on the binary messenger to set the - // initial route to "test". + // Initial route is set directly in the shell/engine and should not send a platform + // channel message as it will arrive too late. FlutterMethodCall* setInitialRouteMethodCall = [FlutterMethodCall methodCallWithMethodName:@"setInitialRoute" arguments:@"test"]; NSData* encodedSetInitialRouteMethod = [[FlutterJSONMethodCodec sharedInstance] encodeMethodCall:setInitialRouteMethodCall]; - OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/navigation" + OCMReject([mockBinaryMessenger sendOnChannel:@"flutter/navigation" message:encodedSetInitialRouteMethod]); } From b9f9015ff98654454c6bc24588fd0f6b46861e04 Mon Sep 17 00:00:00 2001 From: "auto-submit[bot]" <98614782+auto-submit[bot]@users.noreply.github.com> Date: Sat, 7 Sep 2024 00:19:45 +0000 Subject: [PATCH 12/12] Reverts "[skwasm] use temporary RawPaint objects (#54917)" (#55018) Reverts: flutter/engine#54917 Initiated by: jonahwilliams Reason for reverting: failing on framework -> engine roll https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20web_skwasm_tests_7_last/10571/overview Original PR Author: yjbanov Reviewed By: {eyebrowsoffire} This change reverts the following previous change: Same as https://github.com/flutter/engine/pull/54818, but for Skwasm. Addresses the `Paint` issue in https://github.com/flutter/flutter/issues/153678 in Skwasm --- .../src/engine/skwasm/skwasm_impl/canvas.dart | 156 ++++++-------- .../src/engine/skwasm/skwasm_impl/paint.dart | 204 ++++++++++-------- .../engine/skwasm/skwasm_impl/paragraph.dart | 8 +- .../skwasm/skwasm_impl/raw/raw_paint.dart | 69 ++++-- lib/web_ui/skwasm/paint.cpp | 82 +++++-- 5 files changed, 292 insertions(+), 227 deletions(-) diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart index f04e502fd75ea..e33a515d281b9 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart @@ -29,29 +29,27 @@ class SkwasmCanvas implements SceneCanvas { @override void saveLayer(ui.Rect? bounds, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); + paint as SkwasmPaint; if (bounds != null) { withStackScope((StackScope s) { - canvasSaveLayer(_handle, s.convertRectToNative(bounds), paintHandle, nullptr); + canvasSaveLayer(_handle, s.convertRectToNative(bounds), paint.handle, nullptr); }); } else { - canvasSaveLayer(_handle, nullptr, paintHandle, nullptr); + canvasSaveLayer(_handle, nullptr, paint.handle, nullptr); } - paintDispose(paintHandle); } @override void saveLayerWithFilter(ui.Rect? bounds, ui.Paint paint, ui.ImageFilter imageFilter) { final SkwasmImageFilter nativeFilter = SkwasmImageFilter.fromUiFilter(imageFilter); - final paintHandle = (paint as SkwasmPaint).toRawPaint(); + paint as SkwasmPaint; if (bounds != null) { withStackScope((StackScope s) { - canvasSaveLayer(_handle, s.convertRectToNative(bounds), paintHandle, nativeFilter.handle); + canvasSaveLayer(_handle, s.convertRectToNative(bounds), paint.handle, nativeFilter.handle); }); } else { - canvasSaveLayer(_handle, nullptr, paintHandle, nativeFilter.handle); + canvasSaveLayer(_handle, nullptr, paint.handle, nativeFilter.handle); } - paintDispose(paintHandle); } @override @@ -113,78 +111,71 @@ class SkwasmCanvas implements SceneCanvas { @override void drawLine(ui.Offset p1, ui.Offset p2, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); - canvasDrawLine(_handle, p1.dx, p1.dy, p2.dx, p2.dy, paintHandle); - paintDispose(paintHandle); + paint as SkwasmPaint; + canvasDrawLine(_handle, p1.dx, p1.dy, p2.dx, p2.dy, paint.handle); } @override void drawPaint(ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); - canvasDrawPaint(_handle, paintHandle); - paintDispose(paintHandle); + paint as SkwasmPaint; + canvasDrawPaint(_handle, paint.handle); } @override void drawRect(ui.Rect rect, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); + paint as SkwasmPaint; withStackScope((StackScope s) { canvasDrawRect( _handle, s.convertRectToNative(rect), - paintHandle + paint.handle ); }); - paintDispose(paintHandle); } @override void drawRRect(ui.RRect rrect, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); + paint as SkwasmPaint; withStackScope((StackScope s) { canvasDrawRRect( _handle, s.convertRRectToNative(rrect), - paintHandle + paint.handle ); }); - paintDispose(paintHandle); } @override void drawDRRect(ui.RRect outer, ui.RRect inner, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); + paint as SkwasmPaint; withStackScope((StackScope s) { canvasDrawDRRect( _handle, s.convertRRectToNative(outer), s.convertRRectToNative(inner), - paintHandle + paint.handle ); }); - paintDispose(paintHandle); } @override void drawOval(ui.Rect rect, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); + paint as SkwasmPaint; withStackScope((StackScope s) { - canvasDrawOval(_handle, s.convertRectToNative(rect), paintHandle); + canvasDrawOval(_handle, s.convertRectToNative(rect), paint.handle); }); - paintDispose(paintHandle); } @override void drawCircle(ui.Offset center, double radius, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); - canvasDrawCircle(_handle, center.dx, center.dy, radius, paintHandle); - paintDispose(paintHandle); + paint as SkwasmPaint; + canvasDrawCircle(_handle, center.dx, center.dy, radius, paint.handle); } @override void drawArc(ui.Rect rect, double startAngle, double sweepAngle, bool useCenter, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); + paint as SkwasmPaint; withStackScope((StackScope s) { canvasDrawArc( _handle, @@ -192,79 +183,64 @@ class SkwasmCanvas implements SceneCanvas { ui.toDegrees(startAngle), ui.toDegrees(sweepAngle), useCenter, - paintHandle, + paint.handle ); }); - paintDispose(paintHandle); } @override void drawPath(ui.Path path, ui.Paint paint) { + paint as SkwasmPaint; path as SkwasmPath; - final paintHandle = (paint as SkwasmPaint).toRawPaint(); - canvasDrawPath(_handle, path.handle, paintHandle); - paintDispose(paintHandle); + canvasDrawPath(_handle, path.handle, paint.handle); } @override - void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); + void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) => canvasDrawImage( _handle, (image as SkwasmImage).handle, offset.dx, offset.dy, - paintHandle, + (paint as SkwasmPaint).handle, paint.filterQuality.index, ); - paintDispose(paintHandle); - } @override void drawImageRect( ui.Image image, ui.Rect src, ui.Rect dst, - ui.Paint paint, - ) { - withStackScope((StackScope scope) { - final Pointer sourceRect = scope.convertRectToNative(src); - final Pointer destRect = scope.convertRectToNative(dst); - final paintHandle = (paint as SkwasmPaint).toRawPaint(); - canvasDrawImageRect( - _handle, - (image as SkwasmImage).handle, - sourceRect, - destRect, - paintHandle, - paint.filterQuality.index, - ); - paintDispose(paintHandle); - }); - } + ui.Paint paint) => withStackScope((StackScope scope) { + final Pointer sourceRect = scope.convertRectToNative(src); + final Pointer destRect = scope.convertRectToNative(dst); + canvasDrawImageRect( + _handle, + (image as SkwasmImage).handle, + sourceRect, + destRect, + (paint as SkwasmPaint).handle, + paint.filterQuality.index, + ); + }); @override void drawImageNine( ui.Image image, ui.Rect center, ui.Rect dst, - ui.Paint paint, - ) { - withStackScope((StackScope scope) { - final Pointer centerRect = scope.convertIRectToNative(center); - final Pointer destRect = scope.convertRectToNative(dst); - final paintHandle = (paint as SkwasmPaint).toRawPaint(); - canvasDrawImageNine( - _handle, - (image as SkwasmImage).handle, - centerRect, - destRect, - paintHandle, - paint.filterQuality.index, - ); - paintDispose(paintHandle); - }); - } + ui.Paint paint) => withStackScope((StackScope scope) { + final Pointer centerRect = scope.convertIRectToNative(center); + final Pointer destRect = scope.convertRectToNative(dst); + canvasDrawImageNine( + _handle, + (image as SkwasmImage).handle, + centerRect, + destRect, + (paint as SkwasmPaint).handle, + paint.filterQuality.index, + ); + }); @override void drawPicture(ui.Picture picture) { @@ -288,15 +264,13 @@ class SkwasmCanvas implements SceneCanvas { ui.Paint paint ) => withStackScope((StackScope scope) { final RawPointArray rawPoints = scope.convertPointArrayToNative(points); - final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawPoints( _handle, pointMode.index, rawPoints, points.length, - paintHandle, + (paint as SkwasmPaint).handle, ); - paintDispose(paintHandle); }); @override @@ -306,15 +280,13 @@ class SkwasmCanvas implements SceneCanvas { ui.Paint paint ) => withStackScope((StackScope scope) { final RawPointArray rawPoints = scope.convertDoublesToNative(points); - final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawPoints( _handle, pointMode.index, rawPoints, points.length ~/ 2, - paintHandle, + (paint as SkwasmPaint).handle, ); - paintDispose(paintHandle); }); @override @@ -322,16 +294,12 @@ class SkwasmCanvas implements SceneCanvas { ui.Vertices vertices, ui.BlendMode blendMode, ui.Paint paint, - ) { - final paintHandle = (paint as SkwasmPaint).toRawPaint(); - canvasDrawVertices( - _handle, - (vertices as SkwasmVertices).handle, - blendMode.index, - paintHandle, - ); - paintDispose(paintHandle); - } + ) => canvasDrawVertices( + _handle, + (vertices as SkwasmVertices).handle, + blendMode.index, + (paint as SkwasmPaint).handle, + ); @override void drawAtlas( @@ -351,7 +319,6 @@ class SkwasmCanvas implements SceneCanvas { final RawRect rawCullRect = cullRect != null ? scope.convertRectToNative(cullRect) : nullptr; - final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawAtlas( _handle, (atlas as SkwasmImage).handle, @@ -361,9 +328,8 @@ class SkwasmCanvas implements SceneCanvas { transforms.length, (blendMode ?? ui.BlendMode.src).index, rawCullRect, - paintHandle, + (paint as SkwasmPaint).handle, ); - paintDispose(paintHandle); }); @override @@ -384,7 +350,6 @@ class SkwasmCanvas implements SceneCanvas { final RawRect rawCullRect = cullRect != null ? scope.convertRectToNative(cullRect) : nullptr; - final paintHandle = (paint as SkwasmPaint).toRawPaint(); canvasDrawAtlas( _handle, (atlas as SkwasmImage).handle, @@ -394,9 +359,8 @@ class SkwasmCanvas implements SceneCanvas { rstTransforms.length ~/ 4, (blendMode ?? ui.BlendMode.src).index, rawCullRect, - paintHandle, + (paint as SkwasmPaint).handle, ); - paintDispose(paintHandle); }); @override diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart index 0abe010e5e69a..507bf94c63ca6 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart @@ -8,73 +8,31 @@ import 'package:ui/src/engine.dart'; import 'package:ui/src/engine/skwasm/skwasm_impl.dart'; import 'package:ui/ui.dart' as ui; -class SkwasmPaint implements ui.Paint { - SkwasmPaint(); - - /// Creates the C++ side paint object based on the current state of this - /// paint object, and returns it with ownership. - /// - /// It is the responsibility of the caller to dispose of the returned handle - /// when it's no longer needed. - PaintHandle toRawPaint() { - final rawPaint = paintCreate( - isAntiAlias, - blendMode.index, - _colorValue, - style.index, - strokeWidth, - strokeCap.index, - strokeJoin.index, - strokeMiterLimit, - ); - - _maybeSetEffectiveColorFilter(rawPaint); - - final shaderHandle = _shader?.handle; - if (shaderHandle != null) { - paintSetShader(rawPaint, shaderHandle); - } +class SkwasmPaint extends SkwasmObjectWrapper implements ui.Paint { + SkwasmPaint() : super(paintCreate(), _registry); - final localMaskFilter = maskFilter; - if (localMaskFilter != null) { - final nativeFilter = SkwasmMaskFilter.fromUiMaskFilter(localMaskFilter); - paintSetMaskFilter(rawPaint, nativeFilter.handle); - nativeFilter.dispose(); - } + // Must be kept in sync with the default in paint.cc. + static const double _kStrokeMiterLimitDefault = 4.0; - final filter = imageFilter; - if (filter != null) { - final nativeImageFilter = SkwasmImageFilter.fromUiFilter(filter); - paintSetImageFilter(rawPaint, nativeImageFilter.handle); - nativeImageFilter.dispose(); - } + // Must be kept in sync with the default in paint.cc. + static const int _kColorDefault = 0xFF000000; - return rawPaint; - } + // Must be kept in sync with the default in paint.cc. + static final int _kBlendModeDefault = ui.BlendMode.srcOver.index; - /// If `invertColors` is true or `colorFilter` is not null, sets the - /// appropriate Skia color filter. Otherwise, does nothing. - void _maybeSetEffectiveColorFilter(Pointer handle) { - final nativeFilter = _colorFilter != null - ? SkwasmColorFilter.fromEngineColorFilter(_colorFilter!) - : null; - if (invertColors) { - if (nativeFilter != null) { - final composedFilter = SkwasmColorFilter.composed( - _invertColorFilter, - nativeFilter, - ); - nativeFilter.dispose(); - paintSetColorFilter(handle, composedFilter.handle); - composedFilter.dispose(); - } else { - paintSetColorFilter(handle, _invertColorFilter.handle); - } - } else if (nativeFilter != null) { - paintSetColorFilter(handle, nativeFilter.handle); - nativeFilter.dispose(); - } - } + static final SkwasmFinalizationRegistry _registry = + SkwasmFinalizationRegistry(paintDispose); + + ui.BlendMode _cachedBlendMode = ui.BlendMode.srcOver; + + SkwasmShader? _shader; + ui.ImageFilter? _imageFilter; + + EngineColorFilter? _colorFilter; + + ui.MaskFilter? _maskFilter; + + bool _invertColors = false; static final SkwasmColorFilter _invertColorFilter = SkwasmColorFilter.fromEngineColorFilter( const EngineColorFilter.matrix([ @@ -86,71 +44,143 @@ class SkwasmPaint implements ui.Paint { ); @override - ui.BlendMode blendMode = _kBlendModeDefault; + ui.BlendMode get blendMode { + return _cachedBlendMode; + } - // Must be kept in sync with the default in paint.cc. - static const ui.BlendMode _kBlendModeDefault = ui.BlendMode.srcOver; + @override + set blendMode(ui.BlendMode blendMode) { + if (_cachedBlendMode != blendMode) { + _cachedBlendMode = blendMode; + paintSetBlendMode(handle, blendMode.index); + } + } @override - ui.PaintingStyle style = ui.PaintingStyle.fill; + ui.PaintingStyle get style => ui.PaintingStyle.values[paintGetStyle(handle)]; @override - double strokeWidth = 0.0; + set style(ui.PaintingStyle style) => paintSetStyle(handle, style.index); @override - ui.StrokeCap strokeCap = ui.StrokeCap.butt; + double get strokeWidth => paintGetStrokeWidth(handle); @override - ui.StrokeJoin strokeJoin = ui.StrokeJoin.miter; + set strokeWidth(double width) => paintSetStrokeWidth(handle, width); @override - bool isAntiAlias = true; + ui.StrokeCap get strokeCap => ui.StrokeCap.values[paintGetStrokeCap(handle)]; @override - ui.Color get color => ui.Color(_colorValue); + set strokeCap(ui.StrokeCap cap) => paintSetStrokeCap(handle, cap.index); + @override - set color(ui.Color value) { - _colorValue = value.value; - } + ui.StrokeJoin get strokeJoin => ui.StrokeJoin.values[paintGetStrokeJoin(handle)]; - static const int _kColorDefault = 0xFF000000; - int _colorValue = _kColorDefault; + @override + set strokeJoin(ui.StrokeJoin join) => paintSetStrokeJoin(handle, join.index); @override - double strokeMiterLimit = _kStrokeMiterLimitDefault; - static const double _kStrokeMiterLimitDefault = 4.0; + bool get isAntiAlias => paintGetAntiAlias(handle); + + @override + set isAntiAlias(bool value) => paintSetAntiAlias(handle, value); + + @override + ui.Color get color => ui.Color(paintGetColorInt(handle)); + + @override + set color(ui.Color color) => paintSetColorInt(handle, color.value); + + @override + double get strokeMiterLimit => paintGetMiterLimit(handle); + + @override + set strokeMiterLimit(double limit) => paintSetMiterLimit(handle, limit); @override ui.Shader? get shader => _shader; @override set shader(ui.Shader? uiShader) { - uiShader as SkwasmShader?; - _shader = uiShader; + final SkwasmShader? skwasmShader = uiShader as SkwasmShader?; + _shader = skwasmShader; + final ShaderHandle shaderHandle = + skwasmShader != null ? skwasmShader.handle : nullptr; + paintSetShader(handle, shaderHandle); } - SkwasmShader? _shader; @override ui.FilterQuality filterQuality = ui.FilterQuality.none; @override - ui.ImageFilter? imageFilter; + ui.ImageFilter? get imageFilter => _imageFilter; + + @override + set imageFilter(ui.ImageFilter? filter) { + _imageFilter = filter; + + final SkwasmImageFilter? nativeImageFilter = filter != null + ? SkwasmImageFilter.fromUiFilter(filter) + : null; + paintSetImageFilter(handle, nativeImageFilter != null ? nativeImageFilter.handle : nullptr); + } @override ui.ColorFilter? get colorFilter => _colorFilter; + void _setEffectiveColorFilter() { + final SkwasmColorFilter? nativeFilter = _colorFilter != null + ? SkwasmColorFilter.fromEngineColorFilter(_colorFilter!) : null; + if (_invertColors) { + if (nativeFilter != null) { + final SkwasmColorFilter composedFilter = SkwasmColorFilter.composed(_invertColorFilter, nativeFilter); + nativeFilter.dispose(); + paintSetColorFilter(handle, composedFilter.handle); + composedFilter.dispose(); + } else { + paintSetColorFilter(handle, _invertColorFilter.handle); + } + } else if (nativeFilter != null) { + paintSetColorFilter(handle, nativeFilter.handle); + nativeFilter.dispose(); + } else { + paintSetColorFilter(handle, nullptr); + } + } + @override set colorFilter(ui.ColorFilter? filter) { _colorFilter = filter as EngineColorFilter?; + _setEffectiveColorFilter(); } - EngineColorFilter? _colorFilter; + @override + ui.MaskFilter? get maskFilter => _maskFilter; @override - ui.MaskFilter? maskFilter; + set maskFilter(ui.MaskFilter? filter) { + _maskFilter = filter; + if (filter == null) { + paintSetMaskFilter(handle, nullptr); + } else { + final SkwasmMaskFilter nativeFilter = SkwasmMaskFilter.fromUiMaskFilter(filter); + paintSetMaskFilter(handle, nativeFilter.handle); + nativeFilter.dispose(); + } + } @override - bool invertColors = false; + bool get invertColors => _invertColors; + + @override + set invertColors(bool invertColors) { + if (_invertColors == invertColors) { + return; + } + _invertColors = invertColors; + _setEffectiveColorFilter(); + } @override String toString() { @@ -187,7 +217,7 @@ class SkwasmPaint implements ui.Paint { result.write('$semicolon$color'); semicolon = '; '; } - if (blendMode.index != _kBlendModeDefault.index) { + if (blendMode.index != _kBlendModeDefault) { result.write('$semicolon$blendMode'); semicolon = '; '; } diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart index 88cb9fdc54096..98dad74623e9f 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart @@ -398,14 +398,10 @@ class SkwasmTextStyle implements ui.TextStyle { skStringFree(localeHandle); } if (background != null) { - final backgroundPaint = (background! as SkwasmPaint).toRawPaint(); - textStyleSetBackground(handle, backgroundPaint); - paintDispose(backgroundPaint); + textStyleSetBackground(handle, (background! as SkwasmPaint).handle); } if (foreground != null) { - final foregroundPaint = (foreground! as SkwasmPaint).toRawPaint(); - textStyleSetForeground(handle, foregroundPaint); - paintDispose(foregroundPaint); + textStyleSetForeground(handle, (foreground! as SkwasmPaint).handle); } if (shadows != null) { for (final ui.Shadow shadow in shadows!) { diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_paint.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_paint.dart index b74f14aff13ac..307e6968d517a 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_paint.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_paint.dart @@ -13,32 +13,57 @@ final class RawPaint extends Opaque {} typedef PaintHandle = Pointer; -typedef _PaintCreateInitSignature = PaintHandle Function( - Bool, - Int, - Int, - Int, - Float, - Int, - Int, - Float, -); - -@Native<_PaintCreateInitSignature>(symbol: 'paint_create', isLeaf: true) -external PaintHandle paintCreate( - bool isAntiAlias, - int blendMode, - int color, - int style, - double strokeWidth, - int strokeCap, - int strokeJoin, - double strokeMiterLimit, -); +@Native(symbol: 'paint_create', isLeaf: true) +external PaintHandle paintCreate(); @Native(symbol: 'paint_dispose', isLeaf: true) external void paintDispose(PaintHandle paint); +@Native(symbol: 'paint_setBlendMode', isLeaf: true) +external void paintSetBlendMode(PaintHandle paint, int blendMode); + +@Native(symbol: 'paint_setStyle', isLeaf: true) +external void paintSetStyle(PaintHandle paint, int paintStyle); + +@Native(symbol: 'paint_getStyle', isLeaf: true) +external int paintGetStyle(PaintHandle paint); + +@Native(symbol: 'paint_setStrokeWidth', isLeaf: true) +external void paintSetStrokeWidth(PaintHandle paint, double strokeWidth); + +@Native(symbol: 'paint_getStrokeWidth', isLeaf: true) +external double paintGetStrokeWidth(PaintHandle paint); + +@Native(symbol: 'paint_setStrokeCap', isLeaf: true) +external void paintSetStrokeCap(PaintHandle paint, int cap); + +@Native(symbol: 'paint_getStrokeCap', isLeaf: true) +external int paintGetStrokeCap(PaintHandle paint); + +@Native(symbol: 'paint_setStrokeJoin', isLeaf: true) +external void paintSetStrokeJoin(PaintHandle paint, int join); + +@Native(symbol: 'paint_getStrokeJoin', isLeaf: true) +external int paintGetStrokeJoin(PaintHandle paint); + +@Native(symbol: 'paint_setAntiAlias', isLeaf: true) +external void paintSetAntiAlias(PaintHandle paint, bool antiAlias); + +@Native(symbol: 'paint_getAntiAlias', isLeaf: true) +external bool paintGetAntiAlias(PaintHandle paint); + +@Native(symbol: 'paint_setColorInt', isLeaf: true) +external void paintSetColorInt(PaintHandle paint, int color); + +@Native(symbol: 'paint_getColorInt', isLeaf: true) +external int paintGetColorInt(PaintHandle paint); + +@Native(symbol: 'paint_setMiterLimit', isLeaf: true) +external void paintSetMiterLimit(PaintHandle paint, double miterLimit); + +@Native(symbol: 'paint_getMiterLimit', isLeaf: true) +external double paintGetMiterLimit(PaintHandle paint); + @Native(symbol: 'paint_setShader', isLeaf: true) external void paintSetShader(PaintHandle handle, ShaderHandle shader); diff --git a/lib/web_ui/skwasm/paint.cpp b/lib/web_ui/skwasm/paint.cpp index 1c131a561553f..8bba9a5f8a819 100644 --- a/lib/web_ui/skwasm/paint.cpp +++ b/lib/web_ui/skwasm/paint.cpp @@ -12,23 +12,11 @@ using namespace Skwasm; -SKWASM_EXPORT SkPaint* paint_create(bool isAntiAlias, - SkBlendMode blendMode, - SkColor color, - SkPaint::Style style, - SkScalar strokeWidth, - SkPaint::Cap strokeCap, - SkPaint::Join strokeJoin, - SkScalar strokeMiterLimit) { +SKWASM_EXPORT SkPaint* paint_create() { auto paint = new SkPaint(); - paint->setAntiAlias(isAntiAlias); - paint->setBlendMode(blendMode); - paint->setStyle(style); - paint->setStrokeWidth(strokeWidth); - paint->setStrokeCap(strokeCap); - paint->setStrokeJoin(strokeJoin); - paint->setColor(color); - paint->setStrokeMiter(strokeMiterLimit); + + // Antialias defaults to true in flutter. + paint->setAntiAlias(true); return paint; } @@ -36,6 +24,68 @@ SKWASM_EXPORT void paint_dispose(SkPaint* paint) { delete paint; } +SKWASM_EXPORT void paint_setBlendMode(SkPaint* paint, SkBlendMode mode) { + paint->setBlendMode(mode); +} + +// No getter for blend mode, as it's non trivial. Cache on the dart side. + +SKWASM_EXPORT void paint_setStyle(SkPaint* paint, SkPaint::Style style) { + paint->setStyle(style); +} + +SKWASM_EXPORT SkPaint::Style paint_getStyle(SkPaint* paint) { + return paint->getStyle(); +} + +SKWASM_EXPORT void paint_setStrokeWidth(SkPaint* paint, SkScalar width) { + paint->setStrokeWidth(width); +} + +SKWASM_EXPORT SkScalar paint_getStrokeWidth(SkPaint* paint) { + return paint->getStrokeWidth(); +} + +SKWASM_EXPORT void paint_setStrokeCap(SkPaint* paint, SkPaint::Cap cap) { + paint->setStrokeCap(cap); +} + +SKWASM_EXPORT SkPaint::Cap paint_getStrokeCap(SkPaint* paint) { + return paint->getStrokeCap(); +} + +SKWASM_EXPORT void paint_setStrokeJoin(SkPaint* paint, SkPaint::Join join) { + paint->setStrokeJoin(join); +} + +SKWASM_EXPORT SkPaint::Join paint_getStrokeJoin(SkPaint* paint) { + return paint->getStrokeJoin(); +} + +SKWASM_EXPORT void paint_setAntiAlias(SkPaint* paint, bool antiAlias) { + paint->setAntiAlias(antiAlias); +} + +SKWASM_EXPORT bool paint_getAntiAlias(SkPaint* paint) { + return paint->isAntiAlias(); +} + +SKWASM_EXPORT void paint_setColorInt(SkPaint* paint, SkColor colorInt) { + paint->setColor(colorInt); +} + +SKWASM_EXPORT SkColor paint_getColorInt(SkPaint* paint) { + return paint->getColor(); +} + +SKWASM_EXPORT void paint_setMiterLimit(SkPaint* paint, SkScalar miterLimit) { + paint->setStrokeMiter(miterLimit); +} + +SKWASM_EXPORT SkScalar paint_getMiterLimit(SkPaint* paint) { + return paint->getStrokeMiter(); +} + SKWASM_EXPORT void paint_setShader(SkPaint* paint, SkShader* shader) { paint->setShader(sk_ref_sp(shader)); }