Commit 99e5ce2e authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

Revert "simplify code of genPixelsWithView" because breaks retina

This reverts commit 4af27175.
parent a5ee3b44
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
#import "RCTLog.h" #import "RCTLog.h"
#import "RCTUtils.h" #import "RCTUtils.h"
// FIXME: the current approach of using a byte array is probably a bottleneck
// this should be investigated: https://github.com/ProjectSeptemberInc/gl-react-native/issues/6
GLImageData* genPixelsEmpty (int width, int height) GLImageData* genPixelsEmpty (int width, int height)
{ {
GLubyte* data = (GLubyte *) malloc(width*height*4*sizeof(GLubyte)); GLubyte* data = (GLubyte *) malloc(width*height*4*sizeof(GLubyte));
...@@ -57,11 +54,17 @@ GLImageData* genPixelsWithImage (UIImage *image) ...@@ -57,11 +54,17 @@ GLImageData* genPixelsWithImage (UIImage *image)
GLImageData* genPixelsWithView (UIView *view) GLImageData* genPixelsWithView (UIView *view)
{ {
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, RCTScreenScale()); float width = RCTScreenScale() * view.bounds.size.width;
[view drawViewHierarchyInRect:view.frame afterScreenUpdates:YES]; float height = RCTScreenScale() * view.bounds.size.height;
UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext(); GLubyte *data = (GLubyte *)malloc(4 * width * height);
UIGraphicsEndImageContext(); CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
return genPixelsWithImage(snapshot); CGContextRef ctx = CGBitmapContextCreate(data, width, height, 8, 4 * width, colourSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colourSpace);
CGContextClearRect(ctx, CGRectMake(0.0, 0.0, width, height));
CGContextScaleCTM(ctx, RCTScreenScale(), RCTScreenScale());
[view.layer renderInContext:ctx];
CGContextRelease(ctx);
return [[GLImageData alloc] initWithData:data withWidth:width withHeight:height];
} }
@implementation GLTexture @implementation GLTexture
......
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