OSDN Git Service

[Qt][MOVIE_SAVER] Record correct screen with one-board-computer, with background...
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / draw_thread.cpp
1 /*
2         Skelton for retropc emulator
3         Author : Takeda.Toshiya
4         Port to Qt : K.Ohta <whatisthis.sowhat _at_ gmail.com>
5         Date   : 2006.08.18 -
6         License : GPLv2
7         History : 2015.11.10 Split from qt_main.cpp
8         [ win32 main ] -> [ Qt main ] -> [Drawing]
9 */
10
11 #include <Qt>
12 #include <QApplication>
13 #include <QImage>
14 #include <QGuiApplication>
15
16 #include <SDL.h>
17 #include "emu.h"
18 #include "osd.h"
19 #include "vm/vm.h"
20
21 #include "qt_main.h"
22 #include "agar_logger.h"
23 #include "mainwidget_base.h"
24 #include "draw_thread.h"
25 #include "qt_glutil_gl2_0.h"
26
27 DrawThreadClass::DrawThreadClass(EMU *p, OSD *o, QObject *parent) : QThread(parent) {
28         MainWindow = (Ui_MainWindowBase *)parent;
29         glv = MainWindow->getGraphicsView();
30         p_emu = emu;
31         p_osd = o;
32         screen = QGuiApplication::primaryScreen();
33         
34         draw_screen_buffer = NULL;
35         
36         do_change_refresh_rate(screen->refreshRate());
37         connect(screen, SIGNAL(refreshRateChanged(qreal)), this, SLOT(do_change_refresh_rate(qreal)));
38         connect(this, SIGNAL(sig_update_screen(bitmap_t *)), glv, SLOT(update_screen(bitmap_t *)));
39         connect(this, SIGNAL(sig_push_frames_to_avio(int, int, int)), glv->extfunc, SLOT(paintGL_OffScreen(int, int, int)));
40         rec_frame_width = 640;
41         rec_frame_height = 480;
42         rec_frame_count = -1;
43
44         bDrawReq = false;
45 }
46
47 DrawThreadClass::~DrawThreadClass()
48 {
49 }
50
51 void DrawThreadClass::SetEmu(EMU *p)
52 {
53                 p_emu = p;
54                 p_osd = p->get_osd();
55 }
56
57
58 void DrawThreadClass::doDraw(bool flag)
59 {
60         QImage *p;
61         if(flag) {
62                 emit sig_draw_timing(true);
63                 draw_frames = p_osd->draw_screen();
64         } else {
65                 draw_frames = 1;
66         }
67         emit sig_draw_frames(draw_frames);
68 }
69
70 void DrawThreadClass::doExit(void)
71 {
72         //AGAR_DebugLog(AGAR_LOG_DEBUG, "DrawThread : Exit.");
73         bRunThread = false;
74         //this->exit(0);
75 }
76
77 void DrawThreadClass::doWork(const QString &param)
78 {
79         bRunThread = true;
80         do {
81                 if(bDrawReq) {
82                         if(draw_screen_buffer != NULL) {
83                                 bDrawReq = false;
84                                 emit sig_update_screen(draw_screen_buffer);
85                         }
86                 }
87                 if(rec_frame_count > 0) {
88                         emit sig_push_frames_to_avio(rec_frame_count,
89                                                                                  rec_frame_width, rec_frame_height);
90                         rec_frame_count = -1;
91                 }
92                 if(wait_count < 1.0f) {
93                         msleep(1);
94                         wait_count = wait_count + wait_refresh - 1.0f;
95                 } else {
96                         wait_factor = (int)wait_count;
97                         msleep(wait_factor);
98                         wait_count -= (qreal)wait_factor;
99                 }
100         } while(bRunThread);
101         AGAR_DebugLog(AGAR_LOG_DEBUG, "DrawThread : Exit.");
102         this->exit(0);
103 }
104
105 void DrawThreadClass::do_change_refresh_rate(qreal rate)
106 {
107         refresh_rate = rate;    
108         wait_refresh = 1000.0f / (refresh_rate * 2.0);
109         wait_count = wait_refresh * 1.0;
110 }
111
112 void DrawThreadClass::do_update_screen(bitmap_t *p)
113 {
114         draw_screen_buffer = p;
115         bDrawReq = true;
116 }
117         
118 void DrawThreadClass::do_req_encueue_video(int count, int width, int height)
119 {
120         rec_frame_width = width;
121         rec_frame_height = height;
122         rec_frame_count = count;
123 }