现在的位置: 首页 > 综合 > 正文

Texture and Surface

2013年03月28日 ⁄ 综合 ⁄ 共 3926字 ⁄ 字号 评论关闭
Texture
SurfaceTextureClient(ANativeWindow) .... SurfaceTexture...Server
1. SurfaceTexture Server and SurfaceTextureClient
Server, render the data ; client provide the data; they share a buffer.
client:surface
server:  ISurfaceTexture<-BnSurfaceTexture<-SurfaceTexture
ISurfaceTexture<-BnSurfaceTexture<-SurfaceTexture
ISurfaceTexture<-BpSurfaceTexture
(a surface must has a surfaceTexture)
2. SurfaceTextureClient member
a.sp<ISurfaceTexture> mSurfaceTexture, pointer to the server. all call the server will use it as proxy.
b.sp<GraphicBuffer> mSlots[NUM_BUFFER_SLOTS]; //the buffer shared between client and server
server provider buffer, client get the pointer(maybe null, should request first) and fill it, server the use it to render.
3. SurfaceTextureClient function ()
SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer)
//client empty a buffer put to the parameter, also get a new buffer id from server. also request the buffer of the id if necessary.
4. SurfaceTexture's function
connect //it will be called from the client.
disconnect
queueBuffer
dequeueBuffer //dequeueBuffer gets the next buffer slot index for the client to use
requestBuffer // 
5. SurfaceTexture's membership
6. SurfaceTexture, an implementation of SurfaceTexture.
connect //it can connect to many api. 
queueBuffer// in queueBufffer, "listener->onFrameAvailable()" will be called.
7.Surface , an implementation of SurfaceTextureClient
Surface.java
<--->android_view_Surface.cpp
surface is a SurfaceTextureClient
1. construction

a.null 

b.SurfaceTexture Surface(SurfaceTexture surfaceTexture)
    image drawn to the surface may be available to the SurfaceTexture, which can attach them to the OpenGL ES via SurfaceTexture's updateTexImage.
    surfaceTexture, the surfaceTexture that is updated by the surface.
c.Parcel 
d.SurfaceSession

2. Member
 private Canvas mCanvas;
int mSurfaceControl; //The mSurfaceControl will only be present for Surfaces used by the window server.? the c's SurfaceControl pointer.
3. Function
void freezeDisplay(int display)
void unfreezeDisplay(int display)
Canvas lockCanvas(Rect dirty);//lock the rect, return the canvas to draw.
unlockCanvas(Canvas canvas); //unlock the canvas, but don't update
unlockCanvasAndPost(Canvas canvas); //unlock the canvas and update
 SurfaceView
1.SurfaceView.getHolder().getSurface() will return the surface.
2.SurfaceView's membership
a.Surface mSurface;
b.WindowManager.LayoutParams mLayout;
c.IWindowSession mSession;
d.MyWindow mWindow;
e.Rect mSurfaceFrame;
f.ReentrantLock mSurfaceLock;
g.SurfaceHolder mSurfaceHolder;surfaceCreated(mSurfaceHolder),surfaceChanged(mSurfaceHolder, mFormat, myWidth, myHeight),surfaceRedrawNeeded
all above will  be called in "updateWindow."
GLSurfaceView
1.A GLSurfaceView provides the following features:
a.Manages a surface,which is a special piece of memory that can be composited into the Android view system.
b.Manages an EGL display, which enables OpenGL to render into a surface.
c.Accepts a user-provided Renderer object that does the actual rendering.
d.Renders on a dedicated thread to decouple rendering performance from the UI thread.
e.Supports both on-demand and continuous rendering.
a.unlike a regular View, drawing is delegated to a separate Renderer object.
2.membership in GLSurfaceView
GLThread mGLThread; the render thread.
Renderer mRenderer; the render.
3.function in GLSurfaceView
flash to surfacetexture(java)
1.
flashwirtedata->SurfaceTextureClient.queueBuffer->SurfaceTexture.queueBuffer->listener.onFrameAvailable
for java: JNISurfaceTextureContext.onFrameAvailable->SurfaceTexture.java.postEventFromNative->mOnFrameAvailableListener.onFrameAvailable
for cpp: MediaListener.onFrameAvailable->View.postInvalid&FramerateCallbackProc
->handle to flash? (maybe WebView.drawGL)
->GLWebViewState.drawGL->BaseLayerAndroid.drawGL()
2.
how to use gl
a. generate a textureID.
b. generate a SurfaceTexture with the id
c.  generate a Surface with the SurfaceTexture
cpp
1.Surface.cpp
2.SurfaceTextureClient 
SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer) {mSurfaceTexture->queueBuffer}// get buffer from self and put into server's buffer
SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer)// get the dequeue buffer id, 
3. 
SurfaceTextureClient:the class who has data to draw. The server must own a pointer of the client.

抱歉!评论已关闭.