You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement some stuff to make exaple SDL app run
NOTE: the main addition in this commit is WIP support for apps which render on an EGL surface obtained using ANativeWindow_fromSurface currently, this EGL surface is obtained by creating a 700x700 pixel window with GLFW (the 700x700 size is hardcoded in several places) and only Wayland is supported ideally, we'd want to use a wayland subsurface to position the EGL surface above the Surface widget it's associated with (and do whatever for X11)
This commit is contained in:
@@ -17,4 +17,8 @@ public final class Display {
|
||||
public int getRotation() {
|
||||
return 0/*ROTATION_0*/;
|
||||
}
|
||||
|
||||
public float getRefreshRate() {
|
||||
return 60; // FIXME
|
||||
}
|
||||
}
|
||||
|
||||
11
src/api-impl/android/view/InputDevice.java
Normal file
11
src/api-impl/android/view/InputDevice.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package android.view;
|
||||
|
||||
public class InputDevice {
|
||||
public static int[] getDeviceIds() {
|
||||
return new int[]{0}; // might work?
|
||||
}
|
||||
|
||||
public static InputDevice getDevice(int id) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,6 @@ package android.view;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
class InputDevice {}
|
||||
|
||||
/**
|
||||
* Common base class for input events.
|
||||
*/
|
||||
|
||||
@@ -6,187 +6,191 @@ import android.graphics.Rect;
|
||||
import android.content.Context;
|
||||
|
||||
public class SurfaceView extends View {
|
||||
|
||||
public SurfaceView(Context context) {
|
||||
super(context);
|
||||
|
||||
// native_constructor(context);
|
||||
native_constructor(context);
|
||||
}
|
||||
|
||||
private native void native_constructor(Context context);
|
||||
|
||||
public SurfaceHolder getHolder() {
|
||||
return mSurfaceHolder;
|
||||
return mSurfaceHolder;
|
||||
}
|
||||
|
||||
void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {}
|
||||
|
||||
final Surface mSurface = new Surface();
|
||||
|
||||
private final SurfaceHolder mSurfaceHolder = new SurfaceHolder() {
|
||||
private static final String LOG_TAG = "SurfaceHolder";
|
||||
|
||||
private static final String LOG_TAG = "SurfaceHolder";
|
||||
|
||||
@Override
|
||||
public boolean isCreating() {
|
||||
// return mIsCreating;
|
||||
@Override
|
||||
public boolean isCreating() {
|
||||
// return mIsCreating;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(Callback callback) {
|
||||
/* synchronized (mCallbacks) {
|
||||
// This is a linear search, but in practice we'll
|
||||
// have only a couple callbacks, so it doesn't matter.
|
||||
if (mCallbacks.contains(callback) == false) {
|
||||
mCallbacks.add(callback);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@Override
|
||||
public void addCallback(Callback callback) {
|
||||
/* synchronized (mCallbacks) {
|
||||
// This is a linear search, but in practice we'll
|
||||
// have only a couple callbacks, so it doesn't matter.
|
||||
if (mCallbacks.contains(callback) == false) {
|
||||
mCallbacks.add(callback);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCallback(Callback callback) {
|
||||
/* synchronized (mCallbacks) {
|
||||
mCallbacks.remove(callback);
|
||||
}*/
|
||||
}
|
||||
@Override
|
||||
public void removeCallback(Callback callback) {
|
||||
/* synchronized (mCallbacks) {
|
||||
mCallbacks.remove(callback);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFixedSize(int width, int height) {
|
||||
/* if (mRequestedWidth != width || mRequestedHeight != height) {
|
||||
mRequestedWidth = width;
|
||||
mRequestedHeight = height;
|
||||
requestLayout();
|
||||
}*/
|
||||
}
|
||||
@Override
|
||||
public void setFixedSize(int width, int height) {
|
||||
/* if (mRequestedWidth != width || mRequestedHeight != height) {
|
||||
mRequestedWidth = width;
|
||||
mRequestedHeight = height;
|
||||
requestLayout();
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSizeFromLayout() {
|
||||
/* if (mRequestedWidth != -1 || mRequestedHeight != -1) {
|
||||
mRequestedWidth = mRequestedHeight = -1;
|
||||
requestLayout();
|
||||
}*/
|
||||
}
|
||||
@Override
|
||||
public void setSizeFromLayout() {
|
||||
/* if (mRequestedWidth != -1 || mRequestedHeight != -1) {
|
||||
mRequestedWidth = mRequestedHeight = -1;
|
||||
requestLayout();
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFormat(int format) {
|
||||
/*
|
||||
// for backward compatibility reason, OPAQUE always
|
||||
// means 565 for SurfaceView
|
||||
if (format == PixelFormat.OPAQUE)
|
||||
format = PixelFormat.RGB_565;
|
||||
@Override
|
||||
public void setFormat(int format) {
|
||||
/*
|
||||
// for backward compatibility reason, OPAQUE always
|
||||
// means 565 for SurfaceView
|
||||
if (format == PixelFormat.OPAQUE)
|
||||
format = PixelFormat.RGB_565;
|
||||
|
||||
mRequestedFormat = format;
|
||||
if (mWindow != null) {
|
||||
updateWindow(false, false);
|
||||
}*/
|
||||
}
|
||||
mRequestedFormat = format;
|
||||
if (mWindow != null) {
|
||||
updateWindow(false, false);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated setType is now ignored.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setType(int type) { }
|
||||
/**
|
||||
* @deprecated setType is now ignored.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setType(int type) { }
|
||||
|
||||
@Override
|
||||
public void setKeepScreenOn(boolean screenOn) {
|
||||
// Message msg = mHandler.obtainMessage(KEEP_SCREEN_ON_MSG);
|
||||
// msg.arg1 = screenOn ? 1 : 0;
|
||||
// mHandler.sendMessage(msg);
|
||||
}
|
||||
@Override
|
||||
public void setKeepScreenOn(boolean screenOn) {
|
||||
// Message msg = mHandler.obtainMessage(KEEP_SCREEN_ON_MSG);
|
||||
// msg.arg1 = screenOn ? 1 : 0;
|
||||
// mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Canvas} for drawing into the SurfaceView's Surface
|
||||
*
|
||||
* After drawing into the provided {@link Canvas}, the caller must
|
||||
* invoke {@link #unlockCanvasAndPost} to post the new contents to the surface.
|
||||
*
|
||||
* The caller must redraw the entire surface.
|
||||
* @return A canvas for drawing into the surface.
|
||||
*/
|
||||
@Override
|
||||
public Canvas lockCanvas() {
|
||||
// return internalLockCanvas(null);
|
||||
/**
|
||||
* Gets a {@link Canvas} for drawing into the SurfaceView's Surface
|
||||
*
|
||||
* After drawing into the provided {@link Canvas}, the caller must
|
||||
* invoke {@link #unlockCanvasAndPost} to post the new contents to the surface.
|
||||
*
|
||||
* The caller must redraw the entire surface.
|
||||
* @return A canvas for drawing into the surface.
|
||||
*/
|
||||
@Override
|
||||
public Canvas lockCanvas() {
|
||||
// return internalLockCanvas(null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Canvas} for drawing into the SurfaceView's Surface
|
||||
*
|
||||
* After drawing into the provided {@link Canvas}, the caller must
|
||||
* invoke {@link #unlockCanvasAndPost} to post the new contents to the surface.
|
||||
*
|
||||
* @param inOutDirty A rectangle that represents the dirty region that the caller wants
|
||||
* to redraw. This function may choose to expand the dirty rectangle if for example
|
||||
* the surface has been resized or if the previous contents of the surface were
|
||||
* not available. The caller must redraw the entire dirty region as represented
|
||||
* by the contents of the inOutDirty rectangle upon return from this function.
|
||||
* The caller may also pass <code>null</code> instead, in the case where the
|
||||
* entire surface should be redrawn.
|
||||
* @return A canvas for drawing into the surface.
|
||||
*/
|
||||
@Override
|
||||
public Canvas lockCanvas(Rect inOutDirty) {
|
||||
// return internalLockCanvas(inOutDirty);
|
||||
/**
|
||||
* Gets a {@link Canvas} for drawing into the SurfaceView's Surface
|
||||
*
|
||||
* After drawing into the provided {@link Canvas}, the caller must
|
||||
* invoke {@link #unlockCanvasAndPost} to post the new contents to the surface.
|
||||
*
|
||||
* @param inOutDirty A rectangle that represents the dirty region that the caller wants
|
||||
* to redraw. This function may choose to expand the dirty rectangle if for example
|
||||
* the surface has been resized or if the previous contents of the surface were
|
||||
* not available. The caller must redraw the entire dirty region as represented
|
||||
* by the contents of the inOutDirty rectangle upon return from this function.
|
||||
* The caller may also pass <code>null</code> instead, in the case where the
|
||||
* entire surface should be redrawn.
|
||||
* @return A canvas for drawing into the surface.
|
||||
*/
|
||||
@Override
|
||||
public Canvas lockCanvas(Rect inOutDirty) {
|
||||
// return internalLockCanvas(inOutDirty);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final Canvas internalLockCanvas(Rect dirty) {
|
||||
/* mSurfaceLock.lock();
|
||||
private final Canvas internalLockCanvas(Rect dirty) {
|
||||
/* mSurfaceLock.lock();
|
||||
|
||||
if (DEBUG) Log.i(TAG, "Locking canvas... stopped="
|
||||
+ mDrawingStopped + ", win=" + mWindow);
|
||||
if (DEBUG) Log.i(TAG, "Locking canvas... stopped="
|
||||
+ mDrawingStopped + ", win=" + mWindow);
|
||||
|
||||
Canvas c = null;
|
||||
if (!mDrawingStopped && mWindow != null) {
|
||||
try {
|
||||
c = mSurface.lockCanvas(dirty);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "Exception locking surface", e);
|
||||
}
|
||||
}
|
||||
Canvas c = null;
|
||||
if (!mDrawingStopped && mWindow != null) {
|
||||
try {
|
||||
c = mSurface.lockCanvas(dirty);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "Exception locking surface", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) Log.i(TAG, "Returned canvas: " + c);
|
||||
if (c != null) {
|
||||
mLastLockTime = SystemClock.uptimeMillis();
|
||||
return c;
|
||||
}
|
||||
if (DEBUG) Log.i(TAG, "Returned canvas: " + c);
|
||||
if (c != null) {
|
||||
mLastLockTime = SystemClock.uptimeMillis();
|
||||
return c;
|
||||
}
|
||||
|
||||
// If the Surface is not ready to be drawn, then return null,
|
||||
// but throttle calls to this function so it isn't called more
|
||||
// than every 100ms.
|
||||
long now = SystemClock.uptimeMillis();
|
||||
long nextTime = mLastLockTime + 100;
|
||||
if (nextTime > now) {
|
||||
try {
|
||||
Thread.sleep(nextTime-now);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
now = SystemClock.uptimeMillis();
|
||||
}
|
||||
mLastLockTime = now;
|
||||
mSurfaceLock.unlock();
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts the new contents of the {@link Canvas} to the surface and
|
||||
* releases the {@link Canvas}.
|
||||
*
|
||||
* @param canvas The canvas previously obtained from {@link #lockCanvas}.
|
||||
*/
|
||||
@Override
|
||||
public void unlockCanvasAndPost(Canvas canvas) {
|
||||
// mSurface.unlockCanvasAndPost(canvas);
|
||||
// mSurfaceLock.unlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Surface getSurface() {
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect getSurfaceFrame() {
|
||||
// return mSurfaceFrame;
|
||||
// If the Surface is not ready to be drawn, then return null,
|
||||
// but throttle calls to this function so it isn't called more
|
||||
// than every 100ms.
|
||||
long now = SystemClock.uptimeMillis();
|
||||
long nextTime = mLastLockTime + 100;
|
||||
if (nextTime > now) {
|
||||
try {
|
||||
Thread.sleep(nextTime-now);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
now = SystemClock.uptimeMillis();
|
||||
}
|
||||
mLastLockTime = now;
|
||||
mSurfaceLock.unlock();
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts the new contents of the {@link Canvas} to the surface and
|
||||
* releases the {@link Canvas}.
|
||||
*
|
||||
* @param canvas The canvas previously obtained from {@link #lockCanvas}.
|
||||
*/
|
||||
@Override
|
||||
public void unlockCanvasAndPost(Canvas canvas) {
|
||||
// mSurface.unlockCanvasAndPost(canvas);
|
||||
// mSurfaceLock.unlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Surface getSurface() {
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect getSurfaceFrame() {
|
||||
// return mSurfaceFrame;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -525,6 +525,14 @@ public class View extends Object {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public interface OnGenericMotionListener {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public interface OnSystemUiVisibilityChangeListener {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public static interface OnKeyListener {
|
||||
// TODO
|
||||
// boolean onKey(View v, int keyCode, KeyEvent event);
|
||||
@@ -741,6 +749,7 @@ public class View extends Object {
|
||||
public native void setGravity(int gravity);
|
||||
public native void setOnTouchListener(OnTouchListener l);
|
||||
public native void setOnClickListener(OnClickListener l);
|
||||
public /*native*/ void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) {}
|
||||
public native final int getWidth();
|
||||
public native final int getHeight();
|
||||
|
||||
|
||||
@@ -28,5 +28,9 @@ public class Window {
|
||||
set_widget_as_root(native_window, view.widget);
|
||||
}
|
||||
|
||||
public View getDecorView() {
|
||||
return new View(); // FIXME: this can probably backfire
|
||||
}
|
||||
|
||||
private native void set_widget_as_root(long native_window, long widget);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user