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

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

Issue 18191020: UI Resource Manager (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Added DCHECK of resource queue size to PushPropertiesTo 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/resources/scoped_ui_resource.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"
7 #include "cc/animation/scrollbar_animation_controller.h" 8 #include "cc/animation/scrollbar_animation_controller.h"
8 #include "cc/layers/append_quads_data.h" 9 #include "cc/layers/append_quads_data.h"
9 #include "cc/layers/scrollbar_layer_impl.h" 10 #include "cc/layers/scrollbar_layer_impl.h"
10 #include "cc/quads/solid_color_draw_quad.h" 11 #include "cc/quads/solid_color_draw_quad.h"
11 #include "cc/resources/prioritized_resource_manager.h" 12 #include "cc/resources/prioritized_resource_manager.h"
12 #include "cc/resources/priority_calculator.h" 13 #include "cc/resources/priority_calculator.h"
13 #include "cc/resources/resource_update_queue.h" 14 #include "cc/resources/resource_update_queue.h"
14 #include "cc/test/fake_impl_proxy.h" 15 #include "cc/test/fake_impl_proxy.h"
15 #include "cc/test/fake_layer_tree_host.h" 16 #include "cc/test/fake_layer_tree_host.h"
16 #include "cc/test/fake_layer_tree_host_client.h" 17 #include "cc/test/fake_layer_tree_host_client.h"
17 #include "cc/test/fake_layer_tree_host_impl.h" 18 #include "cc/test/fake_layer_tree_host_impl.h"
18 #include "cc/test/fake_scrollbar.h" 19 #include "cc/test/fake_scrollbar.h"
19 #include "cc/test/geometry_test_utils.h" 20 #include "cc/test/geometry_test_utils.h"
20 #include "cc/test/layer_tree_test.h" 21 #include "cc/test/layer_tree_test.h"
21 #include "cc/test/mock_quad_culler.h" 22 #include "cc/test/mock_quad_culler.h"
22 #include "cc/test/test_web_graphics_context_3d.h" 23 #include "cc/test/test_web_graphics_context_3d.h"
24 #include "cc/trees/layer_tree_host.h"
23 #include "cc/trees/layer_tree_impl.h" 25 #include "cc/trees/layer_tree_impl.h"
24 #include "cc/trees/single_thread_proxy.h" 26 #include "cc/trees/single_thread_proxy.h"
25 #include "cc/trees/tree_synchronizer.h" 27 #include "cc/trees/tree_synchronizer.h"
26 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
28 30
29 namespace cc { 31 namespace cc {
30 namespace { 32 namespace {
31 33
32 LayerImpl* LayerImplForScrollAreaAndScrollbar( 34 LayerImpl* LayerImplForScrollAreaAndScrollbar(
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 int max_size = 0; 398 int max_size = 0;
397 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 399 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
398 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 400 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100));
399 RunTest(true, true, true); 401 RunTest(true, true, true);
400 } 402 }
401 403
402 class MockLayerTreeHost : public LayerTreeHost { 404 class MockLayerTreeHost : public LayerTreeHost {
403 public: 405 public:
404 MockLayerTreeHost(LayerTreeHostClient* client, 406 MockLayerTreeHost(LayerTreeHostClient* client,
405 const LayerTreeSettings& settings) 407 const LayerTreeSettings& settings)
406 : LayerTreeHost(client, settings) { 408 : LayerTreeHost(client, settings),
409 next_id_(1),
410 total_ui_resource_created_(0),
411 total_ui_resource_deleted_(0) {
407 Initialize(NULL); 412 Initialize(NULL);
408 } 413 }
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_;
409 }; 441 };
410 442
411 443
412 class ScrollbarLayerTestResourceCreation : public testing::Test { 444 class ScrollbarLayerTestResourceCreation : public testing::Test {
413 public: 445 public:
414 ScrollbarLayerTestResourceCreation() 446 ScrollbarLayerTestResourceCreation()
415 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 447 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
416 448
417 void TestResourceUpload(size_t expected_resources) { 449 void TestResourceUpload(int num_updates,
450 size_t expected_resources,
451 int expected_created,
452 int expected_deleted) {
418 layer_tree_host_.reset( 453 layer_tree_host_.reset(
419 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 454 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
420 455
421 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 456 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
422 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 457 scoped_refptr<Layer> layer_tree_root = Layer::Create();
423 scoped_refptr<Layer> content_layer = Layer::Create(); 458 scoped_refptr<Layer> content_layer = Layer::Create();
424 scoped_refptr<Layer> scrollbar_layer = 459 scoped_refptr<Layer> scrollbar_layer =
425 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 460 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
426 layer_tree_root->AddChild(content_layer); 461 layer_tree_root->AddChild(content_layer);
427 layer_tree_root->AddChild(scrollbar_layer); 462 layer_tree_root->AddChild(scrollbar_layer);
(...skipping 11 matching lines...) Expand all
439 content_layer->SetBounds(gfx::Size(100, 200)); 474 content_layer->SetBounds(gfx::Size(100, 200));
440 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); 475 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200);
441 scrollbar_layer->draw_properties().visible_content_rect = 476 scrollbar_layer->draw_properties().visible_content_rect =
442 gfx::Rect(0, 0, 100, 200); 477 gfx::Rect(0, 0, 100, 200);
443 scrollbar_layer->CreateRenderSurface(); 478 scrollbar_layer->CreateRenderSurface();
444 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); 479 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get();
445 480
446 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 481 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
447 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); 482 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
448 483
449 PriorityCalculator calculator;
450 ResourceUpdateQueue queue; 484 ResourceUpdateQueue queue;
451 OcclusionTracker occlusion_tracker(gfx::Rect(), false); 485 OcclusionTracker occlusion_tracker(gfx::Rect(), false);
452 486
453 scrollbar_layer->SetTexturePriorities(calculator); 487 for (int update_counter = 0; update_counter < num_updates; update_counter++)
454 layer_tree_host_->contents_texture_manager()->PrioritizeTextures(); 488 scrollbar_layer->Update(&queue, &occlusion_tracker);
455 scrollbar_layer->Update(&queue, &occlusion_tracker); 489
456 EXPECT_EQ(0u, queue.FullUploadSize()); 490 // A non-solid-color scrollbar should have requested two textures.
457 EXPECT_EQ(expected_resources, queue.PartialUploadSize()); 491 // A solid-color scrollbar should have requested two textures.
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());
458 495
459 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 496 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
460 497
461 scrollbar_layer->ClearRenderSurface(); 498 scrollbar_layer->ClearRenderSurface();
462 } 499 }
463 500
464 protected: 501 protected:
465 FakeLayerTreeHostClient fake_client_; 502 FakeLayerTreeHostClient fake_client_;
466 LayerTreeSettings layer_tree_settings_; 503 LayerTreeSettings layer_tree_settings_;
467 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 504 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
468 }; 505 };
469 506
470 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 507 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) {
471 layer_tree_settings_.solid_color_scrollbars = false; 508 layer_tree_settings_.solid_color_scrollbars = false;
472 TestResourceUpload(2); 509 TestResourceUpload(0, 0, 0, 0);
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 }
473 } 515 }
474 516
475 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 517 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) {
476 layer_tree_settings_.solid_color_scrollbars = true; 518 layer_tree_settings_.solid_color_scrollbars = true;
477 TestResourceUpload(0); 519 TestResourceUpload(0, 0, 0, 0);
478 } 520 TestResourceUpload(1, 0, 0, 0);
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);
570 } 521 }
571 522
572 } // namespace 523 } // namespace
573 } // namespace cc 524 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/scrollbar_layer_impl.cc ('k') | cc/resources/scoped_ui_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698