Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 1325433003: command_buffer: Add support for creating non-WebGL ES 3 contexts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 844
845 bool EnsureGPUMemoryAvailable(size_t estimated_size) { 845 bool EnsureGPUMemoryAvailable(size_t estimated_size) {
846 MemoryTracker* tracker = memory_tracker(); 846 MemoryTracker* tracker = memory_tracker();
847 if (tracker) { 847 if (tracker) {
848 return tracker->EnsureGPUMemoryAvailable(estimated_size); 848 return tracker->EnsureGPUMemoryAvailable(estimated_size);
849 } 849 }
850 return true; 850 return true;
851 } 851 }
852 852
853 bool IsWebGLContext() const { 853 bool IsWebGLContext() const {
854 return webgl_version_ == 1 || webgl_version_ == 2; 854 return context_type_ == ContextGroup::CONTEXT_TYPE_WEBGL1 ||
855 context_type_ == ContextGroup::CONTEXT_TYPE_WEBGL2;
855 } 856 }
856 857
857 bool IsOffscreenBufferMultisampled() const { 858 bool IsOffscreenBufferMultisampled() const {
858 return offscreen_target_samples_ > 1; 859 return offscreen_target_samples_ > 1;
859 } 860 }
860 861
861 // Creates a Texture for the given texture. 862 // Creates a Texture for the given texture.
862 TextureRef* CreateTexture( 863 TextureRef* CreateTexture(
863 GLuint client_id, GLuint service_id) { 864 GLuint client_id, GLuint service_id) {
864 return texture_manager()->CreateTexture(client_id, service_id); 865 return texture_manager()->CreateTexture(client_id, service_id);
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 2036
2036 // Number of commands remaining to be processed in DoCommands(). 2037 // Number of commands remaining to be processed in DoCommands().
2037 int commands_to_process_; 2038 int commands_to_process_;
2038 2039
2039 bool has_robustness_extension_; 2040 bool has_robustness_extension_;
2040 error::ContextLostReason context_lost_reason_; 2041 error::ContextLostReason context_lost_reason_;
2041 bool context_was_lost_; 2042 bool context_was_lost_;
2042 bool reset_by_robustness_extension_; 2043 bool reset_by_robustness_extension_;
2043 bool supports_post_sub_buffer_; 2044 bool supports_post_sub_buffer_;
2044 2045
2045 // Indicates whether this is a context for WebGL1, WebGL2, or others. 2046 ContextGroup::ContextType context_type_;
2046 // 0: other types
2047 // 1: WebGL 1
2048 // 2: WebGL 2
2049 unsigned webgl_version_;
2050 2047
2051 // These flags are used to override the state of the shared feature_info_ 2048 // These flags are used to override the state of the shared feature_info_
2052 // member. Because the same FeatureInfo instance may be shared among many 2049 // member. Because the same FeatureInfo instance may be shared among many
2053 // contexts, the assumptions on the availablity of extensions in WebGL 2050 // contexts, the assumptions on the availablity of extensions in WebGL
2054 // contexts may be broken. These flags override the shared state to preserve 2051 // contexts may be broken. These flags override the shared state to preserve
2055 // WebGL semantics. 2052 // WebGL semantics.
2056 bool derivatives_explicitly_enabled_; 2053 bool derivatives_explicitly_enabled_;
2057 bool frag_depth_explicitly_enabled_; 2054 bool frag_depth_explicitly_enabled_;
2058 bool draw_buffers_explicitly_enabled_; 2055 bool draw_buffers_explicitly_enabled_;
2059 bool shader_texture_lod_explicitly_enabled_; 2056 bool shader_texture_lod_explicitly_enabled_;
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
2581 current_decoder_error_(error::kNoError), 2578 current_decoder_error_(error::kNoError),
2582 use_shader_translator_(true), 2579 use_shader_translator_(true),
2583 validators_(group_->feature_info()->validators()), 2580 validators_(group_->feature_info()->validators()),
2584 feature_info_(group_->feature_info()), 2581 feature_info_(group_->feature_info()),
2585 frame_number_(0), 2582 frame_number_(0),
2586 has_robustness_extension_(false), 2583 has_robustness_extension_(false),
2587 context_lost_reason_(error::kUnknown), 2584 context_lost_reason_(error::kUnknown),
2588 context_was_lost_(false), 2585 context_was_lost_(false),
2589 reset_by_robustness_extension_(false), 2586 reset_by_robustness_extension_(false),
2590 supports_post_sub_buffer_(false), 2587 supports_post_sub_buffer_(false),
2591 webgl_version_(0), 2588 context_type_(ContextGroup::CONTEXT_TYPE_OPENGLES2),
2592 derivatives_explicitly_enabled_(false), 2589 derivatives_explicitly_enabled_(false),
2593 frag_depth_explicitly_enabled_(false), 2590 frag_depth_explicitly_enabled_(false),
2594 draw_buffers_explicitly_enabled_(false), 2591 draw_buffers_explicitly_enabled_(false),
2595 shader_texture_lod_explicitly_enabled_(false), 2592 shader_texture_lod_explicitly_enabled_(false),
2596 compile_shader_always_succeeds_(false), 2593 compile_shader_always_succeeds_(false),
2597 lose_context_when_out_of_memory_(false), 2594 lose_context_when_out_of_memory_(false),
2598 service_logging_(base::CommandLine::InitializedForCurrentProcess() 2595 service_logging_(base::CommandLine::InitializedForCurrentProcess()
2599 ? base::CommandLine::ForCurrentProcess()->HasSwitch( 2596 ? base::CommandLine::ForCurrentProcess()->HasSwitch(
2600 switches::kEnableGPUServiceLoggingGPU) 2597 switches::kEnableGPUServiceLoggingGPU)
2601 : false), 2598 : false),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2643 const DisallowedFeatures& disallowed_features, 2640 const DisallowedFeatures& disallowed_features,
2644 const std::vector<int32>& attribs) { 2641 const std::vector<int32>& attribs) {
2645 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); 2642 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize");
2646 DCHECK(context->IsCurrent(surface.get())); 2643 DCHECK(context->IsCurrent(surface.get()));
2647 DCHECK(!context_.get()); 2644 DCHECK(!context_.get());
2648 DCHECK(!offscreen || !offscreen_size.IsEmpty()); 2645 DCHECK(!offscreen || !offscreen_size.IsEmpty());
2649 2646
2650 ContextCreationAttribHelper attrib_parser; 2647 ContextCreationAttribHelper attrib_parser;
2651 if (!attrib_parser.Parse(attribs)) 2648 if (!attrib_parser.Parse(attribs))
2652 return false; 2649 return false;
2653 webgl_version_ = attrib_parser.webgl_version; 2650
2651 switch (attrib_parser.context_type) {
2652 case ContextCreationAttribHelper::CONTEXT_TYPE_WEBGL1:
2653 context_type_ = ContextGroup::CONTEXT_TYPE_WEBGL1;
2654 break;
2655 case ContextCreationAttribHelper::CONTEXT_TYPE_WEBGL2:
2656 context_type_ = ContextGroup::CONTEXT_TYPE_WEBGL2;
2657 break;
2658 default:
Zhenyao Mo 2015/08/28 17:16:25 nit: can you move default to the last?
2659 NOTREACHED();
2660 case ContextCreationAttribHelper::CONTEXT_TYPE_OPENGLES2:
2661 context_type_ = ContextGroup::CONTEXT_TYPE_OPENGLES2;
2662 break;
2663 case ContextCreationAttribHelper::CONTEXT_TYPE_OPENGLES3:
2664 context_type_ = ContextGroup::CONTEXT_TYPE_OPENGLES3;
2665 break;
2666 }
2654 2667
2655 surfaceless_ = surface->IsSurfaceless() && !offscreen; 2668 surfaceless_ = surface->IsSurfaceless() && !offscreen;
2656 2669
2657 set_initialized(); 2670 set_initialized();
2658 gpu_state_tracer_ = GPUStateTracer::Create(&state_); 2671 gpu_state_tracer_ = GPUStateTracer::Create(&state_);
2659 2672
2660 if (base::CommandLine::InitializedForCurrentProcess()) { 2673 if (base::CommandLine::InitializedForCurrentProcess()) {
2661 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2674 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2662 switches::kEnableGPUDebugging)) { 2675 switches::kEnableGPUDebugging)) {
2663 set_debug(true); 2676 set_debug(true);
(...skipping 30 matching lines...) Expand all
2694 // If the failIfMajorPerformanceCaveat context creation attribute was true 2707 // If the failIfMajorPerformanceCaveat context creation attribute was true
2695 // and we are using a software renderer, fail. 2708 // and we are using a software renderer, fail.
2696 if (attrib_parser.fail_if_major_perf_caveat && 2709 if (attrib_parser.fail_if_major_perf_caveat &&
2697 feature_info_->feature_flags().is_swiftshader) { 2710 feature_info_->feature_flags().is_swiftshader) {
2698 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. 2711 group_ = NULL; // Must not destroy ContextGroup if it is not initialized.
2699 Destroy(true); 2712 Destroy(true);
2700 return false; 2713 return false;
2701 } 2714 }
2702 2715
2703 disallowed_features_ = disallowed_features; 2716 disallowed_features_ = disallowed_features;
2704 if (webgl_version_ == 1) { 2717 if (context_type_ == ContextGroup::CONTEXT_TYPE_WEBGL1) {
2705 disallowed_features_.npot_support = true; 2718 disallowed_features_.npot_support = true;
2706 } 2719 }
2707 2720
2708 if (!group_->Initialize(this, 2721 if (!group_->Initialize(this, context_type_, disallowed_features_)) {
2709 ContextGroup::GetContextType(webgl_version_),
2710 disallowed_features_)) {
2711 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. 2722 group_ = NULL; // Must not destroy ContextGroup if it is not initialized.
2712 Destroy(true); 2723 Destroy(true);
2713 return false; 2724 return false;
2714 } 2725 }
2715 CHECK_GL_ERROR(); 2726 CHECK_GL_ERROR();
2716 2727 if (context_type_ == ContextGroup::CONTEXT_TYPE_WEBGL2 ||
2717 if (webgl_version_ == 2) { 2728 context_type_ == ContextGroup::CONTEXT_TYPE_OPENGLES3) {
2718 if (!feature_info_->IsES3Capable()) { 2729 if (!feature_info_->IsES3Capable()) {
2719 LOG(ERROR) << "Underlying driver does not support ES3."; 2730 LOG(ERROR) << "Underlying driver does not support ES3.";
2720 Destroy(true); 2731 Destroy(true);
2721 return false; 2732 return false;
2722 } 2733 }
2723 feature_info_->EnableES3Validators(); 2734 feature_info_->EnableES3Validators();
2724 set_unsafe_es3_apis_enabled(true); 2735 set_unsafe_es3_apis_enabled(true);
2725 } 2736 }
2726 2737
2727 state_.attrib_values.resize(group_->max_vertex_attribs()); 2738 state_.attrib_values.resize(group_->max_vertex_attribs());
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
3277 features().ext_draw_buffers ? 1 : 0; 3288 features().ext_draw_buffers ? 1 : 0;
3278 resources.EXT_frag_depth = 3289 resources.EXT_frag_depth =
3279 features().ext_frag_depth ? 1 : 0; 3290 features().ext_frag_depth ? 1 : 0;
3280 resources.EXT_shader_texture_lod = 3291 resources.EXT_shader_texture_lod =
3281 features().ext_shader_texture_lod ? 1 : 0; 3292 features().ext_shader_texture_lod ? 1 : 0;
3282 resources.NV_draw_buffers = 3293 resources.NV_draw_buffers =
3283 features().nv_draw_buffers ? 1 : 0; 3294 features().nv_draw_buffers ? 1 : 0;
3284 } 3295 }
3285 3296
3286 ShShaderSpec shader_spec; 3297 ShShaderSpec shader_spec;
3287 if (IsWebGLContext()) { 3298 switch (context_type_) {
3288 shader_spec = webgl_version_ == 2 ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC; 3299 case ContextGroup::CONTEXT_TYPE_WEBGL1:
3289 } else { 3300 shader_spec = SH_WEBGL_SPEC;
3290 shader_spec = unsafe_es3_apis_enabled() ? SH_GLES3_SPEC : SH_GLES2_SPEC; 3301 break;
3302 case ContextGroup::CONTEXT_TYPE_WEBGL2:
3303 shader_spec = SH_WEBGL2_SPEC;
3304 break;
3305 default:
Zhenyao Mo 2015/08/28 17:16:25 nit: move default to the last.
Kimmo Kinnunen 2015/08/31 12:23:13 Done.
3306 NOTREACHED();
3307 case ContextGroup::CONTEXT_TYPE_OPENGLES2:
3308 shader_spec = SH_GLES2_SPEC;
3309 break;
3310 case ContextGroup::CONTEXT_TYPE_OPENGLES3:
3311 shader_spec = SH_GLES3_SPEC;
3312 break;
3291 } 3313 }
3292 3314
3293 if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) && 3315 if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) &&
3294 features().enable_shader_name_hashing) 3316 features().enable_shader_name_hashing)
3295 resources.HashFunction = &CityHash64; 3317 resources.HashFunction = &CityHash64;
3296 else 3318 else
3297 resources.HashFunction = NULL; 3319 resources.HashFunction = NULL;
3298 3320
3299 int driver_bug_workarounds = 0; 3321 int driver_bug_workarounds = 0;
3300 if (workarounds().needs_glsl_built_in_function_emulation) 3322 if (workarounds().needs_glsl_built_in_function_emulation)
(...skipping 12141 matching lines...) Expand 10 before | Expand all | Expand 10 after
15442 return error::kNoError; 15464 return error::kNoError;
15443 } 15465 }
15444 15466
15445 // Include the auto-generated part of this file. We split this because it means 15467 // Include the auto-generated part of this file. We split this because it means
15446 // we can easily edit the non-auto generated parts right here in this file 15468 // we can easily edit the non-auto generated parts right here in this file
15447 // instead of having to edit some template or the code generator. 15469 // instead of having to edit some template or the code generator.
15448 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 15470 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
15449 15471
15450 } // namespace gles2 15472 } // namespace gles2
15451 } // namespace gpu 15473 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698