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/android/dialog_surface_lookup.h" |
| 20 #include "jni/DialogSurfaceManagerWrapper_jni.h" |
| 21 #include "media/base/bit_reader.h" |
| 22 #include "media/base/decrypt_config.h" |
| 23 |
| 24 using base::android::AttachCurrentThread; |
| 25 using base::android::ConvertJavaStringToUTF8; |
| 26 using base::android::ConvertUTF8ToJavaString; |
| 27 using base::android::JavaIntArrayToIntVector; |
| 28 using base::android::ScopedJavaGlobalRef; |
| 29 using base::android::ScopedJavaLocalRef; |
| 30 |
| 31 namespace media { |
| 32 |
| 33 static base::LazyInstance<DialogSurfaceManager>::Leaky g_surface_manager = |
| 34 LAZY_INSTANCE_INITIALIZER; |
| 35 |
| 36 DialogSurfaceManager& DialogSurfaceManager::Get() { |
| 37 return g_surface_manager.Get(); |
| 38 } |
| 39 |
| 40 DialogSurfaceManager::DialogSurfaceManager() { |
| 41 JNIEnv* env = AttachCurrentThread(); |
| 42 CHECK(env); |
| 43 |
| 44 // Get the surface manager from the browser. |
| 45 // This can, in principle, be run in the gpu process if we send the window |
| 46 // token from the browser. See https://codereview.chromium.org/1967553002 . |
| 47 ScopedJavaLocalRef<jobject> unwrapped_manager( |
| 48 gpu::DialogSurfaceLookup::GetInstance()->GetDialogSurfaceManager()); |
| 49 |
| 50 // Wrap the manager for local access. |
| 51 j_wrapped_manager_.Reset( |
| 52 Java_DialogSurfaceManagerWrapper_wrap(env, unwrapped_manager.obj())); |
| 53 } |
| 54 |
| 55 DialogSurfaceManager::~DialogSurfaceManager() {} |
| 56 |
| 57 std::unique_ptr<DialogSurface> DialogSurfaceManager::CreateSurface( |
| 58 base::ProcessHandle pid, |
| 59 int frame_id, |
| 60 const Config& config, |
| 61 const DialogSurface::Callback& callback) { |
| 62 JNIEnv* env = AttachCurrentThread(); |
| 63 CHECK(env); |
| 64 |
| 65 // TODO(liberato): wrap the callback here, and send in place of the nullptr. |
| 66 // This was omitted for the first CL. |
| 67 |
| 68 ScopedJavaGlobalRef<jobject> result( |
| 69 Java_DialogSurfaceManagerWrapper_createSurface( |
| 70 env, j_wrapped_manager_.obj(), pid, frame_id, nullptr, |
| 71 config.rect.x(), config.rect.y(), config.rect.width(), |
| 72 config.rect.height())); |
| 73 // NOTE: result is always null right now. |
| 74 |
| 75 std::unique_ptr<DialogSurface> surface; |
| 76 |
| 77 return surface; |
| 78 } |
| 79 |
| 80 bool DialogSurfaceManager::RegisterDialogSurfaceManager(JNIEnv* env) { |
| 81 return RegisterNativesImpl(env); |
| 82 } |
| 83 |
| 84 } // namespace media |
OLD | NEW |