diff options
author | ycheo@chromium.org <ycheo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-21 16:08:20 +0000 |
---|---|---|
committer | ycheo@chromium.org <ycheo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-21 16:08:20 +0000 |
commit | 8b4efe95a07d17eb46c86c9a55b0878b6838f01f (patch) | |
tree | 7e0603ea1c5805f2e05bad7c00b3eac878362c5f /android_webview/native/external_video_surface_container_impl.cc | |
parent | 578d5dae5655184ce0abed013a103e6d9e9875d2 (diff) | |
download | chromium_src-8b4efe95a07d17eb46c86c9a55b0878b6838f01f.zip chromium_src-8b4efe95a07d17eb46c86c9a55b0878b6838f01f.tar.gz chromium_src-8b4efe95a07d17eb46c86c9a55b0878b6838f01f.tar.bz2 |
Enable the embedded L1/EME support in WebView.
- Add ExternalVideoSurfaceContainer which handles the external surface for the hole punching in WebView.
- Refactor the callbacks of ContentViewClient on the hole-punching to make them have the single purpose per each function.
BUG=329447
Review URL: https://codereview.chromium.org/132233042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252571 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/native/external_video_surface_container_impl.cc')
-rw-r--r-- | android_webview/native/external_video_surface_container_impl.cc | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/android_webview/native/external_video_surface_container_impl.cc b/android_webview/native/external_video_surface_container_impl.cc new file mode 100644 index 0000000..351b3ca --- /dev/null +++ b/android_webview/native/external_video_surface_container_impl.cc @@ -0,0 +1,112 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/native/external_video_surface_container_impl.h" + +#include "base/android/jni_android.h" +#include "content/public/browser/android/content_view_core.h" +#include "jni/ExternalVideoSurfaceContainer_jni.h" +#include "ui/gfx/rect_f.h" + +using android_webview::ExternalVideoSurfaceContainerImpl; +using base::android::AttachCurrentThread; +using content::ContentViewCore; + +DEFINE_WEB_CONTENTS_USER_DATA_KEY(ExternalVideoSurfaceContainerImpl); + +namespace content { + +// static +void ExternalVideoSurfaceContainer::CreateForWebContents( + WebContents* web_contents) { + WebContentsUserData<ExternalVideoSurfaceContainerImpl>::CreateForWebContents( + web_contents); +} + +// static +ExternalVideoSurfaceContainer* ExternalVideoSurfaceContainer::FromWebContents( + WebContents* web_contents) { + return WebContentsUserData<ExternalVideoSurfaceContainerImpl>:: + FromWebContents(web_contents); +} + +} // namespace content + +namespace android_webview { + +ExternalVideoSurfaceContainerImpl::ExternalVideoSurfaceContainerImpl( + content::WebContents* web_contents) { + ContentViewCore* cvc = ContentViewCore::FromWebContents(web_contents); + if (cvc) { + JNIEnv* env = AttachCurrentThread(); + jobject_.Reset( + Java_ExternalVideoSurfaceContainer_create( + env, reinterpret_cast<intptr_t>(this), cvc->GetJavaObject().obj())); + } +} + +ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() { + JNIEnv* env = AttachCurrentThread(); + Java_ExternalVideoSurfaceContainer_destroy(env, jobject_.obj()); + jobject_.Reset(); +} + +void ExternalVideoSurfaceContainerImpl::RequestExternalVideoSurface( + int player_id, + const SurfaceCreatedCB& surface_created_cb, + const SurfaceDestroyedCB& surface_destroyed_cb) { + surface_created_cb_ = surface_created_cb; + surface_destroyed_cb_ = surface_destroyed_cb; + + JNIEnv* env = AttachCurrentThread(); + Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface( + env, jobject_.obj(), static_cast<jint>(player_id)); +} + +void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface( + int player_id) { + JNIEnv* env = AttachCurrentThread(); + Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface( + env, jobject_.obj(), static_cast<jint>(player_id)); + + surface_created_cb_.Reset(); + surface_destroyed_cb_.Reset(); +} + +void ExternalVideoSurfaceContainerImpl::OnFrameInfoUpdated() { + JNIEnv* env = AttachCurrentThread(); + Java_ExternalVideoSurfaceContainer_onFrameInfoUpdated(env, jobject_.obj()); +} + +void ExternalVideoSurfaceContainerImpl::OnExternalVideoSurfacePositionChanged( + int player_id, const gfx::RectF& rect) { + JNIEnv* env = AttachCurrentThread(); + Java_ExternalVideoSurfaceContainer_onExternalVideoSurfacePositionChanged( + env, + jobject_.obj(), + static_cast<jint>(player_id), + static_cast<jfloat>(rect.x()), + static_cast<jfloat>(rect.y()), + static_cast<jfloat>(rect.x() + rect.width()), + static_cast<jfloat>(rect.y() + rect.height())); +} + +// Methods called from Java. +void ExternalVideoSurfaceContainerImpl::SurfaceCreated( + JNIEnv* env, jobject obj, jint player_id, jobject jsurface) { + if (!surface_created_cb_.is_null()) + surface_created_cb_.Run(static_cast<int>(player_id), jsurface); +} + +void ExternalVideoSurfaceContainerImpl::SurfaceDestroyed( + JNIEnv* env, jobject obj, jint player_id) { + if (!surface_destroyed_cb_.is_null()) + surface_destroyed_cb_.Run(static_cast<int>(player_id)); +} + +bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) { + return RegisterNativesImpl(env) >= 0; +} + +} // namespace android_webview |