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

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_impl.cc

Issue 619843002: cc: Make separate interface for BeginFrame ipc from OutputSurface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 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 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/android/in_process/synchronous_compositor_impl.h" 5 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
6 6
7 #include "base/auto_reset.h"
7 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "cc/input/input_handler.h" 10 #include "cc/input/input_handler.h"
11 #include "content/browser/android/in_process/synchronous_compositor_external_beg in_frame_source.h"
10 #include "content/browser/android/in_process/synchronous_compositor_factory_impl .h" 12 #include "content/browser/android/in_process/synchronous_compositor_factory_impl .h"
11 #include "content/browser/android/in_process/synchronous_input_event_filter.h" 13 #include "content/browser/android/in_process/synchronous_input_event_filter.h"
12 #include "content/browser/renderer_host/render_widget_host_view_android.h" 14 #include "content/browser/renderer_host/render_widget_host_view_android.h"
13 #include "content/common/input/did_overscroll_params.h" 15 #include "content/common/input/did_overscroll_params.h"
14 #include "content/public/browser/android/synchronous_compositor_client.h" 16 #include "content/public/browser/android/synchronous_compositor_client.h"
15 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
18 #include "ui/gl/gl_surface.h" 20 #include "ui/gl/gl_surface.h"
19 21
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 60 }
59 61
60 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( 62 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID(
61 int routing_id) { 63 int routing_id) {
62 return FromID(GetInProcessRendererId(), routing_id); 64 return FromID(GetInProcessRendererId(), routing_id);
63 } 65 }
64 66
65 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) 67 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents)
66 : compositor_client_(NULL), 68 : compositor_client_(NULL),
67 output_surface_(NULL), 69 output_surface_(NULL),
70 begin_frame_source_(nullptr),
68 contents_(contents), 71 contents_(contents),
69 input_handler_(NULL), 72 input_handler_(NULL),
73 invoking_composite_(false),
70 weak_ptr_factory_(this) { 74 weak_ptr_factory_(this) {
71 DCHECK(contents); 75 DCHECK(contents);
72 } 76 }
73 77
74 SynchronousCompositorImpl::~SynchronousCompositorImpl() { 78 SynchronousCompositorImpl::~SynchronousCompositorImpl() {
75 if (compositor_client_) 79 if (compositor_client_)
76 compositor_client_->DidDestroyCompositor(this); 80 compositor_client_->DidDestroyCompositor(this);
81 if (begin_frame_source_)
82 begin_frame_source_->SetCompositor(nullptr);
77 SetInputHandler(NULL); 83 SetInputHandler(NULL);
78 } 84 }
79 85
80 void SynchronousCompositorImpl::SetClient( 86 void SynchronousCompositorImpl::SetClient(
81 SynchronousCompositorClient* compositor_client) { 87 SynchronousCompositorClient* compositor_client) {
82 DCHECK(CalledOnValidThread()); 88 DCHECK(CalledOnValidThread());
83 compositor_client_ = compositor_client; 89 compositor_client_ = compositor_client;
84 } 90 }
85 91
86 // static 92 // static
87 void SynchronousCompositor::SetGpuService( 93 void SynchronousCompositor::SetGpuService(
88 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { 94 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) {
89 g_factory.Get().SetDeferredGpuService(service); 95 g_factory.Get().SetDeferredGpuService(service);
90 } 96 }
91 97
92 // static 98 // static
93 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { 99 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) {
94 g_factory.Get().SetRecordFullDocument(record_full_document); 100 g_factory.Get().SetRecordFullDocument(record_full_document);
95 } 101 }
96 102
103 void SynchronousCompositorImpl::SetExternalBeginFrameSource(
104 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) {
105 begin_frame_source_ = begin_frame_source;
boliu 2014/10/31 16:48:21 It's a bit awkard to DCHECK this, and so let's spl
simonhong 2014/11/01 02:13:06 Done.
106 if (begin_frame_source_)
107 begin_frame_source_->SetCompositor(this);
108 }
109
97 bool SynchronousCompositorImpl::InitializeHwDraw() { 110 bool SynchronousCompositorImpl::InitializeHwDraw() {
98 DCHECK(CalledOnValidThread()); 111 DCHECK(CalledOnValidThread());
99 DCHECK(output_surface_); 112 DCHECK(output_surface_);
100 113
101 scoped_refptr<cc::ContextProvider> onscreen_context = 114 scoped_refptr<cc::ContextProvider> onscreen_context =
102 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(); 115 g_factory.Get().CreateOnscreenContextProviderForCompositorThread();
103 116
104 bool success = output_surface_->InitializeHwDraw(onscreen_context); 117 bool success = output_surface_->InitializeHwDraw(onscreen_context);
105 118
106 if (success) 119 if (success)
(...skipping 10 matching lines...) Expand all
117 130
118 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( 131 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw(
119 gfx::Size surface_size, 132 gfx::Size surface_size,
120 const gfx::Transform& transform, 133 const gfx::Transform& transform,
121 gfx::Rect viewport, 134 gfx::Rect viewport,
122 gfx::Rect clip, 135 gfx::Rect clip,
123 gfx::Rect viewport_rect_for_tile_priority, 136 gfx::Rect viewport_rect_for_tile_priority,
124 const gfx::Transform& transform_for_tile_priority) { 137 const gfx::Transform& transform_for_tile_priority) {
125 DCHECK(CalledOnValidThread()); 138 DCHECK(CalledOnValidThread());
126 DCHECK(output_surface_); 139 DCHECK(output_surface_);
140 DCHECK(!invoking_composite_);
141 DCHECK(compositor_client_);
142 DCHECK(begin_frame_source_);
127 143
144 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
145 true);
128 scoped_ptr<cc::CompositorFrame> frame = 146 scoped_ptr<cc::CompositorFrame> frame =
129 output_surface_->DemandDrawHw(surface_size, 147 output_surface_->DemandDrawHw(surface_size,
130 transform, 148 transform,
131 viewport, 149 viewport,
132 clip, 150 clip,
133 viewport_rect_for_tile_priority, 151 viewport_rect_for_tile_priority,
134 transform_for_tile_priority); 152 transform_for_tile_priority);
135 if (frame.get()) 153 if (frame.get())
136 UpdateFrameMetaData(frame->metadata); 154 UpdateFrameMetaData(frame->metadata);
137 155
156 compositor_client_->SetContinuousInvalidate(
157 begin_frame_source_->NeedsBeginFrames());
158
138 return frame.Pass(); 159 return frame.Pass();
139 } 160 }
140 161
141 void SynchronousCompositorImpl::ReturnResources( 162 void SynchronousCompositorImpl::ReturnResources(
142 const cc::CompositorFrameAck& frame_ack) { 163 const cc::CompositorFrameAck& frame_ack) {
143 DCHECK(CalledOnValidThread()); 164 DCHECK(CalledOnValidThread());
144 output_surface_->ReturnResources(frame_ack); 165 output_surface_->ReturnResources(frame_ack);
145 } 166 }
146 167
147 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { 168 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
148 DCHECK(CalledOnValidThread()); 169 DCHECK(CalledOnValidThread());
149 DCHECK(output_surface_); 170 DCHECK(output_surface_);
171 DCHECK(!invoking_composite_);
172 DCHECK(compositor_client_);
173 DCHECK(begin_frame_source_);
150 174
151 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); 175 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
176 true);
177 scoped_ptr<cc::CompositorFrame> frame =
178 output_surface_->DemandDrawSw(canvas);
152 if (frame.get()) 179 if (frame.get())
153 UpdateFrameMetaData(frame->metadata); 180 UpdateFrameMetaData(frame->metadata);
181
182 compositor_client_->SetContinuousInvalidate(
183 begin_frame_source_->NeedsBeginFrames());
184
154 return !!frame.get(); 185 return !!frame.get();
155 } 186 }
156 187
157 void SynchronousCompositorImpl::UpdateFrameMetaData( 188 void SynchronousCompositorImpl::UpdateFrameMetaData(
158 const cc::CompositorFrameMetadata& frame_metadata) { 189 const cc::CompositorFrameMetadata& frame_metadata) {
159 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 190 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
160 contents_->GetRenderWidgetHostView()); 191 contents_->GetRenderWidgetHostView());
161 if (rwhv) 192 if (rwhv)
162 rwhv->SynchronousFrameMetadata(frame_metadata); 193 rwhv->SynchronousFrameMetadata(frame_metadata);
163 DeliverMessages(); 194 DeliverMessages();
164 } 195 }
165 196
166 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { 197 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) {
167 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
168 DCHECK(output_surface_); 199 DCHECK(output_surface_);
169 200
170 output_surface_->SetMemoryPolicy(bytes_limit); 201 output_surface_->SetMemoryPolicy(bytes_limit);
171 } 202 }
172 203
173 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { 204 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() {
174 if (input_handler_) 205 if (input_handler_)
175 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); 206 input_handler_->OnRootLayerDelegatedScrollOffsetChanged();
176 } 207 }
177 208
178 void SynchronousCompositorImpl::DidBindOutputSurface( 209 void SynchronousCompositorImpl::DidBindOutputSurface(
179 SynchronousCompositorOutputSurface* output_surface) { 210 SynchronousCompositorOutputSurface* output_surface) {
180 DCHECK(CalledOnValidThread()); 211 DCHECK(CalledOnValidThread());
boliu 2014/10/31 16:48:21 You actually do want DCHECK(begin_frame_source_);
simonhong 2014/11/01 02:13:06 Done.
181 output_surface_ = output_surface; 212 output_surface_ = output_surface;
182 if (compositor_client_) 213 if (compositor_client_)
183 compositor_client_->DidInitializeCompositor(this); 214 compositor_client_->DidInitializeCompositor(this);
215
216 output_surface_->SetBeginFrameSource(begin_frame_source_);
184 } 217 }
185 218
186 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( 219 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface(
187 SynchronousCompositorOutputSurface* output_surface) { 220 SynchronousCompositorOutputSurface* output_surface) {
188 DCHECK(CalledOnValidThread()); 221 DCHECK(CalledOnValidThread());
189 222
190 // Allow for transient hand-over when two output surfaces may refer to 223 // Allow for transient hand-over when two output surfaces may refer to
191 // a single delegate. 224 // a single delegate.
192 if (output_surface_ == output_surface) { 225 if (output_surface_ == output_surface) {
193 output_surface_ = NULL; 226 output_surface_ = NULL;
boliu 2014/10/31 16:48:21 output_surface_->SetBeginFrameSource(nullptr);
simonhong 2014/11/01 02:13:06 Done.
194 if (compositor_client_) 227 if (compositor_client_)
195 compositor_client_->DidDestroyCompositor(this); 228 compositor_client_->DidDestroyCompositor(this);
196 compositor_client_ = NULL; 229 compositor_client_ = NULL;
230
231 DCHECK(begin_frame_source_);
boliu 2014/10/31 16:48:21 Don't assume particular destruction order either.
simonhong 2014/11/01 02:13:06 Done.
232 begin_frame_source_->SetCompositor(nullptr);
233 begin_frame_source_ = nullptr;
197 } 234 }
198 } 235 }
199 236
200 void SynchronousCompositorImpl::SetInputHandler( 237 void SynchronousCompositorImpl::SetInputHandler(
201 cc::InputHandler* input_handler) { 238 cc::InputHandler* input_handler) {
202 DCHECK(CalledOnValidThread()); 239 DCHECK(CalledOnValidThread());
203 240
204 if (input_handler_) 241 if (input_handler_)
205 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); 242 input_handler_->SetRootLayerScrollOffsetDelegate(NULL);
206 243
(...skipping 12 matching lines...) Expand all
219 } 256 }
220 } 257 }
221 258
222 void SynchronousCompositorImpl::DidStopFlinging() { 259 void SynchronousCompositorImpl::DidStopFlinging() {
223 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 260 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
224 contents_->GetRenderWidgetHostView()); 261 contents_->GetRenderWidgetHostView());
225 if (rwhv) 262 if (rwhv)
226 rwhv->DidStopFlinging(); 263 rwhv->DidStopFlinging();
227 } 264 }
228 265
229 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { 266 void SynchronousCompositorImpl::SetContinuousInvalidate(
boliu 2014/10/31 16:48:21 Prefer only have one way to get "needs_begin_frame
simonhong 2014/11/01 02:13:06 Done.
267 bool needs_begin_frames) const {
230 DCHECK(CalledOnValidThread()); 268 DCHECK(CalledOnValidThread());
269 if (invoking_composite_)
270 return;
271
231 if (compositor_client_) 272 if (compositor_client_)
232 compositor_client_->SetContinuousInvalidate(enable); 273 compositor_client_->SetContinuousInvalidate(needs_begin_frames);
233 } 274 }
234 275
235 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( 276 InputEventAckState SynchronousCompositorImpl::HandleInputEvent(
236 const blink::WebInputEvent& input_event) { 277 const blink::WebInputEvent& input_event) {
237 DCHECK(CalledOnValidThread()); 278 DCHECK(CalledOnValidThread());
238 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( 279 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent(
239 contents_->GetRoutingID(), input_event); 280 contents_->GetRoutingID(), input_event);
240 } 281 }
241 282
242 void SynchronousCompositorImpl::DeliverMessages() { 283 void SynchronousCompositorImpl::DeliverMessages() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 g_factory.Get(); // Ensure it's initialized. 350 g_factory.Get(); // Ensure it's initialized.
310 SynchronousCompositorImpl::CreateForWebContents(contents); 351 SynchronousCompositorImpl::CreateForWebContents(contents);
311 } 352 }
312 if (SynchronousCompositorImpl* instance = 353 if (SynchronousCompositorImpl* instance =
313 SynchronousCompositorImpl::FromWebContents(contents)) { 354 SynchronousCompositorImpl::FromWebContents(contents)) {
314 instance->SetClient(client); 355 instance->SetClient(client);
315 } 356 }
316 } 357 }
317 358
318 } // namespace content 359 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698