summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 15:42:59 +0000
committerpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 15:42:59 +0000
commit93079e0c4d33bcbfa3e2c214aa3069827b1439be (patch)
treebb5dc3df683402925645a66fd5595c63c7a61653 /ui
parentd613857976ff0b38c09c2e1417815eb1ac113616 (diff)
downloadchromium_src-93079e0c4d33bcbfa3e2c214aa3069827b1439be.zip
chromium_src-93079e0c4d33bcbfa3e2c214aa3069827b1439be.tar.gz
chromium_src-93079e0c4d33bcbfa3e2c214aa3069827b1439be.tar.bz2
Get rid of Image::Image(SkBitmap*)
Bug=124566 Test=Compiles on CrOS,Mac Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=137075 Review URL: https://chromiumcodereview.appspot.com/10378009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137140 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/base/resource/resource_bundle.cc8
-rw-r--r--ui/gfx/image/image.cc7
-rw-r--r--ui/gfx/image/image.h4
-rw-r--r--ui/gfx/image/image_mac_unittest.mm4
-rw-r--r--ui/gfx/image/image_unittest.cc22
-rw-r--r--ui/gfx/image/image_unittest_util.cc36
-rw-r--r--ui/gfx/image/image_unittest_util.h8
-rw-r--r--ui/gfx/image/image_util.cc6
8 files changed, 52 insertions, 43 deletions
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index bb011ab..693677c 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -465,10 +465,10 @@ gfx::Image& ResourceBundle::GetEmptyImage() {
if (empty_image_.IsEmpty()) {
// The placeholder bitmap is bright red so people notice the problem.
- SkBitmap* bitmap = new SkBitmap();
- bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32);
- bitmap->allocPixels();
- bitmap->eraseARGB(255, 255, 0, 0);
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32);
+ bitmap.allocPixels();
+ bitmap.eraseARGB(255, 255, 0, 0);
empty_image_ = gfx::Image(bitmap);
}
return empty_image_;
diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc
index e748dd9..66fb97c 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 =
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_mac_unittest.mm b/ui/gfx/image/image_mac_unittest.mm
index f0ed004..b3a3878 100644
--- a/ui/gfx/image/image_mac_unittest.mm
+++ b/ui/gfx/image/image_mac_unittest.mm
@@ -79,8 +79,8 @@ TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) {
const int height2 = 24;
std::vector<const SkBitmap*> bitmaps;
- bitmaps.push_back(gt::CreateBitmap(width1, height1));
- bitmaps.push_back(gt::CreateBitmap(width2, height2));
+ bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width1, height1)));
+ bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width2, height2)));
gfx::Image image(bitmaps);
EXPECT_EQ(1u, image.RepresentationCount());
diff --git a/ui/gfx/image/image_unittest.cc b/ui/gfx/image/image_unittest.cc
index 8793562..51e06f4 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());
}
@@ -258,8 +258,8 @@ TEST_F(ImageTest, MultiResolutionSkBitmap) {
const int height2 = 24;
std::vector<const SkBitmap*> bitmaps;
- bitmaps.push_back(gt::CreateBitmap(width1, height1));
- bitmaps.push_back(gt::CreateBitmap(width2, height2));
+ bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width1, height1)));
+ bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width2, height2)));
gfx::Image image(bitmaps);
EXPECT_EQ(1u, image.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;
}