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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 default_textures_[ii] = NULL; | 346 default_textures_[ii] = NULL; |
347 } | 347 } |
348 | 348 |
349 if (have_context) { | 349 if (have_context) { |
350 glDeleteTextures(arraysize(black_texture_ids_), black_texture_ids_); | 350 glDeleteTextures(arraysize(black_texture_ids_), black_texture_ids_); |
351 } | 351 } |
352 | 352 |
353 DCHECK_EQ(0u, memory_type_tracker_->GetMemRepresented()); | 353 DCHECK_EQ(0u, memory_type_tracker_->GetMemRepresented()); |
354 } | 354 } |
355 | 355 |
| 356 TextureBase::TextureBase(GLuint service_id) |
| 357 : service_id_(service_id), mailbox_manager_(nullptr) {} |
| 358 |
| 359 TextureBase::~TextureBase() { |
| 360 DCHECK_EQ(nullptr, mailbox_manager_); |
| 361 } |
| 362 |
| 363 void TextureBase::DeleteFromMailboxManager() { |
| 364 if (mailbox_manager_) { |
| 365 mailbox_manager_->TextureDeleted(this); |
| 366 mailbox_manager_ = nullptr; |
| 367 } |
| 368 } |
| 369 |
| 370 void TextureBase::SetMailboxManager(MailboxManager* mailbox_manager) { |
| 371 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); |
| 372 mailbox_manager_ = mailbox_manager; |
| 373 } |
| 374 |
356 Texture::Texture(GLuint service_id) | 375 Texture::Texture(GLuint service_id) |
357 : mailbox_manager_(NULL), | 376 : TextureBase(service_id), |
358 memory_tracking_ref_(NULL), | 377 memory_tracking_ref_(NULL), |
359 service_id_(service_id), | |
360 owned_service_id_(service_id), | 378 owned_service_id_(service_id), |
361 cleared_(true), | 379 cleared_(true), |
362 num_uncleared_mips_(0), | 380 num_uncleared_mips_(0), |
363 num_npot_faces_(0), | 381 num_npot_faces_(0), |
364 target_(0), | 382 target_(0), |
365 usage_(GL_NONE), | 383 usage_(GL_NONE), |
366 base_level_(0), | 384 base_level_(0), |
367 max_level_(1000), | 385 max_level_(1000), |
368 swizzle_r_(GL_RED), | 386 swizzle_r_(GL_RED), |
369 swizzle_g_(GL_GREEN), | 387 swizzle_g_(GL_GREEN), |
370 swizzle_b_(GL_BLUE), | 388 swizzle_b_(GL_BLUE), |
371 swizzle_a_(GL_ALPHA), | 389 swizzle_a_(GL_ALPHA), |
372 max_level_set_(-1), | 390 max_level_set_(-1), |
373 texture_complete_(false), | 391 texture_complete_(false), |
374 texture_mips_dirty_(false), | 392 texture_mips_dirty_(false), |
375 cube_complete_(false), | 393 cube_complete_(false), |
376 npot_(false), | 394 npot_(false), |
377 has_been_bound_(false), | 395 has_been_bound_(false), |
378 framebuffer_attachment_count_(0), | 396 framebuffer_attachment_count_(0), |
379 immutable_(false), | 397 immutable_(false), |
380 has_images_(false), | 398 has_images_(false), |
381 estimated_size_(0), | 399 estimated_size_(0), |
382 can_render_condition_(CAN_RENDER_ALWAYS), | 400 can_render_condition_(CAN_RENDER_ALWAYS), |
383 texture_max_anisotropy_initialized_(false), | 401 texture_max_anisotropy_initialized_(false), |
384 compatibility_swizzle_(nullptr), | 402 compatibility_swizzle_(nullptr), |
385 emulating_rgb_(false) {} | 403 emulating_rgb_(false) {} |
386 | 404 |
387 Texture::~Texture() { | 405 Texture::~Texture() { |
388 if (mailbox_manager_) | 406 DeleteFromMailboxManager(); |
389 mailbox_manager_->TextureDeleted(this); | |
390 } | 407 } |
391 | 408 |
392 void Texture::AddTextureRef(TextureRef* ref) { | 409 void Texture::AddTextureRef(TextureRef* ref) { |
393 DCHECK(refs_.find(ref) == refs_.end()); | 410 DCHECK(refs_.find(ref) == refs_.end()); |
394 refs_.insert(ref); | 411 refs_.insert(ref); |
395 if (!memory_tracking_ref_) { | 412 if (!memory_tracking_ref_) { |
396 memory_tracking_ref_ = ref; | 413 memory_tracking_ref_ = ref; |
397 GetMemTracker()->TrackMemAlloc(estimated_size()); | 414 GetMemTracker()->TrackMemAlloc(estimated_size()); |
398 } | 415 } |
399 } | 416 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 CanRender(feature_info), | 611 CanRender(feature_info), |
595 CanRenderTo(feature_info, level), | 612 CanRenderTo(feature_info, level), |
596 npot_, | 613 npot_, |
597 emulating_rgb_); | 614 emulating_rgb_); |
598 | 615 |
599 signature->append(TextureTag, sizeof(TextureTag)); | 616 signature->append(TextureTag, sizeof(TextureTag)); |
600 signature->append(reinterpret_cast<const char*>(&signature_data), | 617 signature->append(reinterpret_cast<const char*>(&signature_data), |
601 sizeof(signature_data)); | 618 sizeof(signature_data)); |
602 } | 619 } |
603 | 620 |
604 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) { | |
605 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); | |
606 mailbox_manager_ = mailbox_manager; | |
607 } | |
608 | |
609 void Texture::MarkMipmapsGenerated() { | 621 void Texture::MarkMipmapsGenerated() { |
610 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 622 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
611 const Texture::FaceInfo& face_info = face_infos_[ii]; | 623 const Texture::FaceInfo& face_info = face_infos_[ii]; |
612 const Texture::LevelInfo& level0_info = face_info.level_infos[base_level_]; | 624 const Texture::LevelInfo& level0_info = face_info.level_infos[base_level_]; |
613 GLsizei width = level0_info.width; | 625 GLsizei width = level0_info.width; |
614 GLsizei height = level0_info.height; | 626 GLsizei height = level0_info.height; |
615 GLsizei depth = level0_info.depth; | 627 GLsizei depth = level0_info.depth; |
616 GLenum target = target_ == GL_TEXTURE_CUBE_MAP ? | 628 GLenum target = target_ == GL_TEXTURE_CUBE_MAP ? |
617 GLES2Util::IndexToGLFaceTarget(ii) : target_; | 629 GLES2Util::IndexToGLFaceTarget(ii) : target_; |
618 | 630 |
(...skipping 2764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3383 uint32_t TextureManager::GetServiceIdGeneration() const { | 3395 uint32_t TextureManager::GetServiceIdGeneration() const { |
3384 return current_service_id_generation_; | 3396 return current_service_id_generation_; |
3385 } | 3397 } |
3386 | 3398 |
3387 void TextureManager::IncrementServiceIdGeneration() { | 3399 void TextureManager::IncrementServiceIdGeneration() { |
3388 current_service_id_generation_++; | 3400 current_service_id_generation_++; |
3389 } | 3401 } |
3390 | 3402 |
3391 } // namespace gles2 | 3403 } // namespace gles2 |
3392 } // namespace gpu | 3404 } // namespace gpu |
OLD | NEW |