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/dialog_surface_manager.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <limits> |
| 9 #include <memory> |
| 10 #include <utility> |
| 11 |
| 12 #include "base/android/build_info.h" |
| 13 #include "base/android/jni_android.h" |
| 14 #include "base/android/jni_array.h" |
| 15 #include "base/android/jni_string.h" |
| 16 #include "base/logging.h" |
| 17 #include "base/numerics/safe_conversions.h" |
| 18 #include "base/strings/string_util.h" |
| 19 #include "gpu/ipc/common/dialog_surface_lookup.h" |
| 20 #include "jni/DialogSurfaceManagerWrapper_jni.h" |
| 21 #include "media/base/android/dialog_surface_callback.h" |
| 22 #include "media/base/bit_reader.h" |
| 23 #include "media/base/decrypt_config.h" |
| 24 |
| 25 using base::android::AttachCurrentThread; |
| 26 using base::android::ConvertJavaStringToUTF8; |
| 27 using base::android::ConvertUTF8ToJavaString; |
| 28 using base::android::JavaIntArrayToIntVector; |
| 29 using base::android::ScopedJavaGlobalRef; |
| 30 using base::android::ScopedJavaLocalRef; |
| 31 |
| 32 namespace media { |
| 33 |
| 34 static base::LazyInstance<DialogSurfaceManager>::Leaky g_surface_manager = |
| 35 LAZY_INSTANCE_INITIALIZER; |
| 36 |
| 37 DialogSurfaceManager* DialogSurfaceManager::GetPointer() { |
| 38 return g_surface_manager.Pointer(); |
| 39 } |
| 40 |
| 41 DialogSurfaceManager::DialogSurfaceManager() { |
| 42 JNIEnv* env = AttachCurrentThread(); |
| 43 CHECK(env); |
| 44 |
| 45 // Get the surface manager from the browser. |
| 46 // This can, in principle, be run in the gpu process if we send the window |
| 47 // token from the browser. See https://codereview.chromium.org/1967553002 . |
| 48 ScopedJavaLocalRef<jobject> unwrapped_manager( |
| 49 gpu::DialogSurfaceLookup::GetInstance()->GetDialogSurfaceManager()); |
| 50 |
| 51 // Wrap the manager for local access. |
| 52 j_wrapped_manager_.Reset( |
| 53 Java_DialogSurfaceManagerWrapper_wrap(env, unwrapped_manager.obj())); |
| 54 } |
| 55 |
| 56 DialogSurfaceManager::~DialogSurfaceManager() {} |
| 57 |
| 58 std::unique_ptr<DialogSurface> DialogSurfaceManager::CreateSurface( |
| 59 base::ProcessHandle pid, |
| 60 int frame_id, |
| 61 const Config& config, |
| 62 const DialogSurface::Callback& callback) { |
| 63 JNIEnv* env = AttachCurrentThread(); |
| 64 CHECK(env); |
| 65 |
| 66 std::unique_ptr<DialogSurfaceCallback> wrapped_callback( |
| 67 new DialogSurfaceCallback(callback)); |
| 68 |
| 69 ScopedJavaGlobalRef<jobject> result( |
| 70 Java_DialogSurfaceManagerWrapper_createSurface( |
| 71 env, j_wrapped_manager_.obj(), pid, frame_id, wrapped_callback->obj(), |
| 72 config.position.x(), config.position.y(), config.size.width(), |
| 73 config.size.height())); |
| 74 |
| 75 std::unique_ptr<DialogSurface> controller; |
| 76 if (result.obj() != nullptr) { |
| 77 controller.reset(new DialogSurface(result, std::move(wrapped_callback))); |
| 78 } |
| 79 |
| 80 return controller; |
| 81 } |
| 82 |
| 83 bool DialogSurfaceManager::RegisterDialogSurfaceManager(JNIEnv* env) { |
| 84 return RegisterNativesImpl(env); |
| 85 } |
| 86 |
| 87 } // namespace media |
OLD | NEW |