| 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" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 private: | 331 private: |
| 332 NSImage* image_; | 332 NSImage* image_; |
| 333 | 333 |
| 334 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); | 334 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); |
| 335 }; | 335 }; |
| 336 #endif // defined(OS_MACOSX) | 336 #endif // defined(OS_MACOSX) |
| 337 | 337 |
| 338 // The Storage class acts similarly to the pixels in a SkBitmap: the Image | 338 // The Storage class acts similarly to the pixels in a SkBitmap: the Image |
| 339 // class holds a refptr instance of Storage, which in turn holds all the | 339 // class holds a refptr instance of Storage, which in turn holds all the |
| 340 // ImageReps. This way, the Image can be cheaply copied. | 340 // ImageReps. This way, the Image can be cheaply copied. |
| 341 class ImageStorage : public base::RefCounted<ImageStorage> { | 341 // TODO(mgiuca): Avoid using UnsafeRefCounted. http://crbug.com/469952. |
| 342 class ImageStorage : public base::UnsafeRefCounted<ImageStorage> { |
| 342 public: | 343 public: |
| 343 ImageStorage(Image::RepresentationType default_type) | 344 ImageStorage(Image::RepresentationType default_type) |
| 344 : default_representation_type_(default_type), | 345 : default_representation_type_(default_type), |
| 345 #if defined(OS_MACOSX) && !defined(OS_IOS) | 346 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 346 default_representation_color_space_( | 347 default_representation_color_space_( |
| 347 base::mac::GetGenericRGBColorSpace()), | 348 base::mac::GetGenericRGBColorSpace()), |
| 348 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 349 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 349 representations_deleter_(&representations_) { | 350 representations_deleter_(&representations_) { |
| 350 } | 351 } |
| 351 | 352 |
| 352 Image::RepresentationType default_representation_type() { | 353 Image::RepresentationType default_representation_type() { |
| 353 return default_representation_type_; | 354 return default_representation_type_; |
| 354 } | 355 } |
| 355 Image::RepresentationMap& representations() { return representations_; } | 356 Image::RepresentationMap& representations() { return representations_; } |
| 356 | 357 |
| 357 #if defined(OS_MACOSX) && !defined(OS_IOS) | 358 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 358 void set_default_representation_color_space(CGColorSpaceRef color_space) { | 359 void set_default_representation_color_space(CGColorSpaceRef color_space) { |
| 359 default_representation_color_space_ = color_space; | 360 default_representation_color_space_ = color_space; |
| 360 } | 361 } |
| 361 CGColorSpaceRef default_representation_color_space() { | 362 CGColorSpaceRef default_representation_color_space() { |
| 362 return default_representation_color_space_; | 363 return default_representation_color_space_; |
| 363 } | 364 } |
| 364 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 365 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 365 | 366 |
| 366 private: | 367 private: |
| 367 friend class base::RefCounted<ImageStorage>; | 368 friend class base::UnsafeRefCounted<ImageStorage>; |
| 368 | 369 |
| 369 ~ImageStorage() {} | 370 ~ImageStorage() {} |
| 370 | 371 |
| 371 // The type of image that was passed to the constructor. This key will always | 372 // The type of image that was passed to the constructor. This key will always |
| 372 // exist in the |representations_| map. | 373 // exist in the |representations_| map. |
| 373 Image::RepresentationType default_representation_type_; | 374 Image::RepresentationType default_representation_type_; |
| 374 | 375 |
| 375 #if defined(OS_MACOSX) && !defined(OS_IOS) | 376 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 376 // The default representation's colorspace. This is used for converting to | 377 // The default representation's colorspace. This is used for converting to |
| 377 // NSImage. This field exists to compensate for PNGCodec not writing or | 378 // NSImage. This field exists to compensate for PNGCodec not writing or |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 748 } |
| 748 return it->second; | 749 return it->second; |
| 749 } | 750 } |
| 750 | 751 |
| 751 void Image::AddRepresentation(internal::ImageRep* rep) const { | 752 void Image::AddRepresentation(internal::ImageRep* rep) const { |
| 752 CHECK(storage_.get()); | 753 CHECK(storage_.get()); |
| 753 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 754 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
| 754 } | 755 } |
| 755 | 756 |
| 756 } // namespace gfx | 757 } // namespace gfx |
| OLD | NEW |