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.
9 #include "GUIRenderingControl.h"
11 #include "guilib/IRenderingCallback.h"
15 #include "rendering/dx/DeviceResources.h"
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
;
29 CGUIRenderingControl::CGUIRenderingControl(const CGUIRenderingControl
&from
)
32 ControlType
= GUICONTROL_RENDERADDON
;
36 bool CGUIRenderingControl::InitCallback(IRenderingCallback
*callback
)
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
;
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
;
54 device
= DX::DeviceResources::Get()->GetD3DDevice();
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
;
61 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
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
)
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())
81 CGUIControl::Process(currentTime
, dirtyregions
);
84 void CGUIRenderingControl::Render()
86 std::unique_lock
<CCriticalSection
> lock(m_rendering
);
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
92 CServiceBroker::GetWinSystem()->GetGfxContext().SetViewPort(m_posX
, m_posY
, m_width
, m_height
);
93 CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock();
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
110 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
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
);