Commit f0bdf1c7 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Remove gfx::Image's Copy* methods.

They return ownership via raw pointer, and they're unneeded.

Also remove AsUIImage as it has no callers.

BUG=904645

Change-Id: I18497ae1e32ad36ec78cdcf3c5df07d0faf8af39
Reviewed-on: https://chromium-review.googlesource.com/c/1333876
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608601}
parent 86ecac87
......@@ -127,7 +127,7 @@ void BackgroundApplicationListModel::Application::OnImageLoaded(
const gfx::Image& image) {
if (image.IsEmpty())
return;
icon_.reset(image.CopyImageSkia());
icon_.reset(new gfx::ImageSkia(*image.ToImageSkia()));
model_->SendApplicationDataChangedNotifications();
}
......
......@@ -301,10 +301,9 @@ gfx::ImageSkia GetBookmarkFolderIcon(SkColor text_color) {
int resource_id = color_utils::IsDark(text_color)
? IDR_BOOKMARK_BAR_FOLDER
: IDR_BOOKMARK_BAR_FOLDER_WHITE;
std::unique_ptr<gfx::ImageSkia> image(ui::ResourceBundle::GetSharedInstance()
.GetNativeImageNamed(resource_id)
.CopyImageSkia());
return *image.get();
return *ui::ResourceBundle::GetSharedInstance()
.GetNativeImageNamed(resource_id)
.ToImageSkia();
#else
return GetFolderIcon(ui::MaterialDesignController::touch_ui()
? vector_icons::kFolderTouchIcon
......
......@@ -100,7 +100,7 @@ void BookmarkMenuBridge::BuildRootMenu() {
if (!folder_image_) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
folder_image_.reset(
rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage());
[rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).ToNSImage() retain]);
[folder_image_ setTemplate:YES];
}
......
......@@ -94,7 +94,7 @@ HistoryMenuBridge::HistoryMenuBridge(Profile* profile)
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
default_favicon_.reset(
rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
[rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage() retain]);
// Set the static icons in the menu.
NSMenuItem* item = [HistoryMenu() itemWithTag:IDC_SHOW_HISTORY];
......
......@@ -174,7 +174,7 @@ NSString* const kRemindersSharingServiceName =
browserView->ConvertRectToWidget(contentsView->bounds());
gfx::Image image;
if (ui::GrabWindowSnapshot(windowForShare_, rectInWidget, &image)) {
snapshotForShare_.reset(image.CopyNSImage());
snapshotForShare_.reset([image.ToNSImage() retain]);
}
}
......
......@@ -580,39 +580,12 @@ ImageSkia Image::AsImageSkia() const {
return IsEmpty() ? ImageSkia() : *ToImageSkia();
}
#if defined(OS_IOS)
UIImage* Image::AsUIImage() const {
return IsEmpty() ? nil : ToUIImage();
}
#elif defined(OS_MACOSX)
#if defined(OS_MACOSX) && !defined(OS_IOS)
NSImage* Image::AsNSImage() const {
return IsEmpty() ? nil : ToNSImage();
}
#endif
scoped_refptr<base::RefCountedMemory> Image::Copy1xPNGBytes() const {
scoped_refptr<base::RefCountedMemory> original = As1xPNGBytes();
scoped_refptr<base::RefCountedBytes> copy(new base::RefCountedBytes());
copy->data().assign(original->front(), original->front() + original->size());
return copy;
}
ImageSkia* Image::CopyImageSkia() const {
return new ImageSkia(*ToImageSkia());
}
SkBitmap* Image::CopySkBitmap() const {
return new SkBitmap(*ToSkBitmap());
}
#if defined(OS_MACOSX) && !defined(OS_IOS)
NSImage* Image::CopyNSImage() const {
NSImage* image = ToNSImage();
base::mac::NSObjectRetain(image);
return image;
}
#endif
bool Image::HasRepresentation(RepresentationType type) const {
return storage() && storage()->HasRepresentation(type);
}
......
......@@ -134,24 +134,9 @@ class GFX_EXPORT Image {
// image is empty.
ImageSkia AsImageSkia() const;
// Same as ToSkBitmap(), but returns nil if this image is empty.
#if defined(OS_IOS)
UIImage* AsUIImage() const;
#elif defined(OS_MACOSX)
NSImage* AsNSImage() const;
#endif
// Performs a conversion, like above, but returns a copy of the result rather
// than a weak pointer. The caller is responsible for deleting the result.
// Note that the result is only a copy in terms of memory management; the
// backing pixels are shared amongst all copies (a fact of each of the
// converted representations, rather than a limitation imposed by Image) and
// so the result should be considered immutable.
scoped_refptr<base::RefCountedMemory> Copy1xPNGBytes() const;
ImageSkia* CopyImageSkia() const;
SkBitmap* CopySkBitmap() const;
// Same as ToNSImage(), but returns nil if this image is empty.
#if defined(OS_MACOSX) && !defined(OS_IOS)
NSImage* CopyNSImage() const;
NSImage* AsNSImage() const;
#endif
// Inspects the representations map to see if the given type exists.
......
......@@ -129,7 +129,8 @@ gfx::Image ImageFamily::CreateExact(int width, int height) const {
// is not racy to |image|. Since this function can run on a different thread
// than the thread |image| created on, we should not touch the
// non-thread-safe ref count in gfx::Image here.
std::unique_ptr<gfx::ImageSkia> image_skia(image->CopyImageSkia());
std::unique_ptr<gfx::ImageSkia> image_skia(
new gfx::ImageSkia(*image->ToImageSkia()));
return gfx::Image(*image_skia);
}
......
......@@ -435,41 +435,6 @@ TEST_F(ImageTest, PlatformToPlatform) {
EXPECT_EQ(25, image.Height());
}
TEST_F(ImageTest, PlatformToSkiaToCopy) {
const gfx::ImageSkia* image_skia = NULL;
{
gfx::Image image(gt::CreatePlatformImage());
image_skia = image.CopyImageSkia();
}
EXPECT_TRUE(image_skia);
EXPECT_FALSE(image_skia->isNull());
delete image_skia;
const SkBitmap* bitmap = NULL;
{
gfx::Image image(gt::CreatePlatformImage());
bitmap = image.CopySkBitmap();
}
EXPECT_TRUE(bitmap);
EXPECT_FALSE(bitmap->isNull());
delete bitmap;
}
#if defined(OS_MACOSX) && !defined(OS_IOS)
TEST_F(ImageTest, SkiaToCocoaCopy) {
NSImage* ns_image;
{
gfx::Image image(gt::CreateImageSkia(25, 25));
ns_image = image.CopyNSImage();
}
EXPECT_TRUE(ns_image);
base::mac::NSObjectRelease(ns_image);
}
#endif
TEST_F(ImageTest, CheckSkiaColor) {
gfx::Image image(gt::CreatePlatformImage());
......
......@@ -38,7 +38,8 @@ const gfx::ImageSkia CreateSolidColorImage(int width,
gfx::Image DeepCopyImage(const gfx::Image& image) {
if (image.IsEmpty())
return gfx::Image();
std::unique_ptr<gfx::ImageSkia> image_skia(image.CopyImageSkia());
std::unique_ptr<gfx::ImageSkia> image_skia(
new gfx::ImageSkia(*image.ToImageSkia()));
return gfx::Image(*image_skia);
}
......
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