OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/base/android/android_overlay_provider_proxy.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "gpu/ipc/common/android/android_overlay_provider_lookup.h" |
| 9 #include "jni/AndroidOverlayProviderProxy_jni.h" |
| 10 #include "media/base/android/android_overlay_callback.h" |
| 11 |
| 12 using base::android::AttachCurrentThread; |
| 13 using base::android::ScopedJavaGlobalRef; |
| 14 using base::android::ScopedJavaLocalRef; |
| 15 |
| 16 namespace media { |
| 17 |
| 18 static base::LazyInstance<AndroidOverlayProviderProxy>::Leaky |
| 19 g_surface_manager = LAZY_INSTANCE_INITIALIZER; |
| 20 |
| 21 AndroidOverlayProviderProxy* AndroidOverlayProviderProxy::Get() { |
| 22 return g_surface_manager.Pointer(); |
| 23 } |
| 24 |
| 25 AndroidOverlayProviderProxy::AndroidOverlayProviderProxy() { |
| 26 JNIEnv* env = AttachCurrentThread(); |
| 27 |
| 28 // Get the surface manager from the browser. |
| 29 // This can, in principle, be run in the gpu process if we send the window |
| 30 // token from the browser. See https://codereview.chromium.org/1967553002 . |
| 31 // Either way, we end up with an IAndroidOverlayProviderProxy here, and we |
| 32 // don't |
| 33 // care whether it's local or remote. |
| 34 ScopedJavaLocalRef<jobject> unwrapped_provider( |
| 35 gpu::AndroidOverlayProviderLookup::GetInstance() |
| 36 ->GetAndroidOverlayProvider()); |
| 37 |
| 38 // Wrap the manager for access from native code. |
| 39 j_wrapped_provider_.Reset( |
| 40 Java_AndroidOverlayProviderProxy_wrap(env, unwrapped_provider.obj())); |
| 41 } |
| 42 |
| 43 AndroidOverlayProviderProxy::~AndroidOverlayProviderProxy() {} |
| 44 |
| 45 std::unique_ptr<AndroidOverlayProxy> AndroidOverlayProviderProxy::CreateOverlay( |
| 46 base::ProcessHandle pid, |
| 47 int frame_id, |
| 48 const Config& config, |
| 49 const AndroidOverlayProxy::Callback& callback) { |
| 50 JNIEnv* env = AttachCurrentThread(); |
| 51 |
| 52 std::unique_ptr<AndroidOverlayCallback> wrapped_callback( |
| 53 new AndroidOverlayCallback(callback)); |
| 54 |
| 55 ScopedJavaGlobalRef<jobject> result( |
| 56 Java_AndroidOverlayProviderProxy_createOverlay( |
| 57 env, j_wrapped_provider_.obj(), pid, frame_id, |
| 58 wrapped_callback->obj(), config.rect.x(), config.rect.y(), |
| 59 config.rect.width(), config.rect.height())); |
| 60 |
| 61 std::unique_ptr<AndroidOverlayProxy> surface; |
| 62 if (!result.is_null()) { |
| 63 surface.reset(new AndroidOverlayProxy(result, std::move(wrapped_callback))); |
| 64 } |
| 65 |
| 66 return surface; |
| 67 } |
| 68 |
| 69 } // namespace media |
OLD | NEW |