| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame& frame, | 327 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame& frame, |
| 328 const CheckerboardDrawQuad* quad) { | 328 const CheckerboardDrawQuad* quad) { |
| 329 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 329 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 330 | 330 |
| 331 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); | 331 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); |
| 332 DCHECK(program && (program->initialized() || IsContextLost())); | 332 DCHECK(program && (program->initialized() || IsContextLost())); |
| 333 SetUseProgram(program->program()); | 333 SetUseProgram(program->program()); |
| 334 | 334 |
| 335 SkColor color = quad->color; | 335 SkColor color = quad->color; |
| 336 GLC(Context(), | 336 GLC(Context(), |
| 337 Context()->uniform4f(program->fragment_shader().colorLocation(), | 337 Context()->uniform4f(program->fragment_shader().color_location(), |
| 338 SkColorGetR(color) * (1.0f / 255.0f), | 338 SkColorGetR(color) * (1.0f / 255.0f), |
| 339 SkColorGetG(color) * (1.0f / 255.0f), | 339 SkColorGetG(color) * (1.0f / 255.0f), |
| 340 SkColorGetB(color) * (1.0f / 255.0f), | 340 SkColorGetB(color) * (1.0f / 255.0f), |
| 341 1)); | 341 1)); |
| 342 | 342 |
| 343 const int checkerboard_width = 16; | 343 const int checkerboard_width = 16; |
| 344 float frequency = 1.0f / checkerboard_width; | 344 float frequency = 1.0f / checkerboard_width; |
| 345 | 345 |
| 346 gfx::Rect tile_rect = quad->rect; | 346 gfx::Rect tile_rect = quad->rect; |
| 347 float tex_offset_x = tile_rect.x() % checkerboard_width; | 347 float tex_offset_x = tile_rect.x() % checkerboard_width; |
| 348 float tex_offset_y = tile_rect.y() % checkerboard_width; | 348 float tex_offset_y = tile_rect.y() % checkerboard_width; |
| 349 float tex_scale_x = tile_rect.width(); | 349 float tex_scale_x = tile_rect.width(); |
| 350 float tex_scale_y = tile_rect.height(); | 350 float tex_scale_y = tile_rect.height(); |
| 351 GLC(Context(), | 351 GLC(Context(), |
| 352 Context()->uniform4f(program->fragment_shader().texTransformLocation(), | 352 Context()->uniform4f(program->fragment_shader().tex_transform_location(), |
| 353 tex_offset_x, | 353 tex_offset_x, |
| 354 tex_offset_y, | 354 tex_offset_y, |
| 355 tex_scale_x, | 355 tex_scale_x, |
| 356 tex_scale_y)); | 356 tex_scale_y)); |
| 357 | 357 |
| 358 GLC(Context(), | 358 GLC(Context(), |
| 359 Context()->uniform1f(program->fragment_shader().frequencyLocation(), | 359 Context()->uniform1f(program->fragment_shader().frequency_location(), |
| 360 frequency)); | 360 frequency)); |
| 361 | 361 |
| 362 SetShaderOpacity(quad->opacity(), program->fragment_shader().alphaLocation()); | 362 SetShaderOpacity(quad->opacity(), |
| 363 program->fragment_shader().alpha_location()); |
| 363 DrawQuadGeometry(frame, | 364 DrawQuadGeometry(frame, |
| 364 quad->quadTransform(), | 365 quad->quadTransform(), |
| 365 quad->rect, | 366 quad->rect, |
| 366 program->vertex_shader().matrixLocation()); | 367 program->vertex_shader().matrix_location()); |
| 367 } | 368 } |
| 368 | 369 |
| 369 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame& frame, | 370 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame& frame, |
| 370 const DebugBorderDrawQuad* quad) { | 371 const DebugBorderDrawQuad* quad) { |
| 371 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 372 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 372 | 373 |
| 373 static float gl_matrix[16]; | 374 static float gl_matrix[16]; |
| 374 const DebugBorderProgram* program = GetDebugBorderProgram(); | 375 const DebugBorderProgram* program = GetDebugBorderProgram(); |
| 375 DCHECK(program && (program->initialized() || IsContextLost())); | 376 DCHECK(program && (program->initialized() || IsContextLost())); |
| 376 SetUseProgram(program->program()); | 377 SetUseProgram(program->program()); |
| 377 | 378 |
| 378 // Use the full quad_rect for debug quads to not move the edges based on | 379 // Use the full quad_rect for debug quads to not move the edges based on |
| 379 // partial swaps. | 380 // partial swaps. |
| 380 gfx::Rect layer_rect = quad->rect; | 381 gfx::Rect layer_rect = quad->rect; |
| 381 gfx::Transform render_matrix = quad->quadTransform(); | 382 gfx::Transform render_matrix = quad->quadTransform(); |
| 382 render_matrix.Translate(0.5f * layer_rect.width() + layer_rect.x(), | 383 render_matrix.Translate(0.5f * layer_rect.width() + layer_rect.x(), |
| 383 0.5f * layer_rect.height() + layer_rect.y()); | 384 0.5f * layer_rect.height() + layer_rect.y()); |
| 384 render_matrix.Scale(layer_rect.width(), layer_rect.height()); | 385 render_matrix.Scale(layer_rect.width(), layer_rect.height()); |
| 385 GLRenderer::ToGLMatrix(&gl_matrix[0], | 386 GLRenderer::ToGLMatrix(&gl_matrix[0], |
| 386 frame.projection_matrix * render_matrix); | 387 frame.projection_matrix * render_matrix); |
| 387 GLC(Context(), | 388 GLC(Context(), |
| 388 Context()->uniformMatrix4fv( | 389 Context()->uniformMatrix4fv( |
| 389 program->vertex_shader().matrixLocation(), 1, false, &gl_matrix[0])); | 390 program->vertex_shader().matrix_location(), 1, false, &gl_matrix[0])); |
| 390 | 391 |
| 391 SkColor color = quad->color; | 392 SkColor color = quad->color; |
| 392 float alpha = SkColorGetA(color) * (1.0f / 255.0f); | 393 float alpha = SkColorGetA(color) * (1.0f / 255.0f); |
| 393 | 394 |
| 394 GLC(Context(), | 395 GLC(Context(), |
| 395 Context()->uniform4f(program->fragment_shader().colorLocation(), | 396 Context()->uniform4f(program->fragment_shader().color_location(), |
| 396 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, | 397 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, |
| 397 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, | 398 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, |
| 398 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, | 399 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, |
| 399 alpha)); | 400 alpha)); |
| 400 | 401 |
| 401 GLC(Context(), Context()->lineWidth(quad->width)); | 402 GLC(Context(), Context()->lineWidth(quad->width)); |
| 402 | 403 |
| 403 // The indices for the line are stored in the same array as the triangle | 404 // The indices for the line are stored in the same array as the triangle |
| 404 // indices. | 405 // indices. |
| 405 GLC(Context(), | 406 GLC(Context(), |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 int shader_mask_tex_coord_offset_location = -1; | 724 int shader_mask_tex_coord_offset_location = -1; |
| 724 int shader_matrix_location = -1; | 725 int shader_matrix_location = -1; |
| 725 int shader_alpha_location = -1; | 726 int shader_alpha_location = -1; |
| 726 int shader_tex_transform_location = -1; | 727 int shader_tex_transform_location = -1; |
| 727 int shader_tex_scale_location = -1; | 728 int shader_tex_scale_location = -1; |
| 728 | 729 |
| 729 if (use_aa && mask_texture_id) { | 730 if (use_aa && mask_texture_id) { |
| 730 const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA(); | 731 const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA(); |
| 731 SetUseProgram(program->program()); | 732 SetUseProgram(program->program()); |
| 732 GLC(Context(), | 733 GLC(Context(), |
| 733 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); | 734 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 734 | 735 |
| 735 shader_quad_location = program->vertex_shader().pointLocation(); | 736 shader_quad_location = program->vertex_shader().point_location(); |
| 736 shader_edge_location = program->fragment_shader().edgeLocation(); | 737 shader_edge_location = program->fragment_shader().edge_location(); |
| 737 shader_mask_sampler_location = | 738 shader_mask_sampler_location = |
| 738 program->fragment_shader().maskSamplerLocation(); | 739 program->fragment_shader().mask_sampler_location(); |
| 739 shader_mask_tex_coord_scale_location = | 740 shader_mask_tex_coord_scale_location = |
| 740 program->fragment_shader().maskTexCoordScaleLocation(); | 741 program->fragment_shader().mask_tex_coord_scale_location(); |
| 741 shader_mask_tex_coord_offset_location = | 742 shader_mask_tex_coord_offset_location = |
| 742 program->fragment_shader().maskTexCoordOffsetLocation(); | 743 program->fragment_shader().mask_tex_coord_offset_location(); |
| 743 shader_matrix_location = program->vertex_shader().matrixLocation(); | 744 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 744 shader_alpha_location = program->fragment_shader().alphaLocation(); | 745 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 745 shader_tex_scale_location = program->vertex_shader().texScaleLocation(); | 746 shader_tex_scale_location = program->vertex_shader().tex_scale_location(); |
| 746 } else if (!use_aa && mask_texture_id) { | 747 } else if (!use_aa && mask_texture_id) { |
| 747 const RenderPassMaskProgram* program = GetRenderPassMaskProgram(); | 748 const RenderPassMaskProgram* program = GetRenderPassMaskProgram(); |
| 748 SetUseProgram(program->program()); | 749 SetUseProgram(program->program()); |
| 749 GLC(Context(), | 750 GLC(Context(), |
| 750 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); | 751 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 751 | 752 |
| 752 shader_mask_sampler_location = | 753 shader_mask_sampler_location = |
| 753 program->fragment_shader().maskSamplerLocation(); | 754 program->fragment_shader().mask_sampler_location(); |
| 754 shader_mask_tex_coord_scale_location = | 755 shader_mask_tex_coord_scale_location = |
| 755 program->fragment_shader().maskTexCoordScaleLocation(); | 756 program->fragment_shader().mask_tex_coord_scale_location(); |
| 756 shader_mask_tex_coord_offset_location = | 757 shader_mask_tex_coord_offset_location = |
| 757 program->fragment_shader().maskTexCoordOffsetLocation(); | 758 program->fragment_shader().mask_tex_coord_offset_location(); |
| 758 shader_matrix_location = program->vertex_shader().matrixLocation(); | 759 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 759 shader_alpha_location = program->fragment_shader().alphaLocation(); | 760 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 760 shader_tex_transform_location = | 761 shader_tex_transform_location = |
| 761 program->vertex_shader().texTransformLocation(); | 762 program->vertex_shader().tex_transform_location(); |
| 762 } else if (use_aa && !mask_texture_id) { | 763 } else if (use_aa && !mask_texture_id) { |
| 763 const RenderPassProgramAA* program = GetRenderPassProgramAA(); | 764 const RenderPassProgramAA* program = GetRenderPassProgramAA(); |
| 764 SetUseProgram(program->program()); | 765 SetUseProgram(program->program()); |
| 765 GLC(Context(), | 766 GLC(Context(), |
| 766 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); | 767 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 767 | 768 |
| 768 shader_quad_location = program->vertex_shader().pointLocation(); | 769 shader_quad_location = program->vertex_shader().point_location(); |
| 769 shader_edge_location = program->fragment_shader().edgeLocation(); | 770 shader_edge_location = program->fragment_shader().edge_location(); |
| 770 shader_matrix_location = program->vertex_shader().matrixLocation(); | 771 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 771 shader_alpha_location = program->fragment_shader().alphaLocation(); | 772 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 772 shader_tex_scale_location = program->vertex_shader().texScaleLocation(); | 773 shader_tex_scale_location = program->vertex_shader().tex_scale_location(); |
| 773 } else { | 774 } else { |
| 774 const RenderPassProgram* program = GetRenderPassProgram(); | 775 const RenderPassProgram* program = GetRenderPassProgram(); |
| 775 SetUseProgram(program->program()); | 776 SetUseProgram(program->program()); |
| 776 GLC(Context(), | 777 GLC(Context(), |
| 777 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); | 778 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 778 | 779 |
| 779 shader_matrix_location = program->vertex_shader().matrixLocation(); | 780 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 780 shader_alpha_location = program->fragment_shader().alphaLocation(); | 781 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 781 shader_tex_transform_location = | 782 shader_tex_transform_location = |
| 782 program->vertex_shader().texTransformLocation(); | 783 program->vertex_shader().tex_transform_location(); |
| 783 } | 784 } |
| 784 | 785 |
| 785 float tex_scale_x = | 786 float tex_scale_x = |
| 786 quad->rect.width() / static_cast<float>(contents_texture->size().width()); | 787 quad->rect.width() / static_cast<float>(contents_texture->size().width()); |
| 787 float tex_scale_y = quad->rect.height() / | 788 float tex_scale_y = quad->rect.height() / |
| 788 static_cast<float>(contents_texture->size().height()); | 789 static_cast<float>(contents_texture->size().height()); |
| 789 DCHECK_LE(tex_scale_x, 1.0f); | 790 DCHECK_LE(tex_scale_x, 1.0f); |
| 790 DCHECK_LE(tex_scale_y, 1.0f); | 791 DCHECK_LE(tex_scale_y, 1.0f); |
| 791 | 792 |
| 792 if (shader_tex_transform_location != -1) { | 793 if (shader_tex_transform_location != -1) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 unsigned color_location; | 854 unsigned color_location; |
| 854 unsigned point_location; | 855 unsigned point_location; |
| 855 unsigned tex_scale_location; | 856 unsigned tex_scale_location; |
| 856 unsigned edge_location; | 857 unsigned edge_location; |
| 857 }; | 858 }; |
| 858 | 859 |
| 859 template<class T> | 860 template<class T> |
| 860 static void SolidColorUniformLocation(T program, | 861 static void SolidColorUniformLocation(T program, |
| 861 SolidColorProgramUniforms* uniforms) { | 862 SolidColorProgramUniforms* uniforms) { |
| 862 uniforms->program = program->program(); | 863 uniforms->program = program->program(); |
| 863 uniforms->matrix_location = program->vertex_shader().matrixLocation(); | 864 uniforms->matrix_location = program->vertex_shader().matrix_location(); |
| 864 uniforms->color_location = program->fragment_shader().colorLocation(); | 865 uniforms->color_location = program->fragment_shader().color_location(); |
| 865 uniforms->point_location = program->vertex_shader().pointLocation(); | 866 uniforms->point_location = program->vertex_shader().point_location(); |
| 866 uniforms->tex_scale_location = program->vertex_shader().texScaleLocation(); | 867 uniforms->tex_scale_location = program->vertex_shader().tex_scale_location(); |
| 867 uniforms->edge_location = program->fragment_shader().edgeLocation(); | 868 uniforms->edge_location = program->fragment_shader().edge_location(); |
| 868 } | 869 } |
| 869 | 870 |
| 870 bool GLRenderer::SetupQuadForAntialiasing( | 871 bool GLRenderer::SetupQuadForAntialiasing( |
| 871 const gfx::Transform& device_transform, | 872 const gfx::Transform& device_transform, |
| 872 const DrawQuad* quad, | 873 const DrawQuad* quad, |
| 873 gfx::QuadF* local_quad, | 874 gfx::QuadF* local_quad, |
| 874 float edge[24]) const { | 875 float edge[24]) const { |
| 875 gfx::Rect tile_rect = quad->visible_rect; | 876 gfx::Rect tile_rect = quad->visible_rect; |
| 876 | 877 |
| 877 bool clipped = false; | 878 bool clipped = false; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 unsigned edge_location; | 1018 unsigned edge_location; |
| 1018 unsigned matrix_location; | 1019 unsigned matrix_location; |
| 1019 unsigned alpha_location; | 1020 unsigned alpha_location; |
| 1020 unsigned point_location; | 1021 unsigned point_location; |
| 1021 }; | 1022 }; |
| 1022 | 1023 |
| 1023 template <class T> | 1024 template <class T> |
| 1024 static void TileUniformLocation(T program, TileProgramUniforms* uniforms) { | 1025 static void TileUniformLocation(T program, TileProgramUniforms* uniforms) { |
| 1025 uniforms->program = program->program(); | 1026 uniforms->program = program->program(); |
| 1026 uniforms->vertex_tex_transform_location = | 1027 uniforms->vertex_tex_transform_location = |
| 1027 program->vertex_shader().vertexTexTransformLocation(); | 1028 program->vertex_shader().vertex_tex_transform_location(); |
| 1028 uniforms->matrix_location = program->vertex_shader().matrixLocation(); | 1029 uniforms->matrix_location = program->vertex_shader().matrix_location(); |
| 1029 uniforms->point_location = program->vertex_shader().pointLocation(); | 1030 uniforms->point_location = program->vertex_shader().point_location(); |
| 1030 | 1031 |
| 1031 uniforms->sampler_location = program->fragment_shader().samplerLocation(); | 1032 uniforms->sampler_location = program->fragment_shader().sampler_location(); |
| 1032 uniforms->alpha_location = program->fragment_shader().alphaLocation(); | 1033 uniforms->alpha_location = program->fragment_shader().alpha_location(); |
| 1033 uniforms->fragment_tex_transform_location = | 1034 uniforms->fragment_tex_transform_location = |
| 1034 program->fragment_shader().fragmentTexTransformLocation(); | 1035 program->fragment_shader().fragment_tex_transform_location(); |
| 1035 uniforms->edge_location = program->fragment_shader().edgeLocation(); | 1036 uniforms->edge_location = program->fragment_shader().edge_location(); |
| 1036 } | 1037 } |
| 1037 | 1038 |
| 1038 void GLRenderer::DrawTileQuad(const DrawingFrame& frame, | 1039 void GLRenderer::DrawTileQuad(const DrawingFrame& frame, |
| 1039 const TileDrawQuad* quad) { | 1040 const TileDrawQuad* quad) { |
| 1040 gfx::Rect tile_rect = quad->visible_rect; | 1041 gfx::Rect tile_rect = quad->visible_rect; |
| 1041 | 1042 |
| 1042 gfx::RectF tex_coord_rect = quad->tex_coord_rect; | 1043 gfx::RectF tex_coord_rect = quad->tex_coord_rect; |
| 1043 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); | 1044 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); |
| 1044 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); | 1045 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); |
| 1045 | 1046 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 GLC(Context(), Context()->activeTexture(GL_TEXTURE2)); | 1201 GLC(Context(), Context()->activeTexture(GL_TEXTURE2)); |
| 1201 ResourceProvider::ScopedSamplerGL u_plane_lock( | 1202 ResourceProvider::ScopedSamplerGL u_plane_lock( |
| 1202 resource_provider_, u_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR); | 1203 resource_provider_, u_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR); |
| 1203 GLC(Context(), Context()->activeTexture(GL_TEXTURE3)); | 1204 GLC(Context(), Context()->activeTexture(GL_TEXTURE3)); |
| 1204 ResourceProvider::ScopedSamplerGL v_plane_lock( | 1205 ResourceProvider::ScopedSamplerGL v_plane_lock( |
| 1205 resource_provider_, v_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR); | 1206 resource_provider_, v_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR); |
| 1206 | 1207 |
| 1207 SetUseProgram(program->program()); | 1208 SetUseProgram(program->program()); |
| 1208 | 1209 |
| 1209 GLC(Context(), | 1210 GLC(Context(), |
| 1210 Context()->uniform2f(program->vertex_shader().texScaleLocation(), | 1211 Context()->uniform2f(program->vertex_shader().tex_scale_location(), |
| 1211 quad->tex_scale.width(), | 1212 quad->tex_scale.width(), |
| 1212 quad->tex_scale.height())); | 1213 quad->tex_scale.height())); |
| 1213 GLC(Context(), | 1214 GLC(Context(), |
| 1214 Context()->uniform1i(program->fragment_shader().yTextureLocation(), 1)); | 1215 Context()->uniform1i(program->fragment_shader().y_texture_location(), 1)); |
| 1215 GLC(Context(), | 1216 GLC(Context(), |
| 1216 Context()->uniform1i(program->fragment_shader().uTextureLocation(), 2)); | 1217 Context()->uniform1i(program->fragment_shader().u_texture_location(), 2)); |
| 1217 GLC(Context(), | 1218 GLC(Context(), |
| 1218 Context()->uniform1i(program->fragment_shader().vTextureLocation(), 3)); | 1219 Context()->uniform1i(program->fragment_shader().v_texture_location(), 3)); |
| 1219 | 1220 |
| 1220 // These values are magic numbers that are used in the transformation from YUV | 1221 // These values are magic numbers that are used in the transformation from YUV |
| 1221 // to RGB color values. They are taken from the following webpage: | 1222 // to RGB color values. They are taken from the following webpage: |
| 1222 // http://www.fourcc.org/fccyvrgb.php | 1223 // http://www.fourcc.org/fccyvrgb.php |
| 1223 float yuv_to_rgb[9] = { | 1224 float yuv_to_rgb[9] = { |
| 1224 1.164f, 1.164f, 1.164f, | 1225 1.164f, 1.164f, 1.164f, |
| 1225 0.0f, -.391f, 2.018f, | 1226 0.0f, -.391f, 2.018f, |
| 1226 1.596f, -.813f, 0.0f, | 1227 1.596f, -.813f, 0.0f, |
| 1227 }; | 1228 }; |
| 1228 GLC(Context(), | 1229 GLC(Context(), |
| 1229 Context()->uniformMatrix3fv( | 1230 Context()->uniformMatrix3fv( |
| 1230 program->fragment_shader().yuvMatrixLocation(), 1, 0, yuv_to_rgb)); | 1231 program->fragment_shader().yuv_matrix_location(), 1, 0, yuv_to_rgb)); |
| 1231 | 1232 |
| 1232 // These values map to 16, 128, and 128 respectively, and are computed | 1233 // These values map to 16, 128, and 128 respectively, and are computed |
| 1233 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). | 1234 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). |
| 1234 // They are used in the YUV to RGBA conversion formula: | 1235 // They are used in the YUV to RGBA conversion formula: |
| 1235 // Y - 16 : Gives 16 values of head and footroom for overshooting | 1236 // Y - 16 : Gives 16 values of head and footroom for overshooting |
| 1236 // U - 128 : Turns unsigned U into signed U [-128,127] | 1237 // U - 128 : Turns unsigned U into signed U [-128,127] |
| 1237 // V - 128 : Turns unsigned V into signed V [-128,127] | 1238 // V - 128 : Turns unsigned V into signed V [-128,127] |
| 1238 float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, }; | 1239 float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, }; |
| 1239 GLC(Context(), | 1240 GLC(Context(), |
| 1240 Context()->uniform3fv( | 1241 Context()->uniform3fv( |
| 1241 program->fragment_shader().yuvAdjLocation(), 1, yuv_adjust)); | 1242 program->fragment_shader().yuv_adj_location(), 1, yuv_adjust)); |
| 1242 | 1243 |
| 1243 SetShaderOpacity(quad->opacity(), program->fragment_shader().alphaLocation()); | 1244 SetShaderOpacity(quad->opacity(), |
| 1245 program->fragment_shader().alpha_location()); |
| 1244 DrawQuadGeometry(frame, | 1246 DrawQuadGeometry(frame, |
| 1245 quad->quadTransform(), | 1247 quad->quadTransform(), |
| 1246 quad->rect, | 1248 quad->rect, |
| 1247 program->vertex_shader().matrixLocation()); | 1249 program->vertex_shader().matrix_location()); |
| 1248 | 1250 |
| 1249 // Reset active texture back to texture 0. | 1251 // Reset active texture back to texture 0. |
| 1250 GLC(Context(), Context()->activeTexture(GL_TEXTURE0)); | 1252 GLC(Context(), Context()->activeTexture(GL_TEXTURE0)); |
| 1251 } | 1253 } |
| 1252 | 1254 |
| 1253 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame& frame, | 1255 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame& frame, |
| 1254 const StreamVideoDrawQuad* quad) { | 1256 const StreamVideoDrawQuad* quad) { |
| 1255 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1257 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1256 | 1258 |
| 1257 static float gl_matrix[16]; | 1259 static float gl_matrix[16]; |
| 1258 | 1260 |
| 1259 DCHECK(capabilities_.using_egl_image); | 1261 DCHECK(capabilities_.using_egl_image); |
| 1260 | 1262 |
| 1261 const VideoStreamTextureProgram* program = GetVideoStreamTextureProgram(); | 1263 const VideoStreamTextureProgram* program = GetVideoStreamTextureProgram(); |
| 1262 SetUseProgram(program->program()); | 1264 SetUseProgram(program->program()); |
| 1263 | 1265 |
| 1264 ToGLMatrix(&gl_matrix[0], quad->matrix); | 1266 ToGLMatrix(&gl_matrix[0], quad->matrix); |
| 1265 GLC(Context(), | 1267 GLC(Context(), |
| 1266 Context()->uniformMatrix4fv( | 1268 Context()->uniformMatrix4fv( |
| 1267 program->vertex_shader().texMatrixLocation(), 1, false, gl_matrix)); | 1269 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); |
| 1268 | 1270 |
| 1269 GLC(Context(), | 1271 GLC(Context(), |
| 1270 Context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture_id)); | 1272 Context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture_id)); |
| 1271 | 1273 |
| 1272 GLC(Context(), | 1274 GLC(Context(), |
| 1273 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); | 1275 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1274 | 1276 |
| 1275 SetShaderOpacity(quad->opacity(), program->fragment_shader().alphaLocation()); | 1277 SetShaderOpacity(quad->opacity(), |
| 1278 program->fragment_shader().alpha_location()); |
| 1276 DrawQuadGeometry(frame, | 1279 DrawQuadGeometry(frame, |
| 1277 quad->quadTransform(), | 1280 quad->quadTransform(), |
| 1278 quad->rect, | 1281 quad->rect, |
| 1279 program->vertex_shader().matrixLocation()); | 1282 program->vertex_shader().matrix_location()); |
| 1280 } | 1283 } |
| 1281 | 1284 |
| 1282 struct TextureProgramBinding { | 1285 struct TextureProgramBinding { |
| 1283 template <class Program> | 1286 template <class Program> |
| 1284 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1287 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
| 1285 DCHECK(program && (program->initialized() || context->isContextLost())); | 1288 DCHECK(program && (program->initialized() || context->isContextLost())); |
| 1286 program_id = program->program(); | 1289 program_id = program->program(); |
| 1287 sampler_location = program->fragment_shader().samplerLocation(); | 1290 sampler_location = program->fragment_shader().sampler_location(); |
| 1288 matrix_location = program->vertex_shader().matrixLocation(); | 1291 matrix_location = program->vertex_shader().matrix_location(); |
| 1289 alpha_location = program->fragment_shader().alphaLocation(); | 1292 alpha_location = program->fragment_shader().alpha_location(); |
| 1290 } | 1293 } |
| 1291 int program_id; | 1294 int program_id; |
| 1292 int sampler_location; | 1295 int sampler_location; |
| 1293 int matrix_location; | 1296 int matrix_location; |
| 1294 int alpha_location; | 1297 int alpha_location; |
| 1295 }; | 1298 }; |
| 1296 | 1299 |
| 1297 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 1300 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
| 1298 template <class Program> | 1301 template <class Program> |
| 1299 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1302 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
| 1300 TextureProgramBinding::Set(program, context); | 1303 TextureProgramBinding::Set(program, context); |
| 1301 tex_transform_location = program->vertex_shader().texTransformLocation(); | 1304 tex_transform_location = program->vertex_shader().tex_transform_location(); |
| 1302 vertex_opacity_location = program->vertex_shader().vertexOpacityLocation(); | 1305 vertex_opacity_location = |
| 1306 program->vertex_shader().vertex_opacity_location(); |
| 1303 } | 1307 } |
| 1304 int tex_transform_location; | 1308 int tex_transform_location; |
| 1305 int vertex_opacity_location; | 1309 int vertex_opacity_location; |
| 1306 }; | 1310 }; |
| 1307 | 1311 |
| 1308 void GLRenderer::FlushTextureQuadCache() { | 1312 void GLRenderer::FlushTextureQuadCache() { |
| 1309 // Check to see if we have anything to draw. | 1313 // Check to see if we have anything to draw. |
| 1310 if (draw_cache_.program_id == 0) | 1314 if (draw_cache_.program_id == 0) |
| 1311 return; | 1315 return; |
| 1312 | 1316 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame& frame, | 1622 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame& frame, |
| 1619 int texture_id, | 1623 int texture_id, |
| 1620 gfx::Rect rect, | 1624 gfx::Rect rect, |
| 1621 const gfx::Transform& draw_matrix) { | 1625 const gfx::Transform& draw_matrix) { |
| 1622 const RenderPassProgram* program = GetRenderPassProgram(); | 1626 const RenderPassProgram* program = GetRenderPassProgram(); |
| 1623 | 1627 |
| 1624 GLC(Context(), Context()->bindTexture(GL_TEXTURE_2D, texture_id)); | 1628 GLC(Context(), Context()->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 1625 | 1629 |
| 1626 SetUseProgram(program->program()); | 1630 SetUseProgram(program->program()); |
| 1627 GLC(Context(), | 1631 GLC(Context(), |
| 1628 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); | 1632 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1629 GLC(Context(), | 1633 GLC(Context(), |
| 1630 Context()->uniform4f(program->vertex_shader().texTransformLocation(), | 1634 Context()->uniform4f(program->vertex_shader().tex_transform_location(), |
| 1631 0.0f, | 1635 0.0f, |
| 1632 0.0f, | 1636 0.0f, |
| 1633 1.0f, | 1637 1.0f, |
| 1634 1.0f)); | 1638 1.0f)); |
| 1635 SetShaderOpacity(1, program->fragment_shader().alphaLocation()); | 1639 SetShaderOpacity(1, program->fragment_shader().alpha_location()); |
| 1636 DrawQuadGeometry( | 1640 DrawQuadGeometry( |
| 1637 frame, draw_matrix, rect, program->vertex_shader().matrixLocation()); | 1641 frame, draw_matrix, rect, program->vertex_shader().matrix_location()); |
| 1638 } | 1642 } |
| 1639 | 1643 |
| 1640 void GLRenderer::Finish() { | 1644 void GLRenderer::Finish() { |
| 1641 TRACE_EVENT0("cc", "GLRenderer::finish"); | 1645 TRACE_EVENT0("cc", "GLRenderer::finish"); |
| 1642 context_->finish(); | 1646 context_->finish(); |
| 1643 } | 1647 } |
| 1644 | 1648 |
| 1645 bool GLRenderer::SwapBuffers() { | 1649 bool GLRenderer::SwapBuffers() { |
| 1646 DCHECK(visible_); | 1650 DCHECK(visible_); |
| 1647 DCHECK(!is_backbuffer_discarded_); | 1651 DCHECK(!is_backbuffer_discarded_); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2225 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2229 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); |
| 2226 | 2230 |
| 2227 ReleaseRenderPassTextures(); | 2231 ReleaseRenderPassTextures(); |
| 2228 } | 2232 } |
| 2229 | 2233 |
| 2230 bool GLRenderer::IsContextLost() { | 2234 bool GLRenderer::IsContextLost() { |
| 2231 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2235 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 2232 } | 2236 } |
| 2233 | 2237 |
| 2234 } // namespace cc | 2238 } // namespace cc |
| OLD | NEW |