Commit 1e2457e0 authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

wip

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