[WASAPI] fix stream types and frequencies enumeration
[xbmc.git] / xbmc / guilib / GUIRenderingControl.cpp
blobf6e460b19e008844da1a8779bd81702a3102672f
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIRenderingControl.h"
11 #include "guilib/IRenderingCallback.h"
13 #include <mutex>
14 #ifdef TARGET_WINDOWS
15 #include "rendering/dx/DeviceResources.h"
16 #endif
18 #define LABEL_ROW1 10
19 #define LABEL_ROW2 11
20 #define LABEL_ROW3 12
22 CGUIRenderingControl::CGUIRenderingControl(int parentID, int controlID, float posX, float posY, float width, float height)
23 : CGUIControl(parentID, controlID, posX, posY, width, height)
25 ControlType = GUICONTROL_RENDERADDON;
26 m_callback = NULL;
29 CGUIRenderingControl::CGUIRenderingControl(const CGUIRenderingControl &from)
30 : CGUIControl(from)
32 ControlType = GUICONTROL_RENDERADDON;
33 m_callback = NULL;
36 bool CGUIRenderingControl::InitCallback(IRenderingCallback *callback)
38 if (!callback)
39 return false;
41 std::unique_lock<CCriticalSection> lock(m_rendering);
42 CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock();
43 float x = CServiceBroker::GetWinSystem()->GetGfxContext().ScaleFinalXCoord(GetXPosition(), GetYPosition());
44 float y = CServiceBroker::GetWinSystem()->GetGfxContext().ScaleFinalYCoord(GetXPosition(), GetYPosition());
45 float w = CServiceBroker::GetWinSystem()->GetGfxContext().ScaleFinalXCoord(GetXPosition() + GetWidth(), GetYPosition() + GetHeight()) - x;
46 float h = CServiceBroker::GetWinSystem()->GetGfxContext().ScaleFinalYCoord(GetXPosition() + GetWidth(), GetYPosition() + GetHeight()) - y;
47 if (x < 0) x = 0;
48 if (y < 0) y = 0;
49 if (x + w > CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth()) w = CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth() - x;
50 if (y + h > CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight()) h = CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight() - y;
52 void *device = NULL;
53 #if TARGET_WINDOWS
54 device = DX::DeviceResources::Get()->GetD3DDevice();
55 #endif
56 if (callback->Create((int)(x+0.5f), (int)(y+0.5f), (int)(w+0.5f), (int)(h+0.5f), device))
57 m_callback = callback;
58 else
59 return false;
61 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
62 return true;
65 void CGUIRenderingControl::UpdateVisibility(const CGUIListItem *item)
67 // if made invisible, start timer, only free addonptr after
68 // some period, configurable by window class
69 CGUIControl::UpdateVisibility(item);
70 if (!IsVisible() && m_callback)
71 FreeResources();
74 void CGUIRenderingControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
76 //! @todo Add processing to the addon so it could mark when actually changing
77 std::unique_lock<CCriticalSection> lock(m_rendering);
78 if (m_callback && m_callback->IsDirty())
79 MarkDirtyRegion();
81 CGUIControl::Process(currentTime, dirtyregions);
84 void CGUIRenderingControl::Render()
86 std::unique_lock<CCriticalSection> lock(m_rendering);
87 if (m_callback)
89 // set the viewport - note: We currently don't have any control over how
90 // the addon renders, so the best we can do is attempt to define
91 // a viewport??
92 CServiceBroker::GetWinSystem()->GetGfxContext().SetViewPort(m_posX, m_posY, m_width, m_height);
93 CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock();
94 m_callback->Render();
95 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
96 CServiceBroker::GetWinSystem()->GetGfxContext().RestoreViewPort();
99 CGUIControl::Render();
102 void CGUIRenderingControl::FreeResources(bool immediately)
104 std::unique_lock<CCriticalSection> lock(m_rendering);
106 if (!m_callback) return;
108 CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock(); //! @todo locking
109 m_callback->Stop();
110 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
111 m_callback = NULL;
114 bool CGUIRenderingControl::CanFocusFromPoint(const CPoint &point) const
115 { // mouse is allowed to focus this control, but it doesn't actually receive focus
116 return IsVisible() && HitTest(point);