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

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: readbuffer is per framebuffer, not per rendering context 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 m_currentTransformFeedbackPrimitivesWrittenQuery = nullptr; 60 m_currentTransformFeedbackPrimitivesWrittenQuery = nullptr;
61 } 61 }
62 62
63 void WebGL2RenderingContextBase::initializeNewContext() 63 void WebGL2RenderingContextBase::initializeNewContext()
64 { 64 {
65 ASSERT(!isContextLost()); 65 ASSERT(!isContextLost());
66 ASSERT(drawingBuffer()); 66 ASSERT(drawingBuffer());
67 67
68 m_readFramebufferBinding = nullptr; 68 m_readFramebufferBinding = nullptr;
69 69
70 // set the default value of read buffer for drawing buffer
71 m_readBuffer = GL_BACK;
72
70 m_boundCopyReadBuffer = nullptr; 73 m_boundCopyReadBuffer = nullptr;
71 m_boundCopyWriteBuffer = nullptr; 74 m_boundCopyWriteBuffer = nullptr;
72 m_boundPixelPackBuffer = nullptr; 75 m_boundPixelPackBuffer = nullptr;
73 m_boundPixelUnpackBuffer = nullptr; 76 m_boundPixelUnpackBuffer = nullptr;
74 m_boundTransformFeedbackBuffer = nullptr; 77 m_boundTransformFeedbackBuffer = nullptr;
75 m_boundUniformBuffer = nullptr; 78 m_boundUniformBuffer = nullptr;
76 79
77 m_currentBooleanOcclusionQuery = nullptr; 80 m_currentBooleanOcclusionQuery = nullptr;
78 m_currentTransformFeedbackPrimitivesWrittenQuery = nullptr; 81 m_currentTransformFeedbackPrimitivesWrittenQuery = nullptr;
79 82
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return; 170 return;
168 171
169 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen ts.data(), x, y, width, height); 172 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen ts.data(), x, y, width, height);
170 } 173 }
171 174
172 void WebGL2RenderingContextBase::readBuffer(GLenum mode) 175 void WebGL2RenderingContextBase::readBuffer(GLenum mode)
173 { 176 {
174 if (isContextLost()) 177 if (isContextLost())
175 return; 178 return;
176 179
180 switch (mode) {
181 case GL_BACK:
182 case GL_NONE:
183 case GL_COLOR_ATTACHMENT0:
184 break;
185 default:
186 if (mode > GL_COLOR_ATTACHMENT0
187 && mode < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorAttachm ents()))
188 break;
189 synthesizeGLError(GL_INVALID_ENUM, "readBuffer", "invalid read buffer");
190 return;
191 }
192
193 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(GL_READ_FRA MEBUFFER);
194 if (!readFramebufferBinding) {
195 ASSERT(drawingBuffer());
196 if (mode != GL_BACK && mode != GL_NONE) {
197 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
198 return;
199 }
200 // translate GL_BACK to GL_COLOR_ATTACHMENT0, because the default
201 // framebuffer for WebGL is not fb 0, it is an internal fbo.
202 if (mode == GL_BACK)
203 mode = GL_COLOR_ATTACHMENT0;
204 m_readBuffer = mode;
Zhenyao Mo 2015/07/06 17:52:25 I think it's better to cache the original value he
Ken Russell (switch to Gerrit) 2015/07/06 21:19:13 I agree with Mo; it's clearer if the cache holds t
yunchao 2015/07/07 08:10:39 Yeah. Agree with you two. It should cache the orig
205 } else {
206 if (mode == GL_BACK) {
207 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
208 return;
209 }
210 readFramebufferBinding->readBuffer(mode);
211 }
177 webContext()->readBuffer(mode); 212 webContext()->readBuffer(mode);
178 } 213 }
179 214
180 void WebGL2RenderingContextBase::renderbufferStorageImpl( 215 void WebGL2RenderingContextBase::renderbufferStorageImpl(
181 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height, 216 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height,
182 const char* functionName) 217 const char* functionName)
183 { 218 {
184 switch (internalformat) { 219 switch (internalformat) {
185 case GL_R8UI: 220 case GL_R8UI:
186 case GL_R8I: 221 case GL_R8I:
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 return getIntParameter(scriptState, pname); 1805 return getIntParameter(scriptState, pname);
1771 case GL_PACK_SKIP_ROWS: 1806 case GL_PACK_SKIP_ROWS:
1772 return getIntParameter(scriptState, pname); 1807 return getIntParameter(scriptState, pname);
1773 case GL_PIXEL_PACK_BUFFER_BINDING: 1808 case GL_PIXEL_PACK_BUFFER_BINDING:
1774 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_bound PixelPackBuffer.get())); 1809 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_bound PixelPackBuffer.get()));
1775 case GL_PIXEL_UNPACK_BUFFER_BINDING: 1810 case GL_PIXEL_UNPACK_BUFFER_BINDING:
1776 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_bound PixelUnpackBuffer.get())); 1811 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_bound PixelUnpackBuffer.get()));
1777 case GL_RASTERIZER_DISCARD: 1812 case GL_RASTERIZER_DISCARD:
1778 return getBooleanParameter(scriptState, pname); 1813 return getBooleanParameter(scriptState, pname);
1779 case GL_READ_BUFFER: 1814 case GL_READ_BUFFER:
1780 return getUnsignedIntParameter(scriptState, pname); 1815 {
1816 GLint value = 0;
1817 if (!isContextLost()) {
1818 webContext()->getIntegerv(pname, &value);
1819 // translate GL_COLOR_ATTACHMENT0 to GL_BACK for the default fra mebuffer
1820 if (value == GL_COLOR_ATTACHMENT0 && !getFramebufferBinding(GL_R EAD_FRAMEBUFFER))
1821 value = GL_BACK;
Ken Russell (switch to Gerrit) 2015/07/06 21:19:13 The point of caching m_readBuffer is so that its v
yunchao 2015/07/07 08:10:39 Done.
1822 }
1823 return WebGLAny(scriptState, static_cast<unsigned>(value));
1824 }
1781 case GL_READ_FRAMEBUFFER_BINDING: 1825 case GL_READ_FRAMEBUFFER_BINDING:
1782 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_readF ramebufferBinding.get())); 1826 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_readF ramebufferBinding.get()));
1783 case GL_SAMPLE_ALPHA_TO_COVERAGE: 1827 case GL_SAMPLE_ALPHA_TO_COVERAGE:
1784 return getBooleanParameter(scriptState, pname); 1828 return getBooleanParameter(scriptState, pname);
1785 case GL_SAMPLE_COVERAGE: 1829 case GL_SAMPLE_COVERAGE:
1786 return getBooleanParameter(scriptState, pname); 1830 return getBooleanParameter(scriptState, pname);
1787 // case GL_SAMPLER_BINDING WebGLSampler 1831 // case GL_SAMPLER_BINDING WebGLSampler
1788 case GL_TEXTURE_BINDING_2D_ARRAY: 1832 case GL_TEXTURE_BINDING_2D_ARRAY:
1789 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_textu reUnits[m_activeTextureUnit].m_texture2DArrayBinding.get())); 1833 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_textu reUnits[m_activeTextureUnit].m_texture2DArrayBinding.get()));
1790 case GL_TEXTURE_BINDING_3D: 1834 case GL_TEXTURE_BINDING_3D:
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() 2268 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat()
2225 { 2269 {
2226 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) 2270 if (m_readFramebufferBinding && m_readFramebufferBinding->object())
2227 return m_readFramebufferBinding->colorBufferFormat(); 2271 return m_readFramebufferBinding->colorBufferFormat();
2228 if (m_requestedAttributes.alpha()) 2272 if (m_requestedAttributes.alpha())
2229 return GL_RGBA; 2273 return GL_RGBA;
2230 return GL_RGB; 2274 return GL_RGB;
2231 } 2275 }
2232 2276
2233 } // namespace blink 2277 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698