Chromium Code Reviews| Index: gpu/command_buffer/service/buffer_manager.cc |
| diff --git a/gpu/command_buffer/service/buffer_manager.cc b/gpu/command_buffer/service/buffer_manager.cc |
| index 914d9b09da06e8fb3a71c2162e9a8e6291dea962..04b03ca2e6aac3d67d4caadc8b18fb9769ee3a8c 100644 |
| --- a/gpu/command_buffer/service/buffer_manager.cc |
| +++ b/gpu/command_buffer/service/buffer_manager.cc |
| @@ -34,6 +34,7 @@ BufferManager::BufferManager(MemoryTracker* memory_tracker, |
| allow_buffers_on_multiple_targets_(false), |
| allow_fixed_attribs_(false), |
| buffer_count_(0), |
| + primitive_restart_enabled_(false), |
| have_context_(true), |
| use_client_side_arrays_for_stream_buffers_( |
| feature_info |
| @@ -199,13 +200,17 @@ void Buffer::ClearCache() { |
| } |
| template <typename T> |
| -GLuint GetMaxValue(const void* data, GLuint offset, GLsizei count) { |
| +GLuint GetMaxValue(const void* data, GLuint offset, GLsizei count, |
| + GLuint primitive_restart_index) { |
| GLuint max_value = 0; |
| const T* element = |
| reinterpret_cast<const T*>(static_cast<const int8_t*>(data) + offset); |
| const T* end = element + count; |
| for (; element < end; ++element) { |
| if (*element > max_value) { |
| + if (*element == primitive_restart_index) { |
| + continue; |
| + } |
| max_value = *element; |
| } |
| } |
| @@ -241,23 +246,36 @@ bool Buffer::GetMaxValueForRange( |
| // Scan the range for the max value and store |
| GLuint max_v = 0; |
| + GLuint primitive_restart_index = 0; |
| switch (type) { |
| case GL_UNSIGNED_BYTE: |
| - max_v = GetMaxValue<uint8_t>(shadow_.get(), offset, count); |
| + if (manager_->primitive_restart_enabled_) { |
| + primitive_restart_index = 0xFF; |
| + } |
| + max_v = GetMaxValue<uint8_t>(shadow_.get(), offset, count, |
| + primitive_restart_index); |
| break; |
| case GL_UNSIGNED_SHORT: |
| // Check we are not accessing an odd byte for a 2 byte value. |
| if ((offset & 1) != 0) { |
| return false; |
| } |
| - max_v = GetMaxValue<uint16_t>(shadow_.get(), offset, count); |
| + if (manager_->primitive_restart_enabled_) { |
| + primitive_restart_index = 0xFFFF; |
| + } |
| + max_v = GetMaxValue<uint16_t>(shadow_.get(), offset, count, |
| + primitive_restart_index); |
| break; |
| case GL_UNSIGNED_INT: |
| // Check we are not accessing a non aligned address for a 4 byte value. |
| if ((offset & 3) != 0) { |
| return false; |
| } |
| - max_v = GetMaxValue<uint32_t>(shadow_.get(), offset, count); |
| + if (manager_->primitive_restart_enabled_) { |
| + primitive_restart_index = 0xFFFFFFFF; |
| + } |
| + max_v = GetMaxValue<uint32_t>(shadow_.get(), offset, count, |
| + primitive_restart_index); |
| break; |
| default: |
| NOTREACHED(); // should never get here by validation. |
| @@ -536,6 +554,19 @@ Buffer* BufferManager::GetBufferInfoForTarget( |
| } |
| } |
| +void BufferManager::SetPrimitiveRestartState(bool enabled) { |
| + if (primitive_restart_enabled_ != enabled) { |
| + primitive_restart_enabled_ = enabled; |
| + |
| + for (BufferMap::const_iterator it = buffers_.begin(); |
| + it != buffers_.end(); ++it) { |
|
Zhenyao Mo
2016/03/15 18:24:37
nit: wrong indent
yunchao
2016/03/16 16:05:39
Done.
|
| + if (it->second->initial_target() == GL_ELEMENT_ARRAY_BUFFER) { |
| + it->second->range_set_.clear(); |
| + } |
| + } |
| + } |
| +} |
| + |
| bool BufferManager::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| base::trace_event::ProcessMemoryDump* pmd) { |
| const int client_id = memory_tracker_->ClientId(); |