| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromecast/shell/browser/android/external_video_surface_container_impl
.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "content/public/browser/android/content_view_core.h" | |
| 9 #include "jni/ExternalVideoSurfaceContainer_jni.h" | |
| 10 #include "ui/gfx/rect_f.h" | |
| 11 | |
| 12 namespace chromecast { | |
| 13 namespace shell { | |
| 14 | |
| 15 ExternalVideoSurfaceContainerImpl::ExternalVideoSurfaceContainerImpl( | |
| 16 content::WebContents* web_contents) { | |
| 17 content::ContentViewCore* cvc = | |
| 18 content::ContentViewCore::FromWebContents(web_contents); | |
| 19 if (cvc) { | |
| 20 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 21 jobject_.Reset( | |
| 22 Java_ExternalVideoSurfaceContainer_create( | |
| 23 env, reinterpret_cast<intptr_t>(this), cvc->GetJavaObject().obj())); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() { | |
| 28 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 29 Java_ExternalVideoSurfaceContainer_destroy(env, jobject_.obj()); | |
| 30 jobject_.Reset(); | |
| 31 } | |
| 32 | |
| 33 void ExternalVideoSurfaceContainerImpl::RequestExternalVideoSurface( | |
| 34 int player_id, | |
| 35 const SurfaceCreatedCB& surface_created_cb, | |
| 36 const SurfaceDestroyedCB& surface_destroyed_cb) { | |
| 37 surface_created_cb_ = surface_created_cb; | |
| 38 surface_destroyed_cb_ = surface_destroyed_cb; | |
| 39 | |
| 40 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 41 Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface( | |
| 42 env, jobject_.obj(), static_cast<jint>(player_id)); | |
| 43 } | |
| 44 | |
| 45 void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface( | |
| 46 int player_id) { | |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 48 Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface( | |
| 49 env, jobject_.obj(), static_cast<jint>(player_id)); | |
| 50 | |
| 51 surface_created_cb_.Reset(); | |
| 52 surface_destroyed_cb_.Reset(); | |
| 53 } | |
| 54 | |
| 55 void ExternalVideoSurfaceContainerImpl::OnFrameInfoUpdated() { | |
| 56 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 57 Java_ExternalVideoSurfaceContainer_onFrameInfoUpdated(env, jobject_.obj()); | |
| 58 } | |
| 59 | |
| 60 void ExternalVideoSurfaceContainerImpl::OnExternalVideoSurfacePositionChanged( | |
| 61 int player_id, const gfx::RectF& rect) { | |
| 62 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 63 Java_ExternalVideoSurfaceContainer_onExternalVideoSurfacePositionChanged( | |
| 64 env, | |
| 65 jobject_.obj(), | |
| 66 static_cast<jint>(player_id), | |
| 67 static_cast<jfloat>(rect.x()), | |
| 68 static_cast<jfloat>(rect.y()), | |
| 69 static_cast<jfloat>(rect.x() + rect.width()), | |
| 70 static_cast<jfloat>(rect.y() + rect.height())); | |
| 71 } | |
| 72 | |
| 73 // Methods called from Java. | |
| 74 void ExternalVideoSurfaceContainerImpl::SurfaceCreated( | |
| 75 JNIEnv* env, jobject obj, jint player_id, jobject jsurface) { | |
| 76 if (!surface_created_cb_.is_null()) | |
| 77 surface_created_cb_.Run(static_cast<int>(player_id), jsurface); | |
| 78 } | |
| 79 | |
| 80 void ExternalVideoSurfaceContainerImpl::SurfaceDestroyed( | |
| 81 JNIEnv* env, jobject obj, jint player_id) { | |
| 82 if (!surface_destroyed_cb_.is_null()) | |
| 83 surface_destroyed_cb_.Run(static_cast<int>(player_id)); | |
| 84 } | |
| 85 | |
| 86 bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) { | |
| 87 return RegisterNativesImpl(env); | |
| 88 } | |
| 89 | |
| 90 } // namespace shell | |
| 91 } // namespace chromecast | |
| OLD | NEW |