diff options
author | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-15 03:28:29 +0000 |
---|---|---|
committer | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-15 03:28:29 +0000 |
commit | 12c7da12c76dfdd58e9a5fc2ed77b319dfd2c96d (patch) | |
tree | c8b03dacda19d343c7dfc33ad72e4c273f808462 /ui/gfx | |
parent | e7a8cbd4d4d389e666d5d3c372bb5d09a63b829b (diff) | |
download | chromium_src-12c7da12c76dfdd58e9a5fc2ed77b319dfd2c96d.zip chromium_src-12c7da12c76dfdd58e9a5fc2ed77b319dfd2c96d.tar.gz chromium_src-12c7da12c76dfdd58e9a5fc2ed77b319dfd2c96d.tar.bz2 |
Revert 136812 - Get rid of Image::Image(SkBitmap*)
Bug=124566
Test=Compiles on CrOS,Mac
Review URL: https://chromiumcodereview.appspot.com/10378009
TBR=pkotwicz@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=136813
Review URL: https://chromiumcodereview.appspot.com/10383153
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/image/image.cc | 12 | ||||
-rw-r--r-- | ui/gfx/image/image.h | 4 | ||||
-rw-r--r-- | ui/gfx/image/image_unittest.cc | 18 | ||||
-rw-r--r-- | ui/gfx/image/image_unittest_util.cc | 36 | ||||
-rw-r--r-- | ui/gfx/image/image_unittest_util.h | 8 | ||||
-rw-r--r-- | ui/gfx/image/image_util.cc | 6 |
6 files changed, 47 insertions, 37 deletions
diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc index e748dd9..3118ddc 100644 --- a/ui/gfx/image/image.cc +++ b/ui/gfx/image/image.cc @@ -224,13 +224,6 @@ Image::Image() { // |storage_| is NULL for empty Images. } -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) : storage_(new internal::ImageStorage(Image::kImageRepSkia)) { internal::ImageRepSkia* rep = @@ -377,8 +370,9 @@ internal::ImageRep* Image::GetRepresentation( #if defined(TOOLKIT_GTK) if (storage_->default_representation_type() == Image::kImageRepGdk) { internal::ImageRepGdk* pixbuf_rep = default_rep->AsImageRepGdk(); - rep = new internal::ImageRepSkia(new ImageSkia( - internal::GdkPixbufToSkBitmap(pixbuf_rep->pixbuf()))); + scoped_ptr<const SkBitmap> bitmap(internal::GdkPixbufToSkBitmap( + pixbuf_rep->pixbuf())); + rep = new internal::ImageRepSkia(new ImageSkia(*bitmap)); } // We don't do conversions from CairoCachedSurfaces to Skia because the // data lives on the display server and we'll always have a GdkPixbuf if we diff --git a/ui/gfx/image/image.h b/ui/gfx/image/image.h index 9c0e6eb..71c3e17 100644 --- a/ui/gfx/image/image.h +++ b/ui/gfx/image/image.h @@ -62,10 +62,6 @@ class UI_EXPORT Image { // Creates an empty image with no representations. Image(); - // Creates a new image with the default representation. The object will take - // ownership of the image. - explicit Image(const SkBitmap* bitmap); - // Creates a new image by copying the bitmap for use as the default // representation. explicit Image(const SkBitmap& bitmap); diff --git a/ui/gfx/image/image_unittest.cc b/ui/gfx/image/image_unittest.cc index 8793562..732f69f 100644 --- a/ui/gfx/image/image_unittest.cc +++ b/ui/gfx/image/image_unittest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/memory/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/image/image.h" @@ -68,8 +67,8 @@ TEST_F(ImageTest, SkiaToSkia) { } TEST_F(ImageTest, SkiaRefToSkia) { - scoped_ptr<SkBitmap> originalBitmap(gt::CreateBitmap(25, 25)); - gfx::Image image(*originalBitmap.get()); + SkBitmap originalBitmap(gt::CreateBitmap(25, 25)); + gfx::Image image(originalBitmap); const SkBitmap* bitmap = image.ToSkBitmap(); EXPECT_TRUE(bitmap); EXPECT_FALSE(bitmap->isNull()); @@ -104,7 +103,7 @@ TEST_F(ImageTest, SkiaToPlatform) { if (!kUsesSkiaNatively) EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); - EXPECT_TRUE(gt::ToPlatformType(image)); + EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); EXPECT_EQ(kRepCount, image.RepresentationCount()); const SkBitmap* bitmap = image.ToSkBitmap(); @@ -128,7 +127,7 @@ TEST_F(ImageTest, PlatformToSkia) { EXPECT_FALSE(bitmap->isNull()); EXPECT_EQ(kRepCount, image.RepresentationCount()); - EXPECT_TRUE(gt::ToPlatformType(image)); + EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); EXPECT_EQ(kRepCount, image.RepresentationCount()); EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); @@ -136,11 +135,11 @@ TEST_F(ImageTest, PlatformToSkia) { TEST_F(ImageTest, PlatformToPlatform) { gfx::Image image(gt::CreatePlatformImage()); - EXPECT_TRUE(gt::ToPlatformType(image)); + EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); EXPECT_EQ(1U, image.RepresentationCount()); // Make sure double conversion doesn't happen. - EXPECT_TRUE(gt::ToPlatformType(image)); + EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); EXPECT_EQ(1U, image.RepresentationCount()); EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); @@ -221,7 +220,8 @@ TEST_F(ImageTest, SwapRepresentations) { image1.SwapRepresentations(&image2); EXPECT_EQ(bitmap2, image1.ToSkBitmap()); - EXPECT_EQ(platform_image, gt::ToPlatformType(image1)); + EXPECT_TRUE(gt::PlatformImagesEqual(platform_image, + gt::ToPlatformType(image1))); EXPECT_EQ(bitmap1, image2.ToSkBitmap()); EXPECT_EQ(kRepCount, image1.RepresentationCount()); EXPECT_EQ(1U, image2.RepresentationCount()); @@ -237,7 +237,7 @@ TEST_F(ImageTest, Copy) { EXPECT_EQ(1U, image2.RepresentationCount()); EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); - EXPECT_TRUE(gt::ToPlatformType(image2)); + EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image2))); EXPECT_EQ(kRepCount, image2.RepresentationCount()); EXPECT_EQ(kRepCount, image1.RepresentationCount()); } diff --git a/ui/gfx/image/image_unittest_util.cc b/ui/gfx/image/image_unittest_util.cc index 6a72869..141db84 100644 --- a/ui/gfx/image/image_unittest_util.cc +++ b/ui/gfx/image/image_unittest_util.cc @@ -20,11 +20,11 @@ namespace gfx { namespace test { -SkBitmap* CreateBitmap(int width, int height) { - SkBitmap* bitmap = new SkBitmap(); - bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); - bitmap->allocPixels(); - bitmap->eraseRGB(255, 0, 0); +const SkBitmap CreateBitmap(int width, int height) { + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); + bitmap.allocPixels(); + bitmap.eraseRGB(255, 0, 0); return bitmap; } @@ -65,15 +65,15 @@ bool IsEmpty(const gfx::Image& image) { } PlatformImage CreatePlatformImage() { - scoped_ptr<SkBitmap> bitmap(CreateBitmap(25, 25)); + const SkBitmap bitmap(CreateBitmap(25, 25)); #if defined(OS_MACOSX) - NSImage* image = gfx::SkBitmapToNSImage(*(bitmap.get())); + NSImage* image = gfx::SkBitmapToNSImage(bitmap); base::mac::NSObjectRetain(image); return image; #elif defined(TOOLKIT_GTK) - return gfx::GdkPixbufFromSkBitmap(bitmap.get()); + return gfx::GdkPixbufFromSkBitmap(&bitmap); #else - return bitmap.release(); + return bitmap; #endif } @@ -93,7 +93,23 @@ PlatformImage ToPlatformType(const gfx::Image& image) { #elif defined(TOOLKIT_GTK) return image.ToGdkPixbuf(); #else - return image.ToSkBitmap(); + return *image.ToSkBitmap(); +#endif +} + +bool IsPlatformImageValid(PlatformImage image) { +#if defined(OS_MACOSX) || defined(TOOLKIT_GTK) + return image != NULL; +#else + return !image.isNull(); +#endif +} + +bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { +#if defined(OS_MACOSX) || defined(TOOLKIT_GTK) + return image1 == image2; +#else + return image1.getPixels() == image2.getPixels(); #endif } diff --git a/ui/gfx/image/image_unittest_util.h b/ui/gfx/image/image_unittest_util.h index fb471b9..e617f26 100644 --- a/ui/gfx/image/image_unittest_util.h +++ b/ui/gfx/image/image_unittest_util.h @@ -18,10 +18,10 @@ typedef NSImage* PlatformImage; #elif defined(TOOLKIT_GTK) typedef GdkPixbuf* PlatformImage; #else -typedef const SkBitmap* PlatformImage; +typedef const SkBitmap PlatformImage; #endif -SkBitmap* CreateBitmap(int width, int height); +const SkBitmap CreateBitmap(int width, int height); gfx::Image CreateImage(); @@ -35,6 +35,10 @@ gfx::Image::RepresentationType GetPlatformRepresentationType(); PlatformImage ToPlatformType(const gfx::Image& image); +bool IsPlatformImageValid(PlatformImage image); + +bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2); + } // namespace test } // namespace gfx diff --git a/ui/gfx/image/image_util.cc b/ui/gfx/image/image_util.cc index 4216629..ea870c0 100644 --- a/ui/gfx/image/image_util.cc +++ b/ui/gfx/image/image_util.cc @@ -13,9 +13,9 @@ namespace gfx { Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) { - scoped_ptr<SkBitmap> favicon_bitmap(new SkBitmap()); - if (gfx::PNGCodec::Decode(input, input_size, favicon_bitmap.get())) - return new Image(favicon_bitmap.release()); + SkBitmap favicon_bitmap; + if (gfx::PNGCodec::Decode(input, input_size, &favicon_bitmap)) + return new Image(favicon_bitmap); return NULL; } |