Chromium Code Reviews| 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/image_manager.h" | 5 #include "gpu/command_buffer/service/image_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 7 #include "ui/gl/gl_image.h" | 8 #include "ui/gl/gl_image.h" |
| 8 | 9 |
| 9 namespace gpu { | 10 namespace gpu { |
| 10 namespace gles2 { | 11 namespace gles2 { |
| 11 | 12 |
| 12 ImageManager::ImageManager() { | 13 ImageManager::ImageManager() { |
| 13 } | 14 } |
| 14 | 15 |
| 15 ImageManager::~ImageManager() { | 16 ImageManager::~ImageManager() { |
| 16 } | 17 } |
| 17 | 18 |
| 19 void ImageManager::Destroy(bool have_context) { | |
| 20 for (GLImageMap::const_iterator iter = images_.begin(); iter != images_.end(); | |
| 21 ++iter) | |
| 22 iter->second.get()->Destroy(have_context); | |
| 23 images_.clear(); | |
| 24 } | |
| 25 | |
| 18 void ImageManager::AddImage(gfx::GLImage* image, int32 service_id) { | 26 void ImageManager::AddImage(gfx::GLImage* image, int32 service_id) { |
| 19 images_[service_id] = image; | 27 images_[service_id] = image; |
|
reveman
2014/07/24 16:22:03
This could drop a GLImage reference without callin
sohanjg
2014/07/25 10:54:21
Done.
| |
| 20 } | 28 } |
| 21 | 29 |
| 22 void ImageManager::RemoveImage(int32 service_id) { | 30 void ImageManager::RemoveImage(int32 service_id) { |
|
reveman
2014/07/24 16:22:03
In light of the my comment below, this function sh
sohanjg
2014/07/25 10:54:21
Done.
| |
| 23 images_.erase(service_id); | 31 if (service_id <= 0) { |
| 32 LOG(ERROR) << "Cannot remove image with non-positive ID."; | |
| 33 return; | |
| 34 } | |
| 35 GLImageMap::iterator iter = images_.find(service_id); | |
| 36 if (iter == images_.end()) { | |
| 37 LOG(ERROR) << "Invalid ID."; | |
| 38 return; | |
| 39 } | |
| 40 iter->second.get()->Destroy(true); | |
| 41 images_.erase(iter); | |
| 24 } | 42 } |
| 25 | 43 |
| 26 gfx::GLImage* ImageManager::LookupImage(int32 service_id) { | 44 gfx::GLImage* ImageManager::LookupImage(int32 service_id) { |
| 27 GLImageMap::const_iterator iter = images_.find(service_id); | 45 GLImageMap::const_iterator iter = images_.find(service_id); |
| 28 if (iter != images_.end()) | 46 if (iter != images_.end()) |
| 29 return iter->second.get(); | 47 return iter->second.get(); |
| 30 | 48 |
| 31 return NULL; | 49 return NULL; |
| 32 } | 50 } |
| 33 | 51 |
| 34 } // namespace gles2 | 52 } // namespace gles2 |
| 35 } // namespace gpu | 53 } // namespace gpu |
| OLD | NEW |