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