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/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_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 "ui/gfx/frame_time.h"
24 #include "webkit/common/gpu/test_context_provider_factory.h"
25 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
27 using blink::WebColor
;
28 using blink::WebGraphicsContext3D
;
30 using blink::WebRenderingStats
;
35 WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
37 WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
39 bool WebLayerTreeViewImplForTesting::Initialize() {
40 cc::LayerTreeSettings settings
;
42 // For web contents, layer transforms should scale up the contents of layers
43 // to keep content always crisp when possible.
44 settings
.layer_transforms_should_scale_layer_contents
= true;
46 // Accelerated animations are enabled for unit tests.
47 settings
.accelerated_animation_enabled
= true;
49 cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL
, settings
);
50 if (!layer_tree_host_
)
55 void WebLayerTreeViewImplForTesting::setSurfaceReady() {
56 layer_tree_host_
->SetLayerTreeHostClientReady();
59 void WebLayerTreeViewImplForTesting::setRootLayer(
60 const blink::WebLayer
& root
) {
61 layer_tree_host_
->SetRootLayer(
62 static_cast<const WebLayerImpl
*>(&root
)->layer());
65 void WebLayerTreeViewImplForTesting::clearRootLayer() {
66 layer_tree_host_
->SetRootLayer(scoped_refptr
<cc::Layer
>());
69 void WebLayerTreeViewImplForTesting::setViewportSize(
70 const WebSize
& unused_deprecated
,
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(
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
,
109 layer_tree_host_
->SetPageScaleFactorAndLimits(
110 page_scale_factor
, minimum
, maximum
);
113 void WebLayerTreeViewImplForTesting::startPageScaleAnimation(
114 const blink::WebPoint
& scroll
,
116 float new_page_scale
,
117 double duration_sec
) {}
119 void WebLayerTreeViewImplForTesting::setNeedsAnimate() {
120 layer_tree_host_
->SetNeedsAnimate();
123 // Merged into setNeedsAnimate. Staged for removal.
124 void WebLayerTreeViewImplForTesting::setNeedsRedraw() { setNeedsAnimate(); }
126 bool WebLayerTreeViewImplForTesting::commitRequested() const {
127 return layer_tree_host_
->CommitRequested();
130 void WebLayerTreeViewImplForTesting::composite() {
131 layer_tree_host_
->Composite(gfx::FrameTime::Now());
134 void WebLayerTreeViewImplForTesting::didStopFlinging() {}
136 bool WebLayerTreeViewImplForTesting::compositeAndReadback(
137 void* pixels
, const WebRect
& rect_in_device_viewport
) {
138 return layer_tree_host_
->CompositeAndReadback(pixels
,
139 rect_in_device_viewport
);
142 void WebLayerTreeViewImplForTesting::finishAllRendering() {
143 layer_tree_host_
->FinishAllRendering();
146 void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits
) {
147 layer_tree_host_
->SetDeferCommits(defer_commits
);
150 void WebLayerTreeViewImplForTesting::renderingStats(WebRenderingStats
&) const {}
152 void WebLayerTreeViewImplForTesting::Layout() {
155 void WebLayerTreeViewImplForTesting::ApplyScrollAndScale(
156 gfx::Vector2d scroll_delta
,
159 scoped_ptr
<cc::OutputSurface
>
160 WebLayerTreeViewImplForTesting::CreateOutputSurface(bool fallback
) {
161 return make_scoped_ptr(
162 new cc::OutputSurface(cc::TestContextProvider::Create()));
165 scoped_refptr
<cc::ContextProvider
>
166 WebLayerTreeViewImplForTesting::OffscreenContextProvider() {
167 // Unit tests only run in single threaded mode.
168 return webkit::gpu::TestContextProviderFactory::GetInstance()->
169 OffscreenContextProviderForMainThread();
172 } // namespace webkit