DeviceD3D.cpp (2142B)
1 // 2 // Copyright 2015 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 // DeviceD3D.cpp: D3D implementation of egl::Device 8 9 #include "libANGLE/renderer/d3d/DeviceD3D.h" 10 11 #include "libANGLE/Device.h" 12 #include "libANGLE/Display.h" 13 14 #include <EGL/eglext.h> 15 16 namespace rx 17 { 18 19 DeviceD3D::DeviceD3D(GLint deviceType, void *nativeDevice) 20 : mDevice(nativeDevice), mDeviceType(deviceType), mIsInitialized(false) 21 {} 22 23 DeviceD3D::~DeviceD3D() 24 { 25 #if defined(ANGLE_ENABLE_D3D11) 26 if (mIsInitialized && mDeviceType == EGL_D3D11_DEVICE_ANGLE) 27 { 28 // DeviceD3D holds a ref to an externally-sourced D3D11 device. We must release it. 29 ID3D11Device *device = static_cast<ID3D11Device *>(mDevice); 30 device->Release(); 31 } 32 #endif 33 } 34 35 egl::Error DeviceD3D::getAttribute(const egl::Display *display, EGLint attribute, void **outValue) 36 { 37 ASSERT(mIsInitialized); 38 ANGLE_UNUSED_VARIABLE(display); 39 // Validated at higher levels. 40 ASSERT(getType() == attribute); 41 *outValue = mDevice; 42 return egl::NoError(); 43 } 44 45 egl::Error DeviceD3D::initialize() 46 { 47 ASSERT(!mIsInitialized); 48 49 #if defined(ANGLE_ENABLE_D3D11) 50 if (mDeviceType == EGL_D3D11_DEVICE_ANGLE) 51 { 52 // Validate the device 53 IUnknown *iunknown = static_cast<IUnknown *>(mDevice); 54 55 ID3D11Device *d3dDevice = nullptr; 56 HRESULT hr = 57 iunknown->QueryInterface(__uuidof(ID3D11Device), reinterpret_cast<void **>(&d3dDevice)); 58 if (FAILED(hr)) 59 { 60 return egl::EglBadAttribute() << "Invalid D3D device passed into EGLDeviceEXT"; 61 } 62 63 // The QI to ID3D11Device adds a ref to the D3D11 device. 64 // Deliberately don't release the ref here, so that the DeviceD3D holds a ref to the 65 // D3D11 device. 66 } 67 #endif 68 69 mIsInitialized = true; 70 71 return egl::NoError(); 72 } 73 74 EGLint DeviceD3D::getType() 75 { 76 return mDeviceType; 77 } 78 79 void DeviceD3D::generateExtensions(egl::DeviceExtensions *outExtensions) const 80 { 81 outExtensions->deviceD3D = true; 82 } 83 84 } // namespace rx