| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 void WebGL2RenderingContextBase::DestroyContext() { | 191 void WebGL2RenderingContextBase::DestroyContext() { |
| 192 for (auto& callback : get_buffer_sub_data_async_callbacks_) { | 192 for (auto& callback : get_buffer_sub_data_async_callbacks_) { |
| 193 callback->Destroy(); | 193 callback->Destroy(); |
| 194 } | 194 } |
| 195 get_buffer_sub_data_async_callbacks_.clear(); | 195 get_buffer_sub_data_async_callbacks_.clear(); |
| 196 | 196 |
| 197 WebGLRenderingContextBase::DestroyContext(); | 197 WebGLRenderingContextBase::DestroyContext(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void WebGL2RenderingContextBase::InitializeNewContext() { | 200 void WebGL2RenderingContextBase::InitializeNewContext() { |
| 201 ASSERT(!isContextLost()); | 201 DCHECK(!isContextLost()); |
| 202 ASSERT(GetDrawingBuffer()); | 202 DCHECK(GetDrawingBuffer()); |
| 203 | 203 |
| 204 read_framebuffer_binding_ = nullptr; | 204 read_framebuffer_binding_ = nullptr; |
| 205 | 205 |
| 206 bound_copy_read_buffer_ = nullptr; | 206 bound_copy_read_buffer_ = nullptr; |
| 207 bound_copy_write_buffer_ = nullptr; | 207 bound_copy_write_buffer_ = nullptr; |
| 208 bound_pixel_pack_buffer_ = nullptr; | 208 bound_pixel_pack_buffer_ = nullptr; |
| 209 bound_pixel_unpack_buffer_ = nullptr; | 209 bound_pixel_unpack_buffer_ = nullptr; |
| 210 bound_uniform_buffer_ = nullptr; | 210 bound_uniform_buffer_ = nullptr; |
| 211 | 211 |
| 212 current_boolean_occlusion_query_ = nullptr; | 212 current_boolean_occlusion_query_ = nullptr; |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 mode < | 688 mode < |
| 689 static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + MaxColorAttachments())) | 689 static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + MaxColorAttachments())) |
| 690 break; | 690 break; |
| 691 SynthesizeGLError(GL_INVALID_ENUM, "readBuffer", "invalid read buffer"); | 691 SynthesizeGLError(GL_INVALID_ENUM, "readBuffer", "invalid read buffer"); |
| 692 return; | 692 return; |
| 693 } | 693 } |
| 694 | 694 |
| 695 WebGLFramebuffer* read_framebuffer_binding = | 695 WebGLFramebuffer* read_framebuffer_binding = |
| 696 GetFramebufferBinding(GL_READ_FRAMEBUFFER); | 696 GetFramebufferBinding(GL_READ_FRAMEBUFFER); |
| 697 if (!read_framebuffer_binding) { | 697 if (!read_framebuffer_binding) { |
| 698 ASSERT(GetDrawingBuffer()); | 698 DCHECK(GetDrawingBuffer()); |
| 699 if (mode != GL_BACK && mode != GL_NONE) { | 699 if (mode != GL_BACK && mode != GL_NONE) { |
| 700 SynthesizeGLError(GL_INVALID_OPERATION, "readBuffer", | 700 SynthesizeGLError(GL_INVALID_OPERATION, "readBuffer", |
| 701 "invalid read buffer"); | 701 "invalid read buffer"); |
| 702 return; | 702 return; |
| 703 } | 703 } |
| 704 read_buffer_of_default_framebuffer_ = mode; | 704 read_buffer_of_default_framebuffer_ = mode; |
| 705 // translate GL_BACK to GL_COLOR_ATTACHMENT0, because the default | 705 // translate GL_BACK to GL_COLOR_ATTACHMENT0, because the default |
| 706 // framebuffer for WebGL is not fb 0, it is an internal fbo. | 706 // framebuffer for WebGL is not fb 0, it is an internal fbo. |
| 707 if (mode == GL_BACK) | 707 if (mode == GL_BACK) |
| 708 mode = GL_COLOR_ATTACHMENT0; | 708 mode = GL_COLOR_ATTACHMENT0; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 GLsizei width, | 800 GLsizei width, |
| 801 GLsizei height, | 801 GLsizei height, |
| 802 GLenum format, | 802 GLenum format, |
| 803 GLenum type, | 803 GLenum type, |
| 804 long long offset) { | 804 long long offset) { |
| 805 if (isContextLost()) | 805 if (isContextLost()) |
| 806 return; | 806 return; |
| 807 | 807 |
| 808 // Due to WebGL's same-origin restrictions, it is not possible to | 808 // Due to WebGL's same-origin restrictions, it is not possible to |
| 809 // taint the origin using the WebGL API. | 809 // taint the origin using the WebGL API. |
| 810 ASSERT(canvas()->OriginClean()); | 810 DCHECK(canvas()->OriginClean()); |
| 811 | 811 |
| 812 if (!ValidateValueFitNonNegInt32("readPixels", "offset", offset)) | 812 if (!ValidateValueFitNonNegInt32("readPixels", "offset", offset)) |
| 813 return; | 813 return; |
| 814 | 814 |
| 815 WebGLBuffer* buffer = bound_pixel_pack_buffer_.Get(); | 815 WebGLBuffer* buffer = bound_pixel_pack_buffer_.Get(); |
| 816 if (!buffer) { | 816 if (!buffer) { |
| 817 SynthesizeGLError(GL_INVALID_OPERATION, "readPixels", | 817 SynthesizeGLError(GL_INVALID_OPERATION, "readPixels", |
| 818 "no PIXEL_PACK buffer bound"); | 818 "no PIXEL_PACK buffer bound"); |
| 819 return; | 819 return; |
| 820 } | 820 } |
| (...skipping 3729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4550 return 0; | 4550 return 0; |
| 4551 | 4551 |
| 4552 return ContextGL()->GetUniformBlockIndex(ObjectOrZero(program), | 4552 return ContextGL()->GetUniformBlockIndex(ObjectOrZero(program), |
| 4553 uniform_block_name.Utf8().data()); | 4553 uniform_block_name.Utf8().data()); |
| 4554 } | 4554 } |
| 4555 | 4555 |
| 4556 bool WebGL2RenderingContextBase::ValidateUniformBlockIndex( | 4556 bool WebGL2RenderingContextBase::ValidateUniformBlockIndex( |
| 4557 const char* function_name, | 4557 const char* function_name, |
| 4558 WebGLProgram* program, | 4558 WebGLProgram* program, |
| 4559 GLuint block_index) { | 4559 GLuint block_index) { |
| 4560 ASSERT(program); | 4560 DCHECK(program); |
| 4561 if (!program->LinkStatus(this)) { | 4561 if (!program->LinkStatus(this)) { |
| 4562 SynthesizeGLError(GL_INVALID_OPERATION, function_name, | 4562 SynthesizeGLError(GL_INVALID_OPERATION, function_name, |
| 4563 "program not linked"); | 4563 "program not linked"); |
| 4564 return false; | 4564 return false; |
| 4565 } | 4565 } |
| 4566 GLint active_uniform_blocks = 0; | 4566 GLint active_uniform_blocks = 0; |
| 4567 ContextGL()->GetProgramiv(ObjectOrZero(program), GL_ACTIVE_UNIFORM_BLOCKS, | 4567 ContextGL()->GetProgramiv(ObjectOrZero(program), GL_ACTIVE_UNIFORM_BLOCKS, |
| 4568 &active_uniform_blocks); | 4568 &active_uniform_blocks); |
| 4569 if (block_index >= static_cast<GLuint>(active_uniform_blocks)) { | 4569 if (block_index >= static_cast<GLuint>(active_uniform_blocks)) { |
| 4570 SynthesizeGLError(GL_INVALID_VALUE, function_name, | 4570 SynthesizeGLError(GL_INVALID_VALUE, function_name, |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4960 switch (cap) { | 4960 switch (cap) { |
| 4961 case GL_RASTERIZER_DISCARD: | 4961 case GL_RASTERIZER_DISCARD: |
| 4962 return true; | 4962 return true; |
| 4963 default: | 4963 default: |
| 4964 return WebGLRenderingContextBase::ValidateCapability(function_name, cap); | 4964 return WebGLRenderingContextBase::ValidateCapability(function_name, cap); |
| 4965 } | 4965 } |
| 4966 } | 4966 } |
| 4967 | 4967 |
| 4968 bool WebGL2RenderingContextBase::IsBufferBoundToTransformFeedback( | 4968 bool WebGL2RenderingContextBase::IsBufferBoundToTransformFeedback( |
| 4969 WebGLBuffer* buffer) { | 4969 WebGLBuffer* buffer) { |
| 4970 ASSERT(buffer); | 4970 DCHECK(buffer); |
| 4971 return transform_feedback_binding_->IsBufferBoundToTransformFeedback(buffer); | 4971 return transform_feedback_binding_->IsBufferBoundToTransformFeedback(buffer); |
| 4972 } | 4972 } |
| 4973 | 4973 |
| 4974 bool WebGL2RenderingContextBase::IsBufferBoundToNonTransformFeedback( | 4974 bool WebGL2RenderingContextBase::IsBufferBoundToNonTransformFeedback( |
| 4975 WebGLBuffer* buffer) { | 4975 WebGLBuffer* buffer) { |
| 4976 ASSERT(buffer); | 4976 DCHECK(buffer); |
| 4977 | 4977 |
| 4978 if (bound_array_buffer_ == buffer || | 4978 if (bound_array_buffer_ == buffer || |
| 4979 bound_vertex_array_object_->BoundElementArrayBuffer() == buffer || | 4979 bound_vertex_array_object_->BoundElementArrayBuffer() == buffer || |
| 4980 bound_copy_read_buffer_ == buffer || bound_copy_write_buffer_ == buffer || | 4980 bound_copy_read_buffer_ == buffer || bound_copy_write_buffer_ == buffer || |
| 4981 bound_pixel_pack_buffer_ == buffer || | 4981 bound_pixel_pack_buffer_ == buffer || |
| 4982 bound_pixel_unpack_buffer_ == buffer || bound_uniform_buffer_ == buffer) { | 4982 bound_pixel_unpack_buffer_ == buffer || bound_uniform_buffer_ == buffer) { |
| 4983 return true; | 4983 return true; |
| 4984 } | 4984 } |
| 4985 | 4985 |
| 4986 for (size_t i = 0; i <= max_bound_uniform_buffer_index_; ++i) { | 4986 for (size_t i = 0; i <= max_bound_uniform_buffer_index_; ++i) { |
| 4987 if (bound_indexed_uniform_buffers_[i] == buffer) | 4987 if (bound_indexed_uniform_buffers_[i] == buffer) |
| 4988 return true; | 4988 return true; |
| 4989 } | 4989 } |
| 4990 | 4990 |
| 4991 return false; | 4991 return false; |
| 4992 } | 4992 } |
| 4993 | 4993 |
| 4994 bool WebGL2RenderingContextBase::ValidateBufferTargetCompatibility( | 4994 bool WebGL2RenderingContextBase::ValidateBufferTargetCompatibility( |
| 4995 const char* function_name, | 4995 const char* function_name, |
| 4996 GLenum target, | 4996 GLenum target, |
| 4997 WebGLBuffer* buffer) { | 4997 WebGLBuffer* buffer) { |
| 4998 ASSERT(buffer); | 4998 DCHECK(buffer); |
| 4999 | 4999 |
| 5000 switch (buffer->GetInitialTarget()) { | 5000 switch (buffer->GetInitialTarget()) { |
| 5001 case GL_ELEMENT_ARRAY_BUFFER: | 5001 case GL_ELEMENT_ARRAY_BUFFER: |
| 5002 switch (target) { | 5002 switch (target) { |
| 5003 case GL_ARRAY_BUFFER: | 5003 case GL_ARRAY_BUFFER: |
| 5004 case GL_PIXEL_PACK_BUFFER: | 5004 case GL_PIXEL_PACK_BUFFER: |
| 5005 case GL_PIXEL_UNPACK_BUFFER: | 5005 case GL_PIXEL_UNPACK_BUFFER: |
| 5006 case GL_TRANSFORM_FEEDBACK_BUFFER: | 5006 case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 5007 case GL_UNIFORM_BUFFER: | 5007 case GL_UNIFORM_BUFFER: |
| 5008 SynthesizeGLError( | 5008 SynthesizeGLError( |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5770 | 5770 |
| 5771 void WebGL2RenderingContextBase:: | 5771 void WebGL2RenderingContextBase:: |
| 5772 DrawingBufferClientRestorePixelUnpackBufferBinding() { | 5772 DrawingBufferClientRestorePixelUnpackBufferBinding() { |
| 5773 if (!ContextGL()) | 5773 if (!ContextGL()) |
| 5774 return; | 5774 return; |
| 5775 ContextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, | 5775 ContextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, |
| 5776 ObjectOrZero(bound_pixel_unpack_buffer_.Get())); | 5776 ObjectOrZero(bound_pixel_unpack_buffer_.Get())); |
| 5777 } | 5777 } |
| 5778 | 5778 |
| 5779 } // namespace blink | 5779 } // namespace blink |
| OLD | NEW |