diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-13 16:23:34 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-14 10:37:21 +0000 |
commit | 38a9a29f4f9436cace7f0e7abf9c586057df8a4e (patch) | |
tree | c4e8c458dc595bc0ddb435708fa2229edfd00bd4 /chromium/ui/compositor | |
parent | e684a3455bcc29a6e3e66a004e352dea4e1141e7 (diff) | |
download | qtwebengine-chromium-38a9a29f4f9436cace7f0e7abf9c586057df8a4e.tar.gz |
BASELINE: Update Chromium to 73.0.3683.37
Change-Id: I08c9af2948b645f671e5d933aca1f7a90ea372f2
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/ui/compositor')
23 files changed, 457 insertions, 249 deletions
diff --git a/chromium/ui/compositor/BUILD.gn b/chromium/ui/compositor/BUILD.gn index ab830a68656..4804d129daf 100644 --- a/chromium/ui/compositor/BUILD.gn +++ b/chromium/ui/compositor/BUILD.gn @@ -16,8 +16,6 @@ jumbo_component("compositor") { "clip_recorder.h", "closure_animation_observer.cc", "closure_animation_observer.h", - "compositing_recorder.cc", - "compositing_recorder.h", "compositor.cc", "compositor.h", "compositor_animation_observer.h", diff --git a/chromium/ui/compositor/clip_recorder.cc b/chromium/ui/compositor/clip_recorder.cc index 77acf0f7cfc..b5ab1435808 100644 --- a/chromium/ui/compositor/clip_recorder.cc +++ b/chromium/ui/compositor/clip_recorder.cc @@ -6,11 +6,11 @@ #include "cc/paint/display_item_list.h" #include "cc/paint/paint_op_buffer.h" +#include "third_party/skia/include/core/SkPath.h" #include "ui/compositor/paint_context.h" #include "ui/gfx/canvas.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect_conversions.h" -#include "ui/gfx/path.h" #include "ui/gfx/skia_util.h" namespace ui { @@ -38,7 +38,7 @@ void ClipRecorder::ClipRect(const gfx::Rect& clip_rect) { ++num_closers_; } -void ClipRecorder::ClipPath(const gfx::Path& clip_path) { +void ClipRecorder::ClipPath(const SkPath& clip_path) { bool antialias = false; context_.list_->StartPaint(); @@ -49,7 +49,7 @@ void ClipRecorder::ClipPath(const gfx::Path& clip_path) { ++num_closers_; } -void ClipRecorder::ClipPathWithAntiAliasing(const gfx::Path& clip_path) { +void ClipRecorder::ClipPathWithAntiAliasing(const SkPath& clip_path) { bool antialias = true; context_.list_->StartPaint(); diff --git a/chromium/ui/compositor/clip_recorder.h b/chromium/ui/compositor/clip_recorder.h index 7bc0eab96ed..f89ed9601be 100644 --- a/chromium/ui/compositor/clip_recorder.h +++ b/chromium/ui/compositor/clip_recorder.h @@ -9,14 +9,12 @@ #include "ui/compositor/compositor_export.h" #include "ui/gfx/geometry/rect.h" +class SkPath; + namespace cc { class DisplayItemList; } -namespace gfx { -class Path; -} - namespace ui { class PaintContext; @@ -30,8 +28,8 @@ class COMPOSITOR_EXPORT ClipRecorder { ~ClipRecorder(); void ClipRect(const gfx::Rect& clip_rect); - void ClipPath(const gfx::Path& clip_path); - void ClipPathWithAntiAliasing(const gfx::Path& clip_path); + void ClipPath(const SkPath& clip_path); + void ClipPathWithAntiAliasing(const SkPath& clip_path); private: const PaintContext& context_; diff --git a/chromium/ui/compositor/compositing_recorder.cc b/chromium/ui/compositor/compositing_recorder.cc deleted file mode 100644 index ab4bf8826ab..00000000000 --- a/chromium/ui/compositor/compositing_recorder.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/compositor/compositing_recorder.h" - -#include "cc/paint/display_item_list.h" -#include "cc/paint/paint_op_buffer.h" -#include "ui/compositor/paint_context.h" -#include "ui/gfx/canvas.h" - -namespace ui { - -CompositingRecorder::CompositingRecorder(const PaintContext& context, - uint8_t alpha, - bool lcd_text_requires_opaque_layer) - : context_(context), - saved_(alpha < 255) { - if (!saved_) - return; - - context_.list_->StartPaint(); - context_.list_->push<cc::SaveLayerAlphaOp>(nullptr, alpha, - !lcd_text_requires_opaque_layer); - context_.list_->EndPaintOfPairedBegin(); -} - -CompositingRecorder::~CompositingRecorder() { - if (!saved_) - return; - - context_.list_->StartPaint(); - context_.list_->push<cc::RestoreOp>(); - context_.list_->EndPaintOfPairedEnd(); -} - -} // namespace ui diff --git a/chromium/ui/compositor/compositing_recorder.h b/chromium/ui/compositor/compositing_recorder.h deleted file mode 100644 index 78817f9a01f..00000000000 --- a/chromium/ui/compositor/compositing_recorder.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_COMPOSITOR_COMPOSITING_RECORDER_H_ -#define UI_COMPOSITOR_COMPOSITING_RECORDER_H_ - -#include <stdint.h> - -#include "base/macros.h" -#include "ui/compositor/compositor_export.h" - -namespace ui { -class PaintContext; - -// A class to provide scoped compositing filters (eg opacity) of painting to a -// DisplayItemList. The filters provided will be applied to any -// DisplayItems added to the DisplayItemList while this object is alive. In -// other words, any nested PaintRecorders or other such Recorders will -// be filtered by the effect. -class COMPOSITOR_EXPORT CompositingRecorder { - public: - // |alpha| is a value between 0 and 255, where 0 is transparent and 255 is - // opaque. |size_in_context| is the size in the |context|'s space surrounding - // everything that's visible. |lcd_text_requires_opaque_layer| should - // normally be true; if this is false, Skia will respect text rendering - // requests for LCD AA even if they occur on non-opaque layers. This should - // only be used in cases where the text is known to be rendered opaquely on an - // opaque background before compositing. - CompositingRecorder(const PaintContext& context, - uint8_t alpha, - bool lcd_text_requires_opaque_layer); - ~CompositingRecorder(); - - private: - const PaintContext& context_; - bool saved_; - - DISALLOW_COPY_AND_ASSIGN(CompositingRecorder); -}; - -} // namespace ui - -#endif // UI_COMPOSITOR_CLIP_TRANSFORM_RECORDER_H_ diff --git a/chromium/ui/compositor/compositor.cc b/chromium/ui/compositor/compositor.cc index 5358941075a..74e8d5b78d5 100644 --- a/chromium/ui/compositor/compositor.cc +++ b/chromium/ui/compositor/compositor.cc @@ -63,21 +63,21 @@ const char* kDefaultTraceEnvironmentName = "browser"; } // namespace -Compositor::Compositor(const viz::FrameSinkId& frame_sink_id, - ui::ContextFactory* context_factory, - ui::ContextFactoryPrivate* context_factory_private, - scoped_refptr<base::SingleThreadTaskRunner> task_runner, - bool enable_surface_synchronization, - bool enable_pixel_canvas, - bool external_begin_frames_enabled, - bool force_software_compositor, - const char* trace_environment_name) +Compositor::Compositor( + const viz::FrameSinkId& frame_sink_id, + ui::ContextFactory* context_factory, + ui::ContextFactoryPrivate* context_factory_private, + scoped_refptr<base::SingleThreadTaskRunner> task_runner, + bool enable_pixel_canvas, + ui::ExternalBeginFrameClient* external_begin_frame_client, + bool force_software_compositor, + const char* trace_environment_name) : context_factory_(context_factory), context_factory_private_(context_factory_private), frame_sink_id_(frame_sink_id), task_runner_(task_runner), vsync_manager_(new CompositorVSyncManager()), - external_begin_frames_enabled_(external_begin_frames_enabled), + external_begin_frame_client_(external_begin_frame_client), force_software_compositor_(force_software_compositor), layer_animator_collection_(this), is_pixel_canvas_(enable_pixel_canvas), @@ -155,7 +155,7 @@ Compositor::Compositor(const viz::FrameSinkId& frame_sink_id, settings.initial_debug_state.SetRecordRenderingStats( command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); - settings.enable_surface_synchronization = enable_surface_synchronization; + settings.enable_surface_synchronization = true; settings.build_hit_test_data = features::IsVizHitTestingSurfaceLayerEnabled(); settings.use_zero_copy = IsUIZeroCopyEnabled(); @@ -179,6 +179,20 @@ Compositor::Compositor(const viz::FrameSinkId& frame_sink_id, #endif settings.memory_policy.bytes_limit_when_visible = 512 * 1024 * 1024; + + // Used to configure ui compositor memory limit for chromeos devices. + // See crbug.com/923141. + if (command_line->HasSwitch( + switches::kUiCompositorMemoryLimitWhenVisibleMB)) { + std::string value_str = command_line->GetSwitchValueASCII( + switches::kUiCompositorMemoryLimitWhenVisibleMB); + unsigned value_in_mb; + if (base::StringToUint(value_str, &value_in_mb)) { + settings.memory_policy.bytes_limit_when_visible = + 1024 * 1024 * value_in_mb; + } + } + settings.memory_policy.priority_cutoff_when_visible = gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; @@ -190,9 +204,6 @@ Compositor::Compositor(const viz::FrameSinkId& frame_sink_id, settings.enable_latency_recovery = false; } - settings.always_request_presentation_time = - command_line->HasSwitch(cc::switches::kAlwaysRequestPresentationTime); - animation_host_ = cc::AnimationHost::CreateMainInstance(); cc::LayerTreeHost::InitParams params; @@ -505,36 +516,6 @@ scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const { return vsync_manager_; } -void Compositor::IssueExternalBeginFrame(const viz::BeginFrameArgs& args) { - TRACE_EVENT1("ui", "Compositor::IssueExternalBeginFrame", "args", - args.AsValue()); - DCHECK(external_begin_frames_enabled_); - if (context_factory_private_) - context_factory_private_->IssueExternalBeginFrame(this, args); -} - -void Compositor::SetExternalBeginFrameClient(ExternalBeginFrameClient* client) { - DCHECK(external_begin_frames_enabled_); - external_begin_frame_client_ = client; - if (needs_external_begin_frames_ && external_begin_frame_client_) - external_begin_frame_client_->OnNeedsExternalBeginFrames(true); -} - -void Compositor::OnDisplayDidFinishFrame(const viz::BeginFrameAck& ack) { - DCHECK(external_begin_frames_enabled_); - if (external_begin_frame_client_) - external_begin_frame_client_->OnDisplayDidFinishFrame(ack); -} - -void Compositor::OnNeedsExternalBeginFrames(bool needs_begin_frames) { - DCHECK(external_begin_frames_enabled_); - if (external_begin_frame_client_) { - external_begin_frame_client_->OnNeedsExternalBeginFrames( - needs_begin_frames); - } - needs_external_begin_frames_ = needs_begin_frames; -} - void Compositor::AddObserver(CompositorObserver* observer) { observer_list_.AddObserver(observer); } @@ -597,10 +578,10 @@ void Compositor::RequestNewLayerTreeFrameSink() { } void Compositor::DidFailToInitializeLayerTreeFrameSink() { - // The LayerTreeFrameSink should already be bound/initialized before being - // given to - // the Compositor. - NOTREACHED(); + task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&Compositor::RequestNewLayerTreeFrameSink, + context_creation_weak_ptr_factory_.GetWeakPtr())); } void Compositor::DidCommit() { @@ -623,6 +604,12 @@ void Compositor::DidPresentCompositorFrame( trace_environment_name_); } +void Compositor::DidGenerateLocalSurfaceIdAllocation( + const viz::LocalSurfaceIdAllocation& allocation) { + for (auto& observer : observer_list_) + observer.DidGenerateLocalSurfaceIdAllocation(this, allocation); +} + void Compositor::DidSubmitCompositorFrame() { base::TimeTicks start_time = base::TimeTicks::Now(); for (auto& observer : observer_list_) diff --git a/chromium/ui/compositor/compositor.h b/chromium/ui/compositor/compositor.h index 6f46fd5b4b5..313431f82ee 100644 --- a/chromium/ui/compositor/compositor.h +++ b/chromium/ui/compositor/compositor.h @@ -11,7 +11,6 @@ #include <string> #include "base/callback_forward.h" -#include "base/containers/hash_tables.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" @@ -201,8 +200,7 @@ class COMPOSITOR_EXPORT ContextFactory { // view hierarchy. class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient, public cc::LayerTreeHostSingleThreadClient, - public viz::HostFrameSinkClient, - public ExternalBeginFrameClient { + public viz::HostFrameSinkClient { public: // |trace_environment_name| is passed to trace events so that tracing // can identify the environment the trace events are from. Examples are, @@ -211,9 +209,8 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient, ui::ContextFactory* context_factory, ui::ContextFactoryPrivate* context_factory_private, scoped_refptr<base::SingleThreadTaskRunner> task_runner, - bool enable_surface_synchronization, bool enable_pixel_canvas, - bool external_begin_frames_enabled = false, + ExternalBeginFrameClient* external_begin_frame_client = nullptr, bool force_software_compositor = false, const char* trace_environment_name = nullptr); ~Compositor() override; @@ -323,16 +320,6 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient, // Returns the vsync manager for this compositor. scoped_refptr<CompositorVSyncManager> vsync_manager() const; - bool external_begin_frames_enabled() { - return external_begin_frames_enabled_; - } - - void SetExternalBeginFrameClient(ExternalBeginFrameClient* client); - - // The ExternalBeginFrameClient calls this to issue a BeginFrame with the - // given |args|. - void IssueExternalBeginFrame(const viz::BeginFrameArgs& args); - // This flag is used to force a compositor into software compositing even tho // in general chrome is using gpu compositing. This allows the compositor to // be created without a gpu context, and does not go through the gpu path at @@ -377,10 +364,6 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient, base::OnceCallback<void(const gfx::PresentationFeedback&)>; void RequestPresentationTimeForNextFrame(PresentationTimeCallback callback); - // ExternalBeginFrameClient implementation. - void OnDisplayDidFinishFrame(const viz::BeginFrameAck& ack) override; - void OnNeedsExternalBeginFrames(bool needs_begin_frames) override; - // LayerTreeHostClient implementation. void WillBeginMainFrame() override {} void DidBeginMainFrame() override {} @@ -392,6 +375,11 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient, } void RecordWheelAndTouchScrollingCount(bool has_scrolled_by_wheel, bool has_scrolled_by_touch) override {} + void SendOverscrollEventFromImplSide( + const gfx::Vector2dF& overscroll_delta, + cc::ElementId scroll_latched_element_id) override {} + void SendScrollEndEventFromImplSide( + cc::ElementId scroll_latched_element_id) override {} void RequestNewLayerTreeFrameSink() override; void DidInitializeLayerTreeFrameSink() override {} void DidFailToInitializeLayerTreeFrameSink() override; @@ -404,6 +392,8 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient, uint32_t frame_token, const gfx::PresentationFeedback& feedback) override; void RecordEndOfFrameMetrics(base::TimeTicks frame_begin_time) override {} + void DidGenerateLocalSurfaceIdAllocation( + const viz::LocalSurfaceIdAllocation& allocation) override; // cc::LayerTreeHostSingleThreadClient implementation. void DidSubmitCompositorFrame() override; @@ -429,6 +419,10 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient, int activated_frame_count() const { return activated_frame_count_; } float refresh_rate() const { return refresh_rate_; } + ExternalBeginFrameClient* external_begin_frame_client() { + return external_begin_frame_client_; + } + void SetAllowLocksToExtendTimeout(bool allowed) { lock_manager_.set_allow_locks_to_extend_timeout(allowed); } @@ -480,9 +474,7 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient, base::TimeTicks vsync_timebase_; base::TimeDelta vsync_interval_; - bool external_begin_frames_enabled_; - ExternalBeginFrameClient* external_begin_frame_client_ = nullptr; - bool needs_external_begin_frames_ = false; + ExternalBeginFrameClient* const external_begin_frame_client_; const bool force_software_compositor_; diff --git a/chromium/ui/compositor/compositor_observer.h b/chromium/ui/compositor/compositor_observer.h index 4225c8acd6c..5745c3cba89 100644 --- a/chromium/ui/compositor/compositor_observer.h +++ b/chromium/ui/compositor/compositor_observer.h @@ -8,6 +8,10 @@ #include "base/time/time.h" #include "ui/compositor/compositor_export.h" +namespace viz { +class LocalSurfaceIdAllocation; +} + namespace ui { class Compositor; @@ -24,22 +28,30 @@ class COMPOSITOR_EXPORT CompositorObserver { // between two composites (just before the composite as part of the // composite cycle). If the compositor is locked, it will not send this // this signal. - virtual void OnCompositingDidCommit(Compositor* compositor) = 0; + virtual void OnCompositingDidCommit(Compositor* compositor) {} // Called when compositing started: it has taken all the layer changes into // account and has issued the graphics commands. virtual void OnCompositingStarted(Compositor* compositor, - base::TimeTicks start_time) = 0; + base::TimeTicks start_time) {} // Called when compositing completes: the present to screen has completed. - virtual void OnCompositingEnded(Compositor* compositor) = 0; + virtual void OnCompositingEnded(Compositor* compositor) {} // Called when a child of the compositor is resizing. - virtual void OnCompositingChildResizing(Compositor* compositor) = 0; + virtual void OnCompositingChildResizing(Compositor* compositor) {} // Called at the top of the compositor's destructor, to give observers a // chance to remove themselves. - virtual void OnCompositingShuttingDown(Compositor* compositor) = 0; + virtual void OnCompositingShuttingDown(Compositor* compositor) {} + + // Called (asynchronously) when the compositor generates a new + // LocalSurfaceIdAllocation. For example, if + // LayerTreeHost::RequestNewLocalSurfaceId() is called, then this function + // is called once the compositor generates the new LocalSurfaceIdAllocation. + virtual void DidGenerateLocalSurfaceIdAllocation( + Compositor* compositor, + const viz::LocalSurfaceIdAllocation& allocation) {} }; } // namespace ui diff --git a/chromium/ui/compositor/compositor_switches.cc b/chromium/ui/compositor/compositor_switches.cc index a61a7ba9b59..842a3dce204 100644 --- a/chromium/ui/compositor/compositor_switches.cc +++ b/chromium/ui/compositor/compositor_switches.cc @@ -29,6 +29,9 @@ const char kUISlowAnimations[] = "ui-slow-animations"; const char kDisableVsyncForTests[] = "disable-vsync-for-tests"; +const char kUiCompositorMemoryLimitWhenVisibleMB[] = + "ui-compositor-memory-limit-when-visible-mb"; + } // namespace switches namespace features { diff --git a/chromium/ui/compositor/compositor_switches.h b/chromium/ui/compositor/compositor_switches.h index 8757e22e970..d1abbfe30f4 100644 --- a/chromium/ui/compositor/compositor_switches.h +++ b/chromium/ui/compositor/compositor_switches.h @@ -18,6 +18,7 @@ COMPOSITOR_EXPORT extern const char kUIDisableZeroCopy[]; COMPOSITOR_EXPORT extern const char kUIShowPaintRects[]; COMPOSITOR_EXPORT extern const char kUISlowAnimations[]; COMPOSITOR_EXPORT extern const char kDisableVsyncForTests[]; +COMPOSITOR_EXPORT extern const char kUiCompositorMemoryLimitWhenVisibleMB[]; } // namespace switches diff --git a/chromium/ui/compositor/compositor_unittest.cc b/chromium/ui/compositor/compositor_unittest.cc index d393b18fdff..79dda58b2ad 100644 --- a/chromium/ui/compositor/compositor_unittest.cc +++ b/chromium/ui/compositor/compositor_unittest.cc @@ -43,7 +43,6 @@ class CompositorTest : public testing::Test { compositor_.reset(new ui::Compositor( context_factory_private->AllocateFrameSinkId(), context_factory, context_factory_private, CreateTaskRunner(), - false /* enable_surface_synchronization */, false /* enable_pixel_canvas */)); compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); } @@ -105,10 +104,12 @@ class CompositorTestWithMessageLoop : public CompositorTest { TEST_F(CompositorTestWithMessageLoop, OutputColorMatrix) { auto root_layer = std::make_unique<Layer>(ui::LAYER_SOLID_COLOR); + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); root_layer->SetBounds(gfx::Rect(10, 10)); compositor()->SetRootLayer(root_layer.get()); compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10), - viz::LocalSurfaceIdAllocation()); + allocator.GetCurrentLocalSurfaceIdAllocation()); DCHECK(compositor()->IsVisible()); // Set a non-identity color matrix on the compistor display, and expect it to @@ -159,10 +160,12 @@ TEST_F(CompositorTestWithMockedTime, #endif TEST_F(CompositorTestWithMessageLoop, MAYBE_CreateAndReleaseOutputSurface) { std::unique_ptr<Layer> root_layer(new Layer(ui::LAYER_SOLID_COLOR)); + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); root_layer->SetBounds(gfx::Rect(10, 10)); compositor()->SetRootLayer(root_layer.get()); compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10), - viz::LocalSurfaceIdAllocation()); + allocator.GetCurrentLocalSurfaceIdAllocation()); DCHECK(compositor()->IsVisible()); compositor()->ScheduleDraw(); DrawWaiterForTest::WaitForCompositingEnded(compositor()); diff --git a/chromium/ui/compositor/host/host_context_factory_private.cc b/chromium/ui/compositor/host/host_context_factory_private.cc index e16c5490bbc..8297e1aabe3 100644 --- a/chromium/ui/compositor/host/host_context_factory_private.cc +++ b/chromium/ui/compositor/host/host_context_factory_private.cc @@ -78,9 +78,10 @@ void HostContextFactoryPrivate::ConfigureCompositor( // Initialize ExternalBeginFrameController client if enabled. compositor_data.external_begin_frame_controller_client.reset(); - if (compositor->external_begin_frames_enabled()) { + if (compositor->external_begin_frame_client()) { compositor_data.external_begin_frame_controller_client = - std::make_unique<ExternalBeginFrameControllerClientImpl>(compositor); + std::make_unique<ExternalBeginFrameControllerClientImpl>( + compositor->external_begin_frame_client()); root_params->external_begin_frame_controller = compositor_data.external_begin_frame_controller_client ->GetControllerRequest(); @@ -116,8 +117,6 @@ void HostContextFactoryPrivate::ConfigureCompositor( compositor->context_factory()->GetGpuMemoryBufferManager(); params.pipes.compositor_frame_sink_associated_info = std::move(sink_info); params.pipes.client_request = std::move(client_request); - params.local_surface_id_provider = - std::make_unique<viz::DefaultLocalSurfaceIdProvider>(); params.enable_surface_synchronization = true; if (features::IsVizHitTestingDrawQuadEnabled()) { params.hit_test_data_provider = @@ -141,6 +140,14 @@ void HostContextFactoryPrivate::UnconfigureCompositor(Compositor* compositor) { compositor_data_map_.erase(compositor); } +base::flat_set<Compositor*> HostContextFactoryPrivate::GetAllCompositors() { + base::flat_set<Compositor*> all_compositors; + all_compositors.reserve(compositor_data_map_.size()); + for (auto& pair : compositor_data_map_) + all_compositors.insert(pair.first); + return all_compositors; +} + std::unique_ptr<Reflector> HostContextFactoryPrivate::CreateReflector( Compositor* source, Layer* target) { @@ -258,14 +265,6 @@ viz::FrameSinkManagerImpl* HostContextFactoryPrivate::GetFrameSinkManager() { return nullptr; } -base::flat_set<Compositor*> HostContextFactoryPrivate::GetAllCompositors() { - base::flat_set<Compositor*> all_compositors; - all_compositors.reserve(compositor_data_map_.size()); - for (auto& pair : compositor_data_map_) - all_compositors.insert(pair.first); - return all_compositors; -} - HostContextFactoryPrivate::CompositorData::CompositorData() = default; HostContextFactoryPrivate::CompositorData::CompositorData( CompositorData&& other) = default; diff --git a/chromium/ui/compositor/host/host_context_factory_private.h b/chromium/ui/compositor/host/host_context_factory_private.h index 69a441e9fbc..a74630258fd 100644 --- a/chromium/ui/compositor/host/host_context_factory_private.h +++ b/chromium/ui/compositor/host/host_context_factory_private.h @@ -50,6 +50,19 @@ class HostContextFactoryPrivate : public ContextFactoryPrivate { void UnconfigureCompositor(Compositor* compositor); + void set_is_gpu_compositing_disabled(bool value) { + is_gpu_compositing_disabled_ = value; + } + bool is_gpu_compositing_disabled() const { + return is_gpu_compositing_disabled_; + } + + scoped_refptr<base::SingleThreadTaskRunner> resize_task_runner() { + return resize_task_runner_; + } + + base::flat_set<Compositor*> GetAllCompositors(); + // ContextFactoryPrivate implementation. std::unique_ptr<Reflector> CreateReflector(Compositor* source, Layer* target) override; @@ -72,20 +85,6 @@ class HostContextFactoryPrivate : public ContextFactoryPrivate { void SetOutputIsSecure(Compositor* compositor, bool secure) override; viz::FrameSinkManagerImpl* GetFrameSinkManager() override; - protected: - void set_is_gpu_compositing_disabled(bool value) { - is_gpu_compositing_disabled_ = value; - } - bool is_gpu_compositing_disabled() const { - return is_gpu_compositing_disabled_; - } - - scoped_refptr<base::SingleThreadTaskRunner> resize_task_runner() { - return resize_task_runner_; - } - - base::flat_set<Compositor*> GetAllCompositors(); - private: struct CompositorData { CompositorData(); diff --git a/chromium/ui/compositor/layer.cc b/chromium/ui/compositor/layer.cc index b605b586cdd..a1fcf036bd1 100644 --- a/chromium/ui/compositor/layer.cc +++ b/chromium/ui/compositor/layer.cc @@ -166,6 +166,9 @@ Layer::~Layer() { for (auto* child : children_) child->parent_ = nullptr; + if (content_layer_) + content_layer_->ClearClient(); + cc_layer_->SetLayerClient(nullptr); cc_layer_->RemoveFromParent(); if (transfer_release_callback_) transfer_release_callback_->Run(gpu::SyncToken(), false); @@ -219,6 +222,17 @@ std::unique_ptr<Layer> Layer::Clone() const { std::unique_ptr<Layer> Layer::Mirror() { auto mirror = Clone(); mirrors_.emplace_back(std::make_unique<LayerMirror>(this, mirror.get())); + + if (!transfer_resource_.mailbox_holder.mailbox.IsZero()) { + // Send an empty release callback because we don't want the resource to be + // freed up until the original layer releases it. + mirror->SetTransferableResource( + transfer_resource_, + viz::SingleReleaseCallback::Create(base::BindOnce( + [](const gpu::SyncToken& sync_token, bool is_lost) {})), + frame_size_in_dip_); + } + return mirror; } @@ -524,7 +538,6 @@ void Layer::SetLayerBackgroundFilters() { filters.Append(cc::FilterOperation::CreateBlurFilter( background_blur_sigma_, SkBlurImageFilter::kClamp_TileMode)); } - cc_layer_->SetBackdropFilters(filters); } @@ -626,7 +639,10 @@ void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { new_layer->SetTrilinearFiltering(cc_layer_->trilinear_filtering()); cc_layer_ = new_layer.get(); - content_layer_ = nullptr; + if (content_layer_) { + content_layer_->ClearClient(); + content_layer_ = nullptr; + } solid_color_layer_ = nullptr; texture_layer_ = nullptr; surface_layer_ = nullptr; @@ -755,6 +771,16 @@ void Layer::SetTransferableResource( transfer_release_callback_ = std::move(release_callback); transfer_resource_ = resource; SetTextureSize(texture_size_in_dip); + + for (const auto& mirror : mirrors_) { + // The release callbacks should be empty as only the source layer + // should be able to release the texture resource. + mirror->dest()->SetTransferableResource( + transfer_resource_, + viz::SingleReleaseCallback::Create(base::BindOnce( + [](const gpu::SyncToken& sync_token, bool is_lost) {})), + frame_size_in_dip_); + } } void Layer::SetTextureSize(gfx::Size texture_size_in_dip) { @@ -859,6 +885,9 @@ void Layer::SetShowSolidColorContent() { transfer_release_callback_.reset(); } RecomputeDrawsContentAndUVRect(); + + for (const auto& mirror : mirrors_) + mirror->dest()->SetShowSolidColorContent(); } void Layer::UpdateNinePatchLayerImage(const gfx::ImageSkia& image) { @@ -1181,6 +1210,10 @@ void Layer::SetOpacityFromAnimation(float opacity, void Layer::SetVisibilityFromAnimation(bool visible, PropertyChangeReason reason) { + // Sync changes with the mirror layers. + for (const auto& mirror : mirrors_) + mirror->dest()->SetVisible(visible); + if (visible_ == visible) return; diff --git a/chromium/ui/compositor/layer.h b/chromium/ui/compositor/layer.h index 3e1771ffb45..e90777f3935 100644 --- a/chromium/ui/compositor/layer.h +++ b/chromium/ui/compositor/layer.h @@ -249,8 +249,10 @@ class COMPOSITOR_EXPORT Layer : public LayerAnimationDelegate, void SetMaskLayer(Layer* layer_mask); Layer* layer_mask_layer() { return layer_mask_; } - // Sets the visibility of the Layer. A Layer may be visible but not - // drawn. This happens if any ancestor of a Layer is not visible. + // Sets the visibility of the Layer. A Layer may be visible but not drawn. + // This happens if any ancestor of a Layer is not visible. + // Any changes made to this in the source layer will override the visibility + // of its mirror layer. void SetVisible(bool visible); bool visible() const { return visible_; } diff --git a/chromium/ui/compositor/layer_animator.cc b/chromium/ui/compositor/layer_animator.cc index 3c3efd6959c..b5c5886e9a7 100644 --- a/chromium/ui/compositor/layer_animator.cc +++ b/chromium/ui/compositor/layer_animator.cc @@ -227,7 +227,8 @@ void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) { scoped_refptr<LayerAnimator> retain(this); OnScheduled(animation); if (is_animating()) { - animation_queue_.push_back(make_linked_ptr(animation)); + animation_queue_.push_back( + std::unique_ptr<LayerAnimationSequence>(animation)); ProcessQueue(); } else { StartSequenceImmediately(animation); @@ -536,7 +537,7 @@ void LayerAnimator::UpdateAnimationState() { LayerAnimationSequence* LayerAnimator::RemoveAnimation( LayerAnimationSequence* sequence) { - linked_ptr<LayerAnimationSequence> to_return; + std::unique_ptr<LayerAnimationSequence> to_return; bool is_running = false; @@ -553,8 +554,8 @@ LayerAnimationSequence* LayerAnimator::RemoveAnimation( // Then remove from the queue for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); queue_iter != animation_queue_.end(); ++queue_iter) { - if ((*queue_iter) == sequence) { - to_return = *queue_iter; + if (queue_iter->get() == sequence) { + to_return = std::move(*queue_iter); animation_queue_.erase(queue_iter); break; } @@ -651,14 +652,16 @@ void LayerAnimator::AddToQueueIfNotPresent(LayerAnimationSequence* animation) { bool found_sequence = false; for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); queue_iter != animation_queue_.end(); ++queue_iter) { - if ((*queue_iter) == animation) { + if (queue_iter->get() == animation) { found_sequence = true; break; } } - if (!found_sequence) - animation_queue_.push_front(make_linked_ptr(animation)); + if (!found_sequence) { + animation_queue_.push_front( + std::unique_ptr<LayerAnimationSequence>(animation)); + } } void LayerAnimator::RemoveAllAnimationsWithACommonProperty( @@ -749,7 +752,7 @@ void LayerAnimator::EnqueueNewAnimation(LayerAnimationSequence* sequence) { // It is assumed that if there was no conflicting animation, we would // not have been called. No need to check for a collision; just // add to the queue. - animation_queue_.push_back(make_linked_ptr(sequence)); + animation_queue_.push_back(std::unique_ptr<LayerAnimationSequence>(sequence)); ProcessQueue(); } @@ -782,7 +785,7 @@ void LayerAnimator::ReplaceQueuedAnimations(LayerAnimationSequence* sequence) { else ++i; } - animation_queue_.push_back(make_linked_ptr(sequence)); + animation_queue_.push_back(std::unique_ptr<LayerAnimationSequence>(sequence)); ProcessQueue(); } diff --git a/chromium/ui/compositor/layer_animator.h b/chromium/ui/compositor/layer_animator.h index 4e3145d401b..842f111e96a 100644 --- a/chromium/ui/compositor/layer_animator.h +++ b/chromium/ui/compositor/layer_animator.h @@ -11,7 +11,6 @@ #include "base/containers/circular_deque.h" #include "base/gtest_prod_util.h" #include "base/macros.h" -#include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" #include "base/time/time.h" @@ -273,7 +272,7 @@ class COMPOSITOR_EXPORT LayerAnimator : public base::RefCounted<LayerAnimator>, using RunningAnimations = std::vector<RunningAnimation>; using AnimationQueue = - base::circular_deque<linked_ptr<LayerAnimationSequence>>; + base::circular_deque<std::unique_ptr<LayerAnimationSequence>>; // Finishes all animations by either advancing them to their final state or by // aborting them. diff --git a/chromium/ui/compositor/layer_owner_unittest.cc b/chromium/ui/compositor/layer_owner_unittest.cc index 2e6fb209019..1a57e9beb4c 100644 --- a/chromium/ui/compositor/layer_owner_unittest.cc +++ b/chromium/ui/compositor/layer_owner_unittest.cc @@ -85,7 +85,6 @@ void LayerOwnerTestWithCompositor::SetUp() { compositor_.reset( new ui::Compositor(context_factory_private->AllocateFrameSinkId(), context_factory, context_factory_private, task_runner, - false /* enable_surface_synchronization */, false /* enable_pixel_canvas */)); compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); } diff --git a/chromium/ui/compositor/layer_unittest.cc b/chromium/ui/compositor/layer_unittest.cc index efad60457e3..5314e488e27 100644 --- a/chromium/ui/compositor/layer_unittest.cc +++ b/chromium/ui/compositor/layer_unittest.cc @@ -413,10 +413,6 @@ class TestCompositorObserver : public CompositorObserver { void OnCompositingEnded(Compositor* compositor) override { ended_ = true; } - void OnCompositingChildResizing(Compositor* compositor) override {} - - void OnCompositingShuttingDown(Compositor* compositor) override {} - bool committed_ = false; bool started_ = false; bool ended_ = false; @@ -1121,6 +1117,110 @@ TEST_F(LayerWithNullDelegateTest, Visibility) { EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); } +// Various visible/drawn assertions. +TEST_F(LayerWithNullDelegateTest, MirroringVisibility) { + std::unique_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); + std::unique_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); + std::unique_ptr<Layer> l2_mirror = l2->Mirror(); + l1->Add(l2.get()); + l1->Add(l2_mirror.get()); + + NullLayerDelegate delegate; + l1->set_delegate(&delegate); + l2->set_delegate(&delegate); + l2_mirror->set_delegate(&delegate); + + // Layers should initially be drawn. + EXPECT_TRUE(l1->IsDrawn()); + EXPECT_TRUE(l2->IsDrawn()); + EXPECT_TRUE(l2_mirror->IsDrawn()); + EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2_mirror->cc_layer_for_testing()->hide_layer_and_subtree()); + + compositor()->SetRootLayer(l1.get()); + + Draw(); + + // Hiding the root layer should hide that specific layer and its subtree. + l1->SetVisible(false); + + // Since the entire subtree is hidden, no layer should be drawn. + EXPECT_FALSE(l1->IsDrawn()); + EXPECT_FALSE(l2->IsDrawn()); + EXPECT_FALSE(l2_mirror->IsDrawn()); + + // The visibitily property for the subtree is rooted at |l1|. + EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2_mirror->cc_layer_for_testing()->hide_layer_and_subtree()); + + // Hiding |l2| should also set the visibility on its mirror layer. In this + // case the visibility of |l2| will be mirrored by |l2_mirror|. + l2->SetVisible(false); + + // None of the layers are drawn since the visibility is false at every node. + EXPECT_FALSE(l1->IsDrawn()); + EXPECT_FALSE(l2->IsDrawn()); + EXPECT_FALSE(l2_mirror->IsDrawn()); + + // Visibility property is set on every node and hence their subtree is also + // hidden. + EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_TRUE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_TRUE(l2_mirror->cc_layer_for_testing()->hide_layer_and_subtree()); + + // Setting visibility on the root layer should make that layer visible and its + // subtree ready for visibility. + l1->SetVisible(true); + EXPECT_TRUE(l1->IsDrawn()); + EXPECT_FALSE(l2->IsDrawn()); + EXPECT_FALSE(l2_mirror->IsDrawn()); + EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_TRUE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_TRUE(l2_mirror->cc_layer_for_testing()->hide_layer_and_subtree()); + + // Setting visibility on the mirrored layer should not effect its source + // layer. + l2_mirror->SetVisible(true); + EXPECT_TRUE(l1->IsDrawn()); + EXPECT_FALSE(l2->IsDrawn()); + EXPECT_TRUE(l2_mirror->IsDrawn()); + EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_TRUE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2_mirror->cc_layer_for_testing()->hide_layer_and_subtree()); + + // Setting visibility on the source layer should keep the mirror layer in + // sync and not cause any invalid state. + l2->SetVisible(true); + EXPECT_TRUE(l1->IsDrawn()); + EXPECT_TRUE(l2->IsDrawn()); + EXPECT_TRUE(l2_mirror->IsDrawn()); + EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2_mirror->cc_layer_for_testing()->hide_layer_and_subtree()); + + // Setting visibility on the mirrored layer should not effect its source + // layer. + l2_mirror->SetVisible(false); + EXPECT_TRUE(l1->IsDrawn()); + EXPECT_TRUE(l2->IsDrawn()); + EXPECT_FALSE(l2_mirror->IsDrawn()); + EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_TRUE(l2_mirror->cc_layer_for_testing()->hide_layer_and_subtree()); + + // Setting source layer's visibility to true should update the mirror layer + // even if the source layer did not change in the process. + l2->SetVisible(true); + EXPECT_TRUE(l1->IsDrawn()); + EXPECT_TRUE(l2->IsDrawn()); + EXPECT_TRUE(l2_mirror->IsDrawn()); + EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); + EXPECT_FALSE(l2_mirror->cc_layer_for_testing()->hide_layer_and_subtree()); +} + // Checks that stacking-related methods behave as advertised. TEST_F(LayerWithNullDelegateTest, Stacking) { std::unique_ptr<Layer> root(new Layer(LAYER_NOT_DRAWN)); @@ -1512,8 +1612,10 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_CompositorObservers) { // Checks that modifying the hierarchy correctly affects final composite. TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { - GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50), - viz::LocalSurfaceIdAllocation()); + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(50, 50), allocator.GetCurrentLocalSurfaceIdAllocation()); // l0 // +-l11 @@ -1577,14 +1679,104 @@ TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); } +// Checks that basic background blur is working. +TEST_F(LayerWithRealCompositorTest, BackgroundBlur) { + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(200, 200), + allocator.GetCurrentLocalSurfaceIdAllocation()); + // l0 + // +-l1 + // +-l2 + std::unique_ptr<Layer> l0( + CreateColorLayer(SK_ColorRED, gfx::Rect(0, 0, 200, 200))); + std::unique_ptr<Layer> l1( + CreateColorLayer(SK_ColorGREEN, gfx::Rect(100, 100, 100, 100))); + SkColor blue_with_alpha = SkColorSetARGB(40, 10, 20, 200); + std::unique_ptr<Layer> l2( + CreateColorLayer(blue_with_alpha, gfx::Rect(50, 50, 100, 100))); + l2->SetFillsBoundsOpaquely(false); + l2->SetBackgroundBlur(15); + + base::FilePath ref_img1 = test_data_dir().AppendASCII("BackgroundBlur1.png"); + base::FilePath ref_img2 = test_data_dir().AppendASCII("BackgroundBlur2.png"); + SkBitmap bitmap; + + l0->Add(l1.get()); + l0->Add(l2.get()); + DrawTree(l0.get()); + ReadPixels(&bitmap); + ASSERT_FALSE(bitmap.empty()); + // WritePNGFile(bitmap, ref_img1, false); + EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1, cc::ExactPixelComparator(true))); + + l0->StackAtTop(l1.get()); + DrawTree(l0.get()); + ReadPixels(&bitmap); + ASSERT_FALSE(bitmap.empty()); + // WritePNGFile(bitmap, ref_img2, false); + EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); +} + +// Checks that background blur bounds rect gets properly updated when device +// scale changes. +TEST_F(LayerWithRealCompositorTest, BackgroundBlurChangeDeviceScale) { + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(200, 200), + allocator.GetCurrentLocalSurfaceIdAllocation()); + // l0 + // +-l1 + // +-l2 + std::unique_ptr<Layer> l0( + CreateColorLayer(SK_ColorRED, gfx::Rect(0, 0, 200, 200))); + std::unique_ptr<Layer> l1( + CreateColorLayer(SK_ColorGREEN, gfx::Rect(100, 100, 100, 100))); + SkColor blue_with_alpha = SkColorSetARGB(40, 10, 20, 200); + std::unique_ptr<Layer> l2( + CreateColorLayer(blue_with_alpha, gfx::Rect(50, 50, 100, 100))); + l2->SetFillsBoundsOpaquely(false); + l2->SetBackgroundBlur(15); + + base::FilePath ref_img1 = test_data_dir().AppendASCII("BackgroundBlur1.png"); + base::FilePath ref_img2 = + test_data_dir().AppendASCII("BackgroundBlur1_zoom.png"); + SkBitmap bitmap; + + l0->Add(l1.get()); + l0->Add(l2.get()); + DrawTree(l0.get()); + ReadPixels(&bitmap); + ASSERT_FALSE(bitmap.empty()); + // See LayerWithRealCompositorTest.BackgroundBlur test to rewrite this + // baseline. + EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1, cc::ExactPixelComparator(true))); + + allocator.GenerateId(); + // Now change the scale, and make sure the bounds are still correct. + GetCompositor()->SetScaleAndSize( + 2.0f, gfx::Size(200, 200), + allocator.GetCurrentLocalSurfaceIdAllocation()); + DrawTree(l0.get()); + ReadPixels(&bitmap); + ASSERT_FALSE(bitmap.empty()); + // WritePNGFile(bitmap, ref_img2, false); + EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); +} + // It is really hard to write pixel test on text rendering, // due to different font appearance. // So we choose to check result only on Windows. // See https://codereview.chromium.org/1634103003/#msg41 #if defined(OS_WIN) TEST_F(LayerWithRealCompositorTest, CanvasDrawFadedString) { + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); gfx::Size size(50, 50); - GetCompositor()->SetScaleAndSize(1.0f, size, viz::LocalSurfaceIdAllocation()); + GetCompositor()->SetScaleAndSize( + 1.0f, size, allocator.GetCurrentLocalSurfaceIdAllocation()); DrawFadedStringLayerDelegate delegate(SK_ColorBLUE, size); std::unique_ptr<Layer> layer( CreateDrawFadedStringLayerDelegate(gfx::Rect(size), &delegate)); @@ -1617,8 +1809,10 @@ TEST_F(LayerWithRealCompositorTest, CanvasDrawFadedString) { // Opacity is rendered correctly. // Checks that modifying the hierarchy correctly affects final composite. TEST_F(LayerWithRealCompositorTest, Opacity) { - GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50), - viz::LocalSurfaceIdAllocation()); + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(50, 50), allocator.GetCurrentLocalSurfaceIdAllocation()); // l0 // +-l11 @@ -1734,8 +1928,11 @@ TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { l1->set_delegate(&l1_delegate); l1_delegate.set_layer_bounds(l1->bounds()); - GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500), - viz::LocalSurfaceIdAllocation()); + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(500, 500), + allocator.GetCurrentLocalSurfaceIdAllocation()); GetCompositor()->SetRootLayer(root.get()); root->Add(l1.get()); WaitForDraw(); @@ -1751,8 +1948,10 @@ TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. - GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500), - viz::LocalSurfaceIdAllocation()); + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 2.0f, gfx::Size(500, 500), + allocator.GetCurrentLocalSurfaceIdAllocation()); EXPECT_EQ("10,20 200x220", root->bounds().ToString()); EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); // CC layer should still match the UI layer bounds. @@ -1766,8 +1965,10 @@ TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); // Scale down back to 1.0f. - GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500), - viz::LocalSurfaceIdAllocation()); + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(500, 500), + allocator.GetCurrentLocalSurfaceIdAllocation()); EXPECT_EQ("10,20 200x220", root->bounds().ToString()); EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); // CC layer should still match the UI layer bounds. @@ -1784,14 +1985,18 @@ TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { l1_delegate.reset(); // Just changing the size shouldn't notify the scale change nor // trigger repaint. - GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000), - viz::LocalSurfaceIdAllocation()); + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(1000, 1000), + allocator.GetCurrentLocalSurfaceIdAllocation()); // No scale change, so no scale notification. EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); } TEST_F(LayerWithRealCompositorTest, ScaleReparent) { + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); std::unique_ptr<Layer> root( CreateColorLayer(SK_ColorWHITE, gfx::Rect(10, 20, 200, 220))); std::unique_ptr<Layer> l1( @@ -1801,8 +2006,9 @@ TEST_F(LayerWithRealCompositorTest, ScaleReparent) { l1->set_delegate(&l1_delegate); l1_delegate.set_layer_bounds(l1->bounds()); - GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500), - viz::LocalSurfaceIdAllocation()); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(500, 500), + allocator.GetCurrentLocalSurfaceIdAllocation()); GetCompositor()->SetRootLayer(root.get()); root->Add(l1.get()); @@ -1815,8 +2021,10 @@ TEST_F(LayerWithRealCompositorTest, ScaleReparent) { root->Remove(l1.get()); EXPECT_EQ(NULL, l1->parent()); EXPECT_EQ(NULL, l1->GetCompositor()); - GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500), - viz::LocalSurfaceIdAllocation()); + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 2.0f, gfx::Size(500, 500), + allocator.GetCurrentLocalSurfaceIdAllocation()); // Sanity check on root and l1. EXPECT_EQ("10,20 200x220", root->bounds().ToString()); cc_bounds_size = l1->cc_layer_for_testing()->bounds(); @@ -1945,6 +2153,57 @@ TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { EXPECT_EQ(surface_id, surface->surface_id()); } +TEST_F(LayerWithDelegateTest, TransferableResourceMirroring) { + std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); + + auto resource = viz::TransferableResource::MakeGL( + gpu::Mailbox::Generate(), GL_LINEAR, GL_TEXTURE_2D, gpu::SyncToken()); + bool release_callback_run = false; + + layer->SetTransferableResource( + resource, + viz::SingleReleaseCallback::Create( + base::BindOnce(ReturnMailbox, &release_callback_run)), + gfx::Size(10, 10)); + EXPECT_FALSE(release_callback_run); + EXPECT_TRUE(layer->has_external_content()); + + auto mirror = layer->Mirror(); + EXPECT_TRUE(mirror->has_external_content()); + + // Clearing the resource on a mirror layer should not release the source layer + // resource. + mirror.reset(); + EXPECT_FALSE(release_callback_run); + + mirror = layer->Mirror(); + EXPECT_TRUE(mirror->has_external_content()); + + // Clearing the transferable resource on the source layer should clear it from + // the mirror layer as well. + layer->SetShowSolidColorContent(); + EXPECT_TRUE(release_callback_run); + EXPECT_FALSE(layer->has_external_content()); + EXPECT_FALSE(mirror->has_external_content()); + + resource = viz::TransferableResource::MakeGL( + gpu::Mailbox::Generate(), GL_LINEAR, GL_TEXTURE_2D, gpu::SyncToken()); + release_callback_run = false; + + // Setting a transferable resource on the source layer should set it on the + // mirror layers as well. + layer->SetTransferableResource( + resource, + viz::SingleReleaseCallback::Create( + base::BindOnce(ReturnMailbox, &release_callback_run)), + gfx::Size(10, 10)); + EXPECT_FALSE(release_callback_run); + EXPECT_TRUE(layer->has_external_content()); + EXPECT_TRUE(mirror->has_external_content()); + + layer.reset(); +} + // Verifies that layer filters still attached after changing implementation // layer. TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { @@ -2260,8 +2519,11 @@ TEST_F(LayerWithRealCompositorTest, SnapLayerToPixels) { std::unique_ptr<Layer> c1(CreateLayer(LAYER_TEXTURED)); std::unique_ptr<Layer> c11(CreateLayer(LAYER_TEXTURED)); - GetCompositor()->SetScaleAndSize(1.25f, gfx::Size(100, 100), - viz::LocalSurfaceIdAllocation()); + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.25f, gfx::Size(100, 100), + allocator.GetCurrentLocalSurfaceIdAllocation()); GetCompositor()->SetRootLayer(root.get()); root->Add(c1.get()); c1->Add(c11.get()); @@ -2274,8 +2536,10 @@ TEST_F(LayerWithRealCompositorTest, SnapLayerToPixels) { EXPECT_EQ("0.40 0.40", Vector2dFTo100thPrecisionString(c11->subpixel_position_offset())); - GetCompositor()->SetScaleAndSize(1.5f, gfx::Size(100, 100), - viz::LocalSurfaceIdAllocation()); + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.5f, gfx::Size(100, 100), + allocator.GetCurrentLocalSurfaceIdAllocation()); SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); // c11 must already be aligned at 1.5 scale. EXPECT_EQ("0.00 0.00", @@ -2295,8 +2559,11 @@ TEST_F(LayerWithRealCompositorTest, SnapLayerToPixelsWithScaleTransform) { std::unique_ptr<Layer> c11(CreateLayer(LAYER_TEXTURED)); std::unique_ptr<Layer> c111(CreateLayer(LAYER_TEXTURED)); - GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(100, 100), - viz::LocalSurfaceIdAllocation()); + viz::ParentLocalSurfaceIdAllocator allocator; + allocator.GenerateId(); + GetCompositor()->SetScaleAndSize( + 1.0f, gfx::Size(100, 100), + allocator.GetCurrentLocalSurfaceIdAllocation()); GetCompositor()->SetRootLayer(root.get()); root->Add(c1.get()); c1->Add(c11.get()); diff --git a/chromium/ui/compositor/paint_context.h b/chromium/ui/compositor/paint_context.h index 96385275c43..63e5b75b7d0 100644 --- a/chromium/ui/compositor/paint_context.h +++ b/chromium/ui/compositor/paint_context.h @@ -19,7 +19,6 @@ class DisplayItemList; namespace ui { class ClipRecorder; -class CompositingRecorder; class PaintRecorder; class TransformRecorder; @@ -78,7 +77,6 @@ class COMPOSITOR_EXPORT PaintContext { // don't want to expose them on this class so that people must go through the // recorders to access them. friend class ClipRecorder; - friend class CompositingRecorder; friend class PaintRecorder; friend class TransformRecorder; // The Cache class also needs to access the DisplayItemList to append its diff --git a/chromium/ui/compositor/recyclable_compositor_mac.cc b/chromium/ui/compositor/recyclable_compositor_mac.cc index 7f474063719..9aed2f269d0 100644 --- a/chromium/ui/compositor/recyclable_compositor_mac.cc +++ b/chromium/ui/compositor/recyclable_compositor_mac.cc @@ -44,7 +44,6 @@ RecyclableCompositorMac::RecyclableCompositorMac( context_factory, context_factory_private, GetCompositorTaskRunner(), - features::IsSurfaceSynchronizationEnabled(), ui::IsPixelCanvasRecordingEnabled()) { g_recyclable_compositor_count += 1; compositor_.SetAcceleratedWidget( diff --git a/chromium/ui/compositor/recyclable_compositor_mac.h b/chromium/ui/compositor/recyclable_compositor_mac.h index adbb2d498ed..d9991afa341 100644 --- a/chromium/ui/compositor/recyclable_compositor_mac.h +++ b/chromium/ui/compositor/recyclable_compositor_mac.h @@ -56,11 +56,6 @@ class COMPOSITOR_EXPORT RecyclableCompositorMac // ui::CompositorObserver implementation: void OnCompositingDidCommit(ui::Compositor* compositor) override; - void OnCompositingStarted(ui::Compositor* compositor, - base::TimeTicks start_time) override {} - void OnCompositingEnded(ui::Compositor* compositor) override {} - void OnCompositingChildResizing(ui::Compositor* compositor) override {} - void OnCompositingShuttingDown(ui::Compositor* compositor) override {} std::unique_ptr<ui::AcceleratedWidgetMac> accelerated_widget_mac_; ui::Compositor compositor_; diff --git a/chromium/ui/compositor/test/test_compositor_host_ozone.cc b/chromium/ui/compositor/test/test_compositor_host_ozone.cc index 5a97ed93e3a..3efd0450c9b 100644 --- a/chromium/ui/compositor/test/test_compositor_host_ozone.cc +++ b/chromium/ui/compositor/test/test_compositor_host_ozone.cc @@ -13,6 +13,7 @@ #include "base/memory/weak_ptr.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" +#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h" #include "ui/compositor/compositor.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/native_widget_types.h" @@ -72,6 +73,7 @@ class TestCompositorHostOzone : public TestCompositorHost { ui::Compositor compositor_; std::unique_ptr<PlatformWindow> window_; StubPlatformWindowDelegate window_delegate_; + viz::ParentLocalSurfaceIdAllocator allocator_; DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone); }; @@ -85,7 +87,6 @@ TestCompositorHostOzone::TestCompositorHostOzone( context_factory, context_factory_private, base::ThreadTaskRunnerHandle::Get(), - false /* enable_surface_synchronization */, false /* enable_pixel_canvas */) {} TestCompositorHostOzone::~TestCompositorHostOzone() { @@ -103,9 +104,10 @@ void TestCompositorHostOzone::Show() { window_->Show(); DCHECK_NE(window_delegate_.widget(), gfx::kNullAcceleratedWidget); + allocator_.GenerateId(); compositor_.SetAcceleratedWidget(window_delegate_.widget()); compositor_.SetScaleAndSize(1.0f, bounds_.size(), - viz::LocalSurfaceIdAllocation()); + allocator_.GetCurrentLocalSurfaceIdAllocation()); compositor_.SetVisible(true); } |