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

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

Issue 12326146: Refactor/Rename a bunch of GPU stuff (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months 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 | Annotate | Revision Log
OLDNEW
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/shader_manager.h" 5 #include "gpu/command_buffer/service/shader_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 11
12 namespace gpu { 12 namespace gpu {
13 namespace gles2 { 13 namespace gles2 {
14 14
15 ShaderManager::ShaderInfo::ShaderInfo(GLuint service_id, GLenum shader_type) 15 Shader::Shader(GLuint service_id, GLenum shader_type)
16 : use_count_(0), 16 : use_count_(0),
17 service_id_(service_id), 17 service_id_(service_id),
18 shader_type_(shader_type), 18 shader_type_(shader_type),
19 valid_(false), 19 valid_(false),
20 compilation_status_(NOT_COMPILED) { 20 compilation_status_(NOT_COMPILED) {
21 } 21 }
22 22
23 ShaderManager::ShaderInfo::~ShaderInfo() { 23 Shader::~Shader() {
24 } 24 }
25 25
26 void ShaderManager::ShaderInfo::IncUseCount() { 26 void Shader::IncUseCount() {
27 ++use_count_; 27 ++use_count_;
28 } 28 }
29 29
30 void ShaderManager::ShaderInfo::DecUseCount() { 30 void Shader::DecUseCount() {
31 --use_count_; 31 --use_count_;
32 DCHECK_GE(use_count_, 0); 32 DCHECK_GE(use_count_, 0);
33 } 33 }
34 34
35 void ShaderManager::ShaderInfo::MarkAsDeleted() { 35 void Shader::MarkAsDeleted() {
36 DCHECK_NE(service_id_, 0u); 36 DCHECK_NE(service_id_, 0u);
37 service_id_ = 0; 37 service_id_ = 0;
38 } 38 }
39 39
40 void ShaderManager::ShaderInfo::SetStatus( 40 void Shader::SetStatus(
41 bool valid, const char* log, ShaderTranslatorInterface* translator) { 41 bool valid, const char* log, ShaderTranslatorInterface* translator) {
42 valid_ = valid; 42 valid_ = valid;
43 log_info_.reset(log ? new std::string(log) : NULL); 43 log_info_.reset(log ? new std::string(log) : NULL);
44 if (translator && valid) { 44 if (translator && valid) {
45 attrib_map_ = translator->attrib_map(); 45 attrib_map_ = translator->attrib_map();
46 uniform_map_ = translator->uniform_map(); 46 uniform_map_ = translator->uniform_map();
47 name_map_ = translator->name_map(); 47 name_map_ = translator->name_map();
48 } else { 48 } else {
49 attrib_map_.clear(); 49 attrib_map_.clear();
50 uniform_map_.clear(); 50 uniform_map_.clear();
51 name_map_.clear(); 51 name_map_.clear();
52 } 52 }
53 } 53 }
54 54
55 const ShaderManager::ShaderInfo::VariableInfo* 55 const Shader::VariableInfo*
56 ShaderManager::ShaderInfo::GetAttribInfo( 56 Shader::GetAttribInfo(
57 const std::string& name) const { 57 const std::string& name) const {
58 VariableMap::const_iterator it = attrib_map_.find(name); 58 VariableMap::const_iterator it = attrib_map_.find(name);
59 return it != attrib_map_.end() ? &it->second : NULL; 59 return it != attrib_map_.end() ? &it->second : NULL;
60 } 60 }
61 61
62 const std::string* ShaderManager::ShaderInfo::GetAttribMappedName( 62 const std::string* Shader::GetAttribMappedName(
63 const std::string& original_name) const { 63 const std::string& original_name) const {
64 for (VariableMap::const_iterator it = attrib_map_.begin(); 64 for (VariableMap::const_iterator it = attrib_map_.begin();
65 it != attrib_map_.end(); ++it) { 65 it != attrib_map_.end(); ++it) {
66 if (it->second.name == original_name) 66 if (it->second.name == original_name)
67 return &(it->first); 67 return &(it->first);
68 } 68 }
69 return NULL; 69 return NULL;
70 } 70 }
71 71
72 const std::string* ShaderManager::ShaderInfo::GetOriginalNameFromHashedName( 72 const std::string* Shader::GetOriginalNameFromHashedName(
73 const std::string& hashed_name) const { 73 const std::string& hashed_name) const {
74 NameMap::const_iterator it = name_map_.find(hashed_name); 74 NameMap::const_iterator it = name_map_.find(hashed_name);
75 if (it != name_map_.end()) 75 if (it != name_map_.end())
76 return &(it->second); 76 return &(it->second);
77 return NULL; 77 return NULL;
78 } 78 }
79 79
80 const ShaderManager::ShaderInfo::VariableInfo* 80 const Shader::VariableInfo*
81 ShaderManager::ShaderInfo::GetUniformInfo( 81 Shader::GetUniformInfo(
82 const std::string& name) const { 82 const std::string& name) const {
83 VariableMap::const_iterator it = uniform_map_.find(name); 83 VariableMap::const_iterator it = uniform_map_.find(name);
84 return it != uniform_map_.end() ? &it->second : NULL; 84 return it != uniform_map_.end() ? &it->second : NULL;
85 } 85 }
86 86
87 ShaderManager::ShaderManager() {} 87 ShaderManager::ShaderManager() {}
88 88
89 ShaderManager::~ShaderManager() { 89 ShaderManager::~ShaderManager() {
90 DCHECK(shader_infos_.empty()); 90 DCHECK(shader_infos_.empty());
91 } 91 }
92 92
93 void ShaderManager::Destroy(bool have_context) { 93 void ShaderManager::Destroy(bool have_context) {
94 while (!shader_infos_.empty()) { 94 while (!shader_infos_.empty()) {
95 if (have_context) { 95 if (have_context) {
96 ShaderInfo* info = shader_infos_.begin()->second; 96 Shader* info = shader_infos_.begin()->second;
97 if (!info->IsDeleted()) { 97 if (!info->IsDeleted()) {
98 glDeleteShader(info->service_id()); 98 glDeleteShader(info->service_id());
99 info->MarkAsDeleted(); 99 info->MarkAsDeleted();
100 } 100 }
101 } 101 }
102 shader_infos_.erase(shader_infos_.begin()); 102 shader_infos_.erase(shader_infos_.begin());
103 } 103 }
104 } 104 }
105 105
106 ShaderManager::ShaderInfo* ShaderManager::CreateShaderInfo( 106 Shader* ShaderManager::CreateShader(
107 GLuint client_id, 107 GLuint client_id,
108 GLuint service_id, 108 GLuint service_id,
109 GLenum shader_type) { 109 GLenum shader_type) {
110 std::pair<ShaderInfoMap::iterator, bool> result = 110 std::pair<ShaderInfoMap::iterator, bool> result =
111 shader_infos_.insert(std::make_pair( 111 shader_infos_.insert(std::make_pair(
112 client_id, ShaderInfo::Ref(new ShaderInfo(service_id, shader_type)))); 112 client_id, scoped_refptr<Shader>(
113 new Shader(service_id, shader_type))));
113 DCHECK(result.second); 114 DCHECK(result.second);
114 return result.first->second; 115 return result.first->second;
115 } 116 }
116 117
117 ShaderManager::ShaderInfo* ShaderManager::GetShaderInfo(GLuint client_id) { 118 Shader* ShaderManager::GetShader(GLuint client_id) {
118 ShaderInfoMap::iterator it = shader_infos_.find(client_id); 119 ShaderInfoMap::iterator it = shader_infos_.find(client_id);
119 return it != shader_infos_.end() ? it->second : NULL; 120 return it != shader_infos_.end() ? it->second : NULL;
120 } 121 }
121 122
122 bool ShaderManager::GetClientId(GLuint service_id, GLuint* client_id) const { 123 bool ShaderManager::GetClientId(GLuint service_id, GLuint* client_id) const {
123 // This doesn't need to be fast. It's only used during slow queries. 124 // This doesn't need to be fast. It's only used during slow queries.
124 for (ShaderInfoMap::const_iterator it = shader_infos_.begin(); 125 for (ShaderInfoMap::const_iterator it = shader_infos_.begin();
125 it != shader_infos_.end(); ++it) { 126 it != shader_infos_.end(); ++it) {
126 if (it->second->service_id() == service_id) { 127 if (it->second->service_id() == service_id) {
127 *client_id = it->first; 128 *client_id = it->first;
128 return true; 129 return true;
129 } 130 }
130 } 131 }
131 return false; 132 return false;
132 } 133 }
133 134
134 bool ShaderManager::IsOwned(ShaderManager::ShaderInfo* info) { 135 bool ShaderManager::IsOwned(Shader* info) {
135 for (ShaderInfoMap::iterator it = shader_infos_.begin(); 136 for (ShaderInfoMap::iterator it = shader_infos_.begin();
136 it != shader_infos_.end(); ++it) { 137 it != shader_infos_.end(); ++it) {
137 if (it->second.get() == info) { 138 if (it->second.get() == info) {
138 return true; 139 return true;
139 } 140 }
140 } 141 }
141 return false; 142 return false;
142 } 143 }
143 144
144 void ShaderManager::RemoveShaderInfoIfUnused(ShaderManager::ShaderInfo* info) { 145 void ShaderManager::RemoveShader(Shader* info) {
145 DCHECK(info); 146 DCHECK(info);
146 DCHECK(IsOwned(info)); 147 DCHECK(IsOwned(info));
147 if (info->IsDeleted() && !info->InUse()) { 148 if (info->IsDeleted() && !info->InUse()) {
148 for (ShaderInfoMap::iterator it = shader_infos_.begin(); 149 for (ShaderInfoMap::iterator it = shader_infos_.begin();
149 it != shader_infos_.end(); ++it) { 150 it != shader_infos_.end(); ++it) {
150 if (it->second.get() == info) { 151 if (it->second.get() == info) {
151 shader_infos_.erase(it); 152 shader_infos_.erase(it);
152 return; 153 return;
153 } 154 }
154 } 155 }
155 NOTREACHED(); 156 NOTREACHED();
156 } 157 }
157 } 158 }
158 159
159 void ShaderManager::MarkAsDeleted(ShaderManager::ShaderInfo* info) { 160 void ShaderManager::MarkAsDeleted(Shader* info) {
160 DCHECK(info); 161 DCHECK(info);
161 DCHECK(IsOwned(info)); 162 DCHECK(IsOwned(info));
162 info->MarkAsDeleted(); 163 info->MarkAsDeleted();
163 RemoveShaderInfoIfUnused(info); 164 RemoveShader(info);
164 } 165 }
165 166
166 void ShaderManager::UseShader(ShaderManager::ShaderInfo* info) { 167 void ShaderManager::UseShader(Shader* info) {
167 DCHECK(info); 168 DCHECK(info);
168 DCHECK(IsOwned(info)); 169 DCHECK(IsOwned(info));
169 info->IncUseCount(); 170 info->IncUseCount();
170 } 171 }
171 172
172 void ShaderManager::UnuseShader(ShaderManager::ShaderInfo* info) { 173 void ShaderManager::UnuseShader(Shader* info) {
173 DCHECK(info); 174 DCHECK(info);
174 DCHECK(IsOwned(info)); 175 DCHECK(IsOwned(info));
175 info->DecUseCount(); 176 info->DecUseCount();
176 RemoveShaderInfoIfUnused(info); 177 RemoveShader(info);
177 } 178 }
178 179
179 } // namespace gles2 180 } // namespace gles2
180 } // namespace gpu 181 } // namespace gpu
181 182
182 183
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/shader_manager.h ('k') | gpu/command_buffer/service/shader_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698