| 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> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <numeric> |
| 13 #include <set> | 14 #include <set> |
| 14 #include <string> | 15 #include <string> |
| 15 #include <vector> | 16 #include <vector> |
| 16 | 17 |
| 17 #include "base/feature_list.h" | 18 #include "base/feature_list.h" |
| 18 #include "base/logging.h" | 19 #include "base/logging.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 21 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
| 22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 397 |
| 397 const auto& context_caps = | 398 const auto& context_caps = |
| 398 output_surface_->context_provider()->ContextCapabilities(); | 399 output_surface_->context_provider()->ContextCapabilities(); |
| 399 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); | 400 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); |
| 400 | 401 |
| 401 use_discard_framebuffer_ = context_caps.discard_framebuffer; | 402 use_discard_framebuffer_ = context_caps.discard_framebuffer; |
| 402 use_sync_query_ = context_caps.sync_query; | 403 use_sync_query_ = context_caps.sync_query; |
| 403 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; | 404 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; |
| 404 use_blend_equation_advanced_coherent_ = | 405 use_blend_equation_advanced_coherent_ = |
| 405 context_caps.blend_equation_advanced_coherent; | 406 context_caps.blend_equation_advanced_coherent; |
| 407 use_occlusion_query_ = context_caps.occlusion_query; |
| 406 | 408 |
| 407 InitializeSharedObjects(); | 409 InitializeSharedObjects(); |
| 408 } | 410 } |
| 409 | 411 |
| 410 GLRenderer::~GLRenderer() { | 412 GLRenderer::~GLRenderer() { |
| 411 CleanupSharedObjects(); | 413 CleanupSharedObjects(); |
| 412 | 414 |
| 413 if (context_visibility_) { | 415 if (context_visibility_) { |
| 414 auto* context_provider = output_surface_->context_provider(); | 416 auto* context_provider = output_surface_->context_provider(); |
| 415 auto* cache_controller = context_provider->CacheController(); | 417 auto* cache_controller = context_provider->CacheController(); |
| (...skipping 3135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3551 // Occlusion queries can be expensive, so only collect trace data if we select | 3553 // Occlusion queries can be expensive, so only collect trace data if we select |
| 3552 // cc.debug.overdraw. | 3554 // cc.debug.overdraw. |
| 3553 bool tracing_enabled; | 3555 bool tracing_enabled; |
| 3554 TRACE_EVENT_CATEGORY_GROUP_ENABLED( | 3556 TRACE_EVENT_CATEGORY_GROUP_ENABLED( |
| 3555 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), &tracing_enabled); | 3557 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), &tracing_enabled); |
| 3556 | 3558 |
| 3557 // Trace only the root render pass. | 3559 // Trace only the root render pass. |
| 3558 if (frame->current_render_pass != frame->root_render_pass) | 3560 if (frame->current_render_pass != frame->root_render_pass) |
| 3559 tracing_enabled = false; | 3561 tracing_enabled = false; |
| 3560 | 3562 |
| 3563 // ARB_occlusion_query is required for tracing. |
| 3564 if (!use_occlusion_query_) |
| 3565 tracing_enabled = false; |
| 3566 |
| 3567 // Use the current surface area as max result. The effect is that overdraw |
| 3568 // is reported as a percentage of the output surface size. ie. 2x overdraw |
| 3569 // for the whole screen is reported as 200. |
| 3570 int max_result = current_surface_size_.GetArea(); |
| 3571 DCHECK_GT(max_result, 0); |
| 3572 |
| 3561 OverdrawFeedbackCallback overdraw_feedback_callback = base::Bind( | 3573 OverdrawFeedbackCallback overdraw_feedback_callback = base::Bind( |
| 3562 &GLRenderer::ProcessOverdrawFeedback, weak_ptr_factory_.GetWeakPtr(), | 3574 &GLRenderer::ProcessOverdrawFeedback, weak_ptr_factory_.GetWeakPtr(), |
| 3563 base::Owned(new std::vector<int>), arraysize(stencil_tests)); | 3575 base::Owned(new std::vector<int>), arraysize(stencil_tests), max_result); |
| 3564 | 3576 |
| 3565 for (const auto& test : stencil_tests) { | 3577 for (const auto& test : stencil_tests) { |
| 3566 GLuint query = 0; | 3578 GLuint query = 0; |
| 3567 if (tracing_enabled) { | 3579 if (tracing_enabled) { |
| 3568 gl_->GenQueriesEXT(1, &query); | 3580 gl_->GenQueriesEXT(1, &query); |
| 3569 // TODO(reveman): Use SAMPLES_PASSED_ARB for exact amount of overdraw. | 3581 gl_->BeginQueryEXT(GL_SAMPLES_PASSED_ARB, query); |
| 3570 gl_->BeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, query); | |
| 3571 } | 3582 } |
| 3572 | 3583 |
| 3573 gl_->StencilFunc(test.func, test.ref, 0xffffffff); | 3584 gl_->StencilFunc(test.func, test.ref, 0xffffffff); |
| 3574 // Transparent color unless color-coding of overdraw is enabled. | 3585 // Transparent color unless color-coding of overdraw is enabled. |
| 3575 Float4 color = | 3586 Float4 color = |
| 3576 PremultipliedColor(settings_->show_overdraw_feedback ? test.color : 0); | 3587 PremultipliedColor(settings_->show_overdraw_feedback ? test.color : 0); |
| 3577 gl_->Uniform4fv(program->color_location(), 1, color.data); | 3588 gl_->Uniform4fv(program->color_location(), 1, color.data); |
| 3578 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 3589 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
| 3579 | 3590 |
| 3580 if (query) { | 3591 if (query) { |
| 3581 gl_->EndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT); | 3592 gl_->EndQueryEXT(GL_SAMPLES_PASSED_ARB); |
| 3582 context_support_->SignalQuery( | 3593 context_support_->SignalQuery( |
| 3583 query, | 3594 query, |
| 3584 base::Bind(overdraw_feedback_callback, query, test.multiplier)); | 3595 base::Bind(overdraw_feedback_callback, query, test.multiplier)); |
| 3585 } | 3596 } |
| 3586 } | 3597 } |
| 3587 } | 3598 } |
| 3588 | 3599 |
| 3589 void GLRenderer::ProcessOverdrawFeedback(std::vector<int>* overdraw, | 3600 void GLRenderer::ProcessOverdrawFeedback(std::vector<int>* overdraw, |
| 3590 size_t num_expected_results, | 3601 size_t num_expected_results, |
| 3602 int max_result, |
| 3591 unsigned query, | 3603 unsigned query, |
| 3592 int multiplier) { | 3604 int multiplier) { |
| 3593 unsigned result = 0; | 3605 unsigned result = 0; |
| 3594 if (query) { | 3606 if (query) { |
| 3595 gl_->GetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &result); | 3607 gl_->GetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &result); |
| 3596 DCHECK_LE(result, 1u); | |
| 3597 gl_->DeleteQueriesEXT(1, &query); | 3608 gl_->DeleteQueriesEXT(1, &query); |
| 3598 } | 3609 } |
| 3599 | 3610 |
| 3600 // Apply multiplier to get the amount of overdraw. | 3611 // Apply multiplier to get the amount of overdraw. |
| 3601 overdraw->push_back(result * multiplier); | 3612 overdraw->push_back(result * multiplier); |
| 3602 | 3613 |
| 3603 // Return early if we are expecting more results. | 3614 // Return early if we are expecting more results. |
| 3604 if (overdraw->size() < num_expected_results) | 3615 if (overdraw->size() < num_expected_results) |
| 3605 return; | 3616 return; |
| 3606 | 3617 |
| 3607 // Report the maximum amount of overdraw. | 3618 // Report GPU overdraw as a percentage of |max_result|. |
| 3608 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3619 TRACE_COUNTER1( |
| 3609 *std::max_element(overdraw->begin(), overdraw->end())); | 3620 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", |
| 3621 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / |
| 3622 max_result); |
| 3610 } | 3623 } |
| 3611 | 3624 |
| 3612 } // namespace cc | 3625 } // namespace cc |
| OLD | NEW |