Corentin Wallez | 97d2a71 | 2019-01-09 08:35:16 +0000 | [diff] [blame] | 1 | // Copyright 2019 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 | // OpenGLBackend.cpp: contains the definition of symbols exported by OpenGLBackend.h so that they |
| 16 | // can be compiled twice: once export (shared library), once not exported (static library) |
| 17 | |
| 18 | #include "dawn_native/OpenGLBackend.h" |
| 19 | |
Corentin Wallez | abdb566 | 2019-06-17 09:01:09 +0000 | [diff] [blame] | 20 | #include "common/SwapChainUtils.h" |
Corentin Wallez | 97d2a71 | 2019-01-09 08:35:16 +0000 | [diff] [blame] | 21 | #include "dawn_native/opengl/DeviceGL.h" |
Corentin Wallez | abdb566 | 2019-06-17 09:01:09 +0000 | [diff] [blame] | 22 | #include "dawn_native/opengl/NativeSwapChainImplGL.h" |
Corentin Wallez | 97d2a71 | 2019-01-09 08:35:16 +0000 | [diff] [blame] | 23 | |
| 24 | namespace dawn_native { namespace opengl { |
| 25 | |
| 26 | AdapterDiscoveryOptions::AdapterDiscoveryOptions() |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 27 | : AdapterDiscoveryOptionsBase(WGPUBackendType_OpenGL) { |
Corentin Wallez | 97d2a71 | 2019-01-09 08:35:16 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Stephen White | 70102b7 | 2020-11-24 20:57:23 +0000 | [diff] [blame] | 30 | AdapterDiscoveryOptionsES::AdapterDiscoveryOptionsES() |
| 31 | : AdapterDiscoveryOptionsBase(WGPUBackendType_OpenGLES) { |
| 32 | } |
| 33 | |
Corentin Wallez | 9f90c8d | 2019-10-24 23:55:37 +0000 | [diff] [blame] | 34 | DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device, |
Corentin Wallez | abdb566 | 2019-06-17 09:01:09 +0000 | [diff] [blame] | 35 | PresentCallback present, |
| 36 | void* presentUserdata) { |
| 37 | Device* backendDevice = reinterpret_cast<Device*>(device); |
| 38 | |
| 39 | DawnSwapChainImplementation impl; |
| 40 | impl = CreateSwapChainImplementation( |
| 41 | new NativeSwapChainImpl(backendDevice, present, presentUserdata)); |
Corentin Wallez | 9f90c8d | 2019-10-24 23:55:37 +0000 | [diff] [blame] | 42 | impl.textureUsage = WGPUTextureUsage_Present; |
Corentin Wallez | abdb566 | 2019-06-17 09:01:09 +0000 | [diff] [blame] | 43 | |
| 44 | return impl; |
| 45 | } |
| 46 | |
Corentin Wallez | 9f90c8d | 2019-10-24 23:55:37 +0000 | [diff] [blame] | 47 | WGPUTextureFormat GetNativeSwapChainPreferredFormat( |
Corentin Wallez | abdb566 | 2019-06-17 09:01:09 +0000 | [diff] [blame] | 48 | const DawnSwapChainImplementation* swapChain) { |
| 49 | NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData); |
Corentin Wallez | 9f90c8d | 2019-10-24 23:55:37 +0000 | [diff] [blame] | 50 | return static_cast<WGPUTextureFormat>(impl->GetPreferredFormat()); |
Corentin Wallez | abdb566 | 2019-06-17 09:01:09 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Stephen White | b5652c7 | 2021-06-03 16:19:16 +0000 | [diff] [blame] | 53 | ExternalImageDescriptorEGLImage::ExternalImageDescriptorEGLImage() |
| 54 | : ExternalImageDescriptor(ExternalImageType::EGLImage) { |
| 55 | } |
| 56 | |
| 57 | WGPUTexture WrapExternalEGLImage(WGPUDevice cDevice, |
| 58 | const ExternalImageDescriptorEGLImage* descriptor) { |
| 59 | Device* device = reinterpret_cast<Device*>(cDevice); |
| 60 | TextureBase* texture = device->CreateTextureWrappingEGLImage(descriptor, descriptor->image); |
| 61 | return reinterpret_cast<WGPUTexture>(texture); |
| 62 | } |
| 63 | |
Corentin Wallez | 97d2a71 | 2019-01-09 08:35:16 +0000 | [diff] [blame] | 64 | }} // namespace dawn_native::opengl |