Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Side by Side Diff: cc/output/gl_renderer.cc

Issue 18432002: Blend TextureLayer background-color at draw time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added TextureLayer unittest Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 context_->uniformMatrix4fv( 1717 context_->uniformMatrix4fv(
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())));
1727
1728 Float4 background_color = PremultipliedColor(draw_cache_.background_color);
1729 GLC(context_,
1730 context_->uniform4fv(
1731 draw_cache_.background_color_location, 1, background_color.data));
1732
1713 GLC(context_, 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(),
(...skipping 20 matching lines...) Expand all
1743 } else { 1763 } else {
1744 binding.Set(GetNonPremultipliedTextureProgram(tex_coord_precision), 1764 binding.Set(GetNonPremultipliedTextureProgram(tex_coord_precision),
1745 Context()); 1765 Context());
1746 } 1766 }
1747 1767
1748 int resource_id = quad->resource_id; 1768 int resource_id = quad->resource_id;
1749 1769
1750 if (draw_cache_.program_id != binding.program_id || 1770 if (draw_cache_.program_id != binding.program_id ||
1751 draw_cache_.resource_id != resource_id || 1771 draw_cache_.resource_id != resource_id ||
1752 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || 1772 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() ||
1773 draw_cache_.background_color != quad->background_color ||
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();
1779 draw_cache_.background_color = quad->background_color;
1758 1780
1759 draw_cache_.uv_xform_location = binding.tex_transform_location; 1781 draw_cache_.uv_xform_location = binding.tex_transform_location;
1782 draw_cache_.background_color_location = binding.background_color_location;
1760 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; 1783 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location;
1761 draw_cache_.matrix_location = binding.matrix_location; 1784 draw_cache_.matrix_location = binding.matrix_location;
1762 draw_cache_.sampler_location = binding.sampler_location; 1785 draw_cache_.sampler_location = binding.sampler_location;
1763 } 1786 }
1764 1787
1765 // Generate the uv-transform 1788 // Generate the uv-transform
1766 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); 1789 draw_cache_.uv_xform_data.push_back(UVTransform(quad));
1767 1790
1768 // Generate the vertex opacity 1791 // Generate the vertex opacity
1769 const float opacity = quad->opacity(); 1792 const float opacity = quad->opacity();
(...skipping 28 matching lines...) Expand all
1798 SetUseProgram(binding.program_id); 1821 SetUseProgram(binding.program_id);
1799 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); 1822 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0));
1800 Float4 uv_xform = UVTransform(quad); 1823 Float4 uv_xform = UVTransform(quad);
1801 GLC(Context(), 1824 GLC(Context(),
1802 Context()->uniform4f(binding.tex_transform_location, 1825 Context()->uniform4f(binding.tex_transform_location,
1803 uv_xform.data[0], 1826 uv_xform.data[0],
1804 uv_xform.data[1], 1827 uv_xform.data[1],
1805 uv_xform.data[2], 1828 uv_xform.data[2],
1806 uv_xform.data[3])); 1829 uv_xform.data[3]));
1807 1830
1831 Float4 background_color = PremultipliedColor(quad->background_color);
1832 GLC(Context(),
1833 Context()->uniform4fv(
1834 binding.background_color_location, 1, background_color.data));
1835
1808 GLC(Context(), 1836 GLC(Context(),
1809 Context()->uniform1fv( 1837 Context()->uniform1fv(
1810 binding.vertex_opacity_location, 4, quad->vertex_opacity)); 1838 binding.vertex_opacity_location, 4, quad->vertex_opacity));
1811 1839
1812 ResourceProvider::ScopedSamplerGL quad_resource_lock( 1840 ResourceProvider::ScopedSamplerGL quad_resource_lock(
1813 resource_provider_, quad->resource_id, GL_TEXTURE_2D, GL_LINEAR); 1841 resource_provider_, quad->resource_id, GL_TEXTURE_2D, GL_LINEAR);
1814 1842
1815 DrawQuadGeometry( 1843 DrawQuadGeometry(
1816 frame, quad->quadTransform(), quad->rect, binding.matrix_location); 1844 frame, quad->quadTransform(), quad->rect, binding.matrix_location);
1817 } 1845 }
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 std::string unique_context_name = base::StringPrintf( 3037 std::string unique_context_name = base::StringPrintf(
3010 "%s-Offscreen-%p", 3038 "%s-Offscreen-%p",
3011 Settings().compositor_name.c_str(), 3039 Settings().compositor_name.c_str(),
3012 context_); 3040 context_);
3013 resource_provider()->offscreen_context_provider()->Context3d()-> 3041 resource_provider()->offscreen_context_provider()->Context3d()->
3014 pushGroupMarkerEXT(unique_context_name.c_str()); 3042 pushGroupMarkerEXT(unique_context_name.c_str());
3015 } 3043 }
3016 3044
3017 3045
3018 } // namespace cc 3046 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698