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

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

Issue 2934963002: [wip/exp] cc: Measure the amount of overdraw.
Patch Set: . Created 3 years, 6 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | no next file » | 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 ReinitializeGLState(); 559 ReinitializeGLState();
560 } 560 }
561 561
562 void GLRenderer::DoDrawQuad(const DrawQuad* quad, 562 void GLRenderer::DoDrawQuad(const DrawQuad* quad,
563 const gfx::QuadF* clip_region) { 563 const gfx::QuadF* clip_region) {
564 DCHECK(quad->rect.Contains(quad->visible_rect)); 564 DCHECK(quad->rect.Contains(quad->visible_rect));
565 if (quad->material != DrawQuad::TEXTURE_CONTENT) { 565 if (quad->material != DrawQuad::TEXTURE_CONTENT) {
566 FlushTextureQuadCache(SHARED_BINDING); 566 FlushTextureQuadCache(SHARED_BINDING);
567 } 567 }
568 568
569 bool was_drawn = false;
569 switch (quad->material) { 570 switch (quad->material) {
570 case DrawQuad::INVALID: 571 case DrawQuad::INVALID:
571 NOTREACHED(); 572 NOTREACHED();
572 break; 573 break;
573 case DrawQuad::DEBUG_BORDER: 574 case DrawQuad::DEBUG_BORDER:
574 DrawDebugBorderQuad(DebugBorderDrawQuad::MaterialCast(quad)); 575 DrawDebugBorderQuad(DebugBorderDrawQuad::MaterialCast(quad));
576 was_drawn = true;
575 break; 577 break;
576 case DrawQuad::PICTURE_CONTENT: 578 case DrawQuad::PICTURE_CONTENT:
577 // PictureDrawQuad should only be used for resourceless software draws. 579 // PictureDrawQuad should only be used for resourceless software draws.
578 NOTREACHED(); 580 NOTREACHED();
579 break; 581 break;
580 case DrawQuad::RENDER_PASS: 582 case DrawQuad::RENDER_PASS:
581 DrawRenderPassQuad(RenderPassDrawQuad::MaterialCast(quad), clip_region); 583 was_drawn = DrawRenderPassQuad(RenderPassDrawQuad::MaterialCast(quad),
584 clip_region);
582 break; 585 break;
583 case DrawQuad::SOLID_COLOR: 586 case DrawQuad::SOLID_COLOR:
584 DrawSolidColorQuad(SolidColorDrawQuad::MaterialCast(quad), clip_region); 587 was_drawn = DrawSolidColorQuad(SolidColorDrawQuad::MaterialCast(quad),
588 clip_region);
585 break; 589 break;
586 case DrawQuad::STREAM_VIDEO_CONTENT: 590 case DrawQuad::STREAM_VIDEO_CONTENT:
587 DrawStreamVideoQuad(StreamVideoDrawQuad::MaterialCast(quad), clip_region); 591 was_drawn = DrawStreamVideoQuad(StreamVideoDrawQuad::MaterialCast(quad),
592 clip_region);
588 break; 593 break;
589 case DrawQuad::SURFACE_CONTENT: 594 case DrawQuad::SURFACE_CONTENT:
590 // Surface content should be fully resolved to other quad types before 595 // Surface content should be fully resolved to other quad types before
591 // reaching a direct renderer. 596 // reaching a direct renderer.
592 NOTREACHED(); 597 NOTREACHED();
593 break; 598 break;
594 case DrawQuad::TEXTURE_CONTENT: 599 case DrawQuad::TEXTURE_CONTENT:
595 EnqueueTextureQuad(TextureDrawQuad::MaterialCast(quad), clip_region); 600 was_drawn =
601 EnqueueTextureQuad(TextureDrawQuad::MaterialCast(quad), clip_region);
596 break; 602 break;
597 case DrawQuad::TILED_CONTENT: 603 case DrawQuad::TILED_CONTENT:
598 DrawTileQuad(TileDrawQuad::MaterialCast(quad), clip_region); 604 was_drawn = DrawTileQuad(TileDrawQuad::MaterialCast(quad), clip_region);
599 break; 605 break;
600 case DrawQuad::YUV_VIDEO_CONTENT: 606 case DrawQuad::YUV_VIDEO_CONTENT:
601 DrawYUVVideoQuad(YUVVideoDrawQuad::MaterialCast(quad), clip_region); 607 was_drawn =
608 DrawYUVVideoQuad(YUVVideoDrawQuad::MaterialCast(quad), clip_region);
602 break; 609 break;
603 } 610 }
611 if (was_drawn)
612 area_drawn_ += quad->visible_rect.size().GetArea();
604 } 613 }
605 614
606 // This function does not handle 3D sorting right now, since the debug border 615 // This function does not handle 3D sorting right now, since the debug border
607 // quads are just drawn as their original quads and not in split pieces. This 616 // quads are just drawn as their original quads and not in split pieces. This
608 // results in some debug border quads drawing over foreground quads. 617 // results in some debug border quads drawing over foreground quads.
609 void GLRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) { 618 void GLRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) {
610 SetBlendEnabled(quad->ShouldDrawWithBlending()); 619 SetBlendEnabled(quad->ShouldDrawWithBlending());
611 620
612 SetUseProgram(ProgramKey::DebugBorder(), gfx::ColorSpace::CreateSRGB()); 621 SetUseProgram(ProgramKey::DebugBorder(), gfx::ColorSpace::CreateSRGB());
613 622
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 return nullptr; 1035 return nullptr;
1027 #if defined(OS_MACOSX) 1036 #if defined(OS_MACOSX)
1028 // On Macs, this path can sometimes lead to all black output. 1037 // On Macs, this path can sometimes lead to all black output.
1029 // TODO(enne): investigate this and remove this hack. 1038 // TODO(enne): investigate this and remove this hack.
1030 return nullptr; 1039 return nullptr;
1031 #endif 1040 #endif
1032 1041
1033 return tile_quad; 1042 return tile_quad;
1034 } 1043 }
1035 1044
1036 void GLRenderer::DrawRenderPassQuad(const RenderPassDrawQuad* quad, 1045 bool GLRenderer::DrawRenderPassQuad(const RenderPassDrawQuad* quad,
1037 const gfx::QuadF* clip_region) { 1046 const gfx::QuadF* clip_region) {
1038 auto bypass = render_pass_bypass_quads_.find(quad->render_pass_id); 1047 auto bypass = render_pass_bypass_quads_.find(quad->render_pass_id);
1039 DrawRenderPassDrawQuadParams params; 1048 DrawRenderPassDrawQuadParams params;
1040 params.quad = quad; 1049 params.quad = quad;
1041 params.clip_region = clip_region; 1050 params.clip_region = clip_region;
1042 params.window_matrix = current_frame()->window_matrix; 1051 params.window_matrix = current_frame()->window_matrix;
1043 params.projection_matrix = current_frame()->projection_matrix; 1052 params.projection_matrix = current_frame()->projection_matrix;
1044 params.tex_coord_rect = quad->tex_coord_rect; 1053 params.tex_coord_rect = quad->tex_coord_rect;
1045 if (bypass != render_pass_bypass_quads_.end()) { 1054 if (bypass != render_pass_bypass_quads_.end()) {
1046 TileDrawQuad* tile_quad = &bypass->second; 1055 TileDrawQuad* tile_quad = &bypass->second;
1047 // RGBA_8888 here is arbitrary and unused. 1056 // RGBA_8888 here is arbitrary and unused.
1048 Resource tile_resource(tile_quad->resource_id(), tile_quad->texture_size, 1057 Resource tile_resource(tile_quad->resource_id(), tile_quad->texture_size,
1049 ResourceFormat::RGBA_8888, 1058 ResourceFormat::RGBA_8888,
1050 current_frame()->current_render_pass->color_space); 1059 current_frame()->current_render_pass->color_space);
1051 // The projection matrix used by GLRenderer has a flip. As tile texture 1060 // The projection matrix used by GLRenderer has a flip. As tile texture
1052 // inputs are oriented opposite to framebuffer outputs, don't flip via 1061 // inputs are oriented opposite to framebuffer outputs, don't flip via
1053 // texture coords and let the projection matrix naturallyd o it. 1062 // texture coords and let the projection matrix naturallyd o it.
1054 params.flip_texture = false; 1063 params.flip_texture = false;
1055 params.contents_texture = &tile_resource; 1064 params.contents_texture = &tile_resource;
1056 DrawRenderPassQuadInternal(&params); 1065 return DrawRenderPassQuadInternal(&params);
1057 } else { 1066 } else {
1058 ScopedResource* contents_texture = 1067 ScopedResource* contents_texture =
1059 render_pass_textures_[quad->render_pass_id].get(); 1068 render_pass_textures_[quad->render_pass_id].get();
1060 DCHECK(contents_texture); 1069 DCHECK(contents_texture);
1061 DCHECK(contents_texture->id()); 1070 DCHECK(contents_texture->id());
1062 // See above comments about texture flipping. When the input is a 1071 // See above comments about texture flipping. When the input is a
1063 // render pass, it needs to an extra flip to be oriented correctly. 1072 // render pass, it needs to an extra flip to be oriented correctly.
1064 params.flip_texture = true; 1073 params.flip_texture = true;
1065 params.contents_texture = contents_texture; 1074 params.contents_texture = contents_texture;
1066 DrawRenderPassQuadInternal(&params); 1075 return DrawRenderPassQuadInternal(&params);
1067 } 1076 }
1068 } 1077 }
1069 1078
1070 void GLRenderer::DrawRenderPassQuadInternal( 1079 bool GLRenderer::DrawRenderPassQuadInternal(
1071 DrawRenderPassDrawQuadParams* params) { 1080 DrawRenderPassDrawQuadParams* params) {
1072 params->quad_to_target_transform = 1081 params->quad_to_target_transform =
1073 params->quad->shared_quad_state->quad_to_target_transform; 1082 params->quad->shared_quad_state->quad_to_target_transform;
1074 if (!InitializeRPDQParameters(params)) 1083 if (!InitializeRPDQParameters(params))
1075 return; 1084 return false;
1076 UpdateRPDQShadersForBlending(params); 1085 UpdateRPDQShadersForBlending(params);
1077 if (!UpdateRPDQWithSkiaFilters(params)) 1086 if (!UpdateRPDQWithSkiaFilters(params))
1078 return; 1087 return false;
1079 UseRenderPass(current_frame()->current_render_pass); 1088 UseRenderPass(current_frame()->current_render_pass);
1080 SetViewport(); 1089 SetViewport();
1081 UpdateRPDQTexturesForSampling(params); 1090 UpdateRPDQTexturesForSampling(params);
1082 UpdateRPDQBlendMode(params); 1091 UpdateRPDQBlendMode(params);
1083 ChooseRPDQProgram(params); 1092 ChooseRPDQProgram(params);
1084 UpdateRPDQUniforms(params); 1093 UpdateRPDQUniforms(params);
1085 DrawRPDQ(*params); 1094 DrawRPDQ(*params);
1095 return true;
1086 } 1096 }
1087 1097
1088 bool GLRenderer::InitializeRPDQParameters( 1098 bool GLRenderer::InitializeRPDQParameters(
1089 DrawRenderPassDrawQuadParams* params) { 1099 DrawRenderPassDrawQuadParams* params) {
1090 const RenderPassDrawQuad* quad = params->quad; 1100 const RenderPassDrawQuad* quad = params->quad;
1091 SkMatrix local_matrix; 1101 SkMatrix local_matrix;
1092 local_matrix.setTranslate(quad->filters_origin.x(), quad->filters_origin.y()); 1102 local_matrix.setTranslate(quad->filters_origin.x(), quad->filters_origin.y());
1093 local_matrix.postScale(quad->filters_scale.x(), quad->filters_scale.y()); 1103 local_matrix.postScale(quad->filters_scale.x(), quad->filters_scale.y());
1094 params->filters = FiltersForPass(quad->render_pass_id); 1104 params->filters = FiltersForPass(quad->render_pass_id);
1095 params->background_filters = BackgroundFiltersForPass(quad->render_pass_id); 1105 params->background_filters = BackgroundFiltersForPass(quad->render_pass_id);
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 device_quad = GetDeviceQuadWithAntialiasingOnExteriorEdges( 1727 device_quad = GetDeviceQuadWithAntialiasingOnExteriorEdges(
1718 device_layer_edges, device_transform, tile_quad, local_clip_region, 1728 device_layer_edges, device_transform, tile_quad, local_clip_region,
1719 quad); 1729 quad);
1720 } else { 1730 } else {
1721 device_quad = device_layer_edges.ToQuadF(); 1731 device_quad = device_layer_edges.ToQuadF();
1722 } 1732 }
1723 1733
1724 *local_quad = MapQuadToLocalSpace(device_transform, device_quad); 1734 *local_quad = MapQuadToLocalSpace(device_transform, device_quad);
1725 } 1735 }
1726 1736
1727 void GLRenderer::DrawSolidColorQuad(const SolidColorDrawQuad* quad, 1737 bool GLRenderer::DrawSolidColorQuad(const SolidColorDrawQuad* quad,
1728 const gfx::QuadF* clip_region) { 1738 const gfx::QuadF* clip_region) {
1729 gfx::Rect tile_rect = quad->visible_rect; 1739 gfx::Rect tile_rect = quad->visible_rect;
1730 1740
1731 SkColor color = quad->color; 1741 SkColor color = quad->color;
1732 float opacity = quad->shared_quad_state->opacity; 1742 float opacity = quad->shared_quad_state->opacity;
1733 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; 1743 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity;
1734 1744
1735 // Early out if alpha is small enough that quad doesn't contribute to output. 1745 // Early out if alpha is small enough that quad doesn't contribute to output.
1736 if (alpha < std::numeric_limits<float>::epsilon() && 1746 if (alpha < std::numeric_limits<float>::epsilon() &&
1737 quad->ShouldDrawWithBlending()) 1747 quad->ShouldDrawWithBlending())
1738 return; 1748 return false;
1739 1749
1740 gfx::Transform device_transform = 1750 gfx::Transform device_transform =
1741 current_frame()->window_matrix * current_frame()->projection_matrix * 1751 current_frame()->window_matrix * current_frame()->projection_matrix *
1742 quad->shared_quad_state->quad_to_target_transform; 1752 quad->shared_quad_state->quad_to_target_transform;
1743 device_transform.FlattenTo2d(); 1753 device_transform.FlattenTo2d();
1744 if (!device_transform.IsInvertible()) 1754 if (!device_transform.IsInvertible())
1745 return; 1755 return false;
1746 1756
1747 auto local_quad = gfx::QuadF(gfx::RectF(tile_rect)); 1757 auto local_quad = gfx::QuadF(gfx::RectF(tile_rect));
1748 1758
1749 gfx::QuadF device_layer_quad; 1759 gfx::QuadF device_layer_quad;
1750 bool use_aa = false; 1760 bool use_aa = false;
1751 bool allow_aa = settings_->allow_antialiasing && 1761 bool allow_aa = settings_->allow_antialiasing &&
1752 !quad->force_anti_aliasing_off && quad->IsEdge(); 1762 !quad->force_anti_aliasing_off && quad->IsEdge();
1753 1763
1754 if (allow_aa) { 1764 if (allow_aa) {
1755 bool clipped = false; 1765 bool clipped = false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 DrawQuadGeometry(current_frame()->projection_matrix, 1811 DrawQuadGeometry(current_frame()->projection_matrix,
1802 quad->shared_quad_state->quad_to_target_transform, 1812 quad->shared_quad_state->quad_to_target_transform,
1803 centered_rect); 1813 centered_rect);
1804 } else { 1814 } else {
1805 PrepareGeometry(SHARED_BINDING); 1815 PrepareGeometry(SHARED_BINDING);
1806 SetShaderQuadF(local_quad); 1816 SetShaderQuadF(local_quad);
1807 SetShaderMatrix(current_frame()->projection_matrix * 1817 SetShaderMatrix(current_frame()->projection_matrix *
1808 quad->shared_quad_state->quad_to_target_transform); 1818 quad->shared_quad_state->quad_to_target_transform);
1809 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); 1819 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
1810 } 1820 }
1821 return true;
1811 } 1822 }
1812 1823
1813 void GLRenderer::DrawTileQuad(const TileDrawQuad* quad, 1824 bool GLRenderer::DrawTileQuad(const TileDrawQuad* quad,
1814 const gfx::QuadF* clip_region) { 1825 const gfx::QuadF* clip_region) {
1815 DrawContentQuad(quad, quad->resource_id(), clip_region); 1826 return DrawContentQuad(quad, quad->resource_id(), clip_region);
1816 } 1827 }
1817 1828
1818 void GLRenderer::DrawContentQuad(const ContentDrawQuadBase* quad, 1829 bool GLRenderer::DrawContentQuad(const ContentDrawQuadBase* quad,
1819 ResourceId resource_id, 1830 ResourceId resource_id,
1820 const gfx::QuadF* clip_region) { 1831 const gfx::QuadF* clip_region) {
1821 gfx::Transform device_transform = 1832 gfx::Transform device_transform =
1822 current_frame()->window_matrix * current_frame()->projection_matrix * 1833 current_frame()->window_matrix * current_frame()->projection_matrix *
1823 quad->shared_quad_state->quad_to_target_transform; 1834 quad->shared_quad_state->quad_to_target_transform;
1824 device_transform.FlattenTo2d(); 1835 device_transform.FlattenTo2d();
1825 1836
1826 gfx::QuadF device_layer_quad; 1837 gfx::QuadF device_layer_quad;
1827 bool use_aa = false; 1838 bool use_aa = false;
1828 bool allow_aa = settings_->allow_antialiasing && quad->IsEdge(); 1839 bool allow_aa = settings_->allow_antialiasing && quad->IsEdge();
1829 if (allow_aa) { 1840 if (allow_aa) {
1830 bool clipped = false; 1841 bool clipped = false;
1831 bool force_aa = false; 1842 bool force_aa = false;
1832 device_layer_quad = MathUtil::MapQuad( 1843 device_layer_quad = MathUtil::MapQuad(
1833 device_transform, 1844 device_transform,
1834 gfx::QuadF( 1845 gfx::QuadF(
1835 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), 1846 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)),
1836 &clipped); 1847 &clipped);
1837 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); 1848 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa);
1838 } 1849 }
1839 1850
1840 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA 1851 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA
1841 // similar to the way DrawContentQuadNoAA works and then consider 1852 // similar to the way DrawContentQuadNoAA works and then consider
1842 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. 1853 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method.
1843 if (use_aa) 1854 if (use_aa)
1844 DrawContentQuadAA(quad, resource_id, device_transform, device_layer_quad, 1855 return DrawContentQuadAA(quad, resource_id, device_transform,
1845 clip_region); 1856 device_layer_quad, clip_region);
1846 else 1857 return DrawContentQuadNoAA(quad, resource_id, clip_region);
1847 DrawContentQuadNoAA(quad, resource_id, clip_region);
1848 } 1858 }
1849 1859
1850 void GLRenderer::DrawContentQuadAA(const ContentDrawQuadBase* quad, 1860 bool GLRenderer::DrawContentQuadAA(const ContentDrawQuadBase* quad,
1851 ResourceId resource_id, 1861 ResourceId resource_id,
1852 const gfx::Transform& device_transform, 1862 const gfx::Transform& device_transform,
1853 const gfx::QuadF& aa_quad, 1863 const gfx::QuadF& aa_quad,
1854 const gfx::QuadF* clip_region) { 1864 const gfx::QuadF* clip_region) {
1855 if (!device_transform.IsInvertible()) 1865 if (!device_transform.IsInvertible())
1856 return; 1866 return false;
1857 1867
1858 gfx::Rect tile_rect = quad->visible_rect; 1868 gfx::Rect tile_rect = quad->visible_rect;
1859 1869
1860 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( 1870 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional(
1861 quad->tex_coord_rect, gfx::RectF(quad->rect), gfx::RectF(tile_rect)); 1871 quad->tex_coord_rect, gfx::RectF(quad->rect), gfx::RectF(tile_rect));
1862 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); 1872 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width();
1863 float tex_to_geom_scale_y = 1873 float tex_to_geom_scale_y =
1864 quad->rect.height() / quad->tex_coord_rect.height(); 1874 quad->rect.height() / quad->tex_coord_rect.height();
1865 1875
1866 gfx::RectF clamp_geom_rect(tile_rect); 1876 gfx::RectF clamp_geom_rect(tile_rect);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 // The transform and vertex data are used to figure out the extents that the 1956 // The transform and vertex data are used to figure out the extents that the
1947 // un-antialiased quad should have and which vertex this is and the float 1957 // un-antialiased quad should have and which vertex this is and the float
1948 // quad passed in via uniform is the actual geometry that gets used to draw 1958 // quad passed in via uniform is the actual geometry that gets used to draw
1949 // it. This is why this centered rect is used and not the original quad_rect. 1959 // it. This is why this centered rect is used and not the original quad_rect.
1950 gfx::RectF centered_rect( 1960 gfx::RectF centered_rect(
1951 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), 1961 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()),
1952 gfx::SizeF(tile_rect.size())); 1962 gfx::SizeF(tile_rect.size()));
1953 DrawQuadGeometry(current_frame()->projection_matrix, 1963 DrawQuadGeometry(current_frame()->projection_matrix,
1954 quad->shared_quad_state->quad_to_target_transform, 1964 quad->shared_quad_state->quad_to_target_transform,
1955 centered_rect); 1965 centered_rect);
1966 return true;
1956 } 1967 }
1957 1968
1958 void GLRenderer::DrawContentQuadNoAA(const ContentDrawQuadBase* quad, 1969 bool GLRenderer::DrawContentQuadNoAA(const ContentDrawQuadBase* quad,
1959 ResourceId resource_id, 1970 ResourceId resource_id,
1960 const gfx::QuadF* clip_region) { 1971 const gfx::QuadF* clip_region) {
1961 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( 1972 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional(
1962 quad->tex_coord_rect, gfx::RectF(quad->rect), 1973 quad->tex_coord_rect, gfx::RectF(quad->rect),
1963 gfx::RectF(quad->visible_rect)); 1974 gfx::RectF(quad->visible_rect));
1964 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); 1975 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width();
1965 float tex_to_geom_scale_y = 1976 float tex_to_geom_scale_y =
1966 quad->rect.height() / quad->tex_coord_rect.height(); 1977 quad->rect.height() / quad->tex_coord_rect.height();
1967 1978
1968 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); 1979 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(), 2052 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(),
2042 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(), 2053 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(),
2043 tile_quad.p3().x(), tile_quad.p3().y(), 2054 tile_quad.p3().x(), tile_quad.p3().y(),
2044 }; 2055 };
2045 gl_->Uniform2fv(current_program_->quad_location(), 4, gl_quad); 2056 gl_->Uniform2fv(current_program_->quad_location(), 4, gl_quad);
2046 2057
2047 SetShaderMatrix(current_frame()->projection_matrix * 2058 SetShaderMatrix(current_frame()->projection_matrix *
2048 quad->shared_quad_state->quad_to_target_transform); 2059 quad->shared_quad_state->quad_to_target_transform);
2049 2060
2050 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); 2061 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
2062 return true;
2051 } 2063 }
2052 2064
2053 void GLRenderer::DrawYUVVideoQuad(const YUVVideoDrawQuad* quad, 2065 bool GLRenderer::DrawYUVVideoQuad(const YUVVideoDrawQuad* quad,
2054 const gfx::QuadF* clip_region) { 2066 const gfx::QuadF* clip_region) {
2055 SetBlendEnabled(quad->ShouldDrawWithBlending()); 2067 SetBlendEnabled(quad->ShouldDrawWithBlending());
2056 2068
2057 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2069 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2058 gl_, &highp_threshold_cache_, settings_->highp_threshold_min, 2070 gl_, &highp_threshold_cache_, settings_->highp_threshold_min,
2059 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); 2071 quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
2060 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() 2072 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id()
2061 ? YUV_HAS_ALPHA_TEXTURE 2073 ? YUV_HAS_ALPHA_TEXTURE
2062 : YUV_NO_ALPHA_TEXTURE; 2074 : YUV_NO_ALPHA_TEXTURE;
2063 UVTextureMode uv_texture_mode = 2075 UVTextureMode uv_texture_mode =
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 } else { 2220 } else {
2209 float uvs[8] = {0}; 2221 float uvs[8] = {0};
2210 GetScaledUVs(quad->visible_rect, clip_region, uvs); 2222 GetScaledUVs(quad->visible_rect, clip_region, uvs);
2211 gfx::QuadF region_quad = *clip_region; 2223 gfx::QuadF region_quad = *clip_region;
2212 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); 2224 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
2213 region_quad -= gfx::Vector2dF(0.5f, 0.5f); 2225 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2214 DrawQuadGeometryClippedByQuadF( 2226 DrawQuadGeometryClippedByQuadF(
2215 quad->shared_quad_state->quad_to_target_transform, tile_rect, 2227 quad->shared_quad_state->quad_to_target_transform, tile_rect,
2216 region_quad, uvs); 2228 region_quad, uvs);
2217 } 2229 }
2230 return true;
2218 } 2231 }
2219 2232
2220 void GLRenderer::DrawStreamVideoQuad(const StreamVideoDrawQuad* quad, 2233 bool GLRenderer::DrawStreamVideoQuad(const StreamVideoDrawQuad* quad,
2221 const gfx::QuadF* clip_region) { 2234 const gfx::QuadF* clip_region) {
2222 SetBlendEnabled(quad->ShouldDrawWithBlending()); 2235 SetBlendEnabled(quad->ShouldDrawWithBlending());
2223 2236
2224 DCHECK(output_surface_->context_provider() 2237 DCHECK(output_surface_->context_provider()
2225 ->ContextCapabilities() 2238 ->ContextCapabilities()
2226 .egl_image_external); 2239 .egl_image_external);
2227 2240
2228 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2241 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2229 gl_, &highp_threshold_cache_, settings_->highp_threshold_min, 2242 gl_, &highp_threshold_cache_, settings_->highp_threshold_min,
2230 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); 2243 quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
(...skipping 20 matching lines...) Expand all
2251 } else { 2264 } else {
2252 gfx::QuadF region_quad(*clip_region); 2265 gfx::QuadF region_quad(*clip_region);
2253 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); 2266 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height());
2254 region_quad -= gfx::Vector2dF(0.5f, 0.5f); 2267 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2255 float uvs[8] = {0}; 2268 float uvs[8] = {0};
2256 GetScaledUVs(quad->visible_rect, clip_region, uvs); 2269 GetScaledUVs(quad->visible_rect, clip_region, uvs);
2257 DrawQuadGeometryClippedByQuadF( 2270 DrawQuadGeometryClippedByQuadF(
2258 quad->shared_quad_state->quad_to_target_transform, 2271 quad->shared_quad_state->quad_to_target_transform,
2259 gfx::RectF(quad->rect), region_quad, uvs); 2272 gfx::RectF(quad->rect), region_quad, uvs);
2260 } 2273 }
2274 return true;
2261 } 2275 }
2262 2276
2263 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { 2277 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) {
2264 // Check to see if we have anything to draw. 2278 // Check to see if we have anything to draw.
2265 if (draw_cache_.is_empty) 2279 if (draw_cache_.is_empty)
2266 return; 2280 return;
2267 2281
2268 PrepareGeometry(flush_binding); 2282 PrepareGeometry(flush_binding);
2269 2283
2270 // Set the correct blending mode. 2284 // Set the correct blending mode.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 draw_cache_.vertex_opacity_data.resize(0); 2359 draw_cache_.vertex_opacity_data.resize(0);
2346 draw_cache_.matrix_data.resize(0); 2360 draw_cache_.matrix_data.resize(0);
2347 2361
2348 // If we had a clipped binding, prepare the shared binding for the 2362 // If we had a clipped binding, prepare the shared binding for the
2349 // next inserts. 2363 // next inserts.
2350 if (flush_binding == CLIPPED_BINDING) { 2364 if (flush_binding == CLIPPED_BINDING) {
2351 PrepareGeometry(SHARED_BINDING); 2365 PrepareGeometry(SHARED_BINDING);
2352 } 2366 }
2353 } 2367 }
2354 2368
2355 void GLRenderer::EnqueueTextureQuad(const TextureDrawQuad* quad, 2369 bool GLRenderer::EnqueueTextureQuad(const TextureDrawQuad* quad,
2356 const gfx::QuadF* clip_region) { 2370 const gfx::QuadF* clip_region) {
2357 // If we have a clip_region then we have to render the next quad 2371 // If we have a clip_region then we have to render the next quad
2358 // with dynamic geometry, therefore we must flush all pending 2372 // with dynamic geometry, therefore we must flush all pending
2359 // texture quads. 2373 // texture quads.
2360 if (clip_region) { 2374 if (clip_region) {
2361 // We send in false here because we want to flush what's currently in the 2375 // We send in false here because we want to flush what's currently in the
2362 // queue using the shared_geometry and not clipped_geometry 2376 // queue using the shared_geometry and not clipped_geometry
2363 FlushTextureQuadCache(SHARED_BINDING); 2377 FlushTextureQuadCache(SHARED_BINDING);
2364 } 2378 }
2365 2379
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2436 uv[0] = scaled_region.p1().x() + 0.5f; 2450 uv[0] = scaled_region.p1().x() + 0.5f;
2437 uv[1] = scaled_region.p1().y() + 0.5f; 2451 uv[1] = scaled_region.p1().y() + 0.5f;
2438 uv[2] = scaled_region.p2().x() + 0.5f; 2452 uv[2] = scaled_region.p2().x() + 0.5f;
2439 uv[3] = scaled_region.p2().y() + 0.5f; 2453 uv[3] = scaled_region.p2().y() + 0.5f;
2440 uv[4] = scaled_region.p3().x() + 0.5f; 2454 uv[4] = scaled_region.p3().x() + 0.5f;
2441 uv[5] = scaled_region.p3().y() + 0.5f; 2455 uv[5] = scaled_region.p3().y() + 0.5f;
2442 uv[6] = scaled_region.p4().x() + 0.5f; 2456 uv[6] = scaled_region.p4().x() + 0.5f;
2443 uv[7] = scaled_region.p4().y() + 0.5f; 2457 uv[7] = scaled_region.p4().y() + 0.5f;
2444 PrepareGeometry(CLIPPED_BINDING); 2458 PrepareGeometry(CLIPPED_BINDING);
2445 clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv); 2459 clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv);
2460 if (draw_cache_.is_empty)
2461 return false;
2446 FlushTextureQuadCache(CLIPPED_BINDING); 2462 FlushTextureQuadCache(CLIPPED_BINDING);
2447 } else if (gl_composited_texture_quad_border_) { 2463 } else if (gl_composited_texture_quad_border_) {
2464 if (draw_cache_.is_empty)
2465 return false;
2448 FlushTextureQuadCache(SHARED_BINDING); 2466 FlushTextureQuadCache(SHARED_BINDING);
2467 } else {
2468 return false;
2449 } 2469 }
2470 return true;
2450 } 2471 }
2451 2472
2452 void GLRenderer::FinishDrawingFrame() { 2473 void GLRenderer::FinishDrawingFrame() {
2453 if (use_sync_query_) { 2474 if (use_sync_query_) {
2454 DCHECK(current_sync_query_); 2475 DCHECK(current_sync_query_);
2455 current_sync_query_->End(); 2476 current_sync_query_->End();
2456 pending_sync_queries_.push_back(std::move(current_sync_query_)); 2477 pending_sync_queries_.push_back(std::move(current_sync_query_));
2457 } 2478 }
2458 2479
2459 swap_buffer_rect_.Union(current_frame()->root_damage_rect); 2480 swap_buffer_rect_.Union(current_frame()->root_damage_rect);
2460 if (overdraw_feedback_) 2481 if (overdraw_feedback_)
2461 FlushOverdrawFeedback(swap_buffer_rect_); 2482 FlushOverdrawFeedback(swap_buffer_rect_);
2462 2483
2463 if (use_swap_with_bounds_) 2484 if (use_swap_with_bounds_)
2464 swap_content_bounds_ = current_frame()->root_content_bounds; 2485 swap_content_bounds_ = current_frame()->root_content_bounds;
2465 2486
2466 current_framebuffer_lock_ = nullptr; 2487 current_framebuffer_lock_ = nullptr;
2467 2488
2468 gl_->Disable(GL_BLEND); 2489 gl_->Disable(GL_BLEND);
2469 blend_shadow_ = false; 2490 blend_shadow_ = false;
2470 2491
2471 ScheduleCALayers(); 2492 ScheduleCALayers();
2472 ScheduleDCLayers(); 2493 ScheduleDCLayers();
2473 ScheduleOverlays(); 2494 ScheduleOverlays();
2474 } 2495 }
2475 2496
2476 void GLRenderer::FinishDrawingQuadList() { 2497 void GLRenderer::FinishDrawingQuadList() {
2477 FlushTextureQuadCache(SHARED_BINDING); 2498 FlushTextureQuadCache(SHARED_BINDING);
2499 size_t area_total = surface_size_for_swap_buffers().GetArea();
2500 if (area_total) {
2501 LOG(ERROR) << "Total drawn: " << area_drawn_ << " vs. " << area_total
2502 << " = " << static_cast<float>(area_drawn_) / area_total;
2503 }
2504 area_drawn_ = 0;
2478 } 2505 }
2479 2506
2480 void GLRenderer::SetEnableDCLayers(bool enable) { 2507 void GLRenderer::SetEnableDCLayers(bool enable) {
2481 gl_->SetEnableDCLayersCHROMIUM(enable); 2508 gl_->SetEnableDCLayersCHROMIUM(enable);
2482 } 2509 }
2483 2510
2484 bool GLRenderer::FlippedFramebuffer() const { 2511 bool GLRenderer::FlippedFramebuffer() const {
2485 if (force_drawing_frame_framebuffer_unflipped_) 2512 if (force_drawing_frame_framebuffer_unflipped_)
2486 return false; 2513 return false;
2487 if (current_frame()->current_render_pass != current_frame()->root_render_pass) 2514 if (current_frame()->current_render_pass != current_frame()->root_render_pass)
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 return; 3638 return;
3612 3639
3613 // Report GPU overdraw as a percentage of |max_result|. 3640 // Report GPU overdraw as a percentage of |max_result|.
3614 TRACE_COUNTER1( 3641 TRACE_COUNTER1(
3615 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", 3642 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw",
3616 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / 3643 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) /
3617 max_result); 3644 max_result);
3618 } 3645 }
3619 3646
3620 } // namespace cc 3647 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698