| 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" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "ui/gfx/codec/png_codec.h" | |
| 13 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
| 14 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 15 | 14 |
| 15 #if !defined(OS_IOS) |
| 16 #include "ui/gfx/codec/png_codec.h" |
| 17 #endif |
| 18 |
| 16 #if defined(TOOLKIT_GTK) | 19 #if defined(TOOLKIT_GTK) |
| 17 #include <gdk-pixbuf/gdk-pixbuf.h> | 20 #include <gdk-pixbuf/gdk-pixbuf.h> |
| 18 #include <gdk/gdk.h> | 21 #include <gdk/gdk.h> |
| 19 #include <glib-object.h> | 22 #include <glib-object.h> |
| 20 #include "ui/base/gtk/scoped_gobject.h" | 23 #include "ui/base/gtk/scoped_gobject.h" |
| 21 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/gtk_util.h" | 25 #include "ui/gfx/gtk_util.h" |
| 23 #include "ui/gfx/image/cairo_cached_surface.h" | 26 #include "ui/gfx/image/cairo_cached_surface.h" |
| 27 #elif defined(OS_IOS) |
| 28 #include "base/mac/foundation_util.h" |
| 29 #include "ui/gfx/image/image_skia_util_ios.h" |
| 24 #elif defined(OS_MACOSX) | 30 #elif defined(OS_MACOSX) |
| 25 #include "base/mac/mac_util.h" | 31 #include "base/mac/mac_util.h" |
| 26 #include "ui/gfx/image/image_skia_util_mac.h" | 32 #include "ui/gfx/image/image_skia_util_mac.h" |
| 27 #endif | 33 #endif |
| 28 | 34 |
| 29 namespace gfx { | 35 namespace gfx { |
| 30 | 36 |
| 31 namespace internal { | 37 namespace internal { |
| 32 | 38 |
| 33 #if defined(TOOLKIT_GTK) | 39 #if defined(TOOLKIT_GTK) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 gsize image_size; | 83 gsize image_size; |
| 78 GError* error = NULL; | 84 GError* error = NULL; |
| 79 CHECK(gdk_pixbuf_save_to_buffer( | 85 CHECK(gdk_pixbuf_save_to_buffer( |
| 80 pixbuf, &image, &image_size, "png", &error, NULL)); | 86 pixbuf, &image, &image_size, "png", &error, NULL)); |
| 81 png->assign(image, image + image_size); | 87 png->assign(image, image + image_size); |
| 82 g_free(image); | 88 g_free(image); |
| 83 } | 89 } |
| 84 | 90 |
| 85 #endif // defined(TOOLKIT_GTK) | 91 #endif // defined(TOOLKIT_GTK) |
| 86 | 92 |
| 87 #if defined(OS_MACOSX) | 93 #if defined(OS_IOS) |
| 94 void PNGFromUIImage(UIImage* nsimage, std::vector<unsigned char>* png); |
| 95 UIImage* CreateUIImageFromPNG(const std::vector<unsigned char>& png); |
| 96 #elif defined(OS_MACOSX) |
| 88 void PNGFromNSImage(NSImage* nsimage, std::vector<unsigned char>* png); | 97 void PNGFromNSImage(NSImage* nsimage, std::vector<unsigned char>* png); |
| 89 NSImage* NSImageFromPNG(const std::vector<unsigned char>& png); | 98 NSImage* NSImageFromPNG(const std::vector<unsigned char>& png); |
| 90 #endif // defined(OS_MACOSX) | 99 #endif // defined(OS_MACOSX) |
| 91 | 100 |
| 101 #if defined(OS_IOS) |
| 102 ImageSkia* ImageSkiaFromPNG(const std::vector<unsigned char>& png); |
| 103 void PNGFromImageSkia(const ImageSkia* skia, std::vector<unsigned char>* png); |
| 104 #else |
| 92 ImageSkia* ImageSkiaFromPNG(const std::vector<unsigned char>& png) { | 105 ImageSkia* ImageSkiaFromPNG(const std::vector<unsigned char>& png) { |
| 93 SkBitmap bitmap; | 106 SkBitmap bitmap; |
| 94 if (!gfx::PNGCodec::Decode(&png.front(), png.size(), &bitmap)) { | 107 if (!gfx::PNGCodec::Decode(&png.front(), png.size(), &bitmap)) { |
| 95 LOG(WARNING) << "Unable to decode PNG."; | 108 LOG(WARNING) << "Unable to decode PNG."; |
| 96 // Return a 16x16 red image to visually show error. | 109 // Return a 16x16 red image to visually show error. |
| 97 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 110 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
| 98 bitmap.allocPixels(); | 111 bitmap.allocPixels(); |
| 99 bitmap.eraseRGB(0xff, 0, 0); | 112 bitmap.eraseRGB(0xff, 0, 0); |
| 100 } | 113 } |
| 101 return new ImageSkia(bitmap); | 114 return new ImageSkia(bitmap); |
| 102 } | 115 } |
| 103 | 116 |
| 104 void PNGFromImageSkia(const ImageSkia* skia, std::vector<unsigned char>* png) { | 117 void PNGFromImageSkia(const ImageSkia* skia, std::vector<unsigned char>* png) { |
| 105 CHECK(gfx::PNGCodec::EncodeBGRASkBitmap(*skia->bitmap(), false, png)); | 118 CHECK(gfx::PNGCodec::EncodeBGRASkBitmap(*skia->bitmap(), false, png)); |
| 106 } | 119 } |
| 120 #endif |
| 107 | 121 |
| 108 class ImageRepPNG; | 122 class ImageRepPNG; |
| 109 class ImageRepSkia; | 123 class ImageRepSkia; |
| 110 class ImageRepGdk; | 124 class ImageRepGdk; |
| 111 class ImageRepCairo; | 125 class ImageRepCairo; |
| 112 class ImageRepCocoa; | 126 class ImageRepCocoa; |
| 127 class ImageRepCocoaTouch; |
| 113 | 128 |
| 114 // An ImageRep is the object that holds the backing memory for an Image. Each | 129 // An ImageRep is the object that holds the backing memory for an Image. Each |
| 115 // RepresentationType has an ImageRep subclass that is responsible for freeing | 130 // RepresentationType has an ImageRep subclass that is responsible for freeing |
| 116 // the memory that the ImageRep holds. When an ImageRep is created, it expects | 131 // the memory that the ImageRep holds. When an ImageRep is created, it expects |
| 117 // to take ownership of the image, without having to retain it or increase its | 132 // to take ownership of the image, without having to retain it or increase its |
| 118 // reference count. | 133 // reference count. |
| 119 class ImageRep { | 134 class ImageRep { |
| 120 public: | 135 public: |
| 121 explicit ImageRep(Image::RepresentationType rep) : type_(rep) {} | 136 explicit ImageRep(Image::RepresentationType rep) : type_(rep) {} |
| 122 | 137 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 139 CHECK_EQ(type_, Image::kImageRepGdk); | 154 CHECK_EQ(type_, Image::kImageRepGdk); |
| 140 return reinterpret_cast<ImageRepGdk*>(this); | 155 return reinterpret_cast<ImageRepGdk*>(this); |
| 141 } | 156 } |
| 142 | 157 |
| 143 ImageRepCairo* AsImageRepCairo() { | 158 ImageRepCairo* AsImageRepCairo() { |
| 144 CHECK_EQ(type_, Image::kImageRepCairo); | 159 CHECK_EQ(type_, Image::kImageRepCairo); |
| 145 return reinterpret_cast<ImageRepCairo*>(this); | 160 return reinterpret_cast<ImageRepCairo*>(this); |
| 146 } | 161 } |
| 147 #endif | 162 #endif |
| 148 | 163 |
| 149 #if defined(OS_MACOSX) | 164 #if defined(OS_IOS) |
| 165 ImageRepCocoaTouch* AsImageRepCocoaTouch() { |
| 166 CHECK_EQ(type_, Image::kImageRepCocoaTouch); |
| 167 return reinterpret_cast<ImageRepCocoaTouch*>(this); |
| 168 } |
| 169 #elif defined(OS_MACOSX) |
| 150 ImageRepCocoa* AsImageRepCocoa() { | 170 ImageRepCocoa* AsImageRepCocoa() { |
| 151 CHECK_EQ(type_, Image::kImageRepCocoa); | 171 CHECK_EQ(type_, Image::kImageRepCocoa); |
| 152 return reinterpret_cast<ImageRepCocoa*>(this); | 172 return reinterpret_cast<ImageRepCocoa*>(this); |
| 153 } | 173 } |
| 154 #endif | 174 #endif |
| 155 | 175 |
| 156 Image::RepresentationType type() const { return type_; } | 176 Image::RepresentationType type() const { return type_; } |
| 157 | 177 |
| 158 private: | 178 private: |
| 159 Image::RepresentationType type_; | 179 Image::RepresentationType type_; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 258 |
| 239 CairoCachedSurface* surface() const { return cairo_cache_; } | 259 CairoCachedSurface* surface() const { return cairo_cache_; } |
| 240 | 260 |
| 241 private: | 261 private: |
| 242 CairoCachedSurface* cairo_cache_; | 262 CairoCachedSurface* cairo_cache_; |
| 243 | 263 |
| 244 DISALLOW_COPY_AND_ASSIGN(ImageRepCairo); | 264 DISALLOW_COPY_AND_ASSIGN(ImageRepCairo); |
| 245 }; | 265 }; |
| 246 #endif // defined(TOOLKIT_GTK) | 266 #endif // defined(TOOLKIT_GTK) |
| 247 | 267 |
| 248 #if defined(OS_MACOSX) | 268 #if defined(OS_IOS) |
| 269 class ImageRepCocoaTouch : public ImageRep { |
| 270 public: |
| 271 explicit ImageRepCocoaTouch(UIImage* image) |
| 272 : ImageRep(Image::kImageRepCocoaTouch), |
| 273 image_(image) { |
| 274 CHECK(image); |
| 275 } |
| 276 |
| 277 virtual ~ImageRepCocoaTouch() { |
| 278 base::mac::NSObjectRelease(image_); |
| 279 image_ = nil; |
| 280 } |
| 281 |
| 282 UIImage* image() const { return image_; } |
| 283 |
| 284 private: |
| 285 UIImage* image_; |
| 286 |
| 287 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoaTouch); |
| 288 }; |
| 289 #elif defined(OS_MACOSX) |
| 249 class ImageRepCocoa : public ImageRep { | 290 class ImageRepCocoa : public ImageRep { |
| 250 public: | 291 public: |
| 251 explicit ImageRepCocoa(NSImage* image) | 292 explicit ImageRepCocoa(NSImage* image) |
| 252 : ImageRep(Image::kImageRepCocoa), | 293 : ImageRep(Image::kImageRepCocoa), |
| 253 image_(image) { | 294 image_(image) { |
| 254 CHECK(image); | 295 CHECK(image); |
| 255 } | 296 } |
| 256 | 297 |
| 257 virtual ~ImageRepCocoa() { | 298 virtual ~ImageRepCocoa() { |
| 258 base::mac::NSObjectRelease(image_); | 299 base::mac::NSObjectRelease(image_); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 #if defined(TOOLKIT_GTK) | 377 #if defined(TOOLKIT_GTK) |
| 337 Image::Image(GdkPixbuf* pixbuf) { | 378 Image::Image(GdkPixbuf* pixbuf) { |
| 338 if (pixbuf) { | 379 if (pixbuf) { |
| 339 storage_ = new internal::ImageStorage(Image::kImageRepGdk); | 380 storage_ = new internal::ImageStorage(Image::kImageRepGdk); |
| 340 internal::ImageRepGdk* rep = new internal::ImageRepGdk(pixbuf); | 381 internal::ImageRepGdk* rep = new internal::ImageRepGdk(pixbuf); |
| 341 AddRepresentation(rep); | 382 AddRepresentation(rep); |
| 342 } | 383 } |
| 343 } | 384 } |
| 344 #endif | 385 #endif |
| 345 | 386 |
| 346 #if defined(OS_MACOSX) | 387 #if defined(OS_IOS) |
| 388 Image::Image(UIImage* image) |
| 389 : storage_(new internal::ImageStorage(Image::kImageRepCocoaTouch)) { |
| 390 if (image) { |
| 391 internal::ImageRepCocoaTouch* rep = new internal::ImageRepCocoaTouch(image); |
| 392 AddRepresentation(rep); |
| 393 } |
| 394 } |
| 395 #elif defined(OS_MACOSX) |
| 347 Image::Image(NSImage* image) { | 396 Image::Image(NSImage* image) { |
| 348 if (image) { | 397 if (image) { |
| 349 storage_ = new internal::ImageStorage(Image::kImageRepCocoa); | 398 storage_ = new internal::ImageStorage(Image::kImageRepCocoa); |
| 350 internal::ImageRepCocoa* rep = new internal::ImageRepCocoa(image); | 399 internal::ImageRepCocoa* rep = new internal::ImageRepCocoa(image); |
| 351 AddRepresentation(rep); | 400 AddRepresentation(rep); |
| 352 } | 401 } |
| 353 } | 402 } |
| 354 #endif | 403 #endif |
| 355 | 404 |
| 356 Image::Image(const Image& other) : storage_(other.storage_) { | 405 Image::Image(const Image& other) : storage_(other.storage_) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 369 if (!rep) { | 418 if (!rep) { |
| 370 internal::ImageRepPNG* png_rep = new internal::ImageRepPNG(); | 419 internal::ImageRepPNG* png_rep = new internal::ImageRepPNG(); |
| 371 switch (DefaultRepresentationType()) { | 420 switch (DefaultRepresentationType()) { |
| 372 #if defined(TOOLKIT_GTK) | 421 #if defined(TOOLKIT_GTK) |
| 373 case kImageRepGdk: { | 422 case kImageRepGdk: { |
| 374 internal::ImageRepGdk* gdk_rep = | 423 internal::ImageRepGdk* gdk_rep = |
| 375 GetRepresentation(kImageRepGdk, true)->AsImageRepGdk(); | 424 GetRepresentation(kImageRepGdk, true)->AsImageRepGdk(); |
| 376 internal::PNGFromGdkPixbuf(gdk_rep->pixbuf(), png_rep->image()); | 425 internal::PNGFromGdkPixbuf(gdk_rep->pixbuf(), png_rep->image()); |
| 377 break; | 426 break; |
| 378 } | 427 } |
| 428 #elif defined(OS_IOS) |
| 429 case kImageRepCocoaTouch: { |
| 430 internal::ImageRepCocoaTouch* cocoa_touch_rep = |
| 431 GetRepresentation(kImageRepCocoaTouch, true) |
| 432 ->AsImageRepCocoaTouch(); |
| 433 internal::PNGFromUIImage(cocoa_touch_rep->image(), png_rep->image()); |
| 434 break; |
| 435 } |
| 379 #elif defined(OS_MACOSX) | 436 #elif defined(OS_MACOSX) |
| 380 case kImageRepCocoa: { | 437 case kImageRepCocoa: { |
| 381 internal::ImageRepCocoa* cocoa_rep = | 438 internal::ImageRepCocoa* cocoa_rep = |
| 382 GetRepresentation(kImageRepCocoa, true)->AsImageRepCocoa(); | 439 GetRepresentation(kImageRepCocoa, true)->AsImageRepCocoa(); |
| 383 internal::PNGFromNSImage(cocoa_rep->image(), png_rep->image()); | 440 internal::PNGFromNSImage(cocoa_rep->image(), png_rep->image()); |
| 384 break; | 441 break; |
| 385 } | 442 } |
| 386 #endif | 443 #endif |
| 387 case kImageRepSkia: { | 444 case kImageRepSkia: { |
| 388 internal::ImageRepSkia* skia_rep = | 445 internal::ImageRepSkia* skia_rep = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 417 break; | 474 break; |
| 418 } | 475 } |
| 419 #if defined(TOOLKIT_GTK) | 476 #if defined(TOOLKIT_GTK) |
| 420 case kImageRepGdk: { | 477 case kImageRepGdk: { |
| 421 internal::ImageRepGdk* native_rep = | 478 internal::ImageRepGdk* native_rep = |
| 422 GetRepresentation(kImageRepGdk, true)->AsImageRepGdk(); | 479 GetRepresentation(kImageRepGdk, true)->AsImageRepGdk(); |
| 423 rep = new internal::ImageRepSkia(new ImageSkia( | 480 rep = new internal::ImageRepSkia(new ImageSkia( |
| 424 internal::ImageSkiaFromGdkPixbuf(native_rep->pixbuf()))); | 481 internal::ImageSkiaFromGdkPixbuf(native_rep->pixbuf()))); |
| 425 break; | 482 break; |
| 426 } | 483 } |
| 484 #elif defined(OS_IOS) |
| 485 case kImageRepCocoaTouch: { |
| 486 internal::ImageRepCocoaTouch* native_rep = |
| 487 GetRepresentation(kImageRepCocoaTouch, true) |
| 488 ->AsImageRepCocoaTouch(); |
| 489 rep = new internal::ImageRepSkia(new ImageSkia( |
| 490 ImageSkiaFromUIImage(native_rep->image()))); |
| 491 break; |
| 492 } |
| 427 #elif defined(OS_MACOSX) | 493 #elif defined(OS_MACOSX) |
| 428 case kImageRepCocoa: { | 494 case kImageRepCocoa: { |
| 429 internal::ImageRepCocoa* native_rep = | 495 internal::ImageRepCocoa* native_rep = |
| 430 GetRepresentation(kImageRepCocoa, true)->AsImageRepCocoa(); | 496 GetRepresentation(kImageRepCocoa, true)->AsImageRepCocoa(); |
| 431 rep = new internal::ImageRepSkia(new ImageSkia( | 497 rep = new internal::ImageRepSkia(new ImageSkia( |
| 432 ImageSkiaFromNSImage(native_rep->image()))); | 498 ImageSkiaFromNSImage(native_rep->image()))); |
| 433 break; | 499 break; |
| 434 } | 500 } |
| 435 #endif | 501 #endif |
| 436 default: | 502 default: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 // Handle any-to-Cairo conversion. This may create and cache an intermediate | 542 // Handle any-to-Cairo conversion. This may create and cache an intermediate |
| 477 // pixbuf before sending the data to the display server. | 543 // pixbuf before sending the data to the display server. |
| 478 rep = new internal::ImageRepCairo(ToGdkPixbuf()); | 544 rep = new internal::ImageRepCairo(ToGdkPixbuf()); |
| 479 CHECK(rep); | 545 CHECK(rep); |
| 480 AddRepresentation(rep); | 546 AddRepresentation(rep); |
| 481 } | 547 } |
| 482 return rep->AsImageRepCairo()->surface(); | 548 return rep->AsImageRepCairo()->surface(); |
| 483 } | 549 } |
| 484 #endif | 550 #endif |
| 485 | 551 |
| 486 #if defined(OS_MACOSX) | 552 #if defined(OS_IOS) |
| 553 UIImage* Image::ToUIImage() const { |
| 554 internal::ImageRep* rep = GetRepresentation(kImageRepCocoaTouch, false); |
| 555 if (!rep) { |
| 556 switch (DefaultRepresentationType()) { |
| 557 case kImageRepPNG: { |
| 558 internal::ImageRepPNG* png_rep = |
| 559 GetRepresentation(kImageRepPNG, true)->AsImageRepPNG(); |
| 560 rep = new internal::ImageRepCocoaTouch(internal::CreateUIImageFromPNG( |
| 561 *png_rep->image())); |
| 562 break; |
| 563 } |
| 564 case kImageRepSkia: { |
| 565 internal::ImageRepSkia* skia_rep = |
| 566 GetRepresentation(kImageRepSkia, true)->AsImageRepSkia(); |
| 567 UIImage* image = UIImageFromImageSkia(*skia_rep->image()); |
| 568 base::mac::NSObjectRetain(image); |
| 569 rep = new internal::ImageRepCocoaTouch(image); |
| 570 break; |
| 571 } |
| 572 default: |
| 573 NOTREACHED(); |
| 574 } |
| 575 CHECK(rep); |
| 576 AddRepresentation(rep); |
| 577 } |
| 578 return rep->AsImageRepCocoaTouch()->image(); |
| 579 } |
| 580 #elif defined(OS_MACOSX) |
| 487 NSImage* Image::ToNSImage() const { | 581 NSImage* Image::ToNSImage() const { |
| 488 internal::ImageRep* rep = GetRepresentation(kImageRepCocoa, false); | 582 internal::ImageRep* rep = GetRepresentation(kImageRepCocoa, false); |
| 489 if (!rep) { | 583 if (!rep) { |
| 490 switch (DefaultRepresentationType()) { | 584 switch (DefaultRepresentationType()) { |
| 491 case kImageRepPNG: { | 585 case kImageRepPNG: { |
| 492 internal::ImageRepPNG* png_rep = | 586 internal::ImageRepPNG* png_rep = |
| 493 GetRepresentation(kImageRepPNG, true)->AsImageRepPNG(); | 587 GetRepresentation(kImageRepPNG, true)->AsImageRepPNG(); |
| 494 rep = new internal::ImageRepCocoa(internal::NSImageFromPNG( | 588 rep = new internal::ImageRepCocoa(internal::NSImageFromPNG( |
| 495 *png_rep->image())); | 589 *png_rep->image())); |
| 496 break; | 590 break; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 518 } | 612 } |
| 519 | 613 |
| 520 SkBitmap Image::AsBitmap() const { | 614 SkBitmap Image::AsBitmap() const { |
| 521 return IsEmpty() ? SkBitmap() : *ToSkBitmap(); | 615 return IsEmpty() ? SkBitmap() : *ToSkBitmap(); |
| 522 } | 616 } |
| 523 | 617 |
| 524 ImageSkia Image::AsImageSkia() const { | 618 ImageSkia Image::AsImageSkia() const { |
| 525 return IsEmpty() ? ImageSkia() : *ToImageSkia(); | 619 return IsEmpty() ? ImageSkia() : *ToImageSkia(); |
| 526 } | 620 } |
| 527 | 621 |
| 528 #if defined(OS_MACOSX) | 622 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 529 NSImage* Image::AsNSImage() const { | 623 NSImage* Image::AsNSImage() const { |
| 530 return IsEmpty() ? nil : ToNSImage(); | 624 return IsEmpty() ? nil : ToNSImage(); |
| 531 } | 625 } |
| 532 #endif | 626 #endif |
| 533 | 627 |
| 534 ImageSkia* Image::CopyImageSkia() const { | 628 ImageSkia* Image::CopyImageSkia() const { |
| 535 return new ImageSkia(*ToImageSkia()); | 629 return new ImageSkia(*ToImageSkia()); |
| 536 } | 630 } |
| 537 | 631 |
| 538 SkBitmap* Image::CopySkBitmap() const { | 632 SkBitmap* Image::CopySkBitmap() const { |
| 539 return new SkBitmap(*ToSkBitmap()); | 633 return new SkBitmap(*ToSkBitmap()); |
| 540 } | 634 } |
| 541 | 635 |
| 542 #if defined(TOOLKIT_GTK) | 636 #if defined(TOOLKIT_GTK) |
| 543 GdkPixbuf* Image::CopyGdkPixbuf() const { | 637 GdkPixbuf* Image::CopyGdkPixbuf() const { |
| 544 GdkPixbuf* pixbuf = ToGdkPixbuf(); | 638 GdkPixbuf* pixbuf = ToGdkPixbuf(); |
| 545 g_object_ref(pixbuf); | 639 g_object_ref(pixbuf); |
| 546 return pixbuf; | 640 return pixbuf; |
| 547 } | 641 } |
| 548 #endif | 642 #endif |
| 549 | 643 |
| 550 #if defined(OS_MACOSX) | 644 #if defined(OS_IOS) |
| 645 UIImage* Image::CopyUIImage() const { |
| 646 UIImage* image = ToUIImage(); |
| 647 base::mac::NSObjectRetain(image); |
| 648 return image; |
| 649 } |
| 650 #elif defined(OS_MACOSX) |
| 551 NSImage* Image::CopyNSImage() const { | 651 NSImage* Image::CopyNSImage() const { |
| 552 NSImage* image = ToNSImage(); | 652 NSImage* image = ToNSImage(); |
| 553 base::mac::NSObjectRetain(image); | 653 base::mac::NSObjectRetain(image); |
| 554 return image; | 654 return image; |
| 555 } | 655 } |
| 556 #endif | 656 #endif |
| 557 | 657 |
| 558 #if defined(OS_MACOSX) | 658 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 559 Image::operator NSImage*() const { | 659 Image::operator NSImage*() const { |
| 560 return ToNSImage(); | 660 return ToNSImage(); |
| 561 } | 661 } |
| 562 #endif | 662 #endif |
| 563 | 663 |
| 564 bool Image::HasRepresentation(RepresentationType type) const { | 664 bool Image::HasRepresentation(RepresentationType type) const { |
| 565 return storage_.get() && storage_->representations().count(type) != 0; | 665 return storage_.get() && storage_->representations().count(type) != 0; |
| 566 } | 666 } |
| 567 | 667 |
| 568 size_t Image::RepresentationCount() const { | 668 size_t Image::RepresentationCount() const { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 599 } | 699 } |
| 600 return it->second; | 700 return it->second; |
| 601 } | 701 } |
| 602 | 702 |
| 603 void Image::AddRepresentation(internal::ImageRep* rep) const { | 703 void Image::AddRepresentation(internal::ImageRep* rep) const { |
| 604 CHECK(storage_.get()); | 704 CHECK(storage_.get()); |
| 605 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 705 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
| 606 } | 706 } |
| 607 | 707 |
| 608 } // namespace gfx | 708 } // namespace gfx |
| OLD | NEW |