Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 // This file contains the definition of the Texture2D and TextureCUBE classes. | 33 // This file contains the definition of the Texture2D and TextureCUBE classes. |
| 34 | 34 |
| 35 #include "core/cross/precompile.h" | 35 #include "core/cross/precompile.h" |
| 36 #include "core/cross/texture.h" | 36 #include "core/cross/texture.h" |
| 37 #include "core/cross/bitmap.h" | |
| 37 #include "core/cross/renderer.h" | 38 #include "core/cross/renderer.h" |
| 39 #include "core/cross/client_info.h" | |
| 38 #include "core/cross/error.h" | 40 #include "core/cross/error.h" |
| 39 | 41 |
| 40 namespace o3d { | 42 namespace o3d { |
| 41 | 43 |
| 42 O3D_DEFN_CLASS(Texture2D, Texture); | 44 O3D_DEFN_CLASS(Texture2D, Texture); |
| 43 O3D_DEFN_CLASS(TextureCUBE, Texture); | 45 O3D_DEFN_CLASS(TextureCUBE, Texture); |
| 44 | 46 |
| 45 const char* Texture2D::kWidthParamName = | 47 const char* Texture2D::kWidthParamName = |
| 46 O3D_STRING_CONSTANT("width"); | 48 O3D_STRING_CONSTANT("width"); |
| 47 const char* Texture2D::kHeightParamName = | 49 const char* Texture2D::kHeightParamName = |
| 48 O3D_STRING_CONSTANT("height"); | 50 O3D_STRING_CONSTANT("height"); |
| 49 const char* TextureCUBE::kEdgeLengthParamName = | 51 const char* TextureCUBE::kEdgeLengthParamName = |
| 50 O3D_STRING_CONSTANT("edgeLength"); | 52 O3D_STRING_CONSTANT("edgeLength"); |
| 51 | 53 |
| 52 Texture2D::Texture2D(ServiceLocator* service_locator, | 54 Texture2D::Texture2D(ServiceLocator* service_locator, |
| 53 int width, | 55 int width, |
| 54 int height, | 56 int height, |
| 55 Format format, | 57 Format format, |
| 56 int levels, | 58 int levels, |
| 57 bool alpha_is_one, | 59 bool alpha_is_one, |
| 58 bool resize_to_pot, | 60 bool resize_to_pot, |
| 59 bool enable_render_surfaces) | 61 bool enable_render_surfaces) |
| 60 : Texture(service_locator, format, levels, alpha_is_one, | 62 : Texture(service_locator, format, levels, alpha_is_one, |
| 61 resize_to_pot, enable_render_surfaces), | 63 resize_to_pot, enable_render_surfaces), |
| 62 locked_levels_(0) { | 64 locked_levels_(0) { |
| 63 RegisterReadOnlyParamRef(kWidthParamName, &width_param_); | 65 RegisterReadOnlyParamRef(kWidthParamName, &width_param_); |
| 64 RegisterReadOnlyParamRef(kHeightParamName, &height_param_); | 66 RegisterReadOnlyParamRef(kHeightParamName, &height_param_); |
| 65 width_param_->set_read_only_value(width); | 67 width_param_->set_read_only_value(width); |
| 66 height_param_->set_read_only_value(height); | 68 height_param_->set_read_only_value(height); |
| 69 | |
| 70 ServiceDependency<ClientInfoManager> client_info_manager(service_locator); | |
|
apatrick
2009/07/09 18:22:00
Just use GetService here and below.
| |
| 71 client_info_manager->AdjustTextureMemoryUsed( | |
| 72 static_cast<int>(Bitmap::GetMipChainSize(width, height, format, levels))); | |
| 67 } | 73 } |
| 68 | 74 |
| 69 Texture2D::~Texture2D() { | 75 Texture2D::~Texture2D() { |
| 70 if (locked_levels_ != 0) { | 76 if (locked_levels_ != 0) { |
| 71 O3D_ERROR(service_locator()) | 77 O3D_ERROR(service_locator()) |
| 72 << "Texture2D \"" << name() | 78 << "Texture2D \"" << name() |
| 73 << "\" was never unlocked before being destroyed."; | 79 << "\" was never unlocked before being destroyed."; |
| 74 } | 80 } |
| 81 | |
| 82 ServiceDependency<ClientInfoManager> client_info_manager(service_locator()); | |
| 83 client_info_manager->AdjustTextureMemoryUsed( | |
| 84 -static_cast<int>(Bitmap::GetMipChainSize(width(), | |
| 85 height(), | |
| 86 format(), | |
| 87 levels()))); | |
| 75 } | 88 } |
| 76 | 89 |
| 77 ObjectBase::Ref Texture2D::Create(ServiceLocator* service_locator) { | 90 ObjectBase::Ref Texture2D::Create(ServiceLocator* service_locator) { |
| 78 return ObjectBase::Ref(); | 91 return ObjectBase::Ref(); |
| 79 } | 92 } |
| 80 | 93 |
| 81 Texture2DLockHelper::Texture2DLockHelper(Texture2D* texture, int level) | 94 Texture2DLockHelper::Texture2DLockHelper(Texture2D* texture, int level) |
| 82 : texture_(texture), | 95 : texture_(texture), |
| 83 level_(level), | 96 level_(level), |
| 84 data_(NULL), | 97 data_(NULL), |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 109 bool alpha_is_one, | 122 bool alpha_is_one, |
| 110 bool resize_to_pot, | 123 bool resize_to_pot, |
| 111 bool enable_render_surfaces) | 124 bool enable_render_surfaces) |
| 112 : Texture(service_locator, format, levels, alpha_is_one, | 125 : Texture(service_locator, format, levels, alpha_is_one, |
| 113 resize_to_pot, enable_render_surfaces) { | 126 resize_to_pot, enable_render_surfaces) { |
| 114 for (unsigned int i = 0; i < 6; ++i) { | 127 for (unsigned int i = 0; i < 6; ++i) { |
| 115 locked_levels_[i] = 0; | 128 locked_levels_[i] = 0; |
| 116 } | 129 } |
| 117 RegisterReadOnlyParamRef(kEdgeLengthParamName, &edge_length_param_); | 130 RegisterReadOnlyParamRef(kEdgeLengthParamName, &edge_length_param_); |
| 118 edge_length_param_->set_read_only_value(edge_length); | 131 edge_length_param_->set_read_only_value(edge_length); |
| 132 | |
| 133 ServiceDependency<ClientInfoManager> client_info_manager(service_locator); | |
| 134 client_info_manager->AdjustTextureMemoryUsed( | |
| 135 static_cast<int>(Bitmap::GetMipChainSize(edge_length, | |
| 136 edge_length, | |
| 137 format, | |
| 138 levels)) * 6); | |
| 119 } | 139 } |
| 120 | 140 |
| 121 TextureCUBE::~TextureCUBE() { | 141 TextureCUBE::~TextureCUBE() { |
| 122 for (unsigned int i = 0; i < 6; ++i) { | 142 for (unsigned int i = 0; i < 6; ++i) { |
| 123 if (locked_levels_[i] != 0) { | 143 if (locked_levels_[i] != 0) { |
| 124 O3D_ERROR(service_locator()) | 144 O3D_ERROR(service_locator()) |
| 125 << "TextureCUBE \"" << name() << "\" was never unlocked before" | 145 << "TextureCUBE \"" << name() << "\" was never unlocked before" |
| 126 << "being destroyed."; | 146 << "being destroyed."; |
| 127 break; // No need to report it more than once. | 147 break; // No need to report it more than once. |
| 128 } | 148 } |
| 129 } | 149 } |
| 150 | |
| 151 ServiceDependency<ClientInfoManager> client_info_manager(service_locator()); | |
| 152 client_info_manager->AdjustTextureMemoryUsed( | |
| 153 -static_cast<int>(Bitmap::GetMipChainSize(edge_length(), | |
| 154 edge_length(), | |
| 155 format(), | |
| 156 levels()) * 6)); | |
| 130 } | 157 } |
| 131 | 158 |
| 132 ObjectBase::Ref TextureCUBE::Create(ServiceLocator* service_locator) { | 159 ObjectBase::Ref TextureCUBE::Create(ServiceLocator* service_locator) { |
| 133 return ObjectBase::Ref(); | 160 return ObjectBase::Ref(); |
| 134 } | 161 } |
| 135 | 162 |
| 136 } // namespace o3d | 163 } // namespace o3d |
| OLD | NEW |