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

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

Issue 14705008: cc: Cache highp_threshold in TexCoordPrecisionRequired (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use local cache rather than global cache to avoid thread hazards. Created 7 years, 7 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
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 <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)), 108 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)),
109 output_surface_(output_surface), 109 output_surface_(output_surface),
110 context_(output_surface->context3d()), 110 context_(output_surface->context3d()),
111 is_viewport_changed_(false), 111 is_viewport_changed_(false),
112 is_backbuffer_discarded_(false), 112 is_backbuffer_discarded_(false),
113 discard_backbuffer_when_not_visible_(false), 113 discard_backbuffer_when_not_visible_(false),
114 is_using_bind_uniform_(false), 114 is_using_bind_uniform_(false),
115 visible_(true), 115 visible_(true),
116 is_scissor_enabled_(false), 116 is_scissor_enabled_(false),
117 highp_threshold_min_(highp_threshold_min), 117 highp_threshold_min_(highp_threshold_min),
118 highp_threshold_cache_(0),
118 on_demand_tile_raster_resource_id_(0) { 119 on_demand_tile_raster_resource_id_(0) {
119 DCHECK(context_); 120 DCHECK(context_);
120 } 121 }
121 122
122 bool GLRenderer::Initialize() { 123 bool GLRenderer::Initialize() {
123 if (!context_->makeContextCurrent()) 124 if (!context_->makeContextCurrent())
124 return false; 125 return false;
125 126
126 context_->pushGroupMarkerEXT("CompositorContext"); 127 context_->pushGroupMarkerEXT("CompositorContext");
127 128
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 Context()->bindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); 745 Context()->bindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
745 } else { 746 } else {
746 contents_resource_lock = make_scoped_ptr( 747 contents_resource_lock = make_scoped_ptr(
747 new ResourceProvider::ScopedSamplerGL(resource_provider_, 748 new ResourceProvider::ScopedSamplerGL(resource_provider_,
748 contents_texture->id(), 749 contents_texture->id(),
749 GL_TEXTURE_2D, 750 GL_TEXTURE_2D,
750 GL_LINEAR)); 751 GL_LINEAR));
751 } 752 }
752 753
753 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 754 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
754 context_, highp_threshold_min_, 755 context_, &highp_threshold_cache_, highp_threshold_min_,
755 quad->shared_quad_state->visible_content_rect.bottom_right()); 756 quad->shared_quad_state->visible_content_rect.bottom_right());
756 757
757 int shader_quad_location = -1; 758 int shader_quad_location = -1;
758 int shader_edge_location = -1; 759 int shader_edge_location = -1;
759 int shader_mask_sampler_location = -1; 760 int shader_mask_sampler_location = -1;
760 int shader_mask_tex_coord_scale_location = -1; 761 int shader_mask_tex_coord_scale_location = -1;
761 int shader_mask_tex_coord_offset_location = -1; 762 int shader_mask_tex_coord_offset_location = -1;
762 int shader_matrix_location = -1; 763 int shader_matrix_location = -1;
763 int shader_alpha_location = -1; 764 int shader_alpha_location = -1;
764 int shader_color_matrix_location = -1; 765 int shader_color_matrix_location = -1;
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 clamp_tex_rect.Inset(tex_clamp_x, tex_clamp_y, tex_clamp_x, tex_clamp_y); 1220 clamp_tex_rect.Inset(tex_clamp_x, tex_clamp_y, tex_clamp_x, tex_clamp_y);
1220 1221
1221 // Map clamping rectangle to unit square. 1222 // Map clamping rectangle to unit square.
1222 float vertex_tex_translate_x = -clamp_geom_rect.x() / clamp_geom_rect.width(); 1223 float vertex_tex_translate_x = -clamp_geom_rect.x() / clamp_geom_rect.width();
1223 float vertex_tex_translate_y = 1224 float vertex_tex_translate_y =
1224 -clamp_geom_rect.y() / clamp_geom_rect.height(); 1225 -clamp_geom_rect.y() / clamp_geom_rect.height();
1225 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); 1226 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width();
1226 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); 1227 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height();
1227 1228
1228 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1229 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1229 context_, highp_threshold_min_, quad->texture_size); 1230 context_, &highp_threshold_cache_, highp_threshold_min_,
1231 quad->texture_size);
1230 1232
1231 // Map to normalized texture coordinates. 1233 // Map to normalized texture coordinates.
1232 gfx::Size texture_size = quad->texture_size; 1234 gfx::Size texture_size = quad->texture_size;
1233 float fragment_tex_translate_x = clamp_tex_rect.x() / texture_size.width(); 1235 float fragment_tex_translate_x = clamp_tex_rect.x() / texture_size.width();
1234 float fragment_tex_translate_y = clamp_tex_rect.y() / texture_size.height(); 1236 float fragment_tex_translate_y = clamp_tex_rect.y() / texture_size.height();
1235 float fragment_tex_scale_x = clamp_tex_rect.width() / texture_size.width(); 1237 float fragment_tex_scale_x = clamp_tex_rect.width() / texture_size.width();
1236 float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height(); 1238 float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height();
1237 1239
1238 gfx::Transform device_transform = 1240 gfx::Transform device_transform =
1239 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); 1241 frame->window_matrix * frame->projection_matrix * quad->quadTransform();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 tile_rect.size()); 1339 tile_rect.size());
1338 DrawQuadGeometry( 1340 DrawQuadGeometry(
1339 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); 1341 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location);
1340 } 1342 }
1341 1343
1342 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, 1344 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame,
1343 const YUVVideoDrawQuad* quad) { 1345 const YUVVideoDrawQuad* quad) {
1344 SetBlendEnabled(quad->ShouldDrawWithBlending()); 1346 SetBlendEnabled(quad->ShouldDrawWithBlending());
1345 1347
1346 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1348 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1347 context_, highp_threshold_min_, 1349 context_, &highp_threshold_cache_, highp_threshold_min_,
1348 quad->shared_quad_state->visible_content_rect.bottom_right()); 1350 quad->shared_quad_state->visible_content_rect.bottom_right());
1349 1351
1350 const VideoYUVProgram* program = GetVideoYUVProgram(tex_coord_precision); 1352 const VideoYUVProgram* program = GetVideoYUVProgram(tex_coord_precision);
1351 DCHECK(program && (program->initialized() || IsContextLost())); 1353 DCHECK(program && (program->initialized() || IsContextLost()));
1352 1354
1353 GLC(Context(), Context()->activeTexture(GL_TEXTURE1)); 1355 GLC(Context(), Context()->activeTexture(GL_TEXTURE1));
1354 ResourceProvider::ScopedSamplerGL y_plane_lock( 1356 ResourceProvider::ScopedSamplerGL y_plane_lock(
1355 resource_provider_, quad->y_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR); 1357 resource_provider_, quad->y_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR);
1356 GLC(Context(), Context()->activeTexture(GL_TEXTURE2)); 1358 GLC(Context(), Context()->activeTexture(GL_TEXTURE2));
1357 ResourceProvider::ScopedSamplerGL u_plane_lock( 1359 ResourceProvider::ScopedSamplerGL u_plane_lock(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1411
1410 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, 1412 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame,
1411 const StreamVideoDrawQuad* quad) { 1413 const StreamVideoDrawQuad* quad) {
1412 SetBlendEnabled(quad->ShouldDrawWithBlending()); 1414 SetBlendEnabled(quad->ShouldDrawWithBlending());
1413 1415
1414 static float gl_matrix[16]; 1416 static float gl_matrix[16];
1415 1417
1416 DCHECK(capabilities_.using_egl_image); 1418 DCHECK(capabilities_.using_egl_image);
1417 1419
1418 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1420 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1419 context_, highp_threshold_min_, 1421 context_, &highp_threshold_cache_, highp_threshold_min_,
1420 quad->shared_quad_state->visible_content_rect.bottom_right()); 1422 quad->shared_quad_state->visible_content_rect.bottom_right());
1421 1423
1422 const VideoStreamTextureProgram* program = 1424 const VideoStreamTextureProgram* program =
1423 GetVideoStreamTextureProgram(tex_coord_precision); 1425 GetVideoStreamTextureProgram(tex_coord_precision);
1424 SetUseProgram(program->program()); 1426 SetUseProgram(program->program());
1425 1427
1426 ToGLMatrix(&gl_matrix[0], quad->matrix); 1428 ToGLMatrix(&gl_matrix[0], quad->matrix);
1427 GLC(Context(), 1429 GLC(Context(),
1428 Context()->uniformMatrix4fv( 1430 Context()->uniformMatrix4fv(
1429 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); 1431 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 // Clear the cache. 1585 // Clear the cache.
1584 draw_cache_.program_id = 0; 1586 draw_cache_.program_id = 0;
1585 draw_cache_.uv_xform_data.resize(0); 1587 draw_cache_.uv_xform_data.resize(0);
1586 draw_cache_.vertex_opacity_data.resize(0); 1588 draw_cache_.vertex_opacity_data.resize(0);
1587 draw_cache_.matrix_data.resize(0); 1589 draw_cache_.matrix_data.resize(0);
1588 } 1590 }
1589 1591
1590 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, 1592 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame,
1591 const TextureDrawQuad* quad) { 1593 const TextureDrawQuad* quad) {
1592 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1594 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1593 context_, highp_threshold_min_, 1595 context_, &highp_threshold_cache_, highp_threshold_min_,
1594 quad->shared_quad_state->visible_content_rect.bottom_right()); 1596 quad->shared_quad_state->visible_content_rect.bottom_right());
1595 1597
1596 // Choose the correct texture program binding 1598 // Choose the correct texture program binding
1597 TexTransformTextureProgramBinding binding; 1599 TexTransformTextureProgramBinding binding;
1598 if (quad->flipped) 1600 if (quad->flipped)
1599 binding.Set(GetTextureProgramFlip(tex_coord_precision), Context()); 1601 binding.Set(GetTextureProgramFlip(tex_coord_precision), Context());
1600 else 1602 else
1601 binding.Set(GetTextureProgram(tex_coord_precision), Context()); 1603 binding.Set(GetTextureProgram(tex_coord_precision), Context());
1602 1604
1603 int resource_id = quad->resource_id; 1605 int resource_id = quad->resource_id;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; 1640 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix;
1639 1641
1640 Float16 m; 1642 Float16 m;
1641 quad_rect_matrix.matrix().asColMajorf(m.data); 1643 quad_rect_matrix.matrix().asColMajorf(m.data);
1642 draw_cache_.matrix_data.push_back(m); 1644 draw_cache_.matrix_data.push_back(m);
1643 } 1645 }
1644 1646
1645 void GLRenderer::DrawTextureQuad(const DrawingFrame* frame, 1647 void GLRenderer::DrawTextureQuad(const DrawingFrame* frame,
1646 const TextureDrawQuad* quad) { 1648 const TextureDrawQuad* quad) {
1647 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1649 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1648 context_, highp_threshold_min_, 1650 context_, &highp_threshold_cache_, highp_threshold_min_,
1649 quad->shared_quad_state->visible_content_rect.bottom_right()); 1651 quad->shared_quad_state->visible_content_rect.bottom_right());
1650 1652
1651 TexTransformTextureProgramBinding binding; 1653 TexTransformTextureProgramBinding binding;
1652 if (quad->flipped) 1654 if (quad->flipped)
1653 binding.Set(GetTextureProgramFlip(tex_coord_precision), Context()); 1655 binding.Set(GetTextureProgramFlip(tex_coord_precision), Context());
1654 else 1656 else
1655 binding.Set(GetTextureProgram(tex_coord_precision), Context()); 1657 binding.Set(GetTextureProgram(tex_coord_precision), Context());
1656 SetUseProgram(binding.program_id); 1658 SetUseProgram(binding.program_id);
1657 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); 1659 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0));
1658 gfx::PointF uv0 = quad->uv_top_left; 1660 gfx::PointF uv0 = quad->uv_top_left;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 1694
1693 if (!quad->premultiplied_alpha) 1695 if (!quad->premultiplied_alpha)
1694 GLC(context_, context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); 1696 GLC(context_, context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
1695 } 1697 }
1696 1698
1697 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, 1699 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame,
1698 const IOSurfaceDrawQuad* quad) { 1700 const IOSurfaceDrawQuad* quad) {
1699 SetBlendEnabled(quad->ShouldDrawWithBlending()); 1701 SetBlendEnabled(quad->ShouldDrawWithBlending());
1700 1702
1701 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1703 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1702 context_, highp_threshold_min_, 1704 context_, &highp_threshold_cache_, highp_threshold_min_,
1703 quad->shared_quad_state->visible_content_rect.bottom_right()); 1705 quad->shared_quad_state->visible_content_rect.bottom_right());
1704 1706
1705 TexTransformTextureProgramBinding binding; 1707 TexTransformTextureProgramBinding binding;
1706 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision), Context()); 1708 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision), Context());
1707 1709
1708 SetUseProgram(binding.program_id); 1710 SetUseProgram(binding.program_id);
1709 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); 1711 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0));
1710 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) { 1712 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) {
1711 GLC(Context(), 1713 GLC(Context(),
1712 Context()->uniform4f(binding.tex_transform_location, 1714 Context()->uniform4f(binding.tex_transform_location,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 context_->uniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); 1847 context_->uniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0]));
1846 1848
1847 GLC(context_, context_->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); 1849 GLC(context_, context_->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0));
1848 } 1850 }
1849 1851
1850 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame, 1852 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame,
1851 int texture_id, 1853 int texture_id,
1852 gfx::Rect rect, 1854 gfx::Rect rect,
1853 const gfx::Transform& draw_matrix) { 1855 const gfx::Transform& draw_matrix) {
1854 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1856 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1855 context_, highp_threshold_min_, rect.bottom_right()); 1857 context_, &highp_threshold_cache_, highp_threshold_min_,
1858 rect.bottom_right());
1856 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision); 1859 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision);
1857 1860
1858 GLC(Context(), Context()->bindTexture(GL_TEXTURE_2D, texture_id)); 1861 GLC(Context(), Context()->bindTexture(GL_TEXTURE_2D, texture_id));
1859 1862
1860 SetUseProgram(program->program()); 1863 SetUseProgram(program->program());
1861 GLC(Context(), 1864 GLC(Context(),
1862 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); 1865 Context()->uniform1i(program->fragment_shader().sampler_location(), 0));
1863 GLC(Context(), 1866 GLC(Context(),
1864 Context()->uniform4f(program->vertex_shader().tex_transform_location(), 1867 Context()->uniform4f(program->vertex_shader().tex_transform_location(),
1865 0.0f, 1868 0.0f,
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); 2638 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_);
2636 2639
2637 ReleaseRenderPassTextures(); 2640 ReleaseRenderPassTextures();
2638 } 2641 }
2639 2642
2640 bool GLRenderer::IsContextLost() { 2643 bool GLRenderer::IsContextLost() {
2641 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); 2644 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR);
2642 } 2645 }
2643 2646
2644 } // namespace cc 2647 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/shader.h » ('j') | cc/output/shader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698