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_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"
26 using blink::WebColor;
27 using blink::WebGraphicsContext3D;
30 using webkit::WebLayerImpl;
34 WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
36 WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
38 void 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;
48 cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings);
49 DCHECK(layer_tree_host_);
52 void WebLayerTreeViewImplForTesting::setSurfaceReady() {
53 layer_tree_host_->SetLayerTreeHostClientReady();
56 void WebLayerTreeViewImplForTesting::setRootLayer(
57 const blink::WebLayer& root) {
58 layer_tree_host_->SetRootLayer(
59 static_cast<const WebLayerImpl*>(&root)->layer());
62 void WebLayerTreeViewImplForTesting::clearRootLayer() {
63 layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
66 void WebLayerTreeViewImplForTesting::setViewportSize(
67 const WebSize& unused_deprecated,
68 const WebSize& device_viewport_size) {
69 layer_tree_host_->SetViewportSize(device_viewport_size);
72 WebSize WebLayerTreeViewImplForTesting::layoutViewportSize() const {
73 return layer_tree_host_->device_viewport_size();
76 WebSize WebLayerTreeViewImplForTesting::deviceViewportSize() const {
77 return layer_tree_host_->device_viewport_size();
80 void WebLayerTreeViewImplForTesting::setDeviceScaleFactor(
81 float device_scale_factor) {
82 layer_tree_host_->SetDeviceScaleFactor(device_scale_factor);
85 float WebLayerTreeViewImplForTesting::deviceScaleFactor() const {
86 return layer_tree_host_->device_scale_factor();
89 void WebLayerTreeViewImplForTesting::setBackgroundColor(WebColor color) {
90 layer_tree_host_->set_background_color(color);
93 void WebLayerTreeViewImplForTesting::setHasTransparentBackground(
95 layer_tree_host_->set_has_transparent_background(transparent);
98 void WebLayerTreeViewImplForTesting::setVisible(bool visible) {
99 layer_tree_host_->SetVisible(visible);
102 void WebLayerTreeViewImplForTesting::setPageScaleFactorAndLimits(
103 float page_scale_factor,
106 layer_tree_host_->SetPageScaleFactorAndLimits(
107 page_scale_factor, minimum, maximum);
110 void WebLayerTreeViewImplForTesting::startPageScaleAnimation(
111 const blink::WebPoint& scroll,
113 float new_page_scale,
114 double duration_sec) {}
116 void WebLayerTreeViewImplForTesting::setNeedsAnimate() {
117 layer_tree_host_->SetNeedsAnimate();
120 bool WebLayerTreeViewImplForTesting::commitRequested() const {
121 return layer_tree_host_->CommitRequested();
124 void WebLayerTreeViewImplForTesting::didStopFlinging() {}
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);
132 void WebLayerTreeViewImplForTesting::finishAllRendering() {
133 layer_tree_host_->FinishAllRendering();
136 void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) {
137 layer_tree_host_->SetDeferCommits(defer_commits);
140 void WebLayerTreeViewImplForTesting::Layout() {
143 void WebLayerTreeViewImplForTesting::ApplyScrollAndScale(
144 const gfx::Vector2d& scroll_delta,
147 scoped_ptr<cc::OutputSurface>
148 WebLayerTreeViewImplForTesting::CreateOutputSurface(bool fallback) {
149 return make_scoped_ptr(
150 new cc::OutputSurface(cc::TestContextProvider::Create()));
153 scoped_refptr<cc::ContextProvider>
154 WebLayerTreeViewImplForTesting::OffscreenContextProvider() {
155 // Unit tests only run in single threaded mode.
156 return content::TestContextProviderFactory::GetInstance()->
157 OffscreenContextProviderForMainThread();
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
169 outerViewportScrollLayer
170 ? static_cast<const WebLayerImpl*>(outerViewportScrollLayer)->layer()
174 void WebLayerTreeViewImplForTesting::clearViewportLayers() {
175 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
176 scoped_refptr<cc::Layer>(),
177 scoped_refptr<cc::Layer>());
180 } // namespace content