mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 08:05:34 -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 net.kdt.pojavlaunch.*;
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
|
|
||||||
public class AWTCanvasView extends View {
|
public class AWTCanvasView extends TextureView implements TextureView.SurfaceTextureListener, Runnable {
|
||||||
private int mWidth, mHeight;
|
private int mWidth, mHeight;
|
||||||
|
private boolean mIsDestroyed = false;
|
||||||
|
|
||||||
private TextPaint fpsPaint;
|
private TextPaint fpsPaint;
|
||||||
private boolean attached = false;
|
private boolean attached = false;
|
||||||
@ -43,26 +44,52 @@ public class AWTCanvasView extends View {
|
|||||||
fpsPaint = new TextPaint();
|
fpsPaint = new TextPaint();
|
||||||
fpsPaint.setColor(Color.WHITE);
|
fpsPaint.setColor(Color.WHITE);
|
||||||
fpsPaint.setTextSize(20);
|
fpsPaint.setTextSize(20);
|
||||||
|
|
||||||
|
setSurfaceTextureListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
public void onSurfaceTextureAvailable(SurfaceTexture texture, int w, int h) {
|
||||||
mWidth = w;
|
mWidth = w;
|
||||||
mHeight = h;
|
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 boolean drawing = false;
|
||||||
|
private Surface mSurface;
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
public void run() {
|
||||||
super.onDraw(canvas);
|
Canvas canvas;
|
||||||
|
mSurface = new Surface(getSurfaceTexture());
|
||||||
|
|
||||||
|
while (!mIsDestroyed) {
|
||||||
|
canvas = mSurface.lockCanvas(null);
|
||||||
if (!attached) {
|
if (!attached) {
|
||||||
attached = CallbackBridge.nativeAttachThreadToOther(true, MainActivity.isInputStackCall);
|
attached = CallbackBridge.nativeAttachThreadToOther(true, MainActivity.isInputStackCall);
|
||||||
}
|
}
|
||||||
if (attached) {
|
if (attached) {
|
||||||
drawing = JREUtils.renderAWTScreenFrame(canvas, mWidth, mHeight);
|
drawing = JREUtils.renderAWTScreenFrame(canvas, mWidth, mHeight);
|
||||||
}
|
}
|
||||||
canvas.drawText("FPS: " + fps() + ", drawing=" + drawing, 100, 100, fpsPaint);
|
canvas.drawText("FPS: " + fps() + ", drawing=" + drawing, 10, 10, fpsPaint);
|
||||||
|
mSurface.unlockCanvasAndPost(canvas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
#include "log.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
// jclass class_awt;
|
// jclass class_awt;
|
||||||
// jmethodID method_awt;
|
// jmethodID method_awt;
|
||||||
|
|
||||||
// TODO: check for memory leaks
|
// 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) {
|
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;
|
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);
|
androidRgbArray = (*dalvikJNIEnvPtr_ANDROID)->NewIntArray(dalvikJNIEnvPtr_ANDROID, arrayLength);
|
||||||
(*dalvikJNIEnvPtr_ANDROID)->SetIntArrayRegion(dalvikJNIEnvPtr_ANDROID, androidRgbArray, 0, arrayLength, rgbArray);
|
(*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?
|
// Maybe use Skia lib instead?
|
||||||
jclass class_canvas = (*dalvikJNIEnvPtr_ANDROID)->GetObjectClass(dalvikJNIEnvPtr_ANDROID, canvas);
|
jclass class_canvas = (*dalvikJNIEnvPtr_ANDROID)->GetObjectClass(dalvikJNIEnvPtr_ANDROID, canvas);
|
||||||
jmethodID method_canvas = (*dalvikJNIEnvPtr_ANDROID)->GetMethodID(dalvikJNIEnvPtr_ANDROID, class_canvas, "drawBitmap", "([IIIFFIIZLandroid/graphics/Paint;)V");
|
jmethodID method_canvas = (*dalvikJNIEnvPtr_ANDROID)->GetMethodID(dalvikJNIEnvPtr_ANDROID, class_canvas, "drawBitmap", "([IIIFFIIZLandroid/graphics/Paint;)V");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user