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.
19 #include "DirectXPage.xaml.h"
22 using namespace tbbTachyon;
24 using namespace Platform;
25 using namespace Windows::Foundation;
26 using namespace Windows::Foundation::Collections;
27 using namespace Windows::UI::Input;
28 using namespace Windows::UI::Core;
29 using namespace Windows::UI::Xaml;
30 using namespace Windows::UI::Xaml::Controls;
31 using namespace Windows::UI::Xaml::Controls::Primitives;
32 using namespace Windows::UI::Xaml::Data;
33 using namespace Windows::UI::Xaml::Input;
34 using namespace Windows::UI::Xaml::Media;
35 using namespace Windows::UI::Xaml::Navigation;
36 using namespace Windows::Graphics::Display;
38 #include "src/tachyon_video.h"
39 extern int volatile global_number_of_threads;
40 extern volatile bool global_isCancelled;
42 #pragma intrinsic(_BitScanReverse)
43 static int log2( unsigned int x ) {
45 _BitScanReverse(&i,(DWORD)x);
49 const unsigned interval_step_power = 1;
50 const unsigned num_interval_steps = 1 << (interval_step_power+1);
52 DirectXPage::DirectXPage() :
55 InitializeComponent();
57 m_renderer = ref new tbbTachyonRenderer();
59 m_renderer->Initialize(
60 Window::Current->CoreWindow,
62 DisplayProperties::LogicalDpi
65 m_eventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(this, &DirectXPage::OnRendering));
67 int num_threads = 2*tbb::task_scheduler_init::default_num_threads();
68 // The thread slider has geometric sequence with several intermediate steps for each interval between 2^N and 2^(N+1).
69 // The nearest (from below) the power of 2.
70 int i_base = log2(num_threads);
71 int base = 1 << i_base;
72 // The step size for the current interval.
73 int step = base / num_interval_steps;
74 // The number of steps inside the interval.
75 int i_step = (num_threads-base)/step;
77 ThreadsSlider->Maximum = (i_base-interval_step_power)*num_interval_steps + i_step;
78 global_number_of_threads = m_number_of_threads = tbb::task_scheduler_init::automatic;
81 DirectXPage::~DirectXPage()
85 void DirectXPage::OnRendering(Platform::Object^ sender, Platform::Object^ args)
89 m_renderer->Present();
90 m_renderNeeded = true;
94 void tbbTachyon::DirectXPage::ThreadsApply_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
96 if (global_number_of_threads != m_number_of_threads){
97 global_number_of_threads = m_number_of_threads;
98 global_isCancelled = true;
99 video->running = false;
100 m_renderNeeded = true;
101 ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Collapsed;
105 void tbbTachyon::DirectXPage::Exit_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
107 m_renderNeeded = false;
108 Application::Current->Exit();
111 void tbbTachyon::DirectXPage::ThreadsSliderValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e)
113 int pos = (int) e->NewValue;
115 // The nearest (from below) the power of 2.
116 int base = pos<num_interval_steps ? 0 : 1 << (pos/num_interval_steps+interval_step_power);
117 // The step size for the current interval.
118 int step = max(1,base/num_interval_steps);
119 m_number_of_threads = base + (pos%num_interval_steps)*step;
121 if (m_number_of_threads == 0) m_number_of_threads = tbb::task_scheduler_init::automatic;
123 NumberOfThreadsTextBlock->Text="Number Of Threads: " + (m_number_of_threads == tbb::task_scheduler_init::automatic? "Auto": m_number_of_threads.ToString());
124 if (global_number_of_threads != m_number_of_threads){
125 ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Visible;
127 ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Collapsed;