| 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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 GetRepresentation(kImageRepCocoa, true)->AsImageRepCocoa(); | 503 GetRepresentation(kImageRepCocoa, true)->AsImageRepCocoa(); |
| 504 scoped_rep.reset(new internal::ImageRepSkia( | 504 scoped_rep.reset(new internal::ImageRepSkia( |
| 505 new ImageSkia(ImageSkiaFromNSImage(native_rep->image())))); | 505 new ImageSkia(ImageSkiaFromNSImage(native_rep->image())))); |
| 506 break; | 506 break; |
| 507 } | 507 } |
| 508 #endif | 508 #endif |
| 509 default: | 509 default: |
| 510 NOTREACHED(); | 510 NOTREACHED(); |
| 511 } | 511 } |
| 512 CHECK(scoped_rep); | 512 CHECK(scoped_rep); |
| 513 rep = scoped_rep.get(); | 513 rep = AddRepresentation(std::move(scoped_rep)); |
| 514 AddRepresentation(std::move(scoped_rep)); | |
| 515 } | 514 } |
| 516 return rep->AsImageRepSkia()->image(); | 515 return rep->AsImageRepSkia()->image(); |
| 517 } | 516 } |
| 518 | 517 |
| 519 #if defined(OS_IOS) | 518 #if defined(OS_IOS) |
| 520 UIImage* Image::ToUIImage() const { | 519 UIImage* Image::ToUIImage() const { |
| 521 internal::ImageRep* rep = GetRepresentation(kImageRepCocoaTouch, false); | 520 internal::ImageRep* rep = GetRepresentation(kImageRepCocoaTouch, false); |
| 522 if (!rep) { | 521 if (!rep) { |
| 523 scoped_ptr<internal::ImageRep> scoped_rep; | 522 scoped_ptr<internal::ImageRep> scoped_rep; |
| 524 switch (DefaultRepresentationType()) { | 523 switch (DefaultRepresentationType()) { |
| 525 case kImageRepPNG: { | 524 case kImageRepPNG: { |
| 526 internal::ImageRepPNG* png_rep = | 525 internal::ImageRepPNG* png_rep = |
| 527 GetRepresentation(kImageRepPNG, true)->AsImageRepPNG(); | 526 GetRepresentation(kImageRepPNG, true)->AsImageRepPNG(); |
| 528 scoped_rep.reset(new internal::ImageRepCocoaTouch( | 527 scoped_rep.reset(new internal::ImageRepCocoaTouch( |
| 529 internal::CreateUIImageFromPNG(png_rep->image_reps()))); | 528 internal::CreateUIImageFromPNG(png_rep->image_reps()))); |
| 530 break; | 529 break; |
| 531 } | 530 } |
| 532 case kImageRepSkia: { | 531 case kImageRepSkia: { |
| 533 internal::ImageRepSkia* skia_rep = | 532 internal::ImageRepSkia* skia_rep = |
| 534 GetRepresentation(kImageRepSkia, true)->AsImageRepSkia(); | 533 GetRepresentation(kImageRepSkia, true)->AsImageRepSkia(); |
| 535 UIImage* image = UIImageFromImageSkia(*skia_rep->image()); | 534 UIImage* image = UIImageFromImageSkia(*skia_rep->image()); |
| 536 base::mac::NSObjectRetain(image); | 535 base::mac::NSObjectRetain(image); |
| 537 scoped_rep.reset(new internal::ImageRepCocoaTouch(image)); | 536 scoped_rep.reset(new internal::ImageRepCocoaTouch(image)); |
| 538 break; | 537 break; |
| 539 } | 538 } |
| 540 default: | 539 default: |
| 541 NOTREACHED(); | 540 NOTREACHED(); |
| 542 } | 541 } |
| 543 CHECK(scoped_rep); | 542 CHECK(scoped_rep); |
| 544 rep = scoped_rep.get(); | 543 rep = AddRepresentation(std::move(scoped_rep)); |
| 545 AddRepresentation(std::move(scoped_rep)); | |
| 546 } | 544 } |
| 547 return rep->AsImageRepCocoaTouch()->image(); | 545 return rep->AsImageRepCocoaTouch()->image(); |
| 548 } | 546 } |
| 549 #elif defined(OS_MACOSX) | 547 #elif defined(OS_MACOSX) |
| 550 NSImage* Image::ToNSImage() const { | 548 NSImage* Image::ToNSImage() const { |
| 551 internal::ImageRep* rep = GetRepresentation(kImageRepCocoa, false); | 549 internal::ImageRep* rep = GetRepresentation(kImageRepCocoa, false); |
| 552 if (!rep) { | 550 if (!rep) { |
| 553 scoped_ptr<internal::ImageRep> scoped_rep; | 551 scoped_ptr<internal::ImageRep> scoped_rep; |
| 554 CGColorSpaceRef default_representation_color_space = | 552 CGColorSpaceRef default_representation_color_space = |
| 555 storage_->default_representation_color_space(); | 553 storage_->default_representation_color_space(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 568 NSImage* image = NSImageFromImageSkiaWithColorSpace(*skia_rep->image(), | 566 NSImage* image = NSImageFromImageSkiaWithColorSpace(*skia_rep->image(), |
| 569 default_representation_color_space); | 567 default_representation_color_space); |
| 570 base::mac::NSObjectRetain(image); | 568 base::mac::NSObjectRetain(image); |
| 571 scoped_rep.reset(new internal::ImageRepCocoa(image)); | 569 scoped_rep.reset(new internal::ImageRepCocoa(image)); |
| 572 break; | 570 break; |
| 573 } | 571 } |
| 574 default: | 572 default: |
| 575 NOTREACHED(); | 573 NOTREACHED(); |
| 576 } | 574 } |
| 577 CHECK(scoped_rep); | 575 CHECK(scoped_rep); |
| 578 rep = scoped_rep.get(); | 576 rep = AddRepresentation(std::move(scoped_rep)); |
| 579 AddRepresentation(std::move(scoped_rep)); | |
| 580 } | 577 } |
| 581 return rep->AsImageRepCocoa()->image(); | 578 return rep->AsImageRepCocoa()->image(); |
| 582 } | 579 } |
| 583 #endif | 580 #endif |
| 584 | 581 |
| 585 scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const { | 582 scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const { |
| 586 if (IsEmpty()) | 583 if (IsEmpty()) |
| 587 return new base::RefCountedBytes(); | 584 return new base::RefCountedBytes(); |
| 588 | 585 |
| 589 internal::ImageRep* rep = GetRepresentation(kImageRepPNG, false); | 586 internal::ImageRep* rep = GetRepresentation(kImageRepPNG, false); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 CHECK(storage_.get()); | 739 CHECK(storage_.get()); |
| 743 RepresentationMap::const_iterator it = | 740 RepresentationMap::const_iterator it = |
| 744 storage_->representations().find(rep_type); | 741 storage_->representations().find(rep_type); |
| 745 if (it == storage_->representations().end()) { | 742 if (it == storage_->representations().end()) { |
| 746 CHECK(!must_exist); | 743 CHECK(!must_exist); |
| 747 return NULL; | 744 return NULL; |
| 748 } | 745 } |
| 749 return it->second.get(); | 746 return it->second.get(); |
| 750 } | 747 } |
| 751 | 748 |
| 752 void Image::AddRepresentation(scoped_ptr<internal::ImageRep> rep) const { | 749 internal::ImageRep* Image::AddRepresentation( |
| 750 scoped_ptr<internal::ImageRep> rep) const { |
| 753 CHECK(storage_.get()); | 751 CHECK(storage_.get()); |
| 754 RepresentationType type = rep->type(); | 752 RepresentationType type = rep->type(); |
| 755 auto result = | 753 auto result = |
| 756 storage_->representations().insert(std::make_pair(type, std::move(rep))); | 754 storage_->representations().insert(std::make_pair(type, std::move(rep))); |
| 757 | 755 |
| 758 // insert should not fail (implies that there was already a representation of | 756 // insert should not fail (implies that there was already a representation of |
| 759 // that type in the map). | 757 // that type in the map). |
| 760 CHECK(result.second) << "type was already in map."; | 758 CHECK(result.second) << "type was already in map."; |
| 759 |
| 760 return result.first->second.get(); |
| 761 } | 761 } |
| 762 | 762 |
| 763 } // namespace gfx | 763 } // namespace gfx |
| OLD | NEW |