We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / chromecast / browser / android / external_video_surface_container_impl.cc
blobe1f7e8bdab0e85916d16b713f9e89060a6ff6aa4
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 "chromecast/browser/android/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/geometry/rect_f.h"
12 namespace chromecast {
13 namespace shell {
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()));
27 ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() {
28 JNIEnv* env = base::android::AttachCurrentThread();
29 Java_ExternalVideoSurfaceContainer_destroy(env, jobject_.obj());
30 jobject_.Reset();
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;
40 JNIEnv* env = base::android::AttachCurrentThread();
41 Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface(
42 env, jobject_.obj(), static_cast<jint>(player_id));
45 int ExternalVideoSurfaceContainerImpl::GetCurrentPlayerId() {
46 JNIEnv* env = base::android::AttachCurrentThread();
48 int current_player = static_cast<int>(
49 Java_ExternalVideoSurfaceContainer_getCurrentPlayerId(
50 env, jobject_.obj()));
52 if (current_player < 0)
53 return kInvalidPlayerId;
54 else
55 return current_player;
58 void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface(
59 int player_id) {
60 JNIEnv* env = base::android::AttachCurrentThread();
61 Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface(
62 env, jobject_.obj(), static_cast<jint>(player_id));
64 surface_created_cb_.Reset();
65 surface_destroyed_cb_.Reset();
68 void ExternalVideoSurfaceContainerImpl::OnFrameInfoUpdated() {
69 JNIEnv* env = base::android::AttachCurrentThread();
70 Java_ExternalVideoSurfaceContainer_onFrameInfoUpdated(env, jobject_.obj());
73 void ExternalVideoSurfaceContainerImpl::OnExternalVideoSurfacePositionChanged(
74 int player_id, const gfx::RectF& rect) {
75 JNIEnv* env = base::android::AttachCurrentThread();
76 Java_ExternalVideoSurfaceContainer_onExternalVideoSurfacePositionChanged(
77 env,
78 jobject_.obj(),
79 static_cast<jint>(player_id),
80 static_cast<jfloat>(rect.x()),
81 static_cast<jfloat>(rect.y()),
82 static_cast<jfloat>(rect.x() + rect.width()),
83 static_cast<jfloat>(rect.y() + rect.height()));
86 // Methods called from Java.
87 void ExternalVideoSurfaceContainerImpl::SurfaceCreated(
88 JNIEnv* env, jobject obj, jint player_id, jobject jsurface) {
89 if (!surface_created_cb_.is_null())
90 surface_created_cb_.Run(static_cast<int>(player_id), jsurface);
93 void ExternalVideoSurfaceContainerImpl::SurfaceDestroyed(
94 JNIEnv* env, jobject obj, jint player_id) {
95 if (!surface_destroyed_cb_.is_null())
96 surface_destroyed_cb_.Run(static_cast<int>(player_id));
99 bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) {
100 return RegisterNativesImpl(env);
103 } // namespace shell
104 } // namespace chromecast