OLD | NEW |
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 #ifndef UI_GL_ANDROID_SURFACE_TEXTURE_H_ | 5 #ifndef UI_GL_ANDROID_SURFACE_TEXTURE_H_ |
6 #define UI_GL_ANDROID_SURFACE_TEXTURE_H_ | 6 #define UI_GL_ANDROID_SURFACE_TEXTURE_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "ui/gl/gl_export.h" | 13 #include "ui/gl/gl_export.h" |
14 | 14 |
15 struct ANativeWindow; | 15 struct ANativeWindow; |
16 | 16 |
17 namespace gfx { | 17 namespace gfx { |
18 | 18 |
19 // This class serves as a bridge for native code to call java functions inside | 19 // This class serves as a bridge for native code to call java functions inside |
20 // android SurfaceTexture class. | 20 // android SurfaceTexture class. |
21 class GL_EXPORT SurfaceTexture | 21 class GL_EXPORT SurfaceTexture |
22 : public base::RefCountedThreadSafe<SurfaceTexture>{ | 22 : public base::RefCountedThreadSafe<SurfaceTexture>{ |
23 public: | 23 public: |
24 static scoped_refptr<SurfaceTexture> Create(int texture_id); | 24 static scoped_refptr<SurfaceTexture> Create(int texture_id); |
| 25 static scoped_refptr<SurfaceTexture> CreateSingleBuffered(int texture_id); |
25 | 26 |
26 // Set the listener callback, which will be invoked on the same thread that | 27 // Set the listener callback, which will be invoked on the same thread that |
27 // is being called from here for registration. | 28 // is being called from here for registration. |
28 // Note: Since callbacks come in from Java objects that might outlive objects | 29 // Note: Since callbacks come in from Java objects that might outlive objects |
29 // being referenced from the callback, the only robust way here is to create | 30 // being referenced from the callback, the only robust way here is to create |
30 // the callback from a weak pointer to your object. | 31 // the callback from a weak pointer to your object. |
31 void SetFrameAvailableCallback(const base::Closure& callback); | 32 void SetFrameAvailableCallback(const base::Closure& callback); |
32 | 33 |
33 // Update the texture image to the most recent frame from the image stream. | 34 // Update the texture image to the most recent frame from the image stream. |
34 void UpdateTexImage(); | 35 void UpdateTexImage(); |
35 | 36 |
| 37 // Release the texture content. This is needed only in single buffered mode |
| 38 // to allow the image content producer to take ownership |
| 39 // of the image buffer. |
| 40 // This is *only* supported on SurfaceTexture instantiated via |
| 41 // |CreateSingleBuffered(...)|. |
| 42 void ReleaseTexImage(); |
| 43 |
36 // Retrieve the 4x4 texture coordinate transform matrix associated with the | 44 // Retrieve the 4x4 texture coordinate transform matrix associated with the |
37 // texture image set by the most recent call to updateTexImage. | 45 // texture image set by the most recent call to updateTexImage. |
38 void GetTransformMatrix(float mtx[16]); | 46 void GetTransformMatrix(float mtx[16]); |
39 | 47 |
40 // Attach the SurfaceTexture to the texture currently bound to | 48 // Attach the SurfaceTexture to the texture currently bound to |
41 // GL_TEXTURE_EXTERNAL_OES. | 49 // GL_TEXTURE_EXTERNAL_OES. |
42 void AttachToGLContext(); | 50 void AttachToGLContext(); |
43 | 51 |
44 // Detaches the SurfaceTexture from the context that owns its current GL | 52 // Detaches the SurfaceTexture from the context that owns its current GL |
45 // texture. Must be called with that context current on the calling thread. | 53 // texture. Must be called with that context current on the calling thread. |
46 void DetachFromGLContext(); | 54 void DetachFromGLContext(); |
47 | 55 |
48 // Creates a native render surface for this surface texture. | 56 // Creates a native render surface for this surface texture. |
49 // The caller must release the underlying reference when done with the handle | 57 // The caller must release the underlying reference when done with the handle |
50 // by calling ANativeWindow_release(). | 58 // by calling ANativeWindow_release(). |
51 ANativeWindow* CreateSurface(); | 59 ANativeWindow* CreateSurface(); |
52 | 60 |
53 const base::android::JavaRef<jobject>& j_surface_texture() const { | 61 const base::android::JavaRef<jobject>& j_surface_texture() const { |
54 return j_surface_texture_; | 62 return j_surface_texture_; |
55 } | 63 } |
56 | 64 |
| 65 // This should only be used to guard the SurfaceTexture instantiated via |
| 66 // |CreateSingleBuffered(...)| |
| 67 static bool IsSingleBufferModeSupported(); |
| 68 |
57 static bool RegisterSurfaceTexture(JNIEnv* env); | 69 static bool RegisterSurfaceTexture(JNIEnv* env); |
58 | 70 |
59 protected: | 71 protected: |
60 explicit SurfaceTexture( | 72 explicit SurfaceTexture( |
61 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture); | 73 const base::android::ScopedJavaLocalRef<jobject>& j_surface_texture); |
62 | 74 |
63 private: | 75 private: |
64 friend class base::RefCountedThreadSafe<SurfaceTexture>; | 76 friend class base::RefCountedThreadSafe<SurfaceTexture>; |
65 ~SurfaceTexture(); | 77 ~SurfaceTexture(); |
66 | 78 |
67 // Java SurfaceTexture instance. | 79 // Java SurfaceTexture instance. |
68 base::android::ScopedJavaGlobalRef<jobject> j_surface_texture_; | 80 base::android::ScopedJavaGlobalRef<jobject> j_surface_texture_; |
69 | 81 |
70 DISALLOW_COPY_AND_ASSIGN(SurfaceTexture); | 82 DISALLOW_COPY_AND_ASSIGN(SurfaceTexture); |
71 }; | 83 }; |
72 | 84 |
73 } // namespace gfx | 85 } // namespace gfx |
74 | 86 |
75 #endif // UI_GL_ANDROID_SURFACE_TEXTURE_H_ | 87 #endif // UI_GL_ANDROID_SURFACE_TEXTURE_H_ |
OLD | NEW |