| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 const FilterOperations* background_filters = nullptr; | 175 const FilterOperations* background_filters = nullptr; |
| 176 | 176 |
| 177 // Whether the texture to be sampled from needs to be flipped. | 177 // Whether the texture to be sampled from needs to be flipped. |
| 178 bool source_needs_flip = false; | 178 bool source_needs_flip = false; |
| 179 | 179 |
| 180 float edge[24]; | 180 float edge[24]; |
| 181 SkScalar color_matrix[20]; | 181 SkScalar color_matrix[20]; |
| 182 | 182 |
| 183 // Blending refers to modifications to the backdrop. | 183 // Blending refers to modifications to the backdrop. |
| 184 bool use_shaders_for_blending = false; | 184 bool use_shaders_for_blending = false; |
| 185 const Program* program = nullptr; | |
| 186 | 185 |
| 187 bool use_aa = false; | 186 bool use_aa = false; |
| 188 | 187 |
| 189 // Some filters affect pixels outside the original contents bounds. This | 188 // Some filters affect pixels outside the original contents bounds. This |
| 190 // requires translation of the source when texturing, as well as a change in | 189 // requires translation of the source when texturing, as well as a change in |
| 191 // the bounds of the destination. | 190 // the bounds of the destination. |
| 192 gfx::Point src_offset; | 191 gfx::Point src_offset; |
| 193 gfx::RectF dst_rect; | 192 gfx::RectF dst_rect; |
| 194 | 193 |
| 195 // A Skia image that should be sampled from instead of the original | 194 // A Skia image that should be sampled from instead of the original |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 break; | 595 break; |
| 597 } | 596 } |
| 598 } | 597 } |
| 599 | 598 |
| 600 // This function does not handle 3D sorting right now, since the debug border | 599 // This function does not handle 3D sorting right now, since the debug border |
| 601 // quads are just drawn as their original quads and not in split pieces. This | 600 // quads are just drawn as their original quads and not in split pieces. This |
| 602 // results in some debug border quads drawing over foreground quads. | 601 // results in some debug border quads drawing over foreground quads. |
| 603 void GLRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) { | 602 void GLRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) { |
| 604 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 603 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 605 | 604 |
| 606 const Program* program = GetProgram(ProgramKey::DebugBorder()); | 605 SetUseProgram(ProgramKey::DebugBorder(), gfx::ColorSpace::CreateSRGB()); |
| 607 SetUseProgram(program); | |
| 608 | 606 |
| 609 // Use the full quad_rect for debug quads to not move the edges based on | 607 // Use the full quad_rect for debug quads to not move the edges based on |
| 610 // partial swaps. | 608 // partial swaps. |
| 611 gfx::Rect layer_rect = quad->rect; | 609 gfx::Rect layer_rect = quad->rect; |
| 612 gfx::Transform render_matrix; | 610 gfx::Transform render_matrix; |
| 613 QuadRectTransform(&render_matrix, | 611 QuadRectTransform(&render_matrix, |
| 614 quad->shared_quad_state->quad_to_target_transform, | 612 quad->shared_quad_state->quad_to_target_transform, |
| 615 gfx::RectF(layer_rect)); | 613 gfx::RectF(layer_rect)); |
| 616 SetShaderMatrix(current_frame()->projection_matrix * render_matrix); | 614 SetShaderMatrix(current_frame()->projection_matrix * render_matrix); |
| 617 SetShaderColor(quad->color, 1.f); | 615 SetShaderColor(quad->color, 1.f); |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 | 1298 |
| 1301 SamplerType sampler_type = SAMPLER_TYPE_2D; | 1299 SamplerType sampler_type = SAMPLER_TYPE_2D; |
| 1302 MaskMode mask_mode = NO_MASK; | 1300 MaskMode mask_mode = NO_MASK; |
| 1303 bool mask_for_background = params->mask_for_background; | 1301 bool mask_for_background = params->mask_for_background; |
| 1304 if (params->mask_resource_lock) { | 1302 if (params->mask_resource_lock) { |
| 1305 mask_mode = HAS_MASK; | 1303 mask_mode = HAS_MASK; |
| 1306 sampler_type = | 1304 sampler_type = |
| 1307 SamplerTypeFromTextureTarget(params->mask_resource_lock->target()); | 1305 SamplerTypeFromTextureTarget(params->mask_resource_lock->target()); |
| 1308 } | 1306 } |
| 1309 | 1307 |
| 1310 params->program = GetProgram(ProgramKey::RenderPass( | 1308 SetUseProgram(ProgramKey::RenderPass( |
| 1311 tex_coord_precision, sampler_type, shader_blend_mode, | 1309 tex_coord_precision, sampler_type, shader_blend_mode, |
| 1312 params->use_aa ? USE_AA : NO_AA, mask_mode, mask_for_background, | 1310 params->use_aa ? USE_AA : NO_AA, mask_mode, |
| 1313 params->use_color_matrix)); | 1311 mask_for_background, params->use_color_matrix), |
| 1314 SetUseProgram(params->program); | 1312 current_frame()->device_color_space); |
| 1315 } | 1313 } |
| 1316 | 1314 |
| 1317 void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) { | 1315 void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) { |
| 1318 const Program* program = params->program; | |
| 1319 | |
| 1320 gfx::RectF tex_rect(params->src_offset.x(), params->src_offset.y(), | 1316 gfx::RectF tex_rect(params->src_offset.x(), params->src_offset.y(), |
| 1321 params->dst_rect.width(), params->dst_rect.height()); | 1317 params->dst_rect.width(), params->dst_rect.height()); |
| 1322 gfx::Size texture_size; | 1318 gfx::Size texture_size; |
| 1323 if (params->filter_image) { | 1319 if (params->filter_image) { |
| 1324 texture_size.set_width(params->filter_image->width()); | 1320 texture_size.set_width(params->filter_image->width()); |
| 1325 texture_size.set_height(params->filter_image->height()); | 1321 texture_size.set_height(params->filter_image->height()); |
| 1326 } else { | 1322 } else { |
| 1327 texture_size = params->contents_texture->size(); | 1323 texture_size = params->contents_texture->size(); |
| 1328 } | 1324 } |
| 1329 tex_rect.Scale(1.0f / texture_size.width(), 1.0f / texture_size.height()); | 1325 tex_rect.Scale(1.0f / texture_size.width(), 1.0f / texture_size.height()); |
| 1330 | 1326 |
| 1331 DCHECK(program->vertex_tex_transform_location() != -1 || IsContextLost()); | 1327 DCHECK(current_program_->vertex_tex_transform_location() != -1 || |
| 1328 IsContextLost()); |
| 1332 if (params->source_needs_flip) { | 1329 if (params->source_needs_flip) { |
| 1333 // Flip the content vertically in the shader, as the RenderPass input | 1330 // Flip the content vertically in the shader, as the RenderPass input |
| 1334 // texture is already oriented the same way as the framebuffer, but the | 1331 // texture is already oriented the same way as the framebuffer, but the |
| 1335 // projection transform does a flip. | 1332 // projection transform does a flip. |
| 1336 gl_->Uniform4f(program->vertex_tex_transform_location(), tex_rect.x(), | 1333 gl_->Uniform4f(current_program_->vertex_tex_transform_location(), |
| 1337 1.0f - tex_rect.y(), tex_rect.width(), -tex_rect.height()); | 1334 tex_rect.x(), 1.0f - tex_rect.y(), tex_rect.width(), |
| 1335 -tex_rect.height()); |
| 1338 } else { | 1336 } else { |
| 1339 // Tile textures are oriented opposite the framebuffer, so can use | 1337 // Tile textures are oriented opposite the framebuffer, so can use |
| 1340 // the projection transform to do the flip. | 1338 // the projection transform to do the flip. |
| 1341 gl_->Uniform4f(program->vertex_tex_transform_location(), tex_rect.x(), | 1339 gl_->Uniform4f(current_program_->vertex_tex_transform_location(), |
| 1342 tex_rect.y(), tex_rect.width(), tex_rect.height()); | 1340 tex_rect.x(), tex_rect.y(), tex_rect.width(), |
| 1341 tex_rect.height()); |
| 1343 } | 1342 } |
| 1344 | 1343 |
| 1345 GLint last_texture_unit = 0; | 1344 GLint last_texture_unit = 0; |
| 1346 if (program->mask_sampler_location() != -1) { | 1345 if (current_program_->mask_sampler_location() != -1) { |
| 1347 DCHECK(params->mask_resource_lock); | 1346 DCHECK(params->mask_resource_lock); |
| 1348 DCHECK_NE(program->mask_tex_coord_scale_location(), 1); | 1347 DCHECK_NE(current_program_->mask_tex_coord_scale_location(), 1); |
| 1349 DCHECK_NE(program->mask_tex_coord_offset_location(), 1); | 1348 DCHECK_NE(current_program_->mask_tex_coord_offset_location(), 1); |
| 1350 gl_->Uniform1i(program->mask_sampler_location(), 1); | 1349 gl_->Uniform1i(current_program_->mask_sampler_location(), 1); |
| 1351 | 1350 |
| 1352 gfx::RectF mask_uv_rect = params->quad->MaskUVRect(); | 1351 gfx::RectF mask_uv_rect = params->quad->MaskUVRect(); |
| 1353 if (SamplerTypeFromTextureTarget(params->mask_resource_lock->target()) != | 1352 if (SamplerTypeFromTextureTarget(params->mask_resource_lock->target()) != |
| 1354 SAMPLER_TYPE_2D) { | 1353 SAMPLER_TYPE_2D) { |
| 1355 mask_uv_rect.Scale(params->quad->mask_texture_size.width(), | 1354 mask_uv_rect.Scale(params->quad->mask_texture_size.width(), |
| 1356 params->quad->mask_texture_size.height()); | 1355 params->quad->mask_texture_size.height()); |
| 1357 } | 1356 } |
| 1358 if (params->source_needs_flip) { | 1357 if (params->source_needs_flip) { |
| 1359 // Mask textures are oriented vertically flipped relative to the | 1358 // Mask textures are oriented vertically flipped relative to the |
| 1360 // framebuffer and the RenderPass contents texture, so we flip the tex | 1359 // framebuffer and the RenderPass contents texture, so we flip the tex |
| 1361 // coords from the RenderPass texture to find the mask texture coords. | 1360 // coords from the RenderPass texture to find the mask texture coords. |
| 1362 gl_->Uniform2f( | 1361 gl_->Uniform2f( |
| 1363 program->mask_tex_coord_offset_location(), mask_uv_rect.x(), | 1362 current_program_->mask_tex_coord_offset_location(), mask_uv_rect.x(), |
| 1364 mask_uv_rect.height() / tex_rect.height() + mask_uv_rect.y()); | 1363 mask_uv_rect.height() / tex_rect.height() + mask_uv_rect.y()); |
| 1365 gl_->Uniform2f(program->mask_tex_coord_scale_location(), | 1364 gl_->Uniform2f(current_program_->mask_tex_coord_scale_location(), |
| 1366 mask_uv_rect.width() / tex_rect.width(), | 1365 mask_uv_rect.width() / tex_rect.width(), |
| 1367 -mask_uv_rect.height() / tex_rect.height()); | 1366 -mask_uv_rect.height() / tex_rect.height()); |
| 1368 } else { | 1367 } else { |
| 1369 // Tile textures are oriented the same way as mask textures. | 1368 // Tile textures are oriented the same way as mask textures. |
| 1370 gl_->Uniform2f(program->mask_tex_coord_offset_location(), | 1369 gl_->Uniform2f(current_program_->mask_tex_coord_offset_location(), |
| 1371 mask_uv_rect.x(), mask_uv_rect.y()); | 1370 mask_uv_rect.x(), mask_uv_rect.y()); |
| 1372 gl_->Uniform2f(program->mask_tex_coord_scale_location(), | 1371 gl_->Uniform2f(current_program_->mask_tex_coord_scale_location(), |
| 1373 mask_uv_rect.width() / tex_rect.width(), | 1372 mask_uv_rect.width() / tex_rect.width(), |
| 1374 mask_uv_rect.height() / tex_rect.height()); | 1373 mask_uv_rect.height() / tex_rect.height()); |
| 1375 } | 1374 } |
| 1376 | 1375 |
| 1377 last_texture_unit = 1; | 1376 last_texture_unit = 1; |
| 1378 } | 1377 } |
| 1379 | 1378 |
| 1380 if (program->edge_location() != -1) | 1379 if (current_program_->edge_location() != -1) |
| 1381 gl_->Uniform3fv(program->edge_location(), 8, params->edge); | 1380 gl_->Uniform3fv(current_program_->edge_location(), 8, params->edge); |
| 1382 | 1381 |
| 1383 if (program->color_matrix_location() != -1) { | 1382 if (current_program_->color_matrix_location() != -1) { |
| 1384 float matrix[16]; | 1383 float matrix[16]; |
| 1385 for (int i = 0; i < 4; ++i) { | 1384 for (int i = 0; i < 4; ++i) { |
| 1386 for (int j = 0; j < 4; ++j) | 1385 for (int j = 0; j < 4; ++j) |
| 1387 matrix[i * 4 + j] = SkScalarToFloat(params->color_matrix[j * 5 + i]); | 1386 matrix[i * 4 + j] = SkScalarToFloat(params->color_matrix[j * 5 + i]); |
| 1388 } | 1387 } |
| 1389 gl_->UniformMatrix4fv(program->color_matrix_location(), 1, false, matrix); | 1388 gl_->UniformMatrix4fv(current_program_->color_matrix_location(), 1, false, |
| 1389 matrix); |
| 1390 } | 1390 } |
| 1391 static const float kScale = 1.0f / 255.0f; | 1391 static const float kScale = 1.0f / 255.0f; |
| 1392 if (program->color_offset_location() != -1) { | 1392 if (current_program_->color_offset_location() != -1) { |
| 1393 float offset[4]; | 1393 float offset[4]; |
| 1394 for (int i = 0; i < 4; ++i) | 1394 for (int i = 0; i < 4; ++i) |
| 1395 offset[i] = SkScalarToFloat(params->color_matrix[i * 5 + 4]) * kScale; | 1395 offset[i] = SkScalarToFloat(params->color_matrix[i * 5 + 4]) * kScale; |
| 1396 | 1396 |
| 1397 gl_->Uniform4fv(program->color_offset_location(), 1, offset); | 1397 gl_->Uniform4fv(current_program_->color_offset_location(), 1, offset); |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 if (program->backdrop_location() != -1) { | 1400 if (current_program_->backdrop_location() != -1) { |
| 1401 DCHECK(params->background_texture || params->background_image_id); | 1401 DCHECK(params->background_texture || params->background_image_id); |
| 1402 DCHECK_NE(program->backdrop_location(), 0); | 1402 DCHECK_NE(current_program_->backdrop_location(), 0); |
| 1403 DCHECK_NE(program->backdrop_rect_location(), 0); | 1403 DCHECK_NE(current_program_->backdrop_rect_location(), 0); |
| 1404 | 1404 |
| 1405 gl_->Uniform1i(program->backdrop_location(), ++last_texture_unit); | 1405 gl_->Uniform1i(current_program_->backdrop_location(), ++last_texture_unit); |
| 1406 | 1406 |
| 1407 gl_->Uniform4f(program->backdrop_rect_location(), | 1407 gl_->Uniform4f(current_program_->backdrop_rect_location(), |
| 1408 params->background_rect.x(), params->background_rect.y(), | 1408 params->background_rect.x(), params->background_rect.y(), |
| 1409 params->background_rect.width(), | 1409 params->background_rect.width(), |
| 1410 params->background_rect.height()); | 1410 params->background_rect.height()); |
| 1411 | 1411 |
| 1412 if (params->background_image_id) { | 1412 if (params->background_image_id) { |
| 1413 gl_->ActiveTexture(GL_TEXTURE0 + last_texture_unit); | 1413 gl_->ActiveTexture(GL_TEXTURE0 + last_texture_unit); |
| 1414 gl_->BindTexture(GL_TEXTURE_2D, params->background_image_id); | 1414 gl_->BindTexture(GL_TEXTURE_2D, params->background_image_id); |
| 1415 gl_->ActiveTexture(GL_TEXTURE0); | 1415 gl_->ActiveTexture(GL_TEXTURE0); |
| 1416 if (params->mask_for_background) | 1416 if (params->mask_for_background) |
| 1417 gl_->Uniform1i(program->original_backdrop_location(), | 1417 gl_->Uniform1i(current_program_->original_backdrop_location(), |
| 1418 ++last_texture_unit); | 1418 ++last_texture_unit); |
| 1419 } | 1419 } |
| 1420 if (params->background_texture) { | 1420 if (params->background_texture) { |
| 1421 params->shader_background_sampler_lock = | 1421 params->shader_background_sampler_lock = |
| 1422 base::MakeUnique<ResourceProvider::ScopedSamplerGL>( | 1422 base::MakeUnique<ResourceProvider::ScopedSamplerGL>( |
| 1423 resource_provider_, params->background_texture->id(), | 1423 resource_provider_, params->background_texture->id(), |
| 1424 GL_TEXTURE0 + last_texture_unit, GL_LINEAR); | 1424 GL_TEXTURE0 + last_texture_unit, GL_LINEAR); |
| 1425 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1425 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1426 params->shader_background_sampler_lock->target()); | 1426 params->shader_background_sampler_lock->target()); |
| 1427 } | 1427 } |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), | 1741 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), |
| 1742 &clipped); | 1742 &clipped); |
| 1743 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); | 1743 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); |
| 1744 } | 1744 } |
| 1745 | 1745 |
| 1746 float edge[24]; | 1746 float edge[24]; |
| 1747 const gfx::QuadF* aa_quad = use_aa ? &device_layer_quad : nullptr; | 1747 const gfx::QuadF* aa_quad = use_aa ? &device_layer_quad : nullptr; |
| 1748 SetupQuadForClippingAndAntialiasing(device_transform, quad, aa_quad, | 1748 SetupQuadForClippingAndAntialiasing(device_transform, quad, aa_quad, |
| 1749 clip_region, &local_quad, edge); | 1749 clip_region, &local_quad, edge); |
| 1750 | 1750 |
| 1751 const Program* program = | 1751 // TODO(ccameron): Solid color draw quads need to specify their implied |
| 1752 GetProgram(ProgramKey::SolidColor(use_aa ? USE_AA : NO_AA)); | 1752 // color space. Assume SRGB (which is wrong) for now. |
| 1753 SetUseProgram(program); | 1753 gfx::ColorSpace quad_color_space = gfx::ColorSpace::CreateSRGB(); |
| 1754 SetUseProgram(ProgramKey::SolidColor(use_aa ? USE_AA : NO_AA), |
| 1755 quad_color_space); |
| 1754 SetShaderColor(color, opacity); | 1756 SetShaderColor(color, opacity); |
| 1755 | 1757 |
| 1756 if (use_aa) { | 1758 if (use_aa) { |
| 1757 gl_->Uniform3fv(program->edge_location(), 8, edge); | 1759 gl_->Uniform3fv(current_program_->edge_location(), 8, edge); |
| 1758 } | 1760 } |
| 1759 | 1761 |
| 1760 // Enable blending when the quad properties require it or if we decided | 1762 // Enable blending when the quad properties require it or if we decided |
| 1761 // to use antialiasing. | 1763 // to use antialiasing. |
| 1762 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); | 1764 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); |
| 1763 | 1765 |
| 1764 // Antialising requires a normalized quad, but this could lead to floating | 1766 // Antialising requires a normalized quad, but this could lead to floating |
| 1765 // point precision errors, so only normalize when antialising is on. | 1767 // point precision errors, so only normalize when antialising is on. |
| 1766 if (use_aa) { | 1768 if (use_aa) { |
| 1767 // Normalize to tile_rect. | 1769 // Normalize to tile_rect. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1891 // Map to normalized texture coordinates. | 1893 // Map to normalized texture coordinates. |
| 1892 if (sampler != SAMPLER_TYPE_2D_RECT) { | 1894 if (sampler != SAMPLER_TYPE_2D_RECT) { |
| 1893 gfx::Size texture_size = quad->texture_size; | 1895 gfx::Size texture_size = quad->texture_size; |
| 1894 DCHECK(!texture_size.IsEmpty()); | 1896 DCHECK(!texture_size.IsEmpty()); |
| 1895 fragment_tex_translate_x /= texture_size.width(); | 1897 fragment_tex_translate_x /= texture_size.width(); |
| 1896 fragment_tex_translate_y /= texture_size.height(); | 1898 fragment_tex_translate_y /= texture_size.height(); |
| 1897 fragment_tex_scale_x /= texture_size.width(); | 1899 fragment_tex_scale_x /= texture_size.width(); |
| 1898 fragment_tex_scale_y /= texture_size.height(); | 1900 fragment_tex_scale_y /= texture_size.height(); |
| 1899 } | 1901 } |
| 1900 | 1902 |
| 1901 const Program* program = GetProgram(ProgramKey::Tile( | 1903 SetUseProgram( |
| 1902 tex_coord_precision, sampler, USE_AA, | 1904 ProgramKey::Tile(tex_coord_precision, sampler, USE_AA, |
| 1903 quad->swizzle_contents ? DO_SWIZZLE : NO_SWIZZLE, false)); | 1905 quad->swizzle_contents ? DO_SWIZZLE : NO_SWIZZLE, false), |
| 1906 quad_resource_lock.color_space()); |
| 1904 | 1907 |
| 1905 SetUseProgram(program); | 1908 gl_->Uniform3fv(current_program_->edge_location(), 8, edge); |
| 1906 | 1909 |
| 1907 gl_->Uniform3fv(program->edge_location(), 8, edge); | 1910 gl_->Uniform4f(current_program_->vertex_tex_transform_location(), |
| 1908 | |
| 1909 gl_->Uniform4f(program->vertex_tex_transform_location(), | |
| 1910 vertex_tex_translate_x, vertex_tex_translate_y, | 1911 vertex_tex_translate_x, vertex_tex_translate_y, |
| 1911 vertex_tex_scale_x, vertex_tex_scale_y); | 1912 vertex_tex_scale_x, vertex_tex_scale_y); |
| 1912 gl_->Uniform4f(program->fragment_tex_transform_location(), | 1913 gl_->Uniform4f(current_program_->fragment_tex_transform_location(), |
| 1913 fragment_tex_translate_x, fragment_tex_translate_y, | 1914 fragment_tex_translate_x, fragment_tex_translate_y, |
| 1914 fragment_tex_scale_x, fragment_tex_scale_y); | 1915 fragment_tex_scale_x, fragment_tex_scale_y); |
| 1915 | 1916 |
| 1916 // Blending is required for antialiasing. | 1917 // Blending is required for antialiasing. |
| 1917 SetBlendEnabled(true); | 1918 SetBlendEnabled(true); |
| 1918 | 1919 |
| 1919 // Normalize to tile_rect. | 1920 // Normalize to tile_rect. |
| 1920 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 1921 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 1921 | 1922 |
| 1922 SetShaderOpacity(quad); | 1923 SetShaderOpacity(quad); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 DCHECK(!texture_size.IsEmpty()); | 1969 DCHECK(!texture_size.IsEmpty()); |
| 1969 vertex_tex_translate_x /= texture_size.width(); | 1970 vertex_tex_translate_x /= texture_size.width(); |
| 1970 vertex_tex_translate_y /= texture_size.height(); | 1971 vertex_tex_translate_y /= texture_size.height(); |
| 1971 vertex_tex_scale_x /= texture_size.width(); | 1972 vertex_tex_scale_x /= texture_size.width(); |
| 1972 vertex_tex_scale_y /= texture_size.height(); | 1973 vertex_tex_scale_y /= texture_size.height(); |
| 1973 } | 1974 } |
| 1974 | 1975 |
| 1975 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1976 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1976 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); | 1977 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); |
| 1977 | 1978 |
| 1978 const Program* program = GetProgram( | 1979 SetUseProgram( |
| 1979 ProgramKey::Tile(tex_coord_precision, sampler, NO_AA, | 1980 ProgramKey::Tile(tex_coord_precision, sampler, NO_AA, |
| 1980 quad->swizzle_contents ? DO_SWIZZLE : NO_SWIZZLE, | 1981 quad->swizzle_contents ? DO_SWIZZLE : NO_SWIZZLE, |
| 1981 !quad->ShouldDrawWithBlending())); | 1982 !quad->ShouldDrawWithBlending()), |
| 1983 quad_resource_lock.color_space()); |
| 1982 | 1984 |
| 1983 SetUseProgram(program); | 1985 gl_->Uniform4f(current_program_->vertex_tex_transform_location(), |
| 1984 | |
| 1985 gl_->Uniform4f(program->vertex_tex_transform_location(), | |
| 1986 vertex_tex_translate_x, vertex_tex_translate_y, | 1986 vertex_tex_translate_x, vertex_tex_translate_y, |
| 1987 vertex_tex_scale_x, vertex_tex_scale_y); | 1987 vertex_tex_scale_x, vertex_tex_scale_y); |
| 1988 | 1988 |
| 1989 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1989 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1990 | 1990 |
| 1991 SetShaderOpacity(quad); | 1991 SetShaderOpacity(quad); |
| 1992 | 1992 |
| 1993 // Pass quad coordinates to the uniform in the same order as GeometryBinding | 1993 // Pass quad coordinates to the uniform in the same order as GeometryBinding |
| 1994 // does, then vertices will match the texture mapping in the vertex buffer. | 1994 // does, then vertices will match the texture mapping in the vertex buffer. |
| 1995 // The method SetShaderQuadF() changes the order of vertices and so it's | 1995 // The method SetShaderQuadF() changes the order of vertices and so it's |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2014 clipped_geometry_->InitializeCustomQuadWithUVs( | 2014 clipped_geometry_->InitializeCustomQuadWithUVs( |
| 2015 gfx::QuadF(gfx::RectF(quad->visible_rect)), gl_uv); | 2015 gfx::QuadF(gfx::RectF(quad->visible_rect)), gl_uv); |
| 2016 } else { | 2016 } else { |
| 2017 PrepareGeometry(SHARED_BINDING); | 2017 PrepareGeometry(SHARED_BINDING); |
| 2018 } | 2018 } |
| 2019 float gl_quad[8] = { | 2019 float gl_quad[8] = { |
| 2020 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(), | 2020 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(), |
| 2021 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(), | 2021 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(), |
| 2022 tile_quad.p3().x(), tile_quad.p3().y(), | 2022 tile_quad.p3().x(), tile_quad.p3().y(), |
| 2023 }; | 2023 }; |
| 2024 gl_->Uniform2fv(program->quad_location(), 4, gl_quad); | 2024 gl_->Uniform2fv(current_program_->quad_location(), 4, gl_quad); |
| 2025 | 2025 |
| 2026 SetShaderMatrix(current_frame()->projection_matrix * | 2026 SetShaderMatrix(current_frame()->projection_matrix * |
| 2027 quad->shared_quad_state->quad_to_target_transform); | 2027 quad->shared_quad_state->quad_to_target_transform); |
| 2028 | 2028 |
| 2029 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 2029 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
| 2030 } | 2030 } |
| 2031 | 2031 |
| 2032 // TODO(ccameron): This has been replicated in ui/gfx/color_transform.cc. Delete | 2032 // TODO(ccameron): This has been replicated in ui/gfx/color_transform.cc. Delete |
| 2033 // one of the instances. | 2033 // one of the instances. |
| 2034 void ComputeYUVToRGBMatrices(YUVVideoDrawQuad::ColorSpace color_space, | 2034 void ComputeYUVToRGBMatrices(const gfx::ColorSpace& src_color_space, |
| 2035 const gfx::ColorSpace& dst_color_space, |
| 2035 uint32_t bits_per_channel, | 2036 uint32_t bits_per_channel, |
| 2036 float resource_multiplier, | 2037 float resource_multiplier, |
| 2037 float resource_offset, | 2038 float resource_offset, |
| 2038 ColorConversionMode color_conversion_mode, | |
| 2039 float* yuv_to_rgb_matrix) { | 2039 float* yuv_to_rgb_matrix) { |
| 2040 gfx::ColorSpace gfx_color_space; | |
| 2041 switch (color_space) { | |
| 2042 case YUVVideoDrawQuad::REC_601: | |
| 2043 gfx_color_space = gfx::ColorSpace::CreateREC601(); | |
| 2044 break; | |
| 2045 case YUVVideoDrawQuad::REC_709: | |
| 2046 gfx_color_space = gfx::ColorSpace::CreateREC709(); | |
| 2047 break; | |
| 2048 case YUVVideoDrawQuad::JPEG: | |
| 2049 gfx_color_space = gfx::ColorSpace::CreateJpeg(); | |
| 2050 break; | |
| 2051 } | |
| 2052 | |
| 2053 // Compute the matrix |full_transform| which converts input YUV values to RGB | 2040 // Compute the matrix |full_transform| which converts input YUV values to RGB |
| 2054 // values. | 2041 // values. |
| 2055 SkMatrix44 full_transform; | 2042 SkMatrix44 full_transform; |
| 2056 | 2043 |
| 2057 // Start with the resource adjust. | 2044 // Start with the resource adjust. |
| 2058 full_transform.setScale(resource_multiplier, resource_multiplier, | 2045 full_transform.setScale(resource_multiplier, resource_multiplier, |
| 2059 resource_multiplier); | 2046 resource_multiplier); |
| 2060 full_transform.preTranslate(-resource_offset, -resource_offset, | 2047 full_transform.preTranslate(-resource_offset, -resource_offset, |
| 2061 -resource_offset); | 2048 -resource_offset); |
| 2062 | 2049 |
| 2063 // If we're using a LUT for conversion, we only need the resource adjust, | 2050 // If we're using a LUT for conversion, we only need the resource adjust, |
| 2064 // so just return this matrix. | 2051 // so just return this matrix. |
| 2065 if (color_conversion_mode == COLOR_CONVERSION_MODE_LUT) { | 2052 if (dst_color_space.IsValid()) { |
| 2066 full_transform.asColMajorf(yuv_to_rgb_matrix); | 2053 full_transform.asColMajorf(yuv_to_rgb_matrix); |
| 2067 return; | 2054 return; |
| 2068 } | 2055 } |
| 2069 | 2056 |
| 2070 // Then apply the range adjust. | 2057 // Then apply the range adjust. |
| 2071 { | 2058 { |
| 2072 SkMatrix44 range_adjust; | 2059 SkMatrix44 range_adjust; |
| 2073 gfx_color_space.GetRangeAdjustMatrix(&range_adjust); | 2060 src_color_space.GetRangeAdjustMatrix(&range_adjust); |
| 2074 full_transform.postConcat(range_adjust); | 2061 full_transform.postConcat(range_adjust); |
| 2075 } | 2062 } |
| 2076 | 2063 |
| 2077 // Then apply the YUV to RGB full_transform. | 2064 // Then apply the YUV to RGB full_transform. |
| 2078 { | 2065 { |
| 2079 SkMatrix44 rgb_to_yuv; | 2066 SkMatrix44 rgb_to_yuv; |
| 2080 gfx_color_space.GetTransferMatrix(&rgb_to_yuv); | 2067 src_color_space.GetTransferMatrix(&rgb_to_yuv); |
| 2081 SkMatrix44 yuv_to_rgb; | 2068 SkMatrix44 yuv_to_rgb; |
| 2082 rgb_to_yuv.invert(&yuv_to_rgb); | 2069 rgb_to_yuv.invert(&yuv_to_rgb); |
| 2083 full_transform.postConcat(yuv_to_rgb); | 2070 full_transform.postConcat(yuv_to_rgb); |
| 2084 } | 2071 } |
| 2085 | 2072 |
| 2086 full_transform.asColMajorf(yuv_to_rgb_matrix); | 2073 full_transform.asColMajorf(yuv_to_rgb_matrix); |
| 2087 } | 2074 } |
| 2088 | 2075 |
| 2089 void GLRenderer::DrawYUVVideoQuad(const YUVVideoDrawQuad* quad, | 2076 void GLRenderer::DrawYUVVideoQuad(const YUVVideoDrawQuad* quad, |
| 2090 const gfx::QuadF* clip_region) { | 2077 const gfx::QuadF* clip_region) { |
| 2091 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2078 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2092 | 2079 |
| 2093 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2080 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2094 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2081 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2095 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2082 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2096 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() | 2083 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() |
| 2097 ? YUV_HAS_ALPHA_TEXTURE | 2084 ? YUV_HAS_ALPHA_TEXTURE |
| 2098 : YUV_NO_ALPHA_TEXTURE; | 2085 : YUV_NO_ALPHA_TEXTURE; |
| 2099 UVTextureMode uv_texture_mode = | 2086 UVTextureMode uv_texture_mode = |
| 2100 quad->v_plane_resource_id() == quad->u_plane_resource_id() | 2087 quad->v_plane_resource_id() == quad->u_plane_resource_id() |
| 2101 ? UV_TEXTURE_MODE_UV | 2088 ? UV_TEXTURE_MODE_UV |
| 2102 : UV_TEXTURE_MODE_U_V; | 2089 : UV_TEXTURE_MODE_U_V; |
| 2103 ColorConversionMode color_conversion_mode = | 2090 |
| 2104 base::FeatureList::IsEnabled(media::kVideoColorManagement) | 2091 // TODO(ccameron): There are currently three sources of the color space: the |
| 2105 ? COLOR_CONVERSION_MODE_LUT | 2092 // resource, quad->color_space, and quad->video_color_space. Remove two of |
| 2106 : COLOR_CONVERSION_MODE_NONE; | 2093 // them. |
| 2094 gfx::ColorSpace src_color_space = quad->video_color_space; |
| 2095 gfx::ColorSpace dst_color_space = current_frame()->device_color_space; |
| 2096 if (!base::FeatureList::IsEnabled(media::kVideoColorManagement)) { |
| 2097 if (!settings_->enable_color_correct_rendering) |
| 2098 dst_color_space = gfx::ColorSpace(); |
| 2099 switch (quad->color_space) { |
| 2100 case YUVVideoDrawQuad::REC_601: |
| 2101 src_color_space = gfx::ColorSpace::CreateREC601(); |
| 2102 break; |
| 2103 case YUVVideoDrawQuad::REC_709: |
| 2104 src_color_space = gfx::ColorSpace::CreateREC709(); |
| 2105 break; |
| 2106 case YUVVideoDrawQuad::JPEG: |
| 2107 src_color_space = gfx::ColorSpace::CreateJpeg(); |
| 2108 break; |
| 2109 } |
| 2110 } |
| 2111 |
| 2107 ResourceProvider::ScopedSamplerGL y_plane_lock( | 2112 ResourceProvider::ScopedSamplerGL y_plane_lock( |
| 2108 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); | 2113 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); |
| 2109 ResourceProvider::ScopedSamplerGL u_plane_lock( | 2114 ResourceProvider::ScopedSamplerGL u_plane_lock( |
| 2110 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); | 2115 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); |
| 2111 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); | 2116 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); |
| 2112 // TODO(jbauman): Use base::Optional when available. | 2117 // TODO(jbauman): Use base::Optional when available. |
| 2113 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock; | 2118 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock; |
| 2114 | 2119 |
| 2115 if (uv_texture_mode == UV_TEXTURE_MODE_U_V) { | 2120 if (uv_texture_mode == UV_TEXTURE_MODE_U_V) { |
| 2116 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( | 2121 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| 2117 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, | 2122 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, |
| 2118 GL_LINEAR)); | 2123 GL_LINEAR)); |
| 2119 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target()); | 2124 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target()); |
| 2120 } | 2125 } |
| 2121 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; | 2126 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; |
| 2122 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) { | 2127 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) { |
| 2123 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( | 2128 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| 2124 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, | 2129 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, |
| 2125 GL_LINEAR)); | 2130 GL_LINEAR)); |
| 2126 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); | 2131 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); |
| 2127 } | 2132 } |
| 2128 | 2133 |
| 2129 // All planes must have the same sampler type. | 2134 // All planes must have the same sampler type. |
| 2130 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); | 2135 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); |
| 2131 | 2136 |
| 2132 const Program* program = GetProgram( | 2137 SetUseProgram(ProgramKey::YUVVideo(tex_coord_precision, sampler, |
| 2133 ProgramKey::YUVVideo(tex_coord_precision, sampler, alpha_texture_mode, | 2138 alpha_texture_mode, uv_texture_mode), |
| 2134 uv_texture_mode, color_conversion_mode)); | 2139 src_color_space, dst_color_space); |
| 2135 SetUseProgram(program); | |
| 2136 | 2140 |
| 2137 gfx::SizeF ya_tex_scale(1.0f, 1.0f); | 2141 gfx::SizeF ya_tex_scale(1.0f, 1.0f); |
| 2138 gfx::SizeF uv_tex_scale(1.0f, 1.0f); | 2142 gfx::SizeF uv_tex_scale(1.0f, 1.0f); |
| 2139 if (sampler != SAMPLER_TYPE_2D_RECT) { | 2143 if (sampler != SAMPLER_TYPE_2D_RECT) { |
| 2140 DCHECK(!quad->ya_tex_size.IsEmpty()); | 2144 DCHECK(!quad->ya_tex_size.IsEmpty()); |
| 2141 DCHECK(!quad->uv_tex_size.IsEmpty()); | 2145 DCHECK(!quad->uv_tex_size.IsEmpty()); |
| 2142 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), | 2146 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), |
| 2143 1.0f / quad->ya_tex_size.height()); | 2147 1.0f / quad->ya_tex_size.height()); |
| 2144 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), | 2148 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), |
| 2145 1.0f / quad->uv_tex_size.height()); | 2149 1.0f / quad->uv_tex_size.height()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2156 | 2160 |
| 2157 float uv_vertex_tex_translate_x = | 2161 float uv_vertex_tex_translate_x = |
| 2158 quad->uv_tex_coord_rect.x() * uv_tex_scale.width(); | 2162 quad->uv_tex_coord_rect.x() * uv_tex_scale.width(); |
| 2159 float uv_vertex_tex_translate_y = | 2163 float uv_vertex_tex_translate_y = |
| 2160 quad->uv_tex_coord_rect.y() * uv_tex_scale.height(); | 2164 quad->uv_tex_coord_rect.y() * uv_tex_scale.height(); |
| 2161 float uv_vertex_tex_scale_x = | 2165 float uv_vertex_tex_scale_x = |
| 2162 quad->uv_tex_coord_rect.width() * uv_tex_scale.width(); | 2166 quad->uv_tex_coord_rect.width() * uv_tex_scale.width(); |
| 2163 float uv_vertex_tex_scale_y = | 2167 float uv_vertex_tex_scale_y = |
| 2164 quad->uv_tex_coord_rect.height() * uv_tex_scale.height(); | 2168 quad->uv_tex_coord_rect.height() * uv_tex_scale.height(); |
| 2165 | 2169 |
| 2166 gl_->Uniform2f(program->ya_tex_scale_location(), ya_vertex_tex_scale_x, | 2170 gl_->Uniform2f(current_program_->ya_tex_scale_location(), |
| 2167 ya_vertex_tex_scale_y); | 2171 ya_vertex_tex_scale_x, ya_vertex_tex_scale_y); |
| 2168 gl_->Uniform2f(program->ya_tex_offset_location(), ya_vertex_tex_translate_x, | 2172 gl_->Uniform2f(current_program_->ya_tex_offset_location(), |
| 2169 ya_vertex_tex_translate_y); | 2173 ya_vertex_tex_translate_x, ya_vertex_tex_translate_y); |
| 2170 gl_->Uniform2f(program->uv_tex_scale_location(), uv_vertex_tex_scale_x, | 2174 gl_->Uniform2f(current_program_->uv_tex_scale_location(), |
| 2171 uv_vertex_tex_scale_y); | 2175 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); |
| 2172 gl_->Uniform2f(program->uv_tex_offset_location(), uv_vertex_tex_translate_x, | 2176 gl_->Uniform2f(current_program_->uv_tex_offset_location(), |
| 2173 uv_vertex_tex_translate_y); | 2177 uv_vertex_tex_translate_x, uv_vertex_tex_translate_y); |
| 2174 | 2178 |
| 2175 gfx::RectF ya_clamp_rect(ya_vertex_tex_translate_x, ya_vertex_tex_translate_y, | 2179 gfx::RectF ya_clamp_rect(ya_vertex_tex_translate_x, ya_vertex_tex_translate_y, |
| 2176 ya_vertex_tex_scale_x, ya_vertex_tex_scale_y); | 2180 ya_vertex_tex_scale_x, ya_vertex_tex_scale_y); |
| 2177 ya_clamp_rect.Inset(0.5f * ya_tex_scale.width(), | 2181 ya_clamp_rect.Inset(0.5f * ya_tex_scale.width(), |
| 2178 0.5f * ya_tex_scale.height()); | 2182 0.5f * ya_tex_scale.height()); |
| 2179 gfx::RectF uv_clamp_rect(uv_vertex_tex_translate_x, uv_vertex_tex_translate_y, | 2183 gfx::RectF uv_clamp_rect(uv_vertex_tex_translate_x, uv_vertex_tex_translate_y, |
| 2180 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); | 2184 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); |
| 2181 uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(), | 2185 uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(), |
| 2182 0.5f * uv_tex_scale.height()); | 2186 0.5f * uv_tex_scale.height()); |
| 2183 gl_->Uniform4f(program->ya_clamp_rect_location(), ya_clamp_rect.x(), | 2187 gl_->Uniform4f(current_program_->ya_clamp_rect_location(), ya_clamp_rect.x(), |
| 2184 ya_clamp_rect.y(), ya_clamp_rect.right(), | 2188 ya_clamp_rect.y(), ya_clamp_rect.right(), |
| 2185 ya_clamp_rect.bottom()); | 2189 ya_clamp_rect.bottom()); |
| 2186 gl_->Uniform4f(program->uv_clamp_rect_location(), uv_clamp_rect.x(), | 2190 gl_->Uniform4f(current_program_->uv_clamp_rect_location(), uv_clamp_rect.x(), |
| 2187 uv_clamp_rect.y(), uv_clamp_rect.right(), | 2191 uv_clamp_rect.y(), uv_clamp_rect.right(), |
| 2188 uv_clamp_rect.bottom()); | 2192 uv_clamp_rect.bottom()); |
| 2189 | 2193 |
| 2190 gl_->Uniform1i(program->y_texture_location(), 1); | 2194 gl_->Uniform1i(current_program_->y_texture_location(), 1); |
| 2191 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { | 2195 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { |
| 2192 gl_->Uniform1i(program->uv_texture_location(), 2); | 2196 gl_->Uniform1i(current_program_->uv_texture_location(), 2); |
| 2193 } else { | 2197 } else { |
| 2194 gl_->Uniform1i(program->u_texture_location(), 2); | 2198 gl_->Uniform1i(current_program_->u_texture_location(), 2); |
| 2195 gl_->Uniform1i(program->v_texture_location(), 3); | 2199 gl_->Uniform1i(current_program_->v_texture_location(), 3); |
| 2196 } | 2200 } |
| 2197 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) | 2201 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) |
| 2198 gl_->Uniform1i(program->a_texture_location(), 4); | 2202 gl_->Uniform1i(current_program_->a_texture_location(), 4); |
| 2199 | 2203 |
| 2200 if (color_conversion_mode == COLOR_CONVERSION_MODE_LUT) { | |
| 2201 ColorLUTCache::LUT lut = color_lut_cache_.GetLUT( | |
| 2202 quad->video_color_space, current_frame()->device_color_space); | |
| 2203 gl_->ActiveTexture(GL_TEXTURE5); | |
| 2204 gl_->BindTexture(GL_TEXTURE_2D, lut.texture); | |
| 2205 gl_->Uniform1i(program->lut_texture_location(), 5); | |
| 2206 gl_->Uniform1f(program->lut_size_location(), lut.size); | |
| 2207 gl_->ActiveTexture(GL_TEXTURE0); | |
| 2208 } | |
| 2209 float yuv_to_rgb_matrix[16] = {0}; | 2204 float yuv_to_rgb_matrix[16] = {0}; |
| 2210 ComputeYUVToRGBMatrices(quad->color_space, quad->bits_per_channel, | 2205 ComputeYUVToRGBMatrices(src_color_space, dst_color_space, |
| 2211 quad->resource_multiplier, quad->resource_offset, | 2206 quad->bits_per_channel, quad->resource_multiplier, |
| 2212 color_conversion_mode, yuv_to_rgb_matrix); | 2207 quad->resource_offset, yuv_to_rgb_matrix); |
| 2213 gl_->UniformMatrix4fv(program->yuv_and_resource_matrix_location(), 1, 0, | 2208 gl_->UniformMatrix4fv(current_program_->yuv_and_resource_matrix_location(), 1, |
| 2214 yuv_to_rgb_matrix); | 2209 0, yuv_to_rgb_matrix); |
| 2215 | 2210 |
| 2216 // The transform and vertex data are used to figure out the extents that the | 2211 // The transform and vertex data are used to figure out the extents that the |
| 2217 // un-antialiased quad should have and which vertex this is and the float | 2212 // un-antialiased quad should have and which vertex this is and the float |
| 2218 // quad passed in via uniform is the actual geometry that gets used to draw | 2213 // quad passed in via uniform is the actual geometry that gets used to draw |
| 2219 // it. This is why this centered rect is used and not the original quad_rect. | 2214 // it. This is why this centered rect is used and not the original quad_rect. |
| 2220 auto tile_rect = gfx::RectF(quad->rect); | 2215 auto tile_rect = gfx::RectF(quad->rect); |
| 2221 | 2216 |
| 2222 SetShaderOpacity(quad); | 2217 SetShaderOpacity(quad); |
| 2223 if (!clip_region) { | 2218 if (!clip_region) { |
| 2224 DrawQuadGeometry(current_frame()->projection_matrix, | 2219 DrawQuadGeometry(current_frame()->projection_matrix, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2241 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2236 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2242 | 2237 |
| 2243 DCHECK(output_surface_->context_provider() | 2238 DCHECK(output_surface_->context_provider() |
| 2244 ->ContextCapabilities() | 2239 ->ContextCapabilities() |
| 2245 .egl_image_external); | 2240 .egl_image_external); |
| 2246 | 2241 |
| 2247 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2242 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2248 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2243 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2249 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2244 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2250 | 2245 |
| 2251 const Program* program = | |
| 2252 GetProgram(ProgramKey::VideoStream(tex_coord_precision)); | |
| 2253 SetUseProgram(program); | |
| 2254 | |
| 2255 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 2246 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2256 quad->resource_id()); | 2247 quad->resource_id()); |
| 2257 | 2248 |
| 2249 SetUseProgram(ProgramKey::VideoStream(tex_coord_precision), |
| 2250 lock.color_space()); |
| 2251 |
| 2258 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2252 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2259 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); | 2253 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); |
| 2260 | 2254 |
| 2261 static float gl_matrix[16]; | 2255 static float gl_matrix[16]; |
| 2262 ToGLMatrix(&gl_matrix[0], quad->matrix); | 2256 ToGLMatrix(&gl_matrix[0], quad->matrix); |
| 2263 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( | 2257 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( |
| 2264 program->tex_matrix_location(), false, gl_matrix); | 2258 current_program_->tex_matrix_location(), false, gl_matrix); |
| 2265 | 2259 |
| 2266 SetShaderOpacity(quad); | 2260 SetShaderOpacity(quad); |
| 2267 if (!clip_region) { | 2261 if (!clip_region) { |
| 2268 DrawQuadGeometry(current_frame()->projection_matrix, | 2262 DrawQuadGeometry(current_frame()->projection_matrix, |
| 2269 quad->shared_quad_state->quad_to_target_transform, | 2263 quad->shared_quad_state->quad_to_target_transform, |
| 2270 gfx::RectF(quad->rect)); | 2264 gfx::RectF(quad->rect)); |
| 2271 } else { | 2265 } else { |
| 2272 gfx::QuadF region_quad(*clip_region); | 2266 gfx::QuadF region_quad(*clip_region); |
| 2273 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); | 2267 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); |
| 2274 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2268 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2275 float uvs[8] = {0}; | 2269 float uvs[8] = {0}; |
| 2276 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2270 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2277 DrawQuadGeometryClippedByQuadF( | 2271 DrawQuadGeometryClippedByQuadF( |
| 2278 quad->shared_quad_state->quad_to_target_transform, | 2272 quad->shared_quad_state->quad_to_target_transform, |
| 2279 gfx::RectF(quad->rect), region_quad, uvs); | 2273 gfx::RectF(quad->rect), region_quad, uvs); |
| 2280 } | 2274 } |
| 2281 } | 2275 } |
| 2282 | 2276 |
| 2283 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { | 2277 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { |
| 2284 // Check to see if we have anything to draw. | 2278 // Check to see if we have anything to draw. |
| 2285 if (!draw_cache_.program) | 2279 if (draw_cache_.is_empty) |
| 2286 return; | 2280 return; |
| 2287 | 2281 |
| 2288 PrepareGeometry(flush_binding); | 2282 PrepareGeometry(flush_binding); |
| 2289 | 2283 |
| 2290 // Set the correct blending mode. | 2284 // Set the correct blending mode. |
| 2291 SetBlendEnabled(draw_cache_.needs_blending); | 2285 SetBlendEnabled(draw_cache_.needs_blending); |
| 2292 | 2286 |
| 2293 // Bind the program to the GL state. | |
| 2294 SetUseProgram(draw_cache_.program); | |
| 2295 | |
| 2296 // Assume the current active textures is 0. | 2287 // Assume the current active textures is 0. |
| 2297 ResourceProvider::ScopedSamplerGL locked_quad( | 2288 ResourceProvider::ScopedSamplerGL locked_quad( |
| 2298 resource_provider_, | 2289 resource_provider_, |
| 2299 draw_cache_.resource_id, | 2290 draw_cache_.resource_id, |
| 2300 draw_cache_.nearest_neighbor ? GL_NEAREST : GL_LINEAR); | 2291 draw_cache_.nearest_neighbor ? GL_NEAREST : GL_LINEAR); |
| 2292 |
| 2293 // Bind the program to the GL state. |
| 2294 SetUseProgram(draw_cache_.program_key, locked_quad.color_space()); |
| 2295 |
| 2301 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2296 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2302 gl_->BindTexture(locked_quad.target(), locked_quad.texture_id()); | 2297 gl_->BindTexture(locked_quad.target(), locked_quad.texture_id()); |
| 2303 | 2298 |
| 2304 static_assert(sizeof(Float4) == 4 * sizeof(float), | 2299 static_assert(sizeof(Float4) == 4 * sizeof(float), |
| 2305 "Float4 struct should be densely packed"); | 2300 "Float4 struct should be densely packed"); |
| 2306 static_assert(sizeof(Float16) == 16 * sizeof(float), | 2301 static_assert(sizeof(Float16) == 16 * sizeof(float), |
| 2307 "Float16 struct should be densely packed"); | 2302 "Float16 struct should be densely packed"); |
| 2308 | 2303 |
| 2309 // Upload the tranforms for both points and uvs. | 2304 // Upload the tranforms for both points and uvs. |
| 2310 gl_->UniformMatrix4fv( | 2305 gl_->UniformMatrix4fv( |
| 2311 draw_cache_.program->matrix_location(), | 2306 current_program_->matrix_location(), |
| 2312 static_cast<int>(draw_cache_.matrix_data.size()), false, | 2307 static_cast<int>(draw_cache_.matrix_data.size()), false, |
| 2313 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); | 2308 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); |
| 2314 gl_->Uniform4fv(draw_cache_.program->vertex_tex_transform_location(), | 2309 gl_->Uniform4fv(current_program_->vertex_tex_transform_location(), |
| 2315 static_cast<int>(draw_cache_.uv_xform_data.size()), | 2310 static_cast<int>(draw_cache_.uv_xform_data.size()), |
| 2316 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())); | 2311 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())); |
| 2317 | 2312 |
| 2318 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { | 2313 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { |
| 2319 Float4 background_color = | 2314 Float4 background_color = |
| 2320 PremultipliedColor(draw_cache_.background_color, 1.f); | 2315 PremultipliedColor(draw_cache_.background_color, 1.f); |
| 2321 gl_->Uniform4fv(draw_cache_.program->background_color_location(), 1, | 2316 gl_->Uniform4fv(current_program_->background_color_location(), 1, |
| 2322 background_color.data); | 2317 background_color.data); |
| 2323 } | 2318 } |
| 2324 | 2319 |
| 2325 gl_->Uniform1fv( | 2320 gl_->Uniform1fv( |
| 2326 draw_cache_.program->vertex_opacity_location(), | 2321 current_program_->vertex_opacity_location(), |
| 2327 static_cast<int>(draw_cache_.vertex_opacity_data.size()), | 2322 static_cast<int>(draw_cache_.vertex_opacity_data.size()), |
| 2328 static_cast<float*>(&draw_cache_.vertex_opacity_data.front())); | 2323 static_cast<float*>(&draw_cache_.vertex_opacity_data.front())); |
| 2329 | 2324 |
| 2330 DCHECK_LE(draw_cache_.matrix_data.size(), | 2325 DCHECK_LE(draw_cache_.matrix_data.size(), |
| 2331 static_cast<size_t>(std::numeric_limits<int>::max()) / 6u); | 2326 static_cast<size_t>(std::numeric_limits<int>::max()) / 6u); |
| 2332 // Draw the quads! | 2327 // Draw the quads! |
| 2333 gl_->DrawElements(GL_TRIANGLES, | 2328 gl_->DrawElements(GL_TRIANGLES, |
| 2334 6 * static_cast<int>(draw_cache_.matrix_data.size()), | 2329 6 * static_cast<int>(draw_cache_.matrix_data.size()), |
| 2335 GL_UNSIGNED_SHORT, 0); | 2330 GL_UNSIGNED_SHORT, 0); |
| 2336 | 2331 |
| 2337 // Draw the border if requested. | 2332 // Draw the border if requested. |
| 2338 if (gl_composited_texture_quad_border_) { | 2333 if (gl_composited_texture_quad_border_) { |
| 2339 // When we draw the composited borders we have one flush per quad. | 2334 // When we draw the composited borders we have one flush per quad. |
| 2340 DCHECK_EQ(1u, draw_cache_.matrix_data.size()); | 2335 DCHECK_EQ(1u, draw_cache_.matrix_data.size()); |
| 2341 SetBlendEnabled(false); | 2336 SetBlendEnabled(false); |
| 2342 const Program* program = GetProgram(ProgramKey::DebugBorder()); | 2337 SetUseProgram(ProgramKey::DebugBorder(), gfx::ColorSpace::CreateSRGB()); |
| 2343 SetUseProgram(program); | |
| 2344 | 2338 |
| 2345 gl_->UniformMatrix4fv( | 2339 gl_->UniformMatrix4fv( |
| 2346 program->matrix_location(), 1, false, | 2340 current_program_->matrix_location(), 1, false, |
| 2347 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); | 2341 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); |
| 2348 | 2342 |
| 2349 // Pick a random color based on the scale on X and Y. | 2343 // Pick a random color based on the scale on X and Y. |
| 2350 int colorIndex = static_cast<int>(draw_cache_.matrix_data.front().data[0] * | 2344 int colorIndex = static_cast<int>(draw_cache_.matrix_data.front().data[0] * |
| 2351 draw_cache_.matrix_data.front().data[5]); | 2345 draw_cache_.matrix_data.front().data[5]); |
| 2352 SkColor color = DebugColors::GLCompositedTextureQuadBorderColor(colorIndex); | 2346 SkColor color = DebugColors::GLCompositedTextureQuadBorderColor(colorIndex); |
| 2353 SetShaderColor(color, 1.f); | 2347 SetShaderColor(color, 1.f); |
| 2354 | 2348 |
| 2355 gl_->LineWidth(DebugColors::GLCompositedTextureQuadBoderWidth()); | 2349 gl_->LineWidth(DebugColors::GLCompositedTextureQuadBoderWidth()); |
| 2356 // The indices for the line are stored in the same array as the triangle | 2350 // The indices for the line are stored in the same array as the triangle |
| 2357 // indices. | 2351 // indices. |
| 2358 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); | 2352 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); |
| 2359 } | 2353 } |
| 2360 | 2354 |
| 2361 // Clear the cache. | 2355 // Clear the cache. |
| 2362 draw_cache_.program = nullptr; | 2356 draw_cache_.is_empty = true; |
| 2363 draw_cache_.resource_id = -1; | 2357 draw_cache_.resource_id = -1; |
| 2364 draw_cache_.uv_xform_data.resize(0); | 2358 draw_cache_.uv_xform_data.resize(0); |
| 2365 draw_cache_.vertex_opacity_data.resize(0); | 2359 draw_cache_.vertex_opacity_data.resize(0); |
| 2366 draw_cache_.matrix_data.resize(0); | 2360 draw_cache_.matrix_data.resize(0); |
| 2367 | 2361 |
| 2368 // 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 |
| 2369 // next inserts. | 2363 // next inserts. |
| 2370 if (flush_binding == CLIPPED_BINDING) { | 2364 if (flush_binding == CLIPPED_BINDING) { |
| 2371 PrepareGeometry(SHARED_BINDING); | 2365 PrepareGeometry(SHARED_BINDING); |
| 2372 } | 2366 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2384 } | 2378 } |
| 2385 | 2379 |
| 2386 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2380 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2387 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2381 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2388 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2382 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2389 | 2383 |
| 2390 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 2384 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2391 quad->resource_id()); | 2385 quad->resource_id()); |
| 2392 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target()); | 2386 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target()); |
| 2393 | 2387 |
| 2394 const Program* program = GetProgram(ProgramKey::Texture( | 2388 ProgramKey program_key = ProgramKey::Texture( |
| 2395 tex_coord_precision, sampler, | 2389 tex_coord_precision, sampler, |
| 2396 quad->premultiplied_alpha ? PREMULTIPLIED_ALPHA : NON_PREMULTIPLIED_ALPHA, | 2390 quad->premultiplied_alpha ? PREMULTIPLIED_ALPHA : NON_PREMULTIPLIED_ALPHA, |
| 2397 quad->background_color != SK_ColorTRANSPARENT)); | 2391 quad->background_color != SK_ColorTRANSPARENT); |
| 2398 int resource_id = quad->resource_id(); | 2392 int resource_id = quad->resource_id(); |
| 2399 | 2393 |
| 2400 size_t max_quads = StaticGeometryBinding::NUM_QUADS; | 2394 size_t max_quads = StaticGeometryBinding::NUM_QUADS; |
| 2401 if (draw_cache_.program != program || | 2395 if (draw_cache_.is_empty || draw_cache_.program_key != program_key || |
| 2402 draw_cache_.resource_id != resource_id || | 2396 draw_cache_.resource_id != resource_id || |
| 2403 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || | 2397 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || |
| 2404 draw_cache_.nearest_neighbor != quad->nearest_neighbor || | 2398 draw_cache_.nearest_neighbor != quad->nearest_neighbor || |
| 2405 draw_cache_.background_color != quad->background_color || | 2399 draw_cache_.background_color != quad->background_color || |
| 2406 draw_cache_.matrix_data.size() >= max_quads) { | 2400 draw_cache_.matrix_data.size() >= max_quads) { |
| 2407 FlushTextureQuadCache(SHARED_BINDING); | 2401 FlushTextureQuadCache(SHARED_BINDING); |
| 2408 draw_cache_.program = program; | 2402 draw_cache_.is_empty = false; |
| 2403 draw_cache_.program_key = program_key; |
| 2409 draw_cache_.resource_id = resource_id; | 2404 draw_cache_.resource_id = resource_id; |
| 2410 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); | 2405 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); |
| 2411 draw_cache_.nearest_neighbor = quad->nearest_neighbor; | 2406 draw_cache_.nearest_neighbor = quad->nearest_neighbor; |
| 2412 draw_cache_.background_color = quad->background_color; | 2407 draw_cache_.background_color = quad->background_color; |
| 2413 } | 2408 } |
| 2414 | 2409 |
| 2415 // Generate the uv-transform | 2410 // Generate the uv-transform |
| 2416 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; | 2411 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; |
| 2417 if (!clip_region) | 2412 if (!clip_region) |
| 2418 uv_transform = UVTransform(quad); | 2413 uv_transform = UVTransform(quad); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 if (request->has_area()) | 2525 if (request->has_area()) |
| 2531 copy_rect.Intersect(request->area()); | 2526 copy_rect.Intersect(request->area()); |
| 2532 GetFramebufferPixelsAsync(copy_rect, std::move(request)); | 2527 GetFramebufferPixelsAsync(copy_rect, std::move(request)); |
| 2533 } | 2528 } |
| 2534 | 2529 |
| 2535 void GLRenderer::ToGLMatrix(float* gl_matrix, const gfx::Transform& transform) { | 2530 void GLRenderer::ToGLMatrix(float* gl_matrix, const gfx::Transform& transform) { |
| 2536 transform.matrix().asColMajorf(gl_matrix); | 2531 transform.matrix().asColMajorf(gl_matrix); |
| 2537 } | 2532 } |
| 2538 | 2533 |
| 2539 void GLRenderer::SetShaderQuadF(const gfx::QuadF& quad) { | 2534 void GLRenderer::SetShaderQuadF(const gfx::QuadF& quad) { |
| 2540 if (!program_shadow_ || program_shadow_->quad_location() == -1) | 2535 if (!current_program_ || current_program_->quad_location() == -1) |
| 2541 return; | 2536 return; |
| 2542 float gl_quad[8]; | 2537 float gl_quad[8]; |
| 2543 gl_quad[0] = quad.p1().x(); | 2538 gl_quad[0] = quad.p1().x(); |
| 2544 gl_quad[1] = quad.p1().y(); | 2539 gl_quad[1] = quad.p1().y(); |
| 2545 gl_quad[2] = quad.p2().x(); | 2540 gl_quad[2] = quad.p2().x(); |
| 2546 gl_quad[3] = quad.p2().y(); | 2541 gl_quad[3] = quad.p2().y(); |
| 2547 gl_quad[4] = quad.p3().x(); | 2542 gl_quad[4] = quad.p3().x(); |
| 2548 gl_quad[5] = quad.p3().y(); | 2543 gl_quad[5] = quad.p3().y(); |
| 2549 gl_quad[6] = quad.p4().x(); | 2544 gl_quad[6] = quad.p4().x(); |
| 2550 gl_quad[7] = quad.p4().y(); | 2545 gl_quad[7] = quad.p4().y(); |
| 2551 gl_->Uniform2fv(program_shadow_->quad_location(), 4, gl_quad); | 2546 gl_->Uniform2fv(current_program_->quad_location(), 4, gl_quad); |
| 2552 } | 2547 } |
| 2553 | 2548 |
| 2554 void GLRenderer::SetShaderOpacity(const DrawQuad* quad) { | 2549 void GLRenderer::SetShaderOpacity(const DrawQuad* quad) { |
| 2555 if (!program_shadow_ || program_shadow_->alpha_location() == -1) | 2550 if (!current_program_ || current_program_->alpha_location() == -1) |
| 2556 return; | 2551 return; |
| 2557 gl_->Uniform1f(program_shadow_->alpha_location(), | 2552 gl_->Uniform1f(current_program_->alpha_location(), |
| 2558 quad->shared_quad_state->opacity); | 2553 quad->shared_quad_state->opacity); |
| 2559 } | 2554 } |
| 2560 | 2555 |
| 2561 void GLRenderer::SetShaderMatrix(const gfx::Transform& transform) { | 2556 void GLRenderer::SetShaderMatrix(const gfx::Transform& transform) { |
| 2562 if (!program_shadow_ || program_shadow_->matrix_location() == -1) | 2557 if (!current_program_ || current_program_->matrix_location() == -1) |
| 2563 return; | 2558 return; |
| 2564 float gl_matrix[16]; | 2559 float gl_matrix[16]; |
| 2565 ToGLMatrix(gl_matrix, transform); | 2560 ToGLMatrix(gl_matrix, transform); |
| 2566 gl_->UniformMatrix4fv(program_shadow_->matrix_location(), 1, false, | 2561 gl_->UniformMatrix4fv(current_program_->matrix_location(), 1, false, |
| 2567 gl_matrix); | 2562 gl_matrix); |
| 2568 } | 2563 } |
| 2569 | 2564 |
| 2570 void GLRenderer::SetShaderColor(SkColor color, float opacity) { | 2565 void GLRenderer::SetShaderColor(SkColor color, float opacity) { |
| 2571 if (!program_shadow_ || program_shadow_->color_location() == -1) | 2566 if (!current_program_ || current_program_->color_location() == -1) |
| 2572 return; | 2567 return; |
| 2573 Float4 float_color = PremultipliedColor(color, opacity); | 2568 Float4 float_color = PremultipliedColor(color, opacity); |
| 2574 gl_->Uniform4fv(program_shadow_->color_location(), 1, float_color.data); | 2569 gl_->Uniform4fv(current_program_->color_location(), 1, float_color.data); |
| 2575 } | 2570 } |
| 2576 | 2571 |
| 2577 void GLRenderer::SetStencilEnabled(bool enabled) { | 2572 void GLRenderer::SetStencilEnabled(bool enabled) { |
| 2578 if (enabled == stencil_shadow_) | 2573 if (enabled == stencil_shadow_) |
| 2579 return; | 2574 return; |
| 2580 | 2575 |
| 2581 if (enabled) | 2576 if (enabled) |
| 2582 gl_->Enable(GL_STENCIL_TEST); | 2577 gl_->Enable(GL_STENCIL_TEST); |
| 2583 else | 2578 else |
| 2584 gl_->Disable(GL_STENCIL_TEST); | 2579 gl_->Disable(GL_STENCIL_TEST); |
| 2585 stencil_shadow_ = enabled; | 2580 stencil_shadow_ = enabled; |
| 2586 } | 2581 } |
| 2587 | 2582 |
| 2588 void GLRenderer::SetBlendEnabled(bool enabled) { | 2583 void GLRenderer::SetBlendEnabled(bool enabled) { |
| 2589 if (enabled == blend_shadow_) | 2584 if (enabled == blend_shadow_) |
| 2590 return; | 2585 return; |
| 2591 | 2586 |
| 2592 if (enabled) | 2587 if (enabled) |
| 2593 gl_->Enable(GL_BLEND); | 2588 gl_->Enable(GL_BLEND); |
| 2594 else | 2589 else |
| 2595 gl_->Disable(GL_BLEND); | 2590 gl_->Disable(GL_BLEND); |
| 2596 blend_shadow_ = enabled; | 2591 blend_shadow_ = enabled; |
| 2597 } | 2592 } |
| 2598 | 2593 |
| 2599 void GLRenderer::SetUseProgram(const Program* program) { | |
| 2600 DCHECK(program); | |
| 2601 DCHECK(program->initialized() || IsContextLost()); | |
| 2602 if (program == program_shadow_) | |
| 2603 return; | |
| 2604 gl_->UseProgram(program->program()); | |
| 2605 | |
| 2606 // Set uniforms that are common to all programs. | |
| 2607 if (program->sampler_location() != -1) | |
| 2608 gl_->Uniform1i(program->sampler_location(), 0); | |
| 2609 if (program->viewport_location() != -1) { | |
| 2610 float viewport[4] = { | |
| 2611 static_cast<float>(current_window_space_viewport_.x()), | |
| 2612 static_cast<float>(current_window_space_viewport_.y()), | |
| 2613 static_cast<float>(current_window_space_viewport_.width()), | |
| 2614 static_cast<float>(current_window_space_viewport_.height()), | |
| 2615 }; | |
| 2616 gl_->Uniform4fv(program->viewport_location(), 1, viewport); | |
| 2617 } | |
| 2618 program_shadow_ = program; | |
| 2619 } | |
| 2620 | |
| 2621 void GLRenderer::DrawQuadGeometryClippedByQuadF( | 2594 void GLRenderer::DrawQuadGeometryClippedByQuadF( |
| 2622 const gfx::Transform& draw_transform, | 2595 const gfx::Transform& draw_transform, |
| 2623 const gfx::RectF& quad_rect, | 2596 const gfx::RectF& quad_rect, |
| 2624 const gfx::QuadF& clipping_region_quad, | 2597 const gfx::QuadF& clipping_region_quad, |
| 2625 const float* uvs) { | 2598 const float* uvs) { |
| 2626 PrepareGeometry(CLIPPED_BINDING); | 2599 PrepareGeometry(CLIPPED_BINDING); |
| 2627 if (uvs) { | 2600 if (uvs) { |
| 2628 clipped_geometry_->InitializeCustomQuadWithUVs(clipping_region_quad, uvs); | 2601 clipped_geometry_->InitializeCustomQuadWithUVs(clipping_region_quad, uvs); |
| 2629 } else { | 2602 } else { |
| 2630 clipped_geometry_->InitializeCustomQuad(clipping_region_quad); | 2603 clipped_geometry_->InitializeCustomQuad(clipping_region_quad); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 break; | 3009 break; |
| 3037 case CLIPPED_BINDING: | 3010 case CLIPPED_BINDING: |
| 3038 clipped_geometry_->PrepareForDraw(); | 3011 clipped_geometry_->PrepareForDraw(); |
| 3039 break; | 3012 break; |
| 3040 case NO_BINDING: | 3013 case NO_BINDING: |
| 3041 break; | 3014 break; |
| 3042 } | 3015 } |
| 3043 bound_geometry_ = binding; | 3016 bound_geometry_ = binding; |
| 3044 } | 3017 } |
| 3045 | 3018 |
| 3046 const Program* GLRenderer::GetProgram(const ProgramKey& desc) { | 3019 void GLRenderer::SetUseProgram(const ProgramKey& program_key, |
| 3047 std::unique_ptr<Program>& program = program_cache_[desc]; | 3020 const gfx::ColorSpace& src_color_space) { |
| 3021 gfx::ColorSpace dst_color_space; |
| 3022 if (settings_->enable_color_correct_rendering) |
| 3023 dst_color_space = current_frame()->device_color_space; |
| 3024 SetUseProgram(program_key, src_color_space, dst_color_space); |
| 3025 } |
| 3026 |
| 3027 void GLRenderer::SetUseProgram(const ProgramKey& program_key_no_color, |
| 3028 const gfx::ColorSpace& src_color_space, |
| 3029 const gfx::ColorSpace& dst_color_space) { |
| 3030 ProgramKey program_key = program_key_no_color; |
| 3031 if (src_color_space.IsValid() && dst_color_space.IsValid()) |
| 3032 program_key.SetColorConversionMode(COLOR_CONVERSION_MODE_LUT); |
| 3033 |
| 3034 // Create and set the program if needed. |
| 3035 std::unique_ptr<Program>& program = program_cache_[program_key]; |
| 3048 if (!program) { | 3036 if (!program) { |
| 3049 program.reset(new Program); | 3037 program.reset(new Program); |
| 3050 program->Initialize(output_surface_->context_provider(), desc); | 3038 program->Initialize(output_surface_->context_provider(), program_key); |
| 3051 } | 3039 } |
| 3052 return program.get(); | 3040 DCHECK(program); |
| 3041 if (current_program_ != program.get()) { |
| 3042 current_program_ = program.get(); |
| 3043 gl_->UseProgram(current_program_->program()); |
| 3044 } |
| 3045 if (!current_program_->initialized()) { |
| 3046 DCHECK(IsContextLost()); |
| 3047 return; |
| 3048 } |
| 3049 |
| 3050 // Set uniforms that are common to all programs. |
| 3051 if (current_program_->sampler_location() != -1) |
| 3052 gl_->Uniform1i(current_program_->sampler_location(), 0); |
| 3053 if (current_program_->viewport_location() != -1) { |
| 3054 float viewport[4] = { |
| 3055 static_cast<float>(current_window_space_viewport_.x()), |
| 3056 static_cast<float>(current_window_space_viewport_.y()), |
| 3057 static_cast<float>(current_window_space_viewport_.width()), |
| 3058 static_cast<float>(current_window_space_viewport_.height()), |
| 3059 }; |
| 3060 gl_->Uniform4fv(current_program_->viewport_location(), 1, viewport); |
| 3061 } |
| 3062 if (current_program_->lut_texture_location() != -1) { |
| 3063 ColorLUTCache::LUT lut = |
| 3064 color_lut_cache_.GetLUT(src_color_space, dst_color_space); |
| 3065 gl_->ActiveTexture(GL_TEXTURE5); |
| 3066 gl_->BindTexture(GL_TEXTURE_2D, lut.texture); |
| 3067 gl_->Uniform1i(current_program_->lut_texture_location(), 5); |
| 3068 gl_->Uniform1f(current_program_->lut_size_location(), lut.size); |
| 3069 gl_->ActiveTexture(GL_TEXTURE0); |
| 3070 } |
| 3053 } | 3071 } |
| 3054 | 3072 |
| 3055 const Program* GLRenderer::GetProgramIfInitialized( | 3073 const Program* GLRenderer::GetProgramIfInitialized( |
| 3056 const ProgramKey& desc) const { | 3074 const ProgramKey& desc) const { |
| 3057 const auto found = program_cache_.find(desc); | 3075 const auto found = program_cache_.find(desc); |
| 3058 if (found == program_cache_.end()) | 3076 if (found == program_cache_.end()) |
| 3059 return nullptr; | 3077 return nullptr; |
| 3060 return found->second.get(); | 3078 return found->second.get(); |
| 3061 } | 3079 } |
| 3062 | 3080 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3074 gl_->DeleteRenderbuffers(1, &offscreen_stencil_renderbuffer_id_); | 3092 gl_->DeleteRenderbuffers(1, &offscreen_stencil_renderbuffer_id_); |
| 3075 | 3093 |
| 3076 ReleaseRenderPassTextures(); | 3094 ReleaseRenderPassTextures(); |
| 3077 } | 3095 } |
| 3078 | 3096 |
| 3079 void GLRenderer::ReinitializeGLState() { | 3097 void GLRenderer::ReinitializeGLState() { |
| 3080 is_scissor_enabled_ = false; | 3098 is_scissor_enabled_ = false; |
| 3081 scissor_rect_ = gfx::Rect(); | 3099 scissor_rect_ = gfx::Rect(); |
| 3082 stencil_shadow_ = false; | 3100 stencil_shadow_ = false; |
| 3083 blend_shadow_ = true; | 3101 blend_shadow_ = true; |
| 3084 program_shadow_ = nullptr; | 3102 current_program_ = nullptr; |
| 3085 | 3103 |
| 3086 RestoreGLState(); | 3104 RestoreGLState(); |
| 3087 } | 3105 } |
| 3088 | 3106 |
| 3089 void GLRenderer::RestoreGLState() { | 3107 void GLRenderer::RestoreGLState() { |
| 3090 // This restores the current GLRenderer state to the GL context. | 3108 // This restores the current GLRenderer state to the GL context. |
| 3091 bound_geometry_ = NO_BINDING; | 3109 bound_geometry_ = NO_BINDING; |
| 3092 PrepareGeometry(SHARED_BINDING); | 3110 PrepareGeometry(SHARED_BINDING); |
| 3093 | 3111 |
| 3094 gl_->Disable(GL_DEPTH_TEST); | 3112 gl_->Disable(GL_DEPTH_TEST); |
| 3095 gl_->Disable(GL_CULL_FACE); | 3113 gl_->Disable(GL_CULL_FACE); |
| 3096 gl_->ColorMask(true, true, true, true); | 3114 gl_->ColorMask(true, true, true, true); |
| 3097 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | 3115 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 3098 gl_->ActiveTexture(GL_TEXTURE0); | 3116 gl_->ActiveTexture(GL_TEXTURE0); |
| 3099 | 3117 |
| 3100 if (program_shadow_) | 3118 if (current_program_) |
| 3101 gl_->UseProgram(program_shadow_->program()); | 3119 gl_->UseProgram(current_program_->program()); |
| 3102 | 3120 |
| 3103 if (stencil_shadow_) | 3121 if (stencil_shadow_) |
| 3104 gl_->Enable(GL_STENCIL_TEST); | 3122 gl_->Enable(GL_STENCIL_TEST); |
| 3105 else | 3123 else |
| 3106 gl_->Disable(GL_STENCIL_TEST); | 3124 gl_->Disable(GL_STENCIL_TEST); |
| 3107 | 3125 |
| 3108 if (blend_shadow_) | 3126 if (blend_shadow_) |
| 3109 gl_->Enable(GL_BLEND); | 3127 gl_->Enable(GL_BLEND); |
| 3110 else | 3128 else |
| 3111 gl_->Disable(GL_BLEND); | 3129 gl_->Disable(GL_BLEND); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3415 DCHECK(stencil_shadow_); | 3433 DCHECK(stencil_shadow_); |
| 3416 | 3434 |
| 3417 // Test only, keep everything. | 3435 // Test only, keep everything. |
| 3418 gl_->StencilOp(GL_KEEP, GL_KEEP, GL_KEEP); | 3436 gl_->StencilOp(GL_KEEP, GL_KEEP, GL_KEEP); |
| 3419 | 3437 |
| 3420 EnsureScissorTestDisabled(); | 3438 EnsureScissorTestDisabled(); |
| 3421 SetBlendEnabled(true); | 3439 SetBlendEnabled(true); |
| 3422 | 3440 |
| 3423 PrepareGeometry(SHARED_BINDING); | 3441 PrepareGeometry(SHARED_BINDING); |
| 3424 | 3442 |
| 3425 const Program* program = GetProgram(ProgramKey::DebugBorder()); | 3443 SetUseProgram(ProgramKey::DebugBorder(), gfx::ColorSpace::CreateSRGB()); |
| 3426 SetUseProgram(program); | |
| 3427 | 3444 |
| 3428 gfx::Transform render_matrix; | 3445 gfx::Transform render_matrix; |
| 3429 render_matrix.Translate(0.5 * output_rect.width() + output_rect.x(), | 3446 render_matrix.Translate(0.5 * output_rect.width() + output_rect.x(), |
| 3430 0.5 * output_rect.height() + output_rect.y()); | 3447 0.5 * output_rect.height() + output_rect.y()); |
| 3431 render_matrix.Scale(output_rect.width(), output_rect.height()); | 3448 render_matrix.Scale(output_rect.width(), output_rect.height()); |
| 3432 SetShaderMatrix(current_frame()->projection_matrix * render_matrix); | 3449 SetShaderMatrix(current_frame()->projection_matrix * render_matrix); |
| 3433 | 3450 |
| 3434 // Produce hinting for the amount of overdraw on screen for each pixel by | 3451 // Produce hinting for the amount of overdraw on screen for each pixel by |
| 3435 // drawing hint colors to the framebuffer based on the current stencil value. | 3452 // drawing hint colors to the framebuffer based on the current stencil value. |
| 3436 struct { | 3453 struct { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3509 return; | 3526 return; |
| 3510 | 3527 |
| 3511 // Report GPU overdraw as a percentage of |max_result|. | 3528 // Report GPU overdraw as a percentage of |max_result|. |
| 3512 TRACE_COUNTER1( | 3529 TRACE_COUNTER1( |
| 3513 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3530 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", |
| 3514 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / | 3531 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / |
| 3515 max_result); | 3532 max_result); |
| 3516 } | 3533 } |
| 3517 | 3534 |
| 3518 } // namespace cc | 3535 } // namespace cc |
| OLD | NEW |