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/debug/test_context_provider.h"
12 #include "cc/input/input_handler.h"
13 #include "cc/layers/layer.h"
14 #include "cc/output/output_surface.h"
15 #include "cc/trees/layer_tree_host.h"
16 #include "content/test/test_webkit_platform_support.h"
17 #include "third_party/WebKit/public/platform/Platform.h"
18 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
19 #include "third_party/WebKit/public/platform/WebLayer.h"
20 #include "third_party/WebKit/public/platform/WebLayerTreeView.h"
21 #include "third_party/WebKit/public/platform/WebRenderingStats.h"
22 #include "third_party/WebKit/public/platform/WebSize.h"
23 #include "webkit/common/gpu/test_context_provider_factory.h"
24 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
26 using WebKit::WebColor
;
27 using WebKit::WebGraphicsContext3D
;
28 using WebKit::WebRect
;
29 using WebKit::WebRenderingStats
;
30 using WebKit::WebSize
;
34 WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
36 WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
38 bool WebLayerTreeViewImplForTesting::Initialize() {
39 cc::LayerTreeSettings settings
;
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;
45 // Accelerated animations are enabled for unit tests.
46 settings
.accelerated_animation_enabled
= true;
47 layer_tree_host_
= cc::LayerTreeHost::Create(this, NULL
, settings
, NULL
);
48 if (!layer_tree_host_
)
53 void WebLayerTreeViewImplForTesting::setSurfaceReady() {
54 layer_tree_host_
->SetLayerTreeHostClientReady();
57 void WebLayerTreeViewImplForTesting::setRootLayer(
58 const WebKit::WebLayer
& root
) {
59 layer_tree_host_
->SetRootLayer(
60 static_cast<const WebLayerImpl
*>(&root
)->layer());
63 void WebLayerTreeViewImplForTesting::clearRootLayer() {
64 layer_tree_host_
->SetRootLayer(scoped_refptr
<cc::Layer
>());
67 void WebLayerTreeViewImplForTesting::setViewportSize(
68 const WebSize
& unused_deprecated
,
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(
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
,
107 layer_tree_host_
->SetPageScaleFactorAndLimits(
108 page_scale_factor
, minimum
, maximum
);
111 void WebLayerTreeViewImplForTesting::startPageScaleAnimation(
112 const WebKit::WebPoint
& scroll
,
114 float new_page_scale
,
115 double duration_sec
) {}
117 void WebLayerTreeViewImplForTesting::setNeedsAnimate() {
118 layer_tree_host_
->SetNeedsAnimate();
121 void WebLayerTreeViewImplForTesting::setNeedsRedraw() {
122 layer_tree_host_
->SetNeedsRedraw();
125 bool WebLayerTreeViewImplForTesting::commitRequested() const {
126 return layer_tree_host_
->CommitRequested();
129 void WebLayerTreeViewImplForTesting::composite() {
130 layer_tree_host_
->Composite(base::TimeTicks::Now());
133 void WebLayerTreeViewImplForTesting::didStopFlinging() {}
135 bool WebLayerTreeViewImplForTesting::compositeAndReadback(
136 void* pixels
, const WebRect
& rect_in_device_viewport
) {
137 return layer_tree_host_
->CompositeAndReadback(pixels
,
138 rect_in_device_viewport
);
141 void WebLayerTreeViewImplForTesting::finishAllRendering() {
142 layer_tree_host_
->FinishAllRendering();
145 void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits
) {
146 layer_tree_host_
->SetDeferCommits(defer_commits
);
149 void WebLayerTreeViewImplForTesting::renderingStats(WebRenderingStats
&) const {}
151 void WebLayerTreeViewImplForTesting::Layout() {
154 void WebLayerTreeViewImplForTesting::ApplyScrollAndScale(
155 gfx::Vector2d scroll_delta
,
158 scoped_ptr
<cc::OutputSurface
>
159 WebLayerTreeViewImplForTesting::CreateOutputSurface(bool fallback
) {
160 return make_scoped_ptr(
161 new cc::OutputSurface(cc::TestContextProvider::Create()));
164 void WebLayerTreeViewImplForTesting::ScheduleComposite() {
167 scoped_refptr
<cc::ContextProvider
>
168 WebLayerTreeViewImplForTesting::OffscreenContextProvider() {
169 // Unit tests only run in single threaded mode.
170 return webkit::gpu::TestContextProviderFactory::GetInstance()->
171 OffscreenContextProviderForMainThread();
174 } // namespace webkit