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.

204 lines
5.7 KiB

  1. //
  2. // msaa.cpp
  3. //
  4. // AA stuff.
  5. //
  6. #include "private.h"
  7. #include "ic.h"
  8. #include "tim.h"
  9. #include "dim.h"
  10. #include "msaa.h"
  11. #include "tlapi.h"
  12. extern "C" HRESULT WINAPI TF_PostAllThreadMsg(WPARAM wParam, DWORD dwFlags);
  13. //+---------------------------------------------------------------------------
  14. //
  15. // SystemEnableMSAA
  16. //
  17. // Called by msaa to kick cicero msaa support on the desktop.
  18. //----------------------------------------------------------------------------
  19. STDAPI CMSAAControl::SystemEnableMSAA()
  20. {
  21. if (InterlockedIncrement(&GetSharedMemory()->cMSAARef) == 0)
  22. {
  23. TF_PostAllThreadMsg(TFPRIV_ENABLE_MSAA, TLF_TIMACTIVE);
  24. }
  25. return S_OK;
  26. }
  27. //+---------------------------------------------------------------------------
  28. //
  29. // SystemDisableMSAA
  30. //
  31. // Called by msaa to halt cicero msaa support on the desktop.
  32. //----------------------------------------------------------------------------
  33. STDAPI CMSAAControl::SystemDisableMSAA()
  34. {
  35. if (InterlockedDecrement(&GetSharedMemory()->cMSAARef) == -1)
  36. {
  37. TF_PostAllThreadMsg(TFPRIV_DISABLE_MSAA, TLF_TIMACTIVE);
  38. }
  39. return S_OK;
  40. }
  41. //+---------------------------------------------------------------------------
  42. //
  43. // _InitMSAAHook
  44. //
  45. //----------------------------------------------------------------------------
  46. void CInputContext::_InitMSAAHook(IAccServerDocMgr *pAAAdaptor)
  47. {
  48. IDocWrap *pAADocWrapper;
  49. if (_pMSAAState != NULL)
  50. return; // already inited
  51. Assert(_ptsi != NULL);
  52. // try to allocate some space for the state we'll need to save
  53. // since we rarely use msaa, it's stored separately from the ic
  54. if ((_pMSAAState = (MSAA_STATE *)cicMemAlloc(sizeof(MSAA_STATE))) == NULL)
  55. return;
  56. // back up the original ptsi
  57. _pMSAAState->ptsiOrg = _ptsi;
  58. _ptsi = NULL;
  59. if (CoCreateInstance(CLSID_DocWrap, NULL, CLSCTX_INPROC_SERVER,
  60. IID_IDocWrap, (void **)&pAADocWrapper) != S_OK)
  61. {
  62. goto ExitError;
  63. }
  64. if (pAADocWrapper->SetDoc(IID_ITextStoreAnchor, _pMSAAState->ptsiOrg) != S_OK)
  65. goto ExitError;
  66. if (pAADocWrapper->GetWrappedDoc(IID_ITextStoreAnchor, (IUnknown **)&_pMSAAState->pAADoc) != S_OK)
  67. goto ExitError;
  68. if (pAADocWrapper->GetWrappedDoc(IID_ITextStoreAnchor, (IUnknown **)&_ptsi) != S_OK)
  69. goto ExitError;
  70. if (pAAAdaptor->NewDocument(IID_ITextStoreAnchor, _pMSAAState->pAADoc) != S_OK)
  71. goto ExitError;
  72. pAADocWrapper->Release();
  73. return;
  74. ExitError:
  75. pAADocWrapper->Release();
  76. _UninitMSAAHook(pAAAdaptor);
  77. }
  78. //+---------------------------------------------------------------------------
  79. //
  80. // _UninitMSAAHook
  81. //
  82. //----------------------------------------------------------------------------
  83. void CInputContext::_UninitMSAAHook(IAccServerDocMgr *pAAAdaptor)
  84. {
  85. if (_pMSAAState == NULL)
  86. return; // not inited
  87. pAAAdaptor->RevokeDocument(_pMSAAState->pAADoc);
  88. SafeRelease(_pMSAAState->pAADoc);
  89. SafeRelease(_ptsi);
  90. // restore orig unwrapped doc
  91. _ptsi = _pMSAAState->ptsiOrg;
  92. // free msaa struct
  93. cicMemFree(_pMSAAState);
  94. _pMSAAState = NULL;
  95. }
  96. //+---------------------------------------------------------------------------
  97. //
  98. // _InitMSAA
  99. //
  100. //----------------------------------------------------------------------------
  101. void CThreadInputMgr::_InitMSAA()
  102. {
  103. CDocumentInputManager *dim;
  104. CInputContext *pic;
  105. int iDim;
  106. int iContext;
  107. HRESULT hr;
  108. if (_pAAAdaptor != NULL)
  109. return; // already inited
  110. hr = CoCreateInstance(CLSID_AccServerDocMgr, NULL, CLSCTX_INPROC_SERVER,
  111. IID_IAccServerDocMgr, (void **)&_pAAAdaptor);
  112. if (hr != S_OK || _pAAAdaptor == NULL)
  113. {
  114. _pAAAdaptor = NULL;
  115. return;
  116. }
  117. // now wrap all existing ic's
  118. for (iDim = 0; iDim < _rgdim.Count(); iDim++)
  119. {
  120. dim = _rgdim.Get(iDim);
  121. for (iContext = 0; iContext <= dim->_GetCurrentStack(); iContext++)
  122. {
  123. pic = dim->_GetIC(iContext);
  124. // we need to reset our sinks, so msaa can wrap them
  125. // first, disconnect the sink
  126. pic->_GetTSI()->UnadviseSink(SAFECAST(pic, ITextStoreAnchorSink *));
  127. // now announce the ic
  128. pic->_InitMSAAHook(_pAAAdaptor);
  129. // now reset the sink on the wrapped _ptsi
  130. pic->_GetTSI()->AdviseSink(IID_ITextStoreAnchorSink, SAFECAST(pic, ITextStoreAnchorSink *), TS_AS_ALL_SINKS);
  131. }
  132. }
  133. }
  134. //+---------------------------------------------------------------------------
  135. //
  136. // _UninitMSAA
  137. //
  138. //----------------------------------------------------------------------------
  139. void CThreadInputMgr::_UninitMSAA()
  140. {
  141. CDocumentInputManager *dim;
  142. CInputContext *pic;
  143. int iDim;
  144. int iContext;
  145. if (_pAAAdaptor == NULL)
  146. return; // already uninited
  147. // unwrap all existing ic's
  148. for (iDim = 0; iDim < _rgdim.Count(); iDim++)
  149. {
  150. dim = _rgdim.Get(iDim);
  151. for (iContext = 0; iContext <= dim->_GetCurrentStack(); iContext++)
  152. {
  153. pic = dim->_GetIC(iContext);
  154. // we need to reset our sinks
  155. // first, unadvise the wrapped sinks
  156. pic->_GetTSI()->UnadviseSink(SAFECAST(pic, ITextStoreAnchorSink *));
  157. // unwrap the ptsi
  158. pic->_UninitMSAAHook(_pAAAdaptor);
  159. // now reset the sink on the original _ptsi
  160. pic->_GetTSI()->AdviseSink(IID_ITextStoreAnchorSink, SAFECAST(pic, ITextStoreAnchorSink *), TS_AS_ALL_SINKS);
  161. }
  162. }
  163. _pAAAdaptor->Release();
  164. _pAAAdaptor = NULL;
  165. }