• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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 DAWN_DAWN_WSI_H_
16 #define DAWN_DAWN_WSI_H_
17 
18 #include <dawn/dawn.h>
19 
20 // Error message (or nullptr if there was no error)
21 typedef const char* DawnSwapChainError;
22 constexpr DawnSwapChainError DAWN_SWAP_CHAIN_NO_ERROR = nullptr;
23 
24 typedef struct {
25     /// Backend-specific texture id/name/pointer
26     union {
27         void* ptr;
28         uint64_t u64;
29         uint32_t u32;
30     } texture;
31 } DawnSwapChainNextTexture;
32 
33 typedef struct {
34     /// Initialize the swap chain implementation.
35     ///   (*wsiContext) is one of DawnWSIContext{D3D12,Metal,GL}
36     void (*Init)(void* userData, void* wsiContext);
37 
38     /// Destroy the swap chain implementation.
39     void (*Destroy)(void* userData);
40 
41     /// Configure/reconfigure the swap chain.
42     DawnSwapChainError (*Configure)(void* userData,
43                                     DawnTextureFormat format,
44                                     DawnTextureUsageBit allowedUsage,
45                                     uint32_t width,
46                                     uint32_t height);
47 
48     /// Acquire the next texture from the swap chain.
49     DawnSwapChainError (*GetNextTexture)(void* userData, DawnSwapChainNextTexture* nextTexture);
50 
51     /// Present the last acquired texture to the screen.
52     DawnSwapChainError (*Present)(void* userData);
53 
54     /// Each function is called with userData as its first argument.
55     void* userData;
56 
57     /// For use by the D3D12 and Vulkan backends: how the swapchain will use the texture.
58     DawnTextureUsageBit textureUsage;
59 } DawnSwapChainImplementation;
60 
61 #if defined(DAWN_ENABLE_BACKEND_D3D12) && defined(__cplusplus)
62 typedef struct {
63     DawnDevice device = nullptr;
64 } DawnWSIContextD3D12;
65 #endif
66 
67 #if defined(DAWN_ENABLE_BACKEND_METAL) && defined(__OBJC__)
68 #    import <Metal/Metal.h>
69 
70 typedef struct {
71     id<MTLDevice> device = nil;
72 } DawnWSIContextMetal;
73 #endif
74 
75 #ifdef DAWN_ENABLE_BACKEND_OPENGL
76 typedef struct {
77 } DawnWSIContextGL;
78 #endif
79 
80 #ifdef DAWN_ENABLE_BACKEND_VULKAN
81 typedef struct {
82 } DawnWSIContextVulkan;
83 #endif
84 
85 #endif  // DAWN_DAWN_WSI_H
86