Monday, April 16, 2012

eglInitialize函数用法


eglInitialize():

Name

eglInitialize — initialize an EGL display connection
初始化一个EGL显示连接。


C Specification

EGLBoolean eglInitialize(
EGLDisplay display,

EGLint * major,

EGLint * minor);


Parameters

display
Specifies the EGL display connection to initialize.
指定要初始化的EGL显示连接。
major
Returns the major version number of the EGL implementation. May be NULL.
返回EGL实现的主版本号。可以设为NULL
minor
Returns the minor version number of the EGL implementation. May be NULL.
返回EGL实现的次版本号。可以设为NULL


Description

eglInitialize initialized the EGL display connection obtained with eglGetDisplay. Initializing an already initialized EGL display connection has no effect besides returning the version numbers.
函数初始化由eglGetDisplay()函数得到的EGL显示连接。初始化已经初始化过的EGL显示连接只会返回版本号,无其他操作。


major and minor do not return values if they are specified as NULL.
majorminor被设置为NULL,则不会返回值。


Use eglTerminate to release resources associated with an EGL display connection.
使用eglTerminate()来释放一个EGL显示连接关联的资源。


Errors

EGL_FALSE is returned if eglInitialize fails, EGL_TRUE otherwise. major and minor are not modified when EGL_FALSE is returned.
若初始化失败,则返回EGL_FALSE,否则返回EGL_TRUE。当返回EGL_FALSE时,不会修改majorminor的值。


EGL_BAD_DISPLAY is generated if display is not an EGL display connection.
display不是一个EGL显示连接,那么将会生成EGL_BAD_DISPLAY错误。


EGL_NOT_INITIALIZED is generated if display cannot be initialized.
display无法初始化,则会生成EGL_NOT_INITIALIZED错误。


See Also

eglGetDisplay, eglTerminate


Copyright

Copyright © 2003-2004 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, seehttp://oss.sgi.com/projects/FreeB/.

eglGetDisplay函数用法


eglGetDisplay():

Name

eglGetDisplay - return an EGL display connection
返回一个EGL显示连接。


C Specification

EGLDisplay eglGetDisplay(NativeDisplayType native_display)

Parameters

native_display
Specifies the display to connect to. EGL_DEFAULT_DISPLAY indicates the default display.
指定要连接的显示设备。EGL_DEFAULT_DISPLAY表示默认的显示设备。

Description

eglGetDisplay obtains the EGL display connection for the native display native_display.
为显示设备native_display取得一个EGL显示连接。


If display_id is EGL_DEFAULT_DISPLAY, a default display connection is returned.
display_idEGL_DEFAULT_DISPLAY,将返回一个默认的显示连接。


If no display connection matching native_display is available, EGL_NO_DISPLAY is returned. No error is generated.
若没有匹配native_display的显示连接可用,返回EGL_NO_DISPLAY。不会产生错误。


Use eglInitialize to initialize the display connection.
使用eglInitialize来初始化显示连接。


Copyright

Copyright © 2003 Silicon Graphics, Inc.
This document is licensed under the SGI Free Software B License. For details, seehttp://oss.sgi.com/projects/FreeB/.


See Also

eglInitialize

Tuesday, April 10, 2012

eglGetConfigAttrib函数用法



Name

eglGetConfigAttrib - return information about an EGL frame buffer configuration
返回一个EGL帧缓存配置的信息.


C Specification

EGLBoolean eglGetConfigAttrib(EGLDisplay display,
    EGLConfig config,
    EGLint attribute,
    EGLint * value)

Parameters

display
Specifies the EGL display connection.
指定EGL显示连接.
config
Specifies the EGL frame buffer configuration to be queried.
指定要查询的EGL帧缓存配置.
attribute
Specifies the EGL rendering context attribute to be returned.
指定要查询的EGL渲染上下文属性.
value
Returns the requested value.
返回查询得到的值.

Description

eglGetConfigAttrib returns in value the value of attribute for config. attribute can be one of the following:
函数返回配置config的属性attribute的值value.属性attribute的值可以是:


EGL_BUFFER_SIZE
Returns the depth of the color buffer. It is the sum of EGL_RED_SIZE, EGL_GREEN_SIZE,EGL_BLUE_SIZE, and EGL_ALPHA_SIZE.
返回颜色缓冲区的深度,其值是 EGL_RED_SIZE, EGL_GREEN_SIZE,EGL_BLUE_SIZE,  EGL_ALPHA_SIZE四个值的和.

