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"
25 using namespace Microsoft::WRL;
26 using namespace Windows::Foundation;
27 using namespace Windows::Foundation::Collections;
28 using namespace Windows::UI::Core;
29 using namespace DirectX;
31 tbbTachyonRenderer::tbbTachyonRenderer() :
36 tbbTachyonRenderer::~tbbTachyonRenderer()
40 void tbbTachyonRenderer::CreateDeviceIndependentResources()
42 DirectXBase::CreateDeviceIndependentResources();
45 m_dwriteFactory->CreateTextFormat(
48 DWRITE_FONT_WEIGHT_NORMAL,
49 DWRITE_FONT_STYLE_NORMAL,
50 DWRITE_FONT_STRETCH_NORMAL,
58 m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING)
63 unsigned int __stdcall example_main(void*);
65 float g_ratiox, g_ratioy;
66 extern unsigned int *g_pImg;
67 extern int g_sizex, g_sizey;
68 extern int global_xsize, global_ysize;
69 extern int volatile global_number_of_threads;
70 extern volatile long global_startTime;
71 extern volatile long global_elapsedTime;
75 void tbbTachyonRenderer::CreateDeviceResources()
78 DirectXBase::CreateDeviceResources();
81 m_d2dContext->CreateSolidColorBrush(
82 D2D1::ColorF(D2D1::ColorF::Green),
87 D2D1_BITMAP_PROPERTIES1 properties = D2D1::BitmapProperties1(
88 D2D1_BITMAP_OPTIONS_TARGET,
90 DXGI_FORMAT_R8G8B8A8_UNORM,
91 D2D1_ALPHA_MODE_IGNORE
96 //Setting manual rendering size
98 global_ysize = int(global_xsize/m_window->Bounds.Width*m_window->Bounds.Height);
99 D2D1_SIZE_U opacityBitmapSize = D2D1::SizeU(global_xsize, global_ysize);
102 m_d2dContext->CreateBitmap(
105 sizeof(unsigned int)*g_sizex,
111 m_d2dContext->SetTarget(m_opacityBitmap.Get());
112 m_d2dContext->BeginDraw();
114 m_d2dContext->Clear(D2D1::ColorF(D2D1::ColorF::Black, 0.0f));
117 m_d2dContext->EndDraw()
120 std::thread* thread_tmp=new std::thread(example_main, (void*)NULL);
124 void tbbTachyonRenderer::CreateWindowSizeDependentResources()
126 DirectXBase::CreateWindowSizeDependentResources();
129 void tbbTachyonRenderer::Render()
131 D2D1_SIZE_F size = m_d2dContext->GetSize();
134 if (video && video->running)
135 global_elapsedTime=(long)(time(NULL)-global_startTime);
137 Platform::String^ text= "Running in " +
138 (global_number_of_threads == tbb::task_scheduler_init::automatic? "all hardware threads: ":
139 global_number_of_threads.ToString() + (global_number_of_threads==1?" thread: ":" threads: ")) +
140 global_elapsedTime.ToString() + (global_elapsedTime>1?" seconds":" second");
142 g_ratiox=float(size.width/1024.0);
143 g_ratioy=float(size.height/512.0);
146 m_dwriteFactory->CreateTextLayout(
156 m_textLayout->GetMetrics(&m_textMetrics);
159 m_d2dContext->BeginDraw();
161 if(g_pImg)m_opacityBitmap->CopyFromMemory( NULL,(BYTE*)g_pImg, sizeof(unsigned int)*g_sizex );
163 m_d2dContext->DrawBitmap( m_opacityBitmap.Get(), D2D1::RectF(0,0,size.width,size.height) );
166 m_d2dContext->DrawTextLayout(
167 D2D1::Point2F(0.0f, 0.0f),
170 D2D1_DRAW_TEXT_OPTIONS_CLIP
174 HRESULT hr = m_d2dContext->EndDraw();
176 if (hr == D2DERR_RECREATE_TARGET){
177 m_d2dContext->SetTarget(nullptr);
178 m_d2dTargetBitmap = nullptr;
179 CreateWindowSizeDependentResources();
181 DX::ThrowIfFailed(hr);
184 m_renderNeeded = false;