OLD | NEW |
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/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bits.h" | 10 #include "base/bits.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 12 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
13 #include "gpu/command_buffer/service/context_state.h" | 13 #include "gpu/command_buffer/service/context_state.h" |
14 #include "gpu/command_buffer/service/error_state.h" | 14 #include "gpu/command_buffer/service/error_state.h" |
15 #include "gpu/command_buffer/service/feature_info.h" | 15 #include "gpu/command_buffer/service/feature_info.h" |
16 #include "gpu/command_buffer/service/framebuffer_manager.h" | 16 #include "gpu/command_buffer/service/framebuffer_manager.h" |
17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
18 #include "gpu/command_buffer/service/mailbox_manager.h" | 18 #include "gpu/command_buffer/service/mailbox_manager.h" |
19 #include "gpu/command_buffer/service/memory_tracking.h" | 19 #include "gpu/command_buffer/service/memory_tracking.h" |
20 | 20 |
21 namespace gpu { | 21 namespace gpu { |
22 namespace gles2 { | 22 namespace gles2 { |
23 | 23 |
| 24 // This should contain everything to uniquely identify a Texture. |
| 25 static const char TextureTag[] = "|Texture|"; |
| 26 struct TextureSignature { |
| 27 GLenum target_; |
| 28 GLint level_; |
| 29 GLenum min_filter_; |
| 30 GLenum mag_filter_; |
| 31 GLenum wrap_s_; |
| 32 GLenum wrap_t_; |
| 33 GLenum usage_; |
| 34 GLenum internal_format_; |
| 35 GLsizei width_; |
| 36 GLsizei height_; |
| 37 GLsizei depth_; |
| 38 GLint border_; |
| 39 GLenum format_; |
| 40 GLenum type_; |
| 41 bool has_image_; |
| 42 bool can_render_; |
| 43 bool can_render_to_; |
| 44 bool npot_; |
| 45 |
| 46 // Since we will be hashing this signature structure, the padding must be |
| 47 // zero initialized. Although the C++11 specifications specify that this is |
| 48 // true, we will use a constructor with a memset to further enforce it instead |
| 49 // of relying on compilers adhering to this deep dark corner specification. |
| 50 TextureSignature(GLenum target, |
| 51 GLint level, |
| 52 GLenum min_filter, |
| 53 GLenum mag_filter, |
| 54 GLenum wrap_s, |
| 55 GLenum wrap_t, |
| 56 GLenum usage, |
| 57 GLenum internal_format, |
| 58 GLsizei width, |
| 59 GLsizei height, |
| 60 GLsizei depth, |
| 61 GLint border, |
| 62 GLenum format, |
| 63 GLenum type, |
| 64 bool has_image, |
| 65 bool can_render, |
| 66 bool can_render_to, |
| 67 bool npot) { |
| 68 memset(this, 0, sizeof(TextureSignature)); |
| 69 target_ = target; |
| 70 level_ = level; |
| 71 min_filter_ = min_filter; |
| 72 mag_filter_ = mag_filter; |
| 73 wrap_s_ = wrap_s; |
| 74 wrap_t_ = wrap_t; |
| 75 usage_ = usage; |
| 76 internal_format_ = internal_format; |
| 77 width_ = width; |
| 78 height_ = height; |
| 79 depth_ = depth; |
| 80 border_ = border; |
| 81 format_ = format; |
| 82 type_ = type; |
| 83 has_image_ = has_image; |
| 84 can_render_ = can_render; |
| 85 can_render_to_ = can_render_to; |
| 86 npot_ = npot; |
| 87 } |
| 88 }; |
| 89 |
24 TextureManager::DestructionObserver::DestructionObserver() {} | 90 TextureManager::DestructionObserver::DestructionObserver() {} |
25 | 91 |
26 TextureManager::DestructionObserver::~DestructionObserver() {} | 92 TextureManager::DestructionObserver::~DestructionObserver() {} |
27 | 93 |
28 TextureManager::~TextureManager() { | 94 TextureManager::~TextureManager() { |
29 for (unsigned int i = 0; i < destruction_observers_.size(); i++) | 95 for (unsigned int i = 0; i < destruction_observers_.size(); i++) |
30 destruction_observers_[i]->OnTextureManagerDestroying(this); | 96 destruction_observers_[i]->OnTextureManagerDestroying(this); |
31 | 97 |
32 DCHECK(textures_.empty()); | 98 DCHECK(textures_.empty()); |
33 | 99 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 GLint level, | 277 GLint level, |
212 std::string* signature) const { | 278 std::string* signature) const { |
213 DCHECK(feature_info); | 279 DCHECK(feature_info); |
214 DCHECK(signature); | 280 DCHECK(signature); |
215 DCHECK_GE(level, 0); | 281 DCHECK_GE(level, 0); |
216 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 282 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
217 DCHECK_LT(static_cast<size_t>(face_index), | 283 DCHECK_LT(static_cast<size_t>(face_index), |
218 level_infos_.size()); | 284 level_infos_.size()); |
219 DCHECK_LT(static_cast<size_t>(level), | 285 DCHECK_LT(static_cast<size_t>(level), |
220 level_infos_[face_index].size()); | 286 level_infos_[face_index].size()); |
| 287 |
221 const Texture::LevelInfo& info = | 288 const Texture::LevelInfo& info = |
222 level_infos_[face_index][level]; | 289 level_infos_[face_index][level]; |
223 *signature += base::StringPrintf( | 290 |
224 "|Texture|target=%04x|level=%d|internal_format=%04x" | 291 TextureSignature signature_data(target, |
225 "|width=%d|height=%d|depth=%d|border=%d|format=%04x|type=%04x" | 292 level, |
226 "|image=%d|canrender=%d|canrenderto=%d|npot_=%d" | 293 min_filter_, |
227 "|min_filter=%04x|mag_filter=%04x|wrap_s=%04x|wrap_t=%04x" | 294 mag_filter_, |
228 "|usage=%04x", | 295 wrap_s_, |
229 target, level, info.internal_format, | 296 wrap_t_, |
230 info.width, info.height, info.depth, info.border, | 297 usage_, |
231 info.format, info.type, info.image.get() != NULL, | 298 info.internal_format, |
232 CanRender(feature_info), CanRenderTo(), npot_, | 299 info.width, |
233 min_filter_, mag_filter_, wrap_s_, wrap_t_, | 300 info.height, |
234 usage_); | 301 info.depth, |
| 302 info.border, |
| 303 info.format, |
| 304 info.type, |
| 305 info.image.get() != NULL, |
| 306 CanRender(feature_info), |
| 307 CanRenderTo(), |
| 308 npot_); |
| 309 |
| 310 signature->append(TextureTag, sizeof(TextureTag)); |
| 311 signature->append(reinterpret_cast<const char*>(&signature_data), |
| 312 sizeof(signature_data)); |
235 } | 313 } |
236 | 314 |
237 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) { | 315 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) { |
238 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); | 316 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); |
239 mailbox_manager_ = mailbox_manager; | 317 mailbox_manager_ = mailbox_manager; |
240 } | 318 } |
241 | 319 |
242 bool Texture::MarkMipmapsGenerated( | 320 bool Texture::MarkMipmapsGenerated( |
243 const FeatureInfo* feature_info) { | 321 const FeatureInfo* feature_info) { |
244 if (!CanGenerateMipmaps(feature_info)) { | 322 if (!CanGenerateMipmaps(feature_info)) { |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 | 1338 |
1261 void TextureManager::SetLevelImage( | 1339 void TextureManager::SetLevelImage( |
1262 TextureRef* ref, | 1340 TextureRef* ref, |
1263 GLenum target, | 1341 GLenum target, |
1264 GLint level, | 1342 GLint level, |
1265 gfx::GLImage* image) { | 1343 gfx::GLImage* image) { |
1266 DCHECK(ref); | 1344 DCHECK(ref); |
1267 ref->texture()->SetLevelImage(feature_info_.get(), target, level, image); | 1345 ref->texture()->SetLevelImage(feature_info_.get(), target, level, image); |
1268 } | 1346 } |
1269 | 1347 |
| 1348 size_t TextureManager::GetSignatureSize() const { |
| 1349 return sizeof(TextureTag) + sizeof(TextureSignature); |
| 1350 } |
| 1351 |
1270 void TextureManager::AddToSignature( | 1352 void TextureManager::AddToSignature( |
1271 TextureRef* ref, | 1353 TextureRef* ref, |
1272 GLenum target, | 1354 GLenum target, |
1273 GLint level, | 1355 GLint level, |
1274 std::string* signature) const { | 1356 std::string* signature) const { |
1275 ref->texture()->AddToSignature(feature_info_.get(), target, level, signature); | 1357 ref->texture()->AddToSignature(feature_info_.get(), target, level, signature); |
1276 } | 1358 } |
1277 | 1359 |
1278 void TextureManager::UpdateSafeToRenderFrom(int delta) { | 1360 void TextureManager::UpdateSafeToRenderFrom(int delta) { |
1279 num_unsafe_textures_ += delta; | 1361 num_unsafe_textures_ += delta; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 } | 1625 } |
1544 | 1626 |
1545 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 1627 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
1546 texture_state_->texture_upload_count++; | 1628 texture_state_->texture_upload_count++; |
1547 texture_state_->total_texture_upload_time += | 1629 texture_state_->total_texture_upload_time += |
1548 base::TimeTicks::HighResNow() - begin_time_; | 1630 base::TimeTicks::HighResNow() - begin_time_; |
1549 } | 1631 } |
1550 | 1632 |
1551 } // namespace gles2 | 1633 } // namespace gles2 |
1552 } // namespace gpu | 1634 } // namespace gpu |
OLD | NEW |