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 "ui/gl/gl_gl_api_implementation.h" | 5 #include "ui/gl/gl_gl_api_implementation.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_implementation.h" |
13 #include "ui/gl/gl_state_restorer.h" | 14 #include "ui/gl/gl_state_restorer.h" |
14 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
15 #include "ui/gl/gl_switches.h" | 16 #include "ui/gl/gl_switches.h" |
16 | 17 |
17 namespace gfx { | 18 namespace gfx { |
18 | 19 |
19 // The GL Api being used. This could be g_real_gl or gl_trace_gl | 20 // The GL Api being used. This could be g_real_gl or gl_trace_gl |
20 static GLApi* g_gl; | 21 static GLApi* g_gl; |
21 // A GL Api that calls directly into the driver. | 22 // A GL Api that calls directly into the driver. |
22 static RealGLApi* g_real_gl; | 23 static RealGLApi* g_real_gl; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 RealGLApi::RealGLApi() { | 93 RealGLApi::RealGLApi() { |
93 } | 94 } |
94 | 95 |
95 RealGLApi::~RealGLApi() { | 96 RealGLApi::~RealGLApi() { |
96 } | 97 } |
97 | 98 |
98 void RealGLApi::Initialize(DriverGL* driver) { | 99 void RealGLApi::Initialize(DriverGL* driver) { |
99 InitializeBase(driver); | 100 InitializeBase(driver); |
100 } | 101 } |
101 | 102 |
| 103 static inline GLenum GetTexInternalFormat(GLenum internal_format) { |
| 104 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 105 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) |
| 106 return GL_RGBA8; |
| 107 } |
| 108 return internal_format; |
| 109 } |
| 110 |
| 111 // TODO(epenner): Could the above function be merged into this and removed? |
| 112 static inline GLenum GetTexInternalFormat(GLenum internal_format, |
| 113 GLenum format, |
| 114 GLenum type) { |
| 115 GLenum gl_internal_format = GetTexInternalFormat(internal_format); |
| 116 |
| 117 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 118 return gl_internal_format; |
| 119 |
| 120 if (type == GL_FLOAT) { |
| 121 switch (format) { |
| 122 case GL_RGBA: |
| 123 gl_internal_format = GL_RGBA32F_ARB; |
| 124 break; |
| 125 case GL_RGB: |
| 126 gl_internal_format = GL_RGB32F_ARB; |
| 127 break; |
| 128 case GL_LUMINANCE_ALPHA: |
| 129 gl_internal_format = GL_LUMINANCE_ALPHA32F_ARB; |
| 130 break; |
| 131 case GL_LUMINANCE: |
| 132 gl_internal_format = GL_LUMINANCE32F_ARB; |
| 133 break; |
| 134 case GL_ALPHA: |
| 135 gl_internal_format = GL_ALPHA32F_ARB; |
| 136 break; |
| 137 default: |
| 138 NOTREACHED(); |
| 139 break; |
| 140 } |
| 141 } else if (type == GL_HALF_FLOAT_OES) { |
| 142 switch (format) { |
| 143 case GL_RGBA: |
| 144 gl_internal_format = GL_RGBA16F_ARB; |
| 145 break; |
| 146 case GL_RGB: |
| 147 gl_internal_format = GL_RGB16F_ARB; |
| 148 break; |
| 149 case GL_LUMINANCE_ALPHA: |
| 150 gl_internal_format = GL_LUMINANCE_ALPHA16F_ARB; |
| 151 break; |
| 152 case GL_LUMINANCE: |
| 153 gl_internal_format = GL_LUMINANCE16F_ARB; |
| 154 break; |
| 155 case GL_ALPHA: |
| 156 gl_internal_format = GL_ALPHA16F_ARB; |
| 157 break; |
| 158 default: |
| 159 NOTREACHED(); |
| 160 break; |
| 161 } |
| 162 } |
| 163 return gl_internal_format; |
| 164 } |
| 165 |
| 166 static inline GLenum GetTexType(GLenum type) { |
| 167 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 168 if (type == GL_HALF_FLOAT_OES) |
| 169 return GL_HALF_FLOAT_ARB; |
| 170 } |
| 171 return type; |
| 172 } |
| 173 |
| 174 void RealGLApi::glTexImage2DFn( |
| 175 GLenum target, GLint level, GLint internalformat, |
| 176 GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, |
| 177 const void* pixels) { |
| 178 GLenum gl_internal_format = GetTexInternalFormat( |
| 179 internalformat, format, type); |
| 180 GLenum gl_type = GetTexType(type); |
| 181 return driver_->fn.glTexImage2DFn( |
| 182 target, level, gl_internal_format, width, height, border, format, gl_type, |
| 183 pixels); |
| 184 } |
| 185 |
| 186 void RealGLApi::glTexSubImage2DFn( |
| 187 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, |
| 188 GLsizei height, GLenum format, GLenum type, const void* pixels) { |
| 189 GLenum gl_type = GetTexType(type); |
| 190 return driver_->fn.glTexSubImage2DFn( |
| 191 target, level, xoffset, yoffset, width, height, format, gl_type, pixels); |
| 192 } |
| 193 |
| 194 void RealGLApi::glTexStorage2DEXTFn( |
| 195 GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, |
| 196 GLsizei height) { |
| 197 GLenum gl_internal_format = GetTexInternalFormat(internalformat); |
| 198 return driver_->fn.glTexStorage2DEXTFn( |
| 199 target, levels, gl_internal_format, width, height); |
| 200 } |
| 201 |
102 TraceGLApi::~TraceGLApi() { | 202 TraceGLApi::~TraceGLApi() { |
103 } | 203 } |
104 | 204 |
105 VirtualGLApi::VirtualGLApi() | 205 VirtualGLApi::VirtualGLApi() |
106 : real_context_(NULL), | 206 : real_context_(NULL), |
107 current_context_(NULL) { | 207 current_context_(NULL) { |
108 } | 208 } |
109 | 209 |
110 VirtualGLApi::~VirtualGLApi() { | 210 VirtualGLApi::~VirtualGLApi() { |
111 } | 211 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { | 281 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { |
182 switch (name) { | 282 switch (name) { |
183 case GL_EXTENSIONS: | 283 case GL_EXTENSIONS: |
184 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); | 284 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); |
185 default: | 285 default: |
186 return driver_->fn.glGetStringFn(name); | 286 return driver_->fn.glGetStringFn(name); |
187 } | 287 } |
188 } | 288 } |
189 | 289 |
190 } // namespace gfx | 290 } // namespace gfx |
OLD | NEW |