• 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 COMMON_SWAPCHAINUTILS_H_
16 #define COMMON_SWAPCHAINUTILS_H_
17 
18 #include "dawn/dawn_wsi.h"
19 
20 template <typename T>
CreateSwapChainImplementation(T * swapChain)21 DawnSwapChainImplementation CreateSwapChainImplementation(T* swapChain) {
22     DawnSwapChainImplementation impl = {};
23     impl.userData = swapChain;
24     impl.Init = [](void* userData, void* wsiContext) {
25         auto* ctx = static_cast<typename T::WSIContext*>(wsiContext);
26         reinterpret_cast<T*>(userData)->Init(ctx);
27     };
28     impl.Destroy = [](void* userData) { delete reinterpret_cast<T*>(userData); };
29     impl.Configure = [](void* userData, WGPUTextureFormat format, WGPUTextureUsage allowedUsage,
30                         uint32_t width, uint32_t height) {
31         return static_cast<T*>(userData)->Configure(format, allowedUsage, width, height);
32     };
33     impl.GetNextTexture = [](void* userData, DawnSwapChainNextTexture* nextTexture) {
34         return static_cast<T*>(userData)->GetNextTexture(nextTexture);
35     };
36     impl.Present = [](void* userData) { return static_cast<T*>(userData)->Present(); };
37     return impl;
38 }
39 
40 #endif  // COMMON_SWAPCHAINUTILS_H_
41