Mention the platform in the extension manifest documentation.
[chromium-blink-merge.git] / android_webview / native / external_video_surface_container_impl.cc
blob1a10ab547ac1b062f41778945d848e5e2e2c5df4
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.
5 #include "android_webview/native/external_video_surface_container_impl.h"
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"
12 using base::android::AttachCurrentThread;
13 using content::ContentViewCore;
15 namespace android_webview {
17 ExternalVideoSurfaceContainerImpl::ExternalVideoSurfaceContainerImpl(
18 content::WebContents* web_contents) {
19 ContentViewCore* cvc = ContentViewCore::FromWebContents(web_contents);
20 if (cvc) {
21 JNIEnv* env = AttachCurrentThread();
22 jobject_.Reset(
23 Java_ExternalVideoSurfaceContainer_create(
24 env, reinterpret_cast<intptr_t>(this), cvc->GetJavaObject().obj()));
28 ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() {
29 JNIEnv* env = AttachCurrentThread();
30 Java_ExternalVideoSurfaceContainer_destroy(env, jobject_.obj());
31 jobject_.Reset();
34 void ExternalVideoSurfaceContainerImpl::RequestExternalVideoSurface(
35 int player_id,
36 const SurfaceCreatedCB& surface_created_cb,
37 const SurfaceDestroyedCB& surface_destroyed_cb) {
38 surface_created_cb_ = surface_created_cb;
39 surface_destroyed_cb_ = surface_destroyed_cb;
41 JNIEnv* env = AttachCurrentThread();
42 Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface(
43 env, jobject_.obj(), static_cast<jint>(player_id));
46 void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface(
47 int player_id) {
48 JNIEnv* env = AttachCurrentThread();
49 Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface(
50 env, jobject_.obj(), static_cast<jint>(player_id));
52 surface_created_cb_.Reset();
53 surface_destroyed_cb_.Reset();
56 void ExternalVideoSurfaceContainerImpl::OnFrameInfoUpdated() {
57 JNIEnv* env = AttachCurrentThread();
58 Java_ExternalVideoSurfaceContainer_onFrameInfoUpdated(env, jobject_.obj());
61 void ExternalVideoSurfaceContainerImpl::OnExternalVideoSurfacePositionChanged(
62 int player_id, const gfx::RectF& rect) {
63 JNIEnv* env = AttachCurrentThread();
64 Java_ExternalVideoSurfaceContainer_onExternalVideoSurfacePositionChanged(
65 env,
66 jobject_.obj(),
67 static_cast<jint>(player_id),
68 static_cast<jfloat>(rect.x()),
69 static_cast<jfloat>(rect.y()),
70 static_cast<jfloat>(rect.x() + rect.width()),
71 static_cast<jfloat>(rect.y() + rect.height()));
74 // Methods called from Java.
75 void ExternalVideoSurfaceContainerImpl::SurfaceCreated(
76 JNIEnv* env, jobject obj, jint player_id, jobject jsurface) {
77 if (!surface_created_cb_.is_null())
78 surface_created_cb_.Run(static_cast<int>(player_id), jsurface);
81 void ExternalVideoSurfaceContainerImpl::SurfaceDestroyed(
82 JNIEnv* env, jobject obj, jint player_id) {
83 if (!surface_destroyed_cb_.is_null())
84 surface_destroyed_cb_.Run(static_cast<int>(player_id));
87 bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) {
88 return RegisterNativesImpl(env);
91 } // namespace android_webview