Index: gpu/command_buffer/service/gles2_cmd_decoder.cc |
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
index c3bdae5d5d94a78b9cfa80d8087581f367118ec0..c0e0e3d7989901dd1718f8f9f588756c2095fa0d 100644 |
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
@@ -566,7 +566,8 @@ void GLES2Decoder::EndDecoding() {} |
// This class implements GLES2Decoder so we don't have to expose all the GLES2 |
// cmd stuff to outside this class. |
class GLES2DecoderImpl : public GLES2Decoder, |
- public FramebufferManager::TextureDetachObserver { |
+ public FramebufferManager::TextureDetachObserver, |
+ public ErrorStateClient { |
public: |
explicit GLES2DecoderImpl(ContextGroup* group); |
virtual ~GLES2DecoderImpl(); |
@@ -694,6 +695,9 @@ class GLES2DecoderImpl : public GLES2Decoder, |
virtual void OnTextureRefDetachedFromFramebuffer( |
TextureRef* texture) OVERRIDE; |
+ // Overriden from ErrorStateClient. |
+ virtual void OnOutOfMemoryError() OVERRIDE; |
+ |
// Helpers to facilitate calling into compatible extensions. |
static void RenderbufferStorageMultisampleHelper( |
const FeatureInfo* feature_info, |
@@ -1752,6 +1756,9 @@ class GLES2DecoderImpl : public GLES2Decoder, |
bool compile_shader_always_succeeds_; |
+ // An optional behaviour to lose the context and group when OOM. |
+ bool lose_context_when_out_of_memory_; |
+ |
// Log extra info. |
bool service_logging_; |
@@ -2217,7 +2224,7 @@ GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
: GLES2Decoder(), |
group_(group), |
logger_(&debug_marker_manager_), |
- state_(group_->feature_info(), &logger_), |
+ state_(group_->feature_info(), this, &logger_), |
unpack_flip_y_(false), |
unpack_premultiply_alpha_(false), |
unpack_unpremultiply_alpha_(false), |
@@ -2250,6 +2257,7 @@ GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
frag_depth_explicitly_enabled_(false), |
draw_buffers_explicitly_enabled_(false), |
compile_shader_always_succeeds_(false), |
+ lose_context_when_out_of_memory_(false), |
service_logging_(CommandLine::ForCurrentProcess()->HasSwitch( |
switches::kEnableGPUServiceLoggingGPU)), |
viewport_max_width_(0), |
@@ -2323,6 +2331,10 @@ bool GLES2DecoderImpl::Initialize( |
if (!attrib_parser.Parse(attribs)) |
return false; |
+ // Save the loseContextWhenOutOfMemory context creation attribute. |
+ lose_context_when_out_of_memory_ = |
+ attrib_parser.lose_context_when_out_of_memory_; |
+ |
// If the failIfMajorPerformanceCaveat context creation attribute was true |
// and we are using a software renderer, fail. |
if (attrib_parser.fail_if_major_perf_caveat_ && |
@@ -10659,6 +10671,13 @@ void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( |
DoDidUseTexImageIfNeeded(texture, texture->target()); |
} |
+void GLES2DecoderImpl::OnOutOfMemoryError() { |
+ if (lose_context_when_out_of_memory_) { |
+ group_->LoseContexts(GL_UNKNOWN_CONTEXT_RESET_ARB); |
+ LoseContext(GL_GUILTY_CONTEXT_RESET_ARB); |
+ } |
+} |
+ |
// Include the auto-generated part of this file. We split this because it means |
// we can easily edit the non-auto generated parts right here in this file |
// instead of having to edit some template or the code generator. |