| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/app/android/child_process_service_impl.h" | 5 #include "content/app/android/child_process_service_impl.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 #include <cpu-features.h> | 8 #include <cpu-features.h> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 SurfaceTexturePeer::InitInstance(NULL); | 49 SurfaceTexturePeer::InitInstance(NULL); |
| 50 gpu::GpuSurfaceLookup::InitInstance(NULL); | 50 gpu::GpuSurfaceLookup::InitInstance(NULL); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Overridden from SurfaceTextureManager: | 53 // Overridden from SurfaceTextureManager: |
| 54 void RegisterSurfaceTexture(int surface_texture_id, | 54 void RegisterSurfaceTexture(int surface_texture_id, |
| 55 int client_id, | 55 int client_id, |
| 56 gl::SurfaceTexture* surface_texture) override { | 56 gl::SurfaceTexture* surface_texture) override { |
| 57 JNIEnv* env = base::android::AttachCurrentThread(); | 57 JNIEnv* env = base::android::AttachCurrentThread(); |
| 58 Java_ChildProcessServiceImpl_createSurfaceTextureSurface( | 58 Java_ChildProcessServiceImpl_createSurfaceTextureSurface( |
| 59 env, | 59 env, service_impl_, surface_texture_id, client_id, |
| 60 service_impl_.obj(), | 60 surface_texture->j_surface_texture()); |
| 61 surface_texture_id, | |
| 62 client_id, | |
| 63 surface_texture->j_surface_texture().obj()); | |
| 64 } | 61 } |
| 65 void UnregisterSurfaceTexture(int surface_texture_id, | 62 void UnregisterSurfaceTexture(int surface_texture_id, |
| 66 int client_id) override { | 63 int client_id) override { |
| 67 JNIEnv* env = base::android::AttachCurrentThread(); | 64 JNIEnv* env = base::android::AttachCurrentThread(); |
| 68 Java_ChildProcessServiceImpl_destroySurfaceTextureSurface( | 65 Java_ChildProcessServiceImpl_destroySurfaceTextureSurface( |
| 69 env, service_impl_.obj(), surface_texture_id, client_id); | 66 env, service_impl_, surface_texture_id, client_id); |
| 70 } | 67 } |
| 71 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( | 68 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( |
| 72 int surface_texture_id) override { | 69 int surface_texture_id) override { |
| 73 JNIEnv* env = base::android::AttachCurrentThread(); | 70 JNIEnv* env = base::android::AttachCurrentThread(); |
| 74 gl::ScopedJavaSurface surface( | 71 gl::ScopedJavaSurface surface( |
| 75 Java_ChildProcessServiceImpl_getSurfaceTextureSurface( | 72 Java_ChildProcessServiceImpl_getSurfaceTextureSurface( |
| 76 env, service_impl_.obj(), surface_texture_id)); | 73 env, service_impl_, surface_texture_id)); |
| 77 | 74 |
| 78 if (surface.j_surface().is_null()) | 75 if (surface.j_surface().is_null()) |
| 79 return NULL; | 76 return NULL; |
| 80 | 77 |
| 81 // Note: This ensures that any local references used by | 78 // Note: This ensures that any local references used by |
| 82 // ANativeWindow_fromSurface are released immediately. This is needed as a | 79 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| 83 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 80 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
| 84 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 81 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 85 ANativeWindow* native_window = | 82 ANativeWindow* native_window = |
| 86 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | 83 ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
| 87 | 84 |
| 88 return native_window; | 85 return native_window; |
| 89 } | 86 } |
| 90 | 87 |
| 91 // Overridden from SurfaceTexturePeer: | 88 // Overridden from SurfaceTexturePeer: |
| 92 void EstablishSurfaceTexturePeer( | 89 void EstablishSurfaceTexturePeer( |
| 93 base::ProcessHandle pid, | 90 base::ProcessHandle pid, |
| 94 scoped_refptr<gl::SurfaceTexture> surface_texture, | 91 scoped_refptr<gl::SurfaceTexture> surface_texture, |
| 95 int primary_id, | 92 int primary_id, |
| 96 int secondary_id) override { | 93 int secondary_id) override { |
| 97 JNIEnv* env = base::android::AttachCurrentThread(); | 94 JNIEnv* env = base::android::AttachCurrentThread(); |
| 98 content::Java_ChildProcessServiceImpl_establishSurfaceTexturePeer( | 95 content::Java_ChildProcessServiceImpl_establishSurfaceTexturePeer( |
| 99 env, | 96 env, service_impl_, pid, surface_texture->j_surface_texture(), |
| 100 service_impl_.obj(), | 97 primary_id, secondary_id); |
| 101 pid, | |
| 102 surface_texture->j_surface_texture().obj(), | |
| 103 primary_id, | |
| 104 secondary_id); | |
| 105 } | 98 } |
| 106 | 99 |
| 107 // Overridden from GpuSurfaceLookup: | 100 // Overridden from GpuSurfaceLookup: |
| 108 gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override { | 101 gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override { |
| 109 JNIEnv* env = base::android::AttachCurrentThread(); | 102 JNIEnv* env = base::android::AttachCurrentThread(); |
| 110 gl::ScopedJavaSurface surface( | 103 gl::ScopedJavaSurface surface( |
| 111 content::Java_ChildProcessServiceImpl_getViewSurface( | 104 content::Java_ChildProcessServiceImpl_getViewSurface(env, service_impl_, |
| 112 env, service_impl_.obj(), surface_id)); | 105 surface_id)); |
| 113 | 106 |
| 114 if (surface.j_surface().is_null()) | 107 if (surface.j_surface().is_null()) |
| 115 return NULL; | 108 return NULL; |
| 116 | 109 |
| 117 // Note: This ensures that any local references used by | 110 // Note: This ensures that any local references used by |
| 118 // ANativeWindow_fromSurface are released immediately. This is needed as a | 111 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| 119 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 112 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
| 120 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 113 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 121 ANativeWindow* native_window = | 114 ANativeWindow* native_window = |
| 122 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | 115 ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
| 123 | 116 |
| 124 return native_window; | 117 return native_window; |
| 125 } | 118 } |
| 126 | 119 |
| 127 // Overridden from GpuSurfaceLookup: | 120 // Overridden from GpuSurfaceLookup: |
| 128 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override { | 121 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override { |
| 129 JNIEnv* env = base::android::AttachCurrentThread(); | 122 JNIEnv* env = base::android::AttachCurrentThread(); |
| 130 return gl::ScopedJavaSurface( | 123 return gl::ScopedJavaSurface( |
| 131 content::Java_ChildProcessServiceImpl_getViewSurface( | 124 content::Java_ChildProcessServiceImpl_getViewSurface(env, service_impl_, |
| 132 env, service_impl_.obj(), surface_id)); | 125 surface_id)); |
| 133 } | 126 } |
| 134 | 127 |
| 135 private: | 128 private: |
| 136 // The instance of org.chromium.content.app.ChildProcessServiceImpl. | 129 // The instance of org.chromium.content.app.ChildProcessServiceImpl. |
| 137 base::android::ScopedJavaGlobalRef<jobject> service_impl_; | 130 base::android::ScopedJavaGlobalRef<jobject> service_impl_; |
| 138 | 131 |
| 139 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl); | 132 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl); |
| 140 }; | 133 }; |
| 141 | 134 |
| 142 // Chrome actually uses the renderer code path for all of its child | 135 // Chrome actually uses the renderer code path for all of its child |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 174 |
| 182 bool RegisterChildProcessServiceImpl(JNIEnv* env) { | 175 bool RegisterChildProcessServiceImpl(JNIEnv* env) { |
| 183 return RegisterNativesImpl(env); | 176 return RegisterNativesImpl(env); |
| 184 } | 177 } |
| 185 | 178 |
| 186 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 179 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 187 ChildThreadImpl::ShutdownThread(); | 180 ChildThreadImpl::ShutdownThread(); |
| 188 } | 181 } |
| 189 | 182 |
| 190 } // namespace content | 183 } // namespace content |
| OLD | NEW |