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/layers/append_quads_data.h" | 7 #include "cc/layers/append_quads_data.h" |
8 #include "cc/layers/painted_scrollbar_layer.h" | 8 #include "cc/layers/painted_scrollbar_layer.h" |
9 #include "cc/layers/painted_scrollbar_layer_impl.h" | 9 #include "cc/layers/painted_scrollbar_layer_impl.h" |
10 #include "cc/layers/scrollbar_layer_interface.h" | 10 #include "cc/layers/scrollbar_layer_interface.h" |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; } | 577 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; } |
578 int TotalUIResourceCreated() { return total_ui_resource_created_; } | 578 int TotalUIResourceCreated() { return total_ui_resource_created_; } |
579 | 579 |
580 gfx::Size ui_resource_size(UIResourceId id) { | 580 gfx::Size ui_resource_size(UIResourceId id) { |
581 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); | 581 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); |
582 if (iter != ui_resource_bitmap_map_.end()) | 582 if (iter != ui_resource_bitmap_map_.end()) |
583 return iter->second.GetSize(); | 583 return iter->second.GetSize(); |
584 return gfx::Size(); | 584 return gfx::Size(); |
585 } | 585 } |
586 | 586 |
| 587 UIResourceBitmap* ui_resource_bitmap(UIResourceId id) { |
| 588 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id); |
| 589 if (iter != ui_resource_bitmap_map_.end()) |
| 590 return &iter->second; |
| 591 return NULL; |
| 592 } |
| 593 |
587 private: | 594 private: |
588 typedef base::hash_map<UIResourceId, UIResourceBitmap> | 595 typedef base::hash_map<UIResourceId, UIResourceBitmap> |
589 UIResourceBitmapMap; | 596 UIResourceBitmapMap; |
590 UIResourceBitmapMap ui_resource_bitmap_map_; | 597 UIResourceBitmapMap ui_resource_bitmap_map_; |
591 | 598 |
592 int next_id_; | 599 int next_id_; |
593 int total_ui_resource_created_; | 600 int total_ui_resource_created_; |
594 int total_ui_resource_deleted_; | 601 int total_ui_resource_deleted_; |
595 }; | 602 }; |
596 | 603 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 }; | 766 }; |
760 | 767 |
761 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 768 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
762 // Pick a test scale that moves the scrollbar's (non-zero) position to | 769 // Pick a test scale that moves the scrollbar's (non-zero) position to |
763 // a non-pixel-aligned location. | 770 // a non-pixel-aligned location. |
764 TestResourceUpload(.041f); | 771 TestResourceUpload(.041f); |
765 TestResourceUpload(1.41f); | 772 TestResourceUpload(1.41f); |
766 TestResourceUpload(4.1f); | 773 TestResourceUpload(4.1f); |
767 } | 774 } |
768 | 775 |
| 776 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test { |
| 777 public: |
| 778 ScaledScrollbarLayerTestScaledRasterization() |
| 779 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 780 |
| 781 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { |
| 782 layer_tree_host_.reset( |
| 783 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
| 784 |
| 785 bool paint_during_update = true; |
| 786 bool has_thumb = false; |
| 787 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 788 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 789 FakePaintedScrollbarLayer::Create(paint_during_update, |
| 790 has_thumb, |
| 791 layer_tree_root->id()); |
| 792 |
| 793 layer_tree_root->AddChild(scrollbar_layer); |
| 794 |
| 795 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 796 |
| 797 scrollbar_layer->SetBounds(scrollbar_rect.size()); |
| 798 scrollbar_layer->SetPosition(scrollbar_rect.origin()); |
| 799 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); |
| 800 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); |
| 801 gfx::SizeF scaled_size = |
| 802 gfx::ScaleSize(scrollbar_layer->bounds(), test_scale, test_scale); |
| 803 gfx::PointF scaled_location = |
| 804 gfx::ScalePoint(scrollbar_layer->position(), test_scale, test_scale); |
| 805 scrollbar_layer->draw_properties().content_bounds = |
| 806 gfx::Size(scaled_size.width(), scaled_size.height()); |
| 807 scrollbar_layer->draw_properties().contents_scale_x = test_scale; |
| 808 scrollbar_layer->draw_properties().contents_scale_y = test_scale; |
| 809 scrollbar_layer->draw_properties().visible_content_rect = |
| 810 gfx::Rect(scaled_location.x(), |
| 811 scaled_location.y(), |
| 812 scaled_size.width(), |
| 813 scaled_size.height()); |
| 814 |
| 815 ResourceUpdateQueue queue; |
| 816 OcclusionTracker occlusion_tracker(gfx::Rect(), false); |
| 817 scrollbar_layer->SavePaintProperties(); |
| 818 |
| 819 scrollbar_layer->Update(&queue, &occlusion_tracker); |
| 820 |
| 821 UIResourceBitmap* bitmap = layer_tree_host_->ui_resource_bitmap( |
| 822 scrollbar_layer->track_resource_id()); |
| 823 |
| 824 DCHECK(bitmap); |
| 825 |
| 826 AutoLockUIResourceBitmap locked_bitmap(*bitmap); |
| 827 |
| 828 const SkColor* pixels = |
| 829 reinterpret_cast<const SkColor*>(locked_bitmap.GetPixels()); |
| 830 SkColor color = argb_to_skia( |
| 831 scrollbar_layer->fake_scrollbar()->paint_fill_color()); |
| 832 int width = bitmap->GetSize().width(); |
| 833 int height = bitmap->GetSize().height(); |
| 834 |
| 835 // Make sure none of the corners of the bitmap were inadvertently clipped. |
| 836 EXPECT_EQ(color, pixels[0]) |
| 837 << "Top left pixel doesn't match scrollbar color."; |
| 838 |
| 839 EXPECT_EQ(color, pixels[width - 1]) |
| 840 << "Top right pixel doesn't match scrollbar color."; |
| 841 |
| 842 EXPECT_EQ(color, pixels[width * (height - 1)]) |
| 843 << "Bottom left pixel doesn't match scrollbar color."; |
| 844 |
| 845 EXPECT_EQ(color, pixels[width * height - 1]) |
| 846 << "Bottom right pixel doesn't match scrollbar color."; |
| 847 } |
| 848 |
| 849 protected: |
| 850 // On Android, Skia uses ABGR |
| 851 static SkColor argb_to_skia(SkColor c) { |
| 852 return (SkColorGetA(c) << SK_A32_SHIFT) | |
| 853 (SkColorGetR(c) << SK_R32_SHIFT) | |
| 854 (SkColorGetG(c) << SK_G32_SHIFT) | |
| 855 (SkColorGetB(c) << SK_B32_SHIFT); |
| 856 } |
| 857 |
| 858 FakeLayerTreeHostClient fake_client_; |
| 859 LayerTreeSettings layer_tree_settings_; |
| 860 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
| 861 }; |
| 862 |
| 863 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { |
| 864 // Try rasterization at coordinates and scale that caused problematic |
| 865 // rounding and clipping errors. |
| 866 // Vertical Scrollbars. |
| 867 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 868 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 869 |
| 870 // Horizontal Scrollbars. |
| 871 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 872 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 873 } |
| 874 |
769 } // namespace | 875 } // namespace |
770 } // namespace cc | 876 } // namespace cc |
OLD | NEW |