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

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

Issue 1852923002: Enable sampling from DXGI NV12 formats in GLRenderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « cc/output/shader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); 2085 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord));
2086 float u_unsigned = TextureLookup(u_texture, uv_clamped).x; 2086 float u_unsigned = TextureLookup(u_texture, uv_clamped).x;
2087 float v_unsigned = TextureLookup(v_texture, uv_clamped).x; 2087 float v_unsigned = TextureLookup(v_texture, uv_clamped).x;
2088 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; 2088 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj;
2089 vec3 rgb = yuv_matrix * yuv; 2089 vec3 rgb = yuv_matrix * yuv;
2090 gl_FragColor = vec4(rgb, 1.0) * alpha; 2090 gl_FragColor = vec4(rgb, 1.0) * alpha;
2091 } 2091 }
2092 }); 2092 });
2093 } 2093 }
2094 2094
2095 FragmentShaderNV12Video::FragmentShaderNV12Video()
2096 : y_texture_location_(-1),
2097 uv_texture_location_(-1),
2098 alpha_location_(-1),
2099 yuv_matrix_location_(-1),
2100 yuv_adj_location_(-1),
2101 ya_clamp_rect_location_(-1),
2102 uv_clamp_rect_location_(-1) {}
2103
2104 void FragmentShaderNV12Video::Init(GLES2Interface* context,
2105 unsigned program,
2106 int* base_uniform_index) {
2107 static const char* uniforms[] = {
2108 "y_texture", "uv_texture", "alpha", "yuv_matrix",
2109 "yuv_adj", "ya_clamp_rect", "uv_clamp_rect"};
2110 int locations[arraysize(uniforms)];
2111
2112 GetProgramUniformLocations(context, program, arraysize(uniforms), uniforms,
2113 locations, base_uniform_index);
2114 y_texture_location_ = locations[0];
2115 uv_texture_location_ = locations[1];
2116 alpha_location_ = locations[2];
2117 yuv_matrix_location_ = locations[3];
2118 yuv_adj_location_ = locations[4];
2119 ya_clamp_rect_location_ = locations[5];
2120 uv_clamp_rect_location_ = locations[6];
2121 }
2122
2123 std::string FragmentShaderNV12Video::GetShaderString(
2124 TexCoordPrecision precision,
2125 SamplerType sampler) const {
2126 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody());
2127 }
2128
2129 std::string FragmentShaderNV12Video::GetShaderHead() {
2130 return SHADER0([]() {
2131 precision mediump float;
2132 precision mediump int;
2133 varying TexCoordPrecision vec2 v_yaTexCoord;
2134 varying TexCoordPrecision vec2 v_uvTexCoord;
2135 uniform SamplerType y_texture;
2136 uniform SamplerType uv_texture;
2137 uniform float alpha;
2138 uniform vec3 yuv_adj;
2139 uniform mat3 yuv_matrix;
2140 uniform vec4 ya_clamp_rect;
2141 uniform vec4 uv_clamp_rect;
2142 });
2143 }
2144
2145 std::string FragmentShaderNV12Video::GetShaderBody() {
2146 return SHADER0([]() {
2147 void main() {
2148 vec2 ya_clamped =
2149 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord));
2150 float y_raw = TextureLookup(y_texture, ya_clamped).x;
2151 vec2 uv_clamped =
2152 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord));
2153 vec2 uv_unsigned = TextureLookup(uv_texture, uv_clamped).xy;
2154 vec3 yuv = vec3(y_raw, uv_unsigned) + yuv_adj;
2155 vec3 rgb = yuv_matrix * yuv;
2156 gl_FragColor = vec4(rgb, 1.0) * alpha;
2157 }
2158 });
2159 }
2160
2095 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() 2161 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo()
2096 : y_texture_location_(-1), 2162 : y_texture_location_(-1),
2097 u_texture_location_(-1), 2163 u_texture_location_(-1),
2098 v_texture_location_(-1), 2164 v_texture_location_(-1),
2099 a_texture_location_(-1), 2165 a_texture_location_(-1),
2100 alpha_location_(-1), 2166 alpha_location_(-1),
2101 yuv_matrix_location_(-1), 2167 yuv_matrix_location_(-1),
2102 yuv_adj_location_(-1) { 2168 yuv_adj_location_(-1) {
2103 } 2169 }
2104 2170
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 void main() { 2312 void main() {
2247 vec4 d4 = min(edge_dist[0], edge_dist[1]); 2313 vec4 d4 = min(edge_dist[0], edge_dist[1]);
2248 vec2 d2 = min(d4.xz, d4.yw); 2314 vec2 d2 = min(d4.xz, d4.yw);
2249 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 2315 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
2250 gl_FragColor = color * aa; 2316 gl_FragColor = color * aa;
2251 } 2317 }
2252 }); 2318 });
2253 } 2319 }
2254 2320
2255 } // namespace cc 2321 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/shader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698