| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 2298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2309 } | 2309 } |
| 2310 | 2310 |
| 2311 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( | 2311 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( |
| 2312 float device_scale_factor) { | 2312 float device_scale_factor) { |
| 2313 LayerTreeSettings settings; | 2313 LayerTreeSettings settings; |
| 2314 settings.scrollbar_fade_delay_ms = 500; | 2314 settings.scrollbar_fade_delay_ms = 500; |
| 2315 settings.scrollbar_fade_duration_ms = 300; | 2315 settings.scrollbar_fade_duration_ms = 300; |
| 2316 settings.scrollbar_animator = LayerTreeSettings::THINNING; | 2316 settings.scrollbar_animator = LayerTreeSettings::THINNING; |
| 2317 | 2317 |
| 2318 gfx::Size viewport_size(300, 200); | 2318 gfx::Size viewport_size(300, 200); |
| 2319 gfx::Size device_viewport_size = gfx::ToFlooredSize( | 2319 gfx::Size device_viewport_size = |
| 2320 gfx::ScaleSize(viewport_size, device_scale_factor)); | 2320 gfx::ScaleToFlooredSize(viewport_size, device_scale_factor); |
| 2321 gfx::Size content_size(1000, 1000); | 2321 gfx::Size content_size(1000, 1000); |
| 2322 | 2322 |
| 2323 CreateHostImpl(settings, CreateOutputSurface()); | 2323 CreateHostImpl(settings, CreateOutputSurface()); |
| 2324 host_impl_->SetDeviceScaleFactor(device_scale_factor); | 2324 host_impl_->SetDeviceScaleFactor(device_scale_factor); |
| 2325 host_impl_->SetViewportSize(device_viewport_size); | 2325 host_impl_->SetViewportSize(device_viewport_size); |
| 2326 | 2326 |
| 2327 scoped_ptr<LayerImpl> root = | 2327 scoped_ptr<LayerImpl> root = |
| 2328 LayerImpl::Create(host_impl_->active_tree(), 1); | 2328 LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2329 root->SetBounds(viewport_size); | 2329 root->SetBounds(viewport_size); |
| 2330 root->SetHasRenderSurface(true); | 2330 root->SetHasRenderSurface(true); |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3635 EXPECT_FLOAT_EQ(scroll_delta.y(), | 3635 EXPECT_FLOAT_EQ(scroll_delta.y(), |
| 3636 top_controls_height_ - | 3636 top_controls_height_ - |
| 3637 host_impl_->top_controls_manager()->ContentTopOffset()); | 3637 host_impl_->top_controls_manager()->ContentTopOffset()); |
| 3638 | 3638 |
| 3639 // Top controls were hidden by 25px so the inner viewport should have expanded | 3639 // Top controls were hidden by 25px so the inner viewport should have expanded |
| 3640 // by that much. | 3640 // by that much. |
| 3641 LayerImpl* outer_container = | 3641 LayerImpl* outer_container = |
| 3642 host_impl_->active_tree()->OuterViewportContainerLayer(); | 3642 host_impl_->active_tree()->OuterViewportContainerLayer(); |
| 3643 LayerImpl* inner_container = | 3643 LayerImpl* inner_container = |
| 3644 host_impl_->active_tree()->InnerViewportContainerLayer(); | 3644 host_impl_->active_tree()->InnerViewportContainerLayer(); |
| 3645 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling()); | 3645 EXPECT_EQ(gfx::SizeF(100.f, 100.f + 25.f), |
| 3646 inner_container->BoundsForScrolling()); |
| 3646 | 3647 |
| 3647 // Outer viewport should match inner's aspect ratio. The bounds are ceiled. | 3648 // Outer viewport should match inner's aspect ratio. The bounds are ceiled. |
| 3648 float aspect_ratio = inner_container->BoundsForScrolling().width() / | 3649 float aspect_ratio = inner_container->BoundsForScrolling().width() / |
| 3649 inner_container->BoundsForScrolling().height(); | 3650 inner_container->BoundsForScrolling().height(); |
| 3650 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio)); | 3651 gfx::SizeF expected = |
| 3652 gfx::SizeF(gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio))); |
| 3651 EXPECT_EQ(expected, outer_container->BoundsForScrolling()); | 3653 EXPECT_EQ(expected, outer_container->BoundsForScrolling()); |
| 3652 EXPECT_EQ(expected, | 3654 EXPECT_EQ(expected, |
| 3653 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); | 3655 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); |
| 3654 } | 3656 } |
| 3655 | 3657 |
| 3656 // Test that scrolling the outer viewport affects the top controls. | 3658 // Test that scrolling the outer viewport affects the top controls. |
| 3657 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { | 3659 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { |
| 3658 SetupTopControlsAndScrollLayerWithVirtualViewport( | 3660 SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 3659 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); | 3661 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); |
| 3660 DrawFrame(); | 3662 DrawFrame(); |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4705 host_impl_->ScrollEnd(); | 4707 host_impl_->ScrollEnd(); |
| 4706 host_impl_->SetSynchronousInputHandlerRootScrollOffset(gfx::ScrollOffset()); | 4708 host_impl_->SetSynchronousInputHandlerRootScrollOffset(gfx::ScrollOffset()); |
| 4707 | 4709 |
| 4708 // Forces a full tree synchronization and ensures that the scroll delegate | 4710 // Forces a full tree synchronization and ensures that the scroll delegate |
| 4709 // sees the correct size of the new tree. | 4711 // sees the correct size of the new tree. |
| 4710 gfx::Size new_size(42, 24); | 4712 gfx::Size new_size(42, 24); |
| 4711 host_impl_->CreatePendingTree(); | 4713 host_impl_->CreatePendingTree(); |
| 4712 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); | 4714 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
| 4713 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); | 4715 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); |
| 4714 host_impl_->ActivateSyncTree(); | 4716 host_impl_->ActivateSyncTree(); |
| 4715 EXPECT_EQ(new_size, scroll_watcher.scrollable_size()); | 4717 EXPECT_EQ(gfx::SizeF(new_size), scroll_watcher.scrollable_size()); |
| 4716 | 4718 |
| 4717 // Tear down the LayerTreeHostImpl before the InputHandlerClient. | 4719 // Tear down the LayerTreeHostImpl before the InputHandlerClient. |
| 4718 host_impl_.reset(); | 4720 host_impl_.reset(); |
| 4719 } | 4721 } |
| 4720 | 4722 |
| 4721 void CheckLayerScrollDelta(LayerImpl* layer, gfx::Vector2dF scroll_delta) { | 4723 void CheckLayerScrollDelta(LayerImpl* layer, gfx::Vector2dF scroll_delta) { |
| 4722 const gfx::Transform target_space_transform = | 4724 const gfx::Transform target_space_transform = |
| 4723 layer->draw_properties().target_space_transform; | 4725 layer->draw_properties().target_space_transform; |
| 4724 EXPECT_TRUE(target_space_transform.IsScaleOrTranslation()); | 4726 EXPECT_TRUE(target_space_transform.IsScaleOrTranslation()); |
| 4725 gfx::Point translated_point; | 4727 gfx::Point translated_point; |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5485 quad_list, gfx::Rect(DipSizeToPixelSize(viewport_size_))); | 5487 quad_list, gfx::Rect(DipSizeToPixelSize(viewport_size_))); |
| 5486 } | 5488 } |
| 5487 | 5489 |
| 5488 // Make sure that the texture coordinates match their expectations. | 5490 // Make sure that the texture coordinates match their expectations. |
| 5489 void ValidateTextureDrawQuads(const QuadList& quad_list) { | 5491 void ValidateTextureDrawQuads(const QuadList& quad_list) { |
| 5490 for (const auto& quad : quad_list) { | 5492 for (const auto& quad : quad_list) { |
| 5491 if (quad->material != DrawQuad::TEXTURE_CONTENT) | 5493 if (quad->material != DrawQuad::TEXTURE_CONTENT) |
| 5492 continue; | 5494 continue; |
| 5493 const TextureDrawQuad* texture_quad = TextureDrawQuad::MaterialCast(quad); | 5495 const TextureDrawQuad* texture_quad = TextureDrawQuad::MaterialCast(quad); |
| 5494 gfx::SizeF gutter_texture_size_pixels = gfx::ScaleSize( | 5496 gfx::SizeF gutter_texture_size_pixels = gfx::ScaleSize( |
| 5495 gutter_texture_size_, host_impl_->device_scale_factor()); | 5497 gfx::SizeF(gutter_texture_size_), host_impl_->device_scale_factor()); |
| 5496 EXPECT_EQ(texture_quad->uv_top_left.x(), | 5498 EXPECT_EQ(texture_quad->uv_top_left.x(), |
| 5497 texture_quad->rect.x() / gutter_texture_size_pixels.width()); | 5499 texture_quad->rect.x() / gutter_texture_size_pixels.width()); |
| 5498 EXPECT_EQ(texture_quad->uv_top_left.y(), | 5500 EXPECT_EQ(texture_quad->uv_top_left.y(), |
| 5499 texture_quad->rect.y() / gutter_texture_size_pixels.height()); | 5501 texture_quad->rect.y() / gutter_texture_size_pixels.height()); |
| 5500 EXPECT_EQ( | 5502 EXPECT_EQ( |
| 5501 texture_quad->uv_bottom_right.x(), | 5503 texture_quad->uv_bottom_right.x(), |
| 5502 texture_quad->rect.right() / gutter_texture_size_pixels.width()); | 5504 texture_quad->rect.right() / gutter_texture_size_pixels.width()); |
| 5503 EXPECT_EQ( | 5505 EXPECT_EQ( |
| 5504 texture_quad->uv_bottom_right.y(), | 5506 texture_quad->uv_bottom_right.y(), |
| 5505 texture_quad->rect.bottom() / gutter_texture_size_pixels.height()); | 5507 texture_quad->rect.bottom() / gutter_texture_size_pixels.height()); |
| 5506 } | 5508 } |
| 5507 } | 5509 } |
| 5508 | 5510 |
| 5509 gfx::Size DipSizeToPixelSize(const gfx::Size& size) { | 5511 gfx::Size DipSizeToPixelSize(const gfx::Size& size) { |
| 5510 return gfx::ToRoundedSize( | 5512 return gfx::ScaleToRoundedSize(size, host_impl_->device_scale_factor()); |
| 5511 gfx::ScaleSize(size, host_impl_->device_scale_factor())); | |
| 5512 } | 5513 } |
| 5513 | 5514 |
| 5514 DrawQuad::Material gutter_quad_material_; | 5515 DrawQuad::Material gutter_quad_material_; |
| 5515 gfx::Size gutter_texture_size_; | 5516 gfx::Size gutter_texture_size_; |
| 5516 gfx::Size viewport_size_; | 5517 gfx::Size viewport_size_; |
| 5517 BlendStateCheckLayer* child_; | 5518 BlendStateCheckLayer* child_; |
| 5518 bool did_activate_pending_tree_; | 5519 bool did_activate_pending_tree_; |
| 5519 }; | 5520 }; |
| 5520 | 5521 |
| 5521 TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCovered) { | 5522 TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCovered) { |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6274 using GLRenderer::ShouldAntialiasQuad; | 6275 using GLRenderer::ShouldAntialiasQuad; |
| 6275 }; | 6276 }; |
| 6276 | 6277 |
| 6277 TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { | 6278 TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { |
| 6278 // Due to precision issues (especially on Android), sometimes far | 6279 // Due to precision issues (especially on Android), sometimes far |
| 6279 // away quads can end up thinking they need AA. | 6280 // away quads can end up thinking they need AA. |
| 6280 float device_scale_factor = 4.f / 3.f; | 6281 float device_scale_factor = 4.f / 3.f; |
| 6281 host_impl_->SetDeviceScaleFactor(device_scale_factor); | 6282 host_impl_->SetDeviceScaleFactor(device_scale_factor); |
| 6282 gfx::Size root_size(2000, 1000); | 6283 gfx::Size root_size(2000, 1000); |
| 6283 gfx::Size device_viewport_size = | 6284 gfx::Size device_viewport_size = |
| 6284 gfx::ToCeiledSize(gfx::ScaleSize(root_size, device_scale_factor)); | 6285 gfx::ScaleToCeiledSize(root_size, device_scale_factor); |
| 6285 host_impl_->SetViewportSize(device_viewport_size); | 6286 host_impl_->SetViewportSize(device_viewport_size); |
| 6286 | 6287 |
| 6287 host_impl_->CreatePendingTree(); | 6288 host_impl_->CreatePendingTree(); |
| 6288 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f / 16.f, | 6289 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f / 16.f, |
| 6289 16.f); | 6290 16.f); |
| 6290 | 6291 |
| 6291 scoped_ptr<LayerImpl> scoped_root = | 6292 scoped_ptr<LayerImpl> scoped_root = |
| 6292 LayerImpl::Create(host_impl_->pending_tree(), 1); | 6293 LayerImpl::Create(host_impl_->pending_tree(), 1); |
| 6293 LayerImpl* root = scoped_root.get(); | 6294 LayerImpl* root = scoped_root.get(); |
| 6294 root->SetHasRenderSurface(true); | 6295 root->SetHasRenderSurface(true); |
| (...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8556 // Hold an unowned pointer to the output surface to use for mock expectations. | 8557 // Hold an unowned pointer to the output surface to use for mock expectations. |
| 8557 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); | 8558 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); |
| 8558 | 8559 |
| 8559 CreateHostImpl(DefaultSettings(), output_surface.Pass()); | 8560 CreateHostImpl(DefaultSettings(), output_surface.Pass()); |
| 8560 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); | 8561 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); |
| 8561 host_impl_->BeginCommit(); | 8562 host_impl_->BeginCommit(); |
| 8562 } | 8563 } |
| 8563 | 8564 |
| 8564 } // namespace | 8565 } // namespace |
| 8565 } // namespace cc | 8566 } // namespace cc |
| OLD | NEW |