Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 // Native CVPixelBufferRef rendering is only supported on iPhone because it | 13 // Native CVPixelBufferRef rendering is only supported on iPhone because it | 
| 14 // depends on CVOpenGLESTextureCacheCreate. | 14 // depends on CVOpenGLESTextureCacheCreate. | 
| 15 #if TARGET_OS_IPHONE | 15 #if TARGET_OS_IPHONE | 
| 16 | 16 | 
| 17 #import <CoreVideo/CVOpenGLESTextureCache.h> | 17 #import <CoreVideo/CVOpenGLESTextureCache.h> | 
| 18 | 18 | 
| 19 #import "RTCShader+Private.h" | 19 #import "RTCShader+Private.h" | 
| 20 #import "WebRTC/RTCVideoFrame.h" | 20 #import "WebRTC/RTCVideoFrame.h" | 
| 21 | 21 | 
| 22 #include "webrtc/base/checks.h" | 22 #include "webrtc/base/checks.h" | 
| 23 #include "webrtc/base/optional.h" | |
| 23 | 24 | 
| 24 static const char kNV12FragmentShaderSource[] = | 25 static const char kNV12FragmentShaderSource[] = | 
| 25 SHADER_VERSION | 26 SHADER_VERSION | 
| 26 "precision mediump float;" | 27 "precision mediump float;" | 
| 27 FRAGMENT_SHADER_IN " vec2 v_texcoord;\n" | 28 FRAGMENT_SHADER_IN " vec2 v_texcoord;\n" | 
| 28 "uniform lowp sampler2D s_textureY;\n" | 29 "uniform lowp sampler2D s_textureY;\n" | 
| 29 "uniform lowp sampler2D s_textureUV;\n" | 30 "uniform lowp sampler2D s_textureUV;\n" | 
| 30 FRAGMENT_SHADER_OUT | 31 FRAGMENT_SHADER_OUT | 
| 31 "void main() {\n" | 32 "void main() {\n" | 
| 32 " mediump float y;\n" | 33 " mediump float y;\n" | 
| 33 " mediump vec2 uv;\n" | 34 " mediump vec2 uv;\n" | 
| 34 " y = " FRAGMENT_SHADER_TEXTURE "(s_textureY, v_texcoord).r;\n" | 35 " y = " FRAGMENT_SHADER_TEXTURE "(s_textureY, v_texcoord).r;\n" | 
| 35 " uv = " FRAGMENT_SHADER_TEXTURE "(s_textureUV, v_texcoord).ra -\n" | 36 " uv = " FRAGMENT_SHADER_TEXTURE "(s_textureUV, v_texcoord).ra -\n" | 
| 36 " vec2(0.5, 0.5);\n" | 37 " vec2(0.5, 0.5);\n" | 
| 37 " " FRAGMENT_SHADER_COLOR " = vec4(y + 1.403 * uv.y,\n" | 38 " " FRAGMENT_SHADER_COLOR " = vec4(y + 1.403 * uv.y,\n" | 
| 38 " y - 0.344 * uv.x - 0.714 * uv.y,\n" | 39 " y - 0.344 * uv.x - 0.714 * uv.y,\n" | 
| 39 " y + 1.770 * uv.x,\n" | 40 " y + 1.770 * uv.x,\n" | 
| 40 " 1.0);\n" | 41 " 1.0);\n" | 
| 41 " }\n"; | 42 " }\n"; | 
| 42 | 43 | 
| 43 @implementation RTCNativeNV12Shader { | 44 @implementation RTCNativeNV12Shader { | 
| 44 GLuint _vertexBuffer; | 45 GLuint _vertexBuffer; | 
| 45 GLuint _nv12Program; | 46 GLuint _nv12Program; | 
| 46 GLint _ySampler; | 47 GLint _ySampler; | 
| 47 GLint _uvSampler; | 48 GLint _uvSampler; | 
| 48 CVOpenGLESTextureCacheRef _textureCache; | 49 CVOpenGLESTextureCacheRef _textureCache; | 
| 50 // Store current rotation and only upload new vertex data when rotation | |
| 51 // changes. | |
| 52 rtc::Optional<int> _current_rotation; | |
| 
 
tkchin_webrtc
2016/08/08 22:58:45
ditto
 
magjed_webrtc
2016/08/09 13:54:27
Done.
 
 | |
| 49 } | 53 } | 
| 50 | 54 | 
| 51 - (instancetype)initWithContext:(GlContextType *)context { | 55 - (instancetype)initWithContext:(GlContextType *)context { | 
| 52 if (self = [super init]) { | 56 if (self = [super init]) { | 
| 53 if (![self setupNV12Program] || ![self setupTextureCacheWithContext:context] || | 57 if (![self setupNV12Program] || ![self setupTextureCacheWithContext:context] || | 
| 54 !RTCSetupVerticesForProgram(_nv12Program, &_vertexBuffer, nullptr)) { | 58 !RTCSetupVerticesForProgram(_nv12Program, &_vertexBuffer, nullptr)) { | 
| 55 self = nil; | 59 self = nil; | 
| 56 } | 60 } | 
| 57 } | 61 } | 
| 58 return self; | 62 return self; | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 | 146 | 
| 143 RTC_CHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 147 RTC_CHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 
| 144 CVOpenGLESTextureGetTarget(chromaTexture)); | 148 CVOpenGLESTextureGetTarget(chromaTexture)); | 
| 145 glBindTexture(GL_TEXTURE_2D, CVOpenGLESTextureGetName(chromaTexture)); | 149 glBindTexture(GL_TEXTURE_2D, CVOpenGLESTextureGetName(chromaTexture)); | 
| 146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 
| 147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 
| 148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 
| 149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 
| 150 | 154 | 
| 151 glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); | 155 glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); | 
| 156 if (!_current_rotation || frame.rotation != *_current_rotation) { | |
| 157 _current_rotation = rtc::Optional<int>(frame.rotation); | |
| 158 RTCSetVertexData(frame.rotation); | |
| 159 } | |
| 152 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 160 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
| 153 | 161 | 
| 154 CFRelease(chromaTexture); | 162 CFRelease(chromaTexture); | 
| 155 CFRelease(lumaTexture); | 163 CFRelease(lumaTexture); | 
| 156 | 164 | 
| 157 return YES; | 165 return YES; | 
| 158 } | 166 } | 
| 159 | 167 | 
| 160 @end | 168 @end | 
| 161 #endif // TARGET_OS_IPHONE | 169 #endif // TARGET_OS_IPHONE | 
| OLD | NEW |