Chromium Code Reviews| 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 | |
| 3561 OverdrawFeedbackCallback overdraw_feedback_callback = base::Bind( | 3567 OverdrawFeedbackCallback overdraw_feedback_callback = base::Bind( |
| 3562 &GLRenderer::ProcessOverdrawFeedback, weak_ptr_factory_.GetWeakPtr(), | 3568 &GLRenderer::ProcessOverdrawFeedback, weak_ptr_factory_.GetWeakPtr(), |
| 3563 base::Owned(new std::vector<int>), arraysize(stencil_tests)); | 3569 base::Owned(new std::vector<int>), arraysize(stencil_tests)); |
| 3564 | 3570 |
| 3565 for (const auto& test : stencil_tests) { | 3571 for (const auto& test : stencil_tests) { |
| 3566 GLuint query = 0; | 3572 GLuint query = 0; |
| 3567 if (tracing_enabled) { | 3573 if (tracing_enabled) { |
| 3568 gl_->GenQueriesEXT(1, &query); | 3574 gl_->GenQueriesEXT(1, &query); |
| 3569 // TODO(reveman): Use SAMPLES_PASSED_ARB for exact amount of overdraw. | 3575 gl_->BeginQueryEXT(GL_SAMPLES_PASSED_ARB, query); |
| 3570 gl_->BeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, query); | |
| 3571 } | 3576 } |
| 3572 | 3577 |
| 3573 gl_->StencilFunc(test.func, test.ref, 0xffffffff); | 3578 gl_->StencilFunc(test.func, test.ref, 0xffffffff); |
| 3574 // Transparent color unless color-coding of overdraw is enabled. | 3579 // Transparent color unless color-coding of overdraw is enabled. |
| 3575 Float4 color = | 3580 Float4 color = |
| 3576 PremultipliedColor(settings_->show_overdraw_feedback ? test.color : 0); | 3581 PremultipliedColor(settings_->show_overdraw_feedback ? test.color : 0); |
| 3577 gl_->Uniform4fv(program->color_location(), 1, color.data); | 3582 gl_->Uniform4fv(program->color_location(), 1, color.data); |
| 3578 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 3583 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
| 3579 | 3584 |
| 3580 if (query) { | 3585 if (query) { |
| 3581 gl_->EndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT); | 3586 gl_->EndQueryEXT(GL_SAMPLES_PASSED_ARB); |
| 3582 context_support_->SignalQuery( | 3587 context_support_->SignalQuery( |
| 3583 query, | 3588 query, |
| 3584 base::Bind(overdraw_feedback_callback, query, test.multiplier)); | 3589 base::Bind(overdraw_feedback_callback, query, test.multiplier)); |
| 3585 } | 3590 } |
| 3586 } | 3591 } |
| 3587 } | 3592 } |
| 3588 | 3593 |
| 3589 void GLRenderer::ProcessOverdrawFeedback(std::vector<int>* overdraw, | 3594 void GLRenderer::ProcessOverdrawFeedback(std::vector<int>* overdraw, |
| 3590 size_t num_expected_results, | 3595 size_t num_expected_results, |
| 3591 unsigned query, | 3596 unsigned query, |
| 3592 int multiplier) { | 3597 int multiplier) { |
| 3593 unsigned result = 0; | 3598 unsigned result = 0; |
| 3594 if (query) { | 3599 if (query) { |
| 3595 gl_->GetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &result); | 3600 gl_->GetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &result); |
| 3596 DCHECK_LE(result, 1u); | |
| 3597 gl_->DeleteQueriesEXT(1, &query); | 3601 gl_->DeleteQueriesEXT(1, &query); |
| 3598 } | 3602 } |
| 3599 | 3603 |
| 3600 // Apply multiplier to get the amount of overdraw. | 3604 // Apply multiplier to get the amount of overdraw. |
| 3601 overdraw->push_back(result * multiplier); | 3605 overdraw->push_back(result * multiplier); |
| 3602 | 3606 |
| 3603 // Return early if we are expecting more results. | 3607 // Return early if we are expecting more results. |
| 3604 if (overdraw->size() < num_expected_results) | 3608 if (overdraw->size() < num_expected_results) |
| 3605 return; | 3609 return; |
| 3606 | 3610 |
| 3607 // Report the maximum amount of overdraw. | 3611 // Report GPU overdraw as a percentage of the surface size. ie. 2x overdraw |
| 3608 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3612 // for the whole screen is reported as 200. |
| 3609 *std::max_element(overdraw->begin(), overdraw->end())); | 3613 TRACE_COUNTER1( |
| 3614 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | |
| 3615 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / | |
| 3616 current_surface_size_.GetArea()); | |
|
danakj
2017/01/18 19:34:06
I don't think you can/should use a member variable
reveman
2017/01/18 20:05:28
Done.
| |
| 3610 } | 3617 } |
| 3611 | 3618 |
| 3612 } // namespace cc | 3619 } // namespace cc |
| OLD | NEW |