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