| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 GaneshContext::GaneshContext(const scoped_refptr<GLContext>& gl_context) | 22 GaneshContext::GaneshContext(const scoped_refptr<GLContext>& gl_context) |
| 23 : gl_context_(gl_context) { | 23 : gl_context_(gl_context) { |
| 24 DCHECK(gl_context_); | 24 DCHECK(gl_context_); |
| 25 if (is_lost()) | 25 if (is_lost()) |
| 26 return; | 26 return; |
| 27 | 27 |
| 28 gl_context_->AddObserver(this); | 28 gl_context_->AddObserver(this); |
| 29 | 29 |
| 30 GLContext::Scope gl_scope(gl_context_); | 30 GLContext::Scope gl_scope(gl_context_); |
| 31 ::skia::RefPtr<GrGLInterface> interface = | 31 sk_sp<GrGLInterface> interface = CreateMojoSkiaGLBinding(); |
| 32 ::skia::AdoptRef(CreateMojoSkiaGLBinding()); | |
| 33 DCHECK(interface); | 32 DCHECK(interface); |
| 34 gr_context_ = ::skia::AdoptRef(GrContext::Create( | 33 gr_context_.reset(GrContext::Create( |
| 35 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); | 34 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); |
| 36 DCHECK(gr_context_); | 35 DCHECK(gr_context_); |
| 37 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount, | 36 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount, |
| 38 kMaxGaneshResourceCacheBytes); | 37 kMaxGaneshResourceCacheBytes); |
| 39 } | 38 } |
| 40 | 39 |
| 41 GaneshContext::~GaneshContext() { | 40 GaneshContext::~GaneshContext() { |
| 42 DCHECK(!scope_entered_); | 41 DCHECK(!scope_entered_); |
| 43 if (!gr_context_) | 42 if (!gr_context_) |
| 44 return; | 43 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 } | 54 } |
| 56 } | 55 } |
| 57 | 56 |
| 58 void GaneshContext::OnContextLost() { | 57 void GaneshContext::OnContextLost() { |
| 59 DCHECK(gr_context_); | 58 DCHECK(gr_context_); |
| 60 DCHECK(is_lost()); | 59 DCHECK(is_lost()); |
| 61 | 60 |
| 62 gl_context_->RemoveObserver(this); | 61 gl_context_->RemoveObserver(this); |
| 63 if (!scope_entered_) { | 62 if (!scope_entered_) { |
| 64 gr_context_->abandonContext(); | 63 gr_context_->abandonContext(); |
| 65 gr_context_.clear(); | 64 gr_context_.reset(); |
| 66 } | 65 } |
| 67 } | 66 } |
| 68 | 67 |
| 69 GaneshContext::Scope::Scope(const scoped_refptr<GaneshContext>& ganesh_context) | 68 GaneshContext::Scope::Scope(const scoped_refptr<GaneshContext>& ganesh_context) |
| 70 : ganesh_context_(ganesh_context), gl_scope_(ganesh_context->gl_context_) { | 69 : ganesh_context_(ganesh_context), gl_scope_(ganesh_context->gl_context_) { |
| 71 DCHECK(!ganesh_context_->scope_entered_); | 70 DCHECK(!ganesh_context_->scope_entered_); |
| 72 DCHECK(ganesh_context_->gr_context_); | 71 DCHECK(ganesh_context_->gr_context_); |
| 73 DCHECK(!ganesh_context_->is_lost()); | 72 DCHECK(!ganesh_context_->is_lost()); |
| 74 | 73 |
| 75 // Do this first to avoid potential reentrance if the context is lost. | 74 // Do this first to avoid potential reentrance if the context is lost. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 // Flush the Ganesh context when exiting its scope to ensure all pending | 86 // Flush the Ganesh context when exiting its scope to ensure all pending |
| 88 // operations have been applied to the GL context. | 87 // operations have been applied to the GL context. |
| 89 if (!ganesh_context_->is_lost()) { | 88 if (!ganesh_context_->is_lost()) { |
| 90 ganesh_context_->gr_context_->flush(); | 89 ganesh_context_->gr_context_->flush(); |
| 91 } | 90 } |
| 92 | 91 |
| 93 // Abandon the Ganesh context if lost while inside the scope or while | 92 // Abandon the Ganesh context if lost while inside the scope or while |
| 94 // flushing it above. | 93 // flushing it above. |
| 95 if (ganesh_context_->is_lost()) { | 94 if (ganesh_context_->is_lost()) { |
| 96 ganesh_context_->gr_context_->abandonContext(); | 95 ganesh_context_->gr_context_->abandonContext(); |
| 97 ganesh_context_->gr_context_.clear(); | 96 ganesh_context_->gr_context_.reset(); |
| 98 } | 97 } |
| 99 | 98 |
| 100 // Do this last to avoid potential reentrance if the context is lost. | 99 // Do this last to avoid potential reentrance if the context is lost. |
| 101 ganesh_context_->scope_entered_ = false; | 100 ganesh_context_->scope_entered_ = false; |
| 102 } | 101 } |
| 103 | 102 |
| 104 } // namespace skia | 103 } // namespace skia |
| 105 } // namespace mojo | 104 } // namespace mojo |
| OLD | NEW |