Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/wp8/OcvImageManipulation/PhoneXamlDirect3DApp1/PhoneXamlDirect3DApp1Comp/Direct3DContentProvider.cpp
16344 views
1
#include "pch.h"
2
#include "Direct3DContentProvider.h"
3
4
using namespace PhoneXamlDirect3DApp1Comp;
5
6
Direct3DContentProvider::Direct3DContentProvider(Direct3DInterop^ controller) :
7
m_controller(controller)
8
{
9
m_controller->RequestAdditionalFrame += ref new RequestAdditionalFrameHandler([=] ()
10
{
11
if (m_host)
12
{
13
m_host->RequestAdditionalFrame();
14
}
15
});
16
17
m_controller->RecreateSynchronizedTexture += ref new RecreateSynchronizedTextureHandler([=] ()
18
{
19
if (m_host)
20
{
21
m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture);
22
}
23
});
24
}
25
26
// IDrawingSurfaceContentProviderNative interface
27
HRESULT Direct3DContentProvider::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host)
28
{
29
m_host = host;
30
31
return m_controller->Connect(host);
32
}
33
34
void Direct3DContentProvider::Disconnect()
35
{
36
m_controller->Disconnect();
37
m_host = nullptr;
38
m_synchronizedTexture = nullptr;
39
}
40
41
HRESULT Direct3DContentProvider::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty)
42
{
43
return m_controller->PrepareResources(presentTargetTime, contentDirty);
44
}
45
46
HRESULT Direct3DContentProvider::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle)
47
{
48
HRESULT hr = S_OK;
49
50
if (!m_synchronizedTexture)
51
{
52
hr = m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture);
53
}
54
55
// Set output parameters.
56
textureSubRectangle->left = 0.0f;
57
textureSubRectangle->top = 0.0f;
58
textureSubRectangle->right = static_cast<FLOAT>(size->width);
59
textureSubRectangle->bottom = static_cast<FLOAT>(size->height);
60
61
m_synchronizedTexture.CopyTo(synchronizedTexture);
62
63
// Draw to the texture.
64
if (SUCCEEDED(hr))
65
{
66
hr = m_synchronizedTexture->BeginDraw();
67
68
if (SUCCEEDED(hr))
69
{
70
hr = m_controller->GetTexture(size, synchronizedTexture, textureSubRectangle);
71
}
72
73
m_synchronizedTexture->EndDraw();
74
}
75
76
return hr;
77
}
78