| 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 "components/external_video_surface/browser/android/external_video_surfa
ce_container_impl.h" | 5 #include "components/external_video_surface/browser/android/external_video_surfa
ce_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/geometry/rect_f.h" | 10 #include "ui/gfx/geometry/rect_f.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 base::android::ScopedJavaLocalRef<jobject> jcvc = cvc->GetJavaObject(); | 29 base::android::ScopedJavaLocalRef<jobject> jcvc = cvc->GetJavaObject(); |
| 30 if (jcvc.is_null()) | 30 if (jcvc.is_null()) |
| 31 return nullptr; | 31 return nullptr; |
| 32 return new ExternalVideoSurfaceContainerImpl(jcvc); | 32 return new ExternalVideoSurfaceContainerImpl(jcvc); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ExternalVideoSurfaceContainerImpl::ExternalVideoSurfaceContainerImpl( | 35 ExternalVideoSurfaceContainerImpl::ExternalVideoSurfaceContainerImpl( |
| 36 base::android::ScopedJavaLocalRef<jobject> java_content_view_core) { | 36 base::android::ScopedJavaLocalRef<jobject> java_content_view_core) { |
| 37 JNIEnv* env = AttachCurrentThread(); | 37 JNIEnv* env = AttachCurrentThread(); |
| 38 jobject_.Reset(Java_ExternalVideoSurfaceContainer_create( | 38 jobject_.Reset(Java_ExternalVideoSurfaceContainer_create( |
| 39 env, reinterpret_cast<intptr_t>(this), java_content_view_core.obj())); | 39 env, reinterpret_cast<intptr_t>(this), java_content_view_core)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() { | 42 ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() { |
| 43 JNIEnv* env = AttachCurrentThread(); | 43 JNIEnv* env = AttachCurrentThread(); |
| 44 Java_ExternalVideoSurfaceContainer_destroy(env, jobject_.obj()); | 44 Java_ExternalVideoSurfaceContainer_destroy(env, jobject_); |
| 45 jobject_.Reset(); | 45 jobject_.Reset(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void ExternalVideoSurfaceContainerImpl::RequestExternalVideoSurface( | 48 void ExternalVideoSurfaceContainerImpl::RequestExternalVideoSurface( |
| 49 int player_id, | 49 int player_id, |
| 50 const SurfaceCreatedCB& surface_created_cb, | 50 const SurfaceCreatedCB& surface_created_cb, |
| 51 const SurfaceDestroyedCB& surface_destroyed_cb) { | 51 const SurfaceDestroyedCB& surface_destroyed_cb) { |
| 52 surface_created_cb_ = surface_created_cb; | 52 surface_created_cb_ = surface_created_cb; |
| 53 surface_destroyed_cb_ = surface_destroyed_cb; | 53 surface_destroyed_cb_ = surface_destroyed_cb; |
| 54 | 54 |
| 55 JNIEnv* env = AttachCurrentThread(); | 55 JNIEnv* env = AttachCurrentThread(); |
| 56 Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface( | 56 Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface( |
| 57 env, jobject_.obj(), static_cast<jint>(player_id)); | 57 env, jobject_, static_cast<jint>(player_id)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 int ExternalVideoSurfaceContainerImpl::GetCurrentPlayerId() { | 60 int ExternalVideoSurfaceContainerImpl::GetCurrentPlayerId() { |
| 61 JNIEnv* env = AttachCurrentThread(); | 61 JNIEnv* env = AttachCurrentThread(); |
| 62 | 62 |
| 63 int current_player = static_cast<int>( | 63 int current_player = static_cast<int>( |
| 64 Java_ExternalVideoSurfaceContainer_getCurrentPlayerId( | 64 Java_ExternalVideoSurfaceContainer_getCurrentPlayerId(env, jobject_)); |
| 65 env, jobject_.obj())); | |
| 66 | 65 |
| 67 if (current_player < 0) | 66 if (current_player < 0) |
| 68 return kInvalidPlayerId; | 67 return kInvalidPlayerId; |
| 69 else | 68 else |
| 70 return current_player; | 69 return current_player; |
| 71 } | 70 } |
| 72 | 71 |
| 73 void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface( | 72 void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface( |
| 74 int player_id) { | 73 int player_id) { |
| 75 JNIEnv* env = AttachCurrentThread(); | 74 JNIEnv* env = AttachCurrentThread(); |
| 76 Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface( | 75 Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface( |
| 77 env, jobject_.obj(), static_cast<jint>(player_id)); | 76 env, jobject_, static_cast<jint>(player_id)); |
| 78 | 77 |
| 79 surface_created_cb_.Reset(); | 78 surface_created_cb_.Reset(); |
| 80 surface_destroyed_cb_.Reset(); | 79 surface_destroyed_cb_.Reset(); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void ExternalVideoSurfaceContainerImpl::OnFrameInfoUpdated() { | 82 void ExternalVideoSurfaceContainerImpl::OnFrameInfoUpdated() { |
| 84 JNIEnv* env = AttachCurrentThread(); | 83 JNIEnv* env = AttachCurrentThread(); |
| 85 Java_ExternalVideoSurfaceContainer_onFrameInfoUpdated(env, jobject_.obj()); | 84 Java_ExternalVideoSurfaceContainer_onFrameInfoUpdated(env, jobject_); |
| 86 } | 85 } |
| 87 | 86 |
| 88 void ExternalVideoSurfaceContainerImpl::OnExternalVideoSurfacePositionChanged( | 87 void ExternalVideoSurfaceContainerImpl::OnExternalVideoSurfacePositionChanged( |
| 89 int player_id, const gfx::RectF& rect) { | 88 int player_id, const gfx::RectF& rect) { |
| 90 JNIEnv* env = AttachCurrentThread(); | 89 JNIEnv* env = AttachCurrentThread(); |
| 91 Java_ExternalVideoSurfaceContainer_onExternalVideoSurfacePositionChanged( | 90 Java_ExternalVideoSurfaceContainer_onExternalVideoSurfacePositionChanged( |
| 92 env, | 91 env, jobject_, static_cast<jint>(player_id), |
| 93 jobject_.obj(), | 92 static_cast<jfloat>(rect.x()), static_cast<jfloat>(rect.y()), |
| 94 static_cast<jint>(player_id), | |
| 95 static_cast<jfloat>(rect.x()), | |
| 96 static_cast<jfloat>(rect.y()), | |
| 97 static_cast<jfloat>(rect.x() + rect.width()), | 93 static_cast<jfloat>(rect.x() + rect.width()), |
| 98 static_cast<jfloat>(rect.y() + rect.height())); | 94 static_cast<jfloat>(rect.y() + rect.height())); |
| 99 } | 95 } |
| 100 | 96 |
| 101 // Methods called from Java. | 97 // Methods called from Java. |
| 102 void ExternalVideoSurfaceContainerImpl::SurfaceCreated( | 98 void ExternalVideoSurfaceContainerImpl::SurfaceCreated( |
| 103 JNIEnv* env, | 99 JNIEnv* env, |
| 104 const JavaParamRef<jobject>& obj, | 100 const JavaParamRef<jobject>& obj, |
| 105 jint player_id, | 101 jint player_id, |
| 106 const JavaParamRef<jobject>& jsurface) { | 102 const JavaParamRef<jobject>& jsurface) { |
| 107 if (!surface_created_cb_.is_null()) | 103 if (!surface_created_cb_.is_null()) |
| 108 surface_created_cb_.Run(static_cast<int>(player_id), jsurface); | 104 surface_created_cb_.Run(static_cast<int>(player_id), jsurface); |
| 109 } | 105 } |
| 110 | 106 |
| 111 void ExternalVideoSurfaceContainerImpl::SurfaceDestroyed( | 107 void ExternalVideoSurfaceContainerImpl::SurfaceDestroyed( |
| 112 JNIEnv* env, | 108 JNIEnv* env, |
| 113 const JavaParamRef<jobject>& obj, | 109 const JavaParamRef<jobject>& obj, |
| 114 jint player_id) { | 110 jint player_id) { |
| 115 if (!surface_destroyed_cb_.is_null()) | 111 if (!surface_destroyed_cb_.is_null()) |
| 116 surface_destroyed_cb_.Run(static_cast<int>(player_id)); | 112 surface_destroyed_cb_.Run(static_cast<int>(player_id)); |
| 117 } | 113 } |
| 118 | 114 |
| 119 } // namespace external_video_surface | 115 } // namespace external_video_surface |
| OLD | NEW |