OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "gpu/command_buffer/service/gl_utils.h" | 11 #include "gpu/command_buffer/service/gl_utils.h" |
12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 13 #include "gpu/command_buffer/service/texture_manager.h" |
13 #include "ui/gl/gl_version_info.h" | 14 #include "ui/gl/gl_version_info.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, | 18 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
18 0.0f, 1.0f, 0.0f, 0.0f, | 19 0.0f, 1.0f, 0.0f, 0.0f, |
19 0.0f, 0.0f, 1.0f, 0.0f, | 20 0.0f, 0.0f, 1.0f, 0.0f, |
20 0.0f, 0.0f, 0.0f, 1.0f}; | 21 0.0f, 0.0f, 0.0f, 1.0f}; |
21 | 22 |
22 enum FragmentShaderId { | 23 enum { |
23 FRAGMENT_SHADER_COPY_TEXTURE_2D, | 24 SAMPLER_2D, |
24 FRAGMENT_SHADER_COPY_TEXTURE_RECTANGLE_ARB, | 25 SAMPLER_RECTANGLE_ARB, |
25 FRAGMENT_SHADER_COPY_TEXTURE_EXTERNAL_OES, | 26 SAMPLER_EXTERNAL_OES, |
26 FRAGMENT_SHADER_COPY_TEXTURE_PREMULTIPLY_ALPHA_2D, | 27 NUM_SAMPLERS |
27 FRAGMENT_SHADER_COPY_TEXTURE_PREMULTIPLY_ALPHA_RECTANGLE_ARB, | |
28 FRAGMENT_SHADER_COPY_TEXTURE_PREMULTIPLY_ALPHA_EXTERNAL_OES, | |
29 FRAGMENT_SHADER_COPY_TEXTURE_UNPREMULTIPLY_ALPHA_2D, | |
30 FRAGMENT_SHADER_COPY_TEXTURE_UNPREMULTIPLY_ALPHA_RECTANGLE_ARB, | |
31 FRAGMENT_SHADER_COPY_TEXTURE_UNPREMULTIPLY_ALPHA_EXTERNAL_OES, | |
32 NUM_FRAGMENT_SHADERS, | |
33 }; | 28 }; |
34 | 29 |
| 30 enum { |
| 31 S_FORMAT_ALPHA, |
| 32 S_FORMAT_LUMINANCE, |
| 33 S_FORMAT_LUMINANCE_ALPHA, |
| 34 S_FORMAT_RED, |
| 35 S_FORMAT_RGB, |
| 36 S_FORMAT_RGBA, |
| 37 S_FORMAT_RGB8, |
| 38 S_FORMAT_RGBA8, |
| 39 S_FORMAT_BGRA_EXT, |
| 40 S_FORMAT_BGRA8_EXT, |
| 41 S_FORMAT_RGB_YCBCR_420V_CHROMIUM, |
| 42 S_FORMAT_RGB_YCBCR_422_CHROMIUM, |
| 43 S_FORMAT_COMPRESSED, |
| 44 NUM_S_FORMAT |
| 45 }; |
| 46 |
| 47 enum { |
| 48 D_FORMAT_RGB, |
| 49 D_FORMAT_RGBA, |
| 50 D_FORMAT_RGB8, |
| 51 D_FORMAT_RGBA8, |
| 52 D_FORMAT_BGRA_EXT, |
| 53 D_FORMAT_BGRA8_EXT, |
| 54 D_FORMAT_SRGB_EXT, |
| 55 D_FORMAT_SRGB_ALPHA_EXT, |
| 56 D_FORMAT_R8, |
| 57 D_FORMAT_R8UI, |
| 58 D_FORMAT_RG8, |
| 59 D_FORMAT_RG8UI, |
| 60 D_FORMAT_SRGB8, |
| 61 D_FORMAT_RGB565, |
| 62 D_FORMAT_RGB8UI, |
| 63 D_FORMAT_SRGB8_ALPHA8, |
| 64 D_FORMAT_RGB5_A1, |
| 65 D_FORMAT_RGBA4, |
| 66 D_FORMAT_RGBA8UI, |
| 67 D_FORMAT_RGB9_E5, |
| 68 D_FORMAT_R16F, |
| 69 D_FORMAT_R32F, |
| 70 D_FORMAT_RG16F, |
| 71 D_FORMAT_RG32F, |
| 72 D_FORMAT_RGB16F, |
| 73 D_FORMAT_RGB32F, |
| 74 D_FORMAT_RGBA16F, |
| 75 D_FORMAT_RGBA32F, |
| 76 D_FORMAT_R11F_G11F_B10F, |
| 77 NUM_D_FORMAT |
| 78 }; |
| 79 |
| 80 const unsigned kNumVertexShaders = NUM_SAMPLERS; |
| 81 const unsigned kNumFragmentShaders = |
| 82 4 * NUM_SAMPLERS * NUM_S_FORMAT * NUM_D_FORMAT; |
| 83 |
| 84 typedef unsigned ShaderId; |
| 85 |
| 86 ShaderId GetVertexShaderId(GLenum target) { |
| 87 ShaderId id = 0; |
| 88 switch (target) { |
| 89 case GL_TEXTURE_2D: |
| 90 id = SAMPLER_2D; |
| 91 break; |
| 92 case GL_TEXTURE_RECTANGLE_ARB: |
| 93 id = SAMPLER_RECTANGLE_ARB; |
| 94 break; |
| 95 case GL_TEXTURE_EXTERNAL_OES: |
| 96 id = SAMPLER_EXTERNAL_OES; |
| 97 break; |
| 98 default: |
| 99 NOTREACHED(); |
| 100 break; |
| 101 } |
| 102 return id; |
| 103 } |
| 104 |
35 // Returns the correct fragment shader id to evaluate the copy operation for | 105 // Returns the correct fragment shader id to evaluate the copy operation for |
36 // the premultiply alpha pixel store settings and target. | 106 // the premultiply alpha pixel store settings and target. |
37 FragmentShaderId GetFragmentShaderId(bool premultiply_alpha, | 107 ShaderId GetFragmentShaderId(bool premultiply_alpha, |
38 bool unpremultiply_alpha, | 108 bool unpremultiply_alpha, |
39 GLenum target) { | 109 GLenum target, |
40 enum { | 110 GLenum source_format, |
41 SAMPLER_2D, | 111 GLenum dest_format) { |
42 SAMPLER_RECTANGLE_ARB, | 112 unsigned alphaIndex = 0; |
43 SAMPLER_EXTERNAL_OES, | 113 unsigned targetIndex = 0; |
44 NUM_SAMPLERS | 114 unsigned sourceFormatIndex = 0; |
45 }; | 115 unsigned destFormatIndex = 0; |
46 | 116 |
47 // bit 0: premultiply alpha | 117 alphaIndex = (premultiply_alpha ? (1 << 0) : 0) | |
48 // bit 1: unpremultiply alpha | 118 (unpremultiply_alpha ? (1 << 1) : 0); |
49 static FragmentShaderId shader_ids[][NUM_SAMPLERS] = { | |
50 { | |
51 FRAGMENT_SHADER_COPY_TEXTURE_2D, | |
52 FRAGMENT_SHADER_COPY_TEXTURE_RECTANGLE_ARB, | |
53 FRAGMENT_SHADER_COPY_TEXTURE_EXTERNAL_OES, | |
54 }, | |
55 { | |
56 FRAGMENT_SHADER_COPY_TEXTURE_PREMULTIPLY_ALPHA_2D, | |
57 FRAGMENT_SHADER_COPY_TEXTURE_PREMULTIPLY_ALPHA_RECTANGLE_ARB, | |
58 FRAGMENT_SHADER_COPY_TEXTURE_PREMULTIPLY_ALPHA_EXTERNAL_OES, | |
59 }, | |
60 { | |
61 FRAGMENT_SHADER_COPY_TEXTURE_UNPREMULTIPLY_ALPHA_2D, | |
62 FRAGMENT_SHADER_COPY_TEXTURE_UNPREMULTIPLY_ALPHA_RECTANGLE_ARB, | |
63 FRAGMENT_SHADER_COPY_TEXTURE_UNPREMULTIPLY_ALPHA_EXTERNAL_OES, | |
64 }, | |
65 { | |
66 FRAGMENT_SHADER_COPY_TEXTURE_2D, | |
67 FRAGMENT_SHADER_COPY_TEXTURE_RECTANGLE_ARB, | |
68 FRAGMENT_SHADER_COPY_TEXTURE_EXTERNAL_OES, | |
69 }}; | |
70 | |
71 unsigned index = (premultiply_alpha ? (1 << 0) : 0) | | |
72 (unpremultiply_alpha ? (1 << 1) : 0); | |
73 | 119 |
74 switch (target) { | 120 switch (target) { |
75 case GL_TEXTURE_2D: | 121 case GL_TEXTURE_2D: |
76 return shader_ids[index][SAMPLER_2D]; | 122 targetIndex = SAMPLER_2D; |
| 123 break; |
77 case GL_TEXTURE_RECTANGLE_ARB: | 124 case GL_TEXTURE_RECTANGLE_ARB: |
78 return shader_ids[index][SAMPLER_RECTANGLE_ARB]; | 125 targetIndex = SAMPLER_RECTANGLE_ARB; |
| 126 break; |
79 case GL_TEXTURE_EXTERNAL_OES: | 127 case GL_TEXTURE_EXTERNAL_OES: |
80 return shader_ids[index][SAMPLER_EXTERNAL_OES]; | 128 targetIndex = SAMPLER_EXTERNAL_OES; |
| 129 break; |
81 default: | 130 default: |
82 break; | 131 NOTREACHED(); |
83 } | 132 break; |
84 | 133 } |
85 NOTREACHED(); | 134 |
86 return shader_ids[0][SAMPLER_2D]; | 135 switch (source_format) { |
| 136 case GL_ALPHA: |
| 137 sourceFormatIndex = S_FORMAT_ALPHA; |
| 138 break; |
| 139 case GL_LUMINANCE: |
| 140 sourceFormatIndex = S_FORMAT_LUMINANCE; |
| 141 break; |
| 142 case GL_LUMINANCE_ALPHA: |
| 143 sourceFormatIndex = S_FORMAT_LUMINANCE_ALPHA; |
| 144 break; |
| 145 case GL_RED: |
| 146 sourceFormatIndex = S_FORMAT_RED; |
| 147 break; |
| 148 case GL_RGB: |
| 149 sourceFormatIndex = S_FORMAT_RGB; |
| 150 break; |
| 151 case GL_RGBA: |
| 152 sourceFormatIndex = S_FORMAT_RGBA; |
| 153 break; |
| 154 case GL_RGB8: |
| 155 sourceFormatIndex = S_FORMAT_RGB8; |
| 156 break; |
| 157 case GL_RGBA8: |
| 158 sourceFormatIndex = S_FORMAT_RGBA8; |
| 159 break; |
| 160 case GL_BGRA_EXT: |
| 161 sourceFormatIndex = S_FORMAT_BGRA_EXT; |
| 162 break; |
| 163 case GL_BGRA8_EXT: |
| 164 sourceFormatIndex = S_FORMAT_BGRA8_EXT; |
| 165 break; |
| 166 case GL_RGB_YCBCR_420V_CHROMIUM: |
| 167 sourceFormatIndex = S_FORMAT_RGB_YCBCR_420V_CHROMIUM; |
| 168 break; |
| 169 case GL_RGB_YCBCR_422_CHROMIUM: |
| 170 sourceFormatIndex = S_FORMAT_RGB_YCBCR_422_CHROMIUM; |
| 171 break; |
| 172 case GL_ATC_RGB_AMD: |
| 173 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
| 174 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 175 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
| 176 case GL_ETC1_RGB8_OES: |
| 177 sourceFormatIndex = S_FORMAT_COMPRESSED; |
| 178 break; |
| 179 default: |
| 180 NOTREACHED(); |
| 181 break; |
| 182 } |
| 183 |
| 184 switch (dest_format) { |
| 185 case GL_RGB: |
| 186 destFormatIndex = D_FORMAT_RGB; |
| 187 break; |
| 188 case GL_RGBA: |
| 189 destFormatIndex = D_FORMAT_RGBA; |
| 190 break; |
| 191 case GL_RGB8: |
| 192 destFormatIndex = D_FORMAT_RGB8; |
| 193 break; |
| 194 case GL_RGBA8: |
| 195 destFormatIndex = D_FORMAT_RGBA8; |
| 196 break; |
| 197 case GL_BGRA_EXT: |
| 198 destFormatIndex = D_FORMAT_BGRA_EXT; |
| 199 break; |
| 200 case GL_BGRA8_EXT: |
| 201 destFormatIndex = D_FORMAT_BGRA8_EXT; |
| 202 break; |
| 203 case GL_SRGB_EXT: |
| 204 destFormatIndex = D_FORMAT_SRGB_EXT; |
| 205 break; |
| 206 case GL_SRGB_ALPHA_EXT: |
| 207 destFormatIndex = D_FORMAT_SRGB_ALPHA_EXT; |
| 208 break; |
| 209 case GL_R8: |
| 210 destFormatIndex = D_FORMAT_R8; |
| 211 break; |
| 212 case GL_R8UI: |
| 213 destFormatIndex = D_FORMAT_R8UI; |
| 214 break; |
| 215 case GL_RG8: |
| 216 destFormatIndex = D_FORMAT_RG8; |
| 217 break; |
| 218 case GL_RG8UI: |
| 219 destFormatIndex = D_FORMAT_RG8UI; |
| 220 break; |
| 221 case GL_SRGB8: |
| 222 destFormatIndex = D_FORMAT_SRGB8; |
| 223 break; |
| 224 case GL_RGB565: |
| 225 destFormatIndex = D_FORMAT_RGB565; |
| 226 break; |
| 227 case GL_RGB8UI: |
| 228 destFormatIndex = D_FORMAT_RGB8UI; |
| 229 break; |
| 230 case GL_SRGB8_ALPHA8: |
| 231 destFormatIndex = D_FORMAT_SRGB8_ALPHA8; |
| 232 break; |
| 233 case GL_RGB5_A1: |
| 234 destFormatIndex = D_FORMAT_RGB5_A1; |
| 235 break; |
| 236 case GL_RGBA4: |
| 237 destFormatIndex = D_FORMAT_RGBA4; |
| 238 break; |
| 239 case GL_RGBA8UI: |
| 240 destFormatIndex = D_FORMAT_RGBA8UI; |
| 241 break; |
| 242 case GL_RGB9_E5: |
| 243 destFormatIndex = D_FORMAT_RGB9_E5; |
| 244 break; |
| 245 case GL_R16F: |
| 246 destFormatIndex = D_FORMAT_R16F; |
| 247 break; |
| 248 case GL_R32F: |
| 249 destFormatIndex = D_FORMAT_R32F; |
| 250 break; |
| 251 case GL_RG16F: |
| 252 destFormatIndex = D_FORMAT_RG16F; |
| 253 break; |
| 254 case GL_RG32F: |
| 255 destFormatIndex = D_FORMAT_RG32F; |
| 256 break; |
| 257 case GL_RGB16F: |
| 258 destFormatIndex = D_FORMAT_RGB16F; |
| 259 break; |
| 260 case GL_RGB32F: |
| 261 destFormatIndex = D_FORMAT_RGB32F; |
| 262 break; |
| 263 case GL_RGBA16F: |
| 264 destFormatIndex = D_FORMAT_RGBA16F; |
| 265 break; |
| 266 case GL_RGBA32F: |
| 267 destFormatIndex = D_FORMAT_RGBA32F; |
| 268 break; |
| 269 case GL_R11F_G11F_B10F: |
| 270 destFormatIndex = D_FORMAT_R11F_G11F_B10F; |
| 271 break; |
| 272 default: |
| 273 NOTREACHED(); |
| 274 break; |
| 275 } |
| 276 |
| 277 return alphaIndex + targetIndex * 4 + sourceFormatIndex * 4 * NUM_SAMPLERS + |
| 278 destFormatIndex * 4 * NUM_SAMPLERS * NUM_S_FORMAT; |
87 } | 279 } |
88 | 280 |
89 const char* kShaderPrecisionPreamble = "\ | 281 const char* kShaderPrecisionPreamble = |
90 #ifdef GL_ES\n\ | 282 "#ifdef GL_ES\n" |
91 precision mediump float;\n\ | 283 "precision mediump float;\n" |
92 #define TexCoordPrecision mediump\n\ | 284 "#define TexCoordPrecision mediump\n" |
93 #else\n\ | 285 "#else\n" |
94 #define TexCoordPrecision\n\ | 286 "#define TexCoordPrecision\n" |
95 #endif\n"; | 287 "#endif\n"; |
96 | 288 |
97 std::string GetVertexShaderSource(const gl::GLVersionInfo& gl_version_info) { | 289 std::string GetVertexShaderSource(const gl::GLVersionInfo& gl_version_info, |
| 290 GLenum target) { |
98 std::string source; | 291 std::string source; |
99 | 292 |
100 // Preamble for core and compatibility mode. | 293 if (gl_version_info.is_es || gl_version_info.IsLowerThanGL(3, 2)) { |
101 if (gl_version_info.is_desktop_core_profile) { | 294 if (gl_version_info.is_es3 && target != GL_TEXTURE_EXTERNAL_OES) { |
102 source += std::string("\ | 295 source += "#version 300 es\n"; |
103 #version 150\n\ | 296 source += |
104 #define ATTRIBUTE in\n\ | 297 "#define ATTRIBUTE in\n" |
105 #define VARYING out\n"); | 298 "#define VARYING out\n"; |
| 299 } else { |
| 300 source += |
| 301 "#define ATTRIBUTE attribute\n" |
| 302 "#define VARYING varying\n"; |
| 303 } |
106 } else { | 304 } else { |
107 source += std::string("\ | 305 source += "#version 150\n"; |
108 #define ATTRIBUTE attribute\n\ | 306 source += |
109 #define VARYING varying\n"); | 307 "#define ATTRIBUTE in\n" |
| 308 "#define VARYING out\n"; |
110 } | 309 } |
111 | 310 |
112 // Preamble for texture precision. | 311 // Preamble for texture precision. |
113 source += std::string(kShaderPrecisionPreamble); | 312 source += kShaderPrecisionPreamble; |
114 | 313 |
115 // Main shader source. | 314 // Main shader source. |
116 source += std::string("\ | 315 source += |
117 uniform vec2 u_vertex_dest_mult;\n\ | 316 "uniform vec2 u_vertex_dest_mult;\n" |
118 uniform vec2 u_vertex_dest_add;\n\ | 317 "uniform vec2 u_vertex_dest_add;\n" |
119 uniform vec2 u_vertex_source_mult;\n\ | 318 "uniform vec2 u_vertex_source_mult;\n" |
120 uniform vec2 u_vertex_source_add;\n\ | 319 "uniform vec2 u_vertex_source_add;\n" |
121 ATTRIBUTE vec2 a_position;\n\ | 320 "ATTRIBUTE vec2 a_position;\n" |
122 VARYING TexCoordPrecision vec2 v_uv;\n\ | 321 "VARYING TexCoordPrecision vec2 v_uv;\n" |
123 void main(void) {\n\ | 322 "void main(void) {\n" |
124 gl_Position = vec4(0, 0, 0, 1);\n\ | 323 " gl_Position = vec4(0, 0, 0, 1);\n" |
125 gl_Position.xy = a_position.xy * u_vertex_dest_mult + \ | 324 " gl_Position.xy =\n" |
126 u_vertex_dest_add;\n\ | 325 " a_position.xy * u_vertex_dest_mult + u_vertex_dest_add;\n" |
127 v_uv = a_position.xy * u_vertex_source_mult + u_vertex_source_add;\n\ | 326 " v_uv = a_position.xy * u_vertex_source_mult + u_vertex_source_add;\n" |
128 }\n"); | 327 "}\n"; |
129 | 328 |
130 return source; | 329 return source; |
131 } | 330 } |
132 | 331 |
133 std::string GetFragmentShaderSource(const gl::GLVersionInfo& gl_version_info, | 332 std::string GetFragmentShaderSource(const gl::GLVersionInfo& gl_version_info, |
134 bool premultiply_alpha, | 333 bool premultiply_alpha, |
135 bool unpremultiply_alpha, | 334 bool unpremultiply_alpha, |
136 bool nv_egl_stream_consumer_external, | 335 bool nv_egl_stream_consumer_external, |
137 GLenum target) { | 336 GLenum target, |
| 337 GLenum source_format, |
| 338 GLenum dest_format) { |
138 std::string source; | 339 std::string source; |
139 | 340 |
140 // Preamble for core and compatibility mode. | 341 // Preamble for core and compatibility mode. |
141 if (gl_version_info.is_desktop_core_profile) { | 342 if (gl_version_info.is_es || gl_version_info.IsLowerThanGL(3, 2)) { |
142 source += std::string("\ | 343 if (gl_version_info.is_es3 && target != GL_TEXTURE_EXTERNAL_OES) { |
143 #version 150\n\ | 344 source += "#version 300 es\n"; |
144 out vec4 frag_color;\n\ | 345 } |
145 #define VARYING in\n\ | 346 if (target == GL_TEXTURE_EXTERNAL_OES) { |
146 #define FRAGCOLOR frag_color\n\ | 347 source += "#extension GL_OES_EGL_image_external : enable\n"; |
147 #define TextureLookup texture\n"); | 348 |
| 349 if (nv_egl_stream_consumer_external) { |
| 350 source += "#extension GL_NV_EGL_stream_consumer_external : enable\n"; |
| 351 } |
| 352 } |
148 } else { | 353 } else { |
| 354 source += "#version 150\n"; |
| 355 } |
| 356 |
| 357 // Preamble for texture precision. |
| 358 source += kShaderPrecisionPreamble; |
| 359 |
| 360 if (gpu::gles2::GLES2Util::IsSignedIntegerFormat(dest_format)) { |
| 361 source += "#define TextureType ivec4\n"; |
| 362 source += "#define ZERO 0\n"; |
| 363 source += "#define MAX_COLOR 255\n"; |
| 364 if (gpu::gles2::GLES2Util::IsSignedIntegerFormat(source_format)) |
| 365 source += "#define InnerScaleValue 1\n"; |
| 366 else if (gpu::gles2::GLES2Util::IsUnsignedIntegerFormat(source_format)) |
| 367 source += "#define InnerScaleValue 1u\n"; |
| 368 else |
| 369 source += "#define InnerScaleValue 255.0\n"; |
| 370 source += "#define OuterScaleValue 1\n"; |
| 371 } else if (gpu::gles2::GLES2Util::IsUnsignedIntegerFormat(dest_format)) { |
| 372 source += "#define TextureType uvec4\n"; |
| 373 source += "#define ZERO 0u\n"; |
| 374 source += "#define MAX_COLOR 255u\n"; |
| 375 if (gpu::gles2::GLES2Util::IsSignedIntegerFormat(source_format)) |
| 376 source += "#define InnerScaleValue 1\n"; |
| 377 else if (gpu::gles2::GLES2Util::IsUnsignedIntegerFormat(source_format)) |
| 378 source += "#define InnerScaleValue 1u\n"; |
| 379 else |
| 380 source += "#define InnerScaleValue 255.0\n"; |
| 381 source += "#define OuterScaleValue 1u\n"; |
| 382 } else { |
| 383 source += "#define TextureType vec4\n"; |
| 384 source += "#define ZERO 0.0\n"; |
| 385 source += "#define MAX_COLOR 1.0\n"; |
| 386 if (gpu::gles2::GLES2Util::IsSignedIntegerFormat(source_format)) { |
| 387 source += "#define InnerScaleValue 1\n"; |
| 388 source += "#define OuterScaleValue (1.0 / 255.0)\n"; |
| 389 } else if (gpu::gles2::GLES2Util::IsUnsignedIntegerFormat(source_format)) { |
| 390 source += "#define InnerScaleValue 1u\n"; |
| 391 source += "#define OuterScaleValue (1.0 / 255.0)\n"; |
| 392 } else { |
| 393 source += "#define InnerScaleValue 1.0\n"; |
| 394 source += "#define OuterScaleValue 1.0\n"; |
| 395 } |
| 396 } |
| 397 if (gl_version_info.is_es2 || gl_version_info.IsLowerThanGL(3, 2) || |
| 398 target == GL_TEXTURE_EXTERNAL_OES) { |
149 switch (target) { | 399 switch (target) { |
150 case GL_TEXTURE_2D: | 400 case GL_TEXTURE_2D: |
151 source += std::string("#define TextureLookup texture2D\n"); | |
152 break; | |
153 case GL_TEXTURE_RECTANGLE_ARB: | |
154 source += std::string("#define TextureLookup texture2DRect\n"); | |
155 break; | |
156 case GL_TEXTURE_EXTERNAL_OES: | 401 case GL_TEXTURE_EXTERNAL_OES: |
157 source += | 402 source += "#define TextureLookup texture2D\n"; |
158 std::string("#extension GL_OES_EGL_image_external : enable\n"); | |
159 | |
160 if (nv_egl_stream_consumer_external) { | |
161 source += std::string( | |
162 "#extension GL_NV_EGL_stream_consumer_external : enable\n"); | |
163 } | |
164 | |
165 source += std::string("#define TextureLookup texture2D\n"); | |
166 break; | 403 break; |
167 default: | 404 default: |
168 NOTREACHED(); | 405 NOTREACHED(); |
169 break; | 406 break; |
170 } | 407 } |
171 source += std::string("\ | 408 |
172 #define VARYING varying\n\ | 409 source += |
173 #define FRAGCOLOR gl_FragColor\n"); | 410 "#define VARYING varying\n" |
| 411 "#define FRAGCOLOR gl_FragColor\n"; |
| 412 } else { |
| 413 source += |
| 414 "#define VARYING in\n" |
| 415 "out TextureType frag_color;\n" |
| 416 "#define FRAGCOLOR frag_color\n" |
| 417 "#define TextureLookup texture\n"; |
174 } | 418 } |
175 | 419 |
176 // Preamble for sampler type. | 420 // Preamble for sampler type. |
177 switch (target) { | 421 switch (target) { |
178 case GL_TEXTURE_2D: | 422 case GL_TEXTURE_2D: |
179 source += std::string("#define SamplerType sampler2D\n"); | 423 source += "#define SamplerType sampler2D\n"; |
180 break; | 424 break; |
181 case GL_TEXTURE_RECTANGLE_ARB: | 425 case GL_TEXTURE_RECTANGLE_ARB: |
182 source += std::string("#define SamplerType sampler2DRect\n"); | 426 source += "#define SamplerType sampler2DRect\n"; |
183 break; | 427 break; |
184 case GL_TEXTURE_EXTERNAL_OES: | 428 case GL_TEXTURE_EXTERNAL_OES: |
185 source += std::string("#define SamplerType samplerExternalOES\n"); | 429 source += "#define SamplerType samplerExternalOES\n"; |
186 break; | 430 break; |
187 default: | 431 default: |
188 NOTREACHED(); | 432 NOTREACHED(); |
189 break; | 433 break; |
190 } | 434 } |
191 | 435 |
192 // Preamble for texture precision. | |
193 source += std::string(kShaderPrecisionPreamble); | |
194 | |
195 // Main shader source. | 436 // Main shader source. |
196 source += std::string("\ | 437 source += |
197 uniform SamplerType u_sampler;\n\ | 438 "uniform SamplerType u_sampler;\n" |
198 uniform mat4 u_tex_coord_transform;\n\ | 439 "uniform mat4 u_tex_coord_transform;\n" |
199 VARYING TexCoordPrecision vec2 v_uv;\n\ | 440 "VARYING TexCoordPrecision vec2 v_uv;\n" |
200 void main(void) {\n\ | 441 "void main(void) {\n" |
201 TexCoordPrecision vec4 uv = u_tex_coord_transform * vec4(v_uv, 0, 1);\n\ | 442 " TexCoordPrecision vec4 uv =\n" |
202 FRAGCOLOR = TextureLookup(u_sampler, uv.st);\n"); | 443 " u_tex_coord_transform * vec4(v_uv, 0, 1);\n" |
| 444 " vec4 color = TextureLookup(u_sampler, uv.st);\n" |
| 445 " FRAGCOLOR = TextureType(color * InnerScaleValue) * OuterScaleValue;\n"; |
203 | 446 |
204 // Post-processing to premultiply or un-premultiply alpha. | 447 // Post-processing to premultiply or un-premultiply alpha. |
205 if (premultiply_alpha) { | 448 // Check dest format has alpha channel first. |
206 source += std::string(" FRAGCOLOR.rgb *= FRAGCOLOR.a;\n"); | 449 if ((gpu::gles2::GLES2Util::GetChannelsForFormat(dest_format) & 0x0008) != |
207 } | 450 0) { |
208 if (unpremultiply_alpha) { | 451 if (premultiply_alpha) { |
209 source += std::string("\ | 452 source += " FRAGCOLOR.rgb *= FRAGCOLOR.a;\n"; |
210 if (FRAGCOLOR.a > 0.0)\n\ | 453 source += " FRAGCOLOR.rgb /= MAX_COLOR;\n"; |
211 FRAGCOLOR.rgb /= FRAGCOLOR.a;\n"); | 454 } |
| 455 if (unpremultiply_alpha) { |
| 456 source += |
| 457 " if (FRAGCOLOR.a > ZERO) {\n" |
| 458 " FRAGCOLOR.rgb /= FRAGCOLOR.a;\n" |
| 459 " FRAGCOLOR.rgb *= MAX_COLOR;\n" |
| 460 " }\n"; |
| 461 } |
212 } | 462 } |
213 | 463 |
214 // Main function end. | 464 // Main function end. |
215 source += std::string(" }\n"); | 465 source += "}\n"; |
216 | 466 |
217 return source; | 467 return source; |
218 } | 468 } |
219 | 469 |
| 470 GLenum getIntermediateFormat(GLenum format) { |
| 471 switch (format) { |
| 472 case GL_LUMINANCE_ALPHA: |
| 473 case GL_LUMINANCE: |
| 474 case GL_ALPHA: |
| 475 return GL_RGBA; |
| 476 case GL_SRGB_EXT: |
| 477 return GL_SRGB_ALPHA_EXT; |
| 478 case GL_RGB16F: |
| 479 return GL_RGBA16F; |
| 480 case GL_RGB9_E5: |
| 481 case GL_RGB32F: |
| 482 return GL_RGBA32F; |
| 483 case GL_SRGB8: |
| 484 return GL_SRGB8_ALPHA8; |
| 485 case GL_RGB8UI: |
| 486 return GL_RGBA8UI; |
| 487 default: |
| 488 return format; |
| 489 } |
| 490 } |
| 491 |
220 void CompileShader(GLuint shader, const char* shader_source) { | 492 void CompileShader(GLuint shader, const char* shader_source) { |
221 glShaderSource(shader, 1, &shader_source, 0); | 493 glShaderSource(shader, 1, &shader_source, 0); |
222 glCompileShader(shader); | 494 glCompileShader(shader); |
223 #ifndef NDEBUG | 495 #if DCHECK_IS_ON() |
224 GLint compile_status; | 496 GLint compile_status; |
225 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status); | 497 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status); |
226 if (GL_TRUE != compile_status) | 498 if (GL_TRUE != compile_status) { |
227 DLOG(ERROR) << "CopyTextureCHROMIUM: shader compilation failure."; | 499 char buffer[1024]; |
| 500 GLsizei length = 0; |
| 501 glGetShaderInfoLog(shader, sizeof(buffer), &length, buffer); |
| 502 std::string log(buffer, length); |
| 503 DLOG(ERROR) << "CopyTextureCHROMIUM: shader compilation failure: " << log; |
| 504 } |
228 #endif | 505 #endif |
229 } | 506 } |
230 | 507 |
231 void DeleteShader(GLuint shader) { | 508 void DeleteShader(GLuint shader) { |
232 if (shader) | 509 if (shader) |
233 glDeleteShader(shader); | 510 glDeleteShader(shader); |
234 } | 511 } |
235 | 512 |
236 bool BindFramebufferTexture2D(GLenum target, | 513 bool BindFramebufferTexture2D(GLenum target, |
237 GLuint texture_id, | 514 GLuint texture_id, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 } | 597 } |
321 | 598 |
322 } // namespace | 599 } // namespace |
323 | 600 |
324 namespace gpu { | 601 namespace gpu { |
325 namespace gles2 { | 602 namespace gles2 { |
326 | 603 |
327 CopyTextureCHROMIUMResourceManager::CopyTextureCHROMIUMResourceManager() | 604 CopyTextureCHROMIUMResourceManager::CopyTextureCHROMIUMResourceManager() |
328 : initialized_(false), | 605 : initialized_(false), |
329 nv_egl_stream_consumer_external_(false), | 606 nv_egl_stream_consumer_external_(false), |
330 vertex_shader_(0u), | 607 vertex_shaders_(kNumVertexShaders, 0u), |
331 fragment_shaders_(NUM_FRAGMENT_SHADERS, 0u), | 608 fragment_shaders_(kNumFragmentShaders, 0u), |
332 vertex_array_object_id_(0u), | 609 vertex_array_object_id_(0u), |
333 buffer_id_(0u), | 610 buffer_id_(0u), |
334 framebuffer_(0u) {} | 611 framebuffer_(0u) {} |
335 | 612 |
336 CopyTextureCHROMIUMResourceManager::~CopyTextureCHROMIUMResourceManager() { | 613 CopyTextureCHROMIUMResourceManager::~CopyTextureCHROMIUMResourceManager() { |
337 // |buffer_id_| and |framebuffer_| can be not-null because when GPU context is | 614 // |buffer_id_| and |framebuffer_| can be not-null because when GPU context is |
338 // lost, this class can be deleted without releasing resources like | 615 // lost, this class can be deleted without releasing resources like |
339 // GLES2DecoderImpl. | 616 // GLES2DecoderImpl. |
340 } | 617 } |
341 | 618 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 return; | 663 return; |
387 | 664 |
388 if (vertex_array_object_id_) { | 665 if (vertex_array_object_id_) { |
389 glDeleteVertexArraysOES(1, &vertex_array_object_id_); | 666 glDeleteVertexArraysOES(1, &vertex_array_object_id_); |
390 vertex_array_object_id_ = 0; | 667 vertex_array_object_id_ = 0; |
391 } | 668 } |
392 | 669 |
393 glDeleteFramebuffersEXT(1, &framebuffer_); | 670 glDeleteFramebuffersEXT(1, &framebuffer_); |
394 framebuffer_ = 0; | 671 framebuffer_ = 0; |
395 | 672 |
396 DeleteShader(vertex_shader_); | 673 std::for_each( |
| 674 vertex_shaders_.begin(), vertex_shaders_.end(), DeleteShader); |
397 std::for_each( | 675 std::for_each( |
398 fragment_shaders_.begin(), fragment_shaders_.end(), DeleteShader); | 676 fragment_shaders_.begin(), fragment_shaders_.end(), DeleteShader); |
399 | 677 |
400 for (ProgramMap::const_iterator it = programs_.begin(); it != programs_.end(); | 678 for (ProgramMap::const_iterator it = programs_.begin(); it != programs_.end(); |
401 ++it) { | 679 ++it) { |
402 const ProgramInfo& info = it->second; | 680 const ProgramInfo& info = it->second; |
403 glDeleteProgram(info.program); | 681 glDeleteProgram(info.program); |
404 } | 682 } |
405 | 683 |
406 glDeleteBuffersARB(1, &buffer_id_); | 684 glDeleteBuffersARB(1, &buffer_id_); |
407 buffer_id_ = 0; | 685 buffer_id_ = 0; |
408 } | 686 } |
409 | 687 |
410 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( | 688 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( |
411 const gles2::GLES2Decoder* decoder, | 689 const gles2::GLES2Decoder* decoder, |
412 GLenum source_target, | 690 GLenum source_target, |
413 GLuint source_id, | 691 GLuint source_id, |
414 GLenum source_internal_format, | 692 GLenum source_internal_format, |
415 GLenum dest_target, | 693 GLenum dest_target, |
416 GLuint dest_id, | 694 GLuint dest_id, |
417 GLenum dest_internal_format, | 695 GLenum dest_internal_format, |
418 GLsizei width, | 696 GLsizei width, |
419 GLsizei height, | 697 GLsizei height, |
420 bool flip_y, | 698 bool flip_y, |
421 bool premultiply_alpha, | 699 bool premultiply_alpha, |
422 bool unpremultiply_alpha) { | 700 bool unpremultiply_alpha, |
| 701 CopyTextureMethod method) { |
423 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 702 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
424 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | 703 |
425 // format does not contain a superset of the components required by the base | |
426 // format of internalformat. | |
427 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | |
428 bool source_format_contain_superset_of_dest_format = | |
429 (source_internal_format == dest_internal_format && | |
430 source_internal_format != GL_BGRA_EXT) || | |
431 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | |
432 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 704 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
433 // so restrict this to GL_TEXTURE_2D. | 705 // so restrict this to GL_TEXTURE_2D. |
434 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && | 706 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && |
435 !flip_y && !premultiply_alpha_change && | 707 !flip_y && !premultiply_alpha_change && method == DIRECT_COPY) { |
436 source_format_contain_superset_of_dest_format) { | |
437 DoCopyTexImage2D(decoder, | 708 DoCopyTexImage2D(decoder, |
438 source_target, | 709 source_target, |
439 source_id, | 710 source_id, |
440 dest_target, | 711 dest_target, |
441 dest_id, | 712 dest_id, |
442 dest_internal_format, | 713 dest_internal_format, |
443 width, | 714 width, |
444 height, | 715 height, |
445 framebuffer_); | 716 framebuffer_); |
446 return; | 717 return; |
447 } | 718 } |
448 | 719 |
| 720 GLuint dest_texture = dest_id; |
| 721 GLuint intermediate_texture = 0; |
| 722 if (method == DRAW_AND_COPY) { |
| 723 GLenum adjusted_internal_format = |
| 724 getIntermediateFormat(dest_internal_format); |
| 725 glGenTextures(1, &intermediate_texture); |
| 726 glBindTexture(dest_target, intermediate_texture); |
| 727 GLenum format = TextureManager::ExtractFormatFromStorageFormat( |
| 728 adjusted_internal_format); |
| 729 GLenum type = |
| 730 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); |
| 731 |
| 732 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, |
| 733 format, type, nullptr); |
| 734 dest_texture = intermediate_texture; |
| 735 dest_internal_format = adjusted_internal_format; |
| 736 } |
449 // Use kIdentityMatrix if no transform passed in. | 737 // Use kIdentityMatrix if no transform passed in. |
450 DoCopyTextureWithTransform(decoder, source_target, source_id, dest_target, | 738 DoCopyTextureWithTransform( |
451 dest_id, width, height, flip_y, premultiply_alpha, | 739 decoder, source_target, source_id, source_internal_format, dest_target, |
452 unpremultiply_alpha, kIdentityMatrix); | 740 dest_texture, dest_internal_format, width, height, flip_y, |
| 741 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); |
| 742 |
| 743 if (method == DRAW_AND_COPY) { |
| 744 DoCopyTexImage2D(decoder, dest_target, intermediate_texture, dest_target, |
| 745 dest_id, dest_internal_format, width, height, |
| 746 framebuffer_); |
| 747 glDeleteTextures(1, &intermediate_texture); |
| 748 } |
453 } | 749 } |
454 | 750 |
455 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( | 751 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( |
456 const gles2::GLES2Decoder* decoder, | 752 const gles2::GLES2Decoder* decoder, |
457 GLenum source_target, | 753 GLenum source_target, |
458 GLuint source_id, | 754 GLuint source_id, |
459 GLenum source_internal_format, | 755 GLenum source_internal_format, |
460 GLenum dest_target, | 756 GLenum dest_target, |
461 GLuint dest_id, | 757 GLuint dest_id, |
462 GLenum dest_internal_format, | 758 GLenum dest_internal_format, |
463 GLint xoffset, | 759 GLint xoffset, |
464 GLint yoffset, | 760 GLint yoffset, |
465 GLint x, | 761 GLint x, |
466 GLint y, | 762 GLint y, |
467 GLsizei width, | 763 GLsizei width, |
468 GLsizei height, | 764 GLsizei height, |
469 GLsizei dest_width, | 765 GLsizei dest_width, |
470 GLsizei dest_height, | 766 GLsizei dest_height, |
471 GLsizei source_width, | 767 GLsizei source_width, |
472 GLsizei source_height, | 768 GLsizei source_height, |
473 bool flip_y, | 769 bool flip_y, |
474 bool premultiply_alpha, | 770 bool premultiply_alpha, |
475 bool unpremultiply_alpha) { | 771 bool unpremultiply_alpha, |
| 772 CopyTextureMethod method) { |
476 bool use_gl_copy_tex_sub_image_2d = true; | 773 bool use_gl_copy_tex_sub_image_2d = true; |
477 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 774 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
478 // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver, | 775 // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver, |
479 // although opposite in Android. | 776 // although opposite in Android. |
480 // TODO(dshwang): After Mesa fixes this issue, remove this hack. | 777 // TODO(dshwang): After Mesa fixes this issue, remove this hack. |
481 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198 | 778 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198 |
482 use_gl_copy_tex_sub_image_2d = false; | 779 use_gl_copy_tex_sub_image_2d = false; |
483 #endif | 780 #endif |
484 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 781 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
485 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | 782 |
486 // format does not contain a superset of the components required by the base | |
487 // format of internalformat. | |
488 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | |
489 bool source_format_contain_superset_of_dest_format = | |
490 (source_internal_format == dest_internal_format && | |
491 source_internal_format != GL_BGRA_EXT) || | |
492 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | |
493 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 783 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
494 // so restrict this to GL_TEXTURE_2D. | 784 // so restrict this to GL_TEXTURE_2D. |
495 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && | 785 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && |
496 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && | 786 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && |
497 source_format_contain_superset_of_dest_format) { | 787 method == DIRECT_COPY) { |
498 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, | 788 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, |
499 xoffset, yoffset, x, y, width, height, framebuffer_); | 789 xoffset, yoffset, x, y, width, height, framebuffer_); |
500 return; | 790 return; |
501 } | 791 } |
502 | 792 |
| 793 GLint dest_xoffset = xoffset; |
| 794 GLint dest_yoffset = yoffset; |
| 795 GLuint dest_texture = dest_id; |
| 796 GLuint intermediate_texture = 0; |
| 797 if (method == DRAW_AND_COPY) { |
| 798 GLenum adjusted_internal_format = |
| 799 getIntermediateFormat(dest_internal_format); |
| 800 glGenTextures(1, &intermediate_texture); |
| 801 glBindTexture(dest_target, intermediate_texture); |
| 802 GLenum format = TextureManager::ExtractFormatFromStorageFormat( |
| 803 adjusted_internal_format); |
| 804 GLenum type = |
| 805 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); |
| 806 |
| 807 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, |
| 808 format, type, nullptr); |
| 809 dest_texture = intermediate_texture; |
| 810 dest_internal_format = adjusted_internal_format; |
| 811 dest_xoffset = 0; |
| 812 dest_yoffset = 0; |
| 813 dest_width = width; |
| 814 dest_height = height; |
| 815 } |
| 816 |
503 DoCopySubTextureWithTransform( | 817 DoCopySubTextureWithTransform( |
504 decoder, source_target, source_id, source_internal_format, dest_target, | 818 decoder, source_target, source_id, source_internal_format, dest_target, |
505 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, | 819 dest_texture, dest_internal_format, dest_xoffset, dest_yoffset, x, y, |
506 dest_width, dest_height, source_width, source_height, flip_y, | 820 width, height, dest_width, dest_height, source_width, source_height, |
507 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | 821 flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); |
| 822 |
| 823 if (method == DRAW_AND_COPY) { |
| 824 DoCopyTexSubImage2D(decoder, dest_target, intermediate_texture, dest_target, |
| 825 dest_id, xoffset, yoffset, 0, 0, width, height, |
| 826 framebuffer_); |
| 827 glDeleteTextures(1, &intermediate_texture); |
| 828 } |
508 } | 829 } |
509 | 830 |
510 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( | 831 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( |
511 const gles2::GLES2Decoder* decoder, | 832 const gles2::GLES2Decoder* decoder, |
512 GLenum source_target, | 833 GLenum source_target, |
513 GLuint source_id, | 834 GLuint source_id, |
514 GLenum source_internal_format, | 835 GLenum source_internal_format, |
515 GLenum dest_target, | 836 GLenum dest_target, |
516 GLuint dest_id, | 837 GLuint dest_id, |
517 GLenum dest_internal_format, | 838 GLenum dest_internal_format, |
518 GLint xoffset, | 839 GLint xoffset, |
519 GLint yoffset, | 840 GLint yoffset, |
520 GLint x, | 841 GLint x, |
521 GLint y, | 842 GLint y, |
522 GLsizei width, | 843 GLsizei width, |
523 GLsizei height, | 844 GLsizei height, |
524 GLsizei dest_width, | 845 GLsizei dest_width, |
525 GLsizei dest_height, | 846 GLsizei dest_height, |
526 GLsizei source_width, | 847 GLsizei source_width, |
527 GLsizei source_height, | 848 GLsizei source_height, |
528 bool flip_y, | 849 bool flip_y, |
529 bool premultiply_alpha, | 850 bool premultiply_alpha, |
530 bool unpremultiply_alpha, | 851 bool unpremultiply_alpha, |
531 const GLfloat transform_matrix[16]) { | 852 const GLfloat transform_matrix[16]) { |
532 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, | 853 DoCopyTextureInternal( |
533 xoffset, yoffset, x, y, width, height, dest_width, dest_height, | 854 decoder, source_target, source_id, source_internal_format, dest_target, |
534 source_width, source_height, flip_y, premultiply_alpha, | 855 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, |
535 unpremultiply_alpha, transform_matrix); | 856 dest_width, dest_height, source_width, source_height, flip_y, |
| 857 premultiply_alpha, unpremultiply_alpha, transform_matrix); |
536 } | 858 } |
537 | 859 |
538 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( | 860 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( |
539 const gles2::GLES2Decoder* decoder, | 861 const gles2::GLES2Decoder* decoder, |
540 GLenum source_target, | 862 GLenum source_target, |
541 GLuint source_id, | 863 GLuint source_id, |
| 864 GLenum source_format, |
542 GLenum dest_target, | 865 GLenum dest_target, |
543 GLuint dest_id, | 866 GLuint dest_id, |
| 867 GLenum dest_format, |
544 GLsizei width, | 868 GLsizei width, |
545 GLsizei height, | 869 GLsizei height, |
546 bool flip_y, | 870 bool flip_y, |
547 bool premultiply_alpha, | 871 bool premultiply_alpha, |
548 bool unpremultiply_alpha, | 872 bool unpremultiply_alpha, |
549 const GLfloat transform_matrix[16]) { | 873 const GLfloat transform_matrix[16]) { |
550 GLsizei dest_width = width; | 874 GLsizei dest_width = width; |
551 GLsizei dest_height = height; | 875 GLsizei dest_height = height; |
552 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, | 876 DoCopyTextureInternal( |
553 0, 0, 0, 0, width, height, dest_width, dest_height, | 877 decoder, source_target, source_id, source_format, dest_target, dest_id, |
554 width, height, flip_y, premultiply_alpha, | 878 dest_format, 0, 0, 0, 0, width, height, dest_width, dest_height, width, |
555 unpremultiply_alpha, transform_matrix); | 879 height, flip_y, premultiply_alpha, unpremultiply_alpha, transform_matrix); |
556 } | 880 } |
557 | 881 |
558 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( | 882 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( |
559 const gles2::GLES2Decoder* decoder, | 883 const gles2::GLES2Decoder* decoder, |
560 GLenum source_target, | 884 GLenum source_target, |
561 GLuint source_id, | 885 GLuint source_id, |
| 886 GLenum source_format, |
562 GLenum dest_target, | 887 GLenum dest_target, |
563 GLuint dest_id, | 888 GLuint dest_id, |
| 889 GLenum dest_format, |
564 GLint xoffset, | 890 GLint xoffset, |
565 GLint yoffset, | 891 GLint yoffset, |
566 GLint x, | 892 GLint x, |
567 GLint y, | 893 GLint y, |
568 GLsizei width, | 894 GLsizei width, |
569 GLsizei height, | 895 GLsizei height, |
570 GLsizei dest_width, | 896 GLsizei dest_width, |
571 GLsizei dest_height, | 897 GLsizei dest_height, |
572 GLsizei source_width, | 898 GLsizei source_width, |
573 GLsizei source_height, | 899 GLsizei source_height, |
(...skipping 26 matching lines...) Expand all Loading... |
600 glBindVertexArrayOES(vertex_array_object_id_); | 926 glBindVertexArrayOES(vertex_array_object_id_); |
601 } else { | 927 } else { |
602 if (!gl_version_info.is_desktop_core_profile) { | 928 if (!gl_version_info.is_desktop_core_profile) { |
603 decoder->ClearAllAttributes(); | 929 decoder->ClearAllAttributes(); |
604 } | 930 } |
605 glEnableVertexAttribArray(kVertexPositionAttrib); | 931 glEnableVertexAttribArray(kVertexPositionAttrib); |
606 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); | 932 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); |
607 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); | 933 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); |
608 } | 934 } |
609 | 935 |
610 FragmentShaderId fragment_shader_id = GetFragmentShaderId( | 936 ShaderId vertex_shader_id = GetVertexShaderId(source_target); |
611 premultiply_alpha, unpremultiply_alpha, source_target); | 937 DCHECK_LT(static_cast<size_t>(vertex_shader_id), vertex_shaders_.size()); |
| 938 ShaderId fragment_shader_id = GetFragmentShaderId( |
| 939 premultiply_alpha, unpremultiply_alpha, source_target, |
| 940 source_format, dest_format); |
612 DCHECK_LT(static_cast<size_t>(fragment_shader_id), fragment_shaders_.size()); | 941 DCHECK_LT(static_cast<size_t>(fragment_shader_id), fragment_shaders_.size()); |
613 | 942 |
614 ProgramMapKey key(fragment_shader_id); | 943 ProgramMapKey key(fragment_shader_id); |
615 ProgramInfo* info = &programs_[key]; | 944 ProgramInfo* info = &programs_[key]; |
616 // Create program if necessary. | 945 // Create program if necessary. |
617 if (!info->program) { | 946 if (!info->program) { |
618 info->program = glCreateProgram(); | 947 info->program = glCreateProgram(); |
619 if (!vertex_shader_) { | 948 GLuint* vertex_shader = &vertex_shaders_[vertex_shader_id]; |
620 vertex_shader_ = glCreateShader(GL_VERTEX_SHADER); | 949 if (!*vertex_shader) { |
621 std::string source = GetVertexShaderSource(gl_version_info); | 950 *vertex_shader = glCreateShader(GL_VERTEX_SHADER); |
622 CompileShader(vertex_shader_, source.c_str()); | 951 std::string source = |
| 952 GetVertexShaderSource(gl_version_info, source_target); |
| 953 CompileShader(*vertex_shader, source.c_str()); |
623 } | 954 } |
624 glAttachShader(info->program, vertex_shader_); | 955 glAttachShader(info->program, *vertex_shader); |
625 GLuint* fragment_shader = &fragment_shaders_[fragment_shader_id]; | 956 GLuint* fragment_shader = &fragment_shaders_[fragment_shader_id]; |
626 if (!*fragment_shader) { | 957 if (!*fragment_shader) { |
627 *fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); | 958 *fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); |
628 std::string source = GetFragmentShaderSource( | 959 std::string source = GetFragmentShaderSource( |
629 gl_version_info, premultiply_alpha, unpremultiply_alpha, | 960 gl_version_info, premultiply_alpha, unpremultiply_alpha, |
630 nv_egl_stream_consumer_external_, source_target); | 961 nv_egl_stream_consumer_external_, source_target, source_format, |
| 962 dest_format); |
631 CompileShader(*fragment_shader, source.c_str()); | 963 CompileShader(*fragment_shader, source.c_str()); |
632 } | 964 } |
633 glAttachShader(info->program, *fragment_shader); | 965 glAttachShader(info->program, *fragment_shader); |
634 glBindAttribLocation(info->program, kVertexPositionAttrib, "a_position"); | 966 glBindAttribLocation(info->program, kVertexPositionAttrib, "a_position"); |
635 glLinkProgram(info->program); | 967 glLinkProgram(info->program); |
636 #ifndef NDEBUG | 968 #ifndef NDEBUG |
637 GLint linked; | 969 GLint linked; |
638 glGetProgramiv(info->program, GL_LINK_STATUS, &linked); | 970 glGetProgramiv(info->program, GL_LINK_STATUS, &linked); |
639 if (!linked) | 971 if (!linked) |
640 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; | 972 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 decoder->RestoreTextureUnitBindings(0); | 1103 decoder->RestoreTextureUnitBindings(0); |
772 decoder->RestoreActiveTexture(); | 1104 decoder->RestoreActiveTexture(); |
773 decoder->RestoreProgramBindings(); | 1105 decoder->RestoreProgramBindings(); |
774 decoder->RestoreBufferBindings(); | 1106 decoder->RestoreBufferBindings(); |
775 decoder->RestoreFramebufferBindings(); | 1107 decoder->RestoreFramebufferBindings(); |
776 decoder->RestoreGlobalState(); | 1108 decoder->RestoreGlobalState(); |
777 } | 1109 } |
778 | 1110 |
779 } // namespace gles2 | 1111 } // namespace gles2 |
780 } // namespace gpu | 1112 } // namespace gpu |
OLD | NEW |