webgpu/dawn/include/webgpu/webgpu_glfw.h
1// Copyright 2022 The Dawn Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef INCLUDE_WEBGPU_WEBGPU_GLFW_H_
16#define INCLUDE_WEBGPU_WEBGPU_GLFW_H_
17
18#include <memory>
19
20#include "webgpu/webgpu_cpp.h"
21
22#if defined(WGPU_GLFW_SHARED_LIBRARY)
23#if defined(_WIN32)
24#if defined(WGPU_GLFW_IMPLEMENTATION)
25#define WGPU_GLFW_EXPORT __declspec(dllexport)
26#else
27#define WGPU_GLFW_EXPORT __declspec(dllimport)
28#endif
29#else // defined(_WIN32)
30#if defined(WGPU_GLFW_IMPLEMENTATION)
31#define WGPU_GLFW_EXPORT __attribute__((visibility("default")))
32#else
33#define WGPU_GLFW_EXPORT
34#endif
35#endif // defined(_WIN32)
36#else // defined(WGPU_GLFW_SHARED_LIBRARY)
37#define WGPU_GLFW_EXPORT
38#endif // defined(WGPU_GLFW_SHARED_LIBRARY)
39
40struct GLFWwindow;
41
42namespace wgpu::glfw {
43
44// Does the necessary setup on the GLFWwindow to allow creating a wgpu::Surface with it and
45// calls `instance.CreateSurface` with the correct descriptor for this window.
46// Returns a null wgpu::Surface on failure.
47WGPU_GLFW_EXPORT wgpu::Surface CreateSurfaceForWindow(const wgpu::Instance& instance,
48 GLFWwindow* window);
49
50// Use for testing only. Does everything that CreateSurfaceForWindow does except the call to
51// CreateSurface. Useful to be able to modify the descriptor for testing, or when trying to
52// avoid using the global proc table.
53WGPU_GLFW_EXPORT std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptor(
54 GLFWwindow* window);
55
56} // namespace wgpu::glfw
57
58#endif // INCLUDE_WEBGPU_WEBGPU_GLFW_H_