OLD | NEW |
| (Empty) |
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 <string> | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/lazy_instance.h" | |
9 #include "base/logging.h" | |
10 #include "base/threading/thread_local.h" | |
11 #include "ui/gfx/gl/gl_context.h" | |
12 #include "ui/gfx/gl/gl_bindings.h" | |
13 #include "ui/gfx/gl/gl_implementation.h" | |
14 #include "ui/gfx/gl/gl_surface.h" | |
15 #include "ui/gfx/gl/gl_switches.h" | |
16 | |
17 namespace gfx { | |
18 | |
19 namespace { | |
20 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky | |
21 current_context_ = LAZY_INSTANCE_INITIALIZER; | |
22 } // namespace | |
23 | |
24 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { | |
25 if (!share_group_.get()) | |
26 share_group_ = new GLShareGroup; | |
27 | |
28 share_group_->AddContext(this); | |
29 } | |
30 | |
31 GLContext::~GLContext() { | |
32 share_group_->RemoveContext(this); | |
33 if (GetCurrent() == this) { | |
34 SetCurrent(NULL, NULL); | |
35 } | |
36 } | |
37 | |
38 std::string GLContext::GetExtensions() { | |
39 DCHECK(IsCurrent(NULL)); | |
40 | |
41 std::string extensions; | |
42 if (GLSurface::GetCurrent()) { | |
43 extensions = GLSurface::GetCurrent()->GetExtensions(); | |
44 } | |
45 | |
46 const char* gl_ext = reinterpret_cast<const char*>( | |
47 glGetString(GL_EXTENSIONS)); | |
48 if (gl_ext) { | |
49 extensions += (!extensions.empty() && gl_ext[0]) ? " " : ""; | |
50 extensions += gl_ext; | |
51 } | |
52 | |
53 return extensions; | |
54 } | |
55 | |
56 bool GLContext::HasExtension(const char* name) { | |
57 std::string extensions = GetExtensions(); | |
58 extensions += " "; | |
59 | |
60 std::string delimited_name(name); | |
61 delimited_name += " "; | |
62 | |
63 return extensions.find(delimited_name) != std::string::npos; | |
64 } | |
65 | |
66 GLShareGroup* GLContext::share_group() { | |
67 return share_group_.get(); | |
68 } | |
69 | |
70 bool GLContext::LosesAllContextsOnContextLost() { | |
71 switch (GetGLImplementation()) { | |
72 case kGLImplementationDesktopGL: | |
73 return false; | |
74 case kGLImplementationEGLGLES2: | |
75 return true; | |
76 case kGLImplementationOSMesaGL: | |
77 case kGLImplementationAppleGL: | |
78 return false; | |
79 case kGLImplementationMockGL: | |
80 return false; | |
81 default: | |
82 NOTREACHED(); | |
83 return true; | |
84 } | |
85 } | |
86 | |
87 GLContext* GLContext::GetCurrent() { | |
88 return current_context_.Pointer()->Get(); | |
89 } | |
90 | |
91 void GLContext::SetCurrent(GLContext* context, GLSurface* surface) { | |
92 current_context_.Pointer()->Set(context); | |
93 GLSurface::SetCurrent(surface); | |
94 } | |
95 | |
96 bool GLContext::WasAllocatedUsingARBRobustness() { | |
97 return false; | |
98 } | |
99 | |
100 bool GLContext::InitializeExtensionBindings() { | |
101 DCHECK(IsCurrent(NULL)); | |
102 static bool initialized = false; | |
103 if (initialized) | |
104 return initialized; | |
105 initialized = InitializeGLExtensionBindings(GetGLImplementation(), this); | |
106 if (!initialized) | |
107 LOG(ERROR) << "Could not initialize extension bindings."; | |
108 return initialized; | |
109 } | |
110 | |
111 } // namespace gfx | |
OLD | NEW |