OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SKIA_EXT_SKIA_UTILS_MAC_H_ | 5 #ifndef SKIA_EXT_SKIA_UTILS_MAC_H_ |
6 #define SKIA_EXT_SKIA_UTILS_MAC_H_ | 6 #define SKIA_EXT_SKIA_UTILS_MAC_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <ApplicationServices/ApplicationServices.h> | 9 #include <ApplicationServices/ApplicationServices.h> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
14 | 14 |
15 struct SkIRect; | 15 struct SkIRect; |
16 struct SkPoint; | 16 struct SkPoint; |
17 struct SkRect; | 17 struct SkRect; |
18 class SkCanvas; | 18 class SkCanvas; |
19 class SkMatrix; | 19 class SkMatrix; |
20 #ifdef __LP64__ | 20 #ifdef __LP64__ |
21 typedef CGSize NSSize; | 21 typedef CGSize NSSize; |
22 #else | 22 #else |
23 typedef struct _NSSize NSSize; | 23 typedef struct _NSSize NSSize; |
24 #endif | 24 #endif |
25 | 25 |
26 #ifdef __OBJC__ | 26 #ifdef __OBJC__ |
| 27 @class NSBitmapImageRep; |
27 @class NSImage; | 28 @class NSImage; |
28 @class NSImageRep; | 29 @class NSImageRep; |
29 @class NSColor; | 30 @class NSColor; |
30 #else | 31 #else |
| 32 class NSBitmapImageRep; |
31 class NSImage; | 33 class NSImage; |
32 class NSImageRep; | 34 class NSImageRep; |
33 class NSColor; | 35 class NSColor; |
34 #endif | 36 #endif |
35 | 37 |
36 namespace gfx { | 38 namespace gfx { |
37 | 39 |
38 // Converts a Skia point to a CoreGraphics CGPoint. | 40 // Converts a Skia point to a CoreGraphics CGPoint. |
39 // Both use same in-memory format. | 41 // Both use same in-memory format. |
40 inline const CGPoint& SkPointToCGPoint(const SkPoint& point) { | 42 inline const CGPoint& SkPointToCGPoint(const SkPoint& point) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Converts a CGImage to a SkBitmap. | 76 // Converts a CGImage to a SkBitmap. |
75 SK_API SkBitmap CGImageToSkBitmap(CGImageRef image); | 77 SK_API SkBitmap CGImageToSkBitmap(CGImageRef image); |
76 | 78 |
77 // Draws an NSImage with a given size into a SkBitmap. | 79 // Draws an NSImage with a given size into a SkBitmap. |
78 SK_API SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque); | 80 SK_API SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque); |
79 | 81 |
80 // Draws an NSImageRep with a given size into a SkBitmap. | 82 // Draws an NSImageRep with a given size into a SkBitmap. |
81 SK_API SkBitmap NSImageRepToSkBitmap( | 83 SK_API SkBitmap NSImageRepToSkBitmap( |
82 NSImageRep* image, NSSize size, bool is_opaque); | 84 NSImageRep* image, NSSize size, bool is_opaque); |
83 | 85 |
| 86 // Given an SkBitmap, return an autoreleased NSBitmapImageRep in the generic |
| 87 // color space. |
| 88 SK_API NSBitmapImageRep* SkBitmapToNSBitmapImageRep(const SkBitmap& image); |
| 89 |
84 // Given an SkBitmap and a color space, return an autoreleased NSImage. | 90 // Given an SkBitmap and a color space, return an autoreleased NSImage. |
85 SK_API NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& icon, | 91 SK_API NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& icon, |
86 CGColorSpaceRef colorSpace); | 92 CGColorSpaceRef colorSpace); |
87 | 93 |
88 // Given an SkBitmap, return an autoreleased NSImage in the generic color space. | 94 // Given an SkBitmap, return an autoreleased NSImage in the generic color space. |
89 // DEPRECATED, use SkBitmapToNSImageWithColorSpace() instead. | 95 // DEPRECATED, use SkBitmapToNSImageWithColorSpace() instead. |
90 // TODO(thakis): Remove this -- http://crbug.com/69432 | 96 // TODO(thakis): Remove this -- http://crbug.com/69432 |
91 SK_API NSImage* SkBitmapToNSImage(const SkBitmap& icon); | 97 SK_API NSImage* SkBitmapToNSImage(const SkBitmap& icon); |
92 | 98 |
93 // Given a vector of SkBitmaps, return an NSImage with each bitmap added | |
94 // as a representation. | |
95 SK_API NSImage* SkBitmapsToNSImage(const std::vector<const SkBitmap*>& bitmaps); | |
96 | |
97 // Returns |[NSImage imageNamed:@"NSApplicationIcon"]| as SkBitmap. | 99 // Returns |[NSImage imageNamed:@"NSApplicationIcon"]| as SkBitmap. |
98 SK_API SkBitmap AppplicationIconAtSize(int size); | 100 SK_API SkBitmap AppplicationIconAtSize(int size); |
99 | 101 |
100 // Converts a SkCanvas temporarily to a CGContext | 102 // Converts a SkCanvas temporarily to a CGContext |
101 class SK_API SkiaBitLocker { | 103 class SK_API SkiaBitLocker { |
102 public: | 104 public: |
103 explicit SkiaBitLocker(SkCanvas* canvas); | 105 explicit SkiaBitLocker(SkCanvas* canvas); |
104 ~SkiaBitLocker(); | 106 ~SkiaBitLocker(); |
105 CGContextRef cgContext(); | 107 CGContextRef cgContext(); |
106 | 108 |
107 private: | 109 private: |
108 void releaseIfNeeded(); | 110 void releaseIfNeeded(); |
109 SkCanvas* canvas_; | 111 SkCanvas* canvas_; |
110 CGContextRef cgContext_; | 112 CGContextRef cgContext_; |
111 SkBitmap bitmap_; | 113 SkBitmap bitmap_; |
112 bool useDeviceBits_; | 114 bool useDeviceBits_; |
113 }; | 115 }; |
114 | 116 |
115 | 117 |
116 } // namespace gfx | 118 } // namespace gfx |
117 | 119 |
118 #endif // SKIA_EXT_SKIA_UTILS_MAC_H_ | 120 #endif // SKIA_EXT_SKIA_UTILS_MAC_H_ |
OLD | NEW |