| 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 use_sync_query_(false), | 388 use_sync_query_(false), |
| 389 gl_composited_texture_quad_border_( | 389 gl_composited_texture_quad_border_( |
| 390 settings->gl_composited_texture_quad_border), | 390 settings->gl_composited_texture_quad_border), |
| 391 bound_geometry_(NO_BINDING), | 391 bound_geometry_(NO_BINDING), |
| 392 color_lut_cache_(gl_) { | 392 color_lut_cache_(gl_) { |
| 393 DCHECK(gl_); | 393 DCHECK(gl_); |
| 394 DCHECK(context_support_); | 394 DCHECK(context_support_); |
| 395 | 395 |
| 396 const auto& context_caps = | 396 const auto& context_caps = |
| 397 output_surface_->context_provider()->ContextCapabilities(); | 397 output_surface_->context_provider()->ContextCapabilities(); |
| 398 | |
| 399 capabilities_.using_partial_swap = | |
| 400 settings_->partial_swap_enabled && context_caps.post_sub_buffer; | |
| 401 capabilities_.allow_empty_swap = | |
| 402 capabilities_.using_partial_swap || context_caps.commit_overlay_planes; | |
| 403 | |
| 404 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); | 398 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); |
| 405 | 399 |
| 406 capabilities_.using_egl_image = context_caps.egl_image_external; | |
| 407 | |
| 408 capabilities_.max_texture_size = resource_provider_->max_texture_size(); | 400 capabilities_.max_texture_size = resource_provider_->max_texture_size(); |
| 409 capabilities_.best_texture_format = resource_provider_->best_texture_format(); | 401 capabilities_.best_texture_format = resource_provider_->best_texture_format(); |
| 410 | 402 |
| 411 // The updater can access textures while the GLRenderer is using them. | 403 use_discard_framebuffer_ = context_caps.discard_framebuffer; |
| 412 capabilities_.allow_partial_texture_updates = true; | |
| 413 | |
| 414 capabilities_.using_image = context_caps.image; | |
| 415 | |
| 416 capabilities_.using_discard_framebuffer = context_caps.discard_framebuffer; | |
| 417 | |
| 418 capabilities_.allow_rasterize_on_demand = true; | |
| 419 | |
| 420 // If MSAA is slow, we want this renderer to behave as though MSAA is not | |
| 421 // available. Set samples to 0 to achieve this. | |
| 422 if (context_caps.msaa_is_slow) | |
| 423 capabilities_.max_msaa_samples = 0; | |
| 424 else | |
| 425 capabilities_.max_msaa_samples = context_caps.max_samples; | |
| 426 | |
| 427 use_sync_query_ = context_caps.sync_query; | 404 use_sync_query_ = context_caps.sync_query; |
| 428 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; | 405 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; |
| 429 use_blend_equation_advanced_coherent_ = | 406 use_blend_equation_advanced_coherent_ = |
| 430 context_caps.blend_equation_advanced_coherent; | 407 context_caps.blend_equation_advanced_coherent; |
| 431 | 408 |
| 432 InitializeSharedObjects(); | 409 InitializeSharedObjects(); |
| 433 } | 410 } |
| 434 | 411 |
| 435 GLRenderer::~GLRenderer() { | 412 GLRenderer::~GLRenderer() { |
| 436 while (!pending_async_read_pixels_.empty()) { | 413 while (!pending_async_read_pixels_.empty()) { |
| 437 PendingAsyncReadPixels* pending_read = | 414 PendingAsyncReadPixels* pending_read = |
| 438 pending_async_read_pixels_.back().get(); | 415 pending_async_read_pixels_.back().get(); |
| 439 pending_read->finished_read_pixels_callback.Cancel(); | 416 pending_read->finished_read_pixels_callback.Cancel(); |
| 440 pending_async_read_pixels_.pop_back(); | 417 pending_async_read_pixels_.pop_back(); |
| 441 } | 418 } |
| 442 | 419 |
| 443 CleanupSharedObjects(); | 420 CleanupSharedObjects(); |
| 444 } | 421 } |
| 445 | 422 |
| 446 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { | 423 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { |
| 447 return capabilities_; | 424 return capabilities_; |
| 448 } | 425 } |
| 449 | 426 |
| 427 bool GLRenderer::CanPartialSwap() { |
| 428 auto* context_provider = output_surface_->context_provider(); |
| 429 return context_provider->ContextCapabilities().post_sub_buffer; |
| 430 } |
| 431 |
| 450 void GLRenderer::DidChangeVisibility() { | 432 void GLRenderer::DidChangeVisibility() { |
| 451 if (visible_) { | 433 if (visible_) { |
| 452 output_surface_->EnsureBackbuffer(); | 434 output_surface_->EnsureBackbuffer(); |
| 453 } else { | 435 } else { |
| 454 TRACE_EVENT0("cc", "GLRenderer::DidChangeVisibility dropping resources"); | 436 TRACE_EVENT0("cc", "GLRenderer::DidChangeVisibility dropping resources"); |
| 455 ReleaseRenderPassTextures(); | 437 ReleaseRenderPassTextures(); |
| 456 output_surface_->DiscardBackbuffer(); | 438 output_surface_->DiscardBackbuffer(); |
| 457 } | 439 } |
| 458 | 440 |
| 459 PrepareGeometry(NO_BINDING); | 441 PrepareGeometry(NO_BINDING); |
| 460 | 442 |
| 461 // Handle cleanup of resources on the ContextProvider. The compositor | 443 // Handle cleanup of resources on the ContextProvider. The compositor |
| 462 // ContextProvider is not shared, so always pass 0 for the client_id. | 444 // ContextProvider is not shared, so always pass 0 for the client_id. |
| 463 // TODO(crbug.com/487471): Update this when we share compositor | 445 // TODO(crbug.com/487471): Update this when we share compositor |
| 464 // ContextProviders. | 446 // ContextProviders. |
| 465 context_support_->SetClientVisible(0 /* client_id */, visible_); | 447 context_support_->SetClientVisible(0 /* client_id */, visible_); |
| 466 bool aggressively_free_resources = !context_support_->AnyClientsVisible(); | 448 bool aggressively_free_resources = !context_support_->AnyClientsVisible(); |
| 467 if (aggressively_free_resources) | 449 if (aggressively_free_resources) |
| 468 output_surface_->context_provider()->DeleteCachedResources(); | 450 output_surface_->context_provider()->DeleteCachedResources(); |
| 469 context_support_->SetAggressivelyFreeResources(aggressively_free_resources); | 451 context_support_->SetAggressivelyFreeResources(aggressively_free_resources); |
| 470 } | 452 } |
| 471 | 453 |
| 472 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } | 454 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } |
| 473 | 455 |
| 474 void GLRenderer::DiscardPixels() { | 456 void GLRenderer::DiscardPixels() { |
| 475 if (!capabilities_.using_discard_framebuffer) | 457 if (!use_discard_framebuffer_) |
| 476 return; | 458 return; |
| 477 bool using_default_framebuffer = | 459 bool using_default_framebuffer = |
| 478 !current_framebuffer_lock_ && | 460 !current_framebuffer_lock_ && |
| 479 output_surface_->capabilities().uses_default_gl_framebuffer; | 461 output_surface_->capabilities().uses_default_gl_framebuffer; |
| 480 GLenum attachments[] = {static_cast<GLenum>( | 462 GLenum attachments[] = {static_cast<GLenum>( |
| 481 using_default_framebuffer ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0_EXT)}; | 463 using_default_framebuffer ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0_EXT)}; |
| 482 gl_->DiscardFramebufferEXT( | 464 gl_->DiscardFramebufferEXT( |
| 483 GL_FRAMEBUFFER, arraysize(attachments), attachments); | 465 GL_FRAMEBUFFER, arraysize(attachments), attachments); |
| 484 } | 466 } |
| 485 | 467 |
| (...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2459 } | 2441 } |
| 2460 } | 2442 } |
| 2461 | 2443 |
| 2462 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 2444 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
| 2463 const StreamVideoDrawQuad* quad, | 2445 const StreamVideoDrawQuad* quad, |
| 2464 const gfx::QuadF* clip_region) { | 2446 const gfx::QuadF* clip_region) { |
| 2465 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2447 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2466 | 2448 |
| 2467 static float gl_matrix[16]; | 2449 static float gl_matrix[16]; |
| 2468 | 2450 |
| 2469 DCHECK(capabilities_.using_egl_image); | 2451 DCHECK(output_surface_->context_provider() |
| 2452 ->ContextCapabilities() |
| 2453 .egl_image_external); |
| 2470 | 2454 |
| 2471 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2455 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2472 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2456 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2473 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2457 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2474 | 2458 |
| 2475 const VideoStreamTextureProgram* program = | 2459 const VideoStreamTextureProgram* program = |
| 2476 GetVideoStreamTextureProgram(tex_coord_precision); | 2460 GetVideoStreamTextureProgram(tex_coord_precision); |
| 2477 SetUseProgram(program->program()); | 2461 SetUseProgram(program->program()); |
| 2478 | 2462 |
| 2479 ToGLMatrix(&gl_matrix[0], quad->matrix); | 2463 ToGLMatrix(&gl_matrix[0], quad->matrix); |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2903 | 2887 |
| 2904 TRACE_EVENT0("cc,benchmark", "GLRenderer::SwapBuffers"); | 2888 TRACE_EVENT0("cc,benchmark", "GLRenderer::SwapBuffers"); |
| 2905 // We're done! Time to swapbuffers! | 2889 // We're done! Time to swapbuffers! |
| 2906 | 2890 |
| 2907 gfx::Size surface_size = output_surface_->SurfaceSize(); | 2891 gfx::Size surface_size = output_surface_->SurfaceSize(); |
| 2908 | 2892 |
| 2909 CompositorFrame compositor_frame; | 2893 CompositorFrame compositor_frame; |
| 2910 compositor_frame.metadata = std::move(metadata); | 2894 compositor_frame.metadata = std::move(metadata); |
| 2911 compositor_frame.gl_frame_data = base::WrapUnique(new GLFrameData); | 2895 compositor_frame.gl_frame_data = base::WrapUnique(new GLFrameData); |
| 2912 compositor_frame.gl_frame_data->size = surface_size; | 2896 compositor_frame.gl_frame_data->size = surface_size; |
| 2913 if (capabilities_.using_partial_swap) { | 2897 if (use_partial_swap_) { |
| 2914 // If supported, we can save significant bandwidth by only swapping the | 2898 // If supported, we can save significant bandwidth by only swapping the |
| 2915 // damaged/scissored region (clamped to the viewport). | 2899 // damaged/scissored region (clamped to the viewport). |
| 2916 swap_buffer_rect_.Intersect(gfx::Rect(surface_size)); | 2900 swap_buffer_rect_.Intersect(gfx::Rect(surface_size)); |
| 2917 int flipped_y_pos_of_rect_bottom = surface_size.height() - | 2901 int flipped_y_pos_of_rect_bottom = surface_size.height() - |
| 2918 swap_buffer_rect_.y() - | 2902 swap_buffer_rect_.y() - |
| 2919 swap_buffer_rect_.height(); | 2903 swap_buffer_rect_.height(); |
| 2920 compositor_frame.gl_frame_data->sub_buffer_rect = | 2904 compositor_frame.gl_frame_data->sub_buffer_rect = |
| 2921 gfx::Rect(swap_buffer_rect_.x(), | 2905 gfx::Rect(swap_buffer_rect_.x(), |
| 2922 FlippedRootFramebuffer() ? flipped_y_pos_of_rect_bottom | 2906 FlippedRootFramebuffer() ? flipped_y_pos_of_rect_bottom |
| 2923 : swap_buffer_rect_.y(), | 2907 : swap_buffer_rect_.y(), |
| 2924 swap_buffer_rect_.width(), swap_buffer_rect_.height()); | 2908 swap_buffer_rect_.width(), swap_buffer_rect_.height()); |
| 2925 } else { | 2909 } else { |
| 2926 // Expand the swap rect to the full surface unless it's empty, and empty | 2910 // Expand the swap rect to the full surface unless it's empty, and empty |
| 2927 // swap is allowed. | 2911 // swap is allowed. |
| 2928 if (!swap_buffer_rect_.IsEmpty() || !capabilities_.allow_empty_swap) { | 2912 if (!swap_buffer_rect_.IsEmpty() || !allow_empty_swap_) { |
| 2929 swap_buffer_rect_ = gfx::Rect(surface_size); | 2913 swap_buffer_rect_ = gfx::Rect(surface_size); |
| 2930 } | 2914 } |
| 2931 compositor_frame.gl_frame_data->sub_buffer_rect = swap_buffer_rect_; | 2915 compositor_frame.gl_frame_data->sub_buffer_rect = swap_buffer_rect_; |
| 2932 } | 2916 } |
| 2933 | 2917 |
| 2934 swapping_overlay_resources_.push_back(std::move(pending_overlay_resources_)); | 2918 swapping_overlay_resources_.push_back(std::move(pending_overlay_resources_)); |
| 2935 pending_overlay_resources_.clear(); | 2919 pending_overlay_resources_.clear(); |
| 2936 | 2920 |
| 2937 // We always hold onto resources until an extra frame has swapped, to make | 2921 // We always hold onto resources until an extra frame has swapped, to make |
| 2938 // sure we don't update the buffer while it's being scanned out. | 2922 // sure we don't update the buffer while it's being scanned out. |
| (...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4054 | 4038 |
| 4055 gl_->ScheduleCALayerSharedStateCHROMIUM( | 4039 gl_->ScheduleCALayerSharedStateCHROMIUM( |
| 4056 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, | 4040 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, |
| 4057 sorting_context_id, gl_transform); | 4041 sorting_context_id, gl_transform); |
| 4058 gl_->ScheduleCALayerCHROMIUM( | 4042 gl_->ScheduleCALayerCHROMIUM( |
| 4059 texture_id, contents_rect, ca_layer_overlay->background_color, | 4043 texture_id, contents_rect, ca_layer_overlay->background_color, |
| 4060 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 4044 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
| 4061 } | 4045 } |
| 4062 | 4046 |
| 4063 } // namespace cc | 4047 } // namespace cc |
| OLD | NEW |