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

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

Issue 14402003: Add OES_texture_half_float extension support in Chromium for desktop GL implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add support for glReadPixels and updated test cases Created 7 years, 7 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 <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 gl_internal_format = GL_ALPHA16F_ARB; 300 gl_internal_format = GL_ALPHA16F_ARB;
301 break; 301 break;
302 default: 302 default:
303 NOTREACHED(); 303 NOTREACHED();
304 break; 304 break;
305 } 305 }
306 } 306 }
307 return gl_internal_format; 307 return gl_internal_format;
308 } 308 }
309 309
310 static inline GLenum GetTexType(GLenum type) {
311 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
312 if (type == GL_HALF_FLOAT_OES)
313 return GL_HALF_FLOAT_ARB;
314 }
315 return type;
316 }
317
310 static void WrappedTexImage2D( 318 static void WrappedTexImage2D(
311 GLenum target, 319 GLenum target,
312 GLint level, 320 GLint level,
313 GLenum internal_format, 321 GLenum internal_format,
314 GLsizei width, 322 GLsizei width,
315 GLsizei height, 323 GLsizei height,
316 GLint border, 324 GLint border,
317 GLenum format, 325 GLenum format,
318 GLenum type, 326 GLenum type,
319 const void* pixels) { 327 const void* pixels) {
320 glTexImage2D( 328 glTexImage2D(
321 target, level, GetTexInternalFormat(internal_format, format, type), 329 target, level, GetTexInternalFormat(internal_format, format, type),
322 width, height, border, format, type, pixels); 330 width, height, border, format, GetTexType(type), pixels);
331 }
332
333 static void WrappedTexSubImage2D(
334 GLenum target,
335 GLint level,
336 GLint xoffset,
337 GLint yoffset,
338 GLsizei width,
339 GLsizei height,
340 GLenum format,
341 GLenum type,
342 const void * data) {
343 glTexSubImage2D(
344 target, level, xoffset, yoffset, width, height, format,
345 GetTexType(type), data);
323 } 346 }
324 347
325 // Wrapper for glEnable/glDisable that doesn't suck. 348 // Wrapper for glEnable/glDisable that doesn't suck.
326 static void EnableDisable(GLenum pname, bool enable) { 349 static void EnableDisable(GLenum pname, bool enable) {
327 if (enable) { 350 if (enable) {
328 glEnable(pname); 351 glEnable(pname);
329 } else { 352 } else {
330 glDisable(pname); 353 glDisable(pname);
331 } 354 }
332 } 355 }
(...skipping 6575 matching lines...) Expand 10 before | Expand all | Expand 10 after
6908 GLint read_width = read_end_x - read_x; 6931 GLint read_width = read_end_x - read_x;
6909 for (GLint yy = 0; yy < height; ++yy) { 6932 for (GLint yy = 0; yy < height; ++yy) {
6910 GLint ry = y + yy; 6933 GLint ry = y + yy;
6911 6934
6912 // Clear the row. 6935 // Clear the row.
6913 memset(dst, 0, unpadded_row_size); 6936 memset(dst, 0, unpadded_row_size);
6914 6937
6915 // If the row is in range, copy it. 6938 // If the row is in range, copy it.
6916 if (ry >= 0 && ry < max_size.height() && read_width > 0) { 6939 if (ry >= 0 && ry < max_size.height() && read_width > 0) {
6917 glReadPixels( 6940 glReadPixels(
6918 read_x, ry, read_width, 1, format, type, dst + dest_row_offset); 6941 read_x, ry, read_width, 1, format, GetTexType(type),
6942 dst + dest_row_offset);
6919 } 6943 }
6920 dst += padded_row_size; 6944 dst += padded_row_size;
6921 } 6945 }
6922 } else { 6946 } else {
6923 glReadPixels(x, y, width, height, format, type, pixels); 6947 glReadPixels(x, y, width, height, format, GetTexType(type), pixels);
6924 } 6948 }
6925 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); 6949 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels");
6926 if (error == GL_NO_ERROR) { 6950 if (error == GL_NO_ERROR) {
6927 if (result != NULL) { 6951 if (result != NULL) {
6928 *result = true; 6952 *result = true;
6929 } 6953 }
6930 6954
6931 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); 6955 GLenum read_format = GetBoundReadFrameBufferInternalFormat();
6932 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); 6956 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format);
6933 if ((channels_exist & 0x0008) == 0 && 6957 if ((channels_exist & 0x0008) == 0 &&
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
7878 } 7902 }
7879 7903
7880 if (texture->IsAttachedToFramebuffer()) { 7904 if (texture->IsAttachedToFramebuffer()) {
7881 clear_state_dirty_ = true; 7905 clear_state_dirty_ = true;
7882 // TODO(gman): If textures tracked which framebuffers they were attached to 7906 // TODO(gman): If textures tracked which framebuffers they were attached to
7883 // we could just mark those framebuffers as not complete. 7907 // we could just mark those framebuffers as not complete.
7884 framebuffer_manager()->IncFramebufferStateChangeCount(); 7908 framebuffer_manager()->IncFramebufferStateChangeCount();
7885 } 7909 }
7886 7910
7887 if (!teximage2d_faster_than_texsubimage2d_ && level_is_same && pixels) { 7911 if (!teximage2d_faster_than_texsubimage2d_ && level_is_same && pixels) {
7888 glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels); 7912 WrappedTexSubImage2D(target, level, 0, 0, width, height, format,
7913 type, pixels);
7889 texture_manager()->SetLevelCleared(texture, target, level, true); 7914 texture_manager()->SetLevelCleared(texture, target, level, true);
7890 tex_image_2d_failed_ = false; 7915 tex_image_2d_failed_ = false;
7891 return; 7916 return;
7892 } 7917 }
7893 7918
7894 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexImage2D"); 7919 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexImage2D");
7895 WrappedTexImage2D( 7920 WrappedTexImage2D(
7896 target, level, internal_format, width, height, border, format, type, 7921 target, level, internal_format, width, height, border, format, type,
7897 pixels); 7922 pixels);
7898 GLenum error = LOCAL_PEEK_GL_ERROR("glTexImage2D"); 7923 GLenum error = LOCAL_PEEK_GL_ERROR("glTexImage2D");
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
8368 bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height); 8393 bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height);
8369 DCHECK(ok); 8394 DCHECK(ok);
8370 if (xoffset != 0 || yoffset != 0 || 8395 if (xoffset != 0 || yoffset != 0 ||
8371 width != tex_width || height != tex_height) { 8396 width != tex_width || height != tex_height) {
8372 if (!texture_manager()->ClearTextureLevel(this, texture, target, level)) { 8397 if (!texture_manager()->ClearTextureLevel(this, texture, target, level)) {
8373 LOCAL_SET_GL_ERROR( 8398 LOCAL_SET_GL_ERROR(
8374 GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); 8399 GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big");
8375 return error::kNoError; 8400 return error::kNoError;
8376 } 8401 }
8377 ScopedTextureUploadTimer timer(this); 8402 ScopedTextureUploadTimer timer(this);
8378 glTexSubImage2D( 8403 WrappedTexSubImage2D(
8379 target, level, xoffset, yoffset, width, height, format, type, data); 8404 target, level, xoffset, yoffset, width, height, format, type, data);
8380 return error::kNoError; 8405 return error::kNoError;
8381 } 8406 }
8382 8407
8383 if (teximage2d_faster_than_texsubimage2d_ && !texture->IsImmutable()) { 8408 if (teximage2d_faster_than_texsubimage2d_ && !texture->IsImmutable()) {
8384 ScopedTextureUploadTimer timer(this); 8409 ScopedTextureUploadTimer timer(this);
8385 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the 8410 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the
8386 // same as internal_foramt. If that changes we'll need to look them up. 8411 // same as internal_foramt. If that changes we'll need to look them up.
8387 WrappedTexImage2D( 8412 WrappedTexImage2D(
8388 target, level, format, width, height, 0, format, type, data); 8413 target, level, format, width, height, 0, format, type, data);
8389 } else { 8414 } else {
8390 ScopedTextureUploadTimer timer(this); 8415 ScopedTextureUploadTimer timer(this);
8391 glTexSubImage2D( 8416 WrappedTexSubImage2D(
8392 target, level, xoffset, yoffset, width, height, format, type, data); 8417 target, level, xoffset, yoffset, width, height, format, type, data);
8393 } 8418 }
8394 texture_manager()->SetLevelCleared(texture, target, level, true); 8419 texture_manager()->SetLevelCleared(texture, target, level, true);
8395 return error::kNoError; 8420 return error::kNoError;
8396 } 8421 }
8397 8422
8398 error::Error GLES2DecoderImpl::HandleTexSubImage2D( 8423 error::Error GLES2DecoderImpl::HandleTexSubImage2D(
8399 uint32 immediate_data_size, const cmds::TexSubImage2D& c) { 8424 uint32 immediate_data_size, const cmds::TexSubImage2D& c) {
8400 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); 8425 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D");
8401 GLboolean internal = static_cast<GLboolean>(c.internal); 8426 GLboolean internal = static_cast<GLboolean>(c.internal);
(...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after
10263 // it might need to be duped to prevent use-after-free of the memory. 10288 // it might need to be duped to prevent use-after-free of the memory.
10264 gpu::Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id); 10289 gpu::Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id);
10265 base::SharedMemory* shared_memory = buffer.shared_memory; 10290 base::SharedMemory* shared_memory = buffer.shared_memory;
10266 uint32 shm_size = buffer.size; 10291 uint32 shm_size = buffer.size;
10267 uint32 shm_data_offset = c.pixels_shm_offset; 10292 uint32 shm_data_offset = c.pixels_shm_offset;
10268 uint32 shm_data_size = pixels_size; 10293 uint32 shm_data_size = pixels_size;
10269 10294
10270 // Setup the parameters. 10295 // Setup the parameters.
10271 GLenum gl_internal_format = 10296 GLenum gl_internal_format =
10272 GetTexInternalFormat(internal_format, format, type); 10297 GetTexInternalFormat(internal_format, format, type);
10298 GLenum gl_type = GetTexType(type);
10273 gfx::AsyncTexImage2DParams tex_params = {target, level, gl_internal_format, 10299 gfx::AsyncTexImage2DParams tex_params = {target, level, gl_internal_format,
10274 width, height, border, format, type}; 10300 width, height, border, format,
10301 gl_type};
10275 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size, 10302 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size,
10276 shm_data_offset, shm_data_size}; 10303 shm_data_offset, shm_data_size};
10277 10304
10278 // Set up the async state if needed, and make the texture 10305 // Set up the async state if needed, and make the texture
10279 // immutable so the async state stays valid. The level info 10306 // immutable so the async state stays valid. The level info
10280 // is set up lazily when the transfer completes. 10307 // is set up lazily when the transfer completes.
10281 DCHECK(!texture->GetAsyncTransferState()); 10308 DCHECK(!texture->GetAsyncTransferState());
10282 texture->SetAsyncTransferState( 10309 texture->SetAsyncTransferState(
10283 make_scoped_ptr( 10310 make_scoped_ptr(
10284 async_pixel_transfer_delegate_->CreatePixelTransferState( 10311 async_pixel_transfer_delegate_->CreatePixelTransferState(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
10353 10380
10354 // We know the memory/size is safe, so get the real shared memory since 10381 // We know the memory/size is safe, so get the real shared memory since
10355 // it might need to be duped to prevent use-after-free of the memory. 10382 // it might need to be duped to prevent use-after-free of the memory.
10356 gpu::Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id); 10383 gpu::Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id);
10357 base::SharedMemory* shared_memory = buffer.shared_memory; 10384 base::SharedMemory* shared_memory = buffer.shared_memory;
10358 uint32 shm_size = buffer.size; 10385 uint32 shm_size = buffer.size;
10359 uint32 shm_data_offset = c.data_shm_offset; 10386 uint32 shm_data_offset = c.data_shm_offset;
10360 uint32 shm_data_size = data_size; 10387 uint32 shm_data_size = data_size;
10361 10388
10362 // Setup the parameters. 10389 // Setup the parameters.
10390 GLenum gl_type = GetTexType(type);
10363 gfx::AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset, 10391 gfx::AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset,
10364 width, height, format, type}; 10392 width, height, format, gl_type};
10365 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size, 10393 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size,
10366 shm_data_offset, shm_data_size}; 10394 shm_data_offset, shm_data_size};
10367 if (!texture->GetAsyncTransferState()) { 10395 if (!texture->GetAsyncTransferState()) {
10368 // TODO(epenner): We may want to enforce exclusive use 10396 // TODO(epenner): We may want to enforce exclusive use
10369 // of async APIs in which case this should become an error, 10397 // of async APIs in which case this should become an error,
10370 // (the texture should have been async defined). 10398 // (the texture should have been async defined).
10371 gfx::AsyncTexImage2DParams define_params = {target, level, 10399 gfx::AsyncTexImage2DParams define_params = {target, level,
10372 0, 0, 0, 0, 0, 0}; 10400 0, 0, 0, 0, 0, 0};
10373 texture->GetLevelSize(target, level, &define_params.width, 10401 texture->GetLevelSize(target, level, &define_params.width,
10374 &define_params.height); 10402 &define_params.height);
10375 texture->GetLevelType(target, level, &define_params.type, 10403 texture->GetLevelType(target, level, &define_params.type,
10376 &define_params.internal_format); 10404 &define_params.internal_format);
10405
10406 // Update the internal_format and type for PixelTransferState if needed.
10407 define_params.internal_format =
10408 GetTexInternalFormat(define_params.internal_format,
10409 define_params.internal_format, type);
10410 define_params.type = GetTexType(define_params.type);
10411
10377 // Set up the async state if needed, and make the texture 10412 // Set up the async state if needed, and make the texture
10378 // immutable so the async state stays valid. 10413 // immutable so the async state stays valid.
10379 texture->SetAsyncTransferState( 10414 texture->SetAsyncTransferState(
10380 make_scoped_ptr( 10415 make_scoped_ptr(
10381 async_pixel_transfer_delegate_->CreatePixelTransferState( 10416 async_pixel_transfer_delegate_->CreatePixelTransferState(
10382 texture->service_id(), 10417 texture->service_id(),
10383 define_params))); 10418 define_params)));
10384 texture->SetImmutable(true); 10419 texture->SetImmutable(true);
10385 } 10420 }
10386 10421
(...skipping 25 matching lines...) Expand all
10412 return error::kNoError; 10447 return error::kNoError;
10413 } 10448 }
10414 10449
10415 // Include the auto-generated part of this file. We split this because it means 10450 // Include the auto-generated part of this file. We split this because it means
10416 // we can easily edit the non-auto generated parts right here in this file 10451 // we can easily edit the non-auto generated parts right here in this file
10417 // instead of having to edit some template or the code generator. 10452 // instead of having to edit some template or the code generator.
10418 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10453 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10419 10454
10420 } // namespace gles2 10455 } // namespace gles2
10421 } // namespace gpu 10456 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698