diff options
24 files changed, 113 insertions, 98 deletions
diff --git a/ash/wm/image_grid_unittest.cc b/ash/wm/image_grid_unittest.cc index 715ddb9..cf533b5 100644 --- a/ash/wm/image_grid_unittest.cc +++ b/ash/wm/image_grid_unittest.cc @@ -17,8 +17,8 @@ namespace { // Creates a gfx::Image with the requested dimensions. gfx::Image* CreateImage(const gfx::Size& size) { - SkBitmap* bitmap = new SkBitmap(); - bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); return new gfx::Image(bitmap); } diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index 54ac187..9d1df2c 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -519,7 +519,7 @@ void ExtensionInstallUI::ShowConfirmation() { case INLINE_INSTALL_PROMPT: case INSTALL_PROMPT: { prompt_.set_extension(extension_); - prompt_.set_icon(gfx::Image(new SkBitmap(icon_))); + prompt_.set_icon(gfx::Image(icon_)); ShowExtensionInstallDialog(profile_, delegate_, prompt_); break; } diff --git a/chrome/browser/favicon/favicon_tab_helper.cc b/chrome/browser/favicon/favicon_tab_helper.cc index 2d7cda3..3aac80f 100644 --- a/chrome/browser/favicon/favicon_tab_helper.cc +++ b/chrome/browser/favicon/favicon_tab_helper.cc @@ -186,7 +186,7 @@ void FaviconTabHelper::OnDidDownloadFavicon(int id, const GURL& image_url, bool errored, const SkBitmap& image) { - gfx::Image favicon(new SkBitmap(image)); + gfx::Image favicon(image); favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); if (touch_icon_handler_.get()) touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc index fffc7f1..40562e1 100644 --- a/chrome/browser/history/expire_history_backend_unittest.cc +++ b/chrome/browser/history/expire_history_backend_unittest.cc @@ -230,8 +230,9 @@ void ExpireHistoryTest::AddExampleData(URLID url_ids[3], Time visit_times[4]) { thumb_db_->AddIconMapping(url_row3.url(), favicon2); // Thumbnails for each URL. |thumbnail| takes ownership of decoded SkBitmap. - gfx::Image thumbnail( + scoped_ptr<SkBitmap> thumbnail_bitmap( gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); + gfx::Image thumbnail(*thumbnail_bitmap); ThumbnailScore score(0.25, true, true, Time::Now()); Time time; diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index d3f6f0b..c3e0884 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -346,16 +346,19 @@ TEST_F(HistoryBackendTest, DeleteAll) { // Add thumbnails for each page. The |Images| take ownership of SkBitmap // created from decoding the images. ThumbnailScore score(0.25, true, true); - gfx::Image google_bitmap( + scoped_ptr<SkBitmap> google_bitmap( gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); + gfx::Image google_image(*google_bitmap); + Time time; GURL gurl; - backend_->thumbnail_db_->SetPageThumbnail(gurl, row1_id, &google_bitmap, + backend_->thumbnail_db_->SetPageThumbnail(gurl, row1_id, &google_image, score, time); - gfx::Image weewar_bitmap( + scoped_ptr<SkBitmap> weewar_bitmap( gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); - backend_->thumbnail_db_->SetPageThumbnail(gurl, row2_id, &weewar_bitmap, + gfx::Image weewar_image(*weewar_bitmap); + backend_->thumbnail_db_->SetPageThumbnail(gurl, row2_id, &weewar_image, score, time); // Star row1. diff --git a/chrome/browser/history/history_tab_helper.cc b/chrome/browser/history/history_tab_helper.cc index 2da50d0..a9eb13c 100644 --- a/chrome/browser/history/history_tab_helper.cc +++ b/chrome/browser/history/history_tab_helper.cc @@ -158,7 +158,7 @@ void HistoryTabHelper::OnThumbnail(const GURL& url, // Tell History about this thumbnail. history::TopSites* ts = profile->GetTopSites(); if (ts) { - gfx::Image thumbnail(new SkBitmap(bitmap)); + gfx::Image thumbnail(bitmap); ts->SetPageThumbnail(url, &thumbnail, score); } } diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc index bdfd045..863bfc6 100644 --- a/chrome/browser/history/top_sites_unittest.cc +++ b/chrome/browser/history/top_sites_unittest.cc @@ -166,11 +166,11 @@ class TopSitesTest : public HistoryUnitTestBase { // Creates a bitmap of the specified color. Caller takes ownership. gfx::Image CreateBitmap(SkColor color) { - SkBitmap* thumbnail = new SkBitmap; - thumbnail->setConfig(SkBitmap::kARGB_8888_Config, 4, 4); - thumbnail->allocPixels(); - thumbnail->eraseColor(color); - return gfx::Image(thumbnail); // takes ownership. + SkBitmap thumbnail; + thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); + thumbnail.allocPixels(); + thumbnail.eraseColor(color); + return gfx::Image(thumbnail); // adds ref. } // Forces top sites to load top sites from history, then recreates top sites. diff --git a/chrome/browser/icon_loader_chromeos.cc b/chrome/browser/icon_loader_chromeos.cc index 14692be..cc4739f 100644 --- a/chrome/browser/icon_loader_chromeos.cc +++ b/chrome/browser/icon_loader_chromeos.cc @@ -164,15 +164,15 @@ int IconMapper::Lookup(const std::string& extension, // Returns a copy of |source| that is |pixel_size| in width and height. If // |pixel_size| is |kDoNotResize|, returns an unmodified copy of |source|. // |source| must be a square image (width == height). -SkBitmap* GenerateBitmapWithSize(SkBitmap* source, int pixel_size) { - DCHECK(source); - DCHECK(source->width() == source->height()); +SkBitmap GenerateBitmapWithSize(const SkBitmap& source, int pixel_size) { + DCHECK(!source.isNull()); + DCHECK(source.width() == source.height()); - if (pixel_size == kDoNotResize || source->width() == pixel_size) - return new SkBitmap(*source); + if (pixel_size == kDoNotResize || source.width() == pixel_size) + return source; - return new SkBitmap(skia::ImageOperations::Resize( - *source, skia::ImageOperations::RESIZE_BEST, pixel_size, pixel_size)); + return skia::ImageOperations::Resize( + source, skia::ImageOperations::RESIZE_BEST, pixel_size, pixel_size); } int IconSizeToPixelSize(IconLoader::IconSize size) { @@ -203,7 +203,7 @@ void IconLoader::ReadIcon() { if (!gfx::PNGCodec::Decode(bytes->front(), bytes->size(), &bitmap)) NOTREACHED(); image_.reset(new gfx::Image( - GenerateBitmapWithSize(&bitmap, IconSizeToPixelSize(icon_size_)))); + GenerateBitmapWithSize(bitmap, IconSizeToPixelSize(icon_size_)))); target_message_loop_->PostTask( FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); } diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc index b70dfd8..f0bb1e6 100644 --- a/chrome/browser/icon_loader_linux.cc +++ b/chrome/browser/icon_loader_linux.cc @@ -40,14 +40,14 @@ void IconLoader::ReadIcon() { file_util::ReadFileToString(filename, &icon_data); webkit_glue::ImageDecoder decoder; - scoped_ptr<SkBitmap> bitmap(new SkBitmap()); - *bitmap = decoder.Decode( + SkBitmap bitmap; + bitmap = decoder.Decode( reinterpret_cast<const unsigned char*>(icon_data.data()), icon_data.length()); - if (!bitmap->empty()) { - DCHECK_EQ(size_pixels, bitmap->width()); - DCHECK_EQ(size_pixels, bitmap->height()); - image_.reset(new gfx::Image(bitmap.release())); + if (!bitmap.empty()) { + DCHECK_EQ(size_pixels, bitmap.width()); + DCHECK_EQ(size_pixels, bitmap.height()); + image_.reset(new gfx::Image(bitmap)); } else { LOG(WARNING) << "Unsupported file type or load error: " << filename.value(); diff --git a/chrome/browser/icon_loader_win.cc b/chrome/browser/icon_loader_win.cc index f51c064..c217bff 100644 --- a/chrome/browser/icon_loader_win.cc +++ b/chrome/browser/icon_loader_win.cc @@ -10,6 +10,7 @@ #include "base/bind.h" #include "base/message_loop.h" #include "base/threading/thread.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/icon_util.h" #include "ui/gfx/size.h" @@ -34,8 +35,9 @@ void IconLoader::ReadIcon() { SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) return; - image_.reset(new gfx::Image( - IconUtil::CreateSkBitmapFromHICON(file_info.hIcon))); + scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON( + file_info.hIcon)); + image_.reset(new gfx::Image(*bitmap)); DestroyIcon(file_info.hIcon); target_message_loop_->PostTask(FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); diff --git a/chrome/browser/profiles/gaia_info_update_service.cc b/chrome/browser/profiles/gaia_info_update_service.cc index f7ada7e..32ce7cd 100644 --- a/chrome/browser/profiles/gaia_info_update_service.cc +++ b/chrome/browser/profiles/gaia_info_update_service.cc @@ -129,7 +129,7 @@ void GAIAInfoUpdateService::OnDownloadComplete(ProfileDownloader* downloader, if (picture_status == ProfileDownloader::PICTURE_SUCCESS) { profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, picture_url); - gfx::Image gfx_image(new SkBitmap(bitmap)); + gfx::Image gfx_image(bitmap); cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image); } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) { cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc index c8678d1..1834ae7 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.cc +++ b/chrome/browser/tab_contents/thumbnail_generator.cc @@ -471,7 +471,7 @@ void ThumbnailGenerator::UpdateThumbnail( clip_result == ThumbnailGenerator::kNotClipped); score.load_completed = (!load_interrupted_ && !web_contents->IsLoading()); - gfx::Image image(new SkBitmap(thumbnail)); + gfx::Image image(thumbnail); const GURL& url = web_contents->GetURL(); top_sites->SetPageThumbnail(url, &image, score); VLOG(1) << "Thumbnail taken for " << url << ": " << score.ToString(); diff --git a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_unittest.mm b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_unittest.mm index 4c01975..2daa7f1 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_unittest.mm @@ -48,7 +48,7 @@ public: SkBitmap bitmap = decoder.Decode( reinterpret_cast<const unsigned char*>(file_contents.c_str()), file_contents.length()); - icon_ = gfx::Image(new SkBitmap(bitmap)); + icon_ = gfx::Image(bitmap); } void LoadExtension() { diff --git a/chrome/browser/ui/gtk/gtk_theme_service.cc b/chrome/browser/ui/gtk/gtk_theme_service.cc index cd6b0ab..30d92ef 100644 --- a/chrome/browser/ui/gtk/gtk_theme_service.cc +++ b/chrome/browser/ui/gtk/gtk_theme_service.cc @@ -939,16 +939,16 @@ void GtkThemeService::FreeIconSets() { } } -SkBitmap* GtkThemeService::GenerateGtkThemeBitmap(int id) const { +SkBitmap GtkThemeService::GenerateGtkThemeBitmap(int id) const { switch (id) { case IDR_THEME_TOOLBAR: { GtkStyle* style = gtk_rc_get_style(fake_window_); GdkColor* color = &style->bg[GTK_STATE_NORMAL]; - SkBitmap* bitmap = new SkBitmap; - bitmap->setConfig(SkBitmap::kARGB_8888_Config, - kToolbarImageWidth, kToolbarImageHeight); - bitmap->allocPixels(); - bitmap->eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8); + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + kToolbarImageWidth, kToolbarImageHeight); + bitmap.allocPixels(); + bitmap.eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8); return bitmap; } case IDR_THEME_TAB_BACKGROUND: @@ -1001,7 +1001,7 @@ SkBitmap* GtkThemeService::GenerateGtkThemeBitmap(int id) const { } } -SkBitmap* GtkThemeService::GenerateFrameImage( +SkBitmap GtkThemeService::GenerateFrameImage( int color_id, const char* gradient_name) const { // We use two colors: the main color (passed in) and a lightened version of @@ -1038,23 +1038,23 @@ SkBitmap* GtkThemeService::GenerateFrameImage( canvas.FillRect(gfx::Rect(0, gradient_size, kToolbarImageWidth, kToolbarImageHeight - gradient_size), base); - return new SkBitmap(canvas.ExtractBitmap()); + return canvas.ExtractBitmap(); } -SkBitmap* GtkThemeService::GenerateTabImage(int base_id) const { +SkBitmap GtkThemeService::GenerateTabImage(int base_id) const { SkBitmap* base_image = GetBitmapNamed(base_id); SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( *base_image, GetTint(ThemeService::TINT_BACKGROUND_TAB)); - return new SkBitmap(SkBitmapOperations::CreateTiledBitmap( - bg_tint, 0, 0, bg_tint.width(), bg_tint.height())); + return SkBitmapOperations::CreateTiledBitmap( + bg_tint, 0, 0, bg_tint.width(), bg_tint.height()); } -SkBitmap* GtkThemeService::GenerateTintedIcon( +SkBitmap GtkThemeService::GenerateTintedIcon( int base_id, const color_utils::HSL& tint) const { ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - return new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap( - *rb.GetBitmapNamed(base_id), tint)); + return SkBitmapOperations::CreateHSLShiftedBitmap( + *rb.GetBitmapNamed(base_id), tint); } void GtkThemeService::GetNormalButtonTintHSL( diff --git a/chrome/browser/ui/gtk/gtk_theme_service.h b/chrome/browser/ui/gtk/gtk_theme_service.h index 0228c56..d421ffb 100644 --- a/chrome/browser/ui/gtk/gtk_theme_service.h +++ b/chrome/browser/ui/gtk/gtk_theme_service.h @@ -196,21 +196,21 @@ class GtkThemeService : public ThemeService { void FreeIconSets(); // Lazily generates each bitmap used in the gtk theme. - SkBitmap* GenerateGtkThemeBitmap(int id) const; + SkBitmap GenerateGtkThemeBitmap(int id) const; // Creates a GTK+ version of IDR_THEME_FRAME. Instead of tinting, this // creates a theme configurable gradient ending with |color_id| at the // bottom, and |gradient_name| at the top if that color is specified in the // theme. - SkBitmap* GenerateFrameImage(int color_id, - const char* gradient_name) const; + SkBitmap GenerateFrameImage(int color_id, + const char* gradient_name) const; // Takes the base frame image |base_id| and tints it with |tint_id|. - SkBitmap* GenerateTabImage(int base_id) const; + SkBitmap GenerateTabImage(int base_id) const; // Tints an icon based on tint. - SkBitmap* GenerateTintedIcon(int base_id, - const color_utils::HSL& tint) const; + SkBitmap GenerateTintedIcon(int base_id, + const color_utils::HSL& tint) const; // Returns the tint for buttons that contrasts with the normal window // background color. diff --git a/chrome/browser/ui/intents/web_intent_picker_controller.cc b/chrome/browser/ui/intents/web_intent_picker_controller.cc index 924f984..1802c56 100644 --- a/chrome/browser/ui/intents/web_intent_picker_controller.cc +++ b/chrome/browser/ui/intents/web_intent_picker_controller.cc @@ -529,7 +529,7 @@ void WebIntentPickerController::OnFaviconDataAvailable( if (gfx::PNGCodec::Decode(favicon_data.image_data->front(), favicon_data.image_data->size(), &icon_bitmap)) { - gfx::Image icon_image(new SkBitmap(icon_bitmap)); + gfx::Image icon_image(icon_bitmap); picker_model_->UpdateFaviconAt(index, icon_image); return; } @@ -633,7 +633,7 @@ void WebIntentPickerController::DecodeExtensionIconAndResize( icon_bitmap, skia::ImageOperations::RESIZE_BEST, gfx::kFaviconSize, gfx::kFaviconSize); - gfx::Image icon_image(new SkBitmap(resized_icon)); + gfx::Image icon_image(resized_icon); content::BrowserThread::PostTask( content::BrowserThread::UI, diff --git a/chrome/tools/profiles/generate_profile.cc b/chrome/tools/profiles/generate_profile.cc index 940b27d..c310879 100644 --- a/chrome/tools/profiles/generate_profile.cc +++ b/chrome/tools/profiles/generate_profile.cc @@ -181,9 +181,9 @@ void InsertURLBatch(Profile* profile, if (types & FULL_TEXT) history_service->SetPageContents(url, ConstructRandomPage()); if (types & TOP_SITES && top_sites) { - SkBitmap* bitmap = (RandomInt(0, 2) == 0) ? google_bitmap.get() : - weewar_bitmap.get(); - gfx::Image image(new SkBitmap(*bitmap)); + const SkBitmap& bitmap = (RandomInt(0, 2) == 0) ? *google_bitmap : + *weewar_bitmap; + gfx::Image image(bitmap); top_sites->SetPageThumbnail(url, &image, score); } 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_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; } |