Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / test / web_layer_tree_view_impl_for_testing.cc
blobe183c2aa7ebd2f1855fc3e770ff61b1d8ae4b3af
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/output/output_surface.h"
15 #include "cc/test/test_context_provider.h"
16 #include "cc/trees/layer_tree_host.h"
17 #include "content/test/test_webkit_platform_support.h"
18 #include "third_party/WebKit/public/platform/Platform.h"
19 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
20 #include "third_party/WebKit/public/platform/WebLayer.h"
21 #include "third_party/WebKit/public/platform/WebLayerTreeView.h"
22 #include "third_party/WebKit/public/platform/WebSize.h"
23 #include "ui/gfx/frame_time.h"
25 using blink::WebColor;
26 using blink::WebGraphicsContext3D;
27 using blink::WebRect;
28 using blink::WebSize;
30 namespace content {
32 WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
34 WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
36 void WebLayerTreeViewImplForTesting::Initialize() {
37 cc::LayerTreeSettings settings;
39 // For web contents, layer transforms should scale up the contents of layers
40 // to keep content always crisp when possible.
41 settings.layer_transforms_should_scale_layer_contents = true;
43 // Accelerated animations are enabled for unit tests.
44 settings.accelerated_animation_enabled = true;
45 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
46 this, this, NULL, settings, base::MessageLoopProxy::current());
47 DCHECK(layer_tree_host_);
50 void WebLayerTreeViewImplForTesting::setSurfaceReady() {
51 layer_tree_host_->SetLayerTreeHostClientReady();
54 void WebLayerTreeViewImplForTesting::setRootLayer(
55 const blink::WebLayer& root) {
56 layer_tree_host_->SetRootLayer(
57 static_cast<const cc_blink::WebLayerImpl*>(&root)->layer());
60 void WebLayerTreeViewImplForTesting::clearRootLayer() {
61 layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
64 void WebLayerTreeViewImplForTesting::setViewportSize(
65 const WebSize& unused_deprecated,
66 const WebSize& device_viewport_size) {
67 layer_tree_host_->SetViewportSize(device_viewport_size);
70 void WebLayerTreeViewImplForTesting::setViewportSize(
71 const WebSize& device_viewport_size) {
72 layer_tree_host_->SetViewportSize(device_viewport_size);
75 WebSize WebLayerTreeViewImplForTesting::layoutViewportSize() const {
76 return layer_tree_host_->device_viewport_size();
79 WebSize WebLayerTreeViewImplForTesting::deviceViewportSize() const {
80 return layer_tree_host_->device_viewport_size();
83 void WebLayerTreeViewImplForTesting::setDeviceScaleFactor(
84 float device_scale_factor) {
85 layer_tree_host_->SetDeviceScaleFactor(device_scale_factor);
88 float WebLayerTreeViewImplForTesting::deviceScaleFactor() const {
89 return layer_tree_host_->device_scale_factor();
92 void WebLayerTreeViewImplForTesting::setBackgroundColor(WebColor color) {
93 layer_tree_host_->set_background_color(color);
96 void WebLayerTreeViewImplForTesting::setHasTransparentBackground(
97 bool transparent) {
98 layer_tree_host_->set_has_transparent_background(transparent);
101 void WebLayerTreeViewImplForTesting::setVisible(bool visible) {
102 layer_tree_host_->SetVisible(visible);
105 void WebLayerTreeViewImplForTesting::setPageScaleFactorAndLimits(
106 float page_scale_factor,
107 float minimum,
108 float maximum) {
109 layer_tree_host_->SetPageScaleFactorAndLimits(
110 page_scale_factor, minimum, maximum);
113 void WebLayerTreeViewImplForTesting::startPageScaleAnimation(
114 const blink::WebPoint& scroll,
115 bool use_anchor,
116 float new_page_scale,
117 double duration_sec) {}
119 void WebLayerTreeViewImplForTesting::setNeedsAnimate() {
120 layer_tree_host_->SetNeedsAnimate();
123 bool WebLayerTreeViewImplForTesting::commitRequested() const {
124 return layer_tree_host_->CommitRequested();
127 void WebLayerTreeViewImplForTesting::didStopFlinging() {}
129 void WebLayerTreeViewImplForTesting::finishAllRendering() {
130 layer_tree_host_->FinishAllRendering();
133 void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) {
134 layer_tree_host_->SetDeferCommits(defer_commits);
137 void WebLayerTreeViewImplForTesting::Layout() {
140 void WebLayerTreeViewImplForTesting::ApplyScrollAndScale(
141 const gfx::Vector2d& scroll_delta,
142 float page_scale) {}
144 scoped_ptr<cc::OutputSurface>
145 WebLayerTreeViewImplForTesting::CreateOutputSurface(bool fallback) {
146 return make_scoped_ptr(
147 new cc::OutputSurface(cc::TestContextProvider::Create()));
150 void WebLayerTreeViewImplForTesting::registerViewportLayers(
151 const blink::WebLayer* pageScaleLayer,
152 const blink::WebLayer* innerViewportScrollLayer,
153 const blink::WebLayer* outerViewportScrollLayer) {
154 layer_tree_host_->RegisterViewportLayers(
155 static_cast<const cc_blink::WebLayerImpl*>(pageScaleLayer)->layer(),
156 static_cast<const cc_blink::WebLayerImpl*>(innerViewportScrollLayer)
157 ->layer(),
158 // The outer viewport layer will only exist when using pinch virtual
159 // viewports.
160 outerViewportScrollLayer ? static_cast<const cc_blink::WebLayerImpl*>(
161 outerViewportScrollLayer)->layer()
162 : NULL);
165 void WebLayerTreeViewImplForTesting::clearViewportLayers() {
166 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
167 scoped_refptr<cc::Layer>(),
168 scoped_refptr<cc::Layer>());
171 void WebLayerTreeViewImplForTesting::registerSelection(
172 const blink::WebSelectionBound& start,
173 const blink::WebSelectionBound& end) {
176 void WebLayerTreeViewImplForTesting::clearSelection() {
179 } // namespace content