Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 1357423009: gfx: Make conversions from Size to SizeF be explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 } 2306 }
2307 2307
2308 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 2308 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
2309 float device_scale_factor) { 2309 float device_scale_factor) {
2310 LayerTreeSettings settings; 2310 LayerTreeSettings settings;
2311 settings.scrollbar_fade_delay_ms = 500; 2311 settings.scrollbar_fade_delay_ms = 500;
2312 settings.scrollbar_fade_duration_ms = 300; 2312 settings.scrollbar_fade_duration_ms = 300;
2313 settings.scrollbar_animator = LayerTreeSettings::THINNING; 2313 settings.scrollbar_animator = LayerTreeSettings::THINNING;
2314 2314
2315 gfx::Size viewport_size(300, 200); 2315 gfx::Size viewport_size(300, 200);
2316 gfx::Size device_viewport_size = gfx::ToFlooredSize( 2316 gfx::Size device_viewport_size =
2317 gfx::ScaleSize(viewport_size, device_scale_factor)); 2317 gfx::ScaleToFlooredSize(viewport_size, device_scale_factor);
2318 gfx::Size content_size(1000, 1000); 2318 gfx::Size content_size(1000, 1000);
2319 2319
2320 CreateHostImpl(settings, CreateOutputSurface()); 2320 CreateHostImpl(settings, CreateOutputSurface());
2321 host_impl_->SetDeviceScaleFactor(device_scale_factor); 2321 host_impl_->SetDeviceScaleFactor(device_scale_factor);
2322 host_impl_->SetViewportSize(device_viewport_size); 2322 host_impl_->SetViewportSize(device_viewport_size);
2323 2323
2324 scoped_ptr<LayerImpl> root = 2324 scoped_ptr<LayerImpl> root =
2325 LayerImpl::Create(host_impl_->active_tree(), 1); 2325 LayerImpl::Create(host_impl_->active_tree(), 1);
2326 root->SetBounds(viewport_size); 2326 root->SetBounds(viewport_size);
2327 root->SetHasRenderSurface(true); 2327 root->SetHasRenderSurface(true);
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
3632 EXPECT_FLOAT_EQ(scroll_delta.y(), 3632 EXPECT_FLOAT_EQ(scroll_delta.y(),
3633 top_controls_height_ - 3633 top_controls_height_ -
3634 host_impl_->top_controls_manager()->ContentTopOffset()); 3634 host_impl_->top_controls_manager()->ContentTopOffset());
3635 3635
3636 // Top controls were hidden by 25px so the inner viewport should have expanded 3636 // Top controls were hidden by 25px so the inner viewport should have expanded
3637 // by that much. 3637 // by that much.
3638 LayerImpl* outer_container = 3638 LayerImpl* outer_container =
3639 host_impl_->active_tree()->OuterViewportContainerLayer(); 3639 host_impl_->active_tree()->OuterViewportContainerLayer();
3640 LayerImpl* inner_container = 3640 LayerImpl* inner_container =
3641 host_impl_->active_tree()->InnerViewportContainerLayer(); 3641 host_impl_->active_tree()->InnerViewportContainerLayer();
3642 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling()); 3642 EXPECT_EQ(gfx::SizeF(100.f, 100.f + 25.f),
3643 inner_container->BoundsForScrolling());
3643 3644
3644 // Outer viewport should match inner's aspect ratio. The bounds are ceiled. 3645 // Outer viewport should match inner's aspect ratio. The bounds are ceiled.
3645 float aspect_ratio = inner_container->BoundsForScrolling().width() / 3646 float aspect_ratio = inner_container->BoundsForScrolling().width() /
3646 inner_container->BoundsForScrolling().height(); 3647 inner_container->BoundsForScrolling().height();
3647 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio)); 3648 gfx::SizeF expected =
3649 gfx::SizeF(gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio)));
vmpstr 2015/09/23 23:04:25 This is a bit weird. It almost like we want ToCeil
3648 EXPECT_EQ(expected, outer_container->BoundsForScrolling()); 3650 EXPECT_EQ(expected, outer_container->BoundsForScrolling());
3649 EXPECT_EQ(expected, 3651 EXPECT_EQ(expected,
3650 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); 3652 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling());
3651 } 3653 }
3652 3654
3653 // Test that scrolling the outer viewport affects the top controls. 3655 // Test that scrolling the outer viewport affects the top controls.
3654 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { 3656 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) {
3655 SetupTopControlsAndScrollLayerWithVirtualViewport( 3657 SetupTopControlsAndScrollLayerWithVirtualViewport(
3656 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 3658 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
3657 DrawFrame(); 3659 DrawFrame();
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
4702 host_impl_->ScrollEnd(); 4704 host_impl_->ScrollEnd();
4703 host_impl_->SetSynchronousInputHandlerRootScrollOffset(gfx::ScrollOffset()); 4705 host_impl_->SetSynchronousInputHandlerRootScrollOffset(gfx::ScrollOffset());
4704 4706
4705 // Forces a full tree synchronization and ensures that the scroll delegate 4707 // Forces a full tree synchronization and ensures that the scroll delegate
4706 // sees the correct size of the new tree. 4708 // sees the correct size of the new tree.
4707 gfx::Size new_size(42, 24); 4709 gfx::Size new_size(42, 24);
4708 host_impl_->CreatePendingTree(); 4710 host_impl_->CreatePendingTree();
4709 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); 4711 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
4710 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); 4712 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size);
4711 host_impl_->ActivateSyncTree(); 4713 host_impl_->ActivateSyncTree();
4712 EXPECT_EQ(new_size, scroll_watcher.scrollable_size()); 4714 EXPECT_EQ(gfx::SizeF(new_size), scroll_watcher.scrollable_size());
4713 4715
4714 // Tear down the LayerTreeHostImpl before the InputHandlerClient. 4716 // Tear down the LayerTreeHostImpl before the InputHandlerClient.
4715 host_impl_.reset(); 4717 host_impl_.reset();
4716 } 4718 }
4717 4719
4718 void CheckLayerScrollDelta(LayerImpl* layer, gfx::Vector2dF scroll_delta) { 4720 void CheckLayerScrollDelta(LayerImpl* layer, gfx::Vector2dF scroll_delta) {
4719 const gfx::Transform target_space_transform = 4721 const gfx::Transform target_space_transform =
4720 layer->draw_properties().target_space_transform; 4722 layer->draw_properties().target_space_transform;
4721 EXPECT_TRUE(target_space_transform.IsScaleOrTranslation()); 4723 EXPECT_TRUE(target_space_transform.IsScaleOrTranslation());
4722 gfx::Point translated_point; 4724 gfx::Point translated_point;
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
5482 quad_list, gfx::Rect(DipSizeToPixelSize(viewport_size_))); 5484 quad_list, gfx::Rect(DipSizeToPixelSize(viewport_size_)));
5483 } 5485 }
5484 5486
5485 // Make sure that the texture coordinates match their expectations. 5487 // Make sure that the texture coordinates match their expectations.
5486 void ValidateTextureDrawQuads(const QuadList& quad_list) { 5488 void ValidateTextureDrawQuads(const QuadList& quad_list) {
5487 for (const auto& quad : quad_list) { 5489 for (const auto& quad : quad_list) {
5488 if (quad->material != DrawQuad::TEXTURE_CONTENT) 5490 if (quad->material != DrawQuad::TEXTURE_CONTENT)
5489 continue; 5491 continue;
5490 const TextureDrawQuad* texture_quad = TextureDrawQuad::MaterialCast(quad); 5492 const TextureDrawQuad* texture_quad = TextureDrawQuad::MaterialCast(quad);
5491 gfx::SizeF gutter_texture_size_pixels = gfx::ScaleSize( 5493 gfx::SizeF gutter_texture_size_pixels = gfx::ScaleSize(
5492 gutter_texture_size_, host_impl_->device_scale_factor()); 5494 gfx::SizeF(gutter_texture_size_), host_impl_->device_scale_factor());
5493 EXPECT_EQ(texture_quad->uv_top_left.x(), 5495 EXPECT_EQ(texture_quad->uv_top_left.x(),
5494 texture_quad->rect.x() / gutter_texture_size_pixels.width()); 5496 texture_quad->rect.x() / gutter_texture_size_pixels.width());
5495 EXPECT_EQ(texture_quad->uv_top_left.y(), 5497 EXPECT_EQ(texture_quad->uv_top_left.y(),
5496 texture_quad->rect.y() / gutter_texture_size_pixels.height()); 5498 texture_quad->rect.y() / gutter_texture_size_pixels.height());
5497 EXPECT_EQ( 5499 EXPECT_EQ(
5498 texture_quad->uv_bottom_right.x(), 5500 texture_quad->uv_bottom_right.x(),
5499 texture_quad->rect.right() / gutter_texture_size_pixels.width()); 5501 texture_quad->rect.right() / gutter_texture_size_pixels.width());
5500 EXPECT_EQ( 5502 EXPECT_EQ(
5501 texture_quad->uv_bottom_right.y(), 5503 texture_quad->uv_bottom_right.y(),
5502 texture_quad->rect.bottom() / gutter_texture_size_pixels.height()); 5504 texture_quad->rect.bottom() / gutter_texture_size_pixels.height());
5503 } 5505 }
5504 } 5506 }
5505 5507
5506 gfx::Size DipSizeToPixelSize(const gfx::Size& size) { 5508 gfx::Size DipSizeToPixelSize(const gfx::Size& size) {
5507 return gfx::ToRoundedSize( 5509 return gfx::ScaleToRoundedSize(size, host_impl_->device_scale_factor());
5508 gfx::ScaleSize(size, host_impl_->device_scale_factor()));
5509 } 5510 }
5510 5511
5511 DrawQuad::Material gutter_quad_material_; 5512 DrawQuad::Material gutter_quad_material_;
5512 gfx::Size gutter_texture_size_; 5513 gfx::Size gutter_texture_size_;
5513 gfx::Size viewport_size_; 5514 gfx::Size viewport_size_;
5514 BlendStateCheckLayer* child_; 5515 BlendStateCheckLayer* child_;
5515 bool did_activate_pending_tree_; 5516 bool did_activate_pending_tree_;
5516 }; 5517 };
5517 5518
5518 TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCovered) { 5519 TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCovered) {
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
6266 using GLRenderer::ShouldAntialiasQuad; 6267 using GLRenderer::ShouldAntialiasQuad;
6267 }; 6268 };
6268 6269
6269 TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { 6270 TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) {
6270 // Due to precision issues (especially on Android), sometimes far 6271 // Due to precision issues (especially on Android), sometimes far
6271 // away quads can end up thinking they need AA. 6272 // away quads can end up thinking they need AA.
6272 float device_scale_factor = 4.f / 3.f; 6273 float device_scale_factor = 4.f / 3.f;
6273 host_impl_->SetDeviceScaleFactor(device_scale_factor); 6274 host_impl_->SetDeviceScaleFactor(device_scale_factor);
6274 gfx::Size root_size(2000, 1000); 6275 gfx::Size root_size(2000, 1000);
6275 gfx::Size device_viewport_size = 6276 gfx::Size device_viewport_size =
6276 gfx::ToCeiledSize(gfx::ScaleSize(root_size, device_scale_factor)); 6277 gfx::ScaleToCeiledSize(root_size, device_scale_factor);
6277 host_impl_->SetViewportSize(device_viewport_size); 6278 host_impl_->SetViewportSize(device_viewport_size);
6278 6279
6279 host_impl_->CreatePendingTree(); 6280 host_impl_->CreatePendingTree();
6280 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f / 16.f, 6281 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f / 16.f,
6281 16.f); 6282 16.f);
6282 6283
6283 scoped_ptr<LayerImpl> scoped_root = 6284 scoped_ptr<LayerImpl> scoped_root =
6284 LayerImpl::Create(host_impl_->pending_tree(), 1); 6285 LayerImpl::Create(host_impl_->pending_tree(), 1);
6285 LayerImpl* root = scoped_root.get(); 6286 LayerImpl* root = scoped_root.get();
6286 root->SetHasRenderSurface(true); 6287 root->SetHasRenderSurface(true);
(...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after
8547 // Hold an unowned pointer to the output surface to use for mock expectations. 8548 // Hold an unowned pointer to the output surface to use for mock expectations.
8548 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); 8549 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get();
8549 8550
8550 CreateHostImpl(DefaultSettings(), output_surface.Pass()); 8551 CreateHostImpl(DefaultSettings(), output_surface.Pass());
8551 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); 8552 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1);
8552 host_impl_->BeginCommit(); 8553 host_impl_->BeginCommit();
8553 } 8554 }
8554 8555
8555 } // namespace 8556 } // namespace
8556 } // namespace cc 8557 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698