Chromium Code Reviews| Index: gpu/command_buffer/service/valuebuffer_manager.cc |
| diff --git a/gpu/command_buffer/service/valuebuffer_manager.cc b/gpu/command_buffer/service/valuebuffer_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9e46a639547cbdae800893844047e270011a2edb |
| --- /dev/null |
| +++ b/gpu/command_buffer/service/valuebuffer_manager.cc |
| @@ -0,0 +1,159 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "gpu/command_buffer/service/valuebuffer_manager.h" |
| + |
| +#include "gpu/command_buffer/service/program_manager.h" |
| + |
| +namespace gpu { |
| +namespace gles2 { |
| + |
| +ValueState::ValueState(GLenum target) : target_(target) { |
| +} |
| + |
| +ValueState::~ValueState() { |
| +} |
| + |
| +IntValueState::IntValueState(GLenum target, GLint* data) |
| + : ValueState(target), data_(data) { |
| + DCHECK(ValuebufferManager::ApiTypeForSubscriptionTarget(target) & |
| + (Program::kUniform1i |
| + | Program::kUniform2i |
| + | Program::kUniform3i |
| + | Program::kUniform4i)); |
| +} |
| + |
| +IntValueState::~IntValueState() { |
| +} |
| + |
| +FloatValueState::FloatValueState(GLenum target, GLfloat* data) |
| + : ValueState(target), data_(data) { |
| + DCHECK(ValuebufferManager::ApiTypeForSubscriptionTarget(target) & |
| + (Program::kUniform1f |
| + | Program::kUniform2f |
| + | Program::kUniform3f |
| + | Program::kUniform4f |
| + | Program::kUniformMatrix2f |
| + | Program::kUniformMatrix3f |
| + | Program::kUniformMatrix4f)); |
| +} |
| + |
| +FloatValueState::~FloatValueState() { |
| +} |
| + |
| +Valuebuffer::Valuebuffer(ValuebufferManager* manager, GLuint client_id) |
| + : manager_(manager), client_id_(client_id), has_been_bound_(false) { |
| + manager_->StartTracking(this); |
| +} |
| + |
| +Valuebuffer::~Valuebuffer() { |
| + if (manager_) { |
| + manager_->StopTracking(this); |
| + manager_ = NULL; |
| + } |
| +} |
| + |
| +void Valuebuffer::AddSubscription(GLenum subscription) { |
| + subscriptions_.insert(subscription); |
| +} |
| + |
| +void Valuebuffer::RemoveSubscription(GLenum subscription) { |
| + subscriptions_.erase(subscription); |
| +} |
| + |
| +bool Valuebuffer::IsSubscribed(GLenum subscription) { |
| + return subscriptions_.find(subscription) != subscriptions_.end(); |
| +} |
| + |
| +const ValueState* Valuebuffer::GetState(GLenum target) const { |
| + StateMap::const_iterator it = active_state_map_.find(target); |
| + return it != active_state_map_.end() ? it->second.get() : NULL; |
| +} |
| + |
| +void Valuebuffer::UpdateState(const StateMap& pending_state) { |
| + for (SubscriptionSet::const_iterator it = subscriptions_.begin(); |
| + it != subscriptions_.end(); ++it) { |
| + StateMap::const_iterator state_it = pending_state.find((*it)); |
| + if (state_it != pending_state.end()) { |
| + std::pair<StateMap::iterator, bool> result = |
| + active_state_map_.insert(std::make_pair( |
| + state_it->first, scoped_refptr<ValueState>(state_it->second))); |
|
piman
2014/11/04 02:38:22
active_state_map_.insert(*state_it) ?
orglofch
2014/11/04 19:53:28
Done.
|
| + DCHECK(result.second); |
| + } |
| + } |
| +} |
| + |
| +ValuebufferManager::ValuebufferManager() |
| + : valuebuffer_count_(0), have_context_(true) { |
| +} |
| + |
| +ValuebufferManager::~ValuebufferManager() { |
| + DCHECK(valuebuffer_map_.empty()); |
| + DCHECK(pending_state_map_.empty()); |
| + // If this triggers, that means something is keeping a reference to |
| + // a Valuebuffer belonging to this. |
| + CHECK_EQ(valuebuffer_count_, 0u); |
| +} |
| + |
| +void ValuebufferManager::Destroy(bool have_context) { |
| + have_context_ = have_context; |
|
piman
2014/11/04 02:38:22
nit: you're not using have_context_, so you can re
orglofch
2014/11/04 19:53:28
Done.
|
| + valuebuffer_map_.clear(); |
| + pending_state_map_.clear(); |
| +} |
| + |
| +void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) { |
| + ++valuebuffer_count_; |
| +} |
| + |
| +void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) { |
| + --valuebuffer_count_; |
| +} |
| + |
| +void ValuebufferManager::CreateValuebuffer(GLuint client_id) { |
| + scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id)); |
| + std::pair<ValuebufferMap::iterator, bool> result = |
| + valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer)); |
| + DCHECK(result.second); |
| +} |
| + |
| +Valuebuffer* ValuebufferManager::GetValuebuffer(GLuint client_id) { |
| + ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); |
| + return it != valuebuffer_map_.end() ? it->second.get() : NULL; |
| +} |
| + |
| +void ValuebufferManager::RemoveValuebuffer(GLuint client_id) { |
| + ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); |
| + if (it != valuebuffer_map_.end()) { |
| + Valuebuffer* valuebuffer = it->second.get(); |
| + valuebuffer->MarkAsDeleted(); |
| + valuebuffer_map_.erase(it); |
| + } |
| +} |
| + |
| +void ValuebufferManager::UpdateValuebufferState(GLuint client_id) { |
| + ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); |
| + if (it != valuebuffer_map_.end()) { |
| + it->second.get()->UpdateState(pending_state_map_); |
| + } |
| +} |
| + |
| +void ValuebufferManager::UpdateValueState(ValueState* state) { |
| + DCHECK(state); |
| + std::pair<Valuebuffer::StateMap::iterator, bool> result = |
| + pending_state_map_.insert( |
| + std::make_pair(state->target(), scoped_refptr<ValueState>(state))); |
| + DCHECK(result.second); |
| +} |
| + |
| +uint32 ValuebufferManager::ApiTypeForSubscriptionTarget(GLenum target) { |
| + switch (target) { |
| + case GL_MOUSE_POSITION_CHROMIUM: |
| + return Program::kUniform2i; |
| + } |
| + NOTREACHED() << "Unhandled uniform subscription target " << target; |
| + return Program::kUniformNone; |
| +} |
| + |
| +} // namespace gles2 |
| +} // namespace gpu |