Commit 90031d95 authored by stkhapugin's avatar stkhapugin Committed by Commit bot

Adds a new constructor for gfx::Image on iOS.

Chrome iOS is moving to Objective-C Automatic Reference Counting. Under
it, arguments are supposed to be autoreleased. This CL adds a new
constructor that can take both a retained and an autoreleased object.
This is a part of a multiple CL setup that will change the Image(UIImage*) constructor from consuming +1 refcount to retaining the argument.

TEST=none
BUG=645125

Review-Url: https://codereview.chromium.org/2504683002
Cr-Commit-Position: refs/heads/master@{#437513}
parent 089ec1a2
...@@ -61,7 +61,7 @@ void ImageFetcherImpl::StartOrQueueNetworkRequest( ...@@ -61,7 +61,7 @@ void ImageFetcherImpl::StartOrQueueNetworkRequest(
// Most likely always returns 1x images. // Most likely always returns 1x images.
UIImage* ui_image = [UIImage imageWithData:data scale:1]; UIImage* ui_image = [UIImage imageWithData:data scale:1];
if (ui_image) { if (ui_image) {
gfx::Image gfx_image(ui_image); gfx::Image gfx_image(ui_image, base::scoped_policy::ASSUME);
callback.Run(fetch_id, gfx_image); callback.Run(fetch_id, gfx_image);
if (delegate_) { if (delegate_) {
delegate_->OnImageFetched(fetch_id, gfx_image); delegate_->OnImageFetched(fetch_id, gfx_image);
......
...@@ -148,7 +148,7 @@ void IOSImageDecoderImpl::CreateUIImageAndRunCallback( ...@@ -148,7 +148,7 @@ void IOSImageDecoderImpl::CreateUIImageAndRunCallback(
// This constructor does not retain the image, but expects to take the // This constructor does not retain the image, but expects to take the
// ownership, therefore, |ui_image| is retained here, but not released // ownership, therefore, |ui_image| is retained here, but not released
// afterwards. // afterwards.
gfx::Image gfx_image([ui_image retain]); gfx::Image gfx_image(ui_image, base::scoped_policy::RETAIN);
callback.Run(gfx_image); callback.Run(gfx_image);
return; return;
} }
......
...@@ -163,7 +163,7 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { ...@@ -163,7 +163,7 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
} }
// The gfx::Image takes ownership. // The gfx::Image takes ownership.
image = gfx::Image(ui_image.release()); image = gfx::Image(ui_image, base::scoped_policy::RETAIN);
} }
base::AutoLock lock(*images_and_fonts_lock_); base::AutoLock lock(*images_and_fonts_lock_);
......
...@@ -420,10 +420,15 @@ Image::Image(const ImageSkia& image) { ...@@ -420,10 +420,15 @@ Image::Image(const ImageSkia& image) {
} }
#if defined(OS_IOS) #if defined(OS_IOS)
Image::Image(UIImage* image) Image::Image(UIImage* image) : Image(image, base::scoped_policy::ASSUME) {}
Image::Image(UIImage* image, base::scoped_policy::OwnershipPolicy policy)
: storage_(new internal::ImageStorage(Image::kImageRepCocoaTouch)) { : storage_(new internal::ImageStorage(Image::kImageRepCocoaTouch)) {
if (image) if (image) {
if (policy == base::scoped_policy::RETAIN)
base::mac::NSObjectRetain(image);
AddRepresentation(base::MakeUnique<internal::ImageRepCocoaTouch>(image)); AddRepresentation(base::MakeUnique<internal::ImageRepCocoaTouch>(image));
}
} }
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
Image::Image(NSImage* image) { Image::Image(NSImage* image) {
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <vector> #include <vector>
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_policy.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/gfx/gfx_export.h" #include "ui/gfx/gfx_export.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
...@@ -72,6 +73,10 @@ class GFX_EXPORT Image { ...@@ -72,6 +73,10 @@ class GFX_EXPORT Image {
#if defined(OS_IOS) #if defined(OS_IOS)
// Does not retain |image|; expects to take ownership. // Does not retain |image|; expects to take ownership.
explicit Image(UIImage* image); explicit Image(UIImage* image);
// Retains argument according to |policy|.
Image(UIImage* image, base::scoped_policy::OwnershipPolicy policy);
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
// Does not retain |image|; expects to take ownership. // Does not retain |image|; expects to take ownership.
// A single NSImage object can contain multiple bitmaps so there's no reason // A single NSImage object can contain multiple bitmaps so there's no reason
......
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