Chromium Code Reviews| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 gfx::PointF uv0 = quad->uv_top_left; | 91 gfx::PointF uv0 = quad->uv_top_left; |
| 92 gfx::PointF uv1 = quad->uv_bottom_right; | 92 gfx::PointF uv1 = quad->uv_bottom_right; |
| 93 Float4 xform = { { uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y() } }; | 93 Float4 xform = { { uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y() } }; |
| 94 if (quad->flipped) { | 94 if (quad->flipped) { |
| 95 xform.data[1] = 1.0f - xform.data[1]; | 95 xform.data[1] = 1.0f - xform.data[1]; |
| 96 xform.data[3] = -xform.data[3]; | 96 xform.data[3] = -xform.data[3]; |
| 97 } | 97 } |
| 98 return xform; | 98 return xform; |
| 99 } | 99 } |
| 100 | 100 |
| 101 Float4 PremultipliedColor(SkColor color) { | |
| 102 const float factor = 1.0f / 255.0f; | |
| 103 const float alpha = SkColorGetA(color) * factor; | |
| 104 | |
| 105 Float4 result = { { | |
| 106 SkColorGetR(color) * factor * alpha, | |
| 107 SkColorGetG(color) * factor * alpha, | |
| 108 SkColorGetB(color) * factor * alpha, | |
| 109 alpha | |
| 110 } }; | |
| 111 return result; | |
| 112 } | |
| 113 | |
| 101 // Smallest unit that impact anti-aliasing output. We use this to | 114 // Smallest unit that impact anti-aliasing output. We use this to |
| 102 // determine when anti-aliasing is unnecessary. | 115 // determine when anti-aliasing is unnecessary. |
| 103 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; | 116 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; |
| 104 | 117 |
| 105 } // anonymous namespace | 118 } // anonymous namespace |
| 106 | 119 |
| 107 struct GLRenderer::PendingAsyncReadPixels { | 120 struct GLRenderer::PendingAsyncReadPixels { |
| 108 PendingAsyncReadPixels() : buffer(0) {} | 121 PendingAsyncReadPixels() : buffer(0) {} |
| 109 | 122 |
| 110 scoped_ptr<CopyOutputRequest> copy_request; | 123 scoped_ptr<CopyOutputRequest> copy_request; |
| (...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1644 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); | 1657 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); |
| 1645 } | 1658 } |
| 1646 | 1659 |
| 1647 struct TextureProgramBinding { | 1660 struct TextureProgramBinding { |
| 1648 template <class Program> | 1661 template <class Program> |
| 1649 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1662 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
| 1650 DCHECK(program && (program->initialized() || context->isContextLost())); | 1663 DCHECK(program && (program->initialized() || context->isContextLost())); |
| 1651 program_id = program->program(); | 1664 program_id = program->program(); |
| 1652 sampler_location = program->fragment_shader().sampler_location(); | 1665 sampler_location = program->fragment_shader().sampler_location(); |
| 1653 matrix_location = program->vertex_shader().matrix_location(); | 1666 matrix_location = program->vertex_shader().matrix_location(); |
| 1654 alpha_location = program->fragment_shader().alpha_location(); | 1667 background_color_location = |
| 1668 program->fragment_shader().background_color_location(); | |
| 1655 } | 1669 } |
| 1656 int program_id; | 1670 int program_id; |
| 1657 int sampler_location; | 1671 int sampler_location; |
| 1658 int matrix_location; | 1672 int matrix_location; |
| 1659 int alpha_location; | 1673 int background_color_location; |
| 1660 }; | 1674 }; |
| 1661 | 1675 |
| 1662 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 1676 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
| 1663 template <class Program> | 1677 template <class Program> |
| 1664 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1678 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
| 1665 TextureProgramBinding::Set(program, context); | 1679 TextureProgramBinding::Set(program, context); |
| 1666 tex_transform_location = program->vertex_shader().tex_transform_location(); | 1680 tex_transform_location = program->vertex_shader().tex_transform_location(); |
| 1667 vertex_opacity_location = | 1681 vertex_opacity_location = |
| 1668 program->vertex_shader().vertex_opacity_location(); | 1682 program->vertex_shader().vertex_opacity_location(); |
| 1669 } | 1683 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1704 static_cast<int>(draw_cache_.matrix_location), | 1718 static_cast<int>(draw_cache_.matrix_location), |
| 1705 static_cast<int>(draw_cache_.matrix_data.size()), | 1719 static_cast<int>(draw_cache_.matrix_data.size()), |
| 1706 false, | 1720 false, |
| 1707 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()))); | 1721 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()))); |
| 1708 GLC(context_, | 1722 GLC(context_, |
| 1709 context_->uniform4fv( | 1723 context_->uniform4fv( |
| 1710 static_cast<int>(draw_cache_.uv_xform_location), | 1724 static_cast<int>(draw_cache_.uv_xform_location), |
| 1711 static_cast<int>(draw_cache_.uv_xform_data.size()), | 1725 static_cast<int>(draw_cache_.uv_xform_data.size()), |
| 1712 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()))); | 1726 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()))); |
| 1713 GLC(context_, | 1727 GLC(context_, |
| 1728 context_->uniform4fv( | |
| 1729 static_cast<int>(draw_cache_.background_color_location), | |
| 1730 static_cast<int>(draw_cache_.background_color_data.size()), | |
| 1731 reinterpret_cast<float*>( | |
| 1732 &draw_cache_.background_color_data.front()))); | |
| 1733 GLC(context_, | |
| 1714 context_->uniform1fv( | 1734 context_->uniform1fv( |
| 1715 static_cast<int>(draw_cache_.vertex_opacity_location), | 1735 static_cast<int>(draw_cache_.vertex_opacity_location), |
| 1716 static_cast<int>(draw_cache_.vertex_opacity_data.size()), | 1736 static_cast<int>(draw_cache_.vertex_opacity_data.size()), |
| 1717 static_cast<float*>(&draw_cache_.vertex_opacity_data.front()))); | 1737 static_cast<float*>(&draw_cache_.vertex_opacity_data.front()))); |
| 1718 | 1738 |
| 1719 // Draw the quads! | 1739 // Draw the quads! |
| 1720 GLC(context_, | 1740 GLC(context_, |
| 1721 context_->drawElements(GL_TRIANGLES, | 1741 context_->drawElements(GL_TRIANGLES, |
| 1722 6 * draw_cache_.matrix_data.size(), | 1742 6 * draw_cache_.matrix_data.size(), |
| 1723 GL_UNSIGNED_SHORT, | 1743 GL_UNSIGNED_SHORT, |
| 1724 0)); | 1744 0)); |
| 1725 | 1745 |
| 1726 // Clear the cache. | 1746 // Clear the cache. |
| 1727 draw_cache_.program_id = 0; | 1747 draw_cache_.program_id = 0; |
| 1728 draw_cache_.uv_xform_data.resize(0); | 1748 draw_cache_.uv_xform_data.resize(0); |
| 1749 draw_cache_.background_color_data.resize(0); | |
| 1729 draw_cache_.vertex_opacity_data.resize(0); | 1750 draw_cache_.vertex_opacity_data.resize(0); |
| 1730 draw_cache_.matrix_data.resize(0); | 1751 draw_cache_.matrix_data.resize(0); |
| 1731 } | 1752 } |
| 1732 | 1753 |
| 1733 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, | 1754 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, |
| 1734 const TextureDrawQuad* quad) { | 1755 const TextureDrawQuad* quad) { |
| 1735 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1756 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1736 context_, &highp_threshold_cache_, highp_threshold_min_, | 1757 context_, &highp_threshold_cache_, highp_threshold_min_, |
| 1737 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1758 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1738 | 1759 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1750 if (draw_cache_.program_id != binding.program_id || | 1771 if (draw_cache_.program_id != binding.program_id || |
| 1751 draw_cache_.resource_id != resource_id || | 1772 draw_cache_.resource_id != resource_id || |
| 1752 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || | 1773 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || |
| 1753 draw_cache_.matrix_data.size() >= 8) { | 1774 draw_cache_.matrix_data.size() >= 8) { |
| 1754 FlushTextureQuadCache(); | 1775 FlushTextureQuadCache(); |
| 1755 draw_cache_.program_id = binding.program_id; | 1776 draw_cache_.program_id = binding.program_id; |
| 1756 draw_cache_.resource_id = resource_id; | 1777 draw_cache_.resource_id = resource_id; |
| 1757 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); | 1778 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); |
| 1758 | 1779 |
| 1759 draw_cache_.uv_xform_location = binding.tex_transform_location; | 1780 draw_cache_.uv_xform_location = binding.tex_transform_location; |
| 1781 draw_cache_.background_color_location = binding.background_color_location; | |
| 1760 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; | 1782 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; |
| 1761 draw_cache_.matrix_location = binding.matrix_location; | 1783 draw_cache_.matrix_location = binding.matrix_location; |
| 1762 draw_cache_.sampler_location = binding.sampler_location; | 1784 draw_cache_.sampler_location = binding.sampler_location; |
| 1763 } | 1785 } |
| 1764 | 1786 |
| 1765 // Generate the uv-transform | 1787 // Generate the uv-transform |
| 1766 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); | 1788 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); |
| 1767 | 1789 |
| 1790 draw_cache_.background_color_data.push_back( | |
|
enne (OOO)
2013/07/02 01:27:22
I don't think the draw cache should support per-qu
alokp
2013/07/02 22:03:54
Done.
| |
| 1791 PremultipliedColor(quad->background_color)); | |
| 1792 | |
| 1768 // Generate the vertex opacity | 1793 // Generate the vertex opacity |
| 1769 const float opacity = quad->opacity(); | 1794 const float opacity = quad->opacity(); |
| 1770 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); | 1795 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); |
| 1771 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); | 1796 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); |
| 1772 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); | 1797 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); |
| 1773 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); | 1798 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); |
| 1774 | 1799 |
| 1775 // Generate the transform matrix | 1800 // Generate the transform matrix |
| 1776 gfx::Transform quad_rect_matrix; | 1801 gfx::Transform quad_rect_matrix; |
| 1777 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 1802 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1798 SetUseProgram(binding.program_id); | 1823 SetUseProgram(binding.program_id); |
| 1799 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); | 1824 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); |
| 1800 Float4 uv_xform = UVTransform(quad); | 1825 Float4 uv_xform = UVTransform(quad); |
| 1801 GLC(Context(), | 1826 GLC(Context(), |
| 1802 Context()->uniform4f(binding.tex_transform_location, | 1827 Context()->uniform4f(binding.tex_transform_location, |
| 1803 uv_xform.data[0], | 1828 uv_xform.data[0], |
| 1804 uv_xform.data[1], | 1829 uv_xform.data[1], |
| 1805 uv_xform.data[2], | 1830 uv_xform.data[2], |
| 1806 uv_xform.data[3])); | 1831 uv_xform.data[3])); |
| 1807 | 1832 |
| 1833 Float4 background_color = PremultipliedColor(quad->background_color); | |
| 1834 GLC(Context(), | |
| 1835 Context()->uniform4fv( | |
| 1836 binding.background_color_location, 4, background_color.data)); | |
| 1837 | |
| 1808 GLC(Context(), | 1838 GLC(Context(), |
| 1809 Context()->uniform1fv( | 1839 Context()->uniform1fv( |
| 1810 binding.vertex_opacity_location, 4, quad->vertex_opacity)); | 1840 binding.vertex_opacity_location, 4, quad->vertex_opacity)); |
| 1811 | 1841 |
| 1812 ResourceProvider::ScopedSamplerGL quad_resource_lock( | 1842 ResourceProvider::ScopedSamplerGL quad_resource_lock( |
| 1813 resource_provider_, quad->resource_id, GL_TEXTURE_2D, GL_LINEAR); | 1843 resource_provider_, quad->resource_id, GL_TEXTURE_2D, GL_LINEAR); |
| 1814 | 1844 |
| 1815 DrawQuadGeometry( | 1845 DrawQuadGeometry( |
| 1816 frame, quad->quadTransform(), quad->rect, binding.matrix_location); | 1846 frame, quad->quadTransform(), quad->rect, binding.matrix_location); |
| 1817 } | 1847 } |
| (...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3009 std::string unique_context_name = base::StringPrintf( | 3039 std::string unique_context_name = base::StringPrintf( |
| 3010 "%s-Offscreen-%p", | 3040 "%s-Offscreen-%p", |
| 3011 Settings().compositor_name.c_str(), | 3041 Settings().compositor_name.c_str(), |
| 3012 context_); | 3042 context_); |
| 3013 resource_provider()->offscreen_context_provider()->Context3d()-> | 3043 resource_provider()->offscreen_context_provider()->Context3d()-> |
| 3014 pushGroupMarkerEXT(unique_context_name.c_str()); | 3044 pushGroupMarkerEXT(unique_context_name.c_str()); |
| 3015 } | 3045 } |
| 3016 | 3046 |
| 3017 | 3047 |
| 3018 } // namespace cc | 3048 } // namespace cc |
| OLD | NEW |