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

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

Issue 2695203004: Clean up RTCVideoFrame (Closed)
Patch Set: Fix memory leak. Add ObjC rotation enum. Add space in pointer types. Created 3 years, 10 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
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // beginning at the first texcoord in the array. The last argument indicates 131 // beginning at the first texcoord in the array. The last argument indicates
132 // offset of data within |gVertices| as supplied to the vertex buffer. 132 // offset of data within |gVertices| as supplied to the vertex buffer.
133 glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 133 glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
134 (void *)(2 * sizeof(GLfloat))); 134 (void *)(2 * sizeof(GLfloat)));
135 glEnableVertexAttribArray(texcoord); 135 glEnableVertexAttribArray(texcoord);
136 136
137 return YES; 137 return YES;
138 } 138 }
139 139
140 // Set vertex data to the currently bound vertex buffer. 140 // Set vertex data to the currently bound vertex buffer.
141 void RTCSetVertexData(webrtc::VideoRotation rotation) { 141 void RTCSetVertexData(RTCVideoRotation rotation) {
142 // When modelview and projection matrices are identity (default) the world is 142 // When modelview and projection matrices are identity (default) the world is
143 // contained in the square around origin with unit size 2. Drawing to these 143 // contained in the square around origin with unit size 2. Drawing to these
144 // coordinates is equivalent to drawing to the entire screen. The texture is 144 // coordinates is equivalent to drawing to the entire screen. The texture is
145 // stretched over that square using texture coordinates (u, v) that range 145 // stretched over that square using texture coordinates (u, v) that range
146 // from (0, 0) to (1, 1) inclusive. Texture coordinates are flipped vertically 146 // from (0, 0) to (1, 1) inclusive. Texture coordinates are flipped vertically
147 // here because the incoming frame has origin in upper left hand corner but 147 // here because the incoming frame has origin in upper left hand corner but
148 // OpenGL expects origin in bottom left corner. 148 // OpenGL expects origin in bottom left corner.
149 std::array<std::array<GLfloat, 2>, 4> UVCoords = {{ 149 std::array<std::array<GLfloat, 2>, 4> UVCoords = {{
150 {{0, 1}}, // Lower left. 150 {{0, 1}}, // Lower left.
151 {{1, 1}}, // Lower right. 151 {{1, 1}}, // Lower right.
152 {{1, 0}}, // Upper right. 152 {{1, 0}}, // Upper right.
153 {{0, 0}}, // Upper left. 153 {{0, 0}}, // Upper left.
154 }}; 154 }};
155 155
156 // Rotate the UV coordinates. 156 // Rotate the UV coordinates.
157 int rotation_offset; 157 int rotation_offset;
158 switch (rotation) { 158 switch (rotation) {
159 case webrtc::kVideoRotation_0: 159 case RTCVideoRotation_0:
160 rotation_offset = 0; 160 rotation_offset = 0;
161 break; 161 break;
162 case webrtc::kVideoRotation_90: 162 case RTCVideoRotation_90:
163 rotation_offset = 1; 163 rotation_offset = 1;
164 break; 164 break;
165 case webrtc::kVideoRotation_180: 165 case RTCVideoRotation_180:
166 rotation_offset = 2; 166 rotation_offset = 2;
167 break; 167 break;
168 case webrtc::kVideoRotation_270: 168 case RTCVideoRotation_270:
169 rotation_offset = 3; 169 rotation_offset = 3;
170 break; 170 break;
171 } 171 }
172 std::rotate(UVCoords.begin(), UVCoords.begin() + rotation_offset, 172 std::rotate(UVCoords.begin(), UVCoords.begin() + rotation_offset,
173 UVCoords.end()); 173 UVCoords.end());
174 174
175 const GLfloat gVertices[] = { 175 const GLfloat gVertices[] = {
176 // X, Y, U, V. 176 // X, Y, U, V.
177 -1, -1, UVCoords[0][0], UVCoords[0][1], 177 -1, -1, UVCoords[0][0], UVCoords[0][1],
178 1, -1, UVCoords[1][0], UVCoords[1][1], 178 1, -1, UVCoords[1][0], UVCoords[1][1],
179 1, 1, UVCoords[2][0], UVCoords[2][1], 179 1, 1, UVCoords[2][0], UVCoords[2][1],
180 -1, 1, UVCoords[3][0], UVCoords[3][1], 180 -1, 1, UVCoords[3][0], UVCoords[3][1],
181 }; 181 };
182 182
183 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(gVertices), gVertices); 183 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(gVertices), gVertices);
184 } 184 }
OLDNEW
« no previous file with comments | « webrtc/sdk/objc/Framework/Classes/RTCOpenGLVideoRenderer.mm ('k') | webrtc/sdk/objc/Framework/Classes/RTCShader+Private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698