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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 | 295 |
296 gpu::gles2::GLES2Interface* gl_; | 296 gpu::gles2::GLES2Interface* gl_; |
297 unsigned query_id_; | 297 unsigned query_id_; |
298 bool is_pending_; | 298 bool is_pending_; |
299 base::WeakPtrFactory<SyncQuery> weak_ptr_factory_; | 299 base::WeakPtrFactory<SyncQuery> weak_ptr_factory_; |
300 | 300 |
301 DISALLOW_COPY_AND_ASSIGN(SyncQuery); | 301 DISALLOW_COPY_AND_ASSIGN(SyncQuery); |
302 }; | 302 }; |
303 | 303 |
304 std::unique_ptr<GLRenderer> GLRenderer::Create( | 304 std::unique_ptr<GLRenderer> GLRenderer::Create( |
305 RendererClient* client, | 305 DirectRendererClient* client, |
306 const RendererSettings* settings, | 306 const RendererSettings* settings, |
307 OutputSurface* output_surface, | 307 OutputSurface* output_surface, |
308 ResourceProvider* resource_provider, | 308 ResourceProvider* resource_provider, |
309 TextureMailboxDeleter* texture_mailbox_deleter, | 309 TextureMailboxDeleter* texture_mailbox_deleter, |
310 int highp_threshold_min) { | 310 int highp_threshold_min) { |
311 return base::WrapUnique( | 311 return base::WrapUnique( |
312 new GLRenderer(client, settings, output_surface, resource_provider, | 312 new GLRenderer(client, settings, output_surface, resource_provider, |
313 texture_mailbox_deleter, highp_threshold_min)); | 313 texture_mailbox_deleter, highp_threshold_min)); |
314 } | 314 } |
315 | 315 |
316 GLRenderer::GLRenderer(RendererClient* client, | 316 GLRenderer::GLRenderer(DirectRendererClient* client, |
317 const RendererSettings* settings, | 317 const RendererSettings* settings, |
318 OutputSurface* output_surface, | 318 OutputSurface* output_surface, |
319 ResourceProvider* resource_provider, | 319 ResourceProvider* resource_provider, |
320 TextureMailboxDeleter* texture_mailbox_deleter, | 320 TextureMailboxDeleter* texture_mailbox_deleter, |
321 int highp_threshold_min) | 321 int highp_threshold_min) |
322 : DirectRenderer(client, settings, output_surface, resource_provider), | 322 : DirectRenderer(client, settings, output_surface, resource_provider), |
323 offscreen_framebuffer_id_(0), | 323 offscreen_framebuffer_id_(0), |
324 shared_geometry_quad_(QuadVertexRect()), | 324 shared_geometry_quad_(QuadVertexRect()), |
325 gl_(output_surface->context_provider()->ContextGL()), | 325 gl_(output_surface->context_provider()->ContextGL()), |
326 context_support_(output_surface->context_provider()->ContextSupport()), | 326 context_support_(output_surface->context_provider()->ContextSupport()), |
327 texture_mailbox_deleter_(texture_mailbox_deleter), | 327 texture_mailbox_deleter_(texture_mailbox_deleter), |
328 is_backbuffer_discarded_(false), | |
329 is_scissor_enabled_(false), | 328 is_scissor_enabled_(false), |
330 scissor_rect_needs_reset_(true), | 329 scissor_rect_needs_reset_(true), |
331 stencil_shadow_(false), | 330 stencil_shadow_(false), |
332 blend_shadow_(false), | 331 blend_shadow_(false), |
333 highp_threshold_min_(highp_threshold_min), | 332 highp_threshold_min_(highp_threshold_min), |
334 highp_threshold_cache_(0), | 333 highp_threshold_cache_(0), |
335 use_sync_query_(false), | 334 use_sync_query_(false), |
336 bound_geometry_(NO_BINDING) { | 335 bound_geometry_(NO_BINDING) { |
337 DCHECK(gl_); | 336 DCHECK(gl_); |
338 DCHECK(context_support_); | 337 DCHECK(context_support_); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 pending_async_read_pixels_.pop_back(); | 383 pending_async_read_pixels_.pop_back(); |
385 } | 384 } |
386 | 385 |
387 CleanupSharedObjects(); | 386 CleanupSharedObjects(); |
388 } | 387 } |
389 | 388 |
390 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { | 389 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { |
391 return capabilities_; | 390 return capabilities_; |
392 } | 391 } |
393 | 392 |
394 void GLRenderer::DidChangeVisibility() { | |
395 EnforceMemoryPolicy(); | |
396 | |
397 // If we are not visible, we ask the context to aggressively free resources. | |
398 context_support_->SetAggressivelyFreeResources(!visible()); | |
399 } | |
400 | |
401 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } | 393 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } |
402 | 394 |
403 void GLRenderer::DiscardPixels() { | 395 void GLRenderer::DiscardPixels() { |
404 if (!capabilities_.using_discard_framebuffer) | 396 if (!capabilities_.using_discard_framebuffer) |
405 return; | 397 return; |
406 bool using_default_framebuffer = | 398 bool using_default_framebuffer = |
407 !current_framebuffer_lock_ && | 399 !current_framebuffer_lock_ && |
408 output_surface_->capabilities().uses_default_gl_framebuffer; | 400 output_surface_->capabilities().uses_default_gl_framebuffer; |
409 GLenum attachments[] = {static_cast<GLenum>( | 401 GLenum attachments[] = {static_cast<GLenum>( |
410 using_default_framebuffer ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0_EXT)}; | 402 using_default_framebuffer ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0_EXT)}; |
(...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2707 PrepareGeometry(SHARED_BINDING); | 2699 PrepareGeometry(SHARED_BINDING); |
2708 gfx::Transform quad_rect_matrix; | 2700 gfx::Transform quad_rect_matrix; |
2709 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); | 2701 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); |
2710 static float gl_matrix[16]; | 2702 static float gl_matrix[16]; |
2711 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); | 2703 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); |
2712 gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0]); | 2704 gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0]); |
2713 | 2705 |
2714 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 2706 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
2715 } | 2707 } |
2716 | 2708 |
2717 void GLRenderer::Finish() { | |
2718 TRACE_EVENT0("cc", "GLRenderer::Finish"); | |
2719 gl_->Finish(); | |
2720 } | |
2721 | |
2722 void GLRenderer::SwapBuffers(CompositorFrameMetadata metadata) { | 2709 void GLRenderer::SwapBuffers(CompositorFrameMetadata metadata) { |
2723 DCHECK(!is_backbuffer_discarded_); | |
2724 | |
2725 TRACE_EVENT0("cc,benchmark", "GLRenderer::SwapBuffers"); | 2710 TRACE_EVENT0("cc,benchmark", "GLRenderer::SwapBuffers"); |
2726 // We're done! Time to swapbuffers! | 2711 // We're done! Time to swapbuffers! |
2727 | 2712 |
2728 gfx::Size surface_size = output_surface_->SurfaceSize(); | 2713 gfx::Size surface_size = output_surface_->SurfaceSize(); |
2729 | 2714 |
2730 CompositorFrame compositor_frame; | 2715 CompositorFrame compositor_frame; |
2731 compositor_frame.metadata = std::move(metadata); | 2716 compositor_frame.metadata = std::move(metadata); |
2732 compositor_frame.gl_frame_data = base::WrapUnique(new GLFrameData); | 2717 compositor_frame.gl_frame_data = base::WrapUnique(new GLFrameData); |
2733 compositor_frame.gl_frame_data->size = surface_size; | 2718 compositor_frame.gl_frame_data->size = surface_size; |
2734 if (capabilities_.using_partial_swap) { | 2719 if (capabilities_.using_partial_swap) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2803 void GLRenderer::DidReceiveTextureInUseResponses( | 2788 void GLRenderer::DidReceiveTextureInUseResponses( |
2804 const gpu::TextureInUseResponses& responses) { | 2789 const gpu::TextureInUseResponses& responses) { |
2805 DCHECK(settings_->release_overlay_resources_after_gpu_query); | 2790 DCHECK(settings_->release_overlay_resources_after_gpu_query); |
2806 for (const gpu::TextureInUseResponse& response : responses) { | 2791 for (const gpu::TextureInUseResponse& response : responses) { |
2807 if (!response.in_use) { | 2792 if (!response.in_use) { |
2808 swapped_and_acked_overlay_resources_.erase(response.texture); | 2793 swapped_and_acked_overlay_resources_.erase(response.texture); |
2809 } | 2794 } |
2810 } | 2795 } |
2811 } | 2796 } |
2812 | 2797 |
2813 void GLRenderer::EnforceMemoryPolicy() { | |
2814 if (!visible()) { | |
2815 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); | |
2816 ReleaseRenderPassTextures(); | |
2817 DiscardBackbuffer(); | |
2818 output_surface_->context_provider()->DeleteCachedResources(); | |
2819 gl_->Flush(); | |
2820 } | |
2821 PrepareGeometry(NO_BINDING); | |
2822 } | |
2823 | |
2824 void GLRenderer::DiscardBackbuffer() { | |
2825 if (is_backbuffer_discarded_) | |
2826 return; | |
2827 | |
2828 output_surface_->DiscardBackbuffer(); | |
2829 | |
2830 is_backbuffer_discarded_ = true; | |
2831 | |
2832 // Damage tracker needs a full reset every time framebuffer is discarded. | |
2833 client_->SetFullRootLayerDamage(); | |
2834 } | |
2835 | |
2836 void GLRenderer::EnsureBackbuffer() { | |
2837 if (!is_backbuffer_discarded_) | |
2838 return; | |
2839 | |
2840 output_surface_->EnsureBackbuffer(); | |
2841 is_backbuffer_discarded_ = false; | |
2842 } | |
2843 | |
2844 void GLRenderer::GetFramebufferPixelsAsync( | 2798 void GLRenderer::GetFramebufferPixelsAsync( |
2845 const DrawingFrame* frame, | 2799 const DrawingFrame* frame, |
2846 const gfx::Rect& rect, | 2800 const gfx::Rect& rect, |
2847 std::unique_ptr<CopyOutputRequest> request) { | 2801 std::unique_ptr<CopyOutputRequest> request) { |
2848 DCHECK(!request->IsEmpty()); | 2802 DCHECK(!request->IsEmpty()); |
2849 if (request->IsEmpty()) | 2803 if (request->IsEmpty()) |
2850 return; | 2804 return; |
2851 if (rect.IsEmpty()) | 2805 if (rect.IsEmpty()) |
2852 return; | 2806 return; |
2853 | 2807 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2943 base::Closure cancelable_callback = | 2897 base::Closure cancelable_callback = |
2944 pending_async_read_pixels_.front()-> | 2898 pending_async_read_pixels_.front()-> |
2945 finished_read_pixels_callback.callback(); | 2899 finished_read_pixels_callback.callback(); |
2946 | 2900 |
2947 // Save the buffer to verify the callbacks happen in the expected order. | 2901 // Save the buffer to verify the callbacks happen in the expected order. |
2948 pending_async_read_pixels_.front()->buffer = buffer; | 2902 pending_async_read_pixels_.front()->buffer = buffer; |
2949 | 2903 |
2950 gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); | 2904 gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); |
2951 context_support_->SignalQuery(query, cancelable_callback); | 2905 context_support_->SignalQuery(query, cancelable_callback); |
2952 | 2906 |
2953 EnforceMemoryPolicy(); | 2907 // WHY??? |
enne (OOO)
2016/08/08 21:41:18
This doesn't seem needed to me, but feel free to r
| |
2908 PrepareGeometry(NO_BINDING); | |
2954 } | 2909 } |
2955 | 2910 |
2956 void GLRenderer::FinishedReadback(unsigned source_buffer, | 2911 void GLRenderer::FinishedReadback(unsigned source_buffer, |
2957 unsigned query, | 2912 unsigned query, |
2958 const gfx::Size& size) { | 2913 const gfx::Size& size) { |
2959 DCHECK(!pending_async_read_pixels_.empty()); | 2914 DCHECK(!pending_async_read_pixels_.empty()); |
2960 | 2915 |
2961 if (query != 0) { | 2916 if (query != 0) { |
2962 gl_->DeleteQueriesEXT(1, &query); | 2917 gl_->DeleteQueriesEXT(1, &query); |
2963 } | 2918 } |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3777 resource_provider_, contents_texture->id())); | 3732 resource_provider_, contents_texture->id())); |
3778 source_texture = source->texture_id(); | 3733 source_texture = source->texture_id(); |
3779 } | 3734 } |
3780 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0, | 3735 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0, |
3781 0, contents_texture->size().width(), | 3736 0, contents_texture->size().width(), |
3782 contents_texture->size().height(), GL_TRUE, | 3737 contents_texture->size().height(), GL_TRUE, |
3783 GL_FALSE, GL_FALSE); | 3738 GL_FALSE, GL_FALSE); |
3784 } | 3739 } |
3785 | 3740 |
3786 } // namespace cc | 3741 } // namespace cc |
OLD | NEW |