• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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 DAWNNATIVE_SURFACE_H_
16 #define DAWNNATIVE_SURFACE_H_
17 
18 #include "common/RefCounted.h"
19 #include "dawn_native/Error.h"
20 #include "dawn_native/Forward.h"
21 
22 #include "dawn_native/dawn_platform.h"
23 
24 #include "common/Platform.h"
25 
26 #if defined(DAWN_PLATFORM_WINDOWS)
27 #    include "dawn_native/d3d12/d3d12_platform.h"
28 #endif  // defined(DAWN_PLATFORM_WINDOWS)
29 
30 // Forward declare IUnknown
31 // GetCoreWindow needs to return an IUnknown pointer
32 // non-windows platforms don't have this type
33 struct IUnknown;
34 
35 namespace dawn_native {
36 
37     MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance,
38                                          const SurfaceDescriptor* descriptor);
39 
40     // A surface is a sum types of all the kind of windows Dawn supports. The OS-specific types
41     // aren't used because they would cause compilation errors on other OSes (or require
42     // ObjectiveC).
43     // The surface is also used to store the current swapchain so that we can detach it when it is
44     // replaced.
45     class Surface final : public RefCounted {
46       public:
47         Surface(InstanceBase* instance, const SurfaceDescriptor* descriptor);
48 
49         void SetAttachedSwapChain(NewSwapChainBase* swapChain);
50         NewSwapChainBase* GetAttachedSwapChain();
51 
52         // These are valid to call on all Surfaces.
53         enum class Type { MetalLayer, WindowsHWND, WindowsCoreWindow, WindowsSwapChainPanel, Xlib };
54         Type GetType() const;
55         InstanceBase* GetInstance();
56 
57         // Valid to call if the type is MetalLayer
58         void* GetMetalLayer() const;
59 
60         // Valid to call if the type is WindowsHWND
61         void* GetHInstance() const;
62         void* GetHWND() const;
63 
64         // Valid to call if the type is WindowsCoreWindow
65         IUnknown* GetCoreWindow() const;
66 
67         // Valid to call if the type is WindowsSwapChainPanel
68         IUnknown* GetSwapChainPanel() const;
69 
70         // Valid to call if the type is WindowsXlib
71         void* GetXDisplay() const;
72         uint32_t GetXWindow() const;
73 
74       private:
75         ~Surface() override;
76 
77         Ref<InstanceBase> mInstance;
78         Type mType;
79 
80         // The swapchain will set this to null when it is destroyed.
81         Ref<NewSwapChainBase> mSwapChain;
82 
83         // MetalLayer
84         void* mMetalLayer = nullptr;
85 
86         // WindowsHwnd
87         void* mHInstance = nullptr;
88         void* mHWND = nullptr;
89 
90 #if defined(DAWN_PLATFORM_WINDOWS)
91         // WindowsCoreWindow
92         ComPtr<IUnknown> mCoreWindow;
93 
94         // WindowsSwapChainPanel
95         ComPtr<IUnknown> mSwapChainPanel;
96 #endif  // defined(DAWN_PLATFORM_WINDOWS)
97 
98         // Xlib
99         void* mXDisplay = nullptr;
100         uint32_t mXWindow = 0;
101     };
102 
103     absl::FormatConvertResult<absl::FormatConversionCharSet::kString> AbslFormatConvert(
104         Surface::Type value,
105         const absl::FormatConversionSpec& spec,
106         absl::FormatSink* s);
107 
108 }  // namespace dawn_native
109 
110 #endif  // DAWNNATIVE_SURFACE_H_
111