Chromium Code Reviews| Index: media/base/android/dialog_surface_manager.cc |
| diff --git a/media/base/android/dialog_surface_manager.cc b/media/base/android/dialog_surface_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d9b2c500cd0d7e66069ce484e4af4fff5dbfab6e |
| --- /dev/null |
| +++ b/media/base/android/dialog_surface_manager.cc |
| @@ -0,0 +1,87 @@ |
| +// 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/dialog_surface_manager.h" |
| + |
| +#include <algorithm> |
| +#include <limits> |
| +#include <memory> |
| +#include <utility> |
| + |
| +#include "base/android/build_info.h" |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/android/unguessable_token_android.h" |
| +#include "base/logging.h" |
| +#include "base/numerics/safe_conversions.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/unguessable_token.h" |
| +#include "gpu/ipc/common/android/dialog_surface_lookup.h" |
| +#include "jni/DialogSurfaceManagerWrapper_jni.h" |
| +#include "media/base/bit_reader.h" |
| +#include "media/base/decrypt_config.h" |
| + |
| +using base::android::AttachCurrentThread; |
| +using base::android::ConvertJavaStringToUTF8; |
| +using base::android::ConvertUTF8ToJavaString; |
| +using base::android::JavaIntArrayToIntVector; |
| +using base::android::ScopedJavaGlobalRef; |
| +using base::android::ScopedJavaLocalRef; |
| + |
| +namespace media { |
| + |
| +static base::LazyInstance<DialogSurfaceManager>::Leaky g_surface_manager = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +DialogSurfaceManager* DialogSurfaceManager::Get() { |
| + return g_surface_manager.Pointer(); |
| +} |
| + |
| +DialogSurfaceManager::DialogSurfaceManager() { |
| + JNIEnv* env = AttachCurrentThread(); |
| + CHECK(env); |
| + |
| + // 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 IDialogSurfaceManager here, and we don't |
| + // care whether it's local or remote. |
| + ScopedJavaLocalRef<jobject> unwrapped_manager( |
| + gpu::DialogSurfaceLookup::GetInstance()->GetDialogSurfaceManager()); |
| + |
| + // Wrap the manager for access from native code. |
| + j_wrapped_manager_.Reset( |
| + Java_DialogSurfaceManagerWrapper_wrap(env, unwrapped_manager.obj())); |
| +} |
| + |
| +DialogSurfaceManager::~DialogSurfaceManager() {} |
| + |
| +std::unique_ptr<DialogSurfaceHolder> DialogSurfaceManager::CreateSurface( |
| + const base::UnguessableToken& frame_token, |
| + const Config& config, |
| + const DialogSurfaceHolder::Callback& callback) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + CHECK(env); |
| + |
| + // TODO(liberato): wrap the callback here, and send in place of the nullptr. |
| + // This was omitted for the first CL. |
| + |
| + ScopedJavaLocalRef<jobject> frame_token_java = |
| + base::android::UnguessableTokenAndroid::Create(env, frame_token); |
| + if (!frame_token_java.obj()) |
| + return std::unique_ptr<DialogSurfaceHolder>(); |
|
boliu
2016/11/14 16:39:25
nit: return nullptr
liberato (no reviews please)
2016/12/20 17:16:38
code was removed entirely.
|
| + |
| + ScopedJavaGlobalRef<jobject> result( |
| + Java_DialogSurfaceManagerWrapper_createSurface( |
| + env, j_wrapped_manager_.obj(), frame_token_java.obj(), nullptr, |
| + config.rect.x(), config.rect.y(), config.rect.width(), |
| + config.rect.height())); |
| + // NOTE: result is always null right now. |
| + std::unique_ptr<DialogSurfaceHolder> holder; |
| + |
| + return holder; |
| +} |
| + |
| +} // namespace media |