OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 8 #include "base/logging.h" |
9 #include "ui/gfx/gl/gl_context.h" | 9 #include "ui/gfx/gl/gl_context.h" |
10 #include "ui/gfx/gl/gl_bindings.h" | 10 #include "ui/gfx/gl/gl_bindings.h" |
11 #include "ui/gfx/gl/gl_implementation.h" | 11 #include "ui/gfx/gl/gl_implementation.h" |
12 #include "ui/gfx/gl/gl_switches.h" | 12 #include "ui/gfx/gl/gl_switches.h" |
13 | 13 |
14 namespace gfx { | 14 namespace gfx { |
15 | 15 |
16 void GLContext::ReleaseCurrent() { | |
17 // TODO(apatrick): Implement this in GLContext derivatives. | |
18 } | |
19 | |
20 GLSurface* GLContext::GetSurface() { | |
21 // TODO(apatrick): Remove this when surfaces are split from contexts. | |
22 return NULL; | |
23 } | |
24 | |
25 unsigned int GLContext::GetBackingFrameBufferObject() { | |
26 return 0; | |
27 } | |
28 | |
29 std::string GLContext::GetExtensions() { | 16 std::string GLContext::GetExtensions() { |
30 DCHECK(IsCurrent()); | 17 DCHECK(IsCurrent(NULL)); |
31 const char* ext = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); | 18 const char* ext = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
32 return std::string(ext ? ext : ""); | 19 return std::string(ext ? ext : ""); |
33 } | 20 } |
34 | 21 |
35 bool GLContext::HasExtension(const char* name) { | 22 bool GLContext::HasExtension(const char* name) { |
36 std::string extensions = GetExtensions(); | 23 std::string extensions = GetExtensions(); |
37 extensions += " "; | 24 extensions += " "; |
38 | 25 |
39 std::string delimited_name(name); | 26 std::string delimited_name(name); |
40 delimited_name += " "; | 27 delimited_name += " "; |
41 | 28 |
42 return extensions.find(delimited_name) != std::string::npos; | 29 return extensions.find(delimited_name) != std::string::npos; |
43 } | 30 } |
44 | 31 |
45 bool GLContext::InitializeCommon() { | |
46 if (!MakeCurrent()) { | |
47 LOG(ERROR) << "MakeCurrent failed."; | |
48 return false; | |
49 } | |
50 | |
51 if (!IsOffscreen()) { | |
52 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) | |
53 SetSwapInterval(0); | |
54 else | |
55 SetSwapInterval(1); | |
56 } | |
57 | |
58 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | |
59 if (glGetError() != GL_NO_ERROR) { | |
60 LOG(ERROR) << "glClear failed."; | |
61 return false; | |
62 } | |
63 | |
64 return true; | |
65 } | |
66 | |
67 bool GLContext::LosesAllContextsOnContextLost() | 32 bool GLContext::LosesAllContextsOnContextLost() |
68 { | 33 { |
69 switch (GetGLImplementation()) { | 34 switch (GetGLImplementation()) { |
70 case kGLImplementationDesktopGL: | 35 case kGLImplementationDesktopGL: |
71 return false; | 36 return false; |
72 case kGLImplementationEGLGLES2: | 37 case kGLImplementationEGLGLES2: |
73 return true; | 38 return true; |
74 case kGLImplementationOSMesaGL: | 39 case kGLImplementationOSMesaGL: |
75 return false; | 40 return false; |
76 case kGLImplementationMockGL: | 41 case kGLImplementationMockGL: |
77 return false; | 42 return false; |
78 default: | 43 default: |
79 NOTREACHED(); | 44 NOTREACHED(); |
80 return true; | 45 return true; |
81 } | 46 } |
82 } | 47 } |
83 | 48 |
84 } // namespace gfx | 49 } // namespace gfx |
OLD | NEW |