Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: ui/gl/android/surface_texture.cc

Issue 191933002: This is initial API support required for enabling SurfaceTexture backed zero-copy for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sdk version check and comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/gl/android/surface_texture.h" 5 #include "ui/gl/android/surface_texture.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 8
9 // TODO(boliu): Remove this include when we move off ICS. 9 // TODO(boliu): Remove this include when we move off ICS.
10 #include "base/android/build_info.h" 10 #include "base/android/build_info.h"
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "jni/SurfaceTexturePlatformWrapper_jni.h" 13 #include "jni/SurfaceTexturePlatformWrapper_jni.h"
14 #include "ui/gl/android/scoped_java_surface.h" 14 #include "ui/gl/android/scoped_java_surface.h"
15 #include "ui/gl/android/surface_texture_listener.h" 15 #include "ui/gl/android/surface_texture_listener.h"
16 #include "ui/gl/gl_bindings.h" 16 #include "ui/gl/gl_bindings.h"
17 17
18 // TODO(boliu): Remove this method when when we move off ICS. See 18 // TODO(boliu): Remove this method when when we move off ICS. See
19 // http://crbug.com/161864. 19 // http://crbug.com/161864.
20 bool GlContextMethodsAvailable() { 20 bool GlContextMethodsAvailable() {
21 bool available = base::android::BuildInfo::GetInstance()->sdk_int() >= 16; 21 bool available = base::android::BuildInfo::GetInstance()->sdk_int() >= 16;
22 if (!available) 22 if (!available)
23 LOG(WARNING) << "Running on unsupported device: rendering may not work"; 23 LOG(WARNING) << "Running on unsupported device: rendering may not work";
24 return available; 24 return available;
25 } 25 }
26 26
27 namespace gfx { 27 namespace gfx {
28 28
29 SurfaceTexture::SurfaceTexture(int texture_id) { 29 SurfaceTexture* SurfaceTexture::Create(int texture_id) {
30 return new SurfaceTexture(texture_id, false);
31 }
32
33 SurfaceTexture* SurfaceTexture::CreateSingleBufferMode(int texture_id) {
34 DCHECK(IsSingleBufferModeSupported());
35 return new SurfaceTexture(texture_id, true);
36 }
37
38 SurfaceTexture::SurfaceTexture(int texture_id, bool single_buffer_mode) {
30 JNIEnv* env = base::android::AttachCurrentThread(); 39 JNIEnv* env = base::android::AttachCurrentThread();
31 j_surface_texture_.Reset( 40 j_surface_texture_.Reset(Java_SurfaceTexturePlatformWrapper_create(
32 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); 41 env, texture_id, single_buffer_mode));
33 } 42 }
34 43
35 SurfaceTexture::~SurfaceTexture() { 44 SurfaceTexture::~SurfaceTexture() {
36 JNIEnv* env = base::android::AttachCurrentThread(); 45 JNIEnv* env = base::android::AttachCurrentThread();
37 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj()); 46 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj());
38 } 47 }
39 48
40 void SurfaceTexture::SetFrameAvailableCallback( 49 void SurfaceTexture::SetFrameAvailableCallback(
41 const base::Closure& callback) { 50 const base::Closure& callback) {
42 JNIEnv* env = base::android::AttachCurrentThread(); 51 JNIEnv* env = base::android::AttachCurrentThread();
43 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( 52 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback(
44 env, 53 env,
45 j_surface_texture_.obj(), 54 j_surface_texture_.obj(),
46 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback))); 55 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback)));
47 } 56 }
48 57
49 void SurfaceTexture::UpdateTexImage() { 58 void SurfaceTexture::UpdateTexImage() {
50 JNIEnv* env = base::android::AttachCurrentThread(); 59 JNIEnv* env = base::android::AttachCurrentThread();
51 Java_SurfaceTexturePlatformWrapper_updateTexImage(env, 60 Java_SurfaceTexturePlatformWrapper_updateTexImage(env,
52 j_surface_texture_.obj()); 61 j_surface_texture_.obj());
53 } 62 }
54 63
64 void SurfaceTexture::ReleaseTexImage() {
65 DCHECK(IsSingleBufferModeSupported());
66 JNIEnv* env = base::android::AttachCurrentThread();
67 Java_SurfaceTexturePlatformWrapper_releaseTexImage(env,
68 j_surface_texture_.obj());
69 }
70
55 void SurfaceTexture::GetTransformMatrix(float mtx[16]) { 71 void SurfaceTexture::GetTransformMatrix(float mtx[16]) {
56 JNIEnv* env = base::android::AttachCurrentThread(); 72 JNIEnv* env = base::android::AttachCurrentThread();
57 73
58 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix( 74 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix(
59 env, env->NewFloatArray(16)); 75 env, env->NewFloatArray(16));
60 Java_SurfaceTexturePlatformWrapper_getTransformMatrix( 76 Java_SurfaceTexturePlatformWrapper_getTransformMatrix(
61 env, j_surface_texture_.obj(), jmatrix.obj()); 77 env, j_surface_texture_.obj(), jmatrix.obj());
62 78
63 jboolean is_copy; 79 jboolean is_copy;
64 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); 80 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 118
103 ANativeWindow* SurfaceTexture::CreateSurface() { 119 ANativeWindow* SurfaceTexture::CreateSurface() {
104 JNIEnv* env = base::android::AttachCurrentThread(); 120 JNIEnv* env = base::android::AttachCurrentThread();
105 ScopedJavaSurface surface(this); 121 ScopedJavaSurface surface(this);
106 ANativeWindow* native_window = ANativeWindow_fromSurface( 122 ANativeWindow* native_window = ANativeWindow_fromSurface(
107 env, surface.j_surface().obj()); 123 env, surface.j_surface().obj());
108 return native_window; 124 return native_window;
109 } 125 }
110 126
111 // static 127 // static
128 bool SurfaceTexture::IsSingleBufferModeSupported() {
129 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19;
130 }
131
112 bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) { 132 bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) {
113 return RegisterNativesImpl(env); 133 return RegisterNativesImpl(env);
114 } 134 }
115 135
116 } // namespace gfx 136 } // namespace gfx
OLDNEW
« ui/gl/android/surface_texture.h ('K') | « ui/gl/android/surface_texture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698