Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: webkit/compositor_bindings/web_layer_tree_view_impl.cc

Issue 11575049: Make RenderWidget responsible for the composited view's lifetime (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make cc::LayerTreeHost getter chromium-style Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web_layer_tree_view_impl.h" 5 #include "webkit/compositor_bindings/web_layer_tree_view_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "cc/font_atlas.h" 8 #include "cc/font_atlas.h"
9 #include "cc/input_handler.h" 9 #include "cc/input_handler.h"
10 #include "cc/layer.h" 10 #include "cc/layer.h"
11 #include "cc/layer_tree_host.h" 11 #include "cc/layer_tree_host.h"
12 #include "cc/switches.h" 12 #include "cc/switches.h"
13 #include "cc/thread.h" 13 #include "cc/thread.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebInputHandler.h" 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebInputHandler.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli ent.h" 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli ent.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h " 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h "
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
21 #include "web_layer_impl.h" 21 #include "webkit/compositor_bindings/web_layer_impl.h"
22 #include "web_to_ccinput_handler_adapter.h"
23 #include "webkit/compositor_bindings/web_rendering_stats_impl.h" 22 #include "webkit/compositor_bindings/web_rendering_stats_impl.h"
24 23 #include "webkit/compositor_bindings/web_to_ccinput_handler_adapter.h"
25 using namespace cc; 24
26 25
27 namespace WebKit { 26 namespace WebKit {
28 27
29 WebLayerTreeViewImpl::WebLayerTreeViewImpl(WebLayerTreeViewClient* client) 28 WebLayerTreeViewImpl::WebLayerTreeViewImpl(WebLayerTreeViewClient* client)
30 : m_client(client) 29 : client_(client) {
31 { 30 }
32 } 31
33 32 WebLayerTreeViewImpl::~WebLayerTreeViewImpl() {
34 WebLayerTreeViewImpl::~WebLayerTreeViewImpl() 33 }
35 { 34
36 } 35 bool WebLayerTreeViewImpl::initialize(
37 36 const WebLayerTreeView::Settings& web_settings,
38 bool WebLayerTreeViewImpl::initialize(const WebLayerTreeView::Settings& webSetti ngs, scoped_ptr<Thread> implThread) 37 scoped_ptr<cc::Thread> impl_thread) {
39 { 38 cc::LayerTreeSettings settings;
40 LayerTreeSettings settings; 39 settings.acceleratePainting = web_settings.acceleratePainting;
41 settings.acceleratePainting = webSettings.acceleratePainting; 40 settings.renderVSyncEnabled = web_settings.renderVSyncEnabled;
42 settings.renderVSyncEnabled = webSettings.renderVSyncEnabled; 41 settings.perTilePaintingEnabled = web_settings.perTilePaintingEnabled;
43 settings.perTilePaintingEnabled = webSettings.perTilePaintingEnabled; 42 settings.acceleratedAnimationEnabled =
44 settings.acceleratedAnimationEnabled = webSettings.acceleratedAnimationEnabl ed; 43 web_settings.acceleratedAnimationEnabled;
45 settings.pageScalePinchZoomEnabled = webSettings.pageScalePinchZoomEnabled; 44 settings.pageScalePinchZoomEnabled = web_settings.pageScalePinchZoomEnabled;
46 settings.refreshRate = webSettings.refreshRate; 45 settings.refreshRate = web_settings.refreshRate;
47 settings.defaultTileSize = webSettings.defaultTileSize; 46 settings.defaultTileSize = web_settings.defaultTileSize;
48 settings.maxUntiledLayerSize = webSettings.maxUntiledLayerSize; 47 settings.maxUntiledLayerSize = web_settings.maxUntiledLayerSize;
49 settings.initialDebugState.showFPSCounter = webSettings.showFPSCounter; 48 settings.initialDebugState.showFPSCounter = web_settings.showFPSCounter;
50 settings.initialDebugState.showPaintRects = webSettings.showPaintRects; 49 settings.initialDebugState.showPaintRects = web_settings.showPaintRects;
51 settings.initialDebugState.showPlatformLayerTree = webSettings.showPlatformL ayerTree; 50 settings.initialDebugState.showPlatformLayerTree =
52 settings.initialDebugState.showDebugBorders = webSettings.showDebugBorders; 51 web_settings.showPlatformLayerTree;
53 m_layerTreeHost = LayerTreeHost::create(this, settings, implThread.Pass()); 52 settings.initialDebugState.showDebugBorders = web_settings.showDebugBorders;
54 if (!m_layerTreeHost.get()) 53 layer_tree_host_ = cc::LayerTreeHost::create(this,
55 return false; 54 settings,
56 return true; 55 impl_thread.Pass());
57 } 56 if (!layer_tree_host_)
58 57 return false;
59 void WebLayerTreeViewImpl::setSurfaceReady() 58 return true;
60 { 59 }
61 m_layerTreeHost->setSurfaceReady(); 60
62 } 61 cc::LayerTreeHost* WebLayerTreeViewImpl::layer_tree_host() const {
63 62 return layer_tree_host_.get();
64 void WebLayerTreeViewImpl::setRootLayer(const WebLayer& root) 63 }
65 { 64
66 m_layerTreeHost->setRootLayer(static_cast<const WebLayerImpl*>(&root)->layer ()); 65 void WebLayerTreeViewImpl::setSurfaceReady() {
67 } 66 layer_tree_host_->setSurfaceReady();
68 67 }
69 void WebLayerTreeViewImpl::clearRootLayer() 68
70 { 69 void WebLayerTreeViewImpl::setRootLayer(const WebLayer& root) {
71 m_layerTreeHost->setRootLayer(scoped_refptr<Layer>()); 70 layer_tree_host_->setRootLayer(
72 } 71 static_cast<const WebLayerImpl*>(&root)->layer());
73 72 }
74 void WebLayerTreeViewImpl::setViewportSize(const WebSize& layoutViewportSize, co nst WebSize& deviceViewportSize) 73
75 { 74 void WebLayerTreeViewImpl::clearRootLayer() {
76 if (!deviceViewportSize.isEmpty()) 75 layer_tree_host_->setRootLayer(scoped_refptr<cc::Layer>());
77 m_layerTreeHost->setViewportSize(layoutViewportSize, deviceViewportSize) ; 76 }
78 else 77
79 m_layerTreeHost->setViewportSize(layoutViewportSize, layoutViewportSize) ; 78 void WebLayerTreeViewImpl::setViewportSize(
80 } 79 const WebSize& layout_viewport_size, const WebSize& device_viewport_size) {
81 80 if (!device_viewport_size.isEmpty()) {
82 WebSize WebLayerTreeViewImpl::layoutViewportSize() const 81 layer_tree_host_->setViewportSize(layout_viewport_size,
83 { 82 device_viewport_size);
84 return m_layerTreeHost->layoutViewportSize(); 83 } else {
85 } 84 layer_tree_host_->setViewportSize(layout_viewport_size,
86 85 layout_viewport_size);
87 WebSize WebLayerTreeViewImpl::deviceViewportSize() const 86 }
88 { 87 }
89 return m_layerTreeHost->deviceViewportSize(); 88
90 } 89 WebSize WebLayerTreeViewImpl::layoutViewportSize() const {
91 90 return layer_tree_host_->layoutViewportSize();
92 WebFloatPoint WebLayerTreeViewImpl::adjustEventPointForPinchZoom(const WebFloatP oint& point) const 91 }
93 { 92
94 return m_layerTreeHost->adjustEventPointForPinchZoom(point); 93 WebSize WebLayerTreeViewImpl::deviceViewportSize() const {
95 } 94 return layer_tree_host_->deviceViewportSize();
96 95 }
97 void WebLayerTreeViewImpl::setDeviceScaleFactor(const float deviceScaleFactor) 96
98 { 97 WebFloatPoint WebLayerTreeViewImpl::adjustEventPointForPinchZoom(
99 m_layerTreeHost->setDeviceScaleFactor(deviceScaleFactor); 98 const WebFloatPoint& point) const {
100 } 99 return layer_tree_host_->adjustEventPointForPinchZoom(point);
101 100 }
102 float WebLayerTreeViewImpl::deviceScaleFactor() const 101
103 { 102 void WebLayerTreeViewImpl::setDeviceScaleFactor(float device_scale_factor) {
104 return m_layerTreeHost->deviceScaleFactor(); 103 layer_tree_host_->setDeviceScaleFactor(device_scale_factor);
105 } 104 }
106 105
107 void WebLayerTreeViewImpl::setBackgroundColor(WebColor color) 106 float WebLayerTreeViewImpl::deviceScaleFactor() const {
108 { 107 return layer_tree_host_->deviceScaleFactor();
109 m_layerTreeHost->setBackgroundColor(color); 108 }
110 } 109
111 110 void WebLayerTreeViewImpl::setBackgroundColor(WebColor color) {
112 void WebLayerTreeViewImpl::setHasTransparentBackground(bool transparent) 111 layer_tree_host_->setBackgroundColor(color);
113 { 112 }
114 m_layerTreeHost->setHasTransparentBackground(transparent); 113
115 } 114 void WebLayerTreeViewImpl::setHasTransparentBackground(bool transparent) {
116 115 layer_tree_host_->setHasTransparentBackground(transparent);
117 void WebLayerTreeViewImpl::setVisible(bool visible) 116 }
118 { 117
119 m_layerTreeHost->setVisible(visible); 118 void WebLayerTreeViewImpl::setVisible(bool visible) {
120 } 119 layer_tree_host_->setVisible(visible);
121 120 }
122 void WebLayerTreeViewImpl::setPageScaleFactorAndLimits(float pageScaleFactor, fl oat minimum, float maximum) 121
123 { 122 void WebLayerTreeViewImpl::setPageScaleFactorAndLimits(float page_scale_factor,
124 m_layerTreeHost->setPageScaleFactorAndLimits(pageScaleFactor, minimum, maxim um); 123 float minimum,
125 } 124 float maximum) {
126 125 layer_tree_host_->setPageScaleFactorAndLimits(page_scale_factor,
127 void WebLayerTreeViewImpl::startPageScaleAnimation(const WebPoint& scroll, bool useAnchor, float newPageScale, double durationSec) 126 minimum, maximum);
128 { 127 }
129 base::TimeDelta duration = base::TimeDelta::FromMicroseconds(durationSec * b ase::Time::kMicrosecondsPerSecond); 128
130 m_layerTreeHost->startPageScaleAnimation(gfx::Vector2d(scroll.x, scroll.y), useAnchor, newPageScale, duration); 129 void WebLayerTreeViewImpl::startPageScaleAnimation(const WebPoint& scroll,
131 } 130 bool use_anchor,
132 131 float new_page_scale,
133 void WebLayerTreeViewImpl::setNeedsAnimate() 132 double duration_sec) {
134 { 133 int64 duration_us = duration_sec * base::Time::kMicrosecondsPerSecond;
135 m_layerTreeHost->setNeedsAnimate(); 134 base::TimeDelta duration = base::TimeDelta::FromMicroseconds(duration_us);
136 } 135 layer_tree_host_->startPageScaleAnimation(gfx::Vector2d(scroll.x, scroll.y),
137 136 use_anchor,
138 void WebLayerTreeViewImpl::setNeedsRedraw() 137 new_page_scale,
139 { 138 duration);
140 m_layerTreeHost->setNeedsRedraw(); 139 }
141 } 140
142 141 void WebLayerTreeViewImpl::setNeedsAnimate() {
143 bool WebLayerTreeViewImpl::commitRequested() const 142 layer_tree_host_->setNeedsAnimate();
144 { 143 }
145 return m_layerTreeHost->commitRequested(); 144
146 } 145 void WebLayerTreeViewImpl::setNeedsRedraw() {
147 146 layer_tree_host_->setNeedsRedraw();
148 void WebLayerTreeViewImpl::composite() 147 }
149 { 148
150 m_layerTreeHost->composite(); 149 bool WebLayerTreeViewImpl::commitRequested() const {
151 } 150 return layer_tree_host_->commitRequested();
152 151 }
153 void WebLayerTreeViewImpl::updateAnimations(double frameBeginTimeSeconds) 152
154 { 153 void WebLayerTreeViewImpl::composite() {
155 base::TimeTicks frameBeginTime = base::TimeTicks::FromInternalValue(frameBeg inTimeSeconds * base::Time::kMicrosecondsPerSecond); 154 layer_tree_host_->composite();
156 m_layerTreeHost->updateAnimations(frameBeginTime); 155 }
157 } 156
158 157 void WebLayerTreeViewImpl::updateAnimations(double frame_begin_time_seconds) {
159 bool WebLayerTreeViewImpl::compositeAndReadback(void *pixels, const WebRect& rec t) 158 int64 frame_begin_time_us =
160 { 159 frame_begin_time_seconds * base::Time::kMicrosecondsPerSecond;
161 return m_layerTreeHost->compositeAndReadback(pixels, rect); 160 base::TimeTicks frame_begin_time =
162 } 161 base::TimeTicks::FromInternalValue(frame_begin_time_us);
163 162 layer_tree_host_->updateAnimations(frame_begin_time);
164 void WebLayerTreeViewImpl::finishAllRendering() 163 }
165 { 164
166 m_layerTreeHost->finishAllRendering(); 165 bool WebLayerTreeViewImpl::compositeAndReadback(void* pixels,
167 } 166 const WebRect& rect) {
168 167 return layer_tree_host_->compositeAndReadback(pixels, rect);
169 void WebLayerTreeViewImpl::setDeferCommits(bool deferCommits) 168 }
170 { 169
171 m_layerTreeHost->setDeferCommits(deferCommits); 170 void WebLayerTreeViewImpl::finishAllRendering() {
172 } 171 layer_tree_host_->finishAllRendering();
173 172 }
174 void WebLayerTreeViewImpl::renderingStats(WebRenderingStats& stats) const 173
175 { 174 void WebLayerTreeViewImpl::setDeferCommits(bool defer_commits) {
176 m_layerTreeHost->renderingStats( 175 layer_tree_host_->setDeferCommits(defer_commits);
177 &static_cast<WebRenderingStatsImpl&>(stats).rendering_stats); 176 }
178 } 177
179 178 void WebLayerTreeViewImpl::renderingStats(WebRenderingStats& stats) const {
180 void WebLayerTreeViewImpl::setShowFPSCounter(bool show) 179 layer_tree_host_->renderingStats(
181 { 180 &static_cast<WebRenderingStatsImpl&>(stats).rendering_stats);
182 LayerTreeDebugState debugState = m_layerTreeHost->debugState(); 181 }
183 debugState.showFPSCounter = show; 182
184 m_layerTreeHost->setDebugState(debugState); 183 void WebLayerTreeViewImpl::setShowFPSCounter(bool show) {
185 } 184 cc::LayerTreeDebugState debug_state = layer_tree_host_->debugState();
186 185 debug_state.showFPSCounter = show;
187 void WebLayerTreeViewImpl::setShowPaintRects(bool show) 186 layer_tree_host_->setDebugState(debug_state);
188 { 187 }
189 LayerTreeDebugState debugState = m_layerTreeHost->debugState(); 188
190 debugState.showPaintRects = show; 189 void WebLayerTreeViewImpl::setShowPaintRects(bool show) {
191 m_layerTreeHost->setDebugState(debugState); 190 cc::LayerTreeDebugState debug_state = layer_tree_host_->debugState();
192 } 191 debug_state.showPaintRects = show;
193 192 layer_tree_host_->setDebugState(debug_state);
194 scoped_ptr<FontAtlas> WebLayerTreeViewImpl::createFontAtlas() 193 }
195 { 194
196 int fontHeight; 195 scoped_ptr<cc::FontAtlas> WebLayerTreeViewImpl::createFontAtlas() {
197 WebRect asciiToWebRectTable[128]; 196 int font_height;
198 gfx::Rect asciiToRectTable[128]; 197 WebRect ascii_to_web_rect_table[128];
199 SkBitmap bitmap; 198 gfx::Rect ascii_to_rect_table[128];
200 199 SkBitmap bitmap;
201 m_client->createFontAtlas(bitmap, asciiToWebRectTable, fontHeight); 200
202 201 client_->createFontAtlas(bitmap, ascii_to_web_rect_table, font_height);
203 for (int i = 0; i < 128; ++i) 202
204 asciiToRectTable[i] = asciiToWebRectTable[i]; 203 for (int i = 0; i < 128; ++i)
205 204 ascii_to_rect_table[i] = ascii_to_web_rect_table[i];
206 return FontAtlas::create(bitmap, asciiToRectTable, fontHeight).Pass(); 205
207 } 206 return cc::FontAtlas::create(bitmap, ascii_to_rect_table, font_height).Pass();
208 207 }
209 void WebLayerTreeViewImpl::loseCompositorContext(int numTimes) 208
210 { 209 void WebLayerTreeViewImpl::loseCompositorContext(int num_times) {
211 m_layerTreeHost->loseOutputSurface(numTimes); 210 layer_tree_host_->loseOutputSurface(num_times);
212 } 211 }
213 212
214 void WebLayerTreeViewImpl::willBeginFrame() 213 void WebLayerTreeViewImpl::willBeginFrame() {
215 { 214 client_->willBeginFrame();
216 m_client->willBeginFrame(); 215 }
217 } 216
218 217 void WebLayerTreeViewImpl::didBeginFrame() {
219 void WebLayerTreeViewImpl::didBeginFrame() 218 client_->didBeginFrame();
220 { 219 }
221 m_client->didBeginFrame(); 220
222 } 221 void WebLayerTreeViewImpl::animate(double monotonic_frame_begin_time) {
223 222 client_->updateAnimations(monotonic_frame_begin_time);
224 void WebLayerTreeViewImpl::animate(double monotonicFrameBeginTime) 223 }
225 { 224
226 m_client->updateAnimations(monotonicFrameBeginTime); 225 void WebLayerTreeViewImpl::layout() {
227 } 226 client_->layout();
228 227 }
229 void WebLayerTreeViewImpl::layout() 228
230 { 229 void WebLayerTreeViewImpl::applyScrollAndScale(gfx::Vector2d scroll_delta,
231 m_client->layout(); 230 float page_scale) {
232 } 231 client_->applyScrollAndScale(scroll_delta, page_scale);
233 232 }
234 void WebLayerTreeViewImpl::applyScrollAndScale(gfx::Vector2d scrollDelta, float pageScale) 233
235 { 234 scoped_ptr<cc::OutputSurface> WebLayerTreeViewImpl::createOutputSurface() {
236 m_client->applyScrollAndScale(scrollDelta, pageScale); 235 WebKit::WebCompositorOutputSurface* web = client_->createOutputSurface();
237 } 236 return make_scoped_ptr(static_cast<cc::OutputSurface*>(web));
238 237 }
239 scoped_ptr<cc::OutputSurface> WebLayerTreeViewImpl::createOutputSurface() 238
240 { 239 void WebLayerTreeViewImpl::didRecreateOutputSurface(bool success) {
241 WebKit::WebCompositorOutputSurface* web = m_client->createOutputSurface(); 240 client_->didRecreateOutputSurface(success);
242 return make_scoped_ptr(static_cast<cc::OutputSurface*>(web)); 241 }
243 } 242
244 243 scoped_ptr<cc::InputHandler> WebLayerTreeViewImpl::createInputHandler() {
245 void WebLayerTreeViewImpl::didRecreateOutputSurface(bool success) 244 scoped_ptr<cc::InputHandler> ret;
246 { 245 scoped_ptr<WebInputHandler> handler(client_->createInputHandler());
247 m_client->didRecreateOutputSurface(success); 246 if (handler)
248 } 247 ret = WebToCCInputHandlerAdapter::create(handler.Pass());
249 248 return ret.Pass();
250 scoped_ptr<InputHandler> WebLayerTreeViewImpl::createInputHandler() 249 }
251 { 250
252 scoped_ptr<InputHandler> ret; 251 void WebLayerTreeViewImpl::willCommit() {
253 scoped_ptr<WebInputHandler> handler(m_client->createInputHandler()); 252 client_->willCommit();
254 if (handler) 253 }
255 ret = WebToCCInputHandlerAdapter::create(handler.Pass()); 254
256 return ret.Pass(); 255 void WebLayerTreeViewImpl::didCommit() {
257 } 256 client_->didCommit();
258 257 }
259 void WebLayerTreeViewImpl::willCommit() 258
260 { 259 void WebLayerTreeViewImpl::didCommitAndDrawFrame() {
261 m_client->willCommit(); 260 client_->didCommitAndDrawFrame();
262 } 261 }
263 262
264 void WebLayerTreeViewImpl::didCommit() 263 void WebLayerTreeViewImpl::didCompleteSwapBuffers() {
265 { 264 client_->didCompleteSwapBuffers();
266 m_client->didCommit(); 265 }
267 } 266
268 267 void WebLayerTreeViewImpl::scheduleComposite() {
269 void WebLayerTreeViewImpl::didCommitAndDrawFrame() 268 client_->scheduleComposite();
270 { 269 }
271 m_client->didCommitAndDrawFrame(); 270
272 } 271 } // namespace WebKit
273
274 void WebLayerTreeViewImpl::didCompleteSwapBuffers()
275 {
276 m_client->didCompleteSwapBuffers();
277 }
278
279 void WebLayerTreeViewImpl::scheduleComposite()
280 {
281 m_client->scheduleComposite();
282 }
283
284 } // namespace WebKit
OLDNEW
« content/renderer/render_widget.cc ('K') | « webkit/compositor_bindings/web_layer_tree_view_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698