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

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

Issue 1750123002: Upgrade Tex{Sub}Image{2|3}D to handle ES3 unpack parameters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 (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 <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 9527 matching lines...) Expand 10 before | Expand all | Expand 10 after
9538 switch (pname) { 9538 switch (pname) {
9539 case GL_PACK_ALIGNMENT: 9539 case GL_PACK_ALIGNMENT:
9540 case GL_UNPACK_ALIGNMENT: 9540 case GL_UNPACK_ALIGNMENT:
9541 if (!validators_->pixel_store_alignment.IsValid(param)) { 9541 if (!validators_->pixel_store_alignment.IsValid(param)) {
9542 LOCAL_SET_GL_ERROR( 9542 LOCAL_SET_GL_ERROR(
9543 GL_INVALID_VALUE, "glPixelStorei", "invalid param"); 9543 GL_INVALID_VALUE, "glPixelStorei", "invalid param");
9544 return error::kNoError; 9544 return error::kNoError;
9545 } 9545 }
9546 break; 9546 break;
9547 case GL_PACK_ROW_LENGTH: 9547 case GL_PACK_ROW_LENGTH:
9548 case GL_PACK_SKIP_PIXELS:
9549 case GL_PACK_SKIP_ROWS:
9550 case GL_UNPACK_ROW_LENGTH: 9548 case GL_UNPACK_ROW_LENGTH:
9551 case GL_UNPACK_IMAGE_HEIGHT: 9549 case GL_UNPACK_IMAGE_HEIGHT:
9552 case GL_UNPACK_SKIP_PIXELS:
9553 case GL_UNPACK_SKIP_ROWS:
9554 case GL_UNPACK_SKIP_IMAGES:
9555 if (param < 0) { 9550 if (param < 0) {
9556 LOCAL_SET_GL_ERROR( 9551 LOCAL_SET_GL_ERROR(
9557 GL_INVALID_VALUE, "glPixelStorei", "invalid param"); 9552 GL_INVALID_VALUE, "glPixelStorei", "invalid param");
9558 return error::kNoError; 9553 return error::kNoError;
9559 } 9554 }
9555 break;
9556 case GL_PACK_SKIP_PIXELS:
9557 case GL_PACK_SKIP_ROWS:
9558 case GL_UNPACK_SKIP_PIXELS:
9559 case GL_UNPACK_SKIP_ROWS:
9560 case GL_UNPACK_SKIP_IMAGES:
9561 // All SKIP parameters are handled on the client side and should never
9562 // be passed to the service side.
9563 NOTREACHED();
piman 2016/03/08 01:56:50 nit: no NOTREACHED() since this can be reached by
Zhenyao Mo 2016/03/09 18:41:05 Done.
9564 return error::kInvalidArguments;
9560 default: 9565 default:
9561 break; 9566 break;
9562 } 9567 }
9563 // For pack skip parameters, we don't apply them and handle them in command
9564 // buffer.
9565 // For alignment parameters, we always apply them. 9568 // For alignment parameters, we always apply them.
9566 // For other parameters, we don't apply them if no buffer is bound at 9569 // For other parameters, we don't apply them if no buffer is bound at
9567 // PIXEL_PACK or PIXEL_UNPACK. We will handle pack and unpack according to 9570 // PIXEL_PACK or PIXEL_UNPACK. We will handle pack and unpack according to
9568 // the user specified parameters on the client side. 9571 // the user specified parameters on the client side.
9569 switch (pname) { 9572 switch (pname) {
9570 case GL_PACK_ROW_LENGTH: 9573 case GL_PACK_ROW_LENGTH:
9571 if (state_.bound_pixel_pack_buffer.get()) 9574 if (state_.bound_pixel_pack_buffer.get())
9572 glPixelStorei(pname, param); 9575 glPixelStorei(pname, param);
9573 break; 9576 break;
9574 case GL_PACK_SKIP_PIXELS:
9575 case GL_PACK_SKIP_ROWS:
9576 break;
9577 case GL_UNPACK_ROW_LENGTH: 9577 case GL_UNPACK_ROW_LENGTH:
9578 case GL_UNPACK_IMAGE_HEIGHT: 9578 case GL_UNPACK_IMAGE_HEIGHT:
9579 case GL_UNPACK_SKIP_PIXELS:
9580 case GL_UNPACK_SKIP_ROWS:
9581 case GL_UNPACK_SKIP_IMAGES:
9582 if (state_.bound_pixel_unpack_buffer.get()) 9579 if (state_.bound_pixel_unpack_buffer.get())
9583 glPixelStorei(pname, param); 9580 glPixelStorei(pname, param);
9584 break; 9581 break;
9585 default: 9582 default:
9586 glPixelStorei(pname, param); 9583 glPixelStorei(pname, param);
9587 break; 9584 break;
9588 } 9585 }
9589 switch (pname) { 9586 switch (pname) {
9590 case GL_PACK_ALIGNMENT: 9587 case GL_PACK_ALIGNMENT:
9591 state_.pack_alignment = param; 9588 state_.pack_alignment = param;
9592 break; 9589 break;
9593 case GL_PACK_ROW_LENGTH: 9590 case GL_PACK_ROW_LENGTH:
9594 state_.pack_row_length = param; 9591 state_.pack_row_length = param;
9595 break; 9592 break;
9596 case GL_PACK_SKIP_PIXELS:
9597 state_.pack_skip_pixels = param;
9598 break;
9599 case GL_PACK_SKIP_ROWS:
9600 state_.pack_skip_rows = param;
9601 break;
9602 case GL_UNPACK_ALIGNMENT: 9593 case GL_UNPACK_ALIGNMENT:
9603 state_.unpack_alignment = param; 9594 state_.unpack_alignment = param;
9604 break; 9595 break;
9605 case GL_UNPACK_ROW_LENGTH: 9596 case GL_UNPACK_ROW_LENGTH:
9606 state_.unpack_row_length = param; 9597 state_.unpack_row_length = param;
9607 break; 9598 break;
9608 case GL_UNPACK_IMAGE_HEIGHT: 9599 case GL_UNPACK_IMAGE_HEIGHT:
9609 state_.unpack_image_height = param; 9600 state_.unpack_image_height = param;
9610 break; 9601 break;
9611 case GL_UNPACK_SKIP_PIXELS:
9612 state_.unpack_skip_pixels = param;
9613 break;
9614 case GL_UNPACK_SKIP_ROWS:
9615 state_.unpack_skip_rows = param;
9616 break;
9617 case GL_UNPACK_SKIP_IMAGES:
9618 state_.unpack_skip_images = param;
9619 break;
9620 default: 9602 default:
9621 // Validation should have prevented us from getting here. 9603 // Validation should have prevented us from getting here.
9622 NOTREACHED(); 9604 NOTREACHED();
9623 break; 9605 break;
9624 } 9606 }
9625 return error::kNoError; 9607 return error::kNoError;
9626 } 9608 }
9627 9609
9628 error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( 9610 error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM(
9629 uint32_t immediate_data_size, 9611 uint32_t immediate_data_size,
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
10259 int width, 10241 int width,
10260 int height, 10242 int height,
10261 int depth) { 10243 int depth) {
10262 DCHECK(target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY); 10244 DCHECK(target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY);
10263 DCHECK(feature_info_->IsES3Enabled()); 10245 DCHECK(feature_info_->IsES3Enabled());
10264 if (width == 0 || height == 0 || depth == 0) 10246 if (width == 0 || height == 0 || depth == 0)
10265 return true; 10247 return true;
10266 10248
10267 uint32_t size; 10249 uint32_t size;
10268 uint32_t padded_row_size; 10250 uint32_t padded_row_size;
10251 uint32_t padding;
10269 // Here we use unpack buffer to upload zeros into the texture, one layer 10252 // Here we use unpack buffer to upload zeros into the texture, one layer
10270 // at a time. We haven't applied unpack parameters to GL except alignment. 10253 // at a time.
10271 if (!GLES2Util::ComputeImageDataSizes( 10254 // We only take into consideration UNPACK_ALIGNMENT, and clear other unpack
10272 width, height, depth, format, type, state_.unpack_alignment, &size, 10255 // parameters if necessary before TexSubImage3D calls.
10273 nullptr, &padded_row_size)) { 10256 PixelStoreParams params;
10257 params.alignment = state_.unpack_alignment;
10258 if (!GLES2Util::ComputeImageDataSizesES3(width, height, depth,
10259 format, type,
10260 params,
10261 &size,
10262 nullptr,
10263 &padded_row_size,
10264 nullptr,
10265 &padding)) {
10274 return false; 10266 return false;
10275 } 10267 }
10276 const uint32_t kMaxZeroSize = 1024 * 1024 * 2; 10268 const uint32_t kMaxZeroSize = 1024 * 1024 * 2;
10277 uint32_t buffer_size; 10269 uint32_t buffer_size;
10278 std::vector<TexSubCoord3D> subs; 10270 std::vector<TexSubCoord3D> subs;
10279 if (size < kMaxZeroSize) { 10271 if (size < kMaxZeroSize) {
10280 // Case 1: one TexSubImage3D call clears the entire 3D texture. 10272 // Case 1: one TexSubImage3D call clears the entire 3D texture.
10281 buffer_size = size; 10273 buffer_size = size;
10282 subs.push_back(TexSubCoord3D(0, 0, 0, width, height, depth)); 10274 subs.push_back(TexSubCoord3D(0, 0, 0, width, height, depth));
10283 } else { 10275 } else {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
10325 } 10317 }
10326 } 10318 }
10327 } 10319 }
10328 10320
10329 TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearLevel3D", "size", size); 10321 TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearLevel3D", "size", size);
10330 10322
10331 GLuint buffer_id = 0; 10323 GLuint buffer_id = 0;
10332 glGenBuffersARB(1, &buffer_id); 10324 glGenBuffersARB(1, &buffer_id);
10333 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id); 10325 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id);
10334 { 10326 {
10327 // Include padding as some drivers incorrectly requires padding for the
10328 // last row.
10329 buffer_size += padding;
10330 // Buffer size needs to be a multiple of type bytes.
10331 size_t type_bytes = GLES2Util::GetGLTypeSizeForTextures(type);
10332 size_t residual = buffer_size % type_bytes;
10333 if (residual != 0) {
10334 buffer_size += type_bytes - residual;
10335 }
10336 DCHECK(buffer_size % type_bytes == 0);
10335 scoped_ptr<char[]> zero(new char[buffer_size]); 10337 scoped_ptr<char[]> zero(new char[buffer_size]);
10336 memset(zero.get(), 0, buffer_size); 10338 memset(zero.get(), 0, buffer_size);
10337 // TODO(zmo): Consider glMapBufferRange instead. 10339 // TODO(zmo): Consider glMapBufferRange instead.
10338 glBufferData( 10340 glBufferData(
10339 GL_PIXEL_UNPACK_BUFFER, buffer_size, zero.get(), GL_STATIC_DRAW); 10341 GL_PIXEL_UNPACK_BUFFER, buffer_size, zero.get(), GL_STATIC_DRAW);
10340 } 10342 }
10341 10343
10344 Buffer* bound_buffer = buffer_manager()->GetBufferInfoForTarget(
10345 &state_, GL_PIXEL_UNPACK_BUFFER);
10346 if (bound_buffer) {
10347 // If an unpack buffer is bound, we need to clear unpack parameters
10348 // because they have been applied to the driver.
10349 if (state_.unpack_row_length > 0)
10350 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
10351 if (state_.unpack_image_height > 0)
10352 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
10353 DCHECK_EQ(0, state_.unpack_skip_pixels);
10354 DCHECK_EQ(0, state_.unpack_skip_rows);
10355 DCHECK_EQ(0, state_.unpack_skip_images);
10356 }
10357
10342 glBindTexture(texture->target(), texture->service_id()); 10358 glBindTexture(texture->target(), texture->service_id());
10343 10359
10344 for (size_t ii = 0; ii < subs.size(); ++ii) { 10360 for (size_t ii = 0; ii < subs.size(); ++ii) {
10345 glTexSubImage3D(target, level, subs[ii].xoffset, subs[ii].yoffset, 10361 glTexSubImage3D(target, level, subs[ii].xoffset, subs[ii].yoffset,
10346 subs[ii].zoffset, subs[ii].width, subs[ii].height, 10362 subs[ii].zoffset, subs[ii].width, subs[ii].height,
10347 subs[ii].depth, format, type, nullptr); 10363 subs[ii].depth, format, type, nullptr);
10348 } 10364 }
10349 10365
10350 Buffer* bound_buffer = buffer_manager()->GetBufferInfoForTarget( 10366 if (bound_buffer) {
10351 &state_, GL_PIXEL_UNPACK_BUFFER); 10367 if (state_.unpack_row_length > 0)
10368 glPixelStorei(GL_UNPACK_ROW_LENGTH, state_.unpack_row_length);
10369 if (state_.unpack_image_height > 0)
10370 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, state_.unpack_image_height);
10371 }
10372
10352 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 10373 glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
10353 bound_buffer ? bound_buffer->service_id() : 0); 10374 bound_buffer ? bound_buffer->service_id() : 0);
10354 glDeleteBuffersARB(1, &buffer_id); 10375 glDeleteBuffersARB(1, &buffer_id);
10355 10376
10356 TextureRef* bound_texture = 10377 TextureRef* bound_texture =
10357 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); 10378 texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
10358 glBindTexture(texture->target(), 10379 glBindTexture(texture->target(),
10359 bound_texture ? bound_texture->service_id() : 0); 10380 bound_texture ? bound_texture->service_id() : 0);
10360 return true; 10381 return true;
10361 } 10382 }
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
11222 GLenum target = static_cast<GLenum>(c.target); 11243 GLenum target = static_cast<GLenum>(c.target);
11223 GLint level = static_cast<GLint>(c.level); 11244 GLint level = static_cast<GLint>(c.level);
11224 GLint internal_format = static_cast<GLint>(c.internalformat); 11245 GLint internal_format = static_cast<GLint>(c.internalformat);
11225 GLsizei width = static_cast<GLsizei>(c.width); 11246 GLsizei width = static_cast<GLsizei>(c.width);
11226 GLsizei height = static_cast<GLsizei>(c.height); 11247 GLsizei height = static_cast<GLsizei>(c.height);
11227 GLint border = static_cast<GLint>(c.border); 11248 GLint border = static_cast<GLint>(c.border);
11228 GLenum format = static_cast<GLenum>(c.format); 11249 GLenum format = static_cast<GLenum>(c.format);
11229 GLenum type = static_cast<GLenum>(c.type); 11250 GLenum type = static_cast<GLenum>(c.type);
11230 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id); 11251 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id);
11231 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset); 11252 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset);
11232 uint32_t pixels_size; 11253
11233 if (!GLES2Util::ComputeImageDataSizes( 11254 if (width < 0 || height < 0) {
11234 width, height, 1, format, type, state_.unpack_alignment, &pixels_size, 11255 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexImage2D", "dimensions < 0");
11235 NULL, NULL)) { 11256 return error::kNoError;
11257 }
11258 uint32_t pixels_size = 0;
11259 uint32_t skip_size = 0;
11260 bool no_pixels = false;
11261 PixelStoreParams params;
11262 if (state_.bound_pixel_unpack_buffer.get()) {
11263 DCHECK_EQ(0u, pixels_shm_id);
piman 2016/03/08 01:56:50 Is this DCHECK valid? We can't trust the client. W
Zhenyao Mo 2016/03/09 18:41:05 Done.
11264 params = state_.GetUnpackParams(ContextState::k2D);
11265 } else {
11266 if (pixels_shm_id) {
11267 // When reading from client buffer, the command buffer client side took
11268 // the responsibility to take the pixels from the client buffer and
11269 // unpack them according to the full ES3 pack parameters as source, all
11270 // parameters for 0 (except for alignment) as destination mem for the
11271 // service side.
11272 params.alignment = state_.unpack_alignment;
11273 } else {
11274 DCHECK_EQ(0u, pixels_shm_offset);
piman 2016/03/08 01:56:50 Same here.
Zhenyao Mo 2016/03/09 18:41:05 Done.
11275 no_pixels = true;
11276 }
11277 }
11278 if (!no_pixels &&
11279 !GLES2Util::ComputeImageDataSizesES3(width, height, 1,
11280 format, type,
11281 params,
11282 &pixels_size,
11283 nullptr,
11284 nullptr,
11285 &skip_size,
11286 nullptr)) {
11236 return error::kOutOfBounds; 11287 return error::kOutOfBounds;
11237 } 11288 }
11238 const void* pixels = NULL; 11289 DCHECK_EQ(0u, skip_size);
11239 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { 11290
11291 const void* pixels = nullptr;
11292 if (pixels_shm_id) {
11240 pixels = GetSharedMemoryAs<const void*>( 11293 pixels = GetSharedMemoryAs<const void*>(
11241 pixels_shm_id, pixels_shm_offset, pixels_size); 11294 pixels_shm_id, pixels_shm_offset, pixels_size);
11242 if (!pixels) { 11295 if (!pixels) {
11243 return error::kOutOfBounds; 11296 return error::kOutOfBounds;
11244 } 11297 }
11298 } else {
11299 pixels = reinterpret_cast<const void*>(pixels_shm_offset);
11245 } 11300 }
11246 11301
11247 // For testing only. Allows us to stress the ability to respond to OOM errors. 11302 // For testing only. Allows us to stress the ability to respond to OOM errors.
11248 if (workarounds().simulate_out_of_memory_on_large_textures && 11303 if (workarounds().simulate_out_of_memory_on_large_textures &&
11249 (width * height >= 4096 * 4096)) { 11304 (width * height >= 4096 * 4096)) {
11250 LOCAL_SET_GL_ERROR( 11305 LOCAL_SET_GL_ERROR(
11251 GL_OUT_OF_MEMORY, 11306 GL_OUT_OF_MEMORY,
11252 "glTexImage2D", "synthetic out of memory"); 11307 "glTexImage2D", "synthetic out of memory");
11253 return error::kNoError; 11308 return error::kNoError;
11254 } 11309 }
(...skipping 25 matching lines...) Expand all
11280 GLint level = static_cast<GLint>(c.level); 11335 GLint level = static_cast<GLint>(c.level);
11281 GLint internal_format = static_cast<GLint>(c.internalformat); 11336 GLint internal_format = static_cast<GLint>(c.internalformat);
11282 GLsizei width = static_cast<GLsizei>(c.width); 11337 GLsizei width = static_cast<GLsizei>(c.width);
11283 GLsizei height = static_cast<GLsizei>(c.height); 11338 GLsizei height = static_cast<GLsizei>(c.height);
11284 GLsizei depth = static_cast<GLsizei>(c.depth); 11339 GLsizei depth = static_cast<GLsizei>(c.depth);
11285 GLint border = static_cast<GLint>(c.border); 11340 GLint border = static_cast<GLint>(c.border);
11286 GLenum format = static_cast<GLenum>(c.format); 11341 GLenum format = static_cast<GLenum>(c.format);
11287 GLenum type = static_cast<GLenum>(c.type); 11342 GLenum type = static_cast<GLenum>(c.type);
11288 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id); 11343 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id);
11289 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset); 11344 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset);
11290 uint32_t pixels_size; 11345
11291 if (!GLES2Util::ComputeImageDataSizes( 11346 if (width < 0 || height < 0 || depth < 0) {
11292 width, height, depth, format, type, state_.unpack_alignment, &pixels_size, 11347 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexImage3D", "dimensions < 0");
11293 NULL, NULL)) { 11348 return error::kNoError;
11349 }
11350
11351 uint32_t pixels_size = 0;
11352 uint32_t skip_size = 0;
11353 bool no_pixels = false;
11354 PixelStoreParams params;
11355 if (state_.bound_pixel_unpack_buffer.get()) {
11356 DCHECK_EQ(0u, pixels_shm_id);
piman 2016/03/08 01:56:50 Same as above.
Zhenyao Mo 2016/03/09 18:41:05 Done.
11357 params = state_.GetUnpackParams(ContextState::k3D);
11358 } else {
11359 if (pixels_shm_id) {
11360 // When reading from client buffer, the command buffer client side took
11361 // the responsibility to take the pixels from the client buffer and
11362 // unpack them according to the full ES3 pack parameters as source, all
11363 // parameters for 0 (except for alignment) as destination mem for the
11364 // service side.
11365 params.alignment = state_.unpack_alignment;
11366 } else {
11367 DCHECK_EQ(0u, pixels_shm_offset);
piman 2016/03/08 01:56:50 And here.
Zhenyao Mo 2016/03/09 18:41:05 Done.
11368 no_pixels = true;
11369 }
11370 }
11371 if (!no_pixels &&
11372 !GLES2Util::ComputeImageDataSizesES3(width, height, depth,
11373 format, type,
11374 params,
11375 &pixels_size,
11376 nullptr,
11377 nullptr,
11378 &skip_size,
11379 nullptr)) {
11294 return error::kOutOfBounds; 11380 return error::kOutOfBounds;
11295 } 11381 }
11296 const void* pixels = NULL; 11382 DCHECK_EQ(0u, skip_size);
11297 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { 11383
11384 const void* pixels = nullptr;
11385 if (pixels_shm_id) {
11298 pixels = GetSharedMemoryAs<const void*>( 11386 pixels = GetSharedMemoryAs<const void*>(
11299 pixels_shm_id, pixels_shm_offset, pixels_size); 11387 pixels_shm_id, pixels_shm_offset, pixels_size);
11300 if (!pixels) { 11388 if (!pixels) {
11301 return error::kOutOfBounds; 11389 return error::kOutOfBounds;
11302 } 11390 }
11391 } else {
11392 pixels = reinterpret_cast<const void*>(pixels_shm_offset);
11303 } 11393 }
11304 11394
11305 // For testing only. Allows us to stress the ability to respond to OOM errors. 11395 // For testing only. Allows us to stress the ability to respond to OOM errors.
11306 if (workarounds().simulate_out_of_memory_on_large_textures && 11396 if (workarounds().simulate_out_of_memory_on_large_textures &&
11307 (width * height * depth >= 4096 * 4096)) { 11397 (width * height * depth >= 4096 * 4096)) {
11308 LOCAL_SET_GL_ERROR( 11398 LOCAL_SET_GL_ERROR(
11309 GL_OUT_OF_MEMORY, 11399 GL_OUT_OF_MEMORY,
11310 "glTexImage3D", "synthetic out of memory"); 11400 "glTexImage3D", "synthetic out of memory");
11311 return error::kNoError; 11401 return error::kNoError;
11312 } 11402 }
11313 11403
11314 TextureManager::DoTexImageArguments args = { 11404 TextureManager::DoTexImageArguments args = {
11315 target, level, internal_format, width, height, depth, border, format, type, 11405 target, level, internal_format, width, height, depth, border, format, type,
11316 pixels, pixels_size, TextureManager::DoTexImageArguments::kTexImage3D }; 11406 pixels, pixels_size, TextureManager::DoTexImageArguments::kTexImage3D };
11317 texture_manager()->ValidateAndDoTexImage( 11407 texture_manager()->ValidateAndDoTexImage(
11318 &texture_state_, &state_, &framebuffer_state_, "glTexImage3D", args); 11408 &texture_state_, &state_, &framebuffer_state_, "glTexImage3D", args);
11319 11409
11320 // This may be a slow command. Exit command processing to allow for 11410 // This may be a slow command. Exit command processing to allow for
11321 // context preemption and GPU watchdog checks. 11411 // context preemption and GPU watchdog checks.
11322 ExitCommandProcessingEarly(); 11412 ExitCommandProcessingEarly();
11323 return error::kNoError; 11413 return error::kNoError;
11324 } 11414 }
11325 11415
11326 void GLES2DecoderImpl::DoCompressedTexSubImage2D( 11416 void GLES2DecoderImpl::DoCompressedTexSubImage2D(
11327 GLenum target, 11417 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
11328 GLint level, 11418 GLsizei height, GLenum format, GLsizei image_size, const void * data) {
11329 GLint xoffset,
11330 GLint yoffset,
11331 GLsizei width,
11332 GLsizei height,
11333 GLenum format,
11334 GLsizei image_size,
11335 const void * data) {
11336 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( 11419 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget(
11337 &state_, target); 11420 &state_, target);
11338 if (!texture_ref) { 11421 if (!texture_ref) {
11339 LOCAL_SET_GL_ERROR( 11422 LOCAL_SET_GL_ERROR(
11340 GL_INVALID_OPERATION, 11423 GL_INVALID_OPERATION,
11341 "glCompressedTexSubImage2D", "unknown texture for target"); 11424 "glCompressedTexSubImage2D", "unknown texture for target");
11342 return; 11425 return;
11343 } 11426 }
11344 Texture* texture = texture_ref->texture(); 11427 Texture* texture = texture_ref->texture();
11345 GLenum type = 0; 11428 GLenum type = 0;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
11672 return error::kNoError; 11755 return error::kNoError;
11673 11756
11674 GLenum target = static_cast<GLenum>(c.target); 11757 GLenum target = static_cast<GLenum>(c.target);
11675 GLint level = static_cast<GLint>(c.level); 11758 GLint level = static_cast<GLint>(c.level);
11676 GLint xoffset = static_cast<GLint>(c.xoffset); 11759 GLint xoffset = static_cast<GLint>(c.xoffset);
11677 GLint yoffset = static_cast<GLint>(c.yoffset); 11760 GLint yoffset = static_cast<GLint>(c.yoffset);
11678 GLsizei width = static_cast<GLsizei>(c.width); 11761 GLsizei width = static_cast<GLsizei>(c.width);
11679 GLsizei height = static_cast<GLsizei>(c.height); 11762 GLsizei height = static_cast<GLsizei>(c.height);
11680 GLenum format = static_cast<GLenum>(c.format); 11763 GLenum format = static_cast<GLenum>(c.format);
11681 GLenum type = static_cast<GLenum>(c.type); 11764 GLenum type = static_cast<GLenum>(c.type);
11682 uint32_t data_size; 11765 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id);
11683 if (!GLES2Util::ComputeImageDataSizes( 11766 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset);
11684 width, height, 1, format, type, state_.unpack_alignment, &data_size, 11767
11685 NULL, NULL)) { 11768 if (width < 0 || height < 0) {
11769 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexSubImage2D", "dimensions < 0");
11770 return error::kNoError;
11771 }
11772 PixelStoreParams params;
11773 if (state_.bound_pixel_unpack_buffer.get()) {
11774 params = state_.GetUnpackParams(ContextState::k2D);
11775 } else {
11776 // When reading from client buffer, the command buffer client side took
11777 // the responsibility to take the pixels from the client buffer and
11778 // unpack them according to the full ES3 pack parameters as source, all
11779 // parameters for 0 (except for alignment) as destination mem for the
11780 // service side.
11781 params.alignment = state_.unpack_alignment;
11782 }
11783 uint32_t pixels_size;
11784 uint32_t skip_size;
11785 if (!GLES2Util::ComputeImageDataSizesES3(width, height, 1,
11786 format, type,
11787 params,
11788 &pixels_size,
11789 nullptr,
11790 nullptr,
11791 &skip_size,
11792 nullptr)) {
11686 return error::kOutOfBounds; 11793 return error::kOutOfBounds;
11687 } 11794 }
11795 DCHECK_EQ(0u, skip_size);
11688 11796
11689 const void* pixels = GetSharedMemoryAs<const void*>( 11797 const void* pixels;
11690 c.pixels_shm_id, c.pixels_shm_offset, data_size); 11798 if (state_.bound_pixel_unpack_buffer.get()) {
11691 if (!pixels) 11799 if (pixels_shm_id != 0)
11692 return error::kOutOfBounds; 11800 return error::kInvalidArguments;
11801 pixels = reinterpret_cast<const void*>(pixels_shm_offset);
11802 } else {
11803 if (pixels_size > 0) {
11804 if (pixels_shm_id == 0)
11805 return error::kInvalidArguments;
11806 pixels = GetSharedMemoryAs<const void*>(
11807 pixels_shm_id, pixels_shm_offset, pixels_size);
11808 if (!pixels)
11809 return error::kOutOfBounds;
11810 } else {
11811 pixels = nullptr;
11812 }
11813 }
11693 11814
11694 TextureManager::DoTexSubImageArguments args = { 11815 TextureManager::DoTexSubImageArguments args = {
11695 target, level, xoffset, yoffset, 0, width, height, 1, 11816 target, level, xoffset, yoffset, 0, width, height, 1,
11696 format, type, pixels, data_size, 11817 format, type, pixels, pixels_size,
11697 TextureManager::DoTexSubImageArguments::kTexSubImage2D}; 11818 TextureManager::DoTexSubImageArguments::kTexSubImage2D};
11698 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, 11819 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_,
11699 &framebuffer_state_, 11820 &framebuffer_state_,
11700 "glTexSubImage2D", args); 11821 "glTexSubImage2D", args);
11701 11822
11702 // This may be a slow command. Exit command processing to allow for 11823 // This may be a slow command. Exit command processing to allow for
11703 // context preemption and GPU watchdog checks. 11824 // context preemption and GPU watchdog checks.
11704 ExitCommandProcessingEarly(); 11825 ExitCommandProcessingEarly();
11705 return error::kNoError; 11826 return error::kNoError;
11706 } 11827 }
(...skipping 14 matching lines...) Expand all
11721 GLenum target = static_cast<GLenum>(c.target); 11842 GLenum target = static_cast<GLenum>(c.target);
11722 GLint level = static_cast<GLint>(c.level); 11843 GLint level = static_cast<GLint>(c.level);
11723 GLint xoffset = static_cast<GLint>(c.xoffset); 11844 GLint xoffset = static_cast<GLint>(c.xoffset);
11724 GLint yoffset = static_cast<GLint>(c.yoffset); 11845 GLint yoffset = static_cast<GLint>(c.yoffset);
11725 GLint zoffset = static_cast<GLint>(c.zoffset); 11846 GLint zoffset = static_cast<GLint>(c.zoffset);
11726 GLsizei width = static_cast<GLsizei>(c.width); 11847 GLsizei width = static_cast<GLsizei>(c.width);
11727 GLsizei height = static_cast<GLsizei>(c.height); 11848 GLsizei height = static_cast<GLsizei>(c.height);
11728 GLsizei depth = static_cast<GLsizei>(c.depth); 11849 GLsizei depth = static_cast<GLsizei>(c.depth);
11729 GLenum format = static_cast<GLenum>(c.format); 11850 GLenum format = static_cast<GLenum>(c.format);
11730 GLenum type = static_cast<GLenum>(c.type); 11851 GLenum type = static_cast<GLenum>(c.type);
11731 uint32_t data_size; 11852 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id);
11732 if (!GLES2Util::ComputeImageDataSizes( 11853 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset);
11733 width, height, depth, format, type, state_.unpack_alignment, &data_size, 11854
11734 NULL, NULL)) { 11855 if (width < 0 || height < 0 || depth < 0) {
11856 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexSubImage3D", "dimensions < 0");
11857 return error::kNoError;
11858 }
11859 PixelStoreParams params;
11860 if (state_.bound_pixel_unpack_buffer.get()) {
11861 params = state_.GetUnpackParams(ContextState::k3D);
11862 } else {
11863 // When reading from client buffer, the command buffer client side took
11864 // the responsibility to take the pixels from the client buffer and
11865 // unpack them according to the full ES3 pack parameters as source, all
11866 // parameters for 0 (except for alignment) as destination mem for the
11867 // service side.
11868 params.alignment = state_.unpack_alignment;
11869 }
11870 uint32_t pixels_size;
11871 uint32_t skip_size;
11872 if (!GLES2Util::ComputeImageDataSizesES3(width, height, depth,
11873 format, type,
11874 params,
11875 &pixels_size,
11876 nullptr,
11877 nullptr,
11878 &skip_size,
11879 nullptr)) {
11735 return error::kOutOfBounds; 11880 return error::kOutOfBounds;
11736 } 11881 }
11882 DCHECK_EQ(0u, skip_size);
11737 11883
11738 const void* pixels = GetSharedMemoryAs<const void*>( 11884 const void* pixels;
11739 c.pixels_shm_id, c.pixels_shm_offset, data_size); 11885 if (state_.bound_pixel_unpack_buffer.get()) {
11740 if (!pixels) 11886 if (pixels_shm_id != 0)
11741 return error::kOutOfBounds; 11887 return error::kInvalidArguments;
11888 pixels = reinterpret_cast<const void*>(pixels_shm_offset);
11889 } else {
11890 if (pixels_size > 0) {
11891 if (pixels_shm_id == 0)
11892 return error::kInvalidArguments;
11893 pixels = GetSharedMemoryAs<const void*>(
11894 pixels_shm_id, pixels_shm_offset, pixels_size);
11895 if (!pixels)
11896 return error::kOutOfBounds;
11897 } else {
11898 pixels = nullptr;
11899 }
11900 }
11742 11901
11743 TextureManager::DoTexSubImageArguments args = { 11902 TextureManager::DoTexSubImageArguments args = {
11744 target, level, xoffset, yoffset, zoffset, width, height, depth, 11903 target, level, xoffset, yoffset, zoffset, width, height, depth,
11745 format, type, pixels, data_size, 11904 format, type, pixels, pixels_size,
11746 TextureManager::DoTexSubImageArguments::kTexSubImage3D}; 11905 TextureManager::DoTexSubImageArguments::kTexSubImage3D};
11747 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, 11906 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_,
11748 &framebuffer_state_, 11907 &framebuffer_state_,
11749 "glTexSubImage3D", args); 11908 "glTexSubImage3D", args);
11750 11909
11751 // This may be a slow command. Exit command processing to allow for 11910 // This may be a slow command. Exit command processing to allow for
11752 // context preemption and GPU watchdog checks. 11911 // context preemption and GPU watchdog checks.
11753 ExitCommandProcessingEarly(); 11912 ExitCommandProcessingEarly();
11754 return error::kNoError; 11913 return error::kNoError;
11755 } 11914 }
(...skipping 4194 matching lines...) Expand 10 before | Expand all | Expand 10 after
15950 } 16109 }
15951 16110
15952 // Include the auto-generated part of this file. We split this because it means 16111 // Include the auto-generated part of this file. We split this because it means
15953 // we can easily edit the non-auto generated parts right here in this file 16112 // we can easily edit the non-auto generated parts right here in this file
15954 // instead of having to edit some template or the code generator. 16113 // instead of having to edit some template or the code generator.
15955 #include "base/macros.h" 16114 #include "base/macros.h"
15956 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 16115 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
15957 16116
15958 } // namespace gles2 16117 } // namespace gles2
15959 } // namespace gpu 16118 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698