forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ImageSkia is 1:1 to NSImage. This patch adds conversions between Imag…
…eSkia and NSImage instead of SkBitmap wherever possible Renamed image_mac to image_skia_util_mac. Moved AppplicationIconAtSize from skia_utils_mac to image_skia_util_mac BUG=132327 TEST=Chromium task manager icon shows up not blurry when chromium is run in High DPI mode on Mac. Review URL: https://chromiumcodereview.appspot.com/10532102 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142153 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
pkotwicz@chromium.org
committed
Jun 14, 2012
1 parent
5553254
commit 0c40064
Showing
13 changed files
with
136 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_GFX_IMAGE_IMAGE_SKIA_UTIL_MAC_H_ | ||
#define UI_GFX_IMAGE_IMAGE_SKIA_UTIL_MAC_H_ | ||
#pragma once | ||
|
||
#include "ui/base/ui_export.h" | ||
|
||
#ifdef __LP64__ | ||
typedef CGSize NSSize; | ||
#else | ||
typedef struct _NSSize NSSize; | ||
#endif | ||
|
||
#ifdef __OBJC__ | ||
@class NSImage; | ||
#else | ||
class NSImage; | ||
#endif | ||
|
||
namespace gfx { | ||
class ImageSkia; | ||
|
||
// Converts to ImageSkia from NSImage. | ||
UI_EXPORT gfx::ImageSkia ImageSkiaFromNSImage(NSImage* image); | ||
|
||
// Resizes NSImage to |size| DIP and then converts to ImageSkia. | ||
UI_EXPORT gfx::ImageSkia ImageSkiaFromResizedNSImage(NSImage* image, | ||
NSSize size); | ||
|
||
// Resizes |[NSImage imageNamed:@NSApplicationIcon]| to have edge width of | ||
// |size| DIP and returns result as ImageSkia. | ||
UI_EXPORT gfx::ImageSkia ApplicationIconAtSize(int size); | ||
|
||
// Converts to NSImage from ImageSkia. | ||
UI_EXPORT NSImage* NSImageFromImageSkia(const gfx::ImageSkia& image_skia); | ||
|
||
} // namespace gfx | ||
|
||
#endif // UI_GFX_IMAGE_IMAGE_SKIA_UTIL_MAC_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ui/gfx/image/image_skia_util_mac.h" | ||
|
||
#import <AppKit/AppKit.h> | ||
|
||
#include "base/mac/mac_util.h" | ||
#include "base/memory/scoped_nsobject.h" | ||
#include "base/memory/scoped_ptr.h" | ||
#include "skia/ext/skia_utils_mac.h" | ||
#include "third_party/skia/include/core/SkBitmap.h" | ||
#include "ui/gfx/image/image_skia.h" | ||
|
||
namespace gfx { | ||
|
||
gfx::ImageSkia ImageSkiaFromNSImage(NSImage* image) { | ||
return ImageSkiaFromResizedNSImage(image, [image size]); | ||
} | ||
|
||
gfx::ImageSkia ImageSkiaFromResizedNSImage(NSImage* image, | ||
NSSize desired_size) { | ||
// Resize and convert to ImageSkia simultaneously to save on computation. | ||
// TODO(pkotwicz): Separate resizing NSImage and converting to ImageSkia. | ||
float resize_scale_x = desired_size.width / [image size].width; | ||
float resize_scale_y = desired_size.height / [image size].height; | ||
|
||
gfx::ImageSkia image_skia; | ||
for (NSImageRep* image_rep in [image representations]) { | ||
NSSize image_rep_size = NSMakeSize([image_rep pixelsWide] * resize_scale_x, | ||
[image_rep pixelsHigh] * resize_scale_y); | ||
SkBitmap bitmap(gfx::NSImageRepToSkBitmap(image_rep, image_rep_size, | ||
false)); | ||
if (!bitmap.isNull() && !bitmap.empty()) { | ||
float scale_factor = image_rep_size.width / desired_size.width; | ||
image_skia.AddBitmapForScale(bitmap, scale_factor); | ||
} | ||
} | ||
return image_skia; | ||
} | ||
|
||
gfx::ImageSkia ApplicationIconAtSize(int desired_size) { | ||
NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | ||
return ImageSkiaFromResizedNSImage(image, | ||
NSMakeSize(desired_size, desired_size)); | ||
} | ||
|
||
NSImage* NSImageFromImageSkia(const gfx::ImageSkia& image_skia) { | ||
if (image_skia.empty()) | ||
return nil; | ||
|
||
scoped_nsobject<NSImage> image([[NSImage alloc] init]); | ||
|
||
const std::vector<SkBitmap> bitmaps = image_skia.bitmaps(); | ||
for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); | ||
it != bitmaps.end(); ++it) { | ||
[image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)]; | ||
} | ||
|
||
[image setSize:NSMakeSize(image_skia.width(), image_skia.height())]; | ||
return [image.release() autorelease]; | ||
} | ||
|
||
} // namespace gfx |
Oops, something went wrong.