diff options
Diffstat (limited to 'chromium/ui/compositor')
-rw-r--r-- | chromium/ui/compositor/BUILD.gn | 12 | ||||
-rw-r--r-- | chromium/ui/compositor/compositor.cc | 17 | ||||
-rw-r--r-- | chromium/ui/compositor/compositor.h | 12 | ||||
-rw-r--r-- | chromium/ui/compositor/layer.cc | 6 | ||||
-rw-r--r-- | chromium/ui/compositor/layer.h | 4 | ||||
-rw-r--r-- | chromium/ui/compositor/layer_animation_delegate.h | 2 | ||||
-rw-r--r-- | chromium/ui/compositor/layer_animation_element.cc | 18 | ||||
-rw-r--r-- | chromium/ui/compositor/layer_animation_element.h | 3 | ||||
-rw-r--r-- | chromium/ui/compositor/layer_animation_element_unittest.cc | 4 | ||||
-rw-r--r-- | chromium/ui/compositor/layer_animator.cc | 6 | ||||
-rw-r--r-- | chromium/ui/compositor/layer_animator_collection.cc | 4 | ||||
-rw-r--r-- | chromium/ui/compositor/layer_owner.cc | 5 | ||||
-rw-r--r-- | chromium/ui/compositor/layer_unittest.cc | 8 | ||||
-rw-r--r-- | chromium/ui/compositor/recyclable_compositor_mac.cc | 79 | ||||
-rw-r--r-- | chromium/ui/compositor/recyclable_compositor_mac.h | 34 |
15 files changed, 54 insertions, 160 deletions
diff --git a/chromium/ui/compositor/BUILD.gn b/chromium/ui/compositor/BUILD.gn index f102584d789..6f43d267163 100644 --- a/chromium/ui/compositor/BUILD.gn +++ b/chromium/ui/compositor/BUILD.gn @@ -266,12 +266,14 @@ test("compositor_unittests") { } if (is_fuchsia) { - use_cfv2 = false - additional_manifest_fragments = [ - # TODO(crbug.com/1185811): Figure out why jit_capabilities is needed. - "//build/config/fuchsia/test/jit_capabilities.test-cmx", + use_cfv1 = false - "//build/config/fuchsia/test/present_view_capabilities.test-cmx", + # TODO(https://crbug.com/1185811): Investigate removing the requirement for + # job_policy_ambient_mark_vmo_exec for the sake of V8's allocator in tests. + test_runner_shard = "//build/config/fuchsia/test/elf_test_ambient_exec_runner.shard.test-cml" + additional_manifest_fragments = [ + "//build/config/fuchsia/test/present_view.shard.test-cml", + "//third_party/fuchsia-sdk/sdk/pkg/vulkan/client.shard.cml", ] } } diff --git a/chromium/ui/compositor/compositor.cc b/chromium/ui/compositor/compositor.cc index 39771c38101..9bb69f75642 100644 --- a/chromium/ui/compositor/compositor.cc +++ b/chromium/ui/compositor/compositor.cc @@ -455,14 +455,6 @@ void Compositor::SetScaleAndSize(float scale, bool device_scale_factor_changed = device_scale_factor_ != scale; device_scale_factor_ = scale; -#if DCHECK_IS_ON() - if (size_ != size_in_pixel && local_surface_id.is_valid()) { - // A new LocalSurfaceId must be set when the compositor size changes. - DCHECK_NE(local_surface_id, host_->local_surface_id_from_parent()); - DCHECK_NE(local_surface_id, host_->local_surface_id_from_parent()); - } -#endif // DECHECK_IS_ON() - // cc requires the size to be non-empty (meaning DCHECKs if size is empty). if (!size_in_pixel.IsEmpty()) { bool size_changed = size_ != size_in_pixel; @@ -508,7 +500,8 @@ void Compositor::SetDisplayTransformHint(gfx::OverlayTransform hint) { } void Compositor::SetBackgroundColor(SkColor color) { - host_->set_background_color(color); + // TODO(crbug/1308932): Remove FromColor and make all SkColor4f. + host_->set_background_color(SkColor4f::FromColor(color)); ScheduleDraw(); } @@ -665,8 +658,8 @@ ThroughputTracker Compositor::RequestNewThroughputTracker() { weak_ptr_factory_.GetWeakPtr()); } -uint32_t Compositor::GetAverageThroughput() const { - return host_->GetAverageThroughput(); +double Compositor::GetPercentDroppedFrames() const { + return host_->GetPercentDroppedFrames(); } std::unique_ptr<cc::EventsMetricsManager::ScopedMonitor> @@ -736,7 +729,7 @@ void Compositor::DidCommit(base::TimeTicks, base::TimeTicks) { std::unique_ptr<cc::BeginMainFrameMetrics> Compositor::GetBeginMainFrameMetrics() { -#if BUILDFLAG(IS_CHROMEOS_ASH) +#if BUILDFLAG(IS_CHROMEOS) auto metrics_data = std::make_unique<cc::BeginMainFrameMetrics>(); metrics_data->should_measure_smoothness = true; return metrics_data; diff --git a/chromium/ui/compositor/compositor.h b/chromium/ui/compositor/compositor.h index 2f6d2ee4160..5dee5932ce9 100644 --- a/chromium/ui/compositor/compositor.h +++ b/chromium/ui/compositor/compositor.h @@ -337,8 +337,8 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver, // Creates a ThroughputTracker for tracking this Compositor. ThroughputTracker RequestNewThroughputTracker(); - // Returns a percentage representing average throughput of last X seconds. - uint32_t GetAverageThroughput() const; + // Returns a percentage of dropped frames of the last second. + double GetPercentDroppedFrames() const; // Activates a scoped monitor for the current event to track its metrics. // `done_callback` is called when the monitor goes out of scope. @@ -350,7 +350,10 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver, void WillBeginMainFrame() override {} void DidBeginMainFrame() override {} void OnDeferMainFrameUpdatesChanged(bool) override {} - void OnDeferCommitsChanged(bool, cc::PaintHoldingReason) override {} + void OnDeferCommitsChanged( + bool, + cc::PaintHoldingReason, + absl::optional<cc::PaintHoldingCommitTrigger>) override {} void WillUpdateLayers() override {} void DidUpdateLayers() override; void BeginMainFrame(const viz::BeginFrameArgs& args) override; @@ -472,7 +475,8 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver, // // These pointers are owned by |context_factory_|, and must be reset before // calling RemoveCompositor(); - raw_ptr<viz::mojom::DisplayPrivate> display_private_ = nullptr; + raw_ptr<viz::mojom::DisplayPrivate, DanglingUntriaged> display_private_ = + nullptr; raw_ptr<viz::mojom::ExternalBeginFrameController> external_begin_frame_controller_ = nullptr; diff --git a/chromium/ui/compositor/layer.cc b/chromium/ui/compositor/layer.cc index 7b5519ceade..b582922a2d2 100644 --- a/chromium/ui/compositor/layer.cc +++ b/chromium/ui/compositor/layer.cc @@ -1095,10 +1095,6 @@ void Layer::UpdateNinePatchLayerImage(const gfx::ImageSkia& image) { DCHECK(nine_patch_layer_.get()); nine_patch_layer_image_ = image; - // TODO(estade): we don't clean up old bitmaps in the UIResourceManager when - // the scale factor changes. Currently for the way NinePatchLayers are used, - // we don't need/want to, but we should address this in the future if it - // becomes an issue. nine_patch_layer_->SetBitmap( image.GetRepresentation(device_scale_factor_).GetBitmap()); } @@ -1600,7 +1596,7 @@ gfx::RoundedCornersF Layer::GetRoundedCornersForAnimation() const { return rounded_corner_radii(); } -gfx::LinearGradient Layer::GetGradientMaskForAnimation() const { +const gfx::LinearGradient& Layer::GetGradientMaskForAnimation() const { return gradient_mask(); } diff --git a/chromium/ui/compositor/layer.h b/chromium/ui/compositor/layer.h index c0cd7072cf2..3ea74c830f5 100644 --- a/chromium/ui/compositor/layer.h +++ b/chromium/ui/compositor/layer.h @@ -328,7 +328,7 @@ class COMPOSITOR_EXPORT Layer : public LayerAnimationDelegate, // Gets/sets a gradient mask that is applied to the clip bounds on the layer void SetGradientMask(const gfx::LinearGradient& linear_gradient); - const gfx::LinearGradient gradient_mask() const { + const gfx::LinearGradient& gradient_mask() const { return cc_layer_->gradient_mask(); } @@ -601,7 +601,7 @@ class COMPOSITOR_EXPORT Layer : public LayerAnimationDelegate, SkColor GetColorForAnimation() const override; gfx::Rect GetClipRectForAnimation() const override; gfx::RoundedCornersF GetRoundedCornersForAnimation() const override; - gfx::LinearGradient GetGradientMaskForAnimation() const override; + const gfx::LinearGradient& GetGradientMaskForAnimation() const override; float GetDeviceScaleFactor() const override; Layer* GetLayer() override; cc::Layer* GetCcLayer() const override; diff --git a/chromium/ui/compositor/layer_animation_delegate.h b/chromium/ui/compositor/layer_animation_delegate.h index 79088f31ab1..1107a595609 100644 --- a/chromium/ui/compositor/layer_animation_delegate.h +++ b/chromium/ui/compositor/layer_animation_delegate.h @@ -59,7 +59,7 @@ class COMPOSITOR_EXPORT LayerAnimationDelegate { virtual SkColor GetColorForAnimation() const = 0; virtual gfx::Rect GetClipRectForAnimation() const = 0; virtual gfx::RoundedCornersF GetRoundedCornersForAnimation() const = 0; - virtual gfx::LinearGradient GetGradientMaskForAnimation() const = 0; + virtual const gfx::LinearGradient& GetGradientMaskForAnimation() const = 0; virtual float GetDeviceScaleFactor() const = 0; virtual ui::Layer* GetLayer() = 0; virtual cc::Layer* GetCcLayer() const = 0; diff --git a/chromium/ui/compositor/layer_animation_element.cc b/chromium/ui/compositor/layer_animation_element.cc index 1b070f923f5..82bfcc56ba5 100644 --- a/chromium/ui/compositor/layer_animation_element.cc +++ b/chromium/ui/compositor/layer_animation_element.cc @@ -385,10 +385,10 @@ class GradientMaskTransition : public LayerAnimationElement { DCHECK_EQ(start_.step_count(), target_.step_count()); for (auto i = 0; i < static_cast<int>(start_.step_count()); ++i) { gradient_mask.AddStep( - gfx::Tween::FloatValueBetween(t, start_.steps()[i].percent, - target_.steps()[i].percent), + gfx::Tween::FloatValueBetween(t, start_.steps()[i].fraction, + target_.steps()[i].fraction), gfx::Tween::IntValueBetween(t, start_.steps()[i].alpha, - target_.steps()[i].alpha)); + target_.steps()[i].alpha)); } delegate->SetGradientMaskFromAnimation( @@ -404,7 +404,7 @@ class GradientMaskTransition : public LayerAnimationElement { private: gfx::LinearGradient start_; - gfx::LinearGradient target_; + const gfx::LinearGradient target_; }; // ThreadedLayerAnimationElement ----------------------------------------------- @@ -521,6 +521,9 @@ class ThreadedOpacityTransition : public ThreadedLayerAnimationElement { } std::unique_ptr<cc::KeyframeModel> CreateCCKeyframeModel() override { + // Ensures that we don't remove and add a model with the same id in a single + // frame. + UpdateKeyframeModelId(); std::unique_ptr<gfx::AnimationCurve> animation_curve( new FloatAnimationCurveAdapter(tween_type(), start_, target_, duration())); @@ -594,6 +597,9 @@ class ThreadedTransformTransition : public ThreadedLayerAnimationElement { } std::unique_ptr<cc::KeyframeModel> CreateCCKeyframeModel() override { + // Ensures that we don't remove and add a model with the same id in a single + // frame. + UpdateKeyframeModelId(); std::unique_ptr<gfx::AnimationCurve> animation_curve( new TransformAnimationCurveAdapter(tween_type(), start_, target_, duration())); @@ -766,6 +772,10 @@ std::string LayerAnimationElement::ToString() const { last_progressed_fraction_); } +void LayerAnimationElement::UpdateKeyframeModelId() { + keyframe_model_id_ = cc::AnimationIdProvider::NextKeyframeModelId(); +} + std::string LayerAnimationElement::DebugName() const { return "Default"; } diff --git a/chromium/ui/compositor/layer_animation_element.h b/chromium/ui/compositor/layer_animation_element.h index afded4a7863..3008bbec2bd 100644 --- a/chromium/ui/compositor/layer_animation_element.h +++ b/chromium/ui/compositor/layer_animation_element.h @@ -229,6 +229,7 @@ class COMPOSITOR_EXPORT LayerAnimationElement { std::string ToString() const; protected: + void UpdateKeyframeModelId(); virtual std::string DebugName() const; // Called once each time the animation element is run before any call to @@ -258,7 +259,7 @@ class COMPOSITOR_EXPORT LayerAnimationElement { const base::TimeDelta duration_; gfx::Tween::Type tween_type_; - const int keyframe_model_id_; + int keyframe_model_id_; int animation_group_id_; double last_progressed_fraction_; diff --git a/chromium/ui/compositor/layer_animation_element_unittest.cc b/chromium/ui/compositor/layer_animation_element_unittest.cc index c412c9ee57d..3d1fe60c24f 100644 --- a/chromium/ui/compositor/layer_animation_element_unittest.cc +++ b/chromium/ui/compositor/layer_animation_element_unittest.cc @@ -475,9 +475,9 @@ TEST(LayerAnimationElementTest, GradientMaskElement) { gfx::LinearGradient start(45); start.AddStep(0, 0); gfx::LinearGradient target(135); - target.AddStep(50, 255); + target.AddStep(.5, 255); gfx::LinearGradient middle(90); - middle.AddStep(25, 127); + middle.AddStep(.25, 127); base::TimeTicks start_time; base::TimeDelta delta = base::Seconds(1); diff --git a/chromium/ui/compositor/layer_animator.cc b/chromium/ui/compositor/layer_animator.cc index 19dc007026a..84c614d0fa1 100644 --- a/chromium/ui/compositor/layer_animator.cc +++ b/chromium/ui/compositor/layer_animator.cc @@ -289,7 +289,8 @@ void LayerAnimator::StartTogether( bool wait_for_group_start = false; for (iter = animations.begin(); iter != animations.end(); ++iter) - wait_for_group_start |= (*iter)->IsFirstElementThreaded(delegate_); + wait_for_group_start |= + delegate_ && (*iter)->IsFirstElementThreaded(delegate_); int group_id = cc::AnimationIdProvider::NextGroupId(); // These animations (provided they don't animate any common properties) will @@ -326,7 +327,8 @@ void LayerAnimator::ScheduleTogether( bool wait_for_group_start = false; for (iter = animations.begin(); iter != animations.end(); ++iter) - wait_for_group_start |= (*iter)->IsFirstElementThreaded(delegate_); + wait_for_group_start |= + delegate_ && (*iter)->IsFirstElementThreaded(delegate_); int group_id = cc::AnimationIdProvider::NextGroupId(); diff --git a/chromium/ui/compositor/layer_animator_collection.cc b/chromium/ui/compositor/layer_animator_collection.cc index fd9873e6104..5e997fb921b 100644 --- a/chromium/ui/compositor/layer_animator_collection.cc +++ b/chromium/ui/compositor/layer_animator_collection.cc @@ -14,6 +14,10 @@ namespace ui { LayerAnimatorCollection::LayerAnimatorCollection(Compositor* compositor) : compositor_(compositor), last_tick_time_(base::TimeTicks::Now()) { + // Do not check the active duration for the LayerAnimationCollection because + // new animation can be added while running existing animation, which + // extends the duration. + set_check_active_duration(false); } LayerAnimatorCollection::~LayerAnimatorCollection() { diff --git a/chromium/ui/compositor/layer_owner.cc b/chromium/ui/compositor/layer_owner.cc index 0ddca216e7b..71bf9065a1e 100644 --- a/chromium/ui/compositor/layer_owner.cc +++ b/chromium/ui/compositor/layer_owner.cc @@ -4,11 +4,6 @@ #include "ui/compositor/layer_owner.h" -// layer_owner.h is a widely included header and its size impacts build -// time. Try not to raise this limit unless necessary. See -// https://chromium.googlesource.com/chromium/src/+/HEAD/docs/wmax_tokens.md -#pragma clang max_tokens_here 480000 - #include <utility> #include "base/observer_list.h" diff --git a/chromium/ui/compositor/layer_unittest.cc b/chromium/ui/compositor/layer_unittest.cc index 6497d7d1239..fc4de27ee86 100644 --- a/chromium/ui/compositor/layer_unittest.cc +++ b/chromium/ui/compositor/layer_unittest.cc @@ -773,7 +773,7 @@ TEST_F(LayerWithDelegateTest, Cloning) { gfx::Rect clip_rect(1, 1, 2, 2); gfx::LinearGradient gradient_mask(45); - gradient_mask.AddStep(50, 50); + gradient_mask.AddStep(.5, 50); layer->SetTransform(transform); layer->SetColor(SK_ColorRED); @@ -816,7 +816,7 @@ TEST_F(LayerWithDelegateTest, Cloning) { layer->SetRoundedCornerRadius({3, 6, 9, 12}); gradient_mask.set_angle(90); - gradient_mask.AddStep(90, 30); + gradient_mask.AddStep(.9, 30); layer->SetGradientMask(gradient_mask); // The clone is an independent copy, so state changes do not propagate. @@ -1064,7 +1064,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { constexpr viz::SubtreeCaptureId kSubtreeCaptureId(22); l1->SetSubtreeCaptureId(kSubtreeCaptureId); gfx::LinearGradient gradient_mask(45); - gradient_mask.AddStep(50, 50); + gradient_mask.AddStep(.5, 50); l1->SetGradientMask(gradient_mask); EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); @@ -1348,7 +1348,7 @@ TEST_F(LayerWithDelegateTest, RoundedCorner) { TEST_F(LayerWithDelegateTest, GradientMask) { gfx::Rect layer_bounds(10, 20, 100, 100); gfx::LinearGradient gradient_mask; - gradient_mask.AddStep(50, 50); + gradient_mask.AddStep(.5, 50); auto layer = std::make_unique<Layer>(LAYER_TEXTURED); diff --git a/chromium/ui/compositor/recyclable_compositor_mac.cc b/chromium/ui/compositor/recyclable_compositor_mac.cc index a2c1e7dcc46..fbedebe5e63 100644 --- a/chromium/ui/compositor/recyclable_compositor_mac.cc +++ b/chromium/ui/compositor/recyclable_compositor_mac.cc @@ -17,9 +17,6 @@ namespace ui { namespace { -// The number of RecyclableCompositorMacs in existence. -size_t g_recyclable_compositor_count = 0; - // Returns a task runner for creating a ui::Compositor. This allows compositor // tasks to be funneled through ui::WindowResizeHelper's task runner to allow // resize operations to coordinate with frames provided by the GPU process. @@ -44,7 +41,6 @@ RecyclableCompositorMac::RecyclableCompositorMac( context_factory, GetCompositorTaskRunner(), ui::IsPixelCanvasRecordingEnabled()) { - g_recyclable_compositor_count += 1; compositor_.SetAcceleratedWidget( accelerated_widget_mac_->accelerated_widget()); Suspend(); @@ -53,7 +49,6 @@ RecyclableCompositorMac::RecyclableCompositorMac( RecyclableCompositorMac::~RecyclableCompositorMac() { compositor_.RemoveObserver(this); - g_recyclable_compositor_count -= 1; } void RecyclableCompositorMac::Suspend() { @@ -102,78 +97,4 @@ void RecyclableCompositorMac::OnCompositingDidCommit( accelerated_widget_mac_->SetSuspended(false); } -//////////////////////////////////////////////////////////////////////////////// -// RecyclableCompositorMacFactory - -// static -RecyclableCompositorMacFactory* RecyclableCompositorMacFactory::Get() { - static base::NoDestructor<RecyclableCompositorMacFactory> factory; - return factory.get(); -} - -std::unique_ptr<RecyclableCompositorMac> -RecyclableCompositorMacFactory::CreateCompositor( - ui::ContextFactory* context_factory, - bool force_new_compositor) { - if (!compositors_.empty() && !force_new_compositor) { - std::unique_ptr<RecyclableCompositorMac> result; - result = std::move(compositors_.back()); - compositors_.pop_back(); - if (result->compositor()->context_factory() == context_factory) { - return result; - } - } - return std::make_unique<RecyclableCompositorMac>(context_factory); -} - -void RecyclableCompositorMacFactory::RecycleCompositor( - std::unique_ptr<RecyclableCompositorMac> compositor) { - if (recycling_disabled_) - return; - - // Invalidate the surface before suspending it. - compositor->InvalidateSurface(); - compositor->accelerated_widget_mac_->SetSuspended(true); - - // Make this RecyclableCompositorMac recyclable for future instances. - compositors_.push_back(std::move(compositor)); - - // When we get to zero active compositors in use, destroy all spare - // compositors. This is done to appease tests that rely on compositors being - // destroyed immediately (if the compositor is recycled and continues to - // exist, its subsequent initialization will crash). - if (g_recyclable_compositor_count == compositors_.size()) { - compositors_.clear(); - return; - } - - // Post a task to free up the spare ui::Compositors when needed. Post this - // to the browser main thread so that we won't free any compositors while - // in a nested loop waiting to put up a new frame. - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, - base::BindOnce(&RecyclableCompositorMacFactory::ReduceSpareCompositors, - weak_factory_.GetWeakPtr())); -} - -RecyclableCompositorMacFactory::RecyclableCompositorMacFactory() - : weak_factory_(this) { - // TODO(crbug.com/1247756): This class probably isn't needed anymore since - // recycling is always disabled. - recycling_disabled_ = true; -} - -RecyclableCompositorMacFactory::~RecyclableCompositorMacFactory() = default; - -void RecyclableCompositorMacFactory::ReduceSpareCompositors() { - // Allow at most one spare recyclable compositor. - while (compositors_.size() > 1) - compositors_.pop_front(); -} - -void RecyclableCompositorMacFactory::DisableRecyclingForShutdown() { - recycling_disabled_ = true; - compositors_.clear(); -} - } // namespace ui diff --git a/chromium/ui/compositor/recyclable_compositor_mac.h b/chromium/ui/compositor/recyclable_compositor_mac.h index b6110433460..a026b8ee0bc 100644 --- a/chromium/ui/compositor/recyclable_compositor_mac.h +++ b/chromium/ui/compositor/recyclable_compositor_mac.h @@ -52,8 +52,6 @@ class COMPOSITOR_EXPORT RecyclableCompositorMac const gfx::DisplayColorSpaces& display_color_spaces); private: - friend class RecyclableCompositorMacFactory; - // Invalidate the compositor's surface information. void InvalidateSurface(); @@ -72,38 +70,6 @@ class COMPOSITOR_EXPORT RecyclableCompositorMac std::unique_ptr<ui::CompositorLock> compositor_suspended_lock_; }; -//////////////////////////////////////////////////////////////////////////////// -// RecyclableCompositorMacFactory -// -// The factory through which RecyclableCompositorMacs are created and recycled. - -class COMPOSITOR_EXPORT RecyclableCompositorMacFactory { - public: - static RecyclableCompositorMacFactory* Get(); - - // Create a compositor, or recycle a preexisting one. - std::unique_ptr<RecyclableCompositorMac> CreateCompositor( - ui::ContextFactory* context_factory, - bool force_new_compositor = false); - - // Delete a compositor, or allow it to be recycled. - void RecycleCompositor(std::unique_ptr<RecyclableCompositorMac> compositor); - - // Destroy any compositors that are being kept around for recycling. - void DisableRecyclingForShutdown(); - - private: - friend class base::NoDestructor<ui::RecyclableCompositorMacFactory>; - friend class RecyclableCompositorMac; - RecyclableCompositorMacFactory(); - ~RecyclableCompositorMacFactory(); - void ReduceSpareCompositors(); - - bool recycling_disabled_ = false; - std::list<std::unique_ptr<RecyclableCompositorMac>> compositors_; - base::WeakPtrFactory<RecyclableCompositorMacFactory> weak_factory_; -}; - } // namespace ui #endif // UI_COMPOSITOR_RECYCLABLE_COMPOSITOR_MAC_H_ |