summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-23 23:40:06 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-23 23:40:06 +0000
commit64954877e3e7fca9ffa936aee508ee338d78a293 (patch)
treeb192f9f00d51f4c4a2231a4d569c1b736b50974b /ui/gfx
parenta5061244d407a27683b36e4d1ed35d895722805d (diff)
downloadchromium_src-64954877e3e7fca9ffa936aee508ee338d78a293.zip
chromium_src-64954877e3e7fca9ffa936aee508ee338d78a293.tar.gz
chromium_src-64954877e3e7fca9ffa936aee508ee338d78a293.tar.bz2
Sets the proper device scale factor on iOS.
iOS sets a single supported scale factor at runtime, either 100P or 200P depending on whether the device is hidpi. This CL also corrects some conversion methods that did not properly support 200P scale factors. BUG=None TEST=Image unittests all pass on hidpi devices. Review URL: https://chromiumcodereview.appspot.com/11233040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163725 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/image/image_ios.mm17
-rw-r--r--ui/gfx/image/image_skia_util_ios.mm5
-rw-r--r--ui/gfx/image/image_unittest_util.cc13
-rw-r--r--ui/gfx/screen_ios.mm1
4 files changed, 32 insertions, 4 deletions
diff --git a/ui/gfx/image/image_ios.mm b/ui/gfx/image/image_ios.mm
index c8db540..cdc921d 100644
--- a/ui/gfx/image/image_ios.mm
+++ b/ui/gfx/image/image_ios.mm
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/memory/scoped_nsobject.h"
+#include "ui/base/layout.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_util_ios.h"
@@ -25,12 +26,24 @@ void PNGFromUIImage(UIImage* uiimage, std::vector<unsigned char>* png) {
}
UIImage* CreateUIImageFromPNG(const std::vector<unsigned char>& png) {
+ // iOS only supports one scale factor.
+ std::vector<ui::ScaleFactor> supported_scale_factors =
+ ui::GetSupportedScaleFactors();
+ DCHECK_EQ(1U, supported_scale_factors.size());
+ if (supported_scale_factors.size() < 1)
+ return nil;
+
+ ui::ScaleFactor scale_factor = supported_scale_factors[0];
+ float scale = ui::GetScaleFactorScale(scale_factor);
+
NSData* data = [NSData dataWithBytes:&png.front() length:png.size()];
- scoped_nsobject<UIImage> image ([[UIImage alloc] initWithData:data]);
+ scoped_nsobject<UIImage> image (
+ [[UIImage alloc] initWithData:data scale:scale]);
if (!image) {
LOG(WARNING) << "Unable to decode PNG into UIImage.";
// Return a 16x16 red image to visually show error.
- UIGraphicsBeginImageContext(CGSizeMake(16, 16));
+ BOOL opaque = YES;
+ UIGraphicsBeginImageContextWithOptions(CGSizeMake(16, 16), opaque, scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextFillRect(context, CGRectMake(0.0, 0.0, 16, 16));
diff --git a/ui/gfx/image/image_skia_util_ios.mm b/ui/gfx/image/image_skia_util_ios.mm
index 47f076f..d9888d4 100644
--- a/ui/gfx/image/image_skia_util_ios.mm
+++ b/ui/gfx/image/image_skia_util_ios.mm
@@ -48,12 +48,15 @@ UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) {
if (supported_scale_factors.size() < 1)
return nil;
+ ui::ScaleFactor scale_factor = supported_scale_factors[0];
+ float scale = ui::GetScaleFactorScale(scale_factor);
image_skia.EnsureRepsForSupportedScaleFactors();
const ImageSkiaRep& rep =
image_skia.GetRepresentation(supported_scale_factors[0]);
base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space(
CGColorSpaceCreateDeviceRGB());
- return gfx::SkBitmapToUIImageWithColorSpace(rep.sk_bitmap(), color_space);
+ return gfx::SkBitmapToUIImageWithColorSpace(rep.sk_bitmap(), scale,
+ color_space);
}
} // namespace gfx
diff --git a/ui/gfx/image/image_unittest_util.cc b/ui/gfx/image/image_unittest_util.cc
index 3dd5b60..fc4b6cf 100644
--- a/ui/gfx/image/image_unittest_util.cc
+++ b/ui/gfx/image/image_unittest_util.cc
@@ -84,9 +84,20 @@ bool IsEmpty(const gfx::Image& image) {
PlatformImage CreatePlatformImage() {
const SkBitmap bitmap(CreateBitmap(25, 25));
#if defined(OS_IOS)
+ // iOS only supports one scale factor.
+ std::vector<ui::ScaleFactor> supported_scale_factors =
+ ui::GetSupportedScaleFactors();
+ DCHECK_EQ(1U, supported_scale_factors.size());
+ if (supported_scale_factors.size() < 1)
+ return nil;
+
+ ui::ScaleFactor scale_factor = supported_scale_factors[0];
+ float scale = ui::GetScaleFactorScale(scale_factor);
+
base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space(
CGColorSpaceCreateDeviceRGB());
- UIImage* image = gfx::SkBitmapToUIImageWithColorSpace(bitmap, color_space);
+ UIImage* image =
+ gfx::SkBitmapToUIImageWithColorSpace(bitmap, scale, color_space);
base::mac::NSObjectRetain(image);
return image;
#elif defined(OS_MACOSX)
diff --git a/ui/gfx/screen_ios.mm b/ui/gfx/screen_ios.mm
index 6357b98..d1572af 100644
--- a/ui/gfx/screen_ios.mm
+++ b/ui/gfx/screen_ios.mm
@@ -60,6 +60,7 @@ class ScreenIos : public gfx::Screen {
virtual gfx::Display GetPrimaryDisplay() const OVERRIDE {
UIScreen* mainScreen = [[UIScreen screens] objectAtIndex:0];
gfx::Display display(0, gfx::Rect(mainScreen.bounds));
+ display.set_device_scale_factor([mainScreen scale]);
return display;
}
};