我正在编写一个Android应用程序以捕获屏幕数据,并从中制作MP4。第一步是使用一些openGL调用从屏幕上读出像素。
private void screenScrape() {
Log.d(TAG, "In screenScrape");
//read pixels from frame buffer into PBO (GL_PIXEL_PACK_BUFFER)
mySurface.queueEvent(new Runnable() {
@Override
public void run() {
Log.d(TAG, "In Screen Scrape 1");
//generate and bind buffer ID
GLES30.glGenBuffers(1, pboIds);
checkGlError("Gen Buffers");
GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, pboIds.get(0));
checkGlError("Bind Buffers");
//creates and initializes data store for PBO. Any pre-existing data store is deleted
GLES30.glBufferData(GLES30.GL_PIXEL_PACK_BUFFER, (mWidth * mHeight * 4), null, GLES30.GL_STATIC_READ);
checkGlError("Buffer Data");
glReadPixelsPBO(0, 0, mWidth, mHeight, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, 0);
checkGlError("Read Pixels");
}
});
//map PBO data into client address space
mySurface.queueEvent(new Runnable() {
@Override
public void run() {
Log.d(TAG, "In Screen Scrape 2");
//read pixels from PBO into a byte buffer for processing. Unmap buffer for use in next pass
mapBuffer = ((ByteBuffer) GLES30.glMapBufferRange(GLES30.GL_PIXEL_PACK_BUFFER, 0, 4 * mWidth * mHeight, GLES30.GL_MAP_READ_BIT)).order(ByteOrder.nativeOrder());
checkGlError("Map Buffer");
GLES30.glUnmapBuffer(GLES30.GL_PIXEL_PACK_BUFFER);
checkGlError("Unmap Buffer");
//openGL calls return pixels in a flipped format. Flip buffer so image presented right side up
for (int i = 0; i < mWidth; ++i) {
for (int j = 0; j < mHeight; ++j) {
for (int k = 0; k < 4; ++k) {
flippedBuffer.put((i + j * mWidth) * 4 + k, mapBuffer.get((i + (mHeight - 1 - j) * mWidth) * 4 + k));
}
}
}
isByteBufferEmpty(mapBuffer, "MAP BUFFER");
Log.d(TAG, "Flipped Buffer Position: " + flippedBuffer.position() + "Remaining: " + flippedBuffer.remaining() + " Limit: " + flippedBuffer.limit());
convertColorSpaceByteArray(flippedBuffer);
mapBuffer.clear();
}
});
}
mySurface
是我从输入参数初始化的GLMapsurface。
例如GLMapSurface mySurface = inputSurface
,其中inputSurface
是传递的参数。
现在,我的问题是对glMapBufferRange的调用会阻止UI。如何让此调用在后台线程中运行,从而不会阻塞UI?
我试图创建一个新的GLMapSurface
对象并将事件排队,但是它们从未执行。