diff options
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layer_tree_settings.cc | 3 | ||||
-rw-r--r-- | cc/layer_tree_settings.h | 4 | ||||
-rw-r--r-- | cc/scrollbar_layer.cc | 12 | ||||
-rw-r--r-- | cc/scrollbar_layer_impl.cc | 17 | ||||
-rw-r--r-- | cc/scrollbar_layer_unittest.cc | 129 |
5 files changed, 165 insertions, 0 deletions
diff --git a/cc/layer_tree_settings.cc b/cc/layer_tree_settings.cc index e53cf73..4efa88e 100644 --- a/cc/layer_tree_settings.cc +++ b/cc/layer_tree_settings.cc @@ -29,6 +29,9 @@ LayerTreeSettings::LayerTreeSettings() , canUseLCDText(true) , shouldClearRootRenderPass(true) , useLinearFadeScrollbarAnimator(false) + , solidColorScrollbars(false) + , solidColorScrollbarColor(SK_ColorWHITE) + , solidColorScrollbarThicknessDIP(-1) , calculateTopControlsPosition(false) , useCheapnessEstimator(false) , useMemoryManagement(true) diff --git a/cc/layer_tree_settings.h b/cc/layer_tree_settings.h index 69100bf..98c381d 100644 --- a/cc/layer_tree_settings.h +++ b/cc/layer_tree_settings.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "cc/cc_export.h" #include "cc/layer_tree_debug_state.h" +#include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/size.h" namespace cc { @@ -32,6 +33,9 @@ class CC_EXPORT LayerTreeSettings { bool canUseLCDText; bool shouldClearRootRenderPass; bool useLinearFadeScrollbarAnimator; + bool solidColorScrollbars; + SkColor solidColorScrollbarColor; + int solidColorScrollbarThicknessDIP; bool calculateTopControlsPosition; bool useCheapnessEstimator; bool useMemoryManagement; diff --git a/cc/scrollbar_layer.cc b/cc/scrollbar_layer.cc index 6fad23c..ded7bf1 100644 --- a/cc/scrollbar_layer.cc +++ b/cc/scrollbar_layer.cc @@ -70,6 +70,9 @@ int ScrollbarLayer::maxTextureSize() { } float ScrollbarLayer::clampScaleToMaxTextureSize(float scale) { + if (layerTreeHost()->settings().solidColorScrollbars) + return scale; + // If the scaled contentBounds() is bigger than the max texture size of the // device, we need to clamp it by rescaling, since contentBounds() is used // below to set the texture size. @@ -229,6 +232,9 @@ void ScrollbarLayer::setLayerTreeHost(LayerTreeHost* host) void ScrollbarLayer::createUpdaterIfNeeded() { + if (layerTreeHost()->settings().solidColorScrollbars) + return; + m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; if (!m_backTrackUpdater) @@ -252,6 +258,9 @@ void ScrollbarLayer::createUpdaterIfNeeded() void ScrollbarLayer::updatePart(CachingBitmapContentLayerUpdater* painter, LayerUpdater::Resource* resource, const gfx::Rect& rect, ResourceUpdateQueue& queue, RenderingStats* stats) { + if (layerTreeHost()->settings().solidColorScrollbars) + return; + // Skip painting and uploading if there are no invalidations and // we already have valid texture data. if (resource->texture()->haveBackingTexture() && @@ -290,6 +299,9 @@ gfx::Rect ScrollbarLayer::scrollbarLayerRectToContentRect(const gfx::Rect& layer void ScrollbarLayer::setTexturePriorities(const PriorityCalculator&) { + if (layerTreeHost()->settings().solidColorScrollbars) + return; + if (contentBounds().IsEmpty()) return; DCHECK_LE(contentBounds().width(), maxTextureSize()); diff --git a/cc/scrollbar_layer_impl.cc b/cc/scrollbar_layer_impl.cc index f0b5f7f..976f4cb 100644 --- a/cc/scrollbar_layer_impl.cc +++ b/cc/scrollbar_layer_impl.cc @@ -5,8 +5,10 @@ #include "cc/scrollbar_layer_impl.h" #include "cc/layer_tree_impl.h" +#include "cc/layer_tree_settings.h" #include "cc/quad_sink.h" #include "cc/scrollbar_animation_controller.h" +#include "cc/solid_color_draw_quad.h" #include "cc/texture_draw_quad.h" #include "ui/gfx/rect_conversions.h" @@ -151,6 +153,21 @@ void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append if (!m_geometry->hasThumb(&m_scrollbar)) thumbRect = WebRect(); + if (layerTreeImpl()->settings().solidColorScrollbars) { + int thicknessOverride = layerTreeImpl()->settings().solidColorScrollbarThicknessDIP; + if (thicknessOverride != -1) { + if (m_scrollbar.orientation() == WebScrollbar::Vertical) + thumbRect.width = thicknessOverride; + else + thumbRect.height = thicknessOverride; + } + gfx::Rect quadRect(scrollbarLayerRectToContentRect(thumbRect)); + scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); + quad->SetNew(sharedQuadState, quadRect, layerTreeImpl()->settings().solidColorScrollbarColor); + quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); + return; + } + if (m_thumbResourceId && !thumbRect.isEmpty()) { gfx::Rect quadRect(scrollbarLayerRectToContentRect(thumbRect)); gfx::Rect opaqueRect; diff --git a/cc/scrollbar_layer_unittest.cc b/cc/scrollbar_layer_unittest.cc index fa5cd63..c7edef1 100644 --- a/cc/scrollbar_layer_unittest.cc +++ b/cc/scrollbar_layer_unittest.cc @@ -4,17 +4,26 @@ #include "cc/scrollbar_layer.h" +#include "cc/append_quads_data.h" +#include "cc/prioritized_resource_manager.h" +#include "cc/priority_calculator.h" +#include "cc/resource_update_queue.h" #include "cc/scrollbar_animation_controller.h" #include "cc/scrollbar_layer_impl.h" #include "cc/single_thread_proxy.h" +#include "cc/solid_color_draw_quad.h" #include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_scrollbar_theme_painter.h" #include "cc/test/fake_web_scrollbar.h" #include "cc/test/fake_web_scrollbar_theme_geometry.h" +#include "cc/test/geometry_test_utils.h" #include "cc/test/layer_tree_test_common.h" +#include "cc/test/mock_quad_culler.h" #include "cc/test/test_web_graphics_context_3d.h" #include "cc/tree_synchronizer.h" +#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGeometry.h" @@ -138,6 +147,48 @@ TEST(ScrollbarLayerTest, scrollOffsetSynchronization) EXPECT_EQ(300, ccScrollbarLayer->maximum()); } +TEST(ScrollbarLayerTest, solidColorThicknessOverride) +{ + LayerTreeSettings layerTreeSettings; + layerTreeSettings.solidColorScrollbars = true; + layerTreeSettings.solidColorScrollbarThicknessDIP = 3; + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(layerTreeSettings, &proxy); + + scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); + static_cast<FakeWebScrollbar*>(scrollbar.get())->setOverlay(true); + scoped_ptr<LayerImpl> layerImplTreeRoot = layerImplForScrollAreaAndScrollbar(&hostImpl, scrollbar.Pass(), false); + ScrollbarLayerImpl* scrollbarLayerImpl = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); + scrollbarLayerImpl->setThumbSize(gfx::Size(4, 4)); + + // Thickness should be overridden to 3. + { + MockQuadCuller quadCuller; + AppendQuadsData data; + scrollbarLayerImpl->appendQuads(quadCuller, data); + + const QuadList& quads = quadCuller.quadList(); + ASSERT_EQ(1, quads.size()); + EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); + EXPECT_RECT_EQ(gfx::Rect(1, 0, 4, 3), quads[0]->rect); + } + + // Contents scale should scale the draw quad. + scrollbarLayerImpl->drawProperties().contents_scale_x = 2; + scrollbarLayerImpl->drawProperties().contents_scale_y = 2; + { + MockQuadCuller quadCuller; + AppendQuadsData data; + scrollbarLayerImpl->appendQuads(quadCuller, data); + + const QuadList& quads = quadCuller.quadList(); + ASSERT_EQ(1, quads.size()); + EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); + EXPECT_RECT_EQ(gfx::Rect(2, 0, 8, 6), quads[0]->rect); + } + +} + class ScrollbarLayerTestMaxTextureSize : public ThreadedTest { public: ScrollbarLayerTestMaxTextureSize() {} @@ -194,5 +245,83 @@ TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { runTest(true); } +class MockLayerTreeHost : public LayerTreeHost { +public: + MockLayerTreeHost(const LayerTreeSettings& settings) + : LayerTreeHost(&m_fakeClient, settings) + { + initialize(scoped_ptr<Thread>(NULL)); + } + +private: + FakeLayerImplTreeHostClient m_fakeClient; +}; + + +class ScrollbarLayerTestResourceCreation : public testing::Test { +public: + ScrollbarLayerTestResourceCreation() + { + } + + void testResourceUpload(int expectedResources) + { + m_layerTreeHost.reset(new MockLayerTreeHost(m_layerTreeSettings)); + + scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); + scoped_refptr<Layer> layerTreeRoot = Layer::create(); + scoped_refptr<Layer> contentLayer = Layer::create(); + scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(true), layerTreeRoot->id()); + layerTreeRoot->addChild(contentLayer); + layerTreeRoot->addChild(scrollbarLayer); + + m_layerTreeHost->initializeRendererIfNeeded(); + m_layerTreeHost->contentsTextureManager()->setMaxMemoryLimitBytes(1024 * 1024); + m_layerTreeHost->setRootLayer(layerTreeRoot); + + scrollbarLayer->setIsDrawable(true); + scrollbarLayer->setBounds(gfx::Size(100, 100)); + layerTreeRoot->setScrollOffset(gfx::Vector2d(10, 20)); + layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50)); + layerTreeRoot->setBounds(gfx::Size(100, 200)); + contentLayer->setBounds(gfx::Size(100, 200)); + scrollbarLayer->drawProperties().content_bounds = gfx::Size(100, 200); + scrollbarLayer->drawProperties().visible_content_rect = gfx::Rect(0, 0, 100, 200); + scrollbarLayer->createRenderSurface(); + scrollbarLayer->drawProperties().render_target = scrollbarLayer; + + testing::Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + EXPECT_EQ(scrollbarLayer->layerTreeHost(), m_layerTreeHost.get()); + + PriorityCalculator calculator; + ResourceUpdateQueue queue; + OcclusionTracker occlusionTracker(gfx::Rect(), false); + + scrollbarLayer->setTexturePriorities(calculator); + m_layerTreeHost->contentsTextureManager()->prioritizeTextures(); + scrollbarLayer->update(queue, &occlusionTracker, NULL); + EXPECT_EQ(0, queue.fullUploadSize()); + EXPECT_EQ(expectedResources, queue.partialUploadSize()); + + testing::Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); + } + +protected: + scoped_ptr<MockLayerTreeHost> m_layerTreeHost; + LayerTreeSettings m_layerTreeSettings; +}; + +TEST_F(ScrollbarLayerTestResourceCreation, resourceUpload) +{ + m_layerTreeSettings.solidColorScrollbars = false; + testResourceUpload(2); +} + +TEST_F(ScrollbarLayerTestResourceCreation, solidColorNoResourceUpload) +{ + m_layerTreeSettings.solidColorScrollbars = true; + testResourceUpload(0); +} + } // namespace } // namespace cc |