| OLD | NEW |
| 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 "base/containers/hash_tables.h" | 5 #include "base/containers/hash_tables.h" |
| 6 #include "cc/animation/scrollbar_animation_controller.h" | 6 #include "cc/animation/scrollbar_animation_controller.h" |
| 7 #include "cc/debug/test_web_graphics_context_3d.h" | 7 #include "cc/debug/test_web_graphics_context_3d.h" |
| 8 #include "cc/layers/append_quads_data.h" | 8 #include "cc/layers/append_quads_data.h" |
| 9 #include "cc/layers/painted_scrollbar_layer.h" | 9 #include "cc/layers/painted_scrollbar_layer.h" |
| 10 #include "cc/layers/painted_scrollbar_layer_impl.h" | 10 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 : LayerTreeHost(client, settings), | 515 : LayerTreeHost(client, settings), |
| 516 next_id_(1), | 516 next_id_(1), |
| 517 total_ui_resource_created_(0), | 517 total_ui_resource_created_(0), |
| 518 total_ui_resource_deleted_(0) { | 518 total_ui_resource_deleted_(0) { |
| 519 Initialize(NULL); | 519 Initialize(NULL); |
| 520 } | 520 } |
| 521 | 521 |
| 522 virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE { | 522 virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE { |
| 523 total_ui_resource_created_++; | 523 total_ui_resource_created_++; |
| 524 UIResourceId nid = next_id_++; | 524 UIResourceId nid = next_id_++; |
| 525 ui_resource_bitmap_map_[nid] = content->GetBitmap(nid, false); | 525 ui_resource_bitmap_map_.insert( |
| 526 std::make_pair(nid, content->GetBitmap(nid, false))); |
| 526 return nid; | 527 return nid; |
| 527 } | 528 } |
| 528 | 529 |
| 529 // Deletes a UI resource. May safely be called more than once. | 530 // Deletes a UI resource. May safely be called more than once. |
| 530 virtual void DeleteUIResource(UIResourceId id) OVERRIDE { | 531 virtual void DeleteUIResource(UIResourceId id) OVERRIDE { |
| 531 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); | 532 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); |
| 532 if (iter != ui_resource_bitmap_map_.end()) { | 533 if (iter != ui_resource_bitmap_map_.end()) { |
| 533 ui_resource_bitmap_map_.erase(iter); | 534 ui_resource_bitmap_map_.erase(iter); |
| 534 total_ui_resource_deleted_++; | 535 total_ui_resource_deleted_++; |
| 535 } | 536 } |
| 536 } | 537 } |
| 537 | 538 |
| 538 size_t UIResourceCount() { return ui_resource_bitmap_map_.size(); } | 539 size_t UIResourceCount() { return ui_resource_bitmap_map_.size(); } |
| 539 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; } | 540 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; } |
| 540 int TotalUIResourceCreated() { return total_ui_resource_created_; } | 541 int TotalUIResourceCreated() { return total_ui_resource_created_; } |
| 541 | 542 |
| 542 gfx::Size ui_resource_size(UIResourceId id) { | 543 gfx::Size ui_resource_size(UIResourceId id) { |
| 543 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); | 544 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); |
| 544 if (iter != ui_resource_bitmap_map_.end() && iter->second.get()) | 545 if (iter != ui_resource_bitmap_map_.end()) |
| 545 return iter->second->GetSize(); | 546 return iter->second.GetSize(); |
| 546 return gfx::Size(); | 547 return gfx::Size(); |
| 547 } | 548 } |
| 548 | 549 |
| 549 private: | 550 private: |
| 550 typedef base::hash_map<UIResourceId, scoped_refptr<UIResourceBitmap> > | 551 typedef base::hash_map<UIResourceId, UIResourceBitmap> |
| 551 UIResourceBitmapMap; | 552 UIResourceBitmapMap; |
| 552 UIResourceBitmapMap ui_resource_bitmap_map_; | 553 UIResourceBitmapMap ui_resource_bitmap_map_; |
| 553 | 554 |
| 554 int next_id_; | 555 int next_id_; |
| 555 int total_ui_resource_created_; | 556 int total_ui_resource_created_; |
| 556 int total_ui_resource_deleted_; | 557 int total_ui_resource_deleted_; |
| 557 }; | 558 }; |
| 558 | 559 |
| 559 | 560 |
| 560 class ScrollbarLayerTestResourceCreation : public testing::Test { | 561 class ScrollbarLayerTestResourceCreation : public testing::Test { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 725 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
| 725 // Pick a test scale that moves the scrollbar's (non-zero) position to | 726 // Pick a test scale that moves the scrollbar's (non-zero) position to |
| 726 // a non-pixel-aligned location. | 727 // a non-pixel-aligned location. |
| 727 TestResourceUpload(.041f); | 728 TestResourceUpload(.041f); |
| 728 TestResourceUpload(1.41f); | 729 TestResourceUpload(1.41f); |
| 729 TestResourceUpload(4.1f); | 730 TestResourceUpload(4.1f); |
| 730 } | 731 } |
| 731 | 732 |
| 732 } // namespace | 733 } // namespace |
| 733 } // namespace cc | 734 } // namespace cc |
| OLD | NEW |