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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_ANDROID_SURFACE_TEXTURE_BRIDGE_H_
6 #define CONTENT_COMMON_ANDROID_SURFACE_TEXTURE_BRIDGE_H_
10 #include "base/android/scoped_java_ref.h"
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
18 // This class serves as a bridge for native code to call java functions inside
19 // android SurfaceTexture class.
20 class SurfaceTextureBridge
21 : public base::RefCountedThreadSafe
<SurfaceTextureBridge
>{
23 explicit SurfaceTextureBridge(int texture_id
);
25 // Set the listener callback, which will be invoked on the same thread that
26 // is being called from here for registration.
27 // Note: Since callbacks come in from Java objects that might outlive objects
28 // being referenced from the callback, the only robust way here is to create
29 // the callback from a weak pointer to your object.
30 void SetFrameAvailableCallback(const base::Closure
& callback
);
32 // Update the texture image to the most recent frame from the image stream.
33 void UpdateTexImage();
35 // Retrieve the 4x4 texture coordinate transform matrix associated with the
36 // texture image set by the most recent call to updateTexImage.
37 void GetTransformMatrix(float mtx
[16]);
39 // Set the default size of the image buffers.
40 void SetDefaultBufferSize(int width
, int height
);
42 // Attach the SurfaceTexture to the given texture in the GL context that is
43 // current on the calling thread.
44 void AttachToGLContext(int texture_id
);
46 // Detaches the SurfaceTexture from the context that owns its current GL
47 // texture. Must be called with that context current on the calling thread.
48 void DetachFromGLContext();
50 // Creates a native render surface for this surface texture.
51 // The caller must release the underlying reference when done with the handle
52 // by calling ANativeWindow_release().
53 ANativeWindow
* CreateSurface();
55 int texture_id() const {
59 const base::android::JavaRef
<jobject
>& j_surface_texture() const {
60 return j_surface_texture_
;
64 friend class base::RefCountedThreadSafe
<SurfaceTextureBridge
>;
65 ~SurfaceTextureBridge();
67 const int texture_id_
;
69 // Java SurfaceTexture instance.
70 base::android::ScopedJavaGlobalRef
<jobject
> j_surface_texture_
;
72 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureBridge
);
75 } // namespace content
77 #endif // CONTENT_COMMON_ANDROID_SURFACE_TEXTURE_BRIDGE_H_