EGL_RED_SIZE
Returns the number of bits of red stored in the color buffer.
返回颜色缓冲区中红色的位数.

EGL_GREEN_SIZE
Returns the number of bits of green stored in the color buffer.
返回颜色缓冲区中绿色的位数.

EGL_BLUE_SIZE
Returns the number of bits of blue stored in the color buffer.
返回颜色缓冲区中蓝色的位数.

EGL_ALPHA_SIZE
Returns the number of bits of alpha stored in the color buffer.
返回颜色缓冲区中alpha的位数.

EGL_CONFIG_CAVEAT
Returns the caveats for the frame buffer configuration. Possible caveat values are EGL_NONE,EGL_SLOW_CONFIG, and EGL_NON_CONFORMANT.
返回帧缓存配置的警告,可能的警告值为: EGL_NONE,EGL_SLOW_CONFIG,  EGL_NON_CONFORMANT

EGL_CONFIG_ID
Returns the ID of the frame buffer configuration.
返回帧缓存配置的ID.

EGL_DEPTH_SIZE
Returns the number of bits in the depth buffer.
返回深度缓存的位数.

EGL_LEVEL
Returns the frame buffer level. Level zero is the default frame buffer. Positive levels correspond to frame buffers that overlay the default buffer and negative levels correspond to frame buffers that underlay the default buffer.
返回帧缓存层次.层次0是默认的帧缓存.正数的层次对应默认缓存之上的帧缓存,负数的层次对应默认缓存之下的帧缓存.

EGL_MAX_PBUFFER_WIDTH
Returns the maximum width of a pixel buffer surface in pixels.
返回像素缓冲区的最大宽度,以像素为单位.

EGL_MAX_PBUFFER_HEIGHT
Returns the maximum height of a pixel buffer surface in pixels.
返回像素缓冲区的最大高度,以像素为单位.

EGL_MAX_PBUFFER_PIXELS
Returns the maximum size of a pixel buffer surface in pixels.
返回像素缓冲区surface的最大size,以像素为单位.

EGL_NATIVE_RENDERABLE
Returns EGL_TRUE if native rendering APIs can render into the surface, EGL_FALSE otherwise.
如果native的渲染API能够渲染到surface,则返回EGL_TRUE;否则返回EGL_FALSE.

EGL_NATIVE_VISUAL_ID
Returns the ID of the associated native visual.
返回关联的native visualID.

EGL_NATIVE_VISUAL_TYPE
Returns the type of the associated native visual.
返回关联的native visual的类型.

EGL_PRESERVED_RESOURCES
Returns EGL_TRUE if resources are preserved across power management events, EGL_FALSE otherwise.
如果在电源管理过程中,资源被保留,返回EGL_TRUE,否则返回EGL_FALSE.

EGL_SAMPLE_BUFFERS
Returns the number of multisample buffers.
返回多采样缓存的个数.

EGL_SAMPLES
Returns the number of samples per pixel.
返回每个像素的采样个数.

EGL_STENCIL_BITS
Returns the number of bits in the stencil buffer.
返回模板缓冲区的位数.

EGL_SURFACE_TYPE
Returns the types of supported EGL surfaces.
返回支持的EGL surface类型.

EGL_TRANSPARENT_TYPE
Returns the type of supported transparency. Possible transparency values are: EGL_NONE, andEGL_TRANSPARENT_RGB.
返回支持的透明类型.可能的值为EGL_NONEEGL_TRANSPARENT_RGB.

EGL_TRANSPARENT_RED
Returns the transparent red value.
返回透明的红色的值。

EGL_TRANSPARENT_GREEN
Returns the transparent green value.
返回透明的绿色的值。

EGL_TRANSPARENT_BLUE
Returns the transparent blue value.
返回透明的蓝色的值。

Errors

EGL_FALSE is returned on failure, EGL_TRUE otherwise. value is not modified when EGL_FALSE is returned.
如果失败则返回EGL_FALSE,否则返回EGL_TRUE。如果返回EGL_FALSE,那么值value将不会被改变。


EGL_BAD_DISPLAY is generated if display is not an EGL display connection.
如果display不是EGL显示连接,将生成EGL_BAD_DISPLAY错误.


EGL_NOT_INITIALIZED is generated if display has not been initialized.
如果显示display没有被初始化,将生成EGL_NOT_INITIALIZED错误。


EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration.
如果配置config不是一个EGL帧缓存配置,生成EGL_BAD_CONFIG错误。


EGL_BAD_ATTRIBUTE is generated if attribute is not a valid frame buffer configuration attribute.
如果属性attribute不是合法的帧缓存配置属性,将会生成EGL_BAD_ATTRIBUTE错误。


Copyright

Copyright © 2003 Silicon Graphics, Inc.
This document is licensed under the SGI Free Software B License. For details, seehttp://oss.sgi.com/projects/FreeB/.

See Also

eglChooseConfig, eglGetConfigs

Friday, April 6, 2012

SurfaceTexture in Android



public class SurfaceTexture

Class Overview
Captures frames from an image stream as an OpenGL ES texture.
从一个图像流中捕获图像帧作为OpenGL ES纹理。

The image stream may come from either camera preview or video decode. A SurfaceTexture may be used in place of a SurfaceHolder when specifying the output destination of a Camera or MediaPlayer object. Doing so will cause all the frames from the image stream to be sent to the SurfaceTexture object rather than to the device's display. When updateTexImage() is called, the contents of the texture object specified when the SurfaceTexture was created are updated to contain the most recent image from the image stream. This may cause some frames of the stream to be skipped.
图像流可以来自照相机预览或视频解码。当指定CameraMediaPlayer对象的输出目标时,SurfaceTexture可以取代SurfaceHolder,这样将使得从图像流中得到的所有帧都输出到SurfaceTexture对象,而不是用于在设备上显示。当调用updateTexImage()时,用来创建SurfaceTexture的纹理对象内容被更新为包含图像流中最近的图片。这可能会使得流中的某些帧被跳过。

When sampling from the texture one should first transform the texture coordinates using the matrix queried via getTransformMatrix(float[]). The transform matrix may change each time updateTexImage() is called, so it should be re-queried each time the texture image is updated. This matrix transforms traditional 2D OpenGL ES texture coordinate column vectors of the form (s, t, 0, 1) where s and t are on the inclusive interval [0, 1] to the proper sampling location in the streamed texture. This transform compensates for any properties of the image stream source that cause it to appear different from a traditional OpenGL ES texture. For example, sampling from the bottom left corner of the image can be accomplished by transforming the column vector (0, 0, 0, 1) using the queried matrix, while sampling from the top right corner of the image can be done by transforming (1, 1, 0, 1).
当对纹理进行采样的时候,应该首先使用getTransformMatrix(float[])查询得到的矩阵来变换纹理坐标。每次调用updateTexImage()的时候,可能会导致变换矩阵发生变化,因此在纹理图像更新时需要重新查询。该矩阵将传统的2D OpenGL ES纹理坐标列向量(s,t,0,1),其中st[0,1],变换为纹理中对应的采样位置。该变换补偿了图像流中任何可能导致与传统OpenGL ES纹理有差异的属性。例如,从图像的左下角开始采样,可以通过使用查询得到的矩阵来变换列向量(0,0,0,1),而从右上角采样可以通过变换(1,1,0,1)来得到。

The texture object uses the GL_TEXTURE_EXTERNAL_OES texture target, which is defined by the GL_OES_EGL_image_external OpenGL ES extension. This limits how the texture may be used. Each time the texture is bound it must be bound to the GL_TEXTURE_EXTERNAL_OES target rather than the GL_TEXTURE_2D target. Additionally, any OpenGL ES 2.0 shader that samples from the texture must declare its use of this extension using, for example, an "#extension GL_OES_EGL_image_external : require" directive. Such shaders must also access the texture using the samplerExternalOES GLSL sampler type.
纹理对象使用GL_TEXTURE_EXTERNAL_OES作为纹理目标,其是OpenGL ES扩展GL_OES_EGL_image_external定义的。这种纹理目标会对纹理的使用方式造成一些限制。每次纹理绑定的时候,都要绑定到GL_TEXTURE_EXTERNAL_OES,而不是GL_TEXTURE_2D。而且,任何需要从纹理中采样的OpenGL ES 2.0 shader都需要声明其对此扩展的使用,例如,使用指令”#extension GL_OES_EGL_image_external:require”。这些shader也必须使用samplerExternalOES采样方式来访问纹理。

