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

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

Issue 21555004: Scrollbar Layer revert (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 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
« no previous file with comments | « cc/layers/scrollbar_layer_impl.cc ('k') | cc/test/fake_scrollbar_layer.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 "base/containers/hash_tables.h"
8 #include "cc/animation/scrollbar_animation_controller.h" 7 #include "cc/animation/scrollbar_animation_controller.h"
9 #include "cc/layers/append_quads_data.h" 8 #include "cc/layers/append_quads_data.h"
10 #include "cc/layers/scrollbar_layer_impl.h" 9 #include "cc/layers/scrollbar_layer_impl.h"
11 #include "cc/quads/solid_color_draw_quad.h" 10 #include "cc/quads/solid_color_draw_quad.h"
12 #include "cc/resources/prioritized_resource_manager.h" 11 #include "cc/resources/prioritized_resource_manager.h"
13 #include "cc/resources/priority_calculator.h" 12 #include "cc/resources/priority_calculator.h"
14 #include "cc/resources/resource_update_queue.h" 13 #include "cc/resources/resource_update_queue.h"
15 #include "cc/test/fake_impl_proxy.h" 14 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host.h" 15 #include "cc/test/fake_layer_tree_host.h"
17 #include "cc/test/fake_layer_tree_host_client.h" 16 #include "cc/test/fake_layer_tree_host_client.h"
18 #include "cc/test/fake_layer_tree_host_impl.h" 17 #include "cc/test/fake_layer_tree_host_impl.h"
19 #include "cc/test/fake_scrollbar.h" 18 #include "cc/test/fake_scrollbar.h"
20 #include "cc/test/geometry_test_utils.h" 19 #include "cc/test/geometry_test_utils.h"
21 #include "cc/test/layer_tree_test.h" 20 #include "cc/test/layer_tree_test.h"
22 #include "cc/test/mock_quad_culler.h" 21 #include "cc/test/mock_quad_culler.h"
23 #include "cc/test/test_web_graphics_context_3d.h" 22 #include "cc/test/test_web_graphics_context_3d.h"
24 #include "cc/trees/layer_tree_host.h"
25 #include "cc/trees/layer_tree_impl.h" 23 #include "cc/trees/layer_tree_impl.h"
26 #include "cc/trees/single_thread_proxy.h" 24 #include "cc/trees/single_thread_proxy.h"
27 #include "cc/trees/tree_synchronizer.h" 25 #include "cc/trees/tree_synchronizer.h"
28 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
30 28
31 namespace cc { 29 namespace cc {
32 namespace { 30 namespace {
33 31
34 LayerImpl* LayerImplForScrollAreaAndScrollbar( 32 LayerImpl* LayerImplForScrollAreaAndScrollbar(
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 int max_size = 0; 396 int max_size = 0;
399 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 397 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
400 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 398 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100));
401 RunTest(true, true, true); 399 RunTest(true, true, true);
402 } 400 }
403 401
404 class MockLayerTreeHost : public LayerTreeHost { 402 class MockLayerTreeHost : public LayerTreeHost {
405 public: 403 public:
406 MockLayerTreeHost(LayerTreeHostClient* client, 404 MockLayerTreeHost(LayerTreeHostClient* client,
407 const LayerTreeSettings& settings) 405 const LayerTreeSettings& settings)
408 : LayerTreeHost(client, settings), 406 : LayerTreeHost(client, settings) {
409 next_id_(1),
410 total_ui_resource_created_(0),
411 total_ui_resource_deleted_(0) {
412 Initialize(NULL); 407 Initialize(NULL);
413 } 408 }
414
415 virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE {
416 total_ui_resource_created_++;
417 UIResourceId nid = next_id_++;
418 ui_resource_id_set_.insert(nid);
419 return nid;
420 }
421
422 // Deletes a UI resource. May safely be called more than once.
423 virtual void DeleteUIResource(UIResourceId id) OVERRIDE {
424 UIResourceIdSet::iterator iter = ui_resource_id_set_.find(id);
425 if (iter != ui_resource_id_set_.end()) {
426 ui_resource_id_set_.erase(iter);
427 total_ui_resource_deleted_++;
428 }
429 }
430
431 size_t UIResourceCount() { return ui_resource_id_set_.size(); }
432 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; }
433 int TotalUIResourceCreated() { return total_ui_resource_created_; }
434
435 private:
436 typedef base::hash_set<UIResourceId> UIResourceIdSet;
437 UIResourceIdSet ui_resource_id_set_;
438 int next_id_;
439 int total_ui_resource_created_;
440 int total_ui_resource_deleted_;
441 }; 409 };
442 410
443 411
444 class ScrollbarLayerTestResourceCreation : public testing::Test { 412 class ScrollbarLayerTestResourceCreation : public testing::Test {
445 public: 413 public:
446 ScrollbarLayerTestResourceCreation() 414 ScrollbarLayerTestResourceCreation()
447 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 415 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
448 416
449 void TestResourceUpload(int num_updates, 417 void TestResourceUpload(size_t expected_resources) {
450 size_t expected_resources,
451 int expected_created,
452 int expected_deleted) {
453 layer_tree_host_.reset( 418 layer_tree_host_.reset(
454 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 419 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
455 420
456 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 421 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
457 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 422 scoped_refptr<Layer> layer_tree_root = Layer::Create();
458 scoped_refptr<Layer> content_layer = Layer::Create(); 423 scoped_refptr<Layer> content_layer = Layer::Create();
459 scoped_refptr<Layer> scrollbar_layer = 424 scoped_refptr<Layer> scrollbar_layer =
460 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 425 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
461 layer_tree_root->AddChild(content_layer); 426 layer_tree_root->AddChild(content_layer);
462 layer_tree_root->AddChild(scrollbar_layer); 427 layer_tree_root->AddChild(scrollbar_layer);
(...skipping 11 matching lines...) Expand all
474 content_layer->SetBounds(gfx::Size(100, 200)); 439 content_layer->SetBounds(gfx::Size(100, 200));
475 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); 440 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200);
476 scrollbar_layer->draw_properties().visible_content_rect = 441 scrollbar_layer->draw_properties().visible_content_rect =
477 gfx::Rect(0, 0, 100, 200); 442 gfx::Rect(0, 0, 100, 200);
478 scrollbar_layer->CreateRenderSurface(); 443 scrollbar_layer->CreateRenderSurface();
479 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); 444 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get();
480 445
481 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 446 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
482 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); 447 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
483 448
449 PriorityCalculator calculator;
484 ResourceUpdateQueue queue; 450 ResourceUpdateQueue queue;
485 OcclusionTracker occlusion_tracker(gfx::Rect(), false); 451 OcclusionTracker occlusion_tracker(gfx::Rect(), false);
486 452
487 for (int update_counter = 0; update_counter < num_updates; update_counter++) 453 scrollbar_layer->SetTexturePriorities(calculator);
488 scrollbar_layer->Update(&queue, &occlusion_tracker); 454 layer_tree_host_->contents_texture_manager()->PrioritizeTextures();
489 455 scrollbar_layer->Update(&queue, &occlusion_tracker);
490 // A non-solid-color scrollbar should have requested two textures. 456 EXPECT_EQ(0u, queue.FullUploadSize());
491 // A solid-color scrollbar should have requested two textures. 457 EXPECT_EQ(expected_resources, queue.PartialUploadSize());
492 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount());
493 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
494 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
495 458
496 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 459 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
497 460
498 scrollbar_layer->ClearRenderSurface(); 461 scrollbar_layer->ClearRenderSurface();
499 } 462 }
500 463
501 protected: 464 protected:
502 FakeLayerTreeHostClient fake_client_; 465 FakeLayerTreeHostClient fake_client_;
503 LayerTreeSettings layer_tree_settings_; 466 LayerTreeSettings layer_tree_settings_;
504 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 467 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
505 }; 468 };
506 469
507 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 470 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) {
508 layer_tree_settings_.solid_color_scrollbars = false; 471 layer_tree_settings_.solid_color_scrollbars = false;
509 TestResourceUpload(0, 0, 0, 0); 472 TestResourceUpload(2);
510 int num_updates[3] = {1, 5, 10};
511 for (int j = 0; j < 3; j++) {
512 TestResourceUpload(
513 num_updates[j], 2, num_updates[j] * 2, (num_updates[j] - 1) * 2);
514 }
515 } 473 }
516 474
517 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 475 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) {
518 layer_tree_settings_.solid_color_scrollbars = true; 476 layer_tree_settings_.solid_color_scrollbars = true;
519 TestResourceUpload(0, 0, 0, 0); 477 TestResourceUpload(0);
520 TestResourceUpload(1, 0, 0, 0); 478 }
479
480 class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
481 public:
482 ScaledScrollbarLayerTestResourceCreation()
483 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
484
485 void TestResourceUpload(size_t expected_resources, const float test_scale) {
486 layer_tree_host_.reset(
487 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
488
489 gfx::Point scrollbar_location(0, 185);
490 scoped_ptr<FakeScrollbar> scrollbar(new FakeScrollbar(false, true, false));
491 scrollbar->set_location(scrollbar_location);
492
493 scoped_refptr<Layer> layer_tree_root = Layer::Create();
494 scoped_refptr<Layer> content_layer = Layer::Create();
495 scoped_refptr<Layer> scrollbar_layer =
496 ScrollbarLayer::Create(scrollbar.PassAs<cc::Scrollbar>(),
497 layer_tree_root->id());
498 layer_tree_root->AddChild(content_layer);
499 layer_tree_root->AddChild(scrollbar_layer);
500
501 layer_tree_host_->InitializeOutputSurfaceIfNeeded();
502 layer_tree_host_->contents_texture_manager()->
503 SetMaxMemoryLimitBytes(1024 * 1024);
504 layer_tree_host_->SetRootLayer(layer_tree_root);
505
506 scrollbar_layer->SetIsDrawable(true);
507 scrollbar_layer->SetBounds(gfx::Size(100, 15));
508 scrollbar_layer->SetPosition(scrollbar_location);
509 layer_tree_root->SetBounds(gfx::Size(100, 200));
510 content_layer->SetBounds(gfx::Size(100, 200));
511 gfx::SizeF scaled_size =
512 gfx::ScaleSize(scrollbar_layer->bounds(), test_scale, test_scale);
513 gfx::PointF scaled_location =
514 gfx::ScalePoint(scrollbar_layer->position(), test_scale, test_scale);
515 scrollbar_layer->draw_properties().content_bounds =
516 gfx::Size(scaled_size.width(), scaled_size.height());
517 scrollbar_layer->draw_properties().contents_scale_x = test_scale;
518 scrollbar_layer->draw_properties().contents_scale_y = test_scale;
519 scrollbar_layer->draw_properties().visible_content_rect =
520 gfx::Rect(scaled_location.x(),
521 scaled_location.y(),
522 scaled_size.width(),
523 scaled_size.height());
524 scrollbar_layer->CreateRenderSurface();
525 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get();
526
527 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
528 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
529
530 PriorityCalculator calculator;
531 ResourceUpdateQueue queue;
532 OcclusionTracker occlusion_tracker(gfx::Rect(), false);
533
534 scrollbar_layer->SetTexturePriorities(calculator);
535 layer_tree_host_->contents_texture_manager()->PrioritizeTextures();
536 scrollbar_layer->Update(&queue, &occlusion_tracker);
537 EXPECT_EQ(expected_resources, queue.PartialUploadSize());
538
539 // Verify that we have not generated any content uploads that are larger
540 // than their destination textures.
541 while (queue.HasMoreUpdates()) {
542 ResourceUpdate update = queue.TakeFirstPartialUpload();
543 EXPECT_LE(update.texture->size().width(),
544 scrollbar_layer->content_bounds().width());
545 EXPECT_LE(update.texture->size().height(),
546 scrollbar_layer->content_bounds().height());
547
548 EXPECT_LE(update.dest_offset.x() + update.content_rect.width(),
549 update.texture->size().width());
550 EXPECT_LE(update.dest_offset.y() + update.content_rect.height(),
551 update.texture->size().height());
552 }
553
554 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
555
556 scrollbar_layer->ClearRenderSurface();
557 }
558
559 protected:
560 FakeLayerTreeHostClient fake_client_;
561 LayerTreeSettings layer_tree_settings_;
562 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
563 };
564
565 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
566 layer_tree_settings_.solid_color_scrollbars = false;
567 // Pick a test scale that moves the scrollbar's (non-zero) position to
568 // a non-pixel-aligned location.
569 TestResourceUpload(2, 1.41f);
521 } 570 }
522 571
523 } // namespace 572 } // namespace
524 } // namespace cc 573 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/scrollbar_layer_impl.cc ('k') | cc/test/fake_scrollbar_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698