From 54433fa66b838907758911966407de22894f8057 Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Tue, 11 Aug 2020 07:52:22 +0700 Subject: [PATCH] Fix AndroidGraphics2D dalvikvm --- .../android/internal/awt/AndroidGraphics2D.java | 8 ++++++-- .../kdt/minecraftegl/MinecraftEGLInitializer.java | 15 +++++++++------ .../com/kdt/minecraftegl/SurfaceTextureView.java | 7 +++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/android/internal/awt/AndroidGraphics2D.java b/app/src/main/java/com/android/internal/awt/AndroidGraphics2D.java index 40c2b8494b..9ec57669ae 100644 --- a/app/src/main/java/com/android/internal/awt/AndroidGraphics2D.java +++ b/app/src/main/java/com/android/internal/awt/AndroidGraphics2D.java @@ -76,6 +76,7 @@ import android.view.Display; import android.view.WindowManager; import android.content.Context; +import org.lwjgl.opengl.*; public class AndroidGraphics2D extends Graphics2D { @@ -120,7 +121,7 @@ public static AndroidGraphics2D getInstance() { } public static AndroidGraphics2D getInstance(Context ctx, Canvas c, Paint p) { - if (c == null || ctx == null) { + if (c == null /* || ctx == null */) { throw new RuntimeException( "Illegal argument, Canvas cannot be null!"); } @@ -143,7 +144,10 @@ private AndroidGraphics2D(Context ctx, Canvas c, Paint p) { Display d = wm.getDefaultDisplay(); displayWidth = d.getWidth(); displayHeight = d.getHeight(); - } + } else { + displayWidth = AndroidDisplay.windowWidth; + displayHeight = AndroidDisplay.windowHeight; + } blitter = new AndroidJavaBlitter(c); cm = new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000); sm = new SinglePixelPackedSampleModel( diff --git a/app/src/main/java/com/kdt/minecraftegl/MinecraftEGLInitializer.java b/app/src/main/java/com/kdt/minecraftegl/MinecraftEGLInitializer.java index dd99ef5fd4..aefd43ba49 100644 --- a/app/src/main/java/com/kdt/minecraftegl/MinecraftEGLInitializer.java +++ b/app/src/main/java/com/kdt/minecraftegl/MinecraftEGLInitializer.java @@ -1,21 +1,19 @@ package com.kdt.minecraftegl; -import android.app.*; -import android.content.*; +import android.graphics.*; import android.os.*; import android.system.*; +import com.android.internal.awt.*; import dalvik.system.*; import java.lang.reflect.*; import java.util.*; import javax.microedition.khronos.egl.*; +import javax.microedition.khronos.opengles.*; import net.kdt.pojavlaunch.*; import net.kdt.pojavlaunch.exit.*; +import org.lwjgl.opengl.*; import static org.lwjgl.opengl.AndroidContextImplementation.*; -import android.content.pm.*; -import org.lwjgl.opengl.*; -import javax.microedition.khronos.opengles.*; -import android.util.*; public class MinecraftEGLInitializer { @@ -42,6 +40,8 @@ private static void runOnThread(final String[] args) { ExitManager.disableSystemExit(); Thread.sleep(200); // System.out.println(Arrays.toString(args)); + + MainActivity.fixRSAPadding(null); long lSurfaceTexture = Long.parseLong(args[0]); long lProducer = Long.parseLong(args[1]); @@ -50,6 +50,9 @@ private static void runOnThread(final String[] args) { AndroidDisplay.windowWidth = Integer.parseInt(args[3]); AndroidDisplay.windowHeight = Integer.parseInt(args[4]); + Bitmap awtGraphics = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888); + AndroidGraphics2D.getInstance(null, new Canvas(awtGraphics), null); + GLTextureView gtv = new GLTextureView(lSurfaceTexture, lProducer, lFrameAvailableListener); gtv.setRenderer(new GLTextureView.Renderer() { @Override diff --git a/app/src/main/java/com/kdt/minecraftegl/SurfaceTextureView.java b/app/src/main/java/com/kdt/minecraftegl/SurfaceTextureView.java index 2030f09d21..e7d7236c9a 100644 --- a/app/src/main/java/com/kdt/minecraftegl/SurfaceTextureView.java +++ b/app/src/main/java/com/kdt/minecraftegl/SurfaceTextureView.java @@ -9,16 +9,15 @@ public class SurfaceTextureView private SurfaceTextureListener mListener; private boolean isTextureAvailable = false; public SurfaceTextureView(long lSurfaceTexture, long lProducer, long lFrameAvailableListener) { - mSurfaceTexture = new SurfaceTexture(false); - /* + mSurfaceTexture = new SurfaceTexture(true); + try { Tools.findField(mSurfaceTexture, "mSurfaceTexture").set(mSurfaceTexture, lSurfaceTexture); - Tools.findField(mSurfaceTexture, "mProducer").set(mSurfaceTexture, lProducer); + // Tools.findField(mSurfaceTexture, "mProducer").set(mSurfaceTexture, lProducer); Tools.findField(mSurfaceTexture, "mFrameAvailableListener").set(mSurfaceTexture, lFrameAvailableListener); } catch (Throwable th) { throw new RuntimeException(th); } - */ } public SurfaceTexture getSurfaceTexture() {