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

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

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_draw_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 quad->filters_scale, 862 quad->filters_scale,
863 filter.get(), 863 filter.get(),
864 background_texture); 864 background_texture);
865 return background_with_filters; 865 return background_with_filters;
866 } 866 }
867 867
868 scoped_ptr<ScopedResource> 868 scoped_ptr<ScopedResource>
869 GLRenderer::ApplyInverseTransformForBackgroundFilters( 869 GLRenderer::ApplyInverseTransformForBackgroundFilters(
870 DrawingFrame* frame, 870 DrawingFrame* frame,
871 const RenderPassDrawQuad* quad, 871 const RenderPassDrawQuad* quad,
872 const gfx::Transform& contents_device_transform_inverse, 872 const gfx::Transform& contents_device_transform,
873 skia::RefPtr<SkImage> filtered_device_background, 873 skia::RefPtr<SkImage> filtered_device_background,
874 const gfx::Rect& backdrop_bounding_rect) { 874 const gfx::Rect& backdrop_bounding_rect) {
875 // This method draws a background filter, which applies a filter to any pixels 875 // This method draws a background filter, which applies a filter to any pixels
876 // behind the quad and seen through its background. The algorithm works as 876 // behind the quad and seen through its background. The algorithm works as
877 // follows: 877 // follows:
878 // 1. Read the pixels in the bounding box into a buffer. 878 // 1. Read the pixels in the bounding box into a buffer.
879 // Moved to GLRenderer::GetBackdropBoundingBoxForRenderPassQuad(). 879 // Moved to GLRenderer::GetBackdropBoundingBoxForRenderPassQuad().
880 // 2. Read the pixels in the bounding box into a buffer R. 880 // 2. Read the pixels in the bounding box into a buffer R.
881 // Moved to GLRenderer::GetBackdropTexture(). 881 // Moved to GLRenderer::GetBackdropTexture().
882 // 3. Apply the background filter to R, so that it is applied in the pixels' 882 // 3. Apply the background filter to R, so that it is applied in the pixels'
(...skipping 24 matching lines...) Expand all
907 ResourceProvider::TextureHintImmutableFramebuffer, 907 ResourceProvider::TextureHintImmutableFramebuffer,
908 RGBA_8888); 908 RGBA_8888);
909 909
910 const RenderPass* target_render_pass = frame->current_render_pass; 910 const RenderPass* target_render_pass = frame->current_render_pass;
911 bool using_background_texture = 911 bool using_background_texture =
912 UseScopedTexture(frame, background_texture.get(), quad->rect); 912 UseScopedTexture(frame, background_texture.get(), quad->rect);
913 913
914 if (using_background_texture) { 914 if (using_background_texture) {
915 // Copy the readback pixels from device to the background texture for the 915 // Copy the readback pixels from device to the background texture for the
916 // surface. 916 // surface.
917
918 gfx::Transform contents_device_transform_inverse(
919 gfx::Transform::kSkipInitialization);
920 bool did_invert = contents_device_transform.GetInverse(
921 &contents_device_transform_inverse);
922 DCHECK(did_invert);
917 gfx::Transform device_to_framebuffer_transform; 923 gfx::Transform device_to_framebuffer_transform;
918 QuadRectTransform( 924 QuadRectTransform(
919 &device_to_framebuffer_transform, gfx::Transform(), quad->rect); 925 &device_to_framebuffer_transform, gfx::Transform(), quad->rect);
920 device_to_framebuffer_transform.PreconcatTransform( 926 device_to_framebuffer_transform.PreconcatTransform(
921 contents_device_transform_inverse); 927 contents_device_transform_inverse);
922 928
923 #ifndef NDEBUG 929 #ifndef NDEBUG
924 GLC(gl_, gl_->ClearColor(0, 0, 1, 1)); 930 GLC(gl_, gl_->ClearColor(0, 0, 1, 1));
925 gl_->Clear(GL_COLOR_BUFFER_BIT); 931 gl_->Clear(GL_COLOR_BUFFER_BIT);
926 #endif 932 #endif
(...skipping 30 matching lines...) Expand all
957 if (!contents_texture || !contents_texture->id()) 963 if (!contents_texture || !contents_texture->id())
958 return; 964 return;
959 965
960 gfx::Transform quad_rect_matrix; 966 gfx::Transform quad_rect_matrix;
961 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); 967 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect);
962 gfx::Transform contents_device_transform = 968 gfx::Transform contents_device_transform =
963 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; 969 frame->window_matrix * frame->projection_matrix * quad_rect_matrix;
964 contents_device_transform.FlattenTo2d(); 970 contents_device_transform.FlattenTo2d();
965 971
966 // Can only draw surface if device matrix is invertible. 972 // Can only draw surface if device matrix is invertible.
967 gfx::Transform contents_device_transform_inverse( 973 if (!contents_device_transform.IsInvertible())
968 gfx::Transform::kSkipInitialization);
969 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse))
970 return; 974 return;
971 975
972 bool clipped = false; 976 gfx::QuadF surface_quad = SharedGeometryQuad();
973 gfx::QuadF device_quad = MathUtil::MapQuad( 977 float edge[24];
974 contents_device_transform, SharedGeometryQuad(), &clipped); 978 bool use_aa = settings_->allow_antialiasing &&
975 // Use anti-aliasing programs only when necessary. 979 ShouldAntialiasQuad(contents_device_transform, quad,
976 bool use_aa = 980 settings_->force_antialiasing);
977 !clipped && 981
978 (settings_->force_antialiasing || !device_quad.IsRectilinear() || 982 if (use_aa)
979 !gfx::IsNearestRectWithinDistance(device_quad.BoundingBox(), 983 SetupQuadForAntialiasing(contents_device_transform, quad,
980 kAntiAliasingEpsilon)); 984 &surface_quad, edge);
981 985
982 bool need_background_texture = !CanApplyBlendModeUsingBlendFunc(blend_mode) || 986 bool need_background_texture = !CanApplyBlendModeUsingBlendFunc(blend_mode) ||
983 ShouldApplyBackgroundFilters(frame, quad); 987 ShouldApplyBackgroundFilters(frame, quad);
984 988
985 scoped_ptr<ScopedResource> background_texture; 989 scoped_ptr<ScopedResource> background_texture;
986 skia::RefPtr<SkImage> background_image; 990 skia::RefPtr<SkImage> background_image;
987 gfx::Rect background_rect; 991 gfx::Rect background_rect;
988 if (need_background_texture) { 992 if (need_background_texture) {
989 // Compute a bounding box around the pixels that will be visible through 993 // Compute a bounding box around the pixels that will be visible through
990 // the quad. 994 // the quad.
(...skipping 22 matching lines...) Expand all
1013 } 1017 }
1014 1018
1015 if (CanApplyBlendModeUsingBlendFunc(blend_mode) && 1019 if (CanApplyBlendModeUsingBlendFunc(blend_mode) &&
1016 background_with_filters) { 1020 background_with_filters) {
1017 // The background with filters will be copied to the frame buffer. 1021 // The background with filters will be copied to the frame buffer.
1018 // Apply the quad's inverse transform to map the pixels in R into the 1022 // Apply the quad's inverse transform to map the pixels in R into the
1019 // quad's content space. This implicitly clips R by the content bounds of 1023 // quad's content space. This implicitly clips R by the content bounds of
1020 // the quad since the destination texture has bounds matching the quad's 1024 // the quad since the destination texture has bounds matching the quad's
1021 // content. 1025 // content.
1022 background_texture = ApplyInverseTransformForBackgroundFilters( 1026 background_texture = ApplyInverseTransformForBackgroundFilters(
1023 frame, 1027 frame, quad, contents_device_transform, background_with_filters,
1024 quad,
1025 contents_device_transform_inverse,
1026 background_with_filters,
1027 background_rect); 1028 background_rect);
1028 } else if (!CanApplyBlendModeUsingBlendFunc(blend_mode)) { 1029 } else if (!CanApplyBlendModeUsingBlendFunc(blend_mode)) {
1029 if (background_with_filters) { 1030 if (background_with_filters) {
1030 // The background with filters will be used as backdrop for blending. 1031 // The background with filters will be used as backdrop for blending.
1031 background_image = background_with_filters; 1032 background_image = background_with_filters;
1032 } else { 1033 } else {
1033 background_texture = scoped_background_texture.Pass(); 1034 background_texture = scoped_background_texture.Pass();
1034 } 1035 }
1035 } 1036 }
1036 1037
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 // in the shader to maintain orientation 1083 // in the shader to maintain orientation
1083 bool flip_vertically = true; 1084 bool flip_vertically = true;
1084 1085
1085 CopyTextureToFramebuffer(frame, 1086 CopyTextureToFramebuffer(frame,
1086 lock.texture_id(), 1087 lock.texture_id(),
1087 quad->rect, 1088 quad->rect,
1088 quad->quadTransform(), 1089 quad->quadTransform(),
1089 flip_vertically); 1090 flip_vertically);
1090 } 1091 }
1091 1092
1092 LayerQuad device_layer_bounds(gfx::QuadF(device_quad.BoundingBox()));
1093 LayerQuad device_layer_edges(device_quad);
1094 if (use_aa) {
1095 device_layer_bounds.InflateAntiAliasingDistance();
1096 device_layer_edges.InflateAntiAliasingDistance();
1097 }
1098
1099 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock; 1093 scoped_ptr<ResourceProvider::ScopedSamplerGL> mask_resource_lock;
1100 unsigned mask_texture_id = 0; 1094 unsigned mask_texture_id = 0;
1101 SamplerType mask_sampler = SamplerTypeNA; 1095 SamplerType mask_sampler = SamplerTypeNA;
1102 if (quad->mask_resource_id) { 1096 if (quad->mask_resource_id) {
1103 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL( 1097 mask_resource_lock.reset(new ResourceProvider::ScopedSamplerGL(
1104 resource_provider_, quad->mask_resource_id, GL_TEXTURE1, GL_LINEAR)); 1098 resource_provider_, quad->mask_resource_id, GL_TEXTURE1, GL_LINEAR));
1105 mask_texture_id = mask_resource_lock->texture_id(); 1099 mask_texture_id = mask_resource_lock->texture_id();
1106 mask_sampler = SamplerTypeFromTextureTarget(mask_resource_lock->target()); 1100 mask_sampler = SamplerTypeFromTextureTarget(mask_resource_lock->target());
1107 } 1101 }
1108 1102
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 mask_uv_rect.x(), 1346 mask_uv_rect.x(),
1353 mask_uv_rect.bottom())); 1347 mask_uv_rect.bottom()));
1354 GLC(gl_, 1348 GLC(gl_,
1355 gl_->Uniform2f(shader_mask_tex_coord_scale_location, 1349 gl_->Uniform2f(shader_mask_tex_coord_scale_location,
1356 mask_uv_rect.width() / tex_scale_x, 1350 mask_uv_rect.width() / tex_scale_x,
1357 -mask_uv_rect.height() / tex_scale_y)); 1351 -mask_uv_rect.height() / tex_scale_y));
1358 1352
1359 last_texture_unit = 1; 1353 last_texture_unit = 1;
1360 } 1354 }
1361 1355
1362 if (shader_edge_location != -1) { 1356 if (shader_edge_location != -1)
1363 float edge[24];
1364 device_layer_edges.ToFloatArray(edge);
1365 device_layer_bounds.ToFloatArray(&edge[12]);
1366 GLC(gl_, gl_->Uniform3fv(shader_edge_location, 8, edge)); 1357 GLC(gl_, gl_->Uniform3fv(shader_edge_location, 8, edge));
1367 }
1368 1358
1369 if (shader_viewport_location != -1) { 1359 if (shader_viewport_location != -1) {
1370 float viewport[4] = {static_cast<float>(viewport_.x()), 1360 float viewport[4] = {static_cast<float>(viewport_.x()),
1371 static_cast<float>(viewport_.y()), 1361 static_cast<float>(viewport_.y()),
1372 static_cast<float>(viewport_.width()), 1362 static_cast<float>(viewport_.width()),
1373 static_cast<float>(viewport_.height()), }; 1363 static_cast<float>(viewport_.height()), };
1374 GLC(gl_, gl_->Uniform4fv(shader_viewport_location, 1, viewport)); 1364 GLC(gl_, gl_->Uniform4fv(shader_viewport_location, 1, viewport));
1375 } 1365 }
1376 1366
1377 if (shader_color_matrix_location != -1) { 1367 if (shader_color_matrix_location != -1) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 shader_background_sampler_lock = make_scoped_ptr( 1406 shader_background_sampler_lock = make_scoped_ptr(
1417 new ResourceProvider::ScopedSamplerGL(resource_provider_, 1407 new ResourceProvider::ScopedSamplerGL(resource_provider_,
1418 background_texture->id(), 1408 background_texture->id(),
1419 GL_TEXTURE0 + last_texture_unit, 1409 GL_TEXTURE0 + last_texture_unit,
1420 GL_LINEAR)); 1410 GL_LINEAR));
1421 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1411 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1422 shader_background_sampler_lock->target()); 1412 shader_background_sampler_lock->target());
1423 } 1413 }
1424 } 1414 }
1425 1415
1426 // Map device space quad to surface space. contents_device_transform has no 3d
1427 // component since it was flattened, so we don't need to project.
1428 gfx::QuadF surface_quad = MathUtil::MapQuad(contents_device_transform_inverse,
1429 device_layer_edges.ToQuadF(),
1430 &clipped);
1431
1432 SetShaderOpacity(quad->opacity(), shader_alpha_location); 1416 SetShaderOpacity(quad->opacity(), shader_alpha_location);
1433 SetShaderQuadF(surface_quad, shader_quad_location); 1417 SetShaderQuadF(surface_quad, shader_quad_location);
1434 DrawQuadGeometry( 1418 DrawQuadGeometry(
1435 frame, quad->quadTransform(), quad->rect, shader_matrix_location); 1419 frame, quad->quadTransform(), quad->rect, shader_matrix_location);
1436 1420
1437 // Flush the compositor context before the filter bitmap goes out of 1421 // Flush the compositor context before the filter bitmap goes out of
1438 // scope, so the draw gets processed before the filter texture gets deleted. 1422 // scope, so the draw gets processed before the filter texture gets deleted.
1439 if (filter_image) 1423 if (filter_image)
1440 GLC(gl_, gl_->Flush()); 1424 GLC(gl_, gl_->Flush());
1441 1425
(...skipping 14 matching lines...) Expand all
1456 static void SolidColorUniformLocation(T program, 1440 static void SolidColorUniformLocation(T program,
1457 SolidColorProgramUniforms* uniforms) { 1441 SolidColorProgramUniforms* uniforms) {
1458 uniforms->program = program->program(); 1442 uniforms->program = program->program();
1459 uniforms->matrix_location = program->vertex_shader().matrix_location(); 1443 uniforms->matrix_location = program->vertex_shader().matrix_location();
1460 uniforms->viewport_location = program->vertex_shader().viewport_location(); 1444 uniforms->viewport_location = program->vertex_shader().viewport_location();
1461 uniforms->quad_location = program->vertex_shader().quad_location(); 1445 uniforms->quad_location = program->vertex_shader().quad_location();
1462 uniforms->edge_location = program->vertex_shader().edge_location(); 1446 uniforms->edge_location = program->vertex_shader().edge_location();
1463 uniforms->color_location = program->fragment_shader().color_location(); 1447 uniforms->color_location = program->fragment_shader().color_location();
1464 } 1448 }
1465 1449
1466 // static 1450 static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges(
1467 bool GLRenderer::SetupQuadForAntialiasing( 1451 const LayerQuad& device_layer_edges,
1468 const gfx::Transform& device_transform, 1452 const gfx::Transform& device_transform,
1469 const DrawQuad* quad, 1453 const DrawQuad* quad) {
1470 gfx::QuadF* local_quad,
1471 float edge[24]) {
1472 gfx::Rect tile_rect = quad->visible_rect; 1454 gfx::Rect tile_rect = quad->visible_rect;
1473
1474 bool clipped = false;
1475 gfx::QuadF device_layer_quad = MathUtil::MapQuad(
1476 device_transform, gfx::QuadF(quad->visibleContentRect()), &clipped);
1477
1478 bool is_axis_aligned_in_target = device_layer_quad.IsRectilinear();
1479 bool is_nearest_rect_within_epsilon =
1480 is_axis_aligned_in_target &&
1481 gfx::IsNearestRectWithinDistance(device_layer_quad.BoundingBox(),
1482 kAntiAliasingEpsilon);
1483 // AAing clipped quads is not supported by the code yet.
1484 bool use_aa = !clipped && !is_nearest_rect_within_epsilon && quad->IsEdge();
1485 if (!use_aa)
1486 return false;
1487
1488 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox()));
1489 device_layer_bounds.InflateAntiAliasingDistance();
1490
1491 LayerQuad device_layer_edges(device_layer_quad);
1492 device_layer_edges.InflateAntiAliasingDistance();
1493
1494 device_layer_edges.ToFloatArray(edge);
1495 device_layer_bounds.ToFloatArray(&edge[12]);
1496
1497 gfx::PointF bottom_right = tile_rect.bottom_right(); 1455 gfx::PointF bottom_right = tile_rect.bottom_right();
1498 gfx::PointF bottom_left = tile_rect.bottom_left(); 1456 gfx::PointF bottom_left = tile_rect.bottom_left();
1499 gfx::PointF top_left = tile_rect.origin(); 1457 gfx::PointF top_left = tile_rect.origin();
1500 gfx::PointF top_right = tile_rect.top_right(); 1458 gfx::PointF top_right = tile_rect.top_right();
1459 bool clipped = false;
1501 1460
1502 // Map points to device space. We ignore |clipped|, since the result of 1461 // Map points to device space. We ignore |clipped|, since the result of
1503 // |MapPoint()| still produces a valid point to draw the quad with. When 1462 // |MapPoint()| still produces a valid point to draw the quad with. When
1504 // clipped, the point will be outside of the viewport. See crbug.com/416367. 1463 // clipped, the point will be outside of the viewport. See crbug.com/416367.
1505 bottom_right = MathUtil::MapPoint(device_transform, bottom_right, &clipped); 1464 bottom_right = MathUtil::MapPoint(device_transform, bottom_right, &clipped);
1506 bottom_left = MathUtil::MapPoint(device_transform, bottom_left, &clipped); 1465 bottom_left = MathUtil::MapPoint(device_transform, bottom_left, &clipped);
1507 top_left = MathUtil::MapPoint(device_transform, top_left, &clipped); 1466 top_left = MathUtil::MapPoint(device_transform, top_left, &clipped);
1508 top_right = MathUtil::MapPoint(device_transform, top_right, &clipped); 1467 top_right = MathUtil::MapPoint(device_transform, top_right, &clipped);
1509 1468
1510 LayerQuad::Edge bottom_edge(bottom_right, bottom_left); 1469 LayerQuad::Edge bottom_edge(bottom_right, bottom_left);
(...skipping 11 matching lines...) Expand all
1522 if (quad->IsBottomEdge() && tile_rect.bottom() == quad->rect.bottom()) 1481 if (quad->IsBottomEdge() && tile_rect.bottom() == quad->rect.bottom())
1523 bottom_edge = device_layer_edges.bottom(); 1482 bottom_edge = device_layer_edges.bottom();
1524 1483
1525 float sign = gfx::QuadF(tile_rect).IsCounterClockwise() ? -1 : 1; 1484 float sign = gfx::QuadF(tile_rect).IsCounterClockwise() ? -1 : 1;
1526 bottom_edge.scale(sign); 1485 bottom_edge.scale(sign);
1527 left_edge.scale(sign); 1486 left_edge.scale(sign);
1528 top_edge.scale(sign); 1487 top_edge.scale(sign);
1529 right_edge.scale(sign); 1488 right_edge.scale(sign);
1530 1489
1531 // Create device space quad. 1490 // Create device space quad.
1532 LayerQuad device_quad(left_edge, top_edge, right_edge, bottom_edge); 1491 return LayerQuad(left_edge, top_edge, right_edge, bottom_edge).ToQuadF();
1492 }
1493
1494 // static
1495 bool GLRenderer::ShouldAntialiasQuad(const gfx::Transform& device_transform,
1496 const DrawQuad* quad,
1497 bool force_antialiasing) {
1498 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS);
1499 // For render pass quads, |device_transform| already contains quad's rect.
1500 // TODO(rosca@adobe.com): remove branching on is_render_pass_quad
1501 // crbug.com/429702
1502 if (!is_render_pass_quad && !quad->IsEdge())
1503 return false;
1504 gfx::RectF content_rect =
1505 is_render_pass_quad ? QuadVertexRect() : quad->visibleContentRect();
1506
1507 bool clipped = false;
1508 gfx::QuadF device_layer_quad =
1509 MathUtil::MapQuad(device_transform, gfx::QuadF(content_rect), &clipped);
1510
1511 if (device_layer_quad.BoundingBox().IsEmpty())
1512 return false;
1513
1514 bool is_axis_aligned_in_target = device_layer_quad.IsRectilinear();
1515 bool is_nearest_rect_within_epsilon =
1516 is_axis_aligned_in_target &&
1517 gfx::IsNearestRectWithinDistance(device_layer_quad.BoundingBox(),
1518 kAntiAliasingEpsilon);
1519 // AAing clipped quads is not supported by the code yet.
1520 bool use_aa = !clipped && !is_nearest_rect_within_epsilon;
1521 return use_aa || force_antialiasing;
1522 }
1523
1524 // static
1525 void GLRenderer::SetupQuadForAntialiasing(
1526 const gfx::Transform& device_transform,
1527 const DrawQuad* quad,
1528 gfx::QuadF* local_quad,
1529 float edge[24]) {
1530 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS);
1531 gfx::RectF content_rect =
1532 is_render_pass_quad ? QuadVertexRect() : quad->visibleContentRect();
1533
1534 bool clipped = false;
1535 gfx::QuadF device_layer_quad =
1536 MathUtil::MapQuad(device_transform, gfx::QuadF(content_rect), &clipped);
1537
1538 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox()));
1539 device_layer_bounds.InflateAntiAliasingDistance();
1540
1541 LayerQuad device_layer_edges(device_layer_quad);
1542 device_layer_edges.InflateAntiAliasingDistance();
1543
1544 device_layer_edges.ToFloatArray(edge);
1545 device_layer_bounds.ToFloatArray(&edge[12]);
1546
1547 bool use_aa_on_all_four_edges =
1548 is_render_pass_quad ||
1549 (quad->IsTopEdge() && quad->IsLeftEdge() && quad->IsBottomEdge() &&
1550 quad->IsRightEdge() && quad->visible_rect == quad->rect);
1551
1552 gfx::QuadF device_quad =
1553 use_aa_on_all_four_edges
1554 ? device_layer_edges.ToQuadF()
1555 : GetDeviceQuadWithAntialiasingOnExteriorEdges(
1556 device_layer_edges, device_transform, quad);
1533 1557
1534 // Map device space quad to local space. device_transform has no 3d 1558 // Map device space quad to local space. device_transform has no 3d
1535 // component since it was flattened, so we don't need to project. We should 1559 // component since it was flattened, so we don't need to project. We should
1536 // have already checked that the transform was uninvertible above. 1560 // have already checked that the transform was uninvertible above.
1537 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); 1561 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization);
1538 bool did_invert = device_transform.GetInverse(&inverse_device_transform); 1562 bool did_invert = device_transform.GetInverse(&inverse_device_transform);
1539 DCHECK(did_invert); 1563 DCHECK(did_invert);
1540 *local_quad = MathUtil::MapQuad( 1564 *local_quad =
1541 inverse_device_transform, device_quad.ToQuadF(), &clipped); 1565 MathUtil::MapQuad(inverse_device_transform, device_quad, &clipped);
1542 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may 1566 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may
1543 // cause device_quad to become clipped. To our knowledge this scenario does 1567 // cause device_quad to become clipped. To our knowledge this scenario does
1544 // not need to be handled differently than the unclipped case. 1568 // not need to be handled differently than the unclipped case.
1545
1546 return true;
1547 } 1569 }
1548 1570
1549 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, 1571 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame,
1550 const SolidColorDrawQuad* quad) { 1572 const SolidColorDrawQuad* quad) {
1551 gfx::Rect tile_rect = quad->visible_rect; 1573 gfx::Rect tile_rect = quad->visible_rect;
1552 1574
1553 SkColor color = quad->color; 1575 SkColor color = quad->color;
1554 float opacity = quad->opacity(); 1576 float opacity = quad->opacity();
1555 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; 1577 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity;
1556 1578
1557 // Early out if alpha is small enough that quad doesn't contribute to output. 1579 // Early out if alpha is small enough that quad doesn't contribute to output.
1558 if (alpha < std::numeric_limits<float>::epsilon() && 1580 if (alpha < std::numeric_limits<float>::epsilon() &&
1559 quad->ShouldDrawWithBlending()) 1581 quad->ShouldDrawWithBlending())
1560 return; 1582 return;
1561 1583
1562 gfx::Transform device_transform = 1584 gfx::Transform device_transform =
1563 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); 1585 frame->window_matrix * frame->projection_matrix * quad->quadTransform();
1564 device_transform.FlattenTo2d(); 1586 device_transform.FlattenTo2d();
1565 if (!device_transform.IsInvertible()) 1587 if (!device_transform.IsInvertible())
1566 return; 1588 return;
1567 1589
1590 bool force_aa = false;
1568 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); 1591 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect));
1569 float edge[24]; 1592 float edge[24];
1570 bool use_aa = 1593 bool use_aa = settings_->allow_antialiasing &&
1571 settings_->allow_antialiasing && !quad->force_anti_aliasing_off && 1594 !quad->force_anti_aliasing_off &&
1572 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); 1595 ShouldAntialiasQuad(device_transform, quad, force_aa);
1573 1596
1574 SolidColorProgramUniforms uniforms; 1597 SolidColorProgramUniforms uniforms;
1575 if (use_aa) 1598 if (use_aa) {
1599 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge);
1576 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); 1600 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms);
1577 else 1601 } else {
1578 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); 1602 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms);
1603 }
1579 SetUseProgram(uniforms.program); 1604 SetUseProgram(uniforms.program);
1580 1605
1581 GLC(gl_, 1606 GLC(gl_,
1582 gl_->Uniform4f(uniforms.color_location, 1607 gl_->Uniform4f(uniforms.color_location,
1583 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, 1608 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha,
1584 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, 1609 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha,
1585 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, 1610 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha,
1586 alpha)); 1611 alpha));
1587 if (use_aa) { 1612 if (use_aa) {
1588 float viewport[4] = {static_cast<float>(viewport_.x()), 1613 float viewport[4] = {static_cast<float>(viewport_.x()),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 } 1667 }
1643 1668
1644 void GLRenderer::DrawTileQuad(const DrawingFrame* frame, 1669 void GLRenderer::DrawTileQuad(const DrawingFrame* frame,
1645 const TileDrawQuad* quad) { 1670 const TileDrawQuad* quad) {
1646 DrawContentQuad(frame, quad, quad->resource_id); 1671 DrawContentQuad(frame, quad, quad->resource_id);
1647 } 1672 }
1648 1673
1649 void GLRenderer::DrawContentQuad(const DrawingFrame* frame, 1674 void GLRenderer::DrawContentQuad(const DrawingFrame* frame,
1650 const ContentDrawQuadBase* quad, 1675 const ContentDrawQuadBase* quad,
1651 ResourceProvider::ResourceId resource_id) { 1676 ResourceProvider::ResourceId resource_id) {
1677 gfx::Transform device_transform =
1678 frame->window_matrix * frame->projection_matrix * quad->quadTransform();
1679 device_transform.FlattenTo2d();
1680
1681 bool use_aa = settings_->allow_antialiasing &&
1682 ShouldAntialiasQuad(device_transform, quad, false);
1683
1684 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA
1685 // similar to the way DrawContentQuadNoAA works and then consider
1686 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method.
1687 if (use_aa)
1688 DrawContentQuadAA(frame, quad, resource_id, device_transform);
1689 else
1690 DrawContentQuadNoAA(frame, quad, resource_id);
1691 }
1692
1693 void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame,
1694 const ContentDrawQuadBase* quad,
1695 ResourceProvider::ResourceId resource_id,
1696 const gfx::Transform& device_transform) {
1697 if (!device_transform.IsInvertible())
1698 return;
1699
1652 gfx::Rect tile_rect = quad->visible_rect; 1700 gfx::Rect tile_rect = quad->visible_rect;
1653 1701
1654 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( 1702 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional(
1655 quad->tex_coord_rect, quad->rect, tile_rect); 1703 quad->tex_coord_rect, quad->rect, tile_rect);
1656 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); 1704 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width();
1657 float tex_to_geom_scale_y = 1705 float tex_to_geom_scale_y =
1658 quad->rect.height() / quad->tex_coord_rect.height(); 1706 quad->rect.height() / quad->tex_coord_rect.height();
1659 1707
1660 gfx::RectF clamp_geom_rect(tile_rect); 1708 gfx::RectF clamp_geom_rect(tile_rect);
1661 gfx::RectF clamp_tex_rect(tex_coord_rect); 1709 gfx::RectF clamp_tex_rect(tex_coord_rect);
(...skipping 19 matching lines...) Expand all
1681 // Map clamping rectangle to unit square. 1729 // Map clamping rectangle to unit square.
1682 float vertex_tex_translate_x = -clamp_geom_rect.x() / clamp_geom_rect.width(); 1730 float vertex_tex_translate_x = -clamp_geom_rect.x() / clamp_geom_rect.width();
1683 float vertex_tex_translate_y = 1731 float vertex_tex_translate_y =
1684 -clamp_geom_rect.y() / clamp_geom_rect.height(); 1732 -clamp_geom_rect.y() / clamp_geom_rect.height();
1685 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); 1733 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width();
1686 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); 1734 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height();
1687 1735
1688 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1736 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1689 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); 1737 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size);
1690 1738
1691 gfx::Transform device_transform =
1692 frame->window_matrix * frame->projection_matrix * quad->quadTransform();
1693 device_transform.FlattenTo2d();
1694 if (!device_transform.IsInvertible())
1695 return;
1696
1697 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); 1739 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect));
1698 float edge[24]; 1740 float edge[24];
1699 bool use_aa = 1741 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge);
1700 settings_->allow_antialiasing &&
1701 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge);
1702 1742
1703 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f);
1704 GLenum filter = (use_aa || scaled ||
1705 !quad->quadTransform().IsIdentityOrIntegerTranslation())
1706 ? GL_LINEAR
1707 : GL_NEAREST;
1708 ResourceProvider::ScopedSamplerGL quad_resource_lock( 1743 ResourceProvider::ScopedSamplerGL quad_resource_lock(
1709 resource_provider_, resource_id, filter); 1744 resource_provider_, resource_id, GL_LINEAR);
1710 SamplerType sampler = 1745 SamplerType sampler =
1711 SamplerTypeFromTextureTarget(quad_resource_lock.target()); 1746 SamplerTypeFromTextureTarget(quad_resource_lock.target());
1712 1747
1713 float fragment_tex_translate_x = clamp_tex_rect.x(); 1748 float fragment_tex_translate_x = clamp_tex_rect.x();
1714 float fragment_tex_translate_y = clamp_tex_rect.y(); 1749 float fragment_tex_translate_y = clamp_tex_rect.y();
1715 float fragment_tex_scale_x = clamp_tex_rect.width(); 1750 float fragment_tex_scale_x = clamp_tex_rect.width();
1716 float fragment_tex_scale_y = clamp_tex_rect.height(); 1751 float fragment_tex_scale_y = clamp_tex_rect.height();
1717 1752
1718 // Map to normalized texture coordinates. 1753 // Map to normalized texture coordinates.
1719 if (sampler != SamplerType2DRect) { 1754 if (sampler != SamplerType2DRect) {
1720 gfx::Size texture_size = quad->texture_size; 1755 gfx::Size texture_size = quad->texture_size;
1721 DCHECK(!texture_size.IsEmpty()); 1756 DCHECK(!texture_size.IsEmpty());
1722 fragment_tex_translate_x /= texture_size.width(); 1757 fragment_tex_translate_x /= texture_size.width();
1723 fragment_tex_translate_y /= texture_size.height(); 1758 fragment_tex_translate_y /= texture_size.height();
1724 fragment_tex_scale_x /= texture_size.width(); 1759 fragment_tex_scale_x /= texture_size.width();
1725 fragment_tex_scale_y /= texture_size.height(); 1760 fragment_tex_scale_y /= texture_size.height();
1726 } 1761 }
1727 1762
1728 TileProgramUniforms uniforms; 1763 TileProgramUniforms uniforms;
1729 if (use_aa) { 1764 if (quad->swizzle_contents) {
1730 if (quad->swizzle_contents) { 1765 TileUniformLocation(GetTileProgramSwizzleAA(tex_coord_precision, sampler),
1731 TileUniformLocation(GetTileProgramSwizzleAA(tex_coord_precision, sampler), 1766 &uniforms);
1732 &uniforms);
1733 } else {
1734 TileUniformLocation(GetTileProgramAA(tex_coord_precision, sampler),
1735 &uniforms);
1736 }
1737 } else { 1767 } else {
1738 if (quad->ShouldDrawWithBlending()) { 1768 TileUniformLocation(GetTileProgramAA(tex_coord_precision, sampler),
1739 if (quad->swizzle_contents) { 1769 &uniforms);
1740 TileUniformLocation(GetTileProgramSwizzle(tex_coord_precision, sampler),
1741 &uniforms);
1742 } else {
1743 TileUniformLocation(GetTileProgram(tex_coord_precision, sampler),
1744 &uniforms);
1745 }
1746 } else {
1747 if (quad->swizzle_contents) {
1748 TileUniformLocation(
1749 GetTileProgramSwizzleOpaque(tex_coord_precision, sampler),
1750 &uniforms);
1751 } else {
1752 TileUniformLocation(GetTileProgramOpaque(tex_coord_precision, sampler),
1753 &uniforms);
1754 }
1755 }
1756 } 1770 }
1757 1771
1758 SetUseProgram(uniforms.program); 1772 SetUseProgram(uniforms.program);
1759 GLC(gl_, gl_->Uniform1i(uniforms.sampler_location, 0)); 1773 GLC(gl_, gl_->Uniform1i(uniforms.sampler_location, 0));
1760 1774
1761 if (use_aa) { 1775 float viewport[4] = {
1762 float viewport[4] = {static_cast<float>(viewport_.x()), 1776 static_cast<float>(viewport_.x()),
1763 static_cast<float>(viewport_.y()), 1777 static_cast<float>(viewport_.y()),
1764 static_cast<float>(viewport_.width()), 1778 static_cast<float>(viewport_.width()),
1765 static_cast<float>(viewport_.height()), }; 1779 static_cast<float>(viewport_.height()),
1766 GLC(gl_, gl_->Uniform4fv(uniforms.viewport_location, 1, viewport)); 1780 };
1767 GLC(gl_, gl_->Uniform3fv(uniforms.edge_location, 8, edge)); 1781 GLC(gl_, gl_->Uniform4fv(uniforms.viewport_location, 1, viewport));
1782 GLC(gl_, gl_->Uniform3fv(uniforms.edge_location, 8, edge));
1768 1783
1769 GLC(gl_, 1784 GLC(gl_,
1770 gl_->Uniform4f(uniforms.vertex_tex_transform_location, 1785 gl_->Uniform4f(uniforms.vertex_tex_transform_location,
1771 vertex_tex_translate_x, 1786 vertex_tex_translate_x,
1772 vertex_tex_translate_y, 1787 vertex_tex_translate_y,
1773 vertex_tex_scale_x, 1788 vertex_tex_scale_x,
1774 vertex_tex_scale_y)); 1789 vertex_tex_scale_y));
1775 GLC(gl_, 1790 GLC(gl_,
1776 gl_->Uniform4f(uniforms.fragment_tex_transform_location, 1791 gl_->Uniform4f(uniforms.fragment_tex_transform_location,
1777 fragment_tex_translate_x, 1792 fragment_tex_translate_x,
1778 fragment_tex_translate_y, 1793 fragment_tex_translate_y,
1779 fragment_tex_scale_x, 1794 fragment_tex_scale_x,
1780 fragment_tex_scale_y)); 1795 fragment_tex_scale_y));
1781 } else {
1782 // Move fragment shader transform to vertex shader. We can do this while
1783 // still producing correct results as fragment_tex_transform_location
1784 // should always be non-negative when tiles are transformed in a way
1785 // that could result in sampling outside the layer.
1786 vertex_tex_scale_x *= fragment_tex_scale_x;
1787 vertex_tex_scale_y *= fragment_tex_scale_y;
1788 vertex_tex_translate_x *= fragment_tex_scale_x;
1789 vertex_tex_translate_y *= fragment_tex_scale_y;
1790 vertex_tex_translate_x += fragment_tex_translate_x;
1791 vertex_tex_translate_y += fragment_tex_translate_y;
1792 1796
1793 GLC(gl_, 1797 // Blending is required for antialiasing.
1794 gl_->Uniform4f(uniforms.vertex_tex_transform_location, 1798 SetBlendEnabled(true);
1795 vertex_tex_translate_x,
1796 vertex_tex_translate_y,
1797 vertex_tex_scale_x,
1798 vertex_tex_scale_y));
1799 }
1800
1801 // Enable blending when the quad properties require it or if we decided
1802 // to use antialiasing.
1803 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa);
1804 1799
1805 // Normalize to tile_rect. 1800 // Normalize to tile_rect.
1806 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); 1801 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
1807 1802
1808 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); 1803 SetShaderOpacity(quad->opacity(), uniforms.alpha_location);
1809 SetShaderQuadF(local_quad, uniforms.quad_location); 1804 SetShaderQuadF(local_quad, uniforms.quad_location);
1810 1805
1811 // The transform and vertex data are used to figure out the extents that the 1806 // The transform and vertex data are used to figure out the extents that the
1812 // un-antialiased quad should have and which vertex this is and the float 1807 // un-antialiased quad should have and which vertex this is and the float
1813 // quad passed in via uniform is the actual geometry that gets used to draw 1808 // quad passed in via uniform is the actual geometry that gets used to draw
1814 // it. This is why this centered rect is used and not the original quad_rect. 1809 // it. This is why this centered rect is used and not the original quad_rect.
1815 gfx::RectF centered_rect( 1810 gfx::RectF centered_rect(
1816 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), 1811 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()),
1817 tile_rect.size()); 1812 tile_rect.size());
1818 DrawQuadGeometry( 1813 DrawQuadGeometry(
1819 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); 1814 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location);
1820 } 1815 }
1821 1816
1817 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame,
1818 const ContentDrawQuadBase* quad,
1819 ResourceProvider::ResourceId resource_id) {
1820 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional(
1821 quad->tex_coord_rect, quad->rect, quad->visible_rect);
1822 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width();
1823 float tex_to_geom_scale_y =
1824 quad->rect.height() / quad->tex_coord_rect.height();
1825
1826 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f);
1827 GLenum filter =
1828 (scaled || !quad->quadTransform().IsIdentityOrIntegerTranslation())
1829 ? GL_LINEAR
1830 : GL_NEAREST;
1831
1832 ResourceProvider::ScopedSamplerGL quad_resource_lock(
1833 resource_provider_, resource_id, filter);
1834 SamplerType sampler =
1835 SamplerTypeFromTextureTarget(quad_resource_lock.target());
1836
1837 float vertex_tex_translate_x = tex_coord_rect.x();
1838 float vertex_tex_translate_y = tex_coord_rect.y();
1839 float vertex_tex_scale_x = tex_coord_rect.width();
1840 float vertex_tex_scale_y = tex_coord_rect.height();
1841
1842 // Map to normalized texture coordinates.
1843 if (sampler != SamplerType2DRect) {
1844 gfx::Size texture_size = quad->texture_size;
1845 DCHECK(!texture_size.IsEmpty());
1846 vertex_tex_translate_x /= texture_size.width();
1847 vertex_tex_translate_y /= texture_size.height();
1848 vertex_tex_scale_x /= texture_size.width();
1849 vertex_tex_scale_y /= texture_size.height();
1850 }
1851
1852 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1853 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size);
1854
1855 TileProgramUniforms uniforms;
1856 if (quad->ShouldDrawWithBlending()) {
1857 if (quad->swizzle_contents) {
1858 TileUniformLocation(GetTileProgramSwizzle(tex_coord_precision, sampler),
1859 &uniforms);
1860 } else {
1861 TileUniformLocation(GetTileProgram(tex_coord_precision, sampler),
1862 &uniforms);
1863 }
1864 } else {
1865 if (quad->swizzle_contents) {
1866 TileUniformLocation(
1867 GetTileProgramSwizzleOpaque(tex_coord_precision, sampler), &uniforms);
1868 } else {
1869 TileUniformLocation(GetTileProgramOpaque(tex_coord_precision, sampler),
1870 &uniforms);
1871 }
1872 }
1873
1874 SetUseProgram(uniforms.program);
1875 GLC(gl_, gl_->Uniform1i(uniforms.sampler_location, 0));
1876
1877 GLC(gl_,
1878 gl_->Uniform4f(uniforms.vertex_tex_transform_location,
1879 vertex_tex_translate_x,
1880 vertex_tex_translate_y,
1881 vertex_tex_scale_x,
1882 vertex_tex_scale_y));
1883
1884 SetBlendEnabled(quad->ShouldDrawWithBlending());
1885
1886 SetShaderOpacity(quad->opacity(), uniforms.alpha_location);
1887
1888 // Pass quad coordinates to the uniform in the same order as GeometryBinding
1889 // does, then vertices will match the texture mapping in the vertex buffer.
1890 // The method SetShaderQuadF() changes the order of vertices and so it's
1891 // not used here.
1892
1893 gfx::RectF tile_rect = quad->visible_rect;
1894 float gl_quad[8] = {
1895 tile_rect.x(),
1896 tile_rect.bottom(),
1897 tile_rect.x(),
1898 tile_rect.y(),
1899 tile_rect.right(),
1900 tile_rect.y(),
1901 tile_rect.right(),
1902 tile_rect.bottom(),
1903 };
1904 GLC(gl_, gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad));
1905
1906 static float gl_matrix[16];
1907 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad->quadTransform());
1908 GLC(gl_,
1909 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0]));
1910
1911 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0));
1912 }
1913
1822 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, 1914 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame,
1823 const YUVVideoDrawQuad* quad) { 1915 const YUVVideoDrawQuad* quad) {
1824 SetBlendEnabled(quad->ShouldDrawWithBlending()); 1916 SetBlendEnabled(quad->ShouldDrawWithBlending());
1825 1917
1826 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1918 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1827 gl_, 1919 gl_,
1828 &highp_threshold_cache_, 1920 &highp_threshold_cache_,
1829 highp_threshold_min_, 1921 highp_threshold_min_,
1830 quad->shared_quad_state->visible_content_rect.bottom_right()); 1922 quad->shared_quad_state->visible_content_rect.bottom_right());
1831 1923
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( 2089 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture(
1998 quad->texture_size, 2090 quad->texture_size,
1999 GL_TEXTURE_2D, 2091 GL_TEXTURE_2D,
2000 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 2092 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
2001 GL_CLAMP_TO_EDGE, 2093 GL_CLAMP_TO_EDGE,
2002 ResourceProvider::TextureHintImmutable, 2094 ResourceProvider::TextureHintImmutable,
2003 quad->texture_format); 2095 quad->texture_format);
2004 } 2096 }
2005 2097
2006 SkCanvas canvas(on_demand_tile_raster_bitmap_); 2098 SkCanvas canvas(on_demand_tile_raster_bitmap_);
2007 quad->picture_pile->PlaybackToCanvas( 2099 quad->picture_pile->PlaybackToCanvas(&canvas, quad->content_rect,
2008 &canvas, quad->content_rect, quad->contents_scale, NULL); 2100 quad->contents_scale);
2009 2101
2010 uint8_t* bitmap_pixels = NULL; 2102 uint8_t* bitmap_pixels = NULL;
2011 SkBitmap on_demand_tile_raster_bitmap_dest; 2103 SkBitmap on_demand_tile_raster_bitmap_dest;
2012 SkColorType colorType = ResourceFormatToSkColorType(quad->texture_format); 2104 SkColorType colorType = ResourceFormatToSkColorType(quad->texture_format);
2013 if (on_demand_tile_raster_bitmap_.colorType() != colorType) { 2105 if (on_demand_tile_raster_bitmap_.colorType() != colorType) {
2014 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest, 2106 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest,
2015 colorType); 2107 colorType);
2016 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the 2108 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the
2017 // bitmap data. This check will be removed once crbug.com/293728 is fixed. 2109 // bitmap data. This check will be removed once crbug.com/293728 is fixed.
2018 CHECK_EQ(0u, on_demand_tile_raster_bitmap_dest.rowBytes() % 4); 2110 CHECK_EQ(0u, on_demand_tile_raster_bitmap_dest.rowBytes() % 4);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 tex_transform_location = program->vertex_shader().tex_transform_location(); 2147 tex_transform_location = program->vertex_shader().tex_transform_location();
2056 vertex_opacity_location = 2148 vertex_opacity_location =
2057 program->vertex_shader().vertex_opacity_location(); 2149 program->vertex_shader().vertex_opacity_location();
2058 } 2150 }
2059 int tex_transform_location; 2151 int tex_transform_location;
2060 int vertex_opacity_location; 2152 int vertex_opacity_location;
2061 }; 2153 };
2062 2154
2063 void GLRenderer::FlushTextureQuadCache() { 2155 void GLRenderer::FlushTextureQuadCache() {
2064 // Check to see if we have anything to draw. 2156 // Check to see if we have anything to draw.
2065 if (draw_cache_.program_id == 0) 2157 if (draw_cache_.program_id == -1)
2066 return; 2158 return;
2067 2159
2068 // Set the correct blending mode. 2160 // Set the correct blending mode.
2069 SetBlendEnabled(draw_cache_.needs_blending); 2161 SetBlendEnabled(draw_cache_.needs_blending);
2070 2162
2071 // Bind the program to the GL state. 2163 // Bind the program to the GL state.
2072 SetUseProgram(draw_cache_.program_id); 2164 SetUseProgram(draw_cache_.program_id);
2073 2165
2074 // Bind the correct texture sampler location. 2166 // Bind the correct texture sampler location.
2075 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); 2167 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2111 static_cast<float*>(&draw_cache_.vertex_opacity_data.front()))); 2203 static_cast<float*>(&draw_cache_.vertex_opacity_data.front())));
2112 2204
2113 // Draw the quads! 2205 // Draw the quads!
2114 GLC(gl_, 2206 GLC(gl_,
2115 gl_->DrawElements(GL_TRIANGLES, 2207 gl_->DrawElements(GL_TRIANGLES,
2116 6 * draw_cache_.matrix_data.size(), 2208 6 * draw_cache_.matrix_data.size(),
2117 GL_UNSIGNED_SHORT, 2209 GL_UNSIGNED_SHORT,
2118 0)); 2210 0));
2119 2211
2120 // Clear the cache. 2212 // Clear the cache.
2121 draw_cache_.program_id = 0; 2213 draw_cache_.program_id = -1;
2122 draw_cache_.uv_xform_data.resize(0); 2214 draw_cache_.uv_xform_data.resize(0);
2123 draw_cache_.vertex_opacity_data.resize(0); 2215 draw_cache_.vertex_opacity_data.resize(0);
2124 draw_cache_.matrix_data.resize(0); 2216 draw_cache_.matrix_data.resize(0);
2125 } 2217 }
2126 2218
2127 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, 2219 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame,
2128 const TextureDrawQuad* quad) { 2220 const TextureDrawQuad* quad) {
2129 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2221 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2130 gl_, 2222 gl_,
2131 &highp_threshold_cache_, 2223 &highp_threshold_cache_,
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
3342 context_support_->ScheduleOverlayPlane( 3434 context_support_->ScheduleOverlayPlane(
3343 overlay.plane_z_order, 3435 overlay.plane_z_order,
3344 overlay.transform, 3436 overlay.transform,
3345 pending_overlay_resources_.back()->texture_id(), 3437 pending_overlay_resources_.back()->texture_id(),
3346 overlay.display_rect, 3438 overlay.display_rect,
3347 overlay.uv_rect); 3439 overlay.uv_rect);
3348 } 3440 }
3349 } 3441 }
3350 3442
3351 } // namespace cc 3443 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_draw_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698