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

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

Issue 2622243003: The great shader refactor: Clean up GLRenderer (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 DirectRenderer::DrawingFrame* frame = nullptr; 174 DirectRenderer::DrawingFrame* frame = nullptr;
175 175
176 // Whether the texture to be sampled from needs to be flipped. 176 // Whether the texture to be sampled from needs to be flipped.
177 bool source_needs_flip = false; 177 bool source_needs_flip = false;
178 178
179 float edge[24]; 179 float edge[24];
180 SkScalar color_matrix[20]; 180 SkScalar color_matrix[20];
181 181
182 // Blending refers to modifications to the backdrop. 182 // Blending refers to modifications to the backdrop.
183 bool use_shaders_for_blending = false; 183 bool use_shaders_for_blending = false;
184 ShaderLocations locations; 184 const Program* program = nullptr;
185 185
186 bool use_aa = false; 186 bool use_aa = false;
187 187
188 // Some filters affect pixels outside the original contents bounds. This 188 // Some filters affect pixels outside the original contents bounds. This
189 // 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
190 // the bounds of the destination. 190 // the bounds of the destination.
191 gfx::Point src_offset; 191 gfx::Point src_offset;
192 gfx::RectF dst_rect; 192 gfx::RectF dst_rect;
193 193
194 // 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 604 }
605 605
606 // This function does not handle 3D sorting right now, since the debug border 606 // This function does not handle 3D sorting right now, since the debug border
607 // quads are just drawn as their original quads and not in split pieces. This 607 // quads are just drawn as their original quads and not in split pieces. This
608 // results in some debug border quads drawing over foreground quads. 608 // results in some debug border quads drawing over foreground quads.
609 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, 609 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame,
610 const DebugBorderDrawQuad* quad) { 610 const DebugBorderDrawQuad* quad) {
611 SetBlendEnabled(quad->ShouldDrawWithBlending()); 611 SetBlendEnabled(quad->ShouldDrawWithBlending());
612 612
613 static float gl_matrix[16]; 613 static float gl_matrix[16];
614 const DebugBorderProgram* program = GetDebugBorderProgram(); 614 const Program* program = GetProgram(ProgramKey::DebugBorder());
615 DCHECK(program && (program->initialized() || IsContextLost())); 615 DCHECK(program && (program->initialized() || IsContextLost()));
616 SetUseProgram(program->program()); 616 SetUseProgram(program->program());
617 617
618 // Use the full quad_rect for debug quads to not move the edges based on 618 // Use the full quad_rect for debug quads to not move the edges based on
619 // partial swaps. 619 // partial swaps.
620 gfx::Rect layer_rect = quad->rect; 620 gfx::Rect layer_rect = quad->rect;
621 gfx::Transform render_matrix; 621 gfx::Transform render_matrix;
622 QuadRectTransform(&render_matrix, 622 QuadRectTransform(&render_matrix,
623 quad->shared_quad_state->quad_to_target_transform, 623 quad->shared_quad_state->quad_to_target_transform,
624 gfx::RectF(layer_rect)); 624 gfx::RectF(layer_rect));
625 GLRenderer::ToGLMatrix(&gl_matrix[0], 625 GLRenderer::ToGLMatrix(&gl_matrix[0],
626 frame->projection_matrix * render_matrix); 626 frame->projection_matrix * render_matrix);
627 gl_->UniformMatrix4fv(program->vertex_shader().matrix_location(), 1, false, 627 gl_->UniformMatrix4fv(program->matrix_location(), 1, false, &gl_matrix[0]);
628 &gl_matrix[0]);
629 628
630 SkColor color = quad->color; 629 SkColor color = quad->color;
631 float alpha = SkColorGetA(color) * (1.0f / 255.0f); 630 float alpha = SkColorGetA(color) * (1.0f / 255.0f);
632 631
633 gl_->Uniform4f(program->fragment_shader().color_location(), 632 gl_->Uniform4f(program->color_location(),
634 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, 633 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha,
635 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, 634 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha,
636 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, alpha); 635 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, alpha);
637 636
638 gl_->LineWidth(quad->width); 637 gl_->LineWidth(quad->width);
639 638
640 // The indices for the line are stored in the same array as the triangle 639 // The indices for the line are stored in the same array as the triangle
641 // indices. 640 // indices.
642 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); 641 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0);
643 } 642 }
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 void GLRenderer::ChooseRPDQProgram(DrawRenderPassDrawQuadParams* params) { 1309 void GLRenderer::ChooseRPDQProgram(DrawRenderPassDrawQuadParams* params) {
1311 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1310 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1312 gl_, &highp_threshold_cache_, highp_threshold_min_, 1311 gl_, &highp_threshold_cache_, highp_threshold_min_,
1313 params->quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); 1312 params->quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
1314 1313
1315 BlendMode shader_blend_mode = 1314 BlendMode shader_blend_mode =
1316 params->use_shaders_for_blending 1315 params->use_shaders_for_blending
1317 ? BlendModeFromSkXfermode(params->quad->shared_quad_state->blend_mode) 1316 ? BlendModeFromSkXfermode(params->quad->shared_quad_state->blend_mode)
1318 : BLEND_MODE_NONE; 1317 : BLEND_MODE_NONE;
1319 1318
1320 unsigned mask_texture_id = 0; 1319 SamplerType sampler_type = SAMPLER_TYPE_2D;
1321 SamplerType mask_sampler = SAMPLER_TYPE_NA; 1320 MaskMode mask_mode = NO_MASK;
1321 bool mask_for_background = params->mask_for_background;
1322 if (params->mask_resource_lock) { 1322 if (params->mask_resource_lock) {
1323 mask_texture_id = params->mask_resource_lock->texture_id(); 1323 mask_mode = HAS_MASK;
1324 mask_sampler = 1324 sampler_type =
1325 SamplerTypeFromTextureTarget(params->mask_resource_lock->target()); 1325 SamplerTypeFromTextureTarget(params->mask_resource_lock->target());
1326 } 1326 }
1327 bool mask_for_background = params->mask_for_background;
1328 1327
1329 if (params->use_aa && mask_texture_id && !params->use_color_matrix) { 1328 params->program = GetProgram(ProgramKey::RenderPass(
1330 const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA( 1329 tex_coord_precision, sampler_type, shader_blend_mode,
1331 tex_coord_precision, mask_sampler, 1330 params->use_aa ? USE_AA : NO_AA, mask_mode, mask_for_background,
1332 shader_blend_mode, mask_for_background); 1331 params->use_color_matrix));
1333 SetUseProgram(program->program()); 1332 SetUseProgram(params->program->program());
1334 program->vertex_shader().FillLocations(&params->locations); 1333 gl_->Uniform1i(params->program->sampler_location(), 0);
1335 program->fragment_shader().FillLocations(&params->locations);
1336 gl_->Uniform1i(params->locations.sampler, 0);
1337 } else if (!params->use_aa && mask_texture_id && !params->use_color_matrix) {
1338 const RenderPassMaskProgram* program = GetRenderPassMaskProgram(
1339 tex_coord_precision, mask_sampler,
1340 shader_blend_mode, mask_for_background);
1341 SetUseProgram(program->program());
1342 program->vertex_shader().FillLocations(&params->locations);
1343 program->fragment_shader().FillLocations(&params->locations);
1344 gl_->Uniform1i(params->locations.sampler, 0);
1345 } else if (params->use_aa && !mask_texture_id && !params->use_color_matrix) {
1346 const RenderPassProgramAA* program =
1347 GetRenderPassProgramAA(tex_coord_precision, shader_blend_mode);
1348 SetUseProgram(program->program());
1349 program->vertex_shader().FillLocations(&params->locations);
1350 program->fragment_shader().FillLocations(&params->locations);
1351 gl_->Uniform1i(params->locations.sampler, 0);
1352 } else if (params->use_aa && mask_texture_id && params->use_color_matrix) {
1353 const RenderPassMaskColorMatrixProgramAA* program =
1354 GetRenderPassMaskColorMatrixProgramAA(
1355 tex_coord_precision, mask_sampler,
1356 shader_blend_mode, mask_for_background);
1357 SetUseProgram(program->program());
1358 program->vertex_shader().FillLocations(&params->locations);
1359 program->fragment_shader().FillLocations(&params->locations);
1360 gl_->Uniform1i(params->locations.sampler, 0);
1361 } else if (params->use_aa && !mask_texture_id && params->use_color_matrix) {
1362 const RenderPassColorMatrixProgramAA* program =
1363 GetRenderPassColorMatrixProgramAA(tex_coord_precision,
1364 shader_blend_mode);
1365 SetUseProgram(program->program());
1366 program->vertex_shader().FillLocations(&params->locations);
1367 program->fragment_shader().FillLocations(&params->locations);
1368 gl_->Uniform1i(params->locations.sampler, 0);
1369 } else if (!params->use_aa && mask_texture_id && params->use_color_matrix) {
1370 const RenderPassMaskColorMatrixProgram* program =
1371 GetRenderPassMaskColorMatrixProgram(
1372 tex_coord_precision, mask_sampler,
1373 shader_blend_mode, mask_for_background);
1374 SetUseProgram(program->program());
1375 program->vertex_shader().FillLocations(&params->locations);
1376 program->fragment_shader().FillLocations(&params->locations);
1377 gl_->Uniform1i(params->locations.sampler, 0);
1378 } else if (!params->use_aa && !mask_texture_id && params->use_color_matrix) {
1379 const RenderPassColorMatrixProgram* program =
1380 GetRenderPassColorMatrixProgram(tex_coord_precision, shader_blend_mode);
1381 SetUseProgram(program->program());
1382 program->vertex_shader().FillLocations(&params->locations);
1383 program->fragment_shader().FillLocations(&params->locations);
1384 gl_->Uniform1i(params->locations.sampler, 0);
1385 } else {
1386 const RenderPassProgram* program =
1387 GetRenderPassProgram(tex_coord_precision, shader_blend_mode);
1388 SetUseProgram(program->program());
1389 program->vertex_shader().FillLocations(&params->locations);
1390 program->fragment_shader().FillLocations(&params->locations);
1391 gl_->Uniform1i(params->locations.sampler, 0);
1392 }
1393 } 1334 }
1394 1335
1395 void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) { 1336 void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) {
1396 ShaderLocations& locations = params->locations; 1337 const Program* program = params->program;
1338
1397 gfx::RectF tex_rect(params->src_offset.x(), params->src_offset.y(), 1339 gfx::RectF tex_rect(params->src_offset.x(), params->src_offset.y(),
1398 params->dst_rect.width(), params->dst_rect.height()); 1340 params->dst_rect.width(), params->dst_rect.height());
1399 gfx::Size texture_size; 1341 gfx::Size texture_size;
1400 if (params->filter_image) { 1342 if (params->filter_image) {
1401 texture_size.set_width(params->filter_image->width()); 1343 texture_size.set_width(params->filter_image->width());
1402 texture_size.set_height(params->filter_image->height()); 1344 texture_size.set_height(params->filter_image->height());
1403 } else { 1345 } else {
1404 texture_size = params->contents_texture->size(); 1346 texture_size = params->contents_texture->size();
1405 } 1347 }
1406 tex_rect.Scale(1.0f / texture_size.width(), 1.0f / texture_size.height()); 1348 tex_rect.Scale(1.0f / texture_size.width(), 1.0f / texture_size.height());
1407 1349
1408 DCHECK(locations.vertex_tex_transform != -1 || IsContextLost()); 1350 DCHECK(program->vertex_tex_transform_location() != -1 || IsContextLost());
1409 if (params->source_needs_flip) { 1351 if (params->source_needs_flip) {
1410 // Flip the content vertically in the shader, as the RenderPass input 1352 // Flip the content vertically in the shader, as the RenderPass input
1411 // texture is already oriented the same way as the framebuffer, but the 1353 // texture is already oriented the same way as the framebuffer, but the
1412 // projection transform does a flip. 1354 // projection transform does a flip.
1413 gl_->Uniform4f(locations.vertex_tex_transform, tex_rect.x(), 1355 gl_->Uniform4f(program->vertex_tex_transform_location(), tex_rect.x(),
1414 1.0f - tex_rect.y(), tex_rect.width(), -tex_rect.height()); 1356 1.0f - tex_rect.y(), tex_rect.width(), -tex_rect.height());
1415 } else { 1357 } else {
1416 // Tile textures are oriented opposite the framebuffer, so can use 1358 // Tile textures are oriented opposite the framebuffer, so can use
1417 // the projection transform to do the flip. 1359 // the projection transform to do the flip.
1418 gl_->Uniform4f(locations.vertex_tex_transform, tex_rect.x(), tex_rect.y(), 1360 gl_->Uniform4f(program->vertex_tex_transform_location(), tex_rect.x(),
1419 tex_rect.width(), tex_rect.height()); 1361 tex_rect.y(), tex_rect.width(), tex_rect.height());
1420 } 1362 }
1421 1363
1422 GLint last_texture_unit = 0; 1364 GLint last_texture_unit = 0;
1423 if (locations.mask_sampler != -1) { 1365 if (program->mask_sampler_location() != -1) {
1424 DCHECK(params->mask_resource_lock); 1366 DCHECK(params->mask_resource_lock);
1425 DCHECK_NE(locations.mask_tex_coord_scale, 1); 1367 DCHECK_NE(program->mask_tex_coord_scale_location(), 1);
1426 DCHECK_NE(locations.mask_tex_coord_offset, 1); 1368 DCHECK_NE(program->mask_tex_coord_offset_location(), 1);
1427 gl_->Uniform1i(locations.mask_sampler, 1); 1369 gl_->Uniform1i(program->mask_sampler_location(), 1);
1428 1370
1429 gfx::RectF mask_uv_rect = params->quad->MaskUVRect(); 1371 gfx::RectF mask_uv_rect = params->quad->MaskUVRect();
1430 if (SamplerTypeFromTextureTarget(params->mask_resource_lock->target()) != 1372 if (SamplerTypeFromTextureTarget(params->mask_resource_lock->target()) !=
1431 SAMPLER_TYPE_2D) { 1373 SAMPLER_TYPE_2D) {
1432 mask_uv_rect.Scale(params->quad->mask_texture_size.width(), 1374 mask_uv_rect.Scale(params->quad->mask_texture_size.width(),
1433 params->quad->mask_texture_size.height()); 1375 params->quad->mask_texture_size.height());
1434 } 1376 }
1435 if (params->source_needs_flip) { 1377 if (params->source_needs_flip) {
1436 // Mask textures are oriented vertically flipped relative to the 1378 // Mask textures are oriented vertically flipped relative to the
1437 // framebuffer and the RenderPass contents texture, so we flip the tex 1379 // framebuffer and the RenderPass contents texture, so we flip the tex
1438 // coords from the RenderPass texture to find the mask texture coords. 1380 // coords from the RenderPass texture to find the mask texture coords.
1439 gl_->Uniform2f( 1381 gl_->Uniform2f(
1440 locations.mask_tex_coord_offset, mask_uv_rect.x(), 1382 program->mask_tex_coord_offset_location(), mask_uv_rect.x(),
1441 mask_uv_rect.height() / tex_rect.height() + mask_uv_rect.y()); 1383 mask_uv_rect.height() / tex_rect.height() + mask_uv_rect.y());
1442 gl_->Uniform2f(locations.mask_tex_coord_scale, 1384 gl_->Uniform2f(program->mask_tex_coord_scale_location(),
1443 mask_uv_rect.width() / tex_rect.width(), 1385 mask_uv_rect.width() / tex_rect.width(),
1444 -mask_uv_rect.height() / tex_rect.height()); 1386 -mask_uv_rect.height() / tex_rect.height());
1445 } else { 1387 } else {
1446 // Tile textures are oriented the same way as mask textures. 1388 // Tile textures are oriented the same way as mask textures.
1447 gl_->Uniform2f(locations.mask_tex_coord_offset, mask_uv_rect.x(), 1389 gl_->Uniform2f(program->mask_tex_coord_offset_location(),
1448 mask_uv_rect.y()); 1390 mask_uv_rect.x(), mask_uv_rect.y());
1449 gl_->Uniform2f(locations.mask_tex_coord_scale, 1391 gl_->Uniform2f(program->mask_tex_coord_scale_location(),
1450 mask_uv_rect.width() / tex_rect.width(), 1392 mask_uv_rect.width() / tex_rect.width(),
1451 mask_uv_rect.height() / tex_rect.height()); 1393 mask_uv_rect.height() / tex_rect.height());
1452 } 1394 }
1453 1395
1454 last_texture_unit = 1; 1396 last_texture_unit = 1;
1455 } 1397 }
1456 1398
1457 if (locations.edge != -1) 1399 if (program->edge_location() != -1)
1458 gl_->Uniform3fv(locations.edge, 8, params->edge); 1400 gl_->Uniform3fv(program->edge_location(), 8, params->edge);
1459 1401
1460 if (locations.viewport != -1) { 1402 if (program->viewport_location() != -1) {
1461 float viewport[4] = { 1403 float viewport[4] = {
1462 static_cast<float>(current_window_space_viewport_.x()), 1404 static_cast<float>(current_window_space_viewport_.x()),
1463 static_cast<float>(current_window_space_viewport_.y()), 1405 static_cast<float>(current_window_space_viewport_.y()),
1464 static_cast<float>(current_window_space_viewport_.width()), 1406 static_cast<float>(current_window_space_viewport_.width()),
1465 static_cast<float>(current_window_space_viewport_.height()), 1407 static_cast<float>(current_window_space_viewport_.height()),
1466 }; 1408 };
1467 gl_->Uniform4fv(locations.viewport, 1, viewport); 1409 gl_->Uniform4fv(program->viewport_location(), 1, viewport);
1468 } 1410 }
1469 1411
1470 if (locations.color_matrix != -1) { 1412 if (program->color_matrix_location() != -1) {
1471 float matrix[16]; 1413 float matrix[16];
1472 for (int i = 0; i < 4; ++i) { 1414 for (int i = 0; i < 4; ++i) {
1473 for (int j = 0; j < 4; ++j) 1415 for (int j = 0; j < 4; ++j)
1474 matrix[i * 4 + j] = SkScalarToFloat(params->color_matrix[j * 5 + i]); 1416 matrix[i * 4 + j] = SkScalarToFloat(params->color_matrix[j * 5 + i]);
1475 } 1417 }
1476 gl_->UniformMatrix4fv(locations.color_matrix, 1, false, matrix); 1418 gl_->UniformMatrix4fv(program->color_matrix_location(), 1, false, matrix);
1477 } 1419 }
1478 static const float kScale = 1.0f / 255.0f; 1420 static const float kScale = 1.0f / 255.0f;
1479 if (locations.color_offset != -1) { 1421 if (program->color_offset_location() != -1) {
1480 float offset[4]; 1422 float offset[4];
1481 for (int i = 0; i < 4; ++i) 1423 for (int i = 0; i < 4; ++i)
1482 offset[i] = SkScalarToFloat(params->color_matrix[i * 5 + 4]) * kScale; 1424 offset[i] = SkScalarToFloat(params->color_matrix[i * 5 + 4]) * kScale;
1483 1425
1484 gl_->Uniform4fv(locations.color_offset, 1, offset); 1426 gl_->Uniform4fv(program->color_offset_location(), 1, offset);
1485 } 1427 }
1486 1428
1487 if (locations.backdrop != -1) { 1429 if (program->backdrop_location() != -1) {
1488 DCHECK(params->background_texture || params->background_image_id); 1430 DCHECK(params->background_texture || params->background_image_id);
1489 DCHECK_NE(locations.backdrop, 0); 1431 DCHECK_NE(program->backdrop_location(), 0);
1490 DCHECK_NE(locations.backdrop_rect, 0); 1432 DCHECK_NE(program->backdrop_rect_location(), 0);
1491 1433
1492 gl_->Uniform1i(locations.backdrop, ++last_texture_unit); 1434 gl_->Uniform1i(program->backdrop_location(), ++last_texture_unit);
1493 1435
1494 gl_->Uniform4f(locations.backdrop_rect, params->background_rect.x(), 1436 gl_->Uniform4f(program->backdrop_rect_location(),
1495 params->background_rect.y(), params->background_rect.width(), 1437 params->background_rect.x(), params->background_rect.y(),
1438 params->background_rect.width(),
1496 params->background_rect.height()); 1439 params->background_rect.height());
1497 1440
1498 if (params->background_image_id) { 1441 if (params->background_image_id) {
1499 gl_->ActiveTexture(GL_TEXTURE0 + last_texture_unit); 1442 gl_->ActiveTexture(GL_TEXTURE0 + last_texture_unit);
1500 gl_->BindTexture(GL_TEXTURE_2D, params->background_image_id); 1443 gl_->BindTexture(GL_TEXTURE_2D, params->background_image_id);
1501 gl_->ActiveTexture(GL_TEXTURE0); 1444 gl_->ActiveTexture(GL_TEXTURE0);
1502 if (params->mask_for_background) 1445 if (params->mask_for_background)
1503 gl_->Uniform1i(locations.original_backdrop, ++last_texture_unit); 1446 gl_->Uniform1i(program->original_backdrop_location(),
1447 ++last_texture_unit);
1504 } 1448 }
1505 if (params->background_texture) { 1449 if (params->background_texture) {
1506 params->shader_background_sampler_lock = 1450 params->shader_background_sampler_lock =
1507 base::MakeUnique<ResourceProvider::ScopedSamplerGL>( 1451 base::MakeUnique<ResourceProvider::ScopedSamplerGL>(
1508 resource_provider_, params->background_texture->id(), 1452 resource_provider_, params->background_texture->id(),
1509 GL_TEXTURE0 + last_texture_unit, GL_LINEAR); 1453 GL_TEXTURE0 + last_texture_unit, GL_LINEAR);
1510 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1454 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1511 params->shader_background_sampler_lock->target()); 1455 params->shader_background_sampler_lock->target());
1512 } 1456 }
1513 } 1457 }
1514 1458
1515 SetShaderOpacity(params->quad->shared_quad_state->opacity, locations.alpha); 1459 SetShaderOpacity(params->quad->shared_quad_state->opacity,
1516 SetShaderQuadF(params->surface_quad, locations.quad); 1460 program->alpha_location());
1461 SetShaderQuadF(params->surface_quad, program->quad_location());
1517 } 1462 }
1518 1463
1519 void GLRenderer::DrawRPDQ(const DrawRenderPassDrawQuadParams& params) { 1464 void GLRenderer::DrawRPDQ(const DrawRenderPassDrawQuadParams& params) {
1520 DrawQuadGeometry(params.projection_matrix, params.quad_to_target_transform, 1465 DrawQuadGeometry(params.projection_matrix, params.quad_to_target_transform,
1521 params.dst_rect, params.locations.matrix); 1466 params.dst_rect, params.program->matrix_location());
1522 1467
1523 // Flush the compositor context before the filter bitmap goes out of 1468 // Flush the compositor context before the filter bitmap goes out of
1524 // scope, so the draw gets processed before the filter texture gets deleted. 1469 // scope, so the draw gets processed before the filter texture gets deleted.
1525 if (params.filter_image) 1470 if (params.filter_image)
1526 gl_->Flush(); 1471 gl_->Flush();
1527 1472
1528 if (!params.use_shaders_for_blending) 1473 if (!params.use_shaders_for_blending)
1529 RestoreBlendFuncToDefault(params.quad->shared_quad_state->blend_mode); 1474 RestoreBlendFuncToDefault(params.quad->shared_quad_state->blend_mode);
1530 } 1475 }
1531 1476
1532 struct SolidColorProgramUniforms {
1533 unsigned program;
1534 unsigned matrix_location;
1535 unsigned viewport_location;
1536 unsigned quad_location;
1537 unsigned edge_location;
1538 unsigned color_location;
1539 };
1540
1541 template <class T>
1542 static void SolidColorUniformLocation(T program,
1543 SolidColorProgramUniforms* uniforms) {
1544 uniforms->program = program->program();
1545 uniforms->matrix_location = program->vertex_shader().matrix_location();
1546 uniforms->viewport_location = program->vertex_shader().viewport_location();
1547 uniforms->quad_location = program->vertex_shader().quad_location();
1548 uniforms->edge_location = program->vertex_shader().edge_location();
1549 uniforms->color_location = program->fragment_shader().color_location();
1550 }
1551
1552 namespace { 1477 namespace {
1553 // These functions determine if a quad, clipped by a clip_region contains 1478 // These functions determine if a quad, clipped by a clip_region contains
1554 // the entire {top|bottom|left|right} edge. 1479 // the entire {top|bottom|left|right} edge.
1555 bool is_top(const gfx::QuadF* clip_region, const DrawQuad* quad) { 1480 bool is_top(const gfx::QuadF* clip_region, const DrawQuad* quad) {
1556 if (!quad->IsTopEdge()) 1481 if (!quad->IsTopEdge())
1557 return false; 1482 return false;
1558 if (!clip_region) 1483 if (!clip_region)
1559 return true; 1484 return true;
1560 1485
1561 return std::abs(clip_region->p1().y()) < kAntiAliasingEpsilon && 1486 return std::abs(clip_region->p1().y()) < kAntiAliasingEpsilon &&
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), 1772 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)),
1848 &clipped); 1773 &clipped);
1849 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); 1774 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa);
1850 } 1775 }
1851 1776
1852 float edge[24]; 1777 float edge[24];
1853 const gfx::QuadF* aa_quad = use_aa ? &device_layer_quad : nullptr; 1778 const gfx::QuadF* aa_quad = use_aa ? &device_layer_quad : nullptr;
1854 SetupQuadForClippingAndAntialiasing(device_transform, quad, aa_quad, 1779 SetupQuadForClippingAndAntialiasing(device_transform, quad, aa_quad,
1855 clip_region, &local_quad, edge); 1780 clip_region, &local_quad, edge);
1856 1781
1857 SolidColorProgramUniforms uniforms; 1782 const Program* program =
1858 if (use_aa) { 1783 GetProgram(ProgramKey::SolidColor(use_aa ? USE_AA : NO_AA));
1859 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); 1784 SetUseProgram(program->program());
1860 } else {
1861 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms);
1862 }
1863 SetUseProgram(uniforms.program);
1864 1785
1865 gl_->Uniform4f(uniforms.color_location, 1786 gl_->Uniform4f(program->color_location(),
1866 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, 1787 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha,
1867 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, 1788 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha,
1868 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, alpha); 1789 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, alpha);
1869 if (use_aa) { 1790 if (use_aa) {
1870 float viewport[4] = { 1791 float viewport[4] = {
1871 static_cast<float>(current_window_space_viewport_.x()), 1792 static_cast<float>(current_window_space_viewport_.x()),
1872 static_cast<float>(current_window_space_viewport_.y()), 1793 static_cast<float>(current_window_space_viewport_.y()),
1873 static_cast<float>(current_window_space_viewport_.width()), 1794 static_cast<float>(current_window_space_viewport_.width()),
1874 static_cast<float>(current_window_space_viewport_.height()), 1795 static_cast<float>(current_window_space_viewport_.height()),
1875 }; 1796 };
1876 gl_->Uniform4fv(uniforms.viewport_location, 1, viewport); 1797 gl_->Uniform4fv(program->viewport_location(), 1, viewport);
1877 gl_->Uniform3fv(uniforms.edge_location, 8, edge); 1798 gl_->Uniform3fv(program->edge_location(), 8, edge);
1878 } 1799 }
1879 1800
1880 // Enable blending when the quad properties require it or if we decided 1801 // Enable blending when the quad properties require it or if we decided
1881 // to use antialiasing. 1802 // to use antialiasing.
1882 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); 1803 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa);
1883 1804
1884 // Antialising requires a normalized quad, but this could lead to floating 1805 // Antialising requires a normalized quad, but this could lead to floating
1885 // point precision errors, so only normalize when antialising is on. 1806 // point precision errors, so only normalize when antialising is on.
1886 if (use_aa) { 1807 if (use_aa) {
1887 // Normalize to tile_rect. 1808 // Normalize to tile_rect.
1888 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); 1809 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
1889 1810
1890 SetShaderQuadF(local_quad, uniforms.quad_location); 1811 SetShaderQuadF(local_quad, program->quad_location());
1891 1812
1892 // The transform and vertex data are used to figure out the extents that the 1813 // The transform and vertex data are used to figure out the extents that the
1893 // un-antialiased quad should have and which vertex this is and the float 1814 // un-antialiased quad should have and which vertex this is and the float
1894 // quad passed in via uniform is the actual geometry that gets used to draw 1815 // quad passed in via uniform is the actual geometry that gets used to draw
1895 // it. This is why this centered rect is used and not the original 1816 // it. This is why this centered rect is used and not the original
1896 // quad_rect. 1817 // quad_rect.
1897 gfx::RectF centered_rect( 1818 gfx::RectF centered_rect(
1898 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), 1819 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()),
1899 gfx::SizeF(tile_rect.size())); 1820 gfx::SizeF(tile_rect.size()));
1900 DrawQuadGeometry(frame->projection_matrix, 1821 DrawQuadGeometry(frame->projection_matrix,
1901 quad->shared_quad_state->quad_to_target_transform, 1822 quad->shared_quad_state->quad_to_target_transform,
1902 centered_rect, uniforms.matrix_location); 1823 centered_rect, program->matrix_location());
1903 } else { 1824 } else {
1904 PrepareGeometry(SHARED_BINDING); 1825 PrepareGeometry(SHARED_BINDING);
1905 SetShaderQuadF(local_quad, uniforms.quad_location); 1826 SetShaderQuadF(local_quad, program->quad_location());
1906 static float gl_matrix[16]; 1827 static float gl_matrix[16];
1907 ToGLMatrix(&gl_matrix[0], 1828 ToGLMatrix(&gl_matrix[0],
1908 frame->projection_matrix * 1829 frame->projection_matrix *
1909 quad->shared_quad_state->quad_to_target_transform); 1830 quad->shared_quad_state->quad_to_target_transform);
1910 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0]); 1831 gl_->UniformMatrix4fv(program->matrix_location(), 1, false, &gl_matrix[0]);
1911 1832
1912 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); 1833 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
1913 } 1834 }
1914 } 1835 }
1915 1836
1916 struct TileProgramUniforms {
1917 unsigned program;
1918 unsigned matrix_location;
1919 unsigned viewport_location;
1920 unsigned quad_location;
1921 unsigned edge_location;
1922 unsigned vertex_tex_transform_location;
1923 unsigned sampler_location;
1924 unsigned fragment_tex_transform_location;
1925 unsigned alpha_location;
1926 };
1927
1928 template <class T>
1929 static void TileUniformLocation(T program, TileProgramUniforms* uniforms) {
1930 uniforms->program = program->program();
1931 uniforms->matrix_location = program->vertex_shader().matrix_location();
1932 uniforms->viewport_location = program->vertex_shader().viewport_location();
1933 uniforms->quad_location = program->vertex_shader().quad_location();
1934 uniforms->edge_location = program->vertex_shader().edge_location();
1935 uniforms->vertex_tex_transform_location =
1936 program->vertex_shader().vertex_tex_transform_location();
1937
1938 uniforms->sampler_location = program->fragment_shader().sampler_location();
1939 uniforms->alpha_location = program->fragment_shader().alpha_location();
1940 uniforms->fragment_tex_transform_location =
1941 program->fragment_shader().fragment_tex_transform_location();
1942 }
1943
1944 void GLRenderer::DrawTileQuad(const DrawingFrame* frame, 1837 void GLRenderer::DrawTileQuad(const DrawingFrame* frame,
1945 const TileDrawQuad* quad, 1838 const TileDrawQuad* quad,
1946 const gfx::QuadF* clip_region) { 1839 const gfx::QuadF* clip_region) {
1947 DrawContentQuad(frame, quad, quad->resource_id(), clip_region); 1840 DrawContentQuad(frame, quad, quad->resource_id(), clip_region);
1948 } 1841 }
1949 1842
1950 void GLRenderer::DrawContentQuad(const DrawingFrame* frame, 1843 void GLRenderer::DrawContentQuad(const DrawingFrame* frame,
1951 const ContentDrawQuadBase* quad, 1844 const ContentDrawQuadBase* quad,
1952 ResourceId resource_id, 1845 ResourceId resource_id,
1953 const gfx::QuadF* clip_region) { 1846 const gfx::QuadF* clip_region) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 // Map to normalized texture coordinates. 1939 // Map to normalized texture coordinates.
2047 if (sampler != SAMPLER_TYPE_2D_RECT) { 1940 if (sampler != SAMPLER_TYPE_2D_RECT) {
2048 gfx::Size texture_size = quad->texture_size; 1941 gfx::Size texture_size = quad->texture_size;
2049 DCHECK(!texture_size.IsEmpty()); 1942 DCHECK(!texture_size.IsEmpty());
2050 fragment_tex_translate_x /= texture_size.width(); 1943 fragment_tex_translate_x /= texture_size.width();
2051 fragment_tex_translate_y /= texture_size.height(); 1944 fragment_tex_translate_y /= texture_size.height();
2052 fragment_tex_scale_x /= texture_size.width(); 1945 fragment_tex_scale_x /= texture_size.width();
2053 fragment_tex_scale_y /= texture_size.height(); 1946 fragment_tex_scale_y /= texture_size.height();
2054 } 1947 }
2055 1948
2056 TileProgramUniforms uniforms; 1949 const Program* program = GetProgram(ProgramKey::Tile(
2057 if (quad->swizzle_contents) { 1950 tex_coord_precision, sampler, USE_AA,
2058 TileUniformLocation(GetTileProgramSwizzleAA(tex_coord_precision, sampler), 1951 quad->swizzle_contents ? DO_SWIZZLE : NO_SWIZZLE, false));
2059 &uniforms);
2060 } else {
2061 TileUniformLocation(GetTileProgramAA(tex_coord_precision, sampler),
2062 &uniforms);
2063 }
2064 1952
2065 SetUseProgram(uniforms.program); 1953 SetUseProgram(program->program());
2066 gl_->Uniform1i(uniforms.sampler_location, 0); 1954 gl_->Uniform1i(program->sampler_location(), 0);
2067 1955
2068 float viewport[4] = { 1956 float viewport[4] = {
2069 static_cast<float>(current_window_space_viewport_.x()), 1957 static_cast<float>(current_window_space_viewport_.x()),
2070 static_cast<float>(current_window_space_viewport_.y()), 1958 static_cast<float>(current_window_space_viewport_.y()),
2071 static_cast<float>(current_window_space_viewport_.width()), 1959 static_cast<float>(current_window_space_viewport_.width()),
2072 static_cast<float>(current_window_space_viewport_.height()), 1960 static_cast<float>(current_window_space_viewport_.height()),
2073 }; 1961 };
2074 gl_->Uniform4fv(uniforms.viewport_location, 1, viewport); 1962 gl_->Uniform4fv(program->viewport_location(), 1, viewport);
2075 gl_->Uniform3fv(uniforms.edge_location, 8, edge); 1963 gl_->Uniform3fv(program->edge_location(), 8, edge);
2076 1964
2077 gl_->Uniform4f(uniforms.vertex_tex_transform_location, vertex_tex_translate_x, 1965 gl_->Uniform4f(program->vertex_tex_transform_location(),
2078 vertex_tex_translate_y, vertex_tex_scale_x, 1966 vertex_tex_translate_x, vertex_tex_translate_y,
2079 vertex_tex_scale_y); 1967 vertex_tex_scale_x, vertex_tex_scale_y);
2080 gl_->Uniform4f(uniforms.fragment_tex_transform_location, 1968 gl_->Uniform4f(program->fragment_tex_transform_location(),
2081 fragment_tex_translate_x, fragment_tex_translate_y, 1969 fragment_tex_translate_x, fragment_tex_translate_y,
2082 fragment_tex_scale_x, fragment_tex_scale_y); 1970 fragment_tex_scale_x, fragment_tex_scale_y);
2083 1971
2084 // Blending is required for antialiasing. 1972 // Blending is required for antialiasing.
2085 SetBlendEnabled(true); 1973 SetBlendEnabled(true);
2086 1974
2087 // Normalize to tile_rect. 1975 // Normalize to tile_rect.
2088 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); 1976 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
2089 1977
2090 SetShaderOpacity(quad->shared_quad_state->opacity, uniforms.alpha_location); 1978 SetShaderOpacity(quad->shared_quad_state->opacity, program->alpha_location());
2091 SetShaderQuadF(local_quad, uniforms.quad_location); 1979 SetShaderQuadF(local_quad, program->quad_location());
2092 1980
2093 // The transform and vertex data are used to figure out the extents that the 1981 // The transform and vertex data are used to figure out the extents that the
2094 // un-antialiased quad should have and which vertex this is and the float 1982 // un-antialiased quad should have and which vertex this is and the float
2095 // quad passed in via uniform is the actual geometry that gets used to draw 1983 // quad passed in via uniform is the actual geometry that gets used to draw
2096 // it. This is why this centered rect is used and not the original quad_rect. 1984 // it. This is why this centered rect is used and not the original quad_rect.
2097 gfx::RectF centered_rect( 1985 gfx::RectF centered_rect(
2098 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), 1986 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()),
2099 gfx::SizeF(tile_rect.size())); 1987 gfx::SizeF(tile_rect.size()));
2100 DrawQuadGeometry(frame->projection_matrix, 1988 DrawQuadGeometry(frame->projection_matrix,
2101 quad->shared_quad_state->quad_to_target_transform, 1989 quad->shared_quad_state->quad_to_target_transform,
2102 centered_rect, uniforms.matrix_location); 1990 centered_rect, program->matrix_location());
2103 } 1991 }
2104 1992
2105 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, 1993 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame,
2106 const ContentDrawQuadBase* quad, 1994 const ContentDrawQuadBase* quad,
2107 ResourceId resource_id, 1995 ResourceId resource_id,
2108 const gfx::QuadF* clip_region) { 1996 const gfx::QuadF* clip_region) {
2109 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( 1997 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional(
2110 quad->tex_coord_rect, gfx::RectF(quad->rect), 1998 quad->tex_coord_rect, gfx::RectF(quad->rect),
2111 gfx::RectF(quad->visible_rect)); 1999 gfx::RectF(quad->visible_rect));
2112 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); 2000 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width();
(...skipping 24 matching lines...) Expand all
2137 DCHECK(!texture_size.IsEmpty()); 2025 DCHECK(!texture_size.IsEmpty());
2138 vertex_tex_translate_x /= texture_size.width(); 2026 vertex_tex_translate_x /= texture_size.width();
2139 vertex_tex_translate_y /= texture_size.height(); 2027 vertex_tex_translate_y /= texture_size.height();
2140 vertex_tex_scale_x /= texture_size.width(); 2028 vertex_tex_scale_x /= texture_size.width();
2141 vertex_tex_scale_y /= texture_size.height(); 2029 vertex_tex_scale_y /= texture_size.height();
2142 } 2030 }
2143 2031
2144 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2032 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2145 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); 2033 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size);
2146 2034
2147 TileProgramUniforms uniforms; 2035 const Program* program = GetProgram(
2148 if (quad->ShouldDrawWithBlending()) { 2036 ProgramKey::Tile(tex_coord_precision, sampler, NO_AA,
2149 if (quad->swizzle_contents) { 2037 quad->swizzle_contents ? DO_SWIZZLE : NO_SWIZZLE,
2150 TileUniformLocation(GetTileProgramSwizzle(tex_coord_precision, sampler), 2038 !quad->ShouldDrawWithBlending()));
2151 &uniforms);
2152 } else {
2153 TileUniformLocation(GetTileProgram(tex_coord_precision, sampler),
2154 &uniforms);
2155 }
2156 } else {
2157 if (quad->swizzle_contents) {
2158 TileUniformLocation(
2159 GetTileProgramSwizzleOpaque(tex_coord_precision, sampler), &uniforms);
2160 } else {
2161 TileUniformLocation(GetTileProgramOpaque(tex_coord_precision, sampler),
2162 &uniforms);
2163 }
2164 }
2165 2039
2166 SetUseProgram(uniforms.program); 2040 SetUseProgram(program->program());
2167 gl_->Uniform1i(uniforms.sampler_location, 0); 2041 gl_->Uniform1i(program->sampler_location(), 0);
2168 2042
2169 gl_->Uniform4f(uniforms.vertex_tex_transform_location, vertex_tex_translate_x, 2043 gl_->Uniform4f(program->vertex_tex_transform_location(),
2170 vertex_tex_translate_y, vertex_tex_scale_x, 2044 vertex_tex_translate_x, vertex_tex_translate_y,
2171 vertex_tex_scale_y); 2045 vertex_tex_scale_x, vertex_tex_scale_y);
2172 2046
2173 SetBlendEnabled(quad->ShouldDrawWithBlending()); 2047 SetBlendEnabled(quad->ShouldDrawWithBlending());
2174 2048
2175 SetShaderOpacity(quad->shared_quad_state->opacity, uniforms.alpha_location); 2049 SetShaderOpacity(quad->shared_quad_state->opacity, program->alpha_location());
2176 2050
2177 // Pass quad coordinates to the uniform in the same order as GeometryBinding 2051 // Pass quad coordinates to the uniform in the same order as GeometryBinding
2178 // does, then vertices will match the texture mapping in the vertex buffer. 2052 // does, then vertices will match the texture mapping in the vertex buffer.
2179 // The method SetShaderQuadF() changes the order of vertices and so it's 2053 // The method SetShaderQuadF() changes the order of vertices and so it's
2180 // not used here. 2054 // not used here.
2181 auto tile_quad = gfx::QuadF(gfx::RectF(quad->visible_rect)); 2055 auto tile_quad = gfx::QuadF(gfx::RectF(quad->visible_rect));
2182 float width = quad->visible_rect.width(); 2056 float width = quad->visible_rect.width();
2183 float height = quad->visible_rect.height(); 2057 float height = quad->visible_rect.height();
2184 auto top_left = gfx::PointF(quad->visible_rect.origin()); 2058 auto top_left = gfx::PointF(quad->visible_rect.origin());
2185 if (clip_region) { 2059 if (clip_region) {
(...skipping 12 matching lines...) Expand all
2198 clipped_geometry_->InitializeCustomQuadWithUVs( 2072 clipped_geometry_->InitializeCustomQuadWithUVs(
2199 gfx::QuadF(gfx::RectF(quad->visible_rect)), gl_uv); 2073 gfx::QuadF(gfx::RectF(quad->visible_rect)), gl_uv);
2200 } else { 2074 } else {
2201 PrepareGeometry(SHARED_BINDING); 2075 PrepareGeometry(SHARED_BINDING);
2202 } 2076 }
2203 float gl_quad[8] = { 2077 float gl_quad[8] = {
2204 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(), 2078 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(),
2205 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(), 2079 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(),
2206 tile_quad.p3().x(), tile_quad.p3().y(), 2080 tile_quad.p3().x(), tile_quad.p3().y(),
2207 }; 2081 };
2208 gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad); 2082 gl_->Uniform2fv(program->quad_location(), 4, gl_quad);
2209 2083
2210 static float gl_matrix[16]; 2084 static float gl_matrix[16];
2211 ToGLMatrix(&gl_matrix[0], 2085 ToGLMatrix(&gl_matrix[0],
2212 frame->projection_matrix * 2086 frame->projection_matrix *
2213 quad->shared_quad_state->quad_to_target_transform); 2087 quad->shared_quad_state->quad_to_target_transform);
2214 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0]); 2088 gl_->UniformMatrix4fv(program->matrix_location(), 1, false, &gl_matrix[0]);
2215 2089
2216 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); 2090 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
2217 } 2091 }
2218 2092
2219 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, 2093 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame,
2220 const YUVVideoDrawQuad* quad, 2094 const YUVVideoDrawQuad* quad,
2221 const gfx::QuadF* clip_region) { 2095 const gfx::QuadF* clip_region) {
2222 SetBlendEnabled(quad->ShouldDrawWithBlending()); 2096 SetBlendEnabled(quad->ShouldDrawWithBlending());
2223 2097
2224 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2098 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2270 int lut_texture_location = -1; 2144 int lut_texture_location = -1;
2271 int yuv_matrix_location = -1; 2145 int yuv_matrix_location = -1;
2272 int yuv_adj_location = -1; 2146 int yuv_adj_location = -1;
2273 int alpha_location = -1; 2147 int alpha_location = -1;
2274 int resource_multiplier_location = -1; 2148 int resource_multiplier_location = -1;
2275 int resource_offset_location = -1; 2149 int resource_offset_location = -1;
2276 const VideoYUVProgram* program = GetVideoYUVProgram( 2150 const VideoYUVProgram* program = GetVideoYUVProgram(
2277 tex_coord_precision, sampler, use_alpha_plane, use_nv12, use_color_lut); 2151 tex_coord_precision, sampler, use_alpha_plane, use_nv12, use_color_lut);
2278 DCHECK(program && (program->initialized() || IsContextLost())); 2152 DCHECK(program && (program->initialized() || IsContextLost()));
2279 SetUseProgram(program->program()); 2153 SetUseProgram(program->program());
2280 matrix_location = program->vertex_shader().matrix_location(); 2154 matrix_location = program->matrix_location();
2281 ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location(); 2155 ya_tex_scale_location = program->ya_tex_scale_location();
2282 ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location(); 2156 ya_tex_offset_location = program->ya_tex_offset_location();
2283 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location(); 2157 uv_tex_scale_location = program->uv_tex_scale_location();
2284 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location(); 2158 uv_tex_offset_location = program->uv_tex_offset_location();
2285 y_texture_location = program->fragment_shader().y_texture_location(); 2159 y_texture_location = program->fragment_shader().y_texture_location();
2286 u_texture_location = program->fragment_shader().u_texture_location(); 2160 u_texture_location = program->fragment_shader().u_texture_location();
2287 v_texture_location = program->fragment_shader().v_texture_location(); 2161 v_texture_location = program->fragment_shader().v_texture_location();
2288 uv_texture_location = program->fragment_shader().uv_texture_location(); 2162 uv_texture_location = program->fragment_shader().uv_texture_location();
2289 a_texture_location = program->fragment_shader().a_texture_location(); 2163 a_texture_location = program->fragment_shader().a_texture_location();
2290 lut_texture_location = program->fragment_shader().lut_texture_location(); 2164 lut_texture_location = program->fragment_shader().lut_texture_location();
2291 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); 2165 yuv_matrix_location = program->fragment_shader().yuv_matrix_location();
2292 yuv_adj_location = program->fragment_shader().yuv_adj_location(); 2166 yuv_adj_location = program->fragment_shader().yuv_adj_location();
2293 ya_clamp_rect_location = program->fragment_shader().ya_clamp_rect_location(); 2167 ya_clamp_rect_location = program->fragment_shader().ya_clamp_rect_location();
2294 uv_clamp_rect_location = program->fragment_shader().uv_clamp_rect_location(); 2168 uv_clamp_rect_location = program->fragment_shader().uv_clamp_rect_location();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 static float gl_matrix[16]; 2350 static float gl_matrix[16];
2477 2351
2478 DCHECK(output_surface_->context_provider() 2352 DCHECK(output_surface_->context_provider()
2479 ->ContextCapabilities() 2353 ->ContextCapabilities()
2480 .egl_image_external); 2354 .egl_image_external);
2481 2355
2482 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2356 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2483 gl_, &highp_threshold_cache_, highp_threshold_min_, 2357 gl_, &highp_threshold_cache_, highp_threshold_min_,
2484 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); 2358 quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
2485 2359
2486 const VideoStreamTextureProgram* program = 2360 const Program* program =
2487 GetVideoStreamTextureProgram(tex_coord_precision); 2361 GetProgram(ProgramKey::VideoStream(tex_coord_precision));
2488 SetUseProgram(program->program()); 2362 SetUseProgram(program->program());
2489 2363
2490 ToGLMatrix(&gl_matrix[0], quad->matrix); 2364 ToGLMatrix(&gl_matrix[0], quad->matrix);
2491 2365
2492 ResourceProvider::ScopedReadLockGL lock(resource_provider_, 2366 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
2493 quad->resource_id()); 2367 quad->resource_id());
2494 2368
2495 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); 2369 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
2496 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); 2370 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id());
2497 2371
2498 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( 2372 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM(
2499 program->vertex_shader().tex_matrix_location(), false, gl_matrix); 2373 program->tex_matrix_location(), false, gl_matrix);
2500 2374
2501 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); 2375 gl_->Uniform1i(program->sampler_location(), 0);
2502 2376
2503 SetShaderOpacity(quad->shared_quad_state->opacity, 2377 SetShaderOpacity(quad->shared_quad_state->opacity, program->alpha_location());
2504 program->fragment_shader().alpha_location());
2505 if (!clip_region) { 2378 if (!clip_region) {
2506 DrawQuadGeometry(frame->projection_matrix, 2379 DrawQuadGeometry(frame->projection_matrix,
2507 quad->shared_quad_state->quad_to_target_transform, 2380 quad->shared_quad_state->quad_to_target_transform,
2508 gfx::RectF(quad->rect), 2381 gfx::RectF(quad->rect), program->matrix_location());
2509 program->vertex_shader().matrix_location());
2510 } else { 2382 } else {
2511 gfx::QuadF region_quad(*clip_region); 2383 gfx::QuadF region_quad(*clip_region);
2512 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); 2384 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height());
2513 region_quad -= gfx::Vector2dF(0.5f, 0.5f); 2385 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2514 float uvs[8] = {0}; 2386 float uvs[8] = {0};
2515 GetScaledUVs(quad->visible_rect, clip_region, uvs); 2387 GetScaledUVs(quad->visible_rect, clip_region, uvs);
2516 DrawQuadGeometryClippedByQuadF( 2388 DrawQuadGeometryClippedByQuadF(
2517 frame, quad->shared_quad_state->quad_to_target_transform, 2389 frame, quad->shared_quad_state->quad_to_target_transform,
2518 gfx::RectF(quad->rect), region_quad, 2390 gfx::RectF(quad->rect), region_quad, program->matrix_location(), uvs);
2519 program->vertex_shader().matrix_location(), uvs);
2520 } 2391 }
2521 } 2392 }
2522 2393
2523 struct TextureProgramBinding {
2524 template <class Program>
2525 void Set(Program* program) {
2526 DCHECK(program);
2527 program_id = program->program();
2528 sampler_location = program->fragment_shader().sampler_location();
2529 matrix_location = program->vertex_shader().matrix_location();
2530 background_color_location =
2531 program->fragment_shader().background_color_location();
2532 }
2533 int program_id;
2534 int sampler_location;
2535 int matrix_location;
2536 int transform_location;
2537 int background_color_location;
2538 };
2539
2540 struct TexTransformTextureProgramBinding : TextureProgramBinding {
2541 template <class Program>
2542 void Set(Program* program) {
2543 TextureProgramBinding::Set(program);
2544 vertex_tex_transform_location =
2545 program->vertex_shader().vertex_tex_transform_location();
2546 vertex_opacity_location =
2547 program->vertex_shader().vertex_opacity_location();
2548 }
2549 int vertex_tex_transform_location;
2550 int vertex_opacity_location;
2551 };
2552
2553 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { 2394 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) {
2554 // Check to see if we have anything to draw. 2395 // Check to see if we have anything to draw.
2555 if (draw_cache_.program_id == -1) 2396 if (draw_cache_.program_id == -1)
2556 return; 2397 return;
2557 2398
2558 PrepareGeometry(flush_binding); 2399 PrepareGeometry(flush_binding);
2559 2400
2560 // Set the correct blending mode. 2401 // Set the correct blending mode.
2561 SetBlendEnabled(draw_cache_.needs_blending); 2402 SetBlendEnabled(draw_cache_.needs_blending);
2562 2403
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 // Draw the quads! 2445 // Draw the quads!
2605 gl_->DrawElements(GL_TRIANGLES, 2446 gl_->DrawElements(GL_TRIANGLES,
2606 6 * static_cast<int>(draw_cache_.matrix_data.size()), 2447 6 * static_cast<int>(draw_cache_.matrix_data.size()),
2607 GL_UNSIGNED_SHORT, 0); 2448 GL_UNSIGNED_SHORT, 0);
2608 2449
2609 // Draw the border if requested. 2450 // Draw the border if requested.
2610 if (gl_composited_texture_quad_border_) { 2451 if (gl_composited_texture_quad_border_) {
2611 // When we draw the composited borders we have one flush per quad. 2452 // When we draw the composited borders we have one flush per quad.
2612 DCHECK_EQ(1u, draw_cache_.matrix_data.size()); 2453 DCHECK_EQ(1u, draw_cache_.matrix_data.size());
2613 SetBlendEnabled(false); 2454 SetBlendEnabled(false);
2614 const DebugBorderProgram* program = GetDebugBorderProgram(); 2455 const Program* program = GetProgram(ProgramKey::DebugBorder());
2615 DCHECK(program && (program->initialized() || IsContextLost())); 2456 DCHECK(program && (program->initialized() || IsContextLost()));
2616 SetUseProgram(program->program()); 2457 SetUseProgram(program->program());
2617 2458
2618 gl_->UniformMatrix4fv( 2459 gl_->UniformMatrix4fv(
2619 program->vertex_shader().matrix_location(), 1, false, 2460 program->matrix_location(), 1, false,
2620 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); 2461 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()));
2621 2462
2622 gl_->Uniform4f(program->fragment_shader().color_location(), 0.0f, 1.0f, 2463 gl_->Uniform4f(program->color_location(), 0.0f, 1.0f, 0.0f, 1.0f);
2623 0.0f, 1.0f);
2624 2464
2625 gl_->LineWidth(3.0f); 2465 gl_->LineWidth(3.0f);
2626 // The indices for the line are stored in the same array as the triangle 2466 // The indices for the line are stored in the same array as the triangle
2627 // indices. 2467 // indices.
2628 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); 2468 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0);
2629 } 2469 }
2630 2470
2631 // Clear the cache. 2471 // Clear the cache.
2632 draw_cache_.program_id = -1; 2472 draw_cache_.program_id = -1;
2633 draw_cache_.uv_xform_data.resize(0); 2473 draw_cache_.uv_xform_data.resize(0);
(...skipping 19 matching lines...) Expand all
2653 FlushTextureQuadCache(SHARED_BINDING); 2493 FlushTextureQuadCache(SHARED_BINDING);
2654 } 2494 }
2655 2495
2656 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2496 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2657 gl_, &highp_threshold_cache_, highp_threshold_min_, 2497 gl_, &highp_threshold_cache_, highp_threshold_min_,
2658 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); 2498 quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
2659 2499
2660 ResourceProvider::ScopedReadLockGL lock(resource_provider_, 2500 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
2661 quad->resource_id()); 2501 quad->resource_id());
2662 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target()); 2502 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target());
2663 // Choose the correct texture program binding
2664 TexTransformTextureProgramBinding binding;
2665 if (quad->premultiplied_alpha) {
2666 if (quad->background_color == SK_ColorTRANSPARENT) {
2667 binding.Set(GetTextureProgram(tex_coord_precision, sampler));
2668 } else {
2669 binding.Set(GetTextureBackgroundProgram(tex_coord_precision, sampler));
2670 }
2671 } else {
2672 if (quad->background_color == SK_ColorTRANSPARENT) {
2673 binding.Set(
2674 GetNonPremultipliedTextureProgram(tex_coord_precision, sampler));
2675 } else {
2676 binding.Set(GetNonPremultipliedTextureBackgroundProgram(
2677 tex_coord_precision, sampler));
2678 }
2679 }
2680 2503
2504 const Program* program = GetProgram(ProgramKey::Texture(
2505 tex_coord_precision, sampler,
2506 quad->premultiplied_alpha ? PREMULTIPLIED_ALPHA : NON_PREMULTIPLIED_ALPHA,
2507 quad->background_color != SK_ColorTRANSPARENT));
2681 int resource_id = quad->resource_id(); 2508 int resource_id = quad->resource_id();
2509 int program_id = program->program();
2682 2510
2683 size_t max_quads = StaticGeometryBinding::NUM_QUADS; 2511 size_t max_quads = StaticGeometryBinding::NUM_QUADS;
2684 if (draw_cache_.program_id != binding.program_id || 2512 if (draw_cache_.program_id != program_id ||
2685 draw_cache_.resource_id != resource_id || 2513 draw_cache_.resource_id != resource_id ||
2686 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || 2514 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() ||
2687 draw_cache_.nearest_neighbor != quad->nearest_neighbor || 2515 draw_cache_.nearest_neighbor != quad->nearest_neighbor ||
2688 draw_cache_.background_color != quad->background_color || 2516 draw_cache_.background_color != quad->background_color ||
2689 draw_cache_.matrix_data.size() >= max_quads) { 2517 draw_cache_.matrix_data.size() >= max_quads) {
2690 FlushTextureQuadCache(SHARED_BINDING); 2518 FlushTextureQuadCache(SHARED_BINDING);
2691 draw_cache_.program_id = binding.program_id; 2519 draw_cache_.program_id = program_id;
2692 draw_cache_.resource_id = resource_id; 2520 draw_cache_.resource_id = resource_id;
2693 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); 2521 draw_cache_.needs_blending = quad->ShouldDrawWithBlending();
2694 draw_cache_.nearest_neighbor = quad->nearest_neighbor; 2522 draw_cache_.nearest_neighbor = quad->nearest_neighbor;
2695 draw_cache_.background_color = quad->background_color; 2523 draw_cache_.background_color = quad->background_color;
2696 2524
2697 draw_cache_.uv_xform_location = binding.vertex_tex_transform_location; 2525 draw_cache_.uv_xform_location = program->vertex_tex_transform_location();
2698 draw_cache_.background_color_location = binding.background_color_location; 2526 draw_cache_.background_color_location =
2699 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; 2527 program->background_color_location();
2700 draw_cache_.matrix_location = binding.matrix_location; 2528 draw_cache_.vertex_opacity_location = program->vertex_opacity_location();
2701 draw_cache_.sampler_location = binding.sampler_location; 2529 draw_cache_.matrix_location = program->matrix_location();
2530 draw_cache_.sampler_location = program->sampler_location();
2702 } 2531 }
2703 2532
2704 // Generate the uv-transform 2533 // Generate the uv-transform
2705 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; 2534 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}};
2706 if (!clip_region) 2535 if (!clip_region)
2707 uv_transform = UVTransform(quad); 2536 uv_transform = UVTransform(quad);
2708 if (sampler == SAMPLER_TYPE_2D_RECT) { 2537 if (sampler == SAMPLER_TYPE_2D_RECT) {
2709 // Un-normalize the texture coordiantes for rectangle targets. 2538 // Un-normalize the texture coordiantes for rectangle targets.
2710 gfx::Size texture_size = lock.size(); 2539 gfx::Size texture_size = lock.size();
2711 uv_transform.data[0] *= texture_size.width(); 2540 uv_transform.data[0] *= texture_size.width();
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
3278 break; 3107 break;
3279 case CLIPPED_BINDING: 3108 case CLIPPED_BINDING:
3280 clipped_geometry_->PrepareForDraw(); 3109 clipped_geometry_->PrepareForDraw();
3281 break; 3110 break;
3282 case NO_BINDING: 3111 case NO_BINDING:
3283 break; 3112 break;
3284 } 3113 }
3285 bound_geometry_ = binding; 3114 bound_geometry_ = binding;
3286 } 3115 }
3287 3116
3288 const GLRenderer::DebugBorderProgram* GLRenderer::GetDebugBorderProgram() {
3289 return GetProgram(ProgramKey::DebugBorder());
3290 }
3291
3292 const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() {
3293 return GetProgram(ProgramKey::SolidColor(NO_AA));
3294 }
3295
3296 const GLRenderer::SolidColorProgramAA* GLRenderer::GetSolidColorProgramAA() {
3297 return GetProgram(ProgramKey::SolidColor(USE_AA));
3298 }
3299
3300 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram(
3301 TexCoordPrecision precision,
3302 BlendMode blend_mode) {
3303 return GetProgram(ProgramKey::RenderPass(
3304 precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, NO_MASK, false, false));
3305 }
3306
3307 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA(
3308 TexCoordPrecision precision,
3309 BlendMode blend_mode) {
3310 return GetProgram(ProgramKey::RenderPass(
3311 precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, NO_MASK, false, false));
3312 }
3313
3314 const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram(
3315 TexCoordPrecision precision,
3316 SamplerType sampler,
3317 BlendMode blend_mode,
3318 bool mask_for_background) {
3319 return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode,
3320 NO_AA, HAS_MASK, mask_for_background,
3321 false));
3322 }
3323
3324 const GLRenderer::RenderPassMaskProgramAA*
3325 GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision,
3326 SamplerType sampler,
3327 BlendMode blend_mode,
3328 bool mask_for_background) {
3329 return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode,
3330 USE_AA, HAS_MASK,
3331 mask_for_background, false));
3332 }
3333
3334 const GLRenderer::RenderPassColorMatrixProgram*
3335 GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision,
3336 BlendMode blend_mode) {
3337 return GetProgram(ProgramKey::RenderPass(
3338 precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, NO_MASK, false, true));
3339 }
3340
3341 const GLRenderer::RenderPassColorMatrixProgramAA*
3342 GLRenderer::GetRenderPassColorMatrixProgramAA(TexCoordPrecision precision,
3343 BlendMode blend_mode) {
3344 return GetProgram(ProgramKey::RenderPass(
3345 precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, NO_MASK, false, true));
3346 }
3347
3348 const GLRenderer::RenderPassMaskColorMatrixProgram*
3349 GLRenderer::GetRenderPassMaskColorMatrixProgram(
3350 TexCoordPrecision precision,
3351 SamplerType sampler,
3352 BlendMode blend_mode,
3353 bool mask_for_background) {
3354 return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode,
3355 NO_AA, HAS_MASK, mask_for_background,
3356 true));
3357 }
3358
3359 const GLRenderer::RenderPassMaskColorMatrixProgramAA*
3360 GLRenderer::GetRenderPassMaskColorMatrixProgramAA(
3361 TexCoordPrecision precision,
3362 SamplerType sampler,
3363 BlendMode blend_mode,
3364 bool mask_for_background) {
3365 return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode,
3366 USE_AA, HAS_MASK,
3367 mask_for_background, true));
3368 }
3369
3370 const GLRenderer::TileProgram* GLRenderer::GetTileProgram(
3371 TexCoordPrecision precision,
3372 SamplerType sampler) {
3373 return GetProgram(
3374 ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, false));
3375 }
3376
3377 const GLRenderer::TileProgramOpaque* GLRenderer::GetTileProgramOpaque(
3378 TexCoordPrecision precision,
3379 SamplerType sampler) {
3380 return GetProgram(
3381 ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, true));
3382 }
3383
3384 const GLRenderer::TileProgramAA* GLRenderer::GetTileProgramAA(
3385 TexCoordPrecision precision,
3386 SamplerType sampler) {
3387 return GetProgram(
3388 ProgramKey::Tile(precision, sampler, USE_AA, NO_SWIZZLE, false));
3389 }
3390
3391 const GLRenderer::TileProgramSwizzle* GLRenderer::GetTileProgramSwizzle(
3392 TexCoordPrecision precision,
3393 SamplerType sampler) {
3394 return GetProgram(
3395 ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, false));
3396 }
3397
3398 const GLRenderer::TileProgramSwizzleOpaque*
3399 GLRenderer::GetTileProgramSwizzleOpaque(TexCoordPrecision precision,
3400 SamplerType sampler) {
3401 return GetProgram(
3402 ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, true));
3403 }
3404
3405 const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA(
3406 TexCoordPrecision precision,
3407 SamplerType sampler) {
3408 return GetProgram(
3409 ProgramKey::Tile(precision, sampler, USE_AA, DO_SWIZZLE, false));
3410 }
3411
3412 const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram(
3413 TexCoordPrecision precision,
3414 SamplerType sampler) {
3415 return GetProgram(
3416 ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, false));
3417 }
3418
3419 const GLRenderer::NonPremultipliedTextureProgram*
3420 GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision,
3421 SamplerType sampler) {
3422 return GetProgram(
3423 ProgramKey::Texture(precision, sampler, NON_PREMULTIPLIED_ALPHA, false));
3424 }
3425
3426 const GLRenderer::TextureBackgroundProgram*
3427 GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision,
3428 SamplerType sampler) {
3429 return GetProgram(
3430 ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, true));
3431 }
3432
3433 const GLRenderer::NonPremultipliedTextureBackgroundProgram*
3434 GLRenderer::GetNonPremultipliedTextureBackgroundProgram(
3435 TexCoordPrecision precision,
3436 SamplerType sampler) {
3437 return GetProgram(
3438 ProgramKey::Texture(precision, sampler, NON_PREMULTIPLIED_ALPHA, true));
3439 }
3440
3441 const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( 3117 const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram(
3442 TexCoordPrecision precision, 3118 TexCoordPrecision precision,
3443 SamplerType sampler, 3119 SamplerType sampler,
3444 bool use_alpha_plane, 3120 bool use_alpha_plane,
3445 bool use_nv12, 3121 bool use_nv12,
3446 bool use_color_lut) { 3122 bool use_color_lut) {
3447 DCHECK_GE(precision, 0); 3123 DCHECK_GE(precision, 0);
3448 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 3124 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
3449 DCHECK_GE(sampler, 0); 3125 DCHECK_GE(sampler, 0);
3450 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 3126 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
3451 VideoYUVProgram* program = 3127 VideoYUVProgram* program =
3452 &video_yuv_program_[precision][sampler][use_alpha_plane][use_nv12] 3128 &video_yuv_program_[precision][sampler][use_alpha_plane][use_nv12]
3453 [use_color_lut]; 3129 [use_color_lut];
3454 if (!program->initialized()) { 3130 if (!program->initialized()) {
3455 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); 3131 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize");
3456 program->InitializeVideoYUV(output_surface_->context_provider(), precision, 3132 program->InitializeVideoYUV(output_surface_->context_provider(), precision,
3457 sampler, use_alpha_plane, use_nv12, 3133 sampler, use_alpha_plane, use_nv12,
3458 use_color_lut); 3134 use_color_lut);
3459 } 3135 }
3460 return program; 3136 return program;
3461 } 3137 }
3462 3138
3463 const GLRenderer::VideoStreamTextureProgram*
3464 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) {
3465 return GetProgram(ProgramKey::VideoStream(precision));
3466 }
3467
3468 const Program* GLRenderer::GetProgram(const ProgramKey& desc) { 3139 const Program* GLRenderer::GetProgram(const ProgramKey& desc) {
3469 std::unique_ptr<Program>& program = program_cache_[desc]; 3140 std::unique_ptr<Program>& program = program_cache_[desc];
3470 if (!program) { 3141 if (!program) {
3471 program.reset(new Program); 3142 program.reset(new Program);
3472 program->Initialize(output_surface_->context_provider(), desc); 3143 program->Initialize(output_surface_->context_provider(), desc);
3473 } 3144 }
3474 return program.get(); 3145 return program.get();
3475 } 3146 }
3476 3147
3477 const Program* GLRenderer::GetProgramIfInitialized( 3148 const Program* GLRenderer::GetProgramIfInitialized(
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
3829 // The alpha has already been applied when copying the RPDQ to an IOSurface. 3500 // The alpha has already been applied when copying the RPDQ to an IOSurface.
3830 GLfloat alpha = 1; 3501 GLfloat alpha = 1;
3831 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect, 3502 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect,
3832 sorting_context_id, gl_transform); 3503 sorting_context_id, gl_transform);
3833 gl_->ScheduleCALayerCHROMIUM( 3504 gl_->ScheduleCALayerCHROMIUM(
3834 texture_id, contents_rect, ca_layer_overlay->background_color, 3505 texture_id, contents_rect, ca_layer_overlay->background_color,
3835 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); 3506 ca_layer_overlay->edge_aa_mask, bounds_rect, filter);
3836 } 3507 }
3837 3508
3838 } // namespace cc 3509 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698