Path: blob/master/samples/wp8/OcvImageManipulation/PhoneXamlDirect3DApp1/PhoneXamlDirect3DApp1Comp/Direct3DContentProvider.cpp
16344 views
#include "pch.h"1#include "Direct3DContentProvider.h"23using namespace PhoneXamlDirect3DApp1Comp;45Direct3DContentProvider::Direct3DContentProvider(Direct3DInterop^ controller) :6m_controller(controller)7{8m_controller->RequestAdditionalFrame += ref new RequestAdditionalFrameHandler([=] ()9{10if (m_host)11{12m_host->RequestAdditionalFrame();13}14});1516m_controller->RecreateSynchronizedTexture += ref new RecreateSynchronizedTextureHandler([=] ()17{18if (m_host)19{20m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture);21}22});23}2425// IDrawingSurfaceContentProviderNative interface26HRESULT Direct3DContentProvider::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host)27{28m_host = host;2930return m_controller->Connect(host);31}3233void Direct3DContentProvider::Disconnect()34{35m_controller->Disconnect();36m_host = nullptr;37m_synchronizedTexture = nullptr;38}3940HRESULT Direct3DContentProvider::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty)41{42return m_controller->PrepareResources(presentTargetTime, contentDirty);43}4445HRESULT Direct3DContentProvider::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle)46{47HRESULT hr = S_OK;4849if (!m_synchronizedTexture)50{51hr = m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture);52}5354// Set output parameters.55textureSubRectangle->left = 0.0f;56textureSubRectangle->top = 0.0f;57textureSubRectangle->right = static_cast<FLOAT>(size->width);58textureSubRectangle->bottom = static_cast<FLOAT>(size->height);5960m_synchronizedTexture.CopyTo(synchronizedTexture);6162// Draw to the texture.63if (SUCCEEDED(hr))64{65hr = m_synchronizedTexture->BeginDraw();6667if (SUCCEEDED(hr))68{69hr = m_controller->GetTexture(size, synchronizedTexture, textureSubRectangle);70}7172m_synchronizedTexture->EndDraw();73}7475return hr;76}7778