| 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 "cc/scrollbar_layer.h" | 5 #include "cc/scrollbar_layer.h" |
| 6 | 6 |
| 7 #include "cc/prioritized_resource_manager.h" |
| 8 #include "cc/priority_calculator.h" |
| 9 #include "cc/resource_update_queue.h" |
| 7 #include "cc/scrollbar_animation_controller.h" | 10 #include "cc/scrollbar_animation_controller.h" |
| 8 #include "cc/scrollbar_layer_impl.h" | 11 #include "cc/scrollbar_layer_impl.h" |
| 9 #include "cc/single_thread_proxy.h" | 12 #include "cc/single_thread_proxy.h" |
| 10 #include "cc/test/fake_impl_proxy.h" | 13 #include "cc/test/fake_impl_proxy.h" |
| 14 #include "cc/test/fake_layer_tree_host_client.h" |
| 11 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
| 12 #include "cc/test/fake_scrollbar_theme_painter.h" | 16 #include "cc/test/fake_scrollbar_theme_painter.h" |
| 13 #include "cc/test/fake_web_scrollbar.h" | 17 #include "cc/test/fake_web_scrollbar.h" |
| 14 #include "cc/test/fake_web_scrollbar_theme_geometry.h" | 18 #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
| 15 #include "cc/test/layer_tree_test_common.h" | 19 #include "cc/test/layer_tree_test_common.h" |
| 16 #include "cc/test/test_web_graphics_context_3d.h" | 20 #include "cc/test/test_web_graphics_context_3d.h" |
| 17 #include "cc/tree_synchronizer.h" | 21 #include "cc/tree_synchronizer.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" |
| 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGe
ometry.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGe
ometry.h" |
| 21 | 26 |
| 22 namespace cc { | 27 namespace cc { |
| 23 namespace { | 28 namespace { |
| 24 | 29 |
| 25 scoped_ptr<LayerImpl> layerImplForScrollAreaAndScrollbar( | 30 scoped_ptr<LayerImpl> layerImplForScrollAreaAndScrollbar( |
| 26 FakeLayerTreeHostImpl* host_impl, | 31 FakeLayerTreeHostImpl* host_impl, |
| 27 scoped_ptr<WebKit::WebScrollbar> scrollbar, | 32 scoped_ptr<WebKit::WebScrollbar> scrollbar, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 }; | 192 }; |
| 188 | 193 |
| 189 TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { | 194 TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { |
| 190 scoped_ptr<TestWebGraphicsContext3D> context = TestWebGraphicsContext3D::Cre
ate(); | 195 scoped_ptr<TestWebGraphicsContext3D> context = TestWebGraphicsContext3D::Cre
ate(); |
| 191 int max_size = 0; | 196 int max_size = 0; |
| 192 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); | 197 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); |
| 193 setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); | 198 setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); |
| 194 runTest(true); | 199 runTest(true); |
| 195 } | 200 } |
| 196 | 201 |
| 202 class MockLayerTreeHost : public LayerTreeHost { |
| 203 public: |
| 204 MockLayerTreeHost(const LayerTreeSettings& settings) |
| 205 : LayerTreeHost(&m_fakeClient, settings) |
| 206 { |
| 207 initialize(scoped_ptr<Thread>(NULL)); |
| 208 } |
| 209 |
| 210 private: |
| 211 FakeLayerImplTreeHostClient m_fakeClient; |
| 212 }; |
| 213 |
| 214 |
| 215 class ScrollbarLayerTestResourceCreation : public testing::Test { |
| 216 public: |
| 217 ScrollbarLayerTestResourceCreation() |
| 218 { |
| 219 } |
| 220 |
| 221 void testResourceUpload(int expectedResources) |
| 222 { |
| 223 m_layerTreeHost.reset(new MockLayerTreeHost(m_layerTreeSettings)); |
| 224 |
| 225 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
| 226 scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
| 227 scoped_refptr<Layer> contentLayer = Layer::create(); |
| 228 scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::create(scrollbar.P
ass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(),
FakeWebScrollbarThemeGeometry::create(true), layerTreeRoot->id()); |
| 229 layerTreeRoot->addChild(contentLayer); |
| 230 layerTreeRoot->addChild(scrollbarLayer); |
| 231 |
| 232 m_layerTreeHost->initializeRendererIfNeeded(); |
| 233 m_layerTreeHost->contentsTextureManager()->setMaxMemoryLimitBytes(1024 *
1024); |
| 234 m_layerTreeHost->setRootLayer(layerTreeRoot); |
| 235 |
| 236 scrollbarLayer->setIsDrawable(true); |
| 237 scrollbarLayer->setBounds(gfx::Size(100, 100)); |
| 238 layerTreeRoot->setScrollOffset(gfx::Vector2d(10, 20)); |
| 239 layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50)); |
| 240 layerTreeRoot->setBounds(gfx::Size(100, 200)); |
| 241 contentLayer->setBounds(gfx::Size(100, 200)); |
| 242 scrollbarLayer->drawProperties().content_bounds = gfx::Size(100, 200); |
| 243 scrollbarLayer->drawProperties().visible_content_rect = gfx::Rect(0, 0,
100, 200); |
| 244 scrollbarLayer->drawProperties().render_target = scrollbarLayer; |
| 245 |
| 246 testing::Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 247 EXPECT_EQ(scrollbarLayer->layerTreeHost(), m_layerTreeHost.get()); |
| 248 |
| 249 PriorityCalculator calculator; |
| 250 ResourceUpdateQueue queue; |
| 251 OcclusionTracker occlusionTracker(gfx::Rect(), false); |
| 252 |
| 253 scrollbarLayer->setTexturePriorities(calculator); |
| 254 m_layerTreeHost->contentsTextureManager()->prioritizeTextures(); |
| 255 scrollbarLayer->update(queue, &occlusionTracker, NULL); |
| 256 EXPECT_EQ(0, queue.fullUploadSize()); |
| 257 EXPECT_EQ(expectedResources, queue.partialUploadSize()); |
| 258 |
| 259 testing::Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 260 } |
| 261 |
| 262 protected: |
| 263 scoped_ptr<MockLayerTreeHost> m_layerTreeHost; |
| 264 LayerTreeSettings m_layerTreeSettings; |
| 265 }; |
| 266 |
| 267 TEST_F(ScrollbarLayerTestResourceCreation, resourceUpload) |
| 268 { |
| 269 m_layerTreeSettings.solidColorScrollbars = false; |
| 270 testResourceUpload(2); |
| 271 } |
| 272 |
| 273 TEST_F(ScrollbarLayerTestResourceCreation, solidColorNoResourceUpload) |
| 274 { |
| 275 m_layerTreeSettings.solidColorScrollbars = true; |
| 276 testResourceUpload(0); |
| 277 } |
| 278 |
| 197 } // namespace | 279 } // namespace |
| 198 } // namespace cc | 280 } // namespace cc |
| OLD | NEW |