Path: blob/master/samples/wp8/OcvImageManipulation/PhoneXamlDirect3DApp1/PhoneXamlDirect3DApp1Comp/Direct3DInterop.h
16349 views
#pragma once12#include "pch.h"3#include "BasicTimer.h"4#include "QuadRenderer.h"5#include <DrawingSurfaceNative.h>6#include <ppltasks.h>7#include <windows.storage.streams.h>8#include <memory>9#include <mutex>101112#include <opencv2\imgproc\types_c.h>131415namespace PhoneXamlDirect3DApp1Comp16{1718public enum class OCVFilterType19{20ePreview,21eGray,22eCanny,23eBlur,24eFindFeatures,25eSepia,26eNumOCVFilterTypes27};2829class CameraCapturePreviewSink;30class CameraCaptureSampleSink;3132public delegate void RequestAdditionalFrameHandler();33public delegate void RecreateSynchronizedTextureHandler();3435[Windows::Foundation::Metadata::WebHostHidden]36public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler37{38public:39Direct3DInterop();4041Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider();4243// IDrawingSurfaceManipulationHandler44virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost);4546event RequestAdditionalFrameHandler^ RequestAdditionalFrame;47event RecreateSynchronizedTextureHandler^ RecreateSynchronizedTexture;4849property Windows::Foundation::Size WindowBounds;50property Windows::Foundation::Size NativeResolution;51property Windows::Foundation::Size RenderResolution52{53Windows::Foundation::Size get(){ return m_renderResolution; }54void set(Windows::Foundation::Size renderResolution);55}56void SetAlgorithm(OCVFilterType type) { m_algorithm = type; };57void UpdateFrame(byte* buffer, int width, int height);585960protected:61// Event Handlers62void OnPointerPressed(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);63void OnPointerMoved(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);64void OnPointerReleased(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);6566internal:67HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host);68void STDMETHODCALLTYPE Disconnect();69HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty);70HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle);71ID3D11Texture2D* GetTexture();7273private:74void StartCamera();75void ProcessFrame();76bool SwapFrames();7778QuadRenderer^ m_renderer;79Windows::Foundation::Size m_renderResolution;80OCVFilterType m_algorithm;81bool m_contentDirty;82std::shared_ptr<cv::Mat> m_backFrame;83std::shared_ptr<cv::Mat> m_frontFrame;84std::mutex m_mutex;8586Windows::Phone::Media::Capture::AudioVideoCaptureDevice ^pAudioVideoCaptureDevice;87ICameraCaptureDeviceNative* pCameraCaptureDeviceNative;88IAudioVideoCaptureDeviceNative* pAudioVideoCaptureDeviceNative;89CameraCapturePreviewSink* pCameraCapturePreviewSink;90CameraCaptureSampleSink* pCameraCaptureSampleSink;9192//void ApplyPreviewFilter(const cv::Mat& image);93void ApplyGrayFilter(cv::Mat* mat);94void ApplyCannyFilter(cv::Mat* mat);95void ApplyBlurFilter(cv::Mat* mat);96void ApplyFindFeaturesFilter(cv::Mat* mat);97void ApplySepiaFilter(cv::Mat* mat);98};99100class CameraCapturePreviewSink :101public Microsoft::WRL::RuntimeClass<102Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,103ICameraCapturePreviewSink>104{105public:106void SetDelegate(Direct3DInterop^ delegate)107{108m_Direct3dInterop = delegate;109}110111IFACEMETHODIMP_(void) OnFrameAvailable(112DXGI_FORMAT format,113UINT width,114UINT height,115BYTE* pixels);116117private:118Direct3DInterop^ m_Direct3dInterop;119};120121class CameraCaptureSampleSink :122public Microsoft::WRL::RuntimeClass<123Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,124ICameraCaptureSampleSink>125{126public:127void SetDelegate(Direct3DInterop^ delegate)128{129m_Direct3dInterop = delegate;130}131132IFACEMETHODIMP_(void) OnSampleAvailable(133ULONGLONG hnsPresentationTime,134ULONGLONG hnsSampleDuration,135DWORD cbSample,136BYTE* pSample);137138private:139Direct3DInterop^ m_Direct3dInterop;140};141142}143144145