| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 mask_texture_id = mask_resource_lock->texture_id(); | 1059 mask_texture_id = mask_resource_lock->texture_id(); |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 // TODO(danakj): use the background_texture and blend the background in with | 1062 // TODO(danakj): use the background_texture and blend the background in with |
| 1063 // this draw instead of having a separate copy of the background texture. | 1063 // this draw instead of having a separate copy of the background texture. |
| 1064 | 1064 |
| 1065 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; | 1065 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; |
| 1066 if (filter_bitmap.getTexture()) { | 1066 if (filter_bitmap.getTexture()) { |
| 1067 GrTexture* texture = | 1067 GrTexture* texture = |
| 1068 reinterpret_cast<GrTexture*>(filter_bitmap.getTexture()); | 1068 reinterpret_cast<GrTexture*>(filter_bitmap.getTexture()); |
| 1069 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); | 1069 DCHECK_EQ(GL_TEXTURE0, GLRenderer::GetActiveTextureUnit(gl_)); |
| 1070 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); | 1070 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
| 1071 } else { | 1071 } else { |
| 1072 contents_resource_lock = | 1072 contents_resource_lock = |
| 1073 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( | 1073 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( |
| 1074 resource_provider_, contents_texture->id(), GL_LINEAR)); | 1074 resource_provider_, contents_texture->id(), GL_LINEAR)); |
| 1075 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1075 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1076 contents_resource_lock->target()); | 1076 contents_resource_lock->target()); |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1079 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 DCHECK(did_invert); | 1422 DCHECK(did_invert); |
| 1423 *local_quad = MathUtil::MapQuad( | 1423 *local_quad = MathUtil::MapQuad( |
| 1424 inverse_device_transform, device_quad.ToQuadF(), &clipped); | 1424 inverse_device_transform, device_quad.ToQuadF(), &clipped); |
| 1425 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may | 1425 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may |
| 1426 // cause device_quad to become clipped. To our knowledge this scenario does | 1426 // cause device_quad to become clipped. To our knowledge this scenario does |
| 1427 // not need to be handled differently than the unclipped case. | 1427 // not need to be handled differently than the unclipped case. |
| 1428 | 1428 |
| 1429 return true; | 1429 return true; |
| 1430 } | 1430 } |
| 1431 | 1431 |
| 1432 GLint GLRenderer::GetActiveTextureUnit(GLES2Interface* gl) { |
| 1433 GLint active_unit = 0; |
| 1434 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1435 return active_unit; |
| 1436 } |
| 1437 |
| 1432 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, | 1438 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, |
| 1433 const SolidColorDrawQuad* quad) { | 1439 const SolidColorDrawQuad* quad) { |
| 1434 gfx::Rect tile_rect = quad->visible_rect; | 1440 gfx::Rect tile_rect = quad->visible_rect; |
| 1435 | 1441 |
| 1436 SkColor color = quad->color; | 1442 SkColor color = quad->color; |
| 1437 float opacity = quad->opacity(); | 1443 float opacity = quad->opacity(); |
| 1438 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; | 1444 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; |
| 1439 | 1445 |
| 1440 // Early out if alpha is small enough that quad doesn't contribute to output. | 1446 // Early out if alpha is small enough that quad doesn't contribute to output. |
| 1441 if (alpha < std::numeric_limits<float>::epsilon() && | 1447 if (alpha < std::numeric_limits<float>::epsilon() && |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 GetVideoStreamTextureProgram(tex_coord_precision); | 1853 GetVideoStreamTextureProgram(tex_coord_precision); |
| 1848 SetUseProgram(program->program()); | 1854 SetUseProgram(program->program()); |
| 1849 | 1855 |
| 1850 ToGLMatrix(&gl_matrix[0], quad->matrix); | 1856 ToGLMatrix(&gl_matrix[0], quad->matrix); |
| 1851 GLC(gl_, | 1857 GLC(gl_, |
| 1852 gl_->UniformMatrix4fv( | 1858 gl_->UniformMatrix4fv( |
| 1853 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); | 1859 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); |
| 1854 | 1860 |
| 1855 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 1861 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 1856 quad->resource_id); | 1862 quad->resource_id); |
| 1857 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); | 1863 DCHECK_EQ(GL_TEXTURE0, GLRenderer::GetActiveTextureUnit(gl_)); |
| 1858 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); | 1864 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); |
| 1859 | 1865 |
| 1860 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1866 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1861 | 1867 |
| 1862 SetShaderOpacity(quad->opacity(), | 1868 SetShaderOpacity(quad->opacity(), |
| 1863 program->fragment_shader().alpha_location()); | 1869 program->fragment_shader().alpha_location()); |
| 1864 DrawQuadGeometry(frame, | 1870 DrawQuadGeometry(frame, |
| 1865 quad->quadTransform(), | 1871 quad->quadTransform(), |
| 1866 quad->rect, | 1872 quad->rect, |
| 1867 program->vertex_shader().matrix_location()); | 1873 program->vertex_shader().matrix_location()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1957 | 1963 |
| 1958 // Bind the program to the GL state. | 1964 // Bind the program to the GL state. |
| 1959 SetUseProgram(draw_cache_.program_id); | 1965 SetUseProgram(draw_cache_.program_id); |
| 1960 | 1966 |
| 1961 // Bind the correct texture sampler location. | 1967 // Bind the correct texture sampler location. |
| 1962 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); | 1968 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); |
| 1963 | 1969 |
| 1964 // Assume the current active textures is 0. | 1970 // Assume the current active textures is 0. |
| 1965 ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_, | 1971 ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_, |
| 1966 draw_cache_.resource_id); | 1972 draw_cache_.resource_id); |
| 1967 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); | 1973 DCHECK_EQ(GL_TEXTURE0, GLRenderer::GetActiveTextureUnit(gl_)); |
| 1968 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id())); | 1974 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id())); |
| 1969 | 1975 |
| 1970 COMPILE_ASSERT(sizeof(Float4) == 4 * sizeof(float), struct_is_densely_packed); | 1976 COMPILE_ASSERT(sizeof(Float4) == 4 * sizeof(float), struct_is_densely_packed); |
| 1971 COMPILE_ASSERT(sizeof(Float16) == 16 * sizeof(float), | 1977 COMPILE_ASSERT(sizeof(Float16) == 16 * sizeof(float), |
| 1972 struct_is_densely_packed); | 1978 struct_is_densely_packed); |
| 1973 | 1979 |
| 1974 // Upload the tranforms for both points and uvs. | 1980 // Upload the tranforms for both points and uvs. |
| 1975 GLC(gl_, | 1981 GLC(gl_, |
| 1976 gl_->UniformMatrix4fv( | 1982 gl_->UniformMatrix4fv( |
| 1977 static_cast<int>(draw_cache_.matrix_location), | 1983 static_cast<int>(draw_cache_.matrix_location), |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2106 quad->io_surface_size.width(), | 2112 quad->io_surface_size.width(), |
| 2107 quad->io_surface_size.height())); | 2113 quad->io_surface_size.height())); |
| 2108 } | 2114 } |
| 2109 | 2115 |
| 2110 const float vertex_opacity[] = {quad->opacity(), quad->opacity(), | 2116 const float vertex_opacity[] = {quad->opacity(), quad->opacity(), |
| 2111 quad->opacity(), quad->opacity()}; | 2117 quad->opacity(), quad->opacity()}; |
| 2112 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity)); | 2118 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity)); |
| 2113 | 2119 |
| 2114 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 2120 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2115 quad->io_surface_resource_id); | 2121 quad->io_surface_resource_id); |
| 2116 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); | 2122 DCHECK_EQ(GL_TEXTURE0, GLRenderer::GetActiveTextureUnit(gl_)); |
| 2117 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); | 2123 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); |
| 2118 | 2124 |
| 2119 DrawQuadGeometry( | 2125 DrawQuadGeometry( |
| 2120 frame, quad->quadTransform(), quad->rect, binding.matrix_location); | 2126 frame, quad->quadTransform(), quad->rect, binding.matrix_location); |
| 2121 | 2127 |
| 2122 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); | 2128 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); |
| 2123 } | 2129 } |
| 2124 | 2130 |
| 2125 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 2131 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
| 2126 if (use_sync_query_) { | 2132 if (use_sync_query_) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2259 } else { | 2265 } else { |
| 2260 GLC(gl_, | 2266 GLC(gl_, |
| 2261 gl_->Uniform4f(program->vertex_shader().tex_transform_location(), | 2267 gl_->Uniform4f(program->vertex_shader().tex_transform_location(), |
| 2262 0.f, | 2268 0.f, |
| 2263 0.f, | 2269 0.f, |
| 2264 1.f, | 2270 1.f, |
| 2265 1.f)); | 2271 1.f)); |
| 2266 } | 2272 } |
| 2267 | 2273 |
| 2268 SetShaderOpacity(1.f, program->fragment_shader().alpha_location()); | 2274 SetShaderOpacity(1.f, program->fragment_shader().alpha_location()); |
| 2269 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); | 2275 DCHECK_EQ(GL_TEXTURE0, GLRenderer::GetActiveTextureUnit(gl_)); |
| 2270 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id)); | 2276 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id)); |
| 2271 DrawQuadGeometry( | 2277 DrawQuadGeometry( |
| 2272 frame, draw_matrix, rect, program->vertex_shader().matrix_location()); | 2278 frame, draw_matrix, rect, program->vertex_shader().matrix_location()); |
| 2273 } | 2279 } |
| 2274 | 2280 |
| 2275 void GLRenderer::Finish() { | 2281 void GLRenderer::Finish() { |
| 2276 TRACE_EVENT0("cc", "GLRenderer::Finish"); | 2282 TRACE_EVENT0("cc", "GLRenderer::Finish"); |
| 2277 GLC(gl_, gl_->Finish()); | 2283 GLC(gl_, gl_->Finish()); |
| 2278 } | 2284 } |
| 2279 | 2285 |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3165 context_support_->ScheduleOverlayPlane( | 3171 context_support_->ScheduleOverlayPlane( |
| 3166 overlay.plane_z_order, | 3172 overlay.plane_z_order, |
| 3167 overlay.transform, | 3173 overlay.transform, |
| 3168 pending_overlay_resources_.back()->texture_id(), | 3174 pending_overlay_resources_.back()->texture_id(), |
| 3169 overlay.display_rect, | 3175 overlay.display_rect, |
| 3170 overlay.uv_rect); | 3176 overlay.uv_rect); |
| 3171 } | 3177 } |
| 3172 } | 3178 } |
| 3173 | 3179 |
| 3174 } // namespace cc | 3180 } // namespace cc |
| OLD | NEW |