From e5c4d9653dd2d34c4c7809c7ca3e429adb151ed4 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Tue, 28 Nov 2017 13:42:43 -0800 Subject: Share CFHandle code between image.mm and local_glyph_rasterizer.mm --- platform/darwin/src/CFHandle.hpp | 27 ++++++++++++++++++++++++++ platform/darwin/src/image.mm | 21 +------------------- platform/darwin/src/local_glyph_rasterizer.mm | 28 +++++---------------------- platform/ios/config.cmake | 1 + platform/macos/config.cmake | 1 + 5 files changed, 35 insertions(+), 43 deletions(-) create mode 100644 platform/darwin/src/CFHandle.hpp 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 +struct CFHandle { + CFHandle(T t_): t(t_) {} + ~CFHandle() { Releaser(t); } + T operator*() { return t; } + operator bool() { return t; } +private: + T t; +}; + +using CGImageHandle = CFHandle; +using CFDataHandle = CFHandle; +using CGImageSourceHandle = CFHandle; +using CGDataProviderHandle = CFHandle; +using CGColorSpaceHandle = CFHandle; +using CGContextHandle = CFHandle; + +using CFStringRefHandle = CFHandle; +using CFAttributedStringRefHandle = CFHandle; +using CFDictionaryRefHandle = CFHandle; + + +} // 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 -namespace { - -template -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; -using CFDataHandle = CFHandle; -using CGImageSourceHandle = CFHandle; -using CGDataProviderHandle = CFHandle; -using CGColorSpaceHandle = CFHandle; -using CGContextHandle = CFHandle; +#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 #import -namespace { - -template -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; -using CGColorSpaceHandle = CFHandle; -using CTFontDescriptorRefHandle = CFHandle; -using CTFontRefHandle = CFHandle; -using CFStringRefHandle = CFHandle; -using CFAttributedStringRefHandle = CFHandle; -using CTLineRefHandle = CFHandle; -using CFDictionaryRefHandle = CFHandle; - /* Initial implementation of darwin TinySDF support: Draw any CJK glyphs using a default system font @@ -43,6 +21,10 @@ using CFDictionaryRefHandle = CFHandle; - Extract glyph metrics so that this can be used with more than just fixed width glyphs */ +using CTFontDescriptorRefHandle = CFHandle; +using CTFontRefHandle = CFHandle; +using CTLineRefHandle = CFHandle; + 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 -- cgit v1.2.1