| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // This file contains the implementation of ResourceMapBase. | 33 // This file contains the implementation of ResourceMapBase. |
| 34 | 34 |
| 35 #include "command_buffer/service/cross/resource.h" | 35 #include "command_buffer/service/cross/resource.h" |
| 36 | 36 |
| 37 namespace o3d { | 37 namespace o3d { |
| 38 namespace command_buffer { | 38 namespace command_buffer { |
| 39 | 39 |
| 40 // Assigns a resource to a resource ID, by setting it at the right location | 40 // Assigns a resource to a resource ID, by setting it at the right location |
| 41 // into the list, resizing the list if necessary, and destroying an existing | 41 // into the list, resizing the list if necessary, and destroying an existing |
| 42 // resource if one existed already. | 42 // resource if one existed already. |
| 43 void ResourceMapBase::Assign(ResourceID id, Resource *resource) { | 43 void ResourceMapBase::Assign(ResourceId id, Resource *resource) { |
| 44 if (id >= resources_.size()) { | 44 if (id >= resources_.size()) { |
| 45 resources_.resize(id + 1, NULL); | 45 resources_.resize(id + 1, NULL); |
| 46 } else { | 46 } else { |
| 47 Resource *&entry = resources_[id]; | 47 Resource *&entry = resources_[id]; |
| 48 if (entry) { | 48 if (entry) { |
| 49 delete entry; | 49 delete entry; |
| 50 entry = NULL; | 50 entry = NULL; |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 DCHECK(resources_[id] == NULL); | 53 DCHECK(resources_[id] == NULL); |
| 54 resources_[id] = resource; | 54 resources_[id] = resource; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Destroys a resource contained in the map, setting its entry to NULL. If | 57 // Destroys a resource contained in the map, setting its entry to NULL. If |
| 58 // necessary, this will trim the list. | 58 // necessary, this will trim the list. |
| 59 bool ResourceMapBase::Destroy(ResourceID id) { | 59 bool ResourceMapBase::Destroy(ResourceId id) { |
| 60 if (id >= resources_.size()) { | 60 if (id >= resources_.size()) { |
| 61 return false; | 61 return false; |
| 62 } | 62 } |
| 63 Resource *&entry = resources_[id]; | 63 Resource *&entry = resources_[id]; |
| 64 if (entry) { | 64 if (entry) { |
| 65 delete entry; | 65 delete entry; |
| 66 entry = NULL; | 66 entry = NULL; |
| 67 | 67 |
| 68 // Removing the last element, we can trim the list. | 68 // Removing the last element, we can trim the list. |
| 69 // TODO: this may not be optimal to do every time. Investigate if it | 69 // TODO: this may not be optimal to do every time. Investigate if it |
| (...skipping 23 matching lines...) Expand all Loading... |
| 93 for (Container::iterator i = resources_.begin(); i != resources_.end(); ++i) { | 93 for (Container::iterator i = resources_.begin(); i != resources_.end(); ++i) { |
| 94 if (*i) { | 94 if (*i) { |
| 95 delete *i; | 95 delete *i; |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 resources_.clear(); | 98 resources_.clear(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace command_buffer | 101 } // namespace command_buffer |
| 102 } // namespace o3d | 102 } // namespace o3d |
| OLD | NEW |