diff --git a/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java b/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java index 4f0e5d8c8095b38fc3768efbd4b0588adf1b51b6..76e374cf06431c5c59835a369673cd0a1a2acadf 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java @@ -6,8 +6,10 @@ import android.graphics.Bitmap; import android.graphics.PixelFormat; import android.net.Uri; import android.opengl.GLSurfaceView; +import android.support.annotation.Nullable; import android.util.DisplayMetrics; import android.util.Log; +import android.view.MotionEvent; import android.view.ViewGroup; import com.facebook.react.bridge.Arguments; @@ -16,6 +18,10 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.bridge.WritableMap; +import com.facebook.react.touch.CatalystInterceptingViewGroup; +import com.facebook.react.touch.OnInterceptTouchEventListener; +import com.facebook.react.uimanager.PointerEvents; +import com.facebook.react.uimanager.ReactPointerEventsView; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.events.RCTEventEmitter; @@ -33,7 +39,9 @@ import java.util.Queue; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; -public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, RunInGLThread { +public class GLCanvas + extends GLSurfaceView + implements GLSurfaceView.Renderer, RunInGLThread { private ReactContext reactContext; private RNGLContext rnglContext; @@ -43,12 +51,7 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R private int defaultFBO; private int nbContentTextures; - private int renderId; - private boolean opaque; private boolean autoRedraw; - private boolean eventsThrough; - private boolean visibleContent; - private int captureNextFrameId; private GLData data; private List imagesToPreload; private List preloaded = new ArrayList<>(); // FIXME double check that this works @@ -65,8 +68,11 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R reactContext = context; rnglContext = context.getNativeModule(RNGLContext.class); setEGLContextClientVersion(2); + setEGLConfigChooser(8, 8, 8, 8, 16, 0); - getHolder().setFormat(PixelFormat.RGBA_8888); + getHolder().setFormat(PixelFormat.RGB_888); + setZOrderOnTop(true); + setRenderer(this); setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); } @@ -102,14 +108,15 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R } @Override - public void onSurfaceChanged(GL10 gl, int width, int height) { - // FIXME anything to do here? - } + public void onSurfaceChanged(GL10 gl, int width, int height) {} @Override public void onDrawFrame(GL10 gl) { runAll(mRunOnDraw); + if (contentTextures.size() != this.nbContentTextures) + resizeUniformContentTextures(nbContentTextures); + syncEventsThrough(); // FIXME, really need to do this ? if (!preloadingDone) { @@ -139,17 +146,10 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R public void setNbContentTextures(int n) { this.nbContentTextures = n; - runInGLThread(new Runnable() { - @Override - public void run() { - resizeUniformContentTextures(nbContentTextures); - if (preloadingDone) syncContentBitmaps(); - } - }); + requestRender(); } public void setRenderId(int renderId) { - this.renderId = renderId; if (nbContentTextures > 0) { if (preloadingDone) syncContentBitmaps(); requestRender(); @@ -157,16 +157,13 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R } public void setOpaque(boolean opaque) { - this.opaque = opaque; - /* // FIXME: how to do ? if (opaque) { - this.getHolder().setFormat(PixelFormat.RGB_565); + this.getHolder().setFormat(PixelFormat.RGB_888); } else { this.getHolder().setFormat(PixelFormat.TRANSLUCENT); } - */ - this.requestRender(); // FIXME is this required? + this.requestRender(); } public void setAutoRedraw(boolean autoRedraw) { @@ -175,18 +172,15 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R } public void setEventsThrough(boolean eventsThrough) { - this.eventsThrough = eventsThrough; syncEventsThrough(); } public void setVisibleContent(boolean visibleContent) { - this.visibleContent = visibleContent; syncEventsThrough(); } public void setCaptureNextFrameId(int captureNextFrameId) { // FIXME move away from this pattern. just use a method, same to ObjC impl - this.captureNextFrameId = captureNextFrameId; this.requestRender(); } @@ -633,7 +627,6 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R public void render () { if (renderData == null) return; - Log.i("GLCanvas", "render"); syncContentTextures(); int[] defaultFBOArr = new int[1]; @@ -673,5 +666,4 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R "load", event); } - } diff --git a/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java b/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java index 7c16e551b7acc0268daabd6e04f7b151a7db5e73..6065e94025783172ba0bbb87c0aa165f19af9db3 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java @@ -4,10 +4,13 @@ import android.support.annotation.Nullable; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.PointerEvents; import com.facebook.react.uimanager.SimpleViewManager; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ReactProp; +import java.util.Locale; + public class GLCanvasManager extends SimpleViewManager { diff --git a/android/src/main/java/com/projectseptember/RNGL/GLShader.java b/android/src/main/java/com/projectseptember/RNGL/GLShader.java index e19dab7c8af9e0183fe2264b16463ebde5d436d7..59359fa9c83a9600b385a7b471da6b714c6a87a8 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLShader.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLShader.java @@ -37,7 +37,7 @@ public class GLShader { protected void finalize() throws Throwable { super.finalize(); if (buffer != null) { - glDeleteProgram(program); + glDeleteProgram(program); // FIXME: will this ever work? gl calls must be done in GL Thread... glDeleteBuffers(1, buffer, 0); } } diff --git a/android/src/main/java/com/projectseptember/RNGL/GLTexture.java b/android/src/main/java/com/projectseptember/RNGL/GLTexture.java index 08d0e32b4c3e2fcd82925aa8763218b9ddfb493b..626d325fa97b29ec7231c0456743840da53afcfb 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLTexture.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLTexture.java @@ -5,6 +5,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.opengl.GLUtils; +import android.util.Log; import android.view.View; import static android.opengl.GLES20.*; @@ -82,14 +83,13 @@ public class GLTexture { int w = view.getWidth(); int h = view.getHeight(); if (w <= 0 || h <= 0) return Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888); - Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - view.layout(0, 0, view.getWidth(), view.getHeight()); - view.draw(canvas); + Bitmap bitmap = view.getDrawingCache(); + if (bitmap == null) + view.setDrawingCacheEnabled(true); + bitmap = view.getDrawingCache(); Matrix matrix = new Matrix(); matrix.postScale(1, -1); Bitmap transformedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); - bitmap.recycle(); return transformedBitmap; }