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 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 private: | 333 private: |
334 NSImage* image_; | 334 NSImage* image_; |
335 | 335 |
336 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); | 336 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); |
337 }; | 337 }; |
338 #endif // defined(OS_MACOSX) | 338 #endif // defined(OS_MACOSX) |
339 | 339 |
340 // The Storage class acts similarly to the pixels in a SkBitmap: the Image | 340 // The Storage class acts similarly to the pixels in a SkBitmap: the Image |
341 // class holds a refptr instance of Storage, which in turn holds all the | 341 // class holds a refptr instance of Storage, which in turn holds all the |
342 // ImageReps. This way, the Image can be cheaply copied. | 342 // ImageReps. This way, the Image can be cheaply copied. |
343 class ImageStorage : public base::RefCounted<ImageStorage> { | 343 class ImageStorage : public base::RefCountedThreadSafe<ImageStorage> { |
344 public: | 344 public: |
345 ImageStorage(Image::RepresentationType default_type) | 345 ImageStorage(Image::RepresentationType default_type) |
346 : default_representation_type_(default_type) | 346 : default_representation_type_(default_type) |
347 #if defined(OS_MACOSX) && !defined(OS_IOS) | 347 #if defined(OS_MACOSX) && !defined(OS_IOS) |
348 , | 348 , |
349 default_representation_color_space_( | 349 default_representation_color_space_( |
350 base::mac::GetGenericRGBColorSpace()) | 350 base::mac::GetGenericRGBColorSpace()) |
351 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 351 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
352 { | 352 { |
353 } | 353 } |
354 | 354 |
355 Image::RepresentationType default_representation_type() { | 355 Image::RepresentationType default_representation_type() { |
356 return default_representation_type_; | 356 return default_representation_type_; |
357 } | 357 } |
358 Image::RepresentationMap& representations() { return representations_; } | 358 Image::RepresentationMap& representations() { return representations_; } |
359 | 359 |
360 #if defined(OS_MACOSX) && !defined(OS_IOS) | 360 #if defined(OS_MACOSX) && !defined(OS_IOS) |
361 void set_default_representation_color_space(CGColorSpaceRef color_space) { | 361 void set_default_representation_color_space(CGColorSpaceRef color_space) { |
362 default_representation_color_space_ = color_space; | 362 default_representation_color_space_ = color_space; |
363 } | 363 } |
364 CGColorSpaceRef default_representation_color_space() { | 364 CGColorSpaceRef default_representation_color_space() { |
365 return default_representation_color_space_; | 365 return default_representation_color_space_; |
366 } | 366 } |
367 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 367 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
368 | 368 |
369 private: | 369 private: |
370 friend class base::RefCounted<ImageStorage>; | 370 friend class base::RefCountedThreadSafe<ImageStorage>; |
371 | 371 |
372 ~ImageStorage() {} | 372 ~ImageStorage() {} |
373 | 373 |
374 // The type of image that was passed to the constructor. This key will always | 374 // The type of image that was passed to the constructor. This key will always |
375 // exist in the |representations_| map. | 375 // exist in the |representations_| map. |
376 Image::RepresentationType default_representation_type_; | 376 Image::RepresentationType default_representation_type_; |
377 | 377 |
378 #if defined(OS_MACOSX) && !defined(OS_IOS) | 378 #if defined(OS_MACOSX) && !defined(OS_IOS) |
379 // The default representation's colorspace. This is used for converting to | 379 // The default representation's colorspace. This is used for converting to |
380 // NSImage. This field exists to compensate for PNGCodec not writing or | 380 // NSImage. This field exists to compensate for PNGCodec not writing or |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 storage_->representations().insert(std::make_pair(type, std::move(rep))); | 761 storage_->representations().insert(std::make_pair(type, std::move(rep))); |
762 | 762 |
763 // insert should not fail (implies that there was already a representation of | 763 // insert should not fail (implies that there was already a representation of |
764 // that type in the map). | 764 // that type in the map). |
765 CHECK(result.second) << "type was already in map."; | 765 CHECK(result.second) << "type was already in map."; |
766 | 766 |
767 return result.first->second.get(); | 767 return result.first->second.get(); |
768 } | 768 } |
769 | 769 |
770 } // namespace gfx | 770 } // namespace gfx |
OLD | NEW |