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

Side by Side Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 15294018: Limit size of scaled layer rects in ScrollbarLayer to content_bounds(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to fix merge conflict. Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « cc/layers/scrollbar_layer.cc ('k') | cc/test/fake_web_scrollbar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layers/scrollbar_layer.h" 5 #include "cc/layers/scrollbar_layer.h"
6 6
7 #include "cc/animation/scrollbar_animation_controller.h" 7 #include "cc/animation/scrollbar_animation_controller.h"
8 #include "cc/layers/append_quads_data.h" 8 #include "cc/layers/append_quads_data.h"
9 #include "cc/layers/scrollbar_layer_impl.h" 9 #include "cc/layers/scrollbar_layer_impl.h"
10 #include "cc/quads/solid_color_draw_quad.h" 10 #include "cc/quads/solid_color_draw_quad.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 419 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) {
420 layer_tree_settings_.solid_color_scrollbars = false; 420 layer_tree_settings_.solid_color_scrollbars = false;
421 TestResourceUpload(2); 421 TestResourceUpload(2);
422 } 422 }
423 423
424 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 424 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) {
425 layer_tree_settings_.solid_color_scrollbars = true; 425 layer_tree_settings_.solid_color_scrollbars = true;
426 TestResourceUpload(0); 426 TestResourceUpload(0);
427 } 427 }
428 428
429 class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
430 public:
431 ScaledScrollbarLayerTestResourceCreation()
432 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
433
434 void TestResourceUpload(size_t expected_resources, const float test_scale) {
435 layer_tree_host_.reset(
436 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
437
438 WebKit::WebPoint scrollbar_location = WebKit::WebPoint(0, 185);
439 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create());
440 static_cast<FakeWebScrollbar*>(scrollbar.get())
441 ->SetLocation(scrollbar_location);
442
443 scoped_refptr<Layer> layer_tree_root = Layer::Create();
444 scoped_refptr<Layer> content_layer = Layer::Create();
445 scoped_refptr<Layer> scrollbar_layer =
446 ScrollbarLayer::Create(scrollbar.Pass(),
447 FakeScrollbarThemePainter::Create(false)
448 .PassAs<ScrollbarThemePainter>(),
449 FakeWebScrollbarThemeGeometry::Create(true),
450 layer_tree_root->id());
451 layer_tree_root->AddChild(content_layer);
452 layer_tree_root->AddChild(scrollbar_layer);
453
454 layer_tree_host_->InitializeOutputSurfaceIfNeeded();
455 layer_tree_host_->contents_texture_manager()->
456 SetMaxMemoryLimitBytes(1024 * 1024);
457 layer_tree_host_->SetRootLayer(layer_tree_root);
458
459 scrollbar_layer->SetIsDrawable(true);
460 scrollbar_layer->SetBounds(gfx::Size(100, 15));
461 scrollbar_layer->SetPosition(gfx::Point(scrollbar_location));
462 layer_tree_root->SetBounds(gfx::Size(100, 200));
463 content_layer->SetBounds(gfx::Size(100, 200));
464 gfx::SizeF scaled_size =
465 gfx::ScaleSize(scrollbar_layer->bounds(), test_scale, test_scale);
466 gfx::PointF scaled_location =
467 gfx::ScalePoint(scrollbar_layer->position(), test_scale, test_scale);
468 scrollbar_layer->draw_properties().content_bounds =
469 gfx::Size(scaled_size.width(), scaled_size.height());
470 scrollbar_layer->draw_properties().contents_scale_x = test_scale;
471 scrollbar_layer->draw_properties().contents_scale_y = test_scale;
472 scrollbar_layer->draw_properties().visible_content_rect =
473 gfx::Rect(scaled_location.x(),
474 scaled_location.y(),
475 scaled_size.width(),
476 scaled_size.height());
477 scrollbar_layer->CreateRenderSurface();
478 scrollbar_layer->draw_properties().render_target = scrollbar_layer;
479
480 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
481 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
482
483 PriorityCalculator calculator;
484 ResourceUpdateQueue queue;
485 OcclusionTracker occlusion_tracker(gfx::Rect(), false);
486
487 scrollbar_layer->SetTexturePriorities(calculator);
488 layer_tree_host_->contents_texture_manager()->PrioritizeTextures();
489 scrollbar_layer->Update(&queue, &occlusion_tracker, NULL);
490 EXPECT_EQ(expected_resources, queue.PartialUploadSize());
491
492 // Verify that we have not generated any content uploads that are larger
493 // than their destination textures.
494 while (queue.HasMoreUpdates()) {
495 ResourceUpdate update = queue.TakeFirstPartialUpload();
496 EXPECT_LE(update.texture->size().width(),
497 scrollbar_layer->content_bounds().width());
498 EXPECT_LE(update.texture->size().height(),
499 scrollbar_layer->content_bounds().height());
500
501 EXPECT_LE(update.dest_offset.x() + update.content_rect.width(),
502 update.texture->size().width());
503 EXPECT_LE(update.dest_offset.y() + update.content_rect.height(),
504 update.texture->size().height());
505 }
506
507 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
508 }
509
510 protected:
511 FakeLayerTreeHostClient fake_client_;
512 LayerTreeSettings layer_tree_settings_;
513 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
514 };
515
516 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
517 layer_tree_settings_.solid_color_scrollbars = false;
518 // Pick a test scale that moves the scrollbar's (non-zero) position to
519 // a non-pixel-aligned location.
520 TestResourceUpload(2, 1.41f);
521 }
522
429 } // namespace 523 } // namespace
430 } // namespace cc 524 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/scrollbar_layer.cc ('k') | cc/test/fake_web_scrollbar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698