diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-25 11:39:07 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-01-25 15:20:42 +0000 |
commit | 6c91641271e536ffaa88a1dff5127e42ee99a91e (patch) | |
tree | 703d9dd49602377ddc90cbf886aad37913f2496b /chromium/cc/layers | |
parent | b145b7fafd36f0c260d6a768c81fc14e32578099 (diff) | |
download | qtwebengine-chromium-6c91641271e536ffaa88a1dff5127e42ee99a91e.tar.gz |
BASELINE: Update Chromium to 49.0.2623.23
Also adds missing printing sources.
Change-Id: I3726b8f0c7d6751c9fc846096c571fadca7108cd
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'chromium/cc/layers')
109 files changed, 4446 insertions, 1899 deletions
diff --git a/chromium/cc/layers/append_quads_data.h b/chromium/cc/layers/append_quads_data.h index 3d05109c176..0e2715b1df3 100644 --- a/chromium/cc/layers/append_quads_data.h +++ b/chromium/cc/layers/append_quads_data.h @@ -5,35 +5,28 @@ #ifndef CC_LAYERS_APPEND_QUADS_DATA_H_ #define CC_LAYERS_APPEND_QUADS_DATA_H_ -#include "base/basictypes.h" +#include <stdint.h> + #include "cc/quads/render_pass_id.h" namespace cc { +// Set by the layer appending quads. struct AppendQuadsData { - AppendQuadsData() - : num_incomplete_tiles(0), - num_missing_tiles(0), - visible_layer_area(0), - approximated_visible_content_area(0), - checkerboarded_visible_content_area(0), - checkerboarded_no_recording_content_area(0), - checkerboarded_needs_raster_content_area(0) {} - - // Set by the layer appending quads. - int64 num_incomplete_tiles; - // Set by the layer appending quads. - int64 num_missing_tiles; - // Set by the layer appending quads. - int64 visible_layer_area; - // Set by the layer appending quads. - int64 approximated_visible_content_area; - // Set by the layer appending quads. This is total of the following two areas. - int64 checkerboarded_visible_content_area; - // Set by the layer appending quads. This is the area outside interest rect. - int64 checkerboarded_no_recording_content_area; - // Set by the layer appending quads. This is the area within interest rect. - int64 checkerboarded_needs_raster_content_area; + int64_t num_incomplete_tiles = 0; + int64_t num_missing_tiles = 0; + int64_t visible_layer_area = 0; + int64_t approximated_visible_content_area = 0; + + // This is total of the following two areas. + int64_t checkerboarded_visible_content_area = 0; + // This is the area outside interest rect. + int64_t checkerboarded_no_recording_content_area = 0; + // This is the area within interest rect. + int64_t checkerboarded_needs_raster_content_area = 0; + + int64_t num_missing_tiles_no_image_content = 0; + int64_t num_missing_tiles_some_image_content = 0; }; } // namespace cc diff --git a/chromium/cc/layers/content_layer_client.h b/chromium/cc/layers/content_layer_client.h index deb9d619e32..db9274fdb4e 100644 --- a/chromium/cc/layers/content_layer_client.h +++ b/chromium/cc/layers/content_layer_client.h @@ -5,11 +5,11 @@ #ifndef CC_LAYERS_CONTENT_LAYER_CLIENT_H_ #define CC_LAYERS_CONTENT_LAYER_CLIENT_H_ +#include <stddef.h> + #include "cc/base/cc_export.h" #include "cc/playback/display_item_list.h" -class SkCanvas; - namespace gfx { class Rect; } @@ -22,15 +22,17 @@ class CC_EXPORT ContentLayerClient { PAINTING_BEHAVIOR_NORMAL, DISPLAY_LIST_CONSTRUCTION_DISABLED, DISPLAY_LIST_CACHING_DISABLED, - DISPLAY_LIST_PAINTING_DISABLED + DISPLAY_LIST_PAINTING_DISABLED, + SUBSEQUENCE_CACHING_DISABLED, }; - virtual void PaintContents(SkCanvas* canvas, - const gfx::Rect& clip, - PaintingControlSetting painting_status) = 0; + // The paintable region is the rectangular region, within the bounds of the + // layer this client paints, that the client is capable of painting via + // paintContents(). Calling paintContents() will return a DisplayItemList + // that is guaranteed valid only within this region. + virtual gfx::Rect PaintableRegion() = 0; virtual scoped_refptr<DisplayItemList> PaintContentsToDisplayList( - const gfx::Rect& clip, PaintingControlSetting painting_status) = 0; // If true the layer may skip clearing the background before rasterizing, diff --git a/chromium/cc/layers/delegated_frame_provider.cc b/chromium/cc/layers/delegated_frame_provider.cc index 5e016ebc6ac..4923485d081 100644 --- a/chromium/cc/layers/delegated_frame_provider.cc +++ b/chromium/cc/layers/delegated_frame_provider.cc @@ -4,6 +4,8 @@ #include "cc/layers/delegated_frame_provider.h" +#include <stddef.h> + #include "cc/layers/delegated_frame_resource_collection.h" #include "cc/layers/delegated_renderer_layer.h" #include "cc/output/delegated_frame_data.h" @@ -15,10 +17,10 @@ DelegatedFrameProvider::DelegatedFrameProvider( const scoped_refptr<DelegatedFrameResourceCollection>& resource_collection, scoped_ptr<DelegatedFrameData> frame) : resource_collection_(resource_collection) { - RenderPass* root_pass = frame->render_pass_list.back(); + RenderPass* root_pass = frame->render_pass_list.back().get(); frame_size_ = root_pass->output_rect.size(); DCHECK(!frame_size_.IsEmpty()); - SetFrameData(frame.Pass()); + SetFrameData(std::move(frame)); } DelegatedFrameProvider::~DelegatedFrameProvider() { @@ -61,12 +63,12 @@ void DelegatedFrameProvider::SetFrameData( resource_collection_->UnrefResources(returned); } - frame_ = frame.Pass(); + frame_ = std::move(frame); resource_collection_->ReceivedResources(frame_->resource_list); resource_collection_->RefResources(frame_->resource_list); - RenderPass* root_pass = frame_->render_pass_list.back(); + RenderPass* root_pass = frame_->render_pass_list.back().get(); DCHECK_EQ(frame_size_.ToString(), root_pass->output_rect.size().ToString()) << "All frames in a single DelegatedFrameProvider must have the same " << "size. Use a new frame provider for frames of a different size."; diff --git a/chromium/cc/layers/delegated_frame_provider.h b/chromium/cc/layers/delegated_frame_provider.h index f3f93732a6e..7757d0ccacd 100644 --- a/chromium/cc/layers/delegated_frame_provider.h +++ b/chromium/cc/layers/delegated_frame_provider.h @@ -7,6 +7,7 @@ #include <vector> +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" diff --git a/chromium/cc/layers/delegated_frame_provider_unittest.cc b/chromium/cc/layers/delegated_frame_provider_unittest.cc index 4248899641a..5aa8ba3c486 100644 --- a/chromium/cc/layers/delegated_frame_provider_unittest.cc +++ b/chromium/cc/layers/delegated_frame_provider_unittest.cc @@ -3,8 +3,10 @@ // found in the LICENSE file. #include "cc/layers/delegated_frame_provider.h" + #include "cc/layers/delegated_frame_resource_collection.h" #include "cc/layers/delegated_renderer_layer.h" +#include "cc/layers/layer_settings.h" #include "cc/output/delegated_frame_data.h" #include "cc/quads/texture_draw_quad.h" #include "cc/resources/resource_provider.h" @@ -32,8 +34,8 @@ class DelegatedFrameProviderTest root_output_rect, root_damage_rect, gfx::Transform()); - frame->render_pass_list.push_back(root_pass.Pass()); - return frame.Pass(); + frame->render_pass_list.push_back(std::move(root_pass)); + return frame; } void AddTransferableResource(DelegatedFrameData* frame, @@ -84,7 +86,7 @@ class DelegatedFrameProviderTest void SetFrameProvider(scoped_ptr<DelegatedFrameData> frame_data) { frame_provider_ = - new DelegatedFrameProvider(resource_collection_, frame_data.Pass()); + new DelegatedFrameProvider(resource_collection_, std::move(frame_data)); } scoped_refptr<DelegatedFrameResourceCollection> resource_collection_; @@ -99,12 +101,12 @@ TEST_F(DelegatedFrameProviderTest, SameResources) { CreateFrameData(gfx::Rect(1, 1), gfx::Rect(1, 1)); AddTextureQuad(frame.get(), 444); AddTransferableResource(frame.get(), 444); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); frame = CreateFrameData(gfx::Rect(1, 1), gfx::Rect(1, 1)); AddTextureQuad(frame.get(), 444); AddTransferableResource(frame.get(), 444); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); EXPECT_FALSE(ReturnAndResetResourcesAvailable()); EXPECT_EQ(0u, resources_.size()); @@ -121,14 +123,14 @@ TEST_F(DelegatedFrameProviderTest, ReplaceResources) { CreateFrameData(gfx::Rect(1, 1), gfx::Rect(1, 1)); AddTextureQuad(frame.get(), 444); AddTransferableResource(frame.get(), 444); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); EXPECT_FALSE(ReturnAndResetResourcesAvailable()); frame = CreateFrameData(gfx::Rect(1, 1), gfx::Rect(1, 1)); AddTextureQuad(frame.get(), 555); AddTransferableResource(frame.get(), 555); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); EXPECT_TRUE(ReturnAndResetResourcesAvailable()); EXPECT_EQ(1u, resources_.size()); @@ -152,7 +154,7 @@ TEST_F(DelegatedFrameProviderTest, RefResources) { ReturnedResourceArray returned; TransferableResource::ReturnResources(reffed, &returned); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); scoped_refptr<DelegatedRendererLayer> observer1 = DelegatedRendererLayer::Create(layer_settings_, frame_provider_); @@ -179,7 +181,7 @@ TEST_F(DelegatedFrameProviderTest, RefResources) { frame = CreateFrameData(gfx::Rect(5, 5), gfx::Rect(2, 2)); AddTextureQuad(frame.get(), 555); AddTransferableResource(frame.get(), 555); - frame_provider_->SetFrameData(frame.Pass()); + frame_provider_->SetFrameData(std::move(frame)); // The resources from the first frame are still reffed by the observers. EXPECT_FALSE(ReturnAndResetResourcesAvailable()); @@ -210,7 +212,7 @@ TEST_F(DelegatedFrameProviderTest, RefResourcesInFrameProvider) { ReturnedResourceArray returned; TransferableResource::ReturnResources(reffed, &returned); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); scoped_refptr<DelegatedRendererLayer> observer1 = DelegatedRendererLayer::Create(layer_settings_, frame_provider_); @@ -235,7 +237,7 @@ TEST_F(DelegatedFrameProviderTest, RefResourcesInFrameProvider) { frame = CreateFrameData(gfx::Rect(5, 5), gfx::Rect(2, 2)); AddTextureQuad(frame.get(), 555); AddTransferableResource(frame.get(), 555); - frame_provider_->SetFrameData(frame.Pass()); + frame_provider_->SetFrameData(std::move(frame)); EXPECT_TRUE(ReturnAndResetResourcesAvailable()); EXPECT_EQ(1u, resources_.size()); @@ -252,7 +254,7 @@ TEST_F(DelegatedFrameProviderTest, RefResourcesInFrameProviderUntilDestroy) { ReturnedResourceArray returned; TransferableResource::ReturnResources(reffed, &returned); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); scoped_refptr<DelegatedRendererLayer> observer1 = DelegatedRendererLayer::Create(layer_settings_, frame_provider_); @@ -296,7 +298,7 @@ TEST_F(DelegatedFrameProviderTest, Damage) { ReturnedResourceArray returned; TransferableResource::ReturnResources(reffed, &returned); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); scoped_refptr<DelegatedRendererLayer> observer1 = DelegatedRendererLayer::Create(layer_settings_, frame_provider_); @@ -320,7 +322,7 @@ TEST_F(DelegatedFrameProviderTest, Damage) { frame = CreateFrameData(gfx::Rect(5, 5), gfx::Rect(2, 2)); AddTextureQuad(frame.get(), 555); AddTransferableResource(frame.get(), 555); - frame_provider_->SetFrameData(frame.Pass()); + frame_provider_->SetFrameData(std::move(frame)); // Both observers get the damage for the new frame. frame_provider_->GetFrameDataAndRefResources(observer1.get(), &damage); @@ -341,7 +343,7 @@ TEST_F(DelegatedFrameProviderTest, LostNothing) { TransferableResourceArray reffed = frame->resource_list; - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); // There is nothing to lose. EXPECT_FALSE(ReturnAndResetResourcesAvailable()); @@ -356,14 +358,14 @@ TEST_F(DelegatedFrameProviderTest, LostSomething) { AddTextureQuad(frame.get(), 444); AddTransferableResource(frame.get(), 444); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); // Add a second reference on the resource. frame = CreateFrameData(gfx::Rect(5, 5), gfx::Rect(5, 5)); AddTextureQuad(frame.get(), 444); AddTransferableResource(frame.get(), 444); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); // There is something to lose. EXPECT_FALSE(ReturnAndResetResourcesAvailable()); @@ -380,7 +382,7 @@ TEST_F(DelegatedFrameProviderTest, NothingReturnedAfterLoss) { CreateFrameData(gfx::Rect(1, 1), gfx::Rect(1, 1)); AddTextureQuad(frame.get(), 444); AddTransferableResource(frame.get(), 444); - SetFrameProvider(frame.Pass()); + SetFrameProvider(std::move(frame)); EXPECT_FALSE(ReturnAndResetResourcesAvailable()); diff --git a/chromium/cc/layers/delegated_frame_resource_collection.cc b/chromium/cc/layers/delegated_frame_resource_collection.cc index a1bc759a033..c567b822f7e 100644 --- a/chromium/cc/layers/delegated_frame_resource_collection.cc +++ b/chromium/cc/layers/delegated_frame_resource_collection.cc @@ -4,6 +4,8 @@ #include "cc/layers/delegated_frame_resource_collection.h" +#include <stddef.h> + #include "base/bind.h" #include "cc/trees/blocking_task_runner.h" diff --git a/chromium/cc/layers/delegated_frame_resource_collection.h b/chromium/cc/layers/delegated_frame_resource_collection.h index afbc3555a94..0e38c684d3e 100644 --- a/chromium/cc/layers/delegated_frame_resource_collection.h +++ b/chromium/cc/layers/delegated_frame_resource_collection.h @@ -6,6 +6,7 @@ #define CC_LAYERS_DELEGATED_FRAME_RESOURCE_COLLECTION_H_ #include "base/containers/hash_tables.h" +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/threading/thread_checker.h" diff --git a/chromium/cc/layers/delegated_renderer_layer.h b/chromium/cc/layers/delegated_renderer_layer.h index 8845258895c..b71b6eec207 100644 --- a/chromium/cc/layers/delegated_renderer_layer.h +++ b/chromium/cc/layers/delegated_renderer_layer.h @@ -6,6 +6,7 @@ #define CC_LAYERS_DELEGATED_RENDERER_LAYER_H_ #include "base/containers/hash_tables.h" +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/synchronization/lock.h" diff --git a/chromium/cc/layers/delegated_renderer_layer_impl.cc b/chromium/cc/layers/delegated_renderer_layer_impl.cc index 9b3a513206c..5d511168a9b 100644 --- a/chromium/cc/layers/delegated_renderer_layer_impl.cc +++ b/chromium/cc/layers/delegated_renderer_layer_impl.cc @@ -4,6 +4,9 @@ #include "cc/layers/delegated_renderer_layer_impl.h" +#include <stddef.h> +#include <stdint.h> + #include <algorithm> #include <utility> @@ -151,7 +154,7 @@ void DelegatedRendererLayerImpl::SetFrameData( // Display size is already set so we can compute what the damage rect // will be in layer space. The damage may exceed the visible portion of // the frame, so intersect the damage to the layer's bounds. - RenderPass* new_root_pass = render_pass_list.back(); + RenderPass* new_root_pass = render_pass_list.back().get(); gfx::Size frame_size = new_root_pass->output_rect.size(); gfx::Rect damage_in_layer = gfx::ScaleToEnclosingRect(damage_in_frame, inverse_device_scale_factor_); @@ -175,14 +178,12 @@ void DelegatedRendererLayerImpl::SetRenderPasses( RenderPassList* render_passes_in_draw_order) { ClearRenderPasses(); - for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) { - RenderPassList::iterator to_take = - render_passes_in_draw_order->begin() + i; + size_t i = 0; + for (auto& render_pass : *render_passes_in_draw_order) { render_passes_index_by_id_.insert( - RenderPassToIndexMap::value_type((*to_take)->id, i)); - scoped_ptr<RenderPass> taken_render_pass = - render_passes_in_draw_order->take(to_take); - render_passes_in_draw_order_.push_back(taken_render_pass.Pass()); + RenderPassToIndexMap::value_type(render_pass->id, i)); + render_passes_in_draw_order_.push_back(std::move(render_pass)); + ++i; } // Give back an empty array instead of nulls. @@ -246,9 +247,9 @@ void DelegatedRendererLayerImpl::AppendContributingRenderPasses( DCHECK(HasContributingDelegatedRenderPasses()); const RenderPass* root_delegated_render_pass = - render_passes_in_draw_order_.back(); + render_passes_in_draw_order_.back().get(); gfx::Size frame_size = root_delegated_render_pass->output_rect.size(); - gfx::Transform delegated_frame_to_root_transform = screen_space_transform(); + gfx::Transform delegated_frame_to_root_transform = ScreenSpaceTransform(); delegated_frame_to_root_transform.Scale(inverse_device_scale_factor_, inverse_device_scale_factor_); @@ -267,7 +268,7 @@ void DelegatedRendererLayerImpl::AppendContributingRenderPasses( render_passes_in_draw_order_[i]->Copy(output_render_pass_id); copy_pass->transform_to_root_target.ConcatTransform( delegated_frame_to_root_transform); - render_pass_sink->AppendRenderPass(copy_pass.Pass()); + render_pass_sink->AppendRenderPass(std::move(copy_pass)); } } @@ -290,7 +291,7 @@ void DelegatedRendererLayerImpl::AppendQuads( RenderPassId target_render_pass_id = render_pass->id; const RenderPass* root_delegated_render_pass = - render_passes_in_draw_order_.back(); + render_passes_in_draw_order_.back().get(); DCHECK(root_delegated_render_pass->output_rect.origin().IsOrigin()); gfx::Size frame_size = root_delegated_render_pass->output_rect.size(); @@ -314,7 +315,7 @@ void DelegatedRendererLayerImpl::AppendQuads( size_t render_pass_index = IdToIndex(target_render_pass_id.index); const RenderPass* delegated_render_pass = - render_passes_in_draw_order_[render_pass_index]; + render_passes_in_draw_order_[render_pass_index].get(); AppendRenderPassQuads(render_pass, delegated_render_pass, frame_size); @@ -416,11 +417,11 @@ void DelegatedRendererLayerImpl::AppendRenderPassQuads( const SharedQuadState* delegated_shared_quad_state = nullptr; SharedQuadState* output_shared_quad_state = nullptr; - gfx::Transform delegated_frame_to_target_transform = draw_transform(); + gfx::Transform delegated_frame_to_target_transform = DrawTransform(); delegated_frame_to_target_transform.Scale(inverse_device_scale_factor_, inverse_device_scale_factor_); bool is_root_delegated_render_pass = - delegated_render_pass == render_passes_in_draw_order_.back(); + delegated_render_pass == render_passes_in_draw_order_.back().get(); for (const auto& delegated_quad : delegated_render_pass->quad_list) { if (delegated_quad->shared_quad_state != delegated_shared_quad_state) { delegated_shared_quad_state = delegated_quad->shared_quad_state; diff --git a/chromium/cc/layers/delegated_renderer_layer_impl.h b/chromium/cc/layers/delegated_renderer_layer_impl.h index e59c3ac8760..0ca13ebaa83 100644 --- a/chromium/cc/layers/delegated_renderer_layer_impl.h +++ b/chromium/cc/layers/delegated_renderer_layer_impl.h @@ -5,10 +5,12 @@ #ifndef CC_LAYERS_DELEGATED_RENDERER_LAYER_IMPL_H_ #define CC_LAYERS_DELEGATED_RENDERER_LAYER_IMPL_H_ +#include <stddef.h> + #include "base/containers/hash_tables.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" -#include "cc/base/scoped_ptr_vector.h" #include "cc/layers/layer_impl.h" namespace cc { diff --git a/chromium/cc/layers/delegated_renderer_layer_impl_unittest.cc b/chromium/cc/layers/delegated_renderer_layer_impl_unittest.cc index 5deef6c11bc..b94dedf93b2 100644 --- a/chromium/cc/layers/delegated_renderer_layer_impl_unittest.cc +++ b/chromium/cc/layers/delegated_renderer_layer_impl_unittest.cc @@ -4,12 +4,13 @@ #include "cc/layers/delegated_renderer_layer_impl.h" -#include "cc/base/scoped_ptr_vector.h" +#include <stddef.h> + #include "cc/layers/solid_color_layer_impl.h" #include "cc/quads/render_pass_draw_quad.h" #include "cc/quads/solid_color_draw_quad.h" #include "cc/test/fake_delegated_renderer_layer_impl.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_layer_tree_host_impl_client.h" #include "cc/test/fake_output_surface.h" @@ -31,20 +32,28 @@ namespace { class DelegatedRendererLayerImplTest : public testing::Test { public: DelegatedRendererLayerImplTest() - : proxy_(), - always_impl_thread_and_main_thread_blocked_(&proxy_), + : task_runner_provider_(), + always_impl_thread_and_main_thread_blocked_(&task_runner_provider_), output_surface_(FakeOutputSurface::Create3d()) { LayerTreeSettings settings; settings.minimum_occlusion_tracking_size = gfx::Size(); + settings.verify_property_trees = true; - host_impl_.reset(new FakeLayerTreeHostImpl( - settings, &proxy_, &shared_bitmap_manager_, &task_graph_runner_)); + host_impl_.reset(new FakeLayerTreeHostImpl(settings, &task_runner_provider_, + &shared_bitmap_manager_, + &task_graph_runner_)); + host_impl_->SetVisible(true); host_impl_->InitializeRenderer(output_surface_.get()); host_impl_->SetViewportSize(gfx::Size(10, 10)); } + DrawResult PrepareToDrawFrame(LayerTreeHostImpl::FrameData* frame) { + host_impl_->active_tree()->BuildPropertyTreesForTesting(); + return host_impl_->PrepareToDraw(frame); + } + protected: - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; DebugScopedSetImplThreadAndMainThreadBlocked always_impl_thread_and_main_thread_blocked_; TestSharedBitmapManager shared_bitmap_manager_; @@ -69,19 +78,19 @@ class DelegatedRendererLayerImplTestSimple host_impl_->SetViewportSize(gfx::Size(100, 100)); root_layer->SetBounds(gfx::Size(100, 100)); - root_layer->SetHasRenderSurface(true); + root_layer->SetForceRenderSurface(true); - layer_before->SetPosition(gfx::Point(20, 20)); + layer_before->SetPosition(gfx::PointF(20.f, 20.f)); layer_before->SetBounds(gfx::Size(14, 14)); layer_before->SetDrawsContent(true); - layer_before->SetHasRenderSurface(true); + layer_before->SetForceRenderSurface(true); - layer_after->SetPosition(gfx::Point(5, 5)); + layer_after->SetPosition(gfx::PointF(5.f, 5.f)); layer_after->SetBounds(gfx::Size(15, 15)); layer_after->SetDrawsContent(true); - layer_after->SetHasRenderSurface(true); + layer_after->SetForceRenderSurface(true); - delegated_renderer_layer->SetPosition(gfx::Point(3, 3)); + delegated_renderer_layer->SetPosition(gfx::PointF(3.f, 3.f)); delegated_renderer_layer->SetBounds(gfx::Size(10, 10)); delegated_renderer_layer->SetDrawsContent(true); gfx::Transform transform; @@ -112,13 +121,13 @@ class DelegatedRendererLayerImplTestSimple // Force the delegated RenderPasses to come before the RenderPass from // layer_after. - layer_after->AddChild(delegated_renderer_layer.Pass()); - root_layer->AddChild(layer_after.Pass()); + layer_after->AddChild(std::move(delegated_renderer_layer)); + root_layer->AddChild(std::move(layer_after)); // Get the RenderPass generated by layer_before to come before the delegated // RenderPasses. - root_layer->AddChild(layer_before.Pass()); - host_impl_->active_tree()->SetRootLayer(root_layer.Pass()); + root_layer->AddChild(std::move(layer_before)); + host_impl_->active_tree()->SetRootLayer(std::move(root_layer)); } protected: @@ -139,12 +148,12 @@ TEST_F(DelegatedRendererLayerImplTest, host_impl_->SetViewportSize(gfx::Size(100, 100)); root_layer->SetBounds(gfx::Size(100, 100)); - root_layer->SetHasRenderSurface(true); + root_layer->SetForceRenderSurface(true); - delegated_renderer_layer->SetPosition(gfx::Point(3, 3)); + delegated_renderer_layer->SetPosition(gfx::PointF(3.f, 3.f)); delegated_renderer_layer->SetBounds(gfx::Size(10, 10)); delegated_renderer_layer->SetDrawsContent(true); - delegated_renderer_layer->SetHasRenderSurface(true); + delegated_renderer_layer->SetForceRenderSurface(true); gfx::Transform transform; transform.Translate(1.0, 1.0); delegated_renderer_layer->SetTransform(transform); @@ -168,12 +177,12 @@ TEST_F(DelegatedRendererLayerImplTest, fake_delegated_renderer_layer_impl = delegated_renderer_layer.get(); - root_layer->AddChild(delegated_renderer_layer.Pass()); + root_layer->AddChild(std::move(delegated_renderer_layer)); - host_impl_->active_tree()->SetRootLayer(root_layer.Pass()); + host_impl_->active_tree()->SetRootLayer(std::move(root_layer)); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Root layer has one render pass, and delegated renderer layer has two // contributing render passes and its own render pass. @@ -195,7 +204,7 @@ TEST_F(DelegatedRendererLayerImplTest, host_impl_->SetViewportDamage(gfx::Rect(10, 10)); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes. @@ -218,12 +227,12 @@ TEST_F(DelegatedRendererLayerImplTest, host_impl_->SetViewportSize(gfx::Size(100, 100)); root_layer->SetBounds(gfx::Size(100, 100)); - root_layer->SetHasRenderSurface(true); + root_layer->SetForceRenderSurface(true); - delegated_renderer_layer->SetPosition(gfx::Point(3, 3)); + delegated_renderer_layer->SetPosition(gfx::PointF(3.f, 3.f)); delegated_renderer_layer->SetBounds(gfx::Size(10, 10)); delegated_renderer_layer->SetDrawsContent(true); - delegated_renderer_layer->SetHasRenderSurface(true); + delegated_renderer_layer->SetForceRenderSurface(true); gfx::Transform transform; transform.Translate(1.0, 1.0); delegated_renderer_layer->SetTransform(transform); @@ -247,13 +256,13 @@ TEST_F(DelegatedRendererLayerImplTest, fake_delegated_renderer_layer_impl = delegated_renderer_layer.get(); - root_layer->AddChild(delegated_renderer_layer.Pass()); + root_layer->AddChild(std::move(delegated_renderer_layer)); - host_impl_->pending_tree()->SetRootLayer(root_layer.Pass()); + host_impl_->pending_tree()->SetRootLayer(std::move(root_layer)); host_impl_->ActivateSyncTree(); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Root layer has one render pass, and delegated renderer layer has two // contributing render passes and its own render pass. @@ -278,7 +287,7 @@ TEST_F(DelegatedRendererLayerImplTest, host_impl_->ActivateSyncTree(); host_impl_->SetViewportDamage(gfx::Rect(100, 100)); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Root layer has one render pass, and delegated renderer layer no longer // has contributing render passes. @@ -291,7 +300,7 @@ TEST_F(DelegatedRendererLayerImplTest, TEST_F(DelegatedRendererLayerImplTestSimple, AddsContributingRenderPasses) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes. @@ -325,7 +334,7 @@ TEST_F(DelegatedRendererLayerImplTestSimple, AddsContributingRenderPasses) { TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToContributingRenderPasses) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes. @@ -360,7 +369,7 @@ TEST_F(DelegatedRendererLayerImplTestSimple, TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes. @@ -388,7 +397,7 @@ TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) { TEST_F(DelegatedRendererLayerImplTestSimple, QuadsFromRootRenderPassAreModifiedForTheTarget) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes. @@ -427,7 +436,7 @@ TEST_F(DelegatedRendererLayerImplTestSimple, TEST_F(DelegatedRendererLayerImplTestSimple, RenderPassTransformIsModified) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // The delegated layer has a surface between it and the root. EXPECT_TRUE(delegated_renderer_layer_->render_target()->parent()); @@ -462,13 +471,13 @@ class DelegatedRendererLayerImplTestOwnSurface public: DelegatedRendererLayerImplTestOwnSurface() : DelegatedRendererLayerImplTestSimple() { - delegated_renderer_layer_->SetHasRenderSurface(true); + delegated_renderer_layer_->SetForceRenderSurface(true); } }; TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes and its owned surface @@ -507,7 +516,7 @@ TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) { TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToContributingRenderPasses) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes and its owned surface @@ -544,7 +553,7 @@ TEST_F(DelegatedRendererLayerImplTestOwnSurface, TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes and its owned surface @@ -570,7 +579,7 @@ TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) { TEST_F(DelegatedRendererLayerImplTestOwnSurface, QuadsFromRootRenderPassAreNotModifiedForTheTarget) { LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); // Each non-DelegatedRendererLayer added one RenderPass. The // DelegatedRendererLayer added two contributing passes and its owned surface @@ -622,9 +631,9 @@ class DelegatedRendererLayerImplTestTransform host_impl_->SetViewportSize(gfx::Size(200, 200)); root_layer->SetBounds(gfx::Size(100, 100)); - root_layer->SetHasRenderSurface(true); + root_layer->SetForceRenderSurface(true); - delegated_renderer_layer->SetPosition(gfx::Point(20, 20)); + delegated_renderer_layer->SetPosition(gfx::PointF(20.f, 20.f)); delegated_renderer_layer->SetBounds(gfx::Size(75, 75)); delegated_renderer_layer->SetDrawsContent(true); gfx::Transform transform; @@ -734,8 +743,8 @@ class DelegatedRendererLayerImplTestTransform root_layer_ = root_layer.get(); delegated_renderer_layer_ = delegated_renderer_layer.get(); - root_layer->AddChild(delegated_renderer_layer.Pass()); - host_impl_->active_tree()->SetRootLayer(root_layer.Pass()); + root_layer->AddChild(std::move(delegated_renderer_layer)); + host_impl_->active_tree()->SetRootLayer(std::move(root_layer)); } void VerifyRenderPasses( @@ -792,7 +801,7 @@ TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) { SetUpTest(); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); const SharedQuadState* root_delegated_shared_quad_state = nullptr; const SharedQuadState* contrib_delegated_shared_quad_state = nullptr; @@ -846,7 +855,7 @@ TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) { SetUpTest(); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); const SharedQuadState* root_delegated_shared_quad_state = nullptr; const SharedQuadState* contrib_delegated_shared_quad_state = nullptr; @@ -903,10 +912,10 @@ TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) { root_delegated_render_pass_is_clipped_ = false; SetUpTest(); - delegated_renderer_layer_->SetHasRenderSurface(true); + delegated_renderer_layer_->SetForceRenderSurface(true); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); const SharedQuadState* root_delegated_shared_quad_state = nullptr; const SharedQuadState* contrib_delegated_shared_quad_state = nullptr; @@ -951,10 +960,10 @@ TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) { root_delegated_render_pass_is_clipped_ = true; SetUpTest(); - delegated_renderer_layer_->SetHasRenderSurface(true); + delegated_renderer_layer_->SetForceRenderSurface(true); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); const SharedQuadState* root_delegated_shared_quad_state = nullptr; const SharedQuadState* contrib_delegated_shared_quad_state = nullptr; @@ -1001,7 +1010,7 @@ TEST_F(DelegatedRendererLayerImplTestTransform, MismatchedDeviceScaleFactor) { SetUpTest(); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); const SharedQuadState* root_delegated_shared_quad_state = nullptr; const SharedQuadState* contrib_delegated_shared_quad_state = nullptr; @@ -1048,9 +1057,9 @@ class DelegatedRendererLayerImplTestClip host_impl_->SetViewportSize(gfx::Size(100, 100)); root_layer->SetBounds(gfx::Size(100, 100)); - root_layer->SetHasRenderSurface(true); + root_layer->SetForceRenderSurface(true); - delegated_renderer_layer->SetPosition(gfx::Point(20, 20)); + delegated_renderer_layer->SetPosition(gfx::PointF(20.f, 20.f)); delegated_renderer_layer->SetBounds(gfx::Size(50, 50)); delegated_renderer_layer->SetDrawsContent(true); @@ -1153,23 +1162,24 @@ class DelegatedRendererLayerImplTestClip delegated_renderer_layer_ = delegated_renderer_layer.get(); if (clip_delegated_renderer_layer_) { - gfx::Rect clip_rect(21, 27, 23, 21); + gfx::PointF clip_origin(21.f, 27.f); + gfx::Size clip_size(23, 21); - clip_layer->SetPosition(clip_rect.origin()); - clip_layer->SetBounds(clip_rect.size()); + clip_layer->SetPosition(clip_origin); + clip_layer->SetBounds(clip_size); clip_layer->SetMasksToBounds(true); origin_layer->SetPosition( - gfx::PointAtOffsetFromOrigin(-clip_rect.OffsetFromOrigin())); + gfx::PointF(-clip_origin.x(), -clip_origin.y())); - origin_layer->AddChild(delegated_renderer_layer.Pass()); - clip_layer->AddChild(origin_layer.Pass()); - root_layer->AddChild(clip_layer.Pass()); + origin_layer->AddChild(std::move(delegated_renderer_layer)); + clip_layer->AddChild(std::move(origin_layer)); + root_layer->AddChild(std::move(clip_layer)); } else { - root_layer->AddChild(delegated_renderer_layer.Pass()); + root_layer->AddChild(std::move(delegated_renderer_layer)); } - host_impl_->active_tree()->SetRootLayer(root_layer.Pass()); + host_impl_->active_tree()->SetRootLayer(std::move(root_layer)); } protected: @@ -1186,7 +1196,7 @@ TEST_F(DelegatedRendererLayerImplTestClip, SetUpTest(); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); ASSERT_EQ(2u, frame.render_passes.size()); const QuadList& contrib_delegated_quad_list = @@ -1215,7 +1225,7 @@ TEST_F(DelegatedRendererLayerImplTestClip, SetUpTest(); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); ASSERT_EQ(2u, frame.render_passes.size()); const QuadList& contrib_delegated_quad_list = @@ -1245,7 +1255,7 @@ TEST_F(DelegatedRendererLayerImplTestClip, LayerTreeHostImpl::FrameData frame; host_impl_->active_tree()->BuildPropertyTreesForTesting(); - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); ASSERT_EQ(2u, frame.render_passes.size()); const QuadList& contrib_delegated_quad_list = @@ -1276,7 +1286,7 @@ TEST_F(DelegatedRendererLayerImplTestClip, LayerTreeHostImpl::FrameData frame; host_impl_->active_tree()->BuildPropertyTreesForTesting(); - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); ASSERT_EQ(2u, frame.render_passes.size()); const QuadList& contrib_delegated_quad_list = @@ -1304,10 +1314,10 @@ TEST_F(DelegatedRendererLayerImplTestClip, clip_delegated_renderer_layer_ = false; SetUpTest(); - delegated_renderer_layer_->SetHasRenderSurface(true); + delegated_renderer_layer_->SetForceRenderSurface(true); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); ASSERT_EQ(3u, frame.render_passes.size()); const QuadList& contrib_delegated_quad_list = @@ -1333,10 +1343,10 @@ TEST_F(DelegatedRendererLayerImplTestClip, clip_delegated_renderer_layer_ = false; SetUpTest(); - delegated_renderer_layer_->SetHasRenderSurface(true); + delegated_renderer_layer_->SetForceRenderSurface(true); LayerTreeHostImpl::FrameData frame; - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); ASSERT_EQ(3u, frame.render_passes.size()); const QuadList& contrib_delegated_quad_list = @@ -1363,11 +1373,11 @@ TEST_F(DelegatedRendererLayerImplTestClip, clip_delegated_renderer_layer_ = true; SetUpTest(); - delegated_renderer_layer_->SetHasRenderSurface(true); + delegated_renderer_layer_->SetForceRenderSurface(true); LayerTreeHostImpl::FrameData frame; host_impl_->active_tree()->BuildPropertyTreesForTesting(); - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); ASSERT_EQ(3u, frame.render_passes.size()); const QuadList& contrib_delegated_quad_list = @@ -1392,11 +1402,11 @@ TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerClipped_Surface) { clip_delegated_renderer_layer_ = true; SetUpTest(); - delegated_renderer_layer_->SetHasRenderSurface(true); + delegated_renderer_layer_->SetForceRenderSurface(true); LayerTreeHostImpl::FrameData frame; host_impl_->active_tree()->BuildPropertyTreesForTesting(); - EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); + EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); ASSERT_EQ(3u, frame.render_passes.size()); const QuadList& contrib_delegated_quad_list = diff --git a/chromium/cc/layers/delegated_renderer_layer_unittest.cc b/chromium/cc/layers/delegated_renderer_layer_unittest.cc index ad4a345fc0f..a7e9c9a152f 100644 --- a/chromium/cc/layers/delegated_renderer_layer_unittest.cc +++ b/chromium/cc/layers/delegated_renderer_layer_unittest.cc @@ -6,6 +6,7 @@ #include "cc/layers/delegated_frame_provider.h" #include "cc/layers/delegated_frame_resource_collection.h" +#include "cc/layers/layer_settings.h" #include "cc/layers/solid_color_layer.h" #include "cc/output/delegated_frame_data.h" #include "cc/test/fake_delegated_renderer_layer.h" @@ -20,7 +21,7 @@ namespace { class DelegatedRendererLayerTest : public testing::Test { public: DelegatedRendererLayerTest() - : proxy_(), host_client_(FakeLayerTreeHostClient::DIRECT_3D) { + : host_client_(FakeLayerTreeHostClient::DIRECT_3D) { LayerTreeSettings settings; settings.minimum_occlusion_tracking_size = gfx::Size(); @@ -30,7 +31,6 @@ class DelegatedRendererLayerTest : public testing::Test { } protected: - FakeProxy proxy_; FakeLayerTreeHostClient host_client_; TestTaskGraphRunner task_graph_runner_; TestSharedBitmapManager shared_bitmap_manager_; @@ -44,9 +44,9 @@ class DelegatedRendererLayerTestSimple : public DelegatedRendererLayerTest { root_pass->SetNew( RenderPassId(1, 1), gfx::Rect(1, 1), gfx::Rect(1, 1), gfx::Transform()); scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); - frame_data->render_pass_list.push_back(root_pass.Pass()); + frame_data->render_pass_list.push_back(std::move(root_pass)); resources_ = new DelegatedFrameResourceCollection; - provider_ = new DelegatedFrameProvider(resources_, frame_data.Pass()); + provider_ = new DelegatedFrameProvider(resources_, std::move(frame_data)); LayerSettings layer_settings; root_layer_ = SolidColorLayer::Create(layer_settings); layer_before_ = SolidColorLayer::Create(layer_settings); diff --git a/chromium/cc/layers/draw_properties.h b/chromium/cc/layers/draw_properties.h index bcab91036be..0c7e4795f3a 100644 --- a/chromium/cc/layers/draw_properties.h +++ b/chromium/cc/layers/draw_properties.h @@ -5,6 +5,8 @@ #ifndef CC_LAYERS_DRAW_PROPERTIES_H_ #define CC_LAYERS_DRAW_PROPERTIES_H_ +#include <stddef.h> + #include "base/memory/scoped_ptr.h" #include "cc/trees/occlusion.h" #include "third_party/skia/include/core/SkXfermode.h" diff --git a/chromium/cc/layers/empty_content_layer_client.cc b/chromium/cc/layers/empty_content_layer_client.cc new file mode 100644 index 00000000000..1eac1a18d28 --- /dev/null +++ b/chromium/cc/layers/empty_content_layer_client.cc @@ -0,0 +1,45 @@ +// 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 "cc/layers/empty_content_layer_client.h" + +#include "cc/playback/display_item_list.h" +#include "cc/playback/display_item_list_settings.h" +#include "ui/gfx/geometry/rect.h" + +namespace cc { + +namespace { +base::LazyInstance<EmptyContentLayerClient> g_empty_content_layer_client = + LAZY_INSTANCE_INITIALIZER; +} + +// static +ContentLayerClient* EmptyContentLayerClient::GetInstance() { + return g_empty_content_layer_client.Pointer(); +} + +EmptyContentLayerClient::EmptyContentLayerClient() {} + +EmptyContentLayerClient::~EmptyContentLayerClient() {} + +gfx::Rect EmptyContentLayerClient::PaintableRegion() { + return gfx::Rect(); +} + +scoped_refptr<DisplayItemList> +EmptyContentLayerClient::PaintContentsToDisplayList( + PaintingControlSetting painting_status) { + return DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings()); +} + +bool EmptyContentLayerClient::FillsBoundsCompletely() const { + return false; +} + +size_t EmptyContentLayerClient::GetApproximateUnsharedMemoryUsage() const { + return 0u; +} + +} // namespace cc diff --git a/chromium/cc/layers/empty_content_layer_client.h b/chromium/cc/layers/empty_content_layer_client.h new file mode 100644 index 00000000000..2554b8afbc6 --- /dev/null +++ b/chromium/cc/layers/empty_content_layer_client.h @@ -0,0 +1,47 @@ +// 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 CC_LAYERS_EMPTY_CONTENT_LAYER_CLIENT_H_ +#define CC_LAYERS_EMPTY_CONTENT_LAYER_CLIENT_H_ + +#include "base/lazy_instance.h" +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/layers/content_layer_client.h" +#include "ui/gfx/geometry/rect.h" + +namespace cc { + +class DisplayItemList; + +// This is used by deserialized PictureLayers which have no local +// ContentLayerClient but still have valid content from the original serialized +// PictureLayer. The PictureLayer class requires a valid ContentLayerClient to +// determine if it can draw. This is a dummy client to keep the logic fairly +// straightforward. This is also used by unit tests for creating dummy +// PictureLayers. +class CC_EXPORT EmptyContentLayerClient : public ContentLayerClient { + public: + static ContentLayerClient* GetInstance(); + + // ContentLayerClient implementation. + gfx::Rect PaintableRegion() override; + scoped_refptr<DisplayItemList> PaintContentsToDisplayList( + PaintingControlSetting painting_status) override; + bool FillsBoundsCompletely() const override; + size_t GetApproximateUnsharedMemoryUsage() const override; + + private: + friend struct base::DefaultLazyInstanceTraits<EmptyContentLayerClient>; + + EmptyContentLayerClient(); + ~EmptyContentLayerClient() override; + + DISALLOW_COPY_AND_ASSIGN(EmptyContentLayerClient); +}; + +} // namespace cc + +#endif // CC_LAYERS_EMPTY_CONTENT_LAYER_CLIENT_H_ diff --git a/chromium/cc/layers/heads_up_display_layer.h b/chromium/cc/layers/heads_up_display_layer.h index 0760353ed9f..5ffa31aa0c9 100644 --- a/chromium/cc/layers/heads_up_display_layer.h +++ b/chromium/cc/layers/heads_up_display_layer.h @@ -7,6 +7,7 @@ #include <string> +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" diff --git a/chromium/cc/layers/heads_up_display_layer_impl.cc b/chromium/cc/layers/heads_up_display_layer_impl.cc index 1f765091381..035ebc97ae7 100644 --- a/chromium/cc/layers/heads_up_display_layer_impl.cc +++ b/chromium/cc/layers/heads_up_display_layer_impl.cc @@ -4,6 +4,9 @@ #include "cc/layers/heads_up_display_layer_impl.h" +#include <stddef.h> +#include <stdint.h> + #include <algorithm> #include <vector> @@ -20,10 +23,12 @@ #include "cc/trees/layer_tree_host_impl.h" #include "cc/trees/layer_tree_impl.h" #include "skia/ext/platform_canvas.h" +#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/effects/SkColorMatrixFilter.h" +#include "third_party/skia/include/effects/SkGradientShader.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size_conversions.h" @@ -44,7 +49,7 @@ static inline SkPaint CreatePaint() { swizzle_matrix.fMat[2 + 5 * 0] = 1; swizzle_matrix.fMat[3 + 5 * 3] = 1; - skia::RefPtr<SkColorMatrixFilter> filter = + skia::RefPtr<SkColorFilter> filter = skia::AdoptRef(SkColorMatrixFilter::Create(swizzle_matrix)); paint.setColorFilter(filter.get()); #endif @@ -89,11 +94,9 @@ scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( void HeadsUpDisplayLayerImpl::AcquireResource( ResourceProvider* resource_provider) { - for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); - it != resources_.end(); - ++it) { - if (!resource_provider->InUseByConsumer((*it)->id())) { - resources_.swap(it, resources_.end() - 1); + for (auto& resource : resources_) { + if (!resource_provider->InUseByConsumer(resource->id())) { + resource.swap(resources_.back()); return; } } @@ -101,27 +104,18 @@ void HeadsUpDisplayLayerImpl::AcquireResource( scoped_ptr<ScopedResource> resource = ScopedResource::Create(resource_provider); resource->Allocate(internal_content_bounds_, - ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); - resources_.push_back(resource.Pass()); + ResourceProvider::TEXTURE_HINT_IMMUTABLE, + resource_provider->best_texture_format()); + resources_.push_back(std::move(resource)); } -class ResourceSizeIsEqualTo { - public: - explicit ResourceSizeIsEqualTo(const gfx::Size& size_) - : compare_size_(size_) {} - - bool operator()(const ScopedResource* resource) { - return resource->size() == compare_size_; - } - - private: - const gfx::Size compare_size_; -}; - void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( ResourceProvider* resource_provider) { - ScopedPtrVector<ScopedResource>::iterator it_erase = - resources_.partition(ResourceSizeIsEqualTo(internal_content_bounds_)); + auto it_erase = + std::remove_if(resources_.begin(), resources_.end(), + [this](const scoped_ptr<ScopedResource>& resource) { + return internal_content_bounds_ != resource->size(); + }); resources_.erase(it_erase, resources_.end()); } @@ -183,7 +177,7 @@ void HeadsUpDisplayLayerImpl::UpdateHudTexture( SkISize canvas_size; if (hud_surface_) - canvas_size = hud_surface_->getCanvas()->getDeviceSize(); + canvas_size = hud_surface_->getCanvas()->getBaseLayerSize(); else canvas_size.set(0, 0); @@ -275,7 +269,7 @@ void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) { area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); - if (debug_state.ShowMemoryStats()) + if (debug_state.ShowMemoryStats() && memory_entry_.total_bytes_used) DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); } int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, @@ -361,7 +355,8 @@ SkRect HeadsUpDisplayLayerImpl::DrawFPSDisplay( const int kPadding = 4; const int kGap = 6; - const int kFontHeight = 15; + const int kTitleFontHeight = 13; + const int kFontHeight = 12; const int kGraphWidth = base::saturated_cast<int>(fps_counter->time_stamp_history_size()) - 2; @@ -370,18 +365,19 @@ SkRect HeadsUpDisplayLayerImpl::DrawFPSDisplay( const int kHistogramWidth = 37; int width = kGraphWidth + kHistogramWidth + 4 * kPadding; - int height = kFontHeight + kGraphHeight + 4 * kPadding + 2; + int height = kTitleFontHeight + kFontHeight + kGraphHeight + 6 * kPadding + 2; int left = bounds().width() - width - right; SkRect area = SkRect::MakeXYWH(left, top, width, height); SkPaint paint = CreatePaint(); DrawGraphBackground(canvas, &paint, area); + SkRect title_bounds = SkRect::MakeXYWH( + left + kPadding, top + kPadding, kGraphWidth + kHistogramWidth + kGap + 2, + kTitleFontHeight); SkRect text_bounds = - SkRect::MakeXYWH(left + kPadding, - top + kPadding, - kGraphWidth + kHistogramWidth + kGap + 2, - kFontHeight); + SkRect::MakeXYWH(left + kPadding, title_bounds.bottom() + 2 * kPadding, + kGraphWidth + kHistogramWidth + kGap + 2, kFontHeight); SkRect graph_bounds = SkRect::MakeXYWH(left + kPadding, text_bounds.bottom() + 2 * kPadding, kGraphWidth, @@ -391,13 +387,18 @@ SkRect HeadsUpDisplayLayerImpl::DrawFPSDisplay( kHistogramWidth, kGraphHeight); + const std::string title("Frame Rate"); const std::string value_text = - base::StringPrintf("FPS:%5.1f", fps_graph_.value); + base::StringPrintf("%5.1f fps", fps_graph_.value); const std::string min_max_text = base::StringPrintf("%.0f-%.0f", fps_graph_.min, fps_graph_.max); VLOG(1) << value_text; + paint.setColor(DebugColors::HUDTitleColor()); + DrawText(canvas, &paint, title, SkPaint::kLeft_Align, kTitleFontHeight, + title_bounds.left(), title_bounds.bottom()); + paint.setColor(DebugColors::FPSDisplayTextAndGraphColor()); DrawText(canvas, &paint, @@ -498,13 +499,11 @@ SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas, int right, int top, int width) const { - if (!memory_entry_.total_bytes_used) - return SkRect::MakeEmpty(); - const int kPadding = 4; - const int kFontHeight = 13; + const int kTitleFontHeight = 13; + const int kFontHeight = 12; - const int height = 3 * kFontHeight + 4 * kPadding; + const int height = kTitleFontHeight + 2 * kFontHeight + 5 * kPadding; const int left = bounds().width() - width - right; const SkRect area = SkRect::MakeXYWH(left, top, width, height); @@ -513,20 +512,18 @@ SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas, SkPaint paint = CreatePaint(); DrawGraphBackground(canvas, &paint, area); - SkPoint title_pos = SkPoint::Make(left + kPadding, top + kFontHeight); + SkPoint title_pos = + SkPoint::Make(left + kPadding, top + kFontHeight + kPadding); SkPoint stat1_pos = SkPoint::Make(left + width - kPadding - 1, top + kPadding + 2 * kFontHeight); SkPoint stat2_pos = SkPoint::Make(left + width - kPadding - 1, top + 2 * kPadding + 3 * kFontHeight); - paint.setColor(DebugColors::MemoryDisplayTextColor()); - DrawText(canvas, - &paint, - "GPU memory", - SkPaint::kLeft_Align, - kFontHeight, + paint.setColor(DebugColors::HUDTitleColor()); + DrawText(canvas, &paint, "GPU Memory", SkPaint::kLeft_Align, kTitleFontHeight, title_pos); + paint.setColor(DebugColors::MemoryDisplayTextColor()); std::string text = base::StringPrintf( "%6.1f MB used", memory_entry_.total_bytes_used / kMegabyte); DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat1_pos); @@ -537,6 +534,45 @@ SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas, memory_entry_.total_budget_in_bytes / kMegabyte); DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat2_pos); + // Draw memory graph. + int length = 2 * kFontHeight + kPadding + 12; + SkRect oval = + SkRect::MakeXYWH(left + kPadding * 6, + top + kTitleFontHeight + kPadding * 3, length, length); + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kFill_Style); + + paint.setColor(SkColorSetARGB(64, 255, 255, 0)); + canvas->drawArc(oval, 180, 180, true, paint); + + int radius = length / 2; + int cx = oval.left() + radius; + int cy = oval.top() + radius; + double angle = ((double)memory_entry_.total_bytes_used / + memory_entry_.total_budget_in_bytes) * + 180; + + SkColor colors[] = {SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, + SkColorSetARGB(255, 255, 140, 0), SK_ColorRED}; + const SkScalar pos[] = {SkFloatToScalar(0.2f), SkFloatToScalar(0.4f), + SkFloatToScalar(0.6f), SkFloatToScalar(0.8f), + SkFloatToScalar(1.0f)}; + skia::RefPtr<SkShader> gradient_shader = + skia::AdoptRef(SkGradientShader::CreateSweep(cx, cy, colors, pos, 5)); + paint.setShader(gradient_shader.get()); + paint.setFlags(SkPaint::kAntiAlias_Flag); + + // Draw current status. + paint.setStyle(SkPaint::kStroke_Style); + paint.setAlpha(32); + paint.setStrokeWidth(4); + canvas->drawArc(oval, 180, angle, true, paint); + + paint.setStyle(SkPaint::kFill_Style); + paint.setColor(SkColorSetARGB(255, 0, 255, 0)); + canvas->drawArc(oval, 180, angle, true, paint); + paint.setShader(NULL); + return area; } @@ -577,9 +613,10 @@ SkRect HeadsUpDisplayLayerImpl::DrawGpuRasterizationStatus(SkCanvas* canvas, return SkRect::MakeEmpty(); const int kPadding = 4; - const int kFontHeight = 13; + const int kTitleFontHeight = 13; + const int kFontHeight = 12; - const int height = 2 * kFontHeight + 3 * kPadding; + const int height = kTitleFontHeight + kFontHeight + 3 * kPadding; const int left = bounds().width() - width - right; const SkRect area = SkRect::MakeXYWH(left, top, width, height); @@ -588,10 +625,10 @@ SkRect HeadsUpDisplayLayerImpl::DrawGpuRasterizationStatus(SkCanvas* canvas, SkPoint gpu_status_pos = SkPoint::Make(left + width - kPadding, top + 2 * kFontHeight + 2 * kPadding); - - paint.setColor(color); - DrawText(canvas, &paint, "GPU raster: ", SkPaint::kLeft_Align, kFontHeight, + paint.setColor(DebugColors::HUDTitleColor()); + DrawText(canvas, &paint, "GPU Raster", SkPaint::kLeft_Align, kTitleFontHeight, left + kPadding, top + kFontHeight + kPadding); + paint.setColor(color); DrawText(canvas, &paint, status, SkPaint::kRight_Align, kFontHeight, gpu_status_pos); diff --git a/chromium/cc/layers/heads_up_display_layer_impl.h b/chromium/cc/layers/heads_up_display_layer_impl.h index 0663b825417..07e4bedead1 100644 --- a/chromium/cc/layers/heads_up_display_layer_impl.h +++ b/chromium/cc/layers/heads_up_display_layer_impl.h @@ -8,6 +8,7 @@ #include <string> #include <vector> +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/time/time.h" #include "cc/base/cc_export.h" @@ -123,7 +124,7 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl { void AcquireResource(ResourceProvider* resource_provider); void ReleaseUnmatchedSizeResources(ResourceProvider* resource_provider); - ScopedPtrVector<ScopedResource> resources_; + std::vector<scoped_ptr<ScopedResource>> resources_; skia::RefPtr<SkSurface> hud_surface_; skia::RefPtr<SkTypeface> typeface_; diff --git a/chromium/cc/layers/heads_up_display_layer_impl_unittest.cc b/chromium/cc/layers/heads_up_display_layer_impl_unittest.cc index ef377838571..cb69b1b8f12 100644 --- a/chromium/cc/layers/heads_up_display_layer_impl_unittest.cc +++ b/chromium/cc/layers/heads_up_display_layer_impl_unittest.cc @@ -2,13 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stddef.h> + #include "cc/layers/append_quads_data.h" #include "cc/layers/heads_up_display_layer_impl.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" #include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_task_graph_runner.h" +#include "cc/trees/layer_tree_impl.h" #include "testing/gtest/include/gtest/gtest.h" namespace cc { @@ -31,28 +34,32 @@ void CheckDrawLayer(HeadsUpDisplayLayerImpl* layer, } TEST(HeadsUpDisplayLayerImplTest, ResourcelessSoftwareDrawAfterResourceLoss) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); - FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, &task_graph_runner); host_impl.CreatePendingTree(); + host_impl.SetVisible(true); host_impl.InitializeRenderer(output_surface.get()); - scoped_ptr<HeadsUpDisplayLayerImpl> layer = - HeadsUpDisplayLayerImpl::Create(host_impl.pending_tree(), 1); - layer->SetBounds(gfx::Size(100, 100)); + scoped_ptr<HeadsUpDisplayLayerImpl> layer_ptr = + HeadsUpDisplayLayerImpl::Create(host_impl.pending_tree(), 1); + layer_ptr->SetBounds(gfx::Size(100, 100)); + + HeadsUpDisplayLayerImpl* layer = layer_ptr.get(); + + host_impl.pending_tree()->SetRootLayer(std::move(layer_ptr)); + host_impl.pending_tree()->BuildPropertyTreesForTesting(); // Check regular hardware draw is ok. - CheckDrawLayer( - layer.get(), host_impl.resource_provider(), DRAW_MODE_HARDWARE); + CheckDrawLayer(layer, host_impl.resource_provider(), DRAW_MODE_HARDWARE); // Simulate a resource loss on transitioning to resourceless software mode. layer->ReleaseResources(); // Should skip resourceless software draw and not crash in UpdateHudTexture. - CheckDrawLayer(layer.get(), - host_impl.resource_provider(), + CheckDrawLayer(layer, host_impl.resource_provider(), DRAW_MODE_RESOURCELESS_SOFTWARE); } diff --git a/chromium/cc/layers/io_surface_layer.cc b/chromium/cc/layers/io_surface_layer.cc index c2e35304b60..7fb3f3f111a 100644 --- a/chromium/cc/layers/io_surface_layer.cc +++ b/chromium/cc/layers/io_surface_layer.cc @@ -4,6 +4,8 @@ #include "cc/layers/io_surface_layer.h" +#include <stdint.h> + #include "cc/layers/io_surface_layer_impl.h" namespace cc { diff --git a/chromium/cc/layers/io_surface_layer.h b/chromium/cc/layers/io_surface_layer.h index 14eabd98a1e..a88492fb0b4 100644 --- a/chromium/cc/layers/io_surface_layer.h +++ b/chromium/cc/layers/io_surface_layer.h @@ -5,6 +5,9 @@ #ifndef CC_LAYERS_IO_SURFACE_LAYER_H_ #define CC_LAYERS_IO_SURFACE_LAYER_H_ +#include <stdint.h> + +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" diff --git a/chromium/cc/layers/io_surface_layer_impl.cc b/chromium/cc/layers/io_surface_layer_impl.cc index 902a73d65b0..d7c6cda1875 100644 --- a/chromium/cc/layers/io_surface_layer_impl.cc +++ b/chromium/cc/layers/io_surface_layer_impl.cc @@ -79,14 +79,9 @@ void IOSurfaceLayerImpl::AppendQuads( IOSurfaceDrawQuad* quad = render_pass->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>(); - quad->SetNew(shared_quad_state, - quad_rect, - opaque_rect, - visible_quad_rect, - io_surface_size_, - io_surface_resource_id_, - IOSurfaceDrawQuad::FLIPPED, - false); + quad->SetNew(shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, + io_surface_size_, io_surface_resource_id_, + IOSurfaceDrawQuad::FLIPPED); ValidateQuadResources(quad); } diff --git a/chromium/cc/layers/io_surface_layer_impl.h b/chromium/cc/layers/io_surface_layer_impl.h index 8317760cd92..29e9973ed42 100644 --- a/chromium/cc/layers/io_surface_layer_impl.h +++ b/chromium/cc/layers/io_surface_layer_impl.h @@ -7,6 +7,7 @@ #include <string> +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" #include "ui/gfx/geometry/size.h" diff --git a/chromium/cc/layers/io_surface_layer_impl_unittest.cc b/chromium/cc/layers/io_surface_layer_impl_unittest.cc index 75c2cf77f83..ff3e79e0a18 100644 --- a/chromium/cc/layers/io_surface_layer_impl_unittest.cc +++ b/chromium/cc/layers/io_surface_layer_impl_unittest.cc @@ -4,6 +4,8 @@ #include "cc/layers/io_surface_layer_impl.h" +#include <stddef.h> + #include "cc/test/layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/cc/layers/layer.cc b/chromium/cc/layers/layer.cc index 9db52869c0e..cc2cbbb537c 100644 --- a/chromium/cc/layers/layer.cc +++ b/chromium/cc/layers/layer.cc @@ -4,6 +4,9 @@ #include "cc/layers/layer.h" +#include <stddef.h> +#include <stdint.h> + #include <algorithm> #include "base/atomic_sequence_num.h" @@ -13,17 +16,23 @@ #include "base/time/time.h" #include "base/trace_event/trace_event.h" #include "cc/animation/animation.h" -#include "cc/animation/animation_events.h" #include "cc/animation/animation_registrar.h" #include "cc/animation/keyframed_animation_curve.h" #include "cc/animation/layer_animation_controller.h" +#include "cc/animation/mutable_properties.h" #include "cc/base/simple_enclosed_region.h" #include "cc/debug/frame_viewer_instrumentation.h" #include "cc/layers/layer_client.h" #include "cc/layers/layer_impl.h" +#include "cc/layers/layer_proto_converter.h" +#include "cc/layers/layer_settings.h" #include "cc/layers/scrollbar_layer_interface.h" #include "cc/output/copy_output_request.h" #include "cc/output/copy_output_result.h" +#include "cc/proto/cc_conversions.h" +#include "cc/proto/gfx_conversions.h" +#include "cc/proto/layer.pb.h" +#include "cc/proto/skia_conversions.h" #include "cc/trees/draw_property_utils.h" #include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_impl.h" @@ -55,7 +64,8 @@ Layer::Layer(const LayerSettings& settings) effect_tree_index_(-1), clip_tree_index_(-1), property_tree_sequence_number_(-1), - num_layer_or_descendants_with_copy_request_(0), + element_id_(0), + mutable_properties_(kMutablePropertyNone), should_flatten_transform_from_property_tree_(false), should_scroll_on_main_thread_(false), have_wheel_event_handlers_(false), @@ -88,7 +98,8 @@ Layer::Layer(const LayerSettings& settings) replica_layer_(nullptr), client_(nullptr), num_unclipped_descendants_(0), - frame_timing_requests_dirty_(false) { + frame_timing_requests_dirty_(false), + is_hidden_from_property_trees_(false) { if (!settings.use_compositor_animation_timelines) { layer_animation_controller_ = LayerAnimationController::Create(layer_id_); layer_animation_controller_->AddValueObserver(this); @@ -259,15 +270,7 @@ void Layer::SetParent(Layer* layer) { layer->AddDependentNeedsPushProperties(); } - if (parent_) { - parent_->UpdateNumCopyRequestsForSubtree( - -num_layer_or_descendants_with_copy_request_); - } parent_ = layer; - if (parent_) { - parent_->UpdateNumCopyRequestsForSubtree( - num_layer_or_descendants_with_copy_request_); - } SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr); if (!layer_tree_host_) @@ -409,33 +412,20 @@ bool Layer::HasAncestor(const Layer* ancestor) const { void Layer::RequestCopyOfOutput( scoped_ptr<CopyOutputRequest> request) { DCHECK(IsPropertyChangeAllowed()); - bool had_no_copy_requests = copy_requests_.empty(); if (void* source = request->source()) { - auto it = std::find_if( - copy_requests_.begin(), copy_requests_.end(), - [source](const CopyOutputRequest* x) { return x->source() == source; }); + auto it = std::find_if(copy_requests_.begin(), copy_requests_.end(), + [source](const scoped_ptr<CopyOutputRequest>& x) { + return x->source() == source; + }); if (it != copy_requests_.end()) copy_requests_.erase(it); } if (request->IsEmpty()) return; - copy_requests_.push_back(request.Pass()); - if (had_no_copy_requests) { - UpdateNumCopyRequestsForSubtree(1); - } + copy_requests_.push_back(std::move(request)); SetNeedsCommit(); } -void Layer::UpdateNumCopyRequestsForSubtree(int delta) { - if (!delta) - return; - for (Layer* layer = this; layer; layer = layer->parent()) { - layer->num_layer_or_descendants_with_copy_request_ += delta; - layer->SetNeedsPushProperties(); - DCHECK_GE(layer->num_layer_or_descendants_with_copy_request_, 0); - } -} - void Layer::SetBackgroundColor(SkColor background_color) { DCHECK(IsPropertyChangeAllowed()); if (background_color_ == background_color) @@ -1158,7 +1148,7 @@ void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) { static void RunCopyCallbackOnMainThread(scoped_ptr<CopyOutputRequest> request, scoped_ptr<CopyOutputResult> result) { - request->SendResult(result.Pass()); + request->SendResult(std::move(result)); } static void PostCopyCallbackToMainThread( @@ -1172,6 +1162,7 @@ static void PostCopyCallbackToMainThread( } void Layer::PushPropertiesTo(LayerImpl* layer) { + TRACE_EVENT0("cc", "Layer::PushPropertiesTo"); DCHECK(layer_tree_host_); // If we did not SavePaintProperties() for the layer this frame, then push the @@ -1184,8 +1175,12 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer->SetBounds(use_paint_properties ? paint_properties_.bounds : bounds_); +#if defined(NDEBUG) if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots()) layer->SetDebugInfo(TakeDebugInfo()); +#else + layer->SetDebugInfo(TakeDebugInfo()); +#endif layer->SetTransformTreeIndex(transform_tree_index()); layer->SetEffectTreeIndex(effect_tree_index()); @@ -1195,6 +1190,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer->SetDrawsContent(DrawsContent()); layer->SetHideLayerAndSubtree(hide_layer_and_subtree_); layer->SetHasRenderSurface(has_render_surface_); + layer->SetForceRenderSurface(force_render_surface_); if (!layer->FilterIsAnimatingOnImplOnly() && !FilterIsAnimating()) layer->SetFilters(filters_); DCHECK(!(FilterIsAnimating() && layer->FilterIsAnimatingOnImplOnly())); @@ -1219,8 +1215,6 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer->SetShouldFlattenTransform(should_flatten_transform_); layer->set_should_flatten_transform_from_property_tree( should_flatten_transform_from_property_tree_); - layer->set_num_layer_or_descendant_with_copy_request( - num_layer_or_descendants_with_copy_request_); layer->set_draw_blend_mode(draw_blend_mode_); layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) @@ -1232,6 +1226,9 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer->SetScrollClipLayer(scroll_clip_layer_id_); layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); layer->set_user_scrollable_vertical(user_scrollable_vertical_); + layer->SetElementId(element_id_); + layer->SetMutableProperties(mutable_properties_); + layer->set_is_hidden_from_property_trees(is_hidden_from_property_trees_); LayerImpl* scroll_parent = nullptr; if (scroll_parent_) { @@ -1288,31 +1285,28 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer->PushScrollOffsetFromMainThread(scroll_offset_); layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment()); - // Wrap the copy_requests_ in a PostTask to the main thread. - bool had_copy_requests = !copy_requests_.empty(); - ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests; - for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); - it != copy_requests_.end(); - ++it) { - scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner = - layer_tree_host()->proxy()->MainThreadTaskRunner(); - scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it); - const CopyOutputRequest& original_request_ref = *original_request; - scoped_ptr<CopyOutputRequest> main_thread_request = - CopyOutputRequest::CreateRelayRequest( - original_request_ref, - base::Bind(&PostCopyCallbackToMainThread, - main_thread_task_runner, - base::Passed(&original_request))); - main_thread_copy_requests.push_back(main_thread_request.Pass()); - } - if (!copy_requests_.empty() && layer_tree_host_) - layer_tree_host_->property_trees()->needs_rebuild = true; - if (had_copy_requests) - UpdateNumCopyRequestsForSubtree(-1); + { + TRACE_EVENT0("cc", "Layer::PushPropertiesTo::CopyOutputRequests"); + // Wrap the copy_requests_ in a PostTask to the main thread. + std::vector<scoped_ptr<CopyOutputRequest>> main_thread_copy_requests; + for (auto it = copy_requests_.begin(); it != copy_requests_.end(); ++it) { + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner = + layer_tree_host()->task_runner_provider()->MainThreadTaskRunner(); + scoped_ptr<CopyOutputRequest> original_request = std::move(*it); + const CopyOutputRequest& original_request_ref = *original_request; + scoped_ptr<CopyOutputRequest> main_thread_request = + CopyOutputRequest::CreateRelayRequest( + original_request_ref, + base::Bind(&PostCopyCallbackToMainThread, main_thread_task_runner, + base::Passed(&original_request))); + main_thread_copy_requests.push_back(std::move(main_thread_request)); + } + if (!copy_requests_.empty() && layer_tree_host_) + layer_tree_host_->property_trees()->needs_rebuild = true; - copy_requests_.clear(); - layer->PassCopyRequests(&main_thread_copy_requests); + copy_requests_.clear(); + layer->PassCopyRequests(&main_thread_copy_requests); + } // If the main thread commits multiple times before the impl thread actually // draws, then damage tracking will become incorrect if we simply clobber the @@ -1332,11 +1326,6 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { frame_timing_requests_dirty_ = false; } - bool is_page_scale_layer = this == layer_tree_host()->page_scale_layer(); - bool parent_affected = - layer->parent() && layer->parent()->IsAffectedByPageScale(); - layer->SetIsAffectedByPageScale(is_page_scale_layer || parent_affected); - // Reset any state that should be cleared for the next update. stacking_order_changed_ = false; update_rect_ = gfx::Rect(); @@ -1345,6 +1334,301 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { num_dependents_need_push_properties_ = 0; } +void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { + proto->set_type(proto::LayerType::LAYER); +} + +void Layer::ToLayerNodeProto(proto::LayerNode* proto) const { + proto->set_id(layer_id_); + SetTypeForProtoSerialization(proto); + + if (parent_) + proto->set_parent_id(parent_->id()); + + DCHECK_EQ(0, proto->children_size()); + for (const auto& child : children_) { + child->ToLayerNodeProto(proto->add_children()); + } + + if (mask_layer_) + mask_layer_->ToLayerNodeProto(proto->mutable_mask_layer()); + if (replica_layer_) + replica_layer_->ToLayerNodeProto(proto->mutable_replica_layer()); +} + +void Layer::FromLayerNodeProto(const proto::LayerNode& proto, + const LayerIdMap& layer_map) { + DCHECK(proto.has_id()); + layer_id_ = proto.id(); + + // Recursively remove all children. In the case of when the updated + // hierarchy has no children, or the children has changed, the old list + // of children must be removed. The whole hierarchy is always sent, so + // if there were no change in the children, they will be correctly added back + // below. + RemoveAllChildren(); + for (int i = 0; i < proto.children_size(); ++i) { + const proto::LayerNode& child_proto = proto.children(i); + DCHECK(child_proto.has_type()); + scoped_refptr<Layer> child = + LayerProtoConverter::FindOrAllocateAndConstruct(child_proto, layer_map); + child->FromLayerNodeProto(child_proto, layer_map); + AddChild(child); + } + + if (mask_layer_) + mask_layer_->RemoveFromParent(); + if (proto.has_mask_layer()) { + mask_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct( + proto.mask_layer(), layer_map); + mask_layer_->FromLayerNodeProto(proto.mask_layer(), layer_map); + mask_layer_->SetParent(this); + // SetIsMask() is only ever called with true, so no need to reset flag. + mask_layer_->SetIsMask(true); + } else { + mask_layer_ = nullptr; + } + + if (replica_layer_) + replica_layer_->RemoveFromParent(); + if (proto.has_replica_layer()) { + replica_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct( + proto.replica_layer(), layer_map); + replica_layer_->FromLayerNodeProto(proto.replica_layer(), layer_map); + replica_layer_->SetParent(this); + } else { + replica_layer_ = nullptr; + } +} + +bool Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update) { + if (!needs_push_properties_ && num_dependents_need_push_properties_ == 0) + return false; + + // Always set properties metadata for serialized layers. + proto::LayerProperties* proto = layer_update->add_layers(); + proto->set_id(layer_id_); + proto->set_needs_push_properties(needs_push_properties_); + proto->set_num_dependents_need_push_properties( + num_dependents_need_push_properties_); + + if (needs_push_properties_) + LayerSpecificPropertiesToProto(proto); + + needs_push_properties_ = false; + + bool descendant_needs_push_properties = + num_dependents_need_push_properties_ > 0; + num_dependents_need_push_properties_ = 0; + + return descendant_needs_push_properties; +} + +void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) { + DCHECK(proto.has_id()); + DCHECK_EQ(layer_id_, proto.id()); + DCHECK(proto.has_needs_push_properties()); + needs_push_properties_ = proto.needs_push_properties(); + DCHECK(proto.has_num_dependents_need_push_properties()); + num_dependents_need_push_properties_ = + proto.num_dependents_need_push_properties(); + + if (!needs_push_properties_) + return; + + FromLayerSpecificPropertiesProto(proto); +} + +void Layer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto) { + proto::BaseLayerProperties* base = proto->mutable_base(); + + bool use_paint_properties = layer_tree_host_ && + paint_properties_.source_frame_number == + layer_tree_host_->source_frame_number(); + + Point3FToProto(transform_origin_, base->mutable_transform_origin()); + base->set_background_color(background_color_); + SizeToProto(use_paint_properties ? paint_properties_.bounds : bounds_, + base->mutable_bounds()); + + // TODO(nyquist): Figure out what to do with debug info. See crbug.com/570372. + + base->set_transform_free_index(transform_tree_index_); + base->set_effect_tree_index(effect_tree_index_); + base->set_clip_tree_index(clip_tree_index_); + Vector2dFToProto(offset_to_transform_parent_, + base->mutable_offset_to_transform_parent()); + base->set_double_sided(double_sided_); + base->set_draws_content(draws_content_); + base->set_hide_layer_and_subtree(hide_layer_and_subtree_); + base->set_has_render_surface(has_render_surface_); + + // TODO(nyquist): Add support for serializing FilterOperations for + // |filters_| and |background_filters_|. See crbug.com/541321. + + base->set_masks_to_bounds(masks_to_bounds_); + base->set_should_scroll_on_main_thread(should_scroll_on_main_thread_); + base->set_have_wheel_event_handlers(have_wheel_event_handlers_); + base->set_have_scroll_event_handlers(have_scroll_event_handlers_); + RegionToProto(non_fast_scrollable_region_, + base->mutable_non_fast_scrollable_region()); + RegionToProto(touch_event_handler_region_, + base->mutable_touch_event_handler_region()); + base->set_scroll_blocks_on(scroll_blocks_on_); + base->set_contents_opaque(contents_opaque_); + base->set_opacity(opacity_); + base->set_blend_mode(SkXfermodeModeToProto(blend_mode_)); + base->set_is_root_for_isolated_group(is_root_for_isolated_group_); + PointFToProto(position_, base->mutable_position()); + base->set_is_container_for_fixed_position_layers( + is_container_for_fixed_position_layers_); + position_constraint_.ToProtobuf(base->mutable_position_constraint()); + base->set_should_flatten_transform(should_flatten_transform_); + base->set_should_flatten_transform_from_property_tree( + should_flatten_transform_from_property_tree_); + base->set_draw_blend_mode(SkXfermodeModeToProto(draw_blend_mode_)); + base->set_use_parent_backface_visibility(use_parent_backface_visibility_); + TransformToProto(transform_, base->mutable_transform()); + base->set_transform_is_invertible(transform_is_invertible_); + base->set_sorting_context_id(sorting_context_id_); + base->set_num_descendants_that_draw_content( + num_descendants_that_draw_content_); + + base->set_scroll_clip_layer_id(scroll_clip_layer_id_); + base->set_user_scrollable_horizontal(user_scrollable_horizontal_); + base->set_user_scrollable_vertical(user_scrollable_vertical_); + + int scroll_parent_id = scroll_parent_ ? scroll_parent_->id() : INVALID_ID; + base->set_scroll_parent_id(scroll_parent_id); + + if (scroll_children_) { + for (auto* child : *scroll_children_) + base->add_scroll_children_ids(child->id()); + } + + int clip_parent_id = clip_parent_ ? clip_parent_->id() : INVALID_ID; + base->set_clip_parent_id(clip_parent_id); + + if (clip_children_) { + for (auto* child : *clip_children_) + base->add_clip_children_ids(child->id()); + } + + ScrollOffsetToProto(scroll_offset_, base->mutable_scroll_offset()); + Vector2dFToProto(scroll_compensation_adjustment_, + base->mutable_scroll_compensation_adjustment()); + + // TODO(nyquist): Figure out what to do with CopyRequests. + // See crbug.com/570374. + + RectToProto(update_rect_, base->mutable_update_rect()); + base->set_stacking_order_changed(stacking_order_changed_); + + // TODO(nyquist): Figure out what to do with LayerAnimationController. + // See crbug.com/570376. + // TODO(nyquist): Figure out what to do with FrameTimingRequests. See + // crbug.com/570377. + + stacking_order_changed_ = false; + update_rect_ = gfx::Rect(); +} + +void Layer::FromLayerSpecificPropertiesProto( + const proto::LayerProperties& proto) { + DCHECK(proto.has_base()); + DCHECK(layer_tree_host_); + const proto::BaseLayerProperties& base = proto.base(); + + transform_origin_ = ProtoToPoint3F(base.transform_origin()); + background_color_ = base.background_color(); + bounds_ = ProtoToSize(base.bounds()); + + transform_tree_index_ = base.transform_free_index(); + effect_tree_index_ = base.effect_tree_index(); + clip_tree_index_ = base.clip_tree_index(); + offset_to_transform_parent_ = + ProtoToVector2dF(base.offset_to_transform_parent()); + double_sided_ = base.double_sided(); + draws_content_ = base.draws_content(); + hide_layer_and_subtree_ = base.hide_layer_and_subtree(); + has_render_surface_ = base.has_render_surface(); + masks_to_bounds_ = base.masks_to_bounds(); + should_scroll_on_main_thread_ = base.should_scroll_on_main_thread(); + have_wheel_event_handlers_ = base.have_wheel_event_handlers(); + have_scroll_event_handlers_ = base.have_scroll_event_handlers(); + non_fast_scrollable_region_ = + RegionFromProto(base.non_fast_scrollable_region()); + touch_event_handler_region_ = + RegionFromProto(base.touch_event_handler_region()); + scroll_blocks_on_ = (ScrollBlocksOn)base.scroll_blocks_on(); + contents_opaque_ = base.contents_opaque(); + opacity_ = base.opacity(); + blend_mode_ = SkXfermodeModeFromProto(base.blend_mode()); + is_root_for_isolated_group_ = base.is_root_for_isolated_group(); + position_ = ProtoToPointF(base.position()); + is_container_for_fixed_position_layers_ = + base.is_container_for_fixed_position_layers(); + position_constraint_.FromProtobuf(base.position_constraint()); + should_flatten_transform_ = base.should_flatten_transform(); + should_flatten_transform_from_property_tree_ = + base.should_flatten_transform_from_property_tree(); + draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); + use_parent_backface_visibility_ = base.use_parent_backface_visibility(); + transform_ = ProtoToTransform(base.transform()); + transform_is_invertible_ = base.transform_is_invertible(); + sorting_context_id_ = base.sorting_context_id(); + num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); + + scroll_clip_layer_id_ = base.scroll_clip_layer_id(); + user_scrollable_horizontal_ = base.user_scrollable_horizontal(); + user_scrollable_vertical_ = base.user_scrollable_vertical(); + + scroll_parent_ = base.scroll_parent_id() == INVALID_ID + ? nullptr + : layer_tree_host_->LayerById(base.scroll_parent_id()); + + // If there have been scroll children entries in previous deserializations, + // clear out the set. If there have been none, initialize the set of children. + // After this, the set is in the correct state to only add the new children. + // If the set of children has not changed, for now this code still rebuilds + // the set. + if (scroll_children_) + scroll_children_->clear(); + else if (base.scroll_children_ids_size() > 0) + scroll_children_.reset(new std::set<Layer*>); + for (int i = 0; i < base.scroll_children_ids_size(); ++i) { + int child_id = base.scroll_children_ids(i); + scoped_refptr<Layer> child = layer_tree_host_->LayerById(child_id); + scroll_children_->insert(child.get()); + } + + clip_parent_ = base.clip_parent_id() == INVALID_ID + ? nullptr + : layer_tree_host_->LayerById(base.clip_parent_id()); + + // If there have been clip children entries in previous deserializations, + // clear out the set. If there have been none, initialize the set of children. + // After this, the set is in the correct state to only add the new children. + // If the set of children has not changed, for now this code still rebuilds + // the set. + if (clip_children_) + clip_children_->clear(); + else if (base.clip_children_ids_size() > 0) + clip_children_.reset(new std::set<Layer*>); + for (int i = 0; i < base.clip_children_ids_size(); ++i) { + int child_id = base.clip_children_ids(i); + scoped_refptr<Layer> child = layer_tree_host_->LayerById(child_id); + clip_children_->insert(child.get()); + } + + scroll_offset_ = ProtoToScrollOffset(base.scroll_offset()); + scroll_compensation_adjustment_ = + ProtoToVector2dF(base.scroll_compensation_adjustment()); + + update_rect_.Union(ProtoToRect(base.update_rect())); + stacking_order_changed_ = base.stacking_order_changed(); +} + scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { return LayerImpl::Create(tree_impl, layer_id_, new LayerImpl::SyncedScrollOffset); @@ -1408,7 +1692,7 @@ bool Layer::IsSuitableForGpuRasterization() const { scoped_refptr<base::trace_event::ConvertableToTraceFormat> Layer::TakeDebugInfo() { if (client_) - return client_->TakeDebugInfo(); + return client_->TakeDebugInfo(this); else return nullptr; } @@ -1418,9 +1702,8 @@ void Layer::SetHasRenderSurface(bool has_render_surface) { return; has_render_surface_ = has_render_surface; // We do not need SetNeedsCommit here, since this is only ever called - // during a commit, from CalculateDrawProperties. + // during a commit, from CalculateDrawProperties using property trees. SetNeedsPushProperties(); - layer_tree_host_->property_trees()->needs_rebuild = true; } gfx::ScrollOffset Layer::ScrollOffsetForAnimation() const { @@ -1537,7 +1820,7 @@ bool Layer::AddAnimation(scoped_ptr <Animation> animation) { UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", !layer_tree_host_); - layer_animation_controller_->AddAnimation(animation.Pass()); + layer_animation_controller_->AddAnimation(std::move(animation)); SetNeedsCommit(); return true; } @@ -1562,6 +1845,12 @@ void Layer::RemoveAnimation(int animation_id, SetNeedsCommit(); } +void Layer::AbortAnimation(int animation_id) { + DCHECK(layer_animation_controller_); + layer_animation_controller_->AbortAnimation(animation_id); + SetNeedsCommit(); +} + void Layer::SetLayerAnimationControllerForTest( scoped_refptr<LayerAnimationController> controller) { DCHECK(layer_animation_controller_); @@ -1654,6 +1943,26 @@ void Layer::SetFrameTimingRequests( SetNeedsCommit(); } +void Layer::SetElementId(uint64_t id) { + DCHECK(IsPropertyChangeAllowed()); + if (element_id_ == id) + return; + TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), + "Layer::SetElementId", "id", id); + element_id_ = id; + SetNeedsCommit(); +} + +void Layer::SetMutableProperties(uint32_t properties) { + DCHECK(IsPropertyChangeAllowed()); + if (mutable_properties_ == properties) + return; + TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), + "Layer::SetMutableProperties", "properties", properties); + mutable_properties_ = properties; + SetNeedsCommit(); +} + void Layer::DidBeginTracing() { // We'll be dumping layer trees as part of trace, so make sure // PushPropertiesTo() propagates layer debug info to the impl @@ -1662,6 +1971,13 @@ void Layer::DidBeginTracing() { SetNeedsPushProperties(); } +int Layer::num_copy_requests_in_target_subtree() { + return layer_tree_host() + ->property_trees() + ->effect_tree.Node(effect_tree_index()) + ->data.num_copy_requests_in_subtree; +} + void Layer::set_visited(bool visited) { visited_tracker_ = visited ? layer_tree_host()->meta_information_sequence_number() : 0; diff --git a/chromium/cc/layers/layer.h b/chromium/cc/layers/layer.h index 2fec3636457..ef5da3359dc 100644 --- a/chromium/cc/layers/layer.h +++ b/chromium/cc/layers/layer.h @@ -5,11 +5,15 @@ #ifndef CC_LAYERS_LAYER_H_ #define CC_LAYERS_LAYER_H_ +#include <stddef.h> +#include <stdint.h> + #include <set> #include <string> #include <vector> #include "base/callback.h" +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" #include "cc/animation/layer_animation_controller.h" @@ -17,7 +21,6 @@ #include "cc/animation/layer_animation_value_provider.h" #include "cc/base/cc_export.h" #include "cc/base/region.h" -#include "cc/base/scoped_ptr_vector.h" #include "cc/debug/frame_timing_request.h" #include "cc/debug/micro_benchmark.h" #include "cc/layers/layer_lists.h" @@ -67,6 +70,12 @@ class ScrollbarLayerInterface; class SimpleEnclosedRegion; struct AnimationEvent; +namespace proto { +class LayerNode; +class LayerProperties; +class LayerUpdate; +} // namespace proto + // Base class for composited layers. Special layer types are derived from // this class. class CC_EXPORT Layer : public base::RefCounted<Layer>, @@ -74,6 +83,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, public LayerAnimationValueProvider { public: typedef LayerList LayerListType; + typedef base::hash_map<int, scoped_refptr<Layer>> LayerIdMap; enum LayerIdLabels { INVALID_ID = -1, @@ -345,6 +355,8 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, virtual bool DrawsContent() const; // This methods typically need to be overwritten by derived classes. + // TODO(chrishtr): Blink no longer resizes anything during paint. We can + // remove this. virtual void SavePaintProperties(); // Returns true iff anything was updated that needs to be committed. virtual bool Update(); @@ -358,6 +370,46 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, virtual void PushPropertiesTo(LayerImpl* layer); + // Sets the type proto::LayerType that should be used for serialization + // of the current layer by calling LayerNode::set_type(proto::LayerType). + // TODO(nyquist): Start using a forward declared enum class when + // https://github.com/google/protobuf/issues/67 has been fixed and rolled in. + // This function would preferably instead return a proto::LayerType, but + // since that is an enum (the protobuf library does not generate enum + // classes), it can't be forward declared. We don't want to include + // //cc/proto/layer.pb.h in this header file, as it requires that all + // dependent targets would have to be given the config for how to include it. + virtual void SetTypeForProtoSerialization(proto::LayerNode* proto) const; + + // Recursively iterate over this layer and all children and write the + // hierarchical structure to the given LayerNode proto. In addition to the + // structure itself, the Layer id and type is also written to facilitate + // construction of the correct layer on the client. + void ToLayerNodeProto(proto::LayerNode* proto) const; + + // Recursively iterate over the given LayerNode proto and read the structure + // into this node and its children. The |layer_map| should be used to look + // for previously existing Layers, since they should be re-used between each + // hierarchy update. + void FromLayerNodeProto(const proto::LayerNode& proto, + const LayerIdMap& layer_map); + + // This method is similar to PushPropertiesTo, but instead of pushing to + // a LayerImpl, it pushes the properties to proto::LayerProperties. It adds + // this layer to the proto::LayerUpdate if it or any of its descendants + // have changed properties. If this layer contains changed properties, the + // properties themselves will also be pushed the proto::LayerProperties. + // Similarly to PushPropertiesTo, this method also resets + // |needs_push_properties_| and |num_dependents_need_push_properties_|. + // Returns whether any of the descendants have changed properties. + bool ToLayerPropertiesProto(proto::LayerUpdate* layer_update); + + // Read all property values from the given LayerProperties object and update + // the current layer. The values for |needs_push_properties_| and + // |num_dependents_need_push_properties_| are always updated, but the rest + // of |proto| is only read if |needs_push_properties_| is set. + void FromLayerPropertiesProto(const proto::LayerProperties& proto); + LayerTreeHost* layer_tree_host() { return layer_tree_host_; } const LayerTreeHost* layer_tree_host() const { return layer_tree_host_; } @@ -365,6 +417,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, void PauseAnimation(int animation_id, double time_offset); void RemoveAnimation(int animation_id); void RemoveAnimation(int animation_id, Animation::TargetProperty property); + void AbortAnimation(int animation_id); LayerAnimationController* layer_animation_controller() const { return layer_animation_controller_.get(); } @@ -473,6 +526,10 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, const gfx::Rect& clip_rect() const { return clip_rect_; } void set_clip_rect(const gfx::Rect& rect) { clip_rect_ = rect; } + // This should only be called during BeginMainFrame since it does not trigger + // a Commit. This is called right after property tree being built and should + // not trigger property tree rebuild. + void SetHasRenderSurface(bool has_render_surface); bool has_render_surface() const { return has_render_surface_; } @@ -486,15 +543,14 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, } void DidBeginTracing(); - // TODO(weiliangc): this should move to the effect tree. - void set_num_layer_or_descendant_with_copy_request( - int num_layer_or_descendants_with_copy_request) { - num_layer_or_descendants_with_copy_request_ = - num_layer_or_descendants_with_copy_request; - } - int num_layer_or_descendants_with_copy_request() { - return num_layer_or_descendants_with_copy_request_; - } + + int num_copy_requests_in_target_subtree(); + + void SetElementId(uint64_t id); + uint64_t element_id() const { return element_id_; } + + void SetMutableProperties(uint32_t properties); + uint32_t mutable_properties() const { return mutable_properties_; } void set_visited(bool visited); bool visited(); @@ -502,6 +558,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, bool layer_or_descendant_is_drawn(); void set_sorted_for_recursion(bool sorted_for_recursion); bool sorted_for_recursion(); + void set_is_hidden_from_property_trees(bool is_hidden) { + if (is_hidden == is_hidden_from_property_trees_) + return; + is_hidden_from_property_trees_ = is_hidden; + SetNeedsPushProperties(); + } // LayerAnimationValueProvider implementation. gfx::ScrollOffset ScrollOffsetForAnimation() const override; @@ -560,6 +622,24 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, bool IsPropertyChangeAllowed() const; + // Serialize all the necessary properties to be able to reconstruct this Layer + // into proto::LayerProperties. This function must not set values for + // |needs_push_properties_| or |num_dependents_need_push_properties_| as they + // are dealt with at a higher level. This is only called if + // |needs_push_properties_| is set. For descendants of Layer, implementations + // must first call their parent class. This method is not marked as const + // as some implementations need reset member fields, similarly to + // PushPropertiesTo(). + virtual void LayerSpecificPropertiesToProto(proto::LayerProperties* proto); + + // Deserialize all the necessary properties from proto::LayerProperties into + // this Layer. This function must not set values for |needs_push_properties_| + // or |num_dependents_need_push_properties_| as they are dealt with at a + // higher level. This is only called if |needs_push_properties_| is set. For + // descendants of Layer, implementations must first call their parent class. + virtual void FromLayerSpecificPropertiesProto( + const proto::LayerProperties& proto); + // This flag is set when the layer needs to push properties to the impl // side. bool needs_push_properties_; @@ -595,14 +675,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, private: friend class base::RefCounted<Layer>; + friend class LayerSerializationTest; friend class LayerTreeHostCommon; + void SetParent(Layer* layer); bool DescendantIsFixedToContainerLayer() const; - // This should only be called during BeginMainFrame since it does not - // trigger a Commit. - void SetHasRenderSurface(bool has_render_surface); - // This should only be called from RemoveFromParent(). void RemoveChildOrDependent(Layer* child); @@ -618,8 +696,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, // indices becomes invalid. void InvalidatePropertyTreesIndices(); - void UpdateNumCopyRequestsForSubtree(int delta); - LayerList children_; Layer* parent_; @@ -644,7 +720,8 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, int effect_tree_index_; int clip_tree_index_; int property_tree_sequence_number_; - int num_layer_or_descendants_with_copy_request_; + uint64_t element_id_; + uint32_t mutable_properties_; gfx::Vector2dF offset_to_transform_parent_; bool should_flatten_transform_from_property_tree_ : 1; bool should_scroll_on_main_thread_ : 1; @@ -700,7 +777,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, LayerClient* client_; - ScopedPtrVector<CopyOutputRequest> copy_requests_; + std::vector<scoped_ptr<CopyOutputRequest>> copy_requests_; base::Closure did_scroll_callback_; @@ -713,6 +790,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, std::vector<FrameTimingRequest> frame_timing_requests_; bool frame_timing_requests_dirty_; + bool is_hidden_from_property_trees_; DISALLOW_COPY_AND_ASSIGN(Layer); }; diff --git a/chromium/cc/layers/layer_client.h b/chromium/cc/layers/layer_client.h index bcdf1c3c77d..524399d0d84 100644 --- a/chromium/cc/layers/layer_client.h +++ b/chromium/cc/layers/layer_client.h @@ -5,8 +5,6 @@ #ifndef CC_LAYERS_LAYER_CLIENT_H_ #define CC_LAYERS_LAYER_CLIENT_H_ -#include <string> - #include "base/memory/ref_counted.h" #include "cc/base/cc_export.h" @@ -18,14 +16,19 @@ class ConvertableToTraceFormat; namespace cc { +class Layer; + class CC_EXPORT LayerClient { public: // Returns a pointer to a debug info object, if one has been computed. // If not, returns nullptr. // If the returned pointer is non-nullptr, the caller takes // ownership of the pointer. + // + // A pointer to the layer is provided for the convenience of layer clients + // which service multiple layers. virtual scoped_refptr<base::trace_event::ConvertableToTraceFormat> - TakeDebugInfo() = 0; + TakeDebugInfo(Layer* layer) = 0; protected: virtual ~LayerClient() {} diff --git a/chromium/cc/layers/layer_impl.cc b/chromium/cc/layers/layer_impl.cc index 4feff4e3d68..b845968c2f7 100644 --- a/chromium/cc/layers/layer_impl.cc +++ b/chromium/cc/layers/layer_impl.cc @@ -4,13 +4,18 @@ #include "cc/layers/layer_impl.h" +#include <stddef.h> +#include <stdint.h> + +#include <utility> + #include "base/json/json_reader.h" #include "base/numerics/safe_conversions.h" #include "base/strings/stringprintf.h" #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_argument.h" #include "cc/animation/animation_registrar.h" -#include "cc/animation/scrollbar_animation_controller.h" +#include "cc/animation/mutable_properties.h" #include "cc/base/math_util.h" #include "cc/base/simple_enclosed_region.h" #include "cc/debug/debug_colors.h" @@ -18,11 +23,12 @@ #include "cc/debug/micro_benchmark_impl.h" #include "cc/debug/traced_value.h" #include "cc/input/scroll_state.h" +#include "cc/layers/layer.h" #include "cc/layers/layer_utils.h" -#include "cc/layers/painted_scrollbar_layer_impl.h" #include "cc/output/copy_output_request.h" #include "cc/quads/debug_border_draw_quad.h" #include "cc/quads/render_pass.h" +#include "cc/trees/draw_property_utils.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_impl.h" #include "cc/trees/layer_tree_settings.h" @@ -50,7 +56,7 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, layer_id_(id), layer_tree_impl_(tree_impl), scroll_offset_(scroll_offset), - scroll_clip_layer_(nullptr), + scroll_clip_layer_id_(Layer::INVALID_ID), should_scroll_on_main_thread_(false), have_wheel_event_handlers_(false), have_scroll_event_handlers_(false), @@ -71,6 +77,7 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, transform_is_invertible_(true), is_container_for_fixed_position_layers_(false), is_affected_by_page_scale_(true), + was_ever_ready_since_last_transform_animation_(true), background_color_(0), opacity_(1.0), blend_mode_(SkXfermode::kSrcOver_Mode), @@ -84,12 +91,15 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, num_dependents_need_push_properties_(0), sorting_context_id_(0), current_draw_mode_(DRAW_MODE_NONE), - num_layer_or_descendants_with_copy_request_(0), + element_id_(0), + mutable_properties_(kMutablePropertyNone), + force_render_surface_(false), frame_timing_requests_dirty_(false), visited_(false), layer_or_descendant_is_drawn_(false), layer_or_descendant_has_input_handler_(false), - sorted_for_recursion_(false) { + sorted_for_recursion_(false), + is_hidden_from_property_trees_(false) { DCHECK_GT(layer_id_, 0); DCHECK(layer_tree_impl_); layer_tree_impl_->RegisterLayer(this); @@ -104,6 +114,9 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, layer_animation_controller_->set_layer_animation_delegate(this); } } + + layer_tree_impl_->AddToElementMap(this); + SetNeedsPushProperties(); } @@ -118,8 +131,11 @@ LayerImpl::~LayerImpl() { if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree()) layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); + layer_tree_impl_->UnregisterScrollLayer(this); layer_tree_impl_->UnregisterLayer(this); + layer_tree_impl_->RemoveFromElementMap(this); + TRACE_EVENT_OBJECT_DELETED_WITH_ID( TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); } @@ -127,7 +143,7 @@ LayerImpl::~LayerImpl() { void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) { child->SetParent(this); DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl()); - children_.push_back(child.Pass()); + children_.push_back(std::move(child)); layer_tree_impl()->set_needs_update_draw_properties(); } @@ -135,11 +151,11 @@ scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) { for (OwnedLayerImplList::iterator it = children_.begin(); it != children_.end(); ++it) { - if (*it == child) { - scoped_ptr<LayerImpl> ret = children_.take(it); + if (it->get() == child) { + scoped_ptr<LayerImpl> ret = std::move(*it); children_.erase(it); layer_tree_impl()->set_needs_update_draw_properties(); - return ret.Pass(); + return ret; } } return nullptr; @@ -260,7 +276,8 @@ void LayerImpl::SetEffectTreeIndex(int index) { SetNeedsPushProperties(); } -void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) { +void LayerImpl::PassCopyRequests( + std::vector<scoped_ptr<CopyOutputRequest>>* requests) { // In the case that a layer still has a copy request, this means that there's // a commit to the active tree without a draw. This only happens in some // edge cases during lost context or visibility changes, so don't try to @@ -274,9 +291,9 @@ void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) { if (requests->empty()) return; - DCHECK(render_surface()); bool was_empty = copy_requests_.empty(); - copy_requests_.insert_and_take(copy_requests_.end(), requests); + for (auto& request : *requests) + copy_requests_.push_back(std::move(request)); requests->clear(); if (was_empty && layer_tree_impl()->IsActiveTree()) @@ -285,24 +302,25 @@ void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) { } void LayerImpl::TakeCopyRequestsAndTransformToTarget( - ScopedPtrVector<CopyOutputRequest>* requests) { + std::vector<scoped_ptr<CopyOutputRequest>>* requests) { DCHECK(!copy_requests_.empty()); DCHECK(layer_tree_impl()->IsActiveTree()); DCHECK_EQ(render_target(), this); size_t first_inserted_request = requests->size(); - requests->insert_and_take(requests->end(), ©_requests_); + for (auto& request : copy_requests_) + requests->push_back(std::move(request)); copy_requests_.clear(); for (size_t i = first_inserted_request; i < requests->size(); ++i) { - CopyOutputRequest* request = requests->at(i); + CopyOutputRequest* request = (*requests)[i].get(); if (!request->has_area()) continue; gfx::Rect request_in_layer_space = request->area(); request_in_layer_space.Intersect(gfx::Rect(bounds())); request->set_area(MathUtil::MapEnclosingClippedRect( - draw_properties_.target_space_transform, request_in_layer_space)); + DrawTransform(), request_in_layer_space)); } layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); @@ -459,7 +477,20 @@ gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { } void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) { - scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id); + if (scroll_clip_layer_id_ == scroll_clip_layer_id) + return; + + layer_tree_impl()->UnregisterScrollLayer(this); + scroll_clip_layer_id_ = scroll_clip_layer_id; + layer_tree_impl()->RegisterScrollLayer(this); +} + +LayerImpl* LayerImpl::scroll_clip_layer() const { + return layer_tree_impl()->LayerById(scroll_clip_layer_id_); +} + +bool LayerImpl::scrollable() const { + return scroll_clip_layer_id_ != Layer::INVALID_ID; } bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const { @@ -481,7 +512,8 @@ InputHandler::ScrollStatus LayerImpl::TryScroll( return InputHandler::SCROLL_ON_MAIN_THREAD; } - if (!screen_space_transform().IsInvertible()) { + gfx::Transform screen_space_transform = ScreenSpaceTransform(); + if (!screen_space_transform.IsInvertible()) { TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform"); return InputHandler::SCROLL_IGNORED; } @@ -490,7 +522,7 @@ InputHandler::ScrollStatus LayerImpl::TryScroll( bool clipped = false; gfx::Transform inverse_screen_space_transform( gfx::Transform::kSkipInitialization); - if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) { + if (!screen_space_transform.GetInverse(&inverse_screen_space_transform)) { // TODO(shawnsingh): We shouldn't be applying a projection if screen space // transform is uninvertible here. Perhaps we should be returning // SCROLL_ON_MAIN_THREAD in this case? @@ -551,7 +583,14 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { layer->SetDoubleSided(double_sided_); layer->SetDrawsContent(DrawsContent()); layer->SetHideLayerAndSubtree(hide_layer_and_subtree_); + // If whether layer has render surface changes, we need to update draw + // properties. + // TODO(weiliangc): Should be safely removed after impl side is able to + // update render surfaces without rebuilding property trees. + if (layer->has_render_surface() != has_render_surface()) + layer->layer_tree_impl()->set_needs_update_draw_properties(); layer->SetHasRenderSurface(!!render_surface()); + layer->SetForceRenderSurface(force_render_surface_); layer->SetFilters(filters()); layer->SetBackgroundFilters(background_filters()); layer->SetMasksToBounds(masks_to_bounds_); @@ -576,8 +615,9 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); - layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() - : Layer::INVALID_ID); + layer->SetScrollClipLayer(scroll_clip_layer_id_); + layer->SetElementId(element_id_); + layer->SetMutableProperties(mutable_properties_); layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); layer->set_user_scrollable_vertical(user_scrollable_vertical_); @@ -592,6 +632,7 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { layer->SetClipTreeIndex(clip_tree_index_); layer->SetEffectTreeIndex(effect_tree_index_); layer->set_offset_to_transform_parent(offset_to_transform_parent_); + layer->set_is_hidden_from_property_trees(is_hidden_from_property_trees_); LayerImpl* scroll_parent = nullptr; if (scroll_parent_) { @@ -645,9 +686,6 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { layer->SetStackingOrderChanged(stacking_order_changed_); layer->SetDebugInfo(debug_info_); - layer->set_num_layer_or_descendant_with_copy_request( - num_layer_or_descendants_with_copy_request_); - set_num_layer_or_descendant_with_copy_request(0); if (frame_timing_requests_dirty_) { layer->SetFrameTimingRequests(frame_timing_requests_); @@ -661,16 +699,20 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { num_dependents_need_push_properties_ = 0; } +bool LayerImpl::IsAffectedByPageScale() const { + TransformTree& transform_tree = + layer_tree_impl()->property_trees()->transform_tree; + return transform_tree.Node(transform_tree_index()) + ->data.in_subtree_of_page_scale_layer; +} + gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const { - if (!scroll_clip_layer_) + LayerImpl* scroll_clip_layer = + layer_tree_impl()->LayerById(scroll_clip_layer_id_); + if (!scroll_clip_layer) return gfx::Vector2dF(); - gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta(); - - // In virtual-viewport mode, we don't need to compensate for pinch zoom or - // scale since the fixed container is the outer viewport, which sits below - // the page scale. - return delta_from_scroll; + return scroll_clip_layer->bounds_delta(); } base::DictionaryValue* LayerImpl::LayerTreeAsJson() const { @@ -688,7 +730,7 @@ base::DictionaryValue* LayerImpl::LayerTreeAsJson() const { list->AppendDouble(position_.y()); result->Set("Position", list); - const gfx::Transform& gfx_transform = draw_properties_.target_space_transform; + const gfx::Transform& gfx_transform = DrawTransform(); double transform[16]; gfx_transform.matrix().asColMajord(transform); list = new base::ListValue; @@ -803,6 +845,13 @@ void LayerImpl::ResetAllChangeTrackingForSubtree() { num_dependents_need_push_properties_ = 0; } +int LayerImpl::num_copy_requests_in_target_subtree() { + return layer_tree_impl() + ->property_trees() + ->effect_tree.Node(effect_tree_index()) + ->data.num_copy_requests_in_subtree; +} + void LayerImpl::UpdatePropertyTreeTransform() { if (transform_tree_index_ != -1) { TransformTree& transform_tree = @@ -868,6 +917,7 @@ void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) { } transform_tree.set_needs_update(true); + layer_tree_impl()->set_needs_update_draw_properties(); } } } @@ -875,6 +925,8 @@ void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) { void LayerImpl::UpdatePropertyTreeOpacity() { if (effect_tree_index_ != -1) { EffectTree& effect_tree = layer_tree_impl()->property_trees()->effect_tree; + if (effect_tree_index_ >= static_cast<int>(effect_tree.size())) + return; EffectNode* node = effect_tree.Node(effect_tree_index_); // A LayerImpl's own current state is insufficient for determining whether // it owns an OpacityNode, since this depends on the state of the @@ -918,6 +970,7 @@ void LayerImpl::OnOpacityAnimated(float opacity) { void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { SetTransform(transform); UpdatePropertyTreeTransform(); + was_ever_ready_since_last_transform_animation_ = false; } void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { @@ -936,6 +989,7 @@ void LayerImpl::OnAnimationWaitingForDeletion() {} void LayerImpl::OnTransformIsPotentiallyAnimatingChanged(bool is_animating) { UpdatePropertyTreeTransformIsAnimated(is_animating); + was_ever_ready_since_last_transform_animation_ = false; } bool LayerImpl::IsActive() const { @@ -959,7 +1013,7 @@ void LayerImpl::SetBounds(const gfx::Size& bounds) { bounds_ = bounds; - ScrollbarParametersDidChange(true); + layer_tree_impl()->DidUpdateScrollState(id()); if (masks_to_bounds()) NoteLayerPropertyChangedForSubtree(); else @@ -980,7 +1034,7 @@ void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) { else if (this == layer_tree_impl()->OuterViewportContainerLayer()) transform_tree.SetOuterViewportBoundsDelta(bounds_delta); - ScrollbarParametersDidChange(true); + layer_tree_impl()->DidUpdateScrollState(id()); if (masks_to_bounds()) { // If layer is clipping, then update the clip node using the new bounds. @@ -1009,7 +1063,7 @@ void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { return; } - mask_layer_ = mask_layer.Pass(); + mask_layer_ = std::move(mask_layer); mask_layer_id_ = new_layer_id; if (mask_layer_) mask_layer_->SetParent(this); @@ -1018,7 +1072,7 @@ void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() { mask_layer_id_ = -1; - return mask_layer_.Pass(); + return std::move(mask_layer_); } void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) { @@ -1031,7 +1085,7 @@ void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) { return; } - replica_layer_ = replica_layer.Pass(); + replica_layer_ = std::move(replica_layer); replica_layer_id_ = new_layer_id; if (replica_layer_) replica_layer_->SetParent(this); @@ -1040,7 +1094,7 @@ void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) { scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() { replica_layer_id_ = -1; - return replica_layer_.Pass(); + return std::move(replica_layer_); } ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { @@ -1196,6 +1250,32 @@ bool LayerImpl::OpacityIsAnimatingOnImplOnly() const { return opacity_animation && opacity_animation->is_impl_only(); } +void LayerImpl::SetElementId(uint64_t element_id) { + if (element_id == element_id_) + return; + + TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), + "LayerImpl::SetElementId", "id", element_id); + + layer_tree_impl_->RemoveFromElementMap(this); + element_id_ = element_id; + layer_tree_impl_->AddToElementMap(this); + SetNeedsPushProperties(); +} + +void LayerImpl::SetMutableProperties(uint32_t properties) { + if (mutable_properties_ == properties) + return; + + TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), + "LayerImpl::SetMutableProperties", "properties", properties); + + mutable_properties_ = properties; + // If this layer is already in the element map, update its properties. + layer_tree_impl_->AddToElementMap(this); + SetNeedsPushProperties(); +} + void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) { if (blend_mode_ == blend_mode) return; @@ -1308,6 +1388,12 @@ bool LayerImpl::HasOnlyTranslationTransforms() const { observer_type); } +bool LayerImpl::AnimationsPreserveAxisAlignment() const { + return layer_animation_controller_ + ? layer_animation_controller_->AnimationsPreserveAxisAlignment() + : layer_tree_impl_->AnimationsPreserveAxisAlignment(this); +} + bool LayerImpl::MaximumTargetScale(float* max_scale) const { if (!layer_animation_controller_) return layer_tree_impl_->MaximumTargetScale(this, max_scale); @@ -1480,8 +1566,8 @@ void LayerImpl::UpdatePropertyTreeScrollOffset() { void LayerImpl::DidUpdateScrollOffset() { DCHECK(scroll_offset_); + layer_tree_impl()->DidUpdateScrollState(id()); NoteLayerPropertyChangedForSubtree(); - ScrollbarParametersDidChange(false); UpdatePropertyTreeScrollOffset(); @@ -1515,7 +1601,9 @@ void LayerImpl::RecreateResources() { } gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { - if (!scroll_clip_layer_ || bounds().IsEmpty()) + LayerImpl* scroll_clip_layer = + layer_tree_impl()->LayerById(scroll_clip_layer_id_); + if (!scroll_clip_layer || bounds().IsEmpty()) return gfx::ScrollOffset(); LayerImpl const* page_scale_layer = layer_tree_impl()->PageScaleLayer(); @@ -1524,12 +1612,9 @@ gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { IsContainerForFixedPositionLayers()); float scale_factor = 1.f; - for (LayerImpl const* current_layer = this; - current_layer != scroll_clip_layer_->parent(); - current_layer = current_layer->parent()) { - if (current_layer == page_scale_layer) - scale_factor = layer_tree_impl()->current_page_scale_factor(); - } + DCHECK(scroll_clip_layer != page_scale_layer); + if (!scroll_clip_layer->IsAffectedByPageScale() && IsAffectedByPageScale()) + scale_factor = layer_tree_impl()->current_page_scale_factor(); gfx::SizeF scaled_scroll_bounds = gfx::ScaleSize(BoundsForScrolling(), scale_factor); @@ -1537,8 +1622,8 @@ gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { std::floor(scaled_scroll_bounds.height())); gfx::ScrollOffset max_offset( - scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), - scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); + scaled_scroll_bounds.width() - scroll_clip_layer->bounds().width(), + scaled_scroll_bounds.height() - scroll_clip_layer->bounds().height()); // We need the final scroll offset to be in CSS coords. max_offset.Scale(1 / scale_factor); max_offset.SetToMax(gfx::ScrollOffset()); @@ -1561,147 +1646,6 @@ gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { return delta; } -void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, - LayerImpl* scrollbar_clip_layer, - bool on_resize) const { - DCHECK(scrollbar_layer); - LayerImpl* page_scale_layer = layer_tree_impl()->PageScaleLayer(); - - DCHECK(this != page_scale_layer); - DCHECK(scrollbar_clip_layer); - gfx::RectF clip_rect(gfx::PointF(), - scrollbar_clip_layer->BoundsForScrolling()); - - // See comment in MaxScrollOffset() regarding the use of the content layer - // bounds here. - gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling()); - - if (scroll_rect.size().IsEmpty()) - return; - - gfx::ScrollOffset current_offset; - for (LayerImpl const* current_layer = this; - current_layer != scrollbar_clip_layer->parent(); - current_layer = current_layer->parent()) { - current_offset += current_layer->CurrentScrollOffset(); - if (current_layer == page_scale_layer) { - float scale_factor = layer_tree_impl()->current_page_scale_factor(); - current_offset.Scale(scale_factor); - scroll_rect.Scale(scale_factor); - } - } - - bool scrollbar_needs_animation = false; - scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust( - scrollbar_clip_layer->bounds_delta().y()); - if (scrollbar_layer->orientation() == HORIZONTAL) { - float visible_ratio = clip_rect.width() / scroll_rect.width(); - scrollbar_needs_animation |= - scrollbar_layer->SetCurrentPos(current_offset.x()); - scrollbar_needs_animation |= - scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width()); - scrollbar_needs_animation |= - scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); - } else { - float visible_ratio = clip_rect.height() / scroll_rect.height(); - bool y_offset_did_change = - scrollbar_layer->SetCurrentPos(current_offset.y()); - scrollbar_needs_animation |= y_offset_did_change; - scrollbar_needs_animation |= - scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height()); - scrollbar_needs_animation |= - scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); - if (y_offset_did_change && layer_tree_impl()->IsActiveTree() && - this == layer_tree_impl()->OuterViewportScrollLayer()) { - TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(), - current_offset.y()); - } - } - if (scrollbar_needs_animation) { - layer_tree_impl()->set_needs_update_draw_properties(); - // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars - // should activate for every scroll on the main frame, not just the - // scrolls that move the pinch virtual viewport (i.e. trigger from - // either inner or outer viewport). - if (scrollbar_animation_controller_) { - // Non-overlay scrollbars shouldn't trigger animations. - if (scrollbar_layer->is_overlay_scrollbar()) - scrollbar_animation_controller_->DidScrollUpdate(on_resize); - } - } -} - -void LayerImpl::DidBecomeActive() { - if (layer_tree_impl_->settings().scrollbar_animator == - LayerTreeSettings::NO_ANIMATOR) { - return; - } - - bool need_scrollbar_animation_controller = scrollable() && scrollbars_; - if (!need_scrollbar_animation_controller) { - scrollbar_animation_controller_ = nullptr; - return; - } - - if (scrollbar_animation_controller_) - return; - - scrollbar_animation_controller_ = - layer_tree_impl_->CreateScrollbarAnimationController(this); -} - -void LayerImpl::ClearScrollbars() { - if (!scrollbars_) - return; - - scrollbars_.reset(nullptr); -} - -void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) { - DCHECK(layer); - DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end()); - if (!scrollbars_) - scrollbars_.reset(new ScrollbarSet()); - - scrollbars_->insert(layer); -} - -void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) { - DCHECK(scrollbars_); - DCHECK(layer); - DCHECK(scrollbars_->find(layer) != scrollbars_->end()); - - scrollbars_->erase(layer); - if (scrollbars_->empty()) - scrollbars_ = nullptr; -} - -bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const { - if (!scrollbars_) - return false; - - for (ScrollbarSet::iterator it = scrollbars_->begin(); - it != scrollbars_->end(); - ++it) - if ((*it)->orientation() == orientation) - return true; - - return false; -} - -void LayerImpl::ScrollbarParametersDidChange(bool on_resize) { - if (!scrollbars_) - return; - - for (ScrollbarSet::iterator it = scrollbars_->begin(); - it != scrollbars_->end(); - ++it) { - bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_; - bool scroll_layer_resized = is_scroll_layer && on_resize; - (*it)->ScrollbarParametersDidChange(scroll_layer_resized); - } -} - void LayerImpl::SetNeedsPushProperties() { if (needs_push_properties_) return; @@ -1749,6 +1693,11 @@ void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { state->SetInteger("gpu_memory_usage", base::saturated_cast<int>(GPUMemoryUsageInBytes())); + if (mutable_properties_ != kMutablePropertyNone) { + state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); + state->SetInteger("mutable_properties", mutable_properties_); + } + MathUtil::AddToTracedValue( "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive()) : gfx::ScrollOffset(), @@ -1758,7 +1707,7 @@ void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { bool clipped; gfx::QuadF layer_quad = - MathUtil::MapQuad(screen_space_transform(), + MathUtil::MapQuad(ScreenSpaceTransform(), gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); MathUtil::AddToTracedValue("layer_quad", layer_quad, state); if (!touch_event_handler_region_.IsEmpty()) { @@ -1886,7 +1835,6 @@ void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { return; SetNeedsPushProperties(); - layer_tree_impl()->set_needs_update_draw_properties(); if (should_have_render_surface) { render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); return; @@ -1894,24 +1842,68 @@ void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { render_surface_.reset(); } +gfx::Transform LayerImpl::DrawTransform() const { + // Only drawn layers have up-to-date draw properties when property trees are + // enabled. + if (layer_tree_impl()->settings().use_property_trees && + !IsDrawnRenderSurfaceLayerListMember()) { + if (layer_tree_impl()->property_trees()->non_root_surfaces_enabled) { + return DrawTransformFromPropertyTrees( + this, layer_tree_impl()->property_trees()->transform_tree); + } else { + return ScreenSpaceTransformFromPropertyTrees( + this, layer_tree_impl()->property_trees()->transform_tree); + } + } + + return draw_properties().target_space_transform; +} + +gfx::Transform LayerImpl::ScreenSpaceTransform() const { + // Only drawn layers have up-to-date draw properties when property trees are + // enabled. + if (layer_tree_impl()->settings().use_property_trees && + !IsDrawnRenderSurfaceLayerListMember()) { + return ScreenSpaceTransformFromPropertyTrees( + this, layer_tree_impl()->property_trees()->transform_tree); + } + + return draw_properties().screen_space_transform; +} + +void LayerImpl::SetForceRenderSurface(bool force_render_surface) { + if (force_render_surface == force_render_surface_) + return; + + force_render_surface_ = force_render_surface; + NoteLayerPropertyChanged(); +} + Region LayerImpl::GetInvalidationRegion() { return Region(update_rect_); } gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const { - return MathUtil::MapEnclosingClippedRect( - draw_properties_.target_space_transform, gfx::Rect(bounds())); + return MathUtil::MapEnclosingClippedRect(DrawTransform(), + gfx::Rect(bounds())); } gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { - gfx::Transform scaled_draw_transform = - draw_properties_.target_space_transform; + gfx::Transform scaled_draw_transform = DrawTransform(); scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale); return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, gfx::Rect(scaled_bounds)); } +bool LayerImpl::LayerIsHidden() const { + if (layer_tree_impl()->settings().use_property_trees) { + return is_hidden_from_property_trees_; + } else { + return hide_layer_and_subtree_ || (parent() && parent()->LayerIsHidden()); + } +} + float LayerImpl::GetIdealContentsScale() const { float page_scale = IsAffectedByPageScale() ? layer_tree_impl()->current_page_scale_factor() @@ -1925,10 +1917,8 @@ float LayerImpl::GetIdealContentsScale() const { return default_scale; } - // TODO(enne): the transform needs to come from property trees instead of - // draw properties. gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( - draw_properties().target_space_transform, default_scale); + DrawTransform(), default_scale); return std::max(transform_scales.x(), transform_scales.y()); } diff --git a/chromium/cc/layers/layer_impl.h b/chromium/cc/layers/layer_impl.h index 4e94980939e..4dca350d1dd 100644 --- a/chromium/cc/layers/layer_impl.h +++ b/chromium/cc/layers/layer_impl.h @@ -5,12 +5,16 @@ #ifndef CC_LAYERS_LAYER_IMPL_H_ #define CC_LAYERS_LAYER_IMPL_H_ +#include <stddef.h> +#include <stdint.h> + #include <map> #include <set> #include <string> #include <vector> #include "base/logging.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" #include "cc/animation/animation_delegate.h" @@ -19,14 +23,13 @@ #include "cc/animation/layer_animation_value_provider.h" #include "cc/base/cc_export.h" #include "cc/base/region.h" -#include "cc/base/scoped_ptr_vector.h" #include "cc/base/synced_property.h" #include "cc/debug/frame_timing_request.h" #include "cc/input/input_handler.h" -#include "cc/input/scrollbar.h" #include "cc/layers/draw_properties.h" #include "cc/layers/layer_lists.h" #include "cc/layers/layer_position_constraint.h" +#include "cc/layers/performance_properties.h" #include "cc/layers/render_surface_impl.h" #include "cc/layers/scroll_blocks_on.h" #include "cc/output/filter_operations.h" @@ -62,7 +65,6 @@ class PrioritizedTile; class RenderPass; class RenderPassId; class Renderer; -class ScrollbarAnimationController; class ScrollbarLayerImplBase; class SimpleEnclosedRegion; class Tile; @@ -123,13 +125,16 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, void NotifyAnimationFinished(base::TimeTicks monotonic_time, Animation::TargetProperty target_property, int group) override; + void NotifyAnimationAborted(base::TimeTicks monotonic_time, + Animation::TargetProperty target_property, + int group) override{}; // Tree structure. LayerImpl* parent() { return parent_; } const LayerImpl* parent() const { return parent_; } const OwnedLayerImplList& children() const { return children_; } OwnedLayerImplList& children() { return children_; } - LayerImpl* child_at(size_t index) const { return children_[index]; } + LayerImpl* child_at(size_t index) const { return children_[index].get(); } void AddChild(scoped_ptr<LayerImpl> child); scoped_ptr<LayerImpl> RemoveChild(LayerImpl* child); void SetParent(LayerImpl* parent); @@ -205,7 +210,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, // For compatibility with Layer. bool has_render_surface() const { return !!render_surface(); } - + bool force_render_surface() const { return force_render_surface_; } void SetNumDescendantsThatDrawContent(int num_descendants); void SetClipParent(LayerImpl* ancestor); @@ -223,10 +228,10 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, return clip_children_.get(); } - void PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests); + void PassCopyRequests(std::vector<scoped_ptr<CopyOutputRequest>>* requests); // Can only be called when the layer has a copy request. void TakeCopyRequestsAndTransformToTarget( - ScopedPtrVector<CopyOutputRequest>* request); + std::vector<scoped_ptr<CopyOutputRequest>>* request); bool HasCopyRequest() const { return !copy_requests_.empty(); } void SetMaskLayer(scoped_ptr<LayerImpl> mask_layer); @@ -320,6 +325,12 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, bool HasPotentiallyRunningOpacityAnimation() const; bool OpacityIsAnimatingOnImplOnly() const; + void SetElementId(uint64_t element_id); + uint64_t element_id() const { return element_id_; } + + void SetMutableProperties(uint32_t properties); + uint32_t mutable_properties() const { return mutable_properties_; } + void SetBlendMode(SkXfermode::Mode); SkXfermode::Mode blend_mode() const { return blend_mode_; } void set_draw_blend_mode(SkXfermode::Mode blend_mode) { @@ -349,10 +360,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, return is_container_for_fixed_position_layers_; } - bool IsAffectedByPageScale() const { return is_affected_by_page_scale_; } - void SetIsAffectedByPageScale(bool is_affected) { - is_affected_by_page_scale_ = is_affected; - } + bool IsAffectedByPageScale() const; gfx::Vector2dF FixedContainerSizeDelta() const; @@ -383,19 +391,21 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, void ClearRenderSurfaceLayerList(); void SetHasRenderSurface(bool has_render_surface); + void SetForceRenderSurface(bool has_render_surface); + RenderSurfaceImpl* render_surface() const { return render_surface_.get(); } DrawProperties& draw_properties() { return draw_properties_; } const DrawProperties& draw_properties() const { return draw_properties_; } + gfx::Transform DrawTransform() const; + gfx::Transform ScreenSpaceTransform() const; + PerformanceProperties<LayerImpl>& performance_properties() { + return performance_properties_; + } + // The following are shortcut accessors to get various information from // draw_properties_ - const gfx::Transform& draw_transform() const { - return draw_properties_.target_space_transform; - } - const gfx::Transform& screen_space_transform() const { - return draw_properties_.screen_space_transform; - } float draw_opacity() const { return draw_properties_.opacity; } bool screen_space_transform_is_animating() const { return draw_properties_.screen_space_transform_is_animating; @@ -451,9 +461,6 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, gfx::ScrollOffset MaxScrollOffset() const; gfx::ScrollOffset ClampScrollOffsetToLimits(gfx::ScrollOffset offset) const; gfx::Vector2dF ClampScrollToMaxScrollOffset(); - void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, - LayerImpl* scrollbar_clip_layer, - bool on_resize) const; void SetScrollCompensationAdjustment(const gfx::Vector2dF& scroll_offset) { scroll_compensation_adjustment_ = scroll_offset; } @@ -466,8 +473,9 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll); void SetScrollClipLayer(int scroll_clip_layer_id); - LayerImpl* scroll_clip_layer() const { return scroll_clip_layer_; } - bool scrollable() const { return !!scroll_clip_layer_; } + int scroll_clip_layer_id() const { return scroll_clip_layer_id_; } + LayerImpl* scroll_clip_layer() const; + bool scrollable() const; void set_user_scrollable_horizontal(bool scrollable) { user_scrollable_horizontal_ = scrollable; @@ -536,6 +544,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, bool HasPotentiallyRunningTransformAnimation() const; bool TransformIsAnimatingOnImplOnly() const; bool HasOnlyTranslationTransforms() const; + bool AnimationsPreserveAxisAlignment() const; void SetTransformAndInvertibility(const gfx::Transform& transform, bool transform_is_invertible); bool transform_is_invertible() const { return transform_is_invertible_; } @@ -582,7 +591,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, virtual SimpleEnclosedRegion VisibleOpaqueRegion() const; - virtual void DidBecomeActive(); + virtual void DidBecomeActive() {} virtual void DidBeginTracing(); @@ -594,19 +603,8 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, // ReleaseResources call. virtual void RecreateResources(); - ScrollbarAnimationController* scrollbar_animation_controller() const { - return scrollbar_animation_controller_.get(); - } - - typedef std::set<ScrollbarLayerImplBase*> ScrollbarSet; - ScrollbarSet* scrollbars() { return scrollbars_.get(); } - void ClearScrollbars(); - void AddScrollbar(ScrollbarLayerImplBase* layer); - void RemoveScrollbar(ScrollbarLayerImplBase* layer); - bool HasScrollbar(ScrollbarOrientation orientation) const; - void ScrollbarParametersDidChange(bool on_resize); int clip_height() { - return scroll_clip_layer_ ? scroll_clip_layer_->bounds().height() : 0; + return scroll_clip_layer() ? scroll_clip_layer()->bounds().height() : 0; } virtual skia::RefPtr<SkPicture> GetPicture(); @@ -682,19 +680,28 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, } bool sorted_for_recursion() { return sorted_for_recursion_; } - void set_num_layer_or_descendant_with_copy_request( - int num_layer_or_descendants_with_copy_request) { - num_layer_or_descendants_with_copy_request_ = - num_layer_or_descendants_with_copy_request; - } - int num_layer_or_descendants_with_copy_request() { - return num_layer_or_descendants_with_copy_request_; - } + int num_copy_requests_in_target_subtree(); void UpdatePropertyTreeForScrollingAndAnimationIfNeeded(); + void set_is_hidden_from_property_trees(bool is_hidden) { + if (is_hidden == is_hidden_from_property_trees_) + return; + is_hidden_from_property_trees_ = is_hidden; + SetNeedsPushProperties(); + } + bool LayerIsHidden() const; + float GetIdealContentsScale() const; + bool was_ever_ready_since_last_transform_animation() const { + return was_ever_ready_since_last_transform_animation_; + } + + void set_was_ever_ready_since_last_transform_animation(bool was_ready) { + was_ever_ready_since_last_transform_animation_ = was_ready; + } + protected: LayerImpl(LayerTreeImpl* layer_impl, int id, @@ -763,7 +770,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, // Properties synchronized from the associated Layer. gfx::Point3F transform_origin_; gfx::Size bounds_; - LayerImpl* scroll_clip_layer_; + int scroll_clip_layer_id_; gfx::Vector2dF offset_to_transform_parent_; @@ -800,6 +807,10 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, bool is_affected_by_page_scale_ : 1; + // This is true if and only if the layer was ever ready since it last animated + // (all content was complete). + bool was_ever_ready_since_last_transform_animation_ : 1; + Region non_fast_scrollable_region_; Region touch_event_handler_region_; SkColor background_color_; @@ -851,6 +862,8 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, DrawMode current_draw_mode_; private: + uint64_t element_id_; + uint32_t mutable_properties_; // Rect indicating what was repainted/updated during update. // Note that plugin layers bypass this and leave it empty. // This is in the layer's space. @@ -863,28 +876,26 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, // Manages animations for this layer. scoped_refptr<LayerAnimationController> layer_animation_controller_; - // Manages scrollbars for this layer - scoped_ptr<ScrollbarAnimationController> scrollbar_animation_controller_; - - scoped_ptr<ScrollbarSet> scrollbars_; - - ScopedPtrVector<CopyOutputRequest> copy_requests_; + std::vector<scoped_ptr<CopyOutputRequest>> copy_requests_; // Group of properties that need to be computed based on the layer tree // hierarchy before layers can be drawn. DrawProperties draw_properties_; + PerformanceProperties<LayerImpl> performance_properties_; scoped_refptr<base::trace_event::ConvertableToTraceFormat> debug_info_; scoped_ptr<RenderSurfaceImpl> render_surface_; + bool force_render_surface_; + std::vector<FrameTimingRequest> frame_timing_requests_; - int num_layer_or_descendants_with_copy_request_; bool frame_timing_requests_dirty_; bool visited_; bool layer_or_descendant_is_drawn_; // If true, the layer or one of its descendants has a wheel or touch handler. bool layer_or_descendant_has_input_handler_; bool sorted_for_recursion_; + bool is_hidden_from_property_trees_; DISALLOW_COPY_AND_ASSIGN(LayerImpl); }; diff --git a/chromium/cc/layers/layer_impl_unittest.cc b/chromium/cc/layers/layer_impl_unittest.cc index 7404e4e2663..b9fb7679709 100644 --- a/chromium/cc/layers/layer_impl_unittest.cc +++ b/chromium/cc/layers/layer_impl_unittest.cc @@ -4,11 +4,13 @@ #include "cc/layers/layer_impl.h" +#include "cc/animation/mutable_properties.h" #include "cc/layers/painted_scrollbar_layer_impl.h" #include "cc/layers/solid_color_scrollbar_layer_impl.h" #include "cc/output/filter_operation.h" #include "cc/output/filter_operations.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/animation_test_common.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" #include "cc/test/geometry_test_utils.h" @@ -65,18 +67,22 @@ namespace { EXPECT_FALSE(child->LayerPropertyChanged()); \ EXPECT_FALSE(grand_child->LayerPropertyChanged()); -#define VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(code_to_test) \ - root->ResetAllChangeTrackingForSubtree(); \ - host_impl.ForcePrepareToDraw(); \ - EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); \ - code_to_test; \ +#define VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(code_to_test) \ + root->ResetAllChangeTrackingForSubtree(); \ + host_impl.active_tree()->property_trees()->needs_rebuild = true; \ + host_impl.active_tree()->BuildPropertyTreesForTesting(); \ + host_impl.ForcePrepareToDraw(); \ + EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); \ + code_to_test; \ EXPECT_TRUE(host_impl.active_tree()->needs_update_draw_properties()); -#define VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(code_to_test) \ - root->ResetAllChangeTrackingForSubtree(); \ - host_impl.ForcePrepareToDraw(); \ - EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); \ - code_to_test; \ +#define VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(code_to_test) \ + root->ResetAllChangeTrackingForSubtree(); \ + host_impl.active_tree()->property_trees()->needs_rebuild = true; \ + host_impl.active_tree()->BuildPropertyTreesForTesting(); \ + host_impl.ForcePrepareToDraw(); \ + EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); \ + code_to_test; \ EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { @@ -86,19 +92,21 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { // The constructor on this will fake that we are on the correct thread. // Create a simple LayerImpl tree: - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); - FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, &task_graph_runner); + host_impl.SetVisible(true); EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); - scoped_ptr<LayerImpl> root_clip = + scoped_ptr<LayerImpl> root_clip_ptr = LayerImpl::Create(host_impl.active_tree(), 1); + LayerImpl* root_clip = root_clip_ptr.get(); scoped_ptr<LayerImpl> root_ptr = LayerImpl::Create(host_impl.active_tree(), 2); LayerImpl* root = root_ptr.get(); - root_clip->AddChild(root_ptr.Pass()); + root_clip_ptr->AddChild(std::move(root_ptr)); scoped_ptr<LayerImpl> scroll_parent = LayerImpl::Create(host_impl.active_tree(), 3); LayerImpl* scroll_child = LayerImpl::Create(host_impl.active_tree(), 4).get(); @@ -115,9 +123,11 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { clip_children->insert(root); root->AddChild(LayerImpl::Create(host_impl.active_tree(), 7)); - LayerImpl* child = root->children()[0]; + LayerImpl* child = root->children()[0].get(); child->AddChild(LayerImpl::Create(host_impl.active_tree(), 8)); - LayerImpl* grand_child = child->children()[0]; + LayerImpl* grand_child = child->children()[0].get(); + host_impl.active_tree()->SetRootLayer(std::move(root_clip_ptr)); + host_impl.active_tree()->BuildPropertyTreesForTesting(); root->SetScrollClipLayer(root_clip->id()); @@ -190,12 +200,14 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { // changed. EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBounds(arbitrary_size)); - // Changing this property does not cause the layer to be marked as changed + // Changing these properties does not cause the layer to be marked as changed // but does cause the layer to need to push properties. EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( root->SetIsRootForIsolatedGroup(true)); - - // Changing these properties should cause the layer to need to push properties + EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( + root->SetElementId(2)); + EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( + root->SetMutableProperties(kMutablePropertyOpacity)); EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( root->SetScrollParent(scroll_parent.get())); EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( @@ -245,12 +257,13 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { } TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); - FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, &task_graph_runner); + host_impl.SetVisible(true); EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); host_impl.active_tree()->SetRootLayer( LayerImpl::Create(host_impl.active_tree(), 1)); @@ -259,8 +272,13 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { scoped_ptr<LayerImpl> layer_ptr = LayerImpl::Create(host_impl.active_tree(), 2); LayerImpl* layer = layer_ptr.get(); - root->AddChild(layer_ptr.Pass()); + root->AddChild(std::move(layer_ptr)); layer->SetScrollClipLayer(root->id()); + scoped_ptr<LayerImpl> layer2_ptr = + LayerImpl::Create(host_impl.active_tree(), 3); + LayerImpl* layer2 = layer2_ptr.get(); + root->AddChild(std::move(layer2_ptr)); + host_impl.active_tree()->BuildPropertyTreesForTesting(); DCHECK(host_impl.CanDraw()); gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f); @@ -279,13 +297,22 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; - // Render surface functions. - VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true)); + // Set layer to draw content so that their draw property by property trees is + // verified. + VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetDrawsContent(true)); + VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer2->SetDrawsContent(true)); + // Render surface functions should not trigger update draw properties, because + // creating render surface is part of update draw properties. VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true)); - VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(false)); + VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(false)); // Create a render surface, because we must have a render surface if we have // filters. - VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true)); + VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true)); + + VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetForceRenderSurface(true)); + VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetForceRenderSurface(true)); + VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetForceRenderSurface(false)); + VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetForceRenderSurface(false)); // Related filter functions. VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters)); @@ -317,13 +344,11 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true)); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( layer->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 5))); - VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetPosition(arbitrary_point_f)); + VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer2->SetPosition(arbitrary_point_f)); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetShouldFlattenTransform(false)); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->Set3dSortingContextId(1)); - VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( layer->SetDoubleSided(false)); // constructor initializes it to "true". - VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetDrawsContent(true)); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( layer->SetBackgroundColor(arbitrary_color)); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( @@ -340,7 +365,8 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters)); VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetMasksToBounds(true)); VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true)); - VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetPosition(arbitrary_point_f)); + VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( + layer2->SetPosition(arbitrary_point_f)); VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->Set3dSortingContextId(1)); VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( layer->SetDoubleSided(false)); // constructor initializes it to "true". @@ -357,15 +383,19 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( layer->SetTransform(arbitrary_transform)); VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size)); + VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetElementId(2)); + VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( + layer->SetMutableProperties(kMutablePropertyTransform)); } TEST(LayerImplTest, SafeOpaqueBackgroundColor) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); - FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, &task_graph_runner); + host_impl.SetVisible(true); EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); @@ -394,10 +424,10 @@ TEST(LayerImplTest, SafeOpaqueBackgroundColor) { } TEST(LayerImplTest, TransformInvertibility) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, &task_graph_runner); scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); @@ -429,7 +459,7 @@ class LayerImplScrollTest : public testing::Test { public: LayerImplScrollTest() : host_impl_(settings(), - &proxy_, + &task_runner_provider_, &shared_bitmap_manager_, &task_graph_runner_), root_id_(7) { @@ -437,6 +467,7 @@ class LayerImplScrollTest : public testing::Test { LayerImpl::Create(host_impl_.active_tree(), root_id_)); host_impl_.active_tree()->root_layer()->AddChild( LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1)); + host_impl_.active_tree()->BuildPropertyTreesForTesting(); layer()->SetScrollClipLayer(root_id_); // Set the max scroll offset by noting that the root layer has bounds (1,1), // thus whatever bounds are set for the layer will be the max scroll @@ -447,7 +478,7 @@ class LayerImplScrollTest : public testing::Test { } LayerImpl* layer() { - return host_impl_.active_tree()->root_layer()->children()[0]; + return host_impl_.active_tree()->root_layer()->children()[0].get(); } LayerTreeHostImpl& host_impl() { return host_impl_; } @@ -460,7 +491,7 @@ class LayerImplScrollTest : public testing::Test { } private: - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeLayerTreeHostImpl host_impl_; @@ -575,159 +606,5 @@ TEST_F(LayerImplScrollTest, PushPropertiesToMirrorsCurrentScrollOffset) { pending_layer->CurrentScrollOffset()); } -TEST_F(LayerImplScrollTest, SetNewScrollbarParameters) { - gfx::ScrollOffset scroll_offset(10, 5); - layer()->PushScrollOffsetFromMainThread(scroll_offset); - - scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar( - PaintedScrollbarLayerImpl::Create(tree(), 100, VERTICAL)); - vertical_scrollbar->SetScrollLayerAndClipLayerByIds( - layer()->id(), tree()->root_layer()->id()); - - int expected_vertical_maximum = - layer()->bounds().height() - tree()->root_layer()->bounds().height(); - EXPECT_EQ(expected_vertical_maximum, vertical_scrollbar->maximum()); - EXPECT_EQ(scroll_offset.y(), vertical_scrollbar->current_pos()); - - scoped_ptr<PaintedScrollbarLayerImpl> horizontal_scrollbar( - PaintedScrollbarLayerImpl::Create(tree(), 101, HORIZONTAL)); - horizontal_scrollbar->SetScrollLayerAndClipLayerByIds( - layer()->id(), tree()->root_layer()->id()); - - int expected_horizontal_maximum = - layer()->bounds().width() - tree()->root_layer()->bounds().width(); - EXPECT_EQ(expected_horizontal_maximum, horizontal_scrollbar->maximum()); - EXPECT_EQ(scroll_offset.x(), horizontal_scrollbar->current_pos()); -} - -class LayerImplScrollbarSyncTest : public testing::Test { - public: - enum { - ROOT = 1, - IV_CLIP = 2, - PAGE = 3, - IV_SCROLL = 4, - SCROLLBAR = 5, - OLD_ROOT = 6, - OV_CLIP = 7, - OV_SCROLL = 8, - }; - enum TreeID { - PENDING, - ACTIVE - }; - - LayerImplScrollbarSyncTest() - : host_impl_(settings(), - &proxy_, - &shared_bitmap_manager_, - &task_graph_runner_) { - host_impl_.CreatePendingTree(); - - CreateLayers(host_impl_.pending_tree()); - CreateLayers(host_impl_.active_tree()); - } - - void CreateLayers(LayerTreeImpl * tree) { - tree->SetRootLayer(LayerImpl::Create(tree, ROOT)); - LayerImpl * root = tree->root_layer(); - ASSERT_TRUE(root != nullptr); - - int hierarchy[] = {IV_CLIP, PAGE, IV_SCROLL, OLD_ROOT, OV_CLIP, OV_SCROLL}; - LayerImpl * parent = root; - for (int child_id : hierarchy) { - parent->AddChild(LayerImpl::Create(tree, child_id)); - parent = tree->LayerById(child_id); - ASSERT_TRUE(parent != nullptr); - } - - root->AddChild( - SolidColorScrollbarLayerImpl::Create(tree, SCROLLBAR, HORIZONTAL, - 5, 5, false, true)); - } - - LayerImpl* layer(int id, TreeID tree_id) { - LayerTreeImpl* tree = - ((tree_id == PENDING) ? - host_impl_.pending_tree() : host_impl_.active_tree()); - - assert(tree); - return tree->LayerById(id); - } - - bool LayerHasScrollbar(int id, TreeID tree_id) { - return layer(id, tree_id)->HasScrollbar(HORIZONTAL); - } - - ScrollbarLayerImplBase* pending_scrollbar() { - LayerImpl* layer_impl = layer(SCROLLBAR, PENDING); - assert(layer_impl); - return layer_impl->ToScrollbarLayer(); - } - - LayerImpl* pending_root() { - LayerImpl * result = layer(ROOT, PENDING); - assert(result); - return result; - } - - LayerImpl* active_root() { - LayerImpl * result = layer(ROOT, ACTIVE); - assert(result); - return result; - } - - LayerTreeSettings settings() { - LayerTreeSettings settings; - return settings; - } - - private: - FakeImplProxy proxy_; - TestSharedBitmapManager shared_bitmap_manager_; - TestTaskGraphRunner task_graph_runner_; - FakeLayerTreeHostImpl host_impl_; -}; - -TEST_F(LayerImplScrollbarSyncTest, LayerImplBecomesScrollable) { - // In the beginning IV_SCROLL layer is not scrollable. - ASSERT_FALSE(layer(IV_SCROLL, PENDING)->scrollable()); - - // For pinch virtual viewport the clip layer is the inner viewport - // clip layer (IV_CLIP) and the scroll one is the outer viewport - // scroll layer (OV_SCROLL). - pending_scrollbar()->SetScrollLayerAndClipLayerByIds(OV_SCROLL, IV_CLIP); - - ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, PENDING)); - ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, PENDING)); - - // Synchronize with the active tree. - TreeSynchronizer::PushProperties(pending_root(), active_root()); - - ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, ACTIVE)); - ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, ACTIVE)); - - // Make IV_SCROLL layer scrollable. - layer(IV_SCROLL, PENDING)->SetScrollClipLayer(IV_CLIP); - layer(IV_SCROLL, PENDING)->SetNeedsPushProperties(); - ASSERT_TRUE(layer(IV_SCROLL, PENDING)->scrollable()); - - pending_scrollbar()->SetScrollLayerAndClipLayerByIds(OV_SCROLL, IV_CLIP); - - // Now IV_CLIP layer should also receive the scrollbar. - ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, PENDING)); - ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, PENDING)); - ASSERT_TRUE(LayerHasScrollbar(IV_SCROLL, PENDING)); - - // Synchronize with the active tree. - TreeSynchronizer::PushProperties(pending_root(), active_root()); - - ASSERT_TRUE(layer(IV_SCROLL, ACTIVE)->scrollable()); - - ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, ACTIVE)); - ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, ACTIVE)); - ASSERT_TRUE(LayerHasScrollbar(IV_SCROLL, ACTIVE)); -} - } // namespace } // namespace cc diff --git a/chromium/cc/layers/layer_iterator.h b/chromium/cc/layers/layer_iterator.h index 2c129e48cb3..cf01ca19a41 100644 --- a/chromium/cc/layers/layer_iterator.h +++ b/chromium/cc/layers/layer_iterator.h @@ -5,6 +5,8 @@ #ifndef CC_LAYERS_LAYER_ITERATOR_H_ #define CC_LAYERS_LAYER_ITERATOR_H_ +#include <stddef.h> + #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" #include "cc/trees/layer_tree_host_common.h" diff --git a/chromium/cc/layers/layer_iterator_unittest.cc b/chromium/cc/layers/layer_iterator_unittest.cc index 01815f9b36c..b9b3cf3d283 100644 --- a/chromium/cc/layers/layer_iterator_unittest.cc +++ b/chromium/cc/layers/layer_iterator_unittest.cc @@ -40,7 +40,7 @@ class TestLayerImpl : public LayerImpl { count_representing_contributing_surface_(-1), count_representing_itself_(-1) { SetBounds(gfx::Size(100, 100)); - SetPosition(gfx::Point()); + SetPosition(gfx::PointF()); SetDrawsContent(true); } }; @@ -93,7 +93,9 @@ void IterateFrontToBack(LayerImplList* render_surface_layer_list) { class LayerIteratorTest : public testing::Test { public: LayerIteratorTest() - : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), + : host_impl_(&task_runner_provider_, + &shared_bitmap_manager_, + &task_graph_runner_), id_(1) {} scoped_ptr<TestLayerImpl> CreateLayer() { @@ -101,7 +103,7 @@ class LayerIteratorTest : public testing::Test { } protected: - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeLayerTreeHostImpl host_impl_; @@ -128,17 +130,18 @@ TEST_F(LayerIteratorTest, SimpleTree) { TestLayerImpl* third_ptr = third.get(); TestLayerImpl* fourth_ptr = fourth.get(); - root_layer->AddChild(first.Pass()); - root_layer->AddChild(second.Pass()); - root_layer->AddChild(third.Pass()); - root_layer->AddChild(fourth.Pass()); + root_layer->AddChild(std::move(first)); + root_layer->AddChild(std::move(second)); + root_layer->AddChild(std::move(third)); + root_layer->AddChild(std::move(fourth)); - root_layer->SetHasRenderSurface(true); - host_impl_.active_tree()->SetRootLayer(root_layer.Pass()); + host_impl_.active_tree()->SetRootLayer(std::move(root_layer)); LayerImplList render_surface_layer_list; + host_impl_.active_tree()->IncrementRenderSurfaceListIdForTesting(); LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( - root_ptr, root_ptr->bounds(), &render_surface_layer_list); + root_ptr, root_ptr->bounds(), &render_surface_layer_list, + host_impl_.active_tree()->current_render_surface_list_id()); LayerTreeHostCommon::CalculateDrawProperties(&inputs); IterateFrontToBack(&render_surface_layer_list); @@ -170,21 +173,22 @@ TEST_F(LayerIteratorTest, ComplexTree) { TestLayerImpl* root221_ptr = root221.get(); TestLayerImpl* root231_ptr = root231.get(); - root22->AddChild(root221.Pass()); - root23->AddChild(root231.Pass()); - root2->AddChild(root21.Pass()); - root2->AddChild(root22.Pass()); - root2->AddChild(root23.Pass()); - root_layer->AddChild(root1.Pass()); - root_layer->AddChild(root2.Pass()); - root_layer->AddChild(root3.Pass()); + root22->AddChild(std::move(root221)); + root23->AddChild(std::move(root231)); + root2->AddChild(std::move(root21)); + root2->AddChild(std::move(root22)); + root2->AddChild(std::move(root23)); + root_layer->AddChild(std::move(root1)); + root_layer->AddChild(std::move(root2)); + root_layer->AddChild(std::move(root3)); - root_layer->SetHasRenderSurface(true); - host_impl_.active_tree()->SetRootLayer(root_layer.Pass()); + host_impl_.active_tree()->SetRootLayer(std::move(root_layer)); LayerImplList render_surface_layer_list; + host_impl_.active_tree()->IncrementRenderSurfaceListIdForTesting(); LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( - root_ptr, root_ptr->bounds(), &render_surface_layer_list); + root_ptr, root_ptr->bounds(), &render_surface_layer_list, + host_impl_.active_tree()->current_render_surface_list_id()); LayerTreeHostCommon::CalculateDrawProperties(&inputs); IterateFrontToBack(&render_surface_layer_list); @@ -220,25 +224,26 @@ TEST_F(LayerIteratorTest, ComplexTreeMultiSurface) { TestLayerImpl* root221_ptr = root221.get(); TestLayerImpl* root231_ptr = root231.get(); - root22->SetHasRenderSurface(true); - root22->AddChild(root221.Pass()); - root23->SetHasRenderSurface(true); - root23->AddChild(root231.Pass()); + root22->SetForceRenderSurface(true); + root23->SetForceRenderSurface(true); + root2->SetForceRenderSurface(true); + root22->AddChild(std::move(root221)); + root23->AddChild(std::move(root231)); root2->SetDrawsContent(false); - root2->SetHasRenderSurface(true); - root2->AddChild(root21.Pass()); - root2->AddChild(root22.Pass()); - root2->AddChild(root23.Pass()); - root_layer->AddChild(root1.Pass()); - root_layer->AddChild(root2.Pass()); - root_layer->AddChild(root3.Pass()); + root2->AddChild(std::move(root21)); + root2->AddChild(std::move(root22)); + root2->AddChild(std::move(root23)); + root_layer->AddChild(std::move(root1)); + root_layer->AddChild(std::move(root2)); + root_layer->AddChild(std::move(root3)); - root_layer->SetHasRenderSurface(true); - host_impl_.active_tree()->SetRootLayer(root_layer.Pass()); + host_impl_.active_tree()->SetRootLayer(std::move(root_layer)); LayerImplList render_surface_layer_list; + host_impl_.active_tree()->IncrementRenderSurfaceListIdForTesting(); LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( - root_ptr, root_ptr->bounds(), &render_surface_layer_list); + root_ptr, root_ptr->bounds(), &render_surface_layer_list, + host_impl_.active_tree()->current_render_surface_list_id()); LayerTreeHostCommon::CalculateDrawProperties(&inputs); IterateFrontToBack(&render_surface_layer_list); diff --git a/chromium/cc/layers/layer_lists.h b/chromium/cc/layers/layer_lists.h index 870785dad93..264d219a26f 100644 --- a/chromium/cc/layers/layer_lists.h +++ b/chromium/cc/layers/layer_lists.h @@ -8,15 +8,15 @@ #include <vector> #include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" -#include "cc/base/scoped_ptr_vector.h" namespace cc { class Layer; class LayerImpl; typedef std::vector<scoped_refptr<Layer>> LayerList; -typedef ScopedPtrVector<LayerImpl> OwnedLayerImplList; +typedef std::vector<scoped_ptr<LayerImpl>> OwnedLayerImplList; typedef std::vector<LayerImpl*> LayerImplList; } // namespace cc diff --git a/chromium/cc/layers/layer_perftest.cc b/chromium/cc/layers/layer_perftest.cc index 0c0fb4185a4..e27f0309b2e 100644 --- a/chromium/cc/layers/layer_perftest.cc +++ b/chromium/cc/layers/layer_perftest.cc @@ -6,7 +6,8 @@ #include "base/thread_task_runner_handle.h" #include "cc/debug/lap_timer.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/layers/layer_settings.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_impl.h" @@ -24,7 +25,9 @@ static const int kTimeCheckInterval = 10; class LayerPerfTest : public testing::Test { public: LayerPerfTest() - : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), + : host_impl_(&task_runner_provider_, + &shared_bitmap_manager_, + &task_graph_runner_), fake_client_(FakeLayerTreeHostClient::DIRECT_3D), timer_(kWarmupRuns, base::TimeDelta::FromMilliseconds(kTimeLimitMillis), @@ -43,7 +46,7 @@ class LayerPerfTest : public testing::Test { layer_tree_host_ = nullptr; } - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeLayerTreeHostImpl host_impl_; diff --git a/chromium/cc/layers/layer_position_constraint.cc b/chromium/cc/layers/layer_position_constraint.cc index 183b6b5b53e..5d8824e2421 100644 --- a/chromium/cc/layers/layer_position_constraint.cc +++ b/chromium/cc/layers/layer_position_constraint.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "cc/layers/layer_position_constraint.h" +#include "cc/proto/layer_position_constraint.pb.h" namespace cc { @@ -12,6 +13,20 @@ LayerPositionConstraint::LayerPositionConstraint() is_fixed_to_bottom_edge_(false) { } +void LayerPositionConstraint::ToProtobuf( + proto::LayerPositionConstraint* proto) const { + proto->set_is_fixed_position(is_fixed_position_); + proto->set_is_fixed_to_right_edge(is_fixed_to_right_edge_); + proto->set_is_fixed_to_bottom_edge(is_fixed_to_bottom_edge_); +} + +void LayerPositionConstraint::FromProtobuf( + const proto::LayerPositionConstraint& proto) { + is_fixed_position_ = proto.is_fixed_position(); + is_fixed_to_right_edge_ = proto.is_fixed_to_right_edge(); + is_fixed_to_bottom_edge_ = proto.is_fixed_to_bottom_edge(); +} + bool LayerPositionConstraint::operator==( const LayerPositionConstraint& other) const { if (!is_fixed_position_ && !other.is_fixed_position_) diff --git a/chromium/cc/layers/layer_position_constraint.h b/chromium/cc/layers/layer_position_constraint.h index 9a575137736..1ee4bc72775 100644 --- a/chromium/cc/layers/layer_position_constraint.h +++ b/chromium/cc/layers/layer_position_constraint.h @@ -9,6 +9,10 @@ namespace cc { +namespace proto { +class LayerPositionConstraint; +} + class CC_EXPORT LayerPositionConstraint { public: LayerPositionConstraint(); @@ -24,6 +28,9 @@ class CC_EXPORT LayerPositionConstraint { } bool is_fixed_to_bottom_edge() const { return is_fixed_to_bottom_edge_; } + void ToProtobuf(proto::LayerPositionConstraint* proto) const; + void FromProtobuf(const proto::LayerPositionConstraint& proto); + bool operator==(const LayerPositionConstraint&) const; bool operator!=(const LayerPositionConstraint&) const; diff --git a/chromium/cc/layers/layer_position_constraint_unittest.cc b/chromium/cc/layers/layer_position_constraint_unittest.cc index 377d3f417ff..490ce8e2961 100644 --- a/chromium/cc/layers/layer_position_constraint_unittest.cc +++ b/chromium/cc/layers/layer_position_constraint_unittest.cc @@ -8,7 +8,10 @@ #include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" +#include "cc/layers/layer_settings.h" +#include "cc/proto/layer_position_constraint.pb.h" #include "cc/test/fake_layer_tree_host.h" +#include "cc/test/fake_proxy.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/test_task_graph_runner.h" #include "cc/trees/layer_tree_host_common.h" @@ -47,8 +50,10 @@ void SetLayerPropertiesForTesting(Layer* layer, void ExecuteCalculateDrawProperties(LayerImpl* root_layer) { std::vector<LayerImpl*> dummy_render_surface_layer_list; + root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( - root_layer, root_layer->bounds(), &dummy_render_surface_layer_list); + root_layer, root_layer->bounds(), &dummy_render_surface_layer_list, + root_layer->layer_tree_impl()->current_render_surface_list_id()); inputs.inner_viewport_scroll_layer = root_layer->layer_tree_impl()->InnerViewportScrollLayer(); inputs.outer_viewport_scroll_layer = @@ -70,7 +75,9 @@ class LayerPositionConstraintTest : public testing::Test { child_impl_(nullptr), grand_child_impl_(nullptr), great_grand_child_impl_(nullptr) { - layer_tree_host_->InitializeForTesting(scoped_ptr<Proxy>(new FakeProxy)); + layer_tree_host_->InitializeForTesting( + TaskRunnerProvider::Create(nullptr, nullptr), + scoped_ptr<Proxy>(new FakeProxy), nullptr); CreateTreeForTest(); fixed_to_top_left_.set_is_fixed_position(true); fixed_to_bottom_right_.set_is_fixed_position(true); @@ -152,14 +159,16 @@ class LayerPositionConstraintTest : public testing::Test { grand_child_impl_->SetScrollDelta(gfx::Vector2dF()); } root_impl_ = layer_tree_host_->CommitAndCreateLayerImplTree(); - inner_viewport_container_layer_impl_ = root_impl_->children()[0]; - scroll_layer_impl_ = inner_viewport_container_layer_impl_->children()[0]; - outer_viewport_container_layer_impl_ = scroll_layer_impl_->children()[0]; + inner_viewport_container_layer_impl_ = root_impl_->children()[0].get(); + scroll_layer_impl_ = + inner_viewport_container_layer_impl_->children()[0].get(); + outer_viewport_container_layer_impl_ = + scroll_layer_impl_->children()[0].get(); child_transform_layer_impl_ = - outer_viewport_container_layer_impl_->children()[0]; - child_impl_ = child_transform_layer_impl_->children()[0]; - grand_child_impl_ = child_impl_->children()[0]; - great_grand_child_impl_ = grand_child_impl_->children()[0]; + outer_viewport_container_layer_impl_->children()[0].get(); + child_impl_ = child_transform_layer_impl_->children()[0].get(); + grand_child_impl_ = child_impl_->children()[0].get(); + great_grand_child_impl_ = grand_child_impl_->children()[0].get(); } protected: @@ -217,12 +226,13 @@ TEST_F(LayerPositionConstraintTest, gfx::Transform expected_grand_child_transform = expected_child_transform; EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 2: scroll delta of 10, 10 child_impl_->SetScrollDelta(gfx::Vector2d(10, 10)); + child_impl_->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); // Here the child is affected by scroll delta, but the fixed position @@ -231,9 +241,9 @@ TEST_F(LayerPositionConstraintTest, expected_child_transform.Translate(-10.0, -10.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 3: fixed-container size delta of 20, 20 SetFixedContainerSizeDelta(child_impl_, gfx::Vector2d(20, 20)); @@ -241,9 +251,9 @@ TEST_F(LayerPositionConstraintTest, // Top-left fixed-position layer should not be affected by container size. EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 4: Bottom-right fixed-position layer. grand_child_->SetPositionConstraint(fixed_to_bottom_right_); @@ -259,9 +269,9 @@ TEST_F(LayerPositionConstraintTest, expected_grand_child_transform.Translate(20.0, 20.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -276,6 +286,7 @@ TEST_F(LayerPositionConstraintTest, // Case 1: scroll delta of 0, 0 child_impl_->SetScrollDelta(gfx::Vector2d(0, 0)); + child_impl_->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); gfx::Transform expected_child_transform; @@ -286,11 +297,11 @@ TEST_F(LayerPositionConstraintTest, expected_grand_child_transform; EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); // Case 2: scroll delta of 10, 10 child_impl_->SetScrollDelta(gfx::Vector2d(10, 10)); @@ -303,11 +314,11 @@ TEST_F(LayerPositionConstraintTest, expected_grand_child_transform.MakeIdentity(); expected_grand_child_transform.Translate(-2.0, -4.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); // Case 3: fixed-container size delta of 20, 20 SetFixedContainerSizeDelta(child_impl_, gfx::Vector2d(20, 20)); @@ -315,11 +326,11 @@ TEST_F(LayerPositionConstraintTest, // Top-left fixed-position layer should not be affected by container size. EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); // Case 4: Bottom-right fixed-position layer. great_grand_child_->SetPositionConstraint(fixed_to_bottom_right_); @@ -336,11 +347,11 @@ TEST_F(LayerPositionConstraintTest, expected_great_grand_child_transform.Translate(8.0, 6.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -360,6 +371,7 @@ TEST_F(LayerPositionConstraintTest, // Case 1: scroll delta of 0, 0 child_impl_->SetScrollDelta(gfx::Vector2d(0, 0)); + child_impl_->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); gfx::Transform expected_child_transform; @@ -375,11 +387,11 @@ TEST_F(LayerPositionConstraintTest, expected_grand_child_transform; EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); // Case 2: scroll delta of 10, 20 child_impl_->SetScrollDelta(gfx::Vector2d(10, 0)); @@ -403,11 +415,11 @@ TEST_F(LayerPositionConstraintTest, expected_grand_child_transform.Translate(8.0, 6.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -439,17 +451,18 @@ TEST_F(LayerPositionConstraintTest, expected_great_grand_child_transform.PreconcatTransform(rotation_about_z); EXPECT_TRUE(grand_child_impl_->render_surface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_surface_draw_transform, grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); // Case 2: scroll delta of 10, 30 child_impl_->SetScrollDelta(gfx::Vector2d(10, 30)); + child_impl_->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); // Here the grand_child remains unchanged, because it scrolls along with the @@ -475,14 +488,14 @@ TEST_F(LayerPositionConstraintTest, EXPECT_TRUE(grand_child_impl_->render_surface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_surface_draw_transform, grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); // Case 3: fixed-container size delta of 20, 20 SetFixedContainerSizeDelta(child_impl_, gfx::Vector2d(20, 20)); @@ -490,11 +503,11 @@ TEST_F(LayerPositionConstraintTest, // Top-left fixed-position layer should not be affected by container size. EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); // Case 4: Bottom-right fixed-position layer. great_grand_child_->SetPositionConstraint(fixed_to_bottom_right_); @@ -515,11 +528,11 @@ TEST_F(LayerPositionConstraintTest, expected_great_grand_child_transform.PreconcatTransform(rotation_about_z); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -557,10 +570,12 @@ TEST_F(LayerPositionConstraintTest, fixed_position_child->SetTransform(rotation_about_z); CommitAndUpdateImplPointers(); - LayerImpl* fixed_position_child_impl = great_grand_child_impl_->children()[0]; + LayerImpl* fixed_position_child_impl = + great_grand_child_impl_->children()[0].get(); // Case 1: scroll delta of 0, 0 child_impl_->SetScrollDelta(gfx::Vector2d(0, 0)); + child_impl_->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); gfx::Transform expected_child_transform; @@ -581,19 +596,19 @@ TEST_F(LayerPositionConstraintTest, EXPECT_TRUE(grand_child_impl_->render_surface()); EXPECT_TRUE(great_grand_child_impl_->render_surface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_grand_child_surface_draw_transform, grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_great_grand_child_surface_draw_transform, great_grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, - fixed_position_child_impl->draw_transform()); + fixed_position_child_impl->DrawTransform()); // Case 2: scroll delta of 10, 30 child_impl_->SetScrollDelta(gfx::Vector2d(10, 30)); @@ -621,19 +636,19 @@ TEST_F(LayerPositionConstraintTest, EXPECT_TRUE(grand_child_impl_->render_surface()); EXPECT_TRUE(great_grand_child_impl_->render_surface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_grand_child_surface_draw_transform, grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_great_grand_child_surface_draw_transform, great_grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, - fixed_position_child_impl->draw_transform()); + fixed_position_child_impl->DrawTransform()); // Case 3: fixed-container size delta of 20, 20 SetFixedContainerSizeDelta(child_impl_, gfx::Vector2d(20, 20)); @@ -641,18 +656,18 @@ TEST_F(LayerPositionConstraintTest, // Top-left fixed-position layer should not be affected by container size. EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, - fixed_position_child_impl->draw_transform()); + fixed_position_child_impl->DrawTransform()); // Case 4: Bottom-right fixed-position layer. fixed_position_child->SetPositionConstraint(fixed_to_bottom_right_); CommitAndUpdateImplPointers(); - fixed_position_child_impl = great_grand_child_impl_->children()[0]; + fixed_position_child_impl = great_grand_child_impl_->children()[0].get(); child_impl_->SetScrollDelta(gfx::Vector2d(10, 30)); SetFixedContainerSizeDelta(child_impl_, gfx::Vector2d(20, 20)); ExecuteCalculateDrawProperties(root_impl_); @@ -667,13 +682,13 @@ TEST_F(LayerPositionConstraintTest, expected_fixed_position_child_transform.PreconcatTransform(rotation_about_z); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, - fixed_position_child_impl->draw_transform()); + fixed_position_child_impl->DrawTransform()); } TEST_F( @@ -707,16 +722,18 @@ TEST_F( // do not accidentally clip away layers that we want to test. gfx::Transform rotation_about_z; rotation_about_z.Translate(50.0, 50.0); - rotation_about_z.RotateAboutZAxis(90.0); + rotation_about_z.RotateAboutZAxis(30.0); rotation_about_z.Translate(-50.0, -50.0); child_transform_layer_->SetTransform(rotation_about_z); fixed_position_child->SetTransform(rotation_about_z); CommitAndUpdateImplPointers(); - LayerImpl* fixed_position_child_impl = great_grand_child_impl_->children()[0]; + LayerImpl* fixed_position_child_impl = + great_grand_child_impl_->children()[0].get(); // Case 1: scroll delta of 0, 0 child_impl_->SetScrollDelta(gfx::Vector2d(0, 0)); + child_impl_->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); gfx::Transform expected_child_transform; @@ -740,19 +757,19 @@ TEST_F( EXPECT_TRUE(grand_child_impl_->render_surface()); EXPECT_TRUE(great_grand_child_impl_->render_surface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_grand_child_surface_draw_transform, grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_great_grand_child_surface_draw_transform, great_grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, - fixed_position_child_impl->draw_transform()); + fixed_position_child_impl->DrawTransform()); // Case 2: scroll delta of 10, 30 child_impl_->SetScrollDelta(gfx::Vector2d(10, 30)); @@ -785,19 +802,19 @@ TEST_F( EXPECT_TRUE(grand_child_impl_->render_surface()); EXPECT_TRUE(great_grand_child_impl_->render_surface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_grand_child_surface_draw_transform, grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_great_grand_child_surface_draw_transform, great_grand_child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, - fixed_position_child_impl->draw_transform()); + fixed_position_child_impl->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -825,9 +842,9 @@ TEST_F(LayerPositionConstraintTest, expected_surface_draw_transform, child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 2: scroll delta of 10, 10 child_impl_->SetScrollDelta(gfx::Vector2d(10, 10)); @@ -846,9 +863,9 @@ TEST_F(LayerPositionConstraintTest, expected_surface_draw_transform, child_impl_->render_surface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 3: fixed-container size delta of 20, 20 SetFixedContainerSizeDelta(child_impl_, gfx::Vector2d(20, 20)); @@ -856,9 +873,9 @@ TEST_F(LayerPositionConstraintTest, // Top-left fixed-position layer should not be affected by container size. EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 4: Bottom-right fixed-position layer. grand_child_->SetPositionConstraint(fixed_to_bottom_right_); @@ -877,9 +894,9 @@ TEST_F(LayerPositionConstraintTest, expected_grand_child_transform.Translate(20.0, 20.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -898,14 +915,15 @@ TEST_F(LayerPositionConstraintTest, // Case 1: scroll delta of 0, 0 child_impl_->SetScrollDelta(gfx::Vector2d(0, 0)); + child_impl_->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); gfx::Transform expected_child_transform; gfx::Transform expected_grand_child_transform; EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 2: scroll delta of 10, 10 child_impl_->SetScrollDelta(gfx::Vector2d(10, 10)); @@ -916,9 +934,9 @@ TEST_F(LayerPositionConstraintTest, expected_child_transform.MakeIdentity(); expected_child_transform.Translate(-10.0, -10.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 3: fixed-container size delta of 20, 20 SetFixedContainerSizeDelta(child_impl_, gfx::Vector2d(20, 20)); @@ -926,9 +944,9 @@ TEST_F(LayerPositionConstraintTest, // Top-left fixed-position layer should not be affected by container size. EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); // Case 4: Bottom-right fixed-position layer. grand_child_->SetPositionConstraint(fixed_to_bottom_right_); @@ -944,9 +962,9 @@ TEST_F(LayerPositionConstraintTest, expected_grand_child_transform.Translate(20.0, 20.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -968,6 +986,7 @@ TEST_F(LayerPositionConstraintTest, // Case 1: scrollDelta child_impl_->SetScrollDelta(gfx::Vector2d(10, 10)); + child_impl_->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); // Here the child is affected by scroll delta, but the fixed position @@ -979,11 +998,11 @@ TEST_F(LayerPositionConstraintTest, gfx::Transform expected_great_grand_child_transform; EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); // Case 2: sizeDelta child_impl_->SetScrollDelta(gfx::Vector2d(0, 0)); @@ -999,11 +1018,11 @@ TEST_F(LayerPositionConstraintTest, expected_great_grand_child_transform.Translate(20.0, 20.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, - child_impl_->draw_transform()); + child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, - grand_child_impl_->draw_transform()); + grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, - great_grand_child_impl_->draw_transform()); + great_grand_child_impl_->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -1029,10 +1048,12 @@ TEST_F(LayerPositionConstraintTest, LayerImpl* container1 = child_impl_; LayerImpl* fixed_to_container1 = grand_child_impl_; LayerImpl* container2 = great_grand_child_impl_; - LayerImpl* fixed_to_container2 = container2->children()[0]; + LayerImpl* fixed_to_container2 = container2->children()[0].get(); container1->SetScrollDelta(gfx::Vector2d(0, 15)); + container1->SetDrawsContent(true); container2->SetScrollDelta(gfx::Vector2d(30, 0)); + container2->SetDrawsContent(true); ExecuteCalculateDrawProperties(root_impl_); gfx::Transform expected_container1_transform; @@ -1049,16 +1070,16 @@ TEST_F(LayerPositionConstraintTest, gfx::Transform expected_fixed_to_container2_transform; EXPECT_TRANSFORMATION_MATRIX_EQ(expected_container1_transform, - container1->draw_transform()); + container1->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container1_transform, - fixed_to_container1->draw_transform()); + fixed_to_container1->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_container2_transform, - container2->draw_transform()); + container2->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container2_transform, - fixed_to_container2->draw_transform()); + fixed_to_container2->DrawTransform()); } TEST_F(LayerPositionConstraintTest, @@ -1078,6 +1099,7 @@ TEST_F(LayerPositionConstraintTest, // Case 1: fixed-container size delta of 20, 20 scroll_layer_impl_->SetScrollDelta(gfx::Vector2d(10, 10)); + scroll_layer_impl_->SetDrawsContent(true); SetFixedContainerSizeDelta(scroll_layer_impl_, gfx::Vector2d(20, 20)); gfx::Transform expected_scroll_layer_transform; expected_scroll_layer_transform.Translate(-10.0, -10.0); @@ -1087,9 +1109,9 @@ TEST_F(LayerPositionConstraintTest, // Top-left fixed-position layer should not be affected by container size. EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_layer_transform, - scroll_layer_impl_->draw_transform()); + scroll_layer_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_child_transform, - fixed_child_impl->draw_transform()); + fixed_child_impl->DrawTransform()); // Case 2: Bottom-right fixed-position layer. fixed_child->SetPositionConstraint(fixed_to_bottom_right_); @@ -1107,9 +1129,35 @@ TEST_F(LayerPositionConstraintTest, expected_fixed_child_transform.Translate(20.0, 20.0); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_layer_transform, - scroll_layer_impl_->draw_transform()); + scroll_layer_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_child_transform, - fixed_child_impl->draw_transform()); + fixed_child_impl->DrawTransform()); +} + +void VerifySerializeAndDeserializeProto(bool is_fixed_position, + bool is_fixed_to_right_edge, + bool is_fixed_to_bottom_edge) { + LayerPositionConstraint constraint; + constraint.set_is_fixed_position(is_fixed_position); + constraint.set_is_fixed_to_right_edge(is_fixed_to_right_edge); + constraint.set_is_fixed_to_bottom_edge(is_fixed_to_bottom_edge); + proto::LayerPositionConstraint proto; + constraint.ToProtobuf(&proto); + + LayerPositionConstraint constraint2; + constraint2.FromProtobuf(proto); + EXPECT_EQ(constraint, constraint2); +} + +TEST(LayerPositionConstraintSerializationTest, SerializeAndDeserializeProto) { + VerifySerializeAndDeserializeProto(true, true, true); + VerifySerializeAndDeserializeProto(true, true, false); + VerifySerializeAndDeserializeProto(true, false, true); + VerifySerializeAndDeserializeProto(true, false, false); + VerifySerializeAndDeserializeProto(false, true, true); + VerifySerializeAndDeserializeProto(false, true, false); + VerifySerializeAndDeserializeProto(false, false, true); + VerifySerializeAndDeserializeProto(false, false, false); } } // namespace diff --git a/chromium/cc/layers/layer_proto_converter.cc b/chromium/cc/layers/layer_proto_converter.cc new file mode 100644 index 00000000000..086ad99d121 --- /dev/null +++ b/chromium/cc/layers/layer_proto_converter.cc @@ -0,0 +1,126 @@ +// 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 "cc/layers/layer_proto_converter.h" + +#include "base/stl_util.h" +#include "cc/layers/empty_content_layer_client.h" +#include "cc/layers/layer.h" +#include "cc/layers/layer_settings.h" +#include "cc/layers/picture_layer.h" +#include "cc/proto/layer.pb.h" +#include "cc/trees/layer_tree_host_common.h" +#include "cc/trees/layer_tree_settings.h" + +namespace cc { + +LayerProtoConverter::LayerProtoConverter() {} + +LayerProtoConverter::~LayerProtoConverter() {} + +// static +void LayerProtoConverter::SerializeLayerHierarchy( + const scoped_refptr<Layer> root_layer, + proto::LayerNode* root_node) { + root_layer->ToLayerNodeProto(root_node); +} + +// static +scoped_refptr<Layer> LayerProtoConverter::DeserializeLayerHierarchy( + scoped_refptr<Layer> existing_root, + const proto::LayerNode& root_node) { + LayerIdMap layer_id_map; + if (existing_root) + RecursivelyFindAllLayers(existing_root, &layer_id_map); + + scoped_refptr<Layer> new_root = existing_root; + if (!existing_root || + (root_node.has_id() && root_node.id() != existing_root->id())) { + // The root node has changed or there was no root node, + // so find or create the new root. + new_root = FindOrAllocateAndConstruct(root_node, layer_id_map); + } + new_root->FromLayerNodeProto(root_node, layer_id_map); + return new_root; +} + +// static +void LayerProtoConverter::SerializeLayerProperties( + Layer* root_layer, + proto::LayerUpdate* layer_update) { + RecursivelySerializeLayerProperties(root_layer, layer_update); +} + +// static +void LayerProtoConverter::DeserializeLayerProperties( + Layer* existing_root, + const proto::LayerUpdate& layer_update) { + DCHECK(existing_root); + LayerIdMap layer_id_map; + RecursivelyFindAllLayers(existing_root, &layer_id_map); + + for (int i = 0; i < layer_update.layers_size(); ++i) { + const proto::LayerProperties& layer_properties = layer_update.layers(i); + + Layer::LayerIdMap::const_iterator iter = + layer_id_map.find(layer_properties.id()); + DCHECK(iter != layer_id_map.end()); + + iter->second->FromLayerPropertiesProto(layer_properties); + } +} + +// static +void LayerProtoConverter::RecursivelySerializeLayerProperties( + Layer* layer, + proto::LayerUpdate* layer_update) { + bool serialize_descendants = layer->ToLayerPropertiesProto(layer_update); + if (!serialize_descendants) + return; + + for (const auto& child : layer->children()) { + RecursivelySerializeLayerProperties(child.get(), layer_update); + } + if (layer->mask_layer()) + RecursivelySerializeLayerProperties(layer->mask_layer(), layer_update); + if (layer->replica_layer()) + RecursivelySerializeLayerProperties(layer->replica_layer(), layer_update); +} + +// static +void LayerProtoConverter::RecursivelyFindAllLayers( + const scoped_refptr<Layer>& layer, + LayerIdMap* layer_id_map) { + LayerTreeHostCommon::CallFunctionForSubtree( + layer.get(), + [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; }); +} + +// static +scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct( + const proto::LayerNode& proto, + const Layer::LayerIdMap& layer_id_map) { + DCHECK(proto.has_id()); + Layer::LayerIdMap::const_iterator iter = layer_id_map.find(proto.id()); + if (iter != layer_id_map.end()) + return iter->second; + DCHECK(proto.has_type()); + switch (proto.type()) { + // Fall through and build a base layer. This won't have any special layer + // properties but still maintains the layer hierarchy if we run into a + // layer type we don't support. + case proto::UNKNOWN: + case proto::LAYER: + return Layer::Create(LayerSettings()).get(); + case proto::PICTURE_LAYER: + return PictureLayer::Create(LayerSettings(), + EmptyContentLayerClient::GetInstance()); + } + // TODO(nyquist): Add the rest of the necessary LayerTypes. This function + // should not return null. + NOTREACHED(); + return nullptr; +} + +} // namespace cc diff --git a/chromium/cc/layers/layer_proto_converter.h b/chromium/cc/layers/layer_proto_converter.h new file mode 100644 index 00000000000..f821a5d539d --- /dev/null +++ b/chromium/cc/layers/layer_proto_converter.h @@ -0,0 +1,76 @@ +// 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 CC_LAYERS_LAYER_PROTO_CONVERTER_H_ +#define CC_LAYERS_LAYER_PROTO_CONVERTER_H_ + +#include "base/macros.h" +#include "cc/base/cc_export.h" +#include "cc/layers/layer.h" + +namespace cc { + +namespace proto { +class LayerNode; +class LayerUpdate; +} + +// A class to faciliate (de)serialization of a Layer tree to protocol buffers. +class CC_EXPORT LayerProtoConverter { + public: + // Starting at |root_layer|, serializes the layer hierarchy into the + // proto::LayerNode. + static void SerializeLayerHierarchy(const scoped_refptr<Layer> root_layer, + proto::LayerNode* root_node); + + // Recursively iterate over the given LayerNode proto and read the structure + // into a local Layer structure, re-using existing Layers. returns the new + // root Layer after updating the hierarchy (may be the same as + // |existing_root|). |existing_root| may be null, which might happen during + // the first deserialize. + static scoped_refptr<Layer> DeserializeLayerHierarchy( + const scoped_refptr<Layer> existing_root, + const proto::LayerNode& root_node); + + // Starting at |root_layer|, serializes the properties of all the dirty nodes + // in the Layer hierarchy. The proto::LayerUpdate will contain all nodes that + // either are dirty or have dirty descendants. Only nodes that are dirty will + // contain the list of dirty properties. + static void SerializeLayerProperties(Layer* root_layer, + proto::LayerUpdate* layer_update); + + // Iterate over all updated layers from the LayerUpdate, and update the + // local Layers. |existing_root| must not be null, as that will make it + // impossible to find the layer to apply the properties to. + static void DeserializeLayerProperties( + Layer* existing_root, + const proto::LayerUpdate& layer_update); + + // Returns the Layer with proto.id() as the Layer id, if it exists in + // |layer_id_map|. Otherwise, a new Layer is constructed of the type given + // from proto.type(). + static scoped_refptr<Layer> FindOrAllocateAndConstruct( + const proto::LayerNode& proto, + const Layer::LayerIdMap& layer_id_map); + + private: + LayerProtoConverter(); + ~LayerProtoConverter(); + + // This method is the inner recursive function for SerializeLayerProperties + // declared above. + static void RecursivelySerializeLayerProperties( + Layer* root_layer, + proto::LayerUpdate* layer_update); + + using LayerIdMap = base::hash_map<int, scoped_refptr<Layer>>; + // Start at |layer| and recursively add |layer| and all its children and + // special layers to |layer_id_map|. + static void RecursivelyFindAllLayers(const scoped_refptr<Layer>& layer, + LayerIdMap* layer_id_map); +}; + +} // namespace cc + +#endif // CC_LAYERS_LAYER_PROTO_CONVERTER_H_ diff --git a/chromium/cc/layers/layer_proto_converter_unittest.cc b/chromium/cc/layers/layer_proto_converter_unittest.cc new file mode 100644 index 00000000000..3aa74d39d21 --- /dev/null +++ b/chromium/cc/layers/layer_proto_converter_unittest.cc @@ -0,0 +1,407 @@ +// 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 "cc/layers/layer_proto_converter.h" + +#include "cc/layers/empty_content_layer_client.h" +#include "cc/layers/layer.h" +#include "cc/layers/layer_settings.h" +#include "cc/layers/picture_layer.h" +#include "cc/proto/layer.pb.h" +#include "cc/test/fake_layer_tree_host.h" +#include "cc/test/fake_layer_tree_host_client.h" +#include "cc/test/test_task_graph_runner.h" +#include "cc/trees/layer_tree_settings.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace cc { +namespace { +class LayerProtoConverterTest : public testing::Test { + public: + LayerProtoConverterTest() + : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} + + protected: + void SetUp() override { + layer_tree_host_ = + FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_); + } + + void TearDown() override { + layer_tree_host_->SetRootLayer(nullptr); + layer_tree_host_ = nullptr; + } + + TestTaskGraphRunner task_graph_runner_; + FakeLayerTreeHostClient fake_client_; + scoped_ptr<FakeLayerTreeHost> layer_tree_host_; +}; + +TEST_F(LayerProtoConverterTest, TestKeepingRoot) { + /* Test deserialization of a tree that looks like: + root + / \ + a b + \ + c + The old root node will be reused during deserialization. + */ + scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); + proto::LayerNode root_node; + root_node.set_id(old_root->id()); + root_node.set_type(proto::LayerType::LAYER); + + proto::LayerNode* child_a_node = root_node.add_children(); + child_a_node->set_id(442); + child_a_node->set_type(proto::LayerType::LAYER); + child_a_node->set_parent_id(old_root->id()); // root_node + + proto::LayerNode* child_b_node = root_node.add_children(); + child_b_node->set_id(443); + child_b_node->set_type(proto::LayerType::LAYER); + child_b_node->set_parent_id(old_root->id()); // root_node + + proto::LayerNode* child_c_node = child_b_node->add_children(); + child_c_node->set_id(444); + child_c_node->set_type(proto::LayerType::LAYER); + child_c_node->set_parent_id(child_b_node->id()); + + scoped_refptr<Layer> new_root = + LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); + + // The new root should not be the same as the old root. + EXPECT_EQ(old_root->id(), new_root->id()); + ASSERT_EQ(2u, new_root->children().size()); + scoped_refptr<Layer> child_a = new_root->children()[0]; + scoped_refptr<Layer> child_b = new_root->children()[1]; + + EXPECT_EQ(child_a_node->id(), child_a->id()); + EXPECT_EQ(child_b_node->id(), child_b->id()); + + EXPECT_EQ(0u, child_a->children().size()); + ASSERT_EQ(1u, child_b->children().size()); + + scoped_refptr<Layer> child_c = child_b->children()[0]; + EXPECT_EQ(child_c_node->id(), child_c->id()); +} + +TEST_F(LayerProtoConverterTest, TestNoExistingRoot) { + /* Test deserialization of a tree that looks like: + root + / + a + There is no existing root node before serialization. + */ + int new_root_id = 244; + proto::LayerNode root_node; + root_node.set_id(new_root_id); + root_node.set_type(proto::LayerType::LAYER); + + proto::LayerNode* child_a_node = root_node.add_children(); + child_a_node->set_id(442); + child_a_node->set_type(proto::LayerType::LAYER); + child_a_node->set_parent_id(new_root_id); // root_node + + scoped_refptr<Layer> new_root = + LayerProtoConverter::DeserializeLayerHierarchy(nullptr, root_node); + + // The new root should not be the same as the old root. + EXPECT_EQ(new_root_id, new_root->id()); + ASSERT_EQ(1u, new_root->children().size()); + scoped_refptr<Layer> child_a = new_root->children()[0]; + + EXPECT_EQ(child_a_node->id(), child_a->id()); + EXPECT_EQ(0u, child_a->children().size()); +} + +TEST_F(LayerProtoConverterTest, TestSwappingRoot) { + /* Test deserialization of a tree that looks like: + root + / \ + a b + \ + c + The old root node will be swapped out during deserialization. + */ + proto::LayerNode root_node; + root_node.set_id(441); + root_node.set_type(proto::LayerType::LAYER); + + proto::LayerNode* child_a_node = root_node.add_children(); + child_a_node->set_id(442); + child_a_node->set_type(proto::LayerType::LAYER); + child_a_node->set_parent_id(root_node.id()); + + proto::LayerNode* child_b_node = root_node.add_children(); + child_b_node->set_id(443); + child_b_node->set_type(proto::LayerType::LAYER); + child_b_node->set_parent_id(root_node.id()); + + proto::LayerNode* child_c_node = child_b_node->add_children(); + child_c_node->set_id(444); + child_c_node->set_type(proto::LayerType::LAYER); + child_c_node->set_parent_id(child_b_node->id()); + + scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); + scoped_refptr<Layer> new_root = + LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); + + // The new root should not be the same as the old root. + EXPECT_EQ(root_node.id(), new_root->id()); + ASSERT_EQ(2u, new_root->children().size()); + scoped_refptr<Layer> child_a = new_root->children()[0]; + scoped_refptr<Layer> child_b = new_root->children()[1]; + + EXPECT_EQ(child_a_node->id(), child_a->id()); + EXPECT_EQ(child_b_node->id(), child_b->id()); + + EXPECT_EQ(0u, child_a->children().size()); + ASSERT_EQ(1u, child_b->children().size()); + + scoped_refptr<Layer> child_c = child_b->children()[0]; + EXPECT_EQ(child_c_node->id(), child_c->id()); +} + +TEST_F(LayerProtoConverterTest, RecursivePropertiesSerialization) { + /* Testing serialization of properties for a tree that looks like this: + root+ + / \ + a* b*+[mask:*,replica] + / \ + c d* + Layers marked with * have changed properties. + Layers marked with + have descendants with changed properties. + Layer b also has a mask layer and a replica layer. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); + layer_src_root->AddChild(layer_src_a); + layer_src_root->AddChild(layer_src_b); + layer_src_a->AddChild(layer_src_c); + layer_src_b->AddChild(layer_src_d); + layer_src_b->SetMaskLayer(layer_src_b_mask.get()); + layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); + + layer_src_a->SetNeedsPushProperties(); + layer_src_b->SetNeedsPushProperties(); + layer_src_b_mask->SetNeedsPushProperties(); + layer_src_d->SetNeedsPushProperties(); + + proto::LayerUpdate layer_update; + LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), + &layer_update); + + // All flags for pushing properties should have been cleared. + EXPECT_FALSE(layer_src_root->needs_push_properties()); + EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_a->needs_push_properties()); + EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_b->needs_push_properties()); + EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); + EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); + EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_c->needs_push_properties()); + EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_d->needs_push_properties()); + EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); + + // Only 5 of the layers should have been serialized. + ASSERT_EQ(5, layer_update.layers_size()); + EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); + proto::LayerProperties dest_root = layer_update.layers(0); + EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id()); + proto::LayerProperties dest_a = layer_update.layers(1); + EXPECT_EQ(layer_src_b->id(), layer_update.layers(2).id()); + proto::LayerProperties dest_b = layer_update.layers(2); + EXPECT_EQ(layer_src_d->id(), layer_update.layers(3).id()); + proto::LayerProperties dest_d = layer_update.layers(3); + EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(4).id()); + proto::LayerProperties dest_b_mask = layer_update.layers(4); + + // Ensure the properties and dependants metadata is correctly serialized. + EXPECT_FALSE(dest_root.needs_push_properties()); + EXPECT_EQ(2, dest_root.num_dependents_need_push_properties()); + EXPECT_FALSE(dest_root.has_base()); + + EXPECT_TRUE(dest_a.needs_push_properties()); + EXPECT_EQ(0, dest_a.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_a.has_base()); + + EXPECT_TRUE(dest_b.needs_push_properties()); + EXPECT_EQ(2, dest_b.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_b.has_base()); + + EXPECT_TRUE(dest_d.needs_push_properties()); + EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_d.has_base()); + + EXPECT_TRUE(dest_b_mask.needs_push_properties()); + EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_b_mask.has_base()); +} + +TEST_F(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) { + /* Testing serialization of properties for a tree that looks like this: + root+ + \ + b*+[mask:*] + \ + c + Layers marked with * have changed properties. + Layers marked with + have descendants with changed properties. + Layer b also has a mask layer. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); + layer_src_root->AddChild(layer_src_b); + layer_src_b->AddChild(layer_src_c); + layer_src_b->SetMaskLayer(layer_src_b_mask.get()); + + layer_src_b->SetNeedsPushProperties(); + layer_src_b_mask->SetNeedsPushProperties(); + + proto::LayerUpdate layer_update; + LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), + &layer_update); + + // All flags for pushing properties should have been cleared. + EXPECT_FALSE(layer_src_root->needs_push_properties()); + EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_b->needs_push_properties()); + EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); + EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_c->needs_push_properties()); + EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); + + // Only 3 of the layers should have been serialized. + ASSERT_EQ(3, layer_update.layers_size()); + EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); + proto::LayerProperties dest_root = layer_update.layers(0); + EXPECT_EQ(layer_src_b->id(), layer_update.layers(1).id()); + proto::LayerProperties dest_b = layer_update.layers(1); + EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(2).id()); + proto::LayerProperties dest_b_mask = layer_update.layers(2); + + // Ensure the properties and dependants metadata is correctly serialized. + EXPECT_FALSE(dest_root.needs_push_properties()); + EXPECT_EQ(1, dest_root.num_dependents_need_push_properties()); + EXPECT_FALSE(dest_root.has_base()); + + EXPECT_TRUE(dest_b.needs_push_properties()); + EXPECT_EQ(1, dest_b.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_b.has_base()); + + EXPECT_TRUE(dest_b_mask.needs_push_properties()); + EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_b_mask.has_base()); +} + +TEST_F(LayerProtoConverterTest, DeserializeLayerProperties) { + /* Testing deserialization of properties for a tree that looks like this: + root*+ + / \ + a b+ + \ + c* + Layers marked with * have changed properties. + Layers marked with + have descendants with changed properties. + */ + proto::LayerUpdate updates; + + scoped_refptr<Layer> root = Layer::Create(LayerSettings()); + root->SetLayerTreeHost(layer_tree_host_.get()); + proto::LayerProperties* root_props = updates.add_layers(); + root_props->set_id(root->id()); + root_props->set_needs_push_properties(true); + root_props->set_num_dependents_need_push_properties(1); + root_props->mutable_base(); + + scoped_refptr<Layer> a = Layer::Create(LayerSettings()); + a->SetLayerTreeHost(layer_tree_host_.get()); + proto::LayerProperties* a_props = updates.add_layers(); + a_props->set_id(a->id()); + a_props->set_needs_push_properties(false); + a_props->set_num_dependents_need_push_properties(0); + root->AddChild(a); + + scoped_refptr<Layer> b = Layer::Create(LayerSettings()); + b->SetLayerTreeHost(layer_tree_host_.get()); + proto::LayerProperties* b_props = updates.add_layers(); + b_props->set_id(b->id()); + b_props->set_needs_push_properties(false); + b_props->set_num_dependents_need_push_properties(1); + root->AddChild(b); + + scoped_refptr<Layer> c = Layer::Create(LayerSettings()); + c->SetLayerTreeHost(layer_tree_host_.get()); + proto::LayerProperties* c_props = updates.add_layers(); + c_props->set_id(c->id()); + c_props->set_needs_push_properties(true); + c_props->set_num_dependents_need_push_properties(0); + c_props->mutable_base(); + b->AddChild(c); + + LayerProtoConverter::DeserializeLayerProperties(root.get(), updates); + + EXPECT_TRUE(root->needs_push_properties()); + EXPECT_TRUE(root->descendant_needs_push_properties()); + + EXPECT_FALSE(a->needs_push_properties()); + EXPECT_FALSE(a->descendant_needs_push_properties()); + + EXPECT_FALSE(b->needs_push_properties()); + EXPECT_TRUE(b->descendant_needs_push_properties()); + + EXPECT_TRUE(c->needs_push_properties()); + EXPECT_FALSE(c->descendant_needs_push_properties()); + + // Recursively clear out LayerTreeHost. + root->SetLayerTreeHost(nullptr); +} + +TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) { + // Make sure that PictureLayers serialize to the + // proto::LayerType::PICTURE_LAYER type. + scoped_refptr<PictureLayer> layer = PictureLayer::Create( + LayerSettings(), EmptyContentLayerClient::GetInstance()); + + proto::LayerNode layer_hierarchy; + LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy); + EXPECT_EQ(proto::LayerType::PICTURE_LAYER, layer_hierarchy.type()); +} + +TEST_F(LayerProtoConverterTest, PictureLayerTypeDeserialization) { + // Make sure that proto::LayerType::PICTURE_LAYER ends up building a + // PictureLayer. + scoped_refptr<Layer> old_root = PictureLayer::Create( + LayerSettings(), EmptyContentLayerClient::GetInstance()); + proto::LayerNode root_node; + root_node.set_id(old_root->id()); + root_node.set_type(proto::LayerType::PICTURE_LAYER); + + scoped_refptr<Layer> new_root = + LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); + + // Validate that the ids are equal. + EXPECT_EQ(old_root->id(), new_root->id()); + + // Check that the layer type is equal by using the type this layer would + // serialize to. + proto::LayerNode layer_node; + new_root->SetTypeForProtoSerialization(&layer_node); + EXPECT_EQ(proto::LayerType::PICTURE_LAYER, layer_node.type()); +} + +} // namespace +} // namespace cc diff --git a/chromium/cc/layers/layer_settings.cc b/chromium/cc/layers/layer_settings.cc new file mode 100644 index 00000000000..d2eac382e0c --- /dev/null +++ b/chromium/cc/layers/layer_settings.cc @@ -0,0 +1,13 @@ +// 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 "cc/layers/layer_settings.h" + +namespace cc { + +LayerSettings::LayerSettings() : use_compositor_animation_timelines(true) {} + +LayerSettings::~LayerSettings() {} + +} // namespace cc diff --git a/chromium/cc/layers/layer_settings.h b/chromium/cc/layers/layer_settings.h new file mode 100644 index 00000000000..4f1ac3ac0c6 --- /dev/null +++ b/chromium/cc/layers/layer_settings.h @@ -0,0 +1,22 @@ +// 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 CC_LAYERS_LAYER_SETTINGS_H_ +#define CC_LAYERS_LAYER_SETTINGS_H_ + +#include "cc/base/cc_export.h" + +namespace cc { + +class CC_EXPORT LayerSettings { + public: + LayerSettings(); + ~LayerSettings(); + + bool use_compositor_animation_timelines; +}; + +} // namespace cc + +#endif // CC_LAYERS_LAYER_SETTINGS_H_ diff --git a/chromium/cc/layers/layer_unittest.cc b/chromium/cc/layers/layer_unittest.cc index 6f81e8e8483..f73cb2543cc 100644 --- a/chromium/cc/layers/layer_unittest.cc +++ b/chromium/cc/layers/layer_unittest.cc @@ -4,14 +4,22 @@ #include "cc/layers/layer.h" +#include <stddef.h> + #include "base/thread_task_runner_handle.h" +#include "cc/animation/animation_host.h" +#include "cc/animation/animation_id_provider.h" #include "cc/animation/keyframed_animation_curve.h" +#include "cc/animation/mutable_properties.h" #include "cc/base/math_util.h" #include "cc/layers/layer_impl.h" +#include "cc/layers/layer_settings.h" #include "cc/output/copy_output_request.h" #include "cc/output/copy_output_result.h" +#include "cc/proto/layer.pb.h" #include "cc/test/animation_test_common.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" +#include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" @@ -23,6 +31,12 @@ #include "cc/trees/single_thread_proxy.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/gfx/geometry/point3_f.h" +#include "ui/gfx/geometry/point_f.h" +#include "ui/gfx/geometry/scroll_offset.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/geometry/vector2d_f.h" #include "ui/gfx/transform.h" using ::testing::AnyNumber; @@ -39,13 +53,324 @@ using ::testing::_; } while (false) namespace cc { + +// This class is a friend of Layer, and is used as a wrapper for all the tests +// related to proto serialization. This is done so that it is unnecessary to +// add FRIEND_TEST_ALL_PREFIXES in //cc/layers/layer.h for all the tests. +// It is in the cc namespace so that it can be a friend of Layer. +// The tests still have helpful names, and a test with the name FooBar would +// have a wrapper method in this class called RunFooBarTest. +class LayerSerializationTest : public testing::Test { + public: + LayerSerializationTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} + + protected: + void SetUp() override { + layer_tree_host_ = + FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_); + } + + void TearDown() override { + layer_tree_host_->SetRootLayer(nullptr); + layer_tree_host_ = nullptr; + } + + // Serializes |src| to proto and back again to a Layer, then verifies that + // the two Layers are equal for serialization purposes. + void VerifyBaseLayerPropertiesSerializationAndDeserialization(Layer* src) { + // This is required to ensure that properties are serialized. + src->SetNeedsPushProperties(); + src->SetLayerTreeHost(layer_tree_host_.get()); + + // The following two members are reset during serialization, so + // store the original values. + bool stacking_order_changed = src->stacking_order_changed_; + gfx::Rect update_rect = src->update_rect_; + + // Serialize |src| to protobuf and read the first entry in the + // LayerUpdate. There are no descendants, so the serialization + // of |src| is the only entry. + proto::LayerUpdate layer_update; + EXPECT_FALSE(src->ToLayerPropertiesProto(&layer_update)); + ASSERT_EQ(1, layer_update.layers_size()); + proto::LayerProperties props = layer_update.layers(0); + + // The |dest| layer needs to be able to lookup the scroll and clip parents. + if (src->scroll_parent_) + layer_tree_host_->RegisterLayer(src->scroll_parent_); + if (src->scroll_children_) { + for (auto* child : *(src->scroll_children_)) + layer_tree_host_->RegisterLayer(child); + } + if (src->clip_parent_) + layer_tree_host_->RegisterLayer(src->clip_parent_); + if (src->clip_children_) { + for (auto* child : *(src->clip_children_)) + layer_tree_host_->RegisterLayer(child); + } + // Reset the LayerTreeHost registration for the |src| layer so + // it can be re-used for the |dest| layer. + src->SetLayerTreeHost(nullptr); + + scoped_refptr<Layer> dest = Layer::Create(LayerSettings()); + dest->layer_id_ = src->layer_id_; + dest->SetLayerTreeHost(layer_tree_host_.get()); + dest->FromLayerPropertiesProto(props); + + // Verify that both layers are equal. + EXPECT_EQ(src->transform_origin_, dest->transform_origin_); + EXPECT_EQ(src->background_color_, dest->background_color_); + EXPECT_EQ(src->bounds_, dest->bounds_); + EXPECT_EQ(src->transform_tree_index_, dest->transform_tree_index_); + EXPECT_EQ(src->effect_tree_index_, dest->effect_tree_index_); + EXPECT_EQ(src->clip_tree_index_, dest->clip_tree_index_); + EXPECT_EQ(src->offset_to_transform_parent_, + dest->offset_to_transform_parent_); + EXPECT_EQ(src->double_sided_, dest->double_sided_); + EXPECT_EQ(src->draws_content_, dest->draws_content_); + EXPECT_EQ(src->hide_layer_and_subtree_, dest->hide_layer_and_subtree_); + EXPECT_EQ(src->has_render_surface_, dest->has_render_surface_); + EXPECT_EQ(src->masks_to_bounds_, dest->masks_to_bounds_); + EXPECT_EQ(src->should_scroll_on_main_thread_, + dest->should_scroll_on_main_thread_); + EXPECT_EQ(src->have_wheel_event_handlers_, + dest->have_wheel_event_handlers_); + EXPECT_EQ(src->have_scroll_event_handlers_, + dest->have_scroll_event_handlers_); + EXPECT_EQ(src->non_fast_scrollable_region_, + dest->non_fast_scrollable_region_); + EXPECT_EQ(src->touch_event_handler_region_, + dest->touch_event_handler_region_); + EXPECT_EQ(src->scroll_blocks_on_, dest->scroll_blocks_on_); + EXPECT_EQ(src->contents_opaque_, dest->contents_opaque_); + EXPECT_EQ(src->opacity_, dest->opacity_); + EXPECT_EQ(src->blend_mode_, dest->blend_mode_); + EXPECT_EQ(src->is_root_for_isolated_group_, + dest->is_root_for_isolated_group_); + EXPECT_EQ(src->position_, dest->position_); + EXPECT_EQ(src->is_container_for_fixed_position_layers_, + dest->is_container_for_fixed_position_layers_); + EXPECT_EQ(src->position_constraint_, dest->position_constraint_); + EXPECT_EQ(src->should_flatten_transform_, dest->should_flatten_transform_); + EXPECT_EQ(src->should_flatten_transform_from_property_tree_, + dest->should_flatten_transform_from_property_tree_); + EXPECT_EQ(src->draw_blend_mode_, dest->draw_blend_mode_); + EXPECT_EQ(src->use_parent_backface_visibility_, + dest->use_parent_backface_visibility_); + EXPECT_EQ(src->transform_, dest->transform_); + EXPECT_EQ(src->transform_is_invertible_, dest->transform_is_invertible_); + EXPECT_EQ(src->sorting_context_id_, dest->sorting_context_id_); + EXPECT_EQ(src->num_descendants_that_draw_content_, + dest->num_descendants_that_draw_content_); + EXPECT_EQ(src->scroll_clip_layer_id_, dest->scroll_clip_layer_id_); + EXPECT_EQ(src->user_scrollable_horizontal_, + dest->user_scrollable_horizontal_); + EXPECT_EQ(src->user_scrollable_vertical_, dest->user_scrollable_vertical_); + EXPECT_EQ(src->scroll_offset_, dest->scroll_offset_); + EXPECT_EQ(src->scroll_compensation_adjustment_, + dest->scroll_compensation_adjustment_); + EXPECT_EQ(update_rect, dest->update_rect_); + EXPECT_EQ(stacking_order_changed, dest->stacking_order_changed_); + + if (src->scroll_parent_) { + ASSERT_TRUE(dest->scroll_parent_); + EXPECT_EQ(src->scroll_parent_->id(), dest->scroll_parent_->id()); + } else { + EXPECT_FALSE(dest->scroll_parent_); + } + if (src->scroll_children_) { + ASSERT_TRUE(dest->scroll_children_); + EXPECT_EQ(*(src->scroll_children_), *(dest->scroll_children_)); + } else { + EXPECT_FALSE(dest->scroll_children_); + } + + if (src->clip_parent_) { + ASSERT_TRUE(dest->clip_parent_); + EXPECT_EQ(src->clip_parent_->id(), dest->clip_parent_->id()); + } else { + ASSERT_FALSE(dest->clip_parent_); + } + if (src->clip_children_) { + ASSERT_TRUE(dest->clip_children_); + EXPECT_EQ(*(src->clip_children_), *(dest->clip_children_)); + } else { + EXPECT_FALSE(dest->clip_children_); + } + + // The following two members should have been reset during serialization. + EXPECT_FALSE(src->stacking_order_changed_); + EXPECT_EQ(gfx::Rect(), src->update_rect_); + + // Before deleting |dest|, the LayerTreeHost must be unset. + dest->SetLayerTreeHost(nullptr); + + // Cleanup scroll tree. + if (src->scroll_parent_) + layer_tree_host_->UnregisterLayer(src->scroll_parent_); + src->scroll_parent_ = nullptr; + dest->scroll_parent_ = nullptr; + if (src->scroll_children_) { + for (auto* child : *(src->scroll_children_)) + layer_tree_host_->UnregisterLayer(child); + src->scroll_children_.reset(); + dest->scroll_children_.reset(); + } + + // Cleanup clip tree. + if (src->clip_parent_) + layer_tree_host_->UnregisterLayer(src->clip_parent_); + src->clip_parent_ = nullptr; + dest->clip_parent_ = nullptr; + if (src->clip_children_) { + for (auto* child : *(src->clip_children_)) + layer_tree_host_->UnregisterLayer(child); + src->clip_children_.reset(); + dest->clip_children_.reset(); + } + } + + void RunNoMembersChangedTest() { + scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); + } + + void RunArbitraryMembersChangedTest() { + scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + layer->transform_origin_ = gfx::Point3F(3.0f, 1.0f, 4.0f); + layer->background_color_ = SK_ColorRED; + layer->bounds_ = gfx::Size(3, 14); + layer->transform_tree_index_ = -1; + layer->effect_tree_index_ = -1; + layer->clip_tree_index_ = 71; + layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f); + layer->double_sided_ = true; + layer->draws_content_ = true; + layer->hide_layer_and_subtree_ = false; + layer->has_render_surface_ = false; + layer->masks_to_bounds_ = true; + layer->should_scroll_on_main_thread_ = false; + layer->have_wheel_event_handlers_ = true; + layer->have_scroll_event_handlers_ = false; + layer->non_fast_scrollable_region_ = Region(gfx::Rect(5, 1, 14, 3)); + layer->touch_event_handler_region_ = Region(gfx::Rect(3, 14, 1, 5)); + layer->scroll_blocks_on_ = SCROLL_BLOCKS_ON_NONE; + layer->contents_opaque_ = true; + layer->opacity_ = 1.f; + layer->blend_mode_ = SkXfermode::kSrcOver_Mode; + layer->is_root_for_isolated_group_ = true; + layer->position_ = gfx::PointF(3.14f, 6.28f); + layer->is_container_for_fixed_position_layers_ = true; + LayerPositionConstraint pos_con; + pos_con.set_is_fixed_to_bottom_edge(true); + layer->position_constraint_ = pos_con; + layer->should_flatten_transform_ = true; + layer->should_flatten_transform_from_property_tree_ = true; + layer->draw_blend_mode_ = SkXfermode::kSrcOut_Mode; + layer->use_parent_backface_visibility_ = true; + gfx::Transform transform; + transform.Rotate(90); + layer->transform_ = transform; + layer->transform_is_invertible_ = true; + layer->sorting_context_id_ = 0; + layer->num_descendants_that_draw_content_ = 5; + layer->scroll_clip_layer_id_ = Layer::INVALID_ID; + layer->user_scrollable_horizontal_ = false; + layer->user_scrollable_vertical_ = true; + layer->scroll_offset_ = gfx::ScrollOffset(3, 14); + layer->scroll_compensation_adjustment_ = gfx::Vector2dF(6.28f, 3.14f); + layer->update_rect_ = gfx::Rect(14, 15); + layer->stacking_order_changed_ = true; + + VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); + } + + void RunAllMembersChangedTest() { + scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + layer->transform_origin_ = gfx::Point3F(3.0f, 1.0f, 4.0f); + layer->background_color_ = SK_ColorRED; + layer->bounds_ = gfx::Size(3, 14); + layer->transform_tree_index_ = 39; + layer->effect_tree_index_ = 17; + layer->clip_tree_index_ = 71; + layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f); + layer->double_sided_ = !layer->double_sided_; + layer->draws_content_ = !layer->draws_content_; + layer->hide_layer_and_subtree_ = !layer->hide_layer_and_subtree_; + layer->has_render_surface_ = !layer->has_render_surface_; + layer->masks_to_bounds_ = !layer->masks_to_bounds_; + layer->should_scroll_on_main_thread_ = + !layer->should_scroll_on_main_thread_; + layer->have_wheel_event_handlers_ = !layer->have_wheel_event_handlers_; + layer->have_scroll_event_handlers_ = !layer->have_scroll_event_handlers_; + layer->non_fast_scrollable_region_ = Region(gfx::Rect(5, 1, 14, 3)); + layer->touch_event_handler_region_ = Region(gfx::Rect(3, 14, 1, 5)); + layer->scroll_blocks_on_ = SCROLL_BLOCKS_ON_WHEEL_EVENT; + layer->contents_opaque_ = !layer->contents_opaque_; + layer->opacity_ = 3.14f; + layer->blend_mode_ = SkXfermode::kSrcIn_Mode; + layer->is_root_for_isolated_group_ = !layer->is_root_for_isolated_group_; + layer->position_ = gfx::PointF(3.14f, 6.28f); + layer->is_container_for_fixed_position_layers_ = + !layer->is_container_for_fixed_position_layers_; + LayerPositionConstraint pos_con; + pos_con.set_is_fixed_to_bottom_edge(true); + layer->position_constraint_ = pos_con; + layer->should_flatten_transform_ = !layer->should_flatten_transform_; + layer->should_flatten_transform_from_property_tree_ = + !layer->should_flatten_transform_from_property_tree_; + layer->draw_blend_mode_ = SkXfermode::kSrcOut_Mode; + layer->use_parent_backface_visibility_ = + !layer->use_parent_backface_visibility_; + gfx::Transform transform; + transform.Rotate(90); + layer->transform_ = transform; + layer->transform_is_invertible_ = !layer->transform_is_invertible_; + layer->sorting_context_id_ = 42; + layer->num_descendants_that_draw_content_ = 5; + layer->scroll_clip_layer_id_ = 17; + layer->user_scrollable_horizontal_ = !layer->user_scrollable_horizontal_; + layer->user_scrollable_vertical_ = !layer->user_scrollable_vertical_; + layer->scroll_offset_ = gfx::ScrollOffset(3, 14); + layer->scroll_compensation_adjustment_ = gfx::Vector2dF(6.28f, 3.14f); + layer->update_rect_ = gfx::Rect(14, 15); + layer->stacking_order_changed_ = !layer->stacking_order_changed_; + + VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); + } + + void RunScrollAndClipLayersTest() { + scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + + scoped_refptr<Layer> scroll_parent = Layer::Create(LayerSettings()); + layer->scroll_parent_ = scroll_parent.get(); + scoped_refptr<Layer> scroll_child = Layer::Create(LayerSettings()); + layer->scroll_children_.reset(new std::set<Layer*>); + layer->scroll_children_->insert(scroll_child.get()); + + scoped_refptr<Layer> clip_parent = Layer::Create(LayerSettings()); + layer->clip_parent_ = clip_parent.get(); + layer->clip_children_.reset(new std::set<Layer*>); + scoped_refptr<Layer> clip_child1 = Layer::Create(LayerSettings()); + layer->clip_children_->insert(clip_child1.get()); + scoped_refptr<Layer> clip_child2 = Layer::Create(LayerSettings()); + layer->clip_children_->insert(clip_child2.get()); + + VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); + } + + TestTaskGraphRunner task_graph_runner_; + FakeLayerTreeHostClient fake_client_; + scoped_ptr<FakeLayerTreeHost> layer_tree_host_; +}; + namespace { class MockLayerTreeHost : public LayerTreeHost { public: MockLayerTreeHost(LayerTreeHostSingleThreadClient* single_thread_client, LayerTreeHost::InitParams* params) - : LayerTreeHost(params) { + : LayerTreeHost(params, CompositorMode::SingleThreaded) { InitializeSingleThreaded(single_thread_client, base::ThreadTaskRunnerHandle::Get(), nullptr); } @@ -55,18 +380,37 @@ class MockLayerTreeHost : public LayerTreeHost { MOCK_METHOD0(SetNeedsFullTreeSync, void()); }; +class LayerTreeSettingsForLayerTest : public LayerTreeSettings { + public: + LayerTreeSettingsForLayerTest() { use_compositor_animation_timelines = true; } +}; + class LayerTest : public testing::Test { public: LayerTest() - : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), - fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} + : host_impl_(LayerTreeSettingsForLayerTest(), + &task_runner_provider_, + &shared_bitmap_manager_, + &task_graph_runner_), + fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { + layer_settings_.use_compositor_animation_timelines = + settings().use_compositor_animation_timelines; + if (settings().use_compositor_animation_timelines) { + timeline_impl_ = + AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); + timeline_impl_->set_is_impl_only(true); + host_impl_.animation_host()->AddAnimationTimeline(timeline_impl_); + } + } + + const LayerTreeSettings& settings() { return settings_; } + scoped_refptr<AnimationTimeline> timeline_impl() { return timeline_impl_; } protected: void SetUp() override { LayerTreeHost::InitParams params; - LayerTreeSettings settings; params.client = &fake_client_; - params.settings = &settings; + params.settings = &settings_; params.task_graph_runner = &task_graph_runner_; layer_tree_host_.reset( new StrictMock<MockLayerTreeHost>(&fake_client_, ¶ms)); @@ -133,7 +477,7 @@ class LayerTest : public testing::Test { VerifyTestTreeInitialState(); } - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeLayerTreeHostImpl host_impl_; @@ -148,6 +492,9 @@ class LayerTest : public testing::Test { scoped_refptr<Layer> grand_child2_; scoped_refptr<Layer> grand_child3_; + scoped_refptr<AnimationTimeline> timeline_impl_; + + LayerTreeSettingsForLayerTest settings_; LayerSettings layer_settings_; }; @@ -632,6 +979,9 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { gfx::Rect(10, 10))); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetForceRenderSurface(true)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetHideLayerAndSubtree(true)); + EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetElementId(2)); + EXPECT_SET_NEEDS_COMMIT( + 1, test_layer->SetMutableProperties(kMutablePropertyTransform)); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetMaskLayer( dummy_layer1.get())); @@ -719,14 +1069,18 @@ TEST_F(LayerTest, EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(test_layer)); - scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); - impl_layer->layer_animation_controller()->SetAnimationRegistrar( - registrar.get()); - - AddAnimatedTransformToController(impl_layer->layer_animation_controller(), - 1.0, - 0, - 100); + scoped_ptr<AnimationRegistrar> registrar; + if (settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(impl_layer->id(), timeline_impl(), + 1.0, 0, 100); + } else { + registrar = AnimationRegistrar::Create(); + impl_layer->layer_animation_controller()->SetAnimationRegistrar( + registrar.get()); + + AddAnimatedTransformToController(impl_layer->layer_animation_controller(), + 1.0, 0, 100); + } gfx::Transform transform; transform.Rotate(45.0); @@ -737,13 +1091,19 @@ TEST_F(LayerTest, EXPECT_TRUE(impl_layer->LayerPropertyChanged()); impl_layer->ResetAllChangeTrackingForSubtree(); - AddAnimatedTransformToController(impl_layer->layer_animation_controller(), - 1.0, - 0, - 100); - impl_layer->layer_animation_controller() - ->GetAnimation(Animation::TRANSFORM) - ->set_is_impl_only(true); + if (settings().use_compositor_animation_timelines) { + int animation_id = AddAnimatedTransformToLayerWithPlayer( + impl_layer->id(), timeline_impl(), 1.0, 0, 100); + GetAnimationFromLayerWithExistingPlayer(impl_layer->id(), timeline_impl(), + animation_id) + ->set_is_impl_only(true); + } else { + AddAnimatedTransformToController(impl_layer->layer_animation_controller(), + 1.0, 0, 100); + impl_layer->layer_animation_controller() + ->GetAnimation(Animation::TRANSFORM) + ->set_is_impl_only(true); + } transform.Rotate(45.0); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); @@ -761,15 +1121,18 @@ TEST_F(LayerTest, EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(test_layer)); - scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); - impl_layer->layer_animation_controller()->SetAnimationRegistrar( - registrar.get()); - - AddOpacityTransitionToController(impl_layer->layer_animation_controller(), - 1.0, - 0.3f, - 0.7f, - false); + scoped_ptr<AnimationRegistrar> registrar; + if (settings().use_compositor_animation_timelines) { + AddOpacityTransitionToLayerWithPlayer(impl_layer->id(), timeline_impl(), + 1.0, 0.3f, 0.7f, false); + } else { + registrar = AnimationRegistrar::Create(); + impl_layer->layer_animation_controller()->SetAnimationRegistrar( + registrar.get()); + + AddOpacityTransitionToController(impl_layer->layer_animation_controller(), + 1.0, 0.3f, 0.7f, false); + } EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); @@ -778,14 +1141,19 @@ TEST_F(LayerTest, EXPECT_TRUE(impl_layer->LayerPropertyChanged()); impl_layer->ResetAllChangeTrackingForSubtree(); - AddOpacityTransitionToController(impl_layer->layer_animation_controller(), - 1.0, - 0.3f, - 0.7f, - false); - impl_layer->layer_animation_controller() - ->GetAnimation(Animation::OPACITY) - ->set_is_impl_only(true); + if (settings().use_compositor_animation_timelines) { + int animation_id = AddOpacityTransitionToLayerWithPlayer( + impl_layer->id(), timeline_impl(), 1.0, 0.3f, 0.7f, false); + GetAnimationFromLayerWithExistingPlayer(impl_layer->id(), timeline_impl(), + animation_id) + ->set_is_impl_only(true); + } else { + AddOpacityTransitionToController(impl_layer->layer_animation_controller(), + 1.0, 0.3f, 0.7f, false); + impl_layer->layer_animation_controller() + ->GetAnimation(Animation::OPACITY) + ->set_is_impl_only(true); + } EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.75f)); EXPECT_FALSE(impl_layer->LayerPropertyChanged()); @@ -802,12 +1170,18 @@ TEST_F(LayerTest, EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(test_layer)); - scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); - impl_layer->layer_animation_controller()->SetAnimationRegistrar( - registrar.get()); - - AddAnimatedFilterToController( - impl_layer->layer_animation_controller(), 1.0, 1.f, 2.f); + scoped_ptr<AnimationRegistrar> registrar; + if (settings().use_compositor_animation_timelines) { + AddAnimatedFilterToLayerWithPlayer(impl_layer->id(), timeline_impl(), 1.0, + 1.f, 2.f); + } else { + registrar = AnimationRegistrar::Create(); + impl_layer->layer_animation_controller()->SetAnimationRegistrar( + registrar.get()); + + AddAnimatedFilterToController(impl_layer->layer_animation_controller(), 1.0, + 1.f, 2.f); + } FilterOperations filters; filters.Append(FilterOperation::CreateBlurFilter(2.f)); @@ -818,11 +1192,19 @@ TEST_F(LayerTest, EXPECT_TRUE(impl_layer->LayerPropertyChanged()); impl_layer->ResetAllChangeTrackingForSubtree(); - AddAnimatedFilterToController( - impl_layer->layer_animation_controller(), 1.0, 1.f, 2.f); - impl_layer->layer_animation_controller() - ->GetAnimation(Animation::FILTER) - ->set_is_impl_only(true); + if (settings().use_compositor_animation_timelines) { + int animation_id = AddAnimatedFilterToLayerWithPlayer( + impl_layer->id(), timeline_impl(), 1.0, 1.f, 2.f); + GetAnimationFromLayerWithExistingPlayer(impl_layer->id(), timeline_impl(), + animation_id) + ->set_is_impl_only(true); + } else { + AddAnimatedFilterToController(impl_layer->layer_animation_controller(), 1.0, + 1.f, 2.f); + impl_layer->layer_animation_controller() + ->GetAnimation(Animation::FILTER) + ->set_is_impl_only(true); + } filters.Append(FilterOperation::CreateSepiaFilter(0.5f)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFilters(filters)); @@ -969,6 +1351,10 @@ void AssertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) { class LayerLayerTreeHostTest : public testing::Test { public: + LayerLayerTreeHostTest() { + layer_settings_.use_compositor_animation_timelines = true; + } + protected: LayerSettings layer_settings_; }; @@ -1150,12 +1536,16 @@ static bool AddTestAnimation(Layer* layer) { curve->AddKeyframe( FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.7f, nullptr)); scoped_ptr<Animation> animation = - Animation::Create(curve.Pass(), 0, 0, Animation::OPACITY); + Animation::Create(std::move(curve), 0, 0, Animation::OPACITY); - return layer->AddAnimation(animation.Pass()); + return layer->AddAnimation(std::move(animation)); } TEST_F(LayerLayerTreeHostTest, ShouldNotAddAnimationWithoutAnimationRegistrar) { + // This tests isn't needed in new use_compositor_animation_timelines mode. + if (layer_settings_.use_compositor_animation_timelines) + return; + scoped_refptr<Layer> layer = Layer::Create(layer_settings_); // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the @@ -1170,6 +1560,8 @@ TEST_F(LayerLayerTreeHostTest, ShouldNotAddAnimationWithoutAnimationRegistrar) { LayerTreeSettings settings; settings.accelerated_animation_enabled = false; + settings.use_compositor_animation_timelines = + layer_settings_.use_compositor_animation_timelines; LayerTreeHostFactory factory; scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(settings); layer_tree_host->SetRootLayer(layer); @@ -1271,11 +1663,11 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { // layer does not abort either one. scoped_ptr<CopyOutputRequest> request = CopyOutputRequest::CreateRequest( base::Bind(&ReceiveCopyOutputResult, &result_count)); - layer->RequestCopyOfOutput(request.Pass()); + layer->RequestCopyOfOutput(std::move(request)); EXPECT_EQ(0, result_count); request = CopyOutputRequest::CreateRequest( base::Bind(&ReceiveCopyOutputResult, &result_count)); - layer->RequestCopyOfOutput(request.Pass()); + layer->RequestCopyOfOutput(std::move(request)); EXPECT_EQ(0, result_count); // When the layer is destroyed, expect both requests to be aborted. @@ -1292,27 +1684,28 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { request = CopyOutputRequest::CreateRequest(base::Bind( &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source)); request->set_source(this); - layer->RequestCopyOfOutput(request.Pass()); + layer->RequestCopyOfOutput(std::move(request)); EXPECT_EQ(0, did_receive_first_result_from_this_source); // Make a request from a different source. int did_receive_result_from_different_source = 0; request = CopyOutputRequest::CreateRequest(base::Bind( &ReceiveCopyOutputResult, &did_receive_result_from_different_source)); request->set_source(reinterpret_cast<void*>(0xdeadbee0)); - layer->RequestCopyOfOutput(request.Pass()); + layer->RequestCopyOfOutput(std::move(request)); EXPECT_EQ(0, did_receive_result_from_different_source); // Make a request without specifying the source. int did_receive_result_from_anonymous_source = 0; request = CopyOutputRequest::CreateRequest(base::Bind( &ReceiveCopyOutputResult, &did_receive_result_from_anonymous_source)); - layer->RequestCopyOfOutput(request.Pass()); + layer->RequestCopyOfOutput(std::move(request)); EXPECT_EQ(0, did_receive_result_from_anonymous_source); // Make the second request from |this| source. int did_receive_second_result_from_this_source = 0; request = CopyOutputRequest::CreateRequest(base::Bind( &ReceiveCopyOutputResult, &did_receive_second_result_from_this_source)); request->set_source(this); - layer->RequestCopyOfOutput(request.Pass()); // First request to be aborted. + layer->RequestCopyOfOutput( + std::move(request)); // First request to be aborted. EXPECT_EQ(1, did_receive_first_result_from_this_source); EXPECT_EQ(0, did_receive_result_from_different_source); EXPECT_EQ(0, did_receive_result_from_anonymous_source); @@ -1347,5 +1740,398 @@ TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { Mock::VerifyAndClearExpectations(layer_tree_host_.get()); } +TEST_F(LayerTest, RecursiveHierarchySerialization) { + /* Testing serialization and deserialization of a tree that looks like this: + root + / \ + a b + \ + c + Layer c also has a mask layer and a replica layer. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_c_mask = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_c_replica = Layer::Create(LayerSettings()); + layer_src_root->AddChild(layer_src_a); + layer_src_root->AddChild(layer_src_b); + layer_src_b->AddChild(layer_src_c); + layer_src_c->SetMaskLayer(layer_src_c_mask.get()); + layer_src_c->SetReplicaLayer(layer_src_c_replica.get()); + + proto::LayerNode proto; + layer_src_root->ToLayerNodeProto(&proto); + + Layer::LayerIdMap empty_dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); + layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); + + EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); + EXPECT_EQ(nullptr, layer_dest_root->parent()); + ASSERT_EQ(2u, layer_dest_root->children().size()); + + scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); + EXPECT_EQ(0u, layer_dest_a->children().size()); + + scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + EXPECT_EQ(layer_src_root->id(), layer_dest_b->parent()->id()); + ASSERT_EQ(1u, layer_dest_b->children().size()); + + scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; + EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); + EXPECT_EQ(layer_src_b->id(), layer_dest_c->parent()->id()); + EXPECT_EQ(0u, layer_dest_c->children().size()); + EXPECT_EQ(layer_src_c_mask->id(), layer_dest_c->mask_layer()->id()); + EXPECT_EQ(layer_src_c_replica->id(), layer_dest_c->replica_layer()->id()); +} + +TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { + /* Testing serialization and deserialization of a tree that initially looks + like this: + root + / + a + The source tree is then updated by adding layer |b|: + root + / \ + a b + The deserialization should then re-use the Layers from last + deserialization. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); + layer_src_root->AddChild(layer_src_a); + + proto::LayerNode root_proto_1; + layer_src_root->ToLayerNodeProto(&root_proto_1); + + Layer::LayerIdMap dest_layer_map_1; + scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); + layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1); + + EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); + ASSERT_EQ(1u, layer_dest_root->children().size()); + scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id()); + + // Setup new destination layer map. + Layer::LayerIdMap dest_layer_map_2; + dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; + dest_layer_map_2[layer_dest_a_1->id()] = layer_dest_a_1; + + // Add Layer |b|. + scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); + layer_src_root->AddChild(layer_src_b); + + // Second serialization. + proto::LayerNode root_proto_2; + layer_src_root->ToLayerNodeProto(&root_proto_2); + + // Second deserialization. + layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2); + + EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); + ASSERT_EQ(2u, layer_dest_root->children().size()); + + scoped_refptr<Layer> layer_dest_a_2 = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a_2->id()); + EXPECT_EQ(layer_src_root->id(), layer_dest_a_2->parent()->id()); + EXPECT_EQ(0u, layer_dest_a_2->children().size()); + + scoped_refptr<Layer> layer_dest_b_2 = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_b->id(), layer_dest_b_2->id()); + EXPECT_EQ(layer_src_root->id(), layer_dest_b_2->parent()->id()); + EXPECT_EQ(0u, layer_dest_b_2->children().size()); + + // Layer |a| should be the same. + EXPECT_EQ(layer_dest_a_1.get(), layer_dest_a_2.get()); +} + +TEST_F(LayerTest, DeletingSubtreeDeletesLayers) { + /* Testing serialization and deserialization of a tree that initially + looks like this: + root + / \ + a b + \ + c + \ + d + Then the subtree rooted at node |b| is deleted in the next update. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); + layer_src_root->AddChild(layer_src_a); + layer_src_root->AddChild(layer_src_b); + layer_src_b->AddChild(layer_src_c); + layer_src_c->AddChild(layer_src_d); + + // Serialization 1. + proto::LayerNode proto1; + layer_src_root->ToLayerNodeProto(&proto1); + + // Deserialization 1. + Layer::LayerIdMap empty_dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); + layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map); + + EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); + ASSERT_EQ(2u, layer_dest_root->children().size()); + scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; + scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; + ASSERT_EQ(1u, layer_dest_b->children().size()); + scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; + ASSERT_EQ(1u, layer_dest_c->children().size()); + scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0]; + + // Delete the Layer |b| subtree. + layer_src_b->RemoveAllChildren(); + + // Serialization 2. + proto::LayerNode proto2; + layer_src_root->ToLayerNodeProto(&proto2); + + // Deserialization 2. + Layer::LayerIdMap dest_layer_map_2; + dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; + dest_layer_map_2[layer_dest_a->id()] = layer_dest_a; + dest_layer_map_2[layer_dest_b->id()] = layer_dest_b; + layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2); + + EXPECT_EQ(0u, layer_dest_a->children().size()); + EXPECT_EQ(0u, layer_dest_b->children().size()); +} + +TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { + scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_mask = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_replica = Layer::Create(LayerSettings()); + layer_src_root->SetMaskLayer(layer_src_mask.get()); + layer_src_root->SetReplicaLayer(layer_src_replica.get()); + + // Serialization 1. + proto::LayerNode proto1; + layer_src_root->ToLayerNodeProto(&proto1); + + // Deserialization 1. + Layer::LayerIdMap dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); + layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map); + + EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); + ASSERT_TRUE(layer_dest_root->mask_layer()); + ASSERT_TRUE(layer_dest_root->replica_layer()); + EXPECT_EQ(layer_src_root->mask_layer()->id(), + layer_dest_root->mask_layer()->id()); + // TODO(nyquist): Add test for is_mask_ when PictureLayer is supported. + EXPECT_EQ(layer_src_root->replica_layer()->id(), + layer_dest_root->replica_layer()->id()); + + // Store the newly constructed layer structure in the id map. + dest_layer_map[layer_dest_root->id()] = layer_dest_root; + dest_layer_map[layer_dest_root->mask_layer()->id()] = + layer_dest_root->mask_layer(); + dest_layer_map[layer_dest_root->replica_layer()->id()] = + layer_dest_root->replica_layer(); + + // Clear mask and replica layers. + layer_src_root->mask_layer()->RemoveFromParent(); + layer_src_root->replica_layer()->RemoveFromParent(); + + // Serialization 2. + proto::LayerNode proto2; + layer_src_root->ToLayerNodeProto(&proto2); + + // Deserialization 2. + layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map); + + EXPECT_EQ(nullptr, layer_dest_root->mask_layer()); + EXPECT_EQ(nullptr, layer_dest_root->replica_layer()); +} + +TEST_F(LayerTest, SimplePropertiesSerialization) { + /* Testing serialization of properties for a tree that looks like this: + root+ + / \ + a* b*+[mask:*,replica] + / \ + c d* + Layers marked with * have changed properties. + Layers marked with + have descendants with changed properties. + Layer b also has a mask layer and a replica layer. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); + layer_src_root->AddChild(layer_src_a); + layer_src_root->AddChild(layer_src_b); + layer_src_a->AddChild(layer_src_c); + layer_src_b->AddChild(layer_src_d); + layer_src_b->SetMaskLayer(layer_src_b_mask.get()); + layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); + + layer_src_a->SetNeedsPushProperties(); + layer_src_b->SetNeedsPushProperties(); + layer_src_b_mask->SetNeedsPushProperties(); + layer_src_d->SetNeedsPushProperties(); + + // Only layers with descendants that require pushing properties will + // return true from ToLayerPropertiesProto. + proto::LayerUpdate layer_update_root; + EXPECT_TRUE(layer_src_root->ToLayerPropertiesProto(&layer_update_root)); + proto::LayerUpdate layer_update_a; + EXPECT_FALSE(layer_src_a->ToLayerPropertiesProto(&layer_update_a)); + proto::LayerUpdate layer_update_b; + EXPECT_TRUE(layer_src_b->ToLayerPropertiesProto(&layer_update_b)); + proto::LayerUpdate layer_update_b_mask; + EXPECT_FALSE(layer_src_b_mask->ToLayerPropertiesProto(&layer_update_b_mask)); + proto::LayerUpdate layer_update_b_replica; + EXPECT_FALSE( + layer_src_b_replica->ToLayerPropertiesProto(&layer_update_b_replica)); + proto::LayerUpdate layer_update_c; + EXPECT_FALSE(layer_src_c->ToLayerPropertiesProto(&layer_update_c)); + proto::LayerUpdate layer_update_d; + EXPECT_FALSE(layer_src_d->ToLayerPropertiesProto(&layer_update_d)); + + // All flags for pushing properties should have been cleared. + EXPECT_FALSE(layer_src_root->needs_push_properties()); + EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_a->needs_push_properties()); + EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_b->needs_push_properties()); + EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); + EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); + EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_c->needs_push_properties()); + EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); + EXPECT_FALSE(layer_src_d->needs_push_properties()); + EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); + + // Only 5 of the layers should have been serialized. + ASSERT_EQ(1, layer_update_root.layers_size()); + EXPECT_EQ(layer_src_root->id(), layer_update_root.layers(0).id()); + proto::LayerProperties dest_root = layer_update_root.layers(0); + ASSERT_EQ(1, layer_update_a.layers_size()); + EXPECT_EQ(layer_src_a->id(), layer_update_a.layers(0).id()); + proto::LayerProperties dest_a = layer_update_a.layers(0); + ASSERT_EQ(1, layer_update_b.layers_size()); + EXPECT_EQ(layer_src_b->id(), layer_update_b.layers(0).id()); + proto::LayerProperties dest_b = layer_update_b.layers(0); + ASSERT_EQ(1, layer_update_b_mask.layers_size()); + EXPECT_EQ(layer_src_b_mask->id(), layer_update_b_mask.layers(0).id()); + proto::LayerProperties dest_b_mask = layer_update_b_mask.layers(0); + EXPECT_EQ(0, layer_update_b_replica.layers_size()); + EXPECT_EQ(0, layer_update_c.layers_size()); + ASSERT_EQ(1, layer_update_d.layers_size()); + EXPECT_EQ(layer_src_d->id(), layer_update_d.layers(0).id()); + proto::LayerProperties dest_d = layer_update_d.layers(0); + + // Ensure the properties and dependants metadata is correctly serialized. + EXPECT_FALSE(dest_root.needs_push_properties()); + EXPECT_EQ(2, dest_root.num_dependents_need_push_properties()); + EXPECT_FALSE(dest_root.has_base()); + + EXPECT_TRUE(dest_a.needs_push_properties()); + EXPECT_EQ(0, dest_a.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_a.has_base()); + + EXPECT_TRUE(dest_b.needs_push_properties()); + EXPECT_EQ(2, dest_b.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_b.has_base()); + + EXPECT_TRUE(dest_d.needs_push_properties()); + EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_d.has_base()); + + EXPECT_TRUE(dest_b_mask.needs_push_properties()); + EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); + EXPECT_TRUE(dest_b_mask.has_base()); +} + +TEST_F(LayerSerializationTest, SimplePropertiesDeserialization) { + scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + layer->SetLayerTreeHost(layer_tree_host_.get()); + proto::LayerProperties properties; + properties.set_id(layer->id()); + + properties.set_needs_push_properties(true); + properties.set_num_dependents_need_push_properties(2); + properties.mutable_base(); + layer->FromLayerPropertiesProto(properties); + EXPECT_TRUE(layer->needs_push_properties()); + EXPECT_TRUE(layer->descendant_needs_push_properties()); + + properties.set_needs_push_properties(false); + properties.mutable_base()->Clear(); + layer->FromLayerPropertiesProto(properties); + EXPECT_FALSE(layer->needs_push_properties()); + EXPECT_TRUE(layer->descendant_needs_push_properties()); + + properties.set_num_dependents_need_push_properties(0); + layer->FromLayerPropertiesProto(properties); + EXPECT_FALSE(layer->needs_push_properties()); + EXPECT_FALSE(layer->descendant_needs_push_properties()); + + properties.set_needs_push_properties(true); + properties.mutable_base(); + layer->FromLayerPropertiesProto(properties); + EXPECT_TRUE(layer->needs_push_properties()); + EXPECT_FALSE(layer->descendant_needs_push_properties()); + + layer->SetLayerTreeHost(nullptr); +} + +TEST_F(LayerSerializationTest, NoMembersChanged) { + RunNoMembersChangedTest(); +} + +TEST_F(LayerSerializationTest, ArbitraryMembersChanged) { + RunArbitraryMembersChangedTest(); +} + +TEST_F(LayerSerializationTest, AllMembersChanged) { + RunAllMembersChangedTest(); +} + +TEST_F(LayerSerializationTest, ScrollAndClipLayers) { + RunScrollAndClipLayersTest(); +} + +TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { + scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); + scoped_ptr<LayerImpl> impl_layer = + LayerImpl::Create(host_impl_.active_tree(), 1); + + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); + + test_layer->SetElementId(2); + test_layer->SetMutableProperties(kMutablePropertyTransform); + + EXPECT_EQ(0lu, impl_layer->element_id()); + EXPECT_EQ(kMutablePropertyNone, impl_layer->mutable_properties()); + + test_layer->PushPropertiesTo(impl_layer.get()); + + EXPECT_EQ(2lu, impl_layer->element_id()); + EXPECT_EQ(kMutablePropertyTransform, impl_layer->mutable_properties()); +} + } // namespace } // namespace cc diff --git a/chromium/cc/layers/layer_utils_unittest.cc b/chromium/cc/layers/layer_utils_unittest.cc index 534a691e47b..607b06cb9d0 100644 --- a/chromium/cc/layers/layer_utils_unittest.cc +++ b/chromium/cc/layers/layer_utils_unittest.cc @@ -4,10 +4,12 @@ #include "cc/layers/layer_utils.h" +#include "cc/animation/animation_host.h" +#include "cc/animation/animation_id_provider.h" #include "cc/animation/transform_operations.h" #include "cc/layers/layer_impl.h" #include "cc/test/animation_test_common.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_task_graph_runner.h" @@ -22,17 +24,35 @@ float diagonal(float width, float height) { return std::sqrt(width * width + height * height); } +class LayerTreeSettingsForAnimationBoundsTest : public LayerTreeSettings { + public: + LayerTreeSettingsForAnimationBoundsTest() { + use_compositor_animation_timelines = true; + } +}; + class LayerUtilsGetAnimationBoundsTest : public testing::Test { public: LayerUtilsGetAnimationBoundsTest() - : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), + : host_impl_(LayerTreeSettingsForAnimationBoundsTest(), + &task_runner_provider_, + &shared_bitmap_manager_, + &task_graph_runner_), root_(CreateThreeNodeTree(&host_impl_)), - parent_(root_->children()[0]), - child_(parent_->children()[0]) {} + parent_(root_->children()[0].get()), + child_(parent_->children()[0].get()) { + if (host_impl_.settings().use_compositor_animation_timelines) { + timeline_ = + AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); + host_impl_.animation_host()->AddAnimationTimeline(timeline_); + } + } LayerImpl* root() { return root_.get(); } LayerImpl* parent() { return parent_; } LayerImpl* child() { return child_; } + scoped_refptr<AnimationTimeline> timeline() { return timeline_; } + FakeLayerTreeHostImpl& host_impl() { return host_impl_; } private: static scoped_ptr<LayerImpl> CreateThreeNodeTree( @@ -41,16 +61,17 @@ class LayerUtilsGetAnimationBoundsTest : public testing::Test { root->AddChild(LayerImpl::Create(host_impl->active_tree(), 2)); root->children()[0]->AddChild( LayerImpl::Create(host_impl->active_tree(), 3)); - return root.Pass(); + return root; } - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeLayerTreeHostImpl host_impl_; scoped_ptr<LayerImpl> root_; LayerImpl* parent_; LayerImpl* child_; + scoped_refptr<AnimationTimeline> timeline_; }; TEST_F(LayerUtilsGetAnimationBoundsTest, ScaleRoot) { @@ -60,7 +81,12 @@ TEST_F(LayerUtilsGetAnimationBoundsTest, ScaleRoot) { start.AppendScale(1.f, 1.f, 1.f); TransformOperations end; end.AppendScale(2.f, 2.f, 1.f); - AddAnimatedTransformToLayer(root(), duration, start, end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(root()->id(), timeline(), duration, + start, end); + } else { + AddAnimatedTransformToLayer(root(), duration, start, end); + } root()->SetPosition(gfx::PointF()); parent()->SetPosition(gfx::PointF()); @@ -85,7 +111,12 @@ TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateParentLayer) { start.AppendTranslate(0.f, 0.f, 0.f); TransformOperations end; end.AppendTranslate(50.f, 50.f, 0.f); - AddAnimatedTransformToLayer(parent(), duration, start, end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(parent()->id(), timeline(), duration, + start, end); + } else { + AddAnimatedTransformToLayer(parent(), duration, start, end); + } parent()->SetBounds(gfx::Size(350, 200)); @@ -108,7 +139,12 @@ TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateChildLayer) { start.AppendTranslate(0.f, 0.f, 0.f); TransformOperations end; end.AppendTranslate(50.f, 50.f, 0.f); - AddAnimatedTransformToLayer(child(), duration, start, end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(child()->id(), timeline(), duration, + start, end); + } else { + AddAnimatedTransformToLayer(child(), duration, start, end); + } parent()->SetBounds(gfx::Size(350, 200)); @@ -131,11 +167,21 @@ TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateBothLayers) { start.AppendTranslate(0.f, 0.f, 0.f); TransformOperations child_end; child_end.AppendTranslate(50.f, 0.f, 0.f); - AddAnimatedTransformToLayer(parent(), duration, start, child_end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(parent()->id(), timeline(), duration, + start, child_end); + } else { + AddAnimatedTransformToLayer(parent(), duration, start, child_end); + } TransformOperations grand_child_end; grand_child_end.AppendTranslate(0.f, 50.f, 0.f); - AddAnimatedTransformToLayer(child(), duration, start, grand_child_end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(child()->id(), timeline(), duration, + start, grand_child_end); + } else { + AddAnimatedTransformToLayer(child(), duration, start, grand_child_end); + } parent()->SetBounds(gfx::Size(350, 200)); @@ -158,7 +204,12 @@ TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXNoPerspective) { start.AppendRotate(1.f, 0.f, 0.f, 0.f); TransformOperations end; end.AppendRotate(1.f, 0.f, 0.f, 90.f); - AddAnimatedTransformToLayer(child(), duration, start, end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(child()->id(), timeline(), duration, + start, end); + } else { + AddAnimatedTransformToLayer(child(), duration, start, end); + } parent()->SetBounds(gfx::Size(350, 200)); @@ -184,7 +235,12 @@ TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspective) { start.AppendRotate(1.f, 0.f, 0.f, 0.f); TransformOperations end; end.AppendRotate(1.f, 0.f, 0.f, 90.f); - AddAnimatedTransformToLayer(child(), duration, start, end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(child()->id(), timeline(), duration, + start, end); + } else { + AddAnimatedTransformToLayer(child(), duration, start, end); + } // Make the anchor point not the default 0.5 value and line up with the // child center to make the math easier. @@ -218,7 +274,12 @@ TEST_F(LayerUtilsGetAnimationBoundsTest, RotateZ) { start.AppendRotate(0.f, 0.f, 1.f, 0.f); TransformOperations end; end.AppendRotate(0.f, 0.f, 1.f, 90.f); - AddAnimatedTransformToLayer(child(), duration, start, end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(child()->id(), timeline(), duration, + start, end); + } else { + AddAnimatedTransformToLayer(child(), duration, start, end); + } parent()->SetBounds(gfx::Size(350, 200)); @@ -250,7 +311,12 @@ TEST_F(LayerUtilsGetAnimationBoundsTest, MismatchedTransforms) { start.AppendTranslate(5, 6, 7); TransformOperations end; end.AppendRotate(0.f, 0.f, 1.f, 90.f); - AddAnimatedTransformToLayer(child(), duration, start, end); + if (host_impl().settings().use_compositor_animation_timelines) { + AddAnimatedTransformToLayerWithPlayer(child()->id(), timeline(), duration, + start, end); + } else { + AddAnimatedTransformToLayer(child(), duration, start, end); + } parent()->SetBounds(gfx::Size(350, 200)); diff --git a/chromium/cc/layers/nine_patch_layer.cc b/chromium/cc/layers/nine_patch_layer.cc index 575090cad9e..26bb58433e2 100644 --- a/chromium/cc/layers/nine_patch_layer.cc +++ b/chromium/cc/layers/nine_patch_layer.cc @@ -4,6 +4,7 @@ #include "cc/layers/nine_patch_layer.h" +#include "base/trace_event/trace_event.h" #include "cc/layers/nine_patch_layer_impl.h" #include "cc/resources/scoped_ui_resource.h" #include "cc/resources/ui_resource_bitmap.h" @@ -52,6 +53,7 @@ void NinePatchLayer::SetFillCenter(bool fill_center) { void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { UIResourceLayer::PushPropertiesTo(layer); + TRACE_EVENT0("cc", "NinePatchLayer::PushPropertiesTo"); NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); if (!ui_resource_holder_) { diff --git a/chromium/cc/layers/nine_patch_layer.h b/chromium/cc/layers/nine_patch_layer.h index 714a407ddb0..ff766634b19 100644 --- a/chromium/cc/layers/nine_patch_layer.h +++ b/chromium/cc/layers/nine_patch_layer.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_NINE_PATCH_LAYER_H_ #define CC_LAYERS_NINE_PATCH_LAYER_H_ +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" diff --git a/chromium/cc/layers/nine_patch_layer_impl.h b/chromium/cc/layers/nine_patch_layer_impl.h index 948758a876a..28721b32757 100644 --- a/chromium/cc/layers/nine_patch_layer_impl.h +++ b/chromium/cc/layers/nine_patch_layer_impl.h @@ -7,6 +7,7 @@ #include <string> +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" #include "cc/layers/ui_resource_layer_impl.h" diff --git a/chromium/cc/layers/nine_patch_layer_impl_unittest.cc b/chromium/cc/layers/nine_patch_layer_impl_unittest.cc index 3405bc545cf..96778724285 100644 --- a/chromium/cc/layers/nine_patch_layer_impl_unittest.cc +++ b/chromium/cc/layers/nine_patch_layer_impl_unittest.cc @@ -2,13 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stddef.h> + #include "base/containers/hash_tables.h" #include "cc/layers/append_quads_data.h" #include "cc/layers/nine_patch_layer_impl.h" #include "cc/quads/texture_draw_quad.h" #include "cc/resources/ui_resource_bitmap.h" #include "cc/resources/ui_resource_client.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_ui_resource_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" @@ -43,19 +45,20 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, layer_size.width() - border.width(), layer_size.height() - border.height()); - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); - FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, - &task_graph_runner); + FakeUIResourceLayerTreeHostImpl host_impl( + &task_runner_provider, &shared_bitmap_manager, &task_graph_runner); + host_impl.SetVisible(true); host_impl.InitializeRenderer(output_surface.get()); scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::Create(host_impl.active_tree(), 1); layer->draw_properties().visible_layer_rect = visible_layer_rect; layer->SetBounds(layer_size); - layer->SetHasRenderSurface(true); + layer->SetForceRenderSurface(true); layer->draw_properties().render_target = layer.get(); UIResourceId uid = 1; diff --git a/chromium/cc/layers/nine_patch_layer_unittest.cc b/chromium/cc/layers/nine_patch_layer_unittest.cc index 75af3be073e..5f14c091060 100644 --- a/chromium/cc/layers/nine_patch_layer_unittest.cc +++ b/chromium/cc/layers/nine_patch_layer_unittest.cc @@ -4,6 +4,7 @@ #include "cc/layers/nine_patch_layer.h" +#include "cc/layers/layer_settings.h" #include "cc/resources/resource_provider.h" #include "cc/resources/scoped_ui_resource.h" #include "cc/test/fake_layer_tree_host.h" diff --git a/chromium/cc/layers/painted_scrollbar_layer.cc b/chromium/cc/layers/painted_scrollbar_layer.cc index 6fd58623fbf..aabde35b670 100644 --- a/chromium/cc/layers/painted_scrollbar_layer.cc +++ b/chromium/cc/layers/painted_scrollbar_layer.cc @@ -7,8 +7,6 @@ #include <algorithm> #include "base/auto_reset.h" -#include "base/basictypes.h" -#include "base/trace_event/trace_event.h" #include "cc/base/math_util.h" #include "cc/layers/painted_scrollbar_layer_impl.h" #include "cc/resources/ui_resource_bitmap.h" @@ -35,22 +33,22 @@ scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create( const LayerSettings& settings, scoped_ptr<Scrollbar> scrollbar, int scroll_layer_id) { - return make_scoped_refptr( - new PaintedScrollbarLayer(settings, scrollbar.Pass(), scroll_layer_id)); + return make_scoped_refptr(new PaintedScrollbarLayer( + settings, std::move(scrollbar), scroll_layer_id)); } PaintedScrollbarLayer::PaintedScrollbarLayer(const LayerSettings& settings, scoped_ptr<Scrollbar> scrollbar, int scroll_layer_id) : Layer(settings), - scrollbar_(scrollbar.Pass()), + scrollbar_(std::move(scrollbar)), scroll_layer_id_(scroll_layer_id), - clip_layer_id_(Layer::INVALID_ID), internal_contents_scale_(1.f), thumb_thickness_(scrollbar_->ThumbThickness()), thumb_length_(scrollbar_->ThumbLength()), is_overlay_(scrollbar_->IsOverlay()), - has_thumb_(scrollbar_->HasThumb()) { + has_thumb_(scrollbar_->HasThumb()), + thumb_opacity_(scrollbar_->ThumbOpacity()) { if (!scrollbar_->IsOverlay()) SetShouldScrollOnMainThread(true); } @@ -69,14 +67,6 @@ void PaintedScrollbarLayer::SetScrollLayer(int layer_id) { SetNeedsFullTreeSync(); } -void PaintedScrollbarLayer::SetClipLayer(int layer_id) { - if (layer_id == clip_layer_id_) - return; - - clip_layer_id_ = layer_id; - SetNeedsFullTreeSync(); -} - bool PaintedScrollbarLayer::OpacityCanAnimateOnImplThread() const { return scrollbar_->IsOverlay(); } @@ -108,11 +98,10 @@ float PaintedScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { Layer::PushPropertiesTo(layer); - PushScrollClipPropertiesTo(layer); - PaintedScrollbarLayerImpl* scrollbar_layer = static_cast<PaintedScrollbarLayerImpl*>(layer); + scrollbar_layer->SetScrollLayerId(scroll_layer_id_); scrollbar_layer->set_internal_contents_scale_and_bounds( internal_contents_scale_, internal_content_bounds_); @@ -137,6 +126,8 @@ void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { else scrollbar_layer->set_thumb_ui_resource_id(0); + scrollbar_layer->set_thumb_opacity(thumb_opacity_); + scrollbar_layer->set_is_overlay_scrollbar(is_overlay_); } @@ -144,14 +135,6 @@ ScrollbarLayerInterface* PaintedScrollbarLayer::ToScrollbarLayer() { return this; } -void PaintedScrollbarLayer::PushScrollClipPropertiesTo(LayerImpl* layer) { - PaintedScrollbarLayerImpl* scrollbar_layer = - static_cast<PaintedScrollbarLayerImpl*>(layer); - - scrollbar_layer->SetScrollLayerAndClipLayerByIds(scroll_layer_id_, - clip_layer_id_); -} - void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { // When the LTH is set to null or has changed, then this layer should remove // all of its associated resources. @@ -262,17 +245,24 @@ bool PaintedScrollbarLayer::Update() { if (update_rect_.IsEmpty() && track_resource_) return updated; - track_resource_ = ScopedUIResource::Create( - layer_tree_host(), - RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); + if (!track_resource_ || scrollbar_->NeedsPaintPart(TRACK)) { + track_resource_ = ScopedUIResource::Create( + layer_tree_host(), + RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); + } gfx::Rect thumb_layer_rect = OriginThumbRect(); gfx::Rect scaled_thumb_rect = ScrollbarLayerRectToContentRect(thumb_layer_rect); if (has_thumb_ && !scaled_thumb_rect.IsEmpty()) { - thumb_resource_ = ScopedUIResource::Create( - layer_tree_host(), - RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB)); + if (!thumb_resource_ || scrollbar_->NeedsPaintPart(THUMB) || + scaled_thumb_rect.size() != + thumb_resource_->GetBitmap(0, false).GetSize()) { + thumb_resource_ = ScopedUIResource::Create( + layer_tree_host(), + RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB)); + } + thumb_opacity_ = scrollbar_->ThumbOpacity(); } // UI resources changed so push properties is needed. diff --git a/chromium/cc/layers/painted_scrollbar_layer.h b/chromium/cc/layers/painted_scrollbar_layer.h index 3e376b1959e..27dc2c3dd83 100644 --- a/chromium/cc/layers/painted_scrollbar_layer.h +++ b/chromium/cc/layers/painted_scrollbar_layer.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ #define CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/input/scrollbar.h" #include "cc/layers/layer.h" @@ -31,7 +32,6 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerInterface, // ScrollbarLayerInterface int ScrollLayerId() const override; void SetScrollLayer(int layer_id) override; - void SetClipLayer(int layer_id) override; ScrollbarOrientation orientation() const override; @@ -39,7 +39,6 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerInterface, bool Update() override; void SetLayerTreeHost(LayerTreeHost* host) override; void PushPropertiesTo(LayerImpl* layer) override; - void PushScrollClipPropertiesTo(LayerImpl* layer) override; const gfx::Size& internal_content_bounds() const { return internal_content_bounds_; @@ -83,7 +82,6 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerInterface, scoped_ptr<Scrollbar> scrollbar_; int scroll_layer_id_; - int clip_layer_id_; float internal_contents_scale_; gfx::Size internal_content_bounds_; @@ -100,6 +98,8 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerInterface, scoped_ptr<ScopedUIResource> track_resource_; scoped_ptr<ScopedUIResource> thumb_resource_; + float thumb_opacity_; + DISALLOW_COPY_AND_ASSIGN(PaintedScrollbarLayer); }; diff --git a/chromium/cc/layers/painted_scrollbar_layer_impl.cc b/chromium/cc/layers/painted_scrollbar_layer_impl.cc index 0b5b5801dd6..229e7f29c2a 100644 --- a/chromium/cc/layers/painted_scrollbar_layer_impl.cc +++ b/chromium/cc/layers/painted_scrollbar_layer_impl.cc @@ -32,12 +32,12 @@ PaintedScrollbarLayerImpl::PaintedScrollbarLayerImpl( : ScrollbarLayerImplBase(tree_impl, id, orientation, false, false), track_ui_resource_id_(0), thumb_ui_resource_id_(0), + thumb_opacity_(1.f), internal_contents_scale_(1.f), thumb_thickness_(0), thumb_length_(0), track_start_(0), - track_length_(0) { -} + track_length_(0) {} PaintedScrollbarLayerImpl::~PaintedScrollbarLayerImpl() {} @@ -62,6 +62,8 @@ void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_); scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_); + + scrollbar_layer->set_thumb_opacity(thumb_opacity_); } bool PaintedScrollbarLayerImpl::WillDraw(DrawMode draw_mode, @@ -102,7 +104,8 @@ void PaintedScrollbarLayerImpl::AppendQuads( if (thumb_resource_id && !visible_thumb_quad_rect.IsEmpty()) { gfx::Rect opaque_rect; - const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; + const float opacity[] = {thumb_opacity_, thumb_opacity_, thumb_opacity_, + thumb_opacity_}; TextureDrawQuad* quad = render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); quad->SetNew(shared_quad_state, scaled_thumb_quad_rect, opaque_rect, diff --git a/chromium/cc/layers/painted_scrollbar_layer_impl.h b/chromium/cc/layers/painted_scrollbar_layer_impl.h index 65d28aea050..8ea06ab5d8c 100644 --- a/chromium/cc/layers/painted_scrollbar_layer_impl.h +++ b/chromium/cc/layers/painted_scrollbar_layer_impl.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_PAINTED_SCROLLBAR_LAYER_IMPL_H_ #define CC_LAYERS_PAINTED_SCROLLBAR_LAYER_IMPL_H_ +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/input/scrollbar.h" #include "cc/layers/scrollbar_layer_impl_base.h" @@ -45,6 +46,8 @@ class CC_EXPORT PaintedScrollbarLayerImpl : public ScrollbarLayerImplBase { thumb_ui_resource_id_ = uid; } + void set_thumb_opacity(float opacity) { thumb_opacity_ = opacity; } + void set_internal_contents_scale_and_bounds(float content_scale, const gfx::Size& content_bounds) { internal_contents_scale_ = content_scale; @@ -69,6 +72,8 @@ class CC_EXPORT PaintedScrollbarLayerImpl : public ScrollbarLayerImplBase { UIResourceId track_ui_resource_id_; UIResourceId thumb_ui_resource_id_; + float thumb_opacity_; + float internal_contents_scale_; gfx::Size internal_content_bounds_; diff --git a/chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc b/chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc index eac32b67efa..4bc3f066af7 100644 --- a/chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc +++ b/chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc @@ -4,7 +4,10 @@ #include "cc/layers/painted_scrollbar_layer_impl.h" +#include <stddef.h> + #include "cc/quads/draw_quad.h" +#include "cc/quads/texture_draw_quad.h" #include "cc/test/layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" @@ -16,6 +19,7 @@ TEST(PaintedScrollbarLayerImplTest, Occlusion) { float scale = 2.f; gfx::Size scaled_layer_size(20, 2000); gfx::Size viewport_size(1000, 1000); + float thumb_opacity = 0.2f; LayerTestCommon::LayerImplTest impl; @@ -46,10 +50,11 @@ TEST(PaintedScrollbarLayerImplTest, Occlusion) { scrollbar_layer_impl->SetThumbLength(500); scrollbar_layer_impl->SetTrackLength(layer_size.height()); scrollbar_layer_impl->SetCurrentPos(100.f / 4); - scrollbar_layer_impl->SetMaximum(100); - scrollbar_layer_impl->SetVisibleToTotalLengthRatio(1.f / 2); + scrollbar_layer_impl->SetClipLayerLength(100.f); + scrollbar_layer_impl->SetScrollLayerLength(200.f); scrollbar_layer_impl->set_track_ui_resource_id(track_uid); scrollbar_layer_impl->set_thumb_ui_resource_id(thumb_uid); + scrollbar_layer_impl->set_thumb_opacity(thumb_opacity); impl.CalcDrawProps(viewport_size); @@ -71,8 +76,16 @@ TEST(PaintedScrollbarLayerImplTest, Occlusion) { // Note: this is also testing that the thumb and track are both // scaled by the internal contents scale. It's not occlusion-related // but is easy to verify here. - const DrawQuad* thumb_quad = impl.quad_list().ElementAt(0); - const DrawQuad* track_quad = impl.quad_list().ElementAt(1); + const DrawQuad* thumb_draw_quad = impl.quad_list().ElementAt(0); + const DrawQuad* track_draw_quad = impl.quad_list().ElementAt(1); + + EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, thumb_draw_quad->material); + EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, track_draw_quad->material); + + const TextureDrawQuad* thumb_quad = + TextureDrawQuad::MaterialCast(thumb_draw_quad); + const TextureDrawQuad* track_quad = + TextureDrawQuad::MaterialCast(track_draw_quad); gfx::Rect scaled_thumb_rect = gfx::ScaleToEnclosingRect(thumb_rect, scale); EXPECT_EQ(track_quad->rect.ToString(), @@ -84,6 +97,12 @@ TEST(PaintedScrollbarLayerImplTest, Occlusion) { EXPECT_EQ(thumb_quad->rect.ToString(), scaled_thumb_rect.ToString()); EXPECT_EQ(thumb_quad->visible_rect.ToString(), scaled_thumb_rect.ToString()); + EXPECT_EQ(thumb_quad->visible_rect.ToString(), + scaled_thumb_rect.ToString()); + for (size_t i = 0; i < 4; ++i) { + EXPECT_EQ(thumb_opacity, thumb_quad->vertex_opacity[i]); + EXPECT_EQ(1.f, track_quad->vertex_opacity[i]); + } } { diff --git a/chromium/cc/layers/painted_scrollbar_layer_unittest.cc b/chromium/cc/layers/painted_scrollbar_layer_unittest.cc new file mode 100644 index 00000000000..d170e8eab2c --- /dev/null +++ b/chromium/cc/layers/painted_scrollbar_layer_unittest.cc @@ -0,0 +1,87 @@ +// 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 "cc/layers/painted_scrollbar_layer.h" + +#include "cc/layers/layer_settings.h" +#include "cc/test/fake_layer_tree_host.h" +#include "cc/test/fake_layer_tree_host_client.h" +#include "cc/test/fake_scrollbar.h" +#include "cc/test/test_task_graph_runner.h" +#include "testing/gmock/include/gmock/gmock.h" + +using ::testing::Mock; +using ::testing::_; + +namespace cc { + +namespace { + +class MockScrollbar : public FakeScrollbar { + public: + MockScrollbar() : FakeScrollbar(true, true, true) {} + MOCK_METHOD3(PaintPart, + void(SkCanvas* canvas, + ScrollbarPart part, + const gfx::Rect& content_rect)); +}; + +TEST(PaintedScrollbarLayerTest, NeedsPaint) { + FakeLayerTreeHostClient fake_client_(FakeLayerTreeHostClient::DIRECT_3D); + TestTaskGraphRunner task_graph_runner_; + scoped_ptr<FakeLayerTreeHost> layer_tree_host_; + LayerSettings layer_settings_; + + layer_tree_host_ = + FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_); + RendererCapabilities renderer_capabilities; + renderer_capabilities.max_texture_size = 2048; + layer_tree_host_->set_renderer_capabilities(renderer_capabilities); + + MockScrollbar* scrollbar = new MockScrollbar(); + scoped_refptr<PaintedScrollbarLayer> scrollbar_layer = + PaintedScrollbarLayer::Create(layer_settings_, + scoped_ptr<Scrollbar>(scrollbar), 1); + + scrollbar_layer->SetIsDrawable(true); + scrollbar_layer->SetBounds(gfx::Size(100, 100)); + + layer_tree_host_->SetRootLayer(scrollbar_layer); + EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); + scrollbar_layer->SavePaintProperties(); + + // Request no paint, but expect them to be painted because they have not + // yet been initialized. + scrollbar->set_needs_paint_thumb(false); + scrollbar->set_needs_paint_track(false); + EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(1); + EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(1); + scrollbar_layer->Update(); + Mock::VerifyAndClearExpectations(scrollbar); + + // The next update will paint nothing because the first update caused a paint. + EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(0); + EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(0); + scrollbar_layer->Update(); + Mock::VerifyAndClearExpectations(scrollbar); + + // Enable the thumb. + EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(1); + EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(0); + scrollbar->set_needs_paint_thumb(true); + scrollbar->set_needs_paint_track(false); + scrollbar_layer->Update(); + Mock::VerifyAndClearExpectations(scrollbar); + + // Enable the track. + EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(0); + EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(1); + scrollbar->set_needs_paint_thumb(false); + scrollbar->set_needs_paint_track(true); + scrollbar_layer->Update(); + Mock::VerifyAndClearExpectations(scrollbar); +} + +} // namespace +} // namespace cc diff --git a/chromium/cc/layers/performance_properties.h b/chromium/cc/layers/performance_properties.h new file mode 100644 index 00000000000..5d1f4462d24 --- /dev/null +++ b/chromium/cc/layers/performance_properties.h @@ -0,0 +1,27 @@ +// 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 CC_LAYERS_PERFORMANCE_PROPERTIES_H_ +#define CC_LAYERS_PERFORMANCE_PROPERTIES_H_ + +#include "ui/gfx/transform.h" + +namespace cc { + +// Container for properties used to measure performance +template <typename LayerType> +struct CC_EXPORT PerformanceProperties { + PerformanceProperties() + : num_fixed_point_hits(0), translation_from_last_frame(0.f) {} + + // This value stores the numer of times a layer has hit a fixed point + // during commit. It is used to detect jitter in layers. + int num_fixed_point_hits; + float translation_from_last_frame; + gfx::Transform last_commit_screen_space_transform; +}; + +} // namespace cc + +#endif // CC_LAYERS_PERFORMANCE_PROPERTIES_H_ diff --git a/chromium/cc/layers/picture_image_layer.cc b/chromium/cc/layers/picture_image_layer.cc index ee129330b3e..b5a55c237d0 100644 --- a/chromium/cc/layers/picture_image_layer.cc +++ b/chromium/cc/layers/picture_image_layer.cc @@ -4,6 +4,8 @@ #include "cc/layers/picture_image_layer.h" +#include <stddef.h> + #include "cc/layers/picture_image_layer_impl.h" #include "cc/playback/display_item_list_settings.h" #include "cc/playback/drawing_display_item.h" @@ -44,19 +46,32 @@ void PictureImageLayer::SetImage(skia::RefPtr<const SkImage> image) { if (image_.get() == image.get()) return; - image_ = image.Pass(); + image_ = std::move(image); UpdateDrawsContent(HasDrawableContent()); SetNeedsDisplay(); } -void PictureImageLayer::PaintContents( - SkCanvas* canvas, - const gfx::Rect& clip, +gfx::Rect PictureImageLayer::PaintableRegion() { + return gfx::Rect(bounds()); +} + +scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList( ContentLayerClient::PaintingControlSetting painting_control) { DCHECK(image_); DCHECK_GT(image_->width(), 0); DCHECK_GT(image_->height(), 0); + // Picture image layers can be used with GatherPixelRefs, so cached SkPictures + // are currently required. + DisplayItemListSettings settings; + settings.use_cached_picture = true; + scoped_refptr<DisplayItemList> display_list = + DisplayItemList::Create(PaintableRegion(), settings); + + SkPictureRecorder recorder; + SkCanvas* canvas = + recorder.beginRecording(gfx::RectToSkRect(PaintableRegion())); + SkScalar content_to_layer_scale_x = SkFloatToScalar(static_cast<float>(bounds().width()) / image_->width()); SkScalar content_to_layer_scale_y = @@ -67,26 +82,11 @@ void PictureImageLayer::PaintContents( // to the root canvas, this draw must use the kSrcOver_Mode so that // transparent images blend correctly. canvas->drawImage(image_.get(), 0, 0); -} - -scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList( - const gfx::Rect& clip, - ContentLayerClient::PaintingControlSetting painting_control) { - // Picture image layers can be used with GatherPixelRefs, so cached SkPictures - // are currently required. - DisplayItemListSettings settings; - settings.use_cached_picture = true; - scoped_refptr<DisplayItemList> display_list = - DisplayItemList::Create(clip, settings); - - SkPictureRecorder recorder; - SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(clip)); - PaintContents(canvas, clip, painting_control); skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecordingAsPicture()); - auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); - item->SetNew(picture.Pass()); + display_list->CreateAndAppendItem<DrawingDisplayItem>(PaintableRegion(), + std::move(picture)); display_list->Finalize(); return display_list; diff --git a/chromium/cc/layers/picture_image_layer.h b/chromium/cc/layers/picture_image_layer.h index df3068683c3..fd3c1a22d9a 100644 --- a/chromium/cc/layers/picture_image_layer.h +++ b/chromium/cc/layers/picture_image_layer.h @@ -5,6 +5,9 @@ #ifndef CC_LAYERS_PICTURE_IMAGE_LAYER_H_ #define CC_LAYERS_PICTURE_IMAGE_LAYER_H_ +#include <stddef.h> + +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/content_layer_client.h" #include "cc/layers/picture_layer.h" @@ -24,13 +27,10 @@ class CC_EXPORT PictureImageLayer : public PictureLayer, ContentLayerClient { // Layer implementation. scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; + gfx::Rect PaintableRegion() override; + // ContentLayerClient implementation. - void PaintContents( - SkCanvas* canvas, - const gfx::Rect& clip, - ContentLayerClient::PaintingControlSetting painting_control) override; scoped_refptr<DisplayItemList> PaintContentsToDisplayList( - const gfx::Rect& clip, ContentLayerClient::PaintingControlSetting painting_control) override; bool FillsBoundsCompletely() const override; size_t GetApproximateUnsharedMemoryUsage() const override; diff --git a/chromium/cc/layers/picture_image_layer_impl.h b/chromium/cc/layers/picture_image_layer_impl.h index f478951592f..759606a2f45 100644 --- a/chromium/cc/layers/picture_image_layer_impl.h +++ b/chromium/cc/layers/picture_image_layer_impl.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_PICTURE_IMAGE_LAYER_IMPL_H_ #define CC_LAYERS_PICTURE_IMAGE_LAYER_IMPL_H_ +#include "base/macros.h" #include "cc/layers/picture_layer_impl.h" namespace cc { diff --git a/chromium/cc/layers/picture_image_layer_impl_unittest.cc b/chromium/cc/layers/picture_image_layer_impl_unittest.cc index 8d36095e0f3..53b0061b05c 100644 --- a/chromium/cc/layers/picture_image_layer_impl_unittest.cc +++ b/chromium/cc/layers/picture_image_layer_impl_unittest.cc @@ -8,7 +8,7 @@ #include "cc/layers/append_quads_data.h" #include "cc/quads/draw_quad.h" #include "cc/test/fake_display_list_raster_source.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" #include "cc/test/test_shared_bitmap_manager.h" @@ -24,6 +24,11 @@ class TestablePictureImageLayerImpl : public PictureImageLayerImpl { public: TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) : PictureImageLayerImpl(tree_impl, id, false) {} + + scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override { + return make_scoped_ptr(new TestablePictureImageLayerImpl(tree_impl, id())); + } + using PictureLayerImpl::UpdateIdealScales; using PictureLayerImpl::MaximumTilingContentsScale; @@ -42,13 +47,14 @@ class PictureLayerImplImageTestSettings : public LayerTreeSettings { class PictureImageLayerImplTest : public testing::Test { public: PictureImageLayerImplTest() - : proxy_(base::ThreadTaskRunnerHandle::Get()), + : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()), output_surface_(FakeOutputSurface::Create3d()), host_impl_(PictureLayerImplImageTestSettings(), - &proxy_, + &task_runner_provider_, &shared_bitmap_manager_, &task_graph_runner_) { host_impl_.CreatePendingTree(); + host_impl_.SetVisible(true); host_impl_.InitializeRenderer(output_surface_.get()); } @@ -91,7 +97,7 @@ class PictureImageLayerImplTest : public testing::Test { } protected: - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; scoped_ptr<OutputSurface> output_surface_; @@ -102,10 +108,14 @@ TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); layer->SetDrawsContent(true); + TestablePictureImageLayerImpl* layer_ptr = layer.get(); + host_impl_.pending_tree()->SetRootLayer(std::move(layer)); + host_impl_.pending_tree()->BuildPropertyTreesForTesting(); + gfx::Rect viewport(100, 200); - SetupDrawPropertiesAndUpdateTiles( - layer.get(), 2.f, 3.f, 4.f, 1.f, false, viewport); - EXPECT_FLOAT_EQ(1.f, layer->MaximumTilingContentsScale()); + SetupDrawPropertiesAndUpdateTiles(layer_ptr, 2.f, 3.f, 4.f, 1.f, false, + viewport); + EXPECT_FLOAT_EQ(1.f, layer_ptr->MaximumTilingContentsScale()); } TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { @@ -115,6 +125,10 @@ TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { gfx::Rect viewport(100, 200); + TestablePictureImageLayerImpl* pending_layer_ptr = pending_layer.get(); + host_impl_.pending_tree()->SetRootLayer(std::move(pending_layer)); + host_impl_.pending_tree()->BuildPropertyTreesForTesting(); + // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal // to the content scale used by PictureImageLayerImpl. const float suggested_ideal_contents_scale = 2.f; @@ -122,17 +136,13 @@ TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { const float page_scale_factor = 4.f; const float maximum_animation_contents_scale = 1.f; const bool animating_transform_to_screen = false; - SetupDrawPropertiesAndUpdateTiles(pending_layer.get(), - suggested_ideal_contents_scale, - device_scale_factor, - page_scale_factor, - maximum_animation_contents_scale, - animating_transform_to_screen, - viewport); - EXPECT_EQ(1.f, pending_layer->tilings()->tiling_at(0)->contents_scale()); + SetupDrawPropertiesAndUpdateTiles( + pending_layer_ptr, suggested_ideal_contents_scale, device_scale_factor, + page_scale_factor, maximum_animation_contents_scale, + animating_transform_to_screen, viewport); + EXPECT_EQ(1.f, pending_layer_ptr->tilings()->tiling_at(0)->contents_scale()); // Push to active layer. - host_impl_.pending_tree()->SetRootLayer(pending_layer.Pass()); host_impl_.ActivateSyncTree(); TestablePictureImageLayerImpl* active_layer = diff --git a/chromium/cc/layers/picture_image_layer_unittest.cc b/chromium/cc/layers/picture_image_layer_unittest.cc index f9379c6e3f9..b03ea22796b 100644 --- a/chromium/cc/layers/picture_image_layer_unittest.cc +++ b/chromium/cc/layers/picture_image_layer_unittest.cc @@ -4,9 +4,9 @@ #include "cc/layers/picture_image_layer.h" +#include "cc/layers/layer_settings.h" #include "cc/playback/display_item.h" #include "cc/test/skia_common.h" -#include "cc/trees/layer_tree_settings.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" @@ -35,12 +35,12 @@ TEST(PictureImageLayerTest, PaintContentsToDisplayList) { skia::RefPtr<const SkImage> image = skia::AdoptRef(image_surface->newImageSnapshot()); - layer->SetImage(image.Pass()); + layer->SetImage(std::move(image)); layer->SetBounds(gfx::Size(layer_rect.width(), layer_rect.height())); scoped_refptr<DisplayItemList> display_list = layer->PaintContentsToDisplayList( - layer_rect, ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); + ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); unsigned char actual_pixels[4 * 200 * 200] = {0}; DrawDisplayList(actual_pixels, layer_rect, display_list); diff --git a/chromium/cc/layers/picture_layer.cc b/chromium/cc/layers/picture_layer.cc index 6c215a3eba8..f9df22cd9b8 100644 --- a/chromium/cc/layers/picture_layer.cc +++ b/chromium/cc/layers/picture_layer.cc @@ -5,9 +5,13 @@ #include "cc/layers/picture_layer.h" #include "base/auto_reset.h" +#include "base/trace_event/trace_event.h" #include "cc/layers/content_layer_client.h" #include "cc/layers/picture_layer_impl.h" #include "cc/playback/display_list_recording_source.h" +#include "cc/proto/cc_conversions.h" +#include "cc/proto/gfx_conversions.h" +#include "cc/proto/layer.pb.h" #include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_impl.h" #include "third_party/skia/include/core/SkPictureRecorder.h" @@ -32,9 +36,9 @@ PictureLayer::PictureLayer(const LayerSettings& settings, PictureLayer::PictureLayer(const LayerSettings& settings, ContentLayerClient* client, - scoped_ptr<RecordingSource> source) + scoped_ptr<DisplayListRecordingSource> source) : PictureLayer(settings, client) { - recording_source_ = source.Pass(); + recording_source_ = std::move(source); } PictureLayer::~PictureLayer() { @@ -47,40 +51,23 @@ scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { Layer::PushPropertiesTo(base_layer); + TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. DCHECK_EQ(layer_impl->is_mask(), is_mask_); - - int source_frame_number = layer_tree_host()->source_frame_number(); - gfx::Size impl_bounds = layer_impl->bounds(); - gfx::Size recording_source_bounds = recording_source_->GetSize(); - - // If update called, then recording source size must match bounds pushed to - // impl layer. - DCHECK_IMPLIES(update_source_frame_number_ == source_frame_number, - impl_bounds == recording_source_bounds) - << " bounds " << impl_bounds.ToString() << " recording source " - << recording_source_bounds.ToString(); - - if (update_source_frame_number_ != source_frame_number && - recording_source_bounds != impl_bounds) { - // Update may not get called for the layer (if it's not in the viewport - // for example, even though it has resized making the recording source no - // longer valid. In this case just destroy the recording source. - recording_source_->SetEmptyBounds(); - } + DropRecordingSourceContentIfInvalid(); layer_impl->SetNearestNeighbor(nearest_neighbor_); // Preserve lcd text settings from the current raster source. bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); - scoped_refptr<RasterSource> raster_source = + scoped_refptr<DisplayListRasterSource> raster_source = recording_source_->CreateRasterSource(can_use_lcd_text); layer_impl->set_gpu_raster_max_texture_size( layer_tree_host()->device_viewport_size()); - layer_impl->UpdateRasterSource(raster_source, &recording_invalidation_, + layer_impl->UpdateRasterSource(raster_source, invalidation_.region(), nullptr); - DCHECK(recording_invalidation_.IsEmpty()); + DCHECK(invalidation_.IsEmpty()); } void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { @@ -100,10 +87,10 @@ void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { } void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { + DCHECK(!layer_tree_host() || !layer_tree_host()->in_paint_layer_contents()); if (!layer_rect.IsEmpty()) { // Clamp invalidation to the layer bounds. - pending_invalidation_.Union( - gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); + invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); } Layer::SetNeedsDisplayRect(layer_rect); } @@ -116,8 +103,7 @@ bool PictureLayer::Update() { gfx::Size layer_size = paint_properties().bounds; if (last_updated_visible_layer_rect_ == update_rect && - recording_source_->GetSize() == layer_size && - pending_invalidation_.IsEmpty()) { + recording_source_->GetSize() == layer_size && invalidation_.IsEmpty()) { // Only early out if the visible content rect of this layer hasn't changed. return updated; } @@ -132,25 +118,14 @@ bool PictureLayer::Update() { devtools_instrumentation::ScopedLayerTreeTask update_layer( devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); - // Calling paint in WebKit can sometimes cause invalidations, so save - // off the invalidation prior to calling update. - pending_invalidation_.Swap(&recording_invalidation_); - pending_invalidation_.Clear(); - - if (layer_tree_host()->settings().record_full_layer) { - // Workaround for http://crbug.com/235910 - to retain backwards compat - // the full page content must always be provided in the picture layer. - update_rect = gfx::Rect(layer_size); - } - // UpdateAndExpandInvalidation will give us an invalidation that covers // anything not explicitly recorded in this frame. We give this region // to the impl side so that it drops tiles that may not have a recording // for them. DCHECK(client_); updated |= recording_source_->UpdateAndExpandInvalidation( - client_, &recording_invalidation_, layer_size, update_rect, - update_source_frame_number_, RecordingSource::RECORD_NORMALLY); + client_, invalidation_.region(), layer_size, update_rect, + update_source_frame_number_, DisplayListRecordingSource::RECORD_NORMALLY); last_updated_visible_layer_rect_ = visible_layer_rect(); if (updated) { @@ -158,7 +133,7 @@ bool PictureLayer::Update() { } else { // If this invalidation did not affect the recording source, then it can be // cleared as an optimization. - recording_invalidation_.Clear(); + invalidation_.Clear(); } return updated; @@ -169,20 +144,21 @@ void PictureLayer::SetIsMask(bool is_mask) { } skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { - // We could either flatten the RecordingSource into a single SkPicture, - // or paint a fresh one depending on what we intend to do with the + // We could either flatten the DisplayListRecordingSource into a single + // SkPicture, or paint a fresh one depending on what we intend to do with the // picture. For now we just paint a fresh one to get consistent results. if (!DrawsContent()) return skia::RefPtr<SkPicture>(); gfx::Size layer_size = bounds(); - scoped_ptr<RecordingSource> recording_source(new DisplayListRecordingSource); + scoped_ptr<DisplayListRecordingSource> recording_source( + new DisplayListRecordingSource); Region recording_invalidation; recording_source->UpdateAndExpandInvalidation( client_, &recording_invalidation, layer_size, gfx::Rect(layer_size), - update_source_frame_number_, RecordingSource::RECORD_NORMALLY); + update_source_frame_number_, DisplayListRecordingSource::RECORD_NORMALLY); - scoped_refptr<RasterSource> raster_source = + scoped_refptr<DisplayListRasterSource> raster_source = recording_source->CreateRasterSource(false); return raster_source->GetFlattenedPicture(); @@ -209,8 +185,70 @@ bool PictureLayer::HasDrawableContent() const { return client_ && Layer::HasDrawableContent(); } +void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { + proto->set_type(proto::LayerType::PICTURE_LAYER); +} + +void PictureLayer::LayerSpecificPropertiesToProto( + proto::LayerProperties* proto) { + Layer::LayerSpecificPropertiesToProto(proto); + DropRecordingSourceContentIfInvalid(); + + proto::PictureLayerProperties* picture = proto->mutable_picture(); + recording_source_->ToProtobuf(picture->mutable_recording_source()); + RegionToProto(*invalidation_.region(), picture->mutable_invalidation()); + RectToProto(last_updated_visible_layer_rect_, + picture->mutable_last_updated_visible_layer_rect()); + picture->set_is_mask(is_mask_); + picture->set_nearest_neighbor(nearest_neighbor_); + + picture->set_update_source_frame_number(update_source_frame_number_); + + invalidation_.Clear(); +} + +void PictureLayer::FromLayerSpecificPropertiesProto( + const proto::LayerProperties& proto) { + Layer::FromLayerSpecificPropertiesProto(proto); + const proto::PictureLayerProperties& picture = proto.picture(); + recording_source_->FromProtobuf(picture.recording_source()); + + Region new_invalidation = RegionFromProto(picture.invalidation()); + invalidation_.Swap(&new_invalidation); + last_updated_visible_layer_rect_ = + ProtoToRect(picture.last_updated_visible_layer_rect()); + is_mask_ = picture.is_mask(); + nearest_neighbor_ = picture.nearest_neighbor(); + + update_source_frame_number_ = picture.update_source_frame_number(); +} + void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { benchmark->RunOnLayer(this); } +void PictureLayer::DropRecordingSourceContentIfInvalid() { + int source_frame_number = layer_tree_host()->source_frame_number(); + gfx::Size recording_source_bounds = recording_source_->GetSize(); + + gfx::Size layer_bounds = bounds(); + if (paint_properties().source_frame_number == source_frame_number) + layer_bounds = paint_properties().bounds; + + // If update called, then recording source size must match bounds pushed to + // impl layer. + DCHECK(update_source_frame_number_ != source_frame_number || + layer_bounds == recording_source_bounds) + << " bounds " << layer_bounds.ToString() << " recording source " + << recording_source_bounds.ToString(); + + if (update_source_frame_number_ != source_frame_number && + recording_source_bounds != layer_bounds) { + // Update may not get called for the layer (if it's not in the viewport + // for example), even though it has resized making the recording source no + // longer valid. In this case just destroy the recording source. + recording_source_->SetEmptyBounds(); + } +} + } // namespace cc diff --git a/chromium/cc/layers/picture_layer.h b/chromium/cc/layers/picture_layer.h index 771484c19cc..b7e71523802 100644 --- a/chromium/cc/layers/picture_layer.h +++ b/chromium/cc/layers/picture_layer.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_PICTURE_LAYER_H_ #define CC_LAYERS_PICTURE_LAYER_H_ +#include "base/macros.h" #include "cc/base/invalidation_region.h" #include "cc/debug/devtools_instrumentation.h" #include "cc/debug/micro_benchmark_controller.h" @@ -13,7 +14,7 @@ namespace cc { class ContentLayerClient; -class RecordingSource; +class DisplayListRecordingSource; class ResourceUpdateQueue; class CC_EXPORT PictureLayer : public Layer { @@ -39,7 +40,7 @@ class CC_EXPORT PictureLayer : public Layer { ContentLayerClient* client() { return client_; } - RecordingSource* GetRecordingSourceForTesting() { + DisplayListRecordingSource* GetDisplayListRecordingSourceForTesting() { return recording_source_.get(); } @@ -48,22 +49,30 @@ class CC_EXPORT PictureLayer : public Layer { // Allow tests to inject a recording source. PictureLayer(const LayerSettings& settings, ContentLayerClient* client, - scoped_ptr<RecordingSource> source); + scoped_ptr<DisplayListRecordingSource> source); ~PictureLayer() override; bool HasDrawableContent() const override; + void SetTypeForProtoSerialization(proto::LayerNode* proto) const override; + void LayerSpecificPropertiesToProto(proto::LayerProperties* proto) override; + void FromLayerSpecificPropertiesProto( + const proto::LayerProperties& proto) override; bool is_mask() const { return is_mask_; } private: + friend class TestSerializationPictureLayer; + + void DropRecordingSourceContentIfInvalid(); + ContentLayerClient* client_; - scoped_ptr<RecordingSource> recording_source_; + scoped_ptr<DisplayListRecordingSource> recording_source_; devtools_instrumentation:: ScopedLayerObjectTracker instrumentation_object_tracker_; + // Invalidation to use the next time update is called. - InvalidationRegion pending_invalidation_; - // Invalidation from the last time update was called. - Region recording_invalidation_; + InvalidationRegion invalidation_; + gfx::Rect last_updated_visible_layer_rect_; int update_source_frame_number_; diff --git a/chromium/cc/layers/picture_layer_impl.cc b/chromium/cc/layers/picture_layer_impl.cc index f8aa213a925..04ac9ad59a7 100644 --- a/chromium/cc/layers/picture_layer_impl.cc +++ b/chromium/cc/layers/picture_layer_impl.cc @@ -4,6 +4,9 @@ #include "cc/layers/picture_layer_impl.h" +#include <stddef.h> +#include <stdint.h> + #include <algorithm> #include <cmath> #include <limits> @@ -11,6 +14,7 @@ #include "base/time/time.h" #include "base/trace_event/trace_event_argument.h" +#include "cc/base/histograms.h" #include "cc/base/math_util.h" #include "cc/debug/debug_colors.h" #include "cc/debug/micro_benchmark_impl.h" @@ -69,7 +73,6 @@ PictureLayerImpl::PictureLayerImpl( raster_source_scale_(0.f), raster_contents_scale_(0.f), low_res_raster_contents_scale_(0.f), - raster_source_scale_is_fixed_(false), was_screen_space_transform_animating_(false), only_used_low_res_last_append_quads_(false), is_mask_(is_mask), @@ -100,8 +103,8 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { LayerImpl::PushPropertiesTo(base_layer); // Twin relationships should never change once established. - DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); - DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); + DCHECK(!twin_layer_ || twin_layer_ == layer_impl); + DCHECK(!twin_layer_ || layer_impl->twin_layer_ == this); // The twin relationship does not need to exist before the first // PushPropertiesTo from pending to active layer since before that the active // layer can not have a pile or tilings, it has only been created and inserted @@ -112,7 +115,7 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { layer_impl->SetNearestNeighbor(nearest_neighbor_); // Solid color layers have no tilings. - DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); + DCHECK(!raster_source_->IsSolidColor() || tilings_->num_tilings() == 0); // The pending tree should only have a high res (and possibly low res) tiling. DCHECK_LE(tilings_->num_tilings(), layer_tree_impl()->create_low_res_tiling() ? 2u : 1u); @@ -123,8 +126,8 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { DCHECK(invalidation_.IsEmpty()); // After syncing a solid color layer, the active layer has no tilings. - DCHECK_IMPLIES(raster_source_->IsSolidColor(), - layer_impl->tilings_->num_tilings() == 0); + DCHECK(!raster_source_->IsSolidColor() || + layer_impl->tilings_->num_tilings() == 0); layer_impl->raster_page_scale_ = raster_page_scale_; layer_impl->raster_device_scale_ = raster_device_scale_; @@ -144,8 +147,8 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass, AppendQuadsData* append_quads_data) { // The bounds and the pile size may differ if the pile wasn't updated (ie. // PictureLayer::Update didn't happen). In that case the pile will be empty. - DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), - bounds() == raster_source_->GetSize()) + DCHECK(raster_source_->GetSize().IsEmpty() || + bounds() == raster_source_->GetSize()) << " bounds " << bounds().ToString() << " pile " << raster_source_->GetSize().ToString(); @@ -263,7 +266,7 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass, // Ignore missing tiles outside of viewport for tile priority. This is // normally the same as draw viewport but can be independently overridden by - // embedders like Android WebView with SetExternalDrawConstraints. + // embedders like Android WebView with SetExternalTilePriorityConstraints. gfx::Rect scaled_viewport_for_tile_priority = gfx::ScaleToEnclosingRect( viewport_rect_for_tile_priority_in_content_space_, max_contents_scale); @@ -347,8 +350,16 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass, if (geometry_rect.Intersects(scaled_viewport_for_tile_priority)) { append_quads_data->num_missing_tiles++; ++missing_tile_count; + // We only keep track of discardable images if we're using raster tasks, + // so we only gather stats in this case. + if (layer_tree_impl()->settings().image_decode_tasks_enabled) { + if (raster_source_->HasDiscardableImageInRect(geometry_rect)) + append_quads_data->num_missing_tiles_some_image_content++; + else + append_quads_data->num_missing_tiles_no_image_content++; + } } - int64 checkerboarded_area = + int64_t checkerboarded_area = visible_geometry_rect.width() * visible_geometry_rect.height(); append_quads_data->checkerboarded_visible_content_area += checkerboarded_area; @@ -358,7 +369,7 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass, // subtraction. gfx::Rect visible_rect_has_recording = visible_geometry_rect; visible_rect_has_recording.Intersect(scaled_recorded_viewport); - int64 checkerboarded_has_recording_area = + int64_t checkerboarded_has_recording_area = visible_rect_has_recording.width() * visible_rect_has_recording.height(); append_quads_data->checkerboarded_needs_raster_content_area += @@ -404,6 +415,7 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass, bool PictureLayerImpl::UpdateTiles(bool resourceless_software_draw) { if (!resourceless_software_draw) { visible_rect_for_tile_priority_ = visible_layer_rect(); + screen_space_transform_for_tile_priority_ = ScreenSpaceTransform(); } if (!CanHaveTilings()) { @@ -492,7 +504,7 @@ void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() { if (visible_rect_in_content_space.IsEmpty() || layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority) { gfx::Transform view_to_layer(gfx::Transform::kSkipInitialization); - if (screen_space_transform().GetInverse(&view_to_layer)) { + if (screen_space_transform_for_tile_priority_.GetInverse(&view_to_layer)) { // Transform from view space to content space. visible_rect_in_content_space = MathUtil::ProjectEnclosingClippedRect( view_to_layer, viewport_rect_for_tile_priority); @@ -524,13 +536,13 @@ PictureLayerImpl* PictureLayerImpl::GetPendingOrActiveTwinLayer() const { } void PictureLayerImpl::UpdateRasterSource( - scoped_refptr<RasterSource> raster_source, + scoped_refptr<DisplayListRasterSource> raster_source, Region* new_invalidation, const PictureLayerTilingSet* pending_set) { // The bounds and the pile size may differ if the pile wasn't updated (ie. // PictureLayer::Update didn't happen). In that case the pile will be empty. - DCHECK_IMPLIES(!raster_source->GetSize().IsEmpty(), - bounds() == raster_source->GetSize()) + DCHECK(raster_source->GetSize().IsEmpty() || + bounds() == raster_source->GetSize()) << " bounds " << bounds().ToString() << " pile " << raster_source->GetSize().ToString(); @@ -545,9 +557,8 @@ void PictureLayerImpl::UpdateRasterSource( invalidation_.Swap(new_invalidation); bool can_have_tilings = CanHaveTilings(); - DCHECK_IMPLIES( - pending_set, - can_have_tilings == GetPendingOrActiveTwinLayer()->CanHaveTilings()); + DCHECK(!pending_set || + can_have_tilings == GetPendingOrActiveTwinLayer()->CanHaveTilings()); // Need to call UpdateTiles again if CanHaveTilings changed. if (could_have_tilings != can_have_tilings) @@ -586,7 +597,7 @@ void PictureLayerImpl::UpdateCanUseLCDTextAfterCommit() { // Raster sources are considered const, so in order to update the state // a new one must be created and all tiles recreated. - scoped_refptr<RasterSource> new_raster_source = + scoped_refptr<DisplayListRasterSource> new_raster_source = raster_source_->CreateCloneWithoutLCDText(); raster_source_.swap(new_raster_source); @@ -779,8 +790,8 @@ void PictureLayerImpl::GetContentsResourceId(ResourceId* resource_id, gfx::Size* resource_size) const { // The bounds and the pile size may differ if the pile wasn't updated (ie. // PictureLayer::Update didn't happen). In that case the pile will be empty. - DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), - bounds() == raster_source_->GetSize()) + DCHECK(raster_source_->GetSize().IsEmpty() || + bounds() == raster_source_->GetSize()) << " bounds " << bounds().ToString() << " pile " << raster_source_->GetSize().ToString(); gfx::Rect content_rect(bounds()); @@ -891,10 +902,8 @@ bool PictureLayerImpl::ShouldAdjustRasterScale() const { if (raster_device_scale_ != ideal_device_scale_) return true; - // When the source scale changes we want to match it, but not when animating - // or when we've fixed the scale in place. + // When the source scale changes we want to match it, but not when animating. if (!draw_properties().screen_space_transform_is_animating && - !raster_source_scale_is_fixed_ && raster_source_scale_ != ideal_source_scale_) return true; @@ -920,7 +929,7 @@ void PictureLayerImpl::AddLowResolutionTilingIfNeeded() { PictureLayerTiling* low_res = tilings_->FindTilingWithScale(low_res_raster_contents_scale_); - DCHECK_IMPLIES(low_res, low_res->resolution() != HIGH_RESOLUTION); + DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); // Only create new low res tilings when the transform is static. This // prevents wastefully creating a paired low res tiling for every new high @@ -935,33 +944,14 @@ void PictureLayerImpl::AddLowResolutionTilingIfNeeded() { } void PictureLayerImpl::RecalculateRasterScales() { - float old_raster_contents_scale = raster_contents_scale_; - float old_raster_page_scale = raster_page_scale_; - float old_raster_source_scale = raster_source_scale_; + const float old_raster_contents_scale = raster_contents_scale_; + const float old_raster_page_scale = raster_page_scale_; raster_device_scale_ = ideal_device_scale_; raster_page_scale_ = ideal_page_scale_; raster_source_scale_ = ideal_source_scale_; raster_contents_scale_ = ideal_contents_scale_; - // If we're not animating, or leaving an animation, and the - // ideal_source_scale_ changes, then things are unpredictable, and we fix - // the raster_source_scale_ in place. - if (old_raster_source_scale && - !draw_properties().screen_space_transform_is_animating && - !was_screen_space_transform_animating_ && - old_raster_source_scale != ideal_source_scale_) - raster_source_scale_is_fixed_ = true; - - // TODO(danakj): Adjust raster source scale closer to ideal source scale at - // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending - // tree. This will allow CSS scale changes to get re-rastered at an - // appropriate rate. (crbug.com/413636) - if (raster_source_scale_is_fixed_) { - raster_contents_scale_ /= raster_source_scale_; - raster_source_scale_ = 1.f; - } - // During pinch we completely ignore the current ideal scale, and just use // a multiple of the previous scale. bool is_pinching = layer_tree_impl()->PinchGestureActive(); @@ -999,22 +989,24 @@ void PictureLayerImpl::RecalculateRasterScales() { if (maximum_scale) { gfx::Size bounds_at_maximum_scale = gfx::ScaleToCeiledSize(raster_source_->GetSize(), maximum_scale); - int64 maximum_area = static_cast<int64>(bounds_at_maximum_scale.width()) * - static_cast<int64>(bounds_at_maximum_scale.height()); + int64_t maximum_area = + static_cast<int64_t>(bounds_at_maximum_scale.width()) * + static_cast<int64_t>(bounds_at_maximum_scale.height()); gfx::Size viewport = layer_tree_impl()->device_viewport_size(); - int64 viewport_area = static_cast<int64>(viewport.width()) * - static_cast<int64>(viewport.height()); + int64_t viewport_area = static_cast<int64_t>(viewport.width()) * + static_cast<int64_t>(viewport.height()); if (maximum_area <= viewport_area) can_raster_at_maximum_scale = true; } if (starting_scale && starting_scale > maximum_scale) { gfx::Size bounds_at_starting_scale = gfx::ScaleToCeiledSize(raster_source_->GetSize(), starting_scale); - int64 start_area = static_cast<int64>(bounds_at_starting_scale.width()) * - static_cast<int64>(bounds_at_starting_scale.height()); + int64_t start_area = + static_cast<int64_t>(bounds_at_starting_scale.width()) * + static_cast<int64_t>(bounds_at_starting_scale.height()); gfx::Size viewport = layer_tree_impl()->device_viewport_size(); - int64 viewport_area = static_cast<int64>(viewport.width()) * - static_cast<int64>(viewport.height()); + int64_t viewport_area = static_cast<int64_t>(viewport.width()) * + static_cast<int64_t>(viewport.height()); if (start_area <= viewport_area) should_raster_at_starting_scale = true; } @@ -1130,7 +1122,6 @@ void PictureLayerImpl::ResetRasterScale() { raster_source_scale_ = 0.f; raster_contents_scale_ = 0.f; low_res_raster_contents_scale_ = 0.f; - raster_source_scale_is_fixed_ = false; } bool PictureLayerImpl::CanHaveTilings() const { @@ -1214,6 +1205,7 @@ void PictureLayerImpl::AsValueInto( base::trace_event::TracedValue* state) const { LayerImpl::AsValueInto(state); state->SetDouble("ideal_contents_scale", ideal_contents_scale_); + state->SetDouble("raster_contents_scale", raster_contents_scale_); state->SetDouble("geometry_contents_scale", MaximumTilingContentsScale()); state->BeginArray("tilings"); tilings_->AsValueInto(state); diff --git a/chromium/cc/layers/picture_layer_impl.h b/chromium/cc/layers/picture_layer_impl.h index 409afaeb9ca..8a2465a15bc 100644 --- a/chromium/cc/layers/picture_layer_impl.h +++ b/chromium/cc/layers/picture_layer_impl.h @@ -5,12 +5,14 @@ #ifndef CC_LAYERS_PICTURE_LAYER_IMPL_H_ #define CC_LAYERS_PICTURE_LAYER_IMPL_H_ +#include <stddef.h> + #include <map> #include <string> #include <vector> +#include "base/macros.h" #include "cc/base/cc_export.h" -#include "cc/base/scoped_ptr_vector.h" #include "cc/layers/layer_impl.h" #include "cc/tiles/picture_layer_tiling.h" #include "cc/tiles/picture_layer_tiling_set.h" @@ -66,7 +68,7 @@ class CC_EXPORT PictureLayerImpl void set_gpu_raster_max_texture_size(gfx::Size gpu_raster_max_texture_size) { gpu_raster_max_texture_size_ = gpu_raster_max_texture_size; } - void UpdateRasterSource(scoped_refptr<RasterSource> raster_source, + void UpdateRasterSource(scoped_refptr<DisplayListRasterSource> raster_source, Region* new_invalidation, const PictureLayerTilingSet* pending_set); bool UpdateTiles(bool resourceless_software_draw); @@ -93,7 +95,9 @@ class CC_EXPORT PictureLayerImpl bool IsOnActiveOrPendingTree() const; // Used for benchmarking - RasterSource* GetRasterSource() const { return raster_source_.get(); } + DisplayListRasterSource* GetRasterSource() const { + return raster_source_.get(); + } protected: friend class LayerRasterTileIterator; @@ -132,7 +136,7 @@ class CC_EXPORT PictureLayerImpl PictureLayerImpl* twin_layer_; scoped_ptr<PictureLayerTilingSet> tilings_; - scoped_refptr<RasterSource> raster_source_; + scoped_refptr<DisplayListRasterSource> raster_source_; Region invalidation_; float ideal_page_scale_; @@ -146,7 +150,6 @@ class CC_EXPORT PictureLayerImpl float raster_contents_scale_; float low_res_raster_contents_scale_; - bool raster_source_scale_is_fixed_; bool was_screen_space_transform_animating_; bool only_used_low_res_last_append_quads_; const bool is_mask_; @@ -154,13 +157,14 @@ class CC_EXPORT PictureLayerImpl bool nearest_neighbor_; // Any draw properties derived from |transform|, |viewport|, and |clip| - // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid - // for prioritizing tiles during resourceless software draws. This is because - // resourceless software draws can have wildly different transforms/viewports - // from regular draws. Save a copy of the required draw properties of the last - // frame that has a valid viewport for prioritizing tiles. + // parameters in LayerTreeHostImpl::OnDraw are not valid for prioritizing + // tiles during resourceless software draws. This is because resourceless + // software draws can have wildly different transforms/viewports from regular + // draws. Save a copy of the required draw properties of the last frame that + // has a valid viewport for prioritizing tiles. gfx::Rect visible_rect_for_tile_priority_; gfx::Rect viewport_rect_for_tile_priority_in_content_space_; + gfx::Transform screen_space_transform_for_tile_priority_; gfx::Size gpu_raster_max_texture_size_; diff --git a/chromium/cc/layers/picture_layer_impl_perftest.cc b/chromium/cc/layers/picture_layer_impl_perftest.cc index 6c45b095142..c38dd3ea7d8 100644 --- a/chromium/cc/layers/picture_layer_impl_perftest.cc +++ b/chromium/cc/layers/picture_layer_impl_perftest.cc @@ -4,10 +4,11 @@ #include "cc/layers/picture_layer_impl.h" +#include "base/macros.h" #include "base/thread_task_runner_handle.h" #include "cc/debug/lap_timer.h" #include "cc/test/fake_display_list_raster_source.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_picture_layer_impl.h" @@ -40,10 +41,10 @@ void AddTiling(float scale, class PictureLayerImplPerfTest : public testing::Test { public: PictureLayerImplPerfTest() - : proxy_(base::ThreadTaskRunnerHandle::Get()), + : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()), output_surface_(FakeOutputSurface::Create3d()), host_impl_(LayerTreeSettings(), - &proxy_, + &task_runner_provider_, &shared_bitmap_manager_, &task_graph_runner_), timer_(kWarmupRuns, @@ -51,6 +52,7 @@ class PictureLayerImplPerfTest : public testing::Test { kTimeCheckInterval) {} void SetUp() override { + host_impl_.SetVisible(true); host_impl_.InitializeRenderer(output_surface_.get()); } @@ -65,8 +67,9 @@ class PictureLayerImplPerfTest : public testing::Test { FakePictureLayerImpl::CreateWithRasterSource(pending_tree, 7, raster_source); pending_layer->SetDrawsContent(true); - pending_layer->SetHasRenderSurface(true); - pending_tree->SetRootLayer(pending_layer.Pass()); + pending_layer->SetForceRenderSurface(true); + pending_tree->SetRootLayer(std::move(pending_layer)); + pending_tree->BuildPropertyTreesForTesting(); pending_layer_ = static_cast<FakePictureLayerImpl*>( host_impl_.pending_tree()->LayerById(7)); @@ -163,7 +166,7 @@ class PictureLayerImplPerfTest : public testing::Test { protected: TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; scoped_ptr<OutputSurface> output_surface_; FakeLayerTreeHostImpl host_impl_; FakePictureLayerImpl* pending_layer_; diff --git a/chromium/cc/layers/picture_layer_impl_unittest.cc b/chromium/cc/layers/picture_layer_impl_unittest.cc index 93c1f1f823f..5d16d8f6919 100644 --- a/chromium/cc/layers/picture_layer_impl_unittest.cc +++ b/chromium/cc/layers/picture_layer_impl_unittest.cc @@ -4,15 +4,19 @@ #include "cc/layers/picture_layer_impl.h" +#include <stddef.h> + #include <algorithm> #include <limits> #include <set> #include <utility> #include "base/location.h" +#include "base/macros.h" #include "base/thread_task_runner_handle.h" #include "cc/base/math_util.h" #include "cc/layers/append_quads_data.h" +#include "cc/layers/layer_settings.h" #include "cc/layers/picture_layer.h" #include "cc/quads/draw_quad.h" #include "cc/quads/tile_draw_quad.h" @@ -20,7 +24,7 @@ #include "cc/test/fake_content_layer_client.h" #include "cc/test/fake_display_list_raster_source.h" #include "cc/test/fake_display_list_recording_source.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_picture_layer_impl.h" @@ -80,6 +84,7 @@ class PictureLayerImplTestSettings : public GpuRasterizationEnabledSettings { public: PictureLayerImplTestSettings() { layer_transforms_should_scale_layer_contents = true; + verify_property_trees = true; } }; @@ -92,11 +97,11 @@ class LowResTilingsSettings : public PictureLayerImplTestSettings { class PictureLayerImplTest : public testing::Test { public: - PictureLayerImplTest() - : proxy_(base::ThreadTaskRunnerHandle::Get()), + explicit PictureLayerImplTest(const LayerTreeSettings& settings) + : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()), output_surface_(FakeOutputSurface::Create3d()), - host_impl_(LowResTilingsSettings(), - &proxy_, + host_impl_(settings, + &task_runner_provider_, &shared_bitmap_manager_, &task_graph_runner_), root_id_(6), @@ -107,23 +112,14 @@ class PictureLayerImplTest : public testing::Test { host_impl_.SetViewportSize(gfx::Size(10000, 10000)); } - explicit PictureLayerImplTest(const LayerTreeSettings& settings) - : proxy_(base::ThreadTaskRunnerHandle::Get()), - output_surface_(FakeOutputSurface::Create3d()), - host_impl_(settings, - &proxy_, - &shared_bitmap_manager_, - &task_graph_runner_), - root_id_(6), - id_(7) { - host_impl_.SetViewportSize(gfx::Size(10000, 10000)); - } + PictureLayerImplTest() : PictureLayerImplTest(LowResTilingsSettings()) {} ~PictureLayerImplTest() override {} void SetUp() override { InitializeRenderer(); } virtual void InitializeRenderer() { + host_impl_.SetVisible(true); host_impl_.InitializeRenderer(output_surface_.get()); } @@ -147,7 +143,13 @@ class PictureLayerImplTest : public testing::Test { invalidation); } + void RebuildPropertyTreesOnPendingTree() { + host_impl_.pending_tree()->property_trees()->needs_rebuild = true; + host_impl_.pending_tree()->BuildPropertyTreesForTesting(); + } + void ActivateTree() { + RebuildPropertyTreesOnPendingTree(); host_impl_.ActivateSyncTree(); CHECK(!host_impl_.pending_tree()); CHECK(host_impl_.recycle_tree()); @@ -172,16 +174,16 @@ class PictureLayerImplTest : public testing::Test { tile_size, invalidation); } - void SetupTrees(scoped_refptr<RasterSource> pending_raster_source, - scoped_refptr<RasterSource> active_raster_source) { + void SetupTrees(scoped_refptr<DisplayListRasterSource> pending_raster_source, + scoped_refptr<DisplayListRasterSource> active_raster_source) { SetupPendingTree(active_raster_source); ActivateTree(); SetupPendingTreeInternal(pending_raster_source, gfx::Size(), Region()); } void SetupTreesWithInvalidation( - scoped_refptr<RasterSource> pending_raster_source, - scoped_refptr<RasterSource> active_raster_source, + scoped_refptr<DisplayListRasterSource> pending_raster_source, + scoped_refptr<DisplayListRasterSource> active_raster_source, const Region& pending_invalidation) { SetupPendingTreeInternal(active_raster_source, gfx::Size(), Region()); ActivateTree(); @@ -190,8 +192,8 @@ class PictureLayerImplTest : public testing::Test { } void SetupTreesWithFixedTileSize( - scoped_refptr<RasterSource> pending_raster_source, - scoped_refptr<RasterSource> active_raster_source, + scoped_refptr<DisplayListRasterSource> pending_raster_source, + scoped_refptr<DisplayListRasterSource> active_raster_source, const gfx::Size& tile_size, const Region& pending_invalidation) { SetupPendingTreeInternal(active_raster_source, tile_size, Region()); @@ -200,26 +202,27 @@ class PictureLayerImplTest : public testing::Test { pending_invalidation); } - void SetupPendingTree(scoped_refptr<RasterSource> raster_source) { + void SetupPendingTree(scoped_refptr<DisplayListRasterSource> raster_source) { SetupPendingTreeInternal(raster_source, gfx::Size(), Region()); } void SetupPendingTreeWithInvalidation( - scoped_refptr<RasterSource> raster_source, + scoped_refptr<DisplayListRasterSource> raster_source, const Region& invalidation) { SetupPendingTreeInternal(raster_source, gfx::Size(), invalidation); } void SetupPendingTreeWithFixedTileSize( - scoped_refptr<RasterSource> raster_source, + scoped_refptr<DisplayListRasterSource> raster_source, const gfx::Size& tile_size, const Region& invalidation) { SetupPendingTreeInternal(raster_source, tile_size, invalidation); } - void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source, - const gfx::Size& tile_size, - const Region& invalidation) { + void SetupPendingTreeInternal( + scoped_refptr<DisplayListRasterSource> raster_source, + const gfx::Size& tile_size, + const Region& invalidation) { host_impl_.CreatePendingTree(); host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.00001f, 100000.f); @@ -230,7 +233,7 @@ class PictureLayerImplTest : public testing::Test { // Steal from the recycled tree if possible. scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree(); scoped_ptr<FakePictureLayerImpl> pending_layer; - DCHECK_IMPLIES(pending_root, pending_root->id() == root_id_); + DCHECK(!pending_root || pending_root->id() == root_id_); if (!pending_root) { pending_root = LayerImpl::Create(pending_tree, root_id_); pending_layer = FakePictureLayerImpl::Create(pending_tree, id_); @@ -239,23 +242,28 @@ class PictureLayerImplTest : public testing::Test { pending_layer->SetDrawsContent(true); } else { pending_layer.reset(static_cast<FakePictureLayerImpl*>( - pending_root->RemoveChild(pending_root->children()[0]).release())); + pending_root->RemoveChild(pending_root->children()[0].get()) + .release())); if (!tile_size.IsEmpty()) pending_layer->set_fixed_tile_size(tile_size); } - pending_root->SetHasRenderSurface(true); + pending_root->SetForceRenderSurface(true); // The bounds() just mirror the raster source size. pending_layer->SetBounds(raster_source->GetSize()); pending_layer->SetRasterSourceOnPending(raster_source, invalidation); - pending_root->AddChild(pending_layer.Pass()); - pending_tree->SetRootLayer(pending_root.Pass()); + pending_root->AddChild(std::move(pending_layer)); + pending_tree->SetRootLayer(std::move(pending_root)); + pending_tree->SetViewportLayersFromIds( + Layer::INVALID_ID, pending_tree->root_layer()->id(), Layer::INVALID_ID, + Layer::INVALID_ID); pending_layer_ = static_cast<FakePictureLayerImpl*>( host_impl_.pending_tree()->LayerById(id_)); // Add tilings/tiles for the layer. bool update_lcd_text = false; + RebuildPropertyTreesOnPendingTree(); host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); } @@ -285,7 +293,7 @@ class PictureLayerImplTest : public testing::Test { } static void VerifyAllPrioritizedTilesExistAndHaveRasterSource( const PictureLayerTiling* tiling, - RasterSource* raster_source) { + DisplayListRasterSource* raster_source) { auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); for (PictureLayerTiling::CoverageIterator iter( @@ -369,7 +377,7 @@ class PictureLayerImplTest : public testing::Test { protected: void TestQuadsForSolidColor(bool test_for_solid); - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; scoped_ptr<OutputSurface> output_surface_; @@ -403,6 +411,7 @@ TEST_F(PictureLayerImplTest, TileGridAlignment) { // Create an active recording source, but make sure it's not solid. scoped_ptr<FakeDisplayListRecordingSource> active_recording_source = FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_size); + active_recording_source->SetLayerBounds(layer_size); active_recording_source->add_draw_rect(gfx::Rect(layer_size)); active_recording_source->add_draw_rect( gfx::Rect(0, 0, layer_size.width() - 1, layer_size.height() - 1)); @@ -477,17 +486,11 @@ TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) { // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the // identify transform for tile priority. - bool resourceless_software_draw = false; - gfx::Rect viewport = gfx::Rect(layer_bounds), - viewport_rect_for_tile_priority = gfx::Rect(0, 0, 100, 100); + gfx::Rect viewport_rect_for_tile_priority = gfx::Rect(0, 0, 100, 100); gfx::Transform transform, transform_for_tile_priority; - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport_rect_for_tile_priority, - transform_for_tile_priority, - resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, + transform_for_tile_priority); bool update_lcd_text = false; host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text); @@ -515,12 +518,8 @@ TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) { viewport_rect_for_tile_priority = gfx::Rect(200, 200, 100, 100); transform_for_tile_priority.Translate(100, 100); transform_for_tile_priority.Rotate(45); - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport_rect_for_tile_priority, - transform_for_tile_priority, - resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, + transform_for_tile_priority); host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text); gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); @@ -560,60 +559,74 @@ TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) { // software draw. bool resourceless_software_draw = false; gfx::Rect viewport = gfx::Rect(layer_bounds); - gfx::Transform transform; - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport, - transform, - resourceless_software_draw); + gfx::Transform draw_transform; + gfx::Transform tile_priority_transform; + host_impl_.SetExternalTilePriorityConstraints(viewport, + tile_priority_transform); active_layer_->draw_properties().visible_layer_rect = viewport; - active_layer_->draw_properties().screen_space_transform = transform; + active_layer_->draw_properties().screen_space_transform = draw_transform; active_layer_->UpdateTiles(resourceless_software_draw); gfx::Rect visible_rect_for_tile_priority = active_layer_->visible_rect_for_tile_priority(); EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); gfx::Transform screen_space_transform_for_tile_priority = - active_layer_->screen_space_transform(); + active_layer_->draw_properties().screen_space_transform; // Expand viewport and set it as invalid for prioritizing tiles. // Should update viewport and transform, but not update visible rect. host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); resourceless_software_draw = true; viewport = gfx::ScaleToEnclosingRect(viewport, 2); - transform.Translate(1.f, 1.f); + tile_priority_transform.Translate(1.f, 0.f); + draw_transform.Translate(0.f, 1.f); active_layer_->draw_properties().visible_layer_rect = viewport; - active_layer_->draw_properties().screen_space_transform = transform; - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport, - transform, - resourceless_software_draw); + active_layer_->draw_properties().screen_space_transform = draw_transform; + host_impl_.SetExternalTilePriorityConstraints(viewport, + tile_priority_transform); active_layer_->UpdateTiles(resourceless_software_draw); - // Transform for tile priority is updated. - EXPECT_TRANSFORMATION_MATRIX_EQ(transform, - active_layer_->screen_space_transform()); + // Transform for tile priority is not updated. + EXPECT_TRANSFORMATION_MATRIX_EQ( + screen_space_transform_for_tile_priority, + active_layer_->screen_space_transform_for_tile_priority()); // Visible rect for tile priority retains old value. EXPECT_EQ(visible_rect_for_tile_priority, active_layer_->visible_rect_for_tile_priority()); + ASSERT_GT(active_layer_->picture_layer_tiling_set()->num_tilings(), 0u); + EXPECT_EQ(active_layer_->viewport_rect_for_tile_priority_in_content_space(), + active_layer_->picture_layer_tiling_set() + ->tiling_at(0) + ->GetCurrentVisibleRectForTesting()); // Keep expanded viewport but mark it valid. Should update tile viewport. host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); resourceless_software_draw = false; - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport, - transform, - resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints(viewport, + tile_priority_transform); active_layer_->UpdateTiles(resourceless_software_draw); - EXPECT_TRANSFORMATION_MATRIX_EQ(transform, - active_layer_->screen_space_transform()); + EXPECT_TRANSFORMATION_MATRIX_EQ( + draw_transform, + active_layer_->screen_space_transform_for_tile_priority()); EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority()); + + gfx::RectF visible_rect_in_content_space(viewport); + gfx::Transform inverse_draw_transform; + gfx::Transform inverse_tile_priority_transform; + EXPECT_TRUE(draw_transform.GetInverse(&inverse_draw_transform)); + EXPECT_TRUE( + tile_priority_transform.GetInverse(&inverse_tile_priority_transform)); + visible_rect_in_content_space = MathUtil::ProjectClippedRect( + inverse_tile_priority_transform, visible_rect_in_content_space); + visible_rect_in_content_space = MathUtil::ProjectClippedRect( + inverse_draw_transform, visible_rect_in_content_space); + + ASSERT_GT(active_layer_->picture_layer_tiling_set()->num_tilings(), 0u); + EXPECT_EQ(gfx::ToEnclosingRect(visible_rect_in_content_space), + active_layer_->picture_layer_tiling_set() + ->tiling_at(0) + ->GetCurrentVisibleRectForTesting()); } TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) { @@ -626,14 +639,11 @@ TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) { host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); - bool resourceless_software_draw = false; - gfx::Rect viewport = gfx::Rect(layer_bounds); gfx::Rect viewport_rect_for_tile_priority(0, 0, 100, 100); - gfx::Transform transform, transform_for_tile_priority; + gfx::Transform transform_for_tile_priority; - host_impl_.SetExternalDrawConstraints( - transform, viewport, viewport, viewport_rect_for_tile_priority, - transform_for_tile_priority, resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, + transform_for_tile_priority); bool update_lcd_text = false; host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text); @@ -643,9 +653,8 @@ TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) { host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); gfx::Rect another_viewport_rect_for_tile_priority(11, 11, 50, 50); - host_impl_.SetExternalDrawConstraints( - transform, viewport, viewport, another_viewport_rect_for_tile_priority, - transform_for_tile_priority, resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints( + another_viewport_rect_for_tile_priority, transform_for_tile_priority); // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority // should remain to be the previously cached value. @@ -1160,44 +1169,72 @@ TEST_F(PictureLayerImplTest, CleanUpTilings) { active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); ASSERT_EQ(4u, active_layer_->tilings()->num_tilings()); - // Now move the ideal scale to 0.5. Our target stays 1.2. + // Now move the ideal scale to 0.5. SetContentsScaleOnBothLayers(0.5f, 1.f, page_scale, 1.f, 0.f, false); + ASSERT_EQ(6u, active_layer_->tilings()->num_tilings()); - // The high resolution tiling is between target and ideal, so is not - // removed. The low res tiling for the old ideal=1.0 scale is removed. - used_tilings.clear(); - active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); - ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); - - // Now move the ideal scale to 1.0. Our target stays 1.2. - SetContentsScaleOnBothLayers(1.f, 1.f, page_scale, 1.f, 0.f, false); + // And begin an animation to 1.2. There are now 3 tilings, 0.5, 1.0 and 1.2. + // The the 0.5 is ideal, but the 1.2 is high res. 1.0 sits between them. + // high-res tiling is in the middle. There are also ex-low-res tilings paired + // with each of the 3 tilings mentioned here, but since we're animating none + // are marked as LOW_RESOLUTION. + SetContentsScaleOnBothLayers(0.5, 1.f, page_scale, 1.2f, 0.f, true); + ASSERT_EQ(6u, active_layer_->tilings()->num_tilings()); + EXPECT_EQ(HIGH_RESOLUTION, + active_layer_->tilings()->tiling_at(0)->resolution()); + EXPECT_EQ(1.2f, // High-res, though not the ideal scale. + active_layer_->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ(1.f, // Tiling in the middle attack. + active_layer_->tilings()->tiling_at(1)->contents_scale()); + EXPECT_EQ(0.5f, // Ideal scale, but not considered high-res. + active_layer_->tilings()->tiling_at(2)->contents_scale()); - // All the tilings are between are target and the ideal, so they are not - // removed. + EXPECT_EQ(NON_IDEAL_RESOLUTION, + active_layer_->tilings()->tiling_at(1)->resolution()); + EXPECT_EQ(NON_IDEAL_RESOLUTION, + active_layer_->tilings()->tiling_at(2)->resolution()); + EXPECT_EQ(NON_IDEAL_RESOLUTION, + active_layer_->tilings()->tiling_at(3)->resolution()); + EXPECT_EQ(NON_IDEAL_RESOLUTION, + active_layer_->tilings()->tiling_at(4)->resolution()); + EXPECT_EQ(NON_IDEAL_RESOLUTION, + active_layer_->tilings()->tiling_at(5)->resolution()); + + EXPECT_EQ(1.2f * low_res_factor, // Low-res, paired with current high-res. + active_layer_->tilings()->tiling_at(3)->contents_scale()); + EXPECT_EQ(1.f * low_res_factor, // Ex-low-res, paired with the middle one. + active_layer_->tilings()->tiling_at(4)->contents_scale()); + EXPECT_EQ(0.5f * low_res_factor, // Ex-low-res, paired with current ideal. + active_layer_->tilings()->tiling_at(5)->contents_scale()); + + // The high resolution tiling is between target and ideal, so is not removed. + // The ex-low-res tilings are all smaller scale, so they are removed. used_tilings.clear(); active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); - // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. - SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.1f, 1.f, page_scale, 1.f, - 0.f, false); + // Now move the ideal scale to 1.0 on the active layer. The high-res tiling + // stays 1.2. + SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, page_scale, 1.2f, + 0.f, true); - // Because the pending layer's ideal scale is still 1.0, our tilings fall - // in the range [1.0,1.2] and are kept. + // All the tilings are between are target and the ideal, so they are not + // Because the pending layer's ideal scale is still 0.5, all tilings fall + // in the range [0.5,1.2] and are kept. used_tilings.clear(); active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); - // Move the ideal scale on the pending layer to 1.1 as well. Our target stays - // 1.2 still. - SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.1f, 1.f, page_scale, 1.f, + // Move the ideal scale on the pending layer to 1.0 as well. Our high-res + // stays 1.2 still. + SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, page_scale, 1.f, 0.f, false); - // Our 1.0 tiling now falls outside the range between our ideal scale and our - // target raster scale. But it is in our used tilings set, so nothing is + // Our 0.5 tiling now falls outside the range between our ideal scale and our + // high-res raster scale. But it is in our used tilings set, so nothing is // deleted. used_tilings.clear(); - used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); + used_tilings.push_back(active_layer_->tilings()->tiling_at(2)); active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); @@ -1330,12 +1367,18 @@ TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) { host_impl_.pending_tree(), 3, pending_raster_source); mask->SetBounds(layer_bounds); mask->SetDrawsContent(true); + pending_layer_->SetMaskLayer(std::move(mask)); + pending_layer_->SetHasRenderSurface(true); + RebuildPropertyTreesOnPendingTree(); + host_impl_.pending_tree()->UpdateDrawProperties(false); + FakePictureLayerImpl* mask_raw = + static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer()); SetupDrawPropertiesAndUpdateTiles( - mask.get(), contents_scale, device_scale, page_scale, + mask_raw, contents_scale, device_scale, page_scale, maximum_animation_scale, starting_animation_scale, animating_transform); - EXPECT_EQ(mask->HighResTiling()->contents_scale(), contents_scale); - EXPECT_EQ(mask->num_tilings(), 1u); + EXPECT_EQ(mask_raw->HighResTiling()->contents_scale(), contents_scale); + EXPECT_EQ(mask_raw->num_tilings(), 1u); } TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) { @@ -1352,10 +1395,10 @@ TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) { host_impl_.pending_tree(), 3, valid_raster_source); mask_ptr->SetBounds(layer_bounds); mask_ptr->SetDrawsContent(true); - pending_layer_->SetMaskLayer(mask_ptr.Pass()); - pending_layer_->SetHasRenderSurface(true); + pending_layer_->SetMaskLayer(std::move(mask_ptr)); + pending_layer_->SetForceRenderSurface(true); - host_impl_.pending_tree()->BuildPropertyTreesForTesting(); + RebuildPropertyTreesOnPendingTree(); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); bool update_lcd_text = false; host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); @@ -1481,10 +1524,10 @@ TEST_F(PictureLayerImplTest, ScaledMaskLayer) { host_impl_.pending_tree(), 3, valid_raster_source); mask_ptr->SetBounds(layer_bounds); mask_ptr->SetDrawsContent(true); - pending_layer_->SetMaskLayer(mask_ptr.Pass()); - pending_layer_->SetHasRenderSurface(true); + pending_layer_->SetMaskLayer(std::move(mask_ptr)); + pending_layer_->SetForceRenderSurface(true); - host_impl_.pending_tree()->BuildPropertyTreesForTesting(); + RebuildPropertyTreesOnPendingTree(); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); bool update_lcd_text = false; host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); @@ -1569,9 +1612,10 @@ TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) { context->set_max_texture_size(140); host_impl_.DidLoseOutputSurface(); scoped_ptr<OutputSurface> new_output_surface = - FakeOutputSurface::Create3d(context.Pass()); + FakeOutputSurface::Create3d(std::move(context)); + host_impl_.SetVisible(true); host_impl_.InitializeRenderer(new_output_surface.get()); - output_surface_ = new_output_surface.Pass(); + output_surface_ = std::move(new_output_surface); SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, false); @@ -1608,9 +1652,10 @@ TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { context->set_max_texture_size(140); host_impl_.DidLoseOutputSurface(); scoped_ptr<OutputSurface> new_output_surface = - FakeOutputSurface::Create3d(context.Pass()); + FakeOutputSurface::Create3d(std::move(context)); + host_impl_.SetVisible(true); host_impl_.InitializeRenderer(new_output_surface.get()); - output_surface_ = new_output_surface.Pass(); + output_surface_ = std::move(new_output_surface); SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, false); @@ -1766,15 +1811,9 @@ TEST_F(NoLowResPictureLayerImplTest, MarkRequiredOffscreenTiles) { gfx::Size layer_bounds(200, 200); gfx::Transform transform; - gfx::Transform transform_for_tile_priority; bool resourceless_software_draw = false; gfx::Rect viewport(0, 0, 100, 200); - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport, - transform, - resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints(viewport, transform); scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = FakeDisplayListRasterSource::CreateFilled(layer_bounds); @@ -1782,7 +1821,8 @@ TEST_F(NoLowResPictureLayerImplTest, MarkRequiredOffscreenTiles) { Region()); EXPECT_EQ(1u, pending_layer_->num_tilings()); - EXPECT_EQ(viewport, pending_layer_->visible_rect_for_tile_priority()); + EXPECT_EQ(viewport, + pending_layer_->viewport_rect_for_tile_priority_in_content_space()); base::TimeTicks time_ticks; host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); @@ -1828,12 +1868,8 @@ TEST_F(NoLowResPictureLayerImplTest, gfx::Transform transform; gfx::Transform transform_for_tile_priority; bool resourceless_software_draw = false; - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - external_viewport_for_tile_priority, - transform_for_tile_priority, - resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints( + external_viewport_for_tile_priority, transform_for_tile_priority); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); bool update_lcd_text = false; host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); @@ -2015,8 +2051,9 @@ TEST_F(PictureLayerImplTest, gfx::Size viewport_size(400, 400); host_impl_.SetViewportSize(viewport_size); - SetInitialDeviceScaleFactor(2.f); + // Start with an ideal and raster contents scale of 2. + SetInitialDeviceScaleFactor(2.f); SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); // One ideal tile exists, this will get used when drawing. @@ -2026,18 +2063,17 @@ TEST_F(PictureLayerImplTest, host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( ideal_tiles); - // Due to layer scale throttling, the raster contents scale is changed to 1, - // while the ideal is still 2. - SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, - false); + // Due to the animation, the raster contents scale moves to 1, while the + // ideal will still be 2. SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, 0.f, - false); + true); EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale()); EXPECT_EQ(1.f, active_layer_->raster_contents_scale()); EXPECT_EQ(2.f, active_layer_->ideal_contents_scale()); // Both tilings still exist. + ASSERT_GE(active_layer_->tilings()->num_tilings(), 2u); EXPECT_EQ(2.f, active_layer_->tilings()->tiling_at(0)->contents_scale()); EXPECT_EQ(1.f, active_layer_->tilings()->tiling_at(1)->contents_scale()); @@ -2095,6 +2131,76 @@ TEST_F(PictureLayerImplTest, AppendQuadsDataForCheckerboard) { EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads()); } +class ImageDecodeTasksSettings : public PictureLayerImplTestSettings { + public: + ImageDecodeTasksSettings() { image_decode_tasks_enabled = true; } +}; + +class ImageDecodeTasksTest : public PictureLayerImplTest { + public: + ImageDecodeTasksTest() : PictureLayerImplTest(ImageDecodeTasksSettings()) {} +}; + +TEST_F(ImageDecodeTasksTest, CheckerboardWithNoImageContent) { + host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); + + gfx::Size tile_size(100, 100); + gfx::Size layer_bounds(200, 200); + gfx::Rect recorded_viewport(0, 0, 150, 150); + + scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = + FakeDisplayListRasterSource::CreatePartiallyFilled(layer_bounds, + recorded_viewport); + SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); + ActivateTree(); + + scoped_ptr<RenderPass> render_pass = RenderPass::Create(); + AppendQuadsData data; + active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr); + active_layer_->AppendQuads(render_pass.get(), &data); + active_layer_->DidDraw(nullptr); + + EXPECT_EQ(1u, render_pass->quad_list.size()); + EXPECT_EQ(1u, data.num_missing_tiles); + EXPECT_EQ(0u, data.num_incomplete_tiles); + EXPECT_EQ(1u, data.num_missing_tiles_no_image_content); + EXPECT_EQ(0u, data.num_missing_tiles_some_image_content); + EXPECT_EQ(40000, data.checkerboarded_visible_content_area); + EXPECT_EQ(17500, data.checkerboarded_no_recording_content_area); + EXPECT_EQ(22500, data.checkerboarded_needs_raster_content_area); + EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads()); +} + +TEST_F(ImageDecodeTasksTest, CheckerboardWithSomeImageContent) { + host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); + + gfx::Size tile_size(100, 100); + gfx::Size layer_bounds(200, 200); + gfx::Rect recorded_viewport(0, 0, 150, 150); + + scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = + FakeDisplayListRasterSource::CreatePartiallyFilledWithImages( + layer_bounds, recorded_viewport); + SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); + ActivateTree(); + + scoped_ptr<RenderPass> render_pass = RenderPass::Create(); + AppendQuadsData data; + active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr); + active_layer_->AppendQuads(render_pass.get(), &data); + active_layer_->DidDraw(nullptr); + + EXPECT_EQ(1u, render_pass->quad_list.size()); + EXPECT_EQ(1u, data.num_missing_tiles); + EXPECT_EQ(0u, data.num_incomplete_tiles); + EXPECT_EQ(0u, data.num_missing_tiles_no_image_content); + EXPECT_EQ(1u, data.num_missing_tiles_some_image_content); + EXPECT_EQ(40000, data.checkerboarded_visible_content_area); + EXPECT_EQ(17500, data.checkerboarded_no_recording_content_area); + EXPECT_EQ(22500, data.checkerboarded_needs_raster_content_area); + EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads()); +} + TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveAllReady) { gfx::Size layer_bounds(400, 400); gfx::Size tile_size(100, 100); @@ -2274,7 +2380,7 @@ TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) { FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_, pending_raster_source); pending_layer->SetDrawsContent(true); - pending_tree->SetRootLayer(pending_layer.Pass()); + pending_tree->SetRootLayer(std::move(pending_layer)); pending_layer_ = static_cast<FakePictureLayerImpl*>( host_impl_.pending_tree()->LayerById(id_)); @@ -3308,23 +3414,22 @@ TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) { starting_animation_scale, animating_transform); EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); - // Changing the source scale without being in an animation will cause - // the layer to reset its source scale to 1.f. + // Changing the source scale without being in an animation should be + // immediately honored. contents_scale = 3.f; SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, maximum_animation_scale, starting_animation_scale, animating_transform); - EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); + EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f); - // Further changes to the source scale will no longer be reflected in the - // contents scale. + // Further changes to the source scale will continue to be honored. contents_scale = 0.5f; SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, maximum_animation_scale, starting_animation_scale, animating_transform); - EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); + EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.5f); } TEST_F(PictureLayerImplTest, LowResReadyToDrawNotEnoughToActivate) { @@ -3578,12 +3683,7 @@ TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { bool resourceless_software_draw = false; gfx::Rect viewport = gfx::Rect(layer_bounds); gfx::Transform transform; - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport, - transform, - resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints(viewport, transform); active_layer_->draw_properties().visible_layer_rect = viewport; active_layer_->draw_properties().screen_space_transform = transform; active_layer_->UpdateTiles(resourceless_software_draw); @@ -3592,7 +3692,7 @@ TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { active_layer_->visible_rect_for_tile_priority(); EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); gfx::Transform screen_space_transform_for_tile_priority = - active_layer_->screen_space_transform(); + active_layer_->draw_properties().screen_space_transform; // Expand viewport and set it as invalid for prioritizing tiles. // Should update viewport and transform, but not update visible rect. @@ -3602,17 +3702,12 @@ TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { transform.Translate(1.f, 1.f); active_layer_->draw_properties().visible_layer_rect = viewport; active_layer_->draw_properties().screen_space_transform = transform; - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport, - transform, - resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints(viewport, transform); active_layer_->UpdateTiles(resourceless_software_draw); // Transform for tile priority is updated. - EXPECT_TRANSFORMATION_MATRIX_EQ(transform, - active_layer_->screen_space_transform()); + EXPECT_TRANSFORMATION_MATRIX_EQ( + transform, active_layer_->draw_properties().screen_space_transform); // Visible rect for tile priority retains old value. EXPECT_EQ(visible_rect_for_tile_priority, active_layer_->visible_rect_for_tile_priority()); @@ -3620,16 +3715,11 @@ TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { // Keep expanded viewport but mark it valid. Should update tile viewport. host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); resourceless_software_draw = false; - host_impl_.SetExternalDrawConstraints(transform, - viewport, - viewport, - viewport, - transform, - resourceless_software_draw); + host_impl_.SetExternalTilePriorityConstraints(viewport, transform); active_layer_->UpdateTiles(resourceless_software_draw); - EXPECT_TRANSFORMATION_MATRIX_EQ(transform, - active_layer_->screen_space_transform()); + EXPECT_TRANSFORMATION_MATRIX_EQ( + transform, active_layer_->draw_properties().screen_space_transform); EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority()); } @@ -3694,52 +3784,58 @@ TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); - // Now move the ideal scale to 0.5. Our target stays 1.2. + // Now move the ideal scale to 0.5. SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, 0.f, false); + ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); - // The high resolution tiling is between target and ideal, so is not - // removed. The low res tiling for the old ideal=1.0 scale is removed. - used_tilings.clear(); - active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); - ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); - - // Now move the ideal scale to 1.0. Our target stays 1.2. - SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, 0.f, false); + // And begin an animation to 1.2. There are now 3 tilings, 0.5, 1.0 and 1.2. + // The the 0.5 is ideal, but the 1.2 is high res. 1.0 sits between them. + // high-res tiling is in the middle. + SetContentsScaleOnBothLayers(0.5, device_scale, page_scale, 1.2f, 0.f, true); + EXPECT_EQ(HIGH_RESOLUTION, + active_layer_->tilings()->tiling_at(0)->resolution()); + EXPECT_EQ(1.2f, // High-res, though not the ideal scale. + active_layer_->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ(1.f, // Tiling in the middle attack. + active_layer_->tilings()->tiling_at(1)->contents_scale()); + EXPECT_EQ(0.5f, // Ideal scale, but not considered high-res. + active_layer_->tilings()->tiling_at(2)->contents_scale()); - // All the tilings are between are target and the ideal, so they are not + // The high resolution tiling is between target and ideal, so is not // removed. used_tilings.clear(); active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); - ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); + ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); - // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. - SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.1f, device_scale, - page_scale, 1.f, 0.f, false); + // Now move the ideal scale to 1.0 on the active layer. The high-res tiling + // stays 1.2. + SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, device_scale, + page_scale, 1.2f, 0.f, true); - // Because the pending layer's ideal scale is still 1.0, our tilings fall - // in the range [1.0,1.2] and are kept. + // Because the pending layer's ideal scale is still 0.5, all tilings fall + // in the range [0.5,1.2] and are kept. used_tilings.clear(); active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); - ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); + ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); - // Move the ideal scale on the pending layer to 1.1 as well. Our target stays - // 1.2 still. - SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.1f, device_scale, + // Move the ideal scale on the pending layer to 1.0 as well. Our high-res + // stays 1.2 still. + SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, device_scale, page_scale, 1.f, 0.f, false); - // Our 1.0 tiling now falls outside the range between our ideal scale and our - // target raster scale. But it is in our used tilings set, so nothing is + // Our 0.5 tiling now falls outside the range between our ideal scale and our + // high-res raster scale. But it is in our used tilings set, so nothing is // deleted. used_tilings.clear(); - used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); + used_tilings.push_back(active_layer_->tilings()->tiling_at(2)); active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); - ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); + ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); // If we remove it from our used tilings set, it is outside the range to keep // so it is deleted. used_tilings.clear(); active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); - ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); + ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); } TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) { @@ -3783,7 +3879,7 @@ TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) { float max_contents_scale = active_layer_->MaximumTilingContentsScale(); EXPECT_EQ(2.5f, max_contents_scale); - gfx::Transform scaled_draw_transform = active_layer_->draw_transform(); + gfx::Transform scaled_draw_transform = active_layer_->DrawTransform(); scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, SK_MScalar1 / max_contents_scale); @@ -3816,6 +3912,7 @@ class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest { } void InitializeRenderer() override { + host_impl_.SetVisible(true); host_impl_.InitializeRenderer(output_surface_.get()); } }; @@ -3930,7 +4027,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, gfx::Size tile_size(102, 102); gfx::Size layer_bounds(1000, 1000); gfx::Size viewport_size(500, 500); - gfx::Point occluding_layer_position(310, 0); + gfx::PointF occluding_layer_position(310.f, 0.f); host_impl_.SetViewportSize(viewport_size); @@ -3961,12 +4058,13 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, // Partial occlusion. pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); - LayerImpl* layer1 = pending_layer_->children()[0]; + LayerImpl* layer1 = pending_layer_->children()[0].get(); layer1->SetBounds(layer_bounds); layer1->SetDrawsContent(true); layer1->SetContentsOpaque(true); layer1->SetPosition(occluding_layer_position); + RebuildPropertyTreesOnPendingTree(); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); bool update_lcd_text = false; host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); @@ -3989,8 +4087,9 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, EXPECT_EQ(20, unoccluded_tile_count); // Full occlusion. - layer1->SetPosition(gfx::Point(0, 0)); + layer1->SetPosition(gfx::PointF()); + RebuildPropertyTreesOnPendingTree(); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); @@ -4019,7 +4118,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, gfx::Size tile_size(102, 102); gfx::Size layer_bounds(1000, 1000); gfx::Size viewport_size(500, 500); - gfx::Point occluding_layer_position(310, 0); + gfx::PointF occluding_layer_position(310.f, 0.f); host_impl_.SetViewportSize(viewport_size); @@ -4053,12 +4152,13 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, // Partial occlusion. pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); - LayerImpl* layer1 = pending_layer_->children()[0]; + LayerImpl* layer1 = pending_layer_->children()[0].get(); layer1->SetBounds(layer_bounds); layer1->SetDrawsContent(true); layer1->SetContentsOpaque(true); layer1->SetPosition(occluding_layer_position); + RebuildPropertyTreesOnPendingTree(); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); bool update_lcd_text = false; host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); @@ -4094,8 +4194,9 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, } // Full occlusion. - layer1->SetPosition(gfx::PointF(0, 0)); + layer1->SetPosition(gfx::PointF()); + RebuildPropertyTreesOnPendingTree(); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); @@ -4136,7 +4237,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) { gfx::Size tile_size(102, 102); gfx::Size layer_bounds(1000, 1000); gfx::Size viewport_size(500, 500); - gfx::Point occluding_layer_position(310, 0); + gfx::PointF occluding_layer_position(310.f, 0.f); scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = FakeDisplayListRasterSource::CreateFilled(layer_bounds); @@ -4147,7 +4248,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) { ASSERT_TRUE(pending_layer_->CanHaveTilings()); pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); - LayerImpl* layer1 = pending_layer_->children()[0]; + LayerImpl* layer1 = pending_layer_->children()[0].get(); layer1->SetBounds(layer_bounds); layer1->SetDrawsContent(true); layer1->SetContentsOpaque(true); @@ -4161,6 +4262,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) { pending_layer_->AddTiling(1.0f)->set_resolution(HIGH_RESOLUTION); pending_layer_->AddTiling(2.0f)->set_resolution(HIGH_RESOLUTION); + RebuildPropertyTreesOnPendingTree(); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); // UpdateDrawProperties with the occluding layer. bool update_lcd_text = false; @@ -4208,7 +4310,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) { TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) { gfx::Size layer_bounds(1000, 1000); gfx::Size viewport_size(1000, 1000); - gfx::Point occluding_layer_position(310, 0); + gfx::PointF occluding_layer_position(310.f, 0.f); gfx::Rect invalidation_rect(230, 230, 102, 102); scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = @@ -4221,7 +4323,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) { // Partially occlude the active layer. pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2)); - LayerImpl* layer1 = pending_layer_->children()[0]; + LayerImpl* layer1 = pending_layer_->children()[0].get(); layer1->SetBounds(layer_bounds); layer1->SetDrawsContent(true); layer1->SetContentsOpaque(true); @@ -4298,8 +4400,8 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, gfx::Size tile_size(102, 102); gfx::Size layer_bounds(1000, 1000); gfx::Size viewport_size(1000, 1000); - gfx::Point pending_occluding_layer_position(310, 0); - gfx::Point active_occluding_layer_position(0, 310); + gfx::PointF pending_occluding_layer_position(310.f, 0.f); + gfx::PointF active_occluding_layer_position(0.f, 310.f); gfx::Rect invalidation_rect(230, 230, 152, 152); host_impl_.SetViewportSize(viewport_size); @@ -4314,7 +4416,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, // Partially occlude the active layer. pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2)); - LayerImpl* active_occluding_layer = pending_layer_->children()[0]; + LayerImpl* active_occluding_layer = pending_layer_->children()[0].get(); active_occluding_layer->SetBounds(layer_bounds); active_occluding_layer->SetDrawsContent(true); active_occluding_layer->SetContentsOpaque(true); @@ -4329,7 +4431,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, // Partially occlude the pending layer in a different way. pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 3)); - LayerImpl* pending_occluding_layer = pending_layer_->children()[0]; + LayerImpl* pending_occluding_layer = pending_layer_->children()[0].get(); pending_occluding_layer->SetBounds(layer_bounds); pending_occluding_layer->SetDrawsContent(true); pending_occluding_layer->SetContentsOpaque(true); @@ -4338,6 +4440,7 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, EXPECT_EQ(1u, pending_layer_->num_tilings()); EXPECT_EQ(2u, active_layer_->num_tilings()); + RebuildPropertyTreesOnPendingTree(); host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); // UpdateDrawProperties with the occluding layer. bool update_lcd_text = false; @@ -4474,6 +4577,7 @@ void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { gfx::Rect layer_rect(layer_bounds); FakeContentLayerClient client; + client.set_bounds(layer_bounds); scoped_refptr<PictureLayer> layer = PictureLayer::Create(layer_settings_, &client); FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); @@ -4481,7 +4585,8 @@ void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client, &task_graph_runner); host->SetRootLayer(layer); - RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); + DisplayListRecordingSource* recording_source = + layer->GetDisplayListRecordingSourceForTesting(); int frame_number = 0; @@ -4490,9 +4595,9 @@ void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { Region invalidation(layer_rect); recording_source->UpdateAndExpandInvalidation( &client, &invalidation, layer_bounds, layer_rect, frame_number++, - RecordingSource::RECORD_NORMALLY); + DisplayListRecordingSource::RECORD_NORMALLY); - scoped_refptr<RasterSource> pending_raster_source = + scoped_refptr<DisplayListRasterSource> pending_raster_source = recording_source->CreateRasterSource(true); SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); @@ -4537,6 +4642,7 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) { gfx::Rect layer_rect(layer_bounds); FakeContentLayerClient client; + client.set_bounds(layer_bounds); scoped_refptr<PictureLayer> layer = PictureLayer::Create(layer_settings_, &client); FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); @@ -4544,7 +4650,8 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) { scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client, &task_graph_runner); host->SetRootLayer(layer); - RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); + DisplayListRecordingSource* recording_source = + layer->GetDisplayListRecordingSourceForTesting(); int frame_number = 0; @@ -4553,9 +4660,9 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) { Region invalidation1(layer_rect); recording_source->UpdateAndExpandInvalidation( &client, &invalidation1, layer_bounds, layer_rect, frame_number++, - RecordingSource::RECORD_NORMALLY); + DisplayListRecordingSource::RECORD_NORMALLY); - scoped_refptr<RasterSource> raster_source1 = + scoped_refptr<DisplayListRasterSource> raster_source1 = recording_source->CreateRasterSource(true); SetupPendingTree(raster_source1); @@ -4572,9 +4679,9 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) { Region invalidation2(layer_rect); recording_source->UpdateAndExpandInvalidation( &client, &invalidation2, layer_bounds, layer_rect, frame_number++, - RecordingSource::RECORD_NORMALLY); + DisplayListRecordingSource::RECORD_NORMALLY); - scoped_refptr<RasterSource> raster_source2 = + scoped_refptr<DisplayListRasterSource> raster_source2 = recording_source->CreateRasterSource(true); SetupPendingTree(raster_source2); @@ -4724,13 +4831,8 @@ TEST_F(PictureLayerImplTest, ScrollPastLiveTilesRectAndBack) { ActivateTree(); EXPECT_TRUE(active_layer_->HighResTiling()->has_tiles()); - host_impl_.SetExternalDrawConstraints( - gfx::Transform(), // transform - gfx::Rect(), // clip - gfx::Rect(), // viewport - gfx::Rect(0, 5000, 100, 100), // viewport_rect_for_tile_priority - gfx::Transform(), // transform_for_tile_priority - false); + host_impl_.SetExternalTilePriorityConstraints(gfx::Rect(0, 5000, 100, 100), + gfx::Transform()); SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, gfx::Rect()); @@ -4741,13 +4843,8 @@ TEST_F(PictureLayerImplTest, ScrollPastLiveTilesRectAndBack) { EXPECT_FALSE(active_layer_->HighResTiling()->has_tiles()); EXPECT_TRUE(active_layer_->HighResTiling()->live_tiles_rect().IsEmpty()); - host_impl_.SetExternalDrawConstraints( - gfx::Transform(), // transform - gfx::Rect(), // clip - gfx::Rect(), // viewport - gfx::Rect(0, 110, 100, 100), // viewport_rect_for_tile_priority - gfx::Transform(), // transform_for_tile_priority - false); + host_impl_.SetExternalTilePriorityConstraints(gfx::Rect(0, 110, 100, 100), + gfx::Transform()); SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, gfx::Rect()); diff --git a/chromium/cc/layers/picture_layer_unittest.cc b/chromium/cc/layers/picture_layer_unittest.cc index cb73d15a5e9..1ce756717bf 100644 --- a/chromium/cc/layers/picture_layer_unittest.cc +++ b/chromium/cc/layers/picture_layer_unittest.cc @@ -4,41 +4,168 @@ #include "cc/layers/picture_layer.h" +#include <stddef.h> + #include "base/thread_task_runner_handle.h" +#include "cc/layers/append_quads_data.h" #include "cc/layers/content_layer_client.h" +#include "cc/layers/empty_content_layer_client.h" +#include "cc/layers/layer_settings.h" #include "cc/layers/picture_layer_impl.h" #include "cc/playback/display_item_list_settings.h" +#include "cc/proto/layer.pb.h" #include "cc/test/fake_display_list_recording_source.h" #include "cc/test/fake_layer_tree_host.h" +#include "cc/test/fake_output_surface.h" #include "cc/test/fake_picture_layer.h" #include "cc/test/fake_picture_layer_impl.h" #include "cc/test/fake_proxy.h" +#include "cc/test/layer_tree_settings_for_testing.h" +#include "cc/test/skia_common.h" #include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_task_graph_runner.h" #include "cc/trees/single_thread_proxy.h" #include "testing/gtest/include/gtest/gtest.h" namespace cc { -namespace { -class MockContentLayerClient : public ContentLayerClient { +class TestSerializationPictureLayer : public PictureLayer { public: - void PaintContents(SkCanvas* canvas, - const gfx::Rect& clip, - PaintingControlSetting picture_control) override {} - scoped_refptr<DisplayItemList> PaintContentsToDisplayList( - const gfx::Rect& clip, - PaintingControlSetting picture_control) override { - return DisplayItemList::Create(clip, DisplayItemListSettings()); + static scoped_refptr<TestSerializationPictureLayer> Create( + const gfx::Size& recording_source_viewport) { + return make_scoped_refptr(new TestSerializationPictureLayer( + LayerSettings(), EmptyContentLayerClient::GetInstance(), + FakeDisplayListRecordingSource::CreateFilledRecordingSource( + recording_source_viewport), + recording_source_viewport)); + } + + FakeDisplayListRecordingSource* recording_source() { + return static_cast<FakeDisplayListRecordingSource*>( + recording_source_.get()); + } + + void set_invalidation(const Region& invalidation) { + *invalidation_.region() = invalidation; } - bool FillsBoundsCompletely() const override { return false; }; - size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } + + void set_last_updated_visible_layer_rect(const gfx::Rect& rect) { + last_updated_visible_layer_rect_ = rect; + } + + void set_update_source_frame_number(int number) { + update_source_frame_number_ = number; + } + + void set_is_mask(bool is_mask) { is_mask_ = is_mask; } + + void set_nearest_neighbor(bool nearest_neighbor) { + nearest_neighbor_ = nearest_neighbor; + } + + void ValidateSerialization() { + proto::LayerProperties proto; + LayerSpecificPropertiesToProto(&proto); + + FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); + TestTaskGraphRunner task_graph_runner; + scoped_ptr<FakeLayerTreeHost> host = + FakeLayerTreeHost::Create(&host_client, &task_graph_runner); + scoped_refptr<TestSerializationPictureLayer> layer = + TestSerializationPictureLayer::Create(recording_source_viewport_); + host->SetRootLayer(layer); + layer->FromLayerSpecificPropertiesProto(proto); + + // Validate that the PictureLayer specific fields are properly set. + EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); + EXPECT_EQ(last_updated_visible_layer_rect_, + layer->last_updated_visible_layer_rect_); + EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); + EXPECT_EQ(is_mask_, layer->is_mask_); + EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); + } + + private: + TestSerializationPictureLayer(const LayerSettings& settings, + ContentLayerClient* client, + scoped_ptr<DisplayListRecordingSource> source, + const gfx::Size& recording_source_viewport) + : PictureLayer(settings, client, std::move(source)), + recording_source_viewport_(recording_source_viewport) {} + ~TestSerializationPictureLayer() override {} + + gfx::Size recording_source_viewport_; + + DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer); }; +namespace { + +TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) { + FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); + TestTaskGraphRunner task_graph_runner; + scoped_ptr<FakeLayerTreeHost> host = + FakeLayerTreeHost::Create(&host_client, &task_graph_runner); + + gfx::Size recording_source_viewport(256, 256); + scoped_refptr<TestSerializationPictureLayer> layer = + TestSerializationPictureLayer::Create(recording_source_viewport); + host->SetRootLayer(layer); + + Region region(gfx::Rect(14, 15, 16, 17)); + layer->set_invalidation(region); + layer->set_last_updated_visible_layer_rect(gfx::Rect(5, 6, 7, 8)); + layer->set_is_mask(true); + layer->set_nearest_neighbor(true); + + layer->SetBounds(recording_source_viewport); + layer->set_update_source_frame_number(0); + layer->recording_source()->SetDisplayListUsesCachedPicture(false); + layer->recording_source()->add_draw_rect( + gfx::Rect(recording_source_viewport)); + layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); + layer->recording_source()->Rerecord(); + layer->ValidateSerialization(); +} + +TEST(PictureLayerTest, TestSerializationDeserialization) { + FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); + TestTaskGraphRunner task_graph_runner; + scoped_ptr<FakeLayerTreeHost> host = + FakeLayerTreeHost::Create(&host_client, &task_graph_runner); + + gfx::Size recording_source_viewport(256, 256); + scoped_refptr<TestSerializationPictureLayer> layer = + TestSerializationPictureLayer::Create(recording_source_viewport); + host->SetRootLayer(layer); + + layer->SetBounds(recording_source_viewport); + layer->set_update_source_frame_number(0); + layer->recording_source()->SetDisplayListUsesCachedPicture(false); + layer->recording_source()->add_draw_rect( + gfx::Rect(recording_source_viewport)); + layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); + layer->recording_source()->Rerecord(); + layer->ValidateSerialization(); +} + +TEST(PictureLayerTest, TestEmptySerializationDeserialization) { + FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); + TestTaskGraphRunner task_graph_runner; + scoped_ptr<FakeLayerTreeHost> host = + FakeLayerTreeHost::Create(&host_client, &task_graph_runner); + + gfx::Size recording_source_viewport(256, 256); + scoped_refptr<TestSerializationPictureLayer> layer = + TestSerializationPictureLayer::Create(recording_source_viewport); + host->SetRootLayer(layer); + layer->ValidateSerialization(); +} + TEST(PictureLayerTest, NoTilesIfEmptyBounds) { - MockContentLayerClient client; + ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); scoped_refptr<PictureLayer> layer = - PictureLayer::Create(LayerSettings(), &client); + PictureLayer::Create(LayerSettings(), client); layer->SetBounds(gfx::Size(10, 10)); FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); @@ -59,23 +186,100 @@ TEST(PictureLayerTest, NoTilesIfEmptyBounds) { // Intentionally skipping Update since it would normally be skipped on // a layer with empty bounds. - FakeProxy proxy; - { - DebugScopedSetImplThread impl_thread(&proxy); - - TestSharedBitmapManager shared_bitmap_manager; - FakeLayerTreeHostImpl host_impl(LayerTreeSettings(), &proxy, - &shared_bitmap_manager, &task_graph_runner); - host_impl.CreatePendingTree(); - scoped_ptr<FakePictureLayerImpl> layer_impl = - FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); - - layer->PushPropertiesTo(layer_impl.get()); - EXPECT_FALSE(layer_impl->CanHaveTilings()); - EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); - EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); - EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); - } + FakeImplTaskRunnerProvider impl_task_runner_provider; + + TestSharedBitmapManager shared_bitmap_manager; + FakeLayerTreeHostImpl host_impl(LayerTreeSettingsForTesting(), + &impl_task_runner_provider, + &shared_bitmap_manager, &task_graph_runner); + host_impl.CreatePendingTree(); + scoped_ptr<FakePictureLayerImpl> layer_impl = + FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); + + layer->PushPropertiesTo(layer_impl.get()); + EXPECT_FALSE(layer_impl->CanHaveTilings()); + EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); + EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); + EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); +} + +TEST(PictureLayerTest, ClearVisibleRectWhenNoTiling) { + gfx::Size layer_size(50, 50); + FakeContentLayerClient client; + client.set_bounds(layer_size); + skia::RefPtr<SkImage> image = CreateDiscardableImage(layer_size); + client.add_draw_image(image.get(), gfx::Point(), SkPaint()); + scoped_refptr<PictureLayer> layer = + PictureLayer::Create(LayerSettings(), &client); + layer->SetBounds(gfx::Size(10, 10)); + + FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); + TestTaskGraphRunner task_graph_runner; + scoped_ptr<FakeLayerTreeHost> host = + FakeLayerTreeHost::Create(&host_client, &task_graph_runner); + host->SetRootLayer(layer); + layer->SetIsDrawable(true); + layer->SavePaintProperties(); + layer->Update(); + + EXPECT_EQ(0, host->source_frame_number()); + host->CommitComplete(); + EXPECT_EQ(1, host->source_frame_number()); + + layer->SavePaintProperties(); + layer->Update(); + + FakeImplTaskRunnerProvider impl_task_runner_provider; + + TestSharedBitmapManager shared_bitmap_manager; + scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); + LayerTreeSettings layer_tree_settings = LayerTreeSettingsForTesting(); + layer_tree_settings.image_decode_tasks_enabled = true; + FakeLayerTreeHostImpl host_impl(layer_tree_settings, + &impl_task_runner_provider, + &shared_bitmap_manager, &task_graph_runner); + host_impl.SetVisible(true); + EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); + + host_impl.CreatePendingTree(); + host_impl.pending_tree()->SetRootLayer( + FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); + + FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( + host_impl.pending_tree()->root_layer()); + + layer->PushPropertiesTo(layer_impl); + + host->CommitComplete(); + EXPECT_EQ(2, host->source_frame_number()); + + host_impl.ActivateSyncTree(); + + // By updating the draw proprties on the active tree, we will set the viewport + // rect for tile priorities to something non-empty. + const bool can_use_lcd_text = false; + host_impl.active_tree()->property_trees()->needs_rebuild = true; + host_impl.active_tree()->BuildPropertyTreesForTesting(); + host_impl.active_tree()->UpdateDrawProperties(can_use_lcd_text); + + layer->SetBounds(gfx::Size(11, 11)); + layer->SavePaintProperties(); + + host_impl.CreatePendingTree(); + layer_impl = static_cast<FakePictureLayerImpl*>( + host_impl.pending_tree()->root_layer()); + + // We should now have invalid contents and should therefore clear the + // recording source. + layer->PushPropertiesTo(layer_impl); + + host_impl.ActivateSyncTree(); + + scoped_ptr<RenderPass> render_pass = RenderPass::Create(); + AppendQuadsData data; + host_impl.active_tree()->root_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); + host_impl.active_tree()->root_layer()->AppendQuads(render_pass.get(), &data); + host_impl.active_tree()->root_layer()->DidDraw(nullptr); } TEST(PictureLayerTest, SuitableForGpuRasterization) { @@ -84,10 +288,10 @@ TEST(PictureLayerTest, SuitableForGpuRasterization) { FakeDisplayListRecordingSource* recording_source = recording_source_owned.get(); - MockContentLayerClient client; + ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); scoped_refptr<FakePictureLayer> layer = FakePictureLayer::CreateWithRecordingSource( - LayerSettings(), &client, recording_source_owned.Pass()); + LayerSettings(), client, std::move(recording_source_owned)); FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); TestTaskGraphRunner task_graph_runner; @@ -100,8 +304,8 @@ TEST(PictureLayerTest, SuitableForGpuRasterization) { gfx::Rect layer_rect(layer_bounds); Region invalidation(layer_rect); recording_source->UpdateAndExpandInvalidation( - &client, &invalidation, layer_bounds, layer_rect, 1, - RecordingSource::RECORD_NORMALLY); + client, &invalidation, layer_bounds, layer_rect, 1, + DisplayListRecordingSource::RECORD_NORMALLY); // Layer is suitable for gpu rasterization by default. EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); @@ -118,7 +322,7 @@ TEST(PictureLayerTest, SuitableForGpuRasterization) { // non-monotonically. This executes that code path under this scenario allowing // for the code to verify correctness with DCHECKs. TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { - LayerTreeSettings settings; + LayerTreeSettingsForTesting settings; settings.single_thread_proxy_scheduler = false; settings.use_zero_copy = true; @@ -127,9 +331,9 @@ TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - MockContentLayerClient client; + ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); scoped_refptr<FakePictureLayer> layer = - FakePictureLayer::Create(LayerSettings(), &client); + FakePictureLayer::Create(LayerSettings(), client); LayerTreeHost::InitParams params; params.client = &host_client1; @@ -139,11 +343,13 @@ TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); scoped_ptr<LayerTreeHost> host1 = LayerTreeHost::CreateSingleThreaded(&host_client1, ¶ms); + host1->SetVisible(true); host_client1.SetLayerTreeHost(host1.get()); params.client = &host_client2; scoped_ptr<LayerTreeHost> host2 = LayerTreeHost::CreateSingleThreaded(&host_client2, ¶ms); + host2->SetVisible(true); host_client2.SetLayerTreeHost(host2.get()); // The PictureLayer is put in one LayerTreeHost. diff --git a/chromium/cc/layers/render_surface_impl.cc b/chromium/cc/layers/render_surface_impl.cc index 560c75c5b51..600206faa08 100644 --- a/chromium/cc/layers/render_surface_impl.cc +++ b/chromium/cc/layers/render_surface_impl.cc @@ -4,6 +4,8 @@ #include "cc/layers/render_surface_impl.h" +#include <stddef.h> + #include <algorithm> #include "base/logging.h" @@ -18,6 +20,8 @@ #include "cc/quads/render_pass_draw_quad.h" #include "cc/quads/shared_quad_state.h" #include "cc/trees/damage_tracker.h" +#include "cc/trees/draw_property_utils.h" +#include "cc/trees/layer_tree_impl.h" #include "cc/trees/occlusion.h" #include "third_party/skia/include/core/SkImageFilter.h" #include "ui/gfx/geometry/rect_conversions.h" @@ -47,6 +51,14 @@ gfx::RectF RenderSurfaceImpl::DrawableContentRect() const { replica_draw_transform_, gfx::RectF(content_rect_))); } + // If the rect has a NaN coordinate, we return empty rect to avoid crashes in + // functions (for example, gfx::ToEnclosedRect) that are called on this rect. + if (std::isnan(drawable_content_rect.x()) || + std::isnan(drawable_content_rect.y()) || + std::isnan(drawable_content_rect.right()) || + std::isnan(drawable_content_rect.bottom())) + return gfx::RectF(); + return drawable_content_rect; } @@ -182,7 +194,7 @@ void RenderSurfaceImpl::AppendRenderPasses(RenderPassSink* pass_sink) { gfx::IntersectRects(content_rect_, damage_tracker_->current_damage_rect()), screen_space_transform_); - pass_sink->AppendRenderPass(pass.Pass()); + pass_sink->AppendRenderPass(std::move(pass)); } void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass, @@ -216,12 +228,13 @@ void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass, ResourceId mask_resource_id = 0; gfx::Size mask_texture_size; gfx::Vector2dF mask_uv_scale; + gfx::Transform owning_layer_draw_transform = owning_layer_->DrawTransform(); if (mask_layer && mask_layer->DrawsContent() && !mask_layer->bounds().IsEmpty()) { mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size); gfx::Vector2dF owning_layer_draw_scale = - MathUtil::ComputeTransform2dScaleComponents( - owning_layer_->draw_transform(), 1.f); + MathUtil::ComputeTransform2dScaleComponents(owning_layer_draw_transform, + 1.f); gfx::SizeF unclipped_mask_target_size = gfx::ScaleSize( gfx::SizeF(owning_layer_->bounds()), owning_layer_draw_scale.x(), owning_layer_draw_scale.y()); @@ -230,9 +243,9 @@ void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass, content_rect_.height() / unclipped_mask_target_size.height()); } - DCHECK(owning_layer_->draw_properties().target_space_transform.IsScale2d()); + DCHECK(owning_layer_draw_transform.IsScale2d()); gfx::Vector2dF owning_layer_to_target_scale = - owning_layer_->draw_properties().target_space_transform.Scale2d(); + owning_layer_draw_transform.Scale2d(); RenderPassDrawQuad* quad = render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); diff --git a/chromium/cc/layers/render_surface_impl.h b/chromium/cc/layers/render_surface_impl.h index 283f0eb47b6..9ba0f1870bb 100644 --- a/chromium/cc/layers/render_surface_impl.h +++ b/chromium/cc/layers/render_surface_impl.h @@ -5,10 +5,12 @@ #ifndef CC_LAYERS_RENDER_SURFACE_IMPL_H_ #define CC_LAYERS_RENDER_SURFACE_IMPL_H_ +#include <stddef.h> + #include <string> #include <vector> -#include "base/basictypes.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_lists.h" diff --git a/chromium/cc/layers/render_surface_impl_unittest.cc b/chromium/cc/layers/render_surface_impl_unittest.cc index ac406758501..e8eb264460f 100644 --- a/chromium/cc/layers/render_surface_impl_unittest.cc +++ b/chromium/cc/layers/render_surface_impl_unittest.cc @@ -4,6 +4,11 @@ #include "cc/layers/render_surface_impl.h" +#include <stddef.h> + +#include "cc/layers/append_quads_data.h" +#include "cc/quads/render_pass_draw_quad.h" +#include "cc/test/fake_mask_layer_impl.h" #include "cc/test/layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" @@ -19,7 +24,7 @@ TEST(RenderSurfaceLayerImplTest, Occlusion) { LayerImpl* owning_layer_impl = impl.AddChildToRoot<LayerImpl>(); owning_layer_impl->SetBounds(layer_size); owning_layer_impl->SetDrawsContent(true); - owning_layer_impl->SetHasRenderSurface(true); + owning_layer_impl->SetForceRenderSurface(true); impl.CalcDrawProps(viewport_size); @@ -59,5 +64,56 @@ TEST(RenderSurfaceLayerImplTest, Occlusion) { } } +TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) { + gfx::Size layer_size(1000, 1000); + gfx::Size viewport_size(1000, 1000); + + LayerTestCommon::LayerImplTest impl; + scoped_ptr<LayerImpl> root = + LayerImpl::Create(impl.host_impl()->active_tree(), 2); + root->SetHasRenderSurface(true); + scoped_ptr<LayerImpl> surface = + LayerImpl::Create(impl.host_impl()->active_tree(), 3); + surface->SetBounds(layer_size); + surface->SetHasRenderSurface(true); + + gfx::Transform scale; + scale.Scale(2, 2); + surface->SetTransform(scale); + + surface->SetMaskLayer( + FakeMaskLayerImpl::Create(impl.host_impl()->active_tree(), 4)); + surface->mask_layer()->SetDrawsContent(true); + surface->mask_layer()->SetBounds(layer_size); + + scoped_ptr<LayerImpl> child = + LayerImpl::Create(impl.host_impl()->active_tree(), 5); + child->SetDrawsContent(true); + child->SetBounds(layer_size); + + surface->AddChild(std::move(child)); + root->AddChild(std::move(surface)); + impl.host_impl()->active_tree()->SetRootLayer(std::move(root)); + + impl.host_impl()->SetViewportSize(viewport_size); + impl.host_impl()->active_tree()->BuildPropertyTreesForTesting(); + impl.host_impl()->active_tree()->UpdateDrawProperties(false); + + LayerImpl* surface_raw = + impl.host_impl()->active_tree()->root_layer()->children()[0].get(); + RenderSurfaceImpl* render_surface_impl = surface_raw->render_surface(); + scoped_ptr<RenderPass> render_pass = RenderPass::Create(); + AppendQuadsData append_quads_data; + render_surface_impl->AppendQuads( + render_pass.get(), render_surface_impl->draw_transform(), Occlusion(), + SK_ColorBLACK, 1.f, surface_raw->mask_layer(), &append_quads_data, + RenderPassId(1, 1)); + + const RenderPassDrawQuad* quad = + RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front()); + EXPECT_EQ(gfx::Vector2dF(1.f, 1.f), quad->mask_uv_scale); + EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale); +} + } // namespace } // namespace cc diff --git a/chromium/cc/layers/render_surface_unittest.cc b/chromium/cc/layers/render_surface_unittest.cc index 5ecf2f7bac8..a237bcb3ada 100644 --- a/chromium/cc/layers/render_surface_unittest.cc +++ b/chromium/cc/layers/render_surface_unittest.cc @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "cc/base/scoped_ptr_vector.h" #include "cc/layers/append_quads_data.h" #include "cc/layers/layer_impl.h" #include "cc/layers/render_pass_sink.h" #include "cc/layers/render_surface_impl.h" #include "cc/quads/shared_quad_state.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/mock_occlusion_tracker.h" @@ -37,10 +36,10 @@ TEST(RenderSurfaceTest, VerifySurfaceChangesAreTrackedProperly) { // This test checks that SurfacePropertyChanged() has the correct behavior. // - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, &task_graph_runner); scoped_ptr<LayerImpl> owning_layer = LayerImpl::Create(host_impl.active_tree(), 1); @@ -84,10 +83,10 @@ TEST(RenderSurfaceTest, VerifySurfaceChangesAreTrackedProperly) { } TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectSharedQuadState) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, &task_graph_runner); scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(host_impl.active_tree(), 1); @@ -102,7 +101,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectSharedQuadState) { owning_layer->SetBlendMode(blend_mode); RenderSurfaceImpl* render_surface = owning_layer->render_surface(); - root_layer->AddChild(owning_layer.Pass()); + root_layer->AddChild(std::move(owning_layer)); gfx::Rect content_rect(0, 0, 50, 50); gfx::Rect clip_rect(5, 5, 40, 40); @@ -139,7 +138,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectSharedQuadState) { class TestRenderPassSink : public RenderPassSink { public: void AppendRenderPass(scoped_ptr<RenderPass> render_pass) override { - render_passes_.push_back(render_pass.Pass()); + render_passes_.push_back(std::move(render_pass)); } const RenderPassList& RenderPasses() const { @@ -151,10 +150,10 @@ class TestRenderPassSink : public RenderPassSink { }; TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectRenderPass) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, &task_graph_runner); scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(host_impl.active_tree(), 1); @@ -166,7 +165,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectRenderPass) { owning_layer->draw_properties().render_target = owning_layer.get(); RenderSurfaceImpl* render_surface = owning_layer->render_surface(); - root_layer->AddChild(owning_layer.Pass()); + root_layer->AddChild(std::move(owning_layer)); gfx::Rect content_rect(0, 0, 50, 50); gfx::Transform origin; @@ -180,7 +179,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectRenderPass) { render_surface->AppendRenderPasses(&pass_sink); ASSERT_EQ(1u, pass_sink.RenderPasses().size()); - RenderPass* pass = pass_sink.RenderPasses()[0]; + RenderPass* pass = pass_sink.RenderPasses()[0].get(); EXPECT_EQ(RenderPassId(2, 0), pass->id); EXPECT_EQ(content_rect, pass->output_rect); diff --git a/chromium/cc/layers/scrollbar_layer_impl_base.cc b/chromium/cc/layers/scrollbar_layer_impl_base.cc index 6696e498bd0..e8e0f80a18c 100644 --- a/chromium/cc/layers/scrollbar_layer_impl_base.cc +++ b/chromium/cc/layers/scrollbar_layer_impl_base.cc @@ -17,29 +17,27 @@ ScrollbarLayerImplBase::ScrollbarLayerImplBase( bool is_left_side_vertical_scrollbar, bool is_overlay) : LayerImpl(tree_impl, id), - scroll_layer_(nullptr), - clip_layer_(nullptr), + scroll_layer_id_(Layer::INVALID_ID), is_overlay_scrollbar_(is_overlay), thumb_thickness_scale_factor_(1.f), current_pos_(0.f), - maximum_(0), + clip_layer_length_(0.f), + scroll_layer_length_(0.f), orientation_(orientation), is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar), - vertical_adjust_(0.f), - visible_to_total_length_ratio_(1.f) { -} + vertical_adjust_(0.f) {} -ScrollbarLayerImplBase::~ScrollbarLayerImplBase() {} +ScrollbarLayerImplBase::~ScrollbarLayerImplBase() { + layer_tree_impl()->UnregisterScrollbar(this); +} void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { float active_opacity = layer->opacity(); - bool active_hidden = layer->hide_layer_and_subtree(); LayerImpl::PushPropertiesTo(layer); layer->SetOpacity(active_opacity); - layer->SetHideLayerAndSubtree(active_hidden); DCHECK(layer->ToScrollbarLayer()); layer->ToScrollbarLayer()->set_is_overlay_scrollbar(is_overlay_scrollbar_); - PushScrollClipPropertiesTo(layer); + layer->ToScrollbarLayer()->SetScrollLayerId(ScrollLayerId()); } void ScrollbarLayerImplBase::DidBecomeActive() { @@ -47,56 +45,19 @@ void ScrollbarLayerImplBase::DidBecomeActive() { UpdatePropertyTreeOpacity(); } -void ScrollbarLayerImplBase::PushScrollClipPropertiesTo(LayerImpl* layer) { - DCHECK(layer->ToScrollbarLayer()); - layer->ToScrollbarLayer()->SetScrollLayerAndClipLayerByIds(ScrollLayerId(), - ClipLayerId()); -} - ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { return this; } -namespace { - -typedef void (LayerImpl::*ScrollbarRegistrationOperation)( - ScrollbarLayerImplBase*); - -void RegisterScrollbarWithLayers(ScrollbarLayerImplBase* scrollbar, - LayerImpl* container_layer, - LayerImpl* scroll_layer, - ScrollbarRegistrationOperation operation) { - if (!container_layer || !scroll_layer) +void ScrollbarLayerImplBase::SetScrollLayerId(int scroll_layer_id) { + if (scroll_layer_id_ == scroll_layer_id) return; - DCHECK(scrollbar); - - // Scrollbars must be notifed of changes to their scroll and container layers - // and all scrollable layers in between. - for (LayerImpl* current_layer = scroll_layer; - current_layer && current_layer != container_layer->parent(); - current_layer = current_layer->parent()) { - (current_layer->*operation)(scrollbar); - } -} -} // namespace - -void ScrollbarLayerImplBase::SetScrollLayerAndClipLayerByIds( - int scroll_layer_id, - int clip_layer_id) { - LayerImpl* scroll_layer = layer_tree_impl()->LayerById(scroll_layer_id); - LayerImpl* clip_layer = layer_tree_impl()->LayerById(clip_layer_id); - if (scroll_layer_ == scroll_layer && clip_layer_ == clip_layer) - return; + layer_tree_impl()->UnregisterScrollbar(this); - RegisterScrollbarWithLayers( - this, clip_layer_, scroll_layer_, &LayerImpl::RemoveScrollbar); - scroll_layer_ = scroll_layer; - clip_layer_ = clip_layer; - RegisterScrollbarWithLayers( - this, clip_layer_, scroll_layer_, &LayerImpl::AddScrollbar); + scroll_layer_id_ = scroll_layer_id; - ScrollbarParametersDidChange(false); + layer_tree_impl()->RegisterScrollbar(this); } bool ScrollbarLayerImplBase::SetCurrentPos(float current_pos) { @@ -107,18 +68,12 @@ bool ScrollbarLayerImplBase::SetCurrentPos(float current_pos) { return true; } -bool ScrollbarLayerImplBase::SetMaximum(int maximum) { - if (maximum_ == maximum) - return false; - maximum_ = maximum; - NoteLayerPropertyChanged(); - return true; -} - bool ScrollbarLayerImplBase::CanScrollOrientation() const { - if (!scroll_layer_) + LayerImpl* scroll_layer = layer_tree_impl()->LayerById(scroll_layer_id_); + if (!scroll_layer) return false; - return scroll_layer_->user_scrollable(orientation()) && (0 < maximum()); + return scroll_layer->user_scrollable(orientation()) && + clip_layer_length_ < scroll_layer_length_; } bool ScrollbarLayerImplBase::SetVerticalAdjust(float vertical_adjust) { @@ -129,13 +84,18 @@ bool ScrollbarLayerImplBase::SetVerticalAdjust(float vertical_adjust) { return true; } -bool ScrollbarLayerImplBase::SetVisibleToTotalLengthRatio(float ratio) { - if (!IsThumbResizable()) +bool ScrollbarLayerImplBase::SetClipLayerLength(float clip_layer_length) { + if (clip_layer_length_ == clip_layer_length) return false; + clip_layer_length_ = clip_layer_length; + NoteLayerPropertyChanged(); + return true; +} - if (visible_to_total_length_ratio_ == ratio) +bool ScrollbarLayerImplBase::SetScrollLayerLength(float scroll_layer_length) { + if (scroll_layer_length_ == scroll_layer_length) return false; - visible_to_total_length_ratio_ = ratio; + scroll_layer_length_ = scroll_layer_length; NoteLayerPropertyChanged(); return true; } @@ -213,14 +173,14 @@ gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRect() const { float track_length = TrackLength(); int thumb_length = ThumbLength(); int thumb_thickness = ThumbThickness(); + float maximum = scroll_layer_length_ - clip_layer_length_; // With the length known, we can compute the thumb's position. - float clamped_current_pos = - std::min(std::max(current_pos_, 0.f), static_cast<float>(maximum_)); + float clamped_current_pos = std::min(std::max(current_pos_, 0.f), maximum); int thumb_offset = TrackStart(); - if (maximum_ > 0) { - float ratio = clamped_current_pos / maximum_; + if (maximum > 0) { + float ratio = clamped_current_pos / maximum; float max_offset = track_length - thumb_length; thumb_offset += static_cast<int>(ratio * max_offset); } @@ -247,11 +207,4 @@ gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRect() const { return gfx::ToEnclosingRect(thumb_rect); } -void ScrollbarLayerImplBase::ScrollbarParametersDidChange(bool on_resize) { - if (!clip_layer_ || !scroll_layer_) - return; - - scroll_layer_->SetScrollbarPosition(this, clip_layer_, on_resize); -} - } // namespace cc diff --git a/chromium/cc/layers/scrollbar_layer_impl_base.h b/chromium/cc/layers/scrollbar_layer_impl_base.h index 339dcc9f890..79a18e5a28c 100644 --- a/chromium/cc/layers/scrollbar_layer_impl_base.h +++ b/chromium/cc/layers/scrollbar_layer_impl_base.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_SCROLLBAR_LAYER_IMPL_BASE_H_ #define CC_LAYERS_SCROLLBAR_LAYER_IMPL_BASE_H_ +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/input/scrollbar.h" #include "cc/layers/layer.h" @@ -16,24 +17,20 @@ class LayerTreeImpl; class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { public: - int ScrollLayerId() const { - return scroll_layer_ ? scroll_layer_->id() : Layer::INVALID_ID; - } - int ClipLayerId() const { - return clip_layer_ ? clip_layer_->id() : Layer::INVALID_ID; - } + int ScrollLayerId() const { return scroll_layer_id_; } - void SetScrollLayerAndClipLayerByIds(int scroll_layer_id, int clip_layer_id); - void ClearScrollLayer() { scroll_layer_ = nullptr; } - void ClearClipLayer() { clip_layer_ = nullptr; } + void SetScrollLayerId(int scroll_layer_id); float current_pos() const { return current_pos_; } bool SetCurrentPos(float current_pos); - int maximum() const { return maximum_; } - bool SetMaximum(int maximum); - + bool SetClipLayerLength(float clip_layer_length); + bool SetScrollLayerLength(float scroll_layer_length); bool SetVerticalAdjust(float vertical_adjust); + float clip_layer_length() const { return clip_layer_length_; } + float scroll_layer_length() const { return scroll_layer_length_; } + float vertical_adjust() const { return vertical_adjust_; } + bool is_overlay_scrollbar() const { return is_overlay_scrollbar_; } void set_is_overlay_scrollbar(bool is_overlay) { is_overlay_scrollbar_ = is_overlay; @@ -49,9 +46,7 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { void PushPropertiesTo(LayerImpl* layer) override; void DidBecomeActive() override; ScrollbarLayerImplBase* ToScrollbarLayer() override; - void PushScrollClipPropertiesTo(LayerImpl* layer); - bool SetVisibleToTotalLengthRatio(float ratio); // Thumb quad rect in layer space. virtual gfx::Rect ComputeThumbQuadRect() const; @@ -60,8 +55,6 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { } bool SetThumbThicknessScaleFactor(float thumb_thickness_scale_factor); - void ScrollbarParametersDidChange(bool on_resize); - protected: ScrollbarLayerImplBase(LayerTreeImpl* tree_impl, int id, @@ -70,11 +63,6 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { bool is_overlay); ~ScrollbarLayerImplBase() override; - float visible_to_total_length_ratio() const { - return visible_to_total_length_ratio_; - } - float vertical_adjust() const { return vertical_adjust_; } - virtual int ThumbThickness() const = 0; virtual int ThumbLength() const = 0; virtual float TrackLength() const = 0; @@ -84,13 +72,13 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { virtual bool IsThumbResizable() const = 0; private: - LayerImpl* scroll_layer_; - LayerImpl* clip_layer_; + int scroll_layer_id_; bool is_overlay_scrollbar_; float thumb_thickness_scale_factor_; float current_pos_; - int maximum_; + float clip_layer_length_; + float scroll_layer_length_; ScrollbarOrientation orientation_; bool is_left_side_vertical_scrollbar_; @@ -98,11 +86,11 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { // height (which may differ in the presence of top-controls hiding). float vertical_adjust_; - float visible_to_total_length_ratio_; - DISALLOW_COPY_AND_ASSIGN(ScrollbarLayerImplBase); }; +typedef std::set<ScrollbarLayerImplBase*> ScrollbarSet; + } // namespace cc #endif // CC_LAYERS_SCROLLBAR_LAYER_IMPL_BASE_H_ diff --git a/chromium/cc/layers/scrollbar_layer_interface.h b/chromium/cc/layers/scrollbar_layer_interface.h index e76fc27aeb7..5a386b05c02 100644 --- a/chromium/cc/layers/scrollbar_layer_interface.h +++ b/chromium/cc/layers/scrollbar_layer_interface.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_SCROLLBAR_LAYER_INTERFACE_H_ #define CC_LAYERS_SCROLLBAR_LAYER_INTERFACE_H_ +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/input/scrollbar.h" @@ -17,8 +18,6 @@ class CC_EXPORT ScrollbarLayerInterface { public: virtual int ScrollLayerId() const = 0; virtual void SetScrollLayer(int layer_id) = 0; - virtual void SetClipLayer(int layer_id) = 0; - virtual void PushScrollClipPropertiesTo(LayerImpl* layer) = 0; virtual ScrollbarOrientation orientation() const = 0; diff --git a/chromium/cc/layers/scrollbar_layer_unittest.cc b/chromium/cc/layers/scrollbar_layer_unittest.cc index a0d20a58ba4..b9fc9ae4e02 100644 --- a/chromium/cc/layers/scrollbar_layer_unittest.cc +++ b/chromium/cc/layers/scrollbar_layer_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stddef.h> + #include "base/containers/hash_tables.h" #include "base/thread_task_runner_handle.h" #include "cc/animation/scrollbar_animation_controller.h" @@ -12,7 +14,7 @@ #include "cc/layers/solid_color_scrollbar_layer.h" #include "cc/layers/solid_color_scrollbar_layer_impl.h" #include "cc/quads/solid_color_draw_quad.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_impl.h" @@ -50,10 +52,9 @@ LayerImpl* LayerImplForScrollAreaAndScrollbar(const LayerSettings& settings, settings, scrollbar->Orientation(), thumb_thickness, track_start, kIsLeftSideVerticalScrollbar, child1->id()); } else { - child2 = - PaintedScrollbarLayer::Create(settings, scrollbar.Pass(), child1->id()); + child2 = PaintedScrollbarLayer::Create(settings, std::move(scrollbar), + child1->id()); } - child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); layer_tree_root->AddChild(child1); layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); host->SetRootLayer(layer_tree_root); @@ -64,7 +65,7 @@ class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { public: FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client, LayerTreeHost::InitParams* params) - : FakeLayerTreeHost(client, params), + : FakeLayerTreeHost(client, params, CompositorMode::SingleThreaded), next_id_(1), total_ui_resource_created_(0), total_ui_resource_deleted_(0) { @@ -129,6 +130,7 @@ class ScrollbarLayerTest : public testing::Test { layer_tree_host_.reset( new FakeResourceTrackingLayerTreeHost(&fake_client_, ¶ms)); + layer_tree_host_->SetVisible(true); fake_client_.SetLayerTreeHost(layer_tree_host_.get()); // Force output surface creation for renderer capabilities. layer_tree_host_->Composite(base::TimeTicks()); @@ -145,69 +147,37 @@ class ScrollbarLayerTest : public testing::Test { scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; }; -TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer) { - scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); - LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( - layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, - 0, 0); - - LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; - PaintedScrollbarLayerImpl* cc_child2 = - static_cast<PaintedScrollbarLayerImpl*>( - layer_impl_tree_root->children()[1]); - - EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); - EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); -} - -TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { - scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); - LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( - layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), true, false, - 0, 0); - - PaintedScrollbarLayerImpl* cc_child1 = - static_cast<PaintedScrollbarLayerImpl*>( - layer_impl_tree_root->children()[0]); - LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; - - EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); - EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); -} - TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { // Create and attach a non-overlay scrollbar. scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( - layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, - 0, 0); + layer_settings(), layer_tree_host_.get(), std::move(scrollbar), false, + false, 0, 0); PaintedScrollbarLayerImpl* scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( - layer_impl_tree_root->children()[1]); + layer_impl_tree_root->children()[1].get()); // When the scrollbar is not an overlay scrollbar, the scroll should be // responded to on the main thread as the compositor does not yet implement // scrollbar scrolling. - EXPECT_EQ( - InputHandler::SCROLL_ON_MAIN_THREAD, - scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, - SCROLL_BLOCKS_ON_NONE)); + EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, + scrollbar_layer_impl->TryScroll( + gfx::PointF(), InputHandler::GESTURE, SCROLL_BLOCKS_ON_NONE)); // Create and attach an overlay scrollbar. scrollbar.reset(new FakeScrollbar(false, false, true)); layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( - layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, - 0, 0); + layer_settings(), layer_tree_host_.get(), std::move(scrollbar), false, + false, 0, 0); scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( - layer_impl_tree_root->children()[1]); + layer_impl_tree_root->children()[1].get()); // The user shouldn't be able to drag an overlay scrollbar and the scroll // may be handled in the compositor. - EXPECT_EQ( - InputHandler::SCROLL_IGNORED, - scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, - SCROLL_BLOCKS_ON_NONE)); + EXPECT_EQ(InputHandler::SCROLL_IGNORED, + scrollbar_layer_impl->TryScroll( + gfx::PointF(), InputHandler::GESTURE, SCROLL_BLOCKS_ON_NONE)); } TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { @@ -216,7 +186,7 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings()); scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create( - layer_settings(), scrollbar.Pass(), layer_tree_root->id()); + layer_settings(), std::move(scrollbar), layer_tree_root->id()); // Choose bounds to give max_scroll_offset = (30, 50). layer_tree_root->SetBounds(gfx::Size(70, 150)); @@ -230,7 +200,6 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { scroll_layer->AddChild(content_layer); layer_tree_root->AddChild(scrollbar_layer); scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); - scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); layer_tree_root->SavePaintProperties(); content_layer->SavePaintProperties(); @@ -240,10 +209,11 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { ScrollbarLayerImplBase* cc_scrollbar_layer = static_cast<PaintedScrollbarLayerImpl*>( - layer_impl_tree_root->children()[1]); + layer_impl_tree_root->children()[1].get()); EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); - EXPECT_EQ(30, cc_scrollbar_layer->maximum()); + EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() - + cc_scrollbar_layer->clip_layer_length()); layer_tree_root->SetBounds(gfx::Size(700, 1500)); layer_tree_root->SavePaintProperties(); @@ -253,20 +223,19 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { content_layer->SetBounds(gfx::Size(1000, 2000)); content_layer->SavePaintProperties(); - ScrollbarAnimationController* scrollbar_controller = - layer_impl_tree_root->scrollbar_animation_controller(); + layer_tree_host_->UpdateLayers(); layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree(); - EXPECT_EQ(scrollbar_controller, - layer_impl_tree_root->scrollbar_animation_controller()); EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); - EXPECT_EQ(300, cc_scrollbar_layer->maximum()); + EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - + cc_scrollbar_layer->clip_layer_length()); - LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; + LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0].get(); scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); - EXPECT_EQ(300, cc_scrollbar_layer->maximum()); + EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - + cc_scrollbar_layer->clip_layer_length()); } #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ @@ -274,10 +243,9 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { scrollbar_layer->UpdateInternalContentScale(); \ scrollbar_layer->UpdateThumbAndTrackGeometry(); \ root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ - root_layer_impl = root_clip_layer_impl->children()[0]; \ + root_layer_impl = root_clip_layer_impl->children()[0].get(); \ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ - root_layer_impl->children()[1]); \ - scrollbar_layer_impl->ScrollbarParametersDidChange(false); \ + root_layer_impl->children()[1].get()); \ } while (false) TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { @@ -302,7 +270,6 @@ TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); scrollbar_layer->SetBounds(gfx::Size(70, 10)); scrollbar_layer->SetScrollLayer(root_layer->id()); - scrollbar_layer->SetClipLayer(root_clip_layer->id()); scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); @@ -344,7 +311,6 @@ TEST_F(ScrollbarLayerTest, ThumbRect) { root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); scrollbar_layer->SetBounds(gfx::Size(70, 10)); scrollbar_layer->SetScrollLayer(root_layer->id()); - scrollbar_layer->SetClipLayer(root_clip_layer->id()); scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); @@ -408,15 +374,15 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( - layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, true, - kThumbThickness, kTrackStart); + layer_settings(), layer_tree_host_.get(), std::move(scrollbar), false, + true, kThumbThickness, kTrackStart); ScrollbarLayerImplBase* scrollbar_layer_impl = static_cast<SolidColorScrollbarLayerImpl*>( - layer_impl_tree_root->children()[1]); + layer_impl_tree_root->children()[1].get()); scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); scrollbar_layer_impl->SetCurrentPos(10.f); - scrollbar_layer_impl->SetMaximum(100); - scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); + scrollbar_layer_impl->SetClipLayerLength(200 / 3.f); + scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f); // Thickness should be overridden to 3. { @@ -432,7 +398,8 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { // For solid color scrollbars, position and size should reflect the // current viewport state. - scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.2f); + scrollbar_layer_impl->SetClipLayerLength(25.f); + scrollbar_layer_impl->SetScrollLayerLength(125.f); { scoped_ptr<RenderPass> render_pass = RenderPass::Create(); AppendQuadsData data; @@ -446,7 +413,8 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { // We shouldn't attempt div-by-zero when the maximum is zero. scrollbar_layer_impl->SetCurrentPos(0.f); - scrollbar_layer_impl->SetMaximum(0); + scrollbar_layer_impl->SetClipLayerLength(125.f); + scrollbar_layer_impl->SetScrollLayerLength(125.f); { scoped_ptr<RenderPass> render_pass = RenderPass::Create(); AppendQuadsData data; @@ -455,7 +423,7 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { const QuadList& quads = render_pass->quad_list; ASSERT_EQ(1u, quads.size()); EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); - EXPECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); + EXPECT_EQ(gfx::Rect(1, 0, 98, 3), quads.front()->rect); } } @@ -477,18 +445,18 @@ TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { layer_settings(), scrollbar->Orientation(), kThumbThickness, kTrackStart, kIsLeftSideVerticalScrollbar, child1->id()); child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); - child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); scroll_layer->AddChild(child1); scroll_layer->InsertChild(child2, 1); layer_tree_root->AddChild(scroll_layer); layer_tree_host_->SetRootLayer(layer_tree_root); + layer_tree_host_->UpdateLayers(); } LayerImpl* layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree(); - LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; + LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0].get(); - auto* scrollbar_layer_impl = - static_cast<ScrollbarLayerImplBase*>(scroll_layer_impl->children()[1]); + auto* scrollbar_layer_impl = static_cast<ScrollbarLayerImplBase*>( + scroll_layer_impl->children()[1].get()); // Choose layer bounds to give max_scroll_offset = (8, 8). layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); @@ -497,7 +465,6 @@ TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); scrollbar_layer_impl->SetCurrentPos(4.f); - scrollbar_layer_impl->SetMaximum(8); { scoped_ptr<RenderPass> render_pass = RenderPass::Create(); @@ -516,9 +483,9 @@ class ScrollbarLayerSolidColorThumbTest : public testing::Test { public: ScrollbarLayerSolidColorThumbTest() { LayerTreeSettings layer_tree_settings; - host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_, - &shared_bitmap_manager_, - &task_graph_runner_)); + host_impl_.reset(new FakeLayerTreeHostImpl( + layer_tree_settings, &task_runner_provider_, &shared_bitmap_manager_, + &task_graph_runner_)); const int kThumbThickness = 3; const int kTrackStart = 0; @@ -544,7 +511,7 @@ class ScrollbarLayerSolidColorThumbTest : public testing::Test { } protected: - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; scoped_ptr<FakeLayerTreeHostImpl> host_impl_; @@ -554,26 +521,27 @@ class ScrollbarLayerSolidColorThumbTest : public testing::Test { TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { horizontal_scrollbar_layer_->SetCurrentPos(0); - horizontal_scrollbar_layer_->SetMaximum(10); // Simple case - one third of the scrollable area is visible, so the thumb // should be one third as long as the track. - horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f); + horizontal_scrollbar_layer_->SetClipLayerLength(5.f); + horizontal_scrollbar_layer_->SetScrollLayerLength(15.f); horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); // The thumb's length should never be less than its thickness. - horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f); + horizontal_scrollbar_layer_->SetClipLayerLength(0.01f); + horizontal_scrollbar_layer_->SetScrollLayerLength(15.f); horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); } TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); - horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f); - horizontal_scrollbar_layer_->SetCurrentPos(0); - horizontal_scrollbar_layer_->SetMaximum(100); + horizontal_scrollbar_layer_->SetCurrentPos(0.f); + horizontal_scrollbar_layer_->SetClipLayerLength(12.f); + horizontal_scrollbar_layer_->SetScrollLayerLength(112.f); EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); @@ -592,9 +560,9 @@ TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { SolidColorScrollbarLayerImpl* layers[2] = { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; for (size_t i = 0; i < 2; ++i) { - layers[i]->SetVisibleToTotalLengthRatio(0.2f); - layers[i]->SetCurrentPos(25); - layers[i]->SetMaximum(100); + layers[i]->SetCurrentPos(25.f); + layers[i]->SetClipLayerLength(25.f); + layers[i]->SetScrollLayerLength(125.f); } layers[0]->SetBounds(gfx::Size(100, 3)); layers[1]->SetBounds(gfx::Size(3, 100)); @@ -629,7 +597,7 @@ class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); scrollbar_layer_ = PaintedScrollbarLayer::Create( - layer_settings(), scrollbar.Pass(), scroll_layer_->id()); + layer_settings(), std::move(scrollbar), scroll_layer_->id()); scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); scrollbar_layer_->SetBounds(bounds_); @@ -668,7 +636,7 @@ TEST_F(ScrollbarLayerTestMaxTextureSize, DirectRenderer) { int max_size = 0; context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); - RunTest(true, false); + RunTest(CompositorMode::Threaded, false); } TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { @@ -677,7 +645,7 @@ TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { int max_size = 0; context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); - RunTest(true, true); + RunTest(CompositorMode::Threaded, true); } class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { @@ -700,7 +668,7 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { kTrackStart, kIsLeftSideVerticalScrollbar, layer_tree_root->id()); } else { scrollbar_layer = PaintedScrollbarLayer::Create( - layer_settings(), scrollbar.Pass(), layer_tree_root->id()); + layer_settings(), std::move(scrollbar), layer_tree_root->id()); } layer_tree_root->AddChild(content_layer); layer_tree_root->AddChild(scrollbar_layer); @@ -766,7 +734,7 @@ TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetBounds(gfx::Size(100, 15)); - scrollbar_layer->SetPosition(scrollbar_location); + scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); layer_tree_root->SetBounds(gfx::Size(100, 200)); content_layer->SetBounds(gfx::Size(100, 200)); scrollbar_layer->set_visible_layer_rect(gfx::Rect(0, 0, 100, 200)); @@ -909,7 +877,7 @@ class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetBounds(gfx::Size(100, 15)); - scrollbar_layer->SetPosition(scrollbar_location); + scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); layer_tree_root->SetBounds(gfx::Size(100, 200)); content_layer->SetBounds(gfx::Size(100, 200)); scrollbar_layer->set_visible_layer_rect( @@ -978,7 +946,7 @@ class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { layer_tree_host_->SetRootLayer(layer_tree_root); scrollbar_layer->SetBounds(scrollbar_rect.size()); - scrollbar_layer->SetPosition(scrollbar_rect.origin()); + scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin())); scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); scrollbar_layer->set_visible_layer_rect(scrollbar_rect); diff --git a/chromium/cc/layers/solid_color_layer.h b/chromium/cc/layers/solid_color_layer.h index b544f66311a..9a16f1a76f8 100644 --- a/chromium/cc/layers/solid_color_layer.h +++ b/chromium/cc/layers/solid_color_layer.h @@ -6,6 +6,7 @@ #ifndef CC_LAYERS_SOLID_COLOR_LAYER_H_ #define CC_LAYERS_SOLID_COLOR_LAYER_H_ +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" diff --git a/chromium/cc/layers/solid_color_layer_impl.h b/chromium/cc/layers/solid_color_layer_impl.h index 2068ac5db3f..a56b69b909b 100644 --- a/chromium/cc/layers/solid_color_layer_impl.h +++ b/chromium/cc/layers/solid_color_layer_impl.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_SOLID_COLOR_LAYER_IMPL_H_ #define CC_LAYERS_SOLID_COLOR_LAYER_IMPL_H_ +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" diff --git a/chromium/cc/layers/solid_color_layer_impl_unittest.cc b/chromium/cc/layers/solid_color_layer_impl_unittest.cc index a27f22971d0..a4d1bfa7d83 100644 --- a/chromium/cc/layers/solid_color_layer_impl_unittest.cc +++ b/chromium/cc/layers/solid_color_layer_impl_unittest.cc @@ -4,12 +4,15 @@ #include "cc/layers/solid_color_layer_impl.h" +#include <stddef.h> + #include <vector> #include "cc/layers/append_quads_data.h" +#include "cc/layers/layer_settings.h" #include "cc/layers/solid_color_layer.h" #include "cc/quads/solid_color_draw_quad.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/layer_test_common.h" #include "cc/test/test_task_graph_runner.h" @@ -26,14 +29,15 @@ TEST(SolidColorLayerImplTest, VerifyTilingCompleteAndNoOverlap) { gfx::Size layer_size = gfx::Size(800, 600); gfx::Rect visible_layer_rect = gfx::Rect(layer_size); - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&proxy, nullptr, &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, nullptr, + &task_graph_runner); scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(host_impl.active_tree(), 1); layer->draw_properties().visible_layer_rect = visible_layer_rect; layer->SetBounds(layer_size); - layer->SetHasRenderSurface(true); + layer->SetForceRenderSurface(true); layer->draw_properties().render_target = layer.get(); AppendQuadsData data; @@ -51,15 +55,16 @@ TEST(SolidColorLayerImplTest, VerifyCorrectBackgroundColorInQuad) { gfx::Size layer_size = gfx::Size(100, 100); gfx::Rect visible_layer_rect = gfx::Rect(layer_size); - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&proxy, nullptr, &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, nullptr, + &task_graph_runner); scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(host_impl.active_tree(), 1); layer->draw_properties().visible_layer_rect = visible_layer_rect; layer->SetBounds(layer_size); layer->SetBackgroundColor(test_color); - layer->SetHasRenderSurface(true); + layer->SetForceRenderSurface(true); layer->draw_properties().render_target = layer.get(); AppendQuadsData data; @@ -79,15 +84,16 @@ TEST(SolidColorLayerImplTest, VerifyCorrectOpacityInQuad) { gfx::Size layer_size = gfx::Size(100, 100); gfx::Rect visible_layer_rect = gfx::Rect(layer_size); - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&proxy, nullptr, &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, nullptr, + &task_graph_runner); scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(host_impl.active_tree(), 1); layer->draw_properties().visible_layer_rect = visible_layer_rect; layer->SetBounds(layer_size); layer->draw_properties().opacity = opacity; - layer->SetHasRenderSurface(true); + layer->SetForceRenderSurface(true); layer->draw_properties().render_target = layer.get(); AppendQuadsData data; @@ -107,9 +113,10 @@ TEST(SolidColorLayerImplTest, VerifyCorrectBlendModeInQuad) { gfx::Size layer_size = gfx::Size(100, 100); gfx::Rect visible_layer_rect = gfx::Rect(layer_size); - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&proxy, nullptr, &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, nullptr, + &task_graph_runner); scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(host_impl.active_tree(), 1); layer->SetBounds(layer_size); diff --git a/chromium/cc/layers/solid_color_scrollbar_layer.cc b/chromium/cc/layers/solid_color_scrollbar_layer.cc index 4ed55cacd3a..62a3180b279 100644 --- a/chromium/cc/layers/solid_color_scrollbar_layer.cc +++ b/chromium/cc/layers/solid_color_scrollbar_layer.cc @@ -43,7 +43,6 @@ SolidColorScrollbarLayer::SolidColorScrollbarLayer( int scroll_layer_id) : Layer(settings), scroll_layer_id_(Layer::INVALID_ID), - clip_layer_id_(scroll_layer_id), orientation_(orientation), thumb_thickness_(thumb_thickness), track_start_(track_start), @@ -58,15 +57,10 @@ ScrollbarLayerInterface* SolidColorScrollbarLayer::ToScrollbarLayer() { void SolidColorScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { Layer::PushPropertiesTo(layer); - PushScrollClipPropertiesTo(layer); -} - -void SolidColorScrollbarLayer::PushScrollClipPropertiesTo(LayerImpl* layer) { SolidColorScrollbarLayerImpl* scrollbar_layer = static_cast<SolidColorScrollbarLayerImpl*>(layer); - scrollbar_layer->SetScrollLayerAndClipLayerByIds(scroll_layer_id_, - clip_layer_id_); + scrollbar_layer->SetScrollLayerId(scroll_layer_id_); } void SolidColorScrollbarLayer::SetNeedsDisplayRect(const gfx::Rect& rect) { @@ -89,14 +83,6 @@ void SolidColorScrollbarLayer::SetScrollLayer(int layer_id) { SetNeedsFullTreeSync(); } -void SolidColorScrollbarLayer::SetClipLayer(int layer_id) { - if (layer_id == clip_layer_id_) - return; - - clip_layer_id_ = layer_id; - SetNeedsFullTreeSync(); -} - ScrollbarOrientation SolidColorScrollbarLayer::orientation() const { return orientation_; } diff --git a/chromium/cc/layers/solid_color_scrollbar_layer.h b/chromium/cc/layers/solid_color_scrollbar_layer.h index 6097014ca22..8f0c00cbed2 100644 --- a/chromium/cc/layers/solid_color_scrollbar_layer.h +++ b/chromium/cc/layers/solid_color_scrollbar_layer.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_SOLID_COLOR_SCROLLBAR_LAYER_H_ #define CC_LAYERS_SOLID_COLOR_SCROLLBAR_LAYER_H_ +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" #include "cc/layers/scrollbar_layer_interface.h" @@ -29,14 +30,12 @@ class CC_EXPORT SolidColorScrollbarLayer : public ScrollbarLayerInterface, ScrollbarLayerInterface* ToScrollbarLayer() override; void PushPropertiesTo(LayerImpl* layer) override; - void PushScrollClipPropertiesTo(LayerImpl* layer) override; void SetNeedsDisplayRect(const gfx::Rect& rect) override; // ScrollbarLayerInterface int ScrollLayerId() const override; void SetScrollLayer(int layer_id) override; - void SetClipLayer(int layer_id) override; ScrollbarOrientation orientation() const override; @@ -51,7 +50,6 @@ class CC_EXPORT SolidColorScrollbarLayer : public ScrollbarLayerInterface, private: int scroll_layer_id_; - int clip_layer_id_; ScrollbarOrientation orientation_; int thumb_thickness_; int track_start_; diff --git a/chromium/cc/layers/solid_color_scrollbar_layer_impl.cc b/chromium/cc/layers/solid_color_scrollbar_layer_impl.cc index beb9cb6886d..0b0a24e037f 100644 --- a/chromium/cc/layers/solid_color_scrollbar_layer_impl.cc +++ b/chromium/cc/layers/solid_color_scrollbar_layer_impl.cc @@ -75,9 +75,11 @@ int SolidColorScrollbarLayerImpl::ThumbThickness() const { } int SolidColorScrollbarLayerImpl::ThumbLength() const { - return std::max( - static_cast<int>(visible_to_total_length_ratio() * TrackLength()), - ThumbThickness()); + float thumb_length = TrackLength(); + if (scroll_layer_length()) + thumb_length *= clip_layer_length() / scroll_layer_length(); + + return std::max(static_cast<int>(thumb_length), ThumbThickness()); } float SolidColorScrollbarLayerImpl::TrackLength() const { diff --git a/chromium/cc/layers/solid_color_scrollbar_layer_impl_unittest.cc b/chromium/cc/layers/solid_color_scrollbar_layer_impl_unittest.cc index c758497c9ce..a285f44389e 100644 --- a/chromium/cc/layers/solid_color_scrollbar_layer_impl_unittest.cc +++ b/chromium/cc/layers/solid_color_scrollbar_layer_impl_unittest.cc @@ -4,6 +4,8 @@ #include "cc/layers/solid_color_scrollbar_layer_impl.h" +#include <stddef.h> + #include "cc/test/layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" @@ -31,9 +33,9 @@ TEST(SolidColorScrollbarLayerImplTest, Occlusion) { is_overlay); scrollbar_layer_impl->SetBounds(layer_size); scrollbar_layer_impl->SetDrawsContent(true); - scrollbar_layer_impl->SetCurrentPos(100.f / 4); - scrollbar_layer_impl->SetMaximum(100); - scrollbar_layer_impl->SetVisibleToTotalLengthRatio(1.f / 2); + scrollbar_layer_impl->SetCurrentPos(25.f); + scrollbar_layer_impl->SetClipLayerLength(100.f); + scrollbar_layer_impl->SetScrollLayerLength(200.f); // SolidColorScrollbarLayers construct with opacity = 0.f, so override. scrollbar_layer_impl->SetOpacity(1.f); diff --git a/chromium/cc/layers/surface_layer.cc b/chromium/cc/layers/surface_layer.cc index e1862303caa..71ceb46275a 100644 --- a/chromium/cc/layers/surface_layer.cc +++ b/chromium/cc/layers/surface_layer.cc @@ -4,6 +4,10 @@ #include "cc/layers/surface_layer.h" +#include <stdint.h> + +#include "base/macros.h" +#include "base/trace_event/trace_event.h" #include "cc/layers/surface_layer_impl.h" #include "cc/output/swap_promise.h" #include "cc/trees/layer_tree_host.h" @@ -27,7 +31,7 @@ class SatisfySwapPromise : public SwapPromise { void DidNotSwap(DidNotSwapReason reason) override { satisfy_callback_.Run(sequence_); } - int64 TraceId() const override { return 0; } + int64_t TraceId() const override { return 0; } SurfaceSequence sequence_; SurfaceLayer::SatisfyCallback satisfy_callback_; @@ -91,6 +95,7 @@ void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { Layer::PushPropertiesTo(layer); + TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); layer_impl->SetSurfaceId(surface_id_); @@ -112,7 +117,7 @@ void SurfaceLayer::SatisfyDestroySequence() { DCHECK(!destroy_sequence_.is_null()); scoped_ptr<SatisfySwapPromise> satisfy( new SatisfySwapPromise(destroy_sequence_, satisfy_callback_)); - layer_tree_host()->QueueSwapPromise(satisfy.Pass()); + layer_tree_host()->QueueSwapPromise(std::move(satisfy)); destroy_sequence_ = SurfaceSequence(); } diff --git a/chromium/cc/layers/surface_layer.h b/chromium/cc/layers/surface_layer.h index e62d6a2c9dc..c2e8a2d000e 100644 --- a/chromium/cc/layers/surface_layer.h +++ b/chromium/cc/layers/surface_layer.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_SURFACE_LAYER_H_ #define CC_LAYERS_SURFACE_LAYER_H_ +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" #include "cc/surfaces/surface_id.h" diff --git a/chromium/cc/layers/surface_layer_impl.cc b/chromium/cc/layers/surface_layer_impl.cc index 546af40c522..a8a50f33fde 100644 --- a/chromium/cc/layers/surface_layer_impl.cc +++ b/chromium/cc/layers/surface_layer_impl.cc @@ -4,19 +4,25 @@ #include "cc/layers/surface_layer_impl.h" +#include <stdint.h> + #include "base/trace_event/trace_event_argument.h" #include "cc/debug/debug_colors.h" #include "cc/quads/solid_color_draw_quad.h" #include "cc/quads/surface_draw_quad.h" +#include "cc/trees/layer_tree_impl.h" #include "cc/trees/occlusion.h" namespace cc { SurfaceLayerImpl::SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id) : LayerImpl(tree_impl, id), surface_scale_(0.f) { + layer_tree_impl()->AddSurfaceLayer(this); } -SurfaceLayerImpl::~SurfaceLayerImpl() {} +SurfaceLayerImpl::~SurfaceLayerImpl() { + layer_tree_impl()->RemoveSurfaceLayer(this); +} scoped_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl( LayerTreeImpl* tree_impl) { @@ -76,7 +82,6 @@ void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass, SurfaceDrawQuad* quad = render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_); - render_pass->referenced_surfaces.push_back(surface_id_); } void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color, diff --git a/chromium/cc/layers/surface_layer_impl.h b/chromium/cc/layers/surface_layer_impl.h index 2bf6a9a008a..819ee738e34 100644 --- a/chromium/cc/layers/surface_layer_impl.h +++ b/chromium/cc/layers/surface_layer_impl.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_SURFACE_LAYER_IMPL_H_ #define CC_LAYERS_SURFACE_LAYER_IMPL_H_ +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" @@ -22,6 +23,7 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl { void SetSurfaceId(SurfaceId surface_id); void SetSurfaceScale(float scale); void SetSurfaceSize(const gfx::Size& size); + SurfaceId surface_id() const { return surface_id_; } // LayerImpl overrides. scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; diff --git a/chromium/cc/layers/surface_layer_impl_unittest.cc b/chromium/cc/layers/surface_layer_impl_unittest.cc index 3ff8255f151..50d4b3a911c 100644 --- a/chromium/cc/layers/surface_layer_impl_unittest.cc +++ b/chromium/cc/layers/surface_layer_impl_unittest.cc @@ -4,6 +4,8 @@ #include "cc/layers/surface_layer_impl.h" +#include <stddef.h> + #include "cc/test/layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/cc/layers/surface_layer_unittest.cc b/chromium/cc/layers/surface_layer_unittest.cc index e35b88683d8..2f8d5cd8f30 100644 --- a/chromium/cc/layers/surface_layer_unittest.cc +++ b/chromium/cc/layers/surface_layer_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stdint.h> + #include <set> #include <vector> @@ -10,7 +12,7 @@ #include "base/thread_task_runner_handle.h" #include "cc/layers/solid_color_layer.h" #include "cc/layers/surface_layer.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_impl.h" diff --git a/chromium/cc/layers/texture_layer.cc b/chromium/cc/layers/texture_layer.cc index c9fb61b86a0..85df0f2b51c 100644 --- a/chromium/cc/layers/texture_layer.cc +++ b/chromium/cc/layers/texture_layer.cc @@ -8,6 +8,7 @@ #include "base/callback_helpers.h" #include "base/location.h" #include "base/synchronization/lock.h" +#include "base/trace_event/trace_event.h" #include "cc/base/simple_enclosed_region.h" #include "cc/layers/texture_layer_client.h" #include "cc/layers/texture_layer_impl.h" @@ -128,7 +129,7 @@ void TextureLayer::SetTextureMailboxInternal( // If we never commited the mailbox, we need to release it here. if (mailbox.IsValid()) { holder_ref_ = - TextureMailboxHolder::Create(mailbox, release_callback.Pass()); + TextureMailboxHolder::Create(mailbox, std::move(release_callback)); } else { holder_ref_ = nullptr; } @@ -150,11 +151,12 @@ void TextureLayer::SetTextureMailbox( scoped_ptr<SingleReleaseCallback> release_callback) { bool requires_commit = true; bool allow_mailbox_reuse = false; - SetTextureMailboxInternal( - mailbox, release_callback.Pass(), requires_commit, allow_mailbox_reuse); + SetTextureMailboxInternal(mailbox, std::move(release_callback), + requires_commit, allow_mailbox_reuse); } -static void IgnoreReleaseCallback(uint32 sync_point, bool lost) {} +static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) { +} void TextureLayer::SetTextureMailboxWithoutReleaseCallback( const TextureMailbox& mailbox) { @@ -163,14 +165,14 @@ void TextureLayer::SetTextureMailboxWithoutReleaseCallback( // multiple times for the same mailbox. DCHECK(!mailbox.IsValid() || !holder_ref_ || !mailbox.Equals(holder_ref_->holder()->mailbox()) || - mailbox.sync_point() != holder_ref_->holder()->mailbox().sync_point()); + mailbox.sync_token() != holder_ref_->holder()->mailbox().sync_token()); scoped_ptr<SingleReleaseCallback> release; bool requires_commit = true; bool allow_mailbox_reuse = true; if (mailbox.IsValid()) release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); - SetTextureMailboxInternal( - mailbox, release.Pass(), requires_commit, allow_mailbox_reuse); + SetTextureMailboxInternal(mailbox, std::move(release), requires_commit, + allow_mailbox_reuse); } void TextureLayer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { @@ -211,10 +213,8 @@ bool TextureLayer::Update() { // Already within a commit, no need to do another one immediately. bool requires_commit = false; bool allow_mailbox_reuse = false; - SetTextureMailboxInternal(mailbox, - release_callback.Pass(), - requires_commit, - allow_mailbox_reuse); + SetTextureMailboxInternal(mailbox, std::move(release_callback), + requires_commit, allow_mailbox_reuse); updated = true; } } @@ -227,6 +227,7 @@ bool TextureLayer::Update() { void TextureLayer::PushPropertiesTo(LayerImpl* layer) { Layer::PushPropertiesTo(layer); + TRACE_EVENT0("cc", "TextureLayer::PushPropertiesTo"); TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); texture_layer->SetFlipped(flipped_); @@ -245,7 +246,7 @@ void TextureLayer::PushPropertiesTo(LayerImpl* layer) { release_callback_impl = holder->GetCallbackForImplThread(); } texture_layer->SetTextureMailbox(texture_mailbox, - release_callback_impl.Pass()); + std::move(release_callback_impl)); needs_set_mailbox_ = false; } } @@ -266,10 +267,9 @@ TextureLayer::TextureMailboxHolder::TextureMailboxHolder( scoped_ptr<SingleReleaseCallback> release_callback) : internal_references_(0), mailbox_(mailbox), - release_callback_(release_callback.Pass()), - sync_point_(mailbox.sync_point()), - is_lost_(false) { -} + release_callback_(std::move(release_callback)), + sync_token_(mailbox.sync_token()), + is_lost_(false) {} TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { DCHECK_EQ(0u, internal_references_); @@ -280,13 +280,14 @@ TextureLayer::TextureMailboxHolder::Create( const TextureMailbox& mailbox, scoped_ptr<SingleReleaseCallback> release_callback) { return make_scoped_ptr(new MainThreadReference( - new TextureMailboxHolder(mailbox, release_callback.Pass()))); + new TextureMailboxHolder(mailbox, std::move(release_callback)))); } -void TextureLayer::TextureMailboxHolder::Return(uint32 sync_point, - bool is_lost) { +void TextureLayer::TextureMailboxHolder::Return( + const gpu::SyncToken& sync_token, + bool is_lost) { base::AutoLock lock(arguments_lock_); - sync_point_ = sync_point; + sync_token_ = sync_token; is_lost_ = is_lost; } @@ -307,17 +308,17 @@ void TextureLayer::TextureMailboxHolder::InternalAddRef() { void TextureLayer::TextureMailboxHolder::InternalRelease() { DCHECK(main_thread_checker_.CalledOnValidThread()); if (!--internal_references_) { - release_callback_->Run(sync_point_, is_lost_); + release_callback_->Run(sync_token_, is_lost_); mailbox_ = TextureMailbox(); release_callback_ = nullptr; } } void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( - uint32 sync_point, + const gpu::SyncToken& sync_token, bool is_lost, BlockingTaskRunner* main_thread_task_runner) { - Return(sync_point, is_lost); + Return(sync_token, is_lost); main_thread_task_runner->PostTask( FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); } diff --git a/chromium/cc/layers/texture_layer.h b/chromium/cc/layers/texture_layer.h index 0c0b2ec237d..6b529dd9a90 100644 --- a/chromium/cc/layers/texture_layer.h +++ b/chromium/cc/layers/texture_layer.h @@ -8,12 +8,17 @@ #include <string> #include "base/callback.h" +#include "base/macros.h" #include "base/synchronization/lock.h" #include "base/threading/thread_checker.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" #include "cc/resources/texture_mailbox.h" +namespace gpu { +struct SyncToken; +} + namespace cc { class BlockingTaskRunner; class SingleReleaseCallback; @@ -38,7 +43,7 @@ class CC_EXPORT TextureLayer : public Layer { }; const TextureMailbox& mailbox() const { return mailbox_; } - void Return(uint32 sync_point, bool is_lost); + void Return(const gpu::SyncToken& sync_token, bool is_lost); // Gets a ReleaseCallback that can be called from another thread. Note: the // caller must ensure the callback is called. @@ -63,7 +68,7 @@ class CC_EXPORT TextureLayer : public Layer { void InternalAddRef(); void InternalRelease(); void ReturnAndReleaseOnImplThread( - uint32 sync_point, + const gpu::SyncToken& sync_token, bool is_lost, BlockingTaskRunner* main_thread_task_runner); @@ -73,12 +78,12 @@ class CC_EXPORT TextureLayer : public Layer { TextureMailbox mailbox_; scoped_ptr<SingleReleaseCallback> release_callback_; - // This lock guards the sync_point_ and is_lost_ fields because they can be + // This lock guards the sync_token_ and is_lost_ fields because they can be // accessed on both the impl and main thread. We do this to ensure that the // values of these fields are well-ordered such that the last call to // ReturnAndReleaseOnImplThread() defines their values. base::Lock arguments_lock_; - uint32 sync_point_; + gpu::SyncToken sync_token_; bool is_lost_; base::ThreadChecker main_thread_checker_; DISALLOW_COPY_AND_ASSIGN(TextureMailboxHolder); diff --git a/chromium/cc/layers/texture_layer_impl.cc b/chromium/cc/layers/texture_layer_impl.cc index 404d479721a..0d2f4e7558a 100644 --- a/chromium/cc/layers/texture_layer_impl.cc +++ b/chromium/cc/layers/texture_layer_impl.cc @@ -4,6 +4,9 @@ #include "cc/layers/texture_layer_impl.h" +#include <stddef.h> +#include <stdint.h> + #include <vector> #include "base/strings/stringprintf.h" @@ -42,7 +45,7 @@ void TextureLayerImpl::SetTextureMailbox( DCHECK_EQ(mailbox.IsValid(), !!release_callback); FreeTextureMailbox(); texture_mailbox_ = mailbox; - release_callback_ = release_callback.Pass(); + release_callback_ = std::move(release_callback); own_mailbox_ = true; valid_texture_copy_ = false; SetNeedsPushProperties(); @@ -66,7 +69,7 @@ void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) { texture_layer->SetNearestNeighbor(nearest_neighbor_); if (own_mailbox_) { texture_layer->SetTextureMailbox(texture_mailbox_, - release_callback_.Pass()); + std::move(release_callback_)); own_mailbox_ = false; } } @@ -83,7 +86,7 @@ bool TextureLayerImpl::WillDraw(DrawMode draw_mode, texture_mailbox_.IsSharedMemory())) { external_texture_resource_ = resource_provider->CreateResourceFromTextureMailbox( - texture_mailbox_, release_callback_.Pass()); + texture_mailbox_, std::move(release_callback_)); DCHECK(external_texture_resource_); texture_copy_ = nullptr; valid_texture_copy_ = false; @@ -110,8 +113,8 @@ bool TextureLayerImpl::WillDraw(DrawMode draw_mode, } if (texture_copy_->id()) { - std::vector<uint8> swizzled; - uint8* pixels = texture_mailbox_.shared_bitmap()->pixels(); + std::vector<uint8_t> swizzled; + uint8_t* pixels = texture_mailbox_.shared_bitmap()->pixels(); if (!PlatformColor::SameComponentOrder(texture_copy_->format())) { // Swizzle colors. This is slow, but should be really uncommon. @@ -177,7 +180,6 @@ void TextureLayerImpl::AppendQuads(RenderPass* render_pass, nearest_neighbor_); if (!valid_texture_copy_) { quad->set_resource_size_in_pixels(texture_mailbox_.size_in_pixels()); - quad->set_allow_overlay(texture_mailbox_.allow_overlay()); } ValidateQuadResources(quad); } @@ -248,9 +250,10 @@ void TextureLayerImpl::FreeTextureMailbox() { if (own_mailbox_) { DCHECK(!external_texture_resource_); if (release_callback_) { - release_callback_->Run(texture_mailbox_.sync_point(), - false, - layer_tree_impl()->BlockingMainThreadTaskRunner()); + release_callback_->Run(texture_mailbox_.sync_token(), false, + layer_tree_impl() + ->task_runner_provider() + ->blocking_main_thread_task_runner()); } texture_mailbox_ = TextureMailbox(); release_callback_ = nullptr; diff --git a/chromium/cc/layers/texture_layer_impl.h b/chromium/cc/layers/texture_layer_impl.h index 680aaf0aec0..e799eff5a2d 100644 --- a/chromium/cc/layers/texture_layer_impl.h +++ b/chromium/cc/layers/texture_layer_impl.h @@ -8,6 +8,7 @@ #include <string> #include "base/callback.h" +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" diff --git a/chromium/cc/layers/texture_layer_impl_unittest.cc b/chromium/cc/layers/texture_layer_impl_unittest.cc index 27efd971502..93e33423223 100644 --- a/chromium/cc/layers/texture_layer_impl_unittest.cc +++ b/chromium/cc/layers/texture_layer_impl_unittest.cc @@ -4,6 +4,8 @@ #include "cc/layers/texture_layer_impl.h" +#include <stddef.h> + #include "cc/output/context_provider.h" #include "cc/output/output_surface.h" #include "cc/test/layer_test_common.h" @@ -12,10 +14,9 @@ namespace cc { namespace { -void IgnoreCallback(uint32 sync_point, +void IgnoreCallback(const gpu::SyncToken& sync_token, bool lost, - BlockingTaskRunner* main_thread_task_runner) { -} + BlockingTaskRunner* main_thread_task_runner) {} TEST(TextureLayerImplTest, VisibleOpaqueRegion) { const gfx::Size layer_bounds(100, 100); @@ -52,7 +53,7 @@ TEST(TextureLayerImplTest, Occlusion) { gpu::Mailbox mailbox; impl.output_surface()->context_provider()->ContextGL()->GenMailboxCHROMIUM( mailbox.name); - TextureMailbox texture_mailbox(mailbox, GL_TEXTURE_2D, 0); + TextureMailbox texture_mailbox(mailbox, gpu::SyncToken(), GL_TEXTURE_2D); TextureLayerImpl* texture_layer_impl = impl.AddChildToRoot<TextureLayerImpl>(); diff --git a/chromium/cc/layers/texture_layer_unittest.cc b/chromium/cc/layers/texture_layer_unittest.cc index 8c138c35bd4..31313afa3df 100644 --- a/chromium/cc/layers/texture_layer_unittest.cc +++ b/chromium/cc/layers/texture_layer_unittest.cc @@ -4,12 +4,16 @@ #include "cc/layers/texture_layer.h" +#include <stddef.h> +#include <stdint.h> + #include <algorithm> #include <string> #include "base/bind.h" #include "base/callback.h" #include "base/location.h" +#include "base/macros.h" #include "base/single_thread_task_runner.h" #include "base/synchronization/lock.h" #include "base/synchronization/waitable_event.h" @@ -22,7 +26,7 @@ #include "cc/output/compositor_frame_ack.h" #include "cc/output/context_provider.h" #include "cc/resources/returned_resource.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" @@ -74,7 +78,7 @@ class MockLayerTreeHost : public LayerTreeHost { private: MockLayerTreeHost(FakeLayerTreeHostClient* client, LayerTreeHost::InitParams* params) - : LayerTreeHost(params) { + : LayerTreeHost(params, CompositorMode::SingleThreaded) { InitializeSingleThreaded(client, base::ThreadTaskRunnerHandle::Get(), nullptr); } @@ -92,7 +96,7 @@ class FakeTextureLayerClient : public TextureLayerClient { return false; *mailbox = mailbox_; - *release_callback = release_callback_.Pass(); + *release_callback = std::move(release_callback_); mailbox_changed_ = false; return true; } @@ -100,7 +104,7 @@ class FakeTextureLayerClient : public TextureLayerClient { void set_mailbox(const TextureMailbox& mailbox, scoped_ptr<SingleReleaseCallback> release_callback) { mailbox_ = mailbox; - release_callback_ = release_callback.Pass(); + release_callback_ = std::move(release_callback); mailbox_changed_ = true; } @@ -115,20 +119,20 @@ class MockMailboxCallback { public: MOCK_METHOD3(Release, void(const gpu::Mailbox& mailbox, - uint32 sync_point, + const gpu::SyncToken& sync_token, bool lost_resource)); MOCK_METHOD3(Release2, void(SharedBitmap* shared_bitmap, - uint32 sync_point, + const gpu::SyncToken& sync_token, bool lost_resource)); MOCK_METHOD4(ReleaseImpl, void(const gpu::Mailbox& mailbox, - uint32 sync_point, + const gpu::SyncToken& sync_token, bool lost_resource, BlockingTaskRunner* main_thread_task_runner)); MOCK_METHOD4(ReleaseImpl2, void(SharedBitmap* shared_bitmap, - uint32 sync_point, + const gpu::SyncToken& sync_token, bool lost_resource, BlockingTaskRunner* main_thread_task_runner)); }; @@ -137,8 +141,8 @@ struct CommonMailboxObjects { explicit CommonMailboxObjects(SharedBitmapManager* manager) : mailbox_name1_(MailboxFromChar('1')), mailbox_name2_(MailboxFromChar('2')), - sync_point1_(1), - sync_point2_(2) { + sync_token1_(1), + sync_token2_(2) { release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, base::Unretained(&mock_callback_), mailbox_name1_); @@ -151,10 +155,10 @@ struct CommonMailboxObjects { release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, base::Unretained(&mock_callback_), mailbox_name2_); - const uint32 arbitrary_target1 = GL_TEXTURE_2D; - const uint32 arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES; - mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); - mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); + const uint32_t arbitrary_target1 = GL_TEXTURE_2D; + const uint32_t arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES; + mailbox1_ = TextureMailbox(mailbox_name1_, sync_token1_, arbitrary_target1); + mailbox2_ = TextureMailbox(mailbox_name2_, sync_token2_, arbitrary_target2); gfx::Size size(128, 128); shared_bitmap_ = manager->AllocateSharedBitmap(size); DCHECK(shared_bitmap_); @@ -179,8 +183,8 @@ struct CommonMailboxObjects { TextureMailbox mailbox1_; TextureMailbox mailbox2_; TextureMailbox mailbox3_; - uint32 sync_point1_; - uint32 sync_point2_; + gpu::SyncToken sync_token1_; + gpu::SyncToken sync_token2_; scoped_ptr<SharedBitmap> shared_bitmap_; }; @@ -190,7 +194,9 @@ class TextureLayerTest : public testing::Test { : fake_client_( FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), output_surface_(FakeOutputSurface::Create3d()), - host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), + host_impl_(&task_runner_provider_, + &shared_bitmap_manager_, + &task_graph_runner_), test_data_(&shared_bitmap_manager_) {} protected: @@ -211,7 +217,7 @@ class TextureLayerTest : public testing::Test { } scoped_ptr<MockLayerTreeHost> layer_tree_host_; - FakeImplProxy proxy_; + FakeImplTaskRunnerProvider task_runner_provider_; FakeLayerTreeHostClient fake_client_; TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; @@ -250,10 +256,10 @@ class TextureLayerWithMailboxTest : public TextureLayerTest { protected: void TearDown() override { Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); - EXPECT_CALL(test_data_.mock_callback_, - Release(test_data_.mailbox_name1_, - test_data_.sync_point1_, - false)).Times(1); + EXPECT_CALL( + test_data_.mock_callback_, + Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false)) + .Times(1); TextureLayerTest::TearDown(); } }; @@ -274,10 +280,9 @@ TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { Mock::VerifyAndClearExpectations(layer_tree_host_.get()); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); - EXPECT_CALL(test_data_.mock_callback_, - Release(test_data_.mailbox_name1_, - test_data_.sync_point1_, - false)) + EXPECT_CALL( + test_data_.mock_callback_, + Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false)) .Times(1); test_layer->SetTextureMailbox( test_data_.mailbox2_, @@ -286,10 +291,9 @@ TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); - EXPECT_CALL(test_data_.mock_callback_, - Release(test_data_.mailbox_name2_, - test_data_.sync_point2_, - false)) + EXPECT_CALL( + test_data_.mock_callback_, + Release(test_data_.mailbox_name2_, test_data_.sync_token2_, false)) .Times(1); test_layer->SetTextureMailbox(TextureMailbox(), nullptr); Mock::VerifyAndClearExpectations(layer_tree_host_.get()); @@ -304,7 +308,8 @@ TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); EXPECT_CALL(test_data_.mock_callback_, - Release2(test_data_.shared_bitmap_.get(), 0, false)).Times(1); + Release2(test_data_.shared_bitmap_.get(), _, false)) + .Times(1); test_layer->SetTextureMailbox(TextureMailbox(), nullptr); Mock::VerifyAndClearExpectations(layer_tree_host_.get()); Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); @@ -322,8 +327,10 @@ TEST_F(TextureLayerTest, SetTextureMailboxWithoutReleaseCallback) { ASSERT_TRUE(test_layer.get()); // These use the same gpu::Mailbox, but different sync points. - TextureMailbox mailbox1(MailboxFromChar('a'), GL_TEXTURE_2D, 1); - TextureMailbox mailbox2(MailboxFromChar('a'), GL_TEXTURE_2D, 2); + TextureMailbox mailbox1(MailboxFromChar('a'), gpu::SyncToken(1), + GL_TEXTURE_2D); + TextureMailbox mailbox2(MailboxFromChar('a'), gpu::SyncToken(2), + GL_TEXTURE_2D); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); layer_tree_host_->SetRootLayer(test_layer); @@ -365,7 +372,7 @@ class TextureLayerMailboxHolderTest : public TextureLayerTest { void CreateMainRef() { main_ref_ = TestMailboxHolder::Create( test_data_.mailbox1_, - SingleReleaseCallback::Create(test_data_.release_mailbox1_)).Pass(); + SingleReleaseCallback::Create(test_data_.release_mailbox1_)); } void ReleaseMainRef() { main_ref_ = nullptr; } @@ -426,8 +433,8 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { // The compositors both destroy their impl trees before the main thread layer // is destroyed. - compositor1->Run(100, false, main_thread_task_runner_.get()); - compositor2->Run(200, false, main_thread_task_runner_.get()); + compositor1->Run(gpu::SyncToken(100), false, main_thread_task_runner_.get()); + compositor2->Run(gpu::SyncToken(200), false, main_thread_task_runner_.get()); Wait(main_thread_); @@ -437,7 +444,8 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { // The main thread ref is the last one, so the mailbox is released back to the // embedder, with the last sync point provided by the impl trees. EXPECT_CALL(test_data_.mock_callback_, - Release(test_data_.mailbox_name1_, 200, false)).Times(1); + Release(test_data_.mailbox_name1_, gpu::SyncToken(200), false)) + .Times(1); main_thread_.message_loop()->task_runner()->PostTask( FROM_HERE, base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, @@ -475,7 +483,7 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) { Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); // One compositor destroys their impl tree. - compositor1->Run(100, false, main_thread_task_runner_.get()); + compositor1->Run(gpu::SyncToken(100), false, main_thread_task_runner_.get()); // Then the main thread reference is destroyed. main_thread_.message_loop()->task_runner()->PostTask( @@ -490,9 +498,10 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) { // The second impl reference is destroyed last, causing the mailbox to be // released back to the embedder with the last sync point from the impl tree. EXPECT_CALL(test_data_.mock_callback_, - Release(test_data_.mailbox_name1_, 200, true)).Times(1); + Release(test_data_.mailbox_name1_, gpu::SyncToken(200), true)) + .Times(1); - compositor2->Run(200, true, main_thread_task_runner_.get()); + compositor2->Run(gpu::SyncToken(200), true, main_thread_task_runner_.get()); Wait(main_thread_); Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); } @@ -531,7 +540,7 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { base::Unretained(this))); // One compositor destroys their impl tree. - compositor2->Run(200, false, main_thread_task_runner_.get()); + compositor2->Run(gpu::SyncToken(200), false, main_thread_task_runner_.get()); Wait(main_thread_); @@ -541,9 +550,10 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { // The second impl reference is destroyed last, causing the mailbox to be // released back to the embedder with the last sync point from the impl tree. EXPECT_CALL(test_data_.mock_callback_, - Release(test_data_.mailbox_name1_, 100, true)).Times(1); + Release(test_data_.mailbox_name1_, gpu::SyncToken(100), true)) + .Times(1); - compositor1->Run(100, true, main_thread_task_runner_.get()); + compositor1->Run(gpu::SyncToken(100), true, main_thread_task_runner_.get()); Wait(main_thread_); Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); } @@ -582,7 +592,8 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { base::Unretained(this))); EXPECT_CALL(test_data_.mock_callback_, - Release(test_data_.mailbox_name1_, 200, true)).Times(1); + Release(test_data_.mailbox_name1_, gpu::SyncToken(200), true)) + .Times(1); bool manual_reset = false; bool initially_signaled = false; @@ -601,7 +612,7 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { // Before the main thread capturing starts, one compositor destroys their // impl reference. Since capturing did not start, this gets post-tasked to // the main thread. - compositor1->Run(100, false, main_thread_task_runner_.get()); + compositor1->Run(gpu::SyncToken(100), false, main_thread_task_runner_.get()); // Start capturing on the main thread. begin_capture.Signal(); @@ -612,7 +623,7 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { // released before compositor1, whose reference will be released later when // the post-task is serviced. But since it was destroyed _on the impl thread_ // last, its sync point values should be used. - compositor2->Run(200, true, main_thread_task_runner_.get()); + compositor2->Run(gpu::SyncToken(200), true, main_thread_task_runner_.get()); stop_capture.Signal(); Wait(main_thread_); @@ -627,7 +638,7 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { commit_count_(0) {} // Make sure callback is received on main and doesn't block the impl thread. - void ReleaseCallback(uint32 sync_point, bool lost_resource) { + void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); EXPECT_FALSE(lost_resource); ++callback_count_; @@ -639,9 +650,9 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { base::Bind( &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, base::Unretained(this))); - layer_->SetTextureMailbox( - TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), - callback.Pass()); + layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char), + gpu::SyncToken(), GL_TEXTURE_2D), + std::move(callback)); } void BeginTest() override { @@ -748,15 +759,16 @@ class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { protected: TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} - static void ReleaseCallback(uint32 sync_point, bool lost_resource) {} + static void ReleaseCallback(const gpu::SyncToken& sync_token, + bool lost_resource) {} void SetMailbox(char mailbox_char) { scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( base::Bind( &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); - layer_->SetTextureMailbox( - TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), - callback.Pass()); + layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char), + gpu::SyncToken(), GL_TEXTURE_2D), + std::move(callback)); } void BeginTest() override { @@ -835,6 +847,7 @@ class TextureLayerImplWithMailboxTest : public TextureLayerTest { TextureLayerTest::SetUp(); layer_tree_host_ = MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_); + host_impl_.SetVisible(true); EXPECT_TRUE(host_impl_.InitializeRenderer(output_surface_.get())); } @@ -854,10 +867,11 @@ class TextureLayerImplWithMailboxTest : public TextureLayerTest { TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) { EXPECT_CALL( test_data_.mock_callback_, - ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) + ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _)) .Times(AnyNumber()); - EXPECT_CALL(test_data_.mock_callback_, - ReleaseImpl2(test_data_.shared_bitmap_.get(), 0, false, _)) + EXPECT_CALL( + test_data_.mock_callback_, + ReleaseImpl2(test_data_.shared_bitmap_.get(), gpu::SyncToken(), false, _)) .Times(AnyNumber()); // Hardware mode. { @@ -941,7 +955,7 @@ TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) { // Test multiple commits without an activation. EXPECT_CALL( test_data_.mock_callback_, - ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) + ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _)) .Times(1); pending_layer->SetTextureMailbox( test_data_.mailbox2_, @@ -975,7 +989,7 @@ TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) { // Test destructor. EXPECT_CALL( test_data_.mock_callback_, - ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) + ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _)) .Times(1); pending_layer->SetTextureMailbox( test_data_.mailbox1_, @@ -1040,14 +1054,15 @@ class TextureLayerNoExtraCommitForMailboxTest return true; } - *texture_mailbox = TextureMailbox(MailboxFromChar('1'), GL_TEXTURE_2D, 0); + *texture_mailbox = + TextureMailbox(MailboxFromChar('1'), gpu::SyncToken(), GL_TEXTURE_2D); *release_callback = SingleReleaseCallback::Create( base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased, base::Unretained(this))); return true; } - void MailboxReleased(uint32 sync_point, bool lost_resource) { + void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) { // Source frame number during callback is the same as the source frame // on which it was released. EXPECT_EQ(1, layer_tree_host()->source_frame_number()); @@ -1142,10 +1157,11 @@ class TextureLayerChangeInvisibleMailboxTest } TextureMailbox MakeMailbox(char name) { - return TextureMailbox(MailboxFromChar(name), GL_TEXTURE_2D, 0); + return TextureMailbox(MailboxFromChar(name), gpu::SyncToken(), + GL_TEXTURE_2D); } - void MailboxReleased(uint32 sync_point, bool lost_resource) { + void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) { ++mailbox_returned_; } @@ -1265,14 +1281,15 @@ class TextureLayerReleaseResourcesBase TextureMailbox* mailbox, scoped_ptr<SingleReleaseCallback>* release_callback, bool use_shared_memory) override { - *mailbox = TextureMailbox(MailboxFromChar('1'), GL_TEXTURE_2D, 0); + *mailbox = + TextureMailbox(MailboxFromChar('1'), gpu::SyncToken(), GL_TEXTURE_2D); *release_callback = SingleReleaseCallback::Create( base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased, base::Unretained(this))); return true; } - void MailboxReleased(unsigned sync_point, bool lost_resource) { + void MailboxReleased(const gpu::SyncToken& sync_token, bool lost_resource) { mailbox_released_ = true; } @@ -1324,7 +1341,7 @@ SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate); class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { public: - void ReleaseCallback(uint32 sync_point, bool lost_resource) { + void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); EXPECT_FALSE(lost_resource); ++callback_count_; @@ -1337,9 +1354,9 @@ class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { base::Bind( &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback, base::Unretained(this))); - layer_->SetTextureMailbox( - TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), - callback.Pass()); + layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char), + gpu::SyncToken(), GL_TEXTURE_2D), + std::move(callback)); } void SetupTree() override { @@ -1393,7 +1410,7 @@ SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest { public: - void ReleaseCallback(uint32 sync_point, bool lost_resource) { + void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); EXPECT_FALSE(lost_resource); ++callback_count_; @@ -1406,9 +1423,9 @@ class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest { base::Bind( &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback, base::Unretained(this))); - layer_->SetTextureMailbox( - TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), - callback.Pass()); + layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char), + gpu::SyncToken(), GL_TEXTURE_2D), + std::move(callback)); } void SetupTree() override { diff --git a/chromium/cc/layers/ui_resource_layer.cc b/chromium/cc/layers/ui_resource_layer.cc index 87512ebd016..6b5f8779c65 100644 --- a/chromium/cc/layers/ui_resource_layer.cc +++ b/chromium/cc/layers/ui_resource_layer.cc @@ -4,6 +4,7 @@ #include "cc/layers/ui_resource_layer.h" +#include "base/trace_event/trace_event.h" #include "cc/layers/ui_resource_layer_impl.h" #include "cc/resources/scoped_ui_resource.h" #include "cc/resources/ui_resource_bitmap.h" @@ -149,6 +150,7 @@ bool UIResourceLayer::HasDrawableContent() const { void UIResourceLayer::PushPropertiesTo(LayerImpl* layer) { Layer::PushPropertiesTo(layer); + TRACE_EVENT0("cc", "UIResourceLayer::PushPropertiesTo"); UIResourceLayerImpl* layer_impl = static_cast<UIResourceLayerImpl*>(layer); if (!ui_resource_holder_) { diff --git a/chromium/cc/layers/ui_resource_layer.h b/chromium/cc/layers/ui_resource_layer.h index 600f245dd6b..52a45b72da3 100644 --- a/chromium/cc/layers/ui_resource_layer.h +++ b/chromium/cc/layers/ui_resource_layer.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_UI_RESOURCE_LAYER_H_ #define CC_LAYERS_UI_RESOURCE_LAYER_H_ +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" diff --git a/chromium/cc/layers/ui_resource_layer_impl.h b/chromium/cc/layers/ui_resource_layer_impl.h index 87d77e85a20..05293e67778 100644 --- a/chromium/cc/layers/ui_resource_layer_impl.h +++ b/chromium/cc/layers/ui_resource_layer_impl.h @@ -7,6 +7,7 @@ #include <string> +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" #include "cc/resources/resource_provider.h" diff --git a/chromium/cc/layers/ui_resource_layer_impl_unittest.cc b/chromium/cc/layers/ui_resource_layer_impl_unittest.cc index 826c53f8181..92419452c37 100644 --- a/chromium/cc/layers/ui_resource_layer_impl_unittest.cc +++ b/chromium/cc/layers/ui_resource_layer_impl_unittest.cc @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stddef.h> + #include "cc/layers/append_quads_data.h" #include "cc/layers/ui_resource_layer_impl.h" #include "cc/quads/draw_quad.h" #include "cc/resources/ui_resource_bitmap.h" #include "cc/resources/ui_resource_client.h" -#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_ui_resource_layer_tree_host_impl.h" @@ -33,7 +35,7 @@ scoped_ptr<UIResourceLayerImpl> GenerateUIResourceLayer( UIResourceLayerImpl::Create(host_impl->active_tree(), 1); layer->draw_properties().visible_layer_rect = visible_layer_rect; layer->SetBounds(layer_size); - layer->SetHasRenderSurface(true); + layer->SetForceRenderSurface(true); layer->draw_properties().render_target = layer.get(); UIResourceBitmap bitmap(bitmap_size, opaque); @@ -41,7 +43,7 @@ scoped_ptr<UIResourceLayerImpl> GenerateUIResourceLayer( host_impl->CreateUIResource(uid, bitmap); layer->SetUIResourceId(uid); - return layer.Pass(); + return layer; } void QuadSizeTest(scoped_ptr<UIResourceLayerImpl> layer, @@ -57,17 +59,18 @@ void QuadSizeTest(scoped_ptr<UIResourceLayerImpl> layer, } TEST(UIResourceLayerImplTest, VerifyDrawQuads) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); - FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, - &task_graph_runner); + FakeUIResourceLayerTreeHostImpl host_impl( + &task_runner_provider, &shared_bitmap_manager, &task_graph_runner); + host_impl.SetVisible(true); host_impl.InitializeRenderer(output_surface.get()); // Make sure we're appending quads when there are valid values. gfx::Size bitmap_size(100, 100); - gfx::Size layer_size(100, 100);; + gfx::Size layer_size(100, 100); size_t expected_quad_size = 1; bool opaque = true; UIResourceId uid = 1; @@ -76,7 +79,7 @@ TEST(UIResourceLayerImplTest, VerifyDrawQuads) { layer_size, opaque, uid); - QuadSizeTest(layer.Pass(), expected_quad_size); + QuadSizeTest(std::move(layer), expected_quad_size); // Make sure we're not appending quads when there are invalid values. expected_quad_size = 0; @@ -86,7 +89,7 @@ TEST(UIResourceLayerImplTest, VerifyDrawQuads) { layer_size, opaque, uid); - QuadSizeTest(layer.Pass(), expected_quad_size); + QuadSizeTest(std::move(layer), expected_quad_size); } void OpaqueBoundsTest(scoped_ptr<UIResourceLayerImpl> layer, @@ -104,16 +107,17 @@ void OpaqueBoundsTest(scoped_ptr<UIResourceLayerImpl> layer, } TEST(UIResourceLayerImplTest, VerifySetOpaqueOnSkBitmap) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); - FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, - &task_graph_runner); + FakeUIResourceLayerTreeHostImpl host_impl( + &task_runner_provider, &shared_bitmap_manager, &task_graph_runner); + host_impl.SetVisible(true); host_impl.InitializeRenderer(output_surface.get()); gfx::Size bitmap_size(100, 100); - gfx::Size layer_size(100, 100);; + gfx::Size layer_size(100, 100); bool opaque = false; UIResourceId uid = 1; scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(&host_impl, @@ -122,7 +126,7 @@ TEST(UIResourceLayerImplTest, VerifySetOpaqueOnSkBitmap) { opaque, uid); gfx::Rect expected_opaque_bounds; - OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds); + OpaqueBoundsTest(std::move(layer), expected_opaque_bounds); opaque = true; layer = GenerateUIResourceLayer(&host_impl, @@ -131,16 +135,17 @@ TEST(UIResourceLayerImplTest, VerifySetOpaqueOnSkBitmap) { opaque, uid); expected_opaque_bounds = gfx::Rect(layer->bounds()); - OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds); + OpaqueBoundsTest(std::move(layer), expected_opaque_bounds); } TEST(UIResourceLayerImplTest, VerifySetOpaqueOnLayer) { - FakeImplProxy proxy; + FakeImplTaskRunnerProvider task_runner_provider; TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); - FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, - &task_graph_runner); + FakeUIResourceLayerTreeHostImpl host_impl( + &task_runner_provider, &shared_bitmap_manager, &task_graph_runner); + host_impl.SetVisible(true); host_impl.InitializeRenderer(output_surface.get()); gfx::Size bitmap_size(100, 100); @@ -151,13 +156,13 @@ TEST(UIResourceLayerImplTest, VerifySetOpaqueOnLayer) { &host_impl, bitmap_size, layer_size, skbitmap_opaque, uid); layer->SetContentsOpaque(false); gfx::Rect expected_opaque_bounds; - OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds); + OpaqueBoundsTest(std::move(layer), expected_opaque_bounds); layer = GenerateUIResourceLayer( &host_impl, bitmap_size, layer_size, skbitmap_opaque, uid); layer->SetContentsOpaque(true); expected_opaque_bounds = gfx::Rect(layer->bounds()); - OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds); + OpaqueBoundsTest(std::move(layer), expected_opaque_bounds); } TEST(UIResourceLayerImplTest, Occlusion) { diff --git a/chromium/cc/layers/ui_resource_layer_unittest.cc b/chromium/cc/layers/ui_resource_layer_unittest.cc index 3d2681e74bd..fa277109c26 100644 --- a/chromium/cc/layers/ui_resource_layer_unittest.cc +++ b/chromium/cc/layers/ui_resource_layer_unittest.cc @@ -5,6 +5,7 @@ #include "cc/layers/ui_resource_layer.h" #include "base/thread_task_runner_handle.h" +#include "cc/layers/layer_settings.h" #include "cc/resources/resource_provider.h" #include "cc/resources/scoped_ui_resource.h" #include "cc/test/fake_layer_tree_host.h" diff --git a/chromium/cc/layers/video_frame_provider_client_impl.h b/chromium/cc/layers/video_frame_provider_client_impl.h index e626b541405..17525ec4c1f 100644 --- a/chromium/cc/layers/video_frame_provider_client_impl.h +++ b/chromium/cc/layers/video_frame_provider_client_impl.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_ #define CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_ +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" #include "base/threading/thread_checker.h" diff --git a/chromium/cc/layers/video_frame_provider_client_impl_unittest.cc b/chromium/cc/layers/video_frame_provider_client_impl_unittest.cc index 4cbd493e0d5..e337baa9ae7 100644 --- a/chromium/cc/layers/video_frame_provider_client_impl_unittest.cc +++ b/chromium/cc/layers/video_frame_provider_client_impl_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/macros.h" #include "cc/layers/video_frame_provider_client_impl.h" #include "cc/layers/video_layer_impl.h" #include "cc/output/begin_frame_args.h" @@ -18,10 +19,11 @@ namespace cc { // NOTE: We cannot use DebugScopedSetImplThreadAndMainThreadBlocked in these // tests because it gets destroyed before the VideoLayerImpl is destroyed. This // causes a DCHECK in VideoLayerImpl's destructor to fail. -static void DebugSetImplThreadAndMainThreadBlocked(Proxy* proxy) { +static void DebugSetImplThreadAndMainThreadBlocked( + TaskRunnerProvider* task_runner_provider) { #if DCHECK_IS_ON() - proxy->SetCurrentThreadIsImplThread(true); - proxy->SetMainThreadBlocked(true); + task_runner_provider->SetCurrentThreadIsImplThread(true); + task_runner_provider->SetMainThreadBlocked(true); #endif } @@ -36,7 +38,7 @@ class VideoFrameProviderClientImplTest : public testing::Test, gfx::Rect(10, 10), gfx::Size(10, 10), base::TimeDelta())) { - DebugSetImplThreadAndMainThreadBlocked(impl_.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl_.task_runner_provider()); } ~VideoFrameProviderClientImplTest() { diff --git a/chromium/cc/layers/video_layer.cc b/chromium/cc/layers/video_layer.cc index cae00aacf1d..49d6490d7d1 100644 --- a/chromium/cc/layers/video_layer.cc +++ b/chromium/cc/layers/video_layer.cc @@ -25,9 +25,7 @@ VideoLayer::VideoLayer(const LayerSettings& settings, VideoLayer::~VideoLayer() {} scoped_ptr<LayerImpl> VideoLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { - scoped_ptr<VideoLayerImpl> impl = - VideoLayerImpl::Create(tree_impl, id(), provider_, video_rotation_); - return impl.Pass(); + return VideoLayerImpl::Create(tree_impl, id(), provider_, video_rotation_); } bool VideoLayer::Update() { diff --git a/chromium/cc/layers/video_layer.h b/chromium/cc/layers/video_layer.h index 575de4664f0..a59f1cc5668 100644 --- a/chromium/cc/layers/video_layer.h +++ b/chromium/cc/layers/video_layer.h @@ -6,6 +6,7 @@ #define CC_LAYERS_VIDEO_LAYER_H_ #include "base/callback.h" +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer.h" #include "media/base/video_rotation.h" diff --git a/chromium/cc/layers/video_layer_impl.cc b/chromium/cc/layers/video_layer_impl.cc index 3313aa5cfb1..39b8ef20c59 100644 --- a/chromium/cc/layers/video_layer_impl.cc +++ b/chromium/cc/layers/video_layer_impl.cc @@ -4,6 +4,8 @@ #include "cc/layers/video_layer_impl.h" +#include <stddef.h> + #include "base/bind.h" #include "base/logging.h" #include "cc/layers/video_frame_provider_client_impl.h" @@ -15,7 +17,7 @@ #include "cc/resources/single_release_callback_impl.h" #include "cc/trees/layer_tree_impl.h" #include "cc/trees/occlusion.h" -#include "cc/trees/proxy.h" +#include "cc/trees/task_runner_provider.h" #include "media/base/video_frame.h" #if defined(VIDEO_HOLE) @@ -30,8 +32,8 @@ scoped_ptr<VideoLayerImpl> VideoLayerImpl::Create( int id, VideoFrameProvider* provider, media::VideoRotation video_rotation) { - DCHECK(tree_impl->proxy()->IsMainThreadBlocked()); - DCHECK(tree_impl->proxy()->IsImplThread()); + DCHECK(tree_impl->task_runner_provider()->IsMainThreadBlocked()); + DCHECK(tree_impl->task_runner_provider()->IsImplThread()); scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl = VideoFrameProviderClientImpl::Create( @@ -59,8 +61,8 @@ VideoLayerImpl::~VideoLayerImpl() { // on the VideoFrameProviderClientImpl, but we stop when the first // LayerImpl (the one on the pending tree) is destroyed since we know // the main thread is blocked for this commit. - DCHECK(layer_tree_impl()->proxy()->IsImplThread()); - DCHECK(layer_tree_impl()->proxy()->IsMainThreadBlocked()); + DCHECK(layer_tree_impl()->task_runner_provider()->IsImplThread()); + DCHECK(layer_tree_impl()->task_runner_provider()->IsMainThreadBlocked()); provider_client_impl_->Stop(); } } @@ -128,7 +130,7 @@ bool VideoLayerImpl::WillDraw(DrawMode draw_mode, external_resources.read_lock_fences_enabled); frame_resources_.push_back(FrameResource( resource_id, external_resources.mailboxes[i].size_in_pixels(), - external_resources.mailboxes[i].allow_overlay())); + external_resources.mailboxes[i].is_overlay_candidate())); } return true; @@ -138,7 +140,7 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, AppendQuadsData* append_quads_data) { DCHECK(frame_.get()); - gfx::Transform transform = draw_transform(); + gfx::Transform transform = DrawTransform(); gfx::Size rotated_size = bounds(); switch (video_rotation_) { @@ -233,26 +235,20 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, } const gfx::Size ya_tex_size = coded_size; - gfx::Size uv_tex_size; + gfx::Size uv_tex_size = media::VideoFrame::PlaneSize( + frame_->format(), media::VideoFrame::kUPlane, coded_size); if (frame_->HasTextures()) { DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_->format()); DCHECK_EQ(3u, frame_resources_.size()); // Alpha is not supported yet. - DCHECK(visible_rect.origin().IsOrigin()); - DCHECK(visible_rect.size() == coded_size); - uv_tex_size.SetSize((ya_tex_size.width() + 1) / 2, - (ya_tex_size.height() + 1) / 2); } else { - uv_tex_size = media::VideoFrame::PlaneSize( - frame_->format(), media::VideoFrame::kUPlane, coded_size); DCHECK(uv_tex_size == media::VideoFrame::PlaneSize( frame_->format(), media::VideoFrame::kVPlane, coded_size)); - DCHECK_IMPLIES( - frame_resources_.size() > 3, - ya_tex_size == - media::VideoFrame::PlaneSize( - frame_->format(), media::VideoFrame::kAPlane, coded_size)); + DCHECK(frame_resources_.size() <= 3 || + ya_tex_size == media::VideoFrame::PlaneSize( + frame_->format(), media::VideoFrame::kAPlane, + coded_size)); } // Compute the UV sub-sampling factor based on the ratio between @@ -281,12 +277,14 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, break; } case VideoFrameExternalResources::RGBA_RESOURCE: + case VideoFrameExternalResources::RGBA_PREMULTIPLIED_RESOURCE: case VideoFrameExternalResources::RGB_RESOURCE: { DCHECK_EQ(frame_resources_.size(), 1u); if (frame_resources_.size() < 1u) break; bool premultiplied_alpha = - (frame_resource_type_ == VideoFrameExternalResources::RGBA_RESOURCE); + frame_resource_type_ == + VideoFrameExternalResources::RGBA_PREMULTIPLIED_RESOURCE; gfx::PointF uv_top_left(0.f, 0.f); gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale); float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; @@ -313,7 +311,6 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, stream_video_quad->SetNew( shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, frame_resources_[0].id, frame_resources_[0].size_in_pixels, - frame_resources_[0].allow_overlay, scale * provider_client_impl_->StreamTextureMatrix()); ValidateQuadResources(stream_video_quad); break; @@ -327,8 +324,7 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, io_surface_quad->SetNew(shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, visible_rect.size(), frame_resources_[0].id, - IOSurfaceDrawQuad::UNFLIPPED, - frame_resources_[0].allow_overlay); + IOSurfaceDrawQuad::UNFLIPPED); ValidateQuadResources(io_surface_quad); break; } @@ -371,8 +367,10 @@ void VideoLayerImpl::DidDraw(ResourceProvider* resource_provider) { if (frame_resource_type_ == VideoFrameExternalResources::SOFTWARE_RESOURCE) { for (size_t i = 0; i < software_resources_.size(); ++i) { - software_release_callback_.Run( - 0, false, layer_tree_impl()->BlockingMainThreadTaskRunner()); + software_release_callback_.Run(gpu::SyncToken(), false, + layer_tree_impl() + ->task_runner_provider() + ->blocking_main_thread_task_runner()); } software_resources_.clear(); diff --git a/chromium/cc/layers/video_layer_impl.h b/chromium/cc/layers/video_layer_impl.h index 6fab7f58dcb..c1688e887c8 100644 --- a/chromium/cc/layers/video_layer_impl.h +++ b/chromium/cc/layers/video_layer_impl.h @@ -7,6 +7,7 @@ #include <vector> +#include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" #include "cc/resources/release_callback_impl.h" @@ -63,13 +64,15 @@ class CC_EXPORT VideoLayerImpl : public LayerImpl { scoped_ptr<VideoResourceUpdater> updater_; VideoFrameExternalResources::ResourceType frame_resource_type_; struct FrameResource { - FrameResource(ResourceId id, gfx::Size size_in_pixels, bool allow_overlay) + FrameResource(ResourceId id, + gfx::Size size_in_pixels, + bool is_overlay_candidate) : id(id), size_in_pixels(size_in_pixels), - allow_overlay(allow_overlay) {} + is_overlay_candidate(is_overlay_candidate) {} ResourceId id; gfx::Size size_in_pixels; - bool allow_overlay; + bool is_overlay_candidate; }; std::vector<FrameResource> frame_resources_; diff --git a/chromium/cc/layers/video_layer_impl_unittest.cc b/chromium/cc/layers/video_layer_impl_unittest.cc index 28ba58acc2d..355837601ac 100644 --- a/chromium/cc/layers/video_layer_impl_unittest.cc +++ b/chromium/cc/layers/video_layer_impl_unittest.cc @@ -4,6 +4,8 @@ #include "cc/layers/video_layer_impl.h" +#include <stddef.h> + #include "cc/layers/video_frame_provider_client_impl.h" #include "cc/output/context_provider.h" #include "cc/output/output_surface.h" @@ -21,10 +23,11 @@ namespace { // NOTE: We cannot use DebugScopedSetImplThreadAndMainThreadBlocked in these // tests because it gets destroyed before the VideoLayerImpl is destroyed. This // causes a DCHECK in VideoLayerImpl's destructor to fail. -static void DebugSetImplThreadAndMainThreadBlocked(Proxy* proxy) { +static void DebugSetImplThreadAndMainThreadBlocked( + TaskRunnerProvider* task_runner_provider) { #if DCHECK_IS_ON() - proxy->SetCurrentThreadIsImplThread(true); - proxy->SetMainThreadBlocked(true); + task_runner_provider->SetCurrentThreadIsImplThread(true); + task_runner_provider->SetMainThreadBlocked(true); #endif } @@ -33,7 +36,7 @@ TEST(VideoLayerImplTest, Occlusion) { gfx::Size viewport_size(1000, 1000); LayerTestCommon::LayerImplTest impl; - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( media::PIXEL_FORMAT_YV12, gfx::Size(10, 10), gfx::Rect(10, 10), @@ -87,12 +90,12 @@ TEST(VideoLayerImplTest, OccludesOtherLayers) { LayerTestCommon::LayerImplTest impl; impl.host_impl()->SetViewportSize(layer_size); - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); auto active_tree = impl.host_impl()->active_tree(); // Create a video layer with no frame on top of another layer. scoped_ptr<LayerImpl> layer_impl = LayerImpl::Create(active_tree, 3); - layer_impl->SetHasRenderSurface(true); + layer_impl->SetForceRenderSurface(true); layer_impl->SetBounds(layer_size); layer_impl->SetDrawsContent(true); const auto& draw_properties = layer_impl->draw_properties(); @@ -104,8 +107,8 @@ TEST(VideoLayerImplTest, OccludesOtherLayers) { video_layer_impl->SetDrawsContent(true); video_layer_impl->SetContentsOpaque(true); - layer_impl->AddChild(video_layer_impl.Pass()); - active_tree->SetRootLayer(layer_impl.Pass()); + layer_impl->AddChild(std::move(video_layer_impl)); + active_tree->SetRootLayer(std::move(layer_impl)); active_tree->BuildPropertyTreesForTesting(); @@ -127,7 +130,7 @@ TEST(VideoLayerImplTest, OccludesOtherLayers) { TEST(VideoLayerImplTest, DidBecomeActiveShouldSetActiveVideoLayer) { LayerTestCommon::LayerImplTest impl; - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); FakeVideoFrameProvider provider; VideoLayerImpl* video_layer_impl = @@ -147,7 +150,7 @@ TEST(VideoLayerImplTest, Rotated0) { gfx::Size viewport_size(1000, 500); LayerTestCommon::LayerImplTest impl; - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( media::PIXEL_FORMAT_YV12, gfx::Size(20, 10), gfx::Rect(20, 10), @@ -183,7 +186,7 @@ TEST(VideoLayerImplTest, Rotated90) { gfx::Size viewport_size(1000, 500); LayerTestCommon::LayerImplTest impl; - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( media::PIXEL_FORMAT_YV12, gfx::Size(20, 10), gfx::Rect(20, 10), @@ -219,7 +222,7 @@ TEST(VideoLayerImplTest, Rotated180) { gfx::Size viewport_size(1000, 500); LayerTestCommon::LayerImplTest impl; - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( media::PIXEL_FORMAT_YV12, gfx::Size(20, 10), gfx::Rect(20, 10), @@ -255,7 +258,7 @@ TEST(VideoLayerImplTest, Rotated270) { gfx::Size viewport_size(1000, 500); LayerTestCommon::LayerImplTest impl; - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( media::PIXEL_FORMAT_YV12, gfx::Size(20, 10), gfx::Rect(20, 10), @@ -286,15 +289,14 @@ TEST(VideoLayerImplTest, Rotated270) { EXPECT_EQ(gfx::Point3F(0, 0, 0), p2); } -void EmptyCallback(unsigned sync_point) { -} +void EmptyCallback(const gpu::SyncToken& sync_token) {} TEST(VideoLayerImplTest, SoftwareVideoFrameGeneratesYUVQuad) { gfx::Size layer_size(1000, 1000); gfx::Size viewport_size(1000, 1000); LayerTestCommon::LayerImplTest impl; - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); gpu::MailboxHolder mailbox_holder; mailbox_holder.mailbox.name[0] = 1; @@ -331,7 +333,7 @@ TEST(VideoLayerImplTest, NativeYUVFrameGeneratesYUVQuad) { gfx::Size viewport_size(1000, 1000); LayerTestCommon::LayerImplTest impl; - DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); + DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider()); gpu::MailboxHolder mailbox_holder; mailbox_holder.mailbox.name[0] = 1; @@ -341,6 +343,7 @@ TEST(VideoLayerImplTest, NativeYUVFrameGeneratesYUVQuad) { mailbox_holder, mailbox_holder, mailbox_holder, base::Bind(EmptyCallback), gfx::Size(10, 10), gfx::Rect(10, 10), gfx::Size(10, 10), base::TimeDelta()); + ASSERT_TRUE(video_frame); video_frame->metadata()->SetBoolean(media::VideoFrameMetadata::ALLOW_OVERLAY, true); FakeVideoFrameProvider provider; diff --git a/chromium/cc/layers/viewport.cc b/chromium/cc/layers/viewport.cc index 4b68de5376e..3483d673452 100644 --- a/chromium/cc/layers/viewport.cc +++ b/chromium/cc/layers/viewport.cc @@ -93,11 +93,11 @@ void Viewport::PinchUpdate(float magnify_delta, const gfx::Point& anchor) { gfx::Point adjusted_anchor = anchor + pinch_anchor_adjustment_; float page_scale = active_tree->current_page_scale_factor(); gfx::PointF previous_scale_anchor = - gfx::ScalePoint(adjusted_anchor, 1.f / page_scale); + gfx::ScalePoint(gfx::PointF(adjusted_anchor), 1.f / page_scale); active_tree->SetPageScaleOnActiveTree(page_scale * magnify_delta); page_scale = active_tree->current_page_scale_factor(); gfx::PointF new_scale_anchor = - gfx::ScalePoint(adjusted_anchor, 1.f / page_scale); + gfx::ScalePoint(gfx::PointF(adjusted_anchor), 1.f / page_scale); gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; // Scale back to viewport space since that's the coordinate space ScrollBy diff --git a/chromium/cc/layers/viewport.h b/chromium/cc/layers/viewport.h index 5d96cd3b283..5052b5e2499 100644 --- a/chromium/cc/layers/viewport.h +++ b/chromium/cc/layers/viewport.h @@ -5,6 +5,7 @@ #ifndef CC_LAYERS_VIEWPORT_H_ #define CC_LAYERS_VIEWPORT_H_ +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "cc/layers/layer_impl.h" #include "ui/gfx/geometry/vector2d_f.h" |