Chromium Code Reviews| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 // type size is at most 8, so no overflow. | 60 // type size is at most 8, so no overflow. |
| 61 byte_length = sub_length * type_size; | 61 byte_length = sub_length * type_size; |
| 62 } | 62 } |
| 63 long long byte_offset = 0; | 63 long long byte_offset = 0; |
| 64 if (sub_offset) { | 64 if (sub_offset) { |
| 65 // type size is at most 8, so no overflow. | 65 // type size is at most 8, so no overflow. |
| 66 byte_offset = sub_offset * type_size; | 66 byte_offset = sub_offset * type_size; |
| 67 } | 67 } |
| 68 CheckedNumeric<long long> total = byte_offset; | 68 CheckedNumeric<long long> total = byte_offset; |
| 69 total += byte_length; | 69 total += byte_length; |
| 70 if (!total.IsValid() || total.ValueOrDie() > view->byteLength()) { | 70 if (!total.IsValid() || total.ValueOrDefault(0) > view->byteLength()) { |
|
Ken Russell (switch to Gerrit)
2017/04/12 18:56:49
Here and throughout, I think we should continue to
Zhenyao Mo
2017/04/12 20:14:53
Done.
| |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 if (!byte_length) { | 73 if (!byte_length) { |
| 74 byte_length = view->byteLength() - byte_offset; | 74 byte_length = view->byteLength() - byte_offset; |
| 75 } | 75 } |
| 76 uint8_t* data = static_cast<uint8_t*>(view->BaseAddress()); | 76 uint8_t* data = static_cast<uint8_t*>(view->BaseAddress()); |
| 77 data += byte_offset; | 77 data += byte_offset; |
| 78 *out_base_address = data; | 78 *out_base_address = data; |
| 79 *out_byte_length = byte_length; | 79 *out_byte_length = byte_length; |
| 80 return true; | 80 return true; |
| (...skipping 3375 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.ValueOrDefault(0) < 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.ValueOrDefault(0) < 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 2056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5625 return nullptr; | 5643 return nullptr; |
| 5626 } | 5644 } |
| 5627 | 5645 |
| 5628 const char* WebGL2RenderingContextBase::ValidateGetBufferSubDataBounds( | 5646 const char* WebGL2RenderingContextBase::ValidateGetBufferSubDataBounds( |
| 5629 const char* function_name, | 5647 const char* function_name, |
| 5630 WebGLBuffer* source_buffer, | 5648 WebGLBuffer* source_buffer, |
| 5631 GLintptr source_byte_offset, | 5649 GLintptr source_byte_offset, |
| 5632 long long destination_byte_length) { | 5650 long long destination_byte_length) { |
| 5633 CheckedNumeric<long long> src_end = source_byte_offset; | 5651 CheckedNumeric<long long> src_end = source_byte_offset; |
| 5634 src_end += destination_byte_length; | 5652 src_end += destination_byte_length; |
| 5635 if (!src_end.IsValid() || src_end.ValueOrDie() > source_buffer->GetSize()) { | 5653 if (!src_end.IsValid() || |
| 5654 src_end.ValueOrDefault(0) > source_buffer->GetSize()) { | |
| 5636 SynthesizeGLError(GL_INVALID_VALUE, function_name, | 5655 SynthesizeGLError(GL_INVALID_VALUE, function_name, |
| 5637 "overflow of bound buffer"); | 5656 "overflow of bound buffer"); |
| 5638 return "Invalid value: overflow of bound buffer"; | 5657 return "Invalid value: overflow of bound buffer"; |
| 5639 } | 5658 } |
| 5640 | 5659 |
| 5641 return nullptr; | 5660 return nullptr; |
| 5642 } | 5661 } |
| 5643 | 5662 |
| 5644 void WebGL2RenderingContextBase::RemoveBoundBuffer(WebGLBuffer* buffer) { | 5663 void WebGL2RenderingContextBase::RemoveBoundBuffer(WebGLBuffer* buffer) { |
| 5645 if (bound_copy_read_buffer_ == buffer) | 5664 if (bound_copy_read_buffer_ == buffer) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5690 | 5709 |
| 5691 void WebGL2RenderingContextBase:: | 5710 void WebGL2RenderingContextBase:: |
| 5692 DrawingBufferClientRestorePixelUnpackBufferBinding() { | 5711 DrawingBufferClientRestorePixelUnpackBufferBinding() { |
| 5693 if (!ContextGL()) | 5712 if (!ContextGL()) |
| 5694 return; | 5713 return; |
| 5695 ContextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, | 5714 ContextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, |
| 5696 ObjectOrZero(bound_pixel_unpack_buffer_.Get())); | 5715 ObjectOrZero(bound_pixel_unpack_buffer_.Get())); |
| 5697 } | 5716 } |
| 5698 | 5717 |
| 5699 } // namespace blink | 5718 } // namespace blink |
| OLD | NEW |