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 <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 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1094 | 1094 |
1095 void DoLoseContextCHROMIUM(GLenum current, GLenum other); | 1095 void DoLoseContextCHROMIUM(GLenum current, GLenum other); |
1096 | 1096 |
1097 void DoFlushDriverCachesCHROMIUM(void); | 1097 void DoFlushDriverCachesCHROMIUM(void); |
1098 | 1098 |
1099 void DoMatrixLoadfCHROMIUM(GLenum matrix_mode, const GLfloat* matrix); | 1099 void DoMatrixLoadfCHROMIUM(GLenum matrix_mode, const GLfloat* matrix); |
1100 void DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode); | 1100 void DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode); |
1101 void DoScheduleCALayerInUseQueryCHROMIUM(GLsizei count, | 1101 void DoScheduleCALayerInUseQueryCHROMIUM(GLsizei count, |
1102 const GLuint* textures); | 1102 const GLuint* textures); |
1103 | 1103 |
1104 void DoFlushMappedBufferRange( | |
1105 GLenum target, GLintptr offset, GLsizeiptr size); | |
1106 | |
1104 // Creates a Program for the given program. | 1107 // Creates a Program for the given program. |
1105 Program* CreateProgram(GLuint client_id, GLuint service_id) { | 1108 Program* CreateProgram(GLuint client_id, GLuint service_id) { |
1106 return program_manager()->CreateProgram(client_id, service_id); | 1109 return program_manager()->CreateProgram(client_id, service_id); |
1107 } | 1110 } |
1108 | 1111 |
1109 // Gets the program info for the given program. Returns NULL if none exists. | 1112 // Gets the program info for the given program. Returns NULL if none exists. |
1110 Program* GetProgram(GLuint client_id) { | 1113 Program* GetProgram(GLuint client_id) { |
1111 return program_manager()->GetProgram(client_id); | 1114 return program_manager()->GetProgram(client_id); |
1112 } | 1115 } |
1113 | 1116 |
(...skipping 15344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16458 return error::kOutOfBounds; | 16461 return error::kOutOfBounds; |
16459 } | 16462 } |
16460 | 16463 |
16461 if (!validators_->buffer_target.IsValid(target)) { | 16464 if (!validators_->buffer_target.IsValid(target)) { |
16462 LOCAL_SET_GL_ERROR_INVALID_ENUM("glMapBufferRange", target, "target"); | 16465 LOCAL_SET_GL_ERROR_INVALID_ENUM("glMapBufferRange", target, "target"); |
16463 return error::kNoError; | 16466 return error::kNoError; |
16464 } | 16467 } |
16465 | 16468 |
16466 GLbitfield mask = GL_MAP_INVALIDATE_BUFFER_BIT; | 16469 GLbitfield mask = GL_MAP_INVALIDATE_BUFFER_BIT; |
16467 if ((access & mask) == mask) { | 16470 if ((access & mask) == mask) { |
16468 // TODO(zmo): To be on the safe side, always map | 16471 // To be on the safe side, always map GL_MAP_INVALIDATE_BUFFER_BIT to |
16469 // GL_MAP_INVALIDATE_BUFFER_BIT to GL_MAP_INVALIDATE_RANGE_BIT. | 16472 // GL_MAP_INVALIDATE_RANGE_BIT. |
16470 access = (access & ~GL_MAP_INVALIDATE_BUFFER_BIT); | 16473 access = (access & ~GL_MAP_INVALIDATE_BUFFER_BIT); |
16471 access = (access | GL_MAP_INVALIDATE_RANGE_BIT); | 16474 access = (access | GL_MAP_INVALIDATE_RANGE_BIT); |
16472 } | 16475 } |
16473 // TODO(zmo): Always filter out GL_MAP_UNSYNCHRONIZED_BIT to get rid of | 16476 // Always filter out GL_MAP_UNSYNCHRONIZED_BIT to get rid of undefined |
16474 // undefined behaviors. | 16477 // behaviors. |
16475 mask = GL_MAP_READ_BIT | GL_MAP_UNSYNCHRONIZED_BIT; | 16478 mask = GL_MAP_READ_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
16476 if ((access & mask) == mask) { | 16479 if ((access & mask) == mask) { |
16477 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "MapBufferRange", | 16480 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "MapBufferRange", |
16478 "incompatible access bits"); | 16481 "incompatible access bits"); |
16479 return error::kNoError; | 16482 return error::kNoError; |
16480 } | 16483 } |
16481 access = (access & ~GL_MAP_UNSYNCHRONIZED_BIT); | 16484 access = (access & ~GL_MAP_UNSYNCHRONIZED_BIT); |
16482 if ((access & GL_MAP_WRITE_BIT) == GL_MAP_WRITE_BIT && | 16485 if ((access & GL_MAP_WRITE_BIT) == GL_MAP_WRITE_BIT && |
16483 (access & GL_MAP_INVALIDATE_RANGE_BIT) == 0) { | 16486 (access & GL_MAP_INVALIDATE_RANGE_BIT) == 0) { |
16484 access = (access | GL_MAP_READ_BIT); | 16487 access = (access | GL_MAP_READ_BIT); |
16485 } | 16488 } |
16486 void* ptr = glMapBufferRange(target, offset, size, access); | 16489 void* ptr = glMapBufferRange(target, offset, size, access); |
16487 if (ptr == nullptr) { | 16490 if (ptr == nullptr) { |
16488 return error::kNoError; | 16491 return error::kNoError; |
16489 } | 16492 } |
16490 Buffer* buffer = buffer_manager()->GetBufferInfoForTarget(&state_, target); | 16493 Buffer* buffer = buffer_manager()->GetBufferInfoForTarget(&state_, target); |
16491 DCHECK(buffer); | 16494 DCHECK(buffer); |
16492 buffer->SetMappedRange(offset, size, access, ptr, | 16495 buffer->SetMappedRange(offset, size, access, ptr, |
16493 GetSharedMemoryBuffer(data_shm_id)); | 16496 GetSharedMemoryBuffer(data_shm_id)); |
16494 if ((access & GL_MAP_INVALIDATE_RANGE_BIT) == 0) { | 16497 if ((access & GL_MAP_INVALIDATE_RANGE_BIT) == 0) { |
16495 memcpy(mem, ptr, size); | 16498 memcpy(mem, ptr, size); |
16496 } | 16499 } |
16497 *result = 1; | 16500 *result = 1; |
16498 return error::kNoError; | 16501 return error::kNoError; |
16499 } | 16502 } |
16500 | 16503 |
16501 error::Error GLES2DecoderImpl::HandleUnmapBuffer( | 16504 error::Error GLES2DecoderImpl::HandleUnmapBuffer( |
16502 uint32_t immediate_data_size, const void* cmd_data) { | 16505 uint32_t immediate_data_size, const void* cmd_data) { |
16506 const char* func_name = "glUnmapBuffer"; | |
16503 if (!unsafe_es3_apis_enabled()) { | 16507 if (!unsafe_es3_apis_enabled()) { |
16504 return error::kUnknownCommand; | 16508 return error::kUnknownCommand; |
16505 } | 16509 } |
16506 const gles2::cmds::UnmapBuffer& c = | 16510 const gles2::cmds::UnmapBuffer& c = |
16507 *static_cast<const gles2::cmds::UnmapBuffer*>(cmd_data); | 16511 *static_cast<const gles2::cmds::UnmapBuffer*>(cmd_data); |
16508 GLenum target = static_cast<GLenum>(c.target); | 16512 GLenum target = static_cast<GLenum>(c.target); |
16509 | 16513 |
16510 if (!validators_->buffer_target.IsValid(target)) { | 16514 if (!validators_->buffer_target.IsValid(target)) { |
16511 LOCAL_SET_GL_ERROR_INVALID_ENUM("glMapBufferRange", target, "target"); | 16515 LOCAL_SET_GL_ERROR_INVALID_ENUM(func_name, target, "target"); |
16512 return error::kNoError; | 16516 return error::kNoError; |
16513 } | 16517 } |
16514 | 16518 |
16515 Buffer* buffer = buffer_manager()->GetBufferInfoForTarget(&state_, target); | 16519 Buffer* buffer = buffer_manager()->GetBufferInfoForTarget(&state_, target); |
16516 if (!buffer) { | 16520 if (!buffer) { |
16517 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "UnmapBuffer", "no buffer bound"); | 16521 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, "no buffer bound"); |
16518 return error::kNoError; | 16522 return error::kNoError; |
16519 } | 16523 } |
16520 const Buffer::MappedRange* mapped_range = buffer->GetMappedRange(); | 16524 const Buffer::MappedRange* mapped_range = buffer->GetMappedRange(); |
16521 if (!mapped_range) { | 16525 if (!mapped_range) { |
16522 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "UnmapBuffer", | 16526 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, "buffer is unmapped"); |
16523 "buffer is unmapped"); | |
16524 return error::kNoError; | 16527 return error::kNoError; |
16525 } | 16528 } |
16526 if ((mapped_range->access & GL_MAP_WRITE_BIT) == 0 || | 16529 if ((mapped_range->access & GL_MAP_WRITE_BIT) == 0 || |
16527 (mapped_range->access & GL_MAP_FLUSH_EXPLICIT_BIT) == | 16530 (mapped_range->access & GL_MAP_FLUSH_EXPLICIT_BIT) == |
16528 GL_MAP_FLUSH_EXPLICIT_BIT) { | 16531 GL_MAP_FLUSH_EXPLICIT_BIT) { |
16529 // If we don't need to write back, or explict flush is required, no copying | 16532 // If we don't need to write back, or explict flush is required, no copying |
16530 // back is needed. | 16533 // back is needed. |
16531 } else { | 16534 } else { |
16532 void* mem = mapped_range->GetShmPointer(); | 16535 void* mem = mapped_range->GetShmPointer(); |
16533 if (!mem) { | 16536 if (!mem) { |
(...skipping 12 matching lines...) Expand all Loading... | |
16546 // the contexts in the share group. | 16549 // the contexts in the share group. |
16547 LOG(ERROR) << "glUnmapBuffer unexpectedly returned GL_FALSE"; | 16550 LOG(ERROR) << "glUnmapBuffer unexpectedly returned GL_FALSE"; |
16548 // Need to lose current context before broadcasting! | 16551 // Need to lose current context before broadcasting! |
16549 MarkContextLost(error::kGuilty); | 16552 MarkContextLost(error::kGuilty); |
16550 group_->LoseContexts(error::kInnocent); | 16553 group_->LoseContexts(error::kInnocent); |
16551 return error::kLostContext; | 16554 return error::kLostContext; |
16552 } | 16555 } |
16553 return error::kNoError; | 16556 return error::kNoError; |
16554 } | 16557 } |
16555 | 16558 |
16559 void GLES2DecoderImpl::DoFlushMappedBufferRange( | |
16560 GLenum target, GLintptr offset, GLsizeiptr size) { | |
16561 const char* func_name = "glFlushMappedBufferRange"; | |
16562 if (offset < 0) { | |
16563 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, func_name, "offset < 0"); | |
16564 return; | |
16565 } | |
16566 Buffer* buffer = buffer_manager()->GetBufferInfoForTarget(&state_, target); | |
16567 if (!buffer) { | |
16568 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, "no buffer bound"); | |
16569 return; | |
16570 } | |
16571 const Buffer::MappedRange* mapped_range = buffer->GetMappedRange(); | |
16572 if (!mapped_range) { | |
16573 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, "buffer is unmapped"); | |
16574 return; | |
16575 } | |
16576 if ((mapped_range->access & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) { | |
16577 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, | |
16578 "buffer is mapped without MAP_FLUSH_EXPLICIT_BIT flag"); | |
16579 return; | |
16580 } | |
16581 base::CheckedNumeric<GLsizeiptr> range_size = size; | |
16582 range_size += offset; | |
16583 if (!range_size.IsValid() || | |
16584 range_size.ValueOrDefault(0) > mapped_range->size) { | |
16585 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, func_name, | |
16586 "offset + size out-of-bounds"); | |
16587 return; | |
16588 } | |
16589 glFlushMappedBufferRange(target, offset, size); | |
piman
2016/08/08 22:55:22
This in itself won't do anything - the client side
| |
16590 } | |
16591 | |
16556 // Note that GL_LOST_CONTEXT is specific to GLES. | 16592 // Note that GL_LOST_CONTEXT is specific to GLES. |
16557 // For desktop GL we have to query the reset status proactively. | 16593 // For desktop GL we have to query the reset status proactively. |
16558 void GLES2DecoderImpl::OnContextLostError() { | 16594 void GLES2DecoderImpl::OnContextLostError() { |
16559 if (!WasContextLost()) { | 16595 if (!WasContextLost()) { |
16560 // Need to lose current context before broadcasting! | 16596 // Need to lose current context before broadcasting! |
16561 CheckResetStatus(); | 16597 CheckResetStatus(); |
16562 group_->LoseContexts(error::kUnknown); | 16598 group_->LoseContexts(error::kUnknown); |
16563 reset_by_robustness_extension_ = true; | 16599 reset_by_robustness_extension_ = true; |
16564 } | 16600 } |
16565 } | 16601 } |
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17725 } | 17761 } |
17726 | 17762 |
17727 // Include the auto-generated part of this file. We split this because it means | 17763 // Include the auto-generated part of this file. We split this because it means |
17728 // we can easily edit the non-auto generated parts right here in this file | 17764 // we can easily edit the non-auto generated parts right here in this file |
17729 // instead of having to edit some template or the code generator. | 17765 // instead of having to edit some template or the code generator. |
17730 #include "base/macros.h" | 17766 #include "base/macros.h" |
17731 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 17767 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
17732 | 17768 |
17733 } // namespace gles2 | 17769 } // namespace gles2 |
17734 } // namespace gpu | 17770 } // namespace gpu |
OLD | NEW |