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 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "ui/gfx/image/image_png_rep.h" | 14 #include "ui/gfx/image/image_png_rep.h" |
14 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
16 #include "ui/gfx/image/image_skia_source.h" | |
15 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
16 | 18 |
17 #if !defined(OS_IOS) | 19 #if !defined(OS_IOS) |
18 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
19 #endif | 21 #endif |
20 | 22 |
21 #if defined(OS_IOS) | 23 #if defined(OS_IOS) |
22 #include "base/mac/foundation_util.h" | 24 #include "base/mac/foundation_util.h" |
23 #include "ui/gfx/image/image_skia_util_ios.h" | 25 #include "ui/gfx/image/image_skia_util_ios.h" |
24 #elif defined(OS_MACOSX) | 26 #elif defined(OS_MACOSX) |
25 #include "base/mac/mac_util.h" | 27 #include "base/mac/mac_util.h" |
26 #include "ui/gfx/image/image_skia_util_mac.h" | 28 #include "ui/gfx/image/image_skia_util_mac.h" |
27 #endif | 29 #endif |
28 | 30 |
29 namespace gfx { | 31 namespace gfx { |
30 | 32 |
31 namespace internal { | 33 namespace internal { |
32 | 34 |
33 #if defined(OS_IOS) | 35 #if defined(OS_IOS) |
34 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromUIImage( | 36 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromUIImage( |
35 UIImage* uiimage); | 37 UIImage* uiimage); |
36 // Caller takes ownership of the returned UIImage. | 38 // Caller takes ownership of the returned UIImage. |
37 UIImage* CreateUIImageFromPNG( | 39 UIImage* CreateUIImageFromPNG( |
38 const std::vector<gfx::ImagePNGRep>& image_png_reps); | 40 const std::vector<ImagePNGRep>& image_png_reps); |
39 gfx::Size UIImageSize(UIImage* image); | 41 gfx::Size UIImageSize(UIImage* image); |
40 #elif defined(OS_MACOSX) | 42 #elif defined(OS_MACOSX) |
41 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromNSImage( | 43 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromNSImage( |
42 NSImage* nsimage); | 44 NSImage* nsimage); |
43 // Caller takes ownership of the returned NSImage. | 45 // Caller takes ownership of the returned NSImage. |
44 NSImage* NSImageFromPNG(const std::vector<gfx::ImagePNGRep>& image_png_reps, | 46 NSImage* NSImageFromPNG(const std::vector<ImagePNGRep>& image_png_reps, |
45 CGColorSpaceRef color_space); | 47 CGColorSpaceRef color_space); |
46 gfx::Size NSImageSize(NSImage* image); | 48 gfx::Size NSImageSize(NSImage* image); |
47 #endif // defined(OS_MACOSX) | 49 #endif // defined(OS_MACOSX) |
48 | 50 |
49 #if defined(OS_IOS) | 51 #if defined(OS_IOS) |
50 ImageSkia* ImageSkiaFromPNG( | 52 ImageSkia* ImageSkiaFromPNG( |
51 const std::vector<gfx::ImagePNGRep>& image_png_reps); | 53 const std::vector<ImagePNGRep>& image_png_reps); |
52 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia( | 54 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia( |
53 const ImageSkia* skia); | 55 const ImageSkia* skia); |
54 #else | 56 #else |
55 // Returns a 16x16 red image to visually show error in decoding PNG. | 57 // Returns a 16x16 red image to visually show error in decoding PNG. |
56 // Caller takes ownership of returned ImageSkia. | 58 // Caller takes ownership of returned ImageSkia. |
57 ImageSkia* GetErrorImageSkia() { | 59 ImageSkia* GetErrorImageSkia() { |
58 SkBitmap bitmap; | 60 SkBitmap bitmap; |
59 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 61 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
60 bitmap.allocPixels(); | 62 bitmap.allocPixels(); |
61 bitmap.eraseARGB(0xff, 0xff, 0, 0); | 63 bitmap.eraseARGB(0xff, 0xff, 0, 0); |
62 return new gfx::ImageSkia(gfx::ImageSkiaRep(bitmap, 1.0f)); | 64 return new ImageSkia(ImageSkiaRep(bitmap, 1.0f)); |
63 } | 65 } |
64 | 66 |
67 class PNGImageSource : public ImageSkiaSource { | |
68 public: | |
69 PNGImageSource() {} | |
70 virtual ~PNGImageSource() {} | |
71 | |
72 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | |
73 if (image_skia_reps_.empty()) | |
74 return ImageSkiaRep(); | |
75 | |
76 const ImageSkiaRep* rep = NULL; | |
pkotwicz
2014/06/19 14:16:13
Can you please cleanup the comments. Based on the
oshima
2014/06/19 15:50:40
will do.
oshima
2014/06/19 17:15:05
Done. (your description wasn't exactly correct. pl
| |
77 for (ImageSkiaRepSet::const_iterator iter = image_skia_reps_.begin(); | |
78 iter != image_skia_reps_.end(); ++iter) { | |
79 if ((*iter).scale() == scale) | |
80 return (*iter); | |
81 // gfx::ImageSkia decides which the resource scale factor to use, | |
82 // so just pick the larger scale. | |
83 if (!rep || rep->scale() < (*iter).scale()) | |
84 rep = &(*iter); | |
85 // but if it's larger than the reuqsted scale, that's large enough. | |
86 if (rep->scale() >= scale) | |
87 break; | |
88 } | |
89 return rep ? *rep : ImageSkiaRep(); | |
90 } | |
91 | |
92 const gfx::Size size() const { | |
93 return size_; | |
94 } | |
95 | |
96 bool AddPngData(const ImagePNGRep& png_rep) { | |
97 const gfx::ImageSkiaRep rep = ToImageSkiaRep(png_rep); | |
98 if (rep.is_null()) | |
99 return false; | |
100 if (size_.IsEmpty()) | |
101 size_ = gfx::Size(rep.GetWidth(), rep.GetHeight()); | |
102 image_skia_reps_.insert(rep); | |
103 return true; | |
104 } | |
105 | |
106 static ImageSkiaRep ToImageSkiaRep(const ImagePNGRep& png_rep) { | |
107 scoped_refptr<base::RefCountedMemory> raw_data = png_rep.raw_data; | |
108 CHECK(raw_data.get()); | |
109 SkBitmap bitmap; | |
110 if (!PNGCodec::Decode(raw_data->front(), raw_data->size(), | |
111 &bitmap)) { | |
112 LOG(ERROR) << "Unable to decode PNG for " << png_rep.scale << "."; | |
113 return ImageSkiaRep(); | |
114 } | |
115 return ImageSkiaRep(bitmap, png_rep.scale); | |
116 } | |
117 | |
118 private: | |
119 struct Compare { | |
120 bool operator()(const ImageSkiaRep& rep1, const ImageSkiaRep& rep2) { | |
121 return rep1.scale() < rep2.scale(); | |
122 } | |
123 }; | |
124 | |
125 typedef std::set<ImageSkiaRep, Compare> ImageSkiaRepSet; | |
126 ImageSkiaRepSet image_skia_reps_; | |
127 gfx::Size size_; | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(PNGImageSource); | |
130 }; | |
131 | |
65 ImageSkia* ImageSkiaFromPNG( | 132 ImageSkia* ImageSkiaFromPNG( |
66 const std::vector<gfx::ImagePNGRep>& image_png_reps) { | 133 const std::vector<ImagePNGRep>& image_png_reps) { |
67 if (image_png_reps.empty()) | 134 if (image_png_reps.empty()) |
68 return GetErrorImageSkia(); | 135 return GetErrorImageSkia(); |
136 scoped_ptr<PNGImageSource> image_source(new PNGImageSource); | |
69 | 137 |
70 scoped_ptr<gfx::ImageSkia> image_skia(new ImageSkia()); | |
71 for (size_t i = 0; i < image_png_reps.size(); ++i) { | 138 for (size_t i = 0; i < image_png_reps.size(); ++i) { |
72 scoped_refptr<base::RefCountedMemory> raw_data = | 139 if (!image_source->AddPngData(image_png_reps[i])) |
73 image_png_reps[i].raw_data; | |
74 CHECK(raw_data.get()); | |
75 SkBitmap bitmap; | |
76 if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(), | |
77 &bitmap)) { | |
78 LOG(ERROR) << "Unable to decode PNG for " | |
79 << image_png_reps[i].scale | |
80 << "."; | |
81 return GetErrorImageSkia(); | 140 return GetErrorImageSkia(); |
82 } | |
83 image_skia->AddRepresentation(gfx::ImageSkiaRep( | |
84 bitmap, image_png_reps[i].scale)); | |
85 } | 141 } |
86 return image_skia.release(); | 142 const gfx::Size& size = image_source->size(); |
143 DCHECK(!size.IsEmpty()); | |
144 if (size.IsEmpty()) | |
145 return GetErrorImageSkia(); | |
146 return new ImageSkia(image_source.release(), size); | |
87 } | 147 } |
88 | 148 |
89 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia( | 149 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia( |
90 const ImageSkia* image_skia) { | 150 const ImageSkia* image_skia) { |
pkotwicz
2014/06/19 14:16:13
We should also do scaling here.
oshima
2014/06/19 15:50:40
can you explain why this is necessary?
pkotwicz
2014/06/19 21:09:09
Doing resizing going PNG->ImageSkia and ImageSkia-
oshima
2014/06/19 21:29:57
Sorry I still don't understand. This is supposed t
| |
91 ImageSkiaRep image_skia_rep = image_skia->GetRepresentation(1.0f); | 151 ImageSkiaRep image_skia_rep = image_skia->GetRepresentation(1.0f); |
92 | 152 |
93 scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes()); | 153 scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes()); |
94 if (image_skia_rep.scale() != 1.0f || | 154 if (image_skia_rep.scale() != 1.0f || |
95 !gfx::PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false, | 155 !PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false, |
96 &png_bytes->data())) { | 156 &png_bytes->data())) { |
97 return NULL; | 157 return NULL; |
98 } | 158 } |
99 return png_bytes; | 159 return png_bytes; |
100 } | 160 } |
101 #endif | 161 #endif |
102 | 162 |
103 class ImageRepPNG; | 163 class ImageRepPNG; |
104 class ImageRepSkia; | 164 class ImageRepSkia; |
105 class ImageRepCocoa; | 165 class ImageRepCocoa; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 | 355 |
296 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); | 356 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); |
297 }; | 357 }; |
298 #endif // defined(OS_MACOSX) | 358 #endif // defined(OS_MACOSX) |
299 | 359 |
300 // The Storage class acts similarly to the pixels in a SkBitmap: the Image | 360 // The Storage class acts similarly to the pixels in a SkBitmap: the Image |
301 // class holds a refptr instance of Storage, which in turn holds all the | 361 // class holds a refptr instance of Storage, which in turn holds all the |
302 // ImageReps. This way, the Image can be cheaply copied. | 362 // ImageReps. This way, the Image can be cheaply copied. |
303 class ImageStorage : public base::RefCounted<ImageStorage> { | 363 class ImageStorage : public base::RefCounted<ImageStorage> { |
304 public: | 364 public: |
305 ImageStorage(gfx::Image::RepresentationType default_type) | 365 ImageStorage(Image::RepresentationType default_type) |
306 : default_representation_type_(default_type), | 366 : default_representation_type_(default_type), |
307 #if defined(OS_MACOSX) && !defined(OS_IOS) | 367 #if defined(OS_MACOSX) && !defined(OS_IOS) |
308 default_representation_color_space_( | 368 default_representation_color_space_( |
309 base::mac::GetGenericRGBColorSpace()), | 369 base::mac::GetGenericRGBColorSpace()), |
310 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 370 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
311 representations_deleter_(&representations_) { | 371 representations_deleter_(&representations_) { |
312 } | 372 } |
313 | 373 |
314 gfx::Image::RepresentationType default_representation_type() { | 374 Image::RepresentationType default_representation_type() { |
315 return default_representation_type_; | 375 return default_representation_type_; |
316 } | 376 } |
317 gfx::Image::RepresentationMap& representations() { return representations_; } | 377 Image::RepresentationMap& representations() { return representations_; } |
318 | 378 |
319 #if defined(OS_MACOSX) && !defined(OS_IOS) | 379 #if defined(OS_MACOSX) && !defined(OS_IOS) |
320 void set_default_representation_color_space(CGColorSpaceRef color_space) { | 380 void set_default_representation_color_space(CGColorSpaceRef color_space) { |
321 default_representation_color_space_ = color_space; | 381 default_representation_color_space_ = color_space; |
322 } | 382 } |
323 CGColorSpaceRef default_representation_color_space() { | 383 CGColorSpaceRef default_representation_color_space() { |
324 return default_representation_color_space_; | 384 return default_representation_color_space_; |
325 } | 385 } |
326 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 386 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
327 | 387 |
328 private: | 388 private: |
329 friend class base::RefCounted<ImageStorage>; | 389 friend class base::RefCounted<ImageStorage>; |
330 | 390 |
331 ~ImageStorage() {} | 391 ~ImageStorage() {} |
332 | 392 |
333 // The type of image that was passed to the constructor. This key will always | 393 // The type of image that was passed to the constructor. This key will always |
334 // exist in the |representations_| map. | 394 // exist in the |representations_| map. |
335 gfx::Image::RepresentationType default_representation_type_; | 395 Image::RepresentationType default_representation_type_; |
336 | 396 |
337 #if defined(OS_MACOSX) && !defined(OS_IOS) | 397 #if defined(OS_MACOSX) && !defined(OS_IOS) |
338 // The default representation's colorspace. This is used for converting to | 398 // The default representation's colorspace. This is used for converting to |
339 // NSImage. This field exists to compensate for PNGCodec not writing or | 399 // NSImage. This field exists to compensate for PNGCodec not writing or |
340 // reading colorspace ancillary chunks. (sRGB, iCCP). | 400 // reading colorspace ancillary chunks. (sRGB, iCCP). |
341 // Not owned. | 401 // Not owned. |
342 CGColorSpaceRef default_representation_color_space_; | 402 CGColorSpaceRef default_representation_color_space_; |
343 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 403 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
344 | 404 |
345 // All the representations of an Image. Size will always be at least one, with | 405 // All the representations of an Image. Size will always be at least one, with |
346 // more for any converted representations. | 406 // more for any converted representations. |
347 gfx::Image::RepresentationMap representations_; | 407 Image::RepresentationMap representations_; |
348 | 408 |
349 STLValueDeleter<Image::RepresentationMap> representations_deleter_; | 409 STLValueDeleter<Image::RepresentationMap> representations_deleter_; |
350 | 410 |
351 DISALLOW_COPY_AND_ASSIGN(ImageStorage); | 411 DISALLOW_COPY_AND_ASSIGN(ImageStorage); |
352 }; | 412 }; |
353 | 413 |
354 } // namespace internal | 414 } // namespace internal |
355 | 415 |
356 Image::Image() { | 416 Image::Image() { |
357 // |storage_| is NULL for empty Images. | 417 // |storage_| is NULL for empty Images. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 Image& Image::operator=(const Image& other) { | 466 Image& Image::operator=(const Image& other) { |
407 storage_ = other.storage_; | 467 storage_ = other.storage_; |
408 return *this; | 468 return *this; |
409 } | 469 } |
410 | 470 |
411 Image::~Image() { | 471 Image::~Image() { |
412 } | 472 } |
413 | 473 |
414 // static | 474 // static |
415 Image Image::CreateFrom1xBitmap(const SkBitmap& bitmap) { | 475 Image Image::CreateFrom1xBitmap(const SkBitmap& bitmap) { |
416 return gfx::Image(ImageSkia::CreateFrom1xBitmap(bitmap)); | 476 return Image(ImageSkia::CreateFrom1xBitmap(bitmap)); |
417 } | 477 } |
418 | 478 |
419 // static | 479 // static |
420 Image Image::CreateFrom1xPNGBytes(const unsigned char* input, | 480 Image Image::CreateFrom1xPNGBytes(const unsigned char* input, |
421 size_t input_size) { | 481 size_t input_size) { |
422 if (input_size == 0u) | 482 if (input_size == 0u) |
423 return gfx::Image(); | 483 return Image(); |
424 | 484 |
425 scoped_refptr<base::RefCountedBytes> raw_data(new base::RefCountedBytes()); | 485 scoped_refptr<base::RefCountedBytes> raw_data(new base::RefCountedBytes()); |
426 raw_data->data().assign(input, input + input_size); | 486 raw_data->data().assign(input, input + input_size); |
427 | 487 |
428 return CreateFrom1xPNGBytes(raw_data); | 488 return CreateFrom1xPNGBytes(raw_data); |
429 } | 489 } |
430 | 490 |
431 Image Image::CreateFrom1xPNGBytes( | 491 Image Image::CreateFrom1xPNGBytes( |
432 const scoped_refptr<base::RefCountedMemory>& input) { | 492 const scoped_refptr<base::RefCountedMemory>& input) { |
433 if (!input.get() || input->size() == 0u) | 493 if (!input.get() || input->size() == 0u) |
434 return gfx::Image(); | 494 return Image(); |
435 | 495 |
436 std::vector<gfx::ImagePNGRep> image_reps; | 496 std::vector<ImagePNGRep> image_reps; |
437 image_reps.push_back(ImagePNGRep(input, 1.0f)); | 497 image_reps.push_back(ImagePNGRep(input, 1.0f)); |
438 return gfx::Image(image_reps); | 498 return Image(image_reps); |
439 } | 499 } |
440 | 500 |
441 const SkBitmap* Image::ToSkBitmap() const { | 501 const SkBitmap* Image::ToSkBitmap() const { |
442 // Possibly create and cache an intermediate ImageRepSkia. | 502 // Possibly create and cache an intermediate ImageRepSkia. |
443 return ToImageSkia()->bitmap(); | 503 return ToImageSkia()->bitmap(); |
444 } | 504 } |
445 | 505 |
446 const ImageSkia* Image::ToImageSkia() const { | 506 const ImageSkia* Image::ToImageSkia() const { |
447 internal::ImageRep* rep = GetRepresentation(kImageRepSkia, false); | 507 internal::ImageRep* rep = GetRepresentation(kImageRepSkia, false); |
448 if (!rep) { | 508 if (!rep) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 } | 603 } |
544 #endif | 604 #endif |
545 | 605 |
546 scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const { | 606 scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const { |
547 if (IsEmpty()) | 607 if (IsEmpty()) |
548 return new base::RefCountedBytes(); | 608 return new base::RefCountedBytes(); |
549 | 609 |
550 internal::ImageRep* rep = GetRepresentation(kImageRepPNG, false); | 610 internal::ImageRep* rep = GetRepresentation(kImageRepPNG, false); |
551 | 611 |
552 if (rep) { | 612 if (rep) { |
553 const std::vector<gfx::ImagePNGRep>& image_png_reps = | 613 const std::vector<ImagePNGRep>& image_png_reps = |
554 rep->AsImageRepPNG()->image_reps(); | 614 rep->AsImageRepPNG()->image_reps(); |
555 for (size_t i = 0; i < image_png_reps.size(); ++i) { | 615 for (size_t i = 0; i < image_png_reps.size(); ++i) { |
556 if (image_png_reps[i].scale == 1.0f) | 616 if (image_png_reps[i].scale == 1.0f) |
557 return image_png_reps[i].raw_data; | 617 return image_png_reps[i].raw_data; |
558 } | 618 } |
559 return new base::RefCountedBytes(); | 619 return new base::RefCountedBytes(); |
560 } | 620 } |
561 | 621 |
562 scoped_refptr<base::RefCountedMemory> png_bytes(NULL); | 622 scoped_refptr<base::RefCountedMemory> png_bytes(NULL); |
563 switch (DefaultRepresentationType()) { | 623 switch (DefaultRepresentationType()) { |
(...skipping 30 matching lines...) Expand all Loading... | |
594 return new base::RefCountedBytes(); | 654 return new base::RefCountedBytes(); |
595 } | 655 } |
596 | 656 |
597 // Do not insert representations for scale factors other than 1x even if | 657 // Do not insert representations for scale factors other than 1x even if |
598 // they are available because: | 658 // they are available because: |
599 // - Only the 1x PNG bytes can be accessed. | 659 // - Only the 1x PNG bytes can be accessed. |
600 // - ImageRepPNG is not used as an intermediate type in converting to a | 660 // - ImageRepPNG is not used as an intermediate type in converting to a |
601 // final type eg (converting from ImageRepSkia to ImageRepPNG to get an | 661 // final type eg (converting from ImageRepSkia to ImageRepPNG to get an |
602 // ImageRepCocoa). | 662 // ImageRepCocoa). |
603 std::vector<ImagePNGRep> image_png_reps; | 663 std::vector<ImagePNGRep> image_png_reps; |
604 image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f)); | 664 image_png_reps.push_back(ImagePNGRep(png_bytes, 1.0f)); |
605 rep = new internal::ImageRepPNG(image_png_reps); | 665 rep = new internal::ImageRepPNG(image_png_reps); |
606 AddRepresentation(rep); | 666 AddRepresentation(rep); |
607 return png_bytes; | 667 return png_bytes; |
608 } | 668 } |
609 | 669 |
610 SkBitmap Image::AsBitmap() const { | 670 SkBitmap Image::AsBitmap() const { |
611 return IsEmpty() ? SkBitmap() : *ToSkBitmap(); | 671 return IsEmpty() ? SkBitmap() : *ToSkBitmap(); |
612 } | 672 } |
613 | 673 |
614 ImageSkia Image::AsImageSkia() const { | 674 ImageSkia Image::AsImageSkia() const { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 return 0; | 736 return 0; |
677 return GetRepresentation(DefaultRepresentationType(), true)->Height(); | 737 return GetRepresentation(DefaultRepresentationType(), true)->Height(); |
678 } | 738 } |
679 | 739 |
680 gfx::Size Image::Size() const { | 740 gfx::Size Image::Size() const { |
681 if (IsEmpty()) | 741 if (IsEmpty()) |
682 return gfx::Size(); | 742 return gfx::Size(); |
683 return GetRepresentation(DefaultRepresentationType(), true)->Size(); | 743 return GetRepresentation(DefaultRepresentationType(), true)->Size(); |
684 } | 744 } |
685 | 745 |
686 void Image::SwapRepresentations(gfx::Image* other) { | 746 void Image::SwapRepresentations(Image* other) { |
687 storage_.swap(other->storage_); | 747 storage_.swap(other->storage_); |
688 } | 748 } |
689 | 749 |
690 #if defined(OS_MACOSX) && !defined(OS_IOS) | 750 #if defined(OS_MACOSX) && !defined(OS_IOS) |
691 void Image::SetSourceColorSpace(CGColorSpaceRef color_space) { | 751 void Image::SetSourceColorSpace(CGColorSpaceRef color_space) { |
692 if (storage_.get()) | 752 if (storage_.get()) |
693 storage_->set_default_representation_color_space(color_space); | 753 storage_->set_default_representation_color_space(color_space); |
694 } | 754 } |
695 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 755 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
696 | 756 |
(...skipping 12 matching lines...) Expand all Loading... | |
709 } | 769 } |
710 return it->second; | 770 return it->second; |
711 } | 771 } |
712 | 772 |
713 void Image::AddRepresentation(internal::ImageRep* rep) const { | 773 void Image::AddRepresentation(internal::ImageRep* rep) const { |
714 CHECK(storage_.get()); | 774 CHECK(storage_.get()); |
715 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 775 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
716 } | 776 } |
717 | 777 |
718 } // namespace gfx | 778 } // namespace gfx |
OLD | NEW |