| 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.h" | 5 #include "content/app/android/child_process_service.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 26 matching lines...) Expand all Loading... |
| 37 public GpuSurfaceLookup { | 37 public GpuSurfaceLookup { |
| 38 public: | 38 public: |
| 39 // |service| is the instance of | 39 // |service| is the instance of |
| 40 // org.chromium.content.app.ChildProcessService. | 40 // org.chromium.content.app.ChildProcessService. |
| 41 explicit SurfaceTextureManagerImpl( | 41 explicit SurfaceTextureManagerImpl( |
| 42 const base::android::ScopedJavaLocalRef<jobject>& service) | 42 const base::android::ScopedJavaLocalRef<jobject>& service) |
| 43 : service_(service) { | 43 : service_(service) { |
| 44 SurfaceTexturePeer::InitInstance(this); | 44 SurfaceTexturePeer::InitInstance(this); |
| 45 GpuSurfaceLookup::InitInstance(this); | 45 GpuSurfaceLookup::InitInstance(this); |
| 46 } | 46 } |
| 47 virtual ~SurfaceTextureManagerImpl() { | 47 ~SurfaceTextureManagerImpl() override { |
| 48 SurfaceTexturePeer::InitInstance(NULL); | 48 SurfaceTexturePeer::InitInstance(NULL); |
| 49 GpuSurfaceLookup::InitInstance(NULL); | 49 GpuSurfaceLookup::InitInstance(NULL); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Overridden from SurfaceTextureManager: | 52 // Overridden from SurfaceTextureManager: |
| 53 virtual void RegisterSurfaceTexture( | 53 void RegisterSurfaceTexture(int surface_texture_id, |
| 54 int surface_texture_id, | 54 int client_id, |
| 55 int client_id, | 55 gfx::SurfaceTexture* surface_texture) override { |
| 56 gfx::SurfaceTexture* surface_texture) override { | |
| 57 JNIEnv* env = base::android::AttachCurrentThread(); | 56 JNIEnv* env = base::android::AttachCurrentThread(); |
| 58 Java_ChildProcessService_createSurfaceTextureSurface( | 57 Java_ChildProcessService_createSurfaceTextureSurface( |
| 59 env, | 58 env, |
| 60 service_.obj(), | 59 service_.obj(), |
| 61 surface_texture_id, | 60 surface_texture_id, |
| 62 client_id, | 61 client_id, |
| 63 surface_texture->j_surface_texture().obj()); | 62 surface_texture->j_surface_texture().obj()); |
| 64 } | 63 } |
| 65 virtual void UnregisterSurfaceTexture(int surface_texture_id, | 64 void UnregisterSurfaceTexture(int surface_texture_id, |
| 66 int client_id) override { | 65 int client_id) override { |
| 67 JNIEnv* env = base::android::AttachCurrentThread(); | 66 JNIEnv* env = base::android::AttachCurrentThread(); |
| 68 Java_ChildProcessService_destroySurfaceTextureSurface( | 67 Java_ChildProcessService_destroySurfaceTextureSurface( |
| 69 env, service_.obj(), surface_texture_id, client_id); | 68 env, service_.obj(), surface_texture_id, client_id); |
| 70 } | 69 } |
| 71 virtual gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( | 70 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( |
| 72 int surface_texture_id) override { | 71 int surface_texture_id) override { |
| 73 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); |
| 74 gfx::ScopedJavaSurface surface( | 73 gfx::ScopedJavaSurface surface( |
| 75 Java_ChildProcessService_getSurfaceTextureSurface(env, service_.obj(), | 74 Java_ChildProcessService_getSurfaceTextureSurface(env, service_.obj(), |
| 76 surface_texture_id)); | 75 surface_texture_id)); |
| 77 | 76 |
| 78 if (surface.j_surface().is_null()) | 77 if (surface.j_surface().is_null()) |
| 79 return NULL; | 78 return NULL; |
| 80 | 79 |
| 81 // Note: This ensures that any local references used by | 80 // Note: This ensures that any local references used by |
| 82 // ANativeWindow_fromSurface are released immediately. This is needed as a | 81 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| 83 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 82 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
| 84 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 83 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 85 ANativeWindow* native_window = | 84 ANativeWindow* native_window = |
| 86 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | 85 ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
| 87 | 86 |
| 88 return native_window; | 87 return native_window; |
| 89 } | 88 } |
| 90 | 89 |
| 91 // Overridden from SurfaceTexturePeer: | 90 // Overridden from SurfaceTexturePeer: |
| 92 virtual void EstablishSurfaceTexturePeer( | 91 void EstablishSurfaceTexturePeer( |
| 93 base::ProcessHandle pid, | 92 base::ProcessHandle pid, |
| 94 scoped_refptr<gfx::SurfaceTexture> surface_texture, | 93 scoped_refptr<gfx::SurfaceTexture> surface_texture, |
| 95 int primary_id, | 94 int primary_id, |
| 96 int secondary_id) override { | 95 int secondary_id) override { |
| 97 JNIEnv* env = base::android::AttachCurrentThread(); | 96 JNIEnv* env = base::android::AttachCurrentThread(); |
| 98 content::Java_ChildProcessService_establishSurfaceTexturePeer( | 97 content::Java_ChildProcessService_establishSurfaceTexturePeer( |
| 99 env, | 98 env, |
| 100 service_.obj(), | 99 service_.obj(), |
| 101 pid, | 100 pid, |
| 102 surface_texture->j_surface_texture().obj(), | 101 surface_texture->j_surface_texture().obj(), |
| 103 primary_id, | 102 primary_id, |
| 104 secondary_id); | 103 secondary_id); |
| 105 } | 104 } |
| 106 | 105 |
| 107 // Overridden from GpuSurfaceLookup: | 106 // Overridden from GpuSurfaceLookup: |
| 108 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override { | 107 gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override { |
| 109 JNIEnv* env = base::android::AttachCurrentThread(); | 108 JNIEnv* env = base::android::AttachCurrentThread(); |
| 110 gfx::ScopedJavaSurface surface( | 109 gfx::ScopedJavaSurface surface( |
| 111 content::Java_ChildProcessService_getViewSurface( | 110 content::Java_ChildProcessService_getViewSurface( |
| 112 env, service_.obj(), surface_id)); | 111 env, service_.obj(), surface_id)); |
| 113 | 112 |
| 114 if (surface.j_surface().is_null()) | 113 if (surface.j_surface().is_null()) |
| 115 return NULL; | 114 return NULL; |
| 116 | 115 |
| 117 // Note: This ensures that any local references used by | 116 // Note: This ensures that any local references used by |
| 118 // ANativeWindow_fromSurface are released immediately. This is needed as a | 117 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 184 |
| 186 bool RegisterChildProcessService(JNIEnv* env) { | 185 bool RegisterChildProcessService(JNIEnv* env) { |
| 187 return RegisterNativesImpl(env); | 186 return RegisterNativesImpl(env); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void ShutdownMainThread(JNIEnv* env, jobject obj) { | 189 void ShutdownMainThread(JNIEnv* env, jobject obj) { |
| 191 ChildThreadImpl::ShutdownThread(); | 190 ChildThreadImpl::ShutdownThread(); |
| 192 } | 191 } |
| 193 | 192 |
| 194 } // namespace content | 193 } // namespace content |
| OLD | NEW |