| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/skia/ganesh_context.h" | 5 #include "mojo/skia/ganesh_context.h" |
| 6 | 6 |
| 7 #include "mojo/public/c/gpu/MGL/mgl.h" | 7 #include "mojo/public/c/gpu/MGL/mgl.h" |
| 8 #include "mojo/skia/gl_bindings_skia.h" | 8 #include "mojo/skia/gl_bindings_skia.h" |
| 9 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 9 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 GaneshContext::~GaneshContext() { | 41 GaneshContext::~GaneshContext() { |
| 42 if (gl_context_) | 42 if (gl_context_) |
| 43 gl_context_->RemoveObserver(this); | 43 gl_context_->RemoveObserver(this); |
| 44 | 44 |
| 45 ReleaseContext(); | 45 ReleaseContext(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void GaneshContext::OnContextLost() { | 48 void GaneshContext::OnContextLost() { |
| 49 ReleaseContext(); | 49 context_lost_ = true; |
| 50 if (!scope_entered_) |
| 51 ReleaseContext(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void GaneshContext::ReleaseContext() { | 54 void GaneshContext::ReleaseContext() { |
| 53 Scope(this); | 55 Scope(this); |
| 54 gr_context_->abandonContext(); | 56 gr_context_->abandonContext(); |
| 55 gr_context_.clear(); | 57 gr_context_.clear(); |
| 56 gl_context_.reset(); | 58 gl_context_.reset(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void GaneshContext::EnterScope() { | 61 void GaneshContext::EnterScope() { |
| 60 CHECK(!scope_entered_); | 62 CHECK(!scope_entered_); |
| 61 scope_entered_ = true; | 63 scope_entered_ = true; |
| 62 | 64 |
| 63 if (gl_context_) { | 65 if (gl_context_) { |
| 64 previous_mgl_context_ = MGLGetCurrentContext(); | 66 previous_mgl_context_ = MGLGetCurrentContext(); |
| 65 gl_context_->MakeCurrent(); | 67 gl_context_->MakeCurrent(); |
| 66 | 68 |
| 67 // Reset the Ganesh context when entering its scope in case the caller | 69 // Reset the Ganesh context when entering its scope in case the caller |
| 68 // performed low-level GL operations which might interfere with Ganesh's | 70 // performed low-level GL operations which might interfere with Ganesh's |
| 69 // state expectations. | 71 // state expectations. |
| 70 if (gr_context_) | 72 if (gr_context_) |
| 71 gr_context_->resetContext(); | 73 gr_context_->resetContext(); |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 void GaneshContext::ExitScope() { | 77 void GaneshContext::ExitScope() { |
| 76 CHECK(scope_entered_); | 78 CHECK(scope_entered_); |
| 77 scope_entered_ = false; | 79 scope_entered_ = false; |
| 78 | 80 |
| 79 // Flush the Ganesh context when exiting its scope. | 81 if (gl_context_) { |
| 80 if (gr_context_) | 82 // Flush the Ganesh context when exiting its scope. |
| 81 gr_context_->flush(); | 83 if (gr_context_) |
| 84 gr_context_->flush(); |
| 82 | 85 |
| 83 MGLMakeCurrent(previous_mgl_context_); | 86 MGLMakeCurrent(previous_mgl_context_); |
| 84 previous_mgl_context_ = MGL_NO_CONTEXT; | 87 previous_mgl_context_ = MGL_NO_CONTEXT; |
| 88 |
| 89 if (context_lost_) |
| 90 ReleaseContext(); |
| 91 } |
| 85 } | 92 } |
| 86 | 93 |
| 87 } // namespace skia | 94 } // namespace skia |
| 88 } // namespace mojo | 95 } // namespace mojo |
| OLD | NEW |