本文整理匯總了Java中android.graphics.SurfaceTexture.getTransformMatrix方法的典型用法代碼示例。如果您正苦於以下問題:Java SurfaceTexture.getTransformMatrix方法的具體用法?Java SurfaceTexture.getTransformMatrix怎麽用?Java SurfaceTexture.getTransformMatrix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.SurfaceTexture
的用法示例。
在下文中一共展示了SurfaceTexture.getTransformMatrix方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onFrameAvailable
import android.graphics.SurfaceTexture; //導入方法依賴的package包/類
@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
surfaceTexture.updateTexImage();
float[] transform = new float[16]; // TODO - avoid alloc every frame
surfaceTexture.getTransformMatrix(transform);
long timestamp = mIncomingFramePts;// surfaceTexture.getTimestamp();
if (timestamp == 0) {
// Seeing this after device is toggled off/on with power button. The
// first frame back has a zero timestamp.
//
// MPEG4Writer thinks this is cause to abort() in native code, so it's very
// important that we just ignore the frame.
return;
}
handleFrameAvailable(transform, timestamp * 1000);
}
示例2: frameAvailable
import android.graphics.SurfaceTexture; //導入方法依賴的package包/類
/**
* Tells the video recorder that a new frame is available. (Call from non-encoder thread.)
* <p>
* This function sends a message and returns immediately. This isn't sufficient -- we
* don't want the caller to latch a new frame until we're done with this one -- but we
* can get away with it so long as the input frame rate is reasonable and the encoder
* thread doesn't stall.
* <p>
* TODO: either block here until the texture has been rendered onto the encoder surface,
* or have a separate "block if still busy" method that the caller can execute immediately
* before it calls updateTexImage(). The latter is preferred because we don't want to
* stall the caller while this thread does work.
*/
public void frameAvailable(SurfaceTexture st) {
synchronized (mReadyFence) {
if (!mReady) {
return;
}
}
float[] transform = new float[16]; // TODO - avoid alloc every frame
st.getTransformMatrix(transform);
long timestamp = st.getTimestamp();
if (timestamp == 0) {
// Seeing this after device is toggled off/on with power button. The
// first frame back has a zero timestamp.
//
// MPEG4Writer thinks this is cause to abort() in native code, so it's very
// important that we just ignore the frame.
Log.w(TAG, "HEY: got SurfaceTexture with timestamp of zero");
return;
}
mHandler.sendMessage(mHandler.obtainMessage(MSG_FRAME_AVAILABLE,
(int) (timestamp >> 32), (int) timestamp, transform));
}
示例3: drawFrame
import android.graphics.SurfaceTexture; //導入方法依賴的package包/類
public void drawFrame(SurfaceTexture st, boolean invert) {
checkGlError("onDrawFrame start");
st.getTransformMatrix(mSTMatrix);
if (invert) {
mSTMatrix[5] = -mSTMatrix[5];
mSTMatrix[13] = 1.0f - mSTMatrix[13];
}
GLES20.glUseProgram(mProgram);
checkGlError("glUseProgram");
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
checkGlError("glVertexAttribPointer maPosition");
GLES20.glEnableVertexAttribArray(maPositionHandle);
checkGlError("glEnableVertexAttribArray maPositionHandle");
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
checkGlError("glVertexAttribPointer maTextureHandle");
GLES20.glEnableVertexAttribArray(maTextureHandle);
checkGlError("glEnableVertexAttribArray maTextureHandle");
GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
checkGlError("glDrawArrays");
GLES20.glFinish();
}
示例4: drawFrame
import android.graphics.SurfaceTexture; //導入方法依賴的package包/類
public void drawFrame(SurfaceTexture st) {
checkGlError("onDrawFrame start");
st.getTransformMatrix(mSTMatrix);
GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(mProgram);
checkGlError("glUseProgram");
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
checkGlError("glVertexAttribPointer maPosition");
GLES20.glEnableVertexAttribArray(maPositionHandle);
checkGlError("glEnableVertexAttribArray maPositionHandle");
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
checkGlError("glVertexAttribPointer maTextureHandle");
GLES20.glEnableVertexAttribArray(maTextureHandle);
checkGlError("glEnableVertexAttribArray maTextureHandle");
Matrix.setIdentityM(mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
checkGlError("glDrawArrays");
GLES20.glFinish();
}
示例5: glRun
import android.graphics.SurfaceTexture; //導入方法依賴的package包/類
private void glRun(){
EglHelper egl=new EglHelper();
boolean ret=egl.createGLESWithSurface(new EGLConfigAttrs(),new EGLContextAttrs(),new SurfaceTexture(1));
if(!ret){
//todo 錯誤處理
return;
}
int mInputSurfaceTextureId = GpuUtils.createTextureID(true);
SurfaceTexture mInputSurfaceTexture = new SurfaceTexture(mInputSurfaceTextureId);
Point size=mProvider.open(mInputSurfaceTexture);
AvLog.d(TAG,"Provider Opened . data size (x,y)="+size.x+"/"+size.y);
if(size.x<=0||size.y<=0){
//todo 錯誤處理
destroyGL(egl);
synchronized (LOCK){
LOCK.notifyAll();
}
return;
}
int mSourceWidth = size.x;
int mSourceHeight = size.y;
synchronized (LOCK){
LOCK.notifyAll();
}
//要求數據源提供者必須同步返回數據大小
if(mSourceWidth <=0|| mSourceHeight <=0){
error(1,"video source return inaccurate size to SurfaceTextureActuator");
return;
}
if(mRenderer==null){
mRenderer=new WrapRenderer(null);
}
FrameBuffer sourceFrame=new FrameBuffer();
mRenderer.create();
mRenderer.sizeChanged(mSourceWidth, mSourceHeight);
mRenderer.setFlag(mProvider.isLandscape()?WrapRenderer.TYPE_CAMERA:WrapRenderer.TYPE_MOVE);
//用於其他的回調
RenderBean rb=new RenderBean();
rb.egl=egl;
rb.sourceWidth= mSourceWidth;
rb.sourceHeight= mSourceHeight;
rb.endFlag=false;
rb.threadId=Thread.currentThread().getId();
AvLog.d(TAG,"Processor While Loop Entry");
//要求數據源必須同步填充SurfaceTexture,填充完成前等待
while (!mProvider.frame()&&mGLThreadFlag){
mInputSurfaceTexture.updateTexImage();
mInputSurfaceTexture.getTransformMatrix(mRenderer.getTextureMatrix());
AvLog.d(TAG,"timestamp:"+ mInputSurfaceTexture.getTimestamp());
sourceFrame.bindFrameBuffer(mSourceWidth, mSourceHeight);
GLES20.glViewport(0,0, mSourceWidth, mSourceHeight);
mRenderer.draw(mInputSurfaceTextureId);
sourceFrame.unBindFrameBuffer();
rb.textureId=sourceFrame.getCacheTextureId();
//接收數據源傳入的時間戳
rb.timeStamp=mProvider.getTimeStamp();
rb.textureTime= mInputSurfaceTexture.getTimestamp();
observable.notify(rb);
}
AvLog.d(TAG,"out of gl thread loop");
synchronized (LOCK){
rb.endFlag=true;
observable.notify(rb);
mRenderer.destroy();
destroyGL(egl);
LOCK.notifyAll();
AvLog.d(TAG,"gl thread exit");
}
}
示例6: handleMessage
import android.graphics.SurfaceTexture; //導入方法依賴的package包/類
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case WINDOW_MSG_CALCULATE_MVP_MATRIX:
Matrix.setIdentityM(mMVPMatrix, 0);
//平鋪
float scaleX = 1.0f;
float scaleY = 1.0f;
final double previewRatio = mPreviewWidth * 1.0f / mPreviewHeight;
final double viewRatio = mWidth * 1.0f / mHeight;
if (previewRatio < viewRatio) {
scaleY = (float) (mPreviewHeight * 1.0f / (mPreviewWidth / viewRatio));
} else {
scaleX = (float) (mPreviewWidth * 1.0f / (mPreviewHeight * viewRatio));
}
Matrix.scaleM(mMVPMatrix, 0, scaleX, scaleY, 1.0f);
break;
case WINDOW_MSG_ATTACH_SURFACE:
Log.d(TAG, "WINDOW_MSG_ATTACH_SURFACE");
Surface surface = (Surface) msg.obj;
mGLSurface.createSurface(surface);
mGLSurface.makeCurrent();
break;
case WINDOW_MSG_DETACH_SURFACE:
Log.d(TAG, "WINDOW_MSG_DETACH_SURFACE");
releaseGLSurface();
break;
case WINDOW_MSG_UPDATE:
Log.d(TAG, "WINDOW_MSG_UPDATE");
if (mGLSurface == null) {
return false;
}
SurfaceTexture surfaceTexture = (SurfaceTexture) msg.obj;
int textureIndex = msg.arg1;
long presentationTime = msg.getData().getLong(UPDATE_PRESENTATION_TIME_KEY);
surfaceTexture.getTransformMatrix(mTextureTransformMatrix);
mGLSurface.makeCurrent();
mGLSurfaceFilter.draw(textureIndex, mMVPMatrix, mTextureTransformMatrix);
mGLSurface.setPresentationTime(presentationTime);
mGLSurface.swapBuffers();
final CallBack callBack = mCallBack;
if (callBack != null) {
callBack.onOffScreenWindowUpdate();
}
break;
}
return true;
}
示例7: drawFrame
import android.graphics.SurfaceTexture; //導入方法依賴的package包/類
public void drawFrame(SurfaceTexture st) {
checkGlError("onDrawFrame start");
st.getTransformMatrix(mSTMatrix);
GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(mProgram);
checkGlError("glUseProgram");
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
checkGlError("glVertexAttribPointer maPosition");
GLES20.glEnableVertexAttribArray(maPositionHandle);
checkGlError("glEnableVertexAttribArray maPositionHandle");
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
checkGlError("glVertexAttribPointer maTextureHandle");
GLES20.glEnableVertexAttribArray(maTextureHandle);
checkGlError("glEnableVertexAttribArray maTextureHandle");
Matrix.setIdentityM(mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
checkGlError("glDrawArrays");
if (mFingerDown) {
float[] scratch = new float[16];
// Set the camera position (View matrix)
Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
mViewMatrix[12] = (float) (mTouchX * 2.0f / mWidth - 1.0);
mViewMatrix[13] = (float) (mTouchY * -2.0f / mHeight + 1.0);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
// Create a rotation for the triangle
// Use the following code to generate constant rotation.
// Leave this code out when using TouchEvents.
long time = SystemClock.uptimeMillis() % 4000L;
float mAngle = 0.090f * ((int) time);
Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, 1.0f);
// Combine the rotation matrix with the projection and camera view
// Note that the mMVPMatrix factor *must be first* in order
// for the matrix multiplication product to be correct.
Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0);
// Draw triangle
mTriangle.draw(scratch);
}
GLES20.glFinish();
}