| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/atomicops.h" | 15 #include "base/atomicops.h" |
| 16 #include "base/at_exit.h" | 16 #include "base/at_exit.h" |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #define GLES2_GPU_SERVICE 1 | 21 #define GLES2_GPU_SERVICE 1 |
| 22 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 22 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 23 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 23 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 24 #include "gpu/command_buffer/common/id_allocator.h" | 24 #include "gpu/command_buffer/common/id_allocator.h" |
| 25 #include "gpu/command_buffer/common/trace_event.h" |
| 25 #include "gpu/command_buffer/service/buffer_manager.h" | 26 #include "gpu/command_buffer/service/buffer_manager.h" |
| 26 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 27 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 27 #include "gpu/command_buffer/service/context_group.h" | 28 #include "gpu/command_buffer/service/context_group.h" |
| 28 #include "gpu/command_buffer/service/feature_info.h" | 29 #include "gpu/command_buffer/service/feature_info.h" |
| 29 #include "gpu/command_buffer/service/framebuffer_manager.h" | 30 #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 30 #include "gpu/command_buffer/service/gl_utils.h" | 31 #include "gpu/command_buffer/service/gl_utils.h" |
| 31 #include "gpu/command_buffer/service/gles2_cmd_validation.h" | 32 #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
| 32 #include "gpu/command_buffer/service/program_manager.h" | 33 #include "gpu/command_buffer/service/program_manager.h" |
| 33 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 34 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| 34 #include "gpu/command_buffer/service/shader_manager.h" | 35 #include "gpu/command_buffer/service/shader_manager.h" |
| 35 #include "gpu/command_buffer/service/shader_translator.h" | 36 #include "gpu/command_buffer/service/shader_translator.h" |
| 36 #include "gpu/command_buffer/service/texture_manager.h" | 37 #include "gpu/command_buffer/service/texture_manager.h" |
| 37 #include "gpu/common/gpu_trace_event.h" | |
| 38 #include "gpu/GLES2/gles2_command_buffer.h" | 38 #include "gpu/GLES2/gles2_command_buffer.h" |
| 39 #include "ui/gfx/gl/gl_context.h" | 39 #include "ui/gfx/gl/gl_context.h" |
| 40 #include "ui/gfx/gl/gl_implementation.h" | 40 #include "ui/gfx/gl/gl_implementation.h" |
| 41 | 41 |
| 42 #if !defined(GL_DEPTH24_STENCIL8) | 42 #if !defined(GL_DEPTH24_STENCIL8) |
| 43 #define GL_DEPTH24_STENCIL8 0x88F0 | 43 #define GL_DEPTH24_STENCIL8 0x88F0 |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 namespace gpu { | 46 namespace gpu { |
| 47 namespace gles2 { | 47 namespace gles2 { |
| (...skipping 5521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5569 if (error == GL_NO_ERROR) { | 5569 if (error == GL_NO_ERROR) { |
| 5570 texture_manager()->SetLevelInfo(feature_info_, info, | 5570 texture_manager()->SetLevelInfo(feature_info_, info, |
| 5571 target, level, internal_format, width, height, 1, border, format, type); | 5571 target, level, internal_format, width, height, 1, border, format, type); |
| 5572 tex_image_2d_failed_ = false; | 5572 tex_image_2d_failed_ = false; |
| 5573 } | 5573 } |
| 5574 return error::kNoError; | 5574 return error::kNoError; |
| 5575 } | 5575 } |
| 5576 | 5576 |
| 5577 error::Error GLES2DecoderImpl::HandleTexImage2D( | 5577 error::Error GLES2DecoderImpl::HandleTexImage2D( |
| 5578 uint32 immediate_data_size, const gles2::TexImage2D& c) { | 5578 uint32 immediate_data_size, const gles2::TexImage2D& c) { |
| 5579 GPU_TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D"); | 5579 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D"); |
| 5580 tex_image_2d_failed_ = true; | 5580 tex_image_2d_failed_ = true; |
| 5581 GLenum target = static_cast<GLenum>(c.target); | 5581 GLenum target = static_cast<GLenum>(c.target); |
| 5582 GLint level = static_cast<GLint>(c.level); | 5582 GLint level = static_cast<GLint>(c.level); |
| 5583 GLint internal_format = static_cast<GLint>(c.internalformat); | 5583 GLint internal_format = static_cast<GLint>(c.internalformat); |
| 5584 GLsizei width = static_cast<GLsizei>(c.width); | 5584 GLsizei width = static_cast<GLsizei>(c.width); |
| 5585 GLsizei height = static_cast<GLsizei>(c.height); | 5585 GLsizei height = static_cast<GLsizei>(c.height); |
| 5586 GLint border = static_cast<GLint>(c.border); | 5586 GLint border = static_cast<GLint>(c.border); |
| 5587 GLenum format = static_cast<GLenum>(c.format); | 5587 GLenum format = static_cast<GLenum>(c.format); |
| 5588 GLenum type = static_cast<GLenum>(c.type); | 5588 GLenum type = static_cast<GLenum>(c.type); |
| 5589 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); | 5589 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5883 SetGLError(GL_INVALID_VALUE, | 5883 SetGLError(GL_INVALID_VALUE, |
| 5884 "glTexSubImage2D: bad dimensions."); | 5884 "glTexSubImage2D: bad dimensions."); |
| 5885 return; | 5885 return; |
| 5886 } | 5886 } |
| 5887 glTexSubImage2D( | 5887 glTexSubImage2D( |
| 5888 target, level, xoffset, yoffset, width, height, format, type, data); | 5888 target, level, xoffset, yoffset, width, height, format, type, data); |
| 5889 } | 5889 } |
| 5890 | 5890 |
| 5891 error::Error GLES2DecoderImpl::HandleTexSubImage2D( | 5891 error::Error GLES2DecoderImpl::HandleTexSubImage2D( |
| 5892 uint32 immediate_data_size, const gles2::TexSubImage2D& c) { | 5892 uint32 immediate_data_size, const gles2::TexSubImage2D& c) { |
| 5893 GPU_TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); | 5893 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); |
| 5894 GLboolean internal = static_cast<GLboolean>(c.internal); | 5894 GLboolean internal = static_cast<GLboolean>(c.internal); |
| 5895 if (internal == GL_TRUE && tex_image_2d_failed_) | 5895 if (internal == GL_TRUE && tex_image_2d_failed_) |
| 5896 return error::kNoError; | 5896 return error::kNoError; |
| 5897 | 5897 |
| 5898 GLenum target = static_cast<GLenum>(c.target); | 5898 GLenum target = static_cast<GLenum>(c.target); |
| 5899 GLint level = static_cast<GLint>(c.level); | 5899 GLint level = static_cast<GLint>(c.level); |
| 5900 GLint xoffset = static_cast<GLint>(c.xoffset); | 5900 GLint xoffset = static_cast<GLint>(c.xoffset); |
| 5901 GLint yoffset = static_cast<GLint>(c.yoffset); | 5901 GLint yoffset = static_cast<GLint>(c.yoffset); |
| 5902 GLsizei width = static_cast<GLsizei>(c.width); | 5902 GLsizei width = static_cast<GLsizei>(c.width); |
| 5903 GLsizei height = static_cast<GLsizei>(c.height); | 5903 GLsizei height = static_cast<GLsizei>(c.height); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6307 } | 6307 } |
| 6308 service_ids[ii] = info->service_id(); | 6308 service_ids[ii] = info->service_id(); |
| 6309 } | 6309 } |
| 6310 // TODO(gman): call glShaderBinary | 6310 // TODO(gman): call glShaderBinary |
| 6311 return error::kNoError; | 6311 return error::kNoError; |
| 6312 #endif | 6312 #endif |
| 6313 } | 6313 } |
| 6314 | 6314 |
| 6315 error::Error GLES2DecoderImpl::HandleSwapBuffers( | 6315 error::Error GLES2DecoderImpl::HandleSwapBuffers( |
| 6316 uint32 immediate_data_size, const gles2::SwapBuffers& c) { | 6316 uint32 immediate_data_size, const gles2::SwapBuffers& c) { |
| 6317 GPU_TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleSwapBuffers"); | 6317 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleSwapBuffers"); |
| 6318 // If offscreen then don't actually SwapBuffers to the display. Just copy | 6318 // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 6319 // the rendered frame to another frame buffer. | 6319 // the rendered frame to another frame buffer. |
| 6320 if (offscreen_target_frame_buffer_.get()) { | 6320 if (offscreen_target_frame_buffer_.get()) { |
| 6321 ScopedGLErrorSuppressor suppressor(this); | 6321 ScopedGLErrorSuppressor suppressor(this); |
| 6322 | 6322 |
| 6323 // First check to see if a deferred offscreen render buffer resize is | 6323 // First check to see if a deferred offscreen render buffer resize is |
| 6324 // pending. | 6324 // pending. |
| 6325 if (!UpdateOffscreenFrameBufferSize()) { | 6325 if (!UpdateOffscreenFrameBufferSize()) { |
| 6326 LOG(ERROR) << "Context lost because reallocation of offscreen FBO " | 6326 LOG(ERROR) << "Context lost because reallocation of offscreen FBO " |
| 6327 << "failed."; | 6327 << "failed."; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 6353 } | 6353 } |
| 6354 | 6354 |
| 6355 // Run the callback with |binder| in scope, so that the callback can call | 6355 // Run the callback with |binder| in scope, so that the callback can call |
| 6356 // ReadPixels or CopyTexImage2D. | 6356 // ReadPixels or CopyTexImage2D. |
| 6357 if (swap_buffers_callback_.get()) { | 6357 if (swap_buffers_callback_.get()) { |
| 6358 swap_buffers_callback_->Run(); | 6358 swap_buffers_callback_->Run(); |
| 6359 } | 6359 } |
| 6360 return error::kNoError; | 6360 return error::kNoError; |
| 6361 } | 6361 } |
| 6362 } else { | 6362 } else { |
| 6363 GPU_TRACE_EVENT0("gpu", "GLContext::SwapBuffers"); | 6363 TRACE_EVENT0("gpu", "GLContext::SwapBuffers"); |
| 6364 if (!context_->SwapBuffers()) { | 6364 if (!context_->SwapBuffers()) { |
| 6365 LOG(ERROR) << "Context lost because SwapBuffers failed."; | 6365 LOG(ERROR) << "Context lost because SwapBuffers failed."; |
| 6366 return error::kLostContext; | 6366 return error::kLostContext; |
| 6367 } | 6367 } |
| 6368 } | 6368 } |
| 6369 | 6369 |
| 6370 if (swap_buffers_callback_.get()) { | 6370 if (swap_buffers_callback_.get()) { |
| 6371 swap_buffers_callback_->Run(); | 6371 swap_buffers_callback_->Run(); |
| 6372 } | 6372 } |
| 6373 | 6373 |
| 6374 return error::kNoError; | 6374 return error::kNoError; |
| 6375 } | 6375 } |
| 6376 | 6376 |
| 6377 error::Error GLES2DecoderImpl::HandleSetLatchCHROMIUM( | 6377 error::Error GLES2DecoderImpl::HandleSetLatchCHROMIUM( |
| 6378 uint32 immediate_data_size, const gles2::SetLatchCHROMIUM& c) { | 6378 uint32 immediate_data_size, const gles2::SetLatchCHROMIUM& c) { |
| 6379 GPU_TRACE_EVENT0("gpu", "SetLatch"); | 6379 TRACE_EVENT0("gpu", "SetLatch"); |
| 6380 // Ensure the side effects of previous commands are visible to other contexts. | 6380 // Ensure the side effects of previous commands are visible to other contexts. |
| 6381 // There is no need to do this for ANGLE because it uses a | 6381 // There is no need to do this for ANGLE because it uses a |
| 6382 // single D3D device for all contexts. | 6382 // single D3D device for all contexts. |
| 6383 if (!IsAngle()) | 6383 if (!IsAngle()) |
| 6384 glFlush(); | 6384 glFlush(); |
| 6385 | 6385 |
| 6386 int32 shm_id = gpu::kLatchSharedMemoryId; | 6386 int32 shm_id = gpu::kLatchSharedMemoryId; |
| 6387 uint32 latch_id = c.latch_id; | 6387 uint32 latch_id = c.latch_id; |
| 6388 uint32 shm_offset = 0; | 6388 uint32 shm_offset = 0; |
| 6389 base::subtle::Atomic32* latch; | 6389 base::subtle::Atomic32* latch; |
| 6390 if (!SafeMultiplyUint32(latch_id, sizeof(*latch), &shm_offset)) { | 6390 if (!SafeMultiplyUint32(latch_id, sizeof(*latch), &shm_offset)) { |
| 6391 return error::kOutOfBounds; | 6391 return error::kOutOfBounds; |
| 6392 } | 6392 } |
| 6393 latch = GetSharedMemoryAs<base::subtle::Atomic32*>( | 6393 latch = GetSharedMemoryAs<base::subtle::Atomic32*>( |
| 6394 shm_id, shm_offset, sizeof(*latch)); | 6394 shm_id, shm_offset, sizeof(*latch)); |
| 6395 if (!latch) { | 6395 if (!latch) { |
| 6396 return error::kOutOfBounds; | 6396 return error::kOutOfBounds; |
| 6397 } | 6397 } |
| 6398 base::subtle::NoBarrier_Store(latch, 1); | 6398 base::subtle::NoBarrier_Store(latch, 1); |
| 6399 if (!latch_callback_.is_null()) | 6399 if (!latch_callback_.is_null()) |
| 6400 latch_callback_.Run(true); | 6400 latch_callback_.Run(true); |
| 6401 return error::kNoError; | 6401 return error::kNoError; |
| 6402 } | 6402 } |
| 6403 | 6403 |
| 6404 error::Error GLES2DecoderImpl::HandleWaitLatchCHROMIUM( | 6404 error::Error GLES2DecoderImpl::HandleWaitLatchCHROMIUM( |
| 6405 uint32 immediate_data_size, const gles2::WaitLatchCHROMIUM& c) { | 6405 uint32 immediate_data_size, const gles2::WaitLatchCHROMIUM& c) { |
| 6406 GPU_TRACE_EVENT0("gpu", "WaitLatch"); | 6406 TRACE_EVENT0("gpu", "WaitLatch"); |
| 6407 int32 shm_id = gpu::kLatchSharedMemoryId; | 6407 int32 shm_id = gpu::kLatchSharedMemoryId; |
| 6408 uint32 latch_id = c.latch_id; | 6408 uint32 latch_id = c.latch_id; |
| 6409 uint32 shm_offset = 0; | 6409 uint32 shm_offset = 0; |
| 6410 base::subtle::Atomic32* latch; | 6410 base::subtle::Atomic32* latch; |
| 6411 if (!SafeMultiplyUint32(latch_id, sizeof(*latch), &shm_offset)) { | 6411 if (!SafeMultiplyUint32(latch_id, sizeof(*latch), &shm_offset)) { |
| 6412 return error::kOutOfBounds; | 6412 return error::kOutOfBounds; |
| 6413 } | 6413 } |
| 6414 latch = GetSharedMemoryAs<base::subtle::Atomic32*>( | 6414 latch = GetSharedMemoryAs<base::subtle::Atomic32*>( |
| 6415 shm_id, shm_offset, sizeof(*latch)); | 6415 shm_id, shm_offset, sizeof(*latch)); |
| 6416 if (!latch) { | 6416 if (!latch) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6508 return error::kNoError; | 6508 return error::kNoError; |
| 6509 } | 6509 } |
| 6510 | 6510 |
| 6511 // Include the auto-generated part of this file. We split this because it means | 6511 // Include the auto-generated part of this file. We split this because it means |
| 6512 // we can easily edit the non-auto generated parts right here in this file | 6512 // we can easily edit the non-auto generated parts right here in this file |
| 6513 // instead of having to edit some template or the code generator. | 6513 // instead of having to edit some template or the code generator. |
| 6514 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 6514 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 6515 | 6515 |
| 6516 } // namespace gles2 | 6516 } // namespace gles2 |
| 6517 } // namespace gpu | 6517 } // namespace gpu |
| OLD | NEW |