| 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 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 subroot_layer_ = NULL; | 447 subroot_layer_ = NULL; |
| 448 } | 448 } |
| 449 if (root_window_->GetLayer()) { | 449 if (root_window_->GetLayer()) { |
| 450 subroot_layer_ = root_window_->GetLayer(); | 450 subroot_layer_ = root_window_->GetLayer(); |
| 451 root_window_->GetLayer()->AddChild(root_layer); | 451 root_window_->GetLayer()->AddChild(root_layer); |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 | 454 |
| 455 void CompositorImpl::SetSurface(jobject surface) { | 455 void CompositorImpl::SetSurface(jobject surface) { |
| 456 JNIEnv* env = base::android::AttachCurrentThread(); | 456 JNIEnv* env = base::android::AttachCurrentThread(); |
| 457 base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface); | |
| 458 | |
| 459 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); | 457 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); |
| 460 | 458 |
| 461 if (window_) { | 459 if (window_) { |
| 462 // Shut down GL context before unregistering surface. | 460 // Shut down GL context before unregistering surface. |
| 463 SetVisible(false); | 461 SetVisible(false); |
| 464 tracker->RemoveSurface(surface_handle_); | 462 tracker->RemoveSurface(surface_handle_); |
| 465 ANativeWindow_release(window_); | 463 ANativeWindow_release(window_); |
| 466 window_ = NULL; | 464 window_ = NULL; |
| 467 | 465 |
| 468 tracker->UnregisterViewSurface(surface_handle_); | 466 tracker->UnregisterViewSurface(surface_handle_); |
| 469 surface_handle_ = gpu::kNullSurfaceHandle; | 467 surface_handle_ = gpu::kNullSurfaceHandle; |
| 470 } | 468 } |
| 471 | 469 |
| 472 ANativeWindow* window = NULL; | 470 ANativeWindow* window = NULL; |
| 473 if (surface) { | 471 if (surface) { |
| 474 // Note: This ensures that any local references used by | 472 // Note: This ensures that any local references used by |
| 475 // ANativeWindow_fromSurface are released immediately. This is needed as a | 473 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| 476 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 474 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
| 477 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 475 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 478 window = ANativeWindow_fromSurface(env, surface); | 476 window = ANativeWindow_fromSurface(env, surface); |
| 479 } | 477 } |
| 480 | 478 |
| 481 if (window) { | 479 if (window) { |
| 482 window_ = window; | 480 window_ = window; |
| 483 ANativeWindow_acquire(window); | 481 ANativeWindow_acquire(window); |
| 484 surface_handle_ = tracker->AddSurfaceForNativeWidget(window); | 482 surface_handle_ = tracker->AddSurfaceForNativeWidget(window); |
| 485 // Register first, SetVisible() might create a CompositorFrameSink. | 483 // Register first, SetVisible() might create a CompositorFrameSink. |
| 486 tracker->RegisterViewSurface(surface_handle_, j_surface); | 484 tracker->RegisterViewSurface(surface_handle_, surface); |
| 487 SetVisible(true); | 485 SetVisible(true); |
| 488 ANativeWindow_release(window); | 486 ANativeWindow_release(window); |
| 489 } | 487 } |
| 490 } | 488 } |
| 491 | 489 |
| 492 void CompositorImpl::CreateLayerTreeHost() { | 490 void CompositorImpl::CreateLayerTreeHost() { |
| 493 DCHECK(!host_); | 491 DCHECK(!host_); |
| 494 | 492 |
| 495 cc::LayerTreeSettings settings; | 493 cc::LayerTreeSettings settings; |
| 496 settings.renderer_settings.refresh_rate = 60.0; | 494 settings.renderer_settings.refresh_rate = 60.0; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 836 |
| 839 cc::FrameSinkId CompositorImpl::GetFrameSinkId() { | 837 cc::FrameSinkId CompositorImpl::GetFrameSinkId() { |
| 840 return frame_sink_id_; | 838 return frame_sink_id_; |
| 841 } | 839 } |
| 842 | 840 |
| 843 bool CompositorImpl::HavePendingReadbacks() { | 841 bool CompositorImpl::HavePendingReadbacks() { |
| 844 return !readback_layer_tree_->children().empty(); | 842 return !readback_layer_tree_->children().empty(); |
| 845 } | 843 } |
| 846 | 844 |
| 847 } // namespace content | 845 } // namespace content |
| OLD | NEW |