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.

198 lines
4.7 KiB

  1. #include "stdafx.h"
  2. #include "Services.h"
  3. #include "Surface.h"
  4. #include "GdiCache.h"
  5. #include "OSAL.h"
  6. #include "ResourceManager.h"
  7. /***************************************************************************\
  8. *****************************************************************************
  9. *
  10. * class DuDCSurface
  11. *
  12. *****************************************************************************
  13. \***************************************************************************/
  14. //------------------------------------------------------------------------------
  15. HRESULT
  16. DuDCSurface::Build(
  17. IN DuDCSurface::ESource src,
  18. OUT DuDCSurface ** ppsrfNew)
  19. {
  20. DuDCSurface * psrfNew = ClientNew(DuDCSurface);
  21. if (psrfNew == NULL) {
  22. return E_OUTOFMEMORY;
  23. }
  24. switch (src)
  25. {
  26. case srcTempDC:
  27. psrfNew->m_hdc = GetGdiCache()->GetTempDC();
  28. psrfNew->m_fTempDC = TRUE;
  29. break;
  30. case srcCompatibleDC:
  31. psrfNew->m_hdc = GetGdiCache()->GetCompatibleDC();
  32. psrfNew->m_fCompatibleDC = TRUE;
  33. break;
  34. default:
  35. AssertMsg(0, "Unknown DC Source");
  36. }
  37. if (psrfNew->m_hdc == NULL) {
  38. ClientDelete(DuDCSurface, psrfNew);
  39. return DU_E_OUTOFGDIRESOURCES;
  40. }
  41. *ppsrfNew = psrfNew;
  42. return S_OK;
  43. }
  44. //------------------------------------------------------------------------------
  45. HRESULT
  46. DuDCSurface::Build(
  47. IN HDC hdc,
  48. OUT DuDCSurface ** ppsrfNew)
  49. {
  50. Assert(hdc != NULL);
  51. DuDCSurface * psrfNew = ClientNew(DuDCSurface);
  52. if (psrfNew == NULL) {
  53. return E_OUTOFMEMORY;
  54. }
  55. psrfNew->m_hdc = hdc;
  56. *ppsrfNew = psrfNew;
  57. return S_OK;
  58. }
  59. //------------------------------------------------------------------------------
  60. void
  61. DuDCSurface::Destroy()
  62. {
  63. if (m_hdc != NULL) {
  64. if (m_fTempDC) {
  65. GetGdiCache()->ReleaseTempDC(m_hdc);
  66. } else if (m_fCompatibleDC) {
  67. GetGdiCache()->ReleaseCompatibleDC(m_hdc);
  68. }
  69. }
  70. ClientDelete(DuDCSurface, this);
  71. }
  72. //------------------------------------------------------------------------------
  73. void
  74. DuDCSurface::SetIdentityTransform()
  75. {
  76. OS()->SetIdentityTransform(m_hdc);
  77. }
  78. //------------------------------------------------------------------------------
  79. void
  80. DuDCSurface::SetWorldTransform(const XFORM * pxf)
  81. {
  82. OS()->SetWorldTransform(m_hdc, pxf);
  83. }
  84. //------------------------------------------------------------------------------
  85. void *
  86. DuDCSurface::Save()
  87. {
  88. return IntToPtr(SaveDC(m_hdc));
  89. }
  90. //------------------------------------------------------------------------------
  91. void
  92. DuDCSurface::Restore(void * pvState)
  93. {
  94. RestoreDC(m_hdc, PtrToInt(pvState));
  95. }
  96. /***************************************************************************\
  97. *****************************************************************************
  98. *
  99. * class DuGpSurface
  100. *
  101. *****************************************************************************
  102. \***************************************************************************/
  103. //------------------------------------------------------------------------------
  104. HRESULT
  105. DuGpSurface::Build(
  106. IN Gdiplus::Graphics * pgpgr,
  107. OUT DuGpSurface ** ppsrfNew)
  108. {
  109. Assert(pgpgr != NULL);
  110. DuGpSurface * psrfNew = ClientNew(DuGpSurface);
  111. if (psrfNew == NULL) {
  112. return E_OUTOFMEMORY;
  113. }
  114. psrfNew->m_pgpgr = pgpgr;
  115. //
  116. // Initialize common settings on the GDI+ surface
  117. //
  118. pgpgr->SetSmoothingMode(Gdiplus::SmoothingModeHighSpeed);
  119. pgpgr->SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighSpeed);
  120. pgpgr->SetCompositingQuality(Gdiplus::CompositingQualityHighSpeed);
  121. *ppsrfNew = psrfNew;
  122. return S_OK;
  123. }
  124. //------------------------------------------------------------------------------
  125. void
  126. DuGpSurface::Destroy()
  127. {
  128. ClientDelete(DuGpSurface, this);
  129. }
  130. //------------------------------------------------------------------------------
  131. void
  132. DuGpSurface::SetIdentityTransform()
  133. {
  134. m_pgpgr->ResetTransform();
  135. }
  136. //------------------------------------------------------------------------------
  137. void
  138. DuGpSurface::SetWorldTransform(const XFORM * pxf)
  139. {
  140. Gdiplus::Matrix mat(pxf->eM11, pxf->eM12, pxf->eM21, pxf->eM22, pxf->eDx, pxf->eDy);
  141. m_pgpgr->SetTransform(&mat);
  142. }
  143. //------------------------------------------------------------------------------
  144. void *
  145. DuGpSurface::Save()
  146. {
  147. return ULongToPtr(m_pgpgr->Save());
  148. }
  149. //------------------------------------------------------------------------------
  150. void
  151. DuGpSurface::Restore(void * pvState)
  152. {
  153. m_pgpgr->Restore(static_cast<Gdiplus::GraphicsState>(PtrToUlong(pvState)));
  154. }