| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 382 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 383 window = ANativeWindow_fromSurface(env, surface); | 383 window = ANativeWindow_fromSurface(env, surface); |
| 384 } | 384 } |
| 385 if (window) { | 385 if (window) { |
| 386 SetWindowSurface(window); | 386 SetWindowSurface(window); |
| 387 ANativeWindow_release(window); | 387 ANativeWindow_release(window); |
| 388 RegisterViewSurface(surface_id_, j_surface.obj()); | 388 RegisterViewSurface(surface_id_, j_surface.obj()); |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 | 391 |
| 392 void CompositorImpl::CreateLayerTreeHost() { |
| 393 DCHECK(!host_); |
| 394 DCHECK(!WillCompositeThisFrame()); |
| 395 needs_composite_ = false; |
| 396 defer_composite_for_gpu_channel_ = false; |
| 397 pending_swapbuffers_ = 0; |
| 398 cc::LayerTreeSettings settings; |
| 399 settings.renderer_settings.refresh_rate = 60.0; |
| 400 settings.renderer_settings.allow_antialiasing = false; |
| 401 settings.renderer_settings.highp_threshold_min = 2048; |
| 402 settings.impl_side_painting = false; |
| 403 settings.calculate_top_controls_position = false; |
| 404 |
| 405 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 406 settings.initial_debug_state.SetRecordRenderingStats( |
| 407 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
| 408 settings.initial_debug_state.show_fps_counter = |
| 409 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); |
| 410 // TODO(enne): Update this this compositor to use the scheduler. |
| 411 settings.single_thread_proxy_scheduler = false; |
| 412 |
| 413 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
| 414 this, |
| 415 this, |
| 416 HostSharedBitmapManager::current(), |
| 417 BrowserGpuMemoryBufferManager::current(), |
| 418 settings, |
| 419 base::MessageLoopProxy::current(), |
| 420 nullptr); |
| 421 host_->SetRootLayer(root_layer_); |
| 422 |
| 423 host_->SetVisible(true); |
| 424 host_->SetLayerTreeHostClientReady(); |
| 425 host_->SetViewportSize(size_); |
| 426 host_->set_has_transparent_background(has_transparent_background_); |
| 427 host_->SetDeviceScaleFactor(device_scale_factor_); |
| 428 } |
| 429 |
| 392 void CompositorImpl::SetVisible(bool visible) { | 430 void CompositorImpl::SetVisible(bool visible) { |
| 393 if (!visible) { | 431 if (!visible) { |
| 394 DCHECK(host_); | 432 DCHECK(host_); |
| 395 // Look for any layers that were attached to the root for readback | 433 // Look for any layers that were attached to the root for readback |
| 396 // and are waiting for Composite() to happen. | 434 // and are waiting for Composite() to happen. |
| 397 bool readback_pending = false; | 435 bool readback_pending = false; |
| 398 for (size_t i = 0; i < root_layer_->children().size(); ++i) { | 436 for (size_t i = 0; i < root_layer_->children().size(); ++i) { |
| 399 if (root_layer_->children()[i]->HasCopyRequest()) { | 437 if (root_layer_->children()[i]->HasCopyRequest()) { |
| 400 readback_pending = true; | 438 readback_pending = true; |
| 401 break; | 439 break; |
| 402 } | 440 } |
| 403 } | 441 } |
| 404 if (readback_pending) { | 442 if (readback_pending) { |
| 405 ignore_schedule_composite_ = true; | 443 ignore_schedule_composite_ = true; |
| 406 host_->Composite(base::TimeTicks::Now()); | 444 host_->Composite(base::TimeTicks::Now()); |
| 407 ignore_schedule_composite_ = false; | 445 ignore_schedule_composite_ = false; |
| 408 } | 446 } |
| 409 if (WillComposite()) | 447 if (WillComposite()) |
| 410 CancelComposite(); | 448 CancelComposite(); |
| 411 ui_resource_provider_.SetLayerTreeHost(NULL); | 449 ui_resource_provider_.SetLayerTreeHost(NULL); |
| 412 host_.reset(); | 450 host_.reset(); |
| 413 display_client_.reset(); | 451 display_client_.reset(); |
| 414 if (current_composite_task_) { | 452 if (current_composite_task_) { |
| 415 current_composite_task_->Cancel(); | 453 current_composite_task_->Cancel(); |
| 416 current_composite_task_.reset(); | 454 current_composite_task_.reset(); |
| 417 } | 455 } |
| 418 } else if (!host_) { | 456 } else if (!host_) { |
| 419 DCHECK(!WillCompositeThisFrame()); | 457 CreateLayerTreeHost(); |
| 420 needs_composite_ = false; | |
| 421 defer_composite_for_gpu_channel_ = false; | |
| 422 pending_swapbuffers_ = 0; | |
| 423 cc::LayerTreeSettings settings; | |
| 424 settings.renderer_settings.refresh_rate = 60.0; | |
| 425 settings.renderer_settings.allow_antialiasing = false; | |
| 426 settings.renderer_settings.highp_threshold_min = 2048; | |
| 427 settings.impl_side_painting = false; | |
| 428 settings.calculate_top_controls_position = false; | |
| 429 | |
| 430 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 431 settings.initial_debug_state.SetRecordRenderingStats( | |
| 432 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | |
| 433 settings.initial_debug_state.show_fps_counter = | |
| 434 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); | |
| 435 // TODO(enne): Update this this compositor to use the scheduler. | |
| 436 settings.single_thread_proxy_scheduler = false; | |
| 437 | |
| 438 host_ = cc::LayerTreeHost::CreateSingleThreaded( | |
| 439 this, | |
| 440 this, | |
| 441 HostSharedBitmapManager::current(), | |
| 442 BrowserGpuMemoryBufferManager::current(), | |
| 443 settings, | |
| 444 base::MessageLoopProxy::current(), | |
| 445 nullptr); | |
| 446 host_->SetRootLayer(root_layer_); | |
| 447 | |
| 448 host_->SetVisible(true); | |
| 449 host_->SetLayerTreeHostClientReady(); | |
| 450 host_->SetViewportSize(size_); | |
| 451 host_->set_has_transparent_background(has_transparent_background_); | |
| 452 host_->SetDeviceScaleFactor(device_scale_factor_); | |
| 453 ui_resource_provider_.SetLayerTreeHost(host_.get()); | 458 ui_resource_provider_.SetLayerTreeHost(host_.get()); |
| 454 } | 459 } |
| 455 } | 460 } |
| 456 | 461 |
| 457 void CompositorImpl::setDeviceScaleFactor(float factor) { | 462 void CompositorImpl::setDeviceScaleFactor(float factor) { |
| 458 device_scale_factor_ = factor; | 463 device_scale_factor_ = factor; |
| 459 if (host_) | 464 if (host_) |
| 460 host_->SetDeviceScaleFactor(factor); | 465 host_->SetDeviceScaleFactor(factor); |
| 461 } | 466 } |
| 462 | 467 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } | 680 } |
| 676 | 681 |
| 677 void CompositorImpl::SetNeedsAnimate() { | 682 void CompositorImpl::SetNeedsAnimate() { |
| 678 if (!host_) | 683 if (!host_) |
| 679 return; | 684 return; |
| 680 | 685 |
| 681 host_->SetNeedsAnimate(); | 686 host_->SetNeedsAnimate(); |
| 682 } | 687 } |
| 683 | 688 |
| 684 } // namespace content | 689 } // namespace content |
| OLD | NEW |