Commit 07519e62 authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Enable gfx::Image to be created from empty platform images.

BUG=142930
Test=ImageTest.EmptyImageFromEmptyPlatformImage

Review URL: https://chromiumcodereview.appspot.com/10867076

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153525 0039d316-1c4b-4281-b951-d872f2087c98
parent f4c7c61e
......@@ -315,33 +315,41 @@ Image::Image(const unsigned char* png, size_t input_size)
AddRepresentation(rep);
}
Image::Image(const ImageSkia& image)
: storage_(new internal::ImageStorage(Image::kImageRepSkia)) {
internal::ImageRepSkia* rep = new internal::ImageRepSkia(
new ImageSkia(image));
AddRepresentation(rep);
Image::Image(const ImageSkia& image) {
if (!image.isNull()) {
storage_ = new internal::ImageStorage(Image::kImageRepSkia);
internal::ImageRepSkia* rep = new internal::ImageRepSkia(
new ImageSkia(image));
AddRepresentation(rep);
}
}
Image::Image(const SkBitmap& bitmap)
: storage_(new internal::ImageStorage(Image::kImageRepSkia)) {
internal::ImageRepSkia* rep =
new internal::ImageRepSkia(new ImageSkia(bitmap));
AddRepresentation(rep);
Image::Image(const SkBitmap& bitmap) {
if (!bitmap.empty()) {
storage_ = new internal::ImageStorage(Image::kImageRepSkia);
internal::ImageRepSkia* rep =
new internal::ImageRepSkia(new ImageSkia(bitmap));
AddRepresentation(rep);
}
}
#if defined(TOOLKIT_GTK)
Image::Image(GdkPixbuf* pixbuf)
: storage_(new internal::ImageStorage(Image::kImageRepGdk)) {
internal::ImageRepGdk* rep = new internal::ImageRepGdk(pixbuf);
AddRepresentation(rep);
Image::Image(GdkPixbuf* pixbuf) {
if (pixbuf) {
storage_ = new internal::ImageStorage(Image::kImageRepGdk);
internal::ImageRepGdk* rep = new internal::ImageRepGdk(pixbuf);
AddRepresentation(rep);
}
}
#endif
#if defined(OS_MACOSX)
Image::Image(NSImage* image)
: storage_(new internal::ImageStorage(Image::kImageRepCocoa)) {
internal::ImageRepCocoa* rep = new internal::ImageRepCocoa(image);
AddRepresentation(rep);
Image::Image(NSImage* image) {
if (image) {
storage_ = new internal::ImageStorage(Image::kImageRepCocoa);
internal::ImageRepCocoa* rep = new internal::ImageRepCocoa(image);
AddRepresentation(rep);
}
}
#endif
......
......@@ -47,6 +47,28 @@ TEST_F(ImageTest, EmptyImage) {
EXPECT_TRUE(image2.IsEmpty());
}
// Test constructing a gfx::Image from an empty PlatformImage.
TEST_F(ImageTest, EmptyImageFromEmptyPlatformImage) {
#if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
gfx::Image image1(NULL);
EXPECT_TRUE(image1.IsEmpty());
EXPECT_EQ(0U, image1.RepresentationCount());
#endif
// SkBitmap and gfx::ImageSkia are available on all platforms.
SkBitmap bitmap;
EXPECT_TRUE(bitmap.empty());
gfx::Image image2(bitmap);
EXPECT_TRUE(image2.IsEmpty());
EXPECT_EQ(0U, image2.RepresentationCount());
gfx::ImageSkia image_skia;
EXPECT_TRUE(image_skia.isNull());
gfx::Image image3(image_skia);
EXPECT_TRUE(image3.IsEmpty());
EXPECT_EQ(0U, image3.RepresentationCount());
}
TEST_F(ImageTest, SkiaToSkia) {
gfx::Image image(gt::CreateBitmap(25, 25));
const SkBitmap* bitmap = image.ToSkBitmap();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment