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

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 if (begin_frame_source)
106 DCHECK(compositor_client_);
boliu 2014/10/30 16:21:32 Why? I don't think this is guaranteed in general.
simonhong 2014/10/31 00:22:08 Done.
107 begin_frame_source_ = begin_frame_source;
boliu 2014/10/30 16:21:33 You are assuming here that SetExternalBeginFrameSo
simonhong 2014/10/31 00:22:08 Removed that assumption related code in DidBindOut
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_);
127 142
143 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
144 true);
128 scoped_ptr<cc::CompositorFrame> frame = 145 scoped_ptr<cc::CompositorFrame> frame =
129 output_surface_->DemandDrawHw(surface_size, 146 output_surface_->DemandDrawHw(surface_size,
130 transform, 147 transform,
131 viewport, 148 viewport,
132 clip, 149 clip,
133 viewport_rect_for_tile_priority, 150 viewport_rect_for_tile_priority,
134 transform_for_tile_priority); 151 transform_for_tile_priority);
135 if (frame.get()) 152 if (frame.get())
136 UpdateFrameMetaData(frame->metadata); 153 UpdateFrameMetaData(frame->metadata);
137 154
155 bool needs_begin_frames = false;
156 if (begin_frame_source_)
boliu 2014/10/30 16:21:32 This should be a DCHECK like output_surface_. com
simonhong 2014/10/31 00:22:08 yep, right. It should be always not null.
157 needs_begin_frames = begin_frame_source_->NeedsBeginFrames();
158 compositor_client_->SetContinuousInvalidate(needs_begin_frames);
159
138 return frame.Pass(); 160 return frame.Pass();
139 } 161 }
140 162
141 void SynchronousCompositorImpl::ReturnResources( 163 void SynchronousCompositorImpl::ReturnResources(
142 const cc::CompositorFrameAck& frame_ack) { 164 const cc::CompositorFrameAck& frame_ack) {
143 DCHECK(CalledOnValidThread()); 165 DCHECK(CalledOnValidThread());
144 output_surface_->ReturnResources(frame_ack); 166 output_surface_->ReturnResources(frame_ack);
145 } 167 }
146 168
147 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { 169 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
148 DCHECK(CalledOnValidThread()); 170 DCHECK(CalledOnValidThread());
149 DCHECK(output_surface_); 171 DCHECK(output_surface_);
172 DCHECK(!invoking_composite_);
173 DCHECK(compositor_client_);
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 bool needs_begin_frames = false;
183 if (begin_frame_source_)
184 needs_begin_frames = begin_frame_source_->NeedsBeginFrames();
185 compositor_client_->SetContinuousInvalidate(needs_begin_frames);
186
154 return !!frame.get(); 187 return !!frame.get();
155 } 188 }
156 189
157 void SynchronousCompositorImpl::UpdateFrameMetaData( 190 void SynchronousCompositorImpl::UpdateFrameMetaData(
158 const cc::CompositorFrameMetadata& frame_metadata) { 191 const cc::CompositorFrameMetadata& frame_metadata) {
159 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 192 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
160 contents_->GetRenderWidgetHostView()); 193 contents_->GetRenderWidgetHostView());
161 if (rwhv) 194 if (rwhv)
162 rwhv->SynchronousFrameMetadata(frame_metadata); 195 rwhv->SynchronousFrameMetadata(frame_metadata);
163 DeliverMessages(); 196 DeliverMessages();
164 } 197 }
165 198
166 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { 199 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) {
167 DCHECK(CalledOnValidThread()); 200 DCHECK(CalledOnValidThread());
168 DCHECK(output_surface_); 201 DCHECK(output_surface_);
169 202
170 output_surface_->SetMemoryPolicy(bytes_limit); 203 output_surface_->SetMemoryPolicy(bytes_limit);
171 } 204 }
172 205
173 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { 206 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() {
174 if (input_handler_) 207 if (input_handler_)
175 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); 208 input_handler_->OnRootLayerDelegatedScrollOffsetChanged();
176 } 209 }
177 210
178 void SynchronousCompositorImpl::DidBindOutputSurface( 211 void SynchronousCompositorImpl::DidBindOutputSurface(
179 SynchronousCompositorOutputSurface* output_surface) { 212 SynchronousCompositorOutputSurface* output_surface) {
180 DCHECK(CalledOnValidThread()); 213 DCHECK(CalledOnValidThread());
181 output_surface_ = output_surface; 214 output_surface_ = output_surface;
182 if (compositor_client_) 215 if (compositor_client_)
183 compositor_client_->DidInitializeCompositor(this); 216 compositor_client_->DidInitializeCompositor(this);
217
218 DCHECK(begin_frame_source_);
219 output_surface_->SetBeginFrameSource(begin_frame_source_);
184 } 220 }
185 221
186 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( 222 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface(
187 SynchronousCompositorOutputSurface* output_surface) { 223 SynchronousCompositorOutputSurface* output_surface) {
188 DCHECK(CalledOnValidThread()); 224 DCHECK(CalledOnValidThread());
189 225
190 // Allow for transient hand-over when two output surfaces may refer to 226 // Allow for transient hand-over when two output surfaces may refer to
191 // a single delegate. 227 // a single delegate.
192 if (output_surface_ == output_surface) { 228 if (output_surface_ == output_surface) {
193 output_surface_ = NULL; 229 output_surface_ = NULL;
194 if (compositor_client_) 230 if (compositor_client_)
195 compositor_client_->DidDestroyCompositor(this); 231 compositor_client_->DidDestroyCompositor(this);
196 compositor_client_ = NULL; 232 compositor_client_ = NULL;
233
234 DCHECK(begin_frame_source_);
235 begin_frame_source_->SetCompositor(nullptr);
236 begin_frame_source_ = nullptr;
197 } 237 }
198 } 238 }
199 239
200 void SynchronousCompositorImpl::SetInputHandler( 240 void SynchronousCompositorImpl::SetInputHandler(
201 cc::InputHandler* input_handler) { 241 cc::InputHandler* input_handler) {
202 DCHECK(CalledOnValidThread()); 242 DCHECK(CalledOnValidThread());
203 243
204 if (input_handler_) 244 if (input_handler_)
205 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); 245 input_handler_->SetRootLayerScrollOffsetDelegate(NULL);
206 246
(...skipping 12 matching lines...) Expand all
219 } 259 }
220 } 260 }
221 261
222 void SynchronousCompositorImpl::DidStopFlinging() { 262 void SynchronousCompositorImpl::DidStopFlinging() {
223 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 263 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
224 contents_->GetRenderWidgetHostView()); 264 contents_->GetRenderWidgetHostView());
225 if (rwhv) 265 if (rwhv)
226 rwhv->DidStopFlinging(); 266 rwhv->DidStopFlinging();
227 } 267 }
228 268
229 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { 269 void SynchronousCompositorImpl::SetContinuousInvalidate(
270 bool needs_begin_frames) const {
230 DCHECK(CalledOnValidThread()); 271 DCHECK(CalledOnValidThread());
272 if (invoking_composite_)
273 return;
274
231 if (compositor_client_) 275 if (compositor_client_)
232 compositor_client_->SetContinuousInvalidate(enable); 276 compositor_client_->SetContinuousInvalidate(needs_begin_frames);
233 } 277 }
234 278
235 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( 279 InputEventAckState SynchronousCompositorImpl::HandleInputEvent(
236 const blink::WebInputEvent& input_event) { 280 const blink::WebInputEvent& input_event) {
237 DCHECK(CalledOnValidThread()); 281 DCHECK(CalledOnValidThread());
238 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( 282 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent(
239 contents_->GetRoutingID(), input_event); 283 contents_->GetRoutingID(), input_event);
240 } 284 }
241 285
242 void SynchronousCompositorImpl::DeliverMessages() { 286 void SynchronousCompositorImpl::DeliverMessages() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 g_factory.Get(); // Ensure it's initialized. 353 g_factory.Get(); // Ensure it's initialized.
310 SynchronousCompositorImpl::CreateForWebContents(contents); 354 SynchronousCompositorImpl::CreateForWebContents(contents);
311 } 355 }
312 if (SynchronousCompositorImpl* instance = 356 if (SynchronousCompositorImpl* instance =
313 SynchronousCompositorImpl::FromWebContents(contents)) { 357 SynchronousCompositorImpl::FromWebContents(contents)) {
314 instance->SetClient(client); 358 instance->SetClient(client);
315 } 359 }
316 } 360 }
317 361
318 } // namespace content 362 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698