Direct3DInterop.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include "pch.h"
  3. #include "BasicTimer.h"
  4. #include "CubeRenderer.h"
  5. #include <DrawingSurfaceNative.h>
  6. #include <ppltasks.h>
  7. #include <windows.storage.streams.h>
  8. #include <opencv2\core\core.hpp>
  9. #include <opencv2\imgproc\imgproc.hpp>
  10. #include <opencv2\features2d\features2d.hpp>
  11. namespace PhoneXamlDirect3DApp1Comp
  12. {
  13. public enum class OCVFilterType
  14. {
  15. ePreview,
  16. eGray,
  17. eCanny,
  18. eSepia,
  19. eNumOCVFilterTypes
  20. };
  21. public delegate void RequestAdditionalFrameHandler();
  22. public delegate void RecreateSynchronizedTextureHandler();
  23. [Windows::Foundation::Metadata::WebHostHidden]
  24. public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler
  25. {
  26. public:
  27. Direct3DInterop();
  28. Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider();
  29. // IDrawingSurfaceManipulationHandler
  30. virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost);
  31. event RequestAdditionalFrameHandler^ RequestAdditionalFrame;
  32. event RecreateSynchronizedTextureHandler^ RecreateSynchronizedTexture;
  33. property Windows::Foundation::Size WindowBounds;
  34. property Windows::Foundation::Size NativeResolution;
  35. property Windows::Foundation::Size RenderResolution
  36. {
  37. Windows::Foundation::Size get(){ return m_renderResolution; }
  38. void set(Windows::Foundation::Size renderResolution);
  39. }
  40. void CreateTexture(const Platform::Array<int>^ buffer, int with, int height, OCVFilterType filter);
  41. protected:
  42. // Event Handlers
  43. void OnPointerPressed(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
  44. void OnPointerMoved(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
  45. void OnPointerReleased(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
  46. internal:
  47. HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host);
  48. void STDMETHODCALLTYPE Disconnect();
  49. HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty);
  50. HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle);
  51. ID3D11Texture2D* GetTexture();
  52. private:
  53. CubeRenderer^ m_renderer;
  54. BasicTimer^ m_timer;
  55. Windows::Foundation::Size m_renderResolution;
  56. void ApplyGrayFilter(const cv::Mat& image);
  57. void ApplyCannyFilter(const cv::Mat& image);
  58. void ApplySepiaFilter(const cv::Mat& image);
  59. void UpdateImage(const cv::Mat& image);
  60. cv::Mat Lena;
  61. unsigned int frameWidth, frameHeight;
  62. };
  63. }