diff options
author | Chris Loer <chris.loer@gmail.com> | 2017-11-28 13:42:43 -0800 |
---|---|---|
committer | Chris Loer <chris.loer@gmail.com> | 2017-11-28 13:42:43 -0800 |
commit | e5c4d9653dd2d34c4c7809c7ca3e429adb151ed4 (patch) | |
tree | fab60f7af7ac39c28acdb1b785802d29ef69fa26 | |
parent | 8e5542812ec9335f160401a5f2123383b3823b4c (diff) | |
download | qtlocation-mapboxgl-e5c4d9653dd2d34c4c7809c7ca3e429adb151ed4.tar.gz |
Share CFHandle code between image.mm and local_glyph_rasterizer.mm
-rw-r--r-- | platform/darwin/src/CFHandle.hpp | 27 | ||||
-rw-r--r-- | platform/darwin/src/image.mm | 21 | ||||
-rw-r--r-- | platform/darwin/src/local_glyph_rasterizer.mm | 28 | ||||
-rw-r--r-- | platform/ios/config.cmake | 1 | ||||
-rw-r--r-- | platform/macos/config.cmake | 1 |
5 files changed, 35 insertions, 43 deletions
diff --git a/platform/darwin/src/CFHandle.hpp b/platform/darwin/src/CFHandle.hpp new file mode 100644 index 0000000000..b87b8c696f --- /dev/null +++ b/platform/darwin/src/CFHandle.hpp @@ -0,0 +1,27 @@ + +namespace { + +template <typename T, typename S, void (*Releaser)(S)> +struct CFHandle { + CFHandle(T t_): t(t_) {} + ~CFHandle() { Releaser(t); } + T operator*() { return t; } + operator bool() { return t; } +private: + T t; +}; + +using CGImageHandle = CFHandle<CGImageRef, CGImageRef, CGImageRelease>; +using CFDataHandle = CFHandle<CFDataRef, CFTypeRef, CFRelease>; +using CGImageSourceHandle = CFHandle<CGImageSourceRef, CFTypeRef, CFRelease>; +using CGDataProviderHandle = CFHandle<CGDataProviderRef, CGDataProviderRef, CGDataProviderRelease>; +using CGColorSpaceHandle = CFHandle<CGColorSpaceRef, CGColorSpaceRef, CGColorSpaceRelease>; +using CGContextHandle = CFHandle<CGContextRef, CGContextRef, CGContextRelease>; + +using CFStringRefHandle = CFHandle<CFStringRef, CFTypeRef, CFRelease>; +using CFAttributedStringRefHandle = CFHandle<CFAttributedStringRef, CFTypeRef, CFRelease>; +using CFDictionaryRefHandle = CFHandle<CFDictionaryRef, CFTypeRef, CFRelease>; + + +} // namespace + diff --git a/platform/darwin/src/image.mm b/platform/darwin/src/image.mm index 57b680fbdb..7065545763 100644 --- a/platform/darwin/src/image.mm +++ b/platform/darwin/src/image.mm @@ -2,26 +2,7 @@ #import <ImageIO/ImageIO.h> -namespace { - -template <typename T, typename S, void (*Releaser)(S)> -struct CFHandle { - CFHandle(T t_): t(t_) {} - ~CFHandle() { Releaser(t); } - T operator*() { return t; } - operator bool() { return t; } -private: - T t; -}; - -} // namespace - -using CGImageHandle = CFHandle<CGImageRef, CGImageRef, CGImageRelease>; -using CFDataHandle = CFHandle<CFDataRef, CFTypeRef, CFRelease>; -using CGImageSourceHandle = CFHandle<CGImageSourceRef, CFTypeRef, CFRelease>; -using CGDataProviderHandle = CFHandle<CGDataProviderRef, CGDataProviderRef, CGDataProviderRelease>; -using CGColorSpaceHandle = CFHandle<CGColorSpaceRef, CGColorSpaceRef, CGColorSpaceRelease>; -using CGContextHandle = CFHandle<CGContextRef, CGContextRef, CGContextRelease>; +#import "CFHandle.hpp" CGImageRef CGImageFromMGLPremultipliedImage(mbgl::PremultipliedImage&& src) { // We're converting the PremultipliedImage's backing store to a CGDataProvider, and are taking diff --git a/platform/darwin/src/local_glyph_rasterizer.mm b/platform/darwin/src/local_glyph_rasterizer.mm index fa5d1a9302..944fca48c3 100644 --- a/platform/darwin/src/local_glyph_rasterizer.mm +++ b/platform/darwin/src/local_glyph_rasterizer.mm @@ -5,32 +5,10 @@ #import <CoreText/CoreText.h> #import <ImageIO/ImageIO.h> -namespace { - -template <typename T, typename S, void (*Releaser)(S)> -struct CFHandle { - CFHandle(T t_): t(t_) {} - ~CFHandle() { Releaser(t); } - T operator*() { return t; } - operator bool() { return t; } -private: - T t; -}; - -} // namespace - +#import "CFHandle.hpp" namespace mbgl { -using CGContextHandle = CFHandle<CGContextRef, CGContextRef, CGContextRelease>; -using CGColorSpaceHandle = CFHandle<CGColorSpaceRef, CGColorSpaceRef, CGColorSpaceRelease>; -using CTFontDescriptorRefHandle = CFHandle<CTFontDescriptorRef, CFTypeRef, CFRelease>; -using CTFontRefHandle = CFHandle<CTFontRef, CFTypeRef, CFRelease>; -using CFStringRefHandle = CFHandle<CFStringRef, CFTypeRef, CFRelease>; -using CFAttributedStringRefHandle = CFHandle<CFAttributedStringRef, CFTypeRef, CFRelease>; -using CTLineRefHandle = CFHandle<CTLineRef, CFTypeRef, CFRelease>; -using CFDictionaryRefHandle = CFHandle<CFDictionaryRef, CFTypeRef, CFRelease>; - /* Initial implementation of darwin TinySDF support: Draw any CJK glyphs using a default system font @@ -43,6 +21,10 @@ using CFDictionaryRefHandle = CFHandle<CFDictionaryRef, CFTypeRef, CFRelease>; - Extract glyph metrics so that this can be used with more than just fixed width glyphs */ +using CTFontDescriptorRefHandle = CFHandle<CTFontDescriptorRef, CFTypeRef, CFRelease>; +using CTFontRefHandle = CFHandle<CTFontRef, CFTypeRef, CFRelease>; +using CTLineRefHandle = CFHandle<CTLineRef, CFTypeRef, CFRelease>; + class LocalGlyphRasterizer::Impl { public: Impl(CTFontRef fontHandle) diff --git a/platform/ios/config.cmake b/platform/ios/config.cmake index 2cc16bbbc2..0cfc86d548 100644 --- a/platform/ios/config.cmake +++ b/platform/ios/config.cmake @@ -28,6 +28,7 @@ macro(mbgl_platform_core) # Misc PRIVATE platform/darwin/mbgl/storage/reachability.h PRIVATE platform/darwin/mbgl/storage/reachability.m + PRIVATE platform/darwin/src/CFHandle.hpp PRIVATE platform/darwin/src/local_glyph_rasterizer.mm PRIVATE platform/darwin/src/logging_nslog.mm PRIVATE platform/darwin/src/nsthread.mm diff --git a/platform/macos/config.cmake b/platform/macos/config.cmake index 21663885d4..8646a79071 100644 --- a/platform/macos/config.cmake +++ b/platform/macos/config.cmake @@ -14,6 +14,7 @@ macro(mbgl_platform_core) # Misc PRIVATE platform/darwin/mbgl/storage/reachability.h PRIVATE platform/darwin/mbgl/storage/reachability.m + PRIVATE platform/darwin/src/CFHandle.hpp PRIVATE platform/darwin/src/local_glyph_rasterizer.mm PRIVATE platform/darwin/src/logging_nslog.mm PRIVATE platform/darwin/src/nsthread.mm |