mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 15:48:26 -04:00
Change to TextureView again
This commit is contained in:
parent
fa6f2e0dd2
commit
ab2e9e68b1
@ -9,8 +9,9 @@ import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
public class AWTCanvasView extends View {
|
||||
public class AWTCanvasView extends TextureView implements TextureView.SurfaceTextureListener, Runnable {
|
||||
private int mWidth, mHeight;
|
||||
private boolean mIsDestroyed = false;
|
||||
|
||||
private TextPaint fpsPaint;
|
||||
private boolean attached = false;
|
||||
@ -43,26 +44,52 @@ public class AWTCanvasView extends View {
|
||||
fpsPaint = new TextPaint();
|
||||
fpsPaint.setColor(Color.WHITE);
|
||||
fpsPaint.setTextSize(20);
|
||||
|
||||
setSurfaceTextureListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
public void onSurfaceTextureAvailable(SurfaceTexture texture, int w, int h) {
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
// mRadius = (float) (Math.min(mWidth, mHeight) / 2 * 0.8);
|
||||
|
||||
mIsDestroyed = false;
|
||||
new Thread(this, "AndroidAWTRenderer").start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {
|
||||
mIsDestroyed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int w, int h) {
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture texture) {
|
||||
}
|
||||
|
||||
private boolean drawing = false;
|
||||
private Surface mSurface;
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
public void run() {
|
||||
Canvas canvas;
|
||||
mSurface = new Surface(getSurfaceTexture());
|
||||
|
||||
if (!attached) {
|
||||
attached = CallbackBridge.nativeAttachThreadToOther(true, MainActivity.isInputStackCall);
|
||||
while (!mIsDestroyed) {
|
||||
canvas = mSurface.lockCanvas(null);
|
||||
if (!attached) {
|
||||
attached = CallbackBridge.nativeAttachThreadToOther(true, MainActivity.isInputStackCall);
|
||||
}
|
||||
if (attached) {
|
||||
drawing = JREUtils.renderAWTScreenFrame(canvas, mWidth, mHeight);
|
||||
}
|
||||
canvas.drawText("FPS: " + fps() + ", drawing=" + drawing, 10, 10, fpsPaint);
|
||||
mSurface.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
if (attached) {
|
||||
drawing = JREUtils.renderAWTScreenFrame(canvas, mWidth, mHeight);
|
||||
}
|
||||
canvas.drawText("FPS: " + fps() + ", drawing=" + drawing, 100, 100, fpsPaint);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include <jni.h>
|
||||
#include "log.h"
|
||||
#include "utils.h"
|
||||
|
||||
// jclass class_awt;
|
||||
// jmethodID method_awt;
|
||||
|
||||
// TODO: check for memory leaks
|
||||
int printed = 0;
|
||||
JNIEXPORT jboolean JNICALL Java_net_kdt_pojavlaunch_JREUtils_renderAWTScreenFrame(JNIEnv* env, jclass clazz, jobject canvas, jint width, jint height) {
|
||||
if (runtimeJNIEnvPtr_ANDROID == NULL) return JNI_FALSE;
|
||||
|
||||
@ -25,6 +27,10 @@ JNIEXPORT jboolean JNICALL Java_net_kdt_pojavlaunch_JREUtils_renderAWTScreenFram
|
||||
androidRgbArray = (*dalvikJNIEnvPtr_ANDROID)->NewIntArray(dalvikJNIEnvPtr_ANDROID, arrayLength);
|
||||
(*dalvikJNIEnvPtr_ANDROID)->SetIntArrayRegion(dalvikJNIEnvPtr_ANDROID, androidRgbArray, 0, arrayLength, rgbArray);
|
||||
|
||||
if (printed++ < 200) {
|
||||
LOGD("[AWT] First 3 pixels: | %i | %i | %i |", rgbArray[0], rgbArray[1], rgbArray[2]);
|
||||
}
|
||||
|
||||
// Maybe use Skia lib instead?
|
||||
jclass class_canvas = (*dalvikJNIEnvPtr_ANDROID)->GetObjectClass(dalvikJNIEnvPtr_ANDROID, canvas);
|
||||
jmethodID method_canvas = (*dalvikJNIEnvPtr_ANDROID)->GetMethodID(dalvikJNIEnvPtr_ANDROID, class_canvas, "drawBitmap", "([IIIFFIIZLandroid/graphics/Paint;)V");
|
||||
|
Loading…
x
Reference in New Issue
Block a user