diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2018-10-08 19:04:17 +0300 |
---|---|---|
committer | Aleksey Belousov <beloal@users.noreply.github.com> | 2018-10-09 12:03:36 +0300 |
commit | 7eb4c7871e8d09812eae74452c5718bdd9ec797d (patch) | |
tree | 124c47faf7ad8e5637857a7d223691c7e2edf862 | |
parent | f28560ac36899ef8694e75a36535b0f1487b285b (diff) |
Refactored MetalViewpykmlib-0.0.3
-rw-r--r-- | iphone/Maps/Classes/EAGLView.h | 2 | ||||
-rw-r--r-- | iphone/Maps/Classes/EAGLView.mm | 83 | ||||
-rw-r--r-- | iphone/Maps/Classes/MetalContextFactory.h | 4 | ||||
-rw-r--r-- | iphone/Maps/Classes/MetalContextFactory.mm | 3 | ||||
-rw-r--r-- | iphone/Maps/Maps.xcodeproj/project.pbxproj | 6 | ||||
-rw-r--r-- | iphone/Maps/UI/Storyboard/Main.storyboard | 23 |
6 files changed, 58 insertions, 63 deletions
diff --git a/iphone/Maps/Classes/EAGLView.h b/iphone/Maps/Classes/EAGLView.h index 7fc2449983..72ab0df68d 100644 --- a/iphone/Maps/Classes/EAGLView.h +++ b/iphone/Maps/Classes/EAGLView.h @@ -1,7 +1,6 @@ #include "drape/pointers.hpp" #include "drape/drape_global.hpp" -@class MetalView; @class MWMMapWidgets; namespace dp @@ -23,7 +22,6 @@ namespace dp } @property(nonatomic) MWMMapWidgets * widgetsManager; -@property(weak, nonatomic) IBOutlet MetalView * metalView; @property(nonatomic, readonly) BOOL drapeEngineCreated; @property(nonatomic, getter=isLaunchByDeepLink) BOOL launchByDeepLink; diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index 04d1b675ec..78c0b87794 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -1,7 +1,6 @@ #import "EAGLView.h" #import "iosOGLContextFactory.h" #import "MetalContextFactory.h" -#import "MetalView.h" #import "MWMDirectionView.h" #import "MWMMapWidgets.h" @@ -15,6 +14,10 @@ #include "base/assert.hpp" #include "base/logging.hpp" +#ifdef OMIM_METAL_AVAILABLE +#import <MetalKit/MetalKit.h> +#endif + @implementation EAGLView namespace @@ -38,10 +41,38 @@ double getExactDPI(double contentScaleFactor) } } // namespace ++ (dp::ApiVersion)getSupportedApiVersion +{ + static dp::ApiVersion apiVersion = dp::ApiVersion::Invalid; + if (apiVersion != dp::ApiVersion::Invalid) + return apiVersion; + +#ifdef OMIM_METAL_AVAILABLE + if (GetFramework().LoadMetalAllowed()) + { + id<MTLDevice> tempDevice = MTLCreateSystemDefaultDevice(); + if (tempDevice) + apiVersion = dp::ApiVersion::Metal; + } +#endif + + if (apiVersion == dp::ApiVersion::Invalid) + { + EAGLContext * tempContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; + if (tempContext != nil) + apiVersion = dp::ApiVersion::OpenGLES3; + else + apiVersion = dp::ApiVersion::OpenGLES2; + } + + return apiVersion; +} + // You must implement this method + (Class)layerClass { - return [CAEAGLLayer class]; + auto const apiVersion = [EAGLView getSupportedApiVersion]; + return apiVersion == dp::ApiVersion::Metal ? [CAMetalLayer class] : [CAEAGLLayer class]; } // The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder: @@ -56,59 +87,47 @@ double getExactDPI(double contentScaleFactor) return self; } -- (dp::ApiVersion)getSupportedApiVersion -{ -#ifdef OMIM_METAL_AVAILABLE - if (GetFramework().LoadMetalAllowed()) - { - id<MTLDevice> tempDevice = MTLCreateSystemDefaultDevice(); - if (tempDevice) - return dp::ApiVersion::Metal; - } -#endif - EAGLContext * tempContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; - if (tempContext != nil) - return dp::ApiVersion::OpenGLES3; - - return dp::ApiVersion::OpenGLES2;; -} - - (void)initialize { m_presentAvailable = false; m_lastViewSize = CGRectZero; - m_apiVersion = [self getSupportedApiVersion]; + m_apiVersion = [EAGLView getSupportedApiVersion]; // Correct retina display support in renderbuffer. self.contentScaleFactor = [[UIScreen mainScreen] nativeScale]; - if (m_apiVersion != dp::ApiVersion::Metal) + if (m_apiVersion == dp::ApiVersion::Metal) { - // Setup Layer Properties - CAEAGLLayer * eaglLayer = (CAEAGLLayer *)self.layer; - eaglLayer.opaque = YES; - eaglLayer.drawableProperties = @{kEAGLDrawablePropertyRetainedBacking : @NO, - kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGBA8}; +#ifdef OMIM_METAL_AVAILABLE + CAMetalLayer * layer = (CAMetalLayer *)self.layer; + layer.device = MTLCreateSystemDefaultDevice(); + NSAssert(layer.device != NULL, @"Metal is not supported on this device"); + layer.opaque = YES; +#endif + } + else + { + CAEAGLLayer * layer = (CAEAGLLayer *)self.layer; + layer.opaque = YES; + layer.drawableProperties = @{kEAGLDrawablePropertyRetainedBacking : @NO, + kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGBA8}; } } - (void)createDrapeEngine { m2::PointU const s = [self pixelSize]; + if (m_apiVersion == dp::ApiVersion::Metal) { #ifdef OMIM_METAL_AVAILABLE - CHECK(self.metalView != nil, ()); - CHECK_EQUAL(self.bounds.size.width, self.metalView.bounds.size.width, ()); - CHECK_EQUAL(self.bounds.size.height, self.metalView.bounds.size.height, ()); - m_factory = make_unique_dp<MetalContextFactory>(self.metalView, s); + m_factory = make_unique_dp<MetalContextFactory>((CAMetalLayer *)self.layer, s); #endif } else { - CAEAGLLayer * eaglLayer = (CAEAGLLayer *)self.layer; m_factory = make_unique_dp<dp::ThreadSafeFactory>( - new iosOGLContextFactory(eaglLayer, m_apiVersion, m_presentAvailable)); + new iosOGLContextFactory((CAEAGLLayer *)self.layer, m_apiVersion, m_presentAvailable)); } [self createDrapeEngineWithWidth:s.x height:s.y]; } diff --git a/iphone/Maps/Classes/MetalContextFactory.h b/iphone/Maps/Classes/MetalContextFactory.h index 246f587ff3..5c9f4ba30c 100644 --- a/iphone/Maps/Classes/MetalContextFactory.h +++ b/iphone/Maps/Classes/MetalContextFactory.h @@ -1,5 +1,5 @@ #pragma once -#import "MetalView.h" +#import <MetalKit/MetalKit.h> #include "drape/graphics_context_factory.hpp" #include "drape/metal/metal_base_context.hpp" @@ -8,7 +8,7 @@ class MetalContextFactory: public dp::GraphicsContextFactory { public: - MetalContextFactory(MetalView * metalView, m2::PointU const & screenSize); + MetalContextFactory(CAMetalLayer * metalLayer, m2::PointU const & screenSize); dp::GraphicsContext * GetDrawContext() override; dp::GraphicsContext * GetResourcesUploadContext() override; bool IsDrawContextCreated() const override { return true; } diff --git a/iphone/Maps/Classes/MetalContextFactory.mm b/iphone/Maps/Classes/MetalContextFactory.mm index b6826d5aa1..6fc5d7fd9b 100644 --- a/iphone/Maps/Classes/MetalContextFactory.mm +++ b/iphone/Maps/Classes/MetalContextFactory.mm @@ -51,9 +51,8 @@ public: }; } // namespace -MetalContextFactory::MetalContextFactory(MetalView * metalView, m2::PointU const & screenSize) +MetalContextFactory::MetalContextFactory(CAMetalLayer * metalLayer, m2::PointU const & screenSize) { - CAMetalLayer * metalLayer = (CAMetalLayer *)metalView.layer; m_drawContext = make_unique_dp<DrawMetalContext>(metalLayer, screenSize); m_uploadContext = make_unique_dp<UploadMetalContext>(m_drawContext->GetMetalDevice()); } diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index e753233a15..66b8b57007 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -514,7 +514,6 @@ B3E3B50220D485FA00DA8C13 /* DownloadedBookmarksDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3E3B50120D485FA00DA8C13 /* DownloadedBookmarksDataSource.swift */; }; BB25B1A71FB32767007276FA /* transit_colors.txt in Resources */ = {isa = PBXBuildFile; fileRef = BB25B1A51FB32767007276FA /* transit_colors.txt */; }; BB7626B61E85599C0031D71C /* icudt57l.dat in Resources */ = {isa = PBXBuildFile; fileRef = BB7626B41E8559980031D71C /* icudt57l.dat */; }; - BB8123CC212C25FA00ADE512 /* MetalView.mm in Sources */ = {isa = PBXBuildFile; fileRef = BB8123CB212C25FA00ADE512 /* MetalView.mm */; }; BB8123CF212C264700ADE512 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB8123CD212C264700ADE512 /* Metal.framework */; }; BB8123D0212C264700ADE512 /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB8123CE212C264700ADE512 /* MetalKit.framework */; }; BB8123D62130427E00ADE512 /* MetalContextFactory.mm in Sources */ = {isa = PBXBuildFile; fileRef = BB8123D52130427E00ADE512 /* MetalContextFactory.mm */; }; @@ -1478,8 +1477,6 @@ B3E3B50120D485FA00DA8C13 /* DownloadedBookmarksDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadedBookmarksDataSource.swift; sourceTree = "<group>"; }; BB25B1A51FB32767007276FA /* transit_colors.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = transit_colors.txt; path = ../../data/transit_colors.txt; sourceTree = "<group>"; }; BB7626B41E8559980031D71C /* icudt57l.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = icudt57l.dat; path = ../../data/icudt57l.dat; sourceTree = "<group>"; }; - BB8123CA212C25FA00ADE512 /* MetalView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MetalView.h; sourceTree = "<group>"; }; - BB8123CB212C25FA00ADE512 /* MetalView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MetalView.mm; sourceTree = "<group>"; }; BB8123CD212C264700ADE512 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; BB8123CE212C264700ADE512 /* MetalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalKit.framework; path = System/Library/Frameworks/MetalKit.framework; sourceTree = SDKROOT; }; BB8123D42130427E00ADE512 /* MetalContextFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MetalContextFactory.h; sourceTree = "<group>"; }; @@ -1993,8 +1990,6 @@ F6381BF41CD12045004CA943 /* LocaleTranslator.mm */, BB8123D42130427E00ADE512 /* MetalContextFactory.h */, BB8123D52130427E00ADE512 /* MetalContextFactory.mm */, - BB8123CA212C25FA00ADE512 /* MetalView.h */, - BB8123CB212C25FA00ADE512 /* MetalView.mm */, 1D3623240D0F684500981E51 /* MapsAppDelegate.h */, 1D3623250D0F684500981E51 /* MapsAppDelegate.mm */, F613FA741AB330AF002394D4 /* MapViewController */, @@ -5015,7 +5010,6 @@ 6741AA1D1BF340DE002C974C /* MWMDownloadTransitMapAlert.mm in Sources */, 340475771E081A4600C92850 /* MWMTrafficManager.mm in Sources */, 346B42AC1DD5E3D20094EBEE /* MWMLocationNotFoundAlert.mm in Sources */, - BB8123CC212C25FA00ADE512 /* MetalView.mm in Sources */, F6E2FF031E097BA00083EBEC /* MWMSearchHistoryClearCell.mm in Sources */, 340475091E08199E00C92850 /* MWMMyTarget.mm in Sources */, 340416501E7C086000E2B6D6 /* PhotoViewController.swift in Sources */, diff --git a/iphone/Maps/UI/Storyboard/Main.storyboard b/iphone/Maps/UI/Storyboard/Main.storyboard index 0b96c351a7..a57ac0f1a3 100644 --- a/iphone/Maps/UI/Storyboard/Main.storyboard +++ b/iphone/Maps/UI/Storyboard/Main.storyboard @@ -1,14 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Wns-nH-AQU"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Wns-nH-AQU"> <device id="retina4_0" orientation="portrait"> <adaptation id="fullscreen"/> </device> <dependencies> <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/> - <capability name="Aspect ratio constraints" minToolsVersion="5.1"/> - <capability name="Constraints to layout margins" minToolsVersion="6.0"/> - <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> @@ -21,11 +18,6 @@ <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> - <mtkView contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" colorPixelFormat="BGRA8Unorm" depthStencilPixelFormat="Depth32Float" translatesAutoresizingMaskIntoConstraints="NO" id="MSN-qF-aIb" customClass="MetalView"> - <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> - <color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> - <color key="clearColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> - </mtkView> <view hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="65S-M4-TnM" customClass="NavigationInfoArea" customModule="maps_me" customModuleProvider="target"> <rect key="frame" x="0.0" y="20" width="320" height="548"/> <color key="backgroundColor" red="0.0" green="0.0" blue="1" alpha="0.20000000000000001" colorSpace="calibratedRGB"/> @@ -64,13 +56,11 @@ <constraint firstItem="FFY-Dy-Wou" firstAttribute="leading" secondItem="utd-Jy-pE5" secondAttribute="leading" priority="100" id="AW8-cN-xzE"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="trailing" secondItem="65S-M4-TnM" secondAttribute="trailing" priority="100" id="Bjn-UL-ALa"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="xJx-UU-IdV" secondAttribute="bottom" id="BqM-vp-EnJ"/> - <constraint firstAttribute="trailing" secondItem="MSN-qF-aIb" secondAttribute="trailing" id="CY7-PF-9xC"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="bottom" secondItem="65S-M4-TnM" secondAttribute="bottom" priority="100" id="FU7-Pa-O3P"/> <constraint firstItem="QKu-4A-UgP" firstAttribute="leading" secondItem="utd-Jy-pE5" secondAttribute="leading" priority="100" id="Gw4-fq-sLY"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="bottom" secondItem="NI8-tV-i2B" secondAttribute="bottom" priority="100" id="HW4-dR-LNu"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="bottom" secondItem="awj-9E-eBS" secondAttribute="bottom" priority="100" id="Kf4-GM-1aY"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="trailing" secondItem="xJx-UU-IdV" secondAttribute="trailing" priority="100" id="KfO-hH-S7R"/> - <constraint firstAttribute="bottom" secondItem="MSN-qF-aIb" secondAttribute="bottom" id="NJd-U5-NA4"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="FFY-Dy-Wou" secondAttribute="bottom" id="QQc-TF-hhE"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="trailing" secondItem="QKu-4A-UgP" secondAttribute="trailing" priority="100" id="SNy-Ck-trF"/> <constraint firstItem="NI8-tV-i2B" firstAttribute="leading" secondItem="utd-Jy-pE5" secondAttribute="leading" priority="100" id="Uf3-sL-39L"/> @@ -88,15 +78,10 @@ <constraint firstItem="utd-Jy-pE5" firstAttribute="top" secondItem="NI8-tV-i2B" secondAttribute="top" priority="100" id="kvw-Gs-ady"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="bottom" secondItem="xJx-UU-IdV" secondAttribute="bottom" priority="100" id="pur-5a-SQA"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="trailing" secondItem="FFY-Dy-Wou" secondAttribute="trailing" priority="100" id="qdF-Ru-TYd"/> - <constraint firstItem="MSN-qF-aIb" firstAttribute="leading" secondItem="USG-6L-Uhw" secondAttribute="leading" id="qqd-bW-3Yv"/> - <constraint firstAttribute="top" secondItem="MSN-qF-aIb" secondAttribute="top" id="sw9-hi-4De"/> <constraint firstItem="xJx-UU-IdV" firstAttribute="top" secondItem="utd-Jy-pE5" secondAttribute="top" priority="100" id="w8f-5v-bHr"/> <constraint firstItem="utd-Jy-pE5" firstAttribute="top" secondItem="awj-9E-eBS" secondAttribute="top" priority="100" constant="20" id="xFF-Ic-RDu"/> </constraints> <viewLayoutGuide key="safeArea" id="utd-Jy-pE5"/> - <connections> - <outlet property="metalView" destination="MSN-qF-aIb" id="hkg-ia-EVY"/> - </connections> </view> <navigationItem key="navigationItem" id="8E8-0f-UV9"/> <connections> @@ -1033,7 +1018,7 @@ <rect key="frame" x="16" y="0.0" width="276" height="348"/> <subviews> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="87G-jh-N8H" userLabel="CenteredView"> - <rect key="frame" x="0.0" y="42" width="276" height="265"/> + <rect key="frame" x="0.0" y="41.5" width="276" height="265"/> <subviews> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalCompressionResistancePriority="749" image="img_no_maps" translatesAutoresizingMaskIntoConstraints="NO" id="vI9-fc-FO2"> <rect key="frame" x="58" y="0.0" width="160" height="160"/> @@ -1222,7 +1207,7 @@ <rect key="frame" x="16" y="36" width="288" height="334"/> <subviews> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6hj-bQ-tcL" userLabel="CenteredView"> - <rect key="frame" x="0.0" y="1" width="288" height="333"/> + <rect key="frame" x="0.0" y="0.5" width="288" height="333"/> <subviews> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalCompressionResistancePriority="749" image="img_whatsnew_migration" translatesAutoresizingMaskIntoConstraints="NO" id="tap-L1-zYH"> <rect key="frame" x="44" y="0.0" width="200" height="200"/> |