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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 379623002: Read framebuffer should have color image attached for ReadPixels/Copy{Sub}TexImage2D (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 void RestoreClearState(); 1178 void RestoreClearState();
1179 1179
1180 // Remembers the state of some capabilities. 1180 // Remembers the state of some capabilities.
1181 // Returns: true if glEnable/glDisable should actually be called. 1181 // Returns: true if glEnable/glDisable should actually be called.
1182 bool SetCapabilityState(GLenum cap, bool enabled); 1182 bool SetCapabilityState(GLenum cap, bool enabled);
1183 1183
1184 // Check that the currently bound framebuffers are valid. 1184 // Check that the currently bound framebuffers are valid.
1185 // Generates GL error if not. 1185 // Generates GL error if not.
1186 bool CheckBoundFramebuffersValid(const char* func_name); 1186 bool CheckBoundFramebuffersValid(const char* func_name);
1187 1187
1188 // Check that the currently bound read framebuffer has a color image
1189 // attached. Generates GL error if not.
1190 bool CheckBoundReadFramebufferColorAttachment(const char* func_name);
1191
1188 // Check if a framebuffer meets our requirements. 1192 // Check if a framebuffer meets our requirements.
1189 bool CheckFramebufferValid( 1193 bool CheckFramebufferValid(
1190 Framebuffer* framebuffer, 1194 Framebuffer* framebuffer,
1191 GLenum target, 1195 GLenum target,
1192 const char* func_name); 1196 const char* func_name);
1193 1197
1194 // Checks if the current program exists and is valid. If not generates the 1198 // Checks if the current program exists and is valid. If not generates the
1195 // appropriate GL error. Returns true if the current program is in a usable 1199 // appropriate GL error. Returns true if the current program is in a usable
1196 // state. 1200 // state.
1197 bool CheckCurrentProgram(const char* function_name); 1201 bool CheckCurrentProgram(const char* function_name);
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
3187 return valid; 3191 return valid;
3188 } 3192 }
3189 return CheckFramebufferValid(framebuffer_state_.bound_draw_framebuffer.get(), 3193 return CheckFramebufferValid(framebuffer_state_.bound_draw_framebuffer.get(),
3190 GL_DRAW_FRAMEBUFFER_EXT, 3194 GL_DRAW_FRAMEBUFFER_EXT,
3191 func_name) && 3195 func_name) &&
3192 CheckFramebufferValid(framebuffer_state_.bound_read_framebuffer.get(), 3196 CheckFramebufferValid(framebuffer_state_.bound_read_framebuffer.get(),
3193 GL_READ_FRAMEBUFFER_EXT, 3197 GL_READ_FRAMEBUFFER_EXT,
3194 func_name); 3198 func_name);
3195 } 3199 }
3196 3200
3201 bool GLES2DecoderImpl::CheckBoundReadFramebufferColorAttachment(
3202 const char* func_name) {
3203 Framebuffer* framebuffer = features().chromium_framebuffer_multisample ?
3204 framebuffer_state_.bound_read_framebuffer.get() :
3205 framebuffer_state_.bound_draw_framebuffer.get();
3206 if (!framebuffer)
3207 return true;
3208 if (framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL) {
3209 LOCAL_SET_GL_ERROR(
3210 GL_INVALID_OPERATION, func_name, "no color image attached");
3211 return false;
3212 }
3213 return true;
3214 }
3215
3197 gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { 3216 gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() {
3198 Framebuffer* framebuffer = 3217 Framebuffer* framebuffer =
3199 GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); 3218 GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT);
3200 if (framebuffer != NULL) { 3219 if (framebuffer != NULL) {
3201 const Framebuffer::Attachment* attachment = 3220 const Framebuffer::Attachment* attachment =
3202 framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); 3221 framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0);
3203 if (attachment) { 3222 if (attachment) {
3204 return gfx::Size(attachment->width(), attachment->height()); 3223 return gfx::Size(attachment->width(), attachment->height());
3205 } 3224 }
3206 return gfx::Size(0, 0); 3225 return gfx::Size(0, 0);
(...skipping 4222 matching lines...) Expand 10 before | Expand all | Expand 10 after
7429 gfx::Size max_size = GetBoundReadFrameBufferSize(); 7448 gfx::Size max_size = GetBoundReadFrameBufferSize();
7430 7449
7431 int32 max_x; 7450 int32 max_x;
7432 int32 max_y; 7451 int32 max_y;
7433 if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) { 7452 if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) {
7434 LOCAL_SET_GL_ERROR( 7453 LOCAL_SET_GL_ERROR(
7435 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); 7454 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range");
7436 return error::kNoError; 7455 return error::kNoError;
7437 } 7456 }
7438 7457
7458 if (!CheckBoundReadFramebufferColorAttachment("glReadPixels")) {
7459 return error::kNoError;
7460 }
7461
7439 if (!CheckBoundFramebuffersValid("glReadPixels")) { 7462 if (!CheckBoundFramebuffersValid("glReadPixels")) {
7440 return error::kNoError; 7463 return error::kNoError;
7441 } 7464 }
7442 7465
7443 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); 7466 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels");
7444 7467
7445 ScopedResolvedFrameBufferBinder binder(this, false, true); 7468 ScopedResolvedFrameBufferBinder binder(this, false, true);
7446 7469
7447 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { 7470 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) {
7448 // The user requested an out of range area. Get the results 1 line 7471 // The user requested an out of range area. Get the results 1 line
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
8480 LOCAL_SET_GL_ERROR( 8503 LOCAL_SET_GL_ERROR(
8481 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too large"); 8504 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too large");
8482 return; 8505 return;
8483 } 8506 }
8484 8507
8485 if (!EnsureGPUMemoryAvailable(estimated_size)) { 8508 if (!EnsureGPUMemoryAvailable(estimated_size)) {
8486 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "out of memory"); 8509 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "out of memory");
8487 return; 8510 return;
8488 } 8511 }
8489 8512
8513 if (!CheckBoundReadFramebufferColorAttachment("glCopyTexImage2D")) {
8514 return;
8515 }
8516
8490 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { 8517 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) {
8491 return; 8518 return;
8492 } 8519 }
8493 8520
8494 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D"); 8521 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D");
8495 ScopedResolvedFrameBufferBinder binder(this, false, true); 8522 ScopedResolvedFrameBufferBinder binder(this, false, true);
8496 gfx::Size size = GetBoundReadFrameBufferSize(); 8523 gfx::Size size = GetBoundReadFrameBufferSize();
8497 8524
8498 if (texture->IsAttachedToFramebuffer()) { 8525 if (texture->IsAttachedToFramebuffer()) {
8499 framebuffer_state_.clear_state_dirty = true; 8526 framebuffer_state_.clear_state_dirty = true;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
8590 return; 8617 return;
8591 } 8618 }
8592 8619
8593 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { 8620 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) {
8594 LOCAL_SET_GL_ERROR( 8621 LOCAL_SET_GL_ERROR(
8595 GL_INVALID_OPERATION, 8622 GL_INVALID_OPERATION,
8596 "glCopySubImage2D", "can not be used with depth or stencil textures"); 8623 "glCopySubImage2D", "can not be used with depth or stencil textures");
8597 return; 8624 return;
8598 } 8625 }
8599 8626
8627 if (!CheckBoundReadFramebufferColorAttachment("glCopyTexSubImage2D")) {
8628 return;
8629 }
8630
8600 if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { 8631 if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) {
8601 return; 8632 return;
8602 } 8633 }
8603 8634
8604 ScopedResolvedFrameBufferBinder binder(this, false, true); 8635 ScopedResolvedFrameBufferBinder binder(this, false, true);
8605 gfx::Size size = GetBoundReadFrameBufferSize(); 8636 gfx::Size size = GetBoundReadFrameBufferSize();
8606 GLint copyX = 0; 8637 GLint copyX = 0;
8607 GLint copyY = 0; 8638 GLint copyY = 0;
8608 GLint copyWidth = 0; 8639 GLint copyWidth = 0;
8609 GLint copyHeight = 0; 8640 GLint copyHeight = 0;
(...skipping 2272 matching lines...) Expand 10 before | Expand all | Expand 10 after
10882 } 10913 }
10883 } 10914 }
10884 10915
10885 // Include the auto-generated part of this file. We split this because it means 10916 // Include the auto-generated part of this file. We split this because it means
10886 // we can easily edit the non-auto generated parts right here in this file 10917 // we can easily edit the non-auto generated parts right here in this file
10887 // instead of having to edit some template or the code generator. 10918 // instead of having to edit some template or the code generator.
10888 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10919 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10889 10920
10890 } // namespace gles2 10921 } // namespace gles2
10891 } // namespace gpu 10922 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698