Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / test / web_layer_tree_view_impl_for_testing.cc
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.
4
5 #include "content/test/web_layer_tree_view_impl_for_testing.h"
6
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/input/input_handler.h"
12 #include "cc/layers/layer.h"
13 #include "cc/output/output_surface.h"
14 #include "cc/test/test_context_provider.h"
15 #include "cc/trees/layer_tree_host.h"
16 #include "content/test/test_context_provider_factory.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"
24 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
25
26 using blink::WebColor;
27 using blink::WebGraphicsContext3D;
28 using blink::WebRect;
29 using blink::WebSize;
30 using webkit::WebLayerImpl;
31
32 namespace content {
33
34 WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
35
36 WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
37
38 void WebLayerTreeViewImplForTesting::Initialize() {
39   cc::LayerTreeSettings settings;
40
41   // For web contents, layer transforms should scale up the contents of layers
42   // to keep content always crisp when possible.
43   settings.layer_transforms_should_scale_layer_contents = true;
44
45   // Accelerated animations are enabled for unit tests.
46   settings.accelerated_animation_enabled = true;
47   layer_tree_host_ =
48       cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings);
49   DCHECK(layer_tree_host_);
50 }
51
52 void WebLayerTreeViewImplForTesting::setSurfaceReady() {
53   layer_tree_host_->SetLayerTreeHostClientReady();
54 }
55
56 void WebLayerTreeViewImplForTesting::setRootLayer(
57     const blink::WebLayer& root) {
58   layer_tree_host_->SetRootLayer(
59       static_cast<const WebLayerImpl*>(&root)->layer());
60 }
61
62 void WebLayerTreeViewImplForTesting::clearRootLayer() {
63   layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
64 }
65
66 void WebLayerTreeViewImplForTesting::setViewportSize(
67     const WebSize& unused_deprecated,
68     const WebSize& device_viewport_size) {
69   layer_tree_host_->SetViewportSize(device_viewport_size);
70 }
71
72 WebSize WebLayerTreeViewImplForTesting::layoutViewportSize() const {
73   return layer_tree_host_->device_viewport_size();
74 }
75
76 WebSize WebLayerTreeViewImplForTesting::deviceViewportSize() const {
77   return layer_tree_host_->device_viewport_size();
78 }
79
80 void WebLayerTreeViewImplForTesting::setDeviceScaleFactor(
81     float device_scale_factor) {
82   layer_tree_host_->SetDeviceScaleFactor(device_scale_factor);
83 }
84
85 float WebLayerTreeViewImplForTesting::deviceScaleFactor() const {
86   return layer_tree_host_->device_scale_factor();
87 }
88
89 void WebLayerTreeViewImplForTesting::setBackgroundColor(WebColor color) {
90   layer_tree_host_->set_background_color(color);
91 }
92
93 void WebLayerTreeViewImplForTesting::setHasTransparentBackground(
94     bool transparent) {
95   layer_tree_host_->set_has_transparent_background(transparent);
96 }
97
98 void WebLayerTreeViewImplForTesting::setVisible(bool visible) {
99   layer_tree_host_->SetVisible(visible);
100 }
101
102 void WebLayerTreeViewImplForTesting::setPageScaleFactorAndLimits(
103     float page_scale_factor,
104     float minimum,
105     float maximum) {
106   layer_tree_host_->SetPageScaleFactorAndLimits(
107       page_scale_factor, minimum, maximum);
108 }
109
110 void WebLayerTreeViewImplForTesting::startPageScaleAnimation(
111     const blink::WebPoint& scroll,
112     bool use_anchor,
113     float new_page_scale,
114     double duration_sec) {}
115
116 void WebLayerTreeViewImplForTesting::setNeedsAnimate() {
117   layer_tree_host_->SetNeedsAnimate();
118 }
119
120 bool WebLayerTreeViewImplForTesting::commitRequested() const {
121   return layer_tree_host_->CommitRequested();
122 }
123
124 void WebLayerTreeViewImplForTesting::didStopFlinging() {}
125
126 bool WebLayerTreeViewImplForTesting::compositeAndReadback(
127     void* pixels, const WebRect& rect_in_device_viewport) {
128   return layer_tree_host_->CompositeAndReadback(pixels,
129                                                 rect_in_device_viewport);
130 }
131
132 void WebLayerTreeViewImplForTesting::finishAllRendering() {
133   layer_tree_host_->FinishAllRendering();
134 }
135
136 void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) {
137   layer_tree_host_->SetDeferCommits(defer_commits);
138 }
139
140 void WebLayerTreeViewImplForTesting::Layout() {
141 }
142
143 void WebLayerTreeViewImplForTesting::ApplyScrollAndScale(
144     const gfx::Vector2d& scroll_delta,
145     float page_scale) {}
146
147 scoped_ptr<cc::OutputSurface>
148 WebLayerTreeViewImplForTesting::CreateOutputSurface(bool fallback) {
149   return make_scoped_ptr(
150       new cc::OutputSurface(cc::TestContextProvider::Create()));
151 }
152
153 scoped_refptr<cc::ContextProvider>
154 WebLayerTreeViewImplForTesting::OffscreenContextProvider() {
155   // Unit tests only run in single threaded mode.
156   return content::TestContextProviderFactory::GetInstance()->
157       OffscreenContextProviderForMainThread();
158 }
159
160 void WebLayerTreeViewImplForTesting::registerViewportLayers(
161     const blink::WebLayer* pageScaleLayer,
162     const blink::WebLayer* innerViewportScrollLayer,
163     const blink::WebLayer* outerViewportScrollLayer) {
164   layer_tree_host_->RegisterViewportLayers(
165       static_cast<const WebLayerImpl*>(pageScaleLayer)->layer(),
166       static_cast<const WebLayerImpl*>(innerViewportScrollLayer)->layer(),
167       // The outer viewport layer will only exist when using pinch virtual
168       // viewports.
169       outerViewportScrollLayer
170           ? static_cast<const WebLayerImpl*>(outerViewportScrollLayer)->layer()
171           : NULL);
172 }
173
174 void WebLayerTreeViewImplForTesting::clearViewportLayers() {
175   layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
176                                            scoped_refptr<cc::Layer>(),
177                                            scoped_refptr<cc::Layer>());
178 }
179
180 }  // namespace content