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/output/compositor_frame.h" | 21 #include "cc/output/compositor_frame.h" |
17 #include "cc/output/compositor_frame_metadata.h" | 22 #include "cc/output/compositor_frame_metadata.h" |
18 #include "cc/output/context_provider.h" | 23 #include "cc/output/context_provider.h" |
19 #include "cc/output/copy_output_request.h" | 24 #include "cc/output/copy_output_request.h" |
20 #include "cc/output/geometry_binding.h" | 25 #include "cc/output/dynamic_geometry_binding.h" |
21 #include "cc/output/gl_frame_data.h" | 26 #include "cc/output/gl_frame_data.h" |
22 #include "cc/output/output_surface.h" | 27 #include "cc/output/output_surface.h" |
23 #include "cc/output/render_surface_filters.h" | 28 #include "cc/output/render_surface_filters.h" |
| 29 #include "cc/output/static_geometry_binding.h" |
| 30 #include "cc/quads/draw_polygon.h" |
24 #include "cc/quads/picture_draw_quad.h" | 31 #include "cc/quads/picture_draw_quad.h" |
25 #include "cc/quads/render_pass.h" | 32 #include "cc/quads/render_pass.h" |
26 #include "cc/quads/stream_video_draw_quad.h" | 33 #include "cc/quads/stream_video_draw_quad.h" |
27 #include "cc/quads/texture_draw_quad.h" | 34 #include "cc/quads/texture_draw_quad.h" |
28 #include "cc/resources/layer_quad.h" | 35 #include "cc/resources/layer_quad.h" |
29 #include "cc/resources/scoped_gpu_raster.h" | 36 #include "cc/resources/scoped_gpu_raster.h" |
30 #include "cc/resources/scoped_resource.h" | 37 #include "cc/resources/scoped_resource.h" |
31 #include "cc/resources/texture_mailbox_deleter.h" | 38 #include "cc/resources/texture_mailbox_deleter.h" |
32 #include "gpu/GLES2/gl2extchromium.h" | 39 #include "gpu/GLES2/gl2extchromium.h" |
33 #include "gpu/command_buffer/client/context_support.h" | 40 #include "gpu/command_buffer/client/context_support.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 context_support_(output_surface->context_provider()->ContextSupport()), | 323 context_support_(output_surface->context_provider()->ContextSupport()), |
317 texture_mailbox_deleter_(texture_mailbox_deleter), | 324 texture_mailbox_deleter_(texture_mailbox_deleter), |
318 is_backbuffer_discarded_(false), | 325 is_backbuffer_discarded_(false), |
319 is_scissor_enabled_(false), | 326 is_scissor_enabled_(false), |
320 scissor_rect_needs_reset_(true), | 327 scissor_rect_needs_reset_(true), |
321 stencil_shadow_(false), | 328 stencil_shadow_(false), |
322 blend_shadow_(false), | 329 blend_shadow_(false), |
323 highp_threshold_min_(highp_threshold_min), | 330 highp_threshold_min_(highp_threshold_min), |
324 highp_threshold_cache_(0), | 331 highp_threshold_cache_(0), |
325 use_sync_query_(false), | 332 use_sync_query_(false), |
326 on_demand_tile_raster_resource_id_(0) { | 333 on_demand_tile_raster_resource_id_(0), |
| 334 bound_geometry_(NO_BINDING) { |
327 DCHECK(gl_); | 335 DCHECK(gl_); |
328 DCHECK(context_support_); | 336 DCHECK(context_support_); |
329 | 337 |
330 ContextProvider::Capabilities context_caps = | 338 ContextProvider::Capabilities context_caps = |
331 output_surface_->context_provider()->ContextCapabilities(); | 339 output_surface_->context_provider()->ContextCapabilities(); |
332 | 340 |
333 capabilities_.using_partial_swap = | 341 capabilities_.using_partial_swap = |
334 settings_->partial_swap_enabled && context_caps.gpu.post_sub_buffer; | 342 settings_->partial_swap_enabled && context_caps.gpu.post_sub_buffer; |
335 | 343 |
336 DCHECK(!context_caps.gpu.iosurface || context_caps.gpu.texture_rectangle); | 344 DCHECK(!context_caps.gpu.iosurface || context_caps.gpu.texture_rectangle); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 494 |
487 // TODO(enne): Do we need to reinitialize all of this state per frame? | 495 // TODO(enne): Do we need to reinitialize all of this state per frame? |
488 ReinitializeGLState(); | 496 ReinitializeGLState(); |
489 } | 497 } |
490 | 498 |
491 void GLRenderer::DoNoOp() { | 499 void GLRenderer::DoNoOp() { |
492 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, 0)); | 500 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, 0)); |
493 GLC(gl_, gl_->Flush()); | 501 GLC(gl_, gl_->Flush()); |
494 } | 502 } |
495 | 503 |
496 void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { | 504 void GLRenderer::DoDrawQuad(DrawingFrame* frame, |
| 505 const DrawQuad* quad, |
| 506 const gfx::QuadF* clip_region) { |
497 DCHECK(quad->rect.Contains(quad->visible_rect)); | 507 DCHECK(quad->rect.Contains(quad->visible_rect)); |
498 if (quad->material != DrawQuad::TEXTURE_CONTENT) { | 508 if (quad->material != DrawQuad::TEXTURE_CONTENT) { |
499 FlushTextureQuadCache(); | 509 FlushTextureQuadCache(SHARED_BINDING); |
500 } | 510 } |
501 | 511 |
502 switch (quad->material) { | 512 switch (quad->material) { |
503 case DrawQuad::INVALID: | 513 case DrawQuad::INVALID: |
504 NOTREACHED(); | 514 NOTREACHED(); |
505 break; | 515 break; |
506 case DrawQuad::CHECKERBOARD: | 516 case DrawQuad::CHECKERBOARD: |
507 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); | 517 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad), |
| 518 clip_region); |
508 break; | 519 break; |
509 case DrawQuad::DEBUG_BORDER: | 520 case DrawQuad::DEBUG_BORDER: |
510 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 521 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); |
511 break; | 522 break; |
512 case DrawQuad::IO_SURFACE_CONTENT: | 523 case DrawQuad::IO_SURFACE_CONTENT: |
513 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad)); | 524 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad), |
| 525 clip_region); |
514 break; | 526 break; |
515 case DrawQuad::PICTURE_CONTENT: | 527 case DrawQuad::PICTURE_CONTENT: |
516 // PictureDrawQuad should only be used for resourceless software draws. | 528 // PictureDrawQuad should only be used for resourceless software draws. |
517 NOTREACHED(); | 529 NOTREACHED(); |
518 break; | 530 break; |
519 case DrawQuad::RENDER_PASS: | 531 case DrawQuad::RENDER_PASS: |
520 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); | 532 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad), |
| 533 clip_region); |
521 break; | 534 break; |
522 case DrawQuad::SOLID_COLOR: | 535 case DrawQuad::SOLID_COLOR: |
523 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); | 536 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad), |
| 537 clip_region); |
524 break; | 538 break; |
525 case DrawQuad::STREAM_VIDEO_CONTENT: | 539 case DrawQuad::STREAM_VIDEO_CONTENT: |
526 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad)); | 540 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad), |
| 541 clip_region); |
527 break; | 542 break; |
528 case DrawQuad::SURFACE_CONTENT: | 543 case DrawQuad::SURFACE_CONTENT: |
529 // Surface content should be fully resolved to other quad types before | 544 // Surface content should be fully resolved to other quad types before |
530 // reaching a direct renderer. | 545 // reaching a direct renderer. |
531 NOTREACHED(); | 546 NOTREACHED(); |
532 break; | 547 break; |
533 case DrawQuad::TEXTURE_CONTENT: | 548 case DrawQuad::TEXTURE_CONTENT: |
534 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); | 549 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), |
| 550 clip_region); |
535 break; | 551 break; |
536 case DrawQuad::TILED_CONTENT: | 552 case DrawQuad::TILED_CONTENT: |
537 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); | 553 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); |
538 break; | 554 break; |
539 case DrawQuad::YUV_VIDEO_CONTENT: | 555 case DrawQuad::YUV_VIDEO_CONTENT: |
540 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); | 556 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), |
| 557 clip_region); |
541 break; | 558 break; |
542 } | 559 } |
543 } | 560 } |
544 | 561 |
545 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, | 562 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, |
546 const CheckerboardDrawQuad* quad) { | 563 const CheckerboardDrawQuad* quad, |
| 564 const gfx::QuadF* clip_region) { |
| 565 // TODO(enne) For now since checkerboards shouldn't be part of a 3D |
| 566 // context, clipping regions aren't supported so we skip drawing them |
| 567 // if this becomes the case. |
| 568 if (clip_region) { |
| 569 return; |
| 570 } |
547 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 571 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
548 | 572 |
549 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); | 573 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); |
550 DCHECK(program && (program->initialized() || IsContextLost())); | 574 DCHECK(program && (program->initialized() || IsContextLost())); |
551 SetUseProgram(program->program()); | 575 SetUseProgram(program->program()); |
552 | 576 |
553 SkColor color = quad->color; | 577 SkColor color = quad->color; |
554 GLC(gl_, | 578 GLC(gl_, |
555 gl_->Uniform4f(program->fragment_shader().color_location(), | 579 gl_->Uniform4f(program->fragment_shader().color_location(), |
556 SkColorGetR(color) * (1.0f / 255.0f), | 580 SkColorGetR(color) * (1.0f / 255.0f), |
(...skipping 23 matching lines...) Expand all Loading... |
580 frequency)); | 604 frequency)); |
581 | 605 |
582 SetShaderOpacity(quad->opacity(), | 606 SetShaderOpacity(quad->opacity(), |
583 program->fragment_shader().alpha_location()); | 607 program->fragment_shader().alpha_location()); |
584 DrawQuadGeometry(frame, | 608 DrawQuadGeometry(frame, |
585 quad->quadTransform(), | 609 quad->quadTransform(), |
586 quad->rect, | 610 quad->rect, |
587 program->vertex_shader().matrix_location()); | 611 program->vertex_shader().matrix_location()); |
588 } | 612 } |
589 | 613 |
| 614 // This function does not handle 3D sorting right now, since the debug border |
| 615 // quads are just drawn as their original quads and not in split pieces. This |
| 616 // results in some debug border quads drawing over foreground quads. |
590 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, | 617 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, |
591 const DebugBorderDrawQuad* quad) { | 618 const DebugBorderDrawQuad* quad) { |
592 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 619 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
593 | 620 |
594 static float gl_matrix[16]; | 621 static float gl_matrix[16]; |
595 const DebugBorderProgram* program = GetDebugBorderProgram(); | 622 const DebugBorderProgram* program = GetDebugBorderProgram(); |
596 DCHECK(program && (program->initialized() || IsContextLost())); | 623 DCHECK(program && (program->initialized() || IsContextLost())); |
597 SetUseProgram(program->program()); | 624 SetUseProgram(program->program()); |
598 | 625 |
599 // Use the full quad_rect for debug quads to not move the edges based on | 626 // 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... |
811 if (frame->current_render_pass->has_transparent_background) | 838 if (frame->current_render_pass->has_transparent_background) |
812 return false; | 839 return false; |
813 | 840 |
814 // TODO(ajuma): Add support for reference filters once | 841 // TODO(ajuma): Add support for reference filters once |
815 // FilterOperations::GetOutsets supports reference filters. | 842 // FilterOperations::GetOutsets supports reference filters. |
816 if (quad->background_filters.HasReferenceFilter()) | 843 if (quad->background_filters.HasReferenceFilter()) |
817 return false; | 844 return false; |
818 return true; | 845 return true; |
819 } | 846 } |
820 | 847 |
| 848 // This takes a gfx::Rect and a clip region quad in the same space, |
| 849 // and returns a quad with the same proportions in the space -0.5->0.5. |
| 850 bool GetScaledRegion(const gfx::Rect& rect, |
| 851 const gfx::QuadF* clip, |
| 852 gfx::QuadF* scaled_region) { |
| 853 if (!clip) |
| 854 return false; |
| 855 |
| 856 gfx::PointF p1(((clip->p1().x() - rect.x()) / rect.width()) - 0.5f, |
| 857 ((clip->p1().y() - rect.y()) / rect.height()) - 0.5f); |
| 858 gfx::PointF p2(((clip->p2().x() - rect.x()) / rect.width()) - 0.5f, |
| 859 ((clip->p2().y() - rect.y()) / rect.height()) - 0.5f); |
| 860 gfx::PointF p3(((clip->p3().x() - rect.x()) / rect.width()) - 0.5f, |
| 861 ((clip->p3().y() - rect.y()) / rect.height()) - 0.5f); |
| 862 gfx::PointF p4(((clip->p4().x() - rect.x()) / rect.width()) - 0.5f, |
| 863 ((clip->p4().y() - rect.y()) / rect.height()) - 0.5f); |
| 864 *scaled_region = gfx::QuadF(p1, p2, p3, p4); |
| 865 return true; |
| 866 } |
| 867 |
| 868 // This takes a gfx::Rect and a clip region quad in the same space, |
| 869 // and returns the proportional uv's in the space 0->1. |
| 870 bool GetScaledUVs(const gfx::Rect& rect, const gfx::QuadF* clip, float uvs[8]) { |
| 871 if (!clip) |
| 872 return false; |
| 873 |
| 874 uvs[0] = ((clip->p1().x() - rect.x()) / rect.width()); |
| 875 uvs[1] = ((clip->p1().y() - rect.y()) / rect.height()); |
| 876 uvs[2] = ((clip->p2().x() - rect.x()) / rect.width()); |
| 877 uvs[3] = ((clip->p2().y() - rect.y()) / rect.height()); |
| 878 uvs[4] = ((clip->p3().x() - rect.x()) / rect.width()); |
| 879 uvs[5] = ((clip->p3().y() - rect.y()) / rect.height()); |
| 880 uvs[6] = ((clip->p4().x() - rect.x()) / rect.width()); |
| 881 uvs[7] = ((clip->p4().y() - rect.y()) / rect.height()); |
| 882 return true; |
| 883 } |
| 884 |
821 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( | 885 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
822 DrawingFrame* frame, | 886 DrawingFrame* frame, |
823 const RenderPassDrawQuad* quad, | 887 const RenderPassDrawQuad* quad, |
824 const gfx::Transform& contents_device_transform, | 888 const gfx::Transform& contents_device_transform, |
| 889 const gfx::QuadF* clip_region, |
825 bool use_aa) { | 890 bool use_aa) { |
| 891 gfx::QuadF scaled_region; |
| 892 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { |
| 893 scaled_region = SharedGeometryQuad().BoundingBox(); |
| 894 } |
| 895 |
826 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( | 896 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( |
827 contents_device_transform, SharedGeometryQuad().BoundingBox())); | 897 contents_device_transform, scaled_region.BoundingBox())); |
828 | 898 |
829 if (ShouldApplyBackgroundFilters(frame, quad)) { | 899 if (ShouldApplyBackgroundFilters(frame, quad)) { |
830 int top, right, bottom, left; | 900 int top, right, bottom, left; |
831 quad->background_filters.GetOutsets(&top, &right, &bottom, &left); | 901 quad->background_filters.GetOutsets(&top, &right, &bottom, &left); |
832 backdrop_rect.Inset(-left, -top, -right, -bottom); | 902 backdrop_rect.Inset(-left, -top, -right, -bottom); |
833 } | 903 } |
834 | 904 |
835 if (!backdrop_rect.IsEmpty() && use_aa) { | 905 if (!backdrop_rect.IsEmpty() && use_aa) { |
836 const int kOutsetForAntialiasing = 1; | 906 const int kOutsetForAntialiasing = 1; |
837 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); | 907 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); |
(...skipping 28 matching lines...) Expand all Loading... |
866 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 936 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
867 quad->background_filters, background_texture->size()); | 937 quad->background_filters, background_texture->size()); |
868 | 938 |
869 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( | 939 skia::RefPtr<SkImage> background_with_filters = ApplyImageFilter( |
870 ScopedUseGrContext::Create(this, frame), resource_provider_, quad->rect, | 940 ScopedUseGrContext::Create(this, frame), resource_provider_, quad->rect, |
871 quad->filters_scale, filter.get(), background_texture); | 941 quad->filters_scale, filter.get(), background_texture); |
872 return background_with_filters; | 942 return background_with_filters; |
873 } | 943 } |
874 | 944 |
875 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 945 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, |
876 const RenderPassDrawQuad* quad) { | 946 const RenderPassDrawQuad* quad, |
| 947 const gfx::QuadF* clip_region) { |
877 ScopedResource* contents_texture = | 948 ScopedResource* contents_texture = |
878 render_pass_textures_.get(quad->render_pass_id); | 949 render_pass_textures_.get(quad->render_pass_id); |
879 if (!contents_texture || !contents_texture->id()) | 950 if (!contents_texture || !contents_texture->id()) |
880 return; | 951 return; |
881 | 952 |
882 gfx::Transform quad_rect_matrix; | 953 gfx::Transform quad_rect_matrix; |
883 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 954 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
884 gfx::Transform contents_device_transform = | 955 gfx::Transform contents_device_transform = |
885 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 956 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
886 contents_device_transform.FlattenTo2d(); | 957 contents_device_transform.FlattenTo2d(); |
887 | 958 |
888 // Can only draw surface if device matrix is invertible. | 959 // Can only draw surface if device matrix is invertible. |
889 if (!contents_device_transform.IsInvertible()) | 960 if (!contents_device_transform.IsInvertible()) |
890 return; | 961 return; |
891 | 962 |
892 gfx::QuadF surface_quad = SharedGeometryQuad(); | 963 gfx::QuadF surface_quad = SharedGeometryQuad(); |
893 float edge[24]; | 964 float edge[24]; |
894 bool use_aa = settings_->allow_antialiasing && | 965 bool use_aa = settings_->allow_antialiasing && |
895 ShouldAntialiasQuad(contents_device_transform, quad, | 966 ShouldAntialiasQuad(contents_device_transform, quad, |
896 settings_->force_antialiasing); | 967 settings_->force_antialiasing); |
897 | 968 |
898 if (use_aa) | 969 SetupQuadForClippingAndAntialiasing(contents_device_transform, quad, use_aa, |
899 SetupQuadForAntialiasing(contents_device_transform, quad, | 970 clip_region, &surface_quad, edge); |
900 &surface_quad, edge); | |
901 | |
902 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; | 971 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; |
903 bool use_shaders_for_blending = | 972 bool use_shaders_for_blending = |
904 !CanApplyBlendModeUsingBlendFunc(blend_mode) || | 973 !CanApplyBlendModeUsingBlendFunc(blend_mode) || |
905 ShouldApplyBackgroundFilters(frame, quad) || | 974 ShouldApplyBackgroundFilters(frame, quad) || |
906 settings_->force_blending_with_shaders; | 975 settings_->force_blending_with_shaders; |
907 | 976 |
908 scoped_ptr<ScopedResource> background_texture; | 977 scoped_ptr<ScopedResource> background_texture; |
909 skia::RefPtr<SkImage> background_image; | 978 skia::RefPtr<SkImage> background_image; |
910 gfx::Rect background_rect; | 979 gfx::Rect background_rect; |
911 if (use_shaders_for_blending) { | 980 if (use_shaders_for_blending) { |
912 // Compute a bounding box around the pixels that will be visible through | 981 // Compute a bounding box around the pixels that will be visible through |
913 // the quad. | 982 // the quad. |
914 background_rect = GetBackdropBoundingBoxForRenderPassQuad( | 983 background_rect = GetBackdropBoundingBoxForRenderPassQuad( |
915 frame, quad, contents_device_transform, use_aa); | 984 frame, quad, contents_device_transform, clip_region, use_aa); |
916 | 985 |
917 if (!background_rect.IsEmpty()) { | 986 if (!background_rect.IsEmpty()) { |
918 // The pixels from the filtered background should completely replace the | 987 // The pixels from the filtered background should completely replace the |
919 // current pixel values. | 988 // current pixel values. |
920 if (blend_enabled()) | 989 if (blend_enabled()) |
921 SetBlendEnabled(false); | 990 SetBlendEnabled(false); |
922 | 991 |
923 // Read the pixels in the bounding box into a buffer R. | 992 // Read the pixels in the bounding box into a buffer R. |
924 // This function allocates a texture, which should contribute to the | 993 // This function allocates a texture, which should contribute to the |
925 // amount of memory used by render surfaces: | 994 // amount of memory used by render surfaces: |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 static void SolidColorUniformLocation(T program, | 1299 static void SolidColorUniformLocation(T program, |
1231 SolidColorProgramUniforms* uniforms) { | 1300 SolidColorProgramUniforms* uniforms) { |
1232 uniforms->program = program->program(); | 1301 uniforms->program = program->program(); |
1233 uniforms->matrix_location = program->vertex_shader().matrix_location(); | 1302 uniforms->matrix_location = program->vertex_shader().matrix_location(); |
1234 uniforms->viewport_location = program->vertex_shader().viewport_location(); | 1303 uniforms->viewport_location = program->vertex_shader().viewport_location(); |
1235 uniforms->quad_location = program->vertex_shader().quad_location(); | 1304 uniforms->quad_location = program->vertex_shader().quad_location(); |
1236 uniforms->edge_location = program->vertex_shader().edge_location(); | 1305 uniforms->edge_location = program->vertex_shader().edge_location(); |
1237 uniforms->color_location = program->fragment_shader().color_location(); | 1306 uniforms->color_location = program->fragment_shader().color_location(); |
1238 } | 1307 } |
1239 | 1308 |
| 1309 namespace { |
| 1310 // These functions determine if a quad, clipped by a clip_region contains |
| 1311 // the entire {top|bottom|left|right} edge. |
| 1312 bool is_top(const gfx::QuadF* clip_region, const DrawQuad* quad) { |
| 1313 if (!quad->IsTopEdge()) |
| 1314 return false; |
| 1315 if (!clip_region) |
| 1316 return true; |
| 1317 |
| 1318 return std::abs(clip_region->p1().y()) < kAntiAliasingEpsilon && |
| 1319 std::abs(clip_region->p2().y()) < kAntiAliasingEpsilon; |
| 1320 } |
| 1321 |
| 1322 bool is_bottom(const gfx::QuadF* clip_region, const DrawQuad* quad) { |
| 1323 if (!quad->IsBottomEdge()) |
| 1324 return false; |
| 1325 if (!clip_region) |
| 1326 return true; |
| 1327 |
| 1328 return std::abs(clip_region->p3().y() - |
| 1329 quad->shared_quad_state->content_bounds.height()) < |
| 1330 kAntiAliasingEpsilon && |
| 1331 std::abs(clip_region->p4().y() - |
| 1332 quad->shared_quad_state->content_bounds.height()) < |
| 1333 kAntiAliasingEpsilon; |
| 1334 } |
| 1335 |
| 1336 bool is_left(const gfx::QuadF* clip_region, const DrawQuad* quad) { |
| 1337 if (!quad->IsLeftEdge()) |
| 1338 return false; |
| 1339 if (!clip_region) |
| 1340 return true; |
| 1341 |
| 1342 return std::abs(clip_region->p1().x()) < kAntiAliasingEpsilon && |
| 1343 std::abs(clip_region->p4().x()) < kAntiAliasingEpsilon; |
| 1344 } |
| 1345 |
| 1346 bool is_right(const gfx::QuadF* clip_region, const DrawQuad* quad) { |
| 1347 if (!quad->IsRightEdge()) |
| 1348 return false; |
| 1349 if (!clip_region) |
| 1350 return true; |
| 1351 |
| 1352 return std::abs(clip_region->p2().x() - |
| 1353 quad->shared_quad_state->content_bounds.width()) < |
| 1354 kAntiAliasingEpsilon && |
| 1355 std::abs(clip_region->p3().x() - |
| 1356 quad->shared_quad_state->content_bounds.width()) < |
| 1357 kAntiAliasingEpsilon; |
| 1358 } |
| 1359 } // anonymous namespace |
| 1360 |
1240 static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( | 1361 static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( |
1241 const LayerQuad& device_layer_edges, | 1362 const LayerQuad& device_layer_edges, |
1242 const gfx::Transform& device_transform, | 1363 const gfx::Transform& device_transform, |
| 1364 const gfx::QuadF* clip_region, |
1243 const DrawQuad* quad) { | 1365 const DrawQuad* quad) { |
1244 gfx::Rect tile_rect = quad->visible_rect; | 1366 gfx::RectF tile_rect = quad->visible_rect; |
1245 gfx::PointF bottom_right = tile_rect.bottom_right(); | 1367 gfx::QuadF tile_quad(tile_rect); |
1246 gfx::PointF bottom_left = tile_rect.bottom_left(); | 1368 |
1247 gfx::PointF top_left = tile_rect.origin(); | 1369 if (clip_region) { |
1248 gfx::PointF top_right = tile_rect.top_right(); | 1370 if (quad->material != DrawQuad::RENDER_PASS) { |
| 1371 tile_quad = *clip_region; |
| 1372 } else { |
| 1373 GetScaledRegion(quad->rect, clip_region, &tile_quad); |
| 1374 } |
| 1375 } |
| 1376 |
| 1377 gfx::PointF bottom_right = tile_quad.p3(); |
| 1378 gfx::PointF bottom_left = tile_quad.p4(); |
| 1379 gfx::PointF top_left = tile_quad.p1(); |
| 1380 gfx::PointF top_right = tile_quad.p2(); |
1249 bool clipped = false; | 1381 bool clipped = false; |
1250 | 1382 |
1251 // Map points to device space. We ignore |clipped|, since the result of | 1383 // Map points to device space. We ignore |clipped|, since the result of |
1252 // |MapPoint()| still produces a valid point to draw the quad with. When | 1384 // |MapPoint()| still produces a valid point to draw the quad with. When |
1253 // clipped, the point will be outside of the viewport. See crbug.com/416367. | 1385 // clipped, the point will be outside of the viewport. See crbug.com/416367. |
1254 bottom_right = MathUtil::MapPoint(device_transform, bottom_right, &clipped); | 1386 bottom_right = MathUtil::MapPoint(device_transform, bottom_right, &clipped); |
1255 bottom_left = MathUtil::MapPoint(device_transform, bottom_left, &clipped); | 1387 bottom_left = MathUtil::MapPoint(device_transform, bottom_left, &clipped); |
1256 top_left = MathUtil::MapPoint(device_transform, top_left, &clipped); | 1388 top_left = MathUtil::MapPoint(device_transform, top_left, &clipped); |
1257 top_right = MathUtil::MapPoint(device_transform, top_right, &clipped); | 1389 top_right = MathUtil::MapPoint(device_transform, top_right, &clipped); |
1258 | 1390 |
1259 LayerQuad::Edge bottom_edge(bottom_right, bottom_left); | 1391 LayerQuad::Edge bottom_edge(bottom_right, bottom_left); |
1260 LayerQuad::Edge left_edge(bottom_left, top_left); | 1392 LayerQuad::Edge left_edge(bottom_left, top_left); |
1261 LayerQuad::Edge top_edge(top_left, top_right); | 1393 LayerQuad::Edge top_edge(top_left, top_right); |
1262 LayerQuad::Edge right_edge(top_right, bottom_right); | 1394 LayerQuad::Edge right_edge(top_right, bottom_right); |
1263 | 1395 |
1264 // Only apply anti-aliasing to edges not clipped by culling or scissoring. | 1396 // Only apply anti-aliasing to edges not clipped by culling or scissoring. |
1265 if (quad->IsTopEdge() && tile_rect.y() == quad->rect.y()) | 1397 // If an edge is degenerate we do not want to replace it with a "proper" edge |
| 1398 // as that will cause the quad to possibly expand is strange ways. |
| 1399 if (!top_edge.degenerate() && is_top(clip_region, quad) && |
| 1400 tile_rect.y() == quad->rect.y()) { |
1266 top_edge = device_layer_edges.top(); | 1401 top_edge = device_layer_edges.top(); |
1267 if (quad->IsLeftEdge() && tile_rect.x() == quad->rect.x()) | 1402 } |
| 1403 if (!left_edge.degenerate() && is_left(clip_region, quad) && |
| 1404 tile_rect.x() == quad->rect.x()) { |
1268 left_edge = device_layer_edges.left(); | 1405 left_edge = device_layer_edges.left(); |
1269 if (quad->IsRightEdge() && tile_rect.right() == quad->rect.right()) | 1406 } |
| 1407 if (!right_edge.degenerate() && is_right(clip_region, quad) && |
| 1408 tile_rect.right() == quad->rect.right()) { |
1270 right_edge = device_layer_edges.right(); | 1409 right_edge = device_layer_edges.right(); |
1271 if (quad->IsBottomEdge() && tile_rect.bottom() == quad->rect.bottom()) | 1410 } |
| 1411 if (!bottom_edge.degenerate() && is_bottom(clip_region, quad) && |
| 1412 tile_rect.bottom() == quad->rect.bottom()) { |
1272 bottom_edge = device_layer_edges.bottom(); | 1413 bottom_edge = device_layer_edges.bottom(); |
| 1414 } |
1273 | 1415 |
1274 float sign = gfx::QuadF(tile_rect).IsCounterClockwise() ? -1 : 1; | 1416 float sign = tile_quad.IsCounterClockwise() ? -1 : 1; |
1275 bottom_edge.scale(sign); | 1417 bottom_edge.scale(sign); |
1276 left_edge.scale(sign); | 1418 left_edge.scale(sign); |
1277 top_edge.scale(sign); | 1419 top_edge.scale(sign); |
1278 right_edge.scale(sign); | 1420 right_edge.scale(sign); |
1279 | 1421 |
1280 // Create device space quad. | 1422 // Create device space quad. |
1281 return LayerQuad(left_edge, top_edge, right_edge, bottom_edge).ToQuadF(); | 1423 return LayerQuad(left_edge, top_edge, right_edge, bottom_edge).ToQuadF(); |
1282 } | 1424 } |
1283 | 1425 |
| 1426 float GetTotalQuadError(const gfx::QuadF* clipped_quad, |
| 1427 const gfx::QuadF* ideal_rect) { |
| 1428 return (clipped_quad->p1() - ideal_rect->p1()).LengthSquared() + |
| 1429 (clipped_quad->p2() - ideal_rect->p2()).LengthSquared() + |
| 1430 (clipped_quad->p3() - ideal_rect->p3()).LengthSquared() + |
| 1431 (clipped_quad->p4() - ideal_rect->p4()).LengthSquared(); |
| 1432 } |
| 1433 |
| 1434 // Attempt to rotate the clipped quad until it lines up the most |
| 1435 // correctly. This is necessary because we check the edges of this |
| 1436 // quad against the expected left/right/top/bottom for anti-aliasing. |
| 1437 void AlignQuadToBoundingBox(gfx::QuadF* clipped_quad) { |
| 1438 gfx::QuadF bounding_quad = gfx::QuadF(clipped_quad->BoundingBox()); |
| 1439 gfx::QuadF best_rotation = *clipped_quad; |
| 1440 float least_error_amount = GetTotalQuadError(clipped_quad, &bounding_quad); |
| 1441 for (size_t i = 1; i < 4; ++i) { |
| 1442 clipped_quad->Realign(1); |
| 1443 float new_error = GetTotalQuadError(clipped_quad, &bounding_quad); |
| 1444 if (new_error < least_error_amount) { |
| 1445 least_error_amount = new_error; |
| 1446 best_rotation = *clipped_quad; |
| 1447 } |
| 1448 } |
| 1449 *clipped_quad = best_rotation; |
| 1450 } |
| 1451 |
1284 // static | 1452 // static |
1285 bool GLRenderer::ShouldAntialiasQuad(const gfx::Transform& device_transform, | 1453 bool GLRenderer::ShouldAntialiasQuad(const gfx::Transform& device_transform, |
1286 const DrawQuad* quad, | 1454 const DrawQuad* quad, |
1287 bool force_antialiasing) { | 1455 bool force_antialiasing) { |
1288 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); | 1456 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); |
1289 // For render pass quads, |device_transform| already contains quad's rect. | 1457 // For render pass quads, |device_transform| already contains quad's rect. |
1290 // TODO(rosca@adobe.com): remove branching on is_render_pass_quad | 1458 // TODO(rosca@adobe.com): remove branching on is_render_pass_quad |
1291 // crbug.com/429702 | 1459 // crbug.com/429702 |
1292 if (!is_render_pass_quad && !quad->IsEdge()) | 1460 if (!is_render_pass_quad && !quad->IsEdge()) |
1293 return false; | 1461 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
1305 bool is_nearest_rect_within_epsilon = | 1473 bool is_nearest_rect_within_epsilon = |
1306 is_axis_aligned_in_target && | 1474 is_axis_aligned_in_target && |
1307 gfx::IsNearestRectWithinDistance(device_layer_quad.BoundingBox(), | 1475 gfx::IsNearestRectWithinDistance(device_layer_quad.BoundingBox(), |
1308 kAntiAliasingEpsilon); | 1476 kAntiAliasingEpsilon); |
1309 // AAing clipped quads is not supported by the code yet. | 1477 // AAing clipped quads is not supported by the code yet. |
1310 bool use_aa = !clipped && !is_nearest_rect_within_epsilon; | 1478 bool use_aa = !clipped && !is_nearest_rect_within_epsilon; |
1311 return use_aa || force_antialiasing; | 1479 return use_aa || force_antialiasing; |
1312 } | 1480 } |
1313 | 1481 |
1314 // static | 1482 // static |
1315 void GLRenderer::SetupQuadForAntialiasing( | 1483 void GLRenderer::SetupQuadForClippingAndAntialiasing( |
1316 const gfx::Transform& device_transform, | 1484 const gfx::Transform& device_transform, |
1317 const DrawQuad* quad, | 1485 const DrawQuad* quad, |
| 1486 bool use_aa, |
| 1487 const gfx::QuadF* clip_region, |
1318 gfx::QuadF* local_quad, | 1488 gfx::QuadF* local_quad, |
1319 float edge[24]) { | 1489 float edge[24]) { |
1320 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); | 1490 bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); |
1321 gfx::RectF content_rect = | 1491 gfx::QuadF rotated_clip; |
1322 is_render_pass_quad ? QuadVertexRect() : quad->visibleContentRect(); | 1492 const gfx::QuadF* local_clip_region = clip_region; |
| 1493 if (local_clip_region) { |
| 1494 rotated_clip = *clip_region; |
| 1495 AlignQuadToBoundingBox(&rotated_clip); |
| 1496 local_clip_region = &rotated_clip; |
| 1497 } |
1323 | 1498 |
| 1499 gfx::QuadF content_rect = is_render_pass_quad |
| 1500 ? gfx::QuadF(QuadVertexRect()) |
| 1501 : gfx::QuadF(quad->visibleContentRect()); |
| 1502 if (!use_aa) { |
| 1503 if (local_clip_region) { |
| 1504 if (!is_render_pass_quad) { |
| 1505 content_rect = *local_clip_region; |
| 1506 } else { |
| 1507 GetScaledRegion(quad->rect, local_clip_region, &content_rect); |
| 1508 } |
| 1509 *local_quad = content_rect; |
| 1510 } |
| 1511 return; |
| 1512 } |
1324 bool clipped = false; | 1513 bool clipped = false; |
1325 gfx::QuadF device_layer_quad = | 1514 gfx::QuadF device_layer_quad = |
1326 MathUtil::MapQuad(device_transform, gfx::QuadF(content_rect), &clipped); | 1515 MathUtil::MapQuad(device_transform, content_rect, &clipped); |
1327 | 1516 |
1328 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox())); | 1517 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox())); |
1329 device_layer_bounds.InflateAntiAliasingDistance(); | 1518 device_layer_bounds.InflateAntiAliasingDistance(); |
1330 | 1519 |
1331 LayerQuad device_layer_edges(device_layer_quad); | 1520 LayerQuad device_layer_edges(device_layer_quad); |
1332 device_layer_edges.InflateAntiAliasingDistance(); | 1521 device_layer_edges.InflateAntiAliasingDistance(); |
1333 | 1522 |
1334 device_layer_edges.ToFloatArray(edge); | 1523 device_layer_edges.ToFloatArray(edge); |
1335 device_layer_bounds.ToFloatArray(&edge[12]); | 1524 device_layer_bounds.ToFloatArray(&edge[12]); |
1336 | 1525 |
| 1526 // If we have a clip region then we are split, and therefore |
| 1527 // by necessity, at least one of our edges is not an external |
| 1528 // one. |
| 1529 bool is_full_rect = quad->visible_rect == quad->rect; |
| 1530 |
| 1531 bool region_contains_all_outside_edges = |
| 1532 is_full_rect && |
| 1533 (is_top(local_clip_region, quad) && is_left(local_clip_region, quad) && |
| 1534 is_bottom(local_clip_region, quad) && is_right(local_clip_region, quad)); |
| 1535 |
1337 bool use_aa_on_all_four_edges = | 1536 bool use_aa_on_all_four_edges = |
1338 is_render_pass_quad || | 1537 !local_clip_region && |
1339 (quad->IsTopEdge() && quad->IsLeftEdge() && quad->IsBottomEdge() && | 1538 (is_render_pass_quad || region_contains_all_outside_edges); |
1340 quad->IsRightEdge() && quad->visible_rect == quad->rect); | |
1341 | 1539 |
1342 gfx::QuadF device_quad = | 1540 gfx::QuadF device_quad = |
1343 use_aa_on_all_four_edges | 1541 use_aa_on_all_four_edges |
1344 ? device_layer_edges.ToQuadF() | 1542 ? device_layer_edges.ToQuadF() |
1345 : GetDeviceQuadWithAntialiasingOnExteriorEdges( | 1543 : GetDeviceQuadWithAntialiasingOnExteriorEdges( |
1346 device_layer_edges, device_transform, quad); | 1544 device_layer_edges, device_transform, local_clip_region, quad); |
1347 | 1545 |
1348 // Map device space quad to local space. device_transform has no 3d | 1546 // Map device space quad to local space. device_transform has no 3d |
1349 // component since it was flattened, so we don't need to project. We should | 1547 // component since it was flattened, so we don't need to project. We should |
1350 // have already checked that the transform was uninvertible above. | 1548 // have already checked that the transform was uninvertible above. |
1351 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); | 1549 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); |
1352 bool did_invert = device_transform.GetInverse(&inverse_device_transform); | 1550 bool did_invert = device_transform.GetInverse(&inverse_device_transform); |
1353 DCHECK(did_invert); | 1551 DCHECK(did_invert); |
1354 *local_quad = | 1552 *local_quad = |
1355 MathUtil::MapQuad(inverse_device_transform, device_quad, &clipped); | 1553 MathUtil::MapQuad(inverse_device_transform, device_quad, &clipped); |
1356 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may | 1554 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may |
1357 // cause device_quad to become clipped. To our knowledge this scenario does | 1555 // cause device_quad to become clipped. To our knowledge this scenario does |
1358 // not need to be handled differently than the unclipped case. | 1556 // not need to be handled differently than the unclipped case. |
1359 } | 1557 } |
1360 | 1558 |
1361 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, | 1559 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, |
1362 const SolidColorDrawQuad* quad) { | 1560 const SolidColorDrawQuad* quad, |
| 1561 const gfx::QuadF* clip_region) { |
1363 gfx::Rect tile_rect = quad->visible_rect; | 1562 gfx::Rect tile_rect = quad->visible_rect; |
1364 | 1563 |
1365 SkColor color = quad->color; | 1564 SkColor color = quad->color; |
1366 float opacity = quad->opacity(); | 1565 float opacity = quad->opacity(); |
1367 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; | 1566 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; |
1368 | 1567 |
1369 // Early out if alpha is small enough that quad doesn't contribute to output. | 1568 // Early out if alpha is small enough that quad doesn't contribute to output. |
1370 if (alpha < std::numeric_limits<float>::epsilon() && | 1569 if (alpha < std::numeric_limits<float>::epsilon() && |
1371 quad->ShouldDrawWithBlending()) | 1570 quad->ShouldDrawWithBlending()) |
1372 return; | 1571 return; |
1373 | 1572 |
1374 gfx::Transform device_transform = | 1573 gfx::Transform device_transform = |
1375 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); | 1574 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); |
1376 device_transform.FlattenTo2d(); | 1575 device_transform.FlattenTo2d(); |
1377 if (!device_transform.IsInvertible()) | 1576 if (!device_transform.IsInvertible()) |
1378 return; | 1577 return; |
1379 | 1578 |
1380 bool force_aa = false; | 1579 bool force_aa = false; |
1381 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); | 1580 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); |
1382 float edge[24]; | 1581 float edge[24]; |
1383 bool use_aa = settings_->allow_antialiasing && | 1582 bool use_aa = settings_->allow_antialiasing && |
1384 !quad->force_anti_aliasing_off && | 1583 !quad->force_anti_aliasing_off && |
1385 ShouldAntialiasQuad(device_transform, quad, force_aa); | 1584 ShouldAntialiasQuad(device_transform, quad, force_aa); |
| 1585 SetupQuadForClippingAndAntialiasing(device_transform, quad, use_aa, |
| 1586 clip_region, &local_quad, edge); |
1386 | 1587 |
1387 SolidColorProgramUniforms uniforms; | 1588 SolidColorProgramUniforms uniforms; |
1388 if (use_aa) { | 1589 if (use_aa) { |
1389 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); | |
1390 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); | 1590 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); |
1391 } else { | 1591 } else { |
1392 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); | 1592 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); |
1393 } | 1593 } |
1394 SetUseProgram(uniforms.program); | 1594 SetUseProgram(uniforms.program); |
1395 | 1595 |
1396 GLC(gl_, | 1596 GLC(gl_, |
1397 gl_->Uniform4f(uniforms.color_location, | 1597 gl_->Uniform4f(uniforms.color_location, |
1398 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, | 1598 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, |
1399 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, | 1599 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 uniforms->vertex_tex_transform_location = | 1650 uniforms->vertex_tex_transform_location = |
1451 program->vertex_shader().vertex_tex_transform_location(); | 1651 program->vertex_shader().vertex_tex_transform_location(); |
1452 | 1652 |
1453 uniforms->sampler_location = program->fragment_shader().sampler_location(); | 1653 uniforms->sampler_location = program->fragment_shader().sampler_location(); |
1454 uniforms->alpha_location = program->fragment_shader().alpha_location(); | 1654 uniforms->alpha_location = program->fragment_shader().alpha_location(); |
1455 uniforms->fragment_tex_transform_location = | 1655 uniforms->fragment_tex_transform_location = |
1456 program->fragment_shader().fragment_tex_transform_location(); | 1656 program->fragment_shader().fragment_tex_transform_location(); |
1457 } | 1657 } |
1458 | 1658 |
1459 void GLRenderer::DrawTileQuad(const DrawingFrame* frame, | 1659 void GLRenderer::DrawTileQuad(const DrawingFrame* frame, |
1460 const TileDrawQuad* quad) { | 1660 const TileDrawQuad* quad, |
1461 DrawContentQuad(frame, quad, quad->resource_id); | 1661 const gfx::QuadF* clip_region) { |
| 1662 DrawContentQuad(frame, quad, quad->resource_id, clip_region); |
1462 } | 1663 } |
1463 | 1664 |
1464 void GLRenderer::DrawContentQuad(const DrawingFrame* frame, | 1665 void GLRenderer::DrawContentQuad(const DrawingFrame* frame, |
1465 const ContentDrawQuadBase* quad, | 1666 const ContentDrawQuadBase* quad, |
1466 ResourceProvider::ResourceId resource_id) { | 1667 ResourceProvider::ResourceId resource_id, |
| 1668 const gfx::QuadF* clip_region) { |
1467 gfx::Transform device_transform = | 1669 gfx::Transform device_transform = |
1468 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); | 1670 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); |
1469 device_transform.FlattenTo2d(); | 1671 device_transform.FlattenTo2d(); |
1470 | 1672 |
1471 bool use_aa = settings_->allow_antialiasing && | 1673 bool use_aa = settings_->allow_antialiasing && |
1472 ShouldAntialiasQuad(device_transform, quad, false); | 1674 ShouldAntialiasQuad(device_transform, quad, false); |
1473 | 1675 |
1474 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA | 1676 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA |
1475 // similar to the way DrawContentQuadNoAA works and then consider | 1677 // similar to the way DrawContentQuadNoAA works and then consider |
1476 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. | 1678 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. |
1477 if (use_aa) | 1679 if (use_aa) |
1478 DrawContentQuadAA(frame, quad, resource_id, device_transform); | 1680 DrawContentQuadAA(frame, quad, resource_id, device_transform, clip_region); |
1479 else | 1681 else |
1480 DrawContentQuadNoAA(frame, quad, resource_id); | 1682 DrawContentQuadNoAA(frame, quad, resource_id, clip_region); |
1481 } | 1683 } |
1482 | 1684 |
1483 void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, | 1685 void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, |
1484 const ContentDrawQuadBase* quad, | 1686 const ContentDrawQuadBase* quad, |
1485 ResourceProvider::ResourceId resource_id, | 1687 ResourceProvider::ResourceId resource_id, |
1486 const gfx::Transform& device_transform) { | 1688 const gfx::Transform& device_transform, |
| 1689 const gfx::QuadF* clip_region) { |
1487 if (!device_transform.IsInvertible()) | 1690 if (!device_transform.IsInvertible()) |
1488 return; | 1691 return; |
1489 | 1692 |
1490 gfx::Rect tile_rect = quad->visible_rect; | 1693 gfx::Rect tile_rect = quad->visible_rect; |
1491 | 1694 |
1492 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( | 1695 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( |
1493 quad->tex_coord_rect, quad->rect, tile_rect); | 1696 quad->tex_coord_rect, quad->rect, tile_rect); |
1494 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); | 1697 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); |
1495 float tex_to_geom_scale_y = | 1698 float tex_to_geom_scale_y = |
1496 quad->rect.height() / quad->tex_coord_rect.height(); | 1699 quad->rect.height() / quad->tex_coord_rect.height(); |
(...skipping 24 matching lines...) Expand all Loading... |
1521 float vertex_tex_translate_y = | 1724 float vertex_tex_translate_y = |
1522 -clamp_geom_rect.y() / clamp_geom_rect.height(); | 1725 -clamp_geom_rect.y() / clamp_geom_rect.height(); |
1523 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); | 1726 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); |
1524 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); | 1727 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); |
1525 | 1728 |
1526 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1729 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
1527 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); | 1730 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); |
1528 | 1731 |
1529 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); | 1732 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); |
1530 float edge[24]; | 1733 float edge[24]; |
1531 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); | 1734 SetupQuadForClippingAndAntialiasing(device_transform, quad, true, clip_region, |
1532 | 1735 &local_quad, edge); |
1533 ResourceProvider::ScopedSamplerGL quad_resource_lock( | 1736 ResourceProvider::ScopedSamplerGL quad_resource_lock( |
1534 resource_provider_, resource_id, | 1737 resource_provider_, resource_id, |
1535 quad->nearest_neighbor ? GL_NEAREST : GL_LINEAR); | 1738 quad->nearest_neighbor ? GL_NEAREST : GL_LINEAR); |
1536 SamplerType sampler = | 1739 SamplerType sampler = |
1537 SamplerTypeFromTextureTarget(quad_resource_lock.target()); | 1740 SamplerTypeFromTextureTarget(quad_resource_lock.target()); |
1538 | 1741 |
1539 float fragment_tex_translate_x = clamp_tex_rect.x(); | 1742 float fragment_tex_translate_x = clamp_tex_rect.x(); |
1540 float fragment_tex_translate_y = clamp_tex_rect.y(); | 1743 float fragment_tex_translate_y = clamp_tex_rect.y(); |
1541 float fragment_tex_scale_x = clamp_tex_rect.width(); | 1744 float fragment_tex_scale_x = clamp_tex_rect.width(); |
1542 float fragment_tex_scale_y = clamp_tex_rect.height(); | 1745 float fragment_tex_scale_y = clamp_tex_rect.height(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 // it. This is why this centered rect is used and not the original quad_rect. | 1803 // it. This is why this centered rect is used and not the original quad_rect. |
1601 gfx::RectF centered_rect( | 1804 gfx::RectF centered_rect( |
1602 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), | 1805 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), |
1603 tile_rect.size()); | 1806 tile_rect.size()); |
1604 DrawQuadGeometry( | 1807 DrawQuadGeometry( |
1605 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); | 1808 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); |
1606 } | 1809 } |
1607 | 1810 |
1608 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, | 1811 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, |
1609 const ContentDrawQuadBase* quad, | 1812 const ContentDrawQuadBase* quad, |
1610 ResourceProvider::ResourceId resource_id) { | 1813 ResourceProvider::ResourceId resource_id, |
| 1814 const gfx::QuadF* clip_region) { |
1611 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( | 1815 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( |
1612 quad->tex_coord_rect, quad->rect, quad->visible_rect); | 1816 quad->tex_coord_rect, quad->rect, quad->visible_rect); |
1613 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); | 1817 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); |
1614 float tex_to_geom_scale_y = | 1818 float tex_to_geom_scale_y = |
1615 quad->rect.height() / quad->tex_coord_rect.height(); | 1819 quad->rect.height() / quad->tex_coord_rect.height(); |
1616 | 1820 |
1617 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); | 1821 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); |
1618 GLenum filter = | 1822 GLenum filter = |
1619 (scaled || !quad->quadTransform().IsIdentityOrIntegerTranslation()) && | 1823 (scaled || !quad->quadTransform().IsIdentityOrIntegerTranslation()) && |
1620 !quad->nearest_neighbor | 1824 !quad->nearest_neighbor |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 vertex_tex_scale_y)); | 1878 vertex_tex_scale_y)); |
1675 | 1879 |
1676 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1880 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
1677 | 1881 |
1678 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); | 1882 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); |
1679 | 1883 |
1680 // Pass quad coordinates to the uniform in the same order as GeometryBinding | 1884 // Pass quad coordinates to the uniform in the same order as GeometryBinding |
1681 // does, then vertices will match the texture mapping in the vertex buffer. | 1885 // does, then vertices will match the texture mapping in the vertex buffer. |
1682 // The method SetShaderQuadF() changes the order of vertices and so it's | 1886 // The method SetShaderQuadF() changes the order of vertices and so it's |
1683 // not used here. | 1887 // not used here. |
1684 | 1888 gfx::QuadF tile_rect(quad->visible_rect); |
1685 gfx::RectF tile_rect = quad->visible_rect; | 1889 float width = quad->visible_rect.width(); |
| 1890 float height = quad->visible_rect.height(); |
| 1891 gfx::PointF top_left = quad->visible_rect.origin(); |
| 1892 if (clip_region) { |
| 1893 tile_rect = *clip_region; |
| 1894 float gl_uv[8] = { |
| 1895 (tile_rect.p4().x() - top_left.x()) / width, |
| 1896 (tile_rect.p4().y() - top_left.y()) / height, |
| 1897 (tile_rect.p1().x() - top_left.x()) / width, |
| 1898 (tile_rect.p1().y() - top_left.y()) / height, |
| 1899 (tile_rect.p2().x() - top_left.x()) / width, |
| 1900 (tile_rect.p2().y() - top_left.y()) / height, |
| 1901 (tile_rect.p3().x() - top_left.x()) / width, |
| 1902 (tile_rect.p3().y() - top_left.y()) / height, |
| 1903 }; |
| 1904 PrepareGeometry(CLIPPED_BINDING); |
| 1905 clipped_geometry_->InitializeCustomQuadWithUVs( |
| 1906 gfx::QuadF(quad->visible_rect), gl_uv); |
| 1907 } else { |
| 1908 PrepareGeometry(SHARED_BINDING); |
| 1909 } |
1686 float gl_quad[8] = { | 1910 float gl_quad[8] = { |
1687 tile_rect.x(), | 1911 tile_rect.p4().x(), |
1688 tile_rect.bottom(), | 1912 tile_rect.p4().y(), |
1689 tile_rect.x(), | 1913 tile_rect.p1().x(), |
1690 tile_rect.y(), | 1914 tile_rect.p1().y(), |
1691 tile_rect.right(), | 1915 tile_rect.p2().x(), |
1692 tile_rect.y(), | 1916 tile_rect.p2().y(), |
1693 tile_rect.right(), | 1917 tile_rect.p3().x(), |
1694 tile_rect.bottom(), | 1918 tile_rect.p3().y(), |
1695 }; | 1919 }; |
1696 GLC(gl_, gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad)); | 1920 GLC(gl_, gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad)); |
1697 | 1921 |
1698 static float gl_matrix[16]; | 1922 static float gl_matrix[16]; |
1699 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad->quadTransform()); | 1923 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad->quadTransform()); |
1700 GLC(gl_, | 1924 GLC(gl_, |
1701 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0])); | 1925 gl_->UniformMatrix4fv(uniforms.matrix_location, 1, false, &gl_matrix[0])); |
1702 | 1926 |
1703 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); | 1927 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); |
1704 } | 1928 } |
1705 | 1929 |
1706 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, | 1930 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
1707 const YUVVideoDrawQuad* quad) { | 1931 const YUVVideoDrawQuad* quad, |
| 1932 const gfx::QuadF* clip_region) { |
1708 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1933 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
1709 | 1934 |
1710 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1935 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
1711 gl_, | 1936 gl_, |
1712 &highp_threshold_cache_, | 1937 &highp_threshold_cache_, |
1713 highp_threshold_min_, | 1938 highp_threshold_min_, |
1714 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1939 quad->shared_quad_state->visible_content_rect.bottom_right()); |
1715 | 1940 |
1716 bool use_alpha_plane = quad->a_plane_resource_id != 0; | 1941 bool use_alpha_plane = quad->a_plane_resource_id != 0; |
1717 | 1942 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 case YUVVideoDrawQuad::REC_709: | 2062 case YUVVideoDrawQuad::REC_709: |
1838 yuv_to_rgb = yuv_to_rgb_rec709; | 2063 yuv_to_rgb = yuv_to_rgb_rec709; |
1839 yuv_adjust = yuv_adjust_constrained; | 2064 yuv_adjust = yuv_adjust_constrained; |
1840 break; | 2065 break; |
1841 case YUVVideoDrawQuad::JPEG: | 2066 case YUVVideoDrawQuad::JPEG: |
1842 yuv_to_rgb = yuv_to_rgb_jpeg; | 2067 yuv_to_rgb = yuv_to_rgb_jpeg; |
1843 yuv_adjust = yuv_adjust_full; | 2068 yuv_adjust = yuv_adjust_full; |
1844 break; | 2069 break; |
1845 } | 2070 } |
1846 | 2071 |
| 2072 // The transform and vertex data are used to figure out the extents that the |
| 2073 // un-antialiased quad should have and which vertex this is and the float |
| 2074 // quad passed in via uniform is the actual geometry that gets used to draw |
| 2075 // it. This is why this centered rect is used and not the original quad_rect. |
| 2076 gfx::RectF tile_rect = quad->visible_rect; |
1847 GLC(gl_, gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb)); | 2077 GLC(gl_, gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb)); |
1848 GLC(gl_, gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust)); | 2078 GLC(gl_, gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust)); |
1849 | 2079 |
1850 SetShaderOpacity(quad->opacity(), alpha_location); | 2080 SetShaderOpacity(quad->opacity(), alpha_location); |
1851 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, matrix_location); | 2081 if (!clip_region) { |
| 2082 DrawQuadGeometry(frame, quad->quadTransform(), tile_rect, matrix_location); |
| 2083 } else { |
| 2084 float uvs[8] = {0}; |
| 2085 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2086 gfx::QuadF region_quad = *clip_region; |
| 2087 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 2088 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2089 DrawQuadGeometryClippedByQuadF(frame, quad->quadTransform(), tile_rect, |
| 2090 region_quad, matrix_location, uvs); |
| 2091 } |
1852 } | 2092 } |
1853 | 2093 |
1854 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 2094 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
1855 const StreamVideoDrawQuad* quad) { | 2095 const StreamVideoDrawQuad* quad, |
| 2096 const gfx::QuadF* clip_region) { |
1856 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2097 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
1857 | 2098 |
1858 static float gl_matrix[16]; | 2099 static float gl_matrix[16]; |
1859 | 2100 |
1860 DCHECK(capabilities_.using_egl_image); | 2101 DCHECK(capabilities_.using_egl_image); |
1861 | 2102 |
1862 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2103 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
1863 gl_, | 2104 gl_, |
1864 &highp_threshold_cache_, | 2105 &highp_threshold_cache_, |
1865 highp_threshold_min_, | 2106 highp_threshold_min_, |
(...skipping 10 matching lines...) Expand all Loading... |
1876 | 2117 |
1877 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 2118 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
1878 quad->resource_id); | 2119 quad->resource_id); |
1879 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2120 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
1880 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); | 2121 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); |
1881 | 2122 |
1882 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); | 2123 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
1883 | 2124 |
1884 SetShaderOpacity(quad->opacity(), | 2125 SetShaderOpacity(quad->opacity(), |
1885 program->fragment_shader().alpha_location()); | 2126 program->fragment_shader().alpha_location()); |
1886 DrawQuadGeometry(frame, | 2127 if (!clip_region) { |
1887 quad->quadTransform(), | 2128 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, |
1888 quad->rect, | 2129 program->vertex_shader().matrix_location()); |
1889 program->vertex_shader().matrix_location()); | 2130 } else { |
| 2131 gfx::QuadF region_quad(*clip_region); |
| 2132 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); |
| 2133 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2134 float uvs[8] = {0}; |
| 2135 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2136 DrawQuadGeometryClippedByQuadF( |
| 2137 frame, quad->quadTransform(), quad->rect, region_quad, |
| 2138 program->vertex_shader().matrix_location(), uvs); |
| 2139 } |
1890 } | 2140 } |
1891 | 2141 |
1892 struct TextureProgramBinding { | 2142 struct TextureProgramBinding { |
1893 template <class Program> | 2143 template <class Program> |
1894 void Set(Program* program) { | 2144 void Set(Program* program) { |
1895 DCHECK(program); | 2145 DCHECK(program); |
1896 program_id = program->program(); | 2146 program_id = program->program(); |
1897 sampler_location = program->fragment_shader().sampler_location(); | 2147 sampler_location = program->fragment_shader().sampler_location(); |
1898 matrix_location = program->vertex_shader().matrix_location(); | 2148 matrix_location = program->vertex_shader().matrix_location(); |
1899 background_color_location = | 2149 background_color_location = |
1900 program->fragment_shader().background_color_location(); | 2150 program->fragment_shader().background_color_location(); |
1901 } | 2151 } |
1902 int program_id; | 2152 int program_id; |
1903 int sampler_location; | 2153 int sampler_location; |
1904 int matrix_location; | 2154 int matrix_location; |
| 2155 int transform_location; |
1905 int background_color_location; | 2156 int background_color_location; |
1906 }; | 2157 }; |
1907 | 2158 |
1908 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 2159 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
1909 template <class Program> | 2160 template <class Program> |
1910 void Set(Program* program) { | 2161 void Set(Program* program) { |
1911 TextureProgramBinding::Set(program); | 2162 TextureProgramBinding::Set(program); |
1912 tex_transform_location = program->vertex_shader().tex_transform_location(); | 2163 tex_transform_location = program->vertex_shader().tex_transform_location(); |
1913 vertex_opacity_location = | 2164 vertex_opacity_location = |
1914 program->vertex_shader().vertex_opacity_location(); | 2165 program->vertex_shader().vertex_opacity_location(); |
1915 } | 2166 } |
1916 int tex_transform_location; | 2167 int tex_transform_location; |
1917 int vertex_opacity_location; | 2168 int vertex_opacity_location; |
1918 }; | 2169 }; |
1919 | 2170 |
1920 void GLRenderer::FlushTextureQuadCache() { | 2171 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { |
1921 // Check to see if we have anything to draw. | 2172 // Check to see if we have anything to draw. |
1922 if (draw_cache_.program_id == -1) | 2173 if (draw_cache_.program_id == -1) |
1923 return; | 2174 return; |
1924 | 2175 |
| 2176 PrepareGeometry(flush_binding); |
| 2177 |
1925 // Set the correct blending mode. | 2178 // Set the correct blending mode. |
1926 SetBlendEnabled(draw_cache_.needs_blending); | 2179 SetBlendEnabled(draw_cache_.needs_blending); |
1927 | 2180 |
1928 // Bind the program to the GL state. | 2181 // Bind the program to the GL state. |
1929 SetUseProgram(draw_cache_.program_id); | 2182 SetUseProgram(draw_cache_.program_id); |
1930 | 2183 |
1931 // Bind the correct texture sampler location. | 2184 // Bind the correct texture sampler location. |
1932 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); | 2185 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); |
1933 | 2186 |
1934 // Assume the current active textures is 0. | 2187 // Assume the current active textures is 0. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1975 gl_->DrawElements(GL_TRIANGLES, | 2228 gl_->DrawElements(GL_TRIANGLES, |
1976 6 * draw_cache_.matrix_data.size(), | 2229 6 * draw_cache_.matrix_data.size(), |
1977 GL_UNSIGNED_SHORT, | 2230 GL_UNSIGNED_SHORT, |
1978 0)); | 2231 0)); |
1979 | 2232 |
1980 // Clear the cache. | 2233 // Clear the cache. |
1981 draw_cache_.program_id = -1; | 2234 draw_cache_.program_id = -1; |
1982 draw_cache_.uv_xform_data.resize(0); | 2235 draw_cache_.uv_xform_data.resize(0); |
1983 draw_cache_.vertex_opacity_data.resize(0); | 2236 draw_cache_.vertex_opacity_data.resize(0); |
1984 draw_cache_.matrix_data.resize(0); | 2237 draw_cache_.matrix_data.resize(0); |
| 2238 |
| 2239 // If we had a clipped binding, prepare the shared binding for the |
| 2240 // next inserts. |
| 2241 if (flush_binding == CLIPPED_BINDING) { |
| 2242 PrepareGeometry(SHARED_BINDING); |
| 2243 } |
1985 } | 2244 } |
1986 | 2245 |
1987 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, | 2246 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, |
1988 const TextureDrawQuad* quad) { | 2247 const TextureDrawQuad* quad, |
| 2248 const gfx::QuadF* clip_region) { |
| 2249 // If we have a clip_region then we have to render the next quad |
| 2250 // with dynamic geometry, therefore we must flush all pending |
| 2251 // texture quads. |
| 2252 if (clip_region) { |
| 2253 // We send in false here because we want to flush what's currently in the |
| 2254 // queue using the shared_geometry and not clipped_geometry |
| 2255 FlushTextureQuadCache(SHARED_BINDING); |
| 2256 } |
| 2257 |
1989 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2258 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
1990 gl_, | 2259 gl_, |
1991 &highp_threshold_cache_, | 2260 &highp_threshold_cache_, |
1992 highp_threshold_min_, | 2261 highp_threshold_min_, |
1993 quad->shared_quad_state->visible_content_rect.bottom_right()); | 2262 quad->shared_quad_state->visible_content_rect.bottom_right()); |
1994 | 2263 |
1995 // Choose the correct texture program binding | 2264 // Choose the correct texture program binding |
1996 TexTransformTextureProgramBinding binding; | 2265 TexTransformTextureProgramBinding binding; |
1997 if (quad->premultiplied_alpha) { | 2266 if (quad->premultiplied_alpha) { |
1998 if (quad->background_color == SK_ColorTRANSPARENT) { | 2267 if (quad->background_color == SK_ColorTRANSPARENT) { |
(...skipping 11 matching lines...) Expand all Loading... |
2010 } | 2279 } |
2011 | 2280 |
2012 int resource_id = quad->resource_id; | 2281 int resource_id = quad->resource_id; |
2013 | 2282 |
2014 if (draw_cache_.program_id != binding.program_id || | 2283 if (draw_cache_.program_id != binding.program_id || |
2015 draw_cache_.resource_id != resource_id || | 2284 draw_cache_.resource_id != resource_id || |
2016 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || | 2285 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || |
2017 draw_cache_.nearest_neighbor != quad->nearest_neighbor || | 2286 draw_cache_.nearest_neighbor != quad->nearest_neighbor || |
2018 draw_cache_.background_color != quad->background_color || | 2287 draw_cache_.background_color != quad->background_color || |
2019 draw_cache_.matrix_data.size() >= 8) { | 2288 draw_cache_.matrix_data.size() >= 8) { |
2020 FlushTextureQuadCache(); | 2289 FlushTextureQuadCache(SHARED_BINDING); |
2021 draw_cache_.program_id = binding.program_id; | 2290 draw_cache_.program_id = binding.program_id; |
2022 draw_cache_.resource_id = resource_id; | 2291 draw_cache_.resource_id = resource_id; |
2023 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); | 2292 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); |
2024 draw_cache_.nearest_neighbor = quad->nearest_neighbor; | 2293 draw_cache_.nearest_neighbor = quad->nearest_neighbor; |
2025 draw_cache_.background_color = quad->background_color; | 2294 draw_cache_.background_color = quad->background_color; |
2026 | 2295 |
2027 draw_cache_.uv_xform_location = binding.tex_transform_location; | 2296 draw_cache_.uv_xform_location = binding.tex_transform_location; |
2028 draw_cache_.background_color_location = binding.background_color_location; | 2297 draw_cache_.background_color_location = binding.background_color_location; |
2029 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; | 2298 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; |
2030 draw_cache_.matrix_location = binding.matrix_location; | 2299 draw_cache_.matrix_location = binding.matrix_location; |
2031 draw_cache_.sampler_location = binding.sampler_location; | 2300 draw_cache_.sampler_location = binding.sampler_location; |
2032 } | 2301 } |
2033 | 2302 |
2034 // Generate the uv-transform | 2303 // Generate the uv-transform |
2035 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); | 2304 if (!clip_region) { |
| 2305 draw_cache_.uv_xform_data.push_back(UVTransform(quad)); |
| 2306 } else { |
| 2307 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; |
| 2308 draw_cache_.uv_xform_data.push_back(uv_transform); |
| 2309 } |
2036 | 2310 |
2037 // Generate the vertex opacity | 2311 // Generate the vertex opacity |
2038 const float opacity = quad->opacity(); | 2312 const float opacity = quad->opacity(); |
2039 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); | 2313 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); |
2040 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); | 2314 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); |
2041 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); | 2315 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); |
2042 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); | 2316 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); |
2043 | 2317 |
2044 // Generate the transform matrix | 2318 // Generate the transform matrix |
2045 gfx::Transform quad_rect_matrix; | 2319 gfx::Transform quad_rect_matrix; |
2046 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 2320 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
2047 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; | 2321 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; |
2048 | 2322 |
2049 Float16 m; | 2323 Float16 m; |
2050 quad_rect_matrix.matrix().asColMajorf(m.data); | 2324 quad_rect_matrix.matrix().asColMajorf(m.data); |
2051 draw_cache_.matrix_data.push_back(m); | 2325 draw_cache_.matrix_data.push_back(m); |
| 2326 |
| 2327 if (clip_region) { |
| 2328 gfx::QuadF scaled_region; |
| 2329 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { |
| 2330 scaled_region = SharedGeometryQuad().BoundingBox(); |
| 2331 } |
| 2332 // Both the scaled region and the SharedGeomtryQuad are in the space |
| 2333 // -0.5->0.5. We need to move that to the space 0->1. |
| 2334 float uv[8]; |
| 2335 uv[0] = scaled_region.p1().x() + 0.5f; |
| 2336 uv[1] = scaled_region.p1().y() + 0.5f; |
| 2337 uv[2] = scaled_region.p2().x() + 0.5f; |
| 2338 uv[3] = scaled_region.p2().y() + 0.5f; |
| 2339 uv[4] = scaled_region.p3().x() + 0.5f; |
| 2340 uv[5] = scaled_region.p3().y() + 0.5f; |
| 2341 uv[6] = scaled_region.p4().x() + 0.5f; |
| 2342 uv[7] = scaled_region.p4().y() + 0.5f; |
| 2343 PrepareGeometry(CLIPPED_BINDING); |
| 2344 clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv); |
| 2345 FlushTextureQuadCache(CLIPPED_BINDING); |
| 2346 } |
2052 } | 2347 } |
2053 | 2348 |
2054 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, | 2349 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, |
2055 const IOSurfaceDrawQuad* quad) { | 2350 const IOSurfaceDrawQuad* quad, |
| 2351 const gfx::QuadF* clip_region) { |
2056 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2352 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
2057 | 2353 |
2058 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2354 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
2059 gl_, | 2355 gl_, |
2060 &highp_threshold_cache_, | 2356 &highp_threshold_cache_, |
2061 highp_threshold_min_, | 2357 highp_threshold_min_, |
2062 quad->shared_quad_state->visible_content_rect.bottom_right()); | 2358 quad->shared_quad_state->visible_content_rect.bottom_right()); |
2063 | 2359 |
2064 TexTransformTextureProgramBinding binding; | 2360 TexTransformTextureProgramBinding binding; |
2065 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision)); | 2361 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision)); |
(...skipping 18 matching lines...) Expand all Loading... |
2084 | 2380 |
2085 const float vertex_opacity[] = {quad->opacity(), quad->opacity(), | 2381 const float vertex_opacity[] = {quad->opacity(), quad->opacity(), |
2086 quad->opacity(), quad->opacity()}; | 2382 quad->opacity(), quad->opacity()}; |
2087 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity)); | 2383 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity)); |
2088 | 2384 |
2089 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 2385 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
2090 quad->io_surface_resource_id); | 2386 quad->io_surface_resource_id); |
2091 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2387 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
2092 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); | 2388 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); |
2093 | 2389 |
2094 DrawQuadGeometry( | 2390 if (!clip_region) { |
2095 frame, quad->quadTransform(), quad->rect, binding.matrix_location); | 2391 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, |
| 2392 binding.matrix_location); |
| 2393 } else { |
| 2394 float uvs[8] = {0}; |
| 2395 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2396 DrawQuadGeometryClippedByQuadF(frame, quad->quadTransform(), quad->rect, |
| 2397 *clip_region, binding.matrix_location, uvs); |
| 2398 } |
2096 | 2399 |
2097 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); | 2400 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); |
2098 } | 2401 } |
2099 | 2402 |
2100 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 2403 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
2101 if (use_sync_query_) { | 2404 if (use_sync_query_) { |
2102 DCHECK(current_sync_query_); | 2405 DCHECK(current_sync_query_); |
2103 current_sync_query_->End(); | 2406 current_sync_query_->End(); |
2104 pending_sync_queries_.push_back(current_sync_query_.Pass()); | 2407 pending_sync_queries_.push_back(current_sync_query_.Pass()); |
2105 } | 2408 } |
2106 | 2409 |
2107 current_framebuffer_lock_ = nullptr; | 2410 current_framebuffer_lock_ = nullptr; |
2108 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); | 2411 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); |
2109 | 2412 |
2110 GLC(gl_, gl_->Disable(GL_BLEND)); | 2413 GLC(gl_, gl_->Disable(GL_BLEND)); |
2111 blend_shadow_ = false; | 2414 blend_shadow_ = false; |
2112 | 2415 |
2113 ScheduleOverlays(frame); | 2416 ScheduleOverlays(frame); |
2114 } | 2417 } |
2115 | 2418 |
2116 void GLRenderer::FinishDrawingQuadList() { FlushTextureQuadCache(); } | 2419 void GLRenderer::FinishDrawingQuadList() { |
| 2420 FlushTextureQuadCache(SHARED_BINDING); |
| 2421 } |
2117 | 2422 |
2118 bool GLRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { | 2423 bool GLRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { |
2119 if (frame->current_render_pass != frame->root_render_pass) | 2424 if (frame->current_render_pass != frame->root_render_pass) |
2120 return true; | 2425 return true; |
2121 return FlippedRootFramebuffer(); | 2426 return FlippedRootFramebuffer(); |
2122 } | 2427 } |
2123 | 2428 |
2124 bool GLRenderer::FlippedRootFramebuffer() const { | 2429 bool GLRenderer::FlippedRootFramebuffer() const { |
2125 // GL is normally flipped, so a flipped output results in an unflipping. | 2430 // GL is normally flipped, so a flipped output results in an unflipping. |
2126 return !output_surface_->capabilities().flipped_output_surface; | 2431 return !output_surface_->capabilities().flipped_output_surface; |
2127 } | 2432 } |
2128 | 2433 |
2129 void GLRenderer::EnsureScissorTestEnabled() { | 2434 void GLRenderer::EnsureScissorTestEnabled() { |
2130 if (is_scissor_enabled_) | 2435 if (is_scissor_enabled_) |
2131 return; | 2436 return; |
2132 | 2437 |
2133 FlushTextureQuadCache(); | 2438 FlushTextureQuadCache(SHARED_BINDING); |
2134 GLC(gl_, gl_->Enable(GL_SCISSOR_TEST)); | 2439 GLC(gl_, gl_->Enable(GL_SCISSOR_TEST)); |
2135 is_scissor_enabled_ = true; | 2440 is_scissor_enabled_ = true; |
2136 } | 2441 } |
2137 | 2442 |
2138 void GLRenderer::EnsureScissorTestDisabled() { | 2443 void GLRenderer::EnsureScissorTestDisabled() { |
2139 if (!is_scissor_enabled_) | 2444 if (!is_scissor_enabled_) |
2140 return; | 2445 return; |
2141 | 2446 |
2142 FlushTextureQuadCache(); | 2447 FlushTextureQuadCache(SHARED_BINDING); |
2143 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); | 2448 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); |
2144 is_scissor_enabled_ = false; | 2449 is_scissor_enabled_ = false; |
2145 } | 2450 } |
2146 | 2451 |
2147 void GLRenderer::CopyCurrentRenderPassToBitmap( | 2452 void GLRenderer::CopyCurrentRenderPassToBitmap( |
2148 DrawingFrame* frame, | 2453 DrawingFrame* frame, |
2149 scoped_ptr<CopyOutputRequest> request) { | 2454 scoped_ptr<CopyOutputRequest> request) { |
2150 TRACE_EVENT0("cc", "GLRenderer::CopyCurrentRenderPassToBitmap"); | 2455 TRACE_EVENT0("cc", "GLRenderer::CopyCurrentRenderPassToBitmap"); |
2151 gfx::Rect copy_rect = frame->current_render_pass->output_rect; | 2456 gfx::Rect copy_rect = frame->current_render_pass->output_rect; |
2152 if (request->has_area()) | 2457 if (request->has_area()) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 blend_shadow_ = enabled; | 2506 blend_shadow_ = enabled; |
2202 } | 2507 } |
2203 | 2508 |
2204 void GLRenderer::SetUseProgram(unsigned program) { | 2509 void GLRenderer::SetUseProgram(unsigned program) { |
2205 if (program == program_shadow_) | 2510 if (program == program_shadow_) |
2206 return; | 2511 return; |
2207 gl_->UseProgram(program); | 2512 gl_->UseProgram(program); |
2208 program_shadow_ = program; | 2513 program_shadow_ = program; |
2209 } | 2514 } |
2210 | 2515 |
| 2516 void GLRenderer::DrawQuadGeometryClippedByQuadF( |
| 2517 const DrawingFrame* frame, |
| 2518 const gfx::Transform& draw_transform, |
| 2519 const gfx::RectF& quad_rect, |
| 2520 const gfx::QuadF& clipping_region_quad, |
| 2521 int matrix_location, |
| 2522 const float* uvs) { |
| 2523 PrepareGeometry(CLIPPED_BINDING); |
| 2524 if (uvs) { |
| 2525 clipped_geometry_->InitializeCustomQuadWithUVs(clipping_region_quad, uvs); |
| 2526 } else { |
| 2527 clipped_geometry_->InitializeCustomQuad(clipping_region_quad); |
| 2528 } |
| 2529 gfx::Transform quad_rect_matrix; |
| 2530 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); |
| 2531 static float gl_matrix[16]; |
| 2532 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); |
| 2533 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); |
| 2534 |
| 2535 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, |
| 2536 reinterpret_cast<const void*>(0))); |
| 2537 } |
| 2538 |
2211 void GLRenderer::DrawQuadGeometry(const DrawingFrame* frame, | 2539 void GLRenderer::DrawQuadGeometry(const DrawingFrame* frame, |
2212 const gfx::Transform& draw_transform, | 2540 const gfx::Transform& draw_transform, |
2213 const gfx::RectF& quad_rect, | 2541 const gfx::RectF& quad_rect, |
2214 int matrix_location) { | 2542 int matrix_location) { |
| 2543 PrepareGeometry(SHARED_BINDING); |
2215 gfx::Transform quad_rect_matrix; | 2544 gfx::Transform quad_rect_matrix; |
2216 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); | 2545 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); |
2217 static float gl_matrix[16]; | 2546 static float gl_matrix[16]; |
2218 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); | 2547 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); |
2219 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); | 2548 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); |
2220 | 2549 |
2221 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); | 2550 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); |
2222 } | 2551 } |
2223 | 2552 |
2224 void GLRenderer::Finish() { | 2553 void GLRenderer::Finish() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2267 | 2596 |
2268 void GLRenderer::EnforceMemoryPolicy() { | 2597 void GLRenderer::EnforceMemoryPolicy() { |
2269 if (!visible()) { | 2598 if (!visible()) { |
2270 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); | 2599 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); |
2271 ReleaseRenderPassTextures(); | 2600 ReleaseRenderPassTextures(); |
2272 DiscardBackbuffer(); | 2601 DiscardBackbuffer(); |
2273 resource_provider_->ReleaseCachedData(); | 2602 resource_provider_->ReleaseCachedData(); |
2274 output_surface_->context_provider()->DeleteCachedResources(); | 2603 output_surface_->context_provider()->DeleteCachedResources(); |
2275 GLC(gl_, gl_->Flush()); | 2604 GLC(gl_, gl_->Flush()); |
2276 } | 2605 } |
| 2606 PrepareGeometry(NO_BINDING); |
2277 } | 2607 } |
2278 | 2608 |
2279 void GLRenderer::DiscardBackbuffer() { | 2609 void GLRenderer::DiscardBackbuffer() { |
2280 if (is_backbuffer_discarded_) | 2610 if (is_backbuffer_discarded_) |
2281 return; | 2611 return; |
2282 | 2612 |
2283 output_surface_->DiscardBackbuffer(); | 2613 output_surface_->DiscardBackbuffer(); |
2284 | 2614 |
2285 is_backbuffer_discarded_ = true; | 2615 is_backbuffer_discarded_ = true; |
2286 | 2616 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2598 | 2928 |
2599 void GLRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { | 2929 void GLRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { |
2600 EnsureScissorTestEnabled(); | 2930 EnsureScissorTestEnabled(); |
2601 | 2931 |
2602 // Don't unnecessarily ask the context to change the scissor, because it | 2932 // Don't unnecessarily ask the context to change the scissor, because it |
2603 // may cause undesired GPU pipeline flushes. | 2933 // may cause undesired GPU pipeline flushes. |
2604 if (scissor_rect == scissor_rect_ && !scissor_rect_needs_reset_) | 2934 if (scissor_rect == scissor_rect_ && !scissor_rect_needs_reset_) |
2605 return; | 2935 return; |
2606 | 2936 |
2607 scissor_rect_ = scissor_rect; | 2937 scissor_rect_ = scissor_rect; |
2608 FlushTextureQuadCache(); | 2938 FlushTextureQuadCache(SHARED_BINDING); |
2609 GLC(gl_, | 2939 GLC(gl_, |
2610 gl_->Scissor(scissor_rect.x(), | 2940 gl_->Scissor(scissor_rect.x(), |
2611 scissor_rect.y(), | 2941 scissor_rect.y(), |
2612 scissor_rect.width(), | 2942 scissor_rect.width(), |
2613 scissor_rect.height())); | 2943 scissor_rect.height())); |
2614 | 2944 |
2615 scissor_rect_needs_reset_ = false; | 2945 scissor_rect_needs_reset_ = false; |
2616 } | 2946 } |
2617 | 2947 |
2618 void GLRenderer::SetDrawViewport(const gfx::Rect& window_space_viewport) { | 2948 void GLRenderer::SetDrawViewport(const gfx::Rect& window_space_viewport) { |
2619 viewport_ = window_space_viewport; | 2949 viewport_ = window_space_viewport; |
2620 GLC(gl_, | 2950 GLC(gl_, |
2621 gl_->Viewport(window_space_viewport.x(), | 2951 gl_->Viewport(window_space_viewport.x(), |
2622 window_space_viewport.y(), | 2952 window_space_viewport.y(), |
2623 window_space_viewport.width(), | 2953 window_space_viewport.width(), |
2624 window_space_viewport.height())); | 2954 window_space_viewport.height())); |
2625 } | 2955 } |
2626 | 2956 |
2627 void GLRenderer::InitializeSharedObjects() { | 2957 void GLRenderer::InitializeSharedObjects() { |
2628 TRACE_EVENT0("cc", "GLRenderer::InitializeSharedObjects"); | 2958 TRACE_EVENT0("cc", "GLRenderer::InitializeSharedObjects"); |
2629 | 2959 |
2630 // Create an FBO for doing offscreen rendering. | 2960 // Create an FBO for doing offscreen rendering. |
2631 GLC(gl_, gl_->GenFramebuffers(1, &offscreen_framebuffer_id_)); | 2961 GLC(gl_, gl_->GenFramebuffers(1, &offscreen_framebuffer_id_)); |
2632 | 2962 |
2633 shared_geometry_ = make_scoped_ptr( | 2963 shared_geometry_ = |
2634 new GeometryBinding(gl_, QuadVertexRect())); | 2964 make_scoped_ptr(new StaticGeometryBinding(gl_, QuadVertexRect())); |
| 2965 clipped_geometry_ = make_scoped_ptr(new DynamicGeometryBinding(gl_)); |
| 2966 } |
| 2967 |
| 2968 void GLRenderer::PrepareGeometry(BoundGeometry binding) { |
| 2969 if (binding == bound_geometry_) { |
| 2970 return; |
| 2971 } |
| 2972 |
| 2973 switch (binding) { |
| 2974 case SHARED_BINDING: |
| 2975 shared_geometry_->PrepareForDraw(); |
| 2976 break; |
| 2977 case CLIPPED_BINDING: |
| 2978 clipped_geometry_->PrepareForDraw(); |
| 2979 break; |
| 2980 case NO_BINDING: |
| 2981 break; |
| 2982 } |
| 2983 bound_geometry_ = binding; |
2635 } | 2984 } |
2636 | 2985 |
2637 const GLRenderer::TileCheckerboardProgram* | 2986 const GLRenderer::TileCheckerboardProgram* |
2638 GLRenderer::GetTileCheckerboardProgram() { | 2987 GLRenderer::GetTileCheckerboardProgram() { |
2639 if (!tile_checkerboard_program_.initialized()) { | 2988 if (!tile_checkerboard_program_.initialized()) { |
2640 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); | 2989 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); |
2641 tile_checkerboard_program_.Initialize(output_surface_->context_provider(), | 2990 tile_checkerboard_program_.Initialize(output_surface_->context_provider(), |
2642 TEX_COORD_PRECISION_NA, | 2991 TEX_COORD_PRECISION_NA, |
2643 SAMPLER_TYPE_NA); | 2992 SAMPLER_TYPE_NA); |
2644 } | 2993 } |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3104 scissor_rect_needs_reset_ = true; | 3453 scissor_rect_needs_reset_ = true; |
3105 stencil_shadow_ = false; | 3454 stencil_shadow_ = false; |
3106 blend_shadow_ = true; | 3455 blend_shadow_ = true; |
3107 program_shadow_ = 0; | 3456 program_shadow_ = 0; |
3108 | 3457 |
3109 RestoreGLState(); | 3458 RestoreGLState(); |
3110 } | 3459 } |
3111 | 3460 |
3112 void GLRenderer::RestoreGLState() { | 3461 void GLRenderer::RestoreGLState() { |
3113 // This restores the current GLRenderer state to the GL context. | 3462 // This restores the current GLRenderer state to the GL context. |
3114 | 3463 bound_geometry_ = NO_BINDING; |
3115 shared_geometry_->PrepareForDraw(); | 3464 PrepareGeometry(SHARED_BINDING); |
3116 | 3465 |
3117 GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); | 3466 GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); |
3118 GLC(gl_, gl_->Disable(GL_CULL_FACE)); | 3467 GLC(gl_, gl_->Disable(GL_CULL_FACE)); |
3119 GLC(gl_, gl_->ColorMask(true, true, true, true)); | 3468 GLC(gl_, gl_->ColorMask(true, true, true, true)); |
3120 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 3469 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
3121 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); | 3470 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); |
3122 | 3471 |
3123 if (program_shadow_) | 3472 if (program_shadow_) |
3124 gl_->UseProgram(program_shadow_); | 3473 gl_->UseProgram(program_shadow_); |
3125 | 3474 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3173 context_support_->ScheduleOverlayPlane( | 3522 context_support_->ScheduleOverlayPlane( |
3174 overlay.plane_z_order, | 3523 overlay.plane_z_order, |
3175 overlay.transform, | 3524 overlay.transform, |
3176 pending_overlay_resources_.back()->texture_id(), | 3525 pending_overlay_resources_.back()->texture_id(), |
3177 overlay.display_rect, | 3526 overlay.display_rect, |
3178 overlay.uv_rect); | 3527 overlay.uv_rect); |
3179 } | 3528 } |
3180 } | 3529 } |
3181 | 3530 |
3182 } // namespace cc | 3531 } // namespace cc |
OLD | NEW |