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

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 kbr@'s feedback: translate GL_BACK to GL_COLOR_ATTACHMENT0 on default fb of WebGL Created 5 years, 6 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return; 161 return;
162 162
163 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen ts.data(), x, y, width, height); 163 webContext()->invalidateSubFramebuffer(target, attachments.size(), attachmen ts.data(), x, y, width, height);
164 } 164 }
165 165
166 void WebGL2RenderingContextBase::readBuffer(GLenum mode) 166 void WebGL2RenderingContextBase::readBuffer(GLenum mode)
167 { 167 {
168 if (isContextLost()) 168 if (isContextLost())
169 return; 169 return;
170 170
171 switch (mode) {
172 case GL_BACK:
173 case GL_NONE:
174 case GL_COLOR_ATTACHMENT0:
175 break;
176 default:
177 if (attachment > GL_COLOR_ATTACHMENT0
178 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorA ttachments()))
179 break;
180 synthesizeGLError(GL_INVALID_ENUM, "readBuffer", "invalid read buffer");
181 return;
182 }
183
184 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(GL_READ_FRA MEBUFFER);
185 if (!readFramebufferBinding) {
186 ASSERT(drawingBuffer());
187 if (mode != GL_BACK || mode != GL_NONE) {
Zhenyao Mo 2015/06/25 22:42:22 &&, not ||
yunchao 2015/06/30 05:44:56 Done.
188 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
189 return;
190 }
191 // translate GL_BACK to GL_COLOR_ATTACHMENT0, because the default
192 // framebuffer for WebGL is not fb 0, it is an internal fbo.
193 if (mode == GL_BACK)
194 mode = GL_COLOR_ATTACHMENT0;
Zhenyao Mo 2015/06/25 22:42:22 You also need to emulate the reverse in getParamet
yunchao 2015/06/30 05:44:56 Yeah, totally agree with you.
195 } else {
196 if (mode == GL_BACK) {
197 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
198 return;
199 }
200 m_readbufferOfFBO = mode;
201 }
171 webContext()->readBuffer(mode); 202 webContext()->readBuffer(mode);
172 } 203 }
173 204
174 void WebGL2RenderingContextBase::renderbufferStorageImpl( 205 void WebGL2RenderingContextBase::renderbufferStorageImpl(
175 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height, 206 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height,
176 const char* functionName) 207 const char* functionName)
177 { 208 {
178 switch (internalformat) { 209 switch (internalformat) {
179 case GL_R8UI: 210 case GL_R8UI:
180 case GL_R8I: 211 case GL_R8I:
(...skipping 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 m_boundPixelUnpackBuffer = nullptr; 2116 m_boundPixelUnpackBuffer = nullptr;
2086 if (m_boundTransformFeedbackBuffer == buffer) 2117 if (m_boundTransformFeedbackBuffer == buffer)
2087 m_boundTransformFeedbackBuffer = nullptr; 2118 m_boundTransformFeedbackBuffer = nullptr;
2088 if (m_boundUniformBuffer == buffer) 2119 if (m_boundUniformBuffer == buffer)
2089 m_boundUniformBuffer = nullptr; 2120 m_boundUniformBuffer = nullptr;
2090 2121
2091 WebGLRenderingContextBase::removeBoundBuffer(buffer); 2122 WebGLRenderingContextBase::removeBoundBuffer(buffer);
2092 } 2123 }
2093 2124
2094 } // namespace blink 2125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698