Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm

Issue 2176623002: iOS render: Handle frame rotation in OpenGL (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@nv21_texture_render
Patch Set: Remove unused vertex buffer argument to RTCSetVertexData Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "RTCShader.h" 11 #import "RTCShader.h"
12 12
13 #include <vector> 13 #include <vector>
14 14
15 #import "RTCShader+Private.h" 15 #import "RTCShader+Private.h"
16 #import "WebRTC/RTCVideoFrame.h" 16 #import "WebRTC/RTCVideoFrame.h"
17 17
18 #include "webrtc/base/optional.h"
19
18 // |kNumTextures| must not exceed 8, which is the limit in OpenGLES2. Two sets 20 // |kNumTextures| must not exceed 8, which is the limit in OpenGLES2. Two sets
19 // of 3 textures are used here, one for each of the Y, U and V planes. Having 21 // of 3 textures are used here, one for each of the Y, U and V planes. Having
20 // two sets alleviates CPU blockage in the event that the GPU is asked to render 22 // two sets alleviates CPU blockage in the event that the GPU is asked to render
21 // to a texture that is already in use. 23 // to a texture that is already in use.
22 static const GLsizei kNumTextureSets = 2; 24 static const GLsizei kNumTextureSets = 2;
23 static const GLsizei kNumTexturesPerSet = 3; 25 static const GLsizei kNumTexturesPerSet = 3;
24 static const GLsizei kNumTextures = kNumTexturesPerSet * kNumTextureSets; 26 static const GLsizei kNumTextures = kNumTexturesPerSet * kNumTextureSets;
25 27
26 // Fragment shader converts YUV values from input textures into a final RGB 28 // Fragment shader converts YUV values from input textures into a final RGB
27 // pixel. The conversion formula is from http://www.fourcc.org/fccyvrgb.php. 29 // pixel. The conversion formula is from http://www.fourcc.org/fccyvrgb.php.
(...skipping 22 matching lines...) Expand all
50 BOOL _hasUnpackRowLength; 52 BOOL _hasUnpackRowLength;
51 GLint _currentTextureSet; 53 GLint _currentTextureSet;
52 // Handles for OpenGL constructs. 54 // Handles for OpenGL constructs.
53 GLuint _textures[kNumTextures]; 55 GLuint _textures[kNumTextures];
54 GLuint _i420Program; 56 GLuint _i420Program;
55 GLuint _vertexArray; 57 GLuint _vertexArray;
56 GLuint _vertexBuffer; 58 GLuint _vertexBuffer;
57 GLint _ySampler; 59 GLint _ySampler;
58 GLint _uSampler; 60 GLint _uSampler;
59 GLint _vSampler; 61 GLint _vSampler;
62 // Store current rotation and only upload new vertex data when rotation
63 // changes.
64 rtc::Optional<int> _current_rotation;
tkchin_webrtc 2016/08/08 22:58:45 nit: camelcase for objc files _currentRotation
magjed_webrtc 2016/08/09 13:54:27 Done.
60 // Used to create a non-padded plane for GPU upload when we receive padded 65 // Used to create a non-padded plane for GPU upload when we receive padded
61 // frames. 66 // frames.
62 std::vector<uint8_t> _planeBuffer; 67 std::vector<uint8_t> _planeBuffer;
63 } 68 }
64 69
65 - (instancetype)initWithContext:(GlContextType *)context { 70 - (instancetype)initWithContext:(GlContextType *)context {
66 if (self = [super init]) { 71 if (self = [super init]) {
67 #if TARGET_OS_IPHONE 72 #if TARGET_OS_IPHONE
68 _hasUnpackRowLength = (context.API == kEAGLRenderingAPIOpenGLES3); 73 _hasUnpackRowLength = (context.API == kEAGLRenderingAPIOpenGLES3);
69 #else 74 #else
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 117
113 - (BOOL)drawFrame:(RTCVideoFrame*)frame { 118 - (BOOL)drawFrame:(RTCVideoFrame*)frame {
114 glUseProgram(_i420Program); 119 glUseProgram(_i420Program);
115 if (![self updateTextureDataForFrame:frame]) { 120 if (![self updateTextureDataForFrame:frame]) {
116 return NO; 121 return NO;
117 } 122 }
118 #if !TARGET_OS_IPHONE 123 #if !TARGET_OS_IPHONE
119 glBindVertexArray(_vertexArray); 124 glBindVertexArray(_vertexArray);
120 #endif 125 #endif
121 glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); 126 glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
127 if (!_current_rotation || frame.rotation != *_current_rotation) {
128 _current_rotation = rtc::Optional<int>(frame.rotation);
129 RTCSetVertexData(frame.rotation);
130 }
122 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 131 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
123 132
124 return YES; 133 return YES;
125 } 134 }
126 135
127 - (void)uploadPlane:(const uint8_t *)plane 136 - (void)uploadPlane:(const uint8_t *)plane
128 sampler:(GLint)sampler 137 sampler:(GLint)sampler
129 offset:(GLint)offset 138 offset:(GLint)offset
130 width:(size_t)width 139 width:(size_t)width
131 height:(size_t)height 140 height:(size_t)height
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 offset:textureOffset + 2 211 offset:textureOffset + 2
203 width:frame.chromaWidth 212 width:frame.chromaWidth
204 height:frame.chromaHeight 213 height:frame.chromaHeight
205 stride:frame.vPitch]; 214 stride:frame.vPitch];
206 215
207 _currentTextureSet = (_currentTextureSet + 1) % kNumTextureSets; 216 _currentTextureSet = (_currentTextureSet + 1) % kNumTextureSets;
208 return YES; 217 return YES;
209 } 218 }
210 219
211 @end 220 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698