| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)), | 121 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)), |
| 122 output_surface_(output_surface), | 122 output_surface_(output_surface), |
| 123 context_(output_surface->context3d()), | 123 context_(output_surface->context3d()), |
| 124 is_viewport_changed_(false), | 124 is_viewport_changed_(false), |
| 125 is_backbuffer_discarded_(false), | 125 is_backbuffer_discarded_(false), |
| 126 discard_backbuffer_when_not_visible_(false), | 126 discard_backbuffer_when_not_visible_(false), |
| 127 is_using_bind_uniform_(false), | 127 is_using_bind_uniform_(false), |
| 128 visible_(true), | 128 visible_(true), |
| 129 is_scissor_enabled_(false), | 129 is_scissor_enabled_(false), |
| 130 highp_threshold_min_(highp_threshold_min), | 130 highp_threshold_min_(highp_threshold_min), |
| 131 highp_threshold_cache_(0), |
| 131 on_demand_tile_raster_resource_id_(0) { | 132 on_demand_tile_raster_resource_id_(0) { |
| 132 DCHECK(context_); | 133 DCHECK(context_); |
| 133 } | 134 } |
| 134 | 135 |
| 135 bool GLRenderer::Initialize() { | 136 bool GLRenderer::Initialize() { |
| 136 if (!context_->makeContextCurrent()) | 137 if (!context_->makeContextCurrent()) |
| 137 return false; | 138 return false; |
| 138 | 139 |
| 139 context_->pushGroupMarkerEXT("CompositorContext"); | 140 context_->pushGroupMarkerEXT("CompositorContext"); |
| 140 | 141 |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 Context()->bindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); | 765 Context()->bindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
| 765 } else { | 766 } else { |
| 766 contents_resource_lock = make_scoped_ptr( | 767 contents_resource_lock = make_scoped_ptr( |
| 767 new ResourceProvider::ScopedSamplerGL(resource_provider_, | 768 new ResourceProvider::ScopedSamplerGL(resource_provider_, |
| 768 contents_texture->id(), | 769 contents_texture->id(), |
| 769 GL_TEXTURE_2D, | 770 GL_TEXTURE_2D, |
| 770 GL_LINEAR)); | 771 GL_LINEAR)); |
| 771 } | 772 } |
| 772 | 773 |
| 773 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 774 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 774 context_, highp_threshold_min_, | 775 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 775 quad->shared_quad_state->visible_content_rect.bottom_right()); | 776 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 776 | 777 |
| 777 int shader_quad_location = -1; | 778 int shader_quad_location = -1; |
| 778 int shader_edge_location = -1; | 779 int shader_edge_location = -1; |
| 779 int shader_mask_sampler_location = -1; | 780 int shader_mask_sampler_location = -1; |
| 780 int shader_mask_tex_coord_scale_location = -1; | 781 int shader_mask_tex_coord_scale_location = -1; |
| 781 int shader_mask_tex_coord_offset_location = -1; | 782 int shader_mask_tex_coord_offset_location = -1; |
| 782 int shader_matrix_location = -1; | 783 int shader_matrix_location = -1; |
| 783 int shader_alpha_location = -1; | 784 int shader_alpha_location = -1; |
| 784 int shader_color_matrix_location = -1; | 785 int shader_color_matrix_location = -1; |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 clamp_tex_rect.Inset(tex_clamp_x, tex_clamp_y, tex_clamp_x, tex_clamp_y); | 1245 clamp_tex_rect.Inset(tex_clamp_x, tex_clamp_y, tex_clamp_x, tex_clamp_y); |
| 1245 | 1246 |
| 1246 // Map clamping rectangle to unit square. | 1247 // Map clamping rectangle to unit square. |
| 1247 float vertex_tex_translate_x = -clamp_geom_rect.x() / clamp_geom_rect.width(); | 1248 float vertex_tex_translate_x = -clamp_geom_rect.x() / clamp_geom_rect.width(); |
| 1248 float vertex_tex_translate_y = | 1249 float vertex_tex_translate_y = |
| 1249 -clamp_geom_rect.y() / clamp_geom_rect.height(); | 1250 -clamp_geom_rect.y() / clamp_geom_rect.height(); |
| 1250 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); | 1251 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); |
| 1251 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); | 1252 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); |
| 1252 | 1253 |
| 1253 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1254 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1254 context_, highp_threshold_min_, quad->texture_size); | 1255 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1256 quad->texture_size); |
| 1255 | 1257 |
| 1256 // Map to normalized texture coordinates. | 1258 // Map to normalized texture coordinates. |
| 1257 gfx::Size texture_size = quad->texture_size; | 1259 gfx::Size texture_size = quad->texture_size; |
| 1258 float fragment_tex_translate_x = clamp_tex_rect.x() / texture_size.width(); | 1260 float fragment_tex_translate_x = clamp_tex_rect.x() / texture_size.width(); |
| 1259 float fragment_tex_translate_y = clamp_tex_rect.y() / texture_size.height(); | 1261 float fragment_tex_translate_y = clamp_tex_rect.y() / texture_size.height(); |
| 1260 float fragment_tex_scale_x = clamp_tex_rect.width() / texture_size.width(); | 1262 float fragment_tex_scale_x = clamp_tex_rect.width() / texture_size.width(); |
| 1261 float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height(); | 1263 float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height(); |
| 1262 | 1264 |
| 1263 gfx::Transform device_transform = | 1265 gfx::Transform device_transform = |
| 1264 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); | 1266 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 tile_rect.size()); | 1364 tile_rect.size()); |
| 1363 DrawQuadGeometry( | 1365 DrawQuadGeometry( |
| 1364 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); | 1366 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); |
| 1365 } | 1367 } |
| 1366 | 1368 |
| 1367 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, | 1369 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
| 1368 const YUVVideoDrawQuad* quad) { | 1370 const YUVVideoDrawQuad* quad) { |
| 1369 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1371 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1370 | 1372 |
| 1371 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1373 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1372 context_, highp_threshold_min_, | 1374 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1373 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1375 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1374 | 1376 |
| 1375 const VideoYUVProgram* program = GetVideoYUVProgram(tex_coord_precision); | 1377 const VideoYUVProgram* program = GetVideoYUVProgram(tex_coord_precision); |
| 1376 DCHECK(program && (program->initialized() || IsContextLost())); | 1378 DCHECK(program && (program->initialized() || IsContextLost())); |
| 1377 | 1379 |
| 1378 GLC(Context(), Context()->activeTexture(GL_TEXTURE1)); | 1380 GLC(Context(), Context()->activeTexture(GL_TEXTURE1)); |
| 1379 ResourceProvider::ScopedSamplerGL y_plane_lock( | 1381 ResourceProvider::ScopedSamplerGL y_plane_lock( |
| 1380 resource_provider_, quad->y_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR); | 1382 resource_provider_, quad->y_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR); |
| 1381 GLC(Context(), Context()->activeTexture(GL_TEXTURE2)); | 1383 GLC(Context(), Context()->activeTexture(GL_TEXTURE2)); |
| 1382 ResourceProvider::ScopedSamplerGL u_plane_lock( | 1384 ResourceProvider::ScopedSamplerGL u_plane_lock( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 | 1436 |
| 1435 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 1437 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
| 1436 const StreamVideoDrawQuad* quad) { | 1438 const StreamVideoDrawQuad* quad) { |
| 1437 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1439 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1438 | 1440 |
| 1439 static float gl_matrix[16]; | 1441 static float gl_matrix[16]; |
| 1440 | 1442 |
| 1441 DCHECK(capabilities_.using_egl_image); | 1443 DCHECK(capabilities_.using_egl_image); |
| 1442 | 1444 |
| 1443 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1445 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1444 context_, highp_threshold_min_, | 1446 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1445 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1447 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1446 | 1448 |
| 1447 const VideoStreamTextureProgram* program = | 1449 const VideoStreamTextureProgram* program = |
| 1448 GetVideoStreamTextureProgram(tex_coord_precision); | 1450 GetVideoStreamTextureProgram(tex_coord_precision); |
| 1449 SetUseProgram(program->program()); | 1451 SetUseProgram(program->program()); |
| 1450 | 1452 |
| 1451 ToGLMatrix(&gl_matrix[0], quad->matrix); | 1453 ToGLMatrix(&gl_matrix[0], quad->matrix); |
| 1452 GLC(Context(), | 1454 GLC(Context(), |
| 1453 Context()->uniformMatrix4fv( | 1455 Context()->uniformMatrix4fv( |
| 1454 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); | 1456 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 // Clear the cache. | 1610 // Clear the cache. |
| 1609 draw_cache_.program_id = 0; | 1611 draw_cache_.program_id = 0; |
| 1610 draw_cache_.uv_xform_data.resize(0); | 1612 draw_cache_.uv_xform_data.resize(0); |
| 1611 draw_cache_.vertex_opacity_data.resize(0); | 1613 draw_cache_.vertex_opacity_data.resize(0); |
| 1612 draw_cache_.matrix_data.resize(0); | 1614 draw_cache_.matrix_data.resize(0); |
| 1613 } | 1615 } |
| 1614 | 1616 |
| 1615 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, | 1617 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, |
| 1616 const TextureDrawQuad* quad) { | 1618 const TextureDrawQuad* quad) { |
| 1617 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1619 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1618 context_, highp_threshold_min_, | 1620 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1619 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1621 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1620 | 1622 |
| 1621 // Choose the correct texture program binding | 1623 // Choose the correct texture program binding |
| 1622 TexTransformTextureProgramBinding binding; | 1624 TexTransformTextureProgramBinding binding; |
| 1623 if (quad->flipped) | 1625 if (quad->flipped) |
| 1624 binding.Set(GetTextureProgramFlip(tex_coord_precision), Context()); | 1626 binding.Set(GetTextureProgramFlip(tex_coord_precision), Context()); |
| 1625 else | 1627 else |
| 1626 binding.Set(GetTextureProgram(tex_coord_precision), Context()); | 1628 binding.Set(GetTextureProgram(tex_coord_precision), Context()); |
| 1627 | 1629 |
| 1628 int resource_id = quad->resource_id; | 1630 int resource_id = quad->resource_id; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; | 1665 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; |
| 1664 | 1666 |
| 1665 Float16 m; | 1667 Float16 m; |
| 1666 quad_rect_matrix.matrix().asColMajorf(m.data); | 1668 quad_rect_matrix.matrix().asColMajorf(m.data); |
| 1667 draw_cache_.matrix_data.push_back(m); | 1669 draw_cache_.matrix_data.push_back(m); |
| 1668 } | 1670 } |
| 1669 | 1671 |
| 1670 void GLRenderer::DrawTextureQuad(const DrawingFrame* frame, | 1672 void GLRenderer::DrawTextureQuad(const DrawingFrame* frame, |
| 1671 const TextureDrawQuad* quad) { | 1673 const TextureDrawQuad* quad) { |
| 1672 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1674 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1673 context_, highp_threshold_min_, | 1675 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1674 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1676 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1675 | 1677 |
| 1676 TexTransformTextureProgramBinding binding; | 1678 TexTransformTextureProgramBinding binding; |
| 1677 if (quad->flipped) | 1679 if (quad->flipped) |
| 1678 binding.Set(GetTextureProgramFlip(tex_coord_precision), Context()); | 1680 binding.Set(GetTextureProgramFlip(tex_coord_precision), Context()); |
| 1679 else | 1681 else |
| 1680 binding.Set(GetTextureProgram(tex_coord_precision), Context()); | 1682 binding.Set(GetTextureProgram(tex_coord_precision), Context()); |
| 1681 SetUseProgram(binding.program_id); | 1683 SetUseProgram(binding.program_id); |
| 1682 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); | 1684 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); |
| 1683 gfx::PointF uv0 = quad->uv_top_left; | 1685 gfx::PointF uv0 = quad->uv_top_left; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 | 1719 |
| 1718 if (!quad->premultiplied_alpha) | 1720 if (!quad->premultiplied_alpha) |
| 1719 GLC(context_, context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 1721 GLC(context_, context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
| 1720 } | 1722 } |
| 1721 | 1723 |
| 1722 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, | 1724 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, |
| 1723 const IOSurfaceDrawQuad* quad) { | 1725 const IOSurfaceDrawQuad* quad) { |
| 1724 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1726 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1725 | 1727 |
| 1726 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1728 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1727 context_, highp_threshold_min_, | 1729 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1728 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1730 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1729 | 1731 |
| 1730 TexTransformTextureProgramBinding binding; | 1732 TexTransformTextureProgramBinding binding; |
| 1731 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision), Context()); | 1733 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision), Context()); |
| 1732 | 1734 |
| 1733 SetUseProgram(binding.program_id); | 1735 SetUseProgram(binding.program_id); |
| 1734 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); | 1736 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); |
| 1735 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) { | 1737 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) { |
| 1736 GLC(Context(), | 1738 GLC(Context(), |
| 1737 Context()->uniform4f(binding.tex_transform_location, | 1739 Context()->uniform4f(binding.tex_transform_location, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 context_->uniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); | 1865 context_->uniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); |
| 1864 | 1866 |
| 1865 GLC(context_, context_->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); | 1867 GLC(context_, context_->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); |
| 1866 } | 1868 } |
| 1867 | 1869 |
| 1868 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame, | 1870 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame, |
| 1869 int texture_id, | 1871 int texture_id, |
| 1870 gfx::Rect rect, | 1872 gfx::Rect rect, |
| 1871 const gfx::Transform& draw_matrix) { | 1873 const gfx::Transform& draw_matrix) { |
| 1872 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1874 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1873 context_, highp_threshold_min_, rect.bottom_right()); | 1875 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1876 rect.bottom_right()); |
| 1874 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision); | 1877 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision); |
| 1875 | 1878 |
| 1876 GLC(Context(), Context()->bindTexture(GL_TEXTURE_2D, texture_id)); | 1879 GLC(Context(), Context()->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 1877 | 1880 |
| 1878 SetUseProgram(program->program()); | 1881 SetUseProgram(program->program()); |
| 1879 GLC(Context(), | 1882 GLC(Context(), |
| 1880 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | 1883 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1881 GLC(Context(), | 1884 GLC(Context(), |
| 1882 Context()->uniform4f(program->vertex_shader().tex_transform_location(), | 1885 Context()->uniform4f(program->vertex_shader().tex_transform_location(), |
| 1883 0.0f, | 1886 0.0f, |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2782 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 2785 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
| 2783 | 2786 |
| 2784 ReleaseRenderPassTextures(); | 2787 ReleaseRenderPassTextures(); |
| 2785 } | 2788 } |
| 2786 | 2789 |
| 2787 bool GLRenderer::IsContextLost() { | 2790 bool GLRenderer::IsContextLost() { |
| 2788 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2791 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 2789 } | 2792 } |
| 2790 | 2793 |
| 2791 } // namespace cc | 2794 } // namespace cc |
| OLD | NEW |