blob: 3e089bbffafd43ea9e6e557ab2e7786564f2ef31 [file] [log] [blame]
Corentin Wallez97d2a712019-01-09 08:35:16 +00001// 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 Wallezabdb5662019-06-17 09:01:09 +000020#include "common/SwapChainUtils.h"
Corentin Wallez97d2a712019-01-09 08:35:16 +000021#include "dawn_native/opengl/DeviceGL.h"
Corentin Wallezabdb5662019-06-17 09:01:09 +000022#include "dawn_native/opengl/NativeSwapChainImplGL.h"
Corentin Wallez97d2a712019-01-09 08:35:16 +000023
24namespace dawn_native { namespace opengl {
25
26 AdapterDiscoveryOptions::AdapterDiscoveryOptions()
Corentin Wallezf12c9db2020-01-10 13:28:18 +000027 : AdapterDiscoveryOptionsBase(WGPUBackendType_OpenGL) {
Corentin Wallez97d2a712019-01-09 08:35:16 +000028 }
29
Stephen White70102b72020-11-24 20:57:23 +000030 AdapterDiscoveryOptionsES::AdapterDiscoveryOptionsES()
31 : AdapterDiscoveryOptionsBase(WGPUBackendType_OpenGLES) {
32 }
33
Corentin Wallez9f90c8d2019-10-24 23:55:37 +000034 DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device,
Corentin Wallezabdb5662019-06-17 09:01:09 +000035 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 Wallez9f90c8d2019-10-24 23:55:37 +000042 impl.textureUsage = WGPUTextureUsage_Present;
Corentin Wallezabdb5662019-06-17 09:01:09 +000043
44 return impl;
45 }
46
Corentin Wallez9f90c8d2019-10-24 23:55:37 +000047 WGPUTextureFormat GetNativeSwapChainPreferredFormat(
Corentin Wallezabdb5662019-06-17 09:01:09 +000048 const DawnSwapChainImplementation* swapChain) {
49 NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
Corentin Wallez9f90c8d2019-10-24 23:55:37 +000050 return static_cast<WGPUTextureFormat>(impl->GetPreferredFormat());
Corentin Wallezabdb5662019-06-17 09:01:09 +000051 }
52
Stephen Whiteb5652c72021-06-03 16:19:16 +000053 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 Wallez97d2a712019-01-09 08:35:16 +000064}} // namespace dawn_native::opengl