| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/strings/string_split.h" | |
| 16 #include "base/strings/string_util.h" | |
| 17 #include "base/strings/stringprintf.h" | |
| 18 #include "build/build_config.h" | |
| 19 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 20 #include "cc/base/math_util.h" | 15 #include "cc/base/math_util.h" |
| 21 #include "cc/layers/video_layer_impl.h" | 16 #include "cc/layers/video_layer_impl.h" |
| 22 #include "cc/output/compositor_frame.h" | 17 #include "cc/output/compositor_frame.h" |
| 23 #include "cc/output/compositor_frame_metadata.h" | 18 #include "cc/output/compositor_frame_metadata.h" |
| 24 #include "cc/output/context_provider.h" | 19 #include "cc/output/context_provider.h" |
| 25 #include "cc/output/copy_output_request.h" | 20 #include "cc/output/copy_output_request.h" |
| 26 #include "cc/output/dynamic_geometry_binding.h" | 21 #include "cc/output/geometry_binding.h" |
| 27 #include "cc/output/gl_frame_data.h" | 22 #include "cc/output/gl_frame_data.h" |
| 28 #include "cc/output/output_surface.h" | 23 #include "cc/output/output_surface.h" |
| 29 #include "cc/output/render_surface_filters.h" | 24 #include "cc/output/render_surface_filters.h" |
| 30 #include "cc/output/static_geometry_binding.h" | |
| 31 #include "cc/quads/draw_polygon.h" | |
| 32 #include "cc/quads/picture_draw_quad.h" | 25 #include "cc/quads/picture_draw_quad.h" |
| 33 #include "cc/quads/render_pass.h" | 26 #include "cc/quads/render_pass.h" |
| 34 #include "cc/quads/stream_video_draw_quad.h" | 27 #include "cc/quads/stream_video_draw_quad.h" |
| 35 #include "cc/quads/texture_draw_quad.h" | 28 #include "cc/quads/texture_draw_quad.h" |
| 36 #include "cc/resources/layer_quad.h" | 29 #include "cc/resources/layer_quad.h" |
| 37 #include "cc/resources/scoped_gpu_raster.h" | 30 #include "cc/resources/scoped_gpu_raster.h" |
| 38 #include "cc/resources/scoped_resource.h" | 31 #include "cc/resources/scoped_resource.h" |
| 39 #include "cc/resources/texture_mailbox_deleter.h" | 32 #include "cc/resources/texture_mailbox_deleter.h" |
| 40 #include "gpu/GLES2/gl2extchromium.h" | 33 #include "gpu/GLES2/gl2extchromium.h" |
| 41 #include "gpu/command_buffer/client/context_support.h" | 34 #include "gpu/command_buffer/client/context_support.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 context_support_(output_surface->context_provider()->ContextSupport()), | 317 context_support_(output_surface->context_provider()->ContextSupport()), |
| 325 texture_mailbox_deleter_(texture_mailbox_deleter), | 318 texture_mailbox_deleter_(texture_mailbox_deleter), |
| 326 is_backbuffer_discarded_(false), | 319 is_backbuffer_discarded_(false), |
| 327 is_scissor_enabled_(false), | 320 is_scissor_enabled_(false), |
| 328 scissor_rect_needs_reset_(true), | 321 scissor_rect_needs_reset_(true), |
| 329 stencil_shadow_(false), | 322 stencil_shadow_(false), |
| 330 blend_shadow_(false), | 323 blend_shadow_(false), |
| 331 highp_threshold_min_(highp_threshold_min), | 324 highp_threshold_min_(highp_threshold_min), |
| 332 highp_threshold_cache_(0), | 325 highp_threshold_cache_(0), |
| 333 use_sync_query_(false), | 326 use_sync_query_(false), |
| 334 on_demand_tile_raster_resource_id_(0), | 327 on_demand_tile_raster_resource_id_(0) { |
| 335 bound_geometry_(NO_BINDING) { | |
| 336 DCHECK(gl_); | 328 DCHECK(gl_); |
| 337 DCHECK(context_support_); | 329 DCHECK(context_support_); |
| 338 | 330 |
| 339 ContextProvider::Capabilities context_caps = | 331 ContextProvider::Capabilities context_caps = |
| 340 output_surface_->context_provider()->ContextCapabilities(); | 332 output_surface_->context_provider()->ContextCapabilities(); |
| 341 | 333 |
| 342 capabilities_.using_partial_swap = | 334 capabilities_.using_partial_swap = |
| 343 settings_->partial_swap_enabled && context_caps.gpu.post_sub_buffer; | 335 settings_->partial_swap_enabled && context_caps.gpu.post_sub_buffer; |
| 344 | 336 |
| 345 DCHECK(!context_caps.gpu.iosurface || context_caps.gpu.texture_rectangle); | 337 DCHECK(!context_caps.gpu.iosurface || context_caps.gpu.texture_rectangle); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 487 |
| 496 // TODO(enne): Do we need to reinitialize all of this state per frame? | 488 // TODO(enne): Do we need to reinitialize all of this state per frame? |
| 497 ReinitializeGLState(); | 489 ReinitializeGLState(); |
| 498 } | 490 } |
| 499 | 491 |
| 500 void GLRenderer::DoNoOp() { | 492 void GLRenderer::DoNoOp() { |
| 501 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, 0)); | 493 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, 0)); |
| 502 GLC(gl_, gl_->Flush()); | 494 GLC(gl_, gl_->Flush()); |
| 503 } | 495 } |
| 504 | 496 |
| 505 void GLRenderer::DoDrawQuad(DrawingFrame* frame, | 497 void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { |
| 506 const DrawQuad* quad, | |
| 507 const gfx::QuadF* clip_region) { | |
| 508 DCHECK(quad->rect.Contains(quad->visible_rect)); | 498 DCHECK(quad->rect.Contains(quad->visible_rect)); |
| 509 if (quad->material != DrawQuad::TEXTURE_CONTENT) { | 499 if (quad->material != DrawQuad::TEXTURE_CONTENT) { |
| 510 FlushTextureQuadCache(SHARED_BINDING); | 500 FlushTextureQuadCache(); |
| 511 } | 501 } |
| 512 | 502 |
| 513 switch (quad->material) { | 503 switch (quad->material) { |
| 514 case DrawQuad::INVALID: | 504 case DrawQuad::INVALID: |
| 515 NOTREACHED(); | 505 NOTREACHED(); |
| 516 break; | 506 break; |
| 517 case DrawQuad::CHECKERBOARD: | 507 case DrawQuad::CHECKERBOARD: |
| 518 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad), | 508 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); |
| 519 clip_region); | |
| 520 break; | 509 break; |
| 521 case DrawQuad::DEBUG_BORDER: | 510 case DrawQuad::DEBUG_BORDER: |
| 522 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 511 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); |
| 523 break; | 512 break; |
| 524 case DrawQuad::IO_SURFACE_CONTENT: | 513 case DrawQuad::IO_SURFACE_CONTENT: |
| 525 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad), | 514 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad)); |
| 526 clip_region); | |
| 527 break; | 515 break; |
| 528 case DrawQuad::PICTURE_CONTENT: | 516 case DrawQuad::PICTURE_CONTENT: |
| 529 // PictureDrawQuad should only be used for resourceless software draws. | 517 // PictureDrawQuad should only be used for resourceless software draws. |
| 530 NOTREACHED(); | 518 NOTREACHED(); |
| 531 break; | 519 break; |
| 532 case DrawQuad::RENDER_PASS: | 520 case DrawQuad::RENDER_PASS: |
| 533 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad), | 521 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); |
| 534 clip_region); | |
| 535 break; | 522 break; |
| 536 case DrawQuad::SOLID_COLOR: | 523 case DrawQuad::SOLID_COLOR: |
| 537 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad), | 524 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); |
| 538 clip_region); | |
| 539 break; | 525 break; |
| 540 case DrawQuad::STREAM_VIDEO_CONTENT: | 526 case DrawQuad::STREAM_VIDEO_CONTENT: |
| 541 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad), | 527 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad)); |
| 542 clip_region); | |
| 543 break; | 528 break; |
| 544 case DrawQuad::SURFACE_CONTENT: | 529 case DrawQuad::SURFACE_CONTENT: |
| 545 // Surface content should be fully resolved to other quad types before | 530 // Surface content should be fully resolved to other quad types before |
| 546 // reaching a direct renderer. | 531 // reaching a direct renderer. |
| 547 NOTREACHED(); | 532 NOTREACHED(); |
| 548 break; | 533 break; |
| 549 case DrawQuad::TEXTURE_CONTENT: | 534 case DrawQuad::TEXTURE_CONTENT: |
| 550 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), | 535 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); |
| 551 clip_region); | |
| 552 break; | 536 break; |
| 553 case DrawQuad::TILED_CONTENT: | 537 case DrawQuad::TILED_CONTENT: |
| 554 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); | 538 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); |
| 555 break; | 539 break; |
| 556 case DrawQuad::YUV_VIDEO_CONTENT: | 540 case DrawQuad::YUV_VIDEO_CONTENT: |
| 557 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), | 541 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); |
| 558 clip_region); | |
| 559 break; | 542 break; |
| 560 } | 543 } |
| 561 } | 544 } |
| 562 | 545 |
| 563 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, | 546 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, |
| 564 const CheckerboardDrawQuad* quad, | 547 const CheckerboardDrawQuad* quad) { |
| 565 const gfx::QuadF* clip_region) { | |
| 566 // TODO(enne) For now since checkerboards shouldn't be part of a 3D | |
| 567 // context, clipping regions aren't supported so we skip drawing them | |
| 568 // if this becomes the case. | |
| 569 if (clip_region) { | |
| 570 return; | |
| 571 } | |
| 572 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 548 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 573 | 549 |
| 574 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); | 550 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); |
| 575 DCHECK(program && (program->initialized() || IsContextLost())); | 551 DCHECK(program && (program->initialized() || IsContextLost())); |
| 576 SetUseProgram(program->program()); | 552 SetUseProgram(program->program()); |
| 577 | 553 |
| 578 SkColor color = quad->color; | 554 SkColor color = quad->color; |
| 579 GLC(gl_, | 555 GLC(gl_, |
| 580 gl_->Uniform4f(program->fragment_shader().color_location(), | 556 gl_->Uniform4f(program->fragment_shader().color_location(), |
| 581 SkColorGetR(color) * (1.0f / 255.0f), | 557 SkColorGetR(color) * (1.0f / 255.0f), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 603 frequency)); | 579 frequency)); |
| 604 | 580 |
| 605 SetShaderOpacity(quad->opacity(), | 581 SetShaderOpacity(quad->opacity(), |
| 606 program->fragment_shader().alpha_location()); | 582 program->fragment_shader().alpha_location()); |
| 607 DrawQuadGeometry(frame, | 583 DrawQuadGeometry(frame, |
| 608 quad->quadTransform(), | 584 quad->quadTransform(), |
| 609 quad->rect, | 585 quad->rect, |
| 610 program->vertex_shader().matrix_location()); | 586 program->vertex_shader().matrix_location()); |
| 611 } | 587 } |
| 612 | 588 |
| 613 // This function does not handle 3D sorting right now, since the debug border | |
| 614 // quads are just drawn as their original quads and not in split pieces. This | |
| 615 // results in some debug border quads drawing over foreground quads. | |
| 616 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, | 589 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, |
| 617 const DebugBorderDrawQuad* quad) { | 590 const DebugBorderDrawQuad* quad) { |
| 618 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 591 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 619 | 592 |
| 620 static float gl_matrix[16]; | 593 static float gl_matrix[16]; |
| 621 const DebugBorderProgram* program = GetDebugBorderProgram(); | 594 const DebugBorderProgram* program = GetDebugBorderProgram(); |
| 622 DCHECK(program && (program->initialized() || IsContextLost())); | 595 DCHECK(program && (program->initialized() || IsContextLost())); |
| 623 SetUseProgram(program->program()); | 596 SetUseProgram(program->program()); |
| 624 | 597 |
| 625 // Use the full quad_rect for debug quads to not move the edges based on | 598 // Use the full quad_rect for debug quads to not move the edges based on |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 if (frame->current_render_pass->has_transparent_background) | 810 if (frame->current_render_pass->has_transparent_background) |
| 838 return false; | 811 return false; |
| 839 | 812 |
| 840 // TODO(ajuma): Add support for reference filters once | 813 // TODO(ajuma): Add support for reference filters once |
| 841 // FilterOperations::GetOutsets supports reference filters. | 814 // FilterOperations::GetOutsets supports reference filters. |
| 842 if (quad->background_filters.HasReferenceFilter()) | 815 if (quad->background_filters.HasReferenceFilter()) |
| 843 return false; | 816 return false; |
| 844 return true; | 817 return true; |
| 845 } | 818 } |
| 846 | 819 |
| 847 // This takes a gfx::Rect and a clip region quad in the same space, | |
| 848 // and returns a quad with the same proportions in the space -0.5->0.5. | |
| 849 bool GetScaledRegion(const gfx::Rect& rect, | |
| 850 const gfx::QuadF* clip, | |
| 851 gfx::QuadF* scaled_region) { | |
| 852 if (!clip) | |
| 853 return false; | |
| 854 | |
| 855 gfx::PointF p1(((clip->p1().x() - rect.x()) / rect.width()) - 0.5f, | |
| 856 ((clip->p1().y() - rect.y()) / rect.height()) - 0.5f); | |
| 857 gfx::PointF p2(((clip->p2().x() - rect.x()) / rect.width()) - 0.5f, | |
| 858 ((clip->p2().y() - rect.y()) / rect.height()) - 0.5f); | |
| 859 gfx::PointF p3(((clip->p3().x() - rect.x()) / rect.width()) - 0.5f, | |
| 860 ((clip->p3().y() - rect.y()) / rect.height()) - 0.5f); | |
| 861 gfx::PointF p4(((clip->p4().x() - rect.x()) / rect.width()) - 0.5f, | |
| 862 ((clip->p4().y() - rect.y()) / rect.height()) - 0.5f); | |
| 863 *scaled_region = gfx::QuadF(p1, p2, p3, p4); | |
| 864 return true; | |
| 865 } | |
| 866 | |
| 867 // This takes a gfx::Rect and a clip region quad in the same space, | |
| 868 // and returns the proportional uv's in the space 0->1. | |
| 869 bool GetScaledUVs(const gfx::Rect& rect, const gfx::QuadF* clip, float uvs[8]) { | |
| 870 if (!clip) | |
| 871 return false; | |
| 872 | |
| 873 uvs[0] = ((clip->p1().x() - rect.x()) / rect.width()); | |
| 874 uvs[1] = ((clip->p1().y() - rect.y()) / rect.height()); | |
| 875 uvs[2] = ((clip->p2().x() - rect.x()) / rect.width()); | |
| 876 uvs[3] = ((clip->p2().y() - rect.y()) / rect.height()); | |
| 877 uvs[4] = ((clip->p3().x() - rect.x()) / rect.width()); | |
| 878 uvs[5] = ((clip->p3().y() - rect.y()) / rect.height()); | |
| 879 uvs[6] = ((clip->p4().x() - rect.x()) / rect.width()); | |
| 880 uvs[7] = ((clip->p4().y() - rect.y()) / rect.height()); | |
| 881 return true; | |
| 882 } | |
| 883 | |
| 884 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( | 820 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
| 885 DrawingFrame* frame, | 821 DrawingFrame* frame, |
| 886 const RenderPassDrawQuad* quad, | 822 const RenderPassDrawQuad* quad, |
| 887 const gfx::Transform& contents_device_transform, | 823 const gfx::Transform& contents_device_transform, |
| 888 const gfx::QuadF* clip_region, | |
| 889 bool use_aa) { | 824 bool use_aa) { |
| 890 gfx::QuadF scaled_region; | |
| 891 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { | |
| 892 scaled_region = SharedGeometryQuad().BoundingBox(); | |
| 893 } | |
| 894 | |
| 895 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( | 825 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( |
| 896 contents_device_transform, scaled_region.BoundingBox())); | 826 contents_device_transform, SharedGeometryQuad().BoundingBox())); |
| 897 | 827 |
| 898 if (ShouldApplyBackgroundFilters(frame, quad)) { | 828 if (ShouldApplyBackgroundFilters(frame, quad)) { |
| 899 int top, right, bottom, left; | 829 int top, right, bottom, left; |
| 900 quad->background_filters.GetOutsets(&top, &right, &bottom, &left); | 830 quad->background_filters.GetOutsets(&top, &right, &bottom, &left); |
| 901 backdrop_rect.Inset(-left, -top, -right, -bottom); | 831 backdrop_rect.Inset(-left, -top, -right, -bottom); |
| 902 } | 832 } |
| 903 | 833 |
| 904 if (!backdrop_rect.IsEmpty() && use_aa) { | 834 if (!backdrop_rect.IsEmpty() && use_aa) { |
| 905 const int kOutsetForAntialiasing = 1; | 835 const int kOutsetForAntialiasing = 1; |
| 906 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); | 836 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 935 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 865 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
| 936 quad->background_filters, background_texture->size()); | 866 quad->background_filters, background_texture->size()); |
| 937 | 867 |
| 938 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( | 868 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( |
| 939 ScopedUseGrContext::Create(this, frame), resource_provider_, quad->rect, | 869 ScopedUseGrContext::Create(this, frame), resource_provider_, quad->rect, |
| 940 quad->filters_scale, filter.get(), background_texture); | 870 quad->filters_scale, filter.get(), background_texture); |
| 941 return background_with_filters; | 871 return background_with_filters; |
| 942 } | 872 } |
| 943 | 873 |
| 944 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 874 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, |
| 945 const RenderPassDrawQuad* quad, | 875 const RenderPassDrawQuad* quad) { |
| 946 const gfx::QuadF* clip_region) { | |
| 947 ScopedResource* contents_texture = | 876 ScopedResource* contents_texture = |
| 948 render_pass_textures_.get(quad->render_pass_id); | 877 render_pass_textures_.get(quad->render_pass_id); |
| 949 if (!contents_texture || !contents_texture->id()) | 878 if (!contents_texture || !contents_texture->id()) |
| 950 return; | 879 return; |
| 951 | 880 |
| 952 gfx::Transform quad_rect_matrix; | 881 gfx::Transform quad_rect_matrix; |
| 953 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 882 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
| 954 gfx::Transform contents_device_transform = | 883 gfx::Transform contents_device_transform = |
| 955 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 884 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
| 956 contents_device_transform.FlattenTo2d(); | 885 contents_device_transform.FlattenTo2d(); |
| 957 | 886 |
| 958 // Can only draw surface if device matrix is invertible. | 887 // Can only draw surface if device matrix is invertible. |
| 959 if (!contents_device_transform.IsInvertible()) | 888 if (!contents_device_transform.IsInvertible()) |
| 960 return; | 889 return; |
| 961 | 890 |
| 962 gfx::QuadF surface_quad = SharedGeometryQuad(); | 891 gfx::QuadF surface_quad = SharedGeometryQuad(); |
| 963 float edge[24]; | 892 float edge[24]; |
| 964 bool use_aa = settings_->allow_antialiasing && | 893 bool use_aa = settings_->allow_antialiasing && |
| 965 ShouldAntialiasQuad(contents_device_transform, quad, | 894 ShouldAntialiasQuad(contents_device_transform, quad, |
| 966 settings_->force_antialiasing); | 895 settings_->force_antialiasing); |
| 967 | 896 |
| 968 SetupQuadForClippingAndAntialiasing(contents_device_transform, quad, use_aa, | 897 if (use_aa) |
| 969 clip_region, &surface_quad, edge); | 898 SetupQuadForAntialiasing(contents_device_transform, quad, |
| 899 &surface_quad, edge); |
| 900 |
| 970 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; | 901 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; |
| 971 bool use_shaders_for_blending = | 902 bool use_shaders_for_blending = |
| 972 !CanApplyBlendModeUsingBlendFunc(blend_mode) || | 903 !CanApplyBlendModeUsingBlendFunc(blend_mode) || |
| 973 ShouldApplyBackgroundFilters(frame, quad) || | 904 ShouldApplyBackgroundFilters(frame, quad) || |
| 974 settings_->force_blending_with_shaders; | 905 settings_->force_blending_with_shaders; |
| 975 | 906 |
| 976 scoped_ptr<ScopedResource> background_texture; | 907 scoped_ptr<ScopedResource> background_texture; |
| 977 skia::RefPtr<SkImage> background_image; | 908 skia::RefPtr<SkImage> background_image; |
| 978 gfx::Rect background_rect; | 909 gfx::Rect background_rect; |
| 979 if (use_shaders_for_blending) { | 910 if (use_shaders_for_blending) { |
| 980 // Compute a bounding box around the pixels that will be visible through | 911 // Compute a bounding box around the pixels that will be visible through |
| 981 // the quad. | 912 // the quad. |
| 982 background_rect = GetBackdropBoundingBoxForRenderPassQuad( | 913 background_rect = GetBackdropBoundingBoxForRenderPassQuad( |
| 983 frame, quad, contents_device_transform, clip_region, use_aa); | 914 frame, quad, contents_device_transform, use_aa); |
| 984 | 915 |
| 985 if (!background_rect.IsEmpty()) { | 916 if (!background_rect.IsEmpty()) { |
| 986 // The pixels from the filtered background should completely replace the | 917 // The pixels from the filtered background should completely replace the |
| 987 // current pixel values. | 918 // current pixel values. |
| 988 if (blend_enabled()) | 919 if (blend_enabled()) |
| 989 SetBlendEnabled(false); | 920 SetBlendEnabled(false); |
| 990 | 921 |
| 991 // Read the pixels in the bounding box into a buffer R. | 922 // Read the pixels in the bounding box into a buffer R. |
| 992 // This function allocates a texture, which should contribute to the | 923 // This function allocates a texture, which should contribute to the |
| 993 // amount of memory used by render surfaces: | 924 // amount of memory used by render surfaces: |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 static void SolidColorUniformLocation(T program, | 1327 static void SolidColorUniformLocation(T program, |
| 1397 SolidColorProgramUniforms* uniforms) { | 1328 SolidColorProgramUniforms* uniforms) { |
| 1398 uniforms->program = program->program(); | 1329 uniforms->program = program->program(); |
| 1399 uniforms->matrix_location = program->vertex_shader().matrix_location(); | 1330 uniforms->matrix_location = program->vertex_shader().matrix_location(); |
| 1400 uniforms->viewport_location = program->vertex_shader().viewport_location(); | 1331 uniforms->viewport_location = program->vertex_shader().viewport_location(); |
| 1401 uniforms->quad_location = program->vertex_shader().quad_location(); | 1332 uniforms->quad_location = program->vertex_shader().quad_location(); |
| 1402 uniforms->edge_location = program->vertex_shader().edge_location(); | 1333 uniforms->edge_location = program->vertex_shader().edge_location(); |
| 1403 uniforms->color_location = program->fragment_shader().color_location(); | 1334 uniforms->color_location = program->fragment_shader().color_location(); |
| 1404 } | 1335 } |
| 1405 | 1336 |
| 1406 namespace { | |
| 1407 // These functions determine if a quad, clipped by a clip_region contains | |
| 1408 // the entire {top|bottom|left|right} edge. | |
| 1409 bool is_top(const gfx::QuadF* clip_region, const DrawQuad* quad) { | |
| 1410 if (!quad->IsTopEdge()) | |
| 1411 return false; | |
| 1412 if (!clip_region) | |
| 1413 return true; | |
| 1414 | |
| 1415 return std::abs(clip_region->p1().y()) < kAntiAliasingEpsilon && | |
| 1416 std::abs(clip_region->p2().y()) < kAntiAliasingEpsilon; | |
| 1417 } | |
| 1418 | |
| 1419 bool is_bottom(const gfx::QuadF* clip_region, const DrawQuad* quad) { | |
| 1420 if (!quad->IsBottomEdge()) | |
| 1421 return false; | |
| 1422 if (!clip_region) | |
| 1423 return true; | |
| 1424 | |
| 1425 return std::abs(clip_region->p3().y() - | |
| 1426 quad->shared_quad_state->content_bounds.height()) < | |
| 1427 kAntiAliasingEpsilon && | |
| 1428 std::abs(clip_region->p4().y() - | |
| 1429 quad->shared_quad_state->content_bounds.height()) < | |
| 1430 kAntiAliasingEpsilon; | |
| 1431 } | |
| 1432 | |
| 1433 bool is_left(const gfx::QuadF* clip_region, const DrawQuad* quad) { | |
| 1434 if (!quad->IsLeftEdge()) | |
| 1435 return false; | |
| 1436 if (!clip_region) | |
| 1437 return true; | |
| 1438 | |
| 1439 return std::abs(clip_region->p1().x()) < kAntiAliasingEpsilon && | |
| 1440 std::abs(clip_region->p4().x()) < kAntiAliasingEpsilon; | |
| 1441 } | |
| 1442 | |
| 1443 bool is_right(const gfx::QuadF* clip_region, const DrawQuad* quad) { | |
| 1444 if (!quad->IsRightEdge()) | |
| 1445 return false; | |
| 1446 if (!clip_region) | |
| 1447 return true; | |
| 1448 | |
| 1449 return std::abs(clip_region->p2().x() - | |
| 1450 quad->shared_quad_state->content_bounds.width()) < | |
| 1451 kAntiAliasingEpsilon && | |
| 1452 std::abs(clip_region->p3().x() - | |
| 1453 quad->shared_quad_state->content_bounds.width()) < | |
| 1454 kAntiAliasingEpsilon; | |
| 1455 } | |
| 1456 } // anonymous namespace | |
| 1457 | |
| 1458 static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( | 1337 static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( |
| 1459 const LayerQuad& device_layer_edges, | 1338 const LayerQuad& device_layer_edges, |
| 1460 const gfx::Transform& device_transform, | 1339 const gfx::Transform& device_transform, |
| 1461 const gfx::QuadF* clip_region, | |
| 1462 const DrawQuad* quad) { | 1340 const DrawQuad* quad) { |
| 1463 gfx::RectF tile_rect = quad->visible_rect; | 1341 gfx::Rect tile_rect = quad->visible_rect; |
| 1464 gfx::QuadF tile_quad(tile_rect); | 1342 gfx::PointF bottom_right = tile_rect.bottom_right(); |
| 1465 | 1343 gfx::PointF bottom_left = tile_rect.bottom_left(); |
| 1466 if (clip_region) { | 1344 gfx::PointF top_left = tile_rect.origin(); |
| 1467 if (quad->material != DrawQuad::RENDER_PASS) { | 1345 gfx::PointF top_right = tile_rect.top_right(); |
| 1468 tile_quad = *clip_region; | |
| 1469 } else { | |
| 1470 GetScaledRegion(quad->rect, clip_region, &tile_quad); | |
| 1471 } | |
| 1472 } | |
| 1473 | |
| 1474 gfx::PointF bottom_right = tile_quad.p3(); | |
| 1475 gfx::PointF bottom_left = tile_quad.p4(); | |
| 1476 gfx::PointF top_left = tile_quad.p1(); | |
| 1477 gfx::PointF top_right = tile_quad.p2(); | |
| 1478 bool clipped = false; | 1346 bool clipped = false; |
| 1479 | 1347 |
| 1480 // Map points to device space. We ignore |clipped|, since the result of | 1348 // Map points to device space. We ignore |clipped|, since the result of |
| 1481 // |MapPoint()| still produces a valid point to draw the quad with. When | 1349 // |MapPoint()| still produces a valid point to draw the quad with. When |
| 1482 // clipped, the point will be outside of the viewport. See crbug.com/416367. | 1350 // clipped, the point will be outside of the viewport. See crbug.com/416367. |
| 1483 bottom_right = MathUtil::MapPoint(device_transform, bottom_right, &clipped); | 1351 bottom_right = MathUtil::MapPoint(device_transform, bottom_right, &clipped); |
| 1484 bottom_left = MathUtil::MapPoint(device_transform, bottom_left, &clipped); | 1352 bottom_left = MathUtil::MapPoint(device_transform, bottom_left, &clipped); |
| 1485 top_left = MathUtil::MapPoint(device_transform, top_left, &clipped); | 1353 top_left = MathUtil::MapPoint(device_transform, top_left, &clipped); |
| 1486 top_right = MathUtil::MapPoint(device_transform, top_right, &clipped); | 1354 top_right = MathUtil::MapPoint(device_transform, top_right, &clipped); |
| 1487 | 1355 |
| 1488 LayerQuad::Edge bottom_edge(bottom_right, bottom_left); | 1356 LayerQuad::Edge bottom_edge(bottom_right, bottom_left); |
| 1489 LayerQuad::Edge left_edge(bottom_left, top_left); | 1357 LayerQuad::Edge left_edge(bottom_left, top_left); |
| 1490 LayerQuad::Edge top_edge(top_left, top_right); | 1358 LayerQuad::Edge top_edge(top_left, top_right); |
| 1491 LayerQuad::Edge right_edge(top_right, bottom_right); | 1359 LayerQuad::Edge right_edge(top_right, bottom_right); |
| 1492 | 1360 |
| 1493 // Only apply anti-aliasing to edges not clipped by culling or scissoring. | 1361 // Only apply anti-aliasing to edges not clipped by culling or scissoring. |
| 1494 // If an edge is degenerate we do not want to replace it with a "proper" edge | 1362 if (quad->IsTopEdge() && tile_rect.y() == quad->rect.y()) |
| 1495 // as that will cause the quad to possibly expand is strange ways. | |
| 1496 if (!top_edge.degenerate() && is_top(clip_region, quad) && | |
| 1497 tile_rect.y() == quad->rect.y()) { | |
| 1498 top_edge = device_layer_edges.top(); | 1363 top_edge = device_layer_edges.top(); |
| 1499 } | 1364 if (quad->IsLeftEdge() && tile_rect.x() == quad->rect.x()) |
| 1500 if (!left_edge.degenerate() && is_left(clip_region, quad) && | |
| 1501 tile_rect.x() == quad->rect.x()) { | |
| 1502 left_edge = device_layer_edges.left(); | 1365 left_edge = device_layer_edges.left(); |
| 1503 } | 1366 if (quad->IsRightEdge() && tile_rect.right() == quad->rect.right()) |
| 1504 if (!right_edge.degenerate() && is_right(clip_region, quad) && | |
| 1505 tile_rect.right() == quad->rect.right()) { | |
| 1506 right_edge = device_layer_edges.right(); | 1367 right_edge = device_layer_edges.right(); |
| 1507 } | 1368 if (quad->IsBottomEdge() && tile_rect.bottom() == quad->rect.bottom()) |
| 1508 if (!bottom_edge.degenerate() && is_bottom(clip_region, quad) && | |
| 1509 tile_rect.bottom() == quad->rect.bottom()) { | |
| 1510 bottom_edge = device_layer_edges.bottom(); | 1369 bottom_edge = device_layer_edges.bottom(); |
| 1511 } | |
| 1512 | 1370 |
| 1513 float sign = tile_quad.IsCounterClockwise() ? -1 : 1; | 1371 float sign = gfx::QuadF(tile_rect).IsCounterClockwise() ? -1 : 1; |
| 1514 bottom_edge.scale(sign); | 1372 bottom_edge.scale(sign); |
| 1515 left_edge.scale(sign); | 1373 left_edge.scale(sign); |
| 1516 top_edge.scale(sign); | 1374 top_edge.scale(sign); |
| 1517 right_edge.scale(sign); | 1375 right_edge.scale(sign); |
| 1518 | 1376 |
| 1519 // Create device space quad. | 1377 // Create device space quad. |
| 1520 return LayerQuad(left_edge, top_edge, right_edge, bottom_edge).ToQuadF(); | 1378 return LayerQuad(left_edge, top_edge, right_edge, bottom_edge).ToQuadF(); |
| 1521 } | 1379 } |
| 1522 | 1380 |
| 1523 float GetTotalQuadError(const gfx::QuadF* clipped_quad, | |
| 1524 const gfx::QuadF* ideal_rect) { | |
| 1525 return (clipped_quad->p1() - ideal_rect->p1()).LengthSquared() + | |
| 1526 (clipped_quad->p2() - ideal_rect->p2()).LengthSquared() + | |
| 1527 (clipped_quad->p3() - ideal_rect->p3()).LengthSquared() + | |
| 1528 (clipped_quad->p4() - ideal_rect->p4()).LengthSquared(); | |
| 1529 } | |
| 1530 | |
| 1531 // Attempt to rotate the clipped quad until it lines up the most | |
| 1532 // correctly. This is necessary because we check the edges of this | |
| 1533 // quad against the expected left/right/top/bottom for anti-aliasing. | |
| 1534 void AlignQuadToBoundingBox(gfx::QuadF* clipped_quad) { | |
| 1535 gfx::QuadF bounding_quad = gfx::QuadF(clipped_quad->BoundingBox()); | |
| 1536 gfx::QuadF best_rotation = *clipped_quad; | |
| 1537 float least_error_amount = GetTotalQuadError(clipped_quad, &bounding_quad); | |
| 1538 for (size_t i = 1; i < 4; ++i) { | |
| 1539 clipped_quad->Realign(1); | |
| 1540 float new_error = GetTotalQuadError(clipped_quad, &bounding_quad); | |
| 1541 if (new_error < least_error_amount) { | |
| 1542 least_error_amount = new_error; | |
| 1543 best_rotation = *clipped_quad; | |
| 1544 } | |
| 1545 } | |
| 1546 *clipped_quad = best_rotation; | |
| 1547 } | |
| 1548 | |
| 1549 // static | 1381 // static |
| 1550 bool GLRenderer::ShouldAntialiasQuad(const gfx::Transform& device_transform, | 1382 bool GLRenderer::ShouldAntialiasQuad(const gfx::Transform& device_transform, |
| 1551 const DrawQuad* quad, | 1383 const DrawQuad* quad, |
| 1552 bool force_antialiasing) { | 1384 bool force_antialiasing) { |
| 1553 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); | 1385 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); |
| 1554 // For render pass quads, |device_transform| already contains quad's rect. | 1386 // For render pass quads, |device_transform| already contains quad's rect. |
| 1555 // TODO(rosca@adobe.com): remove branching on is_render_pass_quad | 1387 // TODO(rosca@adobe.com): remove branching on is_render_pass_quad |
| 1556 // crbug.com/429702 | 1388 // crbug.com/429702 |
| 1557 if (!is_render_pass_quad && !quad->IsEdge()) | 1389 if (!is_render_pass_quad && !quad->IsEdge()) |
| 1558 return false; | 1390 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1570 bool is_nearest_rect_within_epsilon = | 1402 bool is_nearest_rect_within_epsilon = |
| 1571 is_axis_aligned_in_target && | 1403 is_axis_aligned_in_target && |
| 1572 gfx::IsNearestRectWithinDistance(device_layer_quad.BoundingBox(), | 1404 gfx::IsNearestRectWithinDistance(device_layer_quad.BoundingBox(), |
| 1573 kAntiAliasingEpsilon); | 1405 kAntiAliasingEpsilon); |
| 1574 // AAing clipped quads is not supported by the code yet. | 1406 // AAing clipped quads is not supported by the code yet. |
| 1575 bool use_aa = !clipped && !is_nearest_rect_within_epsilon; | 1407 bool use_aa = !clipped && !is_nearest_rect_within_epsilon; |
| 1576 return use_aa || force_antialiasing; | 1408 return use_aa || force_antialiasing; |
| 1577 } | 1409 } |
| 1578 | 1410 |
| 1579 // static | 1411 // static |
| 1580 void GLRenderer::SetupQuadForClippingAndAntialiasing( | 1412 void GLRenderer::SetupQuadForAntialiasing( |
| 1581 const gfx::Transform& device_transform, | 1413 const gfx::Transform& device_transform, |
| 1582 const DrawQuad* quad, | 1414 const DrawQuad* quad, |
| 1583 bool use_aa, | |
| 1584 const gfx::QuadF* clip_region, | |
| 1585 gfx::QuadF* local_quad, | 1415 gfx::QuadF* local_quad, |
| 1586 float edge[24]) { | 1416 float edge[24]) { |
| 1587 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); | 1417 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); |
| 1588 gfx::QuadF rotated_clip; | 1418 gfx::RectF content_rect = |
| 1589 const gfx::QuadF* local_clip_region = clip_region; | 1419 is_render_pass_quad ? QuadVertexRect() : quad->visibleContentRect(); |
| 1590 if (local_clip_region) { | |
| 1591 rotated_clip = *clip_region; | |
| 1592 AlignQuadToBoundingBox(&rotated_clip); | |
| 1593 local_clip_region = &rotated_clip; | |
| 1594 } | |
| 1595 | 1420 |
| 1596 gfx::QuadF content_rect = is_render_pass_quad | |
| 1597 ? gfx::QuadF(QuadVertexRect()) | |
| 1598 : gfx::QuadF(quad->visibleContentRect()); | |
| 1599 if (!use_aa) { | |
| 1600 if (local_clip_region) { | |
| 1601 if (!is_render_pass_quad) { | |
| 1602 content_rect = *local_clip_region; | |
| 1603 } else { | |
| 1604 GetScaledRegion(quad->rect, local_clip_region, &content_rect); | |
| 1605 } | |
| 1606 *local_quad = content_rect; | |
| 1607 } | |
| 1608 return; | |
| 1609 } | |
| 1610 bool clipped = false; | 1421 bool clipped = false; |
| 1611 gfx::QuadF device_layer_quad = | 1422 gfx::QuadF device_layer_quad = |
| 1612 MathUtil::MapQuad(device_transform, content_rect, &clipped); | 1423 MathUtil::MapQuad(device_transform, gfx::QuadF(content_rect), &clipped); |
| 1613 | 1424 |
| 1614 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox())); | 1425 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox())); |
| 1615 device_layer_bounds.InflateAntiAliasingDistance(); | 1426 device_layer_bounds.InflateAntiAliasingDistance(); |
| 1616 | 1427 |
| 1617 LayerQuad device_layer_edges(device_layer_quad); | 1428 LayerQuad device_layer_edges(device_layer_quad); |
| 1618 device_layer_edges.InflateAntiAliasingDistance(); | 1429 device_layer_edges.InflateAntiAliasingDistance(); |
| 1619 | 1430 |
| 1620 device_layer_edges.ToFloatArray(edge); | 1431 device_layer_edges.ToFloatArray(edge); |
| 1621 device_layer_bounds.ToFloatArray(&edge[12]); | 1432 device_layer_bounds.ToFloatArray(&edge[12]); |
| 1622 | 1433 |
| 1623 // If we have a clip region then we are split, and therefore | |
| 1624 // by necessity, at least one of our edges is not an external | |
| 1625 // one. | |
| 1626 bool is_full_rect = quad->visible_rect == quad->rect; | |
| 1627 | |
| 1628 bool region_contains_all_outside_edges = | |
| 1629 is_full_rect && | |
| 1630 (is_top(local_clip_region, quad) && is_left(local_clip_region, quad) && | |
| 1631 is_bottom(local_clip_region, quad) && is_right(local_clip_region, quad)); | |
| 1632 | |
| 1633 bool use_aa_on_all_four_edges = | 1434 bool use_aa_on_all_four_edges = |
| 1634 !local_clip_region && | 1435 is_render_pass_quad || |
| 1635 (is_render_pass_quad || region_contains_all_outside_edges); | 1436 (quad->IsTopEdge() && quad->IsLeftEdge() && quad->IsBottomEdge() && |
| 1437 quad->IsRightEdge() && quad->visible_rect == quad->rect); |
| 1636 | 1438 |
| 1637 gfx::QuadF device_quad = | 1439 gfx::QuadF device_quad = |
| 1638 use_aa_on_all_four_edges | 1440 use_aa_on_all_four_edges |
| 1639 ? device_layer_edges.ToQuadF() | 1441 ? device_layer_edges.ToQuadF() |
| 1640 : GetDeviceQuadWithAntialiasingOnExteriorEdges( | 1442 : GetDeviceQuadWithAntialiasingOnExteriorEdges( |
| 1641 device_layer_edges, device_transform, local_clip_region, quad); | 1443 device_layer_edges, device_transform, quad); |
| 1642 | 1444 |
| 1643 // Map device space quad to local space. device_transform has no 3d | 1445 // Map device space quad to local space. device_transform has no 3d |
| 1644 // component since it was flattened, so we don't need to project. We should | 1446 // component since it was flattened, so we don't need to project. We should |
| 1645 // have already checked that the transform was uninvertible above. | 1447 // have already checked that the transform was uninvertible above. |
| 1646 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); | 1448 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); |
| 1647 bool did_invert = device_transform.GetInverse(&inverse_device_transform); | 1449 bool did_invert = device_transform.GetInverse(&inverse_device_transform); |
| 1648 DCHECK(did_invert); | 1450 DCHECK(did_invert); |
| 1649 *local_quad = | 1451 *local_quad = |
| 1650 MathUtil::MapQuad(inverse_device_transform, device_quad, &clipped); | 1452 MathUtil::MapQuad(inverse_device_transform, device_quad, &clipped); |
| 1651 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may | 1453 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may |
| 1652 // cause device_quad to become clipped. To our knowledge this scenario does | 1454 // cause device_quad to become clipped. To our knowledge this scenario does |
| 1653 // not need to be handled differently than the unclipped case. | 1455 // not need to be handled differently than the unclipped case. |
| 1654 } | 1456 } |
| 1655 | 1457 |
| 1656 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, | 1458 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, |
| 1657 const SolidColorDrawQuad* quad, | 1459 const SolidColorDrawQuad* quad) { |
| 1658 const gfx::QuadF* clip_region) { | |
| 1659 gfx::Rect tile_rect = quad->visible_rect; | 1460 gfx::Rect tile_rect = quad->visible_rect; |
| 1660 | 1461 |
| 1661 SkColor color = quad->color; | 1462 SkColor color = quad->color; |
| 1662 float opacity = quad->opacity(); | 1463 float opacity = quad->opacity(); |
| 1663 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; | 1464 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; |
| 1664 | 1465 |
| 1665 // Early out if alpha is small enough that quad doesn't contribute to output. | 1466 // Early out if alpha is small enough that quad doesn't contribute to output. |
| 1666 if (alpha < std::numeric_limits<float>::epsilon() && | 1467 if (alpha < std::numeric_limits<float>::epsilon() && |
| 1667 quad->ShouldDrawWithBlending()) | 1468 quad->ShouldDrawWithBlending()) |
| 1668 return; | 1469 return; |
| 1669 | 1470 |
| 1670 gfx::Transform device_transform = | 1471 gfx::Transform device_transform = |
| 1671 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); | 1472 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); |
| 1672 device_transform.FlattenTo2d(); | 1473 device_transform.FlattenTo2d(); |
| 1673 if (!device_transform.IsInvertible()) | 1474 if (!device_transform.IsInvertible()) |
| 1674 return; | 1475 return; |
| 1675 | 1476 |
| 1676 bool force_aa = false; | 1477 bool force_aa = false; |
| 1677 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); | 1478 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); |
| 1678 float edge[24]; | 1479 float edge[24]; |
| 1679 bool use_aa = settings_->allow_antialiasing && | 1480 bool use_aa = settings_->allow_antialiasing && |
| 1680 !quad->force_anti_aliasing_off && | 1481 !quad->force_anti_aliasing_off && |
| 1681 ShouldAntialiasQuad(device_transform, quad, force_aa); | 1482 ShouldAntialiasQuad(device_transform, quad, force_aa); |
| 1682 SetupQuadForClippingAndAntialiasing(device_transform, quad, use_aa, | |
| 1683 clip_region, &local_quad, edge); | |
| 1684 | 1483 |
| 1685 SolidColorProgramUniforms uniforms; | 1484 SolidColorProgramUniforms uniforms; |
| 1686 if (use_aa) { | 1485 if (use_aa) { |
| 1486 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); |
| 1687 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); | 1487 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); |
| 1688 } else { | 1488 } else { |
| 1689 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); | 1489 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); |
| 1690 } | 1490 } |
| 1691 SetUseProgram(uniforms.program); | 1491 SetUseProgram(uniforms.program); |
| 1692 | 1492 |
| 1693 GLC(gl_, | 1493 GLC(gl_, |
| 1694 gl_->Uniform4f(uniforms.color_location, | 1494 gl_->Uniform4f(uniforms.color_location, |
| 1695 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, | 1495 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, |
| 1696 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, | 1496 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1747 uniforms->vertex_tex_transform_location = | 1547 uniforms->vertex_tex_transform_location = |
| 1748 program->vertex_shader().vertex_tex_transform_location(); | 1548 program->vertex_shader().vertex_tex_transform_location(); |
| 1749 | 1549 |
| 1750 uniforms->sampler_location = program->fragment_shader().sampler_location(); | 1550 uniforms->sampler_location = program->fragment_shader().sampler_location(); |
| 1751 uniforms->alpha_location = program->fragment_shader().alpha_location(); | 1551 uniforms->alpha_location = program->fragment_shader().alpha_location(); |
| 1752 uniforms->fragment_tex_transform_location = | 1552 uniforms->fragment_tex_transform_location = |
| 1753 program->fragment_shader().fragment_tex_transform_location(); | 1553 program->fragment_shader().fragment_tex_transform_location(); |
| 1754 } | 1554 } |
| 1755 | 1555 |
| 1756 void GLRenderer::DrawTileQuad(const DrawingFrame* frame, | 1556 void GLRenderer::DrawTileQuad(const DrawingFrame* frame, |
| 1757 const TileDrawQuad* quad, | 1557 const TileDrawQuad* quad) { |
| 1758 const gfx::QuadF* clip_region) { | 1558 DrawContentQuad(frame, quad, quad->resource_id); |
| 1759 DrawContentQuad(frame, quad, quad->resource_id, clip_region); | |
| 1760 } | 1559 } |
| 1761 | 1560 |
| 1762 void GLRenderer::DrawContentQuad(const DrawingFrame* frame, | 1561 void GLRenderer::DrawContentQuad(const DrawingFrame* frame, |
| 1763 const ContentDrawQuadBase* quad, | 1562 const ContentDrawQuadBase* quad, |
| 1764 ResourceProvider::ResourceId resource_id, | 1563 ResourceProvider::ResourceId resource_id) { |
| 1765 const gfx::QuadF* clip_region) { | |
| 1766 gfx::Transform device_transform = | 1564 gfx::Transform device_transform = |
| 1767 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); | 1565 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); |
| 1768 device_transform.FlattenTo2d(); | 1566 device_transform.FlattenTo2d(); |
| 1769 | 1567 |
| 1770 bool use_aa = settings_->allow_antialiasing && | 1568 bool use_aa = settings_->allow_antialiasing && |
| 1771 ShouldAntialiasQuad(device_transform, quad, false); | 1569 ShouldAntialiasQuad(device_transform, quad, false); |
| 1772 | 1570 |
| 1773 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA | 1571 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA |
| 1774 // similar to the way DrawContentQuadNoAA works and then consider | 1572 // similar to the way DrawContentQuadNoAA works and then consider |
| 1775 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. | 1573 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. |
| 1776 if (use_aa) | 1574 if (use_aa) |
| 1777 DrawContentQuadAA(frame, quad, resource_id, device_transform, clip_region); | 1575 DrawContentQuadAA(frame, quad, resource_id, device_transform); |
| 1778 else | 1576 else |
| 1779 DrawContentQuadNoAA(frame, quad, resource_id, clip_region); | 1577 DrawContentQuadNoAA(frame, quad, resource_id); |
| 1780 } | 1578 } |
| 1781 | 1579 |
| 1782 void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, | 1580 void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, |
| 1783 const ContentDrawQuadBase* quad, | 1581 const ContentDrawQuadBase* quad, |
| 1784 ResourceProvider::ResourceId resource_id, | 1582 ResourceProvider::ResourceId resource_id, |
| 1785 const gfx::Transform& device_transform, | 1583 const gfx::Transform& device_transform) { |
| 1786 const gfx::QuadF* clip_region) { | |
| 1787 if (!device_transform.IsInvertible()) | 1584 if (!device_transform.IsInvertible()) |
| 1788 return; | 1585 return; |
| 1789 | 1586 |
| 1790 gfx::Rect tile_rect = quad->visible_rect; | 1587 gfx::Rect tile_rect = quad->visible_rect; |
| 1791 | 1588 |
| 1792 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( | 1589 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( |
| 1793 quad->tex_coord_rect, quad->rect, tile_rect); | 1590 quad->tex_coord_rect, quad->rect, tile_rect); |
| 1794 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); | 1591 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); |
| 1795 float tex_to_geom_scale_y = | 1592 float tex_to_geom_scale_y = |
| 1796 quad->rect.height() / quad->tex_coord_rect.height(); | 1593 quad->rect.height() / quad->tex_coord_rect.height(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1821 float vertex_tex_translate_y = | 1618 float vertex_tex_translate_y = |
| 1822 -clamp_geom_rect.y() / clamp_geom_rect.height(); | 1619 -clamp_geom_rect.y() / clamp_geom_rect.height(); |
| 1823 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); | 1620 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); |
| 1824 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); | 1621 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); |
| 1825 | 1622 |
| 1826 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1623 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1827 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); | 1624 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); |
| 1828 | 1625 |
| 1829 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); | 1626 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); |
| 1830 float edge[24]; | 1627 float edge[24]; |
| 1831 SetupQuadForClippingAndAntialiasing(device_transform, quad, true, clip_region, | 1628 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); |
| 1832 &local_quad, edge); | 1629 |
| 1833 ResourceProvider::ScopedSamplerGL quad_resource_lock( | 1630 ResourceProvider::ScopedSamplerGL quad_resource_lock( |
| 1834 resource_provider_, resource_id, | 1631 resource_provider_, resource_id, |
| 1835 quad->nearest_neighbor ? GL_NEAREST : GL_LINEAR); | 1632 quad->nearest_neighbor ? GL_NEAREST : GL_LINEAR); |
| 1836 SamplerType sampler = | 1633 SamplerType sampler = |
| 1837 SamplerTypeFromTextureTarget(quad_resource_lock.target()); | 1634 SamplerTypeFromTextureTarget(quad_resource_lock.target()); |
| 1838 | 1635 |
| 1839 float fragment_tex_translate_x = clamp_tex_rect.x(); | 1636 float fragment_tex_translate_x = clamp_tex_rect.x(); |
| 1840 float fragment_tex_translate_y = clamp_tex_rect.y(); | 1637 float fragment_tex_translate_y = clamp_tex_rect.y(); |
| 1841 float fragment_tex_scale_x = clamp_tex_rect.width(); | 1638 float fragment_tex_scale_x = clamp_tex_rect.width(); |
| 1842 float fragment_tex_scale_y = clamp_tex_rect.height(); | 1639 float fragment_tex_scale_y = clamp_tex_rect.height(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1900 // it. This is why this centered rect is used and not the original quad_rect. | 1697 // it. This is why this centered rect is used and not the original quad_rect. |
| 1901 gfx::RectF centered_rect( | 1698 gfx::RectF centered_rect( |
| 1902 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), | 1699 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), |
| 1903 tile_rect.size()); | 1700 tile_rect.size()); |
| 1904 DrawQuadGeometry( | 1701 DrawQuadGeometry( |
| 1905 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); | 1702 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); |
| 1906 } | 1703 } |
| 1907 | 1704 |
| 1908 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, | 1705 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, |
| 1909 const ContentDrawQuadBase* quad, | 1706 const ContentDrawQuadBase* quad, |
| 1910 ResourceProvider::ResourceId resource_id, | 1707 ResourceProvider::ResourceId resource_id) { |
| 1911 const gfx::QuadF* clip_region) { | |
| 1912 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( | 1708 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( |
| 1913 quad->tex_coord_rect, quad->rect, quad->visible_rect); | 1709 quad->tex_coord_rect, quad->rect, quad->visible_rect); |
| 1914 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); | 1710 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); |
| 1915 float tex_to_geom_scale_y = | 1711 float tex_to_geom_scale_y = |
| 1916 quad->rect.height() / quad->tex_coord_rect.height(); | 1712 quad->rect.height() / quad->tex_coord_rect.height(); |
| 1917 | 1713 |
| 1918 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); | 1714 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); |
| 1919 GLenum filter = | 1715 GLenum filter = |
| 1920 (scaled || !quad->quadTransform().IsIdentityOrIntegerTranslation()) && | 1716 (scaled || !quad->quadTransform().IsIdentityOrIntegerTranslation()) && |
| 1921 !quad->nearest_neighbor | 1717 !quad->nearest_neighbor |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 vertex_tex_scale_y)); | 1771 vertex_tex_scale_y)); |
| 1976 | 1772 |
| 1977 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1773 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1978 | 1774 |
| 1979 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); | 1775 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); |
| 1980 | 1776 |
| 1981 // Pass quad coordinates to the uniform in the same order as GeometryBinding | 1777 // Pass quad coordinates to the uniform in the same order as GeometryBinding |
| 1982 // does, then vertices will match the texture mapping in the vertex buffer. | 1778 // does, then vertices will match the texture mapping in the vertex buffer. |
| 1983 // The method SetShaderQuadF() changes the order of vertices and so it's | 1779 // The method SetShaderQuadF() changes the order of vertices and so it's |
| 1984 // not used here. | 1780 // not used here. |
| 1985 gfx::QuadF tile_rect(quad->visible_rect); | 1781 |
| 1986 float width = quad->visible_rect.width(); | 1782 gfx::RectF tile_rect = quad->visible_rect; |
| 1987 float height = quad->visible_rect.height(); | |
| 1988 gfx::PointF top_left = quad->visible_rect.origin(); | |
| 1989 if (clip_region) { | |
| 1990 tile_rect = *clip_region; | |
| 1991 float gl_uv[8] = { | |
| 1992 (tile_rect.p4().x() - top_left.x()) / width, | |
| 1993 (tile_rect.p4().y() - top_left.y()) / height, | |
| 1994 (tile_rect.p1().x() - top_left.x()) / width, | |
| 1995 (tile_rect.p1().y() - top_left.y()) / height, | |
| 1996 (tile_rect.p2().x() - top_left.x()) / width, | |
| 1997 (tile_rect.p2().y() - top_left.y()) / height, | |
| 1998 (tile_rect.p3().x() - top_left.x()) / width, | |
| 1999 (tile_rect.p3().y() - top_left.y()) / height, | |
| 2000 }; | |
| 2001 PrepareGeometry(CLIPPED_BINDING); | |
| 2002 clipped_geometry_->InitializeCustomQuadWithUVs( | |
| 2003 gfx::QuadF(quad->visible_rect), gl_uv); | |
| 2004 } else { | |
| 2005 PrepareGeometry(SHARED_BINDING); | |
| 2006 } | |
| 2007 float gl_quad[8] = { | 1783 float gl_quad[8] = { |
| 2008 tile_rect.p4().x(), | 1784 tile_rect.x(), |
| 2009 tile_rect.p4().y(), | 1785 tile_rect.bottom(), |
| 2010 tile_rect.p1().x(), | 1786 tile_rect.x(), |
| 2011 tile_rect.p1().y(), | 1787 tile_rect.y(), |
| 2012 tile_rect.p2().x(), | 1788 tile_rect.right(), |
| 2013 tile_rect.p2().y(), | 1789 tile_rect.y(), |
| 2014 tile_rect.p3().x(), | 1790 tile_rect.right(), |
| 2015 tile_rect.p3().y(), | 1791 tile_rect.bottom(), |
| 2016 }; | 1792 }; |
| 2017 GLC(gl_, gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad)); | 1793 GLC(gl_, gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad)); |
| 2018 | 1794 |
| 2019 static float gl_matrix[16]; | 1795 static float gl_matrix[16]; |
| 2020 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad->quadTransform()); | 1796 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad->quadTransform()); |
| 2021 GLC(gl_, | 1797 GLC(gl_, |
| 2022 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0])); | 1798 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0])); |
| 2023 | 1799 |
| 2024 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); | 1800 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); |
| 2025 } | 1801 } |
| 2026 | 1802 |
| 2027 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, | 1803 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
| 2028 const YUVVideoDrawQuad* quad, | 1804 const YUVVideoDrawQuad* quad) { |
| 2029 const gfx::QuadF* clip_region) { | |
| 2030 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1805 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2031 | 1806 |
| 2032 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1807 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2033 gl_, | 1808 gl_, |
| 2034 &highp_threshold_cache_, | 1809 &highp_threshold_cache_, |
| 2035 highp_threshold_min_, | 1810 highp_threshold_min_, |
| 2036 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1811 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 2037 | 1812 |
| 2038 bool use_alpha_plane = quad->a_plane_resource_id != 0; | 1813 bool use_alpha_plane = quad->a_plane_resource_id != 0; |
| 2039 | 1814 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2159 case YUVVideoDrawQuad::REC_709: | 1934 case YUVVideoDrawQuad::REC_709: |
| 2160 yuv_to_rgb = yuv_to_rgb_rec709; | 1935 yuv_to_rgb = yuv_to_rgb_rec709; |
| 2161 yuv_adjust = yuv_adjust_constrained; | 1936 yuv_adjust = yuv_adjust_constrained; |
| 2162 break; | 1937 break; |
| 2163 case YUVVideoDrawQuad::JPEG: | 1938 case YUVVideoDrawQuad::JPEG: |
| 2164 yuv_to_rgb = yuv_to_rgb_jpeg; | 1939 yuv_to_rgb = yuv_to_rgb_jpeg; |
| 2165 yuv_adjust = yuv_adjust_full; | 1940 yuv_adjust = yuv_adjust_full; |
| 2166 break; | 1941 break; |
| 2167 } | 1942 } |
| 2168 | 1943 |
| 2169 // The transform and vertex data are used to figure out the extents that the | |
| 2170 // un-antialiased quad should have and which vertex this is and the float | |
| 2171 // quad passed in via uniform is the actual geometry that gets used to draw | |
| 2172 // it. This is why this centered rect is used and not the original quad_rect. | |
| 2173 gfx::RectF tile_rect = quad->visible_rect; | |
| 2174 GLC(gl_, gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb)); | 1944 GLC(gl_, gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb)); |
| 2175 GLC(gl_, gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust)); | 1945 GLC(gl_, gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust)); |
| 2176 | 1946 |
| 2177 SetShaderOpacity(quad->opacity(), alpha_location); | 1947 SetShaderOpacity(quad->opacity(), alpha_location); |
| 2178 if (!clip_region) { | 1948 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, matrix_location); |
| 2179 DrawQuadGeometry(frame, quad->quadTransform(), tile_rect, matrix_location); | |
| 2180 } else { | |
| 2181 float uvs[8] = {0}; | |
| 2182 GetScaledUVs(quad->visible_rect, clip_region, uvs); | |
| 2183 gfx::QuadF region_quad = *clip_region; | |
| 2184 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | |
| 2185 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | |
| 2186 DrawQuadGeometryClippedByQuadF(frame, quad->quadTransform(), tile_rect, | |
| 2187 region_quad, matrix_location, uvs); | |
| 2188 } | |
| 2189 } | 1949 } |
| 2190 | 1950 |
| 2191 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 1951 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
| 2192 const StreamVideoDrawQuad* quad, | 1952 const StreamVideoDrawQuad* quad) { |
| 2193 const gfx::QuadF* clip_region) { | |
| 2194 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1953 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2195 | 1954 |
| 2196 static float gl_matrix[16]; | 1955 static float gl_matrix[16]; |
| 2197 | 1956 |
| 2198 DCHECK(capabilities_.using_egl_image); | 1957 DCHECK(capabilities_.using_egl_image); |
| 2199 | 1958 |
| 2200 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1959 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2201 gl_, | 1960 gl_, |
| 2202 &highp_threshold_cache_, | 1961 &highp_threshold_cache_, |
| 2203 highp_threshold_min_, | 1962 highp_threshold_min_, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2214 | 1973 |
| 2215 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 1974 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2216 quad->resource_id); | 1975 quad->resource_id); |
| 2217 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 1976 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2218 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); | 1977 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); |
| 2219 | 1978 |
| 2220 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 1979 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 2221 | 1980 |
| 2222 SetShaderOpacity(quad->opacity(), | 1981 SetShaderOpacity(quad->opacity(), |
| 2223 program->fragment_shader().alpha_location()); | 1982 program->fragment_shader().alpha_location()); |
| 2224 if (!clip_region) { | 1983 DrawQuadGeometry(frame, |
| 2225 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, | 1984 quad->quadTransform(), |
| 2226 program->vertex_shader().matrix_location()); | 1985 quad->rect, |
| 2227 } else { | 1986 program->vertex_shader().matrix_location()); |
| 2228 gfx::QuadF region_quad(*clip_region); | |
| 2229 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); | |
| 2230 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | |
| 2231 float uvs[8] = {0}; | |
| 2232 GetScaledUVs(quad->visible_rect, clip_region, uvs); | |
| 2233 DrawQuadGeometryClippedByQuadF( | |
| 2234 frame, quad->quadTransform(), quad->rect, region_quad, | |
| 2235 program->vertex_shader().matrix_location(), uvs); | |
| 2236 } | |
| 2237 } | 1987 } |
| 2238 | 1988 |
| 2239 struct TextureProgramBinding { | 1989 struct TextureProgramBinding { |
| 2240 template <class Program> | 1990 template <class Program> |
| 2241 void Set(Program* program) { | 1991 void Set(Program* program) { |
| 2242 DCHECK(program); | 1992 DCHECK(program); |
| 2243 program_id = program->program(); | 1993 program_id = program->program(); |
| 2244 sampler_location = program->fragment_shader().sampler_location(); | 1994 sampler_location = program->fragment_shader().sampler_location(); |
| 2245 matrix_location = program->vertex_shader().matrix_location(); | 1995 matrix_location = program->vertex_shader().matrix_location(); |
| 2246 background_color_location = | 1996 background_color_location = |
| 2247 program->fragment_shader().background_color_location(); | 1997 program->fragment_shader().background_color_location(); |
| 2248 } | 1998 } |
| 2249 int program_id; | 1999 int program_id; |
| 2250 int sampler_location; | 2000 int sampler_location; |
| 2251 int matrix_location; | 2001 int matrix_location; |
| 2252 int transform_location; | |
| 2253 int background_color_location; | 2002 int background_color_location; |
| 2254 }; | 2003 }; |
| 2255 | 2004 |
| 2256 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 2005 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
| 2257 template <class Program> | 2006 template <class Program> |
| 2258 void Set(Program* program) { | 2007 void Set(Program* program) { |
| 2259 TextureProgramBinding::Set(program); | 2008 TextureProgramBinding::Set(program); |
| 2260 tex_transform_location = program->vertex_shader().tex_transform_location(); | 2009 tex_transform_location = program->vertex_shader().tex_transform_location(); |
| 2261 vertex_opacity_location = | 2010 vertex_opacity_location = |
| 2262 program->vertex_shader().vertex_opacity_location(); | 2011 program->vertex_shader().vertex_opacity_location(); |
| 2263 } | 2012 } |
| 2264 int tex_transform_location; | 2013 int tex_transform_location; |
| 2265 int vertex_opacity_location; | 2014 int vertex_opacity_location; |
| 2266 }; | 2015 }; |
| 2267 | 2016 |
| 2268 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { | 2017 void GLRenderer::FlushTextureQuadCache() { |
| 2269 // Check to see if we have anything to draw. | 2018 // Check to see if we have anything to draw. |
| 2270 if (draw_cache_.program_id == -1) | 2019 if (draw_cache_.program_id == -1) |
| 2271 return; | 2020 return; |
| 2272 | 2021 |
| 2273 PrepareGeometry(flush_binding); | |
| 2274 | |
| 2275 // Set the correct blending mode. | 2022 // Set the correct blending mode. |
| 2276 SetBlendEnabled(draw_cache_.needs_blending); | 2023 SetBlendEnabled(draw_cache_.needs_blending); |
| 2277 | 2024 |
| 2278 // Bind the program to the GL state. | 2025 // Bind the program to the GL state. |
| 2279 SetUseProgram(draw_cache_.program_id); | 2026 SetUseProgram(draw_cache_.program_id); |
| 2280 | 2027 |
| 2281 // Bind the correct texture sampler location. | 2028 // Bind the correct texture sampler location. |
| 2282 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); | 2029 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); |
| 2283 | 2030 |
| 2284 // Assume the current active textures is 0. | 2031 // Assume the current active textures is 0. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2325 gl_->DrawElements(GL_TRIANGLES, | 2072 gl_->DrawElements(GL_TRIANGLES, |
| 2326 6 * draw_cache_.matrix_data.size(), | 2073 6 * draw_cache_.matrix_data.size(), |
| 2327 GL_UNSIGNED_SHORT, | 2074 GL_UNSIGNED_SHORT, |
| 2328 0)); | 2075 0)); |
| 2329 | 2076 |
| 2330 // Clear the cache. | 2077 // Clear the cache. |
| 2331 draw_cache_.program_id = -1; | 2078 draw_cache_.program_id = -1; |
| 2332 draw_cache_.uv_xform_data.resize(0); | 2079 draw_cache_.uv_xform_data.resize(0); |
| 2333 draw_cache_.vertex_opacity_data.resize(0); | 2080 draw_cache_.vertex_opacity_data.resize(0); |
| 2334 draw_cache_.matrix_data.resize(0); | 2081 draw_cache_.matrix_data.resize(0); |
| 2335 | |
| 2336 // If we had a clipped binding, prepare the shared binding for the | |
| 2337 // next inserts. | |
| 2338 if (flush_binding == CLIPPED_BINDING) { | |
| 2339 PrepareGeometry(SHARED_BINDING); | |
| 2340 } | |
| 2341 } | 2082 } |
| 2342 | 2083 |
| 2343 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, | 2084 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, |
| 2344 const TextureDrawQuad* quad, | 2085 const TextureDrawQuad* quad) { |
| 2345 const gfx::QuadF* clip_region) { | |
| 2346 // If we have a clip_region then we have to render the next quad | |
| 2347 // with dynamic geometry, therefore we must flush all pending | |
| 2348 // texture quads. | |
| 2349 if (clip_region) { | |
| 2350 // We send in false here because we want to flush what's currently in the | |
| 2351 // queue using the shared_geometry and not clipped_geometry | |
| 2352 FlushTextureQuadCache(SHARED_BINDING); | |
| 2353 } | |
| 2354 | |
| 2355 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2086 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2356 gl_, | 2087 gl_, |
| 2357 &highp_threshold_cache_, | 2088 &highp_threshold_cache_, |
| 2358 highp_threshold_min_, | 2089 highp_threshold_min_, |
| 2359 quad->shared_quad_state->visible_content_rect.bottom_right()); | 2090 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 2360 | 2091 |
| 2361 // Choose the correct texture program binding | 2092 // Choose the correct texture program binding |
| 2362 TexTransformTextureProgramBinding binding; | 2093 TexTransformTextureProgramBinding binding; |
| 2363 if (quad->premultiplied_alpha) { | 2094 if (quad->premultiplied_alpha) { |
| 2364 if (quad->background_color == SK_ColorTRANSPARENT) { | 2095 if (quad->background_color == SK_ColorTRANSPARENT) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2376 } | 2107 } |
| 2377 | 2108 |
| 2378 int resource_id = quad->resource_id; | 2109 int resource_id = quad->resource_id; |
| 2379 | 2110 |
| 2380 if (draw_cache_.program_id != binding.program_id || | 2111 if (draw_cache_.program_id != binding.program_id || |
| 2381 draw_cache_.resource_id != resource_id || | 2112 draw_cache_.resource_id != resource_id || |
| 2382 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || | 2113 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || |
| 2383 draw_cache_.nearest_neighbor != quad->nearest_neighbor || | 2114 draw_cache_.nearest_neighbor != quad->nearest_neighbor || |
| 2384 draw_cache_.background_color != quad->background_color || | 2115 draw_cache_.background_color != quad->background_color || |
| 2385 draw_cache_.matrix_data.size() >= 8) { | 2116 draw_cache_.matrix_data.size() >= 8) { |
| 2386 FlushTextureQuadCache(SHARED_BINDING); | 2117 FlushTextureQuadCache(); |
| 2387 draw_cache_.program_id = binding.program_id; | 2118 draw_cache_.program_id = binding.program_id; |
| 2388 draw_cache_.resource_id = resource_id; | 2119 draw_cache_.resource_id = resource_id; |
| 2389 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); | 2120 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); |
| 2390 draw_cache_.nearest_neighbor = quad->nearest_neighbor; | 2121 draw_cache_.nearest_neighbor = quad->nearest_neighbor; |
| 2391 draw_cache_.background_color = quad->background_color; | 2122 draw_cache_.background_color = quad->background_color; |
| 2392 | 2123 |
| 2393 draw_cache_.uv_xform_location = binding.tex_transform_location; | 2124 draw_cache_.uv_xform_location = binding.tex_transform_location; |
| 2394 draw_cache_.background_color_location = binding.background_color_location; | 2125 draw_cache_.background_color_location = binding.background_color_location; |
| 2395 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; | 2126 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; |
| 2396 draw_cache_.matrix_location = binding.matrix_location; | 2127 draw_cache_.matrix_location = binding.matrix_location; |
| 2397 draw_cache_.sampler_location = binding.sampler_location; | 2128 draw_cache_.sampler_location = binding.sampler_location; |
| 2398 } | 2129 } |
| 2399 | 2130 |
| 2400 // Generate the uv-transform | 2131 // Generate the uv-transform |
| 2401 if (!clip_region) { | 2132 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); |
| 2402 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); | |
| 2403 } else { | |
| 2404 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; | |
| 2405 draw_cache_.uv_xform_data.push_back(uv_transform); | |
| 2406 } | |
| 2407 | 2133 |
| 2408 // Generate the vertex opacity | 2134 // Generate the vertex opacity |
| 2409 const float opacity = quad->opacity(); | 2135 const float opacity = quad->opacity(); |
| 2410 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); | 2136 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); |
| 2411 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); | 2137 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); |
| 2412 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); | 2138 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); |
| 2413 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); | 2139 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); |
| 2414 | 2140 |
| 2415 // Generate the transform matrix | 2141 // Generate the transform matrix |
| 2416 gfx::Transform quad_rect_matrix; | 2142 gfx::Transform quad_rect_matrix; |
| 2417 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 2143 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
| 2418 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; | 2144 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; |
| 2419 | 2145 |
| 2420 Float16 m; | 2146 Float16 m; |
| 2421 quad_rect_matrix.matrix().asColMajorf(m.data); | 2147 quad_rect_matrix.matrix().asColMajorf(m.data); |
| 2422 draw_cache_.matrix_data.push_back(m); | 2148 draw_cache_.matrix_data.push_back(m); |
| 2423 | |
| 2424 if (clip_region) { | |
| 2425 gfx::QuadF scaled_region; | |
| 2426 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { | |
| 2427 scaled_region = SharedGeometryQuad().BoundingBox(); | |
| 2428 } | |
| 2429 // Both the scaled region and the SharedGeomtryQuad are in the space | |
| 2430 // -0.5->0.5. We need to move that to the space 0->1. | |
| 2431 float uv[8]; | |
| 2432 uv[0] = scaled_region.p1().x() + 0.5f; | |
| 2433 uv[1] = scaled_region.p1().y() + 0.5f; | |
| 2434 uv[2] = scaled_region.p2().x() + 0.5f; | |
| 2435 uv[3] = scaled_region.p2().y() + 0.5f; | |
| 2436 uv[4] = scaled_region.p3().x() + 0.5f; | |
| 2437 uv[5] = scaled_region.p3().y() + 0.5f; | |
| 2438 uv[6] = scaled_region.p4().x() + 0.5f; | |
| 2439 uv[7] = scaled_region.p4().y() + 0.5f; | |
| 2440 PrepareGeometry(CLIPPED_BINDING); | |
| 2441 clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv); | |
| 2442 FlushTextureQuadCache(CLIPPED_BINDING); | |
| 2443 } | |
| 2444 } | 2149 } |
| 2445 | 2150 |
| 2446 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, | 2151 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, |
| 2447 const IOSurfaceDrawQuad* quad, | 2152 const IOSurfaceDrawQuad* quad) { |
| 2448 const gfx::QuadF* clip_region) { | |
| 2449 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2153 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2450 | 2154 |
| 2451 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2155 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2452 gl_, | 2156 gl_, |
| 2453 &highp_threshold_cache_, | 2157 &highp_threshold_cache_, |
| 2454 highp_threshold_min_, | 2158 highp_threshold_min_, |
| 2455 quad->shared_quad_state->visible_content_rect.bottom_right()); | 2159 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 2456 | 2160 |
| 2457 TexTransformTextureProgramBinding binding; | 2161 TexTransformTextureProgramBinding binding; |
| 2458 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision)); | 2162 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2477 | 2181 |
| 2478 const float vertex_opacity[] = {quad->opacity(), quad->opacity(), | 2182 const float vertex_opacity[] = {quad->opacity(), quad->opacity(), |
| 2479 quad->opacity(), quad->opacity()}; | 2183 quad->opacity(), quad->opacity()}; |
| 2480 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity)); | 2184 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity)); |
| 2481 | 2185 |
| 2482 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 2186 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2483 quad->io_surface_resource_id); | 2187 quad->io_surface_resource_id); |
| 2484 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2188 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2485 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); | 2189 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); |
| 2486 | 2190 |
| 2487 if (!clip_region) { | 2191 DrawQuadGeometry( |
| 2488 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, | 2192 frame, quad->quadTransform(), quad->rect, binding.matrix_location); |
| 2489 binding.matrix_location); | |
| 2490 } else { | |
| 2491 float uvs[8] = {0}; | |
| 2492 GetScaledUVs(quad->visible_rect, clip_region, uvs); | |
| 2493 DrawQuadGeometryClippedByQuadF(frame, quad->quadTransform(), quad->rect, | |
| 2494 *clip_region, binding.matrix_location, uvs); | |
| 2495 } | |
| 2496 | 2193 |
| 2497 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); | 2194 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); |
| 2498 } | 2195 } |
| 2499 | 2196 |
| 2500 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 2197 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
| 2501 if (use_sync_query_) { | 2198 if (use_sync_query_) { |
| 2502 DCHECK(current_sync_query_); | 2199 DCHECK(current_sync_query_); |
| 2503 current_sync_query_->End(); | 2200 current_sync_query_->End(); |
| 2504 pending_sync_queries_.push_back(current_sync_query_.Pass()); | 2201 pending_sync_queries_.push_back(current_sync_query_.Pass()); |
| 2505 } | 2202 } |
| 2506 | 2203 |
| 2507 current_framebuffer_lock_ = nullptr; | 2204 current_framebuffer_lock_ = nullptr; |
| 2508 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); | 2205 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); |
| 2509 | 2206 |
| 2510 GLC(gl_, gl_->Disable(GL_BLEND)); | 2207 GLC(gl_, gl_->Disable(GL_BLEND)); |
| 2511 blend_shadow_ = false; | 2208 blend_shadow_ = false; |
| 2512 | 2209 |
| 2513 ScheduleOverlays(frame); | 2210 ScheduleOverlays(frame); |
| 2514 } | 2211 } |
| 2515 | 2212 |
| 2516 void GLRenderer::FinishDrawingQuadList() { | 2213 void GLRenderer::FinishDrawingQuadList() { FlushTextureQuadCache(); } |
| 2517 FlushTextureQuadCache(SHARED_BINDING); | |
| 2518 } | |
| 2519 | 2214 |
| 2520 bool GLRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { | 2215 bool GLRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { |
| 2521 if (frame->current_render_pass != frame->root_render_pass) | 2216 if (frame->current_render_pass != frame->root_render_pass) |
| 2522 return true; | 2217 return true; |
| 2523 return FlippedRootFramebuffer(); | 2218 return FlippedRootFramebuffer(); |
| 2524 } | 2219 } |
| 2525 | 2220 |
| 2526 bool GLRenderer::FlippedRootFramebuffer() const { | 2221 bool GLRenderer::FlippedRootFramebuffer() const { |
| 2527 // GL is normally flipped, so a flipped output results in an unflipping. | 2222 // GL is normally flipped, so a flipped output results in an unflipping. |
| 2528 return !output_surface_->capabilities().flipped_output_surface; | 2223 return !output_surface_->capabilities().flipped_output_surface; |
| 2529 } | 2224 } |
| 2530 | 2225 |
| 2531 void GLRenderer::EnsureScissorTestEnabled() { | 2226 void GLRenderer::EnsureScissorTestEnabled() { |
| 2532 if (is_scissor_enabled_) | 2227 if (is_scissor_enabled_) |
| 2533 return; | 2228 return; |
| 2534 | 2229 |
| 2535 FlushTextureQuadCache(SHARED_BINDING); | 2230 FlushTextureQuadCache(); |
| 2536 GLC(gl_, gl_->Enable(GL_SCISSOR_TEST)); | 2231 GLC(gl_, gl_->Enable(GL_SCISSOR_TEST)); |
| 2537 is_scissor_enabled_ = true; | 2232 is_scissor_enabled_ = true; |
| 2538 } | 2233 } |
| 2539 | 2234 |
| 2540 void GLRenderer::EnsureScissorTestDisabled() { | 2235 void GLRenderer::EnsureScissorTestDisabled() { |
| 2541 if (!is_scissor_enabled_) | 2236 if (!is_scissor_enabled_) |
| 2542 return; | 2237 return; |
| 2543 | 2238 |
| 2544 FlushTextureQuadCache(SHARED_BINDING); | 2239 FlushTextureQuadCache(); |
| 2545 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); | 2240 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); |
| 2546 is_scissor_enabled_ = false; | 2241 is_scissor_enabled_ = false; |
| 2547 } | 2242 } |
| 2548 | 2243 |
| 2549 void GLRenderer::CopyCurrentRenderPassToBitmap( | 2244 void GLRenderer::CopyCurrentRenderPassToBitmap( |
| 2550 DrawingFrame* frame, | 2245 DrawingFrame* frame, |
| 2551 scoped_ptr<CopyOutputRequest> request) { | 2246 scoped_ptr<CopyOutputRequest> request) { |
| 2552 TRACE_EVENT0("cc", "GLRenderer::CopyCurrentRenderPassToBitmap"); | 2247 TRACE_EVENT0("cc", "GLRenderer::CopyCurrentRenderPassToBitmap"); |
| 2553 gfx::Rect copy_rect = frame->current_render_pass->output_rect; | 2248 gfx::Rect copy_rect = frame->current_render_pass->output_rect; |
| 2554 if (request->has_area()) | 2249 if (request->has_area()) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2603 blend_shadow_ = enabled; | 2298 blend_shadow_ = enabled; |
| 2604 } | 2299 } |
| 2605 | 2300 |
| 2606 void GLRenderer::SetUseProgram(unsigned program) { | 2301 void GLRenderer::SetUseProgram(unsigned program) { |
| 2607 if (program == program_shadow_) | 2302 if (program == program_shadow_) |
| 2608 return; | 2303 return; |
| 2609 gl_->UseProgram(program); | 2304 gl_->UseProgram(program); |
| 2610 program_shadow_ = program; | 2305 program_shadow_ = program; |
| 2611 } | 2306 } |
| 2612 | 2307 |
| 2613 void GLRenderer::DrawQuadGeometryClippedByQuadF( | |
| 2614 const DrawingFrame* frame, | |
| 2615 const gfx::Transform& draw_transform, | |
| 2616 const gfx::RectF& quad_rect, | |
| 2617 const gfx::QuadF& clipping_region_quad, | |
| 2618 int matrix_location, | |
| 2619 const float* uvs) { | |
| 2620 PrepareGeometry(CLIPPED_BINDING); | |
| 2621 if (uvs) { | |
| 2622 clipped_geometry_->InitializeCustomQuadWithUVs(clipping_region_quad, uvs); | |
| 2623 } else { | |
| 2624 clipped_geometry_->InitializeCustomQuad(clipping_region_quad); | |
| 2625 } | |
| 2626 gfx::Transform quad_rect_matrix; | |
| 2627 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); | |
| 2628 static float gl_matrix[16]; | |
| 2629 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); | |
| 2630 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); | |
| 2631 | |
| 2632 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, | |
| 2633 reinterpret_cast<const void*>(0))); | |
| 2634 } | |
| 2635 | |
| 2636 void GLRenderer::DrawQuadGeometry(const DrawingFrame* frame, | 2308 void GLRenderer::DrawQuadGeometry(const DrawingFrame* frame, |
| 2637 const gfx::Transform& draw_transform, | 2309 const gfx::Transform& draw_transform, |
| 2638 const gfx::RectF& quad_rect, | 2310 const gfx::RectF& quad_rect, |
| 2639 int matrix_location) { | 2311 int matrix_location) { |
| 2640 PrepareGeometry(SHARED_BINDING); | |
| 2641 gfx::Transform quad_rect_matrix; | 2312 gfx::Transform quad_rect_matrix; |
| 2642 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); | 2313 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); |
| 2643 static float gl_matrix[16]; | 2314 static float gl_matrix[16]; |
| 2644 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); | 2315 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); |
| 2645 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); | 2316 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); |
| 2646 | 2317 |
| 2647 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); | 2318 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); |
| 2648 } | 2319 } |
| 2649 | 2320 |
| 2650 void GLRenderer::Finish() { | 2321 void GLRenderer::Finish() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2693 | 2364 |
| 2694 void GLRenderer::EnforceMemoryPolicy() { | 2365 void GLRenderer::EnforceMemoryPolicy() { |
| 2695 if (!visible()) { | 2366 if (!visible()) { |
| 2696 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); | 2367 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); |
| 2697 ReleaseRenderPassTextures(); | 2368 ReleaseRenderPassTextures(); |
| 2698 DiscardBackbuffer(); | 2369 DiscardBackbuffer(); |
| 2699 resource_provider_->ReleaseCachedData(); | 2370 resource_provider_->ReleaseCachedData(); |
| 2700 output_surface_->context_provider()->DeleteCachedResources(); | 2371 output_surface_->context_provider()->DeleteCachedResources(); |
| 2701 GLC(gl_, gl_->Flush()); | 2372 GLC(gl_, gl_->Flush()); |
| 2702 } | 2373 } |
| 2703 PrepareGeometry(NO_BINDING); | |
| 2704 } | 2374 } |
| 2705 | 2375 |
| 2706 void GLRenderer::DiscardBackbuffer() { | 2376 void GLRenderer::DiscardBackbuffer() { |
| 2707 if (is_backbuffer_discarded_) | 2377 if (is_backbuffer_discarded_) |
| 2708 return; | 2378 return; |
| 2709 | 2379 |
| 2710 output_surface_->DiscardBackbuffer(); | 2380 output_surface_->DiscardBackbuffer(); |
| 2711 | 2381 |
| 2712 is_backbuffer_discarded_ = true; | 2382 is_backbuffer_discarded_ = true; |
| 2713 | 2383 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3025 | 2695 |
| 3026 void GLRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { | 2696 void GLRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { |
| 3027 EnsureScissorTestEnabled(); | 2697 EnsureScissorTestEnabled(); |
| 3028 | 2698 |
| 3029 // Don't unnecessarily ask the context to change the scissor, because it | 2699 // Don't unnecessarily ask the context to change the scissor, because it |
| 3030 // may cause undesired GPU pipeline flushes. | 2700 // may cause undesired GPU pipeline flushes. |
| 3031 if (scissor_rect == scissor_rect_ && !scissor_rect_needs_reset_) | 2701 if (scissor_rect == scissor_rect_ && !scissor_rect_needs_reset_) |
| 3032 return; | 2702 return; |
| 3033 | 2703 |
| 3034 scissor_rect_ = scissor_rect; | 2704 scissor_rect_ = scissor_rect; |
| 3035 FlushTextureQuadCache(SHARED_BINDING); | 2705 FlushTextureQuadCache(); |
| 3036 GLC(gl_, | 2706 GLC(gl_, |
| 3037 gl_->Scissor(scissor_rect.x(), | 2707 gl_->Scissor(scissor_rect.x(), |
| 3038 scissor_rect.y(), | 2708 scissor_rect.y(), |
| 3039 scissor_rect.width(), | 2709 scissor_rect.width(), |
| 3040 scissor_rect.height())); | 2710 scissor_rect.height())); |
| 3041 | 2711 |
| 3042 scissor_rect_needs_reset_ = false; | 2712 scissor_rect_needs_reset_ = false; |
| 3043 } | 2713 } |
| 3044 | 2714 |
| 3045 void GLRenderer::SetDrawViewport(const gfx::Rect& window_space_viewport) { | 2715 void GLRenderer::SetDrawViewport(const gfx::Rect& window_space_viewport) { |
| 3046 viewport_ = window_space_viewport; | 2716 viewport_ = window_space_viewport; |
| 3047 GLC(gl_, | 2717 GLC(gl_, |
| 3048 gl_->Viewport(window_space_viewport.x(), | 2718 gl_->Viewport(window_space_viewport.x(), |
| 3049 window_space_viewport.y(), | 2719 window_space_viewport.y(), |
| 3050 window_space_viewport.width(), | 2720 window_space_viewport.width(), |
| 3051 window_space_viewport.height())); | 2721 window_space_viewport.height())); |
| 3052 } | 2722 } |
| 3053 | 2723 |
| 3054 void GLRenderer::InitializeSharedObjects() { | 2724 void GLRenderer::InitializeSharedObjects() { |
| 3055 TRACE_EVENT0("cc", "GLRenderer::InitializeSharedObjects"); | 2725 TRACE_EVENT0("cc", "GLRenderer::InitializeSharedObjects"); |
| 3056 | 2726 |
| 3057 // Create an FBO for doing offscreen rendering. | 2727 // Create an FBO for doing offscreen rendering. |
| 3058 GLC(gl_, gl_->GenFramebuffers(1, &offscreen_framebuffer_id_)); | 2728 GLC(gl_, gl_->GenFramebuffers(1, &offscreen_framebuffer_id_)); |
| 3059 | 2729 |
| 3060 shared_geometry_ = | 2730 shared_geometry_ = make_scoped_ptr( |
| 3061 make_scoped_ptr(new StaticGeometryBinding(gl_, QuadVertexRect())); | 2731 new GeometryBinding(gl_, QuadVertexRect())); |
| 3062 clipped_geometry_ = make_scoped_ptr(new DynamicGeometryBinding(gl_)); | |
| 3063 } | |
| 3064 | |
| 3065 void GLRenderer::PrepareGeometry(BoundGeometry binding) { | |
| 3066 if (binding == bound_geometry_) { | |
| 3067 return; | |
| 3068 } | |
| 3069 | |
| 3070 switch (binding) { | |
| 3071 case SHARED_BINDING: | |
| 3072 shared_geometry_->PrepareForDraw(); | |
| 3073 break; | |
| 3074 case CLIPPED_BINDING: | |
| 3075 clipped_geometry_->PrepareForDraw(); | |
| 3076 break; | |
| 3077 case NO_BINDING: | |
| 3078 break; | |
| 3079 } | |
| 3080 bound_geometry_ = binding; | |
| 3081 } | 2732 } |
| 3082 | 2733 |
| 3083 const GLRenderer::TileCheckerboardProgram* | 2734 const GLRenderer::TileCheckerboardProgram* |
| 3084 GLRenderer::GetTileCheckerboardProgram() { | 2735 GLRenderer::GetTileCheckerboardProgram() { |
| 3085 if (!tile_checkerboard_program_.initialized()) { | 2736 if (!tile_checkerboard_program_.initialized()) { |
| 3086 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); | 2737 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); |
| 3087 tile_checkerboard_program_.Initialize(output_surface_->context_provider(), | 2738 tile_checkerboard_program_.Initialize(output_surface_->context_provider(), |
| 3088 TEX_COORD_PRECISION_NA, | 2739 TEX_COORD_PRECISION_NA, |
| 3089 SAMPLER_TYPE_NA); | 2740 SAMPLER_TYPE_NA); |
| 3090 } | 2741 } |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3535 scissor_rect_needs_reset_ = true; | 3186 scissor_rect_needs_reset_ = true; |
| 3536 stencil_shadow_ = false; | 3187 stencil_shadow_ = false; |
| 3537 blend_shadow_ = true; | 3188 blend_shadow_ = true; |
| 3538 program_shadow_ = 0; | 3189 program_shadow_ = 0; |
| 3539 | 3190 |
| 3540 RestoreGLState(); | 3191 RestoreGLState(); |
| 3541 } | 3192 } |
| 3542 | 3193 |
| 3543 void GLRenderer::RestoreGLState() { | 3194 void GLRenderer::RestoreGLState() { |
| 3544 // This restores the current GLRenderer state to the GL context. | 3195 // This restores the current GLRenderer state to the GL context. |
| 3545 bound_geometry_ = NO_BINDING; | 3196 |
| 3546 PrepareGeometry(SHARED_BINDING); | 3197 shared_geometry_->PrepareForDraw(); |
| 3547 | 3198 |
| 3548 GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); | 3199 GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); |
| 3549 GLC(gl_, gl_->Disable(GL_CULL_FACE)); | 3200 GLC(gl_, gl_->Disable(GL_CULL_FACE)); |
| 3550 GLC(gl_, gl_->ColorMask(true, true, true, true)); | 3201 GLC(gl_, gl_->ColorMask(true, true, true, true)); |
| 3551 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 3202 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
| 3552 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); | 3203 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); |
| 3553 | 3204 |
| 3554 if (program_shadow_) | 3205 if (program_shadow_) |
| 3555 gl_->UseProgram(program_shadow_); | 3206 gl_->UseProgram(program_shadow_); |
| 3556 | 3207 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3604 context_support_->ScheduleOverlayPlane( | 3255 context_support_->ScheduleOverlayPlane( |
| 3605 overlay.plane_z_order, | 3256 overlay.plane_z_order, |
| 3606 overlay.transform, | 3257 overlay.transform, |
| 3607 pending_overlay_resources_.back()->texture_id(), | 3258 pending_overlay_resources_.back()->texture_id(), |
| 3608 overlay.display_rect, | 3259 overlay.display_rect, |
| 3609 overlay.uv_rect); | 3260 overlay.uv_rect); |
| 3610 } | 3261 } |
| 3611 } | 3262 } |
| 3612 | 3263 |
| 3613 } // namespace cc | 3264 } // namespace cc |
| OLD | NEW |