OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/logging.h" | 6 #include "base/logging.h" |
7 | 7 |
8 namespace gpu { | 8 namespace gpu { |
9 namespace gles2 { | 9 namespace gles2 { |
10 | 10 |
| 11 ShaderManager::ShaderInfo::ShaderInfo(GLuint service_id, GLenum shader_type) |
| 12 : use_count_(0), |
| 13 service_id_(service_id), |
| 14 shader_type_(shader_type), |
| 15 valid_(false) { |
| 16 } |
| 17 |
| 18 ShaderManager::ShaderInfo::~ShaderInfo() { |
| 19 } |
| 20 |
| 21 void ShaderManager::ShaderInfo::IncUseCount() { |
| 22 ++use_count_; |
| 23 } |
| 24 |
| 25 void ShaderManager::ShaderInfo::DecUseCount() { |
| 26 --use_count_; |
| 27 DCHECK_GE(use_count_, 0); |
| 28 } |
| 29 |
| 30 void ShaderManager::ShaderInfo::MarkAsDeleted() { |
| 31 DCHECK_NE(service_id_, 0u); |
| 32 service_id_ = 0; |
| 33 } |
| 34 |
11 void ShaderManager::ShaderInfo::SetStatus( | 35 void ShaderManager::ShaderInfo::SetStatus( |
12 bool valid, const char* log, ShaderTranslatorInterface* translator) { | 36 bool valid, const char* log, ShaderTranslatorInterface* translator) { |
13 valid_ = valid; | 37 valid_ = valid; |
14 log_info_.reset(log ? new std::string(log) : NULL); | 38 log_info_.reset(log ? new std::string(log) : NULL); |
15 if (translator && valid) { | 39 if (translator && valid) { |
16 attrib_map_ = translator->attrib_map(); | 40 attrib_map_ = translator->attrib_map(); |
17 uniform_map_ = translator->uniform_map(); | 41 uniform_map_ = translator->uniform_map(); |
18 } else { | 42 } else { |
19 attrib_map_.clear(); | 43 attrib_map_.clear(); |
20 uniform_map_.clear(); | 44 uniform_map_.clear(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 for (ShaderInfoMap::const_iterator it = shader_infos_.begin(); | 97 for (ShaderInfoMap::const_iterator it = shader_infos_.begin(); |
74 it != shader_infos_.end(); ++it) { | 98 it != shader_infos_.end(); ++it) { |
75 if (it->second->service_id() == service_id) { | 99 if (it->second->service_id() == service_id) { |
76 *client_id = it->first; | 100 *client_id = it->first; |
77 return true; | 101 return true; |
78 } | 102 } |
79 } | 103 } |
80 return false; | 104 return false; |
81 } | 105 } |
82 | 106 |
| 107 bool ShaderManager::IsOwned(ShaderManager::ShaderInfo* info) { |
| 108 for (ShaderInfoMap::iterator it = shader_infos_.begin(); |
| 109 it != shader_infos_.end(); ++it) { |
| 110 if (it->second.get() == info) { |
| 111 return true; |
| 112 } |
| 113 } |
| 114 return false; |
| 115 } |
| 116 |
83 void ShaderManager::RemoveShaderInfoIfUnused(ShaderManager::ShaderInfo* info) { | 117 void ShaderManager::RemoveShaderInfoIfUnused(ShaderManager::ShaderInfo* info) { |
84 DCHECK(info); | 118 DCHECK(info); |
| 119 DCHECK(IsOwned(info)); |
85 if (info->IsDeleted() && !info->InUse()) { | 120 if (info->IsDeleted() && !info->InUse()) { |
86 for (ShaderInfoMap::iterator it = shader_infos_.begin(); | 121 for (ShaderInfoMap::iterator it = shader_infos_.begin(); |
87 it != shader_infos_.end(); ++it) { | 122 it != shader_infos_.end(); ++it) { |
88 if (it->second->service_id() == info->service_id()) { | 123 if (it->second.get() == info) { |
89 shader_infos_.erase(it); | 124 shader_infos_.erase(it); |
90 return; | 125 return; |
91 } | 126 } |
92 } | 127 } |
93 NOTREACHED(); | 128 NOTREACHED(); |
94 } | 129 } |
95 } | 130 } |
96 | 131 |
97 void ShaderManager::MarkAsDeleted(ShaderManager::ShaderInfo* info) { | 132 void ShaderManager::MarkAsDeleted(ShaderManager::ShaderInfo* info) { |
98 DCHECK(info); | 133 DCHECK(info); |
| 134 DCHECK(IsOwned(info)); |
99 info->MarkAsDeleted(); | 135 info->MarkAsDeleted(); |
100 RemoveShaderInfoIfUnused(info); | 136 RemoveShaderInfoIfUnused(info); |
101 } | 137 } |
102 | 138 |
103 void ShaderManager::UseShader(ShaderManager::ShaderInfo* info) { | 139 void ShaderManager::UseShader(ShaderManager::ShaderInfo* info) { |
104 DCHECK(info); | 140 DCHECK(info); |
| 141 DCHECK(IsOwned(info)); |
105 info->IncUseCount(); | 142 info->IncUseCount(); |
106 } | 143 } |
107 | 144 |
108 void ShaderManager::UnuseShader(ShaderManager::ShaderInfo* info) { | 145 void ShaderManager::UnuseShader(ShaderManager::ShaderInfo* info) { |
109 DCHECK(info); | 146 DCHECK(info); |
| 147 DCHECK(IsOwned(info)); |
110 info->DecUseCount(); | 148 info->DecUseCount(); |
111 RemoveShaderInfoIfUnused(info); | 149 RemoveShaderInfoIfUnused(info); |
112 } | 150 } |
113 | 151 |
114 } // namespace gles2 | 152 } // namespace gles2 |
115 } // namespace gpu | 153 } // namespace gpu |
116 | 154 |
117 | 155 |
OLD | NEW |