| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/webgl/WebGL2RenderingContextBase.h" | 5 #include "modules/webgl/WebGL2RenderingContextBase.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include "bindings/modules/v8/WebGLAny.h" | 8 #include "bindings/modules/v8/WebGLAny.h" |
| 9 #include "core/frame/ImageBitmap.h" | 9 #include "core/frame/ImageBitmap.h" |
| 10 #include "core/html/HTMLCanvasElement.h" | 10 #include "core/html/HTMLCanvasElement.h" |
| (...skipping 3445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3456 "COLOR_ATTACHMENTi_EXT or NONE"); | 3456 "COLOR_ATTACHMENTi_EXT or NONE"); |
| 3457 return; | 3457 return; |
| 3458 } | 3458 } |
| 3459 } | 3459 } |
| 3460 framebuffer_binding_->DrawBuffers(buffers); | 3460 framebuffer_binding_->DrawBuffers(buffers); |
| 3461 } | 3461 } |
| 3462 } | 3462 } |
| 3463 | 3463 |
| 3464 bool WebGL2RenderingContextBase::ValidateClearBuffer(const char* function_name, | 3464 bool WebGL2RenderingContextBase::ValidateClearBuffer(const char* function_name, |
| 3465 GLenum buffer, | 3465 GLenum buffer, |
| 3466 GLsizei size) { | 3466 GLsizei size, |
| 3467 GLuint src_offset) { |
| 3468 CheckedNumeric<GLsizei> checked_size(size); |
| 3469 checked_size -= src_offset; |
| 3470 if (!checked_size.IsValid()) { |
| 3471 SynthesizeGLError(GL_INVALID_VALUE, function_name, |
| 3472 "invalid array size / srcOffset"); |
| 3473 return false; |
| 3474 } |
| 3467 switch (buffer) { | 3475 switch (buffer) { |
| 3468 case GL_COLOR: | 3476 case GL_COLOR: |
| 3469 if (size < 4) { | 3477 if (checked_size.ValueOrDie() < 4) { |
| 3470 SynthesizeGLError(GL_INVALID_VALUE, function_name, | 3478 SynthesizeGLError(GL_INVALID_VALUE, function_name, |
| 3471 "invalid array size"); | 3479 "invalid array size / srcOffset"); |
| 3472 return false; | 3480 return false; |
| 3473 } | 3481 } |
| 3474 break; | 3482 break; |
| 3475 case GL_DEPTH: | 3483 case GL_DEPTH: |
| 3476 case GL_STENCIL: | 3484 case GL_STENCIL: |
| 3477 if (size < 1) { | 3485 if (checked_size.ValueOrDie() < 1) { |
| 3478 SynthesizeGLError(GL_INVALID_VALUE, function_name, | 3486 SynthesizeGLError(GL_INVALID_VALUE, function_name, |
| 3479 "invalid array size"); | 3487 "invalid array size / srcOffset"); |
| 3480 return false; | 3488 return false; |
| 3481 } | 3489 } |
| 3482 break; | 3490 break; |
| 3483 default: | 3491 default: |
| 3484 SynthesizeGLError(GL_INVALID_ENUM, function_name, "invalid buffer"); | 3492 SynthesizeGLError(GL_INVALID_ENUM, function_name, "invalid buffer"); |
| 3485 return false; | 3493 return false; |
| 3486 } | 3494 } |
| 3487 return true; | 3495 return true; |
| 3488 } | 3496 } |
| 3489 | 3497 |
| 3490 WebGLTexture* WebGL2RenderingContextBase::ValidateTexImageBinding( | 3498 WebGLTexture* WebGL2RenderingContextBase::ValidateTexImageBinding( |
| 3491 const char* func_name, | 3499 const char* func_name, |
| 3492 TexImageFunctionID function_id, | 3500 TexImageFunctionID function_id, |
| 3493 GLenum target) { | 3501 GLenum target) { |
| 3494 if (function_id == kTexImage3D || function_id == kTexSubImage3D) | 3502 if (function_id == kTexImage3D || function_id == kTexSubImage3D) |
| 3495 return ValidateTexture3DBinding(func_name, target); | 3503 return ValidateTexture3DBinding(func_name, target); |
| 3496 return ValidateTexture2DBinding(func_name, target); | 3504 return ValidateTexture2DBinding(func_name, target); |
| 3497 } | 3505 } |
| 3498 | 3506 |
| 3499 void WebGL2RenderingContextBase::clearBufferiv(GLenum buffer, | 3507 void WebGL2RenderingContextBase::clearBufferiv(GLenum buffer, |
| 3500 GLint drawbuffer, | 3508 GLint drawbuffer, |
| 3501 NotShared<DOMInt32Array> value) { | 3509 NotShared<DOMInt32Array> value, |
| 3510 GLuint src_offset) { |
| 3502 if (isContextLost() || | 3511 if (isContextLost() || |
| 3503 !ValidateClearBuffer("clearBufferiv", buffer, value.View()->length())) | 3512 !ValidateClearBuffer("clearBufferiv", buffer, value.View()->length(), |
| 3513 src_offset)) |
| 3504 return; | 3514 return; |
| 3505 | 3515 |
| 3506 ContextGL()->ClearBufferiv(buffer, drawbuffer, value.View()->Data()); | 3516 ContextGL()->ClearBufferiv(buffer, drawbuffer, |
| 3517 value.View()->Data() + src_offset); |
| 3507 } | 3518 } |
| 3508 | 3519 |
| 3509 void WebGL2RenderingContextBase::clearBufferiv(GLenum buffer, | 3520 void WebGL2RenderingContextBase::clearBufferiv(GLenum buffer, |
| 3510 GLint drawbuffer, | 3521 GLint drawbuffer, |
| 3511 const Vector<GLint>& value) { | 3522 const Vector<GLint>& value, |
| 3523 GLuint src_offset) { |
| 3512 if (isContextLost() || | 3524 if (isContextLost() || |
| 3513 !ValidateClearBuffer("clearBufferiv", buffer, value.size())) | 3525 !ValidateClearBuffer("clearBufferiv", buffer, value.size(), src_offset)) |
| 3514 return; | 3526 return; |
| 3515 | 3527 |
| 3516 ContextGL()->ClearBufferiv(buffer, drawbuffer, value.Data()); | 3528 ContextGL()->ClearBufferiv(buffer, drawbuffer, value.Data() + src_offset); |
| 3517 } | |
| 3518 | |
| 3519 void WebGL2RenderingContextBase::clearBufferuiv( | |
| 3520 GLenum buffer, | |
| 3521 GLint drawbuffer, | |
| 3522 NotShared<DOMUint32Array> value) { | |
| 3523 if (isContextLost() || | |
| 3524 !ValidateClearBuffer("clearBufferuiv", buffer, value.View()->length())) | |
| 3525 return; | |
| 3526 | |
| 3527 ContextGL()->ClearBufferuiv(buffer, drawbuffer, value.View()->Data()); | |
| 3528 } | 3529 } |
| 3529 | 3530 |
| 3530 void WebGL2RenderingContextBase::clearBufferuiv(GLenum buffer, | 3531 void WebGL2RenderingContextBase::clearBufferuiv(GLenum buffer, |
| 3531 GLint drawbuffer, | 3532 GLint drawbuffer, |
| 3532 const Vector<GLuint>& value) { | 3533 NotShared<DOMUint32Array> value, |
| 3534 GLuint src_offset) { |
| 3533 if (isContextLost() || | 3535 if (isContextLost() || |
| 3534 !ValidateClearBuffer("clearBufferuiv", buffer, value.size())) | 3536 !ValidateClearBuffer("clearBufferuiv", buffer, value.View()->length(), |
| 3537 src_offset)) |
| 3535 return; | 3538 return; |
| 3536 | 3539 |
| 3537 ContextGL()->ClearBufferuiv(buffer, drawbuffer, value.Data()); | 3540 ContextGL()->ClearBufferuiv(buffer, drawbuffer, |
| 3541 value.View()->Data() + src_offset); |
| 3538 } | 3542 } |
| 3539 | 3543 |
| 3540 void WebGL2RenderingContextBase::clearBufferfv( | 3544 void WebGL2RenderingContextBase::clearBufferuiv(GLenum buffer, |
| 3541 GLenum buffer, | 3545 GLint drawbuffer, |
| 3542 GLint drawbuffer, | 3546 const Vector<GLuint>& value, |
| 3543 NotShared<DOMFloat32Array> value) { | 3547 GLuint src_offset) { |
| 3544 if (isContextLost() || | 3548 if (isContextLost() || |
| 3545 !ValidateClearBuffer("clearBufferfv", buffer, value.View()->length())) | 3549 !ValidateClearBuffer("clearBufferuiv", buffer, value.size(), src_offset)) |
| 3546 return; | 3550 return; |
| 3547 | 3551 |
| 3548 ContextGL()->ClearBufferfv(buffer, drawbuffer, value.View()->Data()); | 3552 ContextGL()->ClearBufferuiv(buffer, drawbuffer, value.Data() + src_offset); |
| 3549 } | 3553 } |
| 3550 | 3554 |
| 3551 void WebGL2RenderingContextBase::clearBufferfv(GLenum buffer, | 3555 void WebGL2RenderingContextBase::clearBufferfv(GLenum buffer, |
| 3552 GLint drawbuffer, | 3556 GLint drawbuffer, |
| 3553 const Vector<GLfloat>& value) { | 3557 NotShared<DOMFloat32Array> value, |
| 3558 GLuint src_offset) { |
| 3554 if (isContextLost() || | 3559 if (isContextLost() || |
| 3555 !ValidateClearBuffer("clearBufferfv", buffer, value.size())) | 3560 !ValidateClearBuffer("clearBufferfv", buffer, value.View()->length(), |
| 3561 src_offset)) |
| 3556 return; | 3562 return; |
| 3557 | 3563 |
| 3558 ContextGL()->ClearBufferfv(buffer, drawbuffer, value.Data()); | 3564 ContextGL()->ClearBufferfv(buffer, drawbuffer, |
| 3565 value.View()->Data() + src_offset); |
| 3566 } |
| 3567 |
| 3568 void WebGL2RenderingContextBase::clearBufferfv(GLenum buffer, |
| 3569 GLint drawbuffer, |
| 3570 const Vector<GLfloat>& value, |
| 3571 GLuint src_offset) { |
| 3572 if (isContextLost() || |
| 3573 !ValidateClearBuffer("clearBufferfv", buffer, value.size(), src_offset)) |
| 3574 return; |
| 3575 |
| 3576 ContextGL()->ClearBufferfv(buffer, drawbuffer, value.Data() + src_offset); |
| 3559 } | 3577 } |
| 3560 | 3578 |
| 3561 void WebGL2RenderingContextBase::clearBufferfi(GLenum buffer, | 3579 void WebGL2RenderingContextBase::clearBufferfi(GLenum buffer, |
| 3562 GLint drawbuffer, | 3580 GLint drawbuffer, |
| 3563 GLfloat depth, | 3581 GLfloat depth, |
| 3564 GLint stencil) { | 3582 GLint stencil) { |
| 3565 if (isContextLost()) | 3583 if (isContextLost()) |
| 3566 return; | 3584 return; |
| 3567 | 3585 |
| 3568 ContextGL()->ClearBufferfi(buffer, drawbuffer, depth, stencil); | 3586 ContextGL()->ClearBufferfi(buffer, drawbuffer, depth, stencil); |
| (...skipping 2121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5690 | 5708 |
| 5691 void WebGL2RenderingContextBase:: | 5709 void WebGL2RenderingContextBase:: |
| 5692 DrawingBufferClientRestorePixelUnpackBufferBinding() { | 5710 DrawingBufferClientRestorePixelUnpackBufferBinding() { |
| 5693 if (!ContextGL()) | 5711 if (!ContextGL()) |
| 5694 return; | 5712 return; |
| 5695 ContextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, | 5713 ContextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, |
| 5696 ObjectOrZero(bound_pixel_unpack_buffer_.Get())); | 5714 ObjectOrZero(bound_pixel_unpack_buffer_.Get())); |
| 5697 } | 5715 } |
| 5698 | 5716 |
| 5699 } // namespace blink | 5717 } // namespace blink |
| OLD | NEW |