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 "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 for (size_t i = 0; i < data_packs_.size(); ++i) { | 279 for (size_t i = 0; i < data_packs_.size(); ++i) { |
| 280 base::RefCountedStaticMemory* bytes = | 280 base::RefCountedStaticMemory* bytes = |
| 281 data_packs_[i]->GetStaticMemory(resource_id); | 281 data_packs_[i]->GetStaticMemory(resource_id); |
| 282 if (bytes) | 282 if (bytes) |
| 283 return bytes; | 283 return bytes; |
| 284 } | 284 } |
| 285 | 285 |
| 286 return NULL; | 286 return NULL; |
| 287 } | 287 } |
| 288 | 288 |
| 289 base::RefCountedStaticMemory* ResourceBundle::LoadImageResourceBytes( | |
| 290 int resource_id, | |
| 291 float scale_factor) const { | |
| 292 base::StringPiece data = GetRawImageResource(resource_id, scale_factor); | |
| 293 if (data.empty()) | |
| 294 return NULL; | |
| 295 | |
| 296 return new base::RefCountedStaticMemory( | |
| 297 reinterpret_cast<const unsigned char*>(data.data()), data.length()); | |
| 298 } | |
| 299 | |
| 300 base::StringPiece ResourceBundle::GetRawImageResource( | |
| 301 int resource_id, | |
| 302 float scale_factor) const { | |
| 303 base::StringPiece best_match; | |
| 304 float best_match_scale = 0; | |
| 305 for (size_t i = 0; i < data_packs_.size(); ++i) { | |
| 306 if (best_match.empty() || | |
| 307 fabs(best_match_scale - scale_factor) > | |
| 308 fabs(data_packs_[i]->GetScaleFactor() - scale_factor)) { | |
| 309 if (data_packs_[i]->GetStringPiece(resource_id, &best_match)) | |
|
sail
2012/05/09 16:09:41
Worse case this will cause StringPiece to be overw
flackr
2012/05/09 19:57:01
Done.
| |
| 310 best_match_scale = data_packs_[i]->GetScaleFactor(); | |
| 311 } | |
| 312 } | |
| 313 return best_match; | |
| 314 } | |
| 315 | |
| 289 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) const { | 316 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) const { |
| 290 DCHECK(locale_resources_data_.get()); | 317 DCHECK(locale_resources_data_.get()); |
| 291 base::StringPiece data; | 318 base::StringPiece data; |
| 292 if (locale_resources_data_->GetStringPiece(resource_id, &data)) | 319 if (locale_resources_data_->GetStringPiece(resource_id, &data)) |
| 293 return data; | 320 return data; |
| 294 | 321 |
| 295 for (size_t i = 0; i < data_packs_.size(); ++i) { | 322 for (size_t i = 0; i < data_packs_.size(); ++i) { |
| 296 if (data_packs_[i]->GetStringPiece(resource_id, &data)) | 323 if (data_packs_[i]->GetStringPiece(resource_id, &data)) |
| 297 return data; | 324 return data; |
| 298 } | 325 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 SkBitmap* bitmap = new SkBitmap(); | 433 SkBitmap* bitmap = new SkBitmap(); |
| 407 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); | 434 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); |
| 408 bitmap->allocPixels(); | 435 bitmap->allocPixels(); |
| 409 bitmap->eraseARGB(255, 255, 0, 0); | 436 bitmap->eraseARGB(255, 255, 0, 0); |
| 410 empty_image = new gfx::Image(bitmap); | 437 empty_image = new gfx::Image(bitmap); |
| 411 } | 438 } |
| 412 return empty_image; | 439 return empty_image; |
| 413 } | 440 } |
| 414 | 441 |
| 415 } // namespace ui | 442 } // namespace ui |
| OLD | NEW |