Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.9 KiB

  1. #include "stdafx.h"
  2. #include "Motion.h"
  3. #include "Context.h"
  4. #include "Action.h"
  5. /***************************************************************************\
  6. *****************************************************************************
  7. *
  8. * class MotionSC
  9. *
  10. *****************************************************************************
  11. \***************************************************************************/
  12. IMPLEMENT_SUBCONTEXT(Context::slMotion, MotionSC);
  13. //------------------------------------------------------------------------------
  14. MotionSC::~MotionSC()
  15. {
  16. //
  17. // NOTE: The Context (and its SubContexts) can be destroyed on a different
  18. // thread during destruction. It is advisable to allocate any dangling data
  19. // on the Process heap so that it can be safely destroyed at this time.
  20. //
  21. for (UINT idx = 0; idx < SC_MAXCOLORS; idx++) {
  22. if (m_rghbrStd[idx] != NULL) {
  23. DeleteObject(m_rghbrStd[idx]);
  24. }
  25. if (m_rghpenStd[idx] != NULL) {
  26. DeleteObject(m_rghpenStd[idx]);
  27. }
  28. if (m_rgpgpbrStd[idx] != NULL) {
  29. delete m_rgpgpbrStd[idx];
  30. }
  31. if (m_rgpgppenStd[idx] != NULL) {
  32. delete m_rgpgppenStd[idx];
  33. }
  34. }
  35. }
  36. /***************************************************************************\
  37. *
  38. * MotionSC::OnIdle
  39. *
  40. * OnIdle() gives this SubContext an opportunity to perform any idle-time
  41. * processing. This is time when there are no more messages to process.
  42. *
  43. \***************************************************************************/
  44. DWORD
  45. MotionSC::xwOnIdleNL()
  46. {
  47. int nDelta;
  48. DWORD dwDelay, dwCurTick;
  49. dwCurTick = ::GetTickCount();
  50. nDelta = ComputeTickDelta(dwCurTick, m_dwLastTimeslice + m_dwPauseTimeslice);
  51. if (nDelta >= 0) {
  52. //
  53. // The timeslice is up again, so let the Scheduler process the Actions.
  54. //
  55. dwDelay = m_sch.xwProcessActionsNL();
  56. m_dwLastTimeslice = dwCurTick;
  57. } else {
  58. dwDelay = (DWORD) (-nDelta);
  59. }
  60. return dwDelay;
  61. }
  62. /***************************************************************************\
  63. *
  64. * MotionSC::xwPreDestroyNL
  65. *
  66. * xwPreDestroyNL() gives this SubContext an opportunity to perform any cleanup
  67. * while the Context is still valid. Any operations that involve callbacks
  68. * MUST be done at this time.
  69. *
  70. \***************************************************************************/
  71. void
  72. MotionSC::xwPreDestroyNL()
  73. {
  74. //
  75. // When we callback to allow the SubContext's to destroy, we need to
  76. // grab a ContextLock so that we can defer messages. When we leave
  77. // this scope, all of these messages will be triggered. This needs
  78. // to occur BEFORE the Context continues getting blown away.
  79. //
  80. ContextLock cl;
  81. Verify(cl.LockNL(ContextLock::edDefer, m_pParent));
  82. m_sch.xwPreDestroy();
  83. }
  84. //------------------------------------------------------------------------------
  85. Gdiplus::Brush *
  86. MotionSC::GetBrushF(UINT idxBrush) const
  87. {
  88. AssertMsg(idxBrush <= SC_MAXCOLORS, "Ensure valid color");
  89. if (m_rgpgpbrStd[idxBrush] == NULL) {
  90. if (!ResourceManager::IsInitGdiPlus()) {
  91. return NULL;
  92. }
  93. m_rgpgpbrStd[idxBrush] = new Gdiplus::SolidBrush(GdGetColorInfo(idxBrush)->GetColorF());
  94. }
  95. return m_rgpgpbrStd[idxBrush];
  96. }
  97. //------------------------------------------------------------------------------
  98. Gdiplus::Pen *
  99. MotionSC::GetPenF(UINT idxPen) const
  100. {
  101. AssertMsg(idxPen <= SC_MAXCOLORS, "Ensure valid color");
  102. if (m_rgpgppenStd[idxPen] == NULL) {
  103. if (!ResourceManager::IsInitGdiPlus()) {
  104. return NULL;
  105. }
  106. m_rgpgppenStd[idxPen] = new Gdiplus::Pen(GdGetColorInfo(idxPen)->GetColorF());
  107. }
  108. return m_rgpgppenStd[idxPen];
  109. }