| 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 | 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 { | |
| 845 return context_type_ == CONTEXT_TYPE_WEBGL1 || | |
| 846 context_type_ == CONTEXT_TYPE_WEBGL2; | |
| 847 } | |
| 848 | |
| 849 bool IsOffscreenBufferMultisampled() const { | 844 bool IsOffscreenBufferMultisampled() const { |
| 850 return offscreen_target_samples_ > 1; | 845 return offscreen_target_samples_ > 1; |
| 851 } | 846 } |
| 852 | 847 |
| 853 // Creates a Texture for the given texture. | 848 // Creates a Texture for the given texture. |
| 854 TextureRef* CreateTexture( | 849 TextureRef* CreateTexture( |
| 855 GLuint client_id, GLuint service_id) { | 850 GLuint client_id, GLuint service_id) { |
| 856 return texture_manager()->CreateTexture(client_id, service_id); | 851 return texture_manager()->CreateTexture(client_id, service_id); |
| 857 } | 852 } |
| 858 | 853 |
| (...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2616 const std::vector<int32>& attribs) { | 2611 const std::vector<int32>& attribs) { |
| 2617 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); | 2612 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
| 2618 DCHECK(context->IsCurrent(surface.get())); | 2613 DCHECK(context->IsCurrent(surface.get())); |
| 2619 DCHECK(!context_.get()); | 2614 DCHECK(!context_.get()); |
| 2620 DCHECK(!offscreen || !offscreen_size.IsEmpty()); | 2615 DCHECK(!offscreen || !offscreen_size.IsEmpty()); |
| 2621 | 2616 |
| 2622 ContextCreationAttribHelper attrib_parser; | 2617 ContextCreationAttribHelper attrib_parser; |
| 2623 if (!attrib_parser.Parse(attribs)) | 2618 if (!attrib_parser.Parse(attribs)) |
| 2624 return false; | 2619 return false; |
| 2625 | 2620 |
| 2626 context_type_ = attrib_parser.context_type; | |
| 2627 | |
| 2628 surfaceless_ = surface->IsSurfaceless() && !offscreen; | 2621 surfaceless_ = surface->IsSurfaceless() && !offscreen; |
| 2629 | 2622 |
| 2630 set_initialized(); | 2623 set_initialized(); |
| 2631 gpu_state_tracer_ = GPUStateTracer::Create(&state_); | 2624 gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
| 2632 | 2625 |
| 2633 if (base::CommandLine::InitializedForCurrentProcess()) { | 2626 if (base::CommandLine::InitializedForCurrentProcess()) { |
| 2634 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 2627 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2635 switches::kEnableGPUDebugging)) { | 2628 switches::kEnableGPUDebugging)) { |
| 2636 set_debug(true); | 2629 set_debug(true); |
| 2637 } | 2630 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2667 // If the failIfMajorPerformanceCaveat context creation attribute was true | 2660 // If the failIfMajorPerformanceCaveat context creation attribute was true |
| 2668 // and we are using a software renderer, fail. | 2661 // and we are using a software renderer, fail. |
| 2669 if (attrib_parser.fail_if_major_perf_caveat && | 2662 if (attrib_parser.fail_if_major_perf_caveat && |
| 2670 feature_info_->feature_flags().is_swiftshader) { | 2663 feature_info_->feature_flags().is_swiftshader) { |
| 2671 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2664 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
| 2672 Destroy(true); | 2665 Destroy(true); |
| 2673 return false; | 2666 return false; |
| 2674 } | 2667 } |
| 2675 | 2668 |
| 2676 disallowed_features_ = disallowed_features; | 2669 disallowed_features_ = disallowed_features; |
| 2677 if (context_type_ == CONTEXT_TYPE_WEBGL1) { | 2670 if (attrib_parser.context_type == CONTEXT_TYPE_WEBGL1) { |
| 2678 disallowed_features_.npot_support = true; | 2671 disallowed_features_.npot_support = true; |
| 2679 } | 2672 } |
| 2680 | 2673 |
| 2681 if (!group_->Initialize(this, context_type_, disallowed_features_)) { | 2674 if (!group_->Initialize(this, attrib_parser.context_type, |
| 2675 disallowed_features_)) { |
| 2682 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2676 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
| 2683 Destroy(true); | 2677 Destroy(true); |
| 2684 return false; | 2678 return false; |
| 2685 } | 2679 } |
| 2686 CHECK_GL_ERROR(); | 2680 CHECK_GL_ERROR(); |
| 2687 if (context_type_ == CONTEXT_TYPE_WEBGL2 || | 2681 if (feature_info_->context_type() == CONTEXT_TYPE_WEBGL2 || |
| 2688 context_type_ == CONTEXT_TYPE_OPENGLES3) { | 2682 feature_info_->context_type() == CONTEXT_TYPE_OPENGLES3) { |
| 2689 if (!feature_info_->IsES3Capable()) { | 2683 if (!feature_info_->IsES3Capable()) { |
| 2690 LOG(ERROR) << "Underlying driver does not support ES3."; | 2684 LOG(ERROR) << "Underlying driver does not support ES3."; |
| 2691 Destroy(true); | 2685 Destroy(true); |
| 2692 return false; | 2686 return false; |
| 2693 } | 2687 } |
| 2694 feature_info_->EnableES3Validators(); | 2688 feature_info_->EnableES3Validators(); |
| 2695 set_unsafe_es3_apis_enabled(true); | 2689 set_unsafe_es3_apis_enabled(true); |
| 2696 | 2690 |
| 2697 frag_depth_explicitly_enabled_ = true; | 2691 frag_depth_explicitly_enabled_ = true; |
| 2698 draw_buffers_explicitly_enabled_ = true; | 2692 draw_buffers_explicitly_enabled_ = true; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3219 resources.MaxExpressionComplexity = 256; | 3213 resources.MaxExpressionComplexity = 256; |
| 3220 resources.MaxCallStackDepth = 256; | 3214 resources.MaxCallStackDepth = 256; |
| 3221 | 3215 |
| 3222 GLint range[2] = { 0, 0 }; | 3216 GLint range[2] = { 0, 0 }; |
| 3223 GLint precision = 0; | 3217 GLint precision = 0; |
| 3224 GetShaderPrecisionFormatImpl(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, | 3218 GetShaderPrecisionFormatImpl(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, |
| 3225 range, &precision); | 3219 range, &precision); |
| 3226 resources.FragmentPrecisionHigh = | 3220 resources.FragmentPrecisionHigh = |
| 3227 PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); | 3221 PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); |
| 3228 | 3222 |
| 3229 if (IsWebGLContext()) { | 3223 if (feature_info_->IsWebGLContext()) { |
| 3230 resources.OES_standard_derivatives = derivatives_explicitly_enabled_; | 3224 resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
| 3231 resources.EXT_frag_depth = frag_depth_explicitly_enabled_; | 3225 resources.EXT_frag_depth = frag_depth_explicitly_enabled_; |
| 3232 resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; | 3226 resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; |
| 3233 if (!draw_buffers_explicitly_enabled_) | 3227 if (!draw_buffers_explicitly_enabled_) |
| 3234 resources.MaxDrawBuffers = 1; | 3228 resources.MaxDrawBuffers = 1; |
| 3235 resources.EXT_shader_texture_lod = shader_texture_lod_explicitly_enabled_; | 3229 resources.EXT_shader_texture_lod = shader_texture_lod_explicitly_enabled_; |
| 3236 resources.NV_draw_buffers = | 3230 resources.NV_draw_buffers = |
| 3237 draw_buffers_explicitly_enabled_ && features().nv_draw_buffers; | 3231 draw_buffers_explicitly_enabled_ && features().nv_draw_buffers; |
| 3238 } else { | 3232 } else { |
| 3239 resources.OES_standard_derivatives = | 3233 resources.OES_standard_derivatives = |
| 3240 features().oes_standard_derivatives ? 1 : 0; | 3234 features().oes_standard_derivatives ? 1 : 0; |
| 3241 resources.ARB_texture_rectangle = | 3235 resources.ARB_texture_rectangle = |
| 3242 features().arb_texture_rectangle ? 1 : 0; | 3236 features().arb_texture_rectangle ? 1 : 0; |
| 3243 resources.OES_EGL_image_external = | 3237 resources.OES_EGL_image_external = |
| 3244 features().oes_egl_image_external ? 1 : 0; | 3238 features().oes_egl_image_external ? 1 : 0; |
| 3245 resources.EXT_draw_buffers = | 3239 resources.EXT_draw_buffers = |
| 3246 features().ext_draw_buffers ? 1 : 0; | 3240 features().ext_draw_buffers ? 1 : 0; |
| 3247 resources.EXT_frag_depth = | 3241 resources.EXT_frag_depth = |
| 3248 features().ext_frag_depth ? 1 : 0; | 3242 features().ext_frag_depth ? 1 : 0; |
| 3249 resources.EXT_shader_texture_lod = | 3243 resources.EXT_shader_texture_lod = |
| 3250 features().ext_shader_texture_lod ? 1 : 0; | 3244 features().ext_shader_texture_lod ? 1 : 0; |
| 3251 resources.NV_draw_buffers = | 3245 resources.NV_draw_buffers = |
| 3252 features().nv_draw_buffers ? 1 : 0; | 3246 features().nv_draw_buffers ? 1 : 0; |
| 3253 } | 3247 } |
| 3254 | 3248 |
| 3255 ShShaderSpec shader_spec; | 3249 ShShaderSpec shader_spec; |
| 3256 switch (context_type_) { | 3250 switch (feature_info_->context_type()) { |
| 3257 case CONTEXT_TYPE_WEBGL1: | 3251 case CONTEXT_TYPE_WEBGL1: |
| 3258 shader_spec = SH_WEBGL_SPEC; | 3252 shader_spec = SH_WEBGL_SPEC; |
| 3259 break; | 3253 break; |
| 3260 case CONTEXT_TYPE_WEBGL2: | 3254 case CONTEXT_TYPE_WEBGL2: |
| 3261 shader_spec = SH_WEBGL2_SPEC; | 3255 shader_spec = SH_WEBGL2_SPEC; |
| 3262 break; | 3256 break; |
| 3263 case CONTEXT_TYPE_OPENGLES2: | 3257 case CONTEXT_TYPE_OPENGLES2: |
| 3264 shader_spec = SH_GLES2_SPEC; | 3258 shader_spec = SH_GLES2_SPEC; |
| 3265 break; | 3259 break; |
| 3266 case CONTEXT_TYPE_OPENGLES3: | 3260 case CONTEXT_TYPE_OPENGLES3: |
| (...skipping 5732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8999 accepted_types.push_back(GL_FLOAT); | 8993 accepted_types.push_back(GL_FLOAT); |
| 9000 } | 8994 } |
| 9001 break; | 8995 break; |
| 9002 default: | 8996 default: |
| 9003 accepted_types.push_back(GL_UNSIGNED_BYTE); | 8997 accepted_types.push_back(GL_UNSIGNED_BYTE); |
| 9004 break; | 8998 break; |
| 9005 } | 8999 } |
| 9006 } | 9000 } |
| 9007 break; | 9001 break; |
| 9008 } | 9002 } |
| 9009 if (!IsWebGLContext()) { | 9003 if (!feature_info_->IsWebGLContext()) { |
| 9010 accepted_formats.push_back(GL_BGRA_EXT); | 9004 accepted_formats.push_back(GL_BGRA_EXT); |
| 9011 accepted_types.push_back(GL_UNSIGNED_BYTE); | 9005 accepted_types.push_back(GL_UNSIGNED_BYTE); |
| 9012 } | 9006 } |
| 9013 DCHECK_EQ(accepted_formats.size(), accepted_types.size()); | 9007 DCHECK_EQ(accepted_formats.size(), accepted_types.size()); |
| 9014 bool format_type_acceptable = false; | 9008 bool format_type_acceptable = false; |
| 9015 for (size_t ii = 0; ii < accepted_formats.size(); ++ii) { | 9009 for (size_t ii = 0; ii < accepted_formats.size(); ++ii) { |
| 9016 if (format == accepted_formats[ii] && type == accepted_types[ii]) { | 9010 if (format == accepted_formats[ii] && type == accepted_types[ii]) { |
| 9017 format_type_acceptable = true; | 9011 format_type_acceptable = true; |
| 9018 break; | 9012 break; |
| 9019 } | 9013 } |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9500 case GL_SHADING_LANGUAGE_VERSION: | 9494 case GL_SHADING_LANGUAGE_VERSION: |
| 9501 if (unsafe_es3_apis_enabled()) | 9495 if (unsafe_es3_apis_enabled()) |
| 9502 str = "OpenGL ES GLSL ES 3.0 Chromium"; | 9496 str = "OpenGL ES GLSL ES 3.0 Chromium"; |
| 9503 else | 9497 else |
| 9504 str = "OpenGL ES GLSL ES 1.0 Chromium"; | 9498 str = "OpenGL ES GLSL ES 1.0 Chromium"; |
| 9505 break; | 9499 break; |
| 9506 case GL_RENDERER: | 9500 case GL_RENDERER: |
| 9507 case GL_VENDOR: | 9501 case GL_VENDOR: |
| 9508 // Return the unmasked VENDOR/RENDERER string for WebGL contexts. | 9502 // Return the unmasked VENDOR/RENDERER string for WebGL contexts. |
| 9509 // They are used by WEBGL_debug_renderer_info. | 9503 // They are used by WEBGL_debug_renderer_info. |
| 9510 if (!IsWebGLContext()) | 9504 if (!feature_info_->IsWebGLContext()) |
| 9511 str = "Chromium"; | 9505 str = "Chromium"; |
| 9512 else | 9506 else |
| 9513 str = reinterpret_cast<const char*>(glGetString(name)); | 9507 str = reinterpret_cast<const char*>(glGetString(name)); |
| 9514 break; | 9508 break; |
| 9515 case GL_EXTENSIONS: | 9509 case GL_EXTENSIONS: |
| 9516 { | 9510 { |
| 9517 // For WebGL contexts, strip out the OES derivatives and | 9511 // For WebGL contexts, strip out the OES derivatives and |
| 9518 // EXT frag depth extensions if they have not been enabled. | 9512 // EXT frag depth extensions if they have not been enabled. |
| 9519 if (IsWebGLContext()) { | 9513 if (feature_info_->IsWebGLContext()) { |
| 9520 extensions = feature_info_->extensions(); | 9514 extensions = feature_info_->extensions(); |
| 9521 if (!derivatives_explicitly_enabled_) { | 9515 if (!derivatives_explicitly_enabled_) { |
| 9522 size_t offset = extensions.find(kOESDerivativeExtension); | 9516 size_t offset = extensions.find(kOESDerivativeExtension); |
| 9523 if (std::string::npos != offset) { | 9517 if (std::string::npos != offset) { |
| 9524 extensions.replace(offset, arraysize(kOESDerivativeExtension), | 9518 extensions.replace(offset, arraysize(kOESDerivativeExtension), |
| 9525 std::string()); | 9519 std::string()); |
| 9526 } | 9520 } |
| 9527 } | 9521 } |
| 9528 if (!frag_depth_explicitly_enabled_) { | 9522 if (!frag_depth_explicitly_enabled_) { |
| 9529 size_t offset = extensions.find(kEXTFragDepthExtension); | 9523 size_t offset = extensions.find(kEXTFragDepthExtension); |
| (...skipping 2426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11956 } | 11950 } |
| 11957 | 11951 |
| 11958 error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( | 11952 error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( |
| 11959 uint32 immediate_data_size, | 11953 uint32 immediate_data_size, |
| 11960 const void* cmd_data) { | 11954 const void* cmd_data) { |
| 11961 const gles2::cmds::GetRequestableExtensionsCHROMIUM& c = | 11955 const gles2::cmds::GetRequestableExtensionsCHROMIUM& c = |
| 11962 *static_cast<const gles2::cmds::GetRequestableExtensionsCHROMIUM*>( | 11956 *static_cast<const gles2::cmds::GetRequestableExtensionsCHROMIUM*>( |
| 11963 cmd_data); | 11957 cmd_data); |
| 11964 Bucket* bucket = CreateBucket(c.bucket_id); | 11958 Bucket* bucket = CreateBucket(c.bucket_id); |
| 11965 scoped_refptr<FeatureInfo> info(new FeatureInfo()); | 11959 scoped_refptr<FeatureInfo> info(new FeatureInfo()); |
| 11966 info->Initialize(disallowed_features_); | 11960 info->Initialize(feature_info_->context_type(), disallowed_features_); |
| 11967 bucket->SetFromString(info->extensions().c_str()); | 11961 bucket->SetFromString(info->extensions().c_str()); |
| 11968 return error::kNoError; | 11962 return error::kNoError; |
| 11969 } | 11963 } |
| 11970 | 11964 |
| 11971 error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( | 11965 error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( |
| 11972 uint32 immediate_data_size, | 11966 uint32 immediate_data_size, |
| 11973 const void* cmd_data) { | 11967 const void* cmd_data) { |
| 11974 const gles2::cmds::RequestExtensionCHROMIUM& c = | 11968 const gles2::cmds::RequestExtensionCHROMIUM& c = |
| 11975 *static_cast<const gles2::cmds::RequestExtensionCHROMIUM*>(cmd_data); | 11969 *static_cast<const gles2::cmds::RequestExtensionCHROMIUM*>(cmd_data); |
| 11976 Bucket* bucket = GetBucket(c.bucket_id); | 11970 Bucket* bucket = GetBucket(c.bucket_id); |
| 11977 if (!bucket || bucket->size() == 0) { | 11971 if (!bucket || bucket->size() == 0) { |
| 11978 return error::kInvalidArguments; | 11972 return error::kInvalidArguments; |
| 11979 } | 11973 } |
| 11980 std::string feature_str; | 11974 std::string feature_str; |
| 11981 if (!bucket->GetAsString(&feature_str)) { | 11975 if (!bucket->GetAsString(&feature_str)) { |
| 11982 return error::kInvalidArguments; | 11976 return error::kInvalidArguments; |
| 11983 } | 11977 } |
| 11984 | 11978 |
| 11985 bool desire_standard_derivatives = false; | 11979 bool desire_standard_derivatives = false; |
| 11986 bool desire_frag_depth = false; | 11980 bool desire_frag_depth = false; |
| 11987 bool desire_draw_buffers = false; | 11981 bool desire_draw_buffers = false; |
| 11988 bool desire_shader_texture_lod = false; | 11982 bool desire_shader_texture_lod = false; |
| 11989 if (IsWebGLContext()) { | 11983 if (feature_info_->IsWebGLContext()) { |
| 11990 desire_standard_derivatives = | 11984 desire_standard_derivatives = |
| 11991 feature_str.find("GL_OES_standard_derivatives") != std::string::npos; | 11985 feature_str.find("GL_OES_standard_derivatives") != std::string::npos; |
| 11992 desire_frag_depth = | 11986 desire_frag_depth = |
| 11993 feature_str.find("GL_EXT_frag_depth") != std::string::npos; | 11987 feature_str.find("GL_EXT_frag_depth") != std::string::npos; |
| 11994 desire_draw_buffers = | 11988 desire_draw_buffers = |
| 11995 feature_str.find("GL_EXT_draw_buffers") != std::string::npos; | 11989 feature_str.find("GL_EXT_draw_buffers") != std::string::npos; |
| 11996 desire_shader_texture_lod = | 11990 desire_shader_texture_lod = |
| 11997 feature_str.find("GL_EXT_shader_texture_lod") != std::string::npos; | 11991 feature_str.find("GL_EXT_shader_texture_lod") != std::string::npos; |
| 11998 } | 11992 } |
| 11999 | 11993 |
| (...skipping 3059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15059 return error::kNoError; | 15053 return error::kNoError; |
| 15060 } | 15054 } |
| 15061 | 15055 |
| 15062 // Include the auto-generated part of this file. We split this because it means | 15056 // Include the auto-generated part of this file. We split this because it means |
| 15063 // we can easily edit the non-auto generated parts right here in this file | 15057 // we can easily edit the non-auto generated parts right here in this file |
| 15064 // instead of having to edit some template or the code generator. | 15058 // instead of having to edit some template or the code generator. |
| 15065 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 15059 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 15066 | 15060 |
| 15067 } // namespace gles2 | 15061 } // namespace gles2 |
| 15068 } // namespace gpu | 15062 } // namespace gpu |
| OLD | NEW |