| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "cc/input/scrollbar.h" | 9 #include "cc/input/scrollbar.h" |
| 10 #include "cc/layers/painted_overlay_scrollbar_layer.h" | 10 #include "cc/layers/painted_overlay_scrollbar_layer.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 SkColor color_ = SK_ColorGREEN; | 81 SkColor color_ = SK_ColorGREEN; |
| 82 gfx::Rect rect_; | 82 gfx::Rect rect_; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 TEST_F(LayerTreeHostScrollbarsPixelTest, NoScale) { | 85 TEST_F(LayerTreeHostScrollbarsPixelTest, NoScale) { |
| 86 scoped_refptr<SolidColorLayer> background = | 86 scoped_refptr<SolidColorLayer> background = |
| 87 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | 87 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); |
| 88 | 88 |
| 89 auto scrollbar = base::MakeUnique<PaintedScrollbar>(); | 89 auto scrollbar = base::MakeUnique<PaintedScrollbar>(); |
| 90 scoped_refptr<PaintedScrollbarLayer> layer = | 90 scoped_refptr<PaintedScrollbarLayer> layer = |
| 91 PaintedScrollbarLayer::Create(std::move(scrollbar), Layer::INVALID_ID); | 91 PaintedScrollbarLayer::Create(std::move(scrollbar)); |
| 92 layer->SetIsDrawable(true); | 92 layer->SetIsDrawable(true); |
| 93 layer->SetBounds(gfx::Size(200, 200)); | 93 layer->SetBounds(gfx::Size(200, 200)); |
| 94 background->AddChild(layer); | 94 background->AddChild(layer); |
| 95 | 95 |
| 96 RunPixelTest(PIXEL_TEST_GL, background, | 96 RunPixelTest(PIXEL_TEST_GL, background, |
| 97 base::FilePath(FILE_PATH_LITERAL("spiral.png"))); | 97 base::FilePath(FILE_PATH_LITERAL("spiral.png"))); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(LayerTreeHostScrollbarsPixelTest, DeviceScaleFactor) { | 100 TEST_F(LayerTreeHostScrollbarsPixelTest, DeviceScaleFactor) { |
| 101 // With a device scale of 2, the scrollbar should still be rendered | 101 // With a device scale of 2, the scrollbar should still be rendered |
| 102 // pixel-perfect, not show scaling artifacts | 102 // pixel-perfect, not show scaling artifacts |
| 103 device_scale_factor_ = 2.f; | 103 device_scale_factor_ = 2.f; |
| 104 | 104 |
| 105 scoped_refptr<SolidColorLayer> background = | 105 scoped_refptr<SolidColorLayer> background = |
| 106 CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE); | 106 CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE); |
| 107 | 107 |
| 108 auto scrollbar = base::MakeUnique<PaintedScrollbar>(); | 108 auto scrollbar = base::MakeUnique<PaintedScrollbar>(); |
| 109 scoped_refptr<PaintedScrollbarLayer> layer = | 109 scoped_refptr<PaintedScrollbarLayer> layer = |
| 110 PaintedScrollbarLayer::Create(std::move(scrollbar), Layer::INVALID_ID); | 110 PaintedScrollbarLayer::Create(std::move(scrollbar)); |
| 111 layer->SetIsDrawable(true); | 111 layer->SetIsDrawable(true); |
| 112 layer->SetBounds(gfx::Size(100, 100)); | 112 layer->SetBounds(gfx::Size(100, 100)); |
| 113 background->AddChild(layer); | 113 background->AddChild(layer); |
| 114 | 114 |
| 115 RunPixelTest(PIXEL_TEST_GL, background, | 115 RunPixelTest(PIXEL_TEST_GL, background, |
| 116 base::FilePath(FILE_PATH_LITERAL("spiral_double_scale.png"))); | 116 base::FilePath(FILE_PATH_LITERAL("spiral_double_scale.png"))); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST_F(LayerTreeHostScrollbarsPixelTest, TransformScale) { | 119 TEST_F(LayerTreeHostScrollbarsPixelTest, TransformScale) { |
| 120 scoped_refptr<SolidColorLayer> background = | 120 scoped_refptr<SolidColorLayer> background = |
| 121 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | 121 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); |
| 122 | 122 |
| 123 auto scrollbar = base::MakeUnique<PaintedScrollbar>(); | 123 auto scrollbar = base::MakeUnique<PaintedScrollbar>(); |
| 124 scoped_refptr<PaintedScrollbarLayer> layer = | 124 scoped_refptr<PaintedScrollbarLayer> layer = |
| 125 PaintedScrollbarLayer::Create(std::move(scrollbar), Layer::INVALID_ID); | 125 PaintedScrollbarLayer::Create(std::move(scrollbar)); |
| 126 layer->SetIsDrawable(true); | 126 layer->SetIsDrawable(true); |
| 127 layer->SetBounds(gfx::Size(100, 100)); | 127 layer->SetBounds(gfx::Size(100, 100)); |
| 128 background->AddChild(layer); | 128 background->AddChild(layer); |
| 129 | 129 |
| 130 // This has a scale of 2, it should still be rendered pixel-perfect, not show | 130 // This has a scale of 2, it should still be rendered pixel-perfect, not show |
| 131 // scaling artifacts | 131 // scaling artifacts |
| 132 gfx::Transform scale_transform; | 132 gfx::Transform scale_transform; |
| 133 scale_transform.Scale(2.0, 2.0); | 133 scale_transform.Scale(2.0, 2.0); |
| 134 layer->SetTransform(scale_transform); | 134 layer->SetTransform(scale_transform); |
| 135 | 135 |
| 136 RunPixelTest(PIXEL_TEST_GL, background, | 136 RunPixelTest(PIXEL_TEST_GL, background, |
| 137 base::FilePath(FILE_PATH_LITERAL("spiral_double_scale.png"))); | 137 base::FilePath(FILE_PATH_LITERAL("spiral_double_scale.png"))); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST_F(LayerTreeHostScrollbarsPixelTest, HugeTransformScale) { | 140 TEST_F(LayerTreeHostScrollbarsPixelTest, HugeTransformScale) { |
| 141 scoped_refptr<SolidColorLayer> background = | 141 scoped_refptr<SolidColorLayer> background = |
| 142 CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); | 142 CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); |
| 143 | 143 |
| 144 auto scrollbar = base::MakeUnique<PaintedScrollbar>(); | 144 auto scrollbar = base::MakeUnique<PaintedScrollbar>(); |
| 145 scrollbar->set_paint_scale(1); | 145 scrollbar->set_paint_scale(1); |
| 146 scoped_refptr<PaintedScrollbarLayer> layer = | 146 scoped_refptr<PaintedScrollbarLayer> layer = |
| 147 PaintedScrollbarLayer::Create(std::move(scrollbar), Layer::INVALID_ID); | 147 PaintedScrollbarLayer::Create(std::move(scrollbar)); |
| 148 layer->SetIsDrawable(true); | 148 layer->SetIsDrawable(true); |
| 149 layer->SetBounds(gfx::Size(10, 400)); | 149 layer->SetBounds(gfx::Size(10, 400)); |
| 150 background->AddChild(layer); | 150 background->AddChild(layer); |
| 151 | 151 |
| 152 scoped_refptr<TestInProcessContextProvider> context( | 152 scoped_refptr<TestInProcessContextProvider> context( |
| 153 new TestInProcessContextProvider(nullptr)); | 153 new TestInProcessContextProvider(nullptr)); |
| 154 context->BindToCurrentThread(); | 154 context->BindToCurrentThread(); |
| 155 int max_texture_size = 0; | 155 int max_texture_size = 0; |
| 156 context->ContextGL()->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | 156 context->ContextGL()->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); |
| 157 | 157 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 }; | 232 }; |
| 233 | 233 |
| 234 // Simulate increasing the thickness of a painted overlay scrollbar. Ensure that | 234 // Simulate increasing the thickness of a painted overlay scrollbar. Ensure that |
| 235 // the scrollbar border remains crisp. | 235 // the scrollbar border remains crisp. |
| 236 TEST_F(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledUp) { | 236 TEST_F(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledUp) { |
| 237 scoped_refptr<SolidColorLayer> background = | 237 scoped_refptr<SolidColorLayer> background = |
| 238 CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); | 238 CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); |
| 239 | 239 |
| 240 auto scrollbar = base::MakeUnique<PaintedOverlayScrollbar>(); | 240 auto scrollbar = base::MakeUnique<PaintedOverlayScrollbar>(); |
| 241 scoped_refptr<PaintedOverlayScrollbarLayer> layer = | 241 scoped_refptr<PaintedOverlayScrollbarLayer> layer = |
| 242 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar), | 242 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar)); |
| 243 Layer::INVALID_ID); | |
| 244 | 243 |
| 245 scrollbar_layer_id_ = layer->id(); | 244 scrollbar_layer_id_ = layer->id(); |
| 246 thickness_scale_ = 5.f; | 245 thickness_scale_ = 5.f; |
| 247 | 246 |
| 248 layer->SetIsDrawable(true); | 247 layer->SetIsDrawable(true); |
| 249 layer->SetBounds(gfx::Size(10, 300)); | 248 layer->SetBounds(gfx::Size(10, 300)); |
| 250 background->AddChild(layer); | 249 background->AddChild(layer); |
| 251 | 250 |
| 252 layer->SetPosition(gfx::PointF(185, 10)); | 251 layer->SetPosition(gfx::PointF(185, 10)); |
| 253 | 252 |
| 254 RunPixelTest( | 253 RunPixelTest( |
| 255 PIXEL_TEST_GL, background, | 254 PIXEL_TEST_GL, background, |
| 256 base::FilePath(FILE_PATH_LITERAL("overlay_scrollbar_scaled_up.png"))); | 255 base::FilePath(FILE_PATH_LITERAL("overlay_scrollbar_scaled_up.png"))); |
| 257 } | 256 } |
| 258 | 257 |
| 259 // Simulate decreasing the thickness of a painted overlay scrollbar. Ensure that | 258 // Simulate decreasing the thickness of a painted overlay scrollbar. Ensure that |
| 260 // the scrollbar border remains crisp. | 259 // the scrollbar border remains crisp. |
| 261 TEST_F(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledDown) { | 260 TEST_F(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledDown) { |
| 262 scoped_refptr<SolidColorLayer> background = | 261 scoped_refptr<SolidColorLayer> background = |
| 263 CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); | 262 CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); |
| 264 | 263 |
| 265 auto scrollbar = base::MakeUnique<PaintedOverlayScrollbar>(); | 264 auto scrollbar = base::MakeUnique<PaintedOverlayScrollbar>(); |
| 266 scoped_refptr<PaintedOverlayScrollbarLayer> layer = | 265 scoped_refptr<PaintedOverlayScrollbarLayer> layer = |
| 267 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar), | 266 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar)); |
| 268 Layer::INVALID_ID); | |
| 269 | 267 |
| 270 scrollbar_layer_id_ = layer->id(); | 268 scrollbar_layer_id_ = layer->id(); |
| 271 thickness_scale_ = 0.4f; | 269 thickness_scale_ = 0.4f; |
| 272 | 270 |
| 273 layer->SetIsDrawable(true); | 271 layer->SetIsDrawable(true); |
| 274 layer->SetBounds(gfx::Size(10, 300)); | 272 layer->SetBounds(gfx::Size(10, 300)); |
| 275 background->AddChild(layer); | 273 background->AddChild(layer); |
| 276 | 274 |
| 277 layer->SetPosition(gfx::PointF(185, 10)); | 275 layer->SetPosition(gfx::PointF(185, 10)); |
| 278 | 276 |
| 279 RunPixelTest( | 277 RunPixelTest( |
| 280 PIXEL_TEST_GL, background, | 278 PIXEL_TEST_GL, background, |
| 281 base::FilePath(FILE_PATH_LITERAL("overlay_scrollbar_scaled_down.png"))); | 279 base::FilePath(FILE_PATH_LITERAL("overlay_scrollbar_scaled_down.png"))); |
| 282 } | 280 } |
| 283 | 281 |
| 284 } // namespace | 282 } // namespace |
| 285 } // namespace cc | 283 } // namespace cc |
| 286 | 284 |
| 287 #endif // OS_ANDROID | 285 #endif // OS_ANDROID |
| OLD | NEW |