| 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 "gpu/blink/webgraphicscontext3d_impl.h" | 5 #include "gpu/blink/webgraphicscontext3d_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 : initialized_(false), | 185 : initialized_(false), |
| 186 initialize_failed_(false), | 186 initialize_failed_(false), |
| 187 context_lost_callback_(0), | 187 context_lost_callback_(0), |
| 188 error_message_callback_(0), | 188 error_message_callback_(0), |
| 189 gl_(NULL) {} | 189 gl_(NULL) {} |
| 190 | 190 |
| 191 WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() { | 191 WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() { |
| 192 | 192 |
| 193 } | 193 } |
| 194 | 194 |
| 195 void WebGraphicsContext3DImpl::synthesizeGLError(WGC3Denum error) { | |
| 196 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == | |
| 197 synthetic_errors_.end()) { | |
| 198 synthetic_errors_.push_back(error); | |
| 199 } | |
| 200 } | |
| 201 | |
| 202 blink::WebString WebGraphicsContext3DImpl:: | 195 blink::WebString WebGraphicsContext3DImpl:: |
| 203 getRequestableExtensionsCHROMIUM() { | 196 getRequestableExtensionsCHROMIUM() { |
| 204 return blink::WebString::fromUTF8( | 197 return blink::WebString::fromUTF8( |
| 205 gl_->GetRequestableExtensionsCHROMIUM()); | 198 gl_->GetRequestableExtensionsCHROMIUM()); |
| 206 } | 199 } |
| 207 | 200 |
| 208 void WebGraphicsContext3DImpl::blitFramebufferCHROMIUM( | 201 void WebGraphicsContext3DImpl::blitFramebufferCHROMIUM( |
| 209 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1, | 202 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1, |
| 210 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1, | 203 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1, |
| 211 WGC3Dbitfield mask, WGC3Denum filter) { | 204 WGC3Dbitfield mask, WGC3Denum filter) { |
| 212 gl_->BlitFramebufferCHROMIUM( | 205 gl_->BlitFramebufferCHROMIUM( |
| 213 srcX0, srcY0, srcX1, srcY1, | 206 srcX0, srcY0, srcX1, srcY1, |
| 214 dstX0, dstY0, dstX1, dstY1, | 207 dstX0, dstY0, dstX1, dstY1, |
| 215 mask, filter); | 208 mask, filter); |
| 216 } | 209 } |
| 217 | 210 |
| 218 void WebGraphicsContext3DImpl::drawElements(WGC3Denum mode, | 211 void WebGraphicsContext3DImpl::drawElements(WGC3Denum mode, |
| 219 WGC3Dsizei count, | 212 WGC3Dsizei count, |
| 220 WGC3Denum type, | 213 WGC3Denum type, |
| 221 WGC3Dintptr offset) { | 214 WGC3Dintptr offset) { |
| 222 gl_->DrawElements( | 215 gl_->DrawElements( |
| 223 mode, count, type, | 216 mode, count, type, |
| 224 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); | 217 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); |
| 225 } | 218 } |
| 226 | 219 |
| 227 bool WebGraphicsContext3DImpl::getActiveAttrib( | 220 bool WebGraphicsContext3DImpl::getActiveAttrib( |
| 228 WebGLId program, WGC3Duint index, ActiveInfo& info) { | 221 WebGLId program, WGC3Duint index, ActiveInfo& info) { |
| 229 if (!program) { | |
| 230 synthesizeGLError(GL_INVALID_VALUE); | |
| 231 return false; | |
| 232 } | |
| 233 GLint max_name_length = -1; | 222 GLint max_name_length = -1; |
| 234 gl_->GetProgramiv( | 223 gl_->GetProgramiv( |
| 235 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); | 224 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); |
| 236 if (max_name_length < 0) | 225 // The caller already checked that there is some active attribute. |
| 237 return false; | 226 DCHECK_GT(max_name_length, 0); |
| 238 if (max_name_length == 0) { | |
| 239 // No active attributes exist. | |
| 240 synthesizeGLError(GL_INVALID_VALUE); | |
| 241 return false; | |
| 242 } | |
| 243 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); | 227 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); |
| 244 GLsizei length = 0; | 228 GLsizei length = 0; |
| 245 GLint size = -1; | 229 GLint size = -1; |
| 246 GLenum type = 0; | 230 GLenum type = 0; |
| 247 gl_->GetActiveAttrib( | 231 gl_->GetActiveAttrib( |
| 248 program, index, max_name_length, &length, &size, &type, name.get()); | 232 program, index, max_name_length, &length, &size, &type, name.get()); |
| 249 if (size < 0) { | 233 if (size < 0) { |
| 250 return false; | 234 return false; |
| 251 } | 235 } |
| 252 info.name = blink::WebString::fromUTF8(name.get(), length); | 236 info.name = blink::WebString::fromUTF8(name.get(), length); |
| 253 info.type = type; | 237 info.type = type; |
| 254 info.size = size; | 238 info.size = size; |
| 255 return true; | 239 return true; |
| 256 } | 240 } |
| 257 | 241 |
| 258 bool WebGraphicsContext3DImpl::getActiveUniform( | 242 bool WebGraphicsContext3DImpl::getActiveUniform( |
| 259 WebGLId program, WGC3Duint index, ActiveInfo& info) { | 243 WebGLId program, WGC3Duint index, ActiveInfo& info) { |
| 260 GLint max_name_length = -1; | 244 GLint max_name_length = -1; |
| 261 gl_->GetProgramiv( | 245 gl_->GetProgramiv( |
| 262 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); | 246 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); |
| 263 if (max_name_length < 0) | 247 // The caller already checked that there is some active uniform. |
| 264 return false; | 248 DCHECK_GT(max_name_length, 0); |
| 265 if (max_name_length == 0) { | |
| 266 // No active uniforms exist. | |
| 267 synthesizeGLError(GL_INVALID_VALUE); | |
| 268 return false; | |
| 269 } | |
| 270 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); | 249 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); |
| 271 GLsizei length = 0; | 250 GLsizei length = 0; |
| 272 GLint size = -1; | 251 GLint size = -1; |
| 273 GLenum type = 0; | 252 GLenum type = 0; |
| 274 gl_->GetActiveUniform( | 253 gl_->GetActiveUniform( |
| 275 program, index, max_name_length, &length, &size, &type, name.get()); | 254 program, index, max_name_length, &length, &size, &type, name.get()); |
| 276 if (size < 0) { | 255 if (size < 0) { |
| 277 return false; | 256 return false; |
| 278 } | 257 } |
| 279 info.name = blink::WebString::fromUTF8(name.get(), length); | 258 info.name = blink::WebString::fromUTF8(name.get(), length); |
| 280 info.type = type; | 259 info.type = type; |
| 281 info.size = size; | 260 info.size = size; |
| 282 return true; | 261 return true; |
| 283 } | 262 } |
| 284 | 263 |
| 285 WGC3Denum WebGraphicsContext3DImpl::getError() { | |
| 286 if (!synthetic_errors_.empty()) { | |
| 287 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin(); | |
| 288 WGC3Denum err = *iter; | |
| 289 synthetic_errors_.erase(iter); | |
| 290 return err; | |
| 291 } | |
| 292 | |
| 293 return gl_->GetError(); | |
| 294 } | |
| 295 | |
| 296 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog( | 264 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog( |
| 297 WebGLId program) { | 265 WebGLId program) { |
| 298 GLint logLength = 0; | 266 GLint logLength = 0; |
| 299 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); | 267 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); |
| 300 if (!logLength) | 268 if (!logLength) |
| 301 return blink::WebString(); | 269 return blink::WebString(); |
| 302 scoped_ptr<GLchar[]> log(new GLchar[logLength]); | 270 scoped_ptr<GLchar[]> log(new GLchar[logLength]); |
| 303 if (!log) | 271 if (!log) |
| 304 return blink::WebString(); | 272 return blink::WebString(); |
| 305 GLsizei returnedLogLength = 0; | 273 GLsizei returnedLogLength = 0; |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_WEBGL2; | 650 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_WEBGL2; |
| 683 break; | 651 break; |
| 684 default: | 652 default: |
| 685 NOTREACHED(); | 653 NOTREACHED(); |
| 686 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_OPENGLES2; | 654 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_OPENGLES2; |
| 687 break; | 655 break; |
| 688 } | 656 } |
| 689 } | 657 } |
| 690 | 658 |
| 691 } // namespace gpu_blink | 659 } // namespace gpu_blink |
| OLD | NEW |