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

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

Issue 22870016: Update the nine patch layer to use UI resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ccameron's fix for exisiting nine-patch uses Created 7 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 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 : LayerTreeHost(client, settings), 520 : LayerTreeHost(client, settings),
521 next_id_(1), 521 next_id_(1),
522 total_ui_resource_created_(0), 522 total_ui_resource_created_(0),
523 total_ui_resource_deleted_(0) { 523 total_ui_resource_deleted_(0) {
524 Initialize(NULL); 524 Initialize(NULL);
525 } 525 }
526 526
527 virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE { 527 virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE {
528 total_ui_resource_created_++; 528 total_ui_resource_created_++;
529 UIResourceId nid = next_id_++; 529 UIResourceId nid = next_id_++;
530 ui_resource_bitmap_map_[nid] = content->GetBitmap(nid, false); 530 ui_resource_bitmap_map_.insert(
531 std::make_pair(nid, content->GetBitmap(nid, false)));
531 return nid; 532 return nid;
532 } 533 }
533 534
534 // Deletes a UI resource. May safely be called more than once. 535 // Deletes a UI resource. May safely be called more than once.
535 virtual void DeleteUIResource(UIResourceId id) OVERRIDE { 536 virtual void DeleteUIResource(UIResourceId id) OVERRIDE {
536 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); 537 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
537 if (iter != ui_resource_bitmap_map_.end()) { 538 if (iter != ui_resource_bitmap_map_.end()) {
538 ui_resource_bitmap_map_.erase(iter); 539 ui_resource_bitmap_map_.erase(iter);
539 total_ui_resource_deleted_++; 540 total_ui_resource_deleted_++;
540 } 541 }
541 } 542 }
542 543
543 size_t UIResourceCount() { return ui_resource_bitmap_map_.size(); } 544 size_t UIResourceCount() { return ui_resource_bitmap_map_.size(); }
544 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; } 545 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; }
545 int TotalUIResourceCreated() { return total_ui_resource_created_; } 546 int TotalUIResourceCreated() { return total_ui_resource_created_; }
546 547
547 gfx::Size ui_resource_size(UIResourceId id) { 548 gfx::Size ui_resource_size(UIResourceId id) {
548 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); 549 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
549 if (iter != ui_resource_bitmap_map_.end() && iter->second.get()) 550 if (iter != ui_resource_bitmap_map_.end())
550 return iter->second->GetSize(); 551 return iter->second.GetSize();
551 return gfx::Size(); 552 return gfx::Size();
552 } 553 }
553 554
554 private: 555 private:
555 typedef base::hash_map<UIResourceId, scoped_refptr<UIResourceBitmap> > 556 typedef base::hash_map<UIResourceId, UIResourceBitmap>
556 UIResourceBitmapMap; 557 UIResourceBitmapMap;
557 UIResourceBitmapMap ui_resource_bitmap_map_; 558 UIResourceBitmapMap ui_resource_bitmap_map_;
558 559
559 int next_id_; 560 int next_id_;
560 int total_ui_resource_created_; 561 int total_ui_resource_created_;
561 int total_ui_resource_deleted_; 562 int total_ui_resource_deleted_;
562 }; 563 };
563 564
564 565
565 class ScrollbarLayerTestResourceCreation : public testing::Test { 566 class ScrollbarLayerTestResourceCreation : public testing::Test {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 732 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
732 // Pick a test scale that moves the scrollbar's (non-zero) position to 733 // Pick a test scale that moves the scrollbar's (non-zero) position to
733 // a non-pixel-aligned location. 734 // a non-pixel-aligned location.
734 TestResourceUpload(.041f); 735 TestResourceUpload(.041f);
735 TestResourceUpload(1.41f); 736 TestResourceUpload(1.41f);
736 TestResourceUpload(4.1f); 737 TestResourceUpload(4.1f);
737 } 738 }
738 739
739 } // namespace 740 } // namespace
740 } // namespace cc 741 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698