Guard macOS or iOS specific code in #if guards

This is necessary because @available(macOS 10.N, *) is taken on all iOS
versions but there is no way to say the branch is just not taken on any
iOS version. The proper way to deal with this is to add additional #if
guards to just not compile the code on iOS / macOS.

BUG=dawn:225

Change-Id: I76ec01f933364e9b47b5dda1198359f2ab4d1188
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11900
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn_native/metal/BackendMTL.mm b/src/dawn_native/metal/BackendMTL.mm
index a52536e..646a387 100644
--- a/src/dawn_native/metal/BackendMTL.mm
+++ b/src/dawn_native/metal/BackendMTL.mm
@@ -28,7 +28,6 @@
 
     namespace {
 
-#if defined(DAWN_PLATFORM_MACOS)
         struct PCIIDs {
             uint32_t vendorId;
             uint32_t deviceId;
@@ -39,6 +38,7 @@
             uint32_t vendorId;
         };
 
+#if defined(DAWN_PLATFORM_MACOS)
         const Vendor kVendors[] = {{"AMD", kVendorID_AMD},
                                    {"Radeon", kVendorID_AMD},
                                    {"Intel", kVendorID_Intel},
@@ -158,7 +158,8 @@
 #elif defined(DAWN_PLATFORM_IOS)
         MaybeError GetDevicePCIInfo(id<MTLDevice> device, PCIIDs* ids) {
             DAWN_UNUSED(device);
-            *ids = PCIIDs(0, 0);
+            *ids = PCIIDs{0, 0};
+            return {};
         }
 
         bool IsMetalSupported() {
@@ -183,11 +184,17 @@
                 mPCIInfo.deviceId = ids.deviceId;
             };
 
+#if defined(DAWN_PLATFORM_IOS)
+            mDeviceType = DeviceType::IntegratedGPU;
+#elif defined(DAWN_PLATFORM_MACOS)
             if ([device isLowPower]) {
                 mDeviceType = DeviceType::IntegratedGPU;
             } else {
                 mDeviceType = DeviceType::DiscreteGPU;
             }
+#else
+#    error "Unsupported Apple platform."
+#endif
 
             InitializeSupportedExtensions();
         }
@@ -201,9 +208,11 @@
             return {new Device(this, mDevice, descriptor)};
         }
         void InitializeSupportedExtensions() {
+#if defined(DAWN_PLATFORM_MACOS)
             if ([mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) {
                 mSupportedExtensions.EnableExtension(Extension::TextureCompressionBC);
             }
+#endif
         }
 
         id<MTLDevice> mDevice = nil;
@@ -221,6 +230,7 @@
         std::vector<std::unique_ptr<AdapterBase>> adapters;
 
         if (@available(macOS 10.11, *)) {
+#if defined(DAWN_PLATFORM_MACOS)
             NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
 
             for (id<MTLDevice> device in devices) {
@@ -228,10 +238,13 @@
             }
 
             [devices release];
+#endif
         } else if (@available(iOS 8.0, *)) {
+#if defined(DAWN_PLATFORM_IOS)
             // iOS only has a single device so MTLCopyAllDevices doesn't exist there.
             adapters.push_back(
                 std::make_unique<Adapter>(GetInstance(), MTLCreateSystemDefaultDevice()));
+#endif
         } else {
             UNREACHABLE();
         }
diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm
index 04e9d5f..bacc529 100644
--- a/src/dawn_native/metal/DeviceMTL.mm
+++ b/src/dawn_native/metal/DeviceMTL.mm
@@ -76,11 +76,13 @@
     }
 
     void Device::InitTogglesFromDriver() {
+#if defined(DAWN_PLATFORM_MACOS)
         if (@available(macOS 10.12, *)) {
             bool emulateStoreAndMSAAResolve =
                 ![mMtlDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2];
             SetToggle(Toggle::EmulateStoreAndMSAAResolve, emulateStoreAndMSAAResolve);
         }
+#endif
 
         // TODO(jiawei.shao@intel.com): check iOS feature sets
 
diff --git a/src/dawn_native/metal/TextureMTL.mm b/src/dawn_native/metal/TextureMTL.mm
index ffe56a8..12bbc73 100644
--- a/src/dawn_native/metal/TextureMTL.mm
+++ b/src/dawn_native/metal/TextureMTL.mm
@@ -214,6 +214,7 @@
             case dawn::TextureFormat::Depth24PlusStencil8:
                 return MTLPixelFormatDepth32Float_Stencil8;
 
+#if defined(DAWN_PLATFORM_MACOS)
             case dawn::TextureFormat::BC1RGBAUnorm:
                 return MTLPixelFormatBC1_RGBA;
             case dawn::TextureFormat::BC1RGBAUnormSrgb:
@@ -242,6 +243,7 @@
                 return MTLPixelFormatBC7_RGBAUnorm;
             case dawn::TextureFormat::BC7RGBAUnormSrgb:
                 return MTLPixelFormatBC7_RGBAUnorm_sRGB;
+#endif
 
             default:
                 UNREACHABLE();