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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 | 835 |
836 bool EnsureGPUMemoryAvailable(size_t estimated_size) { | 836 bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
837 MemoryTracker* tracker = memory_tracker(); | 837 MemoryTracker* tracker = memory_tracker(); |
838 if (tracker) { | 838 if (tracker) { |
839 return tracker->EnsureGPUMemoryAvailable(estimated_size); | 839 return tracker->EnsureGPUMemoryAvailable(estimated_size); |
840 } | 840 } |
841 return true; | 841 return true; |
842 } | 842 } |
843 | 843 |
844 bool IsWebGLContext() const { | 844 bool IsWebGLContext() const { |
845 return webgl_version_ == 1 || webgl_version_ == 2; | 845 return context_type_ == CONTEXT_TYPE_WEBGL1 || |
| 846 context_type_ == CONTEXT_TYPE_WEBGL2; |
846 } | 847 } |
847 | 848 |
848 bool IsOffscreenBufferMultisampled() const { | 849 bool IsOffscreenBufferMultisampled() const { |
849 return offscreen_target_samples_ > 1; | 850 return offscreen_target_samples_ > 1; |
850 } | 851 } |
851 | 852 |
852 // Creates a Texture for the given texture. | 853 // Creates a Texture for the given texture. |
853 TextureRef* CreateTexture( | 854 TextureRef* CreateTexture( |
854 GLuint client_id, GLuint service_id) { | 855 GLuint client_id, GLuint service_id) { |
855 return texture_manager()->CreateTexture(client_id, service_id); | 856 return texture_manager()->CreateTexture(client_id, service_id); |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 | 2030 |
2030 // Number of commands remaining to be processed in DoCommands(). | 2031 // Number of commands remaining to be processed in DoCommands(). |
2031 int commands_to_process_; | 2032 int commands_to_process_; |
2032 | 2033 |
2033 bool has_robustness_extension_; | 2034 bool has_robustness_extension_; |
2034 error::ContextLostReason context_lost_reason_; | 2035 error::ContextLostReason context_lost_reason_; |
2035 bool context_was_lost_; | 2036 bool context_was_lost_; |
2036 bool reset_by_robustness_extension_; | 2037 bool reset_by_robustness_extension_; |
2037 bool supports_post_sub_buffer_; | 2038 bool supports_post_sub_buffer_; |
2038 | 2039 |
2039 // Indicates whether this is a context for WebGL1, WebGL2, or others. | 2040 ContextType context_type_; |
2040 // 0: other types | |
2041 // 1: WebGL 1 | |
2042 // 2: WebGL 2 | |
2043 unsigned webgl_version_; | |
2044 | 2041 |
2045 // These flags are used to override the state of the shared feature_info_ | 2042 // These flags are used to override the state of the shared feature_info_ |
2046 // member. Because the same FeatureInfo instance may be shared among many | 2043 // member. Because the same FeatureInfo instance may be shared among many |
2047 // contexts, the assumptions on the availablity of extensions in WebGL | 2044 // contexts, the assumptions on the availablity of extensions in WebGL |
2048 // contexts may be broken. These flags override the shared state to preserve | 2045 // contexts may be broken. These flags override the shared state to preserve |
2049 // WebGL semantics. | 2046 // WebGL semantics. |
2050 bool derivatives_explicitly_enabled_; | 2047 bool derivatives_explicitly_enabled_; |
2051 bool frag_depth_explicitly_enabled_; | 2048 bool frag_depth_explicitly_enabled_; |
2052 bool draw_buffers_explicitly_enabled_; | 2049 bool draw_buffers_explicitly_enabled_; |
2053 bool shader_texture_lod_explicitly_enabled_; | 2050 bool shader_texture_lod_explicitly_enabled_; |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2573 backbuffer_needs_clear_bits_(0), | 2570 backbuffer_needs_clear_bits_(0), |
2574 current_decoder_error_(error::kNoError), | 2571 current_decoder_error_(error::kNoError), |
2575 validators_(group_->feature_info()->validators()), | 2572 validators_(group_->feature_info()->validators()), |
2576 feature_info_(group_->feature_info()), | 2573 feature_info_(group_->feature_info()), |
2577 frame_number_(0), | 2574 frame_number_(0), |
2578 has_robustness_extension_(false), | 2575 has_robustness_extension_(false), |
2579 context_lost_reason_(error::kUnknown), | 2576 context_lost_reason_(error::kUnknown), |
2580 context_was_lost_(false), | 2577 context_was_lost_(false), |
2581 reset_by_robustness_extension_(false), | 2578 reset_by_robustness_extension_(false), |
2582 supports_post_sub_buffer_(false), | 2579 supports_post_sub_buffer_(false), |
2583 webgl_version_(0), | 2580 context_type_(CONTEXT_TYPE_OPENGLES2), |
2584 derivatives_explicitly_enabled_(false), | 2581 derivatives_explicitly_enabled_(false), |
2585 frag_depth_explicitly_enabled_(false), | 2582 frag_depth_explicitly_enabled_(false), |
2586 draw_buffers_explicitly_enabled_(false), | 2583 draw_buffers_explicitly_enabled_(false), |
2587 shader_texture_lod_explicitly_enabled_(false), | 2584 shader_texture_lod_explicitly_enabled_(false), |
2588 compile_shader_always_succeeds_(false), | 2585 compile_shader_always_succeeds_(false), |
2589 lose_context_when_out_of_memory_(false), | 2586 lose_context_when_out_of_memory_(false), |
2590 service_logging_(base::CommandLine::InitializedForCurrentProcess() | 2587 service_logging_(base::CommandLine::InitializedForCurrentProcess() |
2591 ? base::CommandLine::ForCurrentProcess()->HasSwitch( | 2588 ? base::CommandLine::ForCurrentProcess()->HasSwitch( |
2592 switches::kEnableGPUServiceLoggingGPU) | 2589 switches::kEnableGPUServiceLoggingGPU) |
2593 : false), | 2590 : false), |
(...skipping 22 matching lines...) Expand all Loading... |
2616 const DisallowedFeatures& disallowed_features, | 2613 const DisallowedFeatures& disallowed_features, |
2617 const std::vector<int32>& attribs) { | 2614 const std::vector<int32>& attribs) { |
2618 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); | 2615 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
2619 DCHECK(context->IsCurrent(surface.get())); | 2616 DCHECK(context->IsCurrent(surface.get())); |
2620 DCHECK(!context_.get()); | 2617 DCHECK(!context_.get()); |
2621 DCHECK(!offscreen || !offscreen_size.IsEmpty()); | 2618 DCHECK(!offscreen || !offscreen_size.IsEmpty()); |
2622 | 2619 |
2623 ContextCreationAttribHelper attrib_parser; | 2620 ContextCreationAttribHelper attrib_parser; |
2624 if (!attrib_parser.Parse(attribs)) | 2621 if (!attrib_parser.Parse(attribs)) |
2625 return false; | 2622 return false; |
2626 webgl_version_ = attrib_parser.webgl_version; | 2623 |
| 2624 context_type_ = attrib_parser.context_type; |
2627 | 2625 |
2628 surfaceless_ = surface->IsSurfaceless() && !offscreen; | 2626 surfaceless_ = surface->IsSurfaceless() && !offscreen; |
2629 | 2627 |
2630 set_initialized(); | 2628 set_initialized(); |
2631 gpu_state_tracer_ = GPUStateTracer::Create(&state_); | 2629 gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
2632 | 2630 |
2633 if (base::CommandLine::InitializedForCurrentProcess()) { | 2631 if (base::CommandLine::InitializedForCurrentProcess()) { |
2634 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 2632 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
2635 switches::kEnableGPUDebugging)) { | 2633 switches::kEnableGPUDebugging)) { |
2636 set_debug(true); | 2634 set_debug(true); |
(...skipping 30 matching lines...) Expand all Loading... |
2667 // If the failIfMajorPerformanceCaveat context creation attribute was true | 2665 // If the failIfMajorPerformanceCaveat context creation attribute was true |
2668 // and we are using a software renderer, fail. | 2666 // and we are using a software renderer, fail. |
2669 if (attrib_parser.fail_if_major_perf_caveat && | 2667 if (attrib_parser.fail_if_major_perf_caveat && |
2670 feature_info_->feature_flags().is_swiftshader) { | 2668 feature_info_->feature_flags().is_swiftshader) { |
2671 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2669 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
2672 Destroy(true); | 2670 Destroy(true); |
2673 return false; | 2671 return false; |
2674 } | 2672 } |
2675 | 2673 |
2676 disallowed_features_ = disallowed_features; | 2674 disallowed_features_ = disallowed_features; |
2677 if (webgl_version_ == 1) { | 2675 if (context_type_ == CONTEXT_TYPE_WEBGL1) { |
2678 disallowed_features_.npot_support = true; | 2676 disallowed_features_.npot_support = true; |
2679 } | 2677 } |
2680 | 2678 |
2681 if (!group_->Initialize(this, | 2679 if (!group_->Initialize(this, context_type_, disallowed_features_)) { |
2682 ContextGroup::GetContextType(webgl_version_), | |
2683 disallowed_features_)) { | |
2684 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2680 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
2685 Destroy(true); | 2681 Destroy(true); |
2686 return false; | 2682 return false; |
2687 } | 2683 } |
2688 CHECK_GL_ERROR(); | 2684 CHECK_GL_ERROR(); |
2689 | 2685 if (context_type_ == CONTEXT_TYPE_WEBGL2 || |
2690 if (webgl_version_ == 2) { | 2686 context_type_ == CONTEXT_TYPE_OPENGLES3) { |
2691 if (!feature_info_->IsES3Capable()) { | 2687 if (!feature_info_->IsES3Capable()) { |
2692 LOG(ERROR) << "Underlying driver does not support ES3."; | 2688 LOG(ERROR) << "Underlying driver does not support ES3."; |
2693 Destroy(true); | 2689 Destroy(true); |
2694 return false; | 2690 return false; |
2695 } | 2691 } |
2696 feature_info_->EnableES3Validators(); | 2692 feature_info_->EnableES3Validators(); |
2697 set_unsafe_es3_apis_enabled(true); | 2693 set_unsafe_es3_apis_enabled(true); |
2698 | 2694 |
2699 frag_depth_explicitly_enabled_ = true; | 2695 frag_depth_explicitly_enabled_ = true; |
2700 draw_buffers_explicitly_enabled_ = true; | 2696 draw_buffers_explicitly_enabled_ = true; |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3255 features().ext_draw_buffers ? 1 : 0; | 3251 features().ext_draw_buffers ? 1 : 0; |
3256 resources.EXT_frag_depth = | 3252 resources.EXT_frag_depth = |
3257 features().ext_frag_depth ? 1 : 0; | 3253 features().ext_frag_depth ? 1 : 0; |
3258 resources.EXT_shader_texture_lod = | 3254 resources.EXT_shader_texture_lod = |
3259 features().ext_shader_texture_lod ? 1 : 0; | 3255 features().ext_shader_texture_lod ? 1 : 0; |
3260 resources.NV_draw_buffers = | 3256 resources.NV_draw_buffers = |
3261 features().nv_draw_buffers ? 1 : 0; | 3257 features().nv_draw_buffers ? 1 : 0; |
3262 } | 3258 } |
3263 | 3259 |
3264 ShShaderSpec shader_spec; | 3260 ShShaderSpec shader_spec; |
3265 if (IsWebGLContext()) { | 3261 switch (context_type_) { |
3266 shader_spec = webgl_version_ == 2 ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC; | 3262 case CONTEXT_TYPE_WEBGL1: |
3267 } else { | 3263 shader_spec = SH_WEBGL_SPEC; |
3268 shader_spec = unsafe_es3_apis_enabled() ? SH_GLES3_SPEC : SH_GLES2_SPEC; | 3264 break; |
| 3265 case CONTEXT_TYPE_WEBGL2: |
| 3266 shader_spec = SH_WEBGL2_SPEC; |
| 3267 break; |
| 3268 case CONTEXT_TYPE_OPENGLES2: |
| 3269 shader_spec = SH_GLES2_SPEC; |
| 3270 break; |
| 3271 case CONTEXT_TYPE_OPENGLES3: |
| 3272 shader_spec = SH_GLES3_SPEC; |
| 3273 break; |
| 3274 default: |
| 3275 NOTREACHED(); |
| 3276 shader_spec = SH_GLES2_SPEC; |
| 3277 break; |
3269 } | 3278 } |
3270 | 3279 |
3271 if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) && | 3280 if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) && |
3272 features().enable_shader_name_hashing) | 3281 features().enable_shader_name_hashing) |
3273 resources.HashFunction = &CityHash64; | 3282 resources.HashFunction = &CityHash64; |
3274 else | 3283 else |
3275 resources.HashFunction = NULL; | 3284 resources.HashFunction = NULL; |
3276 | 3285 |
3277 int driver_bug_workarounds = 0; | 3286 int driver_bug_workarounds = 0; |
3278 if (workarounds().needs_glsl_built_in_function_emulation) | 3287 if (workarounds().needs_glsl_built_in_function_emulation) |
(...skipping 11758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15037 return error::kNoError; | 15046 return error::kNoError; |
15038 } | 15047 } |
15039 | 15048 |
15040 // Include the auto-generated part of this file. We split this because it means | 15049 // Include the auto-generated part of this file. We split this because it means |
15041 // we can easily edit the non-auto generated parts right here in this file | 15050 // we can easily edit the non-auto generated parts right here in this file |
15042 // instead of having to edit some template or the code generator. | 15051 // instead of having to edit some template or the code generator. |
15043 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 15052 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
15044 | 15053 |
15045 } // namespace gles2 | 15054 } // namespace gles2 |
15046 } // namespace gpu | 15055 } // namespace gpu |
OLD | NEW |