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 3 // found in the LICENSE file. 4 5 #include "ui/gl/gl_share_group.h" 6 7 #include "base/logging.h" 8 #include "ui/gl/gl_context.h" 9 10 namespace gfx { 11 GLShareGroup()12GLShareGroup::GLShareGroup() 13 : shared_context_(NULL) 14 #if defined(OS_MACOSX) 15 , renderer_id_(-1) 16 #endif 17 { 18 } 19 AddContext(GLContext * context)20void GLShareGroup::AddContext(GLContext* context) { 21 contexts_.insert(context); 22 } 23 RemoveContext(GLContext * context)24void GLShareGroup::RemoveContext(GLContext* context) { 25 contexts_.erase(context); 26 if (shared_context_ == context) 27 shared_context_ = NULL; 28 } 29 GetHandle()30void* GLShareGroup::GetHandle() { 31 GLContext* context = GetContext(); 32 if (context) 33 return context->GetHandle(); 34 35 return NULL; 36 } 37 GetContext()38GLContext* GLShareGroup::GetContext() { 39 for (ContextSet::iterator it = contexts_.begin(); 40 it != contexts_.end(); 41 ++it) { 42 if ((*it)->GetHandle()) 43 return *it; 44 } 45 46 return NULL; 47 } 48 SetSharedContext(GLContext * context)49void GLShareGroup::SetSharedContext(GLContext* context) { 50 DCHECK(contexts_.find(context) != contexts_.end()); 51 shared_context_ = context; 52 } 53 GetSharedContext()54GLContext* GLShareGroup::GetSharedContext() { 55 return shared_context_; 56 } 57 58 #if defined(OS_MACOSX) SetRendererID(int renderer_id)59void GLShareGroup::SetRendererID(int renderer_id) { 60 renderer_id_ = renderer_id; 61 } 62 GetRendererID()63int GLShareGroup::GetRendererID() { 64 return renderer_id_; 65 } 66 #endif 67 ~GLShareGroup()68GLShareGroup::~GLShareGroup() { 69 } 70 71 } // namespace gfx 72