| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 gfx::PointF uv0 = quad->uv_top_left; | 89 gfx::PointF uv0 = quad->uv_top_left; |
| 90 gfx::PointF uv1 = quad->uv_bottom_right; | 90 gfx::PointF uv1 = quad->uv_bottom_right; |
| 91 Float4 xform = { { uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y() } }; | 91 Float4 xform = { { uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y() } }; |
| 92 if (quad->flipped) { | 92 if (quad->flipped) { |
| 93 xform.data[1] = 1.0f - xform.data[1]; | 93 xform.data[1] = 1.0f - xform.data[1]; |
| 94 xform.data[3] = -xform.data[3]; | 94 xform.data[3] = -xform.data[3]; |
| 95 } | 95 } |
| 96 return xform; | 96 return xform; |
| 97 } | 97 } |
| 98 | 98 |
| 99 Float4 PremultipliedColor(SkColor color) { |
| 100 const float factor = 1.0f / 255.0f; |
| 101 const float alpha = SkColorGetA(color) * factor; |
| 102 |
| 103 Float4 result = { { |
| 104 SkColorGetR(color) * factor * alpha, |
| 105 SkColorGetG(color) * factor * alpha, |
| 106 SkColorGetB(color) * factor * alpha, |
| 107 alpha |
| 108 } }; |
| 109 return result; |
| 110 } |
| 111 |
| 99 // Smallest unit that impact anti-aliasing output. We use this to | 112 // Smallest unit that impact anti-aliasing output. We use this to |
| 100 // determine when anti-aliasing is unnecessary. | 113 // determine when anti-aliasing is unnecessary. |
| 101 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; | 114 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; |
| 102 | 115 |
| 103 } // anonymous namespace | 116 } // anonymous namespace |
| 104 | 117 |
| 105 struct GLRenderer::PendingAsyncReadPixels { | 118 struct GLRenderer::PendingAsyncReadPixels { |
| 106 PendingAsyncReadPixels() : buffer(0) {} | 119 PendingAsyncReadPixels() : buffer(0) {} |
| 107 | 120 |
| 108 scoped_ptr<CopyOutputRequest> copy_request; | 121 scoped_ptr<CopyOutputRequest> copy_request; |
| (...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1678 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); | 1691 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); |
| 1679 } | 1692 } |
| 1680 | 1693 |
| 1681 struct TextureProgramBinding { | 1694 struct TextureProgramBinding { |
| 1682 template <class Program> | 1695 template <class Program> |
| 1683 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1696 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
| 1684 DCHECK(program && (program->initialized() || context->isContextLost())); | 1697 DCHECK(program && (program->initialized() || context->isContextLost())); |
| 1685 program_id = program->program(); | 1698 program_id = program->program(); |
| 1686 sampler_location = program->fragment_shader().sampler_location(); | 1699 sampler_location = program->fragment_shader().sampler_location(); |
| 1687 matrix_location = program->vertex_shader().matrix_location(); | 1700 matrix_location = program->vertex_shader().matrix_location(); |
| 1688 alpha_location = program->fragment_shader().alpha_location(); | 1701 background_color_location = |
| 1702 program->fragment_shader().background_color_location(); |
| 1689 } | 1703 } |
| 1690 int program_id; | 1704 int program_id; |
| 1691 int sampler_location; | 1705 int sampler_location; |
| 1692 int matrix_location; | 1706 int matrix_location; |
| 1693 int alpha_location; | 1707 int background_color_location; |
| 1694 }; | 1708 }; |
| 1695 | 1709 |
| 1696 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 1710 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
| 1697 template <class Program> | 1711 template <class Program> |
| 1698 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1712 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
| 1699 TextureProgramBinding::Set(program, context); | 1713 TextureProgramBinding::Set(program, context); |
| 1700 tex_transform_location = program->vertex_shader().tex_transform_location(); | 1714 tex_transform_location = program->vertex_shader().tex_transform_location(); |
| 1701 vertex_opacity_location = | 1715 vertex_opacity_location = |
| 1702 program->vertex_shader().vertex_opacity_location(); | 1716 program->vertex_shader().vertex_opacity_location(); |
| 1703 } | 1717 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 context_->uniformMatrix4fv( | 1751 context_->uniformMatrix4fv( |
| 1738 static_cast<int>(draw_cache_.matrix_location), | 1752 static_cast<int>(draw_cache_.matrix_location), |
| 1739 static_cast<int>(draw_cache_.matrix_data.size()), | 1753 static_cast<int>(draw_cache_.matrix_data.size()), |
| 1740 false, | 1754 false, |
| 1741 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()))); | 1755 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()))); |
| 1742 GLC(context_, | 1756 GLC(context_, |
| 1743 context_->uniform4fv( | 1757 context_->uniform4fv( |
| 1744 static_cast<int>(draw_cache_.uv_xform_location), | 1758 static_cast<int>(draw_cache_.uv_xform_location), |
| 1745 static_cast<int>(draw_cache_.uv_xform_data.size()), | 1759 static_cast<int>(draw_cache_.uv_xform_data.size()), |
| 1746 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()))); | 1760 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()))); |
| 1761 |
| 1762 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { |
| 1763 Float4 background_color = PremultipliedColor(draw_cache_.background_color); |
| 1764 GLC(context_, |
| 1765 context_->uniform4fv( |
| 1766 draw_cache_.background_color_location, 1, background_color.data)); |
| 1767 } |
| 1768 |
| 1747 GLC(context_, | 1769 GLC(context_, |
| 1748 context_->uniform1fv( | 1770 context_->uniform1fv( |
| 1749 static_cast<int>(draw_cache_.vertex_opacity_location), | 1771 static_cast<int>(draw_cache_.vertex_opacity_location), |
| 1750 static_cast<int>(draw_cache_.vertex_opacity_data.size()), | 1772 static_cast<int>(draw_cache_.vertex_opacity_data.size()), |
| 1751 static_cast<float*>(&draw_cache_.vertex_opacity_data.front()))); | 1773 static_cast<float*>(&draw_cache_.vertex_opacity_data.front()))); |
| 1752 | 1774 |
| 1753 // Draw the quads! | 1775 // Draw the quads! |
| 1754 GLC(context_, | 1776 GLC(context_, |
| 1755 context_->drawElements(GL_TRIANGLES, | 1777 context_->drawElements(GL_TRIANGLES, |
| 1756 6 * draw_cache_.matrix_data.size(), | 1778 6 * draw_cache_.matrix_data.size(), |
| 1757 GL_UNSIGNED_SHORT, | 1779 GL_UNSIGNED_SHORT, |
| 1758 0)); | 1780 0)); |
| 1759 | 1781 |
| 1760 // Clear the cache. | 1782 // Clear the cache. |
| 1761 draw_cache_.program_id = 0; | 1783 draw_cache_.program_id = 0; |
| 1762 draw_cache_.uv_xform_data.resize(0); | 1784 draw_cache_.uv_xform_data.resize(0); |
| 1763 draw_cache_.vertex_opacity_data.resize(0); | 1785 draw_cache_.vertex_opacity_data.resize(0); |
| 1764 draw_cache_.matrix_data.resize(0); | 1786 draw_cache_.matrix_data.resize(0); |
| 1765 } | 1787 } |
| 1766 | 1788 |
| 1767 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, | 1789 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, |
| 1768 const TextureDrawQuad* quad) { | 1790 const TextureDrawQuad* quad) { |
| 1769 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1791 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1770 context_, &highp_threshold_cache_, highp_threshold_min_, | 1792 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1771 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1793 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1772 | 1794 |
| 1773 // Choose the correct texture program binding | 1795 // Choose the correct texture program binding |
| 1774 TexTransformTextureProgramBinding binding; | 1796 TexTransformTextureProgramBinding binding; |
| 1775 if (quad->premultiplied_alpha) { | 1797 if (quad->premultiplied_alpha) { |
| 1776 binding.Set(GetTextureProgram(tex_coord_precision), Context()); | 1798 if (quad->background_color == SK_ColorTRANSPARENT) { |
| 1799 binding.Set(GetTextureProgram(tex_coord_precision), Context()); |
| 1800 } else { |
| 1801 binding.Set(GetTextureBackgroundProgram(tex_coord_precision), Context()); |
| 1802 } |
| 1777 } else { | 1803 } else { |
| 1778 binding.Set(GetNonPremultipliedTextureProgram(tex_coord_precision), | 1804 if (quad->background_color == SK_ColorTRANSPARENT) { |
| 1779 Context()); | 1805 binding.Set(GetNonPremultipliedTextureProgram(tex_coord_precision), |
| 1806 Context()); |
| 1807 } else { |
| 1808 binding.Set( |
| 1809 GetNonPremultipliedTextureBackgroundProgram(tex_coord_precision), |
| 1810 Context()); |
| 1811 } |
| 1780 } | 1812 } |
| 1781 | 1813 |
| 1782 int resource_id = quad->resource_id; | 1814 int resource_id = quad->resource_id; |
| 1783 | 1815 |
| 1784 if (draw_cache_.program_id != binding.program_id || | 1816 if (draw_cache_.program_id != binding.program_id || |
| 1785 draw_cache_.resource_id != resource_id || | 1817 draw_cache_.resource_id != resource_id || |
| 1786 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || | 1818 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || |
| 1819 draw_cache_.background_color != quad->background_color || |
| 1787 draw_cache_.matrix_data.size() >= 8) { | 1820 draw_cache_.matrix_data.size() >= 8) { |
| 1788 FlushTextureQuadCache(); | 1821 FlushTextureQuadCache(); |
| 1789 draw_cache_.program_id = binding.program_id; | 1822 draw_cache_.program_id = binding.program_id; |
| 1790 draw_cache_.resource_id = resource_id; | 1823 draw_cache_.resource_id = resource_id; |
| 1791 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); | 1824 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); |
| 1825 draw_cache_.background_color = quad->background_color; |
| 1792 | 1826 |
| 1793 draw_cache_.uv_xform_location = binding.tex_transform_location; | 1827 draw_cache_.uv_xform_location = binding.tex_transform_location; |
| 1828 draw_cache_.background_color_location = binding.background_color_location; |
| 1794 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; | 1829 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; |
| 1795 draw_cache_.matrix_location = binding.matrix_location; | 1830 draw_cache_.matrix_location = binding.matrix_location; |
| 1796 draw_cache_.sampler_location = binding.sampler_location; | 1831 draw_cache_.sampler_location = binding.sampler_location; |
| 1797 } | 1832 } |
| 1798 | 1833 |
| 1799 // Generate the uv-transform | 1834 // Generate the uv-transform |
| 1800 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); | 1835 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); |
| 1801 | 1836 |
| 1802 // Generate the vertex opacity | 1837 // Generate the vertex opacity |
| 1803 const float opacity = quad->opacity(); | 1838 const float opacity = quad->opacity(); |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2791 new NonPremultipliedTextureProgram(context_, precision)); | 2826 new NonPremultipliedTextureProgram(context_, precision)); |
| 2792 } | 2827 } |
| 2793 if (!program->initialized()) { | 2828 if (!program->initialized()) { |
| 2794 TRACE_EVENT0("cc", | 2829 TRACE_EVENT0("cc", |
| 2795 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); | 2830 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
| 2796 program->Initialize(context_, is_using_bind_uniform_); | 2831 program->Initialize(context_, is_using_bind_uniform_); |
| 2797 } | 2832 } |
| 2798 return program.get(); | 2833 return program.get(); |
| 2799 } | 2834 } |
| 2800 | 2835 |
| 2836 const GLRenderer::TextureBackgroundProgram* |
| 2837 GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision) { |
| 2838 scoped_ptr<TextureBackgroundProgram>& program = |
| 2839 (precision == TexCoordPrecisionHigh) ? texture_background_program_highp_ |
| 2840 : texture_background_program_; |
| 2841 if (!program) { |
| 2842 program = make_scoped_ptr( |
| 2843 new TextureBackgroundProgram(context_, precision)); |
| 2844 } |
| 2845 if (!program->initialized()) { |
| 2846 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); |
| 2847 program->Initialize(context_, is_using_bind_uniform_); |
| 2848 } |
| 2849 return program.get(); |
| 2850 } |
| 2851 |
| 2852 const GLRenderer::NonPremultipliedTextureBackgroundProgram* |
| 2853 GLRenderer::GetNonPremultipliedTextureBackgroundProgram( |
| 2854 TexCoordPrecision precision) { |
| 2855 scoped_ptr<NonPremultipliedTextureBackgroundProgram>& program = |
| 2856 (precision == TexCoordPrecisionHigh) ? |
| 2857 nonpremultiplied_texture_background_program_highp_ : |
| 2858 nonpremultiplied_texture_background_program_; |
| 2859 if (!program) { |
| 2860 program = make_scoped_ptr( |
| 2861 new NonPremultipliedTextureBackgroundProgram(context_, precision)); |
| 2862 } |
| 2863 if (!program->initialized()) { |
| 2864 TRACE_EVENT0("cc", |
| 2865 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
| 2866 program->Initialize(context_, is_using_bind_uniform_); |
| 2867 } |
| 2868 return program.get(); |
| 2869 } |
| 2870 |
| 2801 const GLRenderer::TextureIOSurfaceProgram* | 2871 const GLRenderer::TextureIOSurfaceProgram* |
| 2802 GLRenderer::GetTextureIOSurfaceProgram(TexCoordPrecision precision) { | 2872 GLRenderer::GetTextureIOSurfaceProgram(TexCoordPrecision precision) { |
| 2803 scoped_ptr<TextureIOSurfaceProgram>& program = | 2873 scoped_ptr<TextureIOSurfaceProgram>& program = |
| 2804 (precision == TexCoordPrecisionHigh) ? texture_io_surface_program_highp_ | 2874 (precision == TexCoordPrecisionHigh) ? texture_io_surface_program_highp_ |
| 2805 : texture_io_surface_program_; | 2875 : texture_io_surface_program_; |
| 2806 if (!program) | 2876 if (!program) |
| 2807 program = | 2877 program = |
| 2808 make_scoped_ptr(new TextureIOSurfaceProgram(context_, precision)); | 2878 make_scoped_ptr(new TextureIOSurfaceProgram(context_, precision)); |
| 2809 if (!program->initialized()) { | 2879 if (!program->initialized()) { |
| 2810 TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); | 2880 TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2922 render_pass_mask_color_matrix_program_aa_highp_->Cleanup(context_); | 2992 render_pass_mask_color_matrix_program_aa_highp_->Cleanup(context_); |
| 2923 if (render_pass_color_matrix_program_aa_highp_) | 2993 if (render_pass_color_matrix_program_aa_highp_) |
| 2924 render_pass_color_matrix_program_aa_highp_->Cleanup(context_); | 2994 render_pass_color_matrix_program_aa_highp_->Cleanup(context_); |
| 2925 if (render_pass_mask_color_matrix_program_highp_) | 2995 if (render_pass_mask_color_matrix_program_highp_) |
| 2926 render_pass_mask_color_matrix_program_highp_->Cleanup(context_); | 2996 render_pass_mask_color_matrix_program_highp_->Cleanup(context_); |
| 2927 | 2997 |
| 2928 if (texture_program_) | 2998 if (texture_program_) |
| 2929 texture_program_->Cleanup(context_); | 2999 texture_program_->Cleanup(context_); |
| 2930 if (nonpremultiplied_texture_program_) | 3000 if (nonpremultiplied_texture_program_) |
| 2931 nonpremultiplied_texture_program_->Cleanup(context_); | 3001 nonpremultiplied_texture_program_->Cleanup(context_); |
| 3002 if (texture_background_program_) |
| 3003 texture_background_program_->Cleanup(context_); |
| 3004 if (nonpremultiplied_texture_background_program_) |
| 3005 nonpremultiplied_texture_background_program_->Cleanup(context_); |
| 2932 if (texture_io_surface_program_) | 3006 if (texture_io_surface_program_) |
| 2933 texture_io_surface_program_->Cleanup(context_); | 3007 texture_io_surface_program_->Cleanup(context_); |
| 2934 | 3008 |
| 2935 if (texture_program_highp_) | 3009 if (texture_program_highp_) |
| 2936 texture_program_highp_->Cleanup(context_); | 3010 texture_program_highp_->Cleanup(context_); |
| 2937 if (nonpremultiplied_texture_program_highp_) | 3011 if (nonpremultiplied_texture_program_highp_) |
| 2938 nonpremultiplied_texture_program_highp_->Cleanup(context_); | 3012 nonpremultiplied_texture_program_highp_->Cleanup(context_); |
| 3013 if (texture_background_program_highp_) |
| 3014 texture_background_program_highp_->Cleanup(context_); |
| 3015 if (nonpremultiplied_texture_background_program_highp_) |
| 3016 nonpremultiplied_texture_background_program_highp_->Cleanup(context_); |
| 2939 if (texture_io_surface_program_highp_) | 3017 if (texture_io_surface_program_highp_) |
| 2940 texture_io_surface_program_highp_->Cleanup(context_); | 3018 texture_io_surface_program_highp_->Cleanup(context_); |
| 2941 | 3019 |
| 2942 if (video_yuv_program_) | 3020 if (video_yuv_program_) |
| 2943 video_yuv_program_->Cleanup(context_); | 3021 video_yuv_program_->Cleanup(context_); |
| 2944 if (video_yuva_program_) | 3022 if (video_yuva_program_) |
| 2945 video_yuva_program_->Cleanup(context_); | 3023 video_yuva_program_->Cleanup(context_); |
| 2946 if (video_stream_texture_program_) | 3024 if (video_stream_texture_program_) |
| 2947 video_stream_texture_program_->Cleanup(context_); | 3025 video_stream_texture_program_->Cleanup(context_); |
| 2948 | 3026 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3025 std::string unique_context_name = base::StringPrintf( | 3103 std::string unique_context_name = base::StringPrintf( |
| 3026 "%s-Offscreen-%p", | 3104 "%s-Offscreen-%p", |
| 3027 Settings().compositor_name.c_str(), | 3105 Settings().compositor_name.c_str(), |
| 3028 context_); | 3106 context_); |
| 3029 resource_provider()->offscreen_context_provider()->Context3d()-> | 3107 resource_provider()->offscreen_context_provider()->Context3d()-> |
| 3030 pushGroupMarkerEXT(unique_context_name.c_str()); | 3108 pushGroupMarkerEXT(unique_context_name.c_str()); |
| 3031 } | 3109 } |
| 3032 | 3110 |
| 3033 | 3111 |
| 3034 } // namespace cc | 3112 } // namespace cc |
| OLD | NEW |