Index: media/base/android/android_overlay_provider_proxy.cc |
diff --git a/media/base/android/android_overlay_provider_proxy.cc b/media/base/android/android_overlay_provider_proxy.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2b67452350b236f14deaacaa0c0d2b73fa0b0b9c |
--- /dev/null |
+++ b/media/base/android/android_overlay_provider_proxy.cc |
@@ -0,0 +1,69 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/base/android/android_overlay_provider_proxy.h" |
+ |
+#include "base/android/jni_android.h" |
+#include "gpu/ipc/common/android/android_overlay_provider_lookup.h" |
+#include "jni/AndroidOverlayProviderProxy_jni.h" |
+#include "media/base/android/android_overlay_callback.h" |
+ |
+using base::android::AttachCurrentThread; |
+using base::android::ScopedJavaGlobalRef; |
+using base::android::ScopedJavaLocalRef; |
+ |
+namespace media { |
+ |
+static base::LazyInstance<AndroidOverlayProviderProxy>::Leaky |
+ g_surface_manager = LAZY_INSTANCE_INITIALIZER; |
+ |
+AndroidOverlayProviderProxy* AndroidOverlayProviderProxy::Get() { |
+ return g_surface_manager.Pointer(); |
+} |
+ |
+AndroidOverlayProviderProxy::AndroidOverlayProviderProxy() { |
+ JNIEnv* env = AttachCurrentThread(); |
+ |
+ // Get the surface manager from the browser. |
+ // This can, in principle, be run in the gpu process if we send the window |
+ // token from the browser. See https://codereview.chromium.org/1967553002 . |
+ // Either way, we end up with an IAndroidOverlayProviderProxy here, and we |
+ // don't |
+ // care whether it's local or remote. |
+ ScopedJavaLocalRef<jobject> unwrapped_provider( |
+ gpu::AndroidOverlayProviderLookup::GetInstance() |
+ ->GetAndroidOverlayProvider()); |
+ |
+ // Wrap the manager for access from native code. |
+ j_wrapped_provider_.Reset( |
+ Java_AndroidOverlayProviderProxy_wrap(env, unwrapped_provider.obj())); |
+} |
+ |
+AndroidOverlayProviderProxy::~AndroidOverlayProviderProxy() {} |
+ |
+std::unique_ptr<AndroidOverlayProxy> AndroidOverlayProviderProxy::CreateOverlay( |
+ base::ProcessHandle pid, |
+ int frame_id, |
+ const Config& config, |
+ const AndroidOverlayProxy::Callback& callback) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ |
+ std::unique_ptr<AndroidOverlayCallback> wrapped_callback( |
+ new AndroidOverlayCallback(callback)); |
+ |
+ ScopedJavaGlobalRef<jobject> result( |
+ Java_AndroidOverlayProviderProxy_createOverlay( |
+ env, j_wrapped_provider_.obj(), pid, frame_id, |
+ wrapped_callback->obj(), config.rect.x(), config.rect.y(), |
+ config.rect.width(), config.rect.height())); |
+ |
+ std::unique_ptr<AndroidOverlayProxy> surface; |
+ if (!result.is_null()) { |
+ surface.reset(new AndroidOverlayProxy(result, std::move(wrapped_callback))); |
+ } |
+ |
+ return surface; |
+} |
+ |
+} // namespace media |