• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include "common/SwapChainUtils.h"
21 #include "dawn_native/opengl/DeviceGL.h"
22 #include "dawn_native/opengl/NativeSwapChainImplGL.h"
23 
24 namespace dawn_native { namespace opengl {
25 
AdapterDiscoveryOptions()26     AdapterDiscoveryOptions::AdapterDiscoveryOptions()
27         : AdapterDiscoveryOptionsBase(WGPUBackendType_OpenGL) {
28     }
29 
AdapterDiscoveryOptionsES()30     AdapterDiscoveryOptionsES::AdapterDiscoveryOptionsES()
31         : AdapterDiscoveryOptionsBase(WGPUBackendType_OpenGLES) {
32     }
33 
CreateNativeSwapChainImpl(WGPUDevice device,PresentCallback present,void * presentUserdata)34     DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device,
35                                                           PresentCallback present,
36                                                           void* presentUserdata) {
37         Device* backendDevice = ToBackend(FromAPI(device));
38 
39         DawnSwapChainImplementation impl;
40         impl = CreateSwapChainImplementation(
41             new NativeSwapChainImpl(backendDevice, present, presentUserdata));
42         impl.textureUsage = WGPUTextureUsage_Present;
43 
44         return impl;
45     }
46 
GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation * swapChain)47     WGPUTextureFormat GetNativeSwapChainPreferredFormat(
48         const DawnSwapChainImplementation* swapChain) {
49         NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
50         return static_cast<WGPUTextureFormat>(impl->GetPreferredFormat());
51     }
52 
ExternalImageDescriptorEGLImage()53     ExternalImageDescriptorEGLImage::ExternalImageDescriptorEGLImage()
54         : ExternalImageDescriptor(ExternalImageType::EGLImage) {
55     }
56 
WrapExternalEGLImage(WGPUDevice device,const ExternalImageDescriptorEGLImage * descriptor)57     WGPUTexture WrapExternalEGLImage(WGPUDevice device,
58                                      const ExternalImageDescriptorEGLImage* descriptor) {
59         Device* backendDevice = ToBackend(FromAPI(device));
60         TextureBase* texture =
61             backendDevice->CreateTextureWrappingEGLImage(descriptor, descriptor->image);
62         return ToAPI(texture);
63     }
64 
65 }}  // namespace dawn_native::opengl
66