SurfaceTexture objects may be created on any thread. updateTexImage() may only be called on the thread with the OpenGL ES context that contains the texture object. The frame-available callback is called on an arbitrary thread, so unless special care is taken updateTexImage() should not be called directly from the callback.
SurfaceTexture对象可以在任何线程里创建。updateTexImage()只能在包含纹理对象的OpenGL ES上下文所在的线程里创建。可以得到帧信息的回调可以在任何线程被调用,因此在没有做必要的保护的情况下,updateTexImage()不应该直接从回调函数中调用。

Summary

Nested Classes
interface  SurfaceTexture.OnFrameAvailableListener     Callback interface for being notified that a new stream frame is available. 当新的帧流可用时通知该回调接口。
class         SurfaceTexture.OutOfResourcesException     Exception thrown when a surface couldn't be created or resized  当无法创建surface或调整surface尺寸时,抛出异常。

Public Constructors
SurfaceTexture(int texName)
Construct a new SurfaceTexture to stream images to a given OpenGL texture.
构造新的源自图像流的SurfaceTexture到给定的OpenGL纹理。

Public Methods
long getTimestamp()
Retrieve the timestamp associated with the texture image set by the most recent call to updateTexImage.
提取最近调用的updateTexImage()为纹理图像设置的时间戳。

void  getTransformMatrix(float[] mtx)
Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by the most recent call to updateTexImage.
提取最近调用的updateTexImage()为纹理图像设置的4×4的纹理坐标变换矩阵。

void  release()
release() frees all the buffers and puts the SurfaceTexture into the 'abandoned' state.
释放所有的缓冲区,将SurfaceTexture置为abandoned状态。

void  setDefaultBufferSize(int width, int height)
Set the default size of the image buffers.
设置默认的图像缓冲区大小。

void  setOnFrameAvailableListener(SurfaceTexture.OnFrameAvailableListener l)
Register a callback to be invoked when a new image frame becomes available to the SurfaceTexture.
注册一个回调函数,当新一帧图像对SurfaceTexture可用时调用。

void  updateTexImage()
Update the texture image to the most recent frame from the image stream.
更新纹理图像为从图像流中提取的最近一帧。

Protected Methods
void  finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.

[Expand]
Inherited Methods
 From class java.lang.Object
Public Constructors

public SurfaceTexture (int texName)

Since: API Level 11
Construct a new SurfaceTexture to stream images to a given OpenGL texture.
构造新的源自图像流的SurfaceTexture到给定的OpenGL纹理。

Parameters

texName the OpenGL texture object name (e.g. generated via glGenTextures)
texNameOpenGL纹理对象名字,如通过glGenTextures创建的。
Public Methods

public long getTimestamp ()

Since: API Level 14
Retrieve the timestamp associated with the texture image set by the most recent call to updateTexImage. This timestamp is in nanoseconds, and is normally monotonically increasing. The timestamp should be unaffected by time-of-day adjustments, and for a camera should be strictly monotonic but for a MediaPlayer may be reset when the position is set. The specific meaning and zero point of the timestamp depends on the source providing images to the SurfaceTexture. Unless otherwise specified by the image source, timestamps cannot generally be compared across SurfaceTexture instances, or across multiple program invocations. It is mostly useful for determining time offsets between subsequent frames.
提取最近调用的updateTexImage()为纹理图像设置的时间戳。该时间戳以纳秒为单位,通常是单调递增的。该时间戳不应受日立时间影响,对camera应该是严格单调的,但是对MediaPlayer来说,设置播放位置时可能会重置。时间戳的特殊含义以及零点位置取决于为SurfaceTexture提供图像的源。除非图像源有特殊说明,时间戳不应该在不同的SurfaceTexture实例之间,或多个程序调用之间进行比较。它主要应该用于在后续帧之间决定时间间隔。

public void getTransformMatrix (float[] mtx)

Since: API Level 11
Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by the most recent call to updateTexImage. This transform matrix maps 2D homogeneous texture coordinates of the form (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture coordinate that should be used to sample that location from the texture. Sampling the texture outside of the range of this transform is undefined. The matrix is stored in column-major order so that it may be passed directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv functions.
提取最近调用的updateTexImage()为纹理图像设置的4×4的纹理坐标变换矩阵。该变换矩阵将2D的其次纹理坐标(s,t,0,1)st[0,1]变换为对应的用于从纹理中采样的纹理坐标。在本变换的范围之外对纹理进行采样时未定义的行为。矩阵列主序存储,可以通过glLoadMatrixf()glUniformMatrix4fv()函数直接传递给OpenGL ES

Parameters

mtx  the array into which the 4x4 matrix will be stored. The array must have exactly 16 elements.
mtx用于存储4×4矩阵。该矩阵必须是16个元素。

public void release ()
Since: API Level 14
release() frees all the buffers and puts the SurfaceTexture into the 'abandoned' state. Once put in this state the SurfaceTexture can never leave it. When in the 'abandoned' state, all methods of the ISurfaceTexture interface will fail with the NO_INIT error. Note that while calling this method causes all the buffers to be freed from the perspective of the the SurfaceTexture, if there are additional references on the buffers (e.g. if a buffer is referenced by a client or by OpenGL ES as a texture) then those buffer will remain allocated. Always call this method when you are done with SurfaceTexture. Failing to do so may delay resource deallocation for a significant amount of time.
释放所有的缓冲区,将SurfaceTexture置为abandoned状态。一旦进入此状态,SurfaceTexture将不会离开此状态。一旦进入abandoned状态,ISurfaceTexture接口的所有方法都将返回NO_INIT错误。注意:调用此方法时,从SurfaceTexture的角度看,所有的缓冲区都被释放,如果仍然有其他的到缓冲区的引用(如,一缓冲区被客户端引用,或者被OpenGL ES作为纹理引用),那么该缓冲区将仍存在。当使用完SurfaceTexture之后,一定要调用此方法,否则将会导致资源重新分配被延误很长时间。

public void setDefaultBufferSize (int width, int height)

Since: API Level 15
Set the default size of the image buffers. The image producer may override the buffer size, in which case the producer-set buffer size will be used, not the default size set by this method. Both video and camera based image producers do override the size. This method may be used to set the image size when producing images with Canvas (via lockCanvas(Rect)), or OpenGL ES (via an EGLSurface). The new default buffer size will take effect the next time the image producer requests a buffer to fill. For Canvas this will be the next time lockCanvas(Rect) is called. For OpenGL ES, the EGLSurface should be destroyed (via eglDestroySurface), made not-current (via eglMakeCurrent), and then recreated (via eglCreateWindowSurface) to ensure that the new default size has taken effect. The width and height parameters must be no greater than the minimum of GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see glGetIntegerv). An error due to invalid dimensions might not be reported until updateTexImage() is called.
设置默认的图像缓冲区大小。图像提供者可能会重写缓冲区大小,这时,将使用新的缓冲区大小,而不是默认大小。基于视频和camera的图像生产者都会重写缓冲区大小。该方法可以用于设置使用Canvas(通过lockCanvas(Rect))来产生图像,或通过OpenGL ES(通过EGLSurface)来产生图像时图像的大小。新的默认缓冲区大小将会在下一次图像生产者请求填充一块缓冲区时生效。对Canvas来说,是下一次调用lockCanvas(Rect);对OpenGL ESEGLSurface应该被销毁(通过eglDestroySurface),变成非当前的(通过eglMakeCurrent),然后在重新创建(通过eglCreateWindowSurface),以保证新的默认大小生效。widthheight参数值应该不大于GL_MAX_VIEWPORT_DIMSGL_MAX_TEXTURE_SIZE(参见glGetIntegerv)。不合理的尺寸所引起的错误在updateTexImage()被调用之前不会被报告。

public void setOnFrameAvailableListener (SurfaceTexture.OnFrameAvailableListener l)

Since: API Level 11
Register a callback to be invoked when a new image frame becomes available to the SurfaceTexture. Note that this callback may be called on an arbitrary thread, so it is not safe to call updateTexImage() without first binding the OpenGL ES context to the thread invoking the callback.
注册一个回调函数,当新一帧图像对SurfaceTexture可用时调用。注意:该回调可能在任何线程被调用,因此在事先不绑定OpenGL ES上下文到调用该回调的线程就调用updateTexImage()是不安全的。

public void updateTexImage ()

Since: API Level 11
Update the texture image to the most recent frame from the image stream. This may only be called while the OpenGL ES context that owns the texture is bound to the thread. It will implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
更新纹理图像为从图像流中提取的最近一帧。只有在拥有该纹理的OpenGL ES上下文被绑定到线程之后调用。隐式绑定该纹理到GL_TEXTURE_EXTERNAL_OES纹理目标。
Protected Methods

protected void finalize ()

Since: API Level 11
Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

Throws

Throwable