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

Side by Side Diff: cc/output/shader.cc

Issue 2121043002: 16 bpp video stream capture, render and WebGL usage - Realsense R200 & SR300 support. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests: cc, skcanvas_video_renderer, wrtcrecorder... Fake capture supports Y16. Created 4 years, 2 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 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/shader.h" 5 #include "cc/output/shader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 2158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 vec2 uv_clamped = 2169 vec2 uv_clamped =
2170 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); 2170 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord));
2171 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); 2171 vec3 yuv = vec3(y_raw, GetUV(uv_clamped));
2172 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); 2172 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped);
2173 } 2173 }
2174 }); 2174 });
2175 2175
2176 return FRAGMENT_SHADER(head, functions); 2176 return FRAGMENT_SHADER(head, functions);
2177 } 2177 }
2178 2178
2179 FragmentShaderYVideo::FragmentShaderYVideo()
2180 : FragmentTexOpaqueBinding(),
2181 x_derivative_location_(-1),
2182 y_derivative_location_(-1) {}
2183
2184 void FragmentShaderYVideo::Init(GLES2Interface* context,
2185 unsigned program,
2186 int* base_uniform_index) {
2187 FragmentTexOpaqueBinding::Init(context, program, base_uniform_index);
2188
2189 static const char* uniforms[] = {"x_derivative", "y_derivative"};
2190 int locations[arraysize(uniforms)];
2191
2192 GetProgramUniformLocations(context, program, arraysize(uniforms), uniforms,
2193 locations, base_uniform_index);
2194 x_derivative_location_ = locations[0];
2195 y_derivative_location_ = locations[1];
2196 }
2197
2198 std::string FragmentShaderYVideo::GetShaderString(TexCoordPrecision precision,
2199 SamplerType sampler) const {
2200 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody());
2201 }
2202
2203 std::string FragmentShaderYVideo::GetShaderHead() {
2204 return SHADER0([]() {
2205 precision mediump float;
2206 varying TexCoordPrecision vec2 v_texCoord;
2207 uniform SamplerType s_texture;
2208 uniform float x_derivative;
2209 uniform float y_derivative;
2210 });
2211 }
2212
2213 std::string FragmentShaderYVideo::GetShaderBody() {
2214 return SHADER0([]() {
2215 vec4 TextureLookupBilinear(sampler2D sampler, highp vec2 texCoord) {
2216 vec4 s1 = texture2D(sampler, texCoord);
2217 vec4 s2 = texture2D(sampler, texCoord + vec2(x_derivative, 0.));
2218 vec4 s3 = texture2D(sampler, texCoord + vec2(0., y_derivative));
2219 vec4 s4 = texture2D(sampler, texCoord + vec2(x_derivative, y_derivative));
2220 vec2 f = fract(texCoord.xy / vec2(x_derivative, y_derivative));
2221 return mix(mix(s1, s2, f.x), mix(s3, s4, f.x), f.y);
2222 }
2223 void main() {
2224 gl_FragColor =
2225 vec4(vec3(TextureLookupBilinear(s_texture, v_texCoord).g), 1.);
2226 }
2227 });
2228 }
2229
2179 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { 2230 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) {
2180 } 2231 }
2181 2232
2182 void FragmentShaderColor::Init(GLES2Interface* context, 2233 void FragmentShaderColor::Init(GLES2Interface* context,
2183 unsigned program, 2234 unsigned program,
2184 int* base_uniform_index) { 2235 int* base_uniform_index) {
2185 static const char* uniforms[] = { 2236 static const char* uniforms[] = {
2186 "color", 2237 "color",
2187 }; 2238 };
2188 int locations[arraysize(uniforms)]; 2239 int locations[arraysize(uniforms)];
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 void main() { 2303 void main() {
2253 vec4 d4 = min(edge_dist[0], edge_dist[1]); 2304 vec4 d4 = min(edge_dist[0], edge_dist[1]);
2254 vec2 d2 = min(d4.xz, d4.yw); 2305 vec2 d2 = min(d4.xz, d4.yw);
2255 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 2306 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
2256 gl_FragColor = color * aa; 2307 gl_FragColor = color * aa;
2257 } 2308 }
2258 }); 2309 });
2259 } 2310 }
2260 2311
2261 } // namespace cc 2312 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698