| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 | 834 |
| 835 bool EnsureGPUMemoryAvailable(size_t estimated_size) { | 835 bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
| 836 MemoryTracker* tracker = memory_tracker(); | 836 MemoryTracker* tracker = memory_tracker(); |
| 837 if (tracker) { | 837 if (tracker) { |
| 838 return tracker->EnsureGPUMemoryAvailable(estimated_size); | 838 return tracker->EnsureGPUMemoryAvailable(estimated_size); |
| 839 } | 839 } |
| 840 return true; | 840 return true; |
| 841 } | 841 } |
| 842 | 842 |
| 843 bool IsWebGLContext() const { | 843 bool IsWebGLContext() const { |
| 844 return webgl_version_ == 1 || webgl_version_ == 2; | 844 return context_type_ == CONTEXT_TYPE_WEBGL1 || |
| 845 context_type_ == CONTEXT_TYPE_WEBGL2; |
| 845 } | 846 } |
| 846 | 847 |
| 847 bool IsOffscreenBufferMultisampled() const { | 848 bool IsOffscreenBufferMultisampled() const { |
| 848 return offscreen_target_samples_ > 1; | 849 return offscreen_target_samples_ > 1; |
| 849 } | 850 } |
| 850 | 851 |
| 851 // Creates a Texture for the given texture. | 852 // Creates a Texture for the given texture. |
| 852 TextureRef* CreateTexture( | 853 TextureRef* CreateTexture( |
| 853 GLuint client_id, GLuint service_id) { | 854 GLuint client_id, GLuint service_id) { |
| 854 return texture_manager()->CreateTexture(client_id, service_id); | 855 return texture_manager()->CreateTexture(client_id, service_id); |
| (...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1999 | 2000 |
| 2000 // Number of commands remaining to be processed in DoCommands(). | 2001 // Number of commands remaining to be processed in DoCommands(). |
| 2001 int commands_to_process_; | 2002 int commands_to_process_; |
| 2002 | 2003 |
| 2003 bool has_robustness_extension_; | 2004 bool has_robustness_extension_; |
| 2004 error::ContextLostReason context_lost_reason_; | 2005 error::ContextLostReason context_lost_reason_; |
| 2005 bool context_was_lost_; | 2006 bool context_was_lost_; |
| 2006 bool reset_by_robustness_extension_; | 2007 bool reset_by_robustness_extension_; |
| 2007 bool supports_post_sub_buffer_; | 2008 bool supports_post_sub_buffer_; |
| 2008 | 2009 |
| 2009 // Indicates whether this is a context for WebGL1, WebGL2, or others. | 2010 ContextType context_type_; |
| 2010 // 0: other types | |
| 2011 // 1: WebGL 1 | |
| 2012 // 2: WebGL 2 | |
| 2013 unsigned webgl_version_; | |
| 2014 | 2011 |
| 2015 // These flags are used to override the state of the shared feature_info_ | 2012 // These flags are used to override the state of the shared feature_info_ |
| 2016 // member. Because the same FeatureInfo instance may be shared among many | 2013 // member. Because the same FeatureInfo instance may be shared among many |
| 2017 // contexts, the assumptions on the availablity of extensions in WebGL | 2014 // contexts, the assumptions on the availablity of extensions in WebGL |
| 2018 // contexts may be broken. These flags override the shared state to preserve | 2015 // contexts may be broken. These flags override the shared state to preserve |
| 2019 // WebGL semantics. | 2016 // WebGL semantics. |
| 2020 bool derivatives_explicitly_enabled_; | 2017 bool derivatives_explicitly_enabled_; |
| 2021 bool frag_depth_explicitly_enabled_; | 2018 bool frag_depth_explicitly_enabled_; |
| 2022 bool draw_buffers_explicitly_enabled_; | 2019 bool draw_buffers_explicitly_enabled_; |
| 2023 bool shader_texture_lod_explicitly_enabled_; | 2020 bool shader_texture_lod_explicitly_enabled_; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2544 backbuffer_needs_clear_bits_(0), | 2541 backbuffer_needs_clear_bits_(0), |
| 2545 current_decoder_error_(error::kNoError), | 2542 current_decoder_error_(error::kNoError), |
| 2546 validators_(group_->feature_info()->validators()), | 2543 validators_(group_->feature_info()->validators()), |
| 2547 feature_info_(group_->feature_info()), | 2544 feature_info_(group_->feature_info()), |
| 2548 frame_number_(0), | 2545 frame_number_(0), |
| 2549 has_robustness_extension_(false), | 2546 has_robustness_extension_(false), |
| 2550 context_lost_reason_(error::kUnknown), | 2547 context_lost_reason_(error::kUnknown), |
| 2551 context_was_lost_(false), | 2548 context_was_lost_(false), |
| 2552 reset_by_robustness_extension_(false), | 2549 reset_by_robustness_extension_(false), |
| 2553 supports_post_sub_buffer_(false), | 2550 supports_post_sub_buffer_(false), |
| 2554 webgl_version_(0), | 2551 context_type_(CONTEXT_TYPE_OPENGLES2), |
| 2555 derivatives_explicitly_enabled_(false), | 2552 derivatives_explicitly_enabled_(false), |
| 2556 frag_depth_explicitly_enabled_(false), | 2553 frag_depth_explicitly_enabled_(false), |
| 2557 draw_buffers_explicitly_enabled_(false), | 2554 draw_buffers_explicitly_enabled_(false), |
| 2558 shader_texture_lod_explicitly_enabled_(false), | 2555 shader_texture_lod_explicitly_enabled_(false), |
| 2559 compile_shader_always_succeeds_(false), | 2556 compile_shader_always_succeeds_(false), |
| 2560 lose_context_when_out_of_memory_(false), | 2557 lose_context_when_out_of_memory_(false), |
| 2561 service_logging_(base::CommandLine::InitializedForCurrentProcess() | 2558 service_logging_(base::CommandLine::InitializedForCurrentProcess() |
| 2562 ? base::CommandLine::ForCurrentProcess()->HasSwitch( | 2559 ? base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2563 switches::kEnableGPUServiceLoggingGPU) | 2560 switches::kEnableGPUServiceLoggingGPU) |
| 2564 : false), | 2561 : false), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2589 const DisallowedFeatures& disallowed_features, | 2586 const DisallowedFeatures& disallowed_features, |
| 2590 const std::vector<int32>& attribs) { | 2587 const std::vector<int32>& attribs) { |
| 2591 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); | 2588 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
| 2592 DCHECK(context->IsCurrent(surface.get())); | 2589 DCHECK(context->IsCurrent(surface.get())); |
| 2593 DCHECK(!context_.get()); | 2590 DCHECK(!context_.get()); |
| 2594 DCHECK(!offscreen || !offscreen_size.IsEmpty()); | 2591 DCHECK(!offscreen || !offscreen_size.IsEmpty()); |
| 2595 | 2592 |
| 2596 ContextCreationAttribHelper attrib_parser; | 2593 ContextCreationAttribHelper attrib_parser; |
| 2597 if (!attrib_parser.Parse(attribs)) | 2594 if (!attrib_parser.Parse(attribs)) |
| 2598 return false; | 2595 return false; |
| 2599 webgl_version_ = attrib_parser.webgl_version; | 2596 |
| 2597 context_type_ = attrib_parser.context_type; |
| 2600 | 2598 |
| 2601 surfaceless_ = surface->IsSurfaceless() && !offscreen; | 2599 surfaceless_ = surface->IsSurfaceless() && !offscreen; |
| 2602 | 2600 |
| 2603 set_initialized(); | 2601 set_initialized(); |
| 2604 gpu_state_tracer_ = GPUStateTracer::Create(&state_); | 2602 gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
| 2605 | 2603 |
| 2606 if (base::CommandLine::InitializedForCurrentProcess()) { | 2604 if (base::CommandLine::InitializedForCurrentProcess()) { |
| 2607 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 2605 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2608 switches::kEnableGPUDebugging)) { | 2606 switches::kEnableGPUDebugging)) { |
| 2609 set_debug(true); | 2607 set_debug(true); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2640 // If the failIfMajorPerformanceCaveat context creation attribute was true | 2638 // If the failIfMajorPerformanceCaveat context creation attribute was true |
| 2641 // and we are using a software renderer, fail. | 2639 // and we are using a software renderer, fail. |
| 2642 if (attrib_parser.fail_if_major_perf_caveat && | 2640 if (attrib_parser.fail_if_major_perf_caveat && |
| 2643 feature_info_->feature_flags().is_swiftshader) { | 2641 feature_info_->feature_flags().is_swiftshader) { |
| 2644 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2642 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
| 2645 Destroy(true); | 2643 Destroy(true); |
| 2646 return false; | 2644 return false; |
| 2647 } | 2645 } |
| 2648 | 2646 |
| 2649 disallowed_features_ = disallowed_features; | 2647 disallowed_features_ = disallowed_features; |
| 2650 if (webgl_version_ == 1) { | 2648 if (context_type_ == CONTEXT_TYPE_WEBGL1) { |
| 2651 disallowed_features_.npot_support = true; | 2649 disallowed_features_.npot_support = true; |
| 2652 } | 2650 } |
| 2653 | 2651 |
| 2654 if (!group_->Initialize(this, | 2652 if (!group_->Initialize(this, context_type_, disallowed_features_)) { |
| 2655 ContextGroup::GetContextType(webgl_version_), | |
| 2656 disallowed_features_)) { | |
| 2657 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2653 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
| 2658 Destroy(true); | 2654 Destroy(true); |
| 2659 return false; | 2655 return false; |
| 2660 } | 2656 } |
| 2661 CHECK_GL_ERROR(); | 2657 CHECK_GL_ERROR(); |
| 2662 | 2658 if (context_type_ == CONTEXT_TYPE_WEBGL2 || |
| 2663 if (webgl_version_ == 2) { | 2659 context_type_ == CONTEXT_TYPE_OPENGLES3) { |
| 2664 if (!feature_info_->IsES3Capable()) { | 2660 if (!feature_info_->IsES3Capable()) { |
| 2665 LOG(ERROR) << "Underlying driver does not support ES3."; | 2661 LOG(ERROR) << "Underlying driver does not support ES3."; |
| 2666 Destroy(true); | 2662 Destroy(true); |
| 2667 return false; | 2663 return false; |
| 2668 } | 2664 } |
| 2669 feature_info_->EnableES3Validators(); | 2665 feature_info_->EnableES3Validators(); |
| 2670 set_unsafe_es3_apis_enabled(true); | 2666 set_unsafe_es3_apis_enabled(true); |
| 2671 | 2667 |
| 2672 frag_depth_explicitly_enabled_ = true; | 2668 frag_depth_explicitly_enabled_ = true; |
| 2673 draw_buffers_explicitly_enabled_ = true; | 2669 draw_buffers_explicitly_enabled_ = true; |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3228 features().ext_draw_buffers ? 1 : 0; | 3224 features().ext_draw_buffers ? 1 : 0; |
| 3229 resources.EXT_frag_depth = | 3225 resources.EXT_frag_depth = |
| 3230 features().ext_frag_depth ? 1 : 0; | 3226 features().ext_frag_depth ? 1 : 0; |
| 3231 resources.EXT_shader_texture_lod = | 3227 resources.EXT_shader_texture_lod = |
| 3232 features().ext_shader_texture_lod ? 1 : 0; | 3228 features().ext_shader_texture_lod ? 1 : 0; |
| 3233 resources.NV_draw_buffers = | 3229 resources.NV_draw_buffers = |
| 3234 features().nv_draw_buffers ? 1 : 0; | 3230 features().nv_draw_buffers ? 1 : 0; |
| 3235 } | 3231 } |
| 3236 | 3232 |
| 3237 ShShaderSpec shader_spec; | 3233 ShShaderSpec shader_spec; |
| 3238 if (IsWebGLContext()) { | 3234 switch (context_type_) { |
| 3239 shader_spec = webgl_version_ == 2 ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC; | 3235 case CONTEXT_TYPE_WEBGL1: |
| 3240 } else { | 3236 shader_spec = SH_WEBGL_SPEC; |
| 3241 shader_spec = unsafe_es3_apis_enabled() ? SH_GLES3_SPEC : SH_GLES2_SPEC; | 3237 break; |
| 3238 case CONTEXT_TYPE_WEBGL2: |
| 3239 shader_spec = SH_WEBGL2_SPEC; |
| 3240 break; |
| 3241 case CONTEXT_TYPE_OPENGLES2: |
| 3242 shader_spec = SH_GLES2_SPEC; |
| 3243 break; |
| 3244 case CONTEXT_TYPE_OPENGLES3: |
| 3245 shader_spec = SH_GLES3_SPEC; |
| 3246 break; |
| 3247 default: |
| 3248 NOTREACHED(); |
| 3249 shader_spec = SH_GLES2_SPEC; |
| 3250 break; |
| 3242 } | 3251 } |
| 3243 | 3252 |
| 3244 if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) && | 3253 if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) && |
| 3245 features().enable_shader_name_hashing) | 3254 features().enable_shader_name_hashing) |
| 3246 resources.HashFunction = &CityHash64; | 3255 resources.HashFunction = &CityHash64; |
| 3247 else | 3256 else |
| 3248 resources.HashFunction = NULL; | 3257 resources.HashFunction = NULL; |
| 3249 | 3258 |
| 3250 int driver_bug_workarounds = 0; | 3259 int driver_bug_workarounds = 0; |
| 3251 if (workarounds().needs_glsl_built_in_function_emulation) | 3260 if (workarounds().needs_glsl_built_in_function_emulation) |
| (...skipping 11529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14781 return error::kNoError; | 14790 return error::kNoError; |
| 14782 } | 14791 } |
| 14783 | 14792 |
| 14784 // Include the auto-generated part of this file. We split this because it means | 14793 // Include the auto-generated part of this file. We split this because it means |
| 14785 // we can easily edit the non-auto generated parts right here in this file | 14794 // we can easily edit the non-auto generated parts right here in this file |
| 14786 // instead of having to edit some template or the code generator. | 14795 // instead of having to edit some template or the code generator. |
| 14787 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 14796 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 14788 | 14797 |
| 14789 } // namespace gles2 | 14798 } // namespace gles2 |
| 14790 } // namespace gpu | 14799 } // namespace gpu |
| OLD | NEW |