Commit 540a1dfe by Geoff Lang Committed by Commit Bot

Refactor DeviceImpl creation.

Add an initialize function to match other impl objects and simplify the creation of DeviceImpls. BUG=742034 Change-Id: I569c8252d5d23c8af98835f6c08e7a3b640fc3f3 Reviewed-on: https://chromium-review.googlesource.com/854626Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 28334a41
...@@ -47,19 +47,25 @@ egl::Error Device::CreateDevice(void *devicePointer, EGLint deviceType, Device * ...@@ -47,19 +47,25 @@ egl::Error Device::CreateDevice(void *devicePointer, EGLint deviceType, Device *
{ {
*outDevice = nullptr; *outDevice = nullptr;
std::unique_ptr<rx::DeviceImpl> newDeviceImpl;
#if defined(ANGLE_ENABLE_D3D11) #if defined(ANGLE_ENABLE_D3D11)
if (deviceType == EGL_D3D11_DEVICE_ANGLE) if (deviceType == EGL_D3D11_DEVICE_ANGLE)
{ {
std::unique_ptr<rx::DeviceD3D> deviceD3D(new rx::DeviceD3D()); newDeviceImpl.reset(new rx::DeviceD3D(deviceType, devicePointer));
ANGLE_TRY(deviceD3D->initialize(devicePointer, deviceType));
*outDevice = new Device(nullptr, deviceD3D.release());
GetDeviceSet()->insert(*outDevice);
return NoError();
} }
#endif #endif
// Note that creating an EGL device from inputted D3D9 parameters isn't currently supported if (newDeviceImpl == nullptr)
return EglBadAttribute(); {
return EglBadAttribute();
}
ANGLE_TRY(newDeviceImpl->initialize());
*outDevice = new Device(nullptr, newDeviceImpl.release());
GetDeviceSet()->insert(*outDevice);
return NoError();
} }
egl::Error Device::CreateDevice(Display *owningDisplay, rx::DeviceImpl *impl, Device **outDevice) egl::Error Device::CreateDevice(Display *owningDisplay, rx::DeviceImpl *impl, Device **outDevice)
......
...@@ -26,6 +26,8 @@ class DeviceImpl : angle::NonCopyable ...@@ -26,6 +26,8 @@ class DeviceImpl : angle::NonCopyable
DeviceImpl(); DeviceImpl();
virtual ~DeviceImpl(); virtual ~DeviceImpl();
virtual egl::Error initialize() = 0;
virtual egl::Error getDevice(void **outValue) = 0; virtual egl::Error getDevice(void **outValue) = 0;
virtual EGLint getType() = 0; virtual EGLint getType() = 0;
virtual void generateExtensions(egl::DeviceExtensions *outExtensions) const = 0; virtual void generateExtensions(egl::DeviceExtensions *outExtensions) const = 0;
......
...@@ -17,14 +17,15 @@ ...@@ -17,14 +17,15 @@
namespace rx namespace rx
{ {
DeviceD3D::DeviceD3D() : mDevice(0), mDeviceType(0), mIsInitialized(false) DeviceD3D::DeviceD3D(GLint deviceType, void *nativeDevice)
: mDevice(nativeDevice), mDeviceType(deviceType), mIsInitialized(false)
{ {
} }
DeviceD3D::~DeviceD3D() DeviceD3D::~DeviceD3D()
{ {
#if defined(ANGLE_ENABLE_D3D11) #if defined(ANGLE_ENABLE_D3D11)
if (mDeviceType == EGL_D3D11_DEVICE_ANGLE) if (mIsInitialized && mDeviceType == EGL_D3D11_DEVICE_ANGLE)
{ {
// DeviceD3D holds a ref to an externally-sourced D3D11 device. We must release it. // DeviceD3D holds a ref to an externally-sourced D3D11 device. We must release it.
ID3D11Device *device = reinterpret_cast<ID3D11Device *>(mDevice); ID3D11Device *device = reinterpret_cast<ID3D11Device *>(mDevice);
...@@ -35,29 +36,20 @@ DeviceD3D::~DeviceD3D() ...@@ -35,29 +36,20 @@ DeviceD3D::~DeviceD3D()
egl::Error DeviceD3D::getDevice(void **outValue) egl::Error DeviceD3D::getDevice(void **outValue)
{ {
if (!mIsInitialized) ASSERT(mIsInitialized);
{
*outValue = nullptr;
return egl::EglBadDevice();
}
*outValue = mDevice; *outValue = mDevice;
return egl::NoError(); return egl::NoError();
} }
egl::Error DeviceD3D::initialize(void *device, EGLint deviceType) egl::Error DeviceD3D::initialize()
{ {
ASSERT(!mIsInitialized); ASSERT(!mIsInitialized);
if (mIsInitialized)
{
return egl::EglBadDevice();
}
#if defined(ANGLE_ENABLE_D3D11) #if defined(ANGLE_ENABLE_D3D11)
if (deviceType == EGL_D3D11_DEVICE_ANGLE) if (mDeviceType == EGL_D3D11_DEVICE_ANGLE)
{ {
// Validate the device // Validate the device
IUnknown *iunknown = reinterpret_cast<IUnknown *>(device); IUnknown *iunknown = reinterpret_cast<IUnknown *>(mDevice);
ID3D11Device *d3dDevice = nullptr; ID3D11Device *d3dDevice = nullptr;
HRESULT hr = HRESULT hr =
...@@ -73,9 +65,7 @@ egl::Error DeviceD3D::initialize(void *device, EGLint deviceType) ...@@ -73,9 +65,7 @@ egl::Error DeviceD3D::initialize(void *device, EGLint deviceType)
} }
#endif #endif
mDevice = device; mIsInitialized = true;
mDeviceType = deviceType;
mIsInitialized = true;
return egl::NoError(); return egl::NoError();
} }
......
...@@ -18,10 +18,10 @@ namespace rx ...@@ -18,10 +18,10 @@ namespace rx
class DeviceD3D : public DeviceImpl class DeviceD3D : public DeviceImpl
{ {
public: public:
DeviceD3D(); DeviceD3D(EGLint deviceType, void *nativeDevice);
~DeviceD3D() override; ~DeviceD3D() override;
egl::Error initialize(void *device, EGLint deviceType); egl::Error initialize() override;
egl::Error getDevice(void **outValue) override; egl::Error getDevice(void **outValue) override;
EGLint getType() override; EGLint getType() override;
void generateExtensions(egl::DeviceExtensions *outExtensions) const override; void generateExtensions(egl::DeviceExtensions *outExtensions) const override;
......
...@@ -3813,15 +3813,9 @@ egl::Error Renderer11::getEGLDevice(DeviceImpl **device) ...@@ -3813,15 +3813,9 @@ egl::Error Renderer11::getEGLDevice(DeviceImpl **device)
if (mEGLDevice == nullptr) if (mEGLDevice == nullptr)
{ {
ASSERT(mDevice != nullptr); ASSERT(mDevice != nullptr);
mEGLDevice = new DeviceD3D(); std::unique_ptr<DeviceD3D> newDevice(new DeviceD3D(EGL_D3D11_DEVICE_ANGLE, mDevice));
egl::Error error = ANGLE_TRY(newDevice->initialize());
mEGLDevice->initialize(reinterpret_cast<void *>(mDevice), EGL_D3D11_DEVICE_ANGLE); mEGLDevice = newDevice.release();
if (error.isError())
{
SafeDelete(mEGLDevice);
return error;
}
} }
*device = static_cast<DeviceImpl *>(mEGLDevice); *device = static_cast<DeviceImpl *>(mEGLDevice);
......
...@@ -3089,15 +3089,9 @@ egl::Error Renderer9::getEGLDevice(DeviceImpl **device) ...@@ -3089,15 +3089,9 @@ egl::Error Renderer9::getEGLDevice(DeviceImpl **device)
if (mEGLDevice == nullptr) if (mEGLDevice == nullptr)
{ {
ASSERT(mDevice != nullptr); ASSERT(mDevice != nullptr);
mEGLDevice = new DeviceD3D(); std::unique_ptr<DeviceD3D> newDevice(new DeviceD3D(EGL_D3D9_DEVICE_ANGLE, mDevice));
egl::Error error = ANGLE_TRY(newDevice->initialize());
mEGLDevice->initialize(reinterpret_cast<void *>(mDevice), EGL_D3D9_DEVICE_ANGLE); mEGLDevice = newDevice.release();
if (error.isError())
{
SafeDelete(mEGLDevice);
return error;
}
} }
*device = static_cast<DeviceImpl *>(mEGLDevice); *device = static_cast<DeviceImpl *>(mEGLDevice);
......
...@@ -22,6 +22,11 @@ DeviceNULL::~DeviceNULL() ...@@ -22,6 +22,11 @@ DeviceNULL::~DeviceNULL()
{ {
} }
egl::Error DeviceNULL::initialize()
{
return egl::NoError();
}
egl::Error DeviceNULL::getDevice(void **outValue) egl::Error DeviceNULL::getDevice(void **outValue)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
......
...@@ -21,6 +21,7 @@ class DeviceNULL : public DeviceImpl ...@@ -21,6 +21,7 @@ class DeviceNULL : public DeviceImpl
DeviceNULL(); DeviceNULL();
~DeviceNULL() override; ~DeviceNULL() override;
egl::Error initialize() override;
egl::Error getDevice(void **outValue) override; egl::Error getDevice(void **outValue) override;
EGLint getType() override; EGLint getType() override;
void generateExtensions(egl::DeviceExtensions *outExtensions) const override; void generateExtensions(egl::DeviceExtensions *outExtensions) const override;
......
...@@ -22,6 +22,12 @@ DeviceVk::~DeviceVk() ...@@ -22,6 +22,12 @@ DeviceVk::~DeviceVk()
{ {
} }
egl::Error DeviceVk::initialize()
{
UNIMPLEMENTED();
return egl::NoError();
}
egl::Error DeviceVk::getDevice(void **outValue) egl::Error DeviceVk::getDevice(void **outValue)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
......
...@@ -21,6 +21,7 @@ class DeviceVk : public DeviceImpl ...@@ -21,6 +21,7 @@ class DeviceVk : public DeviceImpl
DeviceVk(); DeviceVk();
~DeviceVk() override; ~DeviceVk() override;
egl::Error initialize() override;
egl::Error getDevice(void **outValue) override; egl::Error getDevice(void **outValue) override;
EGLint getType() override; EGLint getType() override;
void generateExtensions(egl::DeviceExtensions *outExtensions) const override; void generateExtensions(egl::DeviceExtensions *outExtensions) const override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment