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

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

Issue 2383373002: Reduce SurfaceIdAllocator usage and tie SurfaceFactory to a single FrameSinkId (Closed)
Patch Set: Rebased Created 4 years, 2 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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 24 matching lines...) Expand all
35 #include "gpu/ipc/common/gpu_messages.h" 35 #include "gpu/ipc/common/gpu_messages.h"
36 #include "third_party/WebKit/public/web/WebInputEvent.h" 36 #include "third_party/WebKit/public/web/WebInputEvent.h"
37 #include "ui/gfx/geometry/size_conversions.h" 37 #include "ui/gfx/geometry/size_conversions.h"
38 #include "ui/gfx/geometry/size_f.h" 38 #include "ui/gfx/geometry/size_f.h"
39 39
40 namespace content { 40 namespace content {
41 41
42 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( 42 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame(
43 RenderWidgetHost* widget_host) 43 RenderWidgetHost* widget_host)
44 : host_(RenderWidgetHostImpl::From(widget_host)), 44 : host_(RenderWidgetHostImpl::From(widget_host)),
45 frame_sink_id_(AllocateFrameSinkId()),
45 next_surface_sequence_(1u), 46 next_surface_sequence_(1u),
46 last_compositor_frame_sink_id_(0), 47 last_compositor_frame_sink_id_(0),
47 current_surface_scale_factor_(1.f), 48 current_surface_scale_factor_(1.f),
48 ack_pending_count_(0), 49 ack_pending_count_(0),
49 frame_connector_(nullptr), 50 frame_connector_(nullptr),
50 begin_frame_source_(nullptr), 51 begin_frame_source_(nullptr),
51 weak_factory_(this) { 52 weak_factory_(this) {
52 id_allocator_.reset(new cc::SurfaceIdAllocator(AllocateFrameSinkId())); 53 id_allocator_.reset(new cc::SurfaceIdAllocator(frame_sink_id_));
53 GetSurfaceManager()->RegisterFrameSinkId(id_allocator_->frame_sink_id()); 54 GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
54 RegisterSurfaceNamespaceId(); 55 RegisterFrameSinkId();
55 56
56 host_->SetView(this); 57 host_->SetView(this);
57 GetTextInputManager(); 58 GetTextInputManager();
58 } 59 }
59 60
60 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { 61 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() {
61 if (!surface_id_.is_null()) 62 if (!surface_id_.is_null())
62 surface_factory_->Destroy(surface_id_); 63 surface_factory_->Destroy(surface_id_);
63 64
64 if (GetSurfaceManager()) 65 if (GetSurfaceManager())
65 GetSurfaceManager()->InvalidateFrameSinkId(id_allocator_->frame_sink_id()); 66 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
66 } 67 }
67 68
68 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( 69 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector(
69 CrossProcessFrameConnector* frame_connector) { 70 CrossProcessFrameConnector* frame_connector) {
70 if (frame_connector_ == frame_connector) 71 if (frame_connector_ == frame_connector)
71 return; 72 return;
72 73
73 if (frame_connector_) { 74 if (frame_connector_) {
74 if (!parent_frame_sink_id_.is_null()) { 75 if (!parent_frame_sink_id_.is_null()) {
75 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, 76 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_,
76 GetFrameSinkId()); 77 frame_sink_id_);
77 } 78 }
78 // Unregister the client here, as it is not guaranteed in tests that the 79 // Unregister the client here, as it is not guaranteed in tests that the
79 // destructor will be called. 80 // destructor will be called.
80 GetSurfaceManager()->UnregisterSurfaceFactoryClient( 81 GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_);
81 id_allocator_->frame_sink_id());
82 82
83 parent_frame_sink_id_ = cc::FrameSinkId(); 83 parent_frame_sink_id_ = cc::FrameSinkId();
84 84
85 // After the RenderWidgetHostViewChildFrame loses the frame_connector, it 85 // After the RenderWidgetHostViewChildFrame loses the frame_connector, it
86 // won't be able to walk up the frame tree anymore. Clean up anything that 86 // won't be able to walk up the frame tree anymore. Clean up anything that
87 // needs to be done through the CrossProcessFrameConnector before it's gone. 87 // needs to be done through the CrossProcessFrameConnector before it's gone.
88 88
89 // Unlocks the mouse if this RenderWidgetHostView holds the lock. 89 // Unlocks the mouse if this RenderWidgetHostView holds the lock.
90 UnlockMouse(); 90 UnlockMouse();
91 } 91 }
92 frame_connector_ = frame_connector; 92 frame_connector_ = frame_connector;
93 if (frame_connector_) { 93 if (frame_connector_) {
94 GetSurfaceManager()->RegisterSurfaceFactoryClient( 94 GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, this);
95 id_allocator_->frame_sink_id(), this);
96 RenderWidgetHostViewBase* parent_view = 95 RenderWidgetHostViewBase* parent_view =
97 frame_connector_->GetParentRenderWidgetHostView(); 96 frame_connector_->GetParentRenderWidgetHostView();
98 if (parent_view) { 97 if (parent_view) {
99 parent_frame_sink_id_ = parent_view->GetFrameSinkId(); 98 parent_frame_sink_id_ = parent_view->GetFrameSinkId();
100 DCHECK(!parent_frame_sink_id_.is_null()); 99 DCHECK(!parent_frame_sink_id_.is_null());
101 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, 100 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_,
102 GetFrameSinkId()); 101 frame_sink_id_);
103 } 102 }
104 } 103 }
105 } 104 }
106 105
107 void RenderWidgetHostViewChildFrame::InitAsChild( 106 void RenderWidgetHostViewChildFrame::InitAsChild(
108 gfx::NativeView parent_view) { 107 gfx::NativeView parent_view) {
109 NOTREACHED(); 108 NOTREACHED();
110 } 109 }
111 110
112 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { 111 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 void RenderWidgetHostViewChildFrame::UnlockCompositingSurface() { 297 void RenderWidgetHostViewChildFrame::UnlockCompositingSurface() {
299 NOTIMPLEMENTED(); 298 NOTIMPLEMENTED();
300 } 299 }
301 300
302 RenderWidgetHostViewBase* RenderWidgetHostViewChildFrame::GetParentView() { 301 RenderWidgetHostViewBase* RenderWidgetHostViewChildFrame::GetParentView() {
303 if (!frame_connector_) 302 if (!frame_connector_)
304 return nullptr; 303 return nullptr;
305 return frame_connector_->GetParentRenderWidgetHostView(); 304 return frame_connector_->GetParentRenderWidgetHostView();
306 } 305 }
307 306
308 void RenderWidgetHostViewChildFrame::RegisterSurfaceNamespaceId() { 307 void RenderWidgetHostViewChildFrame::RegisterFrameSinkId() {
309 // If Destroy() has been called before we get here, host_ may be null. 308 // If Destroy() has been called before we get here, host_ may be null.
310 if (host_ && host_->delegate() && host_->delegate()->GetInputEventRouter()) { 309 if (host_ && host_->delegate() && host_->delegate()->GetInputEventRouter()) {
311 RenderWidgetHostInputEventRouter* router = 310 RenderWidgetHostInputEventRouter* router =
312 host_->delegate()->GetInputEventRouter(); 311 host_->delegate()->GetInputEventRouter();
313 if (!router->is_registered(GetFrameSinkId())) 312 if (!router->is_registered(frame_sink_id_))
314 router->AddFrameSinkIdOwner(GetFrameSinkId(), this); 313 router->AddFrameSinkIdOwner(frame_sink_id_, this);
315 } 314 }
316 } 315 }
317 316
318 void RenderWidgetHostViewChildFrame::UnregisterSurfaceNamespaceId() { 317 void RenderWidgetHostViewChildFrame::UnregisterFrameSinkId() {
319 DCHECK(host_); 318 DCHECK(host_);
320 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { 319 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) {
321 host_->delegate()->GetInputEventRouter()->RemoveFrameSinkIdOwner( 320 host_->delegate()->GetInputEventRouter()->RemoveFrameSinkIdOwner(
322 GetFrameSinkId()); 321 frame_sink_id_);
323 } 322 }
324 } 323 }
325 324
326 void RenderWidgetHostViewChildFrame::GestureEventAck( 325 void RenderWidgetHostViewChildFrame::GestureEventAck(
327 const blink::WebGestureEvent& event, 326 const blink::WebGestureEvent& event,
328 InputEventAckState ack_result) { 327 InputEventAckState ack_result) {
329 bool not_consumed = ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED || 328 bool not_consumed = ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED ||
330 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 329 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
331 // GestureScrollBegin is consumed by the target frame and not forwarded, 330 // GestureScrollBegin is consumed by the target frame and not forwarded,
332 // because we don't know whether we will need to bubble scroll until we 331 // because we don't know whether we will need to bubble scroll until we
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 frame_size != current_surface_size_ || 381 frame_size != current_surface_size_ ||
383 scale_factor != current_surface_scale_factor_) { 382 scale_factor != current_surface_scale_factor_) {
384 ClearCompositorSurfaceIfNecessary(); 383 ClearCompositorSurfaceIfNecessary();
385 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 384 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
386 current_surface_size_ = frame_size; 385 current_surface_size_ = frame_size;
387 current_surface_scale_factor_ = scale_factor; 386 current_surface_scale_factor_ = scale_factor;
388 } 387 }
389 388
390 if (!surface_factory_) { 389 if (!surface_factory_) {
391 cc::SurfaceManager* manager = GetSurfaceManager(); 390 cc::SurfaceManager* manager = GetSurfaceManager();
392 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this); 391 surface_factory_ =
392 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this);
393 } 393 }
394 394
395 if (surface_id_.is_null()) { 395 if (surface_id_.is_null()) {
396 surface_id_ = id_allocator_->GenerateId(); 396 surface_id_ = id_allocator_->GenerateId();
397 surface_factory_->Create(surface_id_); 397 surface_factory_->Create(surface_id_);
398 398
399 cc::SurfaceSequence sequence = cc::SurfaceSequence( 399 cc::SurfaceSequence sequence =
400 id_allocator_->frame_sink_id(), next_surface_sequence_++); 400 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++);
401 // The renderer process will satisfy this dependency when it creates a 401 // The renderer process will satisfy this dependency when it creates a
402 // SurfaceLayer. 402 // SurfaceLayer.
403 cc::SurfaceManager* manager = GetSurfaceManager(); 403 cc::SurfaceManager* manager = GetSurfaceManager();
404 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); 404 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence);
405 frame_connector_->SetChildFrameSurface(surface_id_, frame_size, 405 frame_connector_->SetChildFrameSurface(surface_id_, frame_size,
406 scale_factor, sequence); 406 scale_factor, sequence);
407 } 407 }
408 408
409 cc::SurfaceFactory::DrawCallback ack_callback = 409 cc::SurfaceFactory::DrawCallback ack_callback =
410 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), 410 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 462 }
463 463
464 bool RenderWidgetHostViewChildFrame::IsMouseLocked() { 464 bool RenderWidgetHostViewChildFrame::IsMouseLocked() {
465 if (!host_->delegate()) 465 if (!host_->delegate())
466 return false; 466 return false;
467 467
468 return host_->delegate()->HasMouseLock(host_); 468 return host_->delegate()->HasMouseLock(host_);
469 } 469 }
470 470
471 cc::FrameSinkId RenderWidgetHostViewChildFrame::GetFrameSinkId() { 471 cc::FrameSinkId RenderWidgetHostViewChildFrame::GetFrameSinkId() {
472 return id_allocator_->frame_sink_id(); 472 return frame_sink_id_;
473 } 473 }
474 474
475 void RenderWidgetHostViewChildFrame::ProcessKeyboardEvent( 475 void RenderWidgetHostViewChildFrame::ProcessKeyboardEvent(
476 const NativeWebKeyboardEvent& event) { 476 const NativeWebKeyboardEvent& event) {
477 host_->ForwardKeyboardEvent(event); 477 host_->ForwardKeyboardEvent(event);
478 } 478 }
479 479
480 void RenderWidgetHostViewChildFrame::ProcessMouseEvent( 480 void RenderWidgetHostViewChildFrame::ProcessMouseEvent(
481 const blink::WebMouseEvent& event, 481 const blink::WebMouseEvent& event,
482 const ui::LatencyInfo& latency) { 482 const ui::LatencyInfo& latency) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 713
714 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { 714 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const {
715 return true; 715 return true;
716 } 716 }
717 717
718 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { 718 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const {
719 return surface_id_; 719 return surface_id_;
720 }; 720 };
721 721
722 } // namespace content 722 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698