Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320)
[chromium-blink-merge.git] / content / test / web_layer_tree_view_impl_for_testing.cc
blob20da3cd6208d63dcb76119b2bcde30dd5b60cc22
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/test/web_layer_tree_view_impl_for_testing.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/synchronization/lock.h"
10 #include "cc/base/switches.h"
11 #include "cc/blink/web_layer_impl.h"
12 #include "cc/input/input_handler.h"
13 #include "cc/layers/layer.h"
14 #include "cc/scheduler/begin_frame_source.h"
15 #include "cc/test/pixel_test_output_surface.h"
16 #include "cc/test/test_context_provider.h"
17 #include "cc/trees/layer_tree_host.h"
18 #include "content/test/test_blink_web_unit_test_support.h"
19 #include "third_party/WebKit/public/platform/Platform.h"
20 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
21 #include "third_party/WebKit/public/platform/WebLayer.h"
22 #include "third_party/WebKit/public/platform/WebLayerTreeView.h"
23 #include "third_party/WebKit/public/platform/WebSize.h"
24 #include "ui/gfx/frame_time.h"
26 using blink::WebColor;
27 using blink::WebGraphicsContext3D;
28 using blink::WebRect;
29 using blink::WebSize;
31 namespace content {
33 WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
35 WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
37 void WebLayerTreeViewImplForTesting::Initialize() {
38 cc::LayerTreeSettings settings;
40 // For web contents, layer transforms should scale up the contents of layers
41 // to keep content always crisp when possible.
42 settings.layer_transforms_should_scale_layer_contents = true;
44 // Accelerated animations are enabled for unit tests.
45 settings.accelerated_animation_enabled = true;
46 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
47 this, this, nullptr, nullptr, nullptr, settings,
48 base::MessageLoopProxy::current(), nullptr);
49 DCHECK(layer_tree_host_);
52 void WebLayerTreeViewImplForTesting::setRootLayer(
53 const blink::WebLayer& root) {
54 layer_tree_host_->SetRootLayer(
55 static_cast<const cc_blink::WebLayerImpl*>(&root)->layer());
58 void WebLayerTreeViewImplForTesting::clearRootLayer() {
59 layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
62 void WebLayerTreeViewImplForTesting::setViewportSize(
63 const WebSize& unused_deprecated,
64 const WebSize& device_viewport_size) {
65 layer_tree_host_->SetViewportSize(device_viewport_size);
68 void WebLayerTreeViewImplForTesting::setViewportSize(
69 const WebSize& device_viewport_size) {
70 layer_tree_host_->SetViewportSize(device_viewport_size);
73 WebSize WebLayerTreeViewImplForTesting::layoutViewportSize() const {
74 return layer_tree_host_->device_viewport_size();
77 WebSize WebLayerTreeViewImplForTesting::deviceViewportSize() const {
78 return layer_tree_host_->device_viewport_size();
81 void WebLayerTreeViewImplForTesting::setDeviceScaleFactor(
82 float device_scale_factor) {
83 layer_tree_host_->SetDeviceScaleFactor(device_scale_factor);
86 float WebLayerTreeViewImplForTesting::deviceScaleFactor() const {
87 return layer_tree_host_->device_scale_factor();
90 void WebLayerTreeViewImplForTesting::setBackgroundColor(WebColor color) {
91 layer_tree_host_->set_background_color(color);
94 void WebLayerTreeViewImplForTesting::setHasTransparentBackground(
95 bool transparent) {
96 layer_tree_host_->set_has_transparent_background(transparent);
99 void WebLayerTreeViewImplForTesting::setVisible(bool visible) {
100 layer_tree_host_->SetVisible(visible);
103 void WebLayerTreeViewImplForTesting::setPageScaleFactorAndLimits(
104 float page_scale_factor,
105 float minimum,
106 float maximum) {
107 layer_tree_host_->SetPageScaleFactorAndLimits(
108 page_scale_factor, minimum, maximum);
111 void WebLayerTreeViewImplForTesting::startPageScaleAnimation(
112 const blink::WebPoint& scroll,
113 bool use_anchor,
114 float new_page_scale,
115 double duration_sec) {}
117 void WebLayerTreeViewImplForTesting::setNeedsAnimate() {
118 layer_tree_host_->SetNeedsAnimate();
121 bool WebLayerTreeViewImplForTesting::commitRequested() const {
122 return layer_tree_host_->CommitRequested();
125 void WebLayerTreeViewImplForTesting::didStopFlinging() {}
127 void WebLayerTreeViewImplForTesting::finishAllRendering() {
128 layer_tree_host_->FinishAllRendering();
131 void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) {
132 layer_tree_host_->SetDeferCommits(defer_commits);
135 void WebLayerTreeViewImplForTesting::Layout() {
138 void WebLayerTreeViewImplForTesting::ApplyViewportDeltas(
139 const gfx::Vector2dF& inner_delta,
140 const gfx::Vector2dF& outer_delta,
141 const gfx::Vector2dF& elastic_overscroll_delta,
142 float page_scale,
143 float top_controls_delta) {
146 void WebLayerTreeViewImplForTesting::ApplyViewportDeltas(
147 const gfx::Vector2d& scroll_delta,
148 float page_scale,
149 float top_controls_delta) {}
151 void WebLayerTreeViewImplForTesting::RequestNewOutputSurface() {
152 bool flipped_output_surface = false;
153 layer_tree_host_->SetOutputSurface(
154 make_scoped_ptr(new cc::PixelTestOutputSurface(
155 cc::TestContextProvider::Create(), flipped_output_surface)));
158 void WebLayerTreeViewImplForTesting::DidFailToInitializeOutputSurface() {
159 RequestNewOutputSurface();
162 void WebLayerTreeViewImplForTesting::registerViewportLayers(
163 const blink::WebLayer* overscrollElasticityLayer,
164 const blink::WebLayer* pageScaleLayer,
165 const blink::WebLayer* innerViewportScrollLayer,
166 const blink::WebLayer* outerViewportScrollLayer) {
167 layer_tree_host_->RegisterViewportLayers(
168 // The scroll elasticity layer will only exist when using pinch virtual
169 // viewports.
170 overscrollElasticityLayer
171 ? static_cast<const cc_blink::WebLayerImpl*>(
172 overscrollElasticityLayer)->layer()
173 : NULL,
174 static_cast<const cc_blink::WebLayerImpl*>(pageScaleLayer)->layer(),
175 static_cast<const cc_blink::WebLayerImpl*>(innerViewportScrollLayer)
176 ->layer(),
177 // The outer viewport layer will only exist when using pinch virtual
178 // viewports.
179 outerViewportScrollLayer
180 ? static_cast<const cc_blink::WebLayerImpl*>(outerViewportScrollLayer)
181 ->layer()
182 : NULL);
185 void WebLayerTreeViewImplForTesting::clearViewportLayers() {
186 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
187 scoped_refptr<cc::Layer>(),
188 scoped_refptr<cc::Layer>(),
189 scoped_refptr<cc::Layer>());
192 void WebLayerTreeViewImplForTesting::registerSelection(
193 const blink::WebSelectionBound& start,
194 const blink::WebSelectionBound& end) {
197 void WebLayerTreeViewImplForTesting::clearSelection() {
200 } // namespace content