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 <list> | 10 #include <list> |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 GLES2Decoder::~GLES2Decoder() { | 559 GLES2Decoder::~GLES2Decoder() { |
560 } | 560 } |
561 | 561 |
562 void GLES2Decoder::BeginDecoding() {} | 562 void GLES2Decoder::BeginDecoding() {} |
563 | 563 |
564 void GLES2Decoder::EndDecoding() {} | 564 void GLES2Decoder::EndDecoding() {} |
565 | 565 |
566 // This class implements GLES2Decoder so we don't have to expose all the GLES2 | 566 // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
567 // cmd stuff to outside this class. | 567 // cmd stuff to outside this class. |
568 class GLES2DecoderImpl : public GLES2Decoder, | 568 class GLES2DecoderImpl : public GLES2Decoder, |
569 public FramebufferManager::TextureDetachObserver { | 569 public FramebufferManager::TextureDetachObserver, |
| 570 public ErrorStateClient { |
570 public: | 571 public: |
571 explicit GLES2DecoderImpl(ContextGroup* group); | 572 explicit GLES2DecoderImpl(ContextGroup* group); |
572 virtual ~GLES2DecoderImpl(); | 573 virtual ~GLES2DecoderImpl(); |
573 | 574 |
574 // Overridden from AsyncAPIInterface. | 575 // Overridden from AsyncAPIInterface. |
575 virtual Error DoCommand(unsigned int command, | 576 virtual Error DoCommand(unsigned int command, |
576 unsigned int arg_count, | 577 unsigned int arg_count, |
577 const void* args) OVERRIDE; | 578 const void* args) OVERRIDE; |
578 | 579 |
579 // Overridden from AsyncAPIInterface. | 580 // Overridden from AsyncAPIInterface. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); | 688 bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); |
688 bool BoundFramebufferHasDepthAttachment(); | 689 bool BoundFramebufferHasDepthAttachment(); |
689 bool BoundFramebufferHasStencilAttachment(); | 690 bool BoundFramebufferHasStencilAttachment(); |
690 | 691 |
691 virtual error::ContextLostReason GetContextLostReason() OVERRIDE; | 692 virtual error::ContextLostReason GetContextLostReason() OVERRIDE; |
692 | 693 |
693 // Overridden from FramebufferManager::TextureDetachObserver: | 694 // Overridden from FramebufferManager::TextureDetachObserver: |
694 virtual void OnTextureRefDetachedFromFramebuffer( | 695 virtual void OnTextureRefDetachedFromFramebuffer( |
695 TextureRef* texture) OVERRIDE; | 696 TextureRef* texture) OVERRIDE; |
696 | 697 |
| 698 // Overriden from ErrorStateClient. |
| 699 virtual void OnOutOfMemoryError() OVERRIDE; |
| 700 |
697 // Helpers to facilitate calling into compatible extensions. | 701 // Helpers to facilitate calling into compatible extensions. |
698 static void RenderbufferStorageMultisampleHelper( | 702 static void RenderbufferStorageMultisampleHelper( |
699 const FeatureInfo* feature_info, | 703 const FeatureInfo* feature_info, |
700 GLenum target, | 704 GLenum target, |
701 GLsizei samples, | 705 GLsizei samples, |
702 GLenum internal_format, | 706 GLenum internal_format, |
703 GLsizei width, | 707 GLsizei width, |
704 GLsizei height); | 708 GLsizei height); |
705 | 709 |
706 void BlitFramebufferHelper(GLint srcX0, | 710 void BlitFramebufferHelper(GLint srcX0, |
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1745 // contexts, the assumptions on the availablity of extensions in WebGL | 1749 // contexts, the assumptions on the availablity of extensions in WebGL |
1746 // contexts may be broken. These flags override the shared state to preserve | 1750 // contexts may be broken. These flags override the shared state to preserve |
1747 // WebGL semantics. | 1751 // WebGL semantics. |
1748 bool force_webgl_glsl_validation_; | 1752 bool force_webgl_glsl_validation_; |
1749 bool derivatives_explicitly_enabled_; | 1753 bool derivatives_explicitly_enabled_; |
1750 bool frag_depth_explicitly_enabled_; | 1754 bool frag_depth_explicitly_enabled_; |
1751 bool draw_buffers_explicitly_enabled_; | 1755 bool draw_buffers_explicitly_enabled_; |
1752 | 1756 |
1753 bool compile_shader_always_succeeds_; | 1757 bool compile_shader_always_succeeds_; |
1754 | 1758 |
| 1759 // An optional behaviour to lose the context and group when OOM. |
| 1760 bool lose_context_when_out_of_memory_; |
| 1761 |
1755 // Log extra info. | 1762 // Log extra info. |
1756 bool service_logging_; | 1763 bool service_logging_; |
1757 | 1764 |
1758 #if defined(OS_MACOSX) | 1765 #if defined(OS_MACOSX) |
1759 typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; | 1766 typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; |
1760 TextureToIOSurfaceMap texture_to_io_surface_map_; | 1767 TextureToIOSurfaceMap texture_to_io_surface_map_; |
1761 #endif | 1768 #endif |
1762 | 1769 |
1763 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; | 1770 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
1764 | 1771 |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 } | 2217 } |
2211 | 2218 |
2212 GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { | 2219 GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { |
2213 return new GLES2DecoderImpl(group); | 2220 return new GLES2DecoderImpl(group); |
2214 } | 2221 } |
2215 | 2222 |
2216 GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) | 2223 GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
2217 : GLES2Decoder(), | 2224 : GLES2Decoder(), |
2218 group_(group), | 2225 group_(group), |
2219 logger_(&debug_marker_manager_), | 2226 logger_(&debug_marker_manager_), |
2220 state_(group_->feature_info(), &logger_), | 2227 state_(group_->feature_info(), this, &logger_), |
2221 unpack_flip_y_(false), | 2228 unpack_flip_y_(false), |
2222 unpack_premultiply_alpha_(false), | 2229 unpack_premultiply_alpha_(false), |
2223 unpack_unpremultiply_alpha_(false), | 2230 unpack_unpremultiply_alpha_(false), |
2224 attrib_0_buffer_id_(0), | 2231 attrib_0_buffer_id_(0), |
2225 attrib_0_buffer_matches_value_(true), | 2232 attrib_0_buffer_matches_value_(true), |
2226 attrib_0_size_(0), | 2233 attrib_0_size_(0), |
2227 fixed_attrib_buffer_id_(0), | 2234 fixed_attrib_buffer_id_(0), |
2228 fixed_attrib_buffer_size_(0), | 2235 fixed_attrib_buffer_size_(0), |
2229 offscreen_target_color_format_(0), | 2236 offscreen_target_color_format_(0), |
2230 offscreen_target_depth_format_(0), | 2237 offscreen_target_depth_format_(0), |
(...skipping 12 matching lines...) Expand all Loading... |
2243 frame_number_(0), | 2250 frame_number_(0), |
2244 has_robustness_extension_(false), | 2251 has_robustness_extension_(false), |
2245 reset_status_(GL_NO_ERROR), | 2252 reset_status_(GL_NO_ERROR), |
2246 reset_by_robustness_extension_(false), | 2253 reset_by_robustness_extension_(false), |
2247 supports_post_sub_buffer_(false), | 2254 supports_post_sub_buffer_(false), |
2248 force_webgl_glsl_validation_(false), | 2255 force_webgl_glsl_validation_(false), |
2249 derivatives_explicitly_enabled_(false), | 2256 derivatives_explicitly_enabled_(false), |
2250 frag_depth_explicitly_enabled_(false), | 2257 frag_depth_explicitly_enabled_(false), |
2251 draw_buffers_explicitly_enabled_(false), | 2258 draw_buffers_explicitly_enabled_(false), |
2252 compile_shader_always_succeeds_(false), | 2259 compile_shader_always_succeeds_(false), |
| 2260 lose_context_when_out_of_memory_(false), |
2253 service_logging_(CommandLine::ForCurrentProcess()->HasSwitch( | 2261 service_logging_(CommandLine::ForCurrentProcess()->HasSwitch( |
2254 switches::kEnableGPUServiceLoggingGPU)), | 2262 switches::kEnableGPUServiceLoggingGPU)), |
2255 viewport_max_width_(0), | 2263 viewport_max_width_(0), |
2256 viewport_max_height_(0), | 2264 viewport_max_height_(0), |
2257 texture_state_(group_->feature_info() | 2265 texture_state_(group_->feature_info() |
2258 ->workarounds() | 2266 ->workarounds() |
2259 .texsubimage2d_faster_than_teximage2d), | 2267 .texsubimage2d_faster_than_teximage2d), |
2260 validation_texture_(0), | 2268 validation_texture_(0), |
2261 validation_fbo_multisample_(0), | 2269 validation_fbo_multisample_(0), |
2262 validation_fbo_(0) { | 2270 validation_fbo_(0) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2316 | 2324 |
2317 // Take ownership of the context and surface. The surface can be replaced with | 2325 // Take ownership of the context and surface. The surface can be replaced with |
2318 // SetSurface. | 2326 // SetSurface. |
2319 context_ = context; | 2327 context_ = context; |
2320 surface_ = surface; | 2328 surface_ = surface; |
2321 | 2329 |
2322 ContextCreationAttribHelper attrib_parser; | 2330 ContextCreationAttribHelper attrib_parser; |
2323 if (!attrib_parser.Parse(attribs)) | 2331 if (!attrib_parser.Parse(attribs)) |
2324 return false; | 2332 return false; |
2325 | 2333 |
| 2334 // Save the loseContextWhenOutOfMemory context creation attribute. |
| 2335 lose_context_when_out_of_memory_ = |
| 2336 attrib_parser.lose_context_when_out_of_memory_; |
| 2337 |
2326 // If the failIfMajorPerformanceCaveat context creation attribute was true | 2338 // If the failIfMajorPerformanceCaveat context creation attribute was true |
2327 // and we are using a software renderer, fail. | 2339 // and we are using a software renderer, fail. |
2328 if (attrib_parser.fail_if_major_perf_caveat_ && | 2340 if (attrib_parser.fail_if_major_perf_caveat_ && |
2329 feature_info_->feature_flags().is_swiftshader) { | 2341 feature_info_->feature_flags().is_swiftshader) { |
2330 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 2342 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
2331 Destroy(true); | 2343 Destroy(true); |
2332 return false; | 2344 return false; |
2333 } | 2345 } |
2334 | 2346 |
2335 if (!group_->Initialize(this, disallowed_features)) { | 2347 if (!group_->Initialize(this, disallowed_features)) { |
(...skipping 8316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10652 ProcessFinishedAsyncTransfers(); | 10664 ProcessFinishedAsyncTransfers(); |
10653 return error::kNoError; | 10665 return error::kNoError; |
10654 } | 10666 } |
10655 | 10667 |
10656 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( | 10668 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( |
10657 TextureRef* texture_ref) { | 10669 TextureRef* texture_ref) { |
10658 Texture* texture = texture_ref->texture(); | 10670 Texture* texture = texture_ref->texture(); |
10659 DoDidUseTexImageIfNeeded(texture, texture->target()); | 10671 DoDidUseTexImageIfNeeded(texture, texture->target()); |
10660 } | 10672 } |
10661 | 10673 |
| 10674 void GLES2DecoderImpl::OnOutOfMemoryError() { |
| 10675 if (lose_context_when_out_of_memory_) { |
| 10676 group_->LoseContexts(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 10677 LoseContext(GL_GUILTY_CONTEXT_RESET_ARB); |
| 10678 } |
| 10679 } |
| 10680 |
10662 // Include the auto-generated part of this file. We split this because it means | 10681 // Include the auto-generated part of this file. We split this because it means |
10663 // we can easily edit the non-auto generated parts right here in this file | 10682 // we can easily edit the non-auto generated parts right here in this file |
10664 // instead of having to edit some template or the code generator. | 10683 // instead of having to edit some template or the code generator. |
10665 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10684 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
10666 | 10685 |
10667 } // namespace gles2 | 10686 } // namespace gles2 |
10668 } // namespace gpu | 10687 } // namespace gpu |
OLD | NEW |