-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathmain.cpp
More file actions
866 lines (741 loc) · 24.7 KB
/
Copy pathmain.cpp
File metadata and controls
866 lines (741 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
//******************************************************************************
// Copyright (c) 2001-2005 Tweak Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
//******************************************************************************
#ifdef _MSC_VER
//
// We are targetting at least XP, (IE no windows95, etc).
//
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#include <winsock2.h>
#include <windows.h>
#include <winnt.h>
#include <wincon.h>
#include <pthread.h>
//
// NOTE: win_pthreads, which supplies implement.h, seems
// targetted at an earlier version of windows (pre-XP). If you
// include implement.h here, it won't compile. But as far as I
// can tell, it's not needed, so just leave it out.
//
// #include <implement.h>
#endif
#ifdef PLATFORM_LINUX
#include <sched.h>
#endif
#ifndef PLATFORM_LINUX
#include <GL/glew.h>
#endif
#include <RvCommon/GLView.h>
#include "../../utf8Main.h"
#include <RvCommon/QTUtils.h>
#include <RvCommon/RvApplication.h>
#include <RvCommon/RvConsoleWindow.h>
#include <RvCommon/MuUICommands.h>
#include <RvCommon/PyUICommands.h>
#include <RvCommon/RvPreferences.h>
#include <IOproxy/IOproxy.h>
#include <MovieProxy/MovieProxy.h>
#include <MovieSideCar/MovieSideCarIO.h>
#include <ImfHeader.h>
#include <ImfThreading.h>
#include <MovieFB/MovieFB.h>
#include <MovieProcedural/MovieProcedural.h>
#include <MuGL/GLModule.h>
#include <MuIO/IOModule.h>
#include <MuTwkApp/MuInterface.h>
#include <PyTwkApp/PyInterface.h>
#include <IPCore/Application.h>
#include <IPCore/NodeDefinition.h>
#include <RvApp/CommandsModule.h>
#include <RvApp/PyCommandsModule.h>
#include <RvApp/Options.h>
#include <RvPackage/PackageManager.h>
#include <TwkApp/Document.h>
#include <TwkDeploy/Deploy.h>
#include <QTBundle/QTBundle.h>
#include <TwkQtCoreUtil/QtConvert.h>
#include <TwkExc/TwkExcException.h>
#include <TwkFB/IO.h>
#include <TwkFB/TwkFBThreadPool.h>
#include <TwkMovie/MovieIO.h>
#include <TwkUtil/FrameUtils.h>
#include <TwkUtil/SystemInfo.h>
#include <TwkUtil/Daemon.h>
#include <TwkUtil/File.h>
#include <TwkUtil/PathConform.h>
#include <TwkUtil/FourCC.h>
#include <TwkUtil/ThreadName.h>
#include <TwkUtil/MemPool.h>
#include <TwkGLF/GLPixelBufferObjectPool.h>
#include <arg.h>
#include <fstream>
#include <iostream>
#include <iterator>
#include <thread>
#include <sched.h>
#include <sstream>
#include <stdlib.h>
#include <stl_ext/thread_group.h>
#include <signal.h>
#include <string.h>
#include <vector>
#ifndef PLATFORM_WINDOWS
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
#else
#include <TwkGLFFBO/FBOVideoDevice.h>
#include <IPCore/ImageRenderer.h>
#endif
#if defined(RV_VFX_CY2023)
#include <QTextCodec>
#endif
#include <QtWidgets/QtWidgets>
#include <QtGui/QtGui>
#include <RvCommon/RvDocument.h>
// TODO_QT: Remove if everything works.
// Assuming it is not needed: qtGlobals.cpp stopped being generated since Qt 4.6
// #include <QtGlobal>
extern const char* rv_linux_dark;
// RV third party optional customization
#if defined(RV_THIRD_PARTY_CUSTOMIZATION)
extern void rvThirdPartyCustomization(TwkApp::Bundle& bundle, char* licarg);
#endif
//
// Check that a version actually exists. If we're compiling opt error
// out in cpp. Otherwise, just note the lack of version info.
//
#if MAJOR_VERSION == 99
#if NDEBUG
// #error ********* NO VERSION INFORMATION ***********
#else
#ifndef _MSC_VER
#warning********* NO VERSION INFORMATION ***********
#endif
#endif
#endif
#ifdef WIN32
#define FILE_SEP ";"
#else
#define FILE_SEP ":"
#endif
using namespace std;
using namespace TwkFB;
using namespace TwkMovie;
using namespace TwkUtil;
extern const char* TweakDark;
#if !defined(PLATFORM_WINDOWS)
static void control_c_handler(int sig)
{
cout << "INFO: stopped by user" << endl;
exit(1);
}
#endif
void setEnvVar(const string& var, const string& val)
{
#ifdef WIN32
ostringstream str;
str << var << "=" << val;
putenv(str.str().c_str());
#else
setenv(var.c_str(), val.c_str(), 1);
#endif
}
void setEnvVar(const string& var, const QFileInfo& val) { setEnvVar(var, val.absoluteFilePath().toUtf8().data()); }
void addToEnvVar(const string& var, const string& val)
{
if (getenv(var.c_str()))
{
ostringstream str;
str << getenv(var.c_str()) << FILE_SEP << val;
setEnvVar(var, str.str());
}
else
{
setEnvVar(var, val);
}
}
string scarfFile(const string& fileName)
{
ifstream in(fileName.c_str(), ios::binary);
stringstream buffer;
buffer << in.rdbuf();
return buffer.str();
}
#define EXECUTABLE_SHORT_NAME "rv"
#define EXECUTABLE_SHORT_NAME_CAPS "RV"
TwkApp::QTBundle bundle(EXECUTABLE_SHORT_NAME, MAJOR_VERSION, MINOR_VERSION, REVISION_NUMBER);
#ifdef PLATFORM_LINUX
extern "C" int XInitThreads();
#endif
//
// This function is an attempt to prevent QCoreApplication::initLocale() method
// to complain that an invalid locale is currently set.
//
// Before this bugfix, RV's init code explicitely set the current locale to "C".
// At the same time, this locale is now explicitely unsupported by Qt6, and
// instead will instead switch to "C.UTF-8" under Linux, or "UTF-8" under Darwin
// (macOS)
//
// For more information about how Qt initializes the locale, look at
// initLocale() in the file:
//
// QT_HOME/Qt6.x.x/Src/qtbase/src/corelib/kernel/qcoreapplication.cpp
//
static void setPlatformSpecificLocale()
{
std::string locale = "";
#if defined(PLATFORM_DARWIN)
// In Darwin, "C.UTF-8" isn't directly supported, but we can use any
// "<region>.UTF-8" locale. However, as per Qt's initLocale() method
// for in macOS, there is...
//
// ..."no need to try language or region specific CTYPEs, as they
// all point back to the same generic UTF-8 CTYPE."
//
// NOTE: Leaving this here for completeness for the curious minded,
// but the main.cpp file for macOS is actually src/bin/nsapps/RV/main.cpp
locale = "UTF-8";
#elif defined(PLATFORM_LINUX)
// this is valid for Rocky Linux. As per the Qt code, some other Unixes may
// also support "C.utf-8" as an alias to C.UTF-8", but for Rocky Linux there
// is no need.
locale = "C.UTF-8";
#elif defined(WIN32)
// Under Windows, it seems Qt does not try to enfore switching to "C.UTF-8",
// (as this function only seems to be compiled for unix-variants).
// Therefore, we leave it as the "C" locale.
locale = "C";
#endif
setEnvVar("LANG", locale);
setEnvVar("LC_ALL", locale);
// cout << "Set locale to " << locale.c_str() << endl; // for debugging at
// console
}
int utf8Main(int argc, char* argv[])
{
#ifdef PLATFORM_LINUX
XInitThreads();
#endif
#ifdef PLATFORM_WINDOWS
// High DPI support is disabled by default on Windows.
// This is a temporary measure due to reported crashes with
// QtWebEngineWidgets in Qt 6.5.3 on high DPI displays. To enable High DPI
// support, set the environment variable "RV_QT_HDPI_SUPPORT". Note: The
// "RV_QT_HDPI_SUPPORT" environment variable was also used in previous
// versions of RV.
const bool noHighDPISupport = getenv("RV_QT_HDPI_SUPPORT") == nullptr;
#else
// High DPI support is enabled by default on non-Windows platforms.
// To disable High DPI support, set the environment variable
// "RV_NO_QT_HDPI_SUPPORT".
const bool noHighDPISupport = getenv("RV_NO_QT_HDPI_SUPPORT") != nullptr;
#endif
if (noHighDPISupport)
{
qunsetenv("QT_SCALE_FACTOR");
qunsetenv("QT_SCREEN_SCALE_FACTORS");
qunsetenv("QT_AUTO_SCREEN_SCALE_FACTOR");
qputenv("QT_ENABLE_HIGHDPI_SCALING", "0");
qunsetenv("QT_SCALE_FACTOR_ROUNDING_POLICY");
qunsetenv("QT_DEVICE_PIXEL_RATIO");
}
const char* pythonPath = getenv("PYTHONPATH");
const char* pythonHome = getenv("PYTHONHOME");
if (pythonPath)
pythonPath = strdup(pythonPath);
if (pythonHome)
pythonHome = strdup(pythonHome);
#ifndef PLATFORM_WINDOWS
//
// Check the per-process limit on open file descriptors and
// reset the soft limit to the hard limit.
//
struct rlimit rlim;
getrlimit(RLIMIT_NOFILE, &rlim);
rlim.rlim_cur = rlim.rlim_max;
setrlimit(RLIMIT_NOFILE, &rlim);
getrlimit(RLIMIT_NOFILE, &rlim);
if (rlim.rlim_cur < rlim.rlim_max)
{
cerr << "WARNING: unable to increase open file limit above " << rlim.rlim_cur << endl;
}
#else
_setmaxstdio(2048);
#endif
#ifdef PLATFORM_WINDOWS
//
// RV is a "GUI" app, so by default we get no output in the
// console, so "rv.exe -help" doesn't work, etc. Here we
// reattach to the starting console, so we do get that
// output.
//
HANDLE hand = GetStdHandle(STD_OUTPUT_HANDLE);
if ((hand == INVALID_HANDLE_VALUE || GetFileType(hand) == FILE_TYPE_UNKNOWN) && AttachConsole(ATTACH_PARENT_PROCESS))
{
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
}
#endif
//
// Check for a valid HOME. If we are on Windows and HOME is not set then
// see if we can create one from concatenating HOMEDRIVE and HOMEPATH.
//
if (!getenv("HOME"))
{
#ifdef PLATFORM_WINDOWS
if (getenv("HOMEDRIVE") && getenv("HOMEPATH"))
{
string home = string(getenv("HOMEDRIVE")) + getenv("HOMEPATH");
setEnvVar("HOME", home.c_str());
cout << "INFO: Using '" << home << "' for $HOME." << endl;
}
else
#endif
{
cerr << "ERROR: $HOME is not set in the environment and is required." << endl;
exit(-1);
}
}
if (getenv("LANG"))
{
std::string originalLocale = getenv("LANG");
setEnvVar("ORIGINALLOCAL", originalLocale.c_str());
}
else
{
setEnvVar("ORIGINALLOCAL", "en");
}
setPlatformSpecificLocale();
// Refresh the locale using the environment variable set by
// setPlatformSpecificLocale.
QLocale::setDefault(QLocale::system());
TwkFB::ThreadPool::initialize();
// Qt 5.12.1 specific
// Disable Qt Quick hardware rendering because QwebEngineView conflicts with
// QGLWidget
setEnvVar("QT_QUICK_BACKEND", "software");
#if defined(PLATFORM_LINUX)
// Work around for Wacom Tablet issue on linux
// Note: This is a Qt 5.12.4 regression
// (https://bugreports.qt.io/browse/QTBUG-77826)
setEnvVar("QT_XCB_TABLET_LEGACY_COORDINATES", "1");
#endif
// Prevent crash at startup when multithreaded upload is enabled
// (RV Preferences/Rendering/Multithread GPU Upload)
QApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
TwkUtil::MemPool::initialize();
string altPrefsPath;
for (size_t i = 0; i < argc; i++)
{
if (i < argc - 1 && !strcmp(argv[i], "-prefsPath"))
altPrefsPath = argv[i + 1];
}
Rv::RvApplication::initializeQSettings(altPrefsPath);
bool noPrefs = false;
bool resetPrefs = false;
Q_INIT_RESOURCE(rv);
//
// Expand any rvlink urls in argv
//
vector<char*> newArgv;
for (int i = 0; i < argc; ++i)
{
if (0 == strncmp("rvlink://", argv[i], 9))
{
Rv::RvApplication::parseURL(argv[i], newArgv);
}
else
newArgv.push_back(argv[i]);
}
argv = &(newArgv[0]);
argc = newArgv.size();
for (size_t i = 0; i < argc; i++)
{
if (!strcmp(argv[i], "-noPrefs"))
noPrefs = true;
else if (!strcmp(argv[i], "-resetPrefs"))
resetPrefs = true;
}
for (size_t i = 0; i < argc; i++)
{
if (!strcmp(argv[i], "-bakeURL"))
{
string url = Rv::RvApplication::bakeCommandLineURL(argc, argv);
cerr << "Baked URL: " << url << endl;
exit(0);
}
if (!strcmp(argv[i], "-encodeURL"))
{
string url = Rv::RvApplication::encodeCommandLineURL(argc, argv);
cerr << "Encoded URL: " << url << endl;
exit(0);
}
}
Rv::Options& opts = Rv::Options::sharedOptions();
if (resetPrefs)
Rv::RvPreferences::resetPreferencesFile();
if (!noPrefs)
Rv::RvPreferences::loadSettingsIntoOptions(opts);
else
Rv::PackageManager::setIgnorePrefs(true);
Rv::Options::manglePerSourceArgs(argv, argc);
Rv::Options prefOpts = opts;
//
// Additional options. These are QT UI look related.
//
//
// Call the deploy functions
//
TWK_DEPLOY_APP_OBJECT dobj(MAJOR_VERSION, MINOR_VERSION, REVISION_NUMBER, argc, argv, RELEASE_DESCRIPTION, "HEAD=" GIT_HEAD);
Imf::staticInitialize();
TwkFB::GenericIO::init(); // Initialize TwkFB::GenericIO plugins statics
TwkMovie::GenericIO::init(); // Initialize TwkMovie::GenericIO plugins
// statics
IPCore::Application::cacheEnvVars();
//
// We handle the '--help' flag by changing it to '-help' for
// argparse to work.
//
for (int i = 0; i < argc; ++i)
{
if (!strcmp("--help", argv[i]))
{
strcpy(argv[i], "-help");
break;
}
}
//
// Parse cmd line args
//
int strictlicense = 0;
char* prefsPath = 0;
int sleepTime = 0;
if (arg_parse(argc, argv, "", "", RV_ARG_EXAMPLES, "", "", RV_ARG_SEQUENCE_HELP, "", "", RV_ARG_SOURCE_OPTIONS(opts), "", "", "",
ARG_SUBR(Rv::RvApplication::parseInFiles), "Input sequence patterns, images, movies, or directories ",
RV_ARG_PARSE_OPTIONS(opts), "-strictlicense", ARG_FLAG(&strictlicense),
"Exit rather than consume an RV license if no rvsolo licenses are "
"available",
"-prefsPath %S", &prefsPath, "Alternate path to preferences directory",
#if defined(PLATFORM_LINUX)
"-scheduler %S", &opts.schedulePolicy, "Thread scheduling policy (may require root)", "-priorities %d %d",
&opts.displayPriority, &opts.audioPriority, "Set display and audio thread priorities (may require root)",
#endif
"-sleep %d", &sleepTime, "Sleep (in seconds) before starting to allow attaching debugger", NULL)
< 0)
{
exit(-1);
}
//
// Qt itself (on linux) will consider the -geometry flag to be
// a traditional X11 geometry flag, which it's not, so prevent
// this by switching it to "geometri" if it's in argv.
//
for (int i = 0; i < argc; ++i)
if (strcmp(argv[i], "-geometry") == 0)
argv[i][8] = 'i';
if (sleepTime > 0)
{
cout << "INFO: sleeping " << sleepTime << " seconds" << endl;
std::this_thread::sleep_for(std::chrono::seconds(sleepTime));
cout << "INFO: continuing after sleep" << endl;
}
if (opts.showVersion)
{
cout << MAJOR_VERSION << "." << MINOR_VERSION << "." << REVISION_NUMBER << endl;
exit(0);
}
//
// Desktop aware: being "desktop aware" may be causing problems
// on some systems
//
QApplication::setDesktopSettingsAware(opts.qtdesktop == 1);
//
// Set scheduling parameters for display thread
//
if (opts.schedulePolicy)
{
#if defined(PLATFORM_LINUX)
sched_param sp;
memset(&sp, 0, sizeof(sched_param));
sp.sched_priority = opts.displayPriority;
unsigned int policy = SCHED_OTHER;
if (!strcmp(opts.schedulePolicy, "SCHED_RR"))
policy = SCHED_RR;
else if (!strcmp(opts.schedulePolicy, "SCHED_FIFO"))
policy = SCHED_FIFO;
if (policy != SCHED_OTHER)
{
if (sched_setscheduler(0, policy, &sp))
{
cout << "ERROR: can't set thread priority" << endl;
}
}
else
{
if (setpriority(PRIO_PROCESS, 0, opts.displayPriority))
{
cout << "ERROR: can't set thread priority" << endl;
}
}
#elif defined(PLATFORM_DARWIN)
// don't bother here ... use RV or RV64 instead
#else
// Uh... windoz
#endif
}
//
// Banners
//
TWK_DEPLOY_SHOW_PROGRAM_BANNER(cout);
TWK_DEPLOY_SHOW_COPYRIGHT_BANNER(cout);
TWK_DEPLOY_SHOW_LOCAL_BANNER(cout);
//
// Get CPU info and tell the EXR library to use them all
//
if (opts.exrcpus > 0)
{
Imf::setGlobalThreadCount(opts.exrcpus);
}
else
{
Imf::setGlobalThreadCount(TwkUtil::SystemInfo::numCPUs() > 1 ? (TwkUtil::SystemInfo::numCPUs() - 1) : 1);
}
//
// Additional options. These are QT UI look related.
//
// Required by the Live Review RV plugin React component's scroll bars
std::vector<char*> arguments(argv, argv + argc);
static char enableOverlayScrollbar[] = "--enable-features=OverlayScrollbar";
arguments.emplace_back(enableOverlayScrollbar);
argc = static_cast<int>(arguments.size());
argv = &arguments[0];
//
// Application
//
QApplication* app = new QApplication(argc, argv);
QTranslator* translator = new QTranslator();
QLocale locale = QLocale(getenv("ORIGINALLOCAL"));
if (translator->load(locale, QLatin1String("i18n"), "_", QLatin1String(":/translations")))
{
app->installTranslator(translator);
}
QDir dir(QCoreApplication::applicationDirPath());
dir.cdUp();
dir.cd("plugins");
dir.cd("Qt");
QApplication::addLibraryPath(dir.absolutePath());
Rv::RvApplication* rvapp = new Rv::RvApplication(argc, argv);
rvapp->setExecutableNameCaps("RV");
app->installEventFilter(rvapp);
app->setQuitOnLastWindowClosed(true);
//
// Get the bundle info so we can find resource files
//
// init priorities are:
//
// 1) -init script
// 2) $RV_INIT
// 3) $HOME/.rvrc.mu
// 4) $RV_HOME/scripts/rv/rvrc.mu
// 5) ./rvrc.mu
//
if (bundle.top() == "")
{
cerr << "ERROR: can't locate RV home directory (is it installed in "
"root?)"
<< endl;
exit(-1);
}
bundle.setEnvVar("RV_PYTHONPATH_EXTERNAL", (pythonPath) ? pythonPath : "");
bundle.setEnvVar("RV_PYTHONHOME_EXTERNAL", (pythonHome) ? pythonHome : "");
if (getenv("RV_APP_RVIO"))
bundle.setEnvVar("RV_APP_RVIO_SET_BY_USER", "true");
else
bundle.setEnvVar("RV_APP_RVIO", bundle.executableFile("rvio"));
bundle.setEnvVar("RV_APP_RV_SHORT_NAME", EXECUTABLE_SHORT_NAME);
bundle.setEnvVar("RV_APP_RV", bundle.executableFile(EXECUTABLE_SHORT_NAME));
bundle.setEnvVar("RV_APP_MANUAL", bundle.resource("rv_manual", "pdf"));
bundle.setEnvVar("RV_APP_MANUAL_HTML", bundle.resource("rv_manual", "html"));
bundle.setEnvVar("RV_APP_SDI_MANUAL", bundle.resource("rvsdi_manual", "pdf"));
bundle.setEnvVar("RV_APP_SDI_MANUAL_HTML", bundle.resource("rvsdi_manual", "html"));
bundle.setEnvVar("RV_APP_REFERENCE_MANUAL", bundle.resource("rv_reference", "pdf"));
bundle.setEnvVar("RV_APP_REFERENCE_MANUAL_HTML", bundle.resource("rv_reference", "html"));
bundle.setEnvVar("RV_APP_MU_MANUAL", bundle.resource("mu", "pdf"));
bundle.setEnvVar("RV_APP_GTO_REFERENCE", bundle.resource("gto", "pdf"));
bundle.setEnvVar("RV_APP_RELEASE_NOTES", bundle.resource("rv_release_notes", "html"));
bundle.setEnvVar("RV_APP_LICENSES_NOTES", bundle.resource("rv_client_licenses", "html"));
bundle.addPathToEnvVar("OIIO_LIBRARY_PATH", bundle.appPluginPath("OIIO"));
//
// Find the init file
//
string muInitFile = bundle.rcfile("rvrc", "mu", "RV_INIT");
string pyInitFile = bundle.rcfile("rvrc", "py", "RV_PYINIT");
bundle.setEnvVar("RV_APP_INIT", muInitFile.c_str());
bundle.setEnvVar("RV_APP_PYINIT", pyInitFile.c_str());
if (opts.initscript)
muInitFile = opts.initscript;
// RV third party optional customization
#if defined(RV_THIRD_PARTY_CUSTOMIZATION)
rvThirdPartyCustomization(bundle, opts.licarg);
#endif
try
{
TwkFB::loadProxyPlugins("TWK_FB_PLUGIN_PATH");
TwkMovie::loadProxyPlugins("TWK_MOVIE_PLUGIN_PATH");
}
catch (...)
{
cerr << "WARNING: a problem occured while loading plugins." << endl;
cerr << " some plugins may not have been loaded." << endl;
}
TwkMovie::GenericIO::addPlugin(new MovieFBIO());
TwkMovie::GenericIO::addPlugin(new MovieProceduralIO());
//
// Compile the list of sequencable file extensions
//
TwkFB::GenericIO::compileExtensionSet(predicateFileExtensions());
#ifdef PLATFORM_WINDOWS
DWORD targetClass = HIGH_PRIORITY_CLASS;
if (getenv("RV_REALTIME_PRIORITY_CLASS"))
targetClass = REALTIME_PRIORITY_CLASS;
DWORD proClass1 = GetPriorityClass(GetCurrentProcess());
if (0 == SetPriorityClass(GetCurrentProcess(), targetClass))
{
cerr << "ERROR: SetPriorityClass failed, error " << GetLastError() << endl;
}
DWORD proClass2 = GetPriorityClass(GetCurrentProcess());
if (proClass2 != targetClass)
{
cerr << "WARNING: failed to set Priority Class, class " << hex << showbase << int(proClass1) << " -> " << int(proClass2)
<< noshowbase << dec << endl;
}
#endif
//
// QT starts here
//
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_process_attach_np();
#endif
// Rv::dumpApplicationPalette();
Rv::initializeDefaultPalette();
if (!getenv("RV_DARK"))
bundle.setEnvVar("RV_DARK", "", true);
QString csstext;
if (opts.qtcss)
{
string s = scarfFile(opts.qtcss);
QString qcss = QString(s.c_str());
// Always apply font size parameters - Qt handles missing placeholders
// safely
csstext = qcss.arg(opts.fontSize1).arg(opts.fontSize2).arg(opts.fontSize2 - 1);
}
else
{
csstext = QString(rv_linux_dark).arg(opts.fontSize1).arg(opts.fontSize2).arg(opts.fontSize2 - 1);
}
if (!opts.qtstyle || !strcmp(opts.qtstyle, "RV"))
{
bundle.setEnvVar("RV_DARK", "1", true);
app->setStyle(QStyleFactory::create("Cleanlooks"));
}
else
{
app->setStyle(QStyleFactory::create(opts.qtstyle));
}
app->setStyleSheet(csstext);
try
{
TwkApp::initMu(0);
TwkApp::initPython(argc, argv);
Rv::initUICommands();
Rv::initCommands();
if (!opts.initializeAfterParsing((noPrefs) ? 0 : &prefOpts))
{
rvapp->console()->processLastTextBuffer();
exit(-1);
}
TwkApp::initWithFile(TwkApp::muContext(), TwkApp::muProcess(), TwkApp::muModuleList(), muInitFile.c_str());
TwkApp::pyInitWithFile(pyInitFile.c_str(), Rv::pyRvAppCommands(), Rv::pyUICommands());
}
catch (const exception& e)
{
cerr << "ERROR: during initialization: " << e.what() << endl;
rvapp->console()->processLastTextBuffer();
exit(-1);
}
//
// XXX dummyDev is leaking here. Best would be to pass it to the App so
// that it could delete it after startup, since it's no longer needed at
// that point.
//
#ifdef PLATFORM_WINDOWS
TwkGLF::FBOVideoDevice* dummyDev = new TwkGLF::FBOVideoDevice(0, 10, 10, false);
IPCore::ImageRenderer::queryGL();
const char* glVersion = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
if (!glVersion)
{
cout << "ERROR: no GPU available: GL_SHADING_LANGUAGE_VERSION query failed" << endl;
exit(-1);
}
IPCore::Shader::Function::useShadingLanguageVersion(glVersion);
#endif
//
// Organize the input file list
//
bool dorun = true;
rvapp->createNewSessionFromFiles(opts.inputFiles);
rvapp->processNetworkOpts();
int rval = 0;
rvapp->console()->processTextBuffer();
#if !defined(PLATFORM_WINDOWS)
//
// Overwrite python's signal handler
//
if (signal(SIGINT, control_c_handler) == SIG_ERR)
{
cout << "ERROR: failed to install SIGINT signal handler" << endl;
}
#endif
TwkUtil::setThreadName("RV Main");
if (dorun)
{
try
{
rval = app->exec();
}
catch (TwkExc::Exception& exc)
{
cerr << exc;
exit(-1);
}
catch (const exception& e)
{
cerr << "ERROR: Unhandled exception during execution: " << e.what() << endl;
exit(-1);
}
catch (...)
{
cerr << "ERROR: Unhandled unknown exception" << endl;
exit(-1);
}
}
#ifdef PTW32_STATIC_LIB
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();
#endif
TwkFB::ThreadPool::shutdown();
TwkMovie::GenericIO::shutdown(); // Shutdown TwkMovie::GenericIO plugins
TwkFB::GenericIO::shutdown(); // Shutdown TwkFB::GenericIO plugins
TwkGLF::UninitPBOPools();
// Ensure to delete the QApplication before calling finalizePython
delete rvapp;
delete app;
TwkApp::finalizePython();
return rval;
}