aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Fedchin <anightik@gmail.com>2017-01-25 18:45:54 +0300
committerAnton Fedchin <afedchin@ruswizards.com>2017-01-26 22:35:28 +0300
commit1c8b8d3a3787b064ff8fee96f49880c999c9f588 (patch)
tree0f3eebfeca46cff0408fd86759ae52574f033482
parent0ec98b9fa5d3e8cb5eb4f9f83e193c9d0905b60c (diff)
[win32/dx] re-factor ID3DResource to make possible tell to a resource that device is not valid anymore.
-rw-r--r--xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.h2
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DXVAHD.h2
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.cpp2
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.h2
-rw-r--r--xbmc/guilib/D3DResource.cpp29
-rw-r--r--xbmc/guilib/D3DResource.h25
-rw-r--r--xbmc/guilib/GUIFontTTFDX.cpp2
-rw-r--r--xbmc/guilib/GUIFontTTFDX.h18
-rw-r--r--xbmc/rendering/dx/RenderSystemDX.cpp9
9 files changed, 48 insertions, 43 deletions
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.h b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.h
index 2170515919..da28645db0 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.h
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.h
@@ -147,7 +147,7 @@ protected:
// ID3DResource overrides
void OnCreateDevice() override {}
- void OnDestroyDevice() override { CSingleLock lock(m_section); m_state = DXVA_LOST; m_event.Reset(); }
+ void OnDestroyDevice(bool fatal) override { CSingleLock lock(m_section); m_state = DXVA_LOST; m_event.Reset(); }
void OnLostDevice() override { CSingleLock lock(m_section); m_state = DXVA_LOST; m_event.Reset(); }
void OnResetDevice() override { CSingleLock lock(m_section); m_state = DXVA_RESET; m_event.Set(); }
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DXVAHD.h b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DXVAHD.h
index 60be0850d3..4a3dafd458 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DXVAHD.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DXVAHD.h
@@ -64,7 +64,7 @@ public:
// ID3DResource overrides
void OnCreateDevice() override {}
- void OnDestroyDevice() override { CSingleLock lock(m_section); UnInit(); }
+ void OnDestroyDevice(bool fatal) override { CSingleLock lock(m_section); UnInit(); }
void OnLostDevice() override { CSingleLock lock(m_section); UnInit(); }
void OnResetDevice() override { CSingleLock lock(m_section); Close(); }
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.cpp
index a50e9b170e..9bf031095f 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.cpp
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.cpp
@@ -507,7 +507,7 @@ void CRenderCaptureDX::OnLostDevice()
SetState(CAPTURESTATE_FAILED);
}
-void CRenderCaptureDX::OnDestroyDevice()
+void CRenderCaptureDX::OnDestroyDevice(bool fatal)
{
CleanupDX();
SetState(CAPTURESTATE_FAILED);
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.h b/xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.h
index 640461f353..9f9565f988 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/RenderCapture.h
@@ -210,7 +210,7 @@ class CRenderCaptureDX : public CRenderCaptureBase, public ID3DResource
void EndRender();
void ReadOut();
- virtual void OnDestroyDevice();
+ virtual void OnDestroyDevice(bool fatal);
virtual void OnLostDevice();
virtual void OnCreateDevice() {};
diff --git a/xbmc/guilib/D3DResource.cpp b/xbmc/guilib/D3DResource.cpp
index a5aaab7245..8a8d5857de 100644
--- a/xbmc/guilib/D3DResource.cpp
+++ b/xbmc/guilib/D3DResource.cpp
@@ -383,18 +383,15 @@ void CD3DTexture::SaveTexture()
}
}
-void CD3DTexture::OnDestroyDevice()
+void CD3DTexture::OnDestroyDevice(bool fatal)
{
- SaveTexture();
+ if (!fatal)
+ SaveTexture();
SAFE_RELEASE(m_texture);
SAFE_RELEASE(m_textureView);
SAFE_RELEASE(m_renderTarget);
}
-void CD3DTexture::OnLostDevice()
-{
-}
-
void CD3DTexture::RestoreTexture()
{
// yay, we're back - make a new copy of the texture
@@ -416,10 +413,6 @@ void CD3DTexture::OnCreateDevice()
RestoreTexture();
}
-void CD3DTexture::OnResetDevice()
-{
-}
-
unsigned int CD3DTexture::GetMemoryUsage(unsigned int pitch) const
{
switch (m_format)
@@ -533,10 +526,10 @@ bool CD3DEffect::Create(const std::string &effectString, DefinesMap* defines)
void CD3DEffect::Release()
{
g_Windowing.Unregister(this);
- OnDestroyDevice();
+ OnDestroyDevice(false);
}
-void CD3DEffect::OnDestroyDevice()
+void CD3DEffect::OnDestroyDevice(bool fatal)
{
SAFE_RELEASE(m_effect);
m_techniquie = nullptr;
@@ -790,8 +783,14 @@ bool CD3DBuffer::Unmap()
return false;
}
-void CD3DBuffer::OnDestroyDevice()
+void CD3DBuffer::OnDestroyDevice(bool fatal)
{
+ if (fatal)
+ {
+ SAFE_RELEASE(m_buffer);
+ return;
+ }
+
ID3D11Device* pDevice = g_Windowing.Get3D11Device();
ID3D11DeviceContext* pContext = g_Windowing.GetImmediateContext();
@@ -1005,7 +1004,7 @@ void CD3DVertexShader::OnCreateDevice()
m_inited = CreateInternal();
}
-void CD3DVertexShader::OnDestroyDevice()
+void CD3DVertexShader::OnDestroyDevice(bool fatal)
{
ReleaseShader();
}
@@ -1130,7 +1129,7 @@ void CD3DPixelShader::OnCreateDevice()
m_inited = CreateInternal();
}
-void CD3DPixelShader::OnDestroyDevice()
+void CD3DPixelShader::OnDestroyDevice(bool fatal)
{
ReleaseShader();
}
diff --git a/xbmc/guilib/D3DResource.h b/xbmc/guilib/D3DResource.h
index cf0a0b98bf..8a51efd9b4 100644
--- a/xbmc/guilib/D3DResource.h
+++ b/xbmc/guilib/D3DResource.h
@@ -58,10 +58,11 @@ class ID3DResource
public:
virtual ~ID3DResource() {};
- virtual void OnDestroyDevice()=0;
+ virtual void OnDestroyDevice(bool fatal)=0;
virtual void OnCreateDevice()=0;
virtual void OnLostDevice() {};
virtual void OnResetDevice() {};
+ virtual void OnDestroyDevice() { OnDestroyDevice(false); }
};
class CD3DHelper
@@ -137,10 +138,8 @@ public:
static void DrawQuad(const CRect &coords, color_t color, unsigned numViews, ID3D11ShaderResourceView **view, const CRect *texCoords,
SHADER_METHOD options = SHADER_METHOD_RENDER_TEXTURE_BLEND);
- virtual void OnDestroyDevice();
- virtual void OnCreateDevice();
- virtual void OnLostDevice();
- virtual void OnResetDevice();
+ void OnDestroyDevice(bool fatal) override;
+ void OnCreateDevice() override;
private:
unsigned int GetMemoryUsage(unsigned int pitch) const;
@@ -191,8 +190,8 @@ public:
ID3DX11Effect *Get() const { return m_effect; };
- virtual void OnDestroyDevice();
- virtual void OnCreateDevice();
+ void OnDestroyDevice(bool fatal) override;
+ void OnCreateDevice() override;
private:
bool CreateEffect();
@@ -218,8 +217,8 @@ public:
DXGI_FORMAT GetFormat() { return m_format; }
ID3D11Buffer* Get() const { return m_buffer; };
- virtual void OnDestroyDevice();
- virtual void OnCreateDevice();
+ void OnDestroyDevice(bool fatal) override;
+ void OnCreateDevice() override;
private:
bool CreateBuffer(const void *pData);
D3D11_BIND_FLAG m_type;
@@ -247,8 +246,8 @@ public:
void Release();
bool IsInited() { return m_inited; }
- virtual void OnDestroyDevice();
- virtual void OnCreateDevice();
+ void OnDestroyDevice(bool fatal) override;
+ void OnCreateDevice() override;
private:
bool CreateInternal();
@@ -275,8 +274,8 @@ public:
void Release();
bool IsInited() { return m_inited; }
- virtual void OnDestroyDevice();
- virtual void OnCreateDevice();
+ void OnDestroyDevice(bool fatal) override;
+ void OnCreateDevice() override;
private:
bool CreateInternal();
diff --git a/xbmc/guilib/GUIFontTTFDX.cpp b/xbmc/guilib/GUIFontTTFDX.cpp
index f87abf74f0..8d2b028b26 100644
--- a/xbmc/guilib/GUIFontTTFDX.cpp
+++ b/xbmc/guilib/GUIFontTTFDX.cpp
@@ -348,7 +348,7 @@ void CGUIFontTTFDX::CreateStaticIndexBuffer(void)
bool CGUIFontTTFDX::m_staticIndexBufferCreated = false;
ID3D11Buffer* CGUIFontTTFDX::m_staticIndexBuffer = nullptr;
-void CGUIFontTTFDX::OnDestroyDevice(void)
+void CGUIFontTTFDX::OnDestroyDevice(bool fatal)
{
SAFE_RELEASE(m_staticIndexBuffer);
m_staticIndexBufferCreated = false;
diff --git a/xbmc/guilib/GUIFontTTFDX.h b/xbmc/guilib/GUIFontTTFDX.h
index c66ce34273..4b906ae90c 100644
--- a/xbmc/guilib/GUIFontTTFDX.h
+++ b/xbmc/guilib/GUIFontTTFDX.h
@@ -44,21 +44,21 @@ public:
CGUIFontTTFDX(const std::string& strFileName);
virtual ~CGUIFontTTFDX(void);
- virtual bool FirstBegin();
- virtual void LastEnd();
- virtual CVertexBuffer CreateVertexBuffer(const std::vector<SVertex> &vertices) const;
- virtual void DestroyVertexBuffer(CVertexBuffer &bufferHandle) const;
+ bool FirstBegin() override;
+ void LastEnd() override;
+ CVertexBuffer CreateVertexBuffer(const std::vector<SVertex> &vertices) const override;
+ void DestroyVertexBuffer(CVertexBuffer &bufferHandle) const override;
- virtual void OnDestroyDevice();
- virtual void OnCreateDevice();
+ void OnDestroyDevice(bool fatal) override;
+ void OnCreateDevice() override;
static void CreateStaticIndexBuffer(void);
static void DestroyStaticIndexBuffer(void);
protected:
- virtual CBaseTexture* ReallocTexture(unsigned int& newHeight);
- virtual bool CopyCharToTexture(FT_BitmapGlyph bitGlyph, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2);
- virtual void DeleteHardwareTexture();
+ CBaseTexture* ReallocTexture(unsigned int& newHeight) override;
+ bool CopyCharToTexture(FT_BitmapGlyph bitGlyph, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) override;
+ void DeleteHardwareTexture() override;
private:
bool UpdateDynamicVertexBuffer(const SVertex* pSysMem, unsigned int count);
diff --git a/xbmc/rendering/dx/RenderSystemDX.cpp b/xbmc/rendering/dx/RenderSystemDX.cpp
index 21c571db1d..bf072bd8d5 100644
--- a/xbmc/rendering/dx/RenderSystemDX.cpp
+++ b/xbmc/rendering/dx/RenderSystemDX.cpp
@@ -418,7 +418,14 @@ void CRenderSystemDX::DeleteDevice()
// tell any shared resources
for (std::vector<ID3DResource *>::iterator i = m_resources.begin(); i != m_resources.end(); ++i)
- (*i)->OnDestroyDevice();
+ {
+ // the most of resources like textures and buffers try to
+ // receive and save their status from current device.
+ // m_nDeviceStatus contains the last device status and
+ // DXGI_ERROR_DEVICE_REMOVED means that we have no possibility
+ // to use the device anymore, tell all resouces about this.
+ (*i)->OnDestroyDevice(DXGI_ERROR_DEVICE_REMOVED == m_nDeviceStatus);
+ }
if (m_pSwapChain)
m_pSwapChain->SetFullscreenState(false, nullptr);