Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: gpu/command_buffer/service/valuebuffer_manager.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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/gl_utils.h"
6 #include "gpu/command_buffer/service/program_manager.h"
5 #include "gpu/command_buffer/service/valuebuffer_manager.h" 7 #include "gpu/command_buffer/service/valuebuffer_manager.h"
6 8
7 #include "gpu/command_buffer/service/program_manager.h"
8
9 namespace gpu { 9 namespace gpu {
10 namespace gles2 { 10 namespace gles2 {
11 11
12 Valuebuffer::Valuebuffer(ValuebufferManager* manager, GLuint client_id) 12 Valuebuffer::Valuebuffer(ValuebufferManager* manager, unsigned int client_id)
13 : manager_(manager), client_id_(client_id), has_been_bound_(false) { 13 : manager_(manager), client_id_(client_id), has_been_bound_(false) {
14 manager_->StartTracking(this); 14 manager_->StartTracking(this);
15 active_state_map_ = new ValueStateMap();
15 } 16 }
16 17
17 Valuebuffer::~Valuebuffer() { 18 Valuebuffer::~Valuebuffer() {
18 if (manager_) { 19 if (manager_) {
19 manager_->StopTracking(this); 20 manager_->StopTracking(this);
20 manager_ = NULL; 21 manager_ = NULL;
21 } 22 }
22 } 23 }
23 24
24 void Valuebuffer::AddSubscription(GLenum subscription) { 25 void Valuebuffer::AddSubscription(unsigned int subscription) {
25 subscriptions_.insert(subscription); 26 subscriptions_.insert(subscription);
26 } 27 }
27 28
28 void Valuebuffer::RemoveSubscription(GLenum subscription) { 29 void Valuebuffer::RemoveSubscription(unsigned int subscription) {
29 subscriptions_.erase(subscription); 30 subscriptions_.erase(subscription);
30 } 31 }
31 32
32 bool Valuebuffer::IsSubscribed(GLenum subscription) { 33 bool Valuebuffer::IsSubscribed(unsigned int subscription) {
33 return subscriptions_.find(subscription) != subscriptions_.end(); 34 return subscriptions_.find(subscription) != subscriptions_.end();
34 } 35 }
35 36
36 const ValueState *Valuebuffer::GetState(GLenum target) const { 37 const ValueState* Valuebuffer::GetState(unsigned int target) const {
37 StateMap::const_iterator it = active_state_map_.find(target); 38 return active_state_map_->GetState(target);
38 return it != active_state_map_.end() ? &it->second : NULL;
39 } 39 }
40 40
41 void Valuebuffer::UpdateState(const StateMap& pending_state) { 41 void Valuebuffer::UpdateState(const ValueStateMap* pending_state) {
42 DCHECK(pending_state);
42 for (SubscriptionSet::const_iterator it = subscriptions_.begin(); 43 for (SubscriptionSet::const_iterator it = subscriptions_.begin();
43 it != subscriptions_.end(); ++it) { 44 it != subscriptions_.end(); ++it) {
44 StateMap::const_iterator pending_state_it = pending_state.find((*it)); 45 const ValueState *state = pending_state->GetState(*it);
45 if (pending_state_it != pending_state.end()) { 46 if (state != NULL) {
46 active_state_map_[pending_state_it->first] = pending_state_it->second; 47 active_state_map_->UpdateState(*it, *state);
47 } 48 }
48 } 49 }
49 } 50 }
50 51
51 ValuebufferManager::ValuebufferManager() 52 ValuebufferManager::ValuebufferManager(ValueStateMap* state_map)
52 : valuebuffer_count_(0) { 53 : valuebuffer_count_(0),
54 pending_state_map_(state_map) {
53 } 55 }
54 56
55 ValuebufferManager::~ValuebufferManager() { 57 ValuebufferManager::~ValuebufferManager() {
56 DCHECK(valuebuffer_map_.empty()); 58 DCHECK(valuebuffer_map_.empty());
57 DCHECK(pending_state_map_.empty());
58 // If this triggers, that means something is keeping a reference to 59 // If this triggers, that means something is keeping a reference to
59 // a Valuebuffer belonging to this. 60 // a Valuebuffer belonging to this.
60 CHECK_EQ(valuebuffer_count_, 0u); 61 CHECK_EQ(valuebuffer_count_, 0u);
61 } 62 }
62 63
63 void ValuebufferManager::Destroy() { 64 void ValuebufferManager::Destroy() {
64 valuebuffer_map_.clear(); 65 valuebuffer_map_.clear();
65 pending_state_map_.clear();
66 } 66 }
67 67
68 void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) { 68 void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) {
69 ++valuebuffer_count_; 69 ++valuebuffer_count_;
70 } 70 }
71 71
72 void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) { 72 void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) {
73 --valuebuffer_count_; 73 --valuebuffer_count_;
74 } 74 }
75 75
76 void ValuebufferManager::CreateValuebuffer(GLuint client_id) { 76 void ValuebufferManager::CreateValuebuffer(unsigned int client_id) {
77 scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id)); 77 scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id));
78 std::pair<ValuebufferMap::iterator, bool> result = 78 std::pair<ValuebufferMap::iterator, bool> result =
79 valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer)); 79 valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer));
80 DCHECK(result.second); 80 DCHECK(result.second);
81 } 81 }
82 82
83 Valuebuffer* ValuebufferManager::GetValuebuffer(GLuint client_id) { 83 Valuebuffer* ValuebufferManager::GetValuebuffer(unsigned int client_id) {
84 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); 84 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id);
85 return it != valuebuffer_map_.end() ? it->second.get() : NULL; 85 return it != valuebuffer_map_.end() ? it->second.get() : NULL;
86 } 86 }
87 87
88 void ValuebufferManager::RemoveValuebuffer(GLuint client_id) { 88 void ValuebufferManager::RemoveValuebuffer(unsigned int client_id) {
89 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); 89 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id);
90 if (it != valuebuffer_map_.end()) { 90 if (it != valuebuffer_map_.end()) {
91 Valuebuffer* valuebuffer = it->second.get(); 91 Valuebuffer* valuebuffer = it->second.get();
92 valuebuffer->MarkAsDeleted(); 92 valuebuffer->MarkAsDeleted();
93 valuebuffer_map_.erase(it); 93 valuebuffer_map_.erase(it);
94 } 94 }
95 } 95 }
96 96
97 void ValuebufferManager::UpdateValuebufferState(Valuebuffer* valuebuffer) { 97 void ValuebufferManager::UpdateValuebufferState(Valuebuffer* valuebuffer) {
98 DCHECK(valuebuffer); 98 DCHECK(valuebuffer);
99 valuebuffer->UpdateState(pending_state_map_); 99 valuebuffer->UpdateState(pending_state_map_.get());
100 } 100 }
101 101
102 void ValuebufferManager::UpdateValueState( 102 uint32 ValuebufferManager::ApiTypeForSubscriptionTarget(unsigned int target) {
103 GLenum target, const ValueState& state) {
104 pending_state_map_[target] = state;
105 }
106
107 uint32 ValuebufferManager::ApiTypeForSubscriptionTarget(GLenum target) {
108 switch (target) { 103 switch (target) {
109 case GL_MOUSE_POSITION_CHROMIUM: 104 case GL_MOUSE_POSITION_CHROMIUM:
110 return Program::kUniform2i; 105 return Program::kUniform2i;
111 } 106 }
112 NOTREACHED() << "Unhandled uniform subscription target " << target; 107 NOTREACHED() << "Unhandled uniform subscription target " << target;
113 return Program::kUniformNone; 108 return Program::kUniformNone;
114 } 109 }
115 110
116 } // namespace gles2 111 } // namespace gles2
117 } // namespace gpu 112 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/valuebuffer_manager.h ('k') | gpu/command_buffer/service/valuebuffer_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698