| Index: ui/gl/gl_share_group.cc
|
| diff --git a/ui/gl/gl_share_group.cc b/ui/gl/gl_share_group.cc
|
| index dd424a54fe947915e80b36636ae440891387357d..67e9480ad5bc4f4f730ea358fb2760fdd24c15dd 100644
|
| --- a/ui/gl/gl_share_group.cc
|
| +++ b/ui/gl/gl_share_group.cc
|
| @@ -11,7 +11,11 @@
|
| namespace gfx {
|
|
|
| GLShareGroup::GLShareGroup()
|
| - : shared_context_(NULL)
|
| + : shared_contexts_(
|
| + make_scoped_ptr(new std::map<GLSurface::Format,
|
| + scoped_refptr<GLContext>>())),
|
| + active_context_(nullptr),
|
| + format_(GLSurface::GetDefaultFormat())
|
| #if defined(OS_MACOSX)
|
| , renderer_id_(-1)
|
| #endif
|
| @@ -24,8 +28,6 @@ void GLShareGroup::AddContext(GLContext* context) {
|
|
|
| void GLShareGroup::RemoveContext(GLContext* context) {
|
| contexts_.erase(context);
|
| - if (shared_context_ == context)
|
| - shared_context_ = NULL;
|
| }
|
|
|
| void* GLShareGroup::GetHandle() {
|
| @@ -37,23 +39,36 @@ void* GLShareGroup::GetHandle() {
|
| }
|
|
|
| GLContext* GLShareGroup::GetContext() {
|
| - for (ContextSet::iterator it = contexts_.begin();
|
| - it != contexts_.end();
|
| - ++it) {
|
| - if ((*it)->GetHandle())
|
| - return *it;
|
| + for (auto context : contexts_) {
|
| + if (context->GetFormat() == format_ && context->GetHandle())
|
| + return context;
|
| }
|
|
|
| return NULL;
|
| }
|
|
|
| -void GLShareGroup::SetSharedContext(GLContext* context) {
|
| - DCHECK(contexts_.find(context) != contexts_.end());
|
| - shared_context_ = context;
|
| +void GLShareGroup::UpdateActiveSharedContext(GLSurface* surface,
|
| + GpuPreference preference) {
|
| + GLSurface::Format format = surface->GetFormat();
|
| + scoped_refptr<GLContext> context;
|
| + auto it = shared_contexts_->find(format);
|
| + if (it == shared_contexts_->end()) {
|
| + // The shared context with the matched config not found. Create a new one.
|
| + context = GLContext::CreateGLContext(this, surface, preference);
|
| + if (context.get()) {
|
| + shared_contexts_->insert({format, context});
|
| + } else {
|
| + LOG(ERROR) << "Failed to create GLContext.";
|
| + return;
|
| + }
|
| + } else {
|
| + context = it->second;
|
| + }
|
| + active_context_ = context.get();
|
| }
|
|
|
| GLContext* GLShareGroup::GetSharedContext() {
|
| - return shared_context_;
|
| + return active_context_;
|
| }
|
|
|
| #if defined(OS_MACOSX)
|
|
|