Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: Source/core/html/canvas/WebGL2RenderingContextBase.cpp

Issue 1205573003: WebGL 2: validate read buffer attachment when reading from FBO (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed zmo@'s feedback: translate GL_COLOR_ATTACHMENT0 to GL_BACK in getter for default fb Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "core/html/canvas/WebGL2RenderingContextBase.h" 6 #include "core/html/canvas/WebGL2RenderingContextBase.h"
7 7
8 #include "bindings/core/v8/WebGLAny.h" 8 #include "bindings/core/v8/WebGLAny.h"
9 #include "core/html/HTMLCanvasElement.h" 9 #include "core/html/HTMLCanvasElement.h"
10 #include "core/html/HTMLImageElement.h" 10 #include "core/html/HTMLImageElement.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return; 167 return;
168 168
169 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen ts.data(), x, y, width, height); 169 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen ts.data(), x, y, width, height);
170 } 170 }
171 171
172 void WebGL2RenderingContextBase::readBuffer(GLenum mode) 172 void WebGL2RenderingContextBase::readBuffer(GLenum mode)
173 { 173 {
174 if (isContextLost()) 174 if (isContextLost())
175 return; 175 return;
176 176
177 switch (mode) {
178 case GL_BACK:
179 case GL_NONE:
180 case GL_COLOR_ATTACHMENT0:
181 break;
182 default:
183 if (mode > GL_COLOR_ATTACHMENT0
184 && mode < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorAttachm ents()))
185 break;
186 synthesizeGLError(GL_INVALID_ENUM, "readBuffer", "invalid read buffer");
187 return;
188 }
189
190 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(GL_READ_FRA MEBUFFER);
191 if (!readFramebufferBinding) {
192 ASSERT(drawingBuffer());
193 if (mode != GL_BACK && mode != GL_NONE) {
194 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
195 return;
196 }
197 // translate GL_BACK to GL_COLOR_ATTACHMENT0, because the default
198 // framebuffer for WebGL is not fb 0, it is an internal fbo.
199 if (mode == GL_BACK)
200 mode = GL_COLOR_ATTACHMENT0;
201 } else {
202 if (mode == GL_BACK) {
203 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
204 return;
205 }
206 m_readbufferOfFBO = mode;
207 }
177 webContext()->readBuffer(mode); 208 webContext()->readBuffer(mode);
178 } 209 }
179 210
180 void WebGL2RenderingContextBase::renderbufferStorageImpl( 211 void WebGL2RenderingContextBase::renderbufferStorageImpl(
181 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height, 212 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height,
182 const char* functionName) 213 const char* functionName)
183 { 214 {
184 switch (internalformat) { 215 switch (internalformat) {
185 case GL_R8UI: 216 case GL_R8UI:
186 case GL_R8I: 217 case GL_R8I:
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 return getIntParameter(scriptState, pname); 1801 return getIntParameter(scriptState, pname);
1771 case GL_PACK_SKIP_ROWS: 1802 case GL_PACK_SKIP_ROWS:
1772 return getIntParameter(scriptState, pname); 1803 return getIntParameter(scriptState, pname);
1773 case GL_PIXEL_PACK_BUFFER_BINDING: 1804 case GL_PIXEL_PACK_BUFFER_BINDING:
1774 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_bound PixelPackBuffer.get())); 1805 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_bound PixelPackBuffer.get()));
1775 case GL_PIXEL_UNPACK_BUFFER_BINDING: 1806 case GL_PIXEL_UNPACK_BUFFER_BINDING:
1776 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_bound PixelUnpackBuffer.get())); 1807 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_bound PixelUnpackBuffer.get()));
1777 case GL_RASTERIZER_DISCARD: 1808 case GL_RASTERIZER_DISCARD:
1778 return getBooleanParameter(scriptState, pname); 1809 return getBooleanParameter(scriptState, pname);
1779 case GL_READ_BUFFER: 1810 case GL_READ_BUFFER:
1780 return getUnsignedIntParameter(scriptState, pname); 1811 {
1812 GLint value = 0;
1813 if (!isContextLost()) {
1814 webContext()->getIntegerv(pname, &value);
1815 // translate GL_COLOR_ATTACHMENT0 to GL_BACK for the default fra mebuffer
1816 if (value == GL_COLOR_ATTACHMENT0 && !getFramebufferBinding(GL_R EAD_FRAMEBUFFER))
1817 value = GL_BACK;
1818 }
1819 return WebGLAny(scriptState, static_cast<unsigned>(value));
1820 }
1781 case GL_READ_FRAMEBUFFER_BINDING: 1821 case GL_READ_FRAMEBUFFER_BINDING:
1782 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_readF ramebufferBinding.get())); 1822 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_readF ramebufferBinding.get()));
1783 case GL_SAMPLE_ALPHA_TO_COVERAGE: 1823 case GL_SAMPLE_ALPHA_TO_COVERAGE:
1784 return getBooleanParameter(scriptState, pname); 1824 return getBooleanParameter(scriptState, pname);
1785 case GL_SAMPLE_COVERAGE: 1825 case GL_SAMPLE_COVERAGE:
1786 return getBooleanParameter(scriptState, pname); 1826 return getBooleanParameter(scriptState, pname);
1787 // case GL_SAMPLER_BINDING WebGLSampler 1827 // case GL_SAMPLER_BINDING WebGLSampler
1788 case GL_TEXTURE_BINDING_2D_ARRAY: 1828 case GL_TEXTURE_BINDING_2D_ARRAY:
1789 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_textu reUnits[m_activeTextureUnit].m_texture2DArrayBinding.get())); 1829 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_textu reUnits[m_activeTextureUnit].m_texture2DArrayBinding.get()));
1790 case GL_TEXTURE_BINDING_3D: 1830 case GL_TEXTURE_BINDING_3D:
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() 2264 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat()
2225 { 2265 {
2226 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) 2266 if (m_readFramebufferBinding && m_readFramebufferBinding->object())
2227 return m_readFramebufferBinding->colorBufferFormat(); 2267 return m_readFramebufferBinding->colorBufferFormat();
2228 if (m_requestedAttributes.alpha()) 2268 if (m_requestedAttributes.alpha())
2229 return GL_RGBA; 2269 return GL_RGBA;
2230 return GL_RGB; 2270 return GL_RGB;
2231 } 2271 }
2232 2272
2233 } // namespace blink 2273 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698