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

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

Issue 150603004: Fixed rounding issue on scrollbar rasterization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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/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
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
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 scoped_refptr<Layer> layer_tree_root = Layer::Create();
786 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
787 FakePaintedScrollbarLayer::Create(true, false, layer_tree_root->id());
danakj 2014/02/18 20:43:30 can you use temp bools here to give these boolean
bokan 2014/02/18 21:48:15 Done.
788
789 layer_tree_root->AddChild(scrollbar_layer);
790
791 layer_tree_host_->SetRootLayer(layer_tree_root);
792
793 scrollbar_layer->SetBounds(scrollbar_rect.size());
794 scrollbar_layer->SetPosition(scrollbar_rect.origin());
795 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin());
796 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect);
797 gfx::SizeF scaled_size =
798 gfx::ScaleSize(scrollbar_layer->bounds(), test_scale, test_scale);
799 gfx::PointF scaled_location =
800 gfx::ScalePoint(scrollbar_layer->position(), test_scale, test_scale);
801 scrollbar_layer->draw_properties().content_bounds =
802 gfx::Size(scaled_size.width(), scaled_size.height());
803 scrollbar_layer->draw_properties().contents_scale_x = test_scale;
804 scrollbar_layer->draw_properties().contents_scale_y = test_scale;
805 scrollbar_layer->draw_properties().visible_content_rect =
806 gfx::Rect(scaled_location.x(),
807 scaled_location.y(),
808 scaled_size.width(),
809 scaled_size.height());
810
811 ResourceUpdateQueue queue;
812 OcclusionTracker occlusion_tracker(gfx::Rect(), false);
813 scrollbar_layer->SavePaintProperties();
814
815 scrollbar_layer->Update(&queue, &occlusion_tracker);
816
817 UIResourceBitmap* bmp = layer_tree_host_->ui_resource_bitmap(
danakj 2014/02/18 20:43:30 |bitmap|
bokan 2014/02/18 21:48:15 Done.
818 scrollbar_layer->track_resource_id());
819
820 DCHECK(bmp);
821
822 AutoLockUIResourceBitmap lockedBmp(*bmp);
danakj 2014/02/18 20:43:30 |locked_bitmap|
bokan 2014/02/18 21:48:15 Done.
823
824 const SkColor* pixels =
825 reinterpret_cast<const SkColor*>(lockedBmp.GetPixels());
826 SkColor color = scrollbar_layer->fake_scrollbar()->get_color();
827 int width = bmp->GetSize().width();
828 int height = bmp->GetSize().height();
829
830 // Make sure none of the corners of the bitmap were inadvertently clipped.
831 EXPECT_EQ(color, pixels[0])
832 << "Top left pixel doesn't match scrollbar color.";
833
834 EXPECT_EQ(color, pixels[width - 1])
835 << "Top right pixel doesn't match scrollbar color.";
836
837 EXPECT_EQ(color, pixels[width * (height - 1)])
838 << "Bottom left pixel doesn't match scrollbar color.";
839
840 EXPECT_EQ(color, pixels[width * height - 1])
841 << "Bottom right pixel doesn't match scrollbar color.";
842
843 scrollbar_layer->ClearRenderSurface();
844 }
845
846 protected:
847 FakeLayerTreeHostClient fake_client_;
848 LayerTreeSettings layer_tree_settings_;
849 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
850 };
851
852 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
853 // Try rasterization at coordinates and scale that caused problematic
854 // rounding and clipping errors.
855 // Vertical Scrollbars.
856 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
857 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
858
859 // Horizontal Scrollbars.
860 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
861 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
862 }
863
769 } // namespace 864 } // namespace
770 } // namespace cc 865 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698