xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/d3d/d3d11/Device11.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2024 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // Device11.cpp: D3D11 implementation of egl::Device
8 
9 #include "libANGLE/renderer/d3d/d3d11/Device11.h"
10 
11 #include "libANGLE/Device.h"
12 #include "libANGLE/Display.h"
13 
14 #include <EGL/eglext.h>
15 
16 namespace rx
17 {
18 
Device11(void * nativeDevice)19 Device11::Device11(void *nativeDevice)
20 {
21     // Validate the device
22     IUnknown *iunknown = static_cast<IUnknown *>(nativeDevice);
23 
24     // The QI to ID3D11Device adds a ref to the D3D11 device.
25     // Deliberately don't release the ref here, so that the Device11 holds a ref to the
26     // D3D11 device.
27     iunknown->QueryInterface(__uuidof(ID3D11Device), reinterpret_cast<void **>(&mDevice));
28 }
29 
~Device11()30 Device11::~Device11()
31 {
32     if (mDevice)
33     {
34         // Device11 holds a ref to an externally-sourced D3D11 device. We must release it.
35         mDevice->Release();
36         mDevice = nullptr;
37     }
38 }
39 
getAttribute(const egl::Display * display,EGLint attribute,void ** outValue)40 egl::Error Device11::getAttribute(const egl::Display *display, EGLint attribute, void **outValue)
41 {
42     ASSERT(attribute == EGL_D3D11_DEVICE_ANGLE);
43     *outValue = mDevice;
44     return egl::NoError();
45 }
46 
initialize()47 egl::Error Device11::initialize()
48 {
49     if (!mDevice)
50     {
51         return egl::EglBadAttribute() << "Invalid D3D device passed into EGLDeviceEXT";
52     }
53 
54     return egl::NoError();
55 }
56 
generateExtensions(egl::DeviceExtensions * outExtensions) const57 void Device11::generateExtensions(egl::DeviceExtensions *outExtensions) const
58 {
59     outExtensions->deviceD3D   = true;
60     outExtensions->deviceD3D11 = true;
61 }
62 
63 }  // namespace rx
64