Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reading frame bitmap in window mode #831

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public abstract class MapRendererView extends FrameLayout {
/**
* Rendering global parameters
*/
private volatile boolean _frameReadingMode;
private volatile boolean _batterySavingMode;
private volatile int _maxFrameRate;
private volatile long _maxFrameTime;
Expand Down Expand Up @@ -384,6 +385,11 @@ public Bitmap getBitmap() {
_resultBitmap.copyPixelsFromBuffer(_byteBuffer);
_renderingResultIsReady = false;
}
if (_frameReadingMode) {
Matrix matrix = new Matrix();
matrix.preScale(1.0f, -1.0f);
_resultBitmap = Bitmap.createBitmap(_resultBitmap, 0, 0, _windowWidth, _windowHeight, matrix, true);
}
}
return _resultBitmap;
}
Expand Down Expand Up @@ -1488,6 +1494,29 @@ public final void dumpResourcesInfo() {
_mapRenderer.dumpResourcesInfo();
}

public final boolean enableFrameReader() {
if (_frameReadingMode || _byteBuffer != null) {
return true;
} else if (_windowWidth > 0 && _windowHeight > 0) {
synchronized (eglThread) {
_byteBuffer = ByteBuffer.allocateDirect(_windowWidth * _windowHeight * 4);
_renderingResultIsReady = false;
}
_frameReadingMode = true;
return true;
}
return false;
}

public final void disableFrameReader() {
if (_frameReadingMode) {
synchronized (eglThread) {
_byteBuffer = null;
}
_frameReadingMode = false;
}
}

public final boolean isBatterySavingModeEnabled() {
return _batterySavingMode;
}
Expand Down Expand Up @@ -2008,6 +2037,8 @@ public void onSurfaceChanged(GL10 gl, int width, int height) {
synchronized (eglThread) {
eglThread.ok = false;
eglThread.mapRenderer = _mapRenderer;
eglThread.surfaceWidth = width;
eglThread.surfaceHeight = height;
eglThread.startAndCompleteOperation(EGLThreadOperation.INITIALIZE_RENDERING);
ok = eglThread.ok;
}
Expand Down Expand Up @@ -2070,7 +2101,7 @@ public void onDrawFrame(GL10 gl) {

frameId++;

if (_byteBuffer != null) {
if (!_frameReadingMode && _byteBuffer != null) {
for (MapRendererViewListener listener : listeners) {
listener.onFrameReady(MapRendererView.this);
}
Expand Down Expand Up @@ -2425,6 +2456,9 @@ public void run() {
gl.glFlush();
if (byteBuffer != null) {
gl.glFinish();
if (_frameReadingMode) {
egl.eglSwapBuffers(display, surface);
}
synchronized (byteBuffer) {
byteBuffer.rewind();
gl.glReadPixels(0, 0, surfaceWidth, surfaceHeight,
Expand Down