-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This substantially improves performance when using the OpenGL renderer
- Loading branch information
1 parent
cba1cee
commit 7f57cf5
Showing
22 changed files
with
297 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "AndroidFrameRenderedCallback.h" | ||
|
||
AndroidFrameRenderedCallback::AndroidFrameRenderedCallback(JniEnvHandler* jniEnvHandler, jobject androidFrameRenderedListener) | ||
{ | ||
this->jniEnvHandler = jniEnvHandler; | ||
this->androidFrameRenderedListener = androidFrameRenderedListener; | ||
} | ||
|
||
void AndroidFrameRenderedCallback::onFrameRendered(long syncFence, int textureId) | ||
{ | ||
JNIEnv* env = this->jniEnvHandler->getCurrentThreadEnv(); | ||
|
||
jclass listenerClass = env->GetObjectClass(this->androidFrameRenderedListener); | ||
jmethodID onFrameRenderedMethod = env->GetMethodID(listenerClass, "onFrameRendered", "(JI)V"); | ||
env->CallVoidMethod(this->androidFrameRenderedListener, onFrameRenderedMethod, syncFence, textureId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef ANDROIDFRAMERENDEREDCALLBACK_H | ||
#define ANDROIDFRAMERENDEREDCALLBACK_H | ||
|
||
#include "JniEnvHandler.h" | ||
#include <FrameRenderedCallback.h> | ||
#include <jni.h> | ||
|
||
class AndroidFrameRenderedCallback : public FrameRenderedCallback | ||
{ | ||
private: | ||
JniEnvHandler* jniEnvHandler; | ||
jobject androidFrameRenderedListener; | ||
|
||
public: | ||
AndroidFrameRenderedCallback(JniEnvHandler* jniEnvHandler, jobject androidFrameRenderedListener); | ||
void onFrameRendered(long syncFence, int textureId); | ||
}; | ||
|
||
|
||
#endif //ANDROIDFRAMERENDEREDCALLBACK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 0 additions & 76 deletions
76
app/src/main/java/me/magnum/melonds/common/runtime/FrameBufferProvider.kt
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
app/src/main/java/me/magnum/melonds/common/runtime/ScreenshotFrameBufferProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package me.magnum.melonds.common.runtime | ||
|
||
import android.graphics.Bitmap | ||
import java.nio.ByteBuffer | ||
import java.nio.ByteOrder | ||
|
||
class ScreenshotFrameBufferProvider { | ||
|
||
companion object { | ||
private const val SCREEN_WIDTH = 256 | ||
private const val SCREEN_HEIGHT = 384 | ||
} | ||
|
||
private var screenshotBuffer: ByteBuffer? = null | ||
|
||
fun frameBuffer(): ByteBuffer { | ||
return ensureBufferIsReady() | ||
} | ||
|
||
fun getScreenshot(): Bitmap { | ||
val frameBuffer = ensureBufferIsReady() | ||
|
||
return Bitmap.createBitmap(SCREEN_WIDTH, SCREEN_HEIGHT, Bitmap.Config.ARGB_8888).apply { | ||
for (x in 0 until SCREEN_WIDTH) { | ||
for (y in 0 until SCREEN_HEIGHT) { | ||
val pixelPosition = (y * SCREEN_WIDTH + x) * 4 | ||
// There's no need to do a manual pixel format conversion. Since getInt() uses the buffer's byte order, which is little endian, it will automatically | ||
// convert the internal BGRA format into the ARGB format, which is what we need to build the bitmap | ||
val argbPixel = frameBuffer.getInt(pixelPosition) | ||
setPixel(x, y, argbPixel) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun clearBuffer() { | ||
screenshotBuffer?.let { buffer -> | ||
buffer.position(0) | ||
repeat(buffer.capacity() / 4) { | ||
buffer.putInt(0xFF000000.toInt()) | ||
} | ||
} | ||
} | ||
|
||
private fun ensureBufferIsReady(): ByteBuffer { | ||
if (screenshotBuffer != null) { | ||
return screenshotBuffer!! | ||
} | ||
|
||
screenshotBuffer = ByteBuffer.allocateDirect(SCREEN_WIDTH * SCREEN_HEIGHT * 4).order(ByteOrder.nativeOrder()) | ||
return screenshotBuffer!! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.