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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 !gfx::PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false, | 95 !gfx::PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false, |
96 &png_bytes->data())) { | 96 &png_bytes->data())) { |
97 return NULL; | 97 return NULL; |
98 } | 98 } |
99 return png_bytes; | 99 return png_bytes; |
100 } | 100 } |
101 #endif | 101 #endif |
102 | 102 |
103 class ImageRepPNG; | 103 class ImageRepPNG; |
104 class ImageRepSkia; | 104 class ImageRepSkia; |
105 class ImageRepGdk; | |
106 class ImageRepCocoa; | 105 class ImageRepCocoa; |
107 class ImageRepCocoaTouch; | 106 class ImageRepCocoaTouch; |
108 | 107 |
109 // An ImageRep is the object that holds the backing memory for an Image. Each | 108 // An ImageRep is the object that holds the backing memory for an Image. Each |
110 // RepresentationType has an ImageRep subclass that is responsible for freeing | 109 // RepresentationType has an ImageRep subclass that is responsible for freeing |
111 // the memory that the ImageRep holds. When an ImageRep is created, it expects | 110 // the memory that the ImageRep holds. When an ImageRep is created, it expects |
112 // to take ownership of the image, without having to retain it or increase its | 111 // to take ownership of the image, without having to retain it or increase its |
113 // reference count. | 112 // reference count. |
114 class ImageRep { | 113 class ImageRep { |
115 public: | 114 public: |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 689 |
691 #if defined(OS_MACOSX) && !defined(OS_IOS) | 690 #if defined(OS_MACOSX) && !defined(OS_IOS) |
692 void Image::SetSourceColorSpace(CGColorSpaceRef color_space) { | 691 void Image::SetSourceColorSpace(CGColorSpaceRef color_space) { |
693 if (storage_.get()) | 692 if (storage_.get()) |
694 storage_->set_default_representation_color_space(color_space); | 693 storage_->set_default_representation_color_space(color_space); |
695 } | 694 } |
696 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 695 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
697 | 696 |
698 Image::RepresentationType Image::DefaultRepresentationType() const { | 697 Image::RepresentationType Image::DefaultRepresentationType() const { |
699 CHECK(storage_.get()); | 698 CHECK(storage_.get()); |
700 RepresentationType default_type = storage_->default_representation_type(); | 699 return storage_->default_representation_type(); |
701 // The conversions above assume that the default representation type is never | |
702 // kImageRepCairo. | |
703 DCHECK_NE(default_type, kImageRepCairo); | |
704 return default_type; | |
705 } | 700 } |
706 | 701 |
707 internal::ImageRep* Image::GetRepresentation( | 702 internal::ImageRep* Image::GetRepresentation( |
708 RepresentationType rep_type, bool must_exist) const { | 703 RepresentationType rep_type, bool must_exist) const { |
709 CHECK(storage_.get()); | 704 CHECK(storage_.get()); |
710 RepresentationMap::iterator it = storage_->representations().find(rep_type); | 705 RepresentationMap::iterator it = storage_->representations().find(rep_type); |
711 if (it == storage_->representations().end()) { | 706 if (it == storage_->representations().end()) { |
712 CHECK(!must_exist); | 707 CHECK(!must_exist); |
713 return NULL; | 708 return NULL; |
714 } | 709 } |
715 return it->second; | 710 return it->second; |
716 } | 711 } |
717 | 712 |
718 void Image::AddRepresentation(internal::ImageRep* rep) const { | 713 void Image::AddRepresentation(internal::ImageRep* rep) const { |
719 CHECK(storage_.get()); | 714 CHECK(storage_.get()); |
720 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 715 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
721 } | 716 } |
722 | 717 |
723 } // namespace gfx | 718 } // namespace gfx |
OLD | NEW |