Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/compositor_impl_android.h" | 5 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 surface_id_(0), | 178 surface_id_(0), |
| 179 client_(client), | 179 client_(client), |
| 180 root_window_(root_window), | 180 root_window_(root_window), |
| 181 did_post_swapbuffers_(false), | 181 did_post_swapbuffers_(false), |
| 182 ignore_schedule_composite_(false), | 182 ignore_schedule_composite_(false), |
| 183 needs_composite_(false), | 183 needs_composite_(false), |
| 184 needs_animate_(false), | 184 needs_animate_(false), |
| 185 will_composite_immediately_(false), | 185 will_composite_immediately_(false), |
| 186 composite_on_vsync_trigger_(DO_NOT_COMPOSITE), | 186 composite_on_vsync_trigger_(DO_NOT_COMPOSITE), |
| 187 pending_swapbuffers_(0U), | 187 pending_swapbuffers_(0U), |
| 188 defer_composite_for_gpu_channel_(false), | |
| 188 weak_factory_(this) { | 189 weak_factory_(this) { |
| 189 DCHECK(client); | 190 DCHECK(client); |
| 190 DCHECK(root_window); | 191 DCHECK(root_window); |
| 191 ImageTransportFactoryAndroid::AddObserver(this); | 192 ImageTransportFactoryAndroid::AddObserver(this); |
| 192 root_window->AttachCompositor(this); | 193 root_window->AttachCompositor(this); |
| 193 } | 194 } |
| 194 | 195 |
| 195 CompositorImpl::~CompositorImpl() { | 196 CompositorImpl::~CompositorImpl() { |
| 196 root_window_->DetachCompositor(); | 197 root_window_->DetachCompositor(); |
| 197 ImageTransportFactoryAndroid::RemoveObserver(this); | 198 ImageTransportFactoryAndroid::RemoveObserver(this); |
| 198 // Clean-up any surface references. | 199 // Clean-up any surface references. |
| 199 SetSurface(NULL); | 200 SetSurface(NULL); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void CompositorImpl::PostComposite(CompositingTrigger trigger) { | 203 void CompositorImpl::PostComposite(CompositingTrigger trigger) { |
| 203 DCHECK(needs_composite_); | 204 DCHECK(needs_composite_); |
| 204 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); | 205 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); |
| 205 | 206 |
| 206 if (will_composite_immediately_ || | 207 if (defer_composite_for_gpu_channel_ || will_composite_immediately_ || |
| 207 (trigger == COMPOSITE_EVENTUALLY && WillComposite())) { | 208 (trigger == COMPOSITE_EVENTUALLY && WillComposite())) { |
| 208 // We will already composite soon enough. | 209 // We will already composite soon enough. |
| 209 DCHECK(WillComposite()); | 210 DCHECK(WillComposite()); |
| 210 return; | 211 return; |
| 211 } | 212 } |
| 212 | 213 |
| 213 if (DidCompositeThisFrame()) { | 214 if (DidCompositeThisFrame()) { |
| 214 DCHECK(!WillCompositeThisFrame()); | 215 DCHECK(!WillCompositeThisFrame()); |
| 215 if (composite_on_vsync_trigger_ != COMPOSITE_IMMEDIATELY) { | 216 if (composite_on_vsync_trigger_ != COMPOSITE_IMMEDIATELY) { |
| 216 composite_on_vsync_trigger_ = trigger; | 217 composite_on_vsync_trigger_ = trigger; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 if (current_composite_task_) | 253 if (current_composite_task_) |
| 253 current_composite_task_->Cancel(); | 254 current_composite_task_->Cancel(); |
| 254 | 255 |
| 255 // Unretained because we cancel the task on shutdown. | 256 // Unretained because we cancel the task on shutdown. |
| 256 current_composite_task_.reset(new base::CancelableClosure( | 257 current_composite_task_.reset(new base::CancelableClosure( |
| 257 base::Bind(&CompositorImpl::Composite, base::Unretained(this), trigger))); | 258 base::Bind(&CompositorImpl::Composite, base::Unretained(this), trigger))); |
| 258 base::MessageLoop::current()->PostDelayedTask( | 259 base::MessageLoop::current()->PostDelayedTask( |
| 259 FROM_HERE, current_composite_task_->callback(), delay); | 260 FROM_HERE, current_composite_task_->callback(), delay); |
| 260 } | 261 } |
| 261 | 262 |
| 263 void CompositorImpl::OnGpuChannelEstablished() { | |
| 264 defer_composite_for_gpu_channel_ = false; | |
| 265 | |
| 266 if (host_) | |
| 267 PostComposite(COMPOSITE_IMMEDIATELY); | |
| 268 } | |
| 269 | |
| 262 void CompositorImpl::Composite(CompositingTrigger trigger) { | 270 void CompositorImpl::Composite(CompositingTrigger trigger) { |
| 271 if (trigger == COMPOSITE_IMMEDIATELY) | |
| 272 will_composite_immediately_ = false; | |
| 273 | |
| 263 BrowserGpuChannelHostFactory* factory = | 274 BrowserGpuChannelHostFactory* factory = |
| 264 BrowserGpuChannelHostFactory::instance(); | 275 BrowserGpuChannelHostFactory::instance(); |
| 265 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { | 276 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { |
| 266 CauseForGpuLaunch cause = | 277 CauseForGpuLaunch cause = |
| 267 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 278 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 268 factory->EstablishGpuChannel(cause, | 279 factory->EstablishGpuChannel( |
| 269 base::Bind(&CompositorImpl::ScheduleComposite, | 280 cause, base::Bind(&CompositorImpl::OnGpuChannelEstablished, |
| 270 weak_factory_.GetWeakPtr())); | 281 weak_factory_.GetWeakPtr())); |
|
jdduke (slow)
2014/11/21 21:16:34
Maybe |DCHECK(!defer_composite_for_gpu_channel_);|
no sievers
2014/11/21 21:19:19
Done.
| |
| 282 defer_composite_for_gpu_channel_ = true; | |
| 283 current_composite_task_.reset(); | |
| 271 return; | 284 return; |
| 272 } | 285 } |
| 273 | 286 |
| 274 DCHECK(host_); | 287 DCHECK(host_); |
| 275 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); | 288 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); |
| 276 DCHECK(needs_composite_); | 289 DCHECK(needs_composite_); |
| 277 DCHECK(!DidCompositeThisFrame()); | 290 DCHECK(!DidCompositeThisFrame()); |
| 278 | 291 |
| 279 if (trigger == COMPOSITE_IMMEDIATELY) | |
| 280 will_composite_immediately_ = false; | |
| 281 | |
| 282 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers); | 292 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers); |
| 283 if (pending_swapbuffers_ == kMaxSwapBuffers) { | 293 if (pending_swapbuffers_ == kMaxSwapBuffers) { |
| 284 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit"); | 294 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit"); |
| 285 return; | 295 return; |
| 286 } | 296 } |
| 287 | 297 |
| 288 // Reset state before Layout+Composite since that might create more | 298 // Reset state before Layout+Composite since that might create more |
| 289 // requests to Composite that we need to respect. | 299 // requests to Composite that we need to respect. |
| 290 needs_composite_ = false; | 300 needs_composite_ = false; |
| 291 | 301 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 ui_resource_provider_.SetLayerTreeHost(NULL); | 412 ui_resource_provider_.SetLayerTreeHost(NULL); |
| 403 host_.reset(); | 413 host_.reset(); |
| 404 display_client_.reset(); | 414 display_client_.reset(); |
| 405 if (current_composite_task_) { | 415 if (current_composite_task_) { |
| 406 current_composite_task_->Cancel(); | 416 current_composite_task_->Cancel(); |
| 407 current_composite_task_.reset(); | 417 current_composite_task_.reset(); |
| 408 } | 418 } |
| 409 } else if (!host_) { | 419 } else if (!host_) { |
| 410 DCHECK(!WillComposite()); | 420 DCHECK(!WillComposite()); |
| 411 needs_composite_ = false; | 421 needs_composite_ = false; |
| 422 defer_composite_for_gpu_channel_ = false; | |
| 412 pending_swapbuffers_ = 0; | 423 pending_swapbuffers_ = 0; |
| 413 cc::LayerTreeSettings settings; | 424 cc::LayerTreeSettings settings; |
| 414 settings.refresh_rate = 60.0; | 425 settings.refresh_rate = 60.0; |
| 415 settings.impl_side_painting = false; | 426 settings.impl_side_painting = false; |
| 416 settings.allow_antialiasing = false; | 427 settings.allow_antialiasing = false; |
| 417 settings.calculate_top_controls_position = false; | 428 settings.calculate_top_controls_position = false; |
| 418 settings.top_controls_height = 0.f; | 429 settings.top_controls_height = 0.f; |
| 419 settings.highp_threshold_min = 2048; | 430 settings.highp_threshold_min = 2048; |
| 420 | 431 |
| 421 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 432 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 } | 680 } |
| 670 | 681 |
| 671 void CompositorImpl::SetNeedsAnimate() { | 682 void CompositorImpl::SetNeedsAnimate() { |
| 672 if (!host_) | 683 if (!host_) |
| 673 return; | 684 return; |
| 674 | 685 |
| 675 host_->SetNeedsAnimate(); | 686 host_->SetNeedsAnimate(); |
| 676 } | 687 } |
| 677 | 688 |
| 678 } // namespace content | 689 } // namespace content |
| OLD | NEW |