| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 const RenderPassDrawQuad* quad = nullptr; | 167 const RenderPassDrawQuad* quad = nullptr; |
| 168 const Resource* contents_texture = nullptr; | 168 const Resource* contents_texture = nullptr; |
| 169 const gfx::QuadF* clip_region = nullptr; | 169 const gfx::QuadF* clip_region = nullptr; |
| 170 bool flip_texture = false; | 170 bool flip_texture = false; |
| 171 gfx::Transform window_matrix; | 171 gfx::Transform window_matrix; |
| 172 gfx::Transform projection_matrix; | 172 gfx::Transform projection_matrix; |
| 173 gfx::Transform quad_to_target_transform; | 173 gfx::Transform quad_to_target_transform; |
| 174 const FilterOperations* filters = nullptr; | 174 const FilterOperations* filters = nullptr; |
| 175 const FilterOperations* background_filters = nullptr; | 175 const FilterOperations* background_filters = nullptr; |
| 176 | 176 |
| 177 // |frame| is only used for background effects. | |
| 178 DirectRenderer::DrawingFrame* frame = nullptr; | |
| 179 | |
| 180 // Whether the texture to be sampled from needs to be flipped. | 177 // Whether the texture to be sampled from needs to be flipped. |
| 181 bool source_needs_flip = false; | 178 bool source_needs_flip = false; |
| 182 | 179 |
| 183 float edge[24]; | 180 float edge[24]; |
| 184 SkScalar color_matrix[20]; | 181 SkScalar color_matrix[20]; |
| 185 | 182 |
| 186 // Blending refers to modifications to the backdrop. | 183 // Blending refers to modifications to the backdrop. |
| 187 bool use_shaders_for_blending = false; | 184 bool use_shaders_for_blending = false; |
| 188 const Program* program = nullptr; | 185 const Program* program = nullptr; |
| 189 | 186 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 bool using_default_framebuffer = | 457 bool using_default_framebuffer = |
| 461 !current_framebuffer_lock_ && | 458 !current_framebuffer_lock_ && |
| 462 output_surface_->capabilities().uses_default_gl_framebuffer; | 459 output_surface_->capabilities().uses_default_gl_framebuffer; |
| 463 GLenum attachments[] = {static_cast<GLenum>( | 460 GLenum attachments[] = {static_cast<GLenum>( |
| 464 using_default_framebuffer ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0_EXT)}; | 461 using_default_framebuffer ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0_EXT)}; |
| 465 gl_->DiscardFramebufferEXT( | 462 gl_->DiscardFramebufferEXT( |
| 466 GL_FRAMEBUFFER, arraysize(attachments), attachments); | 463 GL_FRAMEBUFFER, arraysize(attachments), attachments); |
| 467 } | 464 } |
| 468 | 465 |
| 469 void GLRenderer::PrepareSurfaceForPass( | 466 void GLRenderer::PrepareSurfaceForPass( |
| 470 DrawingFrame* frame, | |
| 471 SurfaceInitializationMode initialization_mode, | 467 SurfaceInitializationMode initialization_mode, |
| 472 const gfx::Rect& render_pass_scissor) { | 468 const gfx::Rect& render_pass_scissor) { |
| 473 SetViewport(); | 469 SetViewport(); |
| 474 | 470 |
| 475 switch (initialization_mode) { | 471 switch (initialization_mode) { |
| 476 case SURFACE_INITIALIZATION_MODE_PRESERVE: | 472 case SURFACE_INITIALIZATION_MODE_PRESERVE: |
| 477 EnsureScissorTestDisabled(); | 473 EnsureScissorTestDisabled(); |
| 478 return; | 474 return; |
| 479 case SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR: | 475 case SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR: |
| 480 EnsureScissorTestDisabled(); | 476 EnsureScissorTestDisabled(); |
| 481 DiscardPixels(); | 477 DiscardPixels(); |
| 482 ClearFramebuffer(frame); | 478 ClearFramebuffer(); |
| 483 break; | 479 break; |
| 484 case SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR: | 480 case SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR: |
| 485 SetScissorTestRect(render_pass_scissor); | 481 SetScissorTestRect(render_pass_scissor); |
| 486 ClearFramebuffer(frame); | 482 ClearFramebuffer(); |
| 487 break; | 483 break; |
| 488 } | 484 } |
| 489 } | 485 } |
| 490 | 486 |
| 491 void GLRenderer::ClearFramebuffer(DrawingFrame* frame) { | 487 void GLRenderer::ClearFramebuffer() { |
| 492 // On DEBUG builds, opaque render passes are cleared to blue to easily see | 488 // On DEBUG builds, opaque render passes are cleared to blue to easily see |
| 493 // regions that were not drawn on the screen. | 489 // regions that were not drawn on the screen. |
| 494 if (frame->current_render_pass->has_transparent_background) | 490 if (current_frame()->current_render_pass->has_transparent_background) |
| 495 gl_->ClearColor(0, 0, 0, 0); | 491 gl_->ClearColor(0, 0, 0, 0); |
| 496 else | 492 else |
| 497 gl_->ClearColor(0, 0, 1, 1); | 493 gl_->ClearColor(0, 0, 1, 1); |
| 498 | 494 |
| 499 gl_->ClearStencil(0); | 495 gl_->ClearStencil(0); |
| 500 | 496 |
| 501 bool always_clear = overdraw_feedback_; | 497 bool always_clear = overdraw_feedback_; |
| 502 #ifndef NDEBUG | 498 #ifndef NDEBUG |
| 503 always_clear = true; | 499 always_clear = true; |
| 504 #endif | 500 #endif |
| 505 if (always_clear || frame->current_render_pass->has_transparent_background) { | 501 if (always_clear || |
| 502 current_frame()->current_render_pass->has_transparent_background) { |
| 506 GLbitfield clear_bits = GL_COLOR_BUFFER_BIT; | 503 GLbitfield clear_bits = GL_COLOR_BUFFER_BIT; |
| 507 if (always_clear) | 504 if (always_clear) |
| 508 clear_bits |= GL_STENCIL_BUFFER_BIT; | 505 clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 509 gl_->Clear(clear_bits); | 506 gl_->Clear(clear_bits); |
| 510 } | 507 } |
| 511 } | 508 } |
| 512 | 509 |
| 513 void GLRenderer::BeginDrawingFrame(DrawingFrame* frame) { | 510 void GLRenderer::BeginDrawingFrame() { |
| 514 TRACE_EVENT0("cc", "GLRenderer::BeginDrawingFrame"); | 511 TRACE_EVENT0("cc", "GLRenderer::BeginDrawingFrame"); |
| 515 | 512 |
| 516 scoped_refptr<ResourceProvider::Fence> read_lock_fence; | 513 scoped_refptr<ResourceProvider::Fence> read_lock_fence; |
| 517 if (use_sync_query_) { | 514 if (use_sync_query_) { |
| 518 // Block until oldest sync query has passed if the number of pending queries | 515 // Block until oldest sync query has passed if the number of pending queries |
| 519 // ever reach kMaxPendingSyncQueries. | 516 // ever reach kMaxPendingSyncQueries. |
| 520 if (pending_sync_queries_.size() >= kMaxPendingSyncQueries) { | 517 if (pending_sync_queries_.size() >= kMaxPendingSyncQueries) { |
| 521 LOG(ERROR) << "Reached limit of pending sync queries."; | 518 LOG(ERROR) << "Reached limit of pending sync queries."; |
| 522 | 519 |
| 523 pending_sync_queries_.front()->Wait(); | 520 pending_sync_queries_.front()->Wait(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 538 read_lock_fence = current_sync_query_->Begin(); | 535 read_lock_fence = current_sync_query_->Begin(); |
| 539 } else { | 536 } else { |
| 540 read_lock_fence = | 537 read_lock_fence = |
| 541 make_scoped_refptr(new ResourceProvider::SynchronousFence(gl_)); | 538 make_scoped_refptr(new ResourceProvider::SynchronousFence(gl_)); |
| 542 } | 539 } |
| 543 resource_provider_->SetReadLockFence(read_lock_fence.get()); | 540 resource_provider_->SetReadLockFence(read_lock_fence.get()); |
| 544 | 541 |
| 545 // Insert WaitSyncTokenCHROMIUM on quad resources prior to drawing the frame, | 542 // Insert WaitSyncTokenCHROMIUM on quad resources prior to drawing the frame, |
| 546 // so that drawing can proceed without GL context switching interruptions. | 543 // so that drawing can proceed without GL context switching interruptions. |
| 547 ResourceProvider* resource_provider = resource_provider_; | 544 ResourceProvider* resource_provider = resource_provider_; |
| 548 for (const auto& pass : *frame->render_passes_in_draw_order) { | 545 for (const auto& pass : *current_frame()->render_passes_in_draw_order) { |
| 549 for (auto* quad : pass->quad_list) { | 546 for (auto* quad : pass->quad_list) { |
| 550 for (ResourceId resource_id : quad->resources) | 547 for (ResourceId resource_id : quad->resources) |
| 551 resource_provider->WaitSyncTokenIfNeeded(resource_id); | 548 resource_provider->WaitSyncTokenIfNeeded(resource_id); |
| 552 } | 549 } |
| 553 } | 550 } |
| 554 | 551 |
| 555 // TODO(enne): Do we need to reinitialize all of this state per frame? | 552 // TODO(enne): Do we need to reinitialize all of this state per frame? |
| 556 ReinitializeGLState(); | 553 ReinitializeGLState(); |
| 557 } | 554 } |
| 558 | 555 |
| 559 void GLRenderer::DoDrawQuad(DrawingFrame* frame, | 556 void GLRenderer::DoDrawQuad(const DrawQuad* quad, |
| 560 const DrawQuad* quad, | |
| 561 const gfx::QuadF* clip_region) { | 557 const gfx::QuadF* clip_region) { |
| 562 DCHECK(quad->rect.Contains(quad->visible_rect)); | 558 DCHECK(quad->rect.Contains(quad->visible_rect)); |
| 563 if (quad->material != DrawQuad::TEXTURE_CONTENT) { | 559 if (quad->material != DrawQuad::TEXTURE_CONTENT) { |
| 564 FlushTextureQuadCache(SHARED_BINDING); | 560 FlushTextureQuadCache(SHARED_BINDING); |
| 565 } | 561 } |
| 566 | 562 |
| 567 switch (quad->material) { | 563 switch (quad->material) { |
| 568 case DrawQuad::INVALID: | 564 case DrawQuad::INVALID: |
| 569 NOTREACHED(); | 565 NOTREACHED(); |
| 570 break; | 566 break; |
| 571 case DrawQuad::DEBUG_BORDER: | 567 case DrawQuad::DEBUG_BORDER: |
| 572 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 568 DrawDebugBorderQuad(DebugBorderDrawQuad::MaterialCast(quad)); |
| 573 break; | 569 break; |
| 574 case DrawQuad::PICTURE_CONTENT: | 570 case DrawQuad::PICTURE_CONTENT: |
| 575 // PictureDrawQuad should only be used for resourceless software draws. | 571 // PictureDrawQuad should only be used for resourceless software draws. |
| 576 NOTREACHED(); | 572 NOTREACHED(); |
| 577 break; | 573 break; |
| 578 case DrawQuad::RENDER_PASS: | 574 case DrawQuad::RENDER_PASS: |
| 579 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad), | 575 DrawRenderPassQuad(RenderPassDrawQuad::MaterialCast(quad), clip_region); |
| 580 clip_region); | |
| 581 break; | 576 break; |
| 582 case DrawQuad::SOLID_COLOR: | 577 case DrawQuad::SOLID_COLOR: |
| 583 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad), | 578 DrawSolidColorQuad(SolidColorDrawQuad::MaterialCast(quad), clip_region); |
| 584 clip_region); | |
| 585 break; | 579 break; |
| 586 case DrawQuad::STREAM_VIDEO_CONTENT: | 580 case DrawQuad::STREAM_VIDEO_CONTENT: |
| 587 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad), | 581 DrawStreamVideoQuad(StreamVideoDrawQuad::MaterialCast(quad), clip_region); |
| 588 clip_region); | |
| 589 break; | 582 break; |
| 590 case DrawQuad::SURFACE_CONTENT: | 583 case DrawQuad::SURFACE_CONTENT: |
| 591 // Surface content should be fully resolved to other quad types before | 584 // Surface content should be fully resolved to other quad types before |
| 592 // reaching a direct renderer. | 585 // reaching a direct renderer. |
| 593 NOTREACHED(); | 586 NOTREACHED(); |
| 594 break; | 587 break; |
| 595 case DrawQuad::TEXTURE_CONTENT: | 588 case DrawQuad::TEXTURE_CONTENT: |
| 596 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), | 589 EnqueueTextureQuad(TextureDrawQuad::MaterialCast(quad), clip_region); |
| 597 clip_region); | |
| 598 break; | 590 break; |
| 599 case DrawQuad::TILED_CONTENT: | 591 case DrawQuad::TILED_CONTENT: |
| 600 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); | 592 DrawTileQuad(TileDrawQuad::MaterialCast(quad), clip_region); |
| 601 break; | 593 break; |
| 602 case DrawQuad::YUV_VIDEO_CONTENT: | 594 case DrawQuad::YUV_VIDEO_CONTENT: |
| 603 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), | 595 DrawYUVVideoQuad(YUVVideoDrawQuad::MaterialCast(quad), clip_region); |
| 604 clip_region); | |
| 605 break; | 596 break; |
| 606 } | 597 } |
| 607 } | 598 } |
| 608 | 599 |
| 609 // This function does not handle 3D sorting right now, since the debug border | 600 // This function does not handle 3D sorting right now, since the debug border |
| 610 // quads are just drawn as their original quads and not in split pieces. This | 601 // quads are just drawn as their original quads and not in split pieces. This |
| 611 // results in some debug border quads drawing over foreground quads. | 602 // results in some debug border quads drawing over foreground quads. |
| 612 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, | 603 void GLRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) { |
| 613 const DebugBorderDrawQuad* quad) { | |
| 614 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 604 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 615 | 605 |
| 616 const Program* program = GetProgram(ProgramKey::DebugBorder()); | 606 const Program* program = GetProgram(ProgramKey::DebugBorder()); |
| 617 SetUseProgram(program); | 607 SetUseProgram(program); |
| 618 | 608 |
| 619 // Use the full quad_rect for debug quads to not move the edges based on | 609 // Use the full quad_rect for debug quads to not move the edges based on |
| 620 // partial swaps. | 610 // partial swaps. |
| 621 gfx::Rect layer_rect = quad->rect; | 611 gfx::Rect layer_rect = quad->rect; |
| 622 gfx::Transform render_matrix; | 612 gfx::Transform render_matrix; |
| 623 QuadRectTransform(&render_matrix, | 613 QuadRectTransform(&render_matrix, |
| 624 quad->shared_quad_state->quad_to_target_transform, | 614 quad->shared_quad_state->quad_to_target_transform, |
| 625 gfx::RectF(layer_rect)); | 615 gfx::RectF(layer_rect)); |
| 626 SetShaderMatrix(frame->projection_matrix * render_matrix); | 616 SetShaderMatrix(current_frame()->projection_matrix * render_matrix); |
| 627 SetShaderColor(quad->color, 1.f); | 617 SetShaderColor(quad->color, 1.f); |
| 628 | 618 |
| 629 gl_->LineWidth(quad->width); | 619 gl_->LineWidth(quad->width); |
| 630 | 620 |
| 631 // The indices for the line are stored in the same array as the triangle | 621 // The indices for the line are stored in the same array as the triangle |
| 632 // indices. | 622 // indices. |
| 633 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); | 623 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); |
| 634 } | 624 } |
| 635 | 625 |
| 636 static sk_sp<SkImage> WrapTexture( | 626 static sk_sp<SkImage> WrapTexture( |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 uvs[2] = ((clip->p2().x() - rect.x()) / rect.width()); | 824 uvs[2] = ((clip->p2().x() - rect.x()) / rect.width()); |
| 835 uvs[3] = ((clip->p2().y() - rect.y()) / rect.height()); | 825 uvs[3] = ((clip->p2().y() - rect.y()) / rect.height()); |
| 836 uvs[4] = ((clip->p3().x() - rect.x()) / rect.width()); | 826 uvs[4] = ((clip->p3().x() - rect.x()) / rect.width()); |
| 837 uvs[5] = ((clip->p3().y() - rect.y()) / rect.height()); | 827 uvs[5] = ((clip->p3().y() - rect.y()) / rect.height()); |
| 838 uvs[6] = ((clip->p4().x() - rect.x()) / rect.width()); | 828 uvs[6] = ((clip->p4().x() - rect.x()) / rect.width()); |
| 839 uvs[7] = ((clip->p4().y() - rect.y()) / rect.height()); | 829 uvs[7] = ((clip->p4().y() - rect.y()) / rect.height()); |
| 840 return true; | 830 return true; |
| 841 } | 831 } |
| 842 | 832 |
| 843 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( | 833 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
| 844 DrawingFrame* frame, | |
| 845 const RenderPassDrawQuad* quad, | 834 const RenderPassDrawQuad* quad, |
| 846 const gfx::Transform& contents_device_transform, | 835 const gfx::Transform& contents_device_transform, |
| 847 const FilterOperations* filters, | 836 const FilterOperations* filters, |
| 848 const FilterOperations* background_filters, | 837 const FilterOperations* background_filters, |
| 849 const gfx::QuadF* clip_region, | 838 const gfx::QuadF* clip_region, |
| 850 bool use_aa, | 839 bool use_aa, |
| 851 gfx::Rect* unclipped_rect) { | 840 gfx::Rect* unclipped_rect) { |
| 852 gfx::QuadF scaled_region; | 841 gfx::QuadF scaled_region; |
| 853 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { | 842 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { |
| 854 scaled_region = SharedGeometryQuad().BoundingBox(); | 843 scaled_region = SharedGeometryQuad().BoundingBox(); |
| 855 } | 844 } |
| 856 | 845 |
| 857 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( | 846 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( |
| 858 contents_device_transform, scaled_region.BoundingBox())); | 847 contents_device_transform, scaled_region.BoundingBox())); |
| 859 | 848 |
| 860 if (ShouldApplyBackgroundFilters(quad, background_filters)) { | 849 if (ShouldApplyBackgroundFilters(quad, background_filters)) { |
| 861 SkMatrix matrix; | 850 SkMatrix matrix; |
| 862 matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y()); | 851 matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y()); |
| 863 if (FlippedFramebuffer(frame)) { | 852 if (FlippedFramebuffer()) { |
| 864 // TODO(jbroman): This probably isn't the right way to account for this. | 853 // TODO(jbroman): This probably isn't the right way to account for this. |
| 865 // Probably some combination of frame->projection_matrix, | 854 // Probably some combination of current_frame()->projection_matrix, |
| 866 // frame->window_matrix and contents_device_transform? | 855 // current_frame()->window_matrix and contents_device_transform? |
| 867 matrix.postScale(1, -1); | 856 matrix.postScale(1, -1); |
| 868 } | 857 } |
| 869 backdrop_rect = background_filters->MapRectReverse(backdrop_rect, matrix); | 858 backdrop_rect = background_filters->MapRectReverse(backdrop_rect, matrix); |
| 870 } | 859 } |
| 871 | 860 |
| 872 if (!backdrop_rect.IsEmpty() && use_aa) { | 861 if (!backdrop_rect.IsEmpty() && use_aa) { |
| 873 const int kOutsetForAntialiasing = 1; | 862 const int kOutsetForAntialiasing = 1; |
| 874 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); | 863 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); |
| 875 } | 864 } |
| 876 | 865 |
| 877 if (filters) { | 866 if (filters) { |
| 878 DCHECK(!filters->IsEmpty()); | 867 DCHECK(!filters->IsEmpty()); |
| 879 // If we have filters, grab an extra one-pixel border around the | 868 // If we have filters, grab an extra one-pixel border around the |
| 880 // background, so texture edge clamping gives us a transparent border | 869 // background, so texture edge clamping gives us a transparent border |
| 881 // in case the filter expands the result. | 870 // in case the filter expands the result. |
| 882 backdrop_rect.Inset(-1, -1, -1, -1); | 871 backdrop_rect.Inset(-1, -1, -1, -1); |
| 883 } | 872 } |
| 884 | 873 |
| 885 *unclipped_rect = backdrop_rect; | 874 *unclipped_rect = backdrop_rect; |
| 886 backdrop_rect.Intersect(MoveFromDrawToWindowSpace( | 875 backdrop_rect.Intersect(MoveFromDrawToWindowSpace( |
| 887 frame, frame->current_render_pass->output_rect)); | 876 current_frame()->current_render_pass->output_rect)); |
| 888 return backdrop_rect; | 877 return backdrop_rect; |
| 889 } | 878 } |
| 890 | 879 |
| 891 std::unique_ptr<ScopedResource> GLRenderer::GetBackdropTexture( | 880 std::unique_ptr<ScopedResource> GLRenderer::GetBackdropTexture( |
| 892 DrawingFrame* frame, | |
| 893 const gfx::Rect& bounding_rect) { | 881 const gfx::Rect& bounding_rect) { |
| 894 std::unique_ptr<ScopedResource> device_background_texture = | 882 std::unique_ptr<ScopedResource> device_background_texture = |
| 895 ScopedResource::Create(resource_provider_); | 883 ScopedResource::Create(resource_provider_); |
| 896 // CopyTexImage2D fails when called on a texture having immutable storage. | 884 // CopyTexImage2D fails when called on a texture having immutable storage. |
| 897 device_background_texture->Allocate( | 885 device_background_texture->Allocate( |
| 898 bounding_rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, | 886 bounding_rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, |
| 899 BackbufferFormat(), frame->device_color_space); | 887 BackbufferFormat(), current_frame()->device_color_space); |
| 900 { | 888 { |
| 901 ResourceProvider::ScopedWriteLockGL lock( | 889 ResourceProvider::ScopedWriteLockGL lock( |
| 902 resource_provider_, device_background_texture->id(), false); | 890 resource_provider_, device_background_texture->id(), false); |
| 903 GetFramebufferTexture(lock.texture_id(), bounding_rect); | 891 GetFramebufferTexture(lock.texture_id(), bounding_rect); |
| 904 } | 892 } |
| 905 return device_background_texture; | 893 return device_background_texture; |
| 906 } | 894 } |
| 907 | 895 |
| 908 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( | 896 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( |
| 909 const RenderPassDrawQuad* quad, | 897 const RenderPassDrawQuad* quad, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 return nullptr; | 1016 return nullptr; |
| 1029 #if defined(OS_MACOSX) | 1017 #if defined(OS_MACOSX) |
| 1030 // On Macs, this path can sometimes lead to all black output. | 1018 // On Macs, this path can sometimes lead to all black output. |
| 1031 // TODO(enne): investigate this and remove this hack. | 1019 // TODO(enne): investigate this and remove this hack. |
| 1032 return nullptr; | 1020 return nullptr; |
| 1033 #endif | 1021 #endif |
| 1034 | 1022 |
| 1035 return tile_quad; | 1023 return tile_quad; |
| 1036 } | 1024 } |
| 1037 | 1025 |
| 1038 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 1026 void GLRenderer::DrawRenderPassQuad(const RenderPassDrawQuad* quad, |
| 1039 const RenderPassDrawQuad* quad, | |
| 1040 const gfx::QuadF* clip_region) { | 1027 const gfx::QuadF* clip_region) { |
| 1041 auto bypass = render_pass_bypass_quads_.find(quad->render_pass_id); | 1028 auto bypass = render_pass_bypass_quads_.find(quad->render_pass_id); |
| 1042 DrawRenderPassDrawQuadParams params; | 1029 DrawRenderPassDrawQuadParams params; |
| 1043 params.quad = quad; | 1030 params.quad = quad; |
| 1044 params.frame = frame; | |
| 1045 params.clip_region = clip_region; | 1031 params.clip_region = clip_region; |
| 1046 params.window_matrix = frame->window_matrix; | 1032 params.window_matrix = current_frame()->window_matrix; |
| 1047 params.projection_matrix = frame->projection_matrix; | 1033 params.projection_matrix = current_frame()->projection_matrix; |
| 1048 if (bypass != render_pass_bypass_quads_.end()) { | 1034 if (bypass != render_pass_bypass_quads_.end()) { |
| 1049 TileDrawQuad* tile_quad = &bypass->second; | 1035 TileDrawQuad* tile_quad = &bypass->second; |
| 1050 // RGBA_8888 here is arbitrary and unused. | 1036 // RGBA_8888 here is arbitrary and unused. |
| 1051 Resource tile_resource(tile_quad->resource_id(), tile_quad->texture_size, | 1037 Resource tile_resource(tile_quad->resource_id(), tile_quad->texture_size, |
| 1052 ResourceFormat::RGBA_8888, | 1038 ResourceFormat::RGBA_8888, |
| 1053 frame->device_color_space); | 1039 current_frame()->device_color_space); |
| 1054 // The projection matrix used by GLRenderer has a flip. As tile texture | 1040 // The projection matrix used by GLRenderer has a flip. As tile texture |
| 1055 // inputs are oriented opposite to framebuffer outputs, don't flip via | 1041 // inputs are oriented opposite to framebuffer outputs, don't flip via |
| 1056 // texture coords and let the projection matrix naturallyd o it. | 1042 // texture coords and let the projection matrix naturallyd o it. |
| 1057 params.flip_texture = false; | 1043 params.flip_texture = false; |
| 1058 params.contents_texture = &tile_resource; | 1044 params.contents_texture = &tile_resource; |
| 1059 DrawRenderPassQuadInternal(¶ms); | 1045 DrawRenderPassQuadInternal(¶ms); |
| 1060 } else { | 1046 } else { |
| 1061 ScopedResource* contents_texture = | 1047 ScopedResource* contents_texture = |
| 1062 render_pass_textures_[quad->render_pass_id].get(); | 1048 render_pass_textures_[quad->render_pass_id].get(); |
| 1063 DCHECK(contents_texture); | 1049 DCHECK(contents_texture); |
| 1064 DCHECK(contents_texture->id()); | 1050 DCHECK(contents_texture->id()); |
| 1065 // See above comments about texture flipping. When the input is a | 1051 // See above comments about texture flipping. When the input is a |
| 1066 // render pass, it needs to an extra flip to be oriented correctly. | 1052 // render pass, it needs to an extra flip to be oriented correctly. |
| 1067 params.flip_texture = true; | 1053 params.flip_texture = true; |
| 1068 params.contents_texture = contents_texture; | 1054 params.contents_texture = contents_texture; |
| 1069 DrawRenderPassQuadInternal(¶ms); | 1055 DrawRenderPassQuadInternal(¶ms); |
| 1070 } | 1056 } |
| 1071 } | 1057 } |
| 1072 | 1058 |
| 1073 void GLRenderer::DrawRenderPassQuadInternal( | 1059 void GLRenderer::DrawRenderPassQuadInternal( |
| 1074 DrawRenderPassDrawQuadParams* params) { | 1060 DrawRenderPassDrawQuadParams* params) { |
| 1075 params->quad_to_target_transform = | 1061 params->quad_to_target_transform = |
| 1076 params->quad->shared_quad_state->quad_to_target_transform; | 1062 params->quad->shared_quad_state->quad_to_target_transform; |
| 1077 if (!InitializeRPDQParameters(params)) | 1063 if (!InitializeRPDQParameters(params)) |
| 1078 return; | 1064 return; |
| 1079 UpdateRPDQShadersForBlending(params); | 1065 UpdateRPDQShadersForBlending(params); |
| 1080 if (!UpdateRPDQWithSkiaFilters(params)) | 1066 if (!UpdateRPDQWithSkiaFilters(params)) |
| 1081 return; | 1067 return; |
| 1082 UseRenderPass(params->frame, params->frame->current_render_pass); | 1068 UseRenderPass(current_frame()->current_render_pass); |
| 1083 SetViewport(); | 1069 SetViewport(); |
| 1084 UpdateRPDQTexturesForSampling(params); | 1070 UpdateRPDQTexturesForSampling(params); |
| 1085 UpdateRPDQBlendMode(params); | 1071 UpdateRPDQBlendMode(params); |
| 1086 ChooseRPDQProgram(params); | 1072 ChooseRPDQProgram(params); |
| 1087 UpdateRPDQUniforms(params); | 1073 UpdateRPDQUniforms(params); |
| 1088 DrawRPDQ(*params); | 1074 DrawRPDQ(*params); |
| 1089 } | 1075 } |
| 1090 | 1076 |
| 1091 bool GLRenderer::InitializeRPDQParameters( | 1077 bool GLRenderer::InitializeRPDQParameters( |
| 1092 DrawRenderPassDrawQuadParams* params) { | 1078 DrawRenderPassDrawQuadParams* params) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 void GLRenderer::UpdateRPDQShadersForBlending( | 1122 void GLRenderer::UpdateRPDQShadersForBlending( |
| 1137 DrawRenderPassDrawQuadParams* params) { | 1123 DrawRenderPassDrawQuadParams* params) { |
| 1138 const RenderPassDrawQuad* quad = params->quad; | 1124 const RenderPassDrawQuad* quad = params->quad; |
| 1139 SkBlendMode blend_mode = quad->shared_quad_state->blend_mode; | 1125 SkBlendMode blend_mode = quad->shared_quad_state->blend_mode; |
| 1140 params->use_shaders_for_blending = | 1126 params->use_shaders_for_blending = |
| 1141 !CanApplyBlendModeUsingBlendFunc(blend_mode) || | 1127 !CanApplyBlendModeUsingBlendFunc(blend_mode) || |
| 1142 ShouldApplyBackgroundFilters(quad, params->background_filters) || | 1128 ShouldApplyBackgroundFilters(quad, params->background_filters) || |
| 1143 settings_->force_blending_with_shaders; | 1129 settings_->force_blending_with_shaders; |
| 1144 | 1130 |
| 1145 if (params->use_shaders_for_blending) { | 1131 if (params->use_shaders_for_blending) { |
| 1146 DCHECK(params->frame); | |
| 1147 // Compute a bounding box around the pixels that will be visible through | 1132 // Compute a bounding box around the pixels that will be visible through |
| 1148 // the quad. | 1133 // the quad. |
| 1149 gfx::Rect unclipped_rect; | 1134 gfx::Rect unclipped_rect; |
| 1150 params->background_rect = GetBackdropBoundingBoxForRenderPassQuad( | 1135 params->background_rect = GetBackdropBoundingBoxForRenderPassQuad( |
| 1151 params->frame, quad, params->contents_device_transform, params->filters, | 1136 quad, params->contents_device_transform, params->filters, |
| 1152 params->background_filters, params->clip_region, params->use_aa, | 1137 params->background_filters, params->clip_region, params->use_aa, |
| 1153 &unclipped_rect); | 1138 &unclipped_rect); |
| 1154 | 1139 |
| 1155 if (!params->background_rect.IsEmpty()) { | 1140 if (!params->background_rect.IsEmpty()) { |
| 1156 // The pixels from the filtered background should completely replace the | 1141 // The pixels from the filtered background should completely replace the |
| 1157 // current pixel values. | 1142 // current pixel values. |
| 1158 if (blend_enabled()) | 1143 if (blend_enabled()) |
| 1159 SetBlendEnabled(false); | 1144 SetBlendEnabled(false); |
| 1160 | 1145 |
| 1161 // Read the pixels in the bounding box into a buffer R. | 1146 // Read the pixels in the bounding box into a buffer R. |
| 1162 // This function allocates a texture, which should contribute to the | 1147 // This function allocates a texture, which should contribute to the |
| 1163 // amount of memory used by render surfaces: | 1148 // amount of memory used by render surfaces: |
| 1164 // LayerTreeHost::CalculateMemoryForRenderSurfaces. | 1149 // LayerTreeHost::CalculateMemoryForRenderSurfaces. |
| 1165 params->background_texture = | 1150 params->background_texture = GetBackdropTexture(params->background_rect); |
| 1166 GetBackdropTexture(params->frame, params->background_rect); | |
| 1167 | 1151 |
| 1168 if (ShouldApplyBackgroundFilters(quad, params->background_filters) && | 1152 if (ShouldApplyBackgroundFilters(quad, params->background_filters) && |
| 1169 params->background_texture) { | 1153 params->background_texture) { |
| 1170 // Apply the background filters to R, so that it is applied in the | 1154 // Apply the background filters to R, so that it is applied in the |
| 1171 // pixels' coordinate space. | 1155 // pixels' coordinate space. |
| 1172 params->background_image = ApplyBackgroundFilters( | 1156 params->background_image = ApplyBackgroundFilters( |
| 1173 quad, *params->background_filters, params->background_texture.get(), | 1157 quad, *params->background_filters, params->background_texture.get(), |
| 1174 gfx::RectF(params->background_rect), gfx::RectF(unclipped_rect)); | 1158 gfx::RectF(params->background_rect), gfx::RectF(unclipped_rect)); |
| 1175 if (params->background_image) { | 1159 if (params->background_image) { |
| 1176 params->background_image_id = | 1160 params->background_image_id = |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 device_quad = GetDeviceQuadWithAntialiasingOnExteriorEdges( | 1698 device_quad = GetDeviceQuadWithAntialiasingOnExteriorEdges( |
| 1715 device_layer_edges, device_transform, tile_quad, local_clip_region, | 1699 device_layer_edges, device_transform, tile_quad, local_clip_region, |
| 1716 quad); | 1700 quad); |
| 1717 } else { | 1701 } else { |
| 1718 device_quad = device_layer_edges.ToQuadF(); | 1702 device_quad = device_layer_edges.ToQuadF(); |
| 1719 } | 1703 } |
| 1720 | 1704 |
| 1721 *local_quad = MapQuadToLocalSpace(device_transform, device_quad); | 1705 *local_quad = MapQuadToLocalSpace(device_transform, device_quad); |
| 1722 } | 1706 } |
| 1723 | 1707 |
| 1724 void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, | 1708 void GLRenderer::DrawSolidColorQuad(const SolidColorDrawQuad* quad, |
| 1725 const SolidColorDrawQuad* quad, | |
| 1726 const gfx::QuadF* clip_region) { | 1709 const gfx::QuadF* clip_region) { |
| 1727 gfx::Rect tile_rect = quad->visible_rect; | 1710 gfx::Rect tile_rect = quad->visible_rect; |
| 1728 | 1711 |
| 1729 SkColor color = quad->color; | 1712 SkColor color = quad->color; |
| 1730 float opacity = quad->shared_quad_state->opacity; | 1713 float opacity = quad->shared_quad_state->opacity; |
| 1731 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; | 1714 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; |
| 1732 | 1715 |
| 1733 // Early out if alpha is small enough that quad doesn't contribute to output. | 1716 // Early out if alpha is small enough that quad doesn't contribute to output. |
| 1734 if (alpha < std::numeric_limits<float>::epsilon() && | 1717 if (alpha < std::numeric_limits<float>::epsilon() && |
| 1735 quad->ShouldDrawWithBlending()) | 1718 quad->ShouldDrawWithBlending()) |
| 1736 return; | 1719 return; |
| 1737 | 1720 |
| 1738 gfx::Transform device_transform = | 1721 gfx::Transform device_transform = |
| 1739 frame->window_matrix * frame->projection_matrix * | 1722 current_frame()->window_matrix * current_frame()->projection_matrix * |
| 1740 quad->shared_quad_state->quad_to_target_transform; | 1723 quad->shared_quad_state->quad_to_target_transform; |
| 1741 device_transform.FlattenTo2d(); | 1724 device_transform.FlattenTo2d(); |
| 1742 if (!device_transform.IsInvertible()) | 1725 if (!device_transform.IsInvertible()) |
| 1743 return; | 1726 return; |
| 1744 | 1727 |
| 1745 auto local_quad = gfx::QuadF(gfx::RectF(tile_rect)); | 1728 auto local_quad = gfx::QuadF(gfx::RectF(tile_rect)); |
| 1746 | 1729 |
| 1747 gfx::QuadF device_layer_quad; | 1730 gfx::QuadF device_layer_quad; |
| 1748 bool use_aa = false; | 1731 bool use_aa = false; |
| 1749 bool allow_aa = settings_->allow_antialiasing && | 1732 bool allow_aa = settings_->allow_antialiasing && |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1787 SetShaderQuadF(local_quad); | 1770 SetShaderQuadF(local_quad); |
| 1788 | 1771 |
| 1789 // The transform and vertex data are used to figure out the extents that the | 1772 // The transform and vertex data are used to figure out the extents that the |
| 1790 // un-antialiased quad should have and which vertex this is and the float | 1773 // un-antialiased quad should have and which vertex this is and the float |
| 1791 // quad passed in via uniform is the actual geometry that gets used to draw | 1774 // quad passed in via uniform is the actual geometry that gets used to draw |
| 1792 // it. This is why this centered rect is used and not the original | 1775 // it. This is why this centered rect is used and not the original |
| 1793 // quad_rect. | 1776 // quad_rect. |
| 1794 gfx::RectF centered_rect( | 1777 gfx::RectF centered_rect( |
| 1795 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), | 1778 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), |
| 1796 gfx::SizeF(tile_rect.size())); | 1779 gfx::SizeF(tile_rect.size())); |
| 1797 DrawQuadGeometry(frame->projection_matrix, | 1780 DrawQuadGeometry(current_frame()->projection_matrix, |
| 1798 quad->shared_quad_state->quad_to_target_transform, | 1781 quad->shared_quad_state->quad_to_target_transform, |
| 1799 centered_rect); | 1782 centered_rect); |
| 1800 } else { | 1783 } else { |
| 1801 PrepareGeometry(SHARED_BINDING); | 1784 PrepareGeometry(SHARED_BINDING); |
| 1802 SetShaderQuadF(local_quad); | 1785 SetShaderQuadF(local_quad); |
| 1803 SetShaderMatrix(frame->projection_matrix * | 1786 SetShaderMatrix(current_frame()->projection_matrix * |
| 1804 quad->shared_quad_state->quad_to_target_transform); | 1787 quad->shared_quad_state->quad_to_target_transform); |
| 1805 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 1788 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
| 1806 } | 1789 } |
| 1807 } | 1790 } |
| 1808 | 1791 |
| 1809 void GLRenderer::DrawTileQuad(const DrawingFrame* frame, | 1792 void GLRenderer::DrawTileQuad(const TileDrawQuad* quad, |
| 1810 const TileDrawQuad* quad, | |
| 1811 const gfx::QuadF* clip_region) { | 1793 const gfx::QuadF* clip_region) { |
| 1812 DrawContentQuad(frame, quad, quad->resource_id(), clip_region); | 1794 DrawContentQuad(quad, quad->resource_id(), clip_region); |
| 1813 } | 1795 } |
| 1814 | 1796 |
| 1815 void GLRenderer::DrawContentQuad(const DrawingFrame* frame, | 1797 void GLRenderer::DrawContentQuad(const ContentDrawQuadBase* quad, |
| 1816 const ContentDrawQuadBase* quad, | |
| 1817 ResourceId resource_id, | 1798 ResourceId resource_id, |
| 1818 const gfx::QuadF* clip_region) { | 1799 const gfx::QuadF* clip_region) { |
| 1819 gfx::Transform device_transform = | 1800 gfx::Transform device_transform = |
| 1820 frame->window_matrix * frame->projection_matrix * | 1801 current_frame()->window_matrix * current_frame()->projection_matrix * |
| 1821 quad->shared_quad_state->quad_to_target_transform; | 1802 quad->shared_quad_state->quad_to_target_transform; |
| 1822 device_transform.FlattenTo2d(); | 1803 device_transform.FlattenTo2d(); |
| 1823 | 1804 |
| 1824 gfx::QuadF device_layer_quad; | 1805 gfx::QuadF device_layer_quad; |
| 1825 bool use_aa = false; | 1806 bool use_aa = false; |
| 1826 bool allow_aa = settings_->allow_antialiasing && quad->IsEdge(); | 1807 bool allow_aa = settings_->allow_antialiasing && quad->IsEdge(); |
| 1827 if (allow_aa) { | 1808 if (allow_aa) { |
| 1828 bool clipped = false; | 1809 bool clipped = false; |
| 1829 bool force_aa = false; | 1810 bool force_aa = false; |
| 1830 device_layer_quad = MathUtil::MapQuad( | 1811 device_layer_quad = MathUtil::MapQuad( |
| 1831 device_transform, | 1812 device_transform, |
| 1832 gfx::QuadF( | 1813 gfx::QuadF( |
| 1833 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), | 1814 gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), |
| 1834 &clipped); | 1815 &clipped); |
| 1835 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); | 1816 use_aa = ShouldAntialiasQuad(device_layer_quad, clipped, force_aa); |
| 1836 } | 1817 } |
| 1837 | 1818 |
| 1838 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA | 1819 // TODO(timav): simplify coordinate transformations in DrawContentQuadAA |
| 1839 // similar to the way DrawContentQuadNoAA works and then consider | 1820 // similar to the way DrawContentQuadNoAA works and then consider |
| 1840 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. | 1821 // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. |
| 1841 if (use_aa) | 1822 if (use_aa) |
| 1842 DrawContentQuadAA(frame, quad, resource_id, device_transform, | 1823 DrawContentQuadAA(quad, resource_id, device_transform, device_layer_quad, |
| 1843 device_layer_quad, clip_region); | 1824 clip_region); |
| 1844 else | 1825 else |
| 1845 DrawContentQuadNoAA(frame, quad, resource_id, clip_region); | 1826 DrawContentQuadNoAA(quad, resource_id, clip_region); |
| 1846 } | 1827 } |
| 1847 | 1828 |
| 1848 void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, | 1829 void GLRenderer::DrawContentQuadAA(const ContentDrawQuadBase* quad, |
| 1849 const ContentDrawQuadBase* quad, | |
| 1850 ResourceId resource_id, | 1830 ResourceId resource_id, |
| 1851 const gfx::Transform& device_transform, | 1831 const gfx::Transform& device_transform, |
| 1852 const gfx::QuadF& aa_quad, | 1832 const gfx::QuadF& aa_quad, |
| 1853 const gfx::QuadF* clip_region) { | 1833 const gfx::QuadF* clip_region) { |
| 1854 if (!device_transform.IsInvertible()) | 1834 if (!device_transform.IsInvertible()) |
| 1855 return; | 1835 return; |
| 1856 | 1836 |
| 1857 gfx::Rect tile_rect = quad->visible_rect; | 1837 gfx::Rect tile_rect = quad->visible_rect; |
| 1858 | 1838 |
| 1859 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( | 1839 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1942 SetShaderOpacity(quad); | 1922 SetShaderOpacity(quad); |
| 1943 SetShaderQuadF(local_quad); | 1923 SetShaderQuadF(local_quad); |
| 1944 | 1924 |
| 1945 // The transform and vertex data are used to figure out the extents that the | 1925 // The transform and vertex data are used to figure out the extents that the |
| 1946 // un-antialiased quad should have and which vertex this is and the float | 1926 // un-antialiased quad should have and which vertex this is and the float |
| 1947 // quad passed in via uniform is the actual geometry that gets used to draw | 1927 // quad passed in via uniform is the actual geometry that gets used to draw |
| 1948 // it. This is why this centered rect is used and not the original quad_rect. | 1928 // it. This is why this centered rect is used and not the original quad_rect. |
| 1949 gfx::RectF centered_rect( | 1929 gfx::RectF centered_rect( |
| 1950 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), | 1930 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), |
| 1951 gfx::SizeF(tile_rect.size())); | 1931 gfx::SizeF(tile_rect.size())); |
| 1952 DrawQuadGeometry(frame->projection_matrix, | 1932 DrawQuadGeometry(current_frame()->projection_matrix, |
| 1953 quad->shared_quad_state->quad_to_target_transform, | 1933 quad->shared_quad_state->quad_to_target_transform, |
| 1954 centered_rect); | 1934 centered_rect); |
| 1955 } | 1935 } |
| 1956 | 1936 |
| 1957 void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, | 1937 void GLRenderer::DrawContentQuadNoAA(const ContentDrawQuadBase* quad, |
| 1958 const ContentDrawQuadBase* quad, | |
| 1959 ResourceId resource_id, | 1938 ResourceId resource_id, |
| 1960 const gfx::QuadF* clip_region) { | 1939 const gfx::QuadF* clip_region) { |
| 1961 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( | 1940 gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( |
| 1962 quad->tex_coord_rect, gfx::RectF(quad->rect), | 1941 quad->tex_coord_rect, gfx::RectF(quad->rect), |
| 1963 gfx::RectF(quad->visible_rect)); | 1942 gfx::RectF(quad->visible_rect)); |
| 1964 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); | 1943 float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); |
| 1965 float tex_to_geom_scale_y = | 1944 float tex_to_geom_scale_y = |
| 1966 quad->rect.height() / quad->tex_coord_rect.height(); | 1945 quad->rect.height() / quad->tex_coord_rect.height(); |
| 1967 | 1946 |
| 1968 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); | 1947 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 } else { | 2016 } else { |
| 2038 PrepareGeometry(SHARED_BINDING); | 2017 PrepareGeometry(SHARED_BINDING); |
| 2039 } | 2018 } |
| 2040 float gl_quad[8] = { | 2019 float gl_quad[8] = { |
| 2041 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(), | 2020 tile_quad.p4().x(), tile_quad.p4().y(), tile_quad.p1().x(), |
| 2042 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(), | 2021 tile_quad.p1().y(), tile_quad.p2().x(), tile_quad.p2().y(), |
| 2043 tile_quad.p3().x(), tile_quad.p3().y(), | 2022 tile_quad.p3().x(), tile_quad.p3().y(), |
| 2044 }; | 2023 }; |
| 2045 gl_->Uniform2fv(program->quad_location(), 4, gl_quad); | 2024 gl_->Uniform2fv(program->quad_location(), 4, gl_quad); |
| 2046 | 2025 |
| 2047 SetShaderMatrix(frame->projection_matrix * | 2026 SetShaderMatrix(current_frame()->projection_matrix * |
| 2048 quad->shared_quad_state->quad_to_target_transform); | 2027 quad->shared_quad_state->quad_to_target_transform); |
| 2049 | 2028 |
| 2050 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 2029 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
| 2051 } | 2030 } |
| 2052 | 2031 |
| 2053 // TODO(ccameron): This has been replicated in ui/gfx/color_transform.cc. Delete | 2032 // TODO(ccameron): This has been replicated in ui/gfx/color_transform.cc. Delete |
| 2054 // one of the instances. | 2033 // one of the instances. |
| 2055 void ComputeYUVToRGBMatrices(YUVVideoDrawQuad::ColorSpace color_space, | 2034 void ComputeYUVToRGBMatrices(YUVVideoDrawQuad::ColorSpace color_space, |
| 2056 uint32_t bits_per_channel, | 2035 uint32_t bits_per_channel, |
| 2057 float resource_multiplier, | 2036 float resource_multiplier, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2100 SkMatrix44 rgb_to_yuv; | 2079 SkMatrix44 rgb_to_yuv; |
| 2101 gfx_color_space.GetTransferMatrix(&rgb_to_yuv); | 2080 gfx_color_space.GetTransferMatrix(&rgb_to_yuv); |
| 2102 SkMatrix44 yuv_to_rgb; | 2081 SkMatrix44 yuv_to_rgb; |
| 2103 rgb_to_yuv.invert(&yuv_to_rgb); | 2082 rgb_to_yuv.invert(&yuv_to_rgb); |
| 2104 full_transform.postConcat(yuv_to_rgb); | 2083 full_transform.postConcat(yuv_to_rgb); |
| 2105 } | 2084 } |
| 2106 | 2085 |
| 2107 full_transform.asColMajorf(yuv_to_rgb_matrix); | 2086 full_transform.asColMajorf(yuv_to_rgb_matrix); |
| 2108 } | 2087 } |
| 2109 | 2088 |
| 2110 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, | 2089 void GLRenderer::DrawYUVVideoQuad(const YUVVideoDrawQuad* quad, |
| 2111 const YUVVideoDrawQuad* quad, | |
| 2112 const gfx::QuadF* clip_region) { | 2090 const gfx::QuadF* clip_region) { |
| 2113 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2091 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2114 | 2092 |
| 2115 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2093 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2116 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2094 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2117 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2095 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2118 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() | 2096 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() |
| 2119 ? YUV_HAS_ALPHA_TEXTURE | 2097 ? YUV_HAS_ALPHA_TEXTURE |
| 2120 : YUV_NO_ALPHA_TEXTURE; | 2098 : YUV_NO_ALPHA_TEXTURE; |
| 2121 UVTextureMode uv_texture_mode = | 2099 UVTextureMode uv_texture_mode = |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2213 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { | 2191 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { |
| 2214 gl_->Uniform1i(program->uv_texture_location(), 2); | 2192 gl_->Uniform1i(program->uv_texture_location(), 2); |
| 2215 } else { | 2193 } else { |
| 2216 gl_->Uniform1i(program->u_texture_location(), 2); | 2194 gl_->Uniform1i(program->u_texture_location(), 2); |
| 2217 gl_->Uniform1i(program->v_texture_location(), 3); | 2195 gl_->Uniform1i(program->v_texture_location(), 3); |
| 2218 } | 2196 } |
| 2219 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) | 2197 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) |
| 2220 gl_->Uniform1i(program->a_texture_location(), 4); | 2198 gl_->Uniform1i(program->a_texture_location(), 4); |
| 2221 | 2199 |
| 2222 if (color_conversion_mode == COLOR_CONVERSION_MODE_LUT) { | 2200 if (color_conversion_mode == COLOR_CONVERSION_MODE_LUT) { |
| 2223 ColorLUTCache::LUT lut = color_lut_cache_.GetLUT(quad->video_color_space, | 2201 ColorLUTCache::LUT lut = color_lut_cache_.GetLUT( |
| 2224 frame->device_color_space); | 2202 quad->video_color_space, current_frame()->device_color_space); |
| 2225 gl_->ActiveTexture(GL_TEXTURE5); | 2203 gl_->ActiveTexture(GL_TEXTURE5); |
| 2226 gl_->BindTexture(GL_TEXTURE_2D, lut.texture); | 2204 gl_->BindTexture(GL_TEXTURE_2D, lut.texture); |
| 2227 gl_->Uniform1i(program->lut_texture_location(), 5); | 2205 gl_->Uniform1i(program->lut_texture_location(), 5); |
| 2228 gl_->Uniform1f(program->lut_size_location(), lut.size); | 2206 gl_->Uniform1f(program->lut_size_location(), lut.size); |
| 2229 gl_->ActiveTexture(GL_TEXTURE0); | 2207 gl_->ActiveTexture(GL_TEXTURE0); |
| 2230 } | 2208 } |
| 2231 DCHECK_NE(program->yuv_and_resource_matrix_location(), -1); | 2209 DCHECK_NE(program->yuv_and_resource_matrix_location(), -1); |
| 2232 float yuv_to_rgb_matrix[16] = {0}; | 2210 float yuv_to_rgb_matrix[16] = {0}; |
| 2233 ComputeYUVToRGBMatrices(quad->color_space, quad->bits_per_channel, | 2211 ComputeYUVToRGBMatrices(quad->color_space, quad->bits_per_channel, |
| 2234 quad->resource_multiplier, quad->resource_offset, | 2212 quad->resource_multiplier, quad->resource_offset, |
| 2235 color_conversion_mode, yuv_to_rgb_matrix); | 2213 color_conversion_mode, yuv_to_rgb_matrix); |
| 2236 gl_->UniformMatrix4fv(program->yuv_and_resource_matrix_location(), 1, 0, | 2214 gl_->UniformMatrix4fv(program->yuv_and_resource_matrix_location(), 1, 0, |
| 2237 yuv_to_rgb_matrix); | 2215 yuv_to_rgb_matrix); |
| 2238 | 2216 |
| 2239 // The transform and vertex data are used to figure out the extents that the | 2217 // The transform and vertex data are used to figure out the extents that the |
| 2240 // un-antialiased quad should have and which vertex this is and the float | 2218 // un-antialiased quad should have and which vertex this is and the float |
| 2241 // quad passed in via uniform is the actual geometry that gets used to draw | 2219 // quad passed in via uniform is the actual geometry that gets used to draw |
| 2242 // it. This is why this centered rect is used and not the original quad_rect. | 2220 // it. This is why this centered rect is used and not the original quad_rect. |
| 2243 auto tile_rect = gfx::RectF(quad->rect); | 2221 auto tile_rect = gfx::RectF(quad->rect); |
| 2244 | 2222 |
| 2245 SetShaderOpacity(quad); | 2223 SetShaderOpacity(quad); |
| 2246 if (!clip_region) { | 2224 if (!clip_region) { |
| 2247 DrawQuadGeometry(frame->projection_matrix, | 2225 DrawQuadGeometry(current_frame()->projection_matrix, |
| 2248 quad->shared_quad_state->quad_to_target_transform, | 2226 quad->shared_quad_state->quad_to_target_transform, |
| 2249 tile_rect); | 2227 tile_rect); |
| 2250 } else { | 2228 } else { |
| 2251 float uvs[8] = {0}; | 2229 float uvs[8] = {0}; |
| 2252 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2230 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2253 gfx::QuadF region_quad = *clip_region; | 2231 gfx::QuadF region_quad = *clip_region; |
| 2254 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 2232 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 2255 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2233 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2256 DrawQuadGeometryClippedByQuadF( | 2234 DrawQuadGeometryClippedByQuadF( |
| 2257 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, | 2235 quad->shared_quad_state->quad_to_target_transform, tile_rect, |
| 2258 region_quad, uvs); | 2236 region_quad, uvs); |
| 2259 } | 2237 } |
| 2260 } | 2238 } |
| 2261 | 2239 |
| 2262 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 2240 void GLRenderer::DrawStreamVideoQuad(const StreamVideoDrawQuad* quad, |
| 2263 const StreamVideoDrawQuad* quad, | |
| 2264 const gfx::QuadF* clip_region) { | 2241 const gfx::QuadF* clip_region) { |
| 2265 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2242 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2266 | 2243 |
| 2267 DCHECK(output_surface_->context_provider() | 2244 DCHECK(output_surface_->context_provider() |
| 2268 ->ContextCapabilities() | 2245 ->ContextCapabilities() |
| 2269 .egl_image_external); | 2246 .egl_image_external); |
| 2270 | 2247 |
| 2271 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2248 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2272 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2249 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2273 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2250 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2274 | 2251 |
| 2275 const Program* program = | 2252 const Program* program = |
| 2276 GetProgram(ProgramKey::VideoStream(tex_coord_precision)); | 2253 GetProgram(ProgramKey::VideoStream(tex_coord_precision)); |
| 2277 SetUseProgram(program); | 2254 SetUseProgram(program); |
| 2278 | 2255 |
| 2279 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 2256 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2280 quad->resource_id()); | 2257 quad->resource_id()); |
| 2281 | 2258 |
| 2282 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2259 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2283 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); | 2260 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); |
| 2284 | 2261 |
| 2285 static float gl_matrix[16]; | 2262 static float gl_matrix[16]; |
| 2286 ToGLMatrix(&gl_matrix[0], quad->matrix); | 2263 ToGLMatrix(&gl_matrix[0], quad->matrix); |
| 2287 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( | 2264 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( |
| 2288 program->tex_matrix_location(), false, gl_matrix); | 2265 program->tex_matrix_location(), false, gl_matrix); |
| 2289 | 2266 |
| 2290 SetShaderOpacity(quad); | 2267 SetShaderOpacity(quad); |
| 2291 if (!clip_region) { | 2268 if (!clip_region) { |
| 2292 DrawQuadGeometry(frame->projection_matrix, | 2269 DrawQuadGeometry(current_frame()->projection_matrix, |
| 2293 quad->shared_quad_state->quad_to_target_transform, | 2270 quad->shared_quad_state->quad_to_target_transform, |
| 2294 gfx::RectF(quad->rect)); | 2271 gfx::RectF(quad->rect)); |
| 2295 } else { | 2272 } else { |
| 2296 gfx::QuadF region_quad(*clip_region); | 2273 gfx::QuadF region_quad(*clip_region); |
| 2297 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); | 2274 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); |
| 2298 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2275 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2299 float uvs[8] = {0}; | 2276 float uvs[8] = {0}; |
| 2300 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2277 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2301 DrawQuadGeometryClippedByQuadF( | 2278 DrawQuadGeometryClippedByQuadF( |
| 2302 frame, quad->shared_quad_state->quad_to_target_transform, | 2279 quad->shared_quad_state->quad_to_target_transform, |
| 2303 gfx::RectF(quad->rect), region_quad, uvs); | 2280 gfx::RectF(quad->rect), region_quad, uvs); |
| 2304 } | 2281 } |
| 2305 } | 2282 } |
| 2306 | 2283 |
| 2307 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { | 2284 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { |
| 2308 // Check to see if we have anything to draw. | 2285 // Check to see if we have anything to draw. |
| 2309 if (!draw_cache_.program) | 2286 if (!draw_cache_.program) |
| 2310 return; | 2287 return; |
| 2311 | 2288 |
| 2312 PrepareGeometry(flush_binding); | 2289 PrepareGeometry(flush_binding); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2389 draw_cache_.vertex_opacity_data.resize(0); | 2366 draw_cache_.vertex_opacity_data.resize(0); |
| 2390 draw_cache_.matrix_data.resize(0); | 2367 draw_cache_.matrix_data.resize(0); |
| 2391 | 2368 |
| 2392 // If we had a clipped binding, prepare the shared binding for the | 2369 // If we had a clipped binding, prepare the shared binding for the |
| 2393 // next inserts. | 2370 // next inserts. |
| 2394 if (flush_binding == CLIPPED_BINDING) { | 2371 if (flush_binding == CLIPPED_BINDING) { |
| 2395 PrepareGeometry(SHARED_BINDING); | 2372 PrepareGeometry(SHARED_BINDING); |
| 2396 } | 2373 } |
| 2397 } | 2374 } |
| 2398 | 2375 |
| 2399 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, | 2376 void GLRenderer::EnqueueTextureQuad(const TextureDrawQuad* quad, |
| 2400 const TextureDrawQuad* quad, | |
| 2401 const gfx::QuadF* clip_region) { | 2377 const gfx::QuadF* clip_region) { |
| 2402 // If we have a clip_region then we have to render the next quad | 2378 // If we have a clip_region then we have to render the next quad |
| 2403 // with dynamic geometry, therefore we must flush all pending | 2379 // with dynamic geometry, therefore we must flush all pending |
| 2404 // texture quads. | 2380 // texture quads. |
| 2405 if (clip_region) { | 2381 if (clip_region) { |
| 2406 // We send in false here because we want to flush what's currently in the | 2382 // We send in false here because we want to flush what's currently in the |
| 2407 // queue using the shared_geometry and not clipped_geometry | 2383 // queue using the shared_geometry and not clipped_geometry |
| 2408 FlushTextureQuadCache(SHARED_BINDING); | 2384 FlushTextureQuadCache(SHARED_BINDING); |
| 2409 } | 2385 } |
| 2410 | 2386 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2456 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); | 2432 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); |
| 2457 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); | 2433 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); |
| 2458 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); | 2434 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); |
| 2459 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); | 2435 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); |
| 2460 | 2436 |
| 2461 // Generate the transform matrix | 2437 // Generate the transform matrix |
| 2462 gfx::Transform quad_rect_matrix; | 2438 gfx::Transform quad_rect_matrix; |
| 2463 QuadRectTransform(&quad_rect_matrix, | 2439 QuadRectTransform(&quad_rect_matrix, |
| 2464 quad->shared_quad_state->quad_to_target_transform, | 2440 quad->shared_quad_state->quad_to_target_transform, |
| 2465 gfx::RectF(quad->rect)); | 2441 gfx::RectF(quad->rect)); |
| 2466 quad_rect_matrix = frame->projection_matrix * quad_rect_matrix; | 2442 quad_rect_matrix = current_frame()->projection_matrix * quad_rect_matrix; |
| 2467 | 2443 |
| 2468 Float16 m; | 2444 Float16 m; |
| 2469 quad_rect_matrix.matrix().asColMajorf(m.data); | 2445 quad_rect_matrix.matrix().asColMajorf(m.data); |
| 2470 draw_cache_.matrix_data.push_back(m); | 2446 draw_cache_.matrix_data.push_back(m); |
| 2471 | 2447 |
| 2472 if (clip_region) { | 2448 if (clip_region) { |
| 2473 gfx::QuadF scaled_region; | 2449 gfx::QuadF scaled_region; |
| 2474 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { | 2450 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { |
| 2475 scaled_region = SharedGeometryQuad().BoundingBox(); | 2451 scaled_region = SharedGeometryQuad().BoundingBox(); |
| 2476 } | 2452 } |
| 2477 // Both the scaled region and the SharedGeomtryQuad are in the space | 2453 // Both the scaled region and the SharedGeomtryQuad are in the space |
| 2478 // -0.5->0.5. We need to move that to the space 0->1. | 2454 // -0.5->0.5. We need to move that to the space 0->1. |
| 2479 float uv[8]; | 2455 float uv[8]; |
| 2480 uv[0] = scaled_region.p1().x() + 0.5f; | 2456 uv[0] = scaled_region.p1().x() + 0.5f; |
| 2481 uv[1] = scaled_region.p1().y() + 0.5f; | 2457 uv[1] = scaled_region.p1().y() + 0.5f; |
| 2482 uv[2] = scaled_region.p2().x() + 0.5f; | 2458 uv[2] = scaled_region.p2().x() + 0.5f; |
| 2483 uv[3] = scaled_region.p2().y() + 0.5f; | 2459 uv[3] = scaled_region.p2().y() + 0.5f; |
| 2484 uv[4] = scaled_region.p3().x() + 0.5f; | 2460 uv[4] = scaled_region.p3().x() + 0.5f; |
| 2485 uv[5] = scaled_region.p3().y() + 0.5f; | 2461 uv[5] = scaled_region.p3().y() + 0.5f; |
| 2486 uv[6] = scaled_region.p4().x() + 0.5f; | 2462 uv[6] = scaled_region.p4().x() + 0.5f; |
| 2487 uv[7] = scaled_region.p4().y() + 0.5f; | 2463 uv[7] = scaled_region.p4().y() + 0.5f; |
| 2488 PrepareGeometry(CLIPPED_BINDING); | 2464 PrepareGeometry(CLIPPED_BINDING); |
| 2489 clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv); | 2465 clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv); |
| 2490 FlushTextureQuadCache(CLIPPED_BINDING); | 2466 FlushTextureQuadCache(CLIPPED_BINDING); |
| 2491 } else if (gl_composited_texture_quad_border_) { | 2467 } else if (gl_composited_texture_quad_border_) { |
| 2492 FlushTextureQuadCache(SHARED_BINDING); | 2468 FlushTextureQuadCache(SHARED_BINDING); |
| 2493 } | 2469 } |
| 2494 } | 2470 } |
| 2495 | 2471 |
| 2496 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 2472 void GLRenderer::FinishDrawingFrame() { |
| 2497 if (use_sync_query_) { | 2473 if (use_sync_query_) { |
| 2498 DCHECK(current_sync_query_); | 2474 DCHECK(current_sync_query_); |
| 2499 current_sync_query_->End(); | 2475 current_sync_query_->End(); |
| 2500 pending_sync_queries_.push_back(std::move(current_sync_query_)); | 2476 pending_sync_queries_.push_back(std::move(current_sync_query_)); |
| 2501 } | 2477 } |
| 2502 | 2478 |
| 2503 swap_buffer_rect_.Union(frame->root_damage_rect); | 2479 swap_buffer_rect_.Union(current_frame()->root_damage_rect); |
| 2504 if (overdraw_feedback_) | 2480 if (overdraw_feedback_) |
| 2505 FlushOverdrawFeedback(frame, swap_buffer_rect_); | 2481 FlushOverdrawFeedback(swap_buffer_rect_); |
| 2506 | 2482 |
| 2507 current_framebuffer_lock_ = nullptr; | 2483 current_framebuffer_lock_ = nullptr; |
| 2508 | 2484 |
| 2509 gl_->Disable(GL_BLEND); | 2485 gl_->Disable(GL_BLEND); |
| 2510 blend_shadow_ = false; | 2486 blend_shadow_ = false; |
| 2511 | 2487 |
| 2512 ScheduleCALayers(frame); | 2488 ScheduleCALayers(); |
| 2513 ScheduleOverlays(frame); | 2489 ScheduleOverlays(); |
| 2514 } | 2490 } |
| 2515 | 2491 |
| 2516 void GLRenderer::FinishDrawingQuadList() { | 2492 void GLRenderer::FinishDrawingQuadList() { |
| 2517 FlushTextureQuadCache(SHARED_BINDING); | 2493 FlushTextureQuadCache(SHARED_BINDING); |
| 2518 } | 2494 } |
| 2519 | 2495 |
| 2520 bool GLRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { | 2496 bool GLRenderer::FlippedFramebuffer() const { |
| 2521 if (force_drawing_frame_framebuffer_unflipped_) | 2497 if (force_drawing_frame_framebuffer_unflipped_) |
| 2522 return false; | 2498 return false; |
| 2523 if (frame->current_render_pass != frame->root_render_pass) | 2499 if (current_frame()->current_render_pass != current_frame()->root_render_pass) |
| 2524 return true; | 2500 return true; |
| 2525 return FlippedRootFramebuffer(); | 2501 return FlippedRootFramebuffer(); |
| 2526 } | 2502 } |
| 2527 | 2503 |
| 2528 bool GLRenderer::FlippedRootFramebuffer() const { | 2504 bool GLRenderer::FlippedRootFramebuffer() const { |
| 2529 // GL is normally flipped, so a flipped output results in an unflipping. | 2505 // GL is normally flipped, so a flipped output results in an unflipping. |
| 2530 return !output_surface_->capabilities().flipped_output_surface; | 2506 return !output_surface_->capabilities().flipped_output_surface; |
| 2531 } | 2507 } |
| 2532 | 2508 |
| 2533 void GLRenderer::EnsureScissorTestEnabled() { | 2509 void GLRenderer::EnsureScissorTestEnabled() { |
| 2534 if (is_scissor_enabled_) | 2510 if (is_scissor_enabled_) |
| 2535 return; | 2511 return; |
| 2536 | 2512 |
| 2537 FlushTextureQuadCache(SHARED_BINDING); | 2513 FlushTextureQuadCache(SHARED_BINDING); |
| 2538 gl_->Enable(GL_SCISSOR_TEST); | 2514 gl_->Enable(GL_SCISSOR_TEST); |
| 2539 is_scissor_enabled_ = true; | 2515 is_scissor_enabled_ = true; |
| 2540 } | 2516 } |
| 2541 | 2517 |
| 2542 void GLRenderer::EnsureScissorTestDisabled() { | 2518 void GLRenderer::EnsureScissorTestDisabled() { |
| 2543 if (!is_scissor_enabled_) | 2519 if (!is_scissor_enabled_) |
| 2544 return; | 2520 return; |
| 2545 | 2521 |
| 2546 FlushTextureQuadCache(SHARED_BINDING); | 2522 FlushTextureQuadCache(SHARED_BINDING); |
| 2547 gl_->Disable(GL_SCISSOR_TEST); | 2523 gl_->Disable(GL_SCISSOR_TEST); |
| 2548 is_scissor_enabled_ = false; | 2524 is_scissor_enabled_ = false; |
| 2549 } | 2525 } |
| 2550 | 2526 |
| 2551 void GLRenderer::CopyCurrentRenderPassToBitmap( | 2527 void GLRenderer::CopyCurrentRenderPassToBitmap( |
| 2552 DrawingFrame* frame, | |
| 2553 std::unique_ptr<CopyOutputRequest> request) { | 2528 std::unique_ptr<CopyOutputRequest> request) { |
| 2554 TRACE_EVENT0("cc", "GLRenderer::CopyCurrentRenderPassToBitmap"); | 2529 TRACE_EVENT0("cc", "GLRenderer::CopyCurrentRenderPassToBitmap"); |
| 2555 gfx::Rect copy_rect = frame->current_render_pass->output_rect; | 2530 gfx::Rect copy_rect = current_frame()->current_render_pass->output_rect; |
| 2556 if (request->has_area()) | 2531 if (request->has_area()) |
| 2557 copy_rect.Intersect(request->area()); | 2532 copy_rect.Intersect(request->area()); |
| 2558 GetFramebufferPixelsAsync(frame, copy_rect, std::move(request)); | 2533 GetFramebufferPixelsAsync(copy_rect, std::move(request)); |
| 2559 } | 2534 } |
| 2560 | 2535 |
| 2561 void GLRenderer::ToGLMatrix(float* gl_matrix, const gfx::Transform& transform) { | 2536 void GLRenderer::ToGLMatrix(float* gl_matrix, const gfx::Transform& transform) { |
| 2562 transform.matrix().asColMajorf(gl_matrix); | 2537 transform.matrix().asColMajorf(gl_matrix); |
| 2563 } | 2538 } |
| 2564 | 2539 |
| 2565 void GLRenderer::SetShaderQuadF(const gfx::QuadF& quad) { | 2540 void GLRenderer::SetShaderQuadF(const gfx::QuadF& quad) { |
| 2566 if (!program_shadow_ || program_shadow_->quad_location() == -1) | 2541 if (!program_shadow_ || program_shadow_->quad_location() == -1) |
| 2567 return; | 2542 return; |
| 2568 float gl_quad[8]; | 2543 float gl_quad[8]; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2638 static_cast<float>(current_window_space_viewport_.y()), | 2613 static_cast<float>(current_window_space_viewport_.y()), |
| 2639 static_cast<float>(current_window_space_viewport_.width()), | 2614 static_cast<float>(current_window_space_viewport_.width()), |
| 2640 static_cast<float>(current_window_space_viewport_.height()), | 2615 static_cast<float>(current_window_space_viewport_.height()), |
| 2641 }; | 2616 }; |
| 2642 gl_->Uniform4fv(program->viewport_location(), 1, viewport); | 2617 gl_->Uniform4fv(program->viewport_location(), 1, viewport); |
| 2643 } | 2618 } |
| 2644 program_shadow_ = program; | 2619 program_shadow_ = program; |
| 2645 } | 2620 } |
| 2646 | 2621 |
| 2647 void GLRenderer::DrawQuadGeometryClippedByQuadF( | 2622 void GLRenderer::DrawQuadGeometryClippedByQuadF( |
| 2648 const DrawingFrame* frame, | |
| 2649 const gfx::Transform& draw_transform, | 2623 const gfx::Transform& draw_transform, |
| 2650 const gfx::RectF& quad_rect, | 2624 const gfx::RectF& quad_rect, |
| 2651 const gfx::QuadF& clipping_region_quad, | 2625 const gfx::QuadF& clipping_region_quad, |
| 2652 const float* uvs) { | 2626 const float* uvs) { |
| 2653 PrepareGeometry(CLIPPED_BINDING); | 2627 PrepareGeometry(CLIPPED_BINDING); |
| 2654 if (uvs) { | 2628 if (uvs) { |
| 2655 clipped_geometry_->InitializeCustomQuadWithUVs(clipping_region_quad, uvs); | 2629 clipped_geometry_->InitializeCustomQuadWithUVs(clipping_region_quad, uvs); |
| 2656 } else { | 2630 } else { |
| 2657 clipped_geometry_->InitializeCustomQuad(clipping_region_quad); | 2631 clipped_geometry_->InitializeCustomQuad(clipping_region_quad); |
| 2658 } | 2632 } |
| 2659 gfx::Transform quad_rect_matrix; | 2633 gfx::Transform quad_rect_matrix; |
| 2660 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); | 2634 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); |
| 2661 SetShaderMatrix(frame->projection_matrix * quad_rect_matrix); | 2635 SetShaderMatrix(current_frame()->projection_matrix * quad_rect_matrix); |
| 2662 | 2636 |
| 2663 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, | 2637 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, |
| 2664 reinterpret_cast<const void*>(0)); | 2638 reinterpret_cast<const void*>(0)); |
| 2665 } | 2639 } |
| 2666 | 2640 |
| 2667 void GLRenderer::DrawQuadGeometry(const gfx::Transform& projection_matrix, | 2641 void GLRenderer::DrawQuadGeometry(const gfx::Transform& projection_matrix, |
| 2668 const gfx::Transform& draw_transform, | 2642 const gfx::Transform& draw_transform, |
| 2669 const gfx::RectF& quad_rect) { | 2643 const gfx::RectF& quad_rect) { |
| 2670 PrepareGeometry(SHARED_BINDING); | 2644 PrepareGeometry(SHARED_BINDING); |
| 2671 gfx::Transform quad_rect_matrix; | 2645 gfx::Transform quad_rect_matrix; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2752 DCHECK(settings_->release_overlay_resources_after_gpu_query); | 2726 DCHECK(settings_->release_overlay_resources_after_gpu_query); |
| 2753 for (const gpu::TextureInUseResponse& response : responses) { | 2727 for (const gpu::TextureInUseResponse& response : responses) { |
| 2754 if (!response.in_use) { | 2728 if (!response.in_use) { |
| 2755 swapped_and_acked_overlay_resources_.erase(response.texture); | 2729 swapped_and_acked_overlay_resources_.erase(response.texture); |
| 2756 } | 2730 } |
| 2757 } | 2731 } |
| 2758 color_lut_cache_.Swap(); | 2732 color_lut_cache_.Swap(); |
| 2759 } | 2733 } |
| 2760 | 2734 |
| 2761 void GLRenderer::GetFramebufferPixelsAsync( | 2735 void GLRenderer::GetFramebufferPixelsAsync( |
| 2762 const DrawingFrame* frame, | |
| 2763 const gfx::Rect& rect, | 2736 const gfx::Rect& rect, |
| 2764 std::unique_ptr<CopyOutputRequest> request) { | 2737 std::unique_ptr<CopyOutputRequest> request) { |
| 2765 DCHECK(!request->IsEmpty()); | 2738 DCHECK(!request->IsEmpty()); |
| 2766 if (request->IsEmpty()) | 2739 if (request->IsEmpty()) |
| 2767 return; | 2740 return; |
| 2768 if (rect.IsEmpty()) | 2741 if (rect.IsEmpty()) |
| 2769 return; | 2742 return; |
| 2770 | 2743 |
| 2771 if (overdraw_feedback_) | 2744 if (overdraw_feedback_) |
| 2772 FlushOverdrawFeedback(frame, rect); | 2745 FlushOverdrawFeedback(rect); |
| 2773 | 2746 |
| 2774 gfx::Rect window_rect = MoveFromDrawToWindowSpace(frame, rect); | 2747 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect); |
| 2775 DCHECK_GE(window_rect.x(), 0); | 2748 DCHECK_GE(window_rect.x(), 0); |
| 2776 DCHECK_GE(window_rect.y(), 0); | 2749 DCHECK_GE(window_rect.y(), 0); |
| 2777 DCHECK_LE(window_rect.right(), current_surface_size_.width()); | 2750 DCHECK_LE(window_rect.right(), current_surface_size_.width()); |
| 2778 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); | 2751 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); |
| 2779 | 2752 |
| 2780 if (!request->force_bitmap_result()) { | 2753 if (!request->force_bitmap_result()) { |
| 2781 bool own_mailbox = !request->has_texture_mailbox(); | 2754 bool own_mailbox = !request->has_texture_mailbox(); |
| 2782 | 2755 |
| 2783 GLuint texture_id = 0; | 2756 GLuint texture_id = 0; |
| 2784 gpu::Mailbox mailbox; | 2757 gpu::Mailbox mailbox; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2951 format == GL_LUMINANCE_ALPHA || format == GL_RGB || format == GL_RGBA) | 2924 format == GL_LUMINANCE_ALPHA || format == GL_RGB || format == GL_RGBA) |
| 2952 << format; | 2925 << format; |
| 2953 | 2926 |
| 2954 gl_->BindTexture(GL_TEXTURE_2D, texture_id); | 2927 gl_->BindTexture(GL_TEXTURE_2D, texture_id); |
| 2955 gl_->CopyTexImage2D(GL_TEXTURE_2D, 0, format, window_rect.x(), | 2928 gl_->CopyTexImage2D(GL_TEXTURE_2D, 0, format, window_rect.x(), |
| 2956 window_rect.y(), window_rect.width(), | 2929 window_rect.y(), window_rect.width(), |
| 2957 window_rect.height(), 0); | 2930 window_rect.height(), 0); |
| 2958 gl_->BindTexture(GL_TEXTURE_2D, 0); | 2931 gl_->BindTexture(GL_TEXTURE_2D, 0); |
| 2959 } | 2932 } |
| 2960 | 2933 |
| 2961 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { | 2934 void GLRenderer::BindFramebufferToOutputSurface() { |
| 2962 current_framebuffer_lock_ = nullptr; | 2935 current_framebuffer_lock_ = nullptr; |
| 2963 output_surface_->BindFramebuffer(); | 2936 output_surface_->BindFramebuffer(); |
| 2964 | 2937 |
| 2965 if (overdraw_feedback_) { | 2938 if (overdraw_feedback_) { |
| 2966 // Output surfaces that require an external stencil test should not allow | 2939 // Output surfaces that require an external stencil test should not allow |
| 2967 // overdraw feedback by setting |supports_stencil| to false. | 2940 // overdraw feedback by setting |supports_stencil| to false. |
| 2968 DCHECK(!output_surface_->HasExternalStencilTest()); | 2941 DCHECK(!output_surface_->HasExternalStencilTest()); |
| 2969 SetupOverdrawFeedback(); | 2942 SetupOverdrawFeedback(); |
| 2970 SetStencilEnabled(true); | 2943 SetStencilEnabled(true); |
| 2971 } else if (output_surface_->HasExternalStencilTest()) { | 2944 } else if (output_surface_->HasExternalStencilTest()) { |
| 2972 output_surface_->ApplyExternalStencil(); | 2945 output_surface_->ApplyExternalStencil(); |
| 2973 SetStencilEnabled(true); | 2946 SetStencilEnabled(true); |
| 2974 } else { | 2947 } else { |
| 2975 SetStencilEnabled(false); | 2948 SetStencilEnabled(false); |
| 2976 } | 2949 } |
| 2977 } | 2950 } |
| 2978 | 2951 |
| 2979 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame, | 2952 bool GLRenderer::BindFramebufferToTexture(const ScopedResource* texture) { |
| 2980 const ScopedResource* texture) { | |
| 2981 DCHECK(texture->id()); | 2953 DCHECK(texture->id()); |
| 2982 | 2954 |
| 2983 // Explicitly release lock, otherwise we can crash when try to lock | 2955 // Explicitly release lock, otherwise we can crash when try to lock |
| 2984 // same texture again. | 2956 // same texture again. |
| 2985 current_framebuffer_lock_ = nullptr; | 2957 current_framebuffer_lock_ = nullptr; |
| 2986 | 2958 |
| 2987 gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_); | 2959 gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_); |
| 2988 current_framebuffer_lock_ = | 2960 current_framebuffer_lock_ = |
| 2989 base::MakeUnique<ResourceProvider::ScopedWriteLockGL>( | 2961 base::MakeUnique<ResourceProvider::ScopedWriteLockGL>( |
| 2990 resource_provider_, texture->id(), false); | 2962 resource_provider_, texture->id(), false); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3145 gl_->Disable(GL_SCISSOR_TEST); | 3117 gl_->Disable(GL_SCISSOR_TEST); |
| 3146 | 3118 |
| 3147 gl_->Scissor(scissor_rect_.x(), scissor_rect_.y(), scissor_rect_.width(), | 3119 gl_->Scissor(scissor_rect_.x(), scissor_rect_.y(), scissor_rect_.width(), |
| 3148 scissor_rect_.height()); | 3120 scissor_rect_.height()); |
| 3149 } | 3121 } |
| 3150 | 3122 |
| 3151 bool GLRenderer::IsContextLost() { | 3123 bool GLRenderer::IsContextLost() { |
| 3152 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 3124 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
| 3153 } | 3125 } |
| 3154 | 3126 |
| 3155 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { | 3127 void GLRenderer::ScheduleCALayers() { |
| 3156 if (overlay_resource_pool_) { | 3128 if (overlay_resource_pool_) { |
| 3157 overlay_resource_pool_->CheckBusyResources(); | 3129 overlay_resource_pool_->CheckBusyResources(); |
| 3158 } | 3130 } |
| 3159 | 3131 |
| 3160 scoped_refptr<CALayerOverlaySharedState> shared_state; | 3132 scoped_refptr<CALayerOverlaySharedState> shared_state; |
| 3161 size_t copied_render_pass_count = 0; | 3133 size_t copied_render_pass_count = 0; |
| 3162 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { | 3134 for (const CALayerOverlay& ca_layer_overlay : |
| 3135 current_frame()->ca_layer_overlay_list) { |
| 3163 if (ca_layer_overlay.rpdq) { | 3136 if (ca_layer_overlay.rpdq) { |
| 3164 ScheduleRenderPassDrawQuad(&ca_layer_overlay, frame); | 3137 ScheduleRenderPassDrawQuad(&ca_layer_overlay); |
| 3165 shared_state = nullptr; | 3138 shared_state = nullptr; |
| 3166 ++copied_render_pass_count; | 3139 ++copied_render_pass_count; |
| 3167 continue; | 3140 continue; |
| 3168 } | 3141 } |
| 3169 | 3142 |
| 3170 ResourceId contents_resource_id = ca_layer_overlay.contents_resource_id; | 3143 ResourceId contents_resource_id = ca_layer_overlay.contents_resource_id; |
| 3171 unsigned texture_id = 0; | 3144 unsigned texture_id = 0; |
| 3172 if (contents_resource_id) { | 3145 if (contents_resource_id) { |
| 3173 pending_overlay_resources_.push_back( | 3146 pending_overlay_resources_.push_back( |
| 3174 base::MakeUnique<ResourceProvider::ScopedReadLockGL>( | 3147 base::MakeUnique<ResourceProvider::ScopedReadLockGL>( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3208 } | 3181 } |
| 3209 | 3182 |
| 3210 // Take the number of copied render passes in this frame, and use 3 times that | 3183 // Take the number of copied render passes in this frame, and use 3 times that |
| 3211 // amount as the cache limit. | 3184 // amount as the cache limit. |
| 3212 if (overlay_resource_pool_) { | 3185 if (overlay_resource_pool_) { |
| 3213 overlay_resource_pool_->SetResourceUsageLimits( | 3186 overlay_resource_pool_->SetResourceUsageLimits( |
| 3214 std::numeric_limits<std::size_t>::max(), copied_render_pass_count * 5); | 3187 std::numeric_limits<std::size_t>::max(), copied_render_pass_count * 5); |
| 3215 } | 3188 } |
| 3216 } | 3189 } |
| 3217 | 3190 |
| 3218 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { | 3191 void GLRenderer::ScheduleOverlays() { |
| 3219 if (frame->overlay_list.empty()) | 3192 if (current_frame()->overlay_list.empty()) |
| 3220 return; | 3193 return; |
| 3221 | 3194 |
| 3222 OverlayCandidateList& overlays = frame->overlay_list; | 3195 OverlayCandidateList& overlays = current_frame()->overlay_list; |
| 3223 for (const OverlayCandidate& overlay : overlays) { | 3196 for (const OverlayCandidate& overlay : overlays) { |
| 3224 unsigned texture_id = 0; | 3197 unsigned texture_id = 0; |
| 3225 if (overlay.use_output_surface_for_resource) { | 3198 if (overlay.use_output_surface_for_resource) { |
| 3226 texture_id = output_surface_->GetOverlayTextureId(); | 3199 texture_id = output_surface_->GetOverlayTextureId(); |
| 3227 DCHECK(texture_id || IsContextLost()); | 3200 DCHECK(texture_id || IsContextLost()); |
| 3228 } else { | 3201 } else { |
| 3229 pending_overlay_resources_.push_back( | 3202 pending_overlay_resources_.push_back( |
| 3230 base::MakeUnique<ResourceProvider::ScopedReadLockGL>( | 3203 base::MakeUnique<ResourceProvider::ScopedReadLockGL>( |
| 3231 resource_provider_, overlay.resource_id)); | 3204 resource_provider_, overlay.resource_id)); |
| 3232 texture_id = pending_overlay_resources_.back()->texture_id(); | 3205 texture_id = pending_overlay_resources_.back()->texture_id(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3249 // screen. This reuses most of the RPDQ draw logic. | 3222 // screen. This reuses most of the RPDQ draw logic. |
| 3250 // 2. Update parameters to draw into a framebuffer only as large as needed. | 3223 // 2. Update parameters to draw into a framebuffer only as large as needed. |
| 3251 // 3. Fix shader uniforms that were broken by (2). | 3224 // 3. Fix shader uniforms that were broken by (2). |
| 3252 // | 3225 // |
| 3253 // Then: | 3226 // Then: |
| 3254 // 4. Allocate an IOSurface as the drawing destination. | 3227 // 4. Allocate an IOSurface as the drawing destination. |
| 3255 // 5. Draw the RPDQ. | 3228 // 5. Draw the RPDQ. |
| 3256 void GLRenderer::CopyRenderPassDrawQuadToOverlayResource( | 3229 void GLRenderer::CopyRenderPassDrawQuadToOverlayResource( |
| 3257 const CALayerOverlay* ca_layer_overlay, | 3230 const CALayerOverlay* ca_layer_overlay, |
| 3258 Resource** resource, | 3231 Resource** resource, |
| 3259 DrawingFrame* external_frame, | |
| 3260 gfx::RectF* new_bounds) { | 3232 gfx::RectF* new_bounds) { |
| 3261 // Don't carry over any GL state from previous RenderPass draw operations. | 3233 // Don't carry over any GL state from previous RenderPass draw operations. |
| 3262 ReinitializeGLState(); | 3234 ReinitializeGLState(); |
| 3263 | 3235 |
| 3264 ScopedResource* contents_texture = | 3236 ScopedResource* contents_texture = |
| 3265 render_pass_textures_[ca_layer_overlay->rpdq->render_pass_id].get(); | 3237 render_pass_textures_[ca_layer_overlay->rpdq->render_pass_id].get(); |
| 3266 DCHECK(contents_texture); | 3238 DCHECK(contents_texture); |
| 3267 | 3239 |
| 3268 // Configure parameters as if drawing to a framebuffer the size of the | 3240 // Configure parameters as if drawing to a framebuffer the size of the |
| 3269 // screen. | 3241 // screen. |
| 3270 DrawRenderPassDrawQuadParams params; | 3242 DrawRenderPassDrawQuadParams params; |
| 3271 params.quad = ca_layer_overlay->rpdq; | 3243 params.quad = ca_layer_overlay->rpdq; |
| 3272 params.flip_texture = true; | 3244 params.flip_texture = true; |
| 3273 params.contents_texture = contents_texture; | 3245 params.contents_texture = contents_texture; |
| 3274 params.quad_to_target_transform = | 3246 params.quad_to_target_transform = |
| 3275 params.quad->shared_quad_state->quad_to_target_transform; | 3247 params.quad->shared_quad_state->quad_to_target_transform; |
| 3276 | 3248 |
| 3277 // Calculate projection and window matrices using InitializeViewport(). This | 3249 // Calculate projection and window matrices using InitializeViewport(). This |
| 3278 // requires creating a dummy DrawingFrame. | 3250 // requires creating a dummy DrawingFrame. |
| 3279 { | 3251 { |
| 3280 DrawingFrame frame; | 3252 DrawingFrame dummy_frame; |
| 3281 gfx::Rect frame_rect(external_frame->device_viewport_size); | 3253 gfx::Rect frame_rect(current_frame()->device_viewport_size); |
| 3282 force_drawing_frame_framebuffer_unflipped_ = true; | 3254 force_drawing_frame_framebuffer_unflipped_ = true; |
| 3283 InitializeViewport(&frame, frame_rect, frame_rect, frame_rect.size()); | 3255 InitializeViewport(&dummy_frame, frame_rect, frame_rect, frame_rect.size()); |
| 3284 force_drawing_frame_framebuffer_unflipped_ = false; | 3256 force_drawing_frame_framebuffer_unflipped_ = false; |
| 3285 params.projection_matrix = frame.projection_matrix; | 3257 params.projection_matrix = dummy_frame.projection_matrix; |
| 3286 params.window_matrix = frame.window_matrix; | 3258 params.window_matrix = dummy_frame.window_matrix; |
| 3287 } | 3259 } |
| 3288 | 3260 |
| 3289 // Perform basic initialization with the screen-sized viewport. | 3261 // Perform basic initialization with the screen-sized viewport. |
| 3290 if (!InitializeRPDQParameters(¶ms)) | 3262 if (!InitializeRPDQParameters(¶ms)) |
| 3291 return; | 3263 return; |
| 3292 | 3264 |
| 3293 if (!UpdateRPDQWithSkiaFilters(¶ms)) | 3265 if (!UpdateRPDQWithSkiaFilters(¶ms)) |
| 3294 return; | 3266 return; |
| 3295 | 3267 |
| 3296 // |params.dst_rect| now contain values that reflect a potentially increased | 3268 // |params.dst_rect| now contain values that reflect a potentially increased |
| 3297 // size quad. | 3269 // size quad. |
| 3298 gfx::RectF updated_dst_rect = params.dst_rect; | 3270 gfx::RectF updated_dst_rect = params.dst_rect; |
| 3299 | 3271 |
| 3300 // Round the size of the IOSurface to a multiple of 64 pixels. This reduces | 3272 // Round the size of the IOSurface to a multiple of 64 pixels. This reduces |
| 3301 // memory fragmentation. https://crbug.com/146070. This also allows IOSurfaces | 3273 // memory fragmentation. https://crbug.com/146070. This also allows IOSurfaces |
| 3302 // to be more easily reused during a resize operation. | 3274 // to be more easily reused during a resize operation. |
| 3303 uint32_t iosurface_multiple = 64; | 3275 uint32_t iosurface_multiple = 64; |
| 3304 uint32_t iosurface_width = MathUtil::UncheckedRoundUp( | 3276 uint32_t iosurface_width = MathUtil::UncheckedRoundUp( |
| 3305 static_cast<uint32_t>(updated_dst_rect.width()), iosurface_multiple); | 3277 static_cast<uint32_t>(updated_dst_rect.width()), iosurface_multiple); |
| 3306 uint32_t iosurface_height = MathUtil::UncheckedRoundUp( | 3278 uint32_t iosurface_height = MathUtil::UncheckedRoundUp( |
| 3307 static_cast<uint32_t>(updated_dst_rect.height()), iosurface_multiple); | 3279 static_cast<uint32_t>(updated_dst_rect.height()), iosurface_multiple); |
| 3308 | 3280 |
| 3309 *resource = overlay_resource_pool_->AcquireResource( | 3281 *resource = overlay_resource_pool_->AcquireResource( |
| 3310 gfx::Size(iosurface_width, iosurface_height), ResourceFormat::RGBA_8888, | 3282 gfx::Size(iosurface_width, iosurface_height), ResourceFormat::RGBA_8888, |
| 3311 external_frame->device_color_space); | 3283 current_frame()->device_color_space); |
| 3312 *new_bounds = | 3284 *new_bounds = |
| 3313 gfx::RectF(updated_dst_rect.x(), updated_dst_rect.y(), | 3285 gfx::RectF(updated_dst_rect.x(), updated_dst_rect.y(), |
| 3314 (*resource)->size().width(), (*resource)->size().height()); | 3286 (*resource)->size().width(), (*resource)->size().height()); |
| 3315 | 3287 |
| 3316 // Calculate new projection and window matrices for a minimally sized viewport | 3288 // Calculate new projection and window matrices for a minimally sized viewport |
| 3317 // using InitializeViewport(). This requires creating a dummy DrawingFrame. | 3289 // using InitializeViewport(). This requires creating a dummy DrawingFrame. |
| 3318 { | 3290 { |
| 3319 DrawingFrame frame; | 3291 DrawingFrame dummy_frame; |
| 3320 force_drawing_frame_framebuffer_unflipped_ = true; | 3292 force_drawing_frame_framebuffer_unflipped_ = true; |
| 3321 gfx::Rect frame_rect = | 3293 gfx::Rect frame_rect = |
| 3322 gfx::Rect(0, 0, updated_dst_rect.width(), updated_dst_rect.height()); | 3294 gfx::Rect(0, 0, updated_dst_rect.width(), updated_dst_rect.height()); |
| 3323 InitializeViewport(&frame, frame_rect, frame_rect, frame_rect.size()); | 3295 InitializeViewport(&dummy_frame, frame_rect, frame_rect, frame_rect.size()); |
| 3324 force_drawing_frame_framebuffer_unflipped_ = false; | 3296 force_drawing_frame_framebuffer_unflipped_ = false; |
| 3325 params.projection_matrix = frame.projection_matrix; | 3297 params.projection_matrix = dummy_frame.projection_matrix; |
| 3326 params.window_matrix = frame.window_matrix; | 3298 params.window_matrix = dummy_frame.window_matrix; |
| 3327 } | 3299 } |
| 3328 | 3300 |
| 3329 // Calculate a new quad_to_target_transform. | 3301 // Calculate a new quad_to_target_transform. |
| 3330 params.quad_to_target_transform = gfx::Transform(); | 3302 params.quad_to_target_transform = gfx::Transform(); |
| 3331 params.quad_to_target_transform.Translate(-updated_dst_rect.x(), | 3303 params.quad_to_target_transform.Translate(-updated_dst_rect.x(), |
| 3332 -updated_dst_rect.y()); | 3304 -updated_dst_rect.y()); |
| 3333 | 3305 |
| 3334 // Antialiasing works by fading out content that is close to the edge of the | 3306 // Antialiasing works by fading out content that is close to the edge of the |
| 3335 // viewport. All of these values need to be recalculated. | 3307 // viewport. All of these values need to be recalculated. |
| 3336 if (params.use_aa) { | 3308 if (params.use_aa) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3373 | 3345 |
| 3374 // Prior to drawing, set up the destination framebuffer and viewport. | 3346 // Prior to drawing, set up the destination framebuffer and viewport. |
| 3375 gl_->BindFramebuffer(GL_FRAMEBUFFER, temp_fbo); | 3347 gl_->BindFramebuffer(GL_FRAMEBUFFER, temp_fbo); |
| 3376 gl_->Viewport(0, 0, updated_dst_rect.width(), updated_dst_rect.height()); | 3348 gl_->Viewport(0, 0, updated_dst_rect.width(), updated_dst_rect.height()); |
| 3377 | 3349 |
| 3378 DrawRPDQ(params); | 3350 DrawRPDQ(params); |
| 3379 gl_->DeleteFramebuffers(1, &temp_fbo); | 3351 gl_->DeleteFramebuffers(1, &temp_fbo); |
| 3380 } | 3352 } |
| 3381 | 3353 |
| 3382 void GLRenderer::ScheduleRenderPassDrawQuad( | 3354 void GLRenderer::ScheduleRenderPassDrawQuad( |
| 3383 const CALayerOverlay* ca_layer_overlay, | 3355 const CALayerOverlay* ca_layer_overlay) { |
| 3384 DrawingFrame* external_frame) { | |
| 3385 DCHECK(ca_layer_overlay->rpdq); | 3356 DCHECK(ca_layer_overlay->rpdq); |
| 3386 | 3357 |
| 3387 if (!overlay_resource_pool_) { | 3358 if (!overlay_resource_pool_) { |
| 3388 overlay_resource_pool_ = ResourcePool::CreateForGpuMemoryBufferResources( | 3359 overlay_resource_pool_ = ResourcePool::CreateForGpuMemoryBufferResources( |
| 3389 resource_provider_, base::ThreadTaskRunnerHandle::Get().get(), | 3360 resource_provider_, base::ThreadTaskRunnerHandle::Get().get(), |
| 3390 gfx::BufferUsage::SCANOUT, base::TimeDelta::FromSeconds(3)); | 3361 gfx::BufferUsage::SCANOUT, base::TimeDelta::FromSeconds(3)); |
| 3391 } | 3362 } |
| 3392 | 3363 |
| 3393 Resource* resource = nullptr; | 3364 Resource* resource = nullptr; |
| 3394 gfx::RectF new_bounds; | 3365 gfx::RectF new_bounds; |
| 3395 CopyRenderPassDrawQuadToOverlayResource(ca_layer_overlay, &resource, | 3366 CopyRenderPassDrawQuadToOverlayResource(ca_layer_overlay, &resource, |
| 3396 external_frame, &new_bounds); | 3367 &new_bounds); |
| 3397 if (!resource || !resource->id()) | 3368 if (!resource || !resource->id()) |
| 3398 return; | 3369 return; |
| 3399 | 3370 |
| 3400 pending_overlay_resources_.push_back( | 3371 pending_overlay_resources_.push_back( |
| 3401 base::MakeUnique<ResourceProvider::ScopedReadLockGL>(resource_provider_, | 3372 base::MakeUnique<ResourceProvider::ScopedReadLockGL>(resource_provider_, |
| 3402 resource->id())); | 3373 resource->id())); |
| 3403 unsigned texture_id = pending_overlay_resources_.back()->texture_id(); | 3374 unsigned texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3404 | 3375 |
| 3405 // Once a resource is released, it is marked as "busy". It will be | 3376 // Once a resource is released, it is marked as "busy". It will be |
| 3406 // available for reuse after the ScopedReadLockGL is destroyed. | 3377 // available for reuse after the ScopedReadLockGL is destroyed. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3434 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 3405 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
| 3435 } | 3406 } |
| 3436 | 3407 |
| 3437 void GLRenderer::SetupOverdrawFeedback() { | 3408 void GLRenderer::SetupOverdrawFeedback() { |
| 3438 gl_->StencilFunc(GL_ALWAYS, 1, 0xffffffff); | 3409 gl_->StencilFunc(GL_ALWAYS, 1, 0xffffffff); |
| 3439 // First two values are ignored as test always passes. | 3410 // First two values are ignored as test always passes. |
| 3440 gl_->StencilOp(GL_KEEP, GL_KEEP, GL_INCR); | 3411 gl_->StencilOp(GL_KEEP, GL_KEEP, GL_INCR); |
| 3441 gl_->StencilMask(0xffffffff); | 3412 gl_->StencilMask(0xffffffff); |
| 3442 } | 3413 } |
| 3443 | 3414 |
| 3444 void GLRenderer::FlushOverdrawFeedback(const DrawingFrame* frame, | 3415 void GLRenderer::FlushOverdrawFeedback(const gfx::Rect& output_rect) { |
| 3445 const gfx::Rect& output_rect) { | |
| 3446 DCHECK(stencil_shadow_); | 3416 DCHECK(stencil_shadow_); |
| 3447 | 3417 |
| 3448 // Test only, keep everything. | 3418 // Test only, keep everything. |
| 3449 gl_->StencilOp(GL_KEEP, GL_KEEP, GL_KEEP); | 3419 gl_->StencilOp(GL_KEEP, GL_KEEP, GL_KEEP); |
| 3450 | 3420 |
| 3451 EnsureScissorTestDisabled(); | 3421 EnsureScissorTestDisabled(); |
| 3452 SetBlendEnabled(true); | 3422 SetBlendEnabled(true); |
| 3453 | 3423 |
| 3454 PrepareGeometry(SHARED_BINDING); | 3424 PrepareGeometry(SHARED_BINDING); |
| 3455 | 3425 |
| 3456 const Program* program = GetProgram(ProgramKey::DebugBorder()); | 3426 const Program* program = GetProgram(ProgramKey::DebugBorder()); |
| 3457 SetUseProgram(program); | 3427 SetUseProgram(program); |
| 3458 | 3428 |
| 3459 gfx::Transform render_matrix; | 3429 gfx::Transform render_matrix; |
| 3460 render_matrix.Translate(0.5 * output_rect.width() + output_rect.x(), | 3430 render_matrix.Translate(0.5 * output_rect.width() + output_rect.x(), |
| 3461 0.5 * output_rect.height() + output_rect.y()); | 3431 0.5 * output_rect.height() + output_rect.y()); |
| 3462 render_matrix.Scale(output_rect.width(), output_rect.height()); | 3432 render_matrix.Scale(output_rect.width(), output_rect.height()); |
| 3463 SetShaderMatrix(frame->projection_matrix * render_matrix); | 3433 SetShaderMatrix(current_frame()->projection_matrix * render_matrix); |
| 3464 | 3434 |
| 3465 // Produce hinting for the amount of overdraw on screen for each pixel by | 3435 // Produce hinting for the amount of overdraw on screen for each pixel by |
| 3466 // drawing hint colors to the framebuffer based on the current stencil value. | 3436 // drawing hint colors to the framebuffer based on the current stencil value. |
| 3467 struct { | 3437 struct { |
| 3468 int multiplier; | 3438 int multiplier; |
| 3469 GLenum func; | 3439 GLenum func; |
| 3470 GLint ref; | 3440 GLint ref; |
| 3471 SkColor color; | 3441 SkColor color; |
| 3472 } stencil_tests[] = { | 3442 } stencil_tests[] = { |
| 3473 {1, GL_EQUAL, 2, 0x2f0000ff}, // Blue: Overdrawn once. | 3443 {1, GL_EQUAL, 2, 0x2f0000ff}, // Blue: Overdrawn once. |
| 3474 {2, GL_EQUAL, 3, 0x2f00ff00}, // Green: Overdrawn twice. | 3444 {2, GL_EQUAL, 3, 0x2f00ff00}, // Green: Overdrawn twice. |
| 3475 {3, GL_EQUAL, 4, 0x3fff0000}, // Pink: Overdrawn three times. | 3445 {3, GL_EQUAL, 4, 0x3fff0000}, // Pink: Overdrawn three times. |
| 3476 {4, GL_LESS, 4, 0x7fff0000}, // Red: Overdrawn four or more times. | 3446 {4, GL_LESS, 4, 0x7fff0000}, // Red: Overdrawn four or more times. |
| 3477 }; | 3447 }; |
| 3478 | 3448 |
| 3479 // Occlusion queries can be expensive, so only collect trace data if we select | 3449 // Occlusion queries can be expensive, so only collect trace data if we select |
| 3480 // cc.debug.overdraw. | 3450 // cc.debug.overdraw. |
| 3481 bool tracing_enabled; | 3451 bool tracing_enabled; |
| 3482 TRACE_EVENT_CATEGORY_GROUP_ENABLED( | 3452 TRACE_EVENT_CATEGORY_GROUP_ENABLED( |
| 3483 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), &tracing_enabled); | 3453 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), &tracing_enabled); |
| 3484 | 3454 |
| 3485 // Trace only the root render pass. | 3455 // Trace only the root render pass. |
| 3486 if (frame->current_render_pass != frame->root_render_pass) | 3456 if (current_frame()->current_render_pass != current_frame()->root_render_pass) |
| 3487 tracing_enabled = false; | 3457 tracing_enabled = false; |
| 3488 | 3458 |
| 3489 // ARB_occlusion_query is required for tracing. | 3459 // ARB_occlusion_query is required for tracing. |
| 3490 if (!use_occlusion_query_) | 3460 if (!use_occlusion_query_) |
| 3491 tracing_enabled = false; | 3461 tracing_enabled = false; |
| 3492 | 3462 |
| 3493 // Use the current surface area as max result. The effect is that overdraw | 3463 // Use the current surface area as max result. The effect is that overdraw |
| 3494 // is reported as a percentage of the output surface size. ie. 2x overdraw | 3464 // is reported as a percentage of the output surface size. ie. 2x overdraw |
| 3495 // for the whole screen is reported as 200. | 3465 // for the whole screen is reported as 200. |
| 3496 int max_result = current_surface_size_.GetArea(); | 3466 int max_result = current_surface_size_.GetArea(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3540 return; | 3510 return; |
| 3541 | 3511 |
| 3542 // Report GPU overdraw as a percentage of |max_result|. | 3512 // Report GPU overdraw as a percentage of |max_result|. |
| 3543 TRACE_COUNTER1( | 3513 TRACE_COUNTER1( |
| 3544 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3514 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", |
| 3545 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / | 3515 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / |
| 3546 max_result); | 3516 max_result); |
| 3547 } | 3517 } |
| 3548 | 3518 |
| 3549 } // namespace cc | 3519 } // namespace cc |
| OLD | NEW |