- add sources.
[platform/framework/web/crosswalk.git] / src / ui / gl / gl_share_group.cc
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
12 GLShareGroup::GLShareGroup()
13     : shared_context_(NULL)
14 #if defined(OS_MACOSX)
15     , renderer_id_(-1)
16 #endif
17     {
18 }
19
20 void GLShareGroup::AddContext(GLContext* context) {
21   contexts_.insert(context);
22 }
23
24 void GLShareGroup::RemoveContext(GLContext* context) {
25   contexts_.erase(context);
26   if (shared_context_ == context)
27     shared_context_ = NULL;
28 }
29
30 void* GLShareGroup::GetHandle() {
31   GLContext* context = GetContext();
32   if (context)
33     return context->GetHandle();
34
35   return NULL;
36 }
37
38 GLContext* 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
49 void GLShareGroup::SetSharedContext(GLContext* context) {
50   DCHECK(contexts_.find(context) != contexts_.end());
51   shared_context_ = context;
52 }
53
54 GLContext* GLShareGroup::GetSharedContext() {
55   return shared_context_;
56 }
57
58 #if defined(OS_MACOSX)
59 void GLShareGroup::SetRendererID(int renderer_id) {
60   renderer_id_ = renderer_id;
61 }
62
63 int GLShareGroup::GetRendererID() {
64   return renderer_id_;
65 }
66 #endif
67
68 GLShareGroup::~GLShareGroup() {
69 }
70
71 }  // namespace gfx