Direct3DContentProvider.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "pch.h"
  2. #include "Direct3DContentProvider.h"
  3. using namespace PhoneXamlDirect3DApp1Comp;
  4. Direct3DContentProvider::Direct3DContentProvider(Direct3DInterop^ controller) :
  5. m_controller(controller)
  6. {
  7. m_controller->RequestAdditionalFrame += ref new RequestAdditionalFrameHandler([=] ()
  8. {
  9. if (m_host)
  10. {
  11. m_host->RequestAdditionalFrame();
  12. }
  13. });
  14. m_controller->RecreateSynchronizedTexture += ref new RecreateSynchronizedTextureHandler([=] ()
  15. {
  16. if (m_host)
  17. {
  18. m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture);
  19. }
  20. });
  21. }
  22. // IDrawingSurfaceContentProviderNative interface
  23. HRESULT Direct3DContentProvider::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host)
  24. {
  25. m_host = host;
  26. return m_controller->Connect(host);
  27. }
  28. void Direct3DContentProvider::Disconnect()
  29. {
  30. m_controller->Disconnect();
  31. m_host = nullptr;
  32. m_synchronizedTexture = nullptr;
  33. }
  34. HRESULT Direct3DContentProvider::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty)
  35. {
  36. return m_controller->PrepareResources(presentTargetTime, contentDirty);
  37. }
  38. HRESULT Direct3DContentProvider::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle)
  39. {
  40. HRESULT hr = S_OK;
  41. if (!m_synchronizedTexture)
  42. {
  43. hr = m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture);
  44. }
  45. // Set output parameters.
  46. textureSubRectangle->left = 0.0f;
  47. textureSubRectangle->top = 0.0f;
  48. textureSubRectangle->right = static_cast<FLOAT>(size->width);
  49. textureSubRectangle->bottom = static_cast<FLOAT>(size->height);
  50. m_synchronizedTexture.CopyTo(synchronizedTexture);
  51. // Draw to the texture.
  52. if (SUCCEEDED(hr))
  53. {
  54. hr = m_synchronizedTexture->BeginDraw();
  55. if (SUCCEEDED(hr))
  56. {
  57. hr = m_controller->GetTexture(size, synchronizedTexture, textureSubRectangle);
  58. }
  59. m_synchronizedTexture->EndDraw();
  60. }
  61. return hr;
  62. }