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

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: nits + 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(int texture_id, bool single_buffer_mode) {
30 JNIEnv* env = base::android::AttachCurrentThread(); 30 JNIEnv* env = base::android::AttachCurrentThread();
31 j_surface_texture_.Reset( 31 j_surface_texture_.Reset(Java_SurfaceTexturePlatformWrapper_create(
32 Java_SurfaceTexturePlatformWrapper_create(env, texture_id)); 32 env, texture_id, single_buffer_mode));
33 } 33 }
34 34
35 SurfaceTexture::~SurfaceTexture() { 35 SurfaceTexture::~SurfaceTexture() {
36 JNIEnv* env = base::android::AttachCurrentThread(); 36 JNIEnv* env = base::android::AttachCurrentThread();
37 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj()); 37 Java_SurfaceTexturePlatformWrapper_destroy(env, j_surface_texture_.obj());
38 } 38 }
39 39
40 void SurfaceTexture::SetFrameAvailableCallback( 40 void SurfaceTexture::SetFrameAvailableCallback(
41 const base::Closure& callback) { 41 const base::Closure& callback) {
42 JNIEnv* env = base::android::AttachCurrentThread(); 42 JNIEnv* env = base::android::AttachCurrentThread();
43 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback( 43 Java_SurfaceTexturePlatformWrapper_setFrameAvailableCallback(
44 env, 44 env,
45 j_surface_texture_.obj(), 45 j_surface_texture_.obj(),
46 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback))); 46 reinterpret_cast<intptr_t>(new SurfaceTextureListener(callback)));
47 } 47 }
48 48
49 void SurfaceTexture::UpdateTexImage() { 49 void SurfaceTexture::UpdateTexImage() {
50 JNIEnv* env = base::android::AttachCurrentThread(); 50 JNIEnv* env = base::android::AttachCurrentThread();
51 Java_SurfaceTexturePlatformWrapper_updateTexImage(env, 51 Java_SurfaceTexturePlatformWrapper_updateTexImage(env,
52 j_surface_texture_.obj()); 52 j_surface_texture_.obj());
53 } 53 }
54 54
55 void SurfaceTexture::ReleaseTexImage() {
bulach 2014/03/10 12:32:31 should this be protected by base::android::BuildIn
reveman 2014/03/10 13:33:05 I'd prefer DCHECK(single_buffer_mode_)
56 JNIEnv* env = base::android::AttachCurrentThread();
57 Java_SurfaceTexturePlatformWrapper_releaseTexImage(env,
58 j_surface_texture_.obj());
59 }
60
55 void SurfaceTexture::GetTransformMatrix(float mtx[16]) { 61 void SurfaceTexture::GetTransformMatrix(float mtx[16]) {
56 JNIEnv* env = base::android::AttachCurrentThread(); 62 JNIEnv* env = base::android::AttachCurrentThread();
57 63
58 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix( 64 base::android::ScopedJavaLocalRef<jfloatArray> jmatrix(
59 env, env->NewFloatArray(16)); 65 env, env->NewFloatArray(16));
60 Java_SurfaceTexturePlatformWrapper_getTransformMatrix( 66 Java_SurfaceTexturePlatformWrapper_getTransformMatrix(
61 env, j_surface_texture_.obj(), jmatrix.obj()); 67 env, j_surface_texture_.obj(), jmatrix.obj());
62 68
63 jboolean is_copy; 69 jboolean is_copy;
64 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy); 70 jfloat* elements = env->GetFloatArrayElements(jmatrix.obj(), &is_copy);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 env, surface.j_surface().obj()); 113 env, surface.j_surface().obj());
108 return native_window; 114 return native_window;
109 } 115 }
110 116
111 // static 117 // static
112 bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) { 118 bool SurfaceTexture::RegisterSurfaceTexture(JNIEnv* env) {
113 return RegisterNativesImpl(env); 119 return RegisterNativesImpl(env);
114 } 120 }
115 121
116 } // namespace gfx 122 } // 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