1// 2// Copyright 2019 The ANGLE Project Authors. All rights reserved. 3// Use of this source code is governed by a BSD-style license that can be 4// found in the LICENSE file. 5// 6// DisplayVkMac.mm: 7// Implements methods from DisplayVkMac 8// 9 10#include "libANGLE/renderer/vulkan/mac/DisplayVkMac.h" 11 12#include <vulkan/vulkan.h> 13 14#include "libANGLE/renderer/vulkan/RendererVk.h" 15#include "libANGLE/renderer/vulkan/mac/IOSurfaceSurfaceVkMac.h" 16#include "libANGLE/renderer/vulkan/mac/WindowSurfaceVkMac.h" 17#include "libANGLE/renderer/vulkan/vk_caps_utils.h" 18 19#import <Cocoa/Cocoa.h> 20 21namespace rx 22{ 23 24DisplayVkMac::DisplayVkMac(const egl::DisplayState &state) : DisplayVk(state) {} 25 26bool DisplayVkMac::isValidNativeWindow(EGLNativeWindowType window) const 27{ 28 NSObject *layer = reinterpret_cast<NSObject *>(window); 29 return [layer isKindOfClass:[CALayer class]]; 30} 31 32SurfaceImpl *DisplayVkMac::createWindowSurfaceVk(const egl::SurfaceState &state, 33 EGLNativeWindowType window) 34{ 35 ASSERT(isValidNativeWindow(window)); 36 return new WindowSurfaceVkMac(state, window); 37} 38 39SurfaceImpl *DisplayVkMac::createPbufferFromClientBuffer(const egl::SurfaceState &state, 40 EGLenum buftype, 41 EGLClientBuffer clientBuffer, 42 const egl::AttributeMap &attribs) 43{ 44 ASSERT(buftype == EGL_IOSURFACE_ANGLE); 45 46 return new IOSurfaceSurfaceVkMac(state, clientBuffer, attribs); 47} 48 49egl::ConfigSet DisplayVkMac::generateConfigs() 50{ 51 constexpr GLenum kColorFormats[] = {GL_BGRA8_EXT, GL_BGRX8_ANGLEX}; 52 return egl_vk::GenerateConfigs(kColorFormats, egl_vk::kConfigDepthStencilFormats, this); 53} 54 55bool DisplayVkMac::checkConfigSupport(egl::Config *config) 56{ 57 // TODO(geofflang): Test for native support and modify the config accordingly. 58 // anglebug.com/2692 59 return true; 60} 61 62const char *DisplayVkMac::getWSIExtension() const 63{ 64 return VK_EXT_METAL_SURFACE_EXTENSION_NAME; 65} 66 67bool IsVulkanMacDisplayAvailable() 68{ 69 return true; 70} 71 72DisplayImpl *CreateVulkanMacDisplay(const egl::DisplayState &state) 73{ 74 return new DisplayVkMac(state); 75} 76 77void DisplayVkMac::generateExtensions(egl::DisplayExtensions *outExtensions) const 78{ 79 outExtensions->iosurfaceClientBuffer = 80 getRenderer()->getFeatures().supportsExternalMemoryHost.enabled; 81 82 DisplayVk::generateExtensions(outExtensions); 83} 84 85egl::Error DisplayVkMac::validateClientBuffer(const egl::Config *configuration, 86 EGLenum buftype, 87 EGLClientBuffer clientBuffer, 88 const egl::AttributeMap &attribs) const 89{ 90 ASSERT(buftype == EGL_IOSURFACE_ANGLE); 91 92 if (!IOSurfaceSurfaceVkMac::ValidateAttributes(this, clientBuffer, attribs)) 93 { 94 return egl::EglBadAttribute(); 95 } 96 return egl::NoError(); 97} 98 99} // namespace rx 100