OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "android_webview/native/external_video_surface_container_impl.h" | 5 #include "android_webview/native/external_video_surface_container_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "content/public/browser/android/content_view_core.h" | 8 #include "content/public/browser/android/content_view_core.h" |
9 #include "jni/ExternalVideoSurfaceContainer_jni.h" | 9 #include "jni/ExternalVideoSurfaceContainer_jni.h" |
10 #include "ui/gfx/rect_f.h" | 10 #include "ui/gfx/rect_f.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 const SurfaceCreatedCB& surface_created_cb, | 36 const SurfaceCreatedCB& surface_created_cb, |
37 const SurfaceDestroyedCB& surface_destroyed_cb) { | 37 const SurfaceDestroyedCB& surface_destroyed_cb) { |
38 surface_created_cb_ = surface_created_cb; | 38 surface_created_cb_ = surface_created_cb; |
39 surface_destroyed_cb_ = surface_destroyed_cb; | 39 surface_destroyed_cb_ = surface_destroyed_cb; |
40 | 40 |
41 JNIEnv* env = AttachCurrentThread(); | 41 JNIEnv* env = AttachCurrentThread(); |
42 Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface( | 42 Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface( |
43 env, jobject_.obj(), static_cast<jint>(player_id)); | 43 env, jobject_.obj(), static_cast<jint>(player_id)); |
44 } | 44 } |
45 | 45 |
46 int ExternalVideoSurfaceContainerImpl::GetCurrentPlayerId() { | |
47 JNIEnv* env = AttachCurrentThread(); | |
48 jclass cls = env->GetObjectClass(jobject_.obj()); | |
49 jfieldID fid = env->GetStaticFieldID(cls, "INVALID_PLAYER_ID", "I"); | |
50 int invalid_player = static_cast<int>(env->GetStaticIntField(cls, fid)); | |
boliu
2014/12/09 18:15:18
We basically never write manual jni code in chromi
| |
51 | |
52 int current_player = static_cast<int>( | |
53 Java_ExternalVideoSurfaceContainer_getCurrentPlayerId( | |
54 env, jobject_.obj())); | |
55 | |
56 if (current_player == invalid_player) | |
boliu
2014/12/09 18:15:18
You can just do if (current_player < 0) here.
| |
57 return kInvalidPlayerId; | |
58 else | |
59 return current_player; | |
60 } | |
61 | |
46 void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface( | 62 void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface( |
47 int player_id) { | 63 int player_id) { |
48 JNIEnv* env = AttachCurrentThread(); | 64 JNIEnv* env = AttachCurrentThread(); |
49 Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface( | 65 Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface( |
50 env, jobject_.obj(), static_cast<jint>(player_id)); | 66 env, jobject_.obj(), static_cast<jint>(player_id)); |
51 | 67 |
52 surface_created_cb_.Reset(); | 68 surface_created_cb_.Reset(); |
53 surface_destroyed_cb_.Reset(); | 69 surface_destroyed_cb_.Reset(); |
54 } | 70 } |
55 | 71 |
(...skipping 26 matching lines...) Expand all Loading... | |
82 JNIEnv* env, jobject obj, jint player_id) { | 98 JNIEnv* env, jobject obj, jint player_id) { |
83 if (!surface_destroyed_cb_.is_null()) | 99 if (!surface_destroyed_cb_.is_null()) |
84 surface_destroyed_cb_.Run(static_cast<int>(player_id)); | 100 surface_destroyed_cb_.Run(static_cast<int>(player_id)); |
85 } | 101 } |
86 | 102 |
87 bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) { | 103 bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) { |
88 return RegisterNativesImpl(env); | 104 return RegisterNativesImpl(env); |
89 } | 105 } |
90 | 106 |
91 } // namespace android_webview | 107 } // namespace android_webview |
OLD | NEW |