Commit 8acaae75 authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

implement the new pixelRatio per node

parent c3a98a8e
......@@ -70,6 +70,9 @@ public class GLCanvas extends GLSurfaceView
private ExecutorSupplier executorSupplier;
private final Queue<Runnable> mRunOnDraw = new LinkedList<>();
private boolean captureFrameRequested = false;
private float pixelRatio;
private float displayDensity;
public GLCanvas(ThemedReactContext context, ExecutorSupplier executorSupplier) {
super(context);
......@@ -78,6 +81,10 @@ public class GLCanvas extends GLSurfaceView
rnglContext = context.getNativeModule(RNGLContext.class);
setEGLContextClientVersion(2);
DisplayMetrics dm = reactContext.getResources().getDisplayMetrics();
displayDensity = dm.density;
pixelRatio = dm.density;
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
getHolder().setFormat(PixelFormat.RGB_888);
setZOrderOnTop(true);
......@@ -123,6 +130,12 @@ public class GLCanvas extends GLSurfaceView
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
syncSize(w, h, pixelRatio);
}
@Override
public void onDrawFrame(GL10 gl) {
runAll(mRunOnDraw);
......@@ -525,8 +538,8 @@ public class GLCanvas extends GLSurfaceView
uniformsIntBuffer,
uniformsFloatBuffer,
textures,
data.width,
data.height,
(int)(data.width * data.pixelRatio),
(int)(data.height * data.pixelRatio),
data.fboId,
contextChildren,
children);
......@@ -598,11 +611,8 @@ public class GLCanvas extends GLSurfaceView
}
private void recRender (GLRenderData renderData) {
DisplayMetrics dm = reactContext.getResources().getDisplayMetrics();
int w = Float.valueOf(renderData.width.floatValue() * dm.density).intValue();
int h = Float.valueOf(renderData.height.floatValue() * dm.density).intValue();
int w = renderData.width;
int h = renderData.height;
for (GLRenderData child: renderData.contextChildren)
recRender(child);
......@@ -751,4 +761,16 @@ public class GLCanvas extends GLSurfaceView
d.removeAll(b);
return d;
}
public void setPixelRatio(float pixelRatio) {
this.pixelRatio = pixelRatio;
syncSize(this.getWidth(), this.getHeight(), pixelRatio);
}
private void syncSize (int w, int h, float pixelRatio) {
int width = (int) (w * pixelRatio / displayDensity);
int height = (int) (h * pixelRatio / displayDensity);
getHolder().setFixedSize(width, height);
}
}
......@@ -27,6 +27,11 @@ public class GLCanvasManager extends SimpleViewManager<GLCanvas> {
private ExecutorSupplier executorSupplier;
@ReactProp(name="pixelRatio")
public void setPixelRatio (GLCanvas view, float pixelRatio) {
view.setPixelRatio(pixelRatio);
}
@ReactProp(name="nbContentTextures")
public void setNbContentTextures (GLCanvas view, int nbContentTextures) {
view.setNbContentTextures(nbContentTextures);
......
......@@ -10,17 +10,19 @@ public class GLData {
final Integer shader;
final ReadableMap uniforms;
final Integer width;
final Integer height;
final Double width;
final Double height;
final Double pixelRatio;
final Integer fboId;
final List<GLData> contextChildren;
final List<GLData> children;
public GLData(Integer shader, ReadableMap uniforms, Integer width, Integer height, Integer fboId, List<GLData> contextChildren, List<GLData> children) {
public GLData(Integer shader, ReadableMap uniforms, Double width, Double height, Double pixelRatio, Integer fboId, List<GLData> contextChildren, List<GLData> children) {
this.shader = shader;
this.uniforms = uniforms;
this.width = width;
this.height = height;
this.pixelRatio = pixelRatio;
this.fboId = fboId;
this.contextChildren = contextChildren;
this.children = children;
......@@ -37,11 +39,12 @@ public class GLData {
public static GLData fromMap (ReadableMap map) {
Integer shader = map.getInt("shader");
ReadableMap uniforms = map.getMap("uniforms");
Integer width = (int) map.getDouble("width");
Integer height = (int) map.getDouble("height");
Double width = map.getDouble("width");
Double height = map.getDouble("height");
Double pixelRatio = map.getDouble("pixelRatio");
Integer fboId = map.getInt("fboId");
List<GLData> children = fromArray(map.getArray("children"));
List<GLData> contextChildren = fromArray(map.getArray("contextChildren"));
return new GLData(shader, uniforms, width, height, fboId, contextChildren, children);
return new GLData(shader, uniforms, width, height, pixelRatio, fboId, contextChildren, children);
}
}
......@@ -178,6 +178,7 @@ RCT_NOT_IMPLEMENTED(-init)
weak_traverseTree = traverseTree = ^GLRenderData *(GLData *data) {
NSNumber *width = data.width;
NSNumber *height = data.height;
NSNumber *pixelRatio = data.pixelRatio;
int fboId = [data.fboId intValue];
NSMutableArray *contextChildren = [[NSMutableArray alloc] init];
......@@ -275,8 +276,8 @@ RCT_NOT_IMPLEMENTED(-init)
initWithShader:shader
withUniforms:uniforms
withTextures:textures
withWidth:width
withHeight:height
withWidth:(int)([width floatValue] * [pixelRatio floatValue])
withHeight:(int)([height floatValue] * [pixelRatio floatValue])
withFboId:fboId
withContextChildren:contextChildren
withChildren:children];
......@@ -404,16 +405,14 @@ RCT_NOT_IMPLEMENTED(-init)
GLRenderData *rd = _renderData;
if (!rd) return;
RCT_PROFILE_BEGIN_EVENT(0, @"GLCanvas render", nil);
CGFloat scale = self.contentScaleFactor;
@autoreleasepool {
CGFloat scale = RCTScreenScale();
void (^recDraw) (GLRenderData *renderData);
__block __weak void (^weak_recDraw) (GLRenderData *renderData);
weak_recDraw = recDraw = ^void(GLRenderData *renderData) {
float w = [renderData.width floatValue] * scale;
float h = [renderData.height floatValue] * scale;
int w = renderData.width;
int h = renderData.height;
for (GLRenderData *child in renderData.contextChildren)
weak_recDraw(child);
......
......@@ -8,6 +8,7 @@
@property (nonatomic) NSDictionary *uniforms;
@property (nonatomic) NSNumber *width;
@property (nonatomic) NSNumber *height;
@property (nonatomic) NSNumber *pixelRatio;
@property (nonatomic) NSNumber *fboId;
@property (nonatomic) NSArray *contextChildren;
@property (nonatomic) NSArray *children;
......@@ -16,6 +17,7 @@
withUniforms: (NSDictionary *)uniforms
withWidth: (NSNumber *)width
withHeight: (NSNumber *)height
withPixelRatio: (NSNumber *)pixelRatio
withFboId: (NSNumber *)fboId
withContextChildren: (NSArray *)contextChildren
withChildren: (NSArray *)children;
......
......@@ -6,6 +6,7 @@
withUniforms: (NSDictionary *)uniforms
withWidth: (NSNumber *)width
withHeight: (NSNumber *)height
withPixelRatio: (NSNumber *)pixelRatio
withFboId: (NSNumber *)fboId
withContextChildren: (NSArray *)contextChildren
withChildren: (NSArray *)children
......@@ -15,6 +16,7 @@
self.uniforms = uniforms;
self.width = width;
self.height = height;
self.pixelRatio = pixelRatio;
self.fboId = fboId;
self.contextChildren = contextChildren;
self.children = children;
......
......@@ -7,8 +7,8 @@
@property (nonatomic) GLShader *shader;
@property (nonatomic) NSDictionary *uniforms;
@property (nonatomic) NSDictionary *textures;
@property (nonatomic) NSNumber *width;
@property (nonatomic) NSNumber *height;
@property (nonatomic) int width;
@property (nonatomic) int height;
@property (nonatomic) int fboId;
@property (nonatomic) NSArray *contextChildren;
@property (nonatomic) NSArray *children;
......@@ -16,8 +16,8 @@
-(instancetype) initWithShader: (GLShader *)shader
withUniforms:(NSDictionary *)uniforms
withTextures: (NSDictionary *)textures
withWidth: (NSNumber *)width
withHeight: (NSNumber *)height
withWidth: (int)width
withHeight: (int)height
withFboId: (int)fboId
withContextChildren: (NSArray *)contextChildren
withChildren: (NSArray *)children;
......
......@@ -6,8 +6,8 @@
-(instancetype) initWithShader: (GLShader *)shader
withUniforms:(NSDictionary *)uniforms
withTextures: (NSDictionary *)textures
withWidth: (NSNumber *)width
withHeight: (NSNumber *)height
withWidth: (int)width
withHeight: (int)height
withFboId: (int)fboId
withContextChildren: (NSArray *)contextChildren
withChildren: (NSArray *)children
......
......@@ -10,6 +10,7 @@
NSDictionary *uniforms = [self NSDictionary:json[@"uniforms"]];
NSNumber *width = [self NSNumber:json[@"width"]];
NSNumber *height = [self NSNumber:json[@"height"]];
NSNumber *pixelRatio = [self NSNumber:json[@"pixelRatio"]];
NSNumber *fboId = [self NSNumber:json[@"fboId"]];
NSArray *contextChildrenJSON = [self NSArray: json[@"contextChildren"]];
NSArray *childrenJSON = [self NSArray: json[@"children"]];
......@@ -30,6 +31,7 @@
withUniforms: uniforms
withWidth: width
withHeight: height
withPixelRatio: pixelRatio
withFboId: fboId
withContextChildren: contextChildren
withChildren: children];
......
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