| 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 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/gfx/image/image_png_rep.h" | 13 #include "ui/gfx/image/image_png_rep.h" |
| 15 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
| 16 #include "ui/gfx/image/image_skia_source.h" | 15 #include "ui/gfx/image/image_skia_source.h" |
| 17 | 16 |
| 18 #if !defined(OS_IOS) | 17 #if !defined(OS_IOS) |
| 19 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
| 20 #endif | 19 #endif |
| 21 | 20 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); | 332 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); |
| 334 }; | 333 }; |
| 335 #endif // defined(OS_MACOSX) | 334 #endif // defined(OS_MACOSX) |
| 336 | 335 |
| 337 // The Storage class acts similarly to the pixels in a SkBitmap: the Image | 336 // The Storage class acts similarly to the pixels in a SkBitmap: the Image |
| 338 // class holds a refptr instance of Storage, which in turn holds all the | 337 // class holds a refptr instance of Storage, which in turn holds all the |
| 339 // ImageReps. This way, the Image can be cheaply copied. | 338 // ImageReps. This way, the Image can be cheaply copied. |
| 340 class ImageStorage : public base::RefCounted<ImageStorage> { | 339 class ImageStorage : public base::RefCounted<ImageStorage> { |
| 341 public: | 340 public: |
| 342 ImageStorage(Image::RepresentationType default_type) | 341 ImageStorage(Image::RepresentationType default_type) |
| 343 : default_representation_type_(default_type), | 342 : default_representation_type_(default_type) |
| 344 #if defined(OS_MACOSX) && !defined(OS_IOS) | 343 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 344 , |
| 345 default_representation_color_space_( | 345 default_representation_color_space_( |
| 346 base::mac::GetGenericRGBColorSpace()), | 346 base::mac::GetGenericRGBColorSpace()) |
| 347 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 347 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 348 representations_deleter_(&representations_) { | 348 { |
| 349 } | 349 } |
| 350 | 350 |
| 351 Image::RepresentationType default_representation_type() { | 351 Image::RepresentationType default_representation_type() { |
| 352 return default_representation_type_; | 352 return default_representation_type_; |
| 353 } | 353 } |
| 354 Image::RepresentationMap& representations() { return representations_; } | 354 Image::RepresentationMap& representations() { return representations_; } |
| 355 | 355 |
| 356 #if defined(OS_MACOSX) && !defined(OS_IOS) | 356 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 357 void set_default_representation_color_space(CGColorSpaceRef color_space) { | 357 void set_default_representation_color_space(CGColorSpaceRef color_space) { |
| 358 default_representation_color_space_ = color_space; | 358 default_representation_color_space_ = color_space; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 376 // NSImage. This field exists to compensate for PNGCodec not writing or | 376 // NSImage. This field exists to compensate for PNGCodec not writing or |
| 377 // reading colorspace ancillary chunks. (sRGB, iCCP). | 377 // reading colorspace ancillary chunks. (sRGB, iCCP). |
| 378 // Not owned. | 378 // Not owned. |
| 379 CGColorSpaceRef default_representation_color_space_; | 379 CGColorSpaceRef default_representation_color_space_; |
| 380 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 380 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 381 | 381 |
| 382 // All the representations of an Image. Size will always be at least one, with | 382 // All the representations of an Image. Size will always be at least one, with |
| 383 // more for any converted representations. | 383 // more for any converted representations. |
| 384 Image::RepresentationMap representations_; | 384 Image::RepresentationMap representations_; |
| 385 | 385 |
| 386 STLValueDeleter<Image::RepresentationMap> representations_deleter_; | |
| 387 | |
| 388 DISALLOW_COPY_AND_ASSIGN(ImageStorage); | 386 DISALLOW_COPY_AND_ASSIGN(ImageStorage); |
| 389 }; | 387 }; |
| 390 | 388 |
| 391 } // namespace internal | 389 } // namespace internal |
| 392 | 390 |
| 393 Image::Image() { | 391 Image::Image() { |
| 394 // |storage_| is NULL for empty Images. | 392 // |storage_| is NULL for empty Images. |
| 395 } | 393 } |
| 396 | 394 |
| 397 Image::Image(const std::vector<ImagePNGRep>& image_reps) { | 395 Image::Image(const std::vector<ImagePNGRep>& image_reps) { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 730 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 733 | 731 |
| 734 Image::RepresentationType Image::DefaultRepresentationType() const { | 732 Image::RepresentationType Image::DefaultRepresentationType() const { |
| 735 CHECK(storage_.get()); | 733 CHECK(storage_.get()); |
| 736 return storage_->default_representation_type(); | 734 return storage_->default_representation_type(); |
| 737 } | 735 } |
| 738 | 736 |
| 739 internal::ImageRep* Image::GetRepresentation( | 737 internal::ImageRep* Image::GetRepresentation( |
| 740 RepresentationType rep_type, bool must_exist) const { | 738 RepresentationType rep_type, bool must_exist) const { |
| 741 CHECK(storage_.get()); | 739 CHECK(storage_.get()); |
| 742 RepresentationMap::iterator it = storage_->representations().find(rep_type); | 740 RepresentationMap::const_iterator it = |
| 741 storage_->representations().find(rep_type); |
| 743 if (it == storage_->representations().end()) { | 742 if (it == storage_->representations().end()) { |
| 744 CHECK(!must_exist); | 743 CHECK(!must_exist); |
| 745 return NULL; | 744 return NULL; |
| 746 } | 745 } |
| 747 return it->second; | 746 return it->second; |
| 748 } | 747 } |
| 749 | 748 |
| 750 void Image::AddRepresentation(scoped_ptr<internal::ImageRep> rep) const { | 749 void Image::AddRepresentation(scoped_ptr<internal::ImageRep> rep) const { |
| 751 CHECK(storage_.get()); | 750 CHECK(storage_.get()); |
| 752 RepresentationType type = rep->type(); | 751 RepresentationType type = rep->type(); |
| 753 storage_->representations().insert(std::make_pair(type, rep.release())); | 752 storage_->representations().insert(type, rep.Pass()); |
| 754 } | 753 } |
| 755 | 754 |
| 756 } // namespace gfx | 755 } // namespace gfx |
| OLD | NEW |