From e6430e577f105ad8813c92e75c54660c4985026e Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 18 Sep 2017 14:34:04 +0200 Subject: BASELINE: Update Chromium to 61.0.3163.99 Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367 Reviewed-by: Alexandru Croitor --- chromium/ui/compositor/BUILD.gn | 11 ++- chromium/ui/compositor/DEPS | 9 ++ chromium/ui/compositor/clip_recorder.cc | 56 ++++++------- chromium/ui/compositor/clip_recorder.h | 13 +-- chromium/ui/compositor/compositing_recorder.cc | 13 +-- chromium/ui/compositor/compositor.cc | 95 +++++++++++++--------- chromium/ui/compositor/compositor.h | 75 +++++++++-------- chromium/ui/compositor/compositor_switches.cc | 4 + chromium/ui/compositor/compositor_switches.h | 1 + chromium/ui/compositor/compositor_unittest.cc | 5 +- chromium/ui/compositor/compositor_util.cc | 37 ++++----- chromium/ui/compositor/compositor_util.h | 8 +- chromium/ui/compositor/debug_utils.cc | 2 +- chromium/ui/compositor/layer.cc | 73 ++++++++++++----- chromium/ui/compositor/layer.h | 55 ++++++++----- chromium/ui/compositor/layer_animator.cc | 5 -- chromium/ui/compositor/layer_animator.h | 3 +- chromium/ui/compositor/layer_owner_unittest.cc | 7 +- chromium/ui/compositor/layer_unittest.cc | 82 ++++++++++++------- chromium/ui/compositor/paint_cache.cc | 17 ++-- chromium/ui/compositor/paint_cache.h | 17 +++- chromium/ui/compositor/paint_context.cc | 6 -- chromium/ui/compositor/paint_context.h | 5 -- chromium/ui/compositor/paint_recorder.cc | 30 ++++--- chromium/ui/compositor/paint_recorder.h | 2 + chromium/ui/compositor/run_all_unittests.cc | 3 + .../compositor/test/test_compositor_host_ozone.cc | 3 +- .../transform_animation_curve_adapter.cc | 47 +++++++---- .../compositor/transform_animation_curve_adapter.h | 8 +- .../transform_animation_curve_adapter_unittest.cc | 27 +++--- chromium/ui/compositor/transform_recorder.cc | 20 +++-- 31 files changed, 437 insertions(+), 302 deletions(-) (limited to 'chromium/ui/compositor') diff --git a/chromium/ui/compositor/BUILD.gn b/chromium/ui/compositor/BUILD.gn index 83ca119945a..a992c2722fe 100644 --- a/chromium/ui/compositor/BUILD.gn +++ b/chromium/ui/compositor/BUILD.gn @@ -20,6 +20,7 @@ component("compositor") { "compositor.cc", "compositor.h", "compositor_animation_observer.h", + "compositor_constants.h", "compositor_export.h", "compositor_lock.cc", "compositor_lock.h", @@ -54,6 +55,7 @@ component("compositor") { "layer_observer.h", "layer_owner.cc", "layer_owner.h", + "layer_owner_delegate.h", "layer_threaded_animation_delegate.h", "layer_tree_owner.cc", "layer_tree_owner.h", @@ -85,8 +87,10 @@ component("compositor") { "//cc/animation", "//cc/paint", "//cc/surfaces", - "//cc/surfaces:surface_id", "//cc/surfaces:surfaces", + "//components/viz/common", + "//components/viz/host", + "//components/viz/service", "//gpu/command_buffer/common", "//skia", "//ui/display", @@ -153,6 +157,8 @@ static_library("test_support") { "//cc", "//cc:test_support", "//cc/surfaces", + "//components/viz/host", + "//components/viz/service", "//gpu/command_buffer/client:gles2_c_lib", "//gpu/command_buffer/client:gles2_implementation", "//gpu/command_buffer/common:gles2_utils", @@ -206,7 +212,8 @@ test("compositor_unittests") { "//cc", "//cc:test_support", "//cc/surfaces", - "//cc/surfaces:surface_id", + "//components/viz/common", + "//mojo/edk/system", "//skia", "//testing/gmock", "//testing/gtest", diff --git a/chromium/ui/compositor/DEPS b/chromium/ui/compositor/DEPS index 60a4b3df106..75b24eca257 100644 --- a/chromium/ui/compositor/DEPS +++ b/chromium/ui/compositor/DEPS @@ -1,6 +1,9 @@ include_rules = [ "+cc", "-cc/blink", + "+components/viz/common", + "+components/viz/host", + "+components/viz/service", "+gpu/command_buffer/client/gles2_interface.h", "+services/ui/public/cpp", "+skia/ext/refptr.h", @@ -11,3 +14,9 @@ include_rules = [ "+ui/gfx", "+ui/gl", ] + +specific_include_rules = { + "run_all_unittests\.cc": [ + "+mojo/edk/embedder", + ] +} diff --git a/chromium/ui/compositor/clip_recorder.cc b/chromium/ui/compositor/clip_recorder.cc index f42abc6536b..5f8133f2abf 100644 --- a/chromium/ui/compositor/clip_recorder.cc +++ b/chromium/ui/compositor/clip_recorder.cc @@ -4,9 +4,8 @@ #include "ui/compositor/clip_recorder.h" -#include "cc/paint/clip_display_item.h" -#include "cc/paint/clip_path_display_item.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" #include "ui/gfx/geometry/rect.h" @@ -16,48 +15,47 @@ namespace ui { -ClipRecorder::ClipRecorder(const PaintContext& context) - : context_(context), num_closers_(0) { - } +ClipRecorder::ClipRecorder(const PaintContext& context) : context_(context) {} ClipRecorder::~ClipRecorder() { - for (int i = num_closers_ - 1; i >= 0; --i) { - switch (closers_[i]) { - case CLIP_RECT: - context_.list_->CreateAndAppendPairedEndItem(); - break; - case CLIP_PATH: - context_.list_ - ->CreateAndAppendPairedEndItem(); - break; - } + for (int i = 0; i < num_closers_; ++i) { + // Each restore is part of a separate visual rect, so gets its own + // StartPaint/EndPaintOfPairedEnd. + cc::PaintOpBuffer* buffer = context_.list_->StartPaint(); + buffer->push(); + context_.list_->EndPaintOfPairedEnd(); } } -void ClipRecorder::RecordCloser(Closer closer) { - DCHECK_LT(num_closers_, kMaxOpCount); - closers_[num_closers_++] = closer; -} - void ClipRecorder::ClipRect(const gfx::Rect& clip_rect) { bool antialias = false; - context_.list_->CreateAndAppendPairedBeginItem( - clip_rect, std::vector(), antialias); - RecordCloser(CLIP_RECT); + + cc::PaintOpBuffer* buffer = context_.list_->StartPaint(); + buffer->push(); + buffer->push(gfx::RectToSkRect(clip_rect), + SkClipOp::kIntersect, antialias); + context_.list_->EndPaintOfPairedBegin(); + ++num_closers_; } void ClipRecorder::ClipPath(const gfx::Path& clip_path) { bool antialias = false; - context_.list_->CreateAndAppendPairedBeginItem( - clip_path, antialias); - RecordCloser(CLIP_PATH); + + cc::PaintOpBuffer* buffer = context_.list_->StartPaint(); + buffer->push(); + buffer->push(clip_path, SkClipOp::kIntersect, antialias); + context_.list_->EndPaintOfPairedBegin(); + ++num_closers_; } void ClipRecorder::ClipPathWithAntiAliasing(const gfx::Path& clip_path) { bool antialias = true; - context_.list_->CreateAndAppendPairedBeginItem( - clip_path, antialias); - RecordCloser(CLIP_PATH); + + cc::PaintOpBuffer* buffer = context_.list_->StartPaint(); + buffer->push(); + buffer->push(clip_path, SkClipOp::kIntersect, antialias); + context_.list_->EndPaintOfPairedBegin(); + ++num_closers_; } } // namespace ui diff --git a/chromium/ui/compositor/clip_recorder.h b/chromium/ui/compositor/clip_recorder.h index 9650770ce47..7bc0eab96ed 100644 --- a/chromium/ui/compositor/clip_recorder.h +++ b/chromium/ui/compositor/clip_recorder.h @@ -34,19 +34,8 @@ class COMPOSITOR_EXPORT ClipRecorder { void ClipPathWithAntiAliasing(const gfx::Path& clip_path); private: - enum Closer { - CLIP_RECT, - CLIP_PATH, - }; - - void RecordCloser(Closer); - const PaintContext& context_; - // If someone needs to do more than this many operations with a single - // ClipRecorder then we'll increase this. - enum : int { kMaxOpCount = 4 }; - Closer closers_[kMaxOpCount]; - int num_closers_; + int num_closers_ = 0; DISALLOW_COPY_AND_ASSIGN(ClipRecorder); }; diff --git a/chromium/ui/compositor/compositing_recorder.cc b/chromium/ui/compositor/compositing_recorder.cc index d6bfe3d251f..4270342a13a 100644 --- a/chromium/ui/compositor/compositing_recorder.cc +++ b/chromium/ui/compositor/compositing_recorder.cc @@ -4,8 +4,8 @@ #include "ui/compositor/compositing_recorder.h" -#include "cc/paint/compositing_display_item.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" @@ -19,16 +19,19 @@ CompositingRecorder::CompositingRecorder(const PaintContext& context, if (!saved_) return; - context_.list_->CreateAndAppendPairedBeginItem( - alpha, SkBlendMode::kSrcOver, nullptr /* no bounds */, - nullptr /* no color filter */, lcd_text_requires_opaque_layer); + cc::PaintOpBuffer* buffer = context_.list_->StartPaint(); + buffer->push(nullptr, alpha, + !lcd_text_requires_opaque_layer); + context_.list_->EndPaintOfPairedBegin(); } CompositingRecorder::~CompositingRecorder() { if (!saved_) return; - context_.list_->CreateAndAppendPairedEndItem(); + cc::PaintOpBuffer* buffer = context_.list_->StartPaint(); + buffer->push(); + context_.list_->EndPaintOfPairedEnd(); } } // namespace ui diff --git a/chromium/ui/compositor/compositor.cc b/chromium/ui/compositor/compositor.cc index 8ddeb888fe3..70eab90261e 100644 --- a/chromium/ui/compositor/compositor.cc +++ b/chromium/ui/compositor/compositor.cc @@ -15,6 +15,7 @@ #include "base/message_loop/message_loop.h" #include "base/metrics/histogram_macros.h" #include "base/stl_util.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/sys_info.h" @@ -27,13 +28,15 @@ #include "cc/input/input_handler.h" #include "cc/layers/layer.h" #include "cc/output/begin_frame_args.h" -#include "cc/output/context_provider.h" #include "cc/output/latency_info_swap_promise.h" #include "cc/scheduler/begin_frame_source.h" -#include "cc/surfaces/local_surface_id_allocator.h" -#include "cc/surfaces/surface_manager.h" #include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_settings.h" +#include "components/viz/common/gpu/context_provider.h" +#include "components/viz/common/quads/resource_format.h" +#include "components/viz/common/resources/resource_settings.h" +#include "components/viz/common/surfaces/local_surface_id_allocator.h" +#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/compositor/compositor_observer.h" #include "ui/compositor/compositor_switches.h" @@ -43,16 +46,18 @@ #include "ui/compositor/layer_animator_collection.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/display/display_switches.h" +#include "ui/gfx/color_space_switches.h" #include "ui/gfx/icc_profile.h" #include "ui/gfx/switches.h" #include "ui/gl/gl_switches.h" namespace ui { -Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, +Compositor::Compositor(const viz::FrameSinkId& frame_sink_id, ui::ContextFactory* context_factory, ui::ContextFactoryPrivate* context_factory_private, - scoped_refptr task_runner) + scoped_refptr task_runner, + bool enable_surface_synchronization) : context_factory_(context_factory), context_factory_private_(context_factory_private), frame_sink_id_(frame_sink_id), @@ -64,8 +69,9 @@ Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, weak_ptr_factory_(this), lock_timeout_weak_ptr_factory_(this) { if (context_factory_private) { - context_factory_private->GetSurfaceManager()->RegisterFrameSinkId( - frame_sink_id_); + context_factory_private->GetFrameSinkManager() + ->surface_manager() + ->RegisterFrameSinkId(frame_sink_id_); } root_web_layer_ = cc::Layer::Create(); @@ -79,10 +85,18 @@ Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, settings.layers_always_allowed_lcd_text = true; // Use occlusion to allow more overlapping windows to take less memory. settings.use_occlusion_for_tile_prioritization = true; - refresh_rate_ = settings.renderer_settings.refresh_rate = - context_factory_->GetRefreshRate(); + refresh_rate_ = context_factory_->GetRefreshRate(); settings.main_frame_before_activation_enabled = false; + if (command_line->HasSwitch(switches::kLimitFps)) { + std::string fps_str = + command_line->GetSwitchValueASCII(switches::kLimitFps); + double fps; + if (base::StringToDouble(fps_str, &fps) && fps > 0) { + forced_refresh_rate_ = fps; + } + } + if (command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders)) { std::string layer_borders_string = command_line->GetSwitchValueASCII( cc::switches::kUIShowCompositedLayerBorders); @@ -125,8 +139,7 @@ Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, settings.initial_debug_state.SetRecordRenderingStats( command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); - settings.enable_surface_synchronization = - command_line->HasSwitch(cc::switches::kEnableSurfaceSynchronization); + settings.enable_surface_synchronization = enable_surface_synchronization; settings.use_zero_copy = IsUIZeroCopyEnabled(); @@ -134,12 +147,16 @@ Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, command_line->HasSwitch(cc::switches::kUIEnableLayerLists); settings.enable_color_correct_rasterization = - command_line->HasSwitch(switches::kEnableColorCorrectRendering); + base::FeatureList::IsEnabled(features::kColorCorrectRendering); // UI compositor always uses partial raster if not using zero-copy. Zero copy // doesn't currently support partial raster. settings.use_partial_raster = !settings.use_zero_copy; + if (command_line->HasSwitch(switches::kUIEnableRGBA4444Textures)) + settings.preferred_tile_format = viz::RGBA_4444; + settings.resource_settings = context_factory_->GetResourceSettings(); + settings.gpu_memory_policy.bytes_limit_when_visible = 512 * 1024 * 1024; settings.gpu_memory_policy.priority_cutoff_when_visible = gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; @@ -147,9 +164,6 @@ Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, settings.disallow_non_exact_resource_reuse = command_line->HasSwitch(cc::switches::kDisallowNonExactResourceReuse); - // TODO(staraz): LayerTreeSettings shouldn't have a RendererSettings. - settings.renderer_settings = context_factory_->GetRendererSettings(); - base::TimeTicks before_create = base::TimeTicks::Now(); animation_host_ = cc::AnimationHost::CreateMainInstance(); @@ -199,12 +213,12 @@ Compositor::~Compositor() { context_factory_->RemoveCompositor(this); if (context_factory_private_) { - auto* manager = context_factory_private_->GetSurfaceManager(); + auto* manager = context_factory_private_->GetFrameSinkManager(); for (auto& client : child_frame_sinks_) { DCHECK(client.is_valid()); manager->UnregisterFrameSinkHierarchy(frame_sink_id_, client); } - manager->InvalidateFrameSinkId(frame_sink_id_); + manager->surface_manager()->InvalidateFrameSinkId(frame_sink_id_); } } @@ -212,33 +226,34 @@ bool Compositor::IsForSubframe() { return false; } -void Compositor::AddFrameSink(const cc::FrameSinkId& frame_sink_id) { +void Compositor::AddFrameSink(const viz::FrameSinkId& frame_sink_id) { if (!context_factory_private_) return; - context_factory_private_->GetSurfaceManager()->RegisterFrameSinkHierarchy( + context_factory_private_->GetFrameSinkManager()->RegisterFrameSinkHierarchy( frame_sink_id_, frame_sink_id); child_frame_sinks_.insert(frame_sink_id); } -void Compositor::RemoveFrameSink(const cc::FrameSinkId& frame_sink_id) { +void Compositor::RemoveFrameSink(const viz::FrameSinkId& frame_sink_id) { if (!context_factory_private_) return; auto it = child_frame_sinks_.find(frame_sink_id); DCHECK(it != child_frame_sinks_.end()); DCHECK(it->is_valid()); - context_factory_private_->GetSurfaceManager()->UnregisterFrameSinkHierarchy( + context_factory_private_->GetFrameSinkManager()->UnregisterFrameSinkHierarchy( frame_sink_id_, *it); child_frame_sinks_.erase(it); } -void Compositor::SetLocalSurfaceId(const cc::LocalSurfaceId& local_surface_id) { +void Compositor::SetLocalSurfaceId( + const viz::LocalSurfaceId& local_surface_id) { host_->SetLocalSurfaceId(local_surface_id); } -void Compositor::SetCompositorFrameSink( - std::unique_ptr compositor_frame_sink) { - compositor_frame_sink_requested_ = false; - host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); +void Compositor::SetLayerTreeFrameSink( + std::unique_ptr layer_tree_frame_sink) { + layer_tree_frame_sink_requested_ = false; + host_->SetLayerTreeFrameSink(std::move(layer_tree_frame_sink)); // Display properties are reset when the output surface is lost, so update it // to match the Compositor's. if (context_factory_private_) { @@ -315,14 +330,14 @@ void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { } } -void Compositor::SetDisplayColorProfile(const gfx::ICCProfile& icc_profile) { - blending_color_space_ = icc_profile.GetColorSpace(); +void Compositor::SetDisplayColorSpace(const gfx::ColorSpace& color_space) { + blending_color_space_ = color_space; output_color_space_ = blending_color_space_; if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHDR)) { blending_color_space_ = gfx::ColorSpace::CreateExtendedSRGB(); output_color_space_ = gfx::ColorSpace::CreateSCRGBLinear(); } - host_->SetRasterColorSpace(icc_profile.GetParametricColorSpace()); + host_->SetRasterColorSpace(color_space.GetParametricApproximation()); // Color space is reset when the output surface is lost, so this must also be // updated then. // TODO(fsamuel): Get rid of this. @@ -371,6 +386,10 @@ void Compositor::SetAuthoritativeVSyncInterval( void Compositor::SetDisplayVSyncParameters(base::TimeTicks timebase, base::TimeDelta interval) { + if (forced_refresh_rate_) { + timebase = base::TimeTicks(); + interval = base::TimeDelta::FromSeconds(1) / forced_refresh_rate_; + } if (interval.is_zero()) { // TODO(brianderson): We should not be receiving 0 intervals. interval = cc::BeginFrameArgs::DefaultInterval(); @@ -391,13 +410,13 @@ void Compositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) { DCHECK(!widget_valid_); widget_ = widget; widget_valid_ = true; - if (compositor_frame_sink_requested_) - context_factory_->CreateCompositorFrameSink(weak_ptr_factory_.GetWeakPtr()); + if (layer_tree_frame_sink_requested_) + context_factory_->CreateLayerTreeFrameSink(weak_ptr_factory_.GetWeakPtr()); } gfx::AcceleratedWidget Compositor::ReleaseAcceleratedWidget() { DCHECK(!IsVisible()); - host_->ReleaseCompositorFrameSink(); + host_->ReleaseLayerTreeFrameSink(); context_factory_->RemoveCompositor(this); widget_valid_ = false; gfx::AcceleratedWidget widget = widget_; @@ -466,15 +485,15 @@ void Compositor::UpdateLayerTreeHost() { SendDamagedRectsRecursive(root_layer()); } -void Compositor::RequestNewCompositorFrameSink() { - DCHECK(!compositor_frame_sink_requested_); - compositor_frame_sink_requested_ = true; +void Compositor::RequestNewLayerTreeFrameSink() { + DCHECK(!layer_tree_frame_sink_requested_); + layer_tree_frame_sink_requested_ = true; if (widget_valid_) - context_factory_->CreateCompositorFrameSink(weak_ptr_factory_.GetWeakPtr()); + context_factory_->CreateLayerTreeFrameSink(weak_ptr_factory_.GetWeakPtr()); } -void Compositor::DidFailToInitializeCompositorFrameSink() { - // The CompositorFrameSink should already be bound/initialized before being +void Compositor::DidFailToInitializeLayerTreeFrameSink() { + // The LayerTreeFrameSink should already be bound/initialized before being // given to // the Compositor. NOTREACHED(); diff --git a/chromium/ui/compositor/compositor.h b/chromium/ui/compositor/compositor.h index 54a104ae761..163fbb01646 100644 --- a/chromium/ui/compositor/compositor.h +++ b/chromium/ui/compositor/compositor.h @@ -18,9 +18,9 @@ #include "base/time/time.h" #include "build/build_config.h" #include "cc/output/begin_frame_args.h" -#include "cc/surfaces/surface_sequence.h" #include "cc/trees/layer_tree_host_client.h" #include "cc/trees/layer_tree_host_single_thread_client.h" +#include "components/viz/common/surfaces/surface_sequence.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/compositor/compositor_animation_observer.h" #include "ui/compositor/compositor_export.h" @@ -40,13 +40,10 @@ class SingleThreadTaskRunner; namespace cc { class AnimationHost; class AnimationTimeline; -class ContextProvider; class Layer; class LayerTreeDebugState; +class LayerTreeFrameSink; class LayerTreeHost; -class LocalSurfaceId; -class RendererSettings; -class SurfaceManager; class TaskGraphRunner; } @@ -60,6 +57,14 @@ namespace gpu { class GpuMemoryBufferManager; } +namespace viz { +class FrameSinkManagerImpl; +class ContextProvider; +class HostFrameSinkManager; +class LocalSurfaceId; +class ResourceSettings; +} + namespace ui { class Compositor; @@ -75,7 +80,7 @@ class COMPOSITOR_EXPORT ContextFactoryObserver { public: virtual ~ContextFactoryObserver() {} - // Notifies that the ContextProvider returned from + // Notifies that the viz::ContextProvider returned from // ui::ContextFactory::SharedMainThreadContextProvider was lost. When this // is called, the old resources (e.g. shared context, GL helper) still // exist, but are about to be destroyed. Getting a reference to those @@ -98,14 +103,17 @@ class COMPOSITOR_EXPORT ContextFactoryPrivate { virtual void RemoveReflector(Reflector* reflector) = 0; // Allocate a new client ID for the display compositor. - virtual cc::FrameSinkId AllocateFrameSinkId() = 0; + virtual viz::FrameSinkId AllocateFrameSinkId() = 0; - // Gets the surface manager. - virtual cc::SurfaceManager* GetSurfaceManager() = 0; + // Gets the frame sink manager. + virtual viz::FrameSinkManagerImpl* GetFrameSinkManager() = 0; + + // Gets the frame sink manager host instance. + virtual viz::HostFrameSinkManager* GetHostFrameSinkManager() = 0; // Inform the display corresponding to this compositor if it is visible. When // false it does not need to produce any frames. Visibility is reset for each - // call to CreateCompositorFrameSink. + // call to CreateLayerTreeFrameSink. virtual void SetDisplayVisible(ui::Compositor* compositor, bool visible) = 0; // Resize the display corresponding to this compositor to a particular size. @@ -121,7 +129,7 @@ class COMPOSITOR_EXPORT ContextFactoryPrivate { virtual void SetAuthoritativeVSyncInterval(ui::Compositor* compositor, base::TimeDelta interval) = 0; // Mac path for transporting vsync parameters to the display. Other platforms - // update it via the BrowserCompositorCompositorFrameSink directly. + // update it via the BrowserCompositorLayerTreeFrameSink directly. virtual void SetDisplayVSyncParameters(ui::Compositor* compositor, base::TimeTicks timebase, base::TimeDelta interval) = 0; @@ -138,12 +146,12 @@ class COMPOSITOR_EXPORT ContextFactory { // Creates an output surface for the given compositor. The factory may keep // per-compositor data (e.g. a shared context), that needs to be cleaned up // by calling RemoveCompositor when the compositor gets destroyed. - virtual void CreateCompositorFrameSink( + virtual void CreateLayerTreeFrameSink( base::WeakPtr compositor) = 0; // Return a reference to a shared offscreen context provider usable from the // main thread. - virtual scoped_refptr + virtual scoped_refptr SharedMainThreadContextProvider() = 0; // Destroys per-compositor data. @@ -159,7 +167,7 @@ class COMPOSITOR_EXPORT ContextFactory { virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; // Gets the renderer settings. - virtual const cc::RendererSettings& GetRendererSettings() const = 0; + virtual const viz::ResourceSettings& GetResourceSettings() const = 0; virtual void AddObserver(ContextFactoryObserver* observer) = 0; @@ -176,10 +184,11 @@ class COMPOSITOR_EXPORT Compositor NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient), NON_EXPORTED_BASE(public CompositorLockDelegate) { public: - Compositor(const cc::FrameSinkId& frame_sink_id, + Compositor(const viz::FrameSinkId& frame_sink_id, ui::ContextFactory* context_factory, ui::ContextFactoryPrivate* context_factory_private, - scoped_refptr task_runner); + scoped_refptr task_runner, + bool enable_surface_synchronization); ~Compositor() override; ui::ContextFactory* context_factory() { return context_factory_; } @@ -188,12 +197,12 @@ class COMPOSITOR_EXPORT Compositor return context_factory_private_; } - void AddFrameSink(const cc::FrameSinkId& frame_sink_id); - void RemoveFrameSink(const cc::FrameSinkId& frame_sink_id); + void AddFrameSink(const viz::FrameSinkId& frame_sink_id); + void RemoveFrameSink(const viz::FrameSinkId& frame_sink_id); - void SetLocalSurfaceId(const cc::LocalSurfaceId& local_surface_id); + void SetLocalSurfaceId(const viz::LocalSurfaceId& local_surface_id); - void SetCompositorFrameSink(std::unique_ptr surface); + void SetLayerTreeFrameSink(std::unique_ptr surface); // Schedules a redraw of the layer tree associated with this compositor. void ScheduleDraw(); @@ -237,7 +246,7 @@ class COMPOSITOR_EXPORT Compositor void SetScaleAndSize(float scale, const gfx::Size& size_in_pixel); // Set the output color profile into which this compositor should render. - void SetDisplayColorProfile(const gfx::ICCProfile& icc_profile); + void SetDisplayColorSpace(const gfx::ColorSpace& color_space); // Returns the size of the widget that is being drawn to in pixel coordinates. const gfx::Size& size() const { return size_; } @@ -266,9 +275,8 @@ class COMPOSITOR_EXPORT Compositor void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval); // Most platforms set their vsync info via - // BrowerCompositorCompositorFrameSink's - // OnUpdateVSyncParametersFromGpu, but Mac routes vsync info via the - // browser compositor instead through this path. + // BrowerCompositorLayerTreeFrameSink::OnUpdateVSyncParametersFromGpu(), but + // Mac routes vsync info via the browser compositor instead through this path. void SetDisplayVSyncParameters(base::TimeTicks timebase, base::TimeDelta interval); @@ -333,9 +341,9 @@ class COMPOSITOR_EXPORT Compositor float top_controls_delta) override {} void RecordWheelAndTouchScrollingCount(bool has_scrolled_by_wheel, bool has_scrolled_by_touch) override {} - void RequestNewCompositorFrameSink() override; - void DidInitializeCompositorFrameSink() override {} - void DidFailToInitializeCompositorFrameSink() override; + void RequestNewLayerTreeFrameSink() override; + void DidInitializeLayerTreeFrameSink() override {} + void DidFailToInitializeLayerTreeFrameSink() override; void WillCommit() override {} void DidCommit() override; void DidCommitAndDrawFrame() override {} @@ -346,7 +354,7 @@ class COMPOSITOR_EXPORT Compositor // cc::LayerTreeHostSingleThreadClient implementation. void DidSubmitCompositorFrame() override; - void DidLoseCompositorFrameSink() override {} + void DidLoseLayerTreeFrameSink() override {} bool IsLocked() { return !active_locks_.empty(); } @@ -359,7 +367,7 @@ class COMPOSITOR_EXPORT Compositor return &layer_animator_collection_; } - const cc::FrameSinkId& frame_sink_id() const { return frame_sink_id_; } + const viz::FrameSinkId& frame_sink_id() const { return frame_sink_id_; } int activated_frame_count() const { return activated_frame_count_; } float refresh_rate() const { return refresh_rate_; } @@ -394,11 +402,14 @@ class COMPOSITOR_EXPORT Compositor // Current vsync refresh rate per second. float refresh_rate_ = 0.f; + // If nonzero, this is the refresh rate forced from the command-line. + double forced_refresh_rate_ = 0.f; + // A map from child id to parent id. - std::unordered_set child_frame_sinks_; + std::unordered_set child_frame_sinks_; bool widget_valid_ = false; - bool compositor_frame_sink_requested_ = false; - const cc::FrameSinkId frame_sink_id_; + bool layer_tree_frame_sink_requested_ = false; + const viz::FrameSinkId frame_sink_id_; scoped_refptr root_web_layer_; std::unique_ptr animation_host_; std::unique_ptr host_; diff --git a/chromium/ui/compositor/compositor_switches.cc b/chromium/ui/compositor/compositor_switches.cc index 2a999a81a50..991aba5e0ef 100644 --- a/chromium/ui/compositor/compositor_switches.cc +++ b/chromium/ui/compositor/compositor_switches.cc @@ -17,6 +17,10 @@ const char kEnableHardwareOverlays[] = "enable-hardware-overlays"; // Forces tests to produce pixel output when they normally wouldn't. const char kEnablePixelOutputInTests[] = "enable-pixel-output-in-tests"; +// Limits the compositor to output a certain number of frames per second, +// maximum. +const char kLimitFps[] = "limit-fps"; + // Disable partial swap which is needed for some OpenGL drivers / emulators. const char kUIDisablePartialSwap[] = "ui-disable-partial-swap"; diff --git a/chromium/ui/compositor/compositor_switches.h b/chromium/ui/compositor/compositor_switches.h index 0cc31be97b3..54fc3354217 100644 --- a/chromium/ui/compositor/compositor_switches.h +++ b/chromium/ui/compositor/compositor_switches.h @@ -11,6 +11,7 @@ namespace switches { COMPOSITOR_EXPORT extern const char kEnableHardwareOverlays[]; COMPOSITOR_EXPORT extern const char kEnablePixelOutputInTests[]; +COMPOSITOR_EXPORT extern const char kLimitFps[]; COMPOSITOR_EXPORT extern const char kUIDisablePartialSwap[]; COMPOSITOR_EXPORT extern const char kUIEnableRGBA4444Textures[]; COMPOSITOR_EXPORT extern const char kUIEnableZeroCopy[]; diff --git a/chromium/ui/compositor/compositor_unittest.cc b/chromium/ui/compositor/compositor_unittest.cc index de08460d4f5..12fa0ba4974 100644 --- a/chromium/ui/compositor/compositor_unittest.cc +++ b/chromium/ui/compositor/compositor_unittest.cc @@ -10,9 +10,9 @@ #include "base/test/test_mock_time_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "cc/output/begin_frame_args.h" -#include "cc/surfaces/local_surface_id_allocator.h" #include "cc/surfaces/surface_manager.h" #include "cc/test/begin_frame_args_test.h" +#include "components/viz/common/surfaces/local_surface_id_allocator.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/compositor/compositor.h" @@ -39,7 +39,8 @@ class CompositorTest : public testing::Test { compositor_.reset(new ui::Compositor( context_factory_private->AllocateFrameSinkId(), context_factory, - context_factory_private, CreateTaskRunner())); + context_factory_private, CreateTaskRunner(), + false /* enable_surface_synchronization */)); compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); } diff --git a/chromium/ui/compositor/compositor_util.cc b/chromium/ui/compositor/compositor_util.cc index 39109bc92db..91b254340c0 100644 --- a/chromium/ui/compositor/compositor_util.cc +++ b/chromium/ui/compositor/compositor_util.cc @@ -6,16 +6,16 @@ #include "base/command_line.h" #include "cc/base/switches.h" -#include "cc/output/renderer_settings.h" +#include "components/viz/common/display/renderer_settings.h" #include "ui/compositor/compositor_switches.h" #include "ui/display/display_switches.h" -#include "ui/gfx/switches.h" +#include "ui/gfx/color_space_switches.h" namespace ui { -cc::RendererSettings CreateRendererSettings(uint32_t ( - *get_texture_target)(gfx::BufferFormat format, gfx::BufferUsage usage)) { - cc::RendererSettings renderer_settings; +viz::RendererSettings CreateRendererSettings( + const viz::BufferToTextureTargetMap& image_targets) { + viz::RendererSettings renderer_settings; base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); renderer_settings.partial_swap_enabled = !command_line->HasSwitch(switches::kUIDisablePartialSwap); @@ -24,30 +24,21 @@ cc::RendererSettings CreateRendererSettings(uint32_t ( #elif defined(OS_MACOSX) renderer_settings.release_overlay_resources_after_gpu_query = true; #endif - renderer_settings.gl_composited_texture_quad_border = - command_line->HasSwitch(cc::switches::kGlCompositedTextureQuadBorder); + renderer_settings.gl_composited_overlay_candidate_quad_border = + command_line->HasSwitch( + cc::switches::kGlCompositedOverlayCandidateQuadBorder); renderer_settings.show_overdraw_feedback = command_line->HasSwitch(cc::switches::kShowOverdrawFeedback); - if (command_line->HasSwitch(switches::kUIEnableRGBA4444Textures)) - renderer_settings.preferred_tile_format = cc::RGBA_4444; renderer_settings.enable_color_correct_rendering = - command_line->HasSwitch(switches::kEnableColorCorrectRendering) || + base::FeatureList::IsEnabled(features::kColorCorrectRendering) || command_line->HasSwitch(switches::kEnableHDR); - // Populate buffer_to_texture_target_map for all buffer usage/formats. - for (int usage_idx = 0; usage_idx <= static_cast(gfx::BufferUsage::LAST); - ++usage_idx) { - gfx::BufferUsage usage = static_cast(usage_idx); - for (int format_idx = 0; - format_idx <= static_cast(gfx::BufferFormat::LAST); - ++format_idx) { - gfx::BufferFormat format = static_cast(format_idx); - renderer_settings - .buffer_to_texture_target_map[std::make_pair(usage, format)] = - get_texture_target(format, usage); - } - } + renderer_settings.resource_settings.buffer_to_texture_target_map = + image_targets; + renderer_settings.disallow_non_exact_resource_reuse = command_line->HasSwitch(cc::switches::kDisallowNonExactResourceReuse); + renderer_settings.allow_antialiasing = + !command_line->HasSwitch(cc::switches::kDisableCompositedAntialiasing); return renderer_settings; } diff --git a/chromium/ui/compositor/compositor_util.h b/chromium/ui/compositor/compositor_util.h index 9164dba93dc..1939514833f 100644 --- a/chromium/ui/compositor/compositor_util.h +++ b/chromium/ui/compositor/compositor_util.h @@ -7,17 +7,17 @@ #include +#include "components/viz/common/resources/buffer_to_texture_target_map.h" #include "ui/compositor/compositor_export.h" -#include "ui/gfx/buffer_types.h" -namespace cc { +namespace viz { class RendererSettings; } namespace ui { -COMPOSITOR_EXPORT cc::RendererSettings CreateRendererSettings(uint32_t ( - *get_texture_target)(gfx::BufferFormat format, gfx::BufferUsage usage)); +COMPOSITOR_EXPORT viz::RendererSettings CreateRendererSettings( + const viz::BufferToTextureTargetMap& image_targets); } // namespace ui diff --git a/chromium/ui/compositor/debug_utils.cc b/chromium/ui/compositor/debug_utils.cc index 3d4837e392d..75f3457671e 100644 --- a/chromium/ui/compositor/debug_utils.cc +++ b/chromium/ui/compositor/debug_utils.cc @@ -92,7 +92,7 @@ void PrintLayerHierarchyImp(const Layer* layer, *out << '\n' << property_indent_str; *out << "rotation: "; - *out << std::acos(decomp.quaternion[3]) * 360.0 / M_PI; + *out << std::acos(decomp.quaternion.w()) * 360.0 / M_PI; *out << '\n' << property_indent_str; *out << "scale: " << decomp.scale[0]; diff --git a/chromium/ui/compositor/layer.cc b/chromium/ui/compositor/layer.cc index b4a5242be76..d2248572c2a 100644 --- a/chromium/ui/compositor/layer.cc +++ b/chromium/ui/compositor/layer.cc @@ -92,11 +92,12 @@ Layer::Layer() visible_(true), fills_bounds_opaquely_(true), fills_bounds_completely_(false), - background_blur_radius_(0), + background_blur_sigma_(0.0f), layer_saturation_(0.0f), layer_brightness_(0.0f), layer_grayscale_(0.0f), layer_inverted_(false), + layer_blur_sigma_(0.0f), layer_temperature_(0.0f), layer_blue_scale_(1.0f), layer_green_scale_(1.0f), @@ -118,11 +119,12 @@ Layer::Layer(LayerType type) visible_(true), fills_bounds_opaquely_(true), fills_bounds_completely_(false), - background_blur_radius_(0), + background_blur_sigma_(0.0f), layer_saturation_(0.0f), layer_brightness_(0.0f), layer_grayscale_(0.0f), layer_inverted_(false), + layer_blur_sigma_(0.0f), layer_temperature_(0.0f), layer_blue_scale_(1.0f), layer_green_scale_(1.0f), @@ -165,7 +167,7 @@ std::unique_ptr Layer::Clone() const { auto clone = base::MakeUnique(type_); // Background filters. - clone->SetBackgroundBlur(background_blur_radius_); + clone->SetBackgroundBlur(background_blur_sigma_); clone->SetBackgroundZoom(zoom_, zoom_inset_); // Filters. @@ -174,13 +176,18 @@ std::unique_ptr Layer::Clone() const { clone->SetLayerBrightness(GetTargetBrightness()); clone->SetLayerGrayscale(GetTargetGrayscale()); clone->SetLayerInverted(layer_inverted_); + clone->SetLayerBlur(layer_blur_sigma_); if (alpha_shape_) clone->SetAlphaShape(base::MakeUnique(*alpha_shape_)); // cc::Layer state. - if (surface_layer_ && surface_layer_->primary_surface_info().is_valid()) { - clone->SetShowPrimarySurface(surface_layer_->primary_surface_info(), - surface_layer_->surface_reference_factory()); + if (surface_layer_) { + if (surface_layer_->primary_surface_info().is_valid()) { + clone->SetShowPrimarySurface(surface_layer_->primary_surface_info(), + surface_layer_->surface_reference_factory()); + } + if (surface_layer_->fallback_surface_info().is_valid()) + clone->SetFallbackSurface(surface_layer_->fallback_surface_info()); } else if (type_ == LAYER_SOLID_COLOR) { clone->SetColor(GetTargetColor()); } @@ -391,12 +398,18 @@ float Layer::GetTargetTemperature() const { return layer_temperature(); } -void Layer::SetBackgroundBlur(int blur_radius) { - background_blur_radius_ = blur_radius; +void Layer::SetBackgroundBlur(float blur_sigma) { + background_blur_sigma_ = blur_sigma; SetLayerBackgroundFilters(); } +void Layer::SetLayerBlur(float blur_sigma) { + layer_blur_sigma_ = blur_sigma; + + SetLayerFilters(); +} + void Layer::SetLayerSaturation(float saturation) { layer_saturation_ = saturation; SetLayerFilters(); @@ -488,6 +501,10 @@ void Layer::SetLayerFilters() { } if (layer_inverted_) filters.Append(cc::FilterOperation::CreateInvertFilter(1.0)); + if (layer_blur_sigma_) { + filters.Append(cc::FilterOperation::CreateBlurFilter( + layer_blur_sigma_, SkBlurImageFilter::kClamp_TileMode)); + } // Brightness goes last, because the resulting colors neeed clamping, which // cause further color matrix filters to be applied separately. In this order, // they all can be combined in a single pass. @@ -508,9 +525,9 @@ void Layer::SetLayerBackgroundFilters() { if (zoom_ != 1) filters.Append(cc::FilterOperation::CreateZoomFilter(zoom_, zoom_inset_)); - if (background_blur_radius_) { + if (background_blur_sigma_) { filters.Append(cc::FilterOperation::CreateBlurFilter( - background_blur_radius_)); + background_blur_sigma_, SkBlurImageFilter::kClamp_TileMode)); } cc_layer_->SetBackgroundFilters(filters); @@ -610,6 +627,7 @@ void Layer::SwitchToLayer(scoped_refptr new_layer) { new_layer->SetTransform(cc_layer_->transform()); new_layer->SetPosition(cc_layer_->position()); new_layer->SetBackgroundColor(cc_layer_->background_color()); + new_layer->SetCacheRenderSurface(cc_layer_->cache_render_surface()); cc_layer_ = new_layer.get(); content_layer_ = NULL; @@ -638,8 +656,17 @@ void Layer::SwitchCCLayerForTest() { content_layer_ = new_layer; } +// Note: The code that sets this flag would be responsible to unset it on that +// ui::Layer. We do not want to clone this flag to a cloned layer by accident, +// which could be a supprise. But we want to preserve it after switching to a +// new cc::Layer. There could be a whole subtree and the root changed, but does +// not mean we want to treat the cache all different. +void Layer::SetCacheRenderSurface(bool cache_render_surface) { + cc_layer_->SetCacheRenderSurface(cache_render_surface); +} + void Layer::SetTextureMailbox( - const cc::TextureMailbox& mailbox, + const viz::TextureMailbox& mailbox, std::unique_ptr release_callback, gfx::Size texture_size_in_dip) { DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); @@ -682,8 +709,8 @@ bool Layer::TextureFlipped() const { } void Layer::SetShowPrimarySurface( - const cc::SurfaceInfo& surface_info, - scoped_refptr ref_factory) { + const viz::SurfaceInfo& surface_info, + scoped_refptr ref_factory) { DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); if (!surface_layer_) { @@ -703,7 +730,7 @@ void Layer::SetShowPrimarySurface( mirror->dest()->SetShowPrimarySurface(surface_info, ref_factory); } -void Layer::SetFallbackSurface(const cc::SurfaceInfo& surface_info) { +void Layer::SetFallbackSurface(const viz::SurfaceInfo& surface_info) { DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); DCHECK(surface_layer_); @@ -714,7 +741,7 @@ void Layer::SetFallbackSurface(const cc::SurfaceInfo& surface_info) { mirror->dest()->SetFallbackSurface(surface_info); } -const cc::SurfaceInfo* Layer::GetFallbackSurfaceInfo() const { +const viz::SurfaceInfo* Layer::GetFallbackSurfaceInfo() const { if (surface_layer_) return &surface_layer_->fallback_surface_info(); return nullptr; @@ -730,7 +757,7 @@ void Layer::SetShowSolidColorContent() { SwitchToLayer(new_layer); solid_color_layer_ = new_layer; - mailbox_ = cc::TextureMailbox(); + mailbox_ = viz::TextureMailbox(); if (mailbox_release_callback_) { mailbox_release_callback_->Run(gpu::SyncToken(), false); mailbox_release_callback_.reset(); @@ -868,11 +895,13 @@ void Layer::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) { delegate_->OnDelegatedFrameDamage(damage_rect_in_dip); } -void Layer::SetScrollable( - Layer* parent_clip_layer, - const base::Callback& on_scroll) { - cc_layer_->SetScrollClipLayerId(parent_clip_layer->cc_layer_->id()); - cc_layer_->set_did_scroll_callback(on_scroll); +void Layer::SetDidScrollCallback( + base::Callback callback) { + cc_layer_->set_did_scroll_callback(std::move(callback)); +} + +void Layer::SetScrollable(const gfx::Size& container_bounds) { + cc_layer_->SetScrollable(container_bounds); cc_layer_->SetUserScrollable(true, true); } @@ -934,7 +963,7 @@ size_t Layer::GetApproximateUnsharedMemoryUsage() const { } bool Layer::PrepareTextureMailbox( - cc::TextureMailbox* mailbox, + viz::TextureMailbox* mailbox, std::unique_ptr* release_callback) { if (!mailbox_release_callback_) return false; diff --git a/chromium/ui/compositor/layer.h b/chromium/ui/compositor/layer.h index a439bbdf1e5..e89acf51120 100644 --- a/chromium/ui/compositor/layer.h +++ b/chromium/ui/compositor/layer.h @@ -21,8 +21,8 @@ #include "cc/layers/layer_client.h" #include "cc/layers/surface_layer.h" #include "cc/layers/texture_layer_client.h" -#include "cc/resources/texture_mailbox.h" -#include "cc/surfaces/sequence_surface_reference_factory.h" +#include "components/viz/common/quads/texture_mailbox.h" +#include "components/viz/common/surfaces/sequence_surface_reference_factory.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkRegion.h" #include "ui/compositor/compositor.h" @@ -40,8 +40,6 @@ class NinePatchLayer; class SolidColorLayer; class SurfaceLayer; class TextureLayer; -struct ReturnedResource; -typedef std::vector ReturnedResourceArray; } namespace ui { @@ -195,10 +193,14 @@ class COMPOSITOR_EXPORT Layer // temperature otherwise. float GetTargetTemperature() const; - // Blur pixels by this amount in anything below the layer and visible through - // the layer. - int background_blur() const { return background_blur_radius_; } - void SetBackgroundBlur(int blur_radius); + // Blur pixels by 3 * this amount in anything below the layer and visible + // through the layer. + float background_blur() const { return background_blur_sigma_; } + void SetBackgroundBlur(float blur_sigma); + + // Blur pixels of this layer by 3 * this amount. + float layer_blur() const { return layer_blur_sigma_; } + void SetLayerBlur(float blur_sigma); // Saturate all pixels of this layer by this amount. // This effect will get "combined" with the inverted, @@ -296,7 +298,7 @@ class COMPOSITOR_EXPORT Layer // Set new TextureMailbox for this layer. Note that |mailbox| may hold a // shared memory resource or an actual mailbox for a texture. void SetTextureMailbox( - const cc::TextureMailbox& mailbox, + const viz::TextureMailbox& mailbox, std::unique_ptr release_callback, gfx::Size texture_size_in_dip); void SetTextureSize(gfx::Size texture_size_in_dip); @@ -305,15 +307,15 @@ class COMPOSITOR_EXPORT Layer // Begins showing content from a surface with a particular ID. void SetShowPrimarySurface( - const cc::SurfaceInfo& surface_info, - scoped_refptr surface_ref); + const viz::SurfaceInfo& surface_info, + scoped_refptr surface_ref); // In the event that the primary surface is not yet available in the // display compositor, the fallback surface will be used. - void SetFallbackSurface(const cc::SurfaceInfo& surface_info); + void SetFallbackSurface(const viz::SurfaceInfo& surface_info); // Returns the fallback SurfaceInfo set by SetFallbackSurface. - const cc::SurfaceInfo* GetFallbackSurfaceInfo() const; + const viz::SurfaceInfo* GetFallbackSurfaceInfo() const; bool has_external_content() { return texture_layer_.get() || surface_layer_.get(); @@ -366,11 +368,15 @@ class COMPOSITOR_EXPORT Layer // Requets a copy of the layer's output as a texture or bitmap. void RequestCopyOfOutput(std::unique_ptr request); - // Makes this Layer scrollable, clipping to |parent_clip_layer|. |on_scroll| - // is invoked when scrolling performed by the cc::InputHandler is committed. - void SetScrollable( - Layer* parent_clip_layer, - const base::Callback& on_scroll); + // Invoked when scrolling performed by the cc::InputHandler is committed. This + // will only occur if the Layer has set scroll container bounds. + void SetDidScrollCallback( + base::Callback callback); + + // Marks this layer as scrollable inside the provided bounds. This size only + // affects scrolling so if clipping is desired, a separate clipping layer + // needs to be created. + void SetScrollable(const gfx::Size& container_bounds); // Gets and sets the current scroll offset of the layer. gfx::ScrollOffset CurrentScrollOffset() const; @@ -387,7 +393,7 @@ class COMPOSITOR_EXPORT Layer // TextureLayerClient bool PrepareTextureMailbox( - cc::TextureMailbox* mailbox, + viz::TextureMailbox* mailbox, std::unique_ptr* release_callback) override; float device_scale_factor() const { return device_scale_factor_; } @@ -409,6 +415,12 @@ class COMPOSITOR_EXPORT Layer return frame_size_in_dip_; } + // Force use of and cache render surface. Note that this also disables + // occlusion culling in favor of efficient caching. This should + // only be used when paying the cost of creating a render + // surface even if layer is invisible is not a problem. + void SetCacheRenderSurface(bool cache_render_surface); + private: friend class LayerOwner; class LayerMirror; @@ -501,7 +513,7 @@ class COMPOSITOR_EXPORT Layer // to paint the content. cc::Region paint_region_; - int background_blur_radius_; + float background_blur_sigma_; // Several variables which will change the visible representation of // the layer. @@ -509,6 +521,7 @@ class COMPOSITOR_EXPORT Layer float layer_brightness_; float layer_grayscale_; bool layer_inverted_; + float layer_blur_sigma_; // The global color temperature value (0.0f ~ 1.0f). Used to calculate the // layer blue and green colors scales. 0.0f is least warm (default), and 1.0f @@ -563,7 +576,7 @@ class COMPOSITOR_EXPORT Layer gfx::Rect nine_patch_layer_aperture_; // The mailbox used by texture_layer_. - cc::TextureMailbox mailbox_; + viz::TextureMailbox mailbox_; // The callback to release the mailbox. This is only set after // SetTextureMailbox is called, before we give it to the TextureLayer. diff --git a/chromium/ui/compositor/layer_animator.cc b/chromium/ui/compositor/layer_animator.cc index 851d0204a31..09e5b17f16c 100644 --- a/chromium/ui/compositor/layer_animator.cc +++ b/chromium/ui/compositor/layer_animator.cc @@ -215,11 +215,6 @@ void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { case REPLACE_QUEUED_ANIMATIONS: ReplaceQueuedAnimations(animation); break; - case BLEND_WITH_CURRENT_ANIMATION: { - // TODO(vollick) Add support for blended sequences and use them here. - NOTIMPLEMENTED(); - break; - } } } FinishAnyAnimationWithZeroDuration(); diff --git a/chromium/ui/compositor/layer_animator.h b/chromium/ui/compositor/layer_animator.h index 11db8c5419a..19dc61dad58 100644 --- a/chromium/ui/compositor/layer_animator.h +++ b/chromium/ui/compositor/layer_animator.h @@ -62,8 +62,7 @@ class COMPOSITOR_EXPORT LayerAnimator IMMEDIATELY_SET_NEW_TARGET, IMMEDIATELY_ANIMATE_TO_NEW_TARGET, ENQUEUE_NEW_ANIMATION, - REPLACE_QUEUED_ANIMATIONS, - BLEND_WITH_CURRENT_ANIMATION + REPLACE_QUEUED_ANIMATIONS }; explicit LayerAnimator(base::TimeDelta transition_duration); diff --git a/chromium/ui/compositor/layer_owner_unittest.cc b/chromium/ui/compositor/layer_owner_unittest.cc index ecf2dd233f1..94992e09755 100644 --- a/chromium/ui/compositor/layer_owner_unittest.cc +++ b/chromium/ui/compositor/layer_owner_unittest.cc @@ -78,9 +78,10 @@ void LayerOwnerTestWithCompositor::SetUp() { ui::InitializeContextFactoryForTests(false, &context_factory, &context_factory_private); - compositor_.reset(new ui::Compositor( - context_factory_private->AllocateFrameSinkId(), context_factory, - context_factory_private, task_runner)); + compositor_.reset( + new ui::Compositor(context_factory_private->AllocateFrameSinkId(), + context_factory, context_factory_private, task_runner, + false /* enable_surface_synchronization */)); compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); } diff --git a/chromium/ui/compositor/layer_unittest.cc b/chromium/ui/compositor/layer_unittest.cc index f847d75f647..fbb15a8e4eb 100644 --- a/chromium/ui/compositor/layer_unittest.cc +++ b/chromium/ui/compositor/layer_unittest.cc @@ -26,11 +26,11 @@ #include "cc/layers/layer.h" #include "cc/output/copy_output_request.h" #include "cc/output/copy_output_result.h" -#include "cc/surfaces/sequence_surface_reference_factory.h" -#include "cc/surfaces/surface_id.h" -#include "cc/surfaces/surface_reference_factory.h" -#include "cc/surfaces/surface_sequence.h" #include "cc/test/pixel_test_utils.h" +#include "components/viz/common/surfaces/sequence_surface_reference_factory.h" +#include "components/viz/common/surfaces/surface_id.h" +#include "components/viz/common/surfaces/surface_reference_factory.h" +#include "components/viz/common/surfaces/surface_sequence.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/khronos/GLES2/gl2.h" #include "ui/compositor/compositor_observer.h" @@ -199,7 +199,7 @@ class LayerWithRealCompositorTest : public testing::Test { scoped_refptr holder(new ReadbackHolder); std::unique_ptr request = cc::CopyOutputRequest::CreateBitmapRequest( - base::Bind(&ReadbackHolder::OutputRequestCallback, holder)); + base::BindOnce(&ReadbackHolder::OutputRequestCallback, holder)); request->set_area(source_rect); GetCompositor()->root_layer()->RequestCopyOfOutput(std::move(request)); @@ -548,7 +548,7 @@ void ReturnMailbox(bool* run, const gpu::SyncToken& sync_token, bool is_lost) { TEST(LayerStandaloneTest, ReleaseMailboxOnDestruction) { std::unique_ptr layer(new Layer(LAYER_TEXTURED)); bool callback_run = false; - cc::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); + viz::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); layer->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( base::Bind(ReturnMailbox, &callback_run)), @@ -735,6 +735,7 @@ TEST_F(LayerWithDelegateTest, Cloning) { layer->SetLayerInverted(true); const float temperature = 0.8f; layer->SetLayerTemperature(temperature); + layer->SetCacheRenderSurface(true); auto clone = layer->Clone(); @@ -744,6 +745,9 @@ TEST_F(LayerWithDelegateTest, Cloning) { EXPECT_EQ(SK_ColorRED, clone->GetTargetColor()); EXPECT_TRUE(clone->layer_inverted()); EXPECT_FLOAT_EQ(temperature, clone->GetTargetTemperature()); + // Cloning should not preserve cache_render_surface flag. + EXPECT_NE(layer->cc_layer_for_testing()->cache_render_surface(), + clone->cc_layer_for_testing()->cache_render_surface()); layer->SetTransform(gfx::Transform()); layer->SetColor(SK_ColorGREEN); @@ -939,7 +943,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { cc::Layer* before_layer = l1->cc_layer_for_testing(); bool callback1_run = false; - cc::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); + viz::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( base::Bind(ReturnMailbox, &callback1_run)), gfx::Size(10, 10)); @@ -954,7 +958,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { EXPECT_FALSE(callback1_run); bool callback2_run = false; - mailbox = cc::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); + mailbox = viz::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( base::Bind(ReturnMailbox, &callback2_run)), gfx::Size(10, 10)); @@ -974,7 +978,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { // Back to a texture, without changing the bounds of the layer or the texture. bool callback3_run = false; - mailbox = cc::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); + mailbox = viz::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( base::Bind(ReturnMailbox, &callback3_run)), gfx::Size(10, 10)); @@ -1128,8 +1132,8 @@ TEST_F(LayerWithNullDelegateTest, EmptyDamagedRect) { base::Unretained(&run_loop)); std::unique_ptr root(CreateLayer(LAYER_SOLID_COLOR)); - cc::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), - GL_TEXTURE_2D); + viz::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), + GL_TEXTURE_2D); root->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create(callback), gfx::Size(10, 10)); compositor()->SetRootLayer(root.get()); @@ -1734,7 +1738,8 @@ TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { namespace { -class TestSurfaceReferenceFactory : public cc::SequenceSurfaceReferenceFactory { +class TestSurfaceReferenceFactory + : public viz::SequenceSurfaceReferenceFactory { public: TestSurfaceReferenceFactory() = default; @@ -1742,9 +1747,9 @@ class TestSurfaceReferenceFactory : public cc::SequenceSurfaceReferenceFactory { ~TestSurfaceReferenceFactory() override = default; // cc::SequenceSurfaceReferenceFactory implementation: - void SatisfySequence(const cc::SurfaceSequence& seq) const override {} - void RequireSequence(const cc::SurfaceId& id, - const cc::SurfaceSequence& seq) const override {} + void SatisfySequence(const viz::SurfaceSequence& seq) const override {} + void RequireSequence(const viz::SurfaceId& id, + const viz::SurfaceSequence& seq) const override {} DISALLOW_COPY_AND_ASSIGN(TestSurfaceReferenceFactory); }; @@ -1770,7 +1775,7 @@ TEST_F(LayerWithDelegateTest, ExternalContent) { // Showing surface content changes the underlying cc layer. before = child->cc_layer_for_testing(); child->SetShowPrimarySurface( - cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), + viz::SurfaceInfo(viz::SurfaceId(), 1.0, gfx::Size(10, 10)), new TestSurfaceReferenceFactory()); EXPECT_TRUE(child->cc_layer_for_testing()); EXPECT_NE(before.get(), child->cc_layer_for_testing()); @@ -1784,13 +1789,13 @@ TEST_F(LayerWithDelegateTest, ExternalContent) { TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { std::unique_ptr layer(CreateLayer(LAYER_SOLID_COLOR)); - scoped_refptr reference_factory( + scoped_refptr reference_factory( new TestSurfaceReferenceFactory()); - cc::SurfaceId surface_id( - cc::FrameSinkId(0, 1), - cc::LocalSurfaceId(2, base::UnguessableToken::Create())); - cc::SurfaceInfo surface_info(surface_id, 1.0f, gfx::Size(10, 10)); + viz::SurfaceId surface_id( + viz::FrameSinkId(0, 1), + viz::LocalSurfaceId(2, base::UnguessableToken::Create())); + viz::SurfaceInfo surface_info(surface_id, 1.0f, gfx::Size(10, 10)); layer->SetShowPrimarySurface(surface_info, reference_factory); const auto mirror = layer->Mirror(); @@ -1801,9 +1806,9 @@ TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { EXPECT_EQ(surface_info, surface->primary_surface_info()); surface_id = - cc::SurfaceId(cc::FrameSinkId(1, 2), - cc::LocalSurfaceId(3, base::UnguessableToken::Create())); - cc::SurfaceInfo surface_info_2(surface_id, 2.0f, gfx::Size(20, 20)); + viz::SurfaceId(viz::FrameSinkId(1, 2), + viz::LocalSurfaceId(3, base::UnguessableToken::Create())); + viz::SurfaceInfo surface_info_2(surface_id, 2.0f, gfx::Size(20, 20)); layer->SetShowPrimarySurface(surface_info_2, reference_factory); // The mirror should continue to use the same cc_layer. @@ -1818,12 +1823,12 @@ TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { TEST_F(LayerWithDelegateTest, FrameSizeInDip) { std::unique_ptr layer(CreateLayer(LAYER_SOLID_COLOR)); - cc::SurfaceId surface_id( - cc::FrameSinkId(0, 1), - cc::LocalSurfaceId(2, base::UnguessableToken::Create())); + viz::SurfaceId surface_id( + viz::FrameSinkId(0, 1), + viz::LocalSurfaceId(2, base::UnguessableToken::Create())); layer->SetShowPrimarySurface( - cc::SurfaceInfo(surface_id, 2.0f, gfx::Size(30, 40)), + viz::SurfaceInfo(surface_id, 2.0f, gfx::Size(30, 40)), new TestSurfaceReferenceFactory()); EXPECT_EQ(layer->frame_size_in_dip_for_testing(), gfx::Size(15, 20)); @@ -1844,7 +1849,7 @@ TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { // Showing surface content changes the underlying cc layer. scoped_refptr before = layer->cc_layer_for_testing(); layer->SetShowPrimarySurface( - cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), + viz::SurfaceInfo(viz::SurfaceId(), 1.0, gfx::Size(10, 10)), new TestSurfaceReferenceFactory()); EXPECT_EQ(layer->layer_grayscale(), 0.5f); EXPECT_TRUE(layer->cc_layer_for_testing()); @@ -1993,6 +1998,23 @@ TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorWhileAnimating) { EXPECT_EQ(transparent, root->GetTargetColor()); } +// Tests that when a layer with cache_render_surface flag has its CC layer +// switched, that the cache_render_surface flag is maintained. +TEST_F(LayerWithRealCompositorTest, SwitchCCLayerCacheRenderSurface) { + std::unique_ptr root(CreateLayer(LAYER_TEXTURED)); + std::unique_ptr l1(CreateLayer(LAYER_TEXTURED)); + GetCompositor()->SetRootLayer(root.get()); + root->Add(l1.get()); + + l1->SetCacheRenderSurface(true); + + // Change l1's cc::Layer. + l1->SwitchCCLayerForTest(); + + // Ensure that the cache_render_surface flag is maintained. + EXPECT_TRUE(l1->cc_layer_for_testing()->cache_render_surface()); +} + // Tests that the animators in the layer tree is added to the // animator-collection when the root-layer is set to the compositor. TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) { @@ -2168,7 +2190,7 @@ TEST(LayerDelegateTest, DelegatedFrameDamage) { FrameDamageCheckingDelegate delegate; layer->set_delegate(&delegate); layer->SetShowPrimarySurface( - cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), + viz::SurfaceInfo(viz::SurfaceId(), 1.0, gfx::Size(10, 10)), new TestSurfaceReferenceFactory()); EXPECT_FALSE(delegate.delegated_frame_damage_called()); diff --git a/chromium/ui/compositor/paint_cache.cc b/chromium/ui/compositor/paint_cache.cc index afa9d99a508..417a1798083 100644 --- a/chromium/ui/compositor/paint_cache.cc +++ b/chromium/ui/compositor/paint_cache.cc @@ -5,6 +5,7 @@ #include "ui/compositor/paint_cache.h" #include "cc/paint/display_item_list.h" +#include "cc/paint/paint_op_buffer.h" #include "ui/compositor/paint_context.h" namespace ui { @@ -16,17 +17,23 @@ PaintCache::~PaintCache() { bool PaintCache::UseCache(const PaintContext& context, const gfx::Size& size_in_context) { - if (!display_item_.has_value()) + if (!paint_op_buffer_) return false; DCHECK(context.list_); + cc::PaintOpBuffer* buffer = context.list_->StartPaint(); + buffer->push(paint_op_buffer_); gfx::Rect bounds_in_layer = context.ToLayerSpaceBounds(size_in_context); - context.list_->CreateAndAppendDrawingItem( - bounds_in_layer, *display_item_); + context.list_->EndPaintOfUnpaired(bounds_in_layer); return true; } -void PaintCache::SetCache(const cc::DrawingDisplayItem& item) { - display_item_.emplace(item); +cc::PaintOpBuffer* PaintCache::ResetCache() { + paint_op_buffer_ = sk_make_sp(); + return paint_op_buffer_.get(); +} + +void PaintCache::FinalizeCache() { + paint_op_buffer_->ShrinkToFit(); } } // namespace ui diff --git a/chromium/ui/compositor/paint_cache.h b/chromium/ui/compositor/paint_cache.h index efff00930d9..c32e96e54dd 100644 --- a/chromium/ui/compositor/paint_cache.h +++ b/chromium/ui/compositor/paint_cache.h @@ -7,10 +7,14 @@ #include "base/macros.h" #include "base/optional.h" -#include "cc/paint/drawing_display_item.h" +#include "third_party/skia/include/core/SkRefCnt.h" #include "ui/compositor/compositor_export.h" #include "ui/gfx/geometry/rect.h" +namespace cc { +class PaintOpBuffer; +} + namespace ui { class PaintContext; class PaintRecorder; @@ -32,9 +36,16 @@ class COMPOSITOR_EXPORT PaintCache { // Only PaintRecorder can modify these. friend PaintRecorder; - void SetCache(const cc::DrawingDisplayItem& item); + // Resets the cache to be empty, and returns a PaintOpBuffer that is the new + // empty cache. Adding PaintOps to the buffer will put them in the cache. + cc::PaintOpBuffer* ResetCache(); + + // Call when done recording into the cache's PaintOpBuffer. + void FinalizeCache(); - base::Optional display_item_; + // Stored in an sk_sp because PaintOpBuffer requires this to append the cached + // items into it. + sk_sp paint_op_buffer_; DISALLOW_COPY_AND_ASSIGN(PaintCache); }; diff --git a/chromium/ui/compositor/paint_context.cc b/chromium/ui/compositor/paint_context.cc index 54a583d3ea1..b2b4fac54b3 100644 --- a/chromium/ui/compositor/paint_context.cc +++ b/chromium/ui/compositor/paint_context.cc @@ -12,8 +12,6 @@ PaintContext::PaintContext(cc::DisplayItemList* list, float device_scale_factor, const gfx::Rect& invalidation) : list_(list), - owned_recorder_(new cc::PaintRecorder), - recorder_(owned_recorder_.get()), device_scale_factor_(device_scale_factor), invalidation_(invalidation) { #if DCHECK_IS_ON() @@ -25,8 +23,6 @@ PaintContext::PaintContext(cc::DisplayItemList* list, PaintContext::PaintContext(const PaintContext& other, const gfx::Vector2d& offset) : list_(other.list_), - owned_recorder_(nullptr), - recorder_(other.recorder_), device_scale_factor_(other.device_scale_factor_), invalidation_(other.invalidation_), offset_(other.offset_ + offset) { @@ -39,8 +35,6 @@ PaintContext::PaintContext(const PaintContext& other, PaintContext::PaintContext(const PaintContext& other, CloneWithoutInvalidation c) : list_(other.list_), - owned_recorder_(nullptr), - recorder_(other.recorder_), device_scale_factor_(other.device_scale_factor_), invalidation_(), offset_(other.offset_) { diff --git a/chromium/ui/compositor/paint_context.h b/chromium/ui/compositor/paint_context.h index b9c51dd386a..bc17c50f46b 100644 --- a/chromium/ui/compositor/paint_context.h +++ b/chromium/ui/compositor/paint_context.h @@ -85,11 +85,6 @@ class COMPOSITOR_EXPORT PaintContext { gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; cc::DisplayItemList* list_; - std::unique_ptr owned_recorder_; - // A pointer to the |owned_recorder_| in this PaintContext, or in another one - // which this was copied from. We expect a copied-from PaintContext to outlive - // copies made from it. - cc::PaintRecorder* recorder_; // The device scale of the frame being painted. Used to determine which bitmap // resources to use in the frame. float device_scale_factor_; diff --git a/chromium/ui/compositor/paint_recorder.cc b/chromium/ui/compositor/paint_recorder.cc index 97d2b5c42ad..8a8c4c28caf 100644 --- a/chromium/ui/compositor/paint_recorder.cc +++ b/chromium/ui/compositor/paint_recorder.cc @@ -5,7 +5,6 @@ #include "ui/compositor/paint_recorder.h" #include "cc/paint/display_item_list.h" -#include "cc/paint/drawing_display_item.h" #include "cc/paint/paint_recorder.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "ui/compositor/paint_cache.h" @@ -17,13 +16,16 @@ namespace ui { // This class records a reference to the context, the canvas returned // by its recorder_, and the cache. Thus all 3 of these must remain // valid for the lifetime of this object. +// If a |cache| is provided, this records into the |cache|'s PaintOpBuffer +// directly, then appends that to the |context|. If not, then this records +// to the |context|'s PaintOpBuffer. PaintRecorder::PaintRecorder(const PaintContext& context, const gfx::Size& recording_size, PaintCache* cache) : context_(context), - canvas_(context.recorder_->beginRecording( - gfx::RectToSkRect(gfx::Rect(recording_size))), - context.device_scale_factor_), + record_canvas_(cache ? cache->ResetCache() : context_.list_->StartPaint(), + gfx::RectToSkRect(gfx::Rect(recording_size))), + canvas_(&record_canvas_, context.device_scale_factor_), cache_(cache), recording_size_(recording_size) { #if DCHECK_IS_ON() @@ -34,20 +36,22 @@ PaintRecorder::PaintRecorder(const PaintContext& context, PaintRecorder::PaintRecorder(const PaintContext& context, const gfx::Size& recording_size) - : PaintRecorder(context, recording_size, nullptr) { -} + : PaintRecorder(context, recording_size, nullptr) {} PaintRecorder::~PaintRecorder() { #if DCHECK_IS_ON() context_.inside_paint_recorder_ = false; #endif - gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); - const auto& item = - context_.list_->CreateAndAppendDrawingItem( - bounds_in_layer, context_.recorder_->finishRecordingAsPicture(), - gfx::RectToSkRect(gfx::Rect(recording_size_))); - if (cache_) - cache_->SetCache(item); + // If using cache, append what we've saved there to the PaintContext. + // Otherwise, the content is already stored in the PaintContext, and we can + // just close it. + if (cache_) { + cache_->FinalizeCache(); + cache_->UseCache(context_, recording_size_); + } else { + gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); + context_.list_->EndPaintOfUnpaired(bounds_in_layer); + } } } // namespace ui diff --git a/chromium/ui/compositor/paint_recorder.h b/chromium/ui/compositor/paint_recorder.h index c52c3f83847..3785c1bbc23 100644 --- a/chromium/ui/compositor/paint_recorder.h +++ b/chromium/ui/compositor/paint_recorder.h @@ -8,6 +8,7 @@ #include #include "base/macros.h" +#include "cc/paint/record_paint_canvas.h" #include "ui/compositor/compositor_export.h" #include "ui/gfx/canvas.h" #include "ui/gfx/geometry/rect.h" @@ -39,6 +40,7 @@ class COMPOSITOR_EXPORT PaintRecorder { private: const PaintContext& context_; + cc::RecordPaintCanvas record_canvas_; gfx::Canvas canvas_; PaintCache* cache_; gfx::Size recording_size_; diff --git a/chromium/ui/compositor/run_all_unittests.cc b/chromium/ui/compositor/run_all_unittests.cc index df9bb6826b0..e2f22adc452 100644 --- a/chromium/ui/compositor/run_all_unittests.cc +++ b/chromium/ui/compositor/run_all_unittests.cc @@ -4,11 +4,14 @@ #include "base/bind.h" #include "base/test/launcher/unit_test_launcher.h" +#include "mojo/edk/embedder/embedder.h" #include "ui/compositor/test/test_suite.h" int main(int argc, char** argv) { ui::test::CompositorTestSuite test_suite(argc, argv); + mojo::edk::Init(); + return base::LaunchUnitTests( argc, argv, base::Bind(&ui::test::CompositorTestSuite::Run, base::Unretained(&test_suite))); diff --git a/chromium/ui/compositor/test/test_compositor_host_ozone.cc b/chromium/ui/compositor/test/test_compositor_host_ozone.cc index 79b781230d4..97d33afa448 100644 --- a/chromium/ui/compositor/test/test_compositor_host_ozone.cc +++ b/chromium/ui/compositor/test/test_compositor_host_ozone.cc @@ -83,7 +83,8 @@ TestCompositorHostOzone::TestCompositorHostOzone( compositor_(context_factory_private->AllocateFrameSinkId(), context_factory, context_factory_private, - base::ThreadTaskRunnerHandle::Get()) {} + base::ThreadTaskRunnerHandle::Get(), + false /* enable_surface_synchronization */) {} TestCompositorHostOzone::~TestCompositorHostOzone() {} diff --git a/chromium/ui/compositor/transform_animation_curve_adapter.cc b/chromium/ui/compositor/transform_animation_curve_adapter.cc index a41df055258..0973c67abea 100644 --- a/chromium/ui/compositor/transform_animation_curve_adapter.cc +++ b/chromium/ui/compositor/transform_animation_curve_adapter.cc @@ -9,6 +9,16 @@ namespace ui { +namespace { + +static cc::TransformOperations WrapTransform(const gfx::Transform& transform) { + cc::TransformOperations operations; + operations.AppendMatrix(transform); + return operations; +} + +} // namespace + TransformAnimationCurveAdapter::TransformAnimationCurveAdapter( gfx::Tween::Type tween_type, gfx::Transform initial_value, @@ -16,10 +26,12 @@ TransformAnimationCurveAdapter::TransformAnimationCurveAdapter( base::TimeDelta duration) : tween_type_(tween_type), initial_value_(initial_value), + initial_wrapped_value_(WrapTransform(initial_value)), target_value_(target_value), + target_wrapped_value_(WrapTransform(target_value)), duration_(duration) { - gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_); - gfx::DecomposeTransform(&decomposed_target_value_, target_value_); + gfx::DecomposeTransform(&decomposed_initial_value_, initial_value); + gfx::DecomposeTransform(&decomposed_target_value_, target_value); } TransformAnimationCurveAdapter::TransformAnimationCurveAdapter( @@ -38,21 +50,19 @@ std::unique_ptr TransformAnimationCurveAdapter::Clone() tween_type_, initial_value_, target_value_, duration_)); } -gfx::Transform TransformAnimationCurveAdapter::GetValue( +cc::TransformOperations TransformAnimationCurveAdapter::GetValue( base::TimeDelta t) const { if (t >= duration_) - return target_value_; + return target_wrapped_value_; if (t <= base::TimeDelta()) - return initial_value_; + return initial_wrapped_value_; double progress = cc::TimeUtil::Divide(t, duration_); - gfx::DecomposedTransform to_return; - gfx::BlendDecomposedTransforms(&to_return, - decomposed_target_value_, - decomposed_initial_value_, - gfx::Tween::CalculateValue(tween_type_, - progress)); - return gfx::ComposeTransform(to_return); + gfx::DecomposedTransform to_return = gfx::BlendDecomposedTransforms( + decomposed_target_value_, decomposed_initial_value_, + gfx::Tween::CalculateValue(tween_type_, progress)); + + return WrapTransform(gfx::ComposeTransform(to_return)); } bool TransformAnimationCurveAdapter::AnimatedBoundsForBox( @@ -93,9 +103,10 @@ InverseTransformCurveAdapter::InverseTransformCurveAdapter( base::TimeDelta duration) : base_curve_(base_curve), initial_value_(initial_value), + initial_wrapped_value_(WrapTransform(initial_value)), duration_(duration) { effective_initial_value_ = - base_curve_.GetValue(base::TimeDelta()) * initial_value_; + base_curve_.GetValue(base::TimeDelta()).Apply() * initial_value_; } InverseTransformCurveAdapter::~InverseTransformCurveAdapter() { @@ -111,18 +122,20 @@ std::unique_ptr InverseTransformCurveAdapter::Clone() new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_)); } -gfx::Transform InverseTransformCurveAdapter::GetValue(base::TimeDelta t) const { +cc::TransformOperations InverseTransformCurveAdapter::GetValue( + base::TimeDelta t) const { if (t <= base::TimeDelta()) - return initial_value_; + return initial_wrapped_value_; - gfx::Transform base_transform = base_curve_.GetValue(t); + gfx::Transform base_transform = base_curve_.GetValue(t).Apply(); // Invert base gfx::Transform to_return(gfx::Transform::kSkipInitialization); bool is_invertible = base_transform.GetInverse(&to_return); DCHECK(is_invertible); to_return.PreconcatTransform(effective_initial_value_); - return to_return; + + return WrapTransform(to_return); } bool InverseTransformCurveAdapter::AnimatedBoundsForBox( diff --git a/chromium/ui/compositor/transform_animation_curve_adapter.h b/chromium/ui/compositor/transform_animation_curve_adapter.h index 7d79ea7bb0a..53d1d96fd56 100644 --- a/chromium/ui/compositor/transform_animation_curve_adapter.h +++ b/chromium/ui/compositor/transform_animation_curve_adapter.h @@ -10,6 +10,7 @@ #include "base/macros.h" #include "base/time/time.h" #include "cc/animation/animation_curve.h" +#include "cc/animation/transform_operations.h" #include "ui/compositor/compositor_export.h" #include "ui/gfx/animation/tween.h" #include "ui/gfx/transform.h" @@ -32,7 +33,7 @@ class COMPOSITOR_EXPORT TransformAnimationCurveAdapter // TransformAnimationCurve implementation. base::TimeDelta Duration() const override; std::unique_ptr Clone() const override; - gfx::Transform GetValue(base::TimeDelta t) const override; + cc::TransformOperations GetValue(base::TimeDelta t) const override; bool AnimatedBoundsForBox(const gfx::BoxF& box, gfx::BoxF* bounds) const override; bool IsTranslation() const override; @@ -45,7 +46,9 @@ class COMPOSITOR_EXPORT TransformAnimationCurveAdapter private: gfx::Tween::Type tween_type_; gfx::Transform initial_value_; + cc::TransformOperations initial_wrapped_value_; gfx::Transform target_value_; + cc::TransformOperations target_wrapped_value_; gfx::DecomposedTransform decomposed_initial_value_; gfx::DecomposedTransform decomposed_target_value_; base::TimeDelta duration_; @@ -64,7 +67,7 @@ class COMPOSITOR_EXPORT InverseTransformCurveAdapter base::TimeDelta Duration() const override; std::unique_ptr Clone() const override; - gfx::Transform GetValue(base::TimeDelta t) const override; + cc::TransformOperations GetValue(base::TimeDelta t) const override; bool AnimatedBoundsForBox(const gfx::BoxF& box, gfx::BoxF* bounds) const override; bool IsTranslation() const override; @@ -77,6 +80,7 @@ class COMPOSITOR_EXPORT InverseTransformCurveAdapter private: TransformAnimationCurveAdapter base_curve_; gfx::Transform initial_value_; + cc::TransformOperations initial_wrapped_value_; gfx::Transform effective_initial_value_; base::TimeDelta duration_; diff --git a/chromium/ui/compositor/transform_animation_curve_adapter_unittest.cc b/chromium/ui/compositor/transform_animation_curve_adapter_unittest.cc index 10ee66811f3..b5b44e90270 100644 --- a/chromium/ui/compositor/transform_animation_curve_adapter_unittest.cc +++ b/chromium/ui/compositor/transform_animation_curve_adapter_unittest.cc @@ -31,29 +31,28 @@ TEST(InverseTransformCurveAdapterTest, InversesTransform) { const gfx::Transform effective_child_transform = parent_start * child_transform; - TransformAnimationCurveAdapter parent_curve(gfx::Tween::LINEAR, - parent_start, - parent_target, - duration); + TransformAnimationCurveAdapter parent_curve(gfx::Tween::LINEAR, parent_start, + parent_target, duration); - InverseTransformCurveAdapter child_curve(parent_curve, - child_transform, + InverseTransformCurveAdapter child_curve(parent_curve, child_transform, duration); static const int kSteps = 1000; double step = 1.0 / kSteps; - for (int i = 0; i <= kSteps ; ++i) { + for (int i = 0; i <= kSteps; ++i) { base::TimeDelta time_step = cc::TimeUtil::Scale(duration, i * step); std::ostringstream message; message << "Step " << i << " of " << kSteps; SCOPED_TRACE(message.str()); - gfx::Transform progress_parent_transform = parent_curve.GetValue(time_step); - gfx::Transform progress_child_transform = child_curve.GetValue(time_step); - CheckApproximatelyEqual(effective_child_transform, - progress_parent_transform * - progress_child_transform); + gfx::Transform progress_parent_transform = + parent_curve.GetValue(time_step).Apply(); + gfx::Transform progress_child_transform = + child_curve.GetValue(time_step).Apply(); + CheckApproximatelyEqual( + effective_child_transform, + progress_parent_transform * progress_child_transform); } } -} // namespace +} // namespace -} // namespace ui +} // namespace ui diff --git a/chromium/ui/compositor/transform_recorder.cc b/chromium/ui/compositor/transform_recorder.cc index 81c5a965858..525de51cc98 100644 --- a/chromium/ui/compositor/transform_recorder.cc +++ b/chromium/ui/compositor/transform_recorder.cc @@ -5,7 +5,7 @@ #include "ui/compositor/transform_recorder.h" #include "cc/paint/display_item_list.h" -#include "cc/paint/transform_display_item.h" +#include "cc/paint/paint_op_buffer.h" #include "ui/compositor/paint_context.h" namespace ui { @@ -14,14 +14,24 @@ TransformRecorder::TransformRecorder(const PaintContext& context) : context_(context), transformed_(false) {} TransformRecorder::~TransformRecorder() { - if (transformed_) - context_.list_->CreateAndAppendPairedEndItem(); + if (!transformed_) + return; + + cc::PaintOpBuffer* buffer = context_.list_->StartPaint(); + buffer->push(); + context_.list_->EndPaintOfPairedEnd(); } void TransformRecorder::Transform(const gfx::Transform& transform) { DCHECK(!transformed_); - context_.list_->CreateAndAppendPairedBeginItem( - transform); + if (transform.IsIdentity()) + return; + + cc::PaintOpBuffer* buffer = context_.list_->StartPaint(); + buffer->push(); + buffer->push(static_cast(transform.matrix())); + context_.list_->EndPaintOfPairedBegin(); + transformed_ = true; } -- cgit v1.2.1