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/gfx/image/image.h" | 5 #include "ui/gfx/image/image.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 Image::Image() { | 308 Image::Image() { |
309 // |storage_| is NULL for empty Images. | 309 // |storage_| is NULL for empty Images. |
310 } | 310 } |
311 | 311 |
312 Image::Image(const unsigned char* png, size_t input_size) | 312 Image::Image(const unsigned char* png, size_t input_size) |
313 : storage_(new internal::ImageStorage(Image::kImageRepPNG)) { | 313 : storage_(new internal::ImageStorage(Image::kImageRepPNG)) { |
314 internal::ImageRepPNG* rep = new internal::ImageRepPNG(png, input_size); | 314 internal::ImageRepPNG* rep = new internal::ImageRepPNG(png, input_size); |
315 AddRepresentation(rep); | 315 AddRepresentation(rep); |
316 } | 316 } |
317 | 317 |
318 Image::Image(const ImageSkia& image) | 318 Image::Image(const ImageSkia& image) { |
319 : storage_(new internal::ImageStorage(Image::kImageRepSkia)) { | 319 if (!image.isNull()) { |
320 internal::ImageRepSkia* rep = new internal::ImageRepSkia( | 320 storage_ = new internal::ImageStorage(Image::kImageRepSkia); |
321 new ImageSkia(image)); | 321 internal::ImageRepSkia* rep = new internal::ImageRepSkia( |
322 AddRepresentation(rep); | 322 new ImageSkia(image)); |
| 323 AddRepresentation(rep); |
| 324 } |
323 } | 325 } |
324 | 326 |
325 Image::Image(const SkBitmap& bitmap) | 327 Image::Image(const SkBitmap& bitmap) { |
326 : storage_(new internal::ImageStorage(Image::kImageRepSkia)) { | 328 if (!bitmap.empty()) { |
327 internal::ImageRepSkia* rep = | 329 storage_ = new internal::ImageStorage(Image::kImageRepSkia); |
328 new internal::ImageRepSkia(new ImageSkia(bitmap)); | 330 internal::ImageRepSkia* rep = |
329 AddRepresentation(rep); | 331 new internal::ImageRepSkia(new ImageSkia(bitmap)); |
| 332 AddRepresentation(rep); |
| 333 } |
330 } | 334 } |
331 | 335 |
332 #if defined(TOOLKIT_GTK) | 336 #if defined(TOOLKIT_GTK) |
333 Image::Image(GdkPixbuf* pixbuf) | 337 Image::Image(GdkPixbuf* pixbuf) { |
334 : storage_(new internal::ImageStorage(Image::kImageRepGdk)) { | 338 if (pixbuf) { |
335 internal::ImageRepGdk* rep = new internal::ImageRepGdk(pixbuf); | 339 storage_ = new internal::ImageStorage(Image::kImageRepGdk); |
336 AddRepresentation(rep); | 340 internal::ImageRepGdk* rep = new internal::ImageRepGdk(pixbuf); |
| 341 AddRepresentation(rep); |
| 342 } |
337 } | 343 } |
338 #endif | 344 #endif |
339 | 345 |
340 #if defined(OS_MACOSX) | 346 #if defined(OS_MACOSX) |
341 Image::Image(NSImage* image) | 347 Image::Image(NSImage* image) { |
342 : storage_(new internal::ImageStorage(Image::kImageRepCocoa)) { | 348 if (image) { |
343 internal::ImageRepCocoa* rep = new internal::ImageRepCocoa(image); | 349 storage_ = new internal::ImageStorage(Image::kImageRepCocoa); |
344 AddRepresentation(rep); | 350 internal::ImageRepCocoa* rep = new internal::ImageRepCocoa(image); |
| 351 AddRepresentation(rep); |
| 352 } |
345 } | 353 } |
346 #endif | 354 #endif |
347 | 355 |
348 Image::Image(const Image& other) : storage_(other.storage_) { | 356 Image::Image(const Image& other) : storage_(other.storage_) { |
349 } | 357 } |
350 | 358 |
351 Image& Image::operator=(const Image& other) { | 359 Image& Image::operator=(const Image& other) { |
352 storage_ = other.storage_; | 360 storage_ = other.storage_; |
353 return *this; | 361 return *this; |
354 } | 362 } |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 } | 599 } |
592 return it->second; | 600 return it->second; |
593 } | 601 } |
594 | 602 |
595 void Image::AddRepresentation(internal::ImageRep* rep) const { | 603 void Image::AddRepresentation(internal::ImageRep* rep) const { |
596 CHECK(storage_.get()); | 604 CHECK(storage_.get()); |
597 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 605 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
598 } | 606 } |
599 | 607 |
600 } // namespace gfx | 608 } // namespace gfx |
OLD | NEW |