Commit 24f13a0d authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

poc getPixelBuffer

parent 81e1fc71
...@@ -321,9 +321,12 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -321,9 +321,12 @@ RCT_NOT_IMPLEMENTED(-init)
} }
} }
- (void)syncContentData - (void)rasterizeContent
{ {
RCT_PROFILE_BEGIN_EVENT(0, @"GLCanvas syncContentData", nil); // TODO: we need to refactor how this stuff work...
// we should no longer do any rasterize work if all the work is to be done in syncContentTextures
RCT_PROFILE_BEGIN_EVENT(0, @"GLCanvas rasterizeContent", nil);
NSMutableArray *contentData = [[NSMutableArray alloc] init]; NSMutableArray *contentData = [[NSMutableArray alloc] init];
int nb = [_nbContentTextures intValue]; int nb = [_nbContentTextures intValue];
for (int i = 0; i < nb; i++) { for (int i = 0; i < nb; i++) {
...@@ -333,9 +336,14 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -333,9 +336,14 @@ RCT_NOT_IMPLEMENTED(-init)
UIView *v = [view.subviews count] == 1 ? UIView *v = [view.subviews count] == 1 ?
view.subviews[0] : view.subviews[0] :
view; view;
imgData = [GLImageData genPixelsWithView:v withPixelRatio:self.contentScaleFactor];
} else { SEL selector = NSSelectorFromString(@"getPixelBuffer");
imgData = nil; if ([v respondsToSelector:selector]) {
// will do in syncContentTextures at draw() time
}
else {
imgData = [GLImageData genPixelsWithView:v withPixelRatio:self.contentScaleFactor];
}
} }
if (imgData) contentData[i] = imgData; if (imgData) contentData[i] = imgData;
} }
...@@ -344,13 +352,41 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -344,13 +352,41 @@ RCT_NOT_IMPLEMENTED(-init)
RCT_PROFILE_END_EVENT(0, @"gl", nil); RCT_PROFILE_END_EVENT(0, @"gl", nil);
} }
- (void)syncContentTextures - (void)syncContentTextures
{ {
unsigned long max = MIN([_contentData count], [_contentTextures count]); RCT_PROFILE_BEGIN_EVENT(0, @"GLCanvas syncContentTextures", nil);
for (int i=0; i<max; i++) { NSMutableArray *contentData = _contentData.mutableCopy;
[_contentTextures[i] setPixels:_contentData[i]]; unsigned long max = MIN([_nbContentTextures intValue], [_contentTextures count]);
for (int i = 0; i < max; i++) {
UIView *view = self.superview.subviews[i]; // We take siblings by index (closely related to the JS code)
if (view) {
UIView *v = [view.subviews count] == 1 ?
view.subviews[0] :
view;
SEL selector = NSSelectorFromString(@"getPixelBuffer");
if ([v respondsToSelector:selector]) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[[v class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:v];
[invocation invoke];
CVPixelBufferRef buffer;
[invocation getReturnValue:&buffer];
int width = (int) CVPixelBufferGetWidth(buffer);
int height = (int) CVPixelBufferGetHeight(buffer);
contentData[i] = [[GLImageData alloc]
initWithData:CVPixelBufferGetBaseAddress(buffer)
withWidth:width
withHeight:height];
}
[_contentTextures[i] setPixels:contentData[i]];
}
} }
RCT_PROFILE_END_EVENT(0, @"gl", nil);
} }
- (BOOL)haveRemainingToPreload - (BOOL)haveRemainingToPreload
...@@ -372,7 +408,7 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -372,7 +408,7 @@ RCT_NOT_IMPLEMENTED(-init)
return; return;
} }
if ([_nbContentTextures intValue] > 0) { if ([_nbContentTextures intValue] > 0) {
[self syncContentData]; [self rasterizeContent];
} }
[self setNeedsDisplay]; [self setNeedsDisplay];
} }
...@@ -407,7 +443,7 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -407,7 +443,7 @@ RCT_NOT_IMPLEMENTED(-init)
BOOL needsDeferredRendering = [_nbContentTextures intValue] > 0 && !_autoRedraw; BOOL needsDeferredRendering = [_nbContentTextures intValue] > 0 && !_autoRedraw;
if (needsDeferredRendering && !_deferredRendering) { if (needsDeferredRendering && !_deferredRendering) {
_deferredRendering = true; _deferredRendering = true;
[self performSelectorOnMainThread:@selector(syncContentData) withObject:nil waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(rasterizeContent) withObject:nil waitUntilDone:NO];
} }
else { else {
_deferredRendering = false; _deferredRendering = false;
...@@ -534,7 +570,7 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -534,7 +570,7 @@ RCT_NOT_IMPLEMENTED(-init)
}; };
// DRAWING THE SCENE // DRAWING THE SCENE
[self syncContentTextures]; [self syncContentTextures];
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
......
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