| 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 "bindings/modules/v8/WebGLAny.h" | 7 #include "bindings/modules/v8/WebGLAny.h" |
| 8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.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 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 GLenum type, | 904 GLenum type, |
| 905 DOMArrayBufferView* pixels) { | 905 DOMArrayBufferView* pixels) { |
| 906 if (isContextLost()) | 906 if (isContextLost()) |
| 907 return; | 907 return; |
| 908 if (m_boundPixelPackBuffer.get()) { | 908 if (m_boundPixelPackBuffer.get()) { |
| 909 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", | 909 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", |
| 910 "PIXEL_PACK buffer should not be bound"); | 910 "PIXEL_PACK buffer should not be bound"); |
| 911 return; | 911 return; |
| 912 } | 912 } |
| 913 | 913 |
| 914 WebGLRenderingContextBase::readPixels(x, y, width, height, format, type, | 914 readPixelsHelper(x, y, width, height, format, type, pixels, 0); |
| 915 pixels); | |
| 916 } | 915 } |
| 917 | 916 |
| 918 void WebGL2RenderingContextBase::readPixels(GLint x, | 917 void WebGL2RenderingContextBase::readPixels(GLint x, |
| 918 GLint y, |
| 919 GLsizei width, |
| 920 GLsizei height, |
| 921 GLenum format, |
| 922 GLenum type, |
| 923 DOMArrayBufferView* pixels, |
| 924 GLuint offset) { |
| 925 if (isContextLost()) |
| 926 return; |
| 927 if (m_boundPixelPackBuffer.get()) { |
| 928 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", |
| 929 "PIXEL_PACK buffer should not be bound"); |
| 930 return; |
| 931 } |
| 932 |
| 933 readPixelsHelper(x, y, width, height, format, type, pixels, offset); |
| 934 } |
| 935 |
| 936 void WebGL2RenderingContextBase::readPixels(GLint x, |
| 919 GLint y, | 937 GLint y, |
| 920 GLsizei width, | 938 GLsizei width, |
| 921 GLsizei height, | 939 GLsizei height, |
| 922 GLenum format, | 940 GLenum format, |
| 923 GLenum type, | 941 GLenum type, |
| 924 long long offset) { | 942 long long offset) { |
| 925 if (isContextLost()) | 943 if (isContextLost()) |
| 926 return; | 944 return; |
| 927 | 945 |
| 928 // Due to WebGL's same-origin restrictions, it is not possible to | 946 // Due to WebGL's same-origin restrictions, it is not possible to |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 WebGLFramebuffer* readFramebufferBinding = nullptr; | 1952 WebGLFramebuffer* readFramebufferBinding = nullptr; |
| 1935 if (!validateReadBufferAndGetInfo("copyTexSubImage3D", | 1953 if (!validateReadBufferAndGetInfo("copyTexSubImage3D", |
| 1936 readFramebufferBinding)) | 1954 readFramebufferBinding)) |
| 1937 return; | 1955 return; |
| 1938 clearIfComposited(); | 1956 clearIfComposited(); |
| 1939 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); | 1957 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); |
| 1940 contextGL()->CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, | 1958 contextGL()->CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, |
| 1941 width, height); | 1959 width, height); |
| 1942 } | 1960 } |
| 1943 | 1961 |
| 1962 void WebGL2RenderingContextBase::compressedTexImage2D( |
| 1963 GLenum target, |
| 1964 GLint level, |
| 1965 GLenum internalformat, |
| 1966 GLsizei width, |
| 1967 GLsizei height, |
| 1968 GLint border, |
| 1969 DOMArrayBufferView* data) { |
| 1970 WebGLRenderingContextBase::compressedTexImage2D(target, level, internalformat, |
| 1971 width, height, border, data); |
| 1972 } |
| 1973 |
| 1974 void WebGL2RenderingContextBase::compressedTexImage2D( |
| 1975 GLenum target, |
| 1976 GLint level, |
| 1977 GLenum internalformat, |
| 1978 GLsizei width, |
| 1979 GLsizei height, |
| 1980 GLint border, |
| 1981 DOMArrayBufferView* data, |
| 1982 GLuint srcOffset, |
| 1983 GLuint srcLengthOverride) { |
| 1984 if (isContextLost()) |
| 1985 return; |
| 1986 if (!validateTexture2DBinding("compressedTexImage2D", target)) |
| 1987 return; |
| 1988 if (!validateCompressedTexFormat("compressedTexImage2D", internalformat)) |
| 1989 return; |
| 1990 if (srcOffset > data->byteLength()) { |
| 1991 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage2D", |
| 1992 "srcOffset is out of range"); |
| 1993 return; |
| 1994 } |
| 1995 if (srcLengthOverride == 0) { |
| 1996 srcLengthOverride = data->byteLength() - srcOffset; |
| 1997 } else if (srcLengthOverride > data->byteLength() - srcOffset) { |
| 1998 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage2D", |
| 1999 "srcLengthOverride is out of range"); |
| 2000 } |
| 2001 contextGL()->CompressedTexImage2D( |
| 2002 target, level, internalformat, width, height, border, srcLengthOverride, |
| 2003 static_cast<uint8_t*>(data->baseAddress()) + srcOffset); |
| 2004 } |
| 2005 |
| 2006 void WebGL2RenderingContextBase::compressedTexSubImage2D( |
| 2007 GLenum target, |
| 2008 GLint level, |
| 2009 GLint xoffset, |
| 2010 GLint yoffset, |
| 2011 GLsizei width, |
| 2012 GLsizei height, |
| 2013 GLenum format, |
| 2014 DOMArrayBufferView* data) { |
| 2015 WebGLRenderingContextBase::compressedTexSubImage2D( |
| 2016 target, level, xoffset, yoffset, width, height, format, data); |
| 2017 } |
| 2018 |
| 2019 void WebGL2RenderingContextBase::compressedTexSubImage2D( |
| 2020 GLenum target, |
| 2021 GLint level, |
| 2022 GLint xoffset, |
| 2023 GLint yoffset, |
| 2024 GLsizei width, |
| 2025 GLsizei height, |
| 2026 GLenum format, |
| 2027 DOMArrayBufferView* data, |
| 2028 GLuint srcOffset, |
| 2029 GLuint srcLengthOverride) { |
| 2030 if (isContextLost()) |
| 2031 return; |
| 2032 if (!validateTexture2DBinding("compressedTexSubImage2D", target)) |
| 2033 return; |
| 2034 if (!validateCompressedTexFormat("compressedTexSubImage2D", format)) |
| 2035 return; |
| 2036 if (srcOffset > data->byteLength()) { |
| 2037 synthesizeGLError(GL_INVALID_VALUE, "compressedTexSubImage2D", |
| 2038 "srcOffset is out of range"); |
| 2039 return; |
| 2040 } |
| 2041 if (srcLengthOverride == 0) { |
| 2042 srcLengthOverride = data->byteLength() - srcOffset; |
| 2043 } else if (srcLengthOverride > data->byteLength() - srcOffset) { |
| 2044 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage2D", |
| 2045 "srcLengthOverride is out of range"); |
| 2046 } |
| 2047 contextGL()->CompressedTexSubImage2D( |
| 2048 target, level, xoffset, yoffset, width, height, format, srcLengthOverride, |
| 2049 static_cast<uint8_t*>(data->baseAddress()) + srcOffset); |
| 2050 } |
| 2051 |
| 1944 void WebGL2RenderingContextBase::compressedTexImage3D( | 2052 void WebGL2RenderingContextBase::compressedTexImage3D( |
| 1945 GLenum target, | 2053 GLenum target, |
| 1946 GLint level, | 2054 GLint level, |
| 1947 GLenum internalformat, | 2055 GLenum internalformat, |
| 1948 GLsizei width, | 2056 GLsizei width, |
| 1949 GLsizei height, | 2057 GLsizei height, |
| 1950 GLsizei depth, | 2058 GLsizei depth, |
| 1951 GLint border, | 2059 GLint border, |
| 1952 DOMArrayBufferView* data) { | 2060 DOMArrayBufferView* data, |
| 2061 GLuint srcOffset, |
| 2062 GLuint srcLengthOverride) { |
| 1953 if (isContextLost()) | 2063 if (isContextLost()) |
| 1954 return; | 2064 return; |
| 1955 if (!validateTexture3DBinding("compressedTexImage3D", target)) | 2065 if (!validateTexture3DBinding("compressedTexImage3D", target)) |
| 1956 return; | 2066 return; |
| 1957 if (!validateCompressedTexFormat("compressedTexImage3D", internalformat)) | 2067 if (!validateCompressedTexFormat("compressedTexImage3D", internalformat)) |
| 1958 return; | 2068 return; |
| 1959 contextGL()->CompressedTexImage3D(target, level, internalformat, width, | 2069 if (srcOffset > data->byteLength()) { |
| 1960 height, depth, border, data->byteLength(), | 2070 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage3D", |
| 1961 data->baseAddress()); | 2071 "srcOffset is out of range"); |
| 2072 return; |
| 2073 } |
| 2074 if (srcLengthOverride == 0) { |
| 2075 srcLengthOverride = data->byteLength() - srcOffset; |
| 2076 } else if (srcLengthOverride > data->byteLength() - srcOffset) { |
| 2077 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage3D", |
| 2078 "srcLengthOverride is out of range"); |
| 2079 } |
| 2080 contextGL()->CompressedTexImage3D( |
| 2081 target, level, internalformat, width, height, depth, border, |
| 2082 srcLengthOverride, |
| 2083 static_cast<uint8_t*>(data->baseAddress()) + srcOffset); |
| 1962 } | 2084 } |
| 1963 | 2085 |
| 1964 void WebGL2RenderingContextBase::compressedTexSubImage3D( | 2086 void WebGL2RenderingContextBase::compressedTexSubImage3D( |
| 1965 GLenum target, | 2087 GLenum target, |
| 1966 GLint level, | 2088 GLint level, |
| 1967 GLint xoffset, | 2089 GLint xoffset, |
| 1968 GLint yoffset, | 2090 GLint yoffset, |
| 1969 GLint zoffset, | 2091 GLint zoffset, |
| 1970 GLsizei width, | 2092 GLsizei width, |
| 1971 GLsizei height, | 2093 GLsizei height, |
| 1972 GLsizei depth, | 2094 GLsizei depth, |
| 1973 GLenum format, | 2095 GLenum format, |
| 1974 DOMArrayBufferView* data) { | 2096 DOMArrayBufferView* data, |
| 2097 GLuint srcOffset, |
| 2098 GLuint srcLengthOverride) { |
| 1975 if (isContextLost()) | 2099 if (isContextLost()) |
| 1976 return; | 2100 return; |
| 1977 if (!validateTexture3DBinding("compressedTexSubImage3D", target)) | 2101 if (!validateTexture3DBinding("compressedTexSubImage3D", target)) |
| 1978 return; | 2102 return; |
| 1979 if (!validateCompressedTexFormat("compressedTexSubImage3D", format)) | 2103 if (!validateCompressedTexFormat("compressedTexSubImage3D", format)) |
| 1980 return; | 2104 return; |
| 1981 contextGL()->CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, | 2105 if (srcOffset > data->byteLength()) { |
| 1982 width, height, depth, format, | 2106 synthesizeGLError(GL_INVALID_VALUE, "compressedTexSubImage3D", |
| 1983 data->byteLength(), data->baseAddress()); | 2107 "srcOffset is out of range"); |
| 2108 return; |
| 2109 } |
| 2110 if (srcLengthOverride == 0) { |
| 2111 srcLengthOverride = data->byteLength() - srcOffset; |
| 2112 } else if (srcLengthOverride > data->byteLength() - srcOffset) { |
| 2113 synthesizeGLError(GL_INVALID_VALUE, "compressedTexSubImage3D", |
| 2114 "srcLengthOverride is out of range"); |
| 2115 } |
| 2116 contextGL()->CompressedTexSubImage3D( |
| 2117 target, level, xoffset, yoffset, zoffset, width, height, depth, format, |
| 2118 srcLengthOverride, |
| 2119 static_cast<uint8_t*>(data->baseAddress()) + srcOffset); |
| 1984 } | 2120 } |
| 1985 | 2121 |
| 1986 GLint WebGL2RenderingContextBase::getFragDataLocation(WebGLProgram* program, | 2122 GLint WebGL2RenderingContextBase::getFragDataLocation(WebGLProgram* program, |
| 1987 const String& name) { | 2123 const String& name) { |
| 1988 if (isContextLost() || !validateWebGLObject("getFragDataLocation", program)) | 2124 if (isContextLost() || !validateWebGLObject("getFragDataLocation", program)) |
| 1989 return -1; | 2125 return -1; |
| 1990 | 2126 |
| 1991 return contextGL()->GetFragDataLocation(objectOrZero(program), | 2127 return contextGL()->GetFragDataLocation(objectOrZero(program), |
| 1992 name.utf8().data()); | 2128 name.utf8().data()); |
| 1993 } | 2129 } |
| (...skipping 2831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4825 | 4961 |
| 4826 void WebGL2RenderingContextBase:: | 4962 void WebGL2RenderingContextBase:: |
| 4827 DrawingBufferClientRestorePixelUnpackBufferBinding() { | 4963 DrawingBufferClientRestorePixelUnpackBufferBinding() { |
| 4828 if (!contextGL()) | 4964 if (!contextGL()) |
| 4829 return; | 4965 return; |
| 4830 contextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, | 4966 contextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, |
| 4831 objectOrZero(m_boundPixelUnpackBuffer.get())); | 4967 objectOrZero(m_boundPixelUnpackBuffer.get())); |
| 4832 } | 4968 } |
| 4833 | 4969 |
| 4834 } // namespace blink | 4970 } // namespace blink |
| OLD | NEW |