2 Copyright (c) 2005-2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
18 #include "tbbTachyonRenderer.h"
19 #include <DirectXMath.h>
22 #include "../../src/tachyon_video.h"
24 using namespace Microsoft::WRL;
25 using namespace Windows::Foundation;
26 using namespace Windows::Foundation::Collections;
27 using namespace Windows::UI::Core;
28 using namespace DirectX;
30 tbbTachyonRenderer::tbbTachyonRenderer() :
35 tbbTachyonRenderer::~tbbTachyonRenderer()
39 void tbbTachyonRenderer::CreateDeviceIndependentResources()
41 DirectXBase::CreateDeviceIndependentResources();
44 m_dwriteFactory->CreateTextFormat(
47 DWRITE_FONT_WEIGHT_NORMAL,
48 DWRITE_FONT_STYLE_NORMAL,
49 DWRITE_FONT_STRETCH_NORMAL,
57 m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING)
62 unsigned int __stdcall example_main(void*);
64 float g_ratiox, g_ratioy;
65 extern unsigned int *g_pImg;
66 extern int g_sizex, g_sizey;
67 extern int global_xsize, global_ysize;
68 extern int volatile global_number_of_threads;
69 extern volatile long global_startTime;
70 extern volatile long global_elapsedTime;
74 void tbbTachyonRenderer::CreateDeviceResources()
77 DirectXBase::CreateDeviceResources();
80 m_d2dContext->CreateSolidColorBrush(
81 D2D1::ColorF(D2D1::ColorF::Green),
86 D2D1_BITMAP_PROPERTIES1 properties = D2D1::BitmapProperties1(
87 D2D1_BITMAP_OPTIONS_TARGET,
89 DXGI_FORMAT_R8G8B8A8_UNORM,
90 D2D1_ALPHA_MODE_IGNORE
95 //Setting manual rendering size
97 global_ysize = int(global_xsize/m_window->Bounds.Width*m_window->Bounds.Height);
98 D2D1_SIZE_U opacityBitmapSize = D2D1::SizeU(global_xsize, global_ysize);
101 m_d2dContext->CreateBitmap(
104 sizeof(unsigned int)*g_sizex,
110 m_d2dContext->SetTarget(m_opacityBitmap.Get());
111 m_d2dContext->BeginDraw();
113 m_d2dContext->Clear(D2D1::ColorF(D2D1::ColorF::Black, 0.0f));
116 m_d2dContext->EndDraw()
119 std::thread* thread_tmp=new std::thread(example_main, (void*)NULL);
123 void tbbTachyonRenderer::CreateWindowSizeDependentResources()
125 DirectXBase::CreateWindowSizeDependentResources();
128 void tbbTachyonRenderer::Render()
130 D2D1_SIZE_F size = m_d2dContext->GetSize();
133 if (video && video->running)
134 global_elapsedTime=(long)(time(NULL)-global_startTime);
136 Platform::String^ text= "Running in " +
137 (global_number_of_threads == utility::get_default_num_threads()? "all hardware threads: ":
138 global_number_of_threads.ToString() + (global_number_of_threads==1?" thread: ":" threads: ")) +
139 global_elapsedTime.ToString() + (global_elapsedTime>1?" seconds":" second");
141 g_ratiox=float(size.width/1024.0);
142 g_ratioy=float(size.height/512.0);
145 m_dwriteFactory->CreateTextLayout(
155 m_textLayout->GetMetrics(&m_textMetrics);
158 m_d2dContext->BeginDraw();
160 if(g_pImg)m_opacityBitmap->CopyFromMemory( NULL,(BYTE*)g_pImg, sizeof(unsigned int)*g_sizex );
162 m_d2dContext->DrawBitmap( m_opacityBitmap.Get(), D2D1::RectF(0,0,size.width,size.height) );
165 m_d2dContext->DrawTextLayout(
166 D2D1::Point2F(0.0f, 0.0f),
169 D2D1_DRAW_TEXT_OPTIONS_CLIP
173 HRESULT hr = m_d2dContext->EndDraw();
175 if (hr == D2DERR_RECREATE_TARGET){
176 m_d2dContext->SetTarget(nullptr);
177 m_d2dTargetBitmap = nullptr;
178 CreateWindowSizeDependentResources();
180 DX::ThrowIfFailed(hr);
183 m_renderNeeded = false;