Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gl-react-native-v2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ym
gl-react-native-v2
Commits
27e53817
Commit
27e53817
authored
Feb 08, 2016
by
Gaëtan Renaudeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve implementation
parent
24f13a0d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
18 deletions
+32
-18
ios/GLCanvas.m
ios/GLCanvas.m
+9
-18
ios/GLTexture.h
ios/GLTexture.h
+1
-0
ios/GLTexture.m
ios/GLTexture.m
+22
-0
No files found.
ios/GLCanvas.m
View file @
27e53817
...
...
@@ -43,7 +43,7 @@ NSArray* diff (NSArray* a, NSArray* b) {
GLRenderData
*
_renderData
;
NSArray
*
_
contentData
;
NSArray
*
_
rasterizedContent
;
NSArray
*
_contentTextures
;
NSDictionary
*
_images
;
// This caches the currently used images (imageSrc -> GLReactImage)
...
...
@@ -88,7 +88,7 @@ RCT_NOT_IMPLEMENTED(-init)
_images
=
nil
;
_preloaded
=
nil
;
_captureConfigs
=
nil
;
_
contentData
=
nil
;
_
rasterizedContent
=
nil
;
_contentTextures
=
nil
;
_data
=
nil
;
_renderData
=
nil
;
...
...
@@ -323,11 +323,8 @@ RCT_NOT_IMPLEMENTED(-init)
-
(
void
)
rasterizeContent
{
// 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
*
rasterizedContent
=
[[
NSMutableArray
alloc
]
init
];
int
nb
=
[
_nbContentTextures
intValue
];
for
(
int
i
=
0
;
i
<
nb
;
i
++
)
{
UIView
*
view
=
self
.
superview
.
subviews
[
i
];
// We take siblings by index (closely related to the JS code)
...
...
@@ -345,9 +342,9 @@ RCT_NOT_IMPLEMENTED(-init)
imgData
=
[
GLImageData
genPixelsWithView
:
v
withPixelRatio
:
self
.
contentScaleFactor
];
}
}
if
(
imgData
)
contentData
[
i
]
=
imgData
;
if
(
imgData
)
rasterizedContent
[
i
]
=
imgData
;
}
_
contentData
=
contentData
;
_
rasterizedContent
=
rasterizedContent
;
[
self
setNeedsDisplay
];
RCT_PROFILE_END_EVENT
(
0
,
@"gl"
,
nil
);
}
...
...
@@ -355,7 +352,6 @@ RCT_NOT_IMPLEMENTED(-init)
-
(
void
)
syncContentTextures
{
RCT_PROFILE_BEGIN_EVENT
(
0
,
@"GLCanvas syncContentTextures"
,
nil
);
NSMutableArray
*
contentData
=
_contentData
.
mutableCopy
;
unsigned
long
max
=
MIN
([
_nbContentTextures
intValue
],
[
_contentTextures
count
]);
for
(
int
i
=
0
;
i
<
max
;
i
++
)
{
...
...
@@ -374,16 +370,11 @@ RCT_NOT_IMPLEMENTED(-init)
[
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
]
setPixelsWithPixelBuffer
:
buffer
];
}
else
{
[
_contentTextures
[
i
]
setPixels
:
_rasterizedContent
[
i
]];
}
[
_contentTextures
[
i
]
setPixels
:
contentData
[
i
]];
}
}
RCT_PROFILE_END_EVENT
(
0
,
@"gl"
,
nil
);
...
...
ios/GLTexture.h
View file @
27e53817
...
...
@@ -14,5 +14,6 @@
-
(
void
)
setShapeWithWidth
:(
float
)
width
withHeight
:(
float
)
height
;
-
(
void
)
setPixels
:
(
GLImageData
*
)
data
;
-
(
void
)
setPixelsWithPixelBuffer
:
(
CVPixelBufferRef
)
buffer
;
@end
ios/GLTexture.m
View file @
27e53817
...
...
@@ -6,6 +6,7 @@
{
GLuint
_handle
;
// The identifier of the gl texture
GLImageData
*
dataCurrentlyUploaded
;
// The last set data (cache)
CVPixelBufferRef
bufferCurrentlyUploaded
;
// The last set buffer (cache)
}
-
(
instancetype
)
init
...
...
@@ -21,6 +22,7 @@
{
glDeleteTextures
(
1
,
&
_handle
);
dataCurrentlyUploaded
=
nil
;
bufferCurrentlyUploaded
=
NULL
;
}
-
(
void
)
makeTexture
...
...
@@ -54,6 +56,7 @@
-
(
void
)
setPixels
:
(
GLImageData
*
)
data
{
GLImageData
*
d
=
data
==
nil
?
[
GLImageData
empty
]
:
data
;
bufferCurrentlyUploaded
=
NULL
;
if
(
d
!=
dataCurrentlyUploaded
)
{
dataCurrentlyUploaded
=
d
;
[
self
bind
];
...
...
@@ -61,4 +64,23 @@
}
}
-
(
void
)
setPixelsWithPixelBuffer
:
(
CVPixelBufferRef
)
buffer
{
if
(
buffer
==
NULL
)
{
[
self
setPixels
:[
GLImageData
empty
]];
}
else
{
dataCurrentlyUploaded
=
nil
;
if
(
buffer
!=
bufferCurrentlyUploaded
)
{
bufferCurrentlyUploaded
=
buffer
;
[
self
bind
];
int
width
=
(
int
)
CVPixelBufferGetWidth
(
buffer
);
int
height
=
(
int
)
CVPixelBufferGetHeight
(
buffer
);
GLubyte
*
data
=
CVPixelBufferGetBaseAddress
(
buffer
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
GL_RGBA
,
width
,
height
,
0
,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
data
);
}
}
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment