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

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

Issue 1320093002: Command Buffer: read pixels into pixel pack buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get correct pixel size Created 5 years 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 (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 <cmath> 10 #include <cmath>
(...skipping 9157 matching lines...) Expand 10 before | Expand all | Expand 10 after
9168 GLsizei height = c.height; 9168 GLsizei height = c.height;
9169 GLenum format = c.format; 9169 GLenum format = c.format;
9170 GLenum type = c.type; 9170 GLenum type = c.type;
9171 GLboolean async = static_cast<GLboolean>(c.async); 9171 GLboolean async = static_cast<GLboolean>(c.async);
9172 if (width < 0 || height < 0) { 9172 if (width < 0 || height < 0) {
9173 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); 9173 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0");
9174 return error::kNoError; 9174 return error::kNoError;
9175 } 9175 }
9176 typedef cmds::ReadPixels::Result Result; 9176 typedef cmds::ReadPixels::Result Result;
9177 uint32 pixels_size; 9177 uint32 pixels_size;
9178 if (state_.bound_pixel_pack_buffer.get()) { 9178 PixelStoreParams params = state_.GetPackParams();
9179 // TODO(zmo): Need to handle the case of reading into a PIXEL_PACK_BUFFER 9179 if (!GLES2Util::ComputeImageDataSizesES3(
9180 // in ES3, including more pack parameters. For now, generate a GL error. 9180 width, height, 1, format, type, params, &pixels_size, NULL, NULL, NULL)) {
Zhenyao Mo 2015/12/15 23:50:56 nit: use nullptr instead.
yunchao 2015/12/16 11:04:25 Done.
9181 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels",
9182 "ReadPixels to a pixel pack buffer isn't implemented");
9183 return error::kNoError;
9184 }
9185 if (!GLES2Util::ComputeImageDataSizes(
9186 width, height, 1, format, type, state_.pack_alignment, &pixels_size,
9187 NULL, NULL)) {
9188 return error::kOutOfBounds; 9181 return error::kOutOfBounds;
9189 } 9182 }
9190 void* pixels = GetSharedMemoryAs<void*>( 9183
9191 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); 9184 void* pixels = NULL;
Zhenyao Mo 2015/12/15 23:50:56 nit: use nullptr instead.
yunchao 2015/12/16 11:04:25 Done.
9192 if (!pixels) { 9185 Buffer* buffer = state_.bound_pixel_pack_buffer.get();
9193 return error::kOutOfBounds; 9186 if (c.pixels_shm_id == 0) {
9187 if (buffer) {
9188 if (buffer->GetMappedRange()) {
9189 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels",
9190 "pixel pack buffer should not be mapped to client memory");
9191 return error::kNoError;
9192 }
9193 if (buffer->size() < pixels_size) {
9194 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels",
9195 "pixel pack buffer is not large enough");
9196 return error::kNoError;
9197 }
9198 if (c.pixels_shm_offset != 0) {
9199 return error::kInvalidArguments;
9200 }
9201 pixels = reinterpret_cast<void *>(0);
Zhenyao Mo 2015/12/15 23:50:56 Here you will need to consider the offset paramete
yunchao 2015/12/16 11:04:25 Done.
9202 } else {
9203 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels",
Zhenyao Mo 2015/12/15 23:50:56 Here you should return error::kInvalidArguments. N
yunchao 2015/12/16 11:04:25 Done.
9204 "no pixel pack buffer bound");
9205 return error::kNoError;
9206 }
9207 } else {
9208 if (buffer) {
9209 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels",
9210 "pixel pack buffer should not bound");
Zhenyao Mo 2015/12/15 23:50:56 Here you should return error::kInvalidArguments. N
yunchao 2015/12/16 11:04:25 Done.
9211 return error::kNoError;
9212 } else {
9213 pixels = GetSharedMemoryAs<void*>(
9214 c.pixels_shm_id, c.pixels_shm_offset, pixels_size);
9215 if (!pixels) {
9216 return error::kOutOfBounds;
9217 }
9218 }
9194 } 9219 }
9220
9195 Result* result = NULL; 9221 Result* result = NULL;
9196 if (c.result_shm_id != 0) { 9222 if (c.result_shm_id != 0) {
9197 result = GetSharedMemoryAs<Result*>( 9223 result = GetSharedMemoryAs<Result*>(
9198 c.result_shm_id, c.result_shm_offset, sizeof(*result)); 9224 c.result_shm_id, c.result_shm_offset, sizeof(*result));
9199 if (!result) { 9225 if (!result) {
9200 return error::kOutOfBounds; 9226 return error::kOutOfBounds;
9201 } 9227 }
9202 } 9228 }
9203 9229
9204 if (!validators_->read_pixel_format.IsValid(format)) { 9230 if (!validators_->read_pixel_format.IsValid(format)) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
9319 } 9345 }
9320 9346
9321 if (!CheckBoundFramebuffersValid("glReadPixels")) { 9347 if (!CheckBoundFramebuffersValid("glReadPixels")) {
9322 return error::kNoError; 9348 return error::kNoError;
9323 } 9349 }
9324 9350
9325 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); 9351 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels");
9326 9352
9327 ScopedResolvedFrameBufferBinder binder(this, false, true); 9353 ScopedResolvedFrameBufferBinder binder(this, false, true);
9328 9354
9329 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { 9355 if ((x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height())
9356 && c.pixels_shm_id != 0) {
Zhenyao Mo 2015/12/15 23:50:56 We do want to handle the out-of-bounds readPixels
yunchao 2015/12/16 11:04:25 Done.
9330 // The user requested an out of range area. Get the results 1 line 9357 // The user requested an out of range area. Get the results 1 line
9331 // at a time. 9358 // at a time.
9332 uint32 temp_size; 9359 uint32 temp_size;
9333 uint32 unpadded_row_size; 9360 uint32 unpadded_row_size;
9334 uint32 padded_row_size; 9361 uint32 padded_row_size;
9335 if (!GLES2Util::ComputeImageDataSizes( 9362 if (!GLES2Util::ComputeImageDataSizes(
9336 width, 2, 1, format, type, state_.pack_alignment, &temp_size, 9363 width, 2, 1, format, type, state_.pack_alignment, &temp_size,
9337 &unpadded_row_size, &padded_row_size)) { 9364 &unpadded_row_size, &padded_row_size)) {
9338 LOCAL_SET_GL_ERROR( 9365 LOCAL_SET_GL_ERROR(
9339 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); 9366 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range");
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
9395 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); 9422 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
9396 return error::kNoError; 9423 return error::kNoError;
9397 } else { 9424 } else {
9398 // On error, unbind pack buffer and fall through to sync readpixels 9425 // On error, unbind pack buffer and fall through to sync readpixels
9399 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); 9426 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
9400 glDeleteBuffersARB(1, &buffer); 9427 glDeleteBuffersARB(1, &buffer);
9401 } 9428 }
9402 } 9429 }
9403 glReadPixels(x, y, width, height, format, type, pixels); 9430 glReadPixels(x, y, width, height, format, type, pixels);
9404 } 9431 }
9405 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); 9432 if (c.pixels_shm_id != 0) {
9406 if (error == GL_NO_ERROR) { 9433 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels");
9407 if (result != NULL) { 9434 if (error == GL_NO_ERROR) {
9408 *result = true; 9435 if (result != NULL) {
9436 *result = true;
9437 }
9438 FinishReadPixels(c, 0);
9409 } 9439 }
9410 FinishReadPixels(c, 0);
9411 } 9440 }
9412 9441
9413 return error::kNoError; 9442 return error::kNoError;
9414 } 9443 }
9415 9444
9416 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, 9445 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size,
9417 const void* cmd_data) { 9446 const void* cmd_data) {
9418 const gles2::cmds::PixelStorei& c = 9447 const gles2::cmds::PixelStorei& c =
9419 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); 9448 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data);
9420 GLenum pname = c.pname; 9449 GLenum pname = c.pname;
(...skipping 6364 matching lines...) Expand 10 before | Expand all | Expand 10 after
15785 return error::kNoError; 15814 return error::kNoError;
15786 } 15815 }
15787 15816
15788 // Include the auto-generated part of this file. We split this because it means 15817 // Include the auto-generated part of this file. We split this because it means
15789 // we can easily edit the non-auto generated parts right here in this file 15818 // we can easily edit the non-auto generated parts right here in this file
15790 // instead of having to edit some template or the code generator. 15819 // instead of having to edit some template or the code generator.
15791 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 15820 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
15792 15821
15793 } // namespace gles2 15822 } // namespace gles2
15794 } // namespace gpu 15823 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698