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

Side by Side Diff: content/browser/frame_host/render_widget_host_view_child_frame.cc

Issue 1094113003: Allow out-of-process iframes to render to compositing surfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed one Created 5 years, 6 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/frame_host/render_widget_host_view_child_frame.h" 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
6 6
7 #include "cc/surfaces/surface.h"
8 #include "cc/surfaces/surface_factory.h"
9 #include "cc/surfaces/surface_manager.h"
10 #include "cc/surfaces/surface_sequence.h"
7 #include "content/browser/accessibility/browser_accessibility_manager.h" 11 #include "content/browser/accessibility/browser_accessibility_manager.h"
8 #include "content/browser/frame_host/cross_process_frame_connector.h" 12 #include "content/browser/frame_host/cross_process_frame_connector.h"
13 #include "content/browser/gpu/compositor_util.h"
9 #include "content/browser/renderer_host/render_widget_host_impl.h" 14 #include "content/browser/renderer_host/render_widget_host_impl.h"
10 #include "content/common/gpu/gpu_messages.h" 15 #include "content/common/gpu/gpu_messages.h"
11 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
12 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
13 18
14 namespace content { 19 namespace content {
15 20
16 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( 21 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame(
17 RenderWidgetHost* widget_host) 22 RenderWidgetHost* widget_host)
18 : host_(RenderWidgetHostImpl::From(widget_host)), 23 : host_(RenderWidgetHostImpl::From(widget_host)),
19 frame_connector_(NULL) { 24 use_surfaces_(UseSurfacesEnabled()),
25 next_surface_sequence_(1u),
26 last_output_surface_id_(0),
27 current_surface_scale_factor_(1.f),
28 ack_pending_count_(0),
29 frame_connector_(NULL),
30 weak_factory_(this) {
31 #if !defined(OS_ANDROID)
32 if (use_surfaces_) {
33 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
34 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator();
35 }
36 #endif // !defined(OS_ANDROID)
37
20 host_->SetView(this); 38 host_->SetView(this);
21 } 39 }
22 40
23 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { 41 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() {
42 if (!surface_id_.is_null())
43 surface_factory_->Destroy(surface_id_);
24 } 44 }
25 45
26 void RenderWidgetHostViewChildFrame::InitAsChild( 46 void RenderWidgetHostViewChildFrame::InitAsChild(
27 gfx::NativeView parent_view) { 47 gfx::NativeView parent_view) {
28 NOTREACHED(); 48 NOTREACHED();
29 } 49 }
30 50
31 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { 51 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const {
32 return host_; 52 return host_;
33 } 53 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 199 }
180 200
181 #if defined(OS_ANDROID) 201 #if defined(OS_ANDROID)
182 void RenderWidgetHostViewChildFrame::LockCompositingSurface() { 202 void RenderWidgetHostViewChildFrame::LockCompositingSurface() {
183 } 203 }
184 204
185 void RenderWidgetHostViewChildFrame::UnlockCompositingSurface() { 205 void RenderWidgetHostViewChildFrame::UnlockCompositingSurface() {
186 } 206 }
187 #endif 207 #endif
188 208
209 void RenderWidgetHostViewChildFrame::SurfaceDrawn(uint32 output_surface_id,
210 cc::SurfaceDrawStatus drawn) {
211 cc::CompositorFrameAck ack;
212 DCHECK(ack_pending_count_ > 0);
213 if (!surface_returned_resources_.empty())
214 ack.resources.swap(surface_returned_resources_);
215 if (host_) {
216 host_->Send(new ViewMsg_SwapCompositorFrameAck(host_->GetRoutingID(),
217 output_surface_id, ack));
218 }
219 ack_pending_count_--;
220 }
221
189 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( 222 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame(
190 uint32 output_surface_id, 223 uint32 output_surface_id,
191 scoped_ptr<cc::CompositorFrame> frame) { 224 scoped_ptr<cc::CompositorFrame> frame) {
192 last_scroll_offset_ = frame->metadata.root_scroll_offset; 225 last_scroll_offset_ = frame->metadata.root_scroll_offset;
193 if (frame_connector_) { 226
227 if (!frame_connector_)
228 return;
229
230 // When not using surfaces, the frame just gets proxied to
231 // the embedder's renderer to be composited.
232 if (!frame->delegated_frame_data || !use_surfaces_) {
194 frame_connector_->ChildFrameCompositorFrameSwapped( 233 frame_connector_->ChildFrameCompositorFrameSwapped(
195 output_surface_id, 234 output_surface_id,
196 host_->GetProcess()->GetID(), 235 host_->GetProcess()->GetID(),
197 host_->GetRoutingID(), 236 host_->GetRoutingID(),
198 frame.Pass()); 237 frame.Pass());
238 return;
199 } 239 }
240
241 #if !defined(OS_ANDROID)
242 cc::RenderPass* root_pass =
243 frame->delegated_frame_data->render_pass_list.back();
244
245 gfx::Size frame_size = root_pass->output_rect.size();
246 float scale_factor = frame->metadata.device_scale_factor;
247
248 // Check whether we need to recreate the cc::Surface, which means the child
249 // frame renderer has changed its output surface, or size, or scale factor.
250 if (output_surface_id != last_output_surface_id_ && surface_factory_) {
251 surface_factory_->Destroy(surface_id_);
252 surface_factory_.reset();
253 }
254 if (output_surface_id != last_output_surface_id_ ||
255 frame_size != current_surface_size_ ||
256 scale_factor != current_surface_scale_factor_) {
257 if (surface_factory_ && !surface_id_.is_null())
258 surface_factory_->Destroy(surface_id_);
259 surface_id_ = cc::SurfaceId();
260 last_output_surface_id_ = output_surface_id;
261 current_surface_size_ = frame_size;
262 current_surface_scale_factor_ = scale_factor;
263 }
264
265 if (!surface_factory_) {
266 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
267 cc::SurfaceManager* manager = factory->GetSurfaceManager();
268 surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this));
269 }
270
271 if (surface_id_.is_null()) {
272 surface_id_ = id_allocator_->GenerateId();
273 surface_factory_->Create(surface_id_);
274
275 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
276 cc::SurfaceSequence sequence = cc::SurfaceSequence(
277 id_allocator_->id_namespace(), next_surface_sequence_++);
278 // The renderer process will satisfy this dependency when it creates a
279 // SurfaceLayer.
280 factory->GetSurfaceManager()
281 ->GetSurfaceForId(surface_id_)
282 ->AddDestructionDependency(sequence);
283 frame_connector_->SetChildFrameSurface(surface_id_, frame_size,
284 scale_factor, sequence);
285 }
286
287 cc::SurfaceFactory::DrawCallback ack_callback =
288 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(),
289 output_surface_id);
290 ack_pending_count_++;
291 // If this value grows very large, something is going wrong.
292 DCHECK(ack_pending_count_ < 1000);
293 surface_factory_->SubmitFrame(surface_id_, frame.Pass(), ack_callback);
294 #endif // !defined(OS_ANDROID)
200 } 295 }
201 296
202 void RenderWidgetHostViewChildFrame::GetScreenInfo( 297 void RenderWidgetHostViewChildFrame::GetScreenInfo(
203 blink::WebScreenInfo* results) { 298 blink::WebScreenInfo* results) {
204 } 299 }
205 300
206 gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() { 301 gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() {
207 // We do not have any root window specific parts in this view. 302 // We do not have any root window specific parts in this view.
208 return GetViewBounds(); 303 return GetViewBounds();
209 } 304 }
210 305
211 #if defined(USE_AURA) 306 #if defined(USE_AURA)
212 void RenderWidgetHostViewChildFrame::ProcessAckedTouchEvent( 307 void RenderWidgetHostViewChildFrame::ProcessAckedTouchEvent(
213 const TouchEventWithLatencyInfo& touch, 308 const TouchEventWithLatencyInfo& touch,
214 InputEventAckState ack_result) { 309 InputEventAckState ack_result) {
215 } 310 }
216 #endif // defined(USE_AURA) 311 #endif // defined(USE_AURA)
217 312
218 bool RenderWidgetHostViewChildFrame::LockMouse() { 313 bool RenderWidgetHostViewChildFrame::LockMouse() {
219 return false; 314 return false;
220 } 315 }
221 316
222 void RenderWidgetHostViewChildFrame::UnlockMouse() { 317 void RenderWidgetHostViewChildFrame::UnlockMouse() {
223 } 318 }
224 319
225 uint32_t RenderWidgetHostViewChildFrame::GetSurfaceIdNamespace() { 320 uint32_t RenderWidgetHostViewChildFrame::GetSurfaceIdNamespace() {
226 // TODO(kenrb): Create SurfaceFactory here when RWHVChildFrame 321 if (!use_surfaces_)
227 // gets compositor surface support. 322 return 0;
228 return 0; 323
324 return id_allocator_->id_namespace();
229 } 325 }
230 326
231 #if defined(OS_MACOSX) 327 #if defined(OS_MACOSX)
232 void RenderWidgetHostViewChildFrame::SetActive(bool active) { 328 void RenderWidgetHostViewChildFrame::SetActive(bool active) {
233 } 329 }
234 330
235 void RenderWidgetHostViewChildFrame::SetWindowVisibility(bool visible) { 331 void RenderWidgetHostViewChildFrame::SetWindowVisibility(bool visible) {
236 } 332 }
237 333
238 void RenderWidgetHostViewChildFrame::WindowFrameChanged() { 334 void RenderWidgetHostViewChildFrame::WindowFrameChanged() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 void RenderWidgetHostViewChildFrame::SetParentNativeViewAccessible( 390 void RenderWidgetHostViewChildFrame::SetParentNativeViewAccessible(
295 gfx::NativeViewAccessible accessible_parent) { 391 gfx::NativeViewAccessible accessible_parent) {
296 } 392 }
297 393
298 gfx::NativeViewId RenderWidgetHostViewChildFrame::GetParentForWindowlessPlugin() 394 gfx::NativeViewId RenderWidgetHostViewChildFrame::GetParentForWindowlessPlugin()
299 const { 395 const {
300 return NULL; 396 return NULL;
301 } 397 }
302 #endif // defined(OS_WIN) 398 #endif // defined(OS_WIN)
303 399
400 // cc::SurfaceFactoryClient implementation.
401 void RenderWidgetHostViewChildFrame::ReturnResources(
402 const cc::ReturnedResourceArray& resources) {
403 if (resources.empty())
404 return;
405
406 if (!ack_pending_count_ && host_) {
407 cc::CompositorFrameAck ack;
408 std::copy(resources.begin(), resources.end(),
409 std::back_inserter(ack.resources));
410 host_->Send(new ViewMsg_ReclaimCompositorResources(
411 host_->GetRoutingID(), last_output_surface_id_, ack));
412 return;
413 }
414
415 std::copy(resources.begin(), resources.end(),
416 std::back_inserter(surface_returned_resources_));
417 }
418
304 BrowserAccessibilityManager* 419 BrowserAccessibilityManager*
305 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( 420 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager(
306 BrowserAccessibilityDelegate* delegate) { 421 BrowserAccessibilityDelegate* delegate) {
307 return BrowserAccessibilityManager::Create( 422 return BrowserAccessibilityManager::Create(
308 BrowserAccessibilityManager::GetEmptyDocument(), delegate); 423 BrowserAccessibilityManager::GetEmptyDocument(), delegate);
309 } 424 }
310 425
311 } // namespace content 426 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698