OLD | NEW |
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> |
11 #include <map> | 11 #include <map> |
12 #include <stack> | 12 #include <stack> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/at_exit.h" | 16 #include "base/at_exit.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/callback_helpers.h" | |
19 #include "base/command_line.h" | 18 #include "base/command_line.h" |
20 #include "base/debug/trace_event.h" | 19 #include "base/debug/trace_event.h" |
21 #include "base/debug/trace_event_synthetic_delay.h" | 20 #include "base/debug/trace_event_synthetic_delay.h" |
22 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
23 #include "base/numerics/safe_math.h" | |
24 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
26 #include "build/build_config.h" | 24 #include "build/build_config.h" |
27 #define GLES2_GPU_SERVICE 1 | 25 #define GLES2_GPU_SERVICE 1 |
28 #include "gpu/command_buffer/common/debug_marker_manager.h" | 26 #include "gpu/command_buffer/common/debug_marker_manager.h" |
29 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 27 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
30 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 28 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
31 #include "gpu/command_buffer/common/id_allocator.h" | 29 #include "gpu/command_buffer/common/id_allocator.h" |
32 #include "gpu/command_buffer/common/mailbox.h" | 30 #include "gpu/command_buffer/common/mailbox.h" |
33 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" | 31 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 511 |
514 struct FenceCallback { | 512 struct FenceCallback { |
515 explicit FenceCallback() | 513 explicit FenceCallback() |
516 : fence(gfx::GLFence::Create()) { | 514 : fence(gfx::GLFence::Create()) { |
517 DCHECK(fence); | 515 DCHECK(fence); |
518 } | 516 } |
519 std::vector<base::Closure> callbacks; | 517 std::vector<base::Closure> callbacks; |
520 scoped_ptr<gfx::GLFence> fence; | 518 scoped_ptr<gfx::GLFence> fence; |
521 }; | 519 }; |
522 | 520 |
523 class AsyncUploadTokenCompletionObserver | |
524 : public AsyncPixelTransferCompletionObserver { | |
525 public: | |
526 explicit AsyncUploadTokenCompletionObserver(uint32 async_upload_token) | |
527 : async_upload_token_(async_upload_token) { | |
528 } | |
529 | |
530 virtual void DidComplete(const AsyncMemoryParams& mem_params) OVERRIDE { | |
531 DCHECK(mem_params.buffer()); | |
532 void* data = mem_params.GetDataAddress(); | |
533 AsyncUploadSync* sync = static_cast<AsyncUploadSync*>(data); | |
534 sync->SetAsyncUploadToken(async_upload_token_); | |
535 } | |
536 | |
537 private: | |
538 virtual ~AsyncUploadTokenCompletionObserver() { | |
539 } | |
540 | |
541 uint32 async_upload_token_; | |
542 | |
543 DISALLOW_COPY_AND_ASSIGN(AsyncUploadTokenCompletionObserver); | |
544 }; | |
545 | |
546 // } // anonymous namespace. | 521 // } // anonymous namespace. |
547 | 522 |
548 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, | 523 bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
549 uint32* service_texture_id) { | 524 uint32* service_texture_id) { |
550 return false; | 525 return false; |
551 } | 526 } |
552 | 527 |
553 GLES2Decoder::GLES2Decoder() | 528 GLES2Decoder::GLES2Decoder() |
554 : initialized_(false), | 529 : initialized_(false), |
555 debug_(false), | 530 debug_(false), |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); | 706 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
732 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); | 707 bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
733 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); | 708 void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
734 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); | 709 bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
735 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); | 710 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
736 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); | 711 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
737 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); | 712 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
738 bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); | 713 bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
739 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); | 714 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
740 | 715 |
741 // Helper for async upload token completion notification callback. | |
742 base::Closure AsyncUploadTokenCompletionClosure(uint32 async_upload_token, | |
743 uint32 sync_data_shm_id, | |
744 uint32 sync_data_shm_offset); | |
745 | |
746 | |
747 | |
748 // Workarounds | 716 // Workarounds |
749 void OnFboChanged() const; | 717 void OnFboChanged() const; |
750 void OnUseFramebuffer() const; | 718 void OnUseFramebuffer() const; |
751 | 719 |
752 // TODO(gman): Cache these pointers? | 720 // TODO(gman): Cache these pointers? |
753 BufferManager* buffer_manager() { | 721 BufferManager* buffer_manager() { |
754 return group_->buffer_manager(); | 722 return group_->buffer_manager(); |
755 } | 723 } |
756 | 724 |
757 RenderbufferManager* renderbuffer_manager() { | 725 RenderbufferManager* renderbuffer_manager() { |
(...skipping 9622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10380 if (!texture_ref || | 10348 if (!texture_ref || |
10381 async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { | 10349 async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
10382 LOCAL_SET_GL_ERROR( | 10350 LOCAL_SET_GL_ERROR( |
10383 GL_INVALID_OPERATION, | 10351 GL_INVALID_OPERATION, |
10384 function_name, "transfer already in progress"); | 10352 function_name, "transfer already in progress"); |
10385 return false; | 10353 return false; |
10386 } | 10354 } |
10387 return true; | 10355 return true; |
10388 } | 10356 } |
10389 | 10357 |
10390 base::Closure GLES2DecoderImpl::AsyncUploadTokenCompletionClosure( | |
10391 uint32 async_upload_token, | |
10392 uint32 sync_data_shm_id, | |
10393 uint32 sync_data_shm_offset) { | |
10394 scoped_refptr<gpu::Buffer> buffer = GetSharedMemoryBuffer(sync_data_shm_id); | |
10395 if (!buffer || !buffer->GetDataAddress(sync_data_shm_offset, | |
10396 sizeof(AsyncUploadSync))) | |
10397 return base::Closure(); | |
10398 | |
10399 AsyncMemoryParams mem_params(buffer, | |
10400 sync_data_shm_offset, | |
10401 sizeof(AsyncUploadSync)); | |
10402 | |
10403 scoped_refptr<AsyncUploadTokenCompletionObserver> observer( | |
10404 new AsyncUploadTokenCompletionObserver(async_upload_token)); | |
10405 | |
10406 return base::Bind( | |
10407 &AsyncPixelTransferManager::AsyncNotifyCompletion, | |
10408 base::Unretained(GetAsyncPixelTransferManager()), | |
10409 mem_params, | |
10410 observer); | |
10411 } | |
10412 | |
10413 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( | 10358 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( |
10414 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) { | 10359 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) { |
10415 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); | 10360 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); |
10416 GLenum target = static_cast<GLenum>(c.target); | 10361 GLenum target = static_cast<GLenum>(c.target); |
10417 GLint level = static_cast<GLint>(c.level); | 10362 GLint level = static_cast<GLint>(c.level); |
10418 // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use | 10363 // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use |
10419 // unsigned integer for internalformat. | 10364 // unsigned integer for internalformat. |
10420 GLenum internal_format = static_cast<GLenum>(c.internalformat); | 10365 GLenum internal_format = static_cast<GLenum>(c.internalformat); |
10421 GLsizei width = static_cast<GLsizei>(c.width); | 10366 GLsizei width = static_cast<GLsizei>(c.width); |
10422 GLsizei height = static_cast<GLsizei>(c.height); | 10367 GLsizei height = static_cast<GLsizei>(c.height); |
10423 GLint border = static_cast<GLint>(c.border); | 10368 GLint border = static_cast<GLint>(c.border); |
10424 GLenum format = static_cast<GLenum>(c.format); | 10369 GLenum format = static_cast<GLenum>(c.format); |
10425 GLenum type = static_cast<GLenum>(c.type); | 10370 GLenum type = static_cast<GLenum>(c.type); |
10426 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); | 10371 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
10427 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); | 10372 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
10428 uint32 pixels_size; | 10373 uint32 pixels_size; |
10429 uint32 async_upload_token = static_cast<uint32>(c.async_upload_token); | |
10430 uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id); | |
10431 uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); | |
10432 | |
10433 base::ScopedClosureRunner scoped_completion_callback; | |
10434 if (async_upload_token) { | |
10435 base::Closure completion_closure = | |
10436 AsyncUploadTokenCompletionClosure(async_upload_token, | |
10437 sync_data_shm_id, | |
10438 sync_data_shm_offset); | |
10439 if (completion_closure.is_null()) | |
10440 return error::kInvalidArguments; | |
10441 | |
10442 scoped_completion_callback.Reset(completion_closure); | |
10443 } | |
10444 | 10374 |
10445 // TODO(epenner): Move this and copies of this memory validation | 10375 // TODO(epenner): Move this and copies of this memory validation |
10446 // into ValidateTexImage2D step. | 10376 // into ValidateTexImage2D step. |
10447 if (!GLES2Util::ComputeImageDataSizes( | 10377 if (!GLES2Util::ComputeImageDataSizes( |
10448 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, | 10378 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, |
10449 NULL)) { | 10379 NULL)) { |
10450 return error::kOutOfBounds; | 10380 return error::kOutOfBounds; |
10451 } | 10381 } |
10452 const void* pixels = NULL; | 10382 const void* pixels = NULL; |
10453 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { | 10383 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10520 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { | 10450 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { |
10521 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); | 10451 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); |
10522 GLenum target = static_cast<GLenum>(c.target); | 10452 GLenum target = static_cast<GLenum>(c.target); |
10523 GLint level = static_cast<GLint>(c.level); | 10453 GLint level = static_cast<GLint>(c.level); |
10524 GLint xoffset = static_cast<GLint>(c.xoffset); | 10454 GLint xoffset = static_cast<GLint>(c.xoffset); |
10525 GLint yoffset = static_cast<GLint>(c.yoffset); | 10455 GLint yoffset = static_cast<GLint>(c.yoffset); |
10526 GLsizei width = static_cast<GLsizei>(c.width); | 10456 GLsizei width = static_cast<GLsizei>(c.width); |
10527 GLsizei height = static_cast<GLsizei>(c.height); | 10457 GLsizei height = static_cast<GLsizei>(c.height); |
10528 GLenum format = static_cast<GLenum>(c.format); | 10458 GLenum format = static_cast<GLenum>(c.format); |
10529 GLenum type = static_cast<GLenum>(c.type); | 10459 GLenum type = static_cast<GLenum>(c.type); |
10530 uint32 async_upload_token = static_cast<uint32>(c.async_upload_token); | |
10531 uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id); | |
10532 uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); | |
10533 | |
10534 base::ScopedClosureRunner scoped_completion_callback; | |
10535 if (async_upload_token) { | |
10536 base::Closure completion_closure = | |
10537 AsyncUploadTokenCompletionClosure(async_upload_token, | |
10538 sync_data_shm_id, | |
10539 sync_data_shm_offset); | |
10540 if (completion_closure.is_null()) | |
10541 return error::kInvalidArguments; | |
10542 | |
10543 scoped_completion_callback.Reset(completion_closure); | |
10544 } | |
10545 | 10460 |
10546 // TODO(epenner): Move this and copies of this memory validation | 10461 // TODO(epenner): Move this and copies of this memory validation |
10547 // into ValidateTexSubImage2D step. | 10462 // into ValidateTexSubImage2D step. |
10548 uint32 data_size; | 10463 uint32 data_size; |
10549 if (!GLES2Util::ComputeImageDataSizes( | 10464 if (!GLES2Util::ComputeImageDataSizes( |
10550 width, height, format, type, state_.unpack_alignment, &data_size, | 10465 width, height, format, type, state_.unpack_alignment, &data_size, |
10551 NULL, NULL)) { | 10466 NULL, NULL)) { |
10552 return error::kOutOfBounds; | 10467 return error::kOutOfBounds; |
10553 } | 10468 } |
10554 const void* pixels = GetSharedMemoryAs<const void*>( | 10469 const void* pixels = GetSharedMemoryAs<const void*>( |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10637 LOCAL_SET_GL_ERROR( | 10552 LOCAL_SET_GL_ERROR( |
10638 GL_INVALID_OPERATION, | 10553 GL_INVALID_OPERATION, |
10639 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); | 10554 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); |
10640 return error::kNoError; | 10555 return error::kNoError; |
10641 } | 10556 } |
10642 delegate->WaitForTransferCompletion(); | 10557 delegate->WaitForTransferCompletion(); |
10643 ProcessFinishedAsyncTransfers(); | 10558 ProcessFinishedAsyncTransfers(); |
10644 return error::kNoError; | 10559 return error::kNoError; |
10645 } | 10560 } |
10646 | 10561 |
10647 error::Error GLES2DecoderImpl::HandleWaitAllAsyncTexImage2DCHROMIUM( | |
10648 uint32 immediate_data_size, const cmds::WaitAllAsyncTexImage2DCHROMIUM& c) { | |
10649 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); | |
10650 | |
10651 GetAsyncPixelTransferManager()->WaitAllAsyncTexImage2D(); | |
10652 ProcessFinishedAsyncTransfers(); | |
10653 return error::kNoError; | |
10654 } | |
10655 | |
10656 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( | 10562 void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( |
10657 TextureRef* texture_ref) { | 10563 TextureRef* texture_ref) { |
10658 Texture* texture = texture_ref->texture(); | 10564 Texture* texture = texture_ref->texture(); |
10659 DoDidUseTexImageIfNeeded(texture, texture->target()); | 10565 DoDidUseTexImageIfNeeded(texture, texture->target()); |
10660 } | 10566 } |
10661 | 10567 |
10662 // Include the auto-generated part of this file. We split this because it means | 10568 // Include the auto-generated part of this file. We split this because it means |
10663 // we can easily edit the non-auto generated parts right here in this file | 10569 // we can easily edit the non-auto generated parts right here in this file |
10664 // instead of having to edit some template or the code generator. | 10570 // instead of having to edit some template or the code generator. |
10665 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10571 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
10666 | 10572 |
10667 } // namespace gles2 | 10573 } // namespace gles2 |
10668 } // namespace gpu | 10574 } // namespace gpu |
OLD | NEW |