| 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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 const DebugBorderProgram* program = GetDebugBorderProgram(); | 572 const DebugBorderProgram* program = GetDebugBorderProgram(); |
| 573 DCHECK(program && (program->initialized() || IsContextLost())); | 573 DCHECK(program && (program->initialized() || IsContextLost())); |
| 574 SetUseProgram(program->program()); | 574 SetUseProgram(program->program()); |
| 575 | 575 |
| 576 // Use the full quad_rect for debug quads to not move the edges based on | 576 // Use the full quad_rect for debug quads to not move the edges based on |
| 577 // partial swaps. | 577 // partial swaps. |
| 578 gfx::Rect layer_rect = quad->rect; | 578 gfx::Rect layer_rect = quad->rect; |
| 579 gfx::Transform render_matrix; | 579 gfx::Transform render_matrix; |
| 580 QuadRectTransform(&render_matrix, | 580 QuadRectTransform(&render_matrix, |
| 581 quad->shared_quad_state->quad_to_target_transform, | 581 quad->shared_quad_state->quad_to_target_transform, |
| 582 layer_rect); | 582 gfx::RectF(layer_rect)); |
| 583 GLRenderer::ToGLMatrix(&gl_matrix[0], | 583 GLRenderer::ToGLMatrix(&gl_matrix[0], |
| 584 frame->projection_matrix * render_matrix); | 584 frame->projection_matrix * render_matrix); |
| 585 gl_->UniformMatrix4fv(program->vertex_shader().matrix_location(), 1, false, | 585 gl_->UniformMatrix4fv(program->vertex_shader().matrix_location(), 1, false, |
| 586 &gl_matrix[0]); | 586 &gl_matrix[0]); |
| 587 | 587 |
| 588 SkColor color = quad->color; | 588 SkColor color = quad->color; |
| 589 float alpha = SkColorGetA(color) * (1.0f / 255.0f); | 589 float alpha = SkColorGetA(color) * (1.0f / 255.0f); |
| 590 | 590 |
| 591 gl_->Uniform4f(program->fragment_shader().color_location(), | 591 gl_->Uniform4f(program->fragment_shader().color_location(), |
| 592 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, | 592 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 const RenderPassDrawQuad* quad, | 871 const RenderPassDrawQuad* quad, |
| 872 const gfx::QuadF* clip_region) { | 872 const gfx::QuadF* clip_region) { |
| 873 ScopedResource* contents_texture = | 873 ScopedResource* contents_texture = |
| 874 render_pass_textures_.get(quad->render_pass_id); | 874 render_pass_textures_.get(quad->render_pass_id); |
| 875 DCHECK(contents_texture); | 875 DCHECK(contents_texture); |
| 876 DCHECK(contents_texture->id()); | 876 DCHECK(contents_texture->id()); |
| 877 | 877 |
| 878 gfx::Transform quad_rect_matrix; | 878 gfx::Transform quad_rect_matrix; |
| 879 QuadRectTransform(&quad_rect_matrix, | 879 QuadRectTransform(&quad_rect_matrix, |
| 880 quad->shared_quad_state->quad_to_target_transform, | 880 quad->shared_quad_state->quad_to_target_transform, |
| 881 quad->rect); | 881 gfx::RectF(quad->rect)); |
| 882 gfx::Transform contents_device_transform = | 882 gfx::Transform contents_device_transform = |
| 883 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 883 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
| 884 contents_device_transform.FlattenTo2d(); | 884 contents_device_transform.FlattenTo2d(); |
| 885 | 885 |
| 886 // Can only draw surface if device matrix is invertible. | 886 // Can only draw surface if device matrix is invertible. |
| 887 if (!contents_device_transform.IsInvertible()) | 887 if (!contents_device_transform.IsInvertible()) |
| 888 return; | 888 return; |
| 889 | 889 |
| 890 gfx::QuadF surface_quad = SharedGeometryQuad(); | 890 gfx::QuadF surface_quad = SharedGeometryQuad(); |
| 891 | 891 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 GL_TEXTURE0 + last_texture_unit, | 1200 GL_TEXTURE0 + last_texture_unit, |
| 1201 GL_LINEAR)); | 1201 GL_LINEAR)); |
| 1202 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1202 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1203 shader_background_sampler_lock->target()); | 1203 shader_background_sampler_lock->target()); |
| 1204 } | 1204 } |
| 1205 } | 1205 } |
| 1206 | 1206 |
| 1207 SetShaderOpacity(quad->shared_quad_state->opacity, locations.alpha); | 1207 SetShaderOpacity(quad->shared_quad_state->opacity, locations.alpha); |
| 1208 SetShaderQuadF(surface_quad, locations.quad); | 1208 SetShaderQuadF(surface_quad, locations.quad); |
| 1209 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, | 1209 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, |
| 1210 quad->rect, locations.matrix); | 1210 gfx::RectF(quad->rect), locations.matrix); |
| 1211 | 1211 |
| 1212 // Flush the compositor context before the filter bitmap goes out of | 1212 // Flush the compositor context before the filter bitmap goes out of |
| 1213 // scope, so the draw gets processed before the filter texture gets deleted. | 1213 // scope, so the draw gets processed before the filter texture gets deleted. |
| 1214 if (filter_image_id) | 1214 if (filter_image_id) |
| 1215 gl_->Flush(); | 1215 gl_->Flush(); |
| 1216 | 1216 |
| 1217 if (!use_shaders_for_blending) | 1217 if (!use_shaders_for_blending) |
| 1218 RestoreBlendFuncToDefault(blend_mode); | 1218 RestoreBlendFuncToDefault(blend_mode); |
| 1219 } | 1219 } |
| 1220 | 1220 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 kAntiAliasingEpsilon; | 1289 kAntiAliasingEpsilon; |
| 1290 } | 1290 } |
| 1291 } // anonymous namespace | 1291 } // anonymous namespace |
| 1292 | 1292 |
| 1293 static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( | 1293 static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( |
| 1294 const LayerQuad& device_layer_edges, | 1294 const LayerQuad& device_layer_edges, |
| 1295 const gfx::Transform& device_transform, | 1295 const gfx::Transform& device_transform, |
| 1296 const gfx::QuadF& tile_quad, | 1296 const gfx::QuadF& tile_quad, |
| 1297 const gfx::QuadF* clip_region, | 1297 const gfx::QuadF* clip_region, |
| 1298 const DrawQuad* quad) { | 1298 const DrawQuad* quad) { |
| 1299 gfx::RectF tile_rect = quad->visible_rect; | 1299 gfx::RectF tile_rect = gfx::RectF(quad->visible_rect); |
| 1300 | 1300 |
| 1301 gfx::PointF bottom_right = tile_quad.p3(); | 1301 gfx::PointF bottom_right = tile_quad.p3(); |
| 1302 gfx::PointF bottom_left = tile_quad.p4(); | 1302 gfx::PointF bottom_left = tile_quad.p4(); |
| 1303 gfx::PointF top_left = tile_quad.p1(); | 1303 gfx::PointF top_left = tile_quad.p1(); |
| 1304 gfx::PointF top_right = tile_quad.p2(); | 1304 gfx::PointF top_right = tile_quad.p2(); |
| 1305 bool clipped = false; | 1305 bool clipped = false; |
| 1306 | 1306 |
| 1307 // Map points to device space. We ignore |clipped|, since the result of | 1307 // Map points to device space. We ignore |clipped|, since the result of |
| 1308 // |MapPoint()| still produces a valid point to draw the quad with. When | 1308 // |MapPoint()| still produces a valid point to draw the quad with. When |
| 1309 // clipped, the point will be outside of the viewport. See crbug.com/416367. | 1309 // clipped, the point will be outside of the viewport. See crbug.com/416367. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 (is_top(local_clip_region, quad) && is_left(local_clip_region, quad) && | 1459 (is_top(local_clip_region, quad) && is_left(local_clip_region, quad) && |
| 1460 is_bottom(local_clip_region, quad) && is_right(local_clip_region, quad)); | 1460 is_bottom(local_clip_region, quad) && is_right(local_clip_region, quad)); |
| 1461 | 1461 |
| 1462 bool use_aa_on_all_four_edges = | 1462 bool use_aa_on_all_four_edges = |
| 1463 !local_clip_region && region_contains_all_outside_edges; | 1463 !local_clip_region && region_contains_all_outside_edges; |
| 1464 | 1464 |
| 1465 gfx::QuadF device_quad; | 1465 gfx::QuadF device_quad; |
| 1466 if (use_aa_on_all_four_edges) { | 1466 if (use_aa_on_all_four_edges) { |
| 1467 device_quad = device_layer_edges.ToQuadF(); | 1467 device_quad = device_layer_edges.ToQuadF(); |
| 1468 } else { | 1468 } else { |
| 1469 gfx::QuadF tile_quad(local_clip_region ? *local_clip_region | 1469 gfx::QuadF tile_quad(local_clip_region |
| 1470 : gfx::QuadF(quad->visible_rect)); | 1470 ? *local_clip_region |
| 1471 : gfx::QuadF(gfx::RectF(quad->visible_rect))); |
| 1471 device_quad = GetDeviceQuadWithAntialiasingOnExteriorEdges( | 1472 device_quad = GetDeviceQuadWithAntialiasingOnExteriorEdges( |
| 1472 device_layer_edges, device_transform, tile_quad, local_clip_region, | 1473 device_layer_edges, device_transform, tile_quad, local_clip_region, |
| 1473 quad); | 1474 quad); |
| 1474 } | 1475 } |
| 1475 | 1476 |
| 1476 *local_quad = MapQuadToLocalSpace(device_transform, device_quad); | 1477 *local_quad = MapQuadToLocalSpace(device_transform, device_quad); |
| 1477 } | 1478 } |
| 1478 | 1479 |
| 1479 // static | 1480 // static |
| 1480 void GLRenderer::SetupRenderPassQuadForClippingAndAntialiasing( | 1481 void GLRenderer::SetupRenderPassQuadForClippingAndAntialiasing( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1497 return; | 1498 return; |
| 1498 } | 1499 } |
| 1499 | 1500 |
| 1500 LayerQuad device_layer_edges(*aa_quad); | 1501 LayerQuad device_layer_edges(*aa_quad); |
| 1501 InflateAntiAliasingDistances(*aa_quad, &device_layer_edges, edge); | 1502 InflateAntiAliasingDistances(*aa_quad, &device_layer_edges, edge); |
| 1502 | 1503 |
| 1503 gfx::QuadF device_quad; | 1504 gfx::QuadF device_quad; |
| 1504 | 1505 |
| 1505 // Apply anti-aliasing only to the edges that are not being clipped | 1506 // Apply anti-aliasing only to the edges that are not being clipped |
| 1506 if (local_clip_region) { | 1507 if (local_clip_region) { |
| 1507 gfx::QuadF tile_quad(quad->visible_rect); | 1508 gfx::QuadF tile_quad(gfx::RectF(quad->visible_rect)); |
| 1508 GetScaledRegion(quad->rect, local_clip_region, &tile_quad); | 1509 GetScaledRegion(quad->rect, local_clip_region, &tile_quad); |
| 1509 device_quad = GetDeviceQuadWithAntialiasingOnExteriorEdges( | 1510 device_quad = GetDeviceQuadWithAntialiasingOnExteriorEdges( |
| 1510 device_layer_edges, device_transform, tile_quad, local_clip_region, | 1511 device_layer_edges, device_transform, tile_quad, local_clip_region, |
| 1511 quad); | 1512 quad); |
| 1512 } else { | 1513 } else { |
| 1513 device_quad = device_layer_edges.ToQuadF(); | 1514 device_quad = device_layer_edges.ToQuadF(); |
| 1514 } | 1515 } |
| 1515 | 1516 |
| 1516 *local_quad = MapQuadToLocalSpace(device_transform, device_quad); | 1517 *local_quad = MapQuadToLocalSpace(device_transform, device_quad); |
| 1517 } | 1518 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1542 gfx::QuadF device_layer_quad; | 1543 gfx::QuadF device_layer_quad; |
| 1543 bool use_aa = false; | 1544 bool use_aa = false; |
| 1544 bool allow_aa = settings_->allow_antialiasing && | 1545 bool allow_aa = settings_->allow_antialiasing && |
| 1545 !quad->force_anti_aliasing_off && quad->IsEdge(); | 1546 !quad->force_anti_aliasing_off && quad->IsEdge(); |
| 1546 | 1547 |
| 1547 if (allow_aa) { | 1548 if (allow_aa) { |
| 1548 bool clipped = false; | 1549 bool clipped = false; |
| 1549 bool force_aa = false; | 1550 bool force_aa = false; |
| 1550 device_layer_quad = MathUtil::MapQuad( | 1551 device_layer_quad = MathUtil::MapQuad( |
| 1551 device_transform, | 1552 device_transform, |
| 1552 gfx::QuadF(quad->shared_quad_state->visible_quad_layer_rect), &clipped); | 1553 gfx::QuadF( |
| 1554 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), |
| 1555 &clipped); |
| 1553 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); | 1556 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); |
| 1554 } | 1557 } |
| 1555 | 1558 |
| 1556 float edge[24]; | 1559 float edge[24]; |
| 1557 const gfx::QuadF* aa_quad = use_aa ? &device_layer_quad : nullptr; | 1560 const gfx::QuadF* aa_quad = use_aa ? &device_layer_quad : nullptr; |
| 1558 SetupQuadForClippingAndAntialiasing(device_transform, quad, aa_quad, | 1561 SetupQuadForClippingAndAntialiasing(device_transform, quad, aa_quad, |
| 1559 clip_region, &local_quad, edge); | 1562 clip_region, &local_quad, edge); |
| 1560 | 1563 |
| 1561 SolidColorProgramUniforms uniforms; | 1564 SolidColorProgramUniforms uniforms; |
| 1562 if (use_aa) { | 1565 if (use_aa) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 device_transform.FlattenTo2d(); | 1663 device_transform.FlattenTo2d(); |
| 1661 | 1664 |
| 1662 gfx::QuadF device_layer_quad; | 1665 gfx::QuadF device_layer_quad; |
| 1663 bool use_aa = false; | 1666 bool use_aa = false; |
| 1664 bool allow_aa = settings_->allow_antialiasing && quad->IsEdge(); | 1667 bool allow_aa = settings_->allow_antialiasing && quad->IsEdge(); |
| 1665 if (allow_aa) { | 1668 if (allow_aa) { |
| 1666 bool clipped = false; | 1669 bool clipped = false; |
| 1667 bool force_aa = false; | 1670 bool force_aa = false; |
| 1668 device_layer_quad = MathUtil::MapQuad( | 1671 device_layer_quad = MathUtil::MapQuad( |
| 1669 device_transform, | 1672 device_transform, |
| 1670 gfx::QuadF(quad->shared_quad_state->visible_quad_layer_rect), &clipped); | 1673 gfx::QuadF( |
| 1674 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), |
| 1675 &clipped); |
| 1671 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); | 1676 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); |
| 1672 } | 1677 } |
| 1673 | 1678 |
| 1674 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA | 1679 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA |
| 1675 // similar to the way DrawContentQuadNoAA works and then consider | 1680 // similar to the way DrawContentQuadNoAA works and then consider |
| 1676 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. | 1681 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. |
| 1677 if (use_aa) | 1682 if (use_aa) |
| 1678 DrawContentQuadAA(frame, quad, resource_id, device_transform, | 1683 DrawContentQuadAA(frame, quad, resource_id, device_transform, |
| 1679 device_layer_quad, clip_region); | 1684 device_layer_quad, clip_region); |
| 1680 else | 1685 else |
| 1681 DrawContentQuadNoAA(frame, quad, resource_id, clip_region); | 1686 DrawContentQuadNoAA(frame, quad, resource_id, clip_region); |
| 1682 } | 1687 } |
| 1683 | 1688 |
| 1684 void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, | 1689 void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, |
| 1685 const ContentDrawQuadBase* quad, | 1690 const ContentDrawQuadBase* quad, |
| 1686 ResourceId resource_id, | 1691 ResourceId resource_id, |
| 1687 const gfx::Transform& device_transform, | 1692 const gfx::Transform& device_transform, |
| 1688 const gfx::QuadF& aa_quad, | 1693 const gfx::QuadF& aa_quad, |
| 1689 const gfx::QuadF* clip_region) { | 1694 const gfx::QuadF* clip_region) { |
| 1690 if (!device_transform.IsInvertible()) | 1695 if (!device_transform.IsInvertible()) |
| 1691 return; | 1696 return; |
| 1692 | 1697 |
| 1693 gfx::Rect tile_rect = quad->visible_rect; | 1698 gfx::Rect tile_rect = quad->visible_rect; |
| 1694 | 1699 |
| 1695 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( | 1700 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( |
| 1696 quad->tex_coord_rect, quad->rect, tile_rect); | 1701 quad->tex_coord_rect, gfx::RectF(quad->rect), gfx::RectF(tile_rect)); |
| 1697 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); | 1702 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); |
| 1698 float tex_to_geom_scale_y = | 1703 float tex_to_geom_scale_y = |
| 1699 quad->rect.height() / quad->tex_coord_rect.height(); | 1704 quad->rect.height() / quad->tex_coord_rect.height(); |
| 1700 | 1705 |
| 1701 gfx::RectF clamp_geom_rect(tile_rect); | 1706 gfx::RectF clamp_geom_rect(tile_rect); |
| 1702 gfx::RectF clamp_tex_rect(tex_coord_rect); | 1707 gfx::RectF clamp_tex_rect(tex_coord_rect); |
| 1703 // Clamp texture coordinates to avoid sampling outside the layer | 1708 // Clamp texture coordinates to avoid sampling outside the layer |
| 1704 // by deflating the tile region half a texel or half a texel | 1709 // by deflating the tile region half a texel or half a texel |
| 1705 // minus epsilon for one pixel layers. The resulting clamp region | 1710 // minus epsilon for one pixel layers. The resulting clamp region |
| 1706 // is mapped to the unit square by the vertex shader and mapped | 1711 // is mapped to the unit square by the vertex shader and mapped |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 tile_rect.size()); | 1805 tile_rect.size()); |
| 1801 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, | 1806 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, |
| 1802 centered_rect, uniforms.matrix_location); | 1807 centered_rect, uniforms.matrix_location); |
| 1803 } | 1808 } |
| 1804 | 1809 |
| 1805 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, | 1810 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, |
| 1806 const ContentDrawQuadBase* quad, | 1811 const ContentDrawQuadBase* quad, |
| 1807 ResourceId resource_id, | 1812 ResourceId resource_id, |
| 1808 const gfx::QuadF* clip_region) { | 1813 const gfx::QuadF* clip_region) { |
| 1809 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( | 1814 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( |
| 1810 quad->tex_coord_rect, quad->rect, quad->visible_rect); | 1815 quad->tex_coord_rect, gfx::RectF(quad->rect), |
| 1816 gfx::RectF(quad->visible_rect)); |
| 1811 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); | 1817 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); |
| 1812 float tex_to_geom_scale_y = | 1818 float tex_to_geom_scale_y = |
| 1813 quad->rect.height() / quad->tex_coord_rect.height(); | 1819 quad->rect.height() / quad->tex_coord_rect.height(); |
| 1814 | 1820 |
| 1815 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); | 1821 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); |
| 1816 GLenum filter = (scaled || | 1822 GLenum filter = (scaled || |
| 1817 !quad->shared_quad_state->quad_to_target_transform | 1823 !quad->shared_quad_state->quad_to_target_transform |
| 1818 .IsIdentityOrIntegerTranslation()) && | 1824 .IsIdentityOrIntegerTranslation()) && |
| 1819 !quad->nearest_neighbor | 1825 !quad->nearest_neighbor |
| 1820 ? GL_LINEAR | 1826 ? GL_LINEAR |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1870 vertex_tex_scale_y); | 1876 vertex_tex_scale_y); |
| 1871 | 1877 |
| 1872 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1878 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1873 | 1879 |
| 1874 SetShaderOpacity(quad->shared_quad_state->opacity, uniforms.alpha_location); | 1880 SetShaderOpacity(quad->shared_quad_state->opacity, uniforms.alpha_location); |
| 1875 | 1881 |
| 1876 // Pass quad coordinates to the uniform in the same order as GeometryBinding | 1882 // Pass quad coordinates to the uniform in the same order as GeometryBinding |
| 1877 // does, then vertices will match the texture mapping in the vertex buffer. | 1883 // does, then vertices will match the texture mapping in the vertex buffer. |
| 1878 // The method SetShaderQuadF() changes the order of vertices and so it's | 1884 // The method SetShaderQuadF() changes the order of vertices and so it's |
| 1879 // not used here. | 1885 // not used here. |
| 1880 gfx::QuadF tile_rect(quad->visible_rect); | 1886 gfx::QuadF tile_quad(gfx::RectF(quad->visible_rect)); |
| 1881 float width = quad->visible_rect.width(); | 1887 float width = quad->visible_rect.width(); |
| 1882 float height = quad->visible_rect.height(); | 1888 float height = quad->visible_rect.height(); |
| 1883 gfx::PointF top_left = quad->visible_rect.origin(); | 1889 gfx::PointF top_left = quad->visible_rect.origin(); |
| 1884 if (clip_region) { | 1890 if (clip_region) { |
| 1885 tile_rect = *clip_region; | 1891 tile_quad = *clip_region; |
| 1886 float gl_uv[8] = { | 1892 float gl_uv[8] = { |
| 1887 (tile_rect.p4().x() - top_left.x()) / width, | 1893 (tile_quad.p4().x() - top_left.x()) / width, |
| 1888 (tile_rect.p4().y() - top_left.y()) / height, | 1894 (tile_quad.p4().y() - top_left.y()) / height, |
| 1889 (tile_rect.p1().x() - top_left.x()) / width, | 1895 (tile_quad.p1().x() - top_left.x()) / width, |
| 1890 (tile_rect.p1().y() - top_left.y()) / height, | 1896 (tile_quad.p1().y() - top_left.y()) / height, |
| 1891 (tile_rect.p2().x() - top_left.x()) / width, | 1897 (tile_quad.p2().x() - top_left.x()) / width, |
| 1892 (tile_rect.p2().y() - top_left.y()) / height, | 1898 (tile_quad.p2().y() - top_left.y()) / height, |
| 1893 (tile_rect.p3().x() - top_left.x()) / width, | 1899 (tile_quad.p3().x() - top_left.x()) / width, |
| 1894 (tile_rect.p3().y() - top_left.y()) / height, | 1900 (tile_quad.p3().y() - top_left.y()) / height, |
| 1895 }; | 1901 }; |
| 1896 PrepareGeometry(CLIPPED_BINDING); | 1902 PrepareGeometry(CLIPPED_BINDING); |
| 1897 clipped_geometry_->InitializeCustomQuadWithUVs( | 1903 clipped_geometry_->InitializeCustomQuadWithUVs( |
| 1898 gfx::QuadF(quad->visible_rect), gl_uv); | 1904 gfx::QuadF(gfx::RectF(quad->visible_rect)), gl_uv); |
| 1899 } else { | 1905 } else { |
| 1900 PrepareGeometry(SHARED_BINDING); | 1906 PrepareGeometry(SHARED_BINDING); |
| 1901 } | 1907 } |
| 1902 float gl_quad[8] = { | 1908 float gl_quad[8] = { |
| 1903 tile_rect.p4().x(), | 1909 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(), |
| 1904 tile_rect.p4().y(), | 1910 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(), |
| 1905 tile_rect.p1().x(), | 1911 tile_quad.p3().x(), tile_quad.p3().y(), |
| 1906 tile_rect.p1().y(), | |
| 1907 tile_rect.p2().x(), | |
| 1908 tile_rect.p2().y(), | |
| 1909 tile_rect.p3().x(), | |
| 1910 tile_rect.p3().y(), | |
| 1911 }; | 1912 }; |
| 1912 gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad); | 1913 gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad); |
| 1913 | 1914 |
| 1914 static float gl_matrix[16]; | 1915 static float gl_matrix[16]; |
| 1915 ToGLMatrix(&gl_matrix[0], | 1916 ToGLMatrix(&gl_matrix[0], |
| 1916 frame->projection_matrix * | 1917 frame->projection_matrix * |
| 1917 quad->shared_quad_state->quad_to_target_transform); | 1918 quad->shared_quad_state->quad_to_target_transform); |
| 1918 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0]); | 1919 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0]); |
| 1919 | 1920 |
| 1920 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 1921 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 case YUVVideoDrawQuad::JPEG: | 2108 case YUVVideoDrawQuad::JPEG: |
| 2108 yuv_to_rgb = yuv_to_rgb_jpeg; | 2109 yuv_to_rgb = yuv_to_rgb_jpeg; |
| 2109 yuv_adjust = yuv_adjust_full; | 2110 yuv_adjust = yuv_adjust_full; |
| 2110 break; | 2111 break; |
| 2111 } | 2112 } |
| 2112 | 2113 |
| 2113 // The transform and vertex data are used to figure out the extents that the | 2114 // The transform and vertex data are used to figure out the extents that the |
| 2114 // un-antialiased quad should have and which vertex this is and the float | 2115 // un-antialiased quad should have and which vertex this is and the float |
| 2115 // quad passed in via uniform is the actual geometry that gets used to draw | 2116 // quad passed in via uniform is the actual geometry that gets used to draw |
| 2116 // it. This is why this centered rect is used and not the original quad_rect. | 2117 // it. This is why this centered rect is used and not the original quad_rect. |
| 2117 gfx::RectF tile_rect = quad->rect; | 2118 gfx::RectF tile_rect = gfx::RectF(quad->rect); |
| 2118 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb); | 2119 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb); |
| 2119 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust); | 2120 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust); |
| 2120 | 2121 |
| 2121 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location); | 2122 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location); |
| 2122 if (!clip_region) { | 2123 if (!clip_region) { |
| 2123 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, | 2124 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, |
| 2124 tile_rect, matrix_location); | 2125 tile_rect, matrix_location); |
| 2125 } else { | 2126 } else { |
| 2126 float uvs[8] = {0}; | 2127 float uvs[8] = {0}; |
| 2127 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2128 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2159 quad->resource_id()); | 2160 quad->resource_id()); |
| 2160 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2161 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2161 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); | 2162 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); |
| 2162 | 2163 |
| 2163 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); | 2164 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); |
| 2164 | 2165 |
| 2165 SetShaderOpacity(quad->shared_quad_state->opacity, | 2166 SetShaderOpacity(quad->shared_quad_state->opacity, |
| 2166 program->fragment_shader().alpha_location()); | 2167 program->fragment_shader().alpha_location()); |
| 2167 if (!clip_region) { | 2168 if (!clip_region) { |
| 2168 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, | 2169 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, |
| 2169 quad->rect, program->vertex_shader().matrix_location()); | 2170 gfx::RectF(quad->rect), |
| 2171 program->vertex_shader().matrix_location()); |
| 2170 } else { | 2172 } else { |
| 2171 gfx::QuadF region_quad(*clip_region); | 2173 gfx::QuadF region_quad(*clip_region); |
| 2172 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); | 2174 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); |
| 2173 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2175 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2174 float uvs[8] = {0}; | 2176 float uvs[8] = {0}; |
| 2175 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2177 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2176 DrawQuadGeometryClippedByQuadF( | 2178 DrawQuadGeometryClippedByQuadF( |
| 2177 frame, quad->shared_quad_state->quad_to_target_transform, quad->rect, | 2179 frame, quad->shared_quad_state->quad_to_target_transform, |
| 2178 region_quad, program->vertex_shader().matrix_location(), uvs); | 2180 gfx::RectF(quad->rect), region_quad, |
| 2181 program->vertex_shader().matrix_location(), uvs); |
| 2179 } | 2182 } |
| 2180 } | 2183 } |
| 2181 | 2184 |
| 2182 struct TextureProgramBinding { | 2185 struct TextureProgramBinding { |
| 2183 template <class Program> | 2186 template <class Program> |
| 2184 void Set(Program* program) { | 2187 void Set(Program* program) { |
| 2185 DCHECK(program); | 2188 DCHECK(program); |
| 2186 program_id = program->program(); | 2189 program_id = program->program(); |
| 2187 sampler_location = program->fragment_shader().sampler_location(); | 2190 sampler_location = program->fragment_shader().sampler_location(); |
| 2188 matrix_location = program->vertex_shader().matrix_location(); | 2191 matrix_location = program->vertex_shader().matrix_location(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2348 const float opacity = quad->shared_quad_state->opacity; | 2351 const float opacity = quad->shared_quad_state->opacity; |
| 2349 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); | 2352 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); |
| 2350 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); | 2353 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); |
| 2351 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); | 2354 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); |
| 2352 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); | 2355 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); |
| 2353 | 2356 |
| 2354 // Generate the transform matrix | 2357 // Generate the transform matrix |
| 2355 gfx::Transform quad_rect_matrix; | 2358 gfx::Transform quad_rect_matrix; |
| 2356 QuadRectTransform(&quad_rect_matrix, | 2359 QuadRectTransform(&quad_rect_matrix, |
| 2357 quad->shared_quad_state->quad_to_target_transform, | 2360 quad->shared_quad_state->quad_to_target_transform, |
| 2358 quad->rect); | 2361 gfx::RectF(quad->rect)); |
| 2359 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; | 2362 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; |
| 2360 | 2363 |
| 2361 Float16 m; | 2364 Float16 m; |
| 2362 quad_rect_matrix.matrix().asColMajorf(m.data); | 2365 quad_rect_matrix.matrix().asColMajorf(m.data); |
| 2363 draw_cache_.matrix_data.push_back(m); | 2366 draw_cache_.matrix_data.push_back(m); |
| 2364 | 2367 |
| 2365 if (clip_region) { | 2368 if (clip_region) { |
| 2366 gfx::QuadF scaled_region; | 2369 gfx::QuadF scaled_region; |
| 2367 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { | 2370 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { |
| 2368 scaled_region = SharedGeometryQuad().BoundingBox(); | 2371 scaled_region = SharedGeometryQuad().BoundingBox(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2414 quad->shared_quad_state->opacity}; | 2417 quad->shared_quad_state->opacity}; |
| 2415 gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity); | 2418 gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity); |
| 2416 | 2419 |
| 2417 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 2420 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2418 quad->io_surface_resource_id()); | 2421 quad->io_surface_resource_id()); |
| 2419 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2422 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2420 gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id()); | 2423 gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id()); |
| 2421 | 2424 |
| 2422 if (!clip_region) { | 2425 if (!clip_region) { |
| 2423 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, | 2426 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, |
| 2424 quad->rect, binding.matrix_location); | 2427 gfx::RectF(quad->rect), binding.matrix_location); |
| 2425 } else { | 2428 } else { |
| 2426 float uvs[8] = {0}; | 2429 float uvs[8] = {0}; |
| 2427 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2430 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2428 DrawQuadGeometryClippedByQuadF( | 2431 DrawQuadGeometryClippedByQuadF( |
| 2429 frame, quad->shared_quad_state->quad_to_target_transform, quad->rect, | 2432 frame, quad->shared_quad_state->quad_to_target_transform, |
| 2430 *clip_region, binding.matrix_location, uvs); | 2433 gfx::RectF(quad->rect), *clip_region, binding.matrix_location, uvs); |
| 2431 } | 2434 } |
| 2432 | 2435 |
| 2433 gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); | 2436 gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); |
| 2434 } | 2437 } |
| 2435 | 2438 |
| 2436 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 2439 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
| 2437 if (use_sync_query_) { | 2440 if (use_sync_query_) { |
| 2438 DCHECK(current_sync_query_); | 2441 DCHECK(current_sync_query_); |
| 2439 current_sync_query_->End(); | 2442 current_sync_query_->End(); |
| 2440 pending_sync_queries_.push_back(current_sync_query_.Pass()); | 2443 pending_sync_queries_.push_back(current_sync_query_.Pass()); |
| 2441 } | 2444 } |
| 2442 | 2445 |
| 2443 current_framebuffer_lock_ = nullptr; | 2446 current_framebuffer_lock_ = nullptr; |
| 2444 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); | 2447 swap_buffer_rect_.Union(frame->root_damage_rect); |
| 2445 | 2448 |
| 2446 gl_->Disable(GL_BLEND); | 2449 gl_->Disable(GL_BLEND); |
| 2447 blend_shadow_ = false; | 2450 blend_shadow_ = false; |
| 2448 | 2451 |
| 2449 ScheduleOverlays(frame); | 2452 ScheduleOverlays(frame); |
| 2450 } | 2453 } |
| 2451 | 2454 |
| 2452 void GLRenderer::FinishDrawingQuadList() { | 2455 void GLRenderer::FinishDrawingQuadList() { |
| 2453 FlushTextureQuadCache(SHARED_BINDING); | 2456 FlushTextureQuadCache(SHARED_BINDING); |
| 2454 } | 2457 } |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3532 texture_id = pending_overlay_resources_.back()->texture_id(); | 3535 texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3533 } | 3536 } |
| 3534 | 3537 |
| 3535 context_support_->ScheduleOverlayPlane( | 3538 context_support_->ScheduleOverlayPlane( |
| 3536 overlay.plane_z_order, overlay.transform, texture_id, | 3539 overlay.plane_z_order, overlay.transform, texture_id, |
| 3537 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3540 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
| 3538 } | 3541 } |
| 3539 } | 3542 } |
| 3540 | 3543 |
| 3541 } // namespace cc | 3544 } // namespace cc |
| OLD | NEW |