| 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 bool WebGraphicsContext3DImpl::genSyncTokenCHROMIUM(WGC3Duint64 fenceSync, | 195 bool WebGraphicsContext3DImpl::genSyncTokenCHROMIUM(WGC3Duint64 fenceSync, |
| 203 WGC3Dbyte* syncToken) { | 196 WGC3Dbyte* syncToken) { |
| 204 gl_->GenSyncTokenCHROMIUM(fenceSync, syncToken); | 197 gl_->GenSyncTokenCHROMIUM(fenceSync, syncToken); |
| 205 return true; | 198 return true; |
| 206 } | 199 } |
| 207 | 200 |
| 208 blink::WebString WebGraphicsContext3DImpl:: | 201 blink::WebString WebGraphicsContext3DImpl:: |
| 209 getRequestableExtensionsCHROMIUM() { | 202 getRequestableExtensionsCHROMIUM() { |
| 210 return blink::WebString::fromUTF8( | 203 return blink::WebString::fromUTF8( |
| 211 gl_->GetRequestableExtensionsCHROMIUM()); | 204 gl_->GetRequestableExtensionsCHROMIUM()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 225 WGC3Dsizei count, | 218 WGC3Dsizei count, |
| 226 WGC3Denum type, | 219 WGC3Denum type, |
| 227 WGC3Dintptr offset) { | 220 WGC3Dintptr offset) { |
| 228 gl_->DrawElements( | 221 gl_->DrawElements( |
| 229 mode, count, type, | 222 mode, count, type, |
| 230 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); | 223 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); |
| 231 } | 224 } |
| 232 | 225 |
| 233 bool WebGraphicsContext3DImpl::getActiveAttrib( | 226 bool WebGraphicsContext3DImpl::getActiveAttrib( |
| 234 WebGLId program, WGC3Duint index, ActiveInfo& info) { | 227 WebGLId program, WGC3Duint index, ActiveInfo& info) { |
| 235 if (!program) { | |
| 236 synthesizeGLError(GL_INVALID_VALUE); | |
| 237 return false; | |
| 238 } | |
| 239 GLint max_name_length = -1; | 228 GLint max_name_length = -1; |
| 240 gl_->GetProgramiv( | 229 gl_->GetProgramiv( |
| 241 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); | 230 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); |
| 242 if (max_name_length < 0) | 231 // The caller already checked that there is some active attribute. |
| 243 return false; | 232 DCHECK_GT(max_name_length, 0); |
| 244 if (max_name_length == 0) { | |
| 245 // No active attributes exist. | |
| 246 synthesizeGLError(GL_INVALID_VALUE); | |
| 247 return false; | |
| 248 } | |
| 249 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); | 233 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); |
| 250 GLsizei length = 0; | 234 GLsizei length = 0; |
| 251 GLint size = -1; | 235 GLint size = -1; |
| 252 GLenum type = 0; | 236 GLenum type = 0; |
| 253 gl_->GetActiveAttrib( | 237 gl_->GetActiveAttrib( |
| 254 program, index, max_name_length, &length, &size, &type, name.get()); | 238 program, index, max_name_length, &length, &size, &type, name.get()); |
| 255 if (size < 0) { | 239 if (size < 0) { |
| 256 return false; | 240 return false; |
| 257 } | 241 } |
| 258 info.name = blink::WebString::fromUTF8(name.get(), length); | 242 info.name = blink::WebString::fromUTF8(name.get(), length); |
| 259 info.type = type; | 243 info.type = type; |
| 260 info.size = size; | 244 info.size = size; |
| 261 return true; | 245 return true; |
| 262 } | 246 } |
| 263 | 247 |
| 264 bool WebGraphicsContext3DImpl::getActiveUniform( | 248 bool WebGraphicsContext3DImpl::getActiveUniform( |
| 265 WebGLId program, WGC3Duint index, ActiveInfo& info) { | 249 WebGLId program, WGC3Duint index, ActiveInfo& info) { |
| 266 GLint max_name_length = -1; | 250 GLint max_name_length = -1; |
| 267 gl_->GetProgramiv( | 251 gl_->GetProgramiv( |
| 268 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); | 252 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); |
| 269 if (max_name_length < 0) | 253 // The caller already checked that there is some active uniform. |
| 270 return false; | 254 DCHECK_GT(max_name_length, 0); |
| 271 if (max_name_length == 0) { | |
| 272 // No active uniforms exist. | |
| 273 synthesizeGLError(GL_INVALID_VALUE); | |
| 274 return false; | |
| 275 } | |
| 276 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); | 255 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); |
| 277 GLsizei length = 0; | 256 GLsizei length = 0; |
| 278 GLint size = -1; | 257 GLint size = -1; |
| 279 GLenum type = 0; | 258 GLenum type = 0; |
| 280 gl_->GetActiveUniform( | 259 gl_->GetActiveUniform( |
| 281 program, index, max_name_length, &length, &size, &type, name.get()); | 260 program, index, max_name_length, &length, &size, &type, name.get()); |
| 282 if (size < 0) { | 261 if (size < 0) { |
| 283 return false; | 262 return false; |
| 284 } | 263 } |
| 285 info.name = blink::WebString::fromUTF8(name.get(), length); | 264 info.name = blink::WebString::fromUTF8(name.get(), length); |
| 286 info.type = type; | 265 info.type = type; |
| 287 info.size = size; | 266 info.size = size; |
| 288 return true; | 267 return true; |
| 289 } | 268 } |
| 290 | 269 |
| 291 WGC3Denum WebGraphicsContext3DImpl::getError() { | |
| 292 if (!synthetic_errors_.empty()) { | |
| 293 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin(); | |
| 294 WGC3Denum err = *iter; | |
| 295 synthetic_errors_.erase(iter); | |
| 296 return err; | |
| 297 } | |
| 298 | |
| 299 return gl_->GetError(); | |
| 300 } | |
| 301 | |
| 302 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog( | 270 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog( |
| 303 WebGLId program) { | 271 WebGLId program) { |
| 304 GLint logLength = 0; | 272 GLint logLength = 0; |
| 305 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); | 273 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); |
| 306 if (!logLength) | 274 if (!logLength) |
| 307 return blink::WebString(); | 275 return blink::WebString(); |
| 308 scoped_ptr<GLchar[]> log(new GLchar[logLength]); | 276 scoped_ptr<GLchar[]> log(new GLchar[logLength]); |
| 309 if (!log) | 277 if (!log) |
| 310 return blink::WebString(); | 278 return blink::WebString(); |
| 311 GLsizei returnedLogLength = 0; | 279 GLsizei returnedLogLength = 0; |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_WEBGL2; | 656 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_WEBGL2; |
| 689 break; | 657 break; |
| 690 default: | 658 default: |
| 691 NOTREACHED(); | 659 NOTREACHED(); |
| 692 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_OPENGLES2; | 660 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_OPENGLES2; |
| 693 break; | 661 break; |
| 694 } | 662 } |
| 695 } | 663 } |
| 696 | 664 |
| 697 } // namespace gpu_blink | 665 } // namespace gpu_blink |
| OLD | NEW |