Chromium Code Reviews| 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/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; | |
|
boliu
2017/01/04 01:48:44
some of these are not needed, which probably means
liberato (no reviews please)
2017/01/11 22:17:57
thought i cleaned these up. sorry about that.
do
| |
| 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::Get() { | |
| 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 // Either way, we end up with an IDialogSurfaceManager here, and we don't | |
| 49 // care whether it's local or remote. | |
| 50 ScopedJavaLocalRef<jobject> unwrapped_manager( | |
| 51 gpu::DialogSurfaceLookup::GetInstance()->GetDialogSurfaceManager()); | |
| 52 | |
| 53 // Wrap the manager for access from native code. | |
| 54 j_wrapped_manager_.Reset( | |
| 55 Java_DialogSurfaceManagerWrapper_wrap(env, unwrapped_manager.obj())); | |
| 56 } | |
| 57 | |
| 58 DialogSurfaceManager::~DialogSurfaceManager() {} | |
| 59 | |
| 60 std::unique_ptr<DialogSurface> DialogSurfaceManager::CreateSurface( | |
| 61 base::ProcessHandle pid, | |
| 62 int frame_id, | |
| 63 const Config& config, | |
| 64 const DialogSurface::Callback& callback) { | |
| 65 JNIEnv* env = AttachCurrentThread(); | |
| 66 CHECK(env); | |
| 67 | |
| 68 std::unique_ptr<DialogSurfaceCallback> wrapped_callback( | |
| 69 new DialogSurfaceCallback(callback)); | |
| 70 | |
| 71 ScopedJavaGlobalRef<jobject> result( | |
| 72 Java_DialogSurfaceManagerWrapper_createSurface( | |
| 73 env, j_wrapped_manager_.obj(), pid, frame_id, wrapped_callback->obj(), | |
| 74 config.rect.x(), config.rect.y(), config.rect.width(), | |
| 75 config.rect.height())); | |
| 76 | |
| 77 std::unique_ptr<DialogSurface> surface; | |
| 78 if (result.obj() != nullptr) { | |
|
boliu
2017/01/04 01:48:44
nit: !result.is_null() reads better..
liberato (no reviews please)
2017/01/11 22:17:57
Done.
| |
| 79 surface.reset(new DialogSurface(result, std::move(wrapped_callback))); | |
| 80 } | |
| 81 | |
| 82 return surface; | |
| 83 } | |
| 84 | |
| 85 } // namespace media | |
| OLD | NEW |