diff options
author | sievers@chromium.org <sievers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-06 04:23:28 +0000 |
---|---|---|
committer | sievers@chromium.org <sievers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-06 04:23:28 +0000 |
commit | 1d01807e2f36c8700d2b81f10ddfb0acbde2873c (patch) | |
tree | b6ab8d3e54e267426ec87d16cd83c9daf663eb2b | |
parent | f8bebfb177f7c99e858c56208db69e8f48ed63ad (diff) | |
download | chromium_src-1d01807e2f36c8700d2b81f10ddfb0acbde2873c.zip chromium_src-1d01807e2f36c8700d2b81f10ddfb0acbde2873c.tar.gz chromium_src-1d01807e2f36c8700d2b81f10ddfb0acbde2873c.tar.bz2 |
Android: Remove Surface cruft
This removes unused Surface-related Java-level IPC plumbing.
What is not needed anymore is the code to pass Surfaces to child
processes. This was only used in a deprecated render path and for
MediaPlayer being instantiated in the renderer (which is not supported
anymore, it lives in the browser process now).
Review URL: https://chromiumcodereview.appspot.com/12388038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186356 0039d316-1c4b-4281-b951-d872f2087c98
36 files changed, 137 insertions, 459 deletions
diff --git a/base/android/jni_generator/jni_generator_tests.py b/base/android/jni_generator/jni_generator_tests.py index 187263c..e9171b0 100755 --- a/base/android/jni_generator/jni_generator_tests.py +++ b/base/android/jni_generator/jni_generator_tests.py @@ -1888,7 +1888,6 @@ import org.chromium.content.app.ContentMain; import org.chromium.content.browser.SandboxedProcessConnection; import org.chromium.content.common.ISandboxedProcessCallback; import org.chromium.content.common.ISandboxedProcessService; -import org.chromium.content.common.SurfaceCallback; import org.chromium.content.common.WillNotRaise.AnException; import org.chromium.content.common.WillRaise.AnException; diff --git a/content/app/android/sandboxed_process_service.cc b/content/app/android/sandboxed_process_service.cc index 6316ab8..e7118ff 100644 --- a/content/app/android/sandboxed_process_service.cc +++ b/content/app/android/sandboxed_process_service.cc @@ -36,13 +36,12 @@ class SurfaceTexturePeerSandboxedImpl : public content::SurfaceTexturePeer { virtual void EstablishSurfaceTexturePeer( base::ProcessHandle pid, - SurfaceTextureTarget type, scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, int primary_id, int secondary_id) { JNIEnv* env = base::android::AttachCurrentThread(); content::Java_SandboxedProcessService_establishSurfaceTexturePeer( - env, service_, pid, type, + env, service_, pid, surface_texture_bridge->j_surface_texture().obj(), primary_id, secondary_id); CheckException(env); diff --git a/content/browser/android/browser_jni_registrar.cc b/content/browser/android/browser_jni_registrar.cc index 435062c..e30394b 100644 --- a/content/browser/android/browser_jni_registrar.cc +++ b/content/browser/android/browser_jni_registrar.cc @@ -32,8 +32,6 @@ base::android::RegistrationMethod kContentRegisteredMethods[] = { { "AndroidLocationApiAdapter", content::AndroidLocationApiAdapter::RegisterGeolocationService }, { "AndroidBrowserProcess", content::RegisterAndroidBrowserProcess }, - { "BrowserProcessSurfaceTexture", - SurfaceTexturePeerBrowserImpl::RegisterBrowserProcessSurfaceTexture }, { "ContentSettings", content::ContentSettings::RegisterContentSettings }, { "ContentViewRenderView", content::ContentViewRenderView::RegisterContentViewRenderView }, diff --git a/content/browser/android/content_video_view.cc b/content/browser/android/content_video_view.cc index a9aced4..158749b 100644 --- a/content/browser/android/content_video_view.cc +++ b/content/browser/android/content_video_view.cc @@ -8,7 +8,6 @@ #include "base/command_line.h" #include "base/logging.h" #include "content/browser/android/media_player_manager_android.h" -#include "content/common/android/surface_callback.h" #include "content/common/android/surface_texture_peer.h" #include "content/public/common/content_switches.h" #include "jni/ContentVideoView_jni.h" diff --git a/content/browser/android/surface_texture_peer_browser_impl.cc b/content/browser/android/surface_texture_peer_browser_impl.cc index 70dcf1a..afd999b 100644 --- a/content/browser/android/surface_texture_peer_browser_impl.cc +++ b/content/browser/android/surface_texture_peer_browser_impl.cc @@ -6,16 +6,15 @@ #include "content/browser/android/media_player_manager_android.h" #include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/common/android/surface_callback.h" +#include "content/common/android/scoped_java_surface.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host.h" -#include "jni/BrowserProcessSurfaceTexture_jni.h" #include "media/base/android/media_player_bridge.h" -using base::android::MethodID; - namespace content { +namespace { + // Pass a java surface object to the MediaPlayerBridge object // identified by render process handle, render view ID and player ID. static void SetSurfacePeer( @@ -33,8 +32,6 @@ static void SetSurfacePeer( it.Advance(); } - JNIEnv* env = base::android::AttachCurrentThread(); - DCHECK(env); if (renderer_id) { RenderViewHostImpl* host = RenderViewHostImpl::FromID( renderer_id, render_view_id); @@ -43,57 +40,32 @@ static void SetSurfacePeer( host->media_player_manager()->GetPlayer(player_id); if (player && player != host->media_player_manager()->GetFullscreenPlayer()) { - base::android::ScopedJavaLocalRef<jclass> cls( - base::android::GetClass(env, "android/view/Surface")); - jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( - env, cls.obj(), "<init>", "(Landroid/graphics/SurfaceTexture;)V"); - ScopedJavaLocalRef<jobject> j_surface( - env, env->NewObject( - cls.obj(), constructor, - surface_texture_bridge->j_surface_texture().obj())); - player->SetVideoSurface(j_surface.obj()); - ReleaseSurface(j_surface.obj()); + ScopedJavaSurface surface(surface_texture_bridge.get()); + player->SetVideoSurface(surface.j_surface().obj()); } } } } -SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl( - bool player_in_render_process) - : player_in_render_process_(player_in_render_process) { +} // anonymous namespace + +SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl() { } SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() { - if (surface_.obj()) - ReleaseSurface(surface_.obj()); } void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer( base::ProcessHandle render_process_handle, - SurfaceTextureTarget type, scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, int render_view_id, int player_id) { if (!surface_texture_bridge) return; - JNIEnv* env = base::android::AttachCurrentThread(); - DCHECK(env); - if (player_in_render_process_) { - Java_BrowserProcessSurfaceTexture_establishSurfaceTexturePeer( - env, render_process_handle, type, - surface_texture_bridge->j_surface_texture().obj(), - render_view_id, player_id); - } else { - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( - &SetSurfacePeer, surface_texture_bridge, render_process_handle, - render_view_id, player_id)); - } -} - -bool SurfaceTexturePeerBrowserImpl::RegisterBrowserProcessSurfaceTexture( - JNIEnv* env) { - return RegisterNativesImpl(env); + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( + &SetSurfacePeer, surface_texture_bridge, render_process_handle, + render_view_id, player_id)); } } // namespace content diff --git a/content/browser/android/surface_texture_peer_browser_impl.h b/content/browser/android/surface_texture_peer_browser_impl.h index 9dd1c59..06c97bc 100644 --- a/content/browser/android/surface_texture_peer_browser_impl.h +++ b/content/browser/android/surface_texture_peer_browser_impl.h @@ -5,7 +5,6 @@ #ifndef CONTENT_BROWSER_ANDROID_SURFACE_TEXTURE_PEER_BROWSER_IMPL_H_ #define CONTENT_BROWSER_ANDROID_SURFACE_TEXTURE_PEER_BROWSER_IMPL_H_ -#include "base/android/scoped_java_ref.h" #include "base/compiler_specific.h" #include "content/common/android/surface_texture_peer.h" @@ -19,25 +18,17 @@ class SurfaceTexturePeerBrowserImpl : public SurfaceTexturePeer { // will send the java surface texture object to the render process through // SandboxedProcessService. Otherwise, it will pass the surface texture // to the MediaPlayerBridge object in the browser process. - explicit SurfaceTexturePeerBrowserImpl(bool player_in_render_process); + SurfaceTexturePeerBrowserImpl(); virtual ~SurfaceTexturePeerBrowserImpl(); // SurfaceTexturePeer implementation. virtual void EstablishSurfaceTexturePeer( base::ProcessHandle render_process_handle, - SurfaceTextureTarget type, scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, int render_view_id, int player_id) OVERRIDE; - static bool RegisterBrowserProcessSurfaceTexture(JNIEnv* env); - private: - // Whether the media player is in render process. - bool player_in_render_process_; - - base::android::ScopedJavaGlobalRef<jobject> surface_; - DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerBrowserImpl); }; diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc index 459dbeb..03fb379 100644 --- a/content/browser/browser_main_loop.cc +++ b/content/browser/browser_main_loop.cc @@ -402,9 +402,7 @@ void BrowserMainLoop::MainMessageLoopStart() { parts_->PostMainMessageLoopStart(); #if defined(OS_ANDROID) - SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl( - parameters_.command_line.HasSwitch( - switches::kMediaPlayerInRenderProcess))); + SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl()); DataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); #endif diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 9806638..ba0054d 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -825,7 +825,6 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( switches::kLoggingLevel, switches::kMemoryMetrics, #if defined(OS_ANDROID) - switches::kMediaPlayerInRenderProcess, switches::kNetworkCountryIso, switches::kDisableGestureRequirementForMediaPlayback, #endif diff --git a/content/common/android/common_jni_registrar.cc b/content/common/android/common_jni_registrar.cc index 3169f44..f854fd96 100644 --- a/content/common/android/common_jni_registrar.cc +++ b/content/common/android/common_jni_registrar.cc @@ -9,7 +9,6 @@ #include "content/common/android/command_line.h" #include "content/common/android/device_telephony_info.h" #include "content/common/android/hash_set.h" -#include "content/common/android/surface_callback.h" #include "content/common/android/surface_texture_listener.h" #include "content/common/android/trace_event_binding.h" @@ -19,7 +18,6 @@ base::android::RegistrationMethod kContentRegisteredMethods[] = { { "DeviceTelephonyInfo", content::DeviceTelephonyInfo::RegisterDeviceTelephonyInfo }, { "HashSet", content::RegisterHashSet }, - { "SurfaceCallback", content::RegisterSurfaceCallback }, { "SurfaceTextureListener", content::SurfaceTextureListener::RegisterSurfaceTextureListener }, { "TraceEvent", RegisterTraceEvent }, diff --git a/content/common/android/scoped_java_surface.cc b/content/common/android/scoped_java_surface.cc new file mode 100644 index 0000000..ca84f72 --- /dev/null +++ b/content/common/android/scoped_java_surface.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2013 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 "content/common/android/scoped_java_surface.h" + +#include "base/logging.h" +#include "content/common/android/surface_texture_bridge.h" +#include "jni/Surface_jni.h" + +namespace { + +bool g_jni_initialized = false; + +void RegisterNativesIfNeeded(JNIEnv* env) { + if (!g_jni_initialized) { + JNI_Surface::RegisterNativesImpl(env); + g_jni_initialized = true; + } +} + +} // anonymous namespace + +namespace content { + +ScopedJavaSurface::ScopedJavaSurface() { +} + +ScopedJavaSurface::ScopedJavaSurface( + const base::android::JavaRef<jobject>& surface) { + JNIEnv* env = base::android::AttachCurrentThread(); + RegisterNativesIfNeeded(env); + DCHECK(env->IsInstanceOf(surface.obj(), g_Surface_clazz)); + j_surface_.Reset(surface); +} + +ScopedJavaSurface::ScopedJavaSurface( + const SurfaceTextureBridge* surface_texture) { + JNIEnv* env = base::android::AttachCurrentThread(); + RegisterNativesIfNeeded(env); + ScopedJavaLocalRef<jobject> tmp(JNI_Surface::Java_Surface_Constructor( + env, surface_texture->j_surface_texture().obj())); + DCHECK(!tmp.is_null()); + j_surface_.Reset(tmp); +} + +ScopedJavaSurface::~ScopedJavaSurface() { + if (!j_surface_.is_null()) { + JNIEnv* env = base::android::AttachCurrentThread(); + JNI_Surface::Java_Surface_release(env, j_surface_.obj()); + } +} + +} // namespace content diff --git a/content/common/android/scoped_java_surface.h b/content/common/android/scoped_java_surface.h new file mode 100644 index 0000000..de0b673 --- /dev/null +++ b/content/common/android/scoped_java_surface.h @@ -0,0 +1,42 @@ +// Copyright (c) 2013 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. + +#ifndef CONTENT_COMMON_ANDROID_SCOPED_JAVA_SURFACE_H_ +#define CONTENT_COMMON_ANDROID_SCOPED_JAVA_SURFACE_H_ + +#include <jni.h> + +#include "base/android/scoped_java_ref.h" + +namespace content { + +class SurfaceTextureBridge; + +// A helper class for holding a scoped reference to a Java Surface instance. +// When going out of scope, Surface.release() is called on the Java object to +// make sure server-side references (esp. wrt graphics memory) are released. +class ScopedJavaSurface { + public: + ScopedJavaSurface(); + + // Wraps an existing Java Surface object in a ScopedJavaSurface. + explicit ScopedJavaSurface(const base::android::JavaRef<jobject>& surface); + + // Creates a Java Surface from a SurfaceTexture and wraps it in a + // ScopedJavaSurface. + explicit ScopedJavaSurface(const SurfaceTextureBridge* surface_texture); + + ~ScopedJavaSurface(); + + const base::android::JavaRef<jobject>& j_surface() const { + return j_surface_; + } + + private: + base::android::ScopedJavaGlobalRef<jobject> j_surface_; +}; + +} // namespace content + +#endif // CONTENT_COMMON_ANDROID_SCOPED_JAVA_SURFACE_H_ diff --git a/content/common/android/surface_callback.cc b/content/common/android/surface_callback.cc deleted file mode 100644 index 7bfd033..0000000 --- a/content/common/android/surface_callback.cc +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) 2012 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 "content/common/android/surface_callback.h" - -#include <android/native_window_jni.h> - -#include "base/android/jni_android.h" -#include "base/bind.h" -#include "base/lazy_instance.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/message_loop_proxy.h" -#include "base/synchronization/lock.h" -#include "base/synchronization/waitable_event.h" -#include "ui/gl/android_native_window.h" -#include "jni/SurfaceCallback_jni.h" - -using base::android::AttachCurrentThread; -using base::android::CheckException; -using base::android::GetClass; -using base::android::MethodID; -using base::WaitableEvent; -using content::SurfaceTexturePeer; - -namespace content { - -namespace { - -struct GlobalState { - base::Lock registration_lock; - // We hold a reference to a message loop proxy which handles message loop - // destruction gracefully, which is important since we post tasks from an - // arbitrary binder thread while the main thread might be shutting down. - // Also, in single-process mode we have two ChildThread objects for render - // and gpu thread, so we need to store the msg loops separately. - scoped_refptr<base::MessageLoopProxy> native_window_loop; - scoped_refptr<base::MessageLoopProxy> video_surface_loop; - NativeWindowCallback native_window_callback; - VideoSurfaceCallback video_surface_callback; -}; - -base::LazyInstance<GlobalState>::Leaky g_state = LAZY_INSTANCE_INITIALIZER; - -void RunNativeWindowCallback(int32 routing_id, - int32 renderer_id, - ANativeWindow* native_window, - WaitableEvent* completion) { - g_state.Pointer()->native_window_callback.Run( - routing_id, renderer_id, native_window, completion); -} - -void RunVideoSurfaceCallback(int32 routing_id, - int32 renderer_id, - jobject surface) { - g_state.Pointer()->video_surface_callback.Run( - routing_id, renderer_id, surface); -} - -} // namespace <anonymous> - -static void SetSurface(JNIEnv* env, jclass clazz, - jint type, - jobject surface, - jint primaryID, - jint secondaryID) { - SetSurfaceAsync(env, surface, - static_cast<SurfaceTexturePeer::SurfaceTextureTarget>(type), - primaryID, secondaryID, NULL); -} - -void ReleaseSurface(jobject surface) { - if (surface == NULL) - return; - - JNIEnv* env = AttachCurrentThread(); - CHECK(env); - - ScopedJavaLocalRef<jclass> cls(GetClass(env, "android/view/Surface")); - - jmethodID method = MethodID::Get<MethodID::TYPE_INSTANCE>( - env, cls.obj(), "release", "()V"); - - env->CallVoidMethod(surface, method); -} - -void SetSurfaceAsync(JNIEnv* env, - jobject jsurface, - SurfaceTexturePeer::SurfaceTextureTarget type, - int primary_id, - int secondary_id, - WaitableEvent* completion) { - base::AutoLock lock(g_state.Pointer()->registration_lock); - - ANativeWindow* native_window = NULL; - - if (jsurface && - type != SurfaceTexturePeer::SET_VIDEO_SURFACE_TEXTURE) { - native_window = ANativeWindow_fromSurface(env, jsurface); - ReleaseSurface(jsurface); - } - GlobalState* const global_state = g_state.Pointer(); - - switch (type) { - case SurfaceTexturePeer::SET_GPU_SURFACE_TEXTURE: { - // This should only be sent as a reaction to the renderer - // activating compositing. If the GPU process crashes, we expect this - // to be resent after the new thread is initialized. - DCHECK(global_state->native_window_loop); - global_state->native_window_loop->PostTask( - FROM_HERE, - base::Bind(&RunNativeWindowCallback, - primary_id, - static_cast<uint32_t>(secondary_id), - native_window, - completion)); - // ANativeWindow_release will be called in SetNativeWindow() - break; - } - case SurfaceTexturePeer::SET_VIDEO_SURFACE_TEXTURE: { - jobject surface = env->NewGlobalRef(jsurface); - DCHECK(global_state->video_surface_loop); - global_state->video_surface_loop->PostTask( - FROM_HERE, - base::Bind(&RunVideoSurfaceCallback, - primary_id, - secondary_id, - surface)); - break; - } - } -} - -void RegisterVideoSurfaceCallback(base::MessageLoopProxy* loop, - VideoSurfaceCallback& callback) { - GlobalState* const global_state = g_state.Pointer(); - base::AutoLock lock(global_state->registration_lock); - global_state->video_surface_loop = loop; - global_state->video_surface_callback = callback; -} - -void RegisterNativeWindowCallback(base::MessageLoopProxy* loop, - NativeWindowCallback& callback) { - GlobalState* const global_state = g_state.Pointer(); - base::AutoLock lock(global_state->registration_lock); - global_state->native_window_loop = loop; - global_state->native_window_callback = callback; -} - -bool RegisterSurfaceCallback(JNIEnv* env) { - return RegisterNativesImpl(env); -} - -} // namespace content diff --git a/content/common/android/surface_callback.h b/content/common/android/surface_callback.h deleted file mode 100644 index ff1898d..0000000 --- a/content/common/android/surface_callback.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CONTENT_COMMON_ANDROID_SURFACE_CALLBACK_H_ -#define CONTENT_COMMON_ANDROID_SURFACE_CALLBACK_H_ - -#include <jni.h> - -#include "base/callback.h" -#include "content/common/android/surface_texture_peer.h" - -struct ANativeWindow; - -namespace base { -class MessageLoopProxy; -class WaitableEvent; -} - -namespace content { - -// This file implements support for passing surface handles from Java -// to the correct thread on the native side. On Android, these surface -// handles can only be passed across processes through Java IPC (Binder), -// which means calls from Java come in on arbitrary threads. Hence the -// static nature and the need for the client to register a callback with -// the corresponding message loop. - -// Asynchronously sets the Surface. This can be called from any thread. -// The Surface will be set to the proper thread based on the type. The -// nature of primary_id and secondary_id depend on the type of surface -// and are used to route the surface to the correct client. -// This method will call release() on the jsurface object to release -// all the resources. So after calling this method, the caller should -// not use the jsurface object again. -void SetSurfaceAsync(JNIEnv* env, - jobject jsurface, - SurfaceTexturePeer::SurfaceTextureTarget type, - int primary_id, - int secondary_id, - base::WaitableEvent* completion); - -void ReleaseSurface(jobject surface); - -typedef base::Callback<void(int, int, ANativeWindow*, base::WaitableEvent*)> - NativeWindowCallback; -void RegisterNativeWindowCallback(base::MessageLoopProxy* loop, - NativeWindowCallback& callback); - -typedef base::Callback<void(int, int, jobject surface)> VideoSurfaceCallback; -void RegisterVideoSurfaceCallback(base::MessageLoopProxy* loop, - VideoSurfaceCallback& callback); - -bool RegisterSurfaceCallback(JNIEnv* env); - -} // namespace content - -#endif // CONTENT_COMMON_ANDROID_SURFACE_CALLBACK_H_ diff --git a/content/common/android/surface_texture_bridge.cc b/content/common/android/surface_texture_bridge.cc index 7026919..7f9d710 100644 --- a/content/common/android/surface_texture_bridge.cc +++ b/content/common/android/surface_texture_bridge.cc @@ -10,9 +10,9 @@ #include "base/android/build_info.h" #include "base/android/jni_android.h" #include "base/logging.h" +#include "content/common/android/scoped_java_surface.h" #include "content/common/android/surface_texture_listener.h" #include "jni/SurfaceTexture_jni.h" -#include "jni/Surface_jni.h" using base::android::AttachCurrentThread; using base::android::CheckException; @@ -25,7 +25,6 @@ bool g_jni_initialized = false; void RegisterNativesIfNeeded(JNIEnv* env) { if (!g_jni_initialized) { JNI_SurfaceTexture::RegisterNativesImpl(env); - JNI_Surface::RegisterNativesImpl(env); g_jni_initialized = true; } } @@ -139,12 +138,9 @@ void SurfaceTextureBridge::DetachFromGLContext() { ANativeWindow* SurfaceTextureBridge::CreateSurface() { JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jobject> jsurface( - JNI_Surface::Java_Surface_Constructor( - env, j_surface_texture_.obj())); - DCHECK(!jsurface.is_null()); - ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface.obj()); - JNI_Surface::Java_Surface_release(env, jsurface.obj()); + ScopedJavaSurface surface(this); + ANativeWindow* native_window = + ANativeWindow_fromSurface(env, surface.j_surface().obj()); return native_window; } diff --git a/content/common/android/surface_texture_peer.h b/content/common/android/surface_texture_peer.h index 4760127..921ff4c 100644 --- a/content/common/android/surface_texture_peer.h +++ b/content/common/android/surface_texture_peer.h @@ -12,13 +12,6 @@ namespace content { class SurfaceTexturePeer { public: - enum SurfaceTextureTarget { - // These are used in java so don't change them unless we can - // share an enum from java and remove this enum. - SET_GPU_SURFACE_TEXTURE = 0, // Contains gpu surface_texture_ and id - SET_VIDEO_SURFACE_TEXTURE = 1, // contains video surface_texture_ and id - }; - static SurfaceTexturePeer* GetInstance(); static void InitInstance(SurfaceTexturePeer* instance); @@ -27,7 +20,6 @@ class SurfaceTexturePeer { // process. virtual void EstablishSurfaceTexturePeer( base::ProcessHandle pid, - SurfaceTextureTarget type, scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, int primary_id, int secondary_id) = 0; diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc index 71ac691..62d85e9 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -912,10 +912,9 @@ void GpuChannel::OnRegisterStreamTextureProxy( } void GpuChannel::OnEstablishStreamTexture( - int32 stream_id, SurfaceTexturePeer::SurfaceTextureTarget type, - int32 primary_id, int32 secondary_id) { + int32 stream_id, int32 primary_id, int32 secondary_id) { stream_texture_manager_->EstablishStreamTexture( - stream_id, type, primary_id, secondary_id); + stream_id, primary_id, secondary_id); } #endif diff --git a/content/common/gpu/gpu_channel.h b/content/common/gpu/gpu_channel.h index 4e87588..8f21b35 100644 --- a/content/common/gpu/gpu_channel.h +++ b/content/common/gpu/gpu_channel.h @@ -177,8 +177,7 @@ class GpuChannel : public IPC::Listener, // Create a java surface texture object and send it to the renderer process // through binder thread. void OnEstablishStreamTexture( - int32 stream_id, SurfaceTexturePeer::SurfaceTextureTarget type, - int32 primary_id, int32 secondary_id); + int32 stream_id, int32 primary_id, int32 secondary_id); #endif // Collect rendering stats. diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h index 687340c..07db342 100644 --- a/content/common/gpu/gpu_messages.h +++ b/content/common/gpu/gpu_messages.h @@ -106,7 +106,6 @@ IPC_STRUCT_BEGIN(GpuStreamTextureMsg_MatrixChanged_Params) IPC_STRUCT_MEMBER(float, m32) IPC_STRUCT_MEMBER(float, m33) IPC_STRUCT_END() -IPC_ENUM_TRAITS(content::SurfaceTexturePeer::SurfaceTextureTarget) #endif IPC_STRUCT_TRAITS_BEGIN(content::DxDiagNode) @@ -438,10 +437,8 @@ IPC_SYNC_MESSAGE_CONTROL2_1(GpuChannelMsg_RegisterStreamTextureProxy, // Tells the GPU process create and send the java surface texture object to // the renderer process through the binder thread. -IPC_MESSAGE_CONTROL4(GpuChannelMsg_EstablishStreamTexture, +IPC_MESSAGE_CONTROL3(GpuChannelMsg_EstablishStreamTexture, int32, /* stream_id */ - content::SurfaceTexturePeer::SurfaceTextureTarget, - /* type */ int32, /* primary_id */ int32 /* secondary_id */) #endif diff --git a/content/common/gpu/media/android_video_decode_accelerator.cc b/content/common/gpu/media/android_video_decode_accelerator.cc index 920e69a..1f90308 100644 --- a/content/common/gpu/media/android_video_decode_accelerator.cc +++ b/content/common/gpu/media/android_video_decode_accelerator.cc @@ -4,14 +4,10 @@ #include "content/common/gpu/media/android_video_decode_accelerator.h" -#include <jni.h> - -#include "base/android/jni_android.h" -#include "base/android/scoped_java_ref.h" #include "base/bind.h" #include "base/logging.h" #include "base/message_loop.h" -#include "content/common/android/surface_callback.h" +#include "content/common/android/scoped_java_surface.h" #include "content/common/gpu/gpu_channel.h" #include "gpu/command_buffer/service/gles2_cmd_decoder.h" #include "media/base/bitstream_buffer.h" @@ -19,9 +15,6 @@ #include "media/video/picture.h" #include "ui/gl/gl_bindings.h" -using base::android::MethodID; -using base::android::ScopedJavaLocalRef; - namespace content { // Helper macros for dealing with failure. If |result| evaluates false, emit @@ -385,22 +378,12 @@ void AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { media_codec_.reset(new media::MediaCodecBridge(codec_)); - JNIEnv* env = base::android::AttachCurrentThread(); - CHECK(env); - ScopedJavaLocalRef<jclass> cls( - base::android::GetClass(env, "android/view/Surface")); - jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( - env, cls.obj(), "<init>", "(Landroid/graphics/SurfaceTexture;)V"); - ScopedJavaLocalRef<jobject> j_surface( - env, env->NewObject( - cls.obj(), constructor, - surface_texture_->j_surface_texture().obj())); - + ScopedJavaSurface surface(surface_texture_.get()); // VDA does not pass the container indicated resolution in the initialization // phase. Here, we set 720p by default. // TODO(dwkang): find out a way to remove the following hard-coded value. - media_codec_->StartVideo(codec_, gfx::Size(1280, 720), j_surface.obj()); - content::ReleaseSurface(j_surface.obj()); + media_codec_->StartVideo( + codec_, gfx::Size(1280, 720), surface.j_surface().obj()); media_codec_->GetOutputBuffers(); } diff --git a/content/common/gpu/stream_texture_manager_android.cc b/content/common/gpu/stream_texture_manager_android.cc index e073fbc..6eb7a10 100644 --- a/content/common/gpu/stream_texture_manager_android.cc +++ b/content/common/gpu/stream_texture_manager_android.cc @@ -119,15 +119,13 @@ void StreamTextureManagerAndroid::RegisterStreamTextureProxy( } void StreamTextureManagerAndroid::EstablishStreamTexture( - int32 stream_id, SurfaceTexturePeer::SurfaceTextureTarget type, - int32 primary_id, int32 secondary_id) { + int32 stream_id, int32 primary_id, int32 secondary_id) { StreamTextureAndroid* stream_texture = textures_.Lookup(stream_id); base::ProcessHandle process = channel_->renderer_pid(); if (stream_texture) { SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( process, - type, stream_texture->surface_texture_bridge(), primary_id, secondary_id); diff --git a/content/common/gpu/stream_texture_manager_android.h b/content/common/gpu/stream_texture_manager_android.h index 342ff40..e514fc9 100644 --- a/content/common/gpu/stream_texture_manager_android.h +++ b/content/common/gpu/stream_texture_manager_android.h @@ -40,8 +40,7 @@ class StreamTextureManagerAndroid : public gpu::StreamTextureManager { void RegisterStreamTextureProxy( int32 stream_id, const gfx::Size& initial_size, int32 route_id); void EstablishStreamTexture( - int32 stream_id, content::SurfaceTexturePeer::SurfaceTextureTarget type, - int32 primary_id, int32 secondary_id); + int32 stream_id, int32 primary_id, int32 secondary_id); // Send new transform matrix. void SendMatrixChanged(int route_id, diff --git a/content/content_common.gypi b/content/content_common.gypi index 92e1452..07df4dd 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -113,8 +113,8 @@ 'common/android/device_telephony_info.h', 'common/android/hash_set.cc', 'common/android/hash_set.h', - 'common/android/surface_callback.cc', - 'common/android/surface_callback.h', + 'common/android/scoped_java_surface.cc', + 'common/android/scoped_java_surface.h', 'common/android/surface_texture_bridge.cc', 'common/android/surface_texture_bridge.h', 'common/android/surface_texture_listener.cc', diff --git a/content/content_jni.gypi b/content/content_jni.gypi index 7077e1f..44ef10a 100644 --- a/content/content_jni.gypi +++ b/content/content_jni.gypi @@ -12,7 +12,6 @@ 'public/android/java/src/org/chromium/content/app/LibraryLoader.java', 'public/android/java/src/org/chromium/content/app/SandboxedProcessService.java', 'public/android/java/src/org/chromium/content/browser/AndroidBrowserProcess.java', - 'public/android/java/src/org/chromium/content/browser/BrowserProcessSurfaceTexture.java', 'public/android/java/src/org/chromium/content/browser/ContentSettings.java', 'public/android/java/src/org/chromium/content/browser/ContentVideoView.java', 'public/android/java/src/org/chromium/content/browser/ContentViewCore.java', @@ -31,7 +30,6 @@ 'public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java', 'public/android/java/src/org/chromium/content/common/CommandLine.java', 'public/android/java/src/org/chromium/content/common/DeviceTelephonyInfo.java', - 'public/android/java/src/org/chromium/content/common/SurfaceCallback.java', 'public/android/java/src/org/chromium/content/common/SurfaceTextureListener.java', 'public/android/java/src/org/chromium/content/common/TraceEvent.java', ], diff --git a/content/public/android/java/src/org/chromium/content/app/SandboxedProcessService.java b/content/public/android/java/src/org/chromium/content/app/SandboxedProcessService.java index d89cce1..13c8c58 100644 --- a/content/public/android/java/src/org/chromium/content/app/SandboxedProcessService.java +++ b/content/public/android/java/src/org/chromium/content/app/SandboxedProcessService.java @@ -25,7 +25,6 @@ import org.chromium.content.browser.SandboxedProcessConnection; import org.chromium.content.common.ISandboxedProcessCallback; import org.chromium.content.common.ISandboxedProcessService; import org.chromium.content.common.ProcessInitException; -import org.chromium.content.common.SurfaceCallback; /** * This is the base class for sandboxed services; the SandboxedProcessService0, 1.. etc @@ -94,12 +93,6 @@ public class SandboxedProcessService extends Service { } return Process.myPid(); } - - @Override - public void setSurface(int type, Surface surface, int primaryID, int secondaryID) { - // This gives up ownership of the Surface. - SurfaceCallback.setSurface(type, surface, primaryID, secondaryID); - } }; /* package */ static Context getContext() { @@ -210,7 +203,6 @@ public class SandboxedProcessService extends Service { * call to the correct process. * * @param pid Process handle of the sandboxed process to share the SurfaceTexture with. - * @param type The type of process that the SurfaceTexture is for. * @param surfaceObject The Surface or SurfaceTexture to share with the other sandboxed process. * @param primaryID Used to route the call to the correct client instance. * @param secondaryID Used to route the call to the correct client instance. @@ -218,7 +210,7 @@ public class SandboxedProcessService extends Service { @SuppressWarnings("unused") @CalledByNative private void establishSurfaceTexturePeer( - int pid, int type, Object surfaceObject, int primaryID, int secondaryID) { + int pid, Object surfaceObject, int primaryID, int secondaryID) { if (mCallback == null) { Log.e(TAG, "No callback interface has been provided."); return; @@ -236,7 +228,7 @@ public class SandboxedProcessService extends Service { return; } try { - mCallback.establishSurfacePeer(pid, type, surface, primaryID, secondaryID); + mCallback.establishSurfacePeer(pid, surface, primaryID, secondaryID); } catch (RemoteException e) { Log.e(TAG, "Unable to call establishSurfaceTexturePeer: " + e); return; diff --git a/content/public/android/java/src/org/chromium/content/browser/BrowserProcessSurfaceTexture.java b/content/public/android/java/src/org/chromium/content/browser/BrowserProcessSurfaceTexture.java deleted file mode 100644 index e22add1..0000000 --- a/content/public/android/java/src/org/chromium/content/browser/BrowserProcessSurfaceTexture.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 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. - -package org.chromium.content.browser; - -import android.graphics.SurfaceTexture; -import android.view.Surface; - -import org.chromium.base.CalledByNative; -import org.chromium.base.JNINamespace; - -@JNINamespace("content") -class BrowserProcessSurfaceTexture { - /** - * Called from native code to set up the peer surface texture producer in - * another process. - * - * @param pid Process handle of the sandboxed process to share the - * SurfaceTexture with. - * @param type The type of process that the SurfaceTexture is for. - * @param st The SurfaceTexture object to share with the sandboxed process. - * @param primaryID Used to route the call to the correct client instance. - * @param secondaryID Used to route the call to the correct client instance. - */ - @SuppressWarnings("unused") - @CalledByNative - static void establishSurfaceTexturePeer(int pid, int type, SurfaceTexture st, int primaryID, - int secondaryID) { - Surface surface = new Surface(st); - SandboxedProcessLauncher.establishSurfacePeer(pid, type, surface, primaryID, secondaryID); - - // We need to explicitly release the native resource of our newly created surface - // or the Surface class will print a warning message to the log in its finalizer. - // This should be ok to do since our caller is responsible for retaining a - // reference to the SurfaceTexture that is being sent across processes and the - // receiving end should have retained a reference before the binder call finished. - surface.release(); - } -} diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java b/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java index 7b258d2..5764e51 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java @@ -53,9 +53,6 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, private static final int MEDIA_ERROR = 100; private static final int MEDIA_INFO = 200; - // Type needs to be kept in sync with surface_texture_peer.h. - private static final int SET_VIDEO_SURFACE_TEXTURE = 1; - /** The video is streamed and its container is not valid for progressive * playback i.e the video's index (e.g moov atom) is not at the start of the * file. diff --git a/content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java b/content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java index cc84195..4ea75bd 100644 --- a/content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java +++ b/content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java @@ -257,24 +257,6 @@ public class SandboxedProcessLauncher { connection.unbindHighPriority(false); } - static void establishSurfacePeer( - int pid, int type, Surface surface, int primaryID, int secondaryID) { - Log.d(TAG, "establishSurfaceTexturePeer: pid = " + pid + ", " + - "type = " + type + ", " + - "primaryID = " + primaryID + ", " + - "secondaryID = " + secondaryID); - ISandboxedProcessService service = SandboxedProcessLauncher.getSandboxedService(pid); - if (service == null) { - Log.e(TAG, "Unable to get SandboxedProcessService from pid."); - return; - } - try { - service.setSurface(type, surface, primaryID, secondaryID); - } catch (RemoteException e) { - Log.e(TAG, "Unable to call setSurface: " + e); - } - } - /** * This implementation is used to receive callbacks from the remote service. */ @@ -288,15 +270,9 @@ public class SandboxedProcessLauncher { * to use a Handler. */ public void establishSurfacePeer( - int pid, int type, Surface surface, int primaryID, int secondaryID) { - SandboxedProcessLauncher.establishSurfacePeer(pid, type, surface, - primaryID, secondaryID); - // The SandboxProcessService now holds a reference to the - // Surface's resources, so we release our reference to it now to - // avoid waiting for the finalizer to get around to it. - if (surface != null) { - surface.release(); - } + int pid, Surface surface, int primaryID, int secondaryID) { + // TODO(sievers): This should call into native and pass the Surface to the + // right media player instance. } }; }; diff --git a/content/public/android/java/src/org/chromium/content/common/ISandboxedProcessCallback.aidl b/content/public/android/java/src/org/chromium/content/common/ISandboxedProcessCallback.aidl index 72b5535..103b6da 100644 --- a/content/public/android/java/src/org/chromium/content/common/ISandboxedProcessCallback.aidl +++ b/content/public/android/java/src/org/chromium/content/common/ISandboxedProcessCallback.aidl @@ -10,5 +10,5 @@ oneway interface ISandboxedProcessCallback { // Conduit to pass a Surface from the sandboxed renderer to the plugin. void establishSurfacePeer( - int pid, int type, in Surface surface, int primaryID, int secondaryID); + int pid, in Surface surface, int primaryID, int secondaryID); } diff --git a/content/public/android/java/src/org/chromium/content/common/ISandboxedProcessService.aidl b/content/public/android/java/src/org/chromium/content/common/ISandboxedProcessService.aidl index b8f7da3..3d7be3c 100644 --- a/content/public/android/java/src/org/chromium/content/common/ISandboxedProcessService.aidl +++ b/content/public/android/java/src/org/chromium/content/common/ISandboxedProcessService.aidl @@ -12,7 +12,4 @@ import android.os.Bundle; interface ISandboxedProcessService { // Sets up the initial IPC channel and returns the pid of the sandboxed process. int setupConnection(in Bundle args, ISandboxedProcessCallback callback); - - // Shares the Surface with the sandboxed process. - void setSurface(int type, in Surface surface, int primaryID, int secondaryID); } diff --git a/content/public/android/java/src/org/chromium/content/common/SurfaceCallback.java b/content/public/android/java/src/org/chromium/content/common/SurfaceCallback.java deleted file mode 100644 index e101933..0000000 --- a/content/public/android/java/src/org/chromium/content/common/SurfaceCallback.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 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. - -package org.chromium.content.common; - -import android.view.Surface; - -import org.chromium.base.JNINamespace; - -/* This implements the entry point for passing a Surface handle received through Binder - * back to the native code. - */ -@JNINamespace("content") -public class SurfaceCallback { - // Calling setSurface passes ownership to the callee and calls release() on the passed in - // object. - public static void setSurface(int type, Surface surface, int primaryID, int secondaryID) { - nativeSetSurface(type, surface, primaryID, secondaryID); - } - - /** - * Sets up the Surface iBinder for a producer identified by the IDs. - * - * @param type The install type for the Surface - * @param surface The parceled Surface to set. - * @param primaryID Used to identify the correct target instance. - * @param secondaryID Used to identify the correct target instance. - */ - private static native void nativeSetSurface(int type, Surface surface, - int primaryID, int secondaryID); -} diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index 11de18f..0c17b8e 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -753,9 +753,6 @@ const char kDisableMediaHistoryLogging[] = "disable-media-history"; const char kDisableGestureRequirementForMediaPlayback[] = "disable-gesture-requirement-for-media-playback"; -// Whether to run media elements in the renderer process. -const char kMediaPlayerInRenderProcess[] = "media-player-in-render-process"; - // The telephony region (ISO country code) to use in phone number detection. const char kNetworkCountryIso[] = "network-country-iso"; diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index c1a7d5e..457ab690 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -229,7 +229,6 @@ extern const char kEnableVisualWordMovement[]; CONTENT_EXPORT extern const char kUseMobileUserAgent[]; #if defined(OS_ANDROID) -extern const char kMediaPlayerInRenderProcess[]; extern const char kDisableMediaHistoryLogging[]; extern const char kDisableGestureRequirementForMediaPlayback[]; extern const char kNetworkCountryIso[]; diff --git a/content/renderer/gpu/stream_texture_host_android.cc b/content/renderer/gpu/stream_texture_host_android.cc index 2ecbe7e..a924ddc 100644 --- a/content/renderer/gpu/stream_texture_host_android.cc +++ b/content/renderer/gpu/stream_texture_host_android.cc @@ -52,13 +52,10 @@ bool StreamTextureHost::OnMessageReceived(const IPC::Message& message) { return handled; } -void StreamTextureHost::EstablishPeer( - SurfaceTexturePeer::SurfaceTextureTarget type, - int32 primary_id, int32 secondary_id) { +void StreamTextureHost::EstablishPeer(int32 primary_id, int32 secondary_id) { if (channel_.get()) { channel_->Send(new GpuChannelMsg_EstablishStreamTexture( - stream_id_, type, - primary_id, secondary_id)); + stream_id_, primary_id, secondary_id)); } } void StreamTextureHost::OnChannelError() { diff --git a/content/renderer/gpu/stream_texture_host_android.h b/content/renderer/gpu/stream_texture_host_android.h index 3fd184c..b85029d 100644 --- a/content/renderer/gpu/stream_texture_host_android.h +++ b/content/renderer/gpu/stream_texture_host_android.h @@ -41,8 +41,7 @@ class StreamTextureHost : public IPC::Listener { // Request the GPU process to create the surface texture and forward it // to the renderer process. - void EstablishPeer(SurfaceTexturePeer::SurfaceTextureTarget type, - int32 primary_id, int32 secondary_id); + void EstablishPeer(int32 primary_id, int32 secondary_id); // IPC::Channel::Listener implementation: virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; diff --git a/content/renderer/media/stream_texture_factory_impl_android.cc b/content/renderer/media/stream_texture_factory_impl_android.cc index 97327bf..ebfae20 100644 --- a/content/renderer/media/stream_texture_factory_impl_android.cc +++ b/content/renderer/media/stream_texture_factory_impl_android.cc @@ -119,8 +119,7 @@ webkit_media::StreamTextureProxy* StreamTextureFactoryImpl::CreateProxy() { void StreamTextureFactoryImpl::EstablishPeer(int stream_id, int player_id) { DCHECK(channel_.get()); channel_->Send(new GpuChannelMsg_EstablishStreamTexture( - stream_id, SurfaceTexturePeer::SET_VIDEO_SURFACE_TEXTURE, - view_id_, player_id)); + stream_id, view_id_, player_id)); } unsigned StreamTextureFactoryImpl::CreateStreamTexture(unsigned* texture_id) { diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 12b4bf4..be1a151 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2733,7 +2733,7 @@ WebMediaPlayer* RenderViewImpl::createMediaPlayer( return NULL; } - if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) { + if (cmd_line->HasSwitch(switches::kInProcessWebGL)) { if (!media_bridge_manager_.get()) { media_bridge_manager_.reset( new webkit_media::MediaPlayerBridgeManagerImpl(1)); |