| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| 11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
| 12 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_gl_api_implementation.h" | 13 #include "ui/gl/gl_gl_api_implementation.h" |
| 14 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
| 15 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
| 16 #include "ui/gl/gl_switches.h" | 16 #include "ui/gl/gl_switches.h" |
| 17 #include "ui/gl/gl_version_info.h" |
| 17 | 18 |
| 18 namespace gfx { | 19 namespace gfx { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky | 22 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky |
| 22 current_context_ = LAZY_INSTANCE_INITIALIZER; | 23 current_context_ = LAZY_INSTANCE_INITIALIZER; |
| 23 | 24 |
| 24 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky | 25 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky |
| 25 current_real_context_ = LAZY_INSTANCE_INITIALIZER; | 26 current_real_context_ = LAZY_INSTANCE_INITIALIZER; |
| 26 } // namespace | 27 } // namespace |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 void GLContext::SetUnbindFboOnMakeCurrent() { | 52 void GLContext::SetUnbindFboOnMakeCurrent() { |
| 52 NOTIMPLEMENTED(); | 53 NOTIMPLEMENTED(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 std::string GLContext::GetExtensions() { | 56 std::string GLContext::GetExtensions() { |
| 56 DCHECK(IsCurrent(NULL)); | 57 DCHECK(IsCurrent(NULL)); |
| 57 const char* ext = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); | 58 const char* ext = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 58 return std::string(ext ? ext : ""); | 59 return std::string(ext ? ext : ""); |
| 59 } | 60 } |
| 60 | 61 |
| 62 std::string GLContext::GetGLVersion() { |
| 63 DCHECK(IsCurrent(NULL)); |
| 64 const char *version = |
| 65 reinterpret_cast<const char*>(glGetString(GL_VERSION)); |
| 66 return std::string(version ? version : ""); |
| 67 } |
| 68 |
| 61 bool GLContext::HasExtension(const char* name) { | 69 bool GLContext::HasExtension(const char* name) { |
| 62 std::string extensions = GetExtensions(); | 70 std::string extensions = GetExtensions(); |
| 63 extensions += " "; | 71 extensions += " "; |
| 64 | 72 |
| 65 std::string delimited_name(name); | 73 std::string delimited_name(name); |
| 66 delimited_name += " "; | 74 delimited_name += " "; |
| 67 | 75 |
| 68 return extensions.find(delimited_name) != std::string::npos; | 76 return extensions.find(delimited_name) != std::string::npos; |
| 69 } | 77 } |
| 70 | 78 |
| 79 const GLVersionInfo* GLContext::GetVersionInfo() { |
| 80 if(!version_info_) { |
| 81 std::string version = GetGLVersion(); |
| 82 version_info_ = scoped_ptr<GLVersionInfo>( |
| 83 new GLVersionInfo(version.c_str())); |
| 84 } |
| 85 return version_info_.get(); |
| 86 } |
| 87 |
| 71 GLShareGroup* GLContext::share_group() { | 88 GLShareGroup* GLContext::share_group() { |
| 72 return share_group_.get(); | 89 return share_group_.get(); |
| 73 } | 90 } |
| 74 | 91 |
| 75 bool GLContext::LosesAllContextsOnContextLost() { | 92 bool GLContext::LosesAllContextsOnContextLost() { |
| 76 switch (GetGLImplementation()) { | 93 switch (GetGLImplementation()) { |
| 77 case kGLImplementationDesktopGL: | 94 case kGLImplementationDesktopGL: |
| 78 return false; | 95 return false; |
| 79 case kGLImplementationEGLGLES2: | 96 case kGLImplementationEGLGLES2: |
| 80 return true; | 97 return true; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 107 } | 124 } |
| 108 | 125 |
| 109 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) { | 126 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) { |
| 110 state_restorer_ = make_scoped_ptr(state_restorer); | 127 state_restorer_ = make_scoped_ptr(state_restorer); |
| 111 } | 128 } |
| 112 | 129 |
| 113 bool GLContext::WasAllocatedUsingRobustnessExtension() { | 130 bool GLContext::WasAllocatedUsingRobustnessExtension() { |
| 114 return false; | 131 return false; |
| 115 } | 132 } |
| 116 | 133 |
| 117 bool GLContext::InitializeExtensionBindings() { | 134 bool GLContext::InitializeDynamicBindings() { |
| 118 DCHECK(IsCurrent(NULL)); | 135 DCHECK(IsCurrent(NULL)); |
| 119 static bool initialized = false; | 136 static bool initialized = false; |
| 120 if (initialized) | 137 if (initialized) |
| 121 return initialized; | 138 return initialized; |
| 122 initialized = InitializeGLExtensionBindings(GetGLImplementation(), this); | 139 initialized = InitializeDynamicGLBindings(GetGLImplementation(), this); |
| 123 if (!initialized) | 140 if (!initialized) |
| 124 LOG(ERROR) << "Could not initialize extension bindings."; | 141 LOG(ERROR) << "Could not initialize dynamic bindings."; |
| 125 return initialized; | 142 return initialized; |
| 126 } | 143 } |
| 127 | 144 |
| 128 void GLContext::SetupForVirtualization() { | 145 void GLContext::SetupForVirtualization() { |
| 129 if (!virtual_gl_api_) { | 146 if (!virtual_gl_api_) { |
| 130 virtual_gl_api_.reset(new VirtualGLApi()); | 147 virtual_gl_api_.reset(new VirtualGLApi()); |
| 131 virtual_gl_api_->Initialize(&g_driver_gl, this); | 148 virtual_gl_api_->Initialize(&g_driver_gl, this); |
| 132 } | 149 } |
| 133 } | 150 } |
| 134 | 151 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 151 : GLContext(share_group) {} | 168 : GLContext(share_group) {} |
| 152 | 169 |
| 153 GLContextReal::~GLContextReal() {} | 170 GLContextReal::~GLContextReal() {} |
| 154 | 171 |
| 155 void GLContextReal::SetCurrent(GLSurface* surface) { | 172 void GLContextReal::SetCurrent(GLSurface* surface) { |
| 156 GLContext::SetCurrent(surface); | 173 GLContext::SetCurrent(surface); |
| 157 current_real_context_.Pointer()->Set(surface ? this : NULL); | 174 current_real_context_.Pointer()->Set(surface ? this : NULL); |
| 158 } | 175 } |
| 159 | 176 |
| 160 } // namespace gfx | 177 } // namespace gfx |
| OLD | NEW |