OSDN Git Service

[Draw][OpenGL][OSD] Prepare to direct update vram.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 27 Jul 2018 07:40:25 +0000 (16:40 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 27 Jul 2018 07:40:25 +0000 (16:40 +0900)
source/src/qt/CMakeLists.txt
source/src/qt/gui/CMakeLists.txt
source/src/qt/gui/draw_thread.cpp
source/src/qt/gui/draw_thread.h
source/src/qt/gui/gl/qt_glutil_gl_tmpl.h
source/src/qt/gui/gl4_3/qt_glutil_gl4_3.cpp
source/src/qt/gui/qt_gldraw.cpp
source/src/qt/gui/qt_gldraw.h
source/src/qt/osd_base.cpp
source/src/qt/osd_base.h
source/src/qt/osd_screen.cpp

index 0054597..87d71ee 100644 (file)
@@ -1,5 +1,5 @@
 message("* qt/osd")
-SET(THIS_LIB_VERSION 2.13.0)
+SET(THIS_LIB_VERSION 2.13.1)
 
 set(s_qt_osd_headers
        osd_base.h
index 307bf51..5204aba 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/gui")
 
-set(THIS_LIB_VERSION 2.15.1)
+set(THIS_LIB_VERSION 2.15.2)
 #include(cotire)
 #include(PrecompiledHeader)
 
index bce2720..28ae769 100644 (file)
@@ -46,6 +46,11 @@ DrawThreadClass::DrawThreadClass(OSD *o, CSP_Logger *logger,QObject *parent) : Q
        
        connect(this, SIGNAL(sig_update_osd()), glv, SLOT(update_osd()), Qt::QueuedConnection);
        connect(this, SIGNAL(sig_push_frames_to_avio(int, int, int)), glv->extfunc, SLOT(paintGL_OffScreen(int, int, int)));
+       connect(this, SIGNAL(sig_map_texture()), glv, SLOT(do_map_vram_texture()));
+       connect(this, SIGNAL(sig_unmap_texture()), glv, SLOT(do_unmap_vram_texture()));
+       connect(glv,  SIGNAL(sig_map_texture_reply(bool, void *, int, int)), this, SLOT(do_recv_texture_map_status(bool, void *, int, int)));
+       connect(glv,  SIGNAL(sig_unmap_texture_reply()), this, SLOT(do_recv_texture_unmap_status()));
+       
        //connect(this, SIGNAL(sig_call_draw_screen()), p_osd, SLOT(draw_screen()));
        //connect(this, SIGNAL(sig_call_no_draw_screen()), p_osd, SLOT(no_draw_screen()));
        use_separate_thread_draw = true;
@@ -60,6 +65,12 @@ DrawThreadClass::DrawThreadClass(OSD *o, CSP_Logger *logger,QObject *parent) : Q
        wait_refresh = emu_frame_rate;
        bDrawReq = true;
        renderSemaphore = new QSemaphore(0);
+       textureMappingSemaphore = new QSemaphore(0);
+       mapping_status = false;
+       mapping_pointer = NULL;
+       mapping_width = 0;
+       mapping_height = 0;
+       mapped_drawn = false;
 }
 
 DrawThreadClass::~DrawThreadClass()
@@ -68,6 +79,10 @@ DrawThreadClass::~DrawThreadClass()
                while(renderSemaphore->available() <= 0) renderSemaphore->release(1);
                delete renderSemaphore;
        }
+       if(textureMappingSemaphore != NULL) {
+               while(textureMappingSemaphore->available() <= 0) textureMappingSemaphore->release(1);
+               delete textureMappingSemaphore;
+       }
 
 }
 
@@ -86,12 +101,15 @@ void DrawThreadClass::do_set_frames_per_second(double fps)
 
 void DrawThreadClass::doDrawMain(bool flag)
 {
+       req_map_screen_texture();
        p_osd->do_decode_movie(1);
        if(flag) {
                draw_frames = p_osd->draw_screen();
        } else {
                draw_frames = p_osd->no_draw_screen();
        }
+       req_unmap_screen_texture();
+
        emit sig_draw_frames(draw_frames);
 }
 void DrawThreadClass::doDraw(bool flag)
@@ -116,7 +134,9 @@ void DrawThreadClass::doExit(void)
 
 void DrawThreadClass::do_draw_one_turn(bool _req_draw)
 {
-       if((_req_draw) && (draw_screen_buffer != NULL)) {
+       if((mapped_drawn) && (_req_draw)) {
+               emit sig_update_screen(NULL);
+       } else if((_req_draw) && (draw_screen_buffer != NULL)) {
                emit sig_update_screen(draw_screen_buffer);
        } else {
                if(ncount == 0) emit sig_update_osd();
@@ -128,6 +148,7 @@ void DrawThreadClass::do_draw_one_turn(bool _req_draw)
                                                                         rec_frame_width, rec_frame_height);
                rec_frame_count = -1;
        }
+       mapped_drawn = false;
 }
 
 void DrawThreadClass::doWork(const QString &param)
@@ -182,3 +203,47 @@ void DrawThreadClass::do_req_encueue_video(int count, int width, int height)
        rec_frame_count = count;
 }
 
+void DrawThreadClass::req_map_screen_texture()
+{
+       mapping_status = false;
+       mapping_pointer = NULL;
+       mapping_width = 0;
+       mapping_height = 0;
+       if(glv->is_ready_to_map_vram_texture()) {
+               emit sig_map_texture();
+               textureMappingSemaphore->acquire();
+       }
+}
+
+void DrawThreadClass::req_unmap_screen_texture()
+{
+       if(mapping_status) {
+               if(glv->is_ready_to_map_vram_texture()) {
+                       emit sig_unmap_texture();
+                       textureMappingSemaphore->acquire();
+               }
+       }
+}
+
+void DrawThreadClass::do_recv_texture_map_status(bool f, void *p, int width, int height)
+{
+       mapping_status = f;
+       mapping_pointer = (scrntype_t *)p;
+       mapping_width = width;
+       mapping_height = height;
+       p_osd->do_set_screen_map_texture_address(mapping_pointer, mapping_width, mapping_height);
+       if(mapping_status) {
+               mapped_drawn = true;
+       }
+       textureMappingSemaphore->release(1);
+}
+
+void DrawThreadClass::do_recv_texture_unmap_status(void)
+{
+       mapping_status = false;
+       mapping_pointer = NULL;
+       mapping_width = 0;
+       mapping_height = 0;
+       p_osd->do_set_screen_map_texture_address(mapping_pointer, mapping_width, mapping_height);
+       textureMappingSemaphore->release(1);
+}
index 428f486..98c0808 100644 (file)
@@ -52,11 +52,18 @@ class DLL_PREFIX DrawThreadClass : public QThread {
        CSP_Logger *csp_logger;
        int ncount;
        double emu_frame_rate;
+
+       bool mapping_status;
+       scrntype_t *mapping_pointer;
+       int mapping_width;
+       int mapping_height;
+       bool mapped_drawn;
        void doDrawMain(bool flag);
  public:
        DrawThreadClass(OSD *o, CSP_Logger *logger, QObject *parent = 0);
        ~DrawThreadClass();
        QSemaphore *renderSemaphore;
+       QSemaphore *textureMappingSemaphore;
        
        void run() { doWork("");}
        void SetEmu(EMU *p);
@@ -69,6 +76,11 @@ public slots:
        void do_req_encueue_video(int count, int width, int height);
        void do_draw_one_turn(bool _req_draw);
        void do_set_frames_per_second(double fps);
+       void do_recv_texture_map_status(bool f, void *p, int width, int height);
+       void do_recv_texture_unmap_status(void);
+
+       void req_map_screen_texture();
+       void req_unmap_screen_texture();
 signals:
        int sig_draw_frames(int);
        int message_changed(QString);
@@ -78,6 +90,8 @@ signals:
        int sig_push_frames_to_avio(int, int, int);
        int sig_call_draw_screen();
        int sig_call_no_draw_screen();
+       int sig_map_texture();
+       int sig_unmap_texture();
 };
 
 QT_END_NAMESPACE
index 1c783a8..813a482 100644 (file)
@@ -321,6 +321,14 @@ public:
                        }
                }
        }
+       virtual scrntype_t *get_screen_buffer(int y) { return NULL; }
+       virtual void get_screen_geometry(int *w, int *h) {
+               if(w != NULL) *w = 0;
+               if(h != NULL) *h = 0;
+       }
+       virtual bool is_ready_to_map_vram_texture(void) { return false; }
+       virtual bool map_vram_texture(void) { return false; }
+       virtual bool unmap_vram_texture(void) { return false; }
 public slots:
        virtual void paintGL(void) { }
        virtual void resizeGL(int width, int height) { }
@@ -347,6 +355,7 @@ public slots:
        virtual void do_set_display_osd(bool onoff) { }
        virtual void do_display_osd_leds(int lednum, bool onoff) { }
        virtual void do_set_led_width(int bitwidth) { }
+
 signals:
        int sig_push_image_to_movie(int, int, int, QImage *);
 };
index a29dda9..67f518f 100644 (file)
@@ -1255,9 +1255,9 @@ void GLDraw_4_3::setBrightness(GLfloat r, GLfloat g, GLfloat b)
                } else {
                        uploadMainTexture(imgptr, false);
                }
-               crt_flag = true;
                p_wid->doneCurrent();
        }
+       crt_flag = true;
 }
 
 void GLDraw_4_3::set_texture_vertex(float wmul, float hmul)
index 2c068d3..d923492 100644 (file)
@@ -197,3 +197,39 @@ void GLDrawClass::do_stop_run_vm()
 {
        run_vm = false;
 }
+
+void GLDrawClass::do_map_vram_texture()
+{
+       bool stat = false;
+       int w = 0;
+       int h = 0;
+       void *p = NULL;
+       if(extfunc != NULL) {
+               if(extfunc->is_ready_to_map_vram_texture()) {
+                       this->makeCurrent();
+                       stat = extfunc->map_vram_texture();
+                       if(stat) {
+                               extfunc->get_screen_geometry(&w, &h);
+                               p = extfunc->get_screen_buffer(0);
+                       }
+               }
+       }
+       emit sig_map_texture_reply(stat, p, w, h);
+}
+
+void GLDrawClass::do_unmap_vram_texture()
+{
+       if(extfunc != NULL) {
+               if(extfunc->is_ready_to_map_vram_texture()) {
+                       extfunc->unmap_vram_texture();  
+                       this->doneCurrent();
+               }
+       }
+       emit sig_unmap_texture_reply();
+}
+
+const bool GLDrawClass::is_ready_to_map_vram_texture(void)
+{
+       if(extfunc == NULL) return false;
+       return extfunc->is_ready_to_map_vram_texture();
+}
index 7fda9df..cbd6a65 100644 (file)
@@ -97,12 +97,16 @@ public:
        uint32_t get_scan_from_index(int index);
        const char *get_key_vk_name(int index);
        quint32 getModState(void) { return modifier;}
-       quint32 modifier;
+       
        void InitFBO(void);
        void closeEvent(QCloseEvent *event);
        void drawUpdateTexture(bitmap_t *p);
        QString logGLString(bool getExtensions = false);
        bool emu_launched;
+       quint32 modifier;
+
+       const bool is_ready_to_map_vram_texture(void);
+       
 public slots:
        void initKeyCode(void);
        void releaseKeyCode(void);
@@ -145,6 +149,8 @@ public slots:
        void do_update_icon(int icon_type,  int localnum, QPixmap *p);
        void do_update_icon(int icon_type, int localnum, QString message, QColor bg, QColor fg, QColor fg2, QColor fg3, QColor lg, QColor tg, float pt);
 
+       void do_map_vram_texture();
+       void do_unmap_vram_texture();
 signals:
        void update_screenChanged(int tick);
        void do_notify_move_mouse(int x, int y);
@@ -161,6 +167,9 @@ signals:
        int sig_set_display_osd(bool);
        int sig_display_osd_leds(int,bool);
        int sig_resize_osd(int);
+
+       int sig_map_texture_reply(bool, void *, int, int);
+       int sig_unmap_texture_reply();
 };
 
 #endif // End.
index 5d22448..d2bbda7 100644 (file)
@@ -51,6 +51,10 @@ OSD_BASE::OSD_BASE(USING_FLAGS *p, CSP_Logger *logger) : QThread(0)
        max_vm_nodes = 0;
        p_logger = logger;
        
+       mapped_screen_pointer = NULL;
+       mapped_screen_width = 0;
+       mapped_screen_height = 0;
+       mapped_screen_status = false;
        SupportedFeatures.clear();
 }
 
index 0c0d0a7..94bcc7b 100644 (file)
@@ -207,6 +207,10 @@ protected:
        virtual void initialize_video();
        virtual void release_video();
   
+       scrntype_t *mapped_screen_pointer;
+       int mapped_screen_width;
+       int mapped_screen_height;
+       bool mapped_screen_status;
        bitmap_t dshow_screen_buffer;
        int direct_show_width, direct_show_height;
        bool direct_show_mute[2];
@@ -487,6 +491,7 @@ public slots:
        int draw_screen();
        int no_draw_screen();
        void do_draw(bool flag);
+       void do_set_screen_map_texture_address(scrntype_t *p, int width, int height);
 
 signals:
        int sig_update_screen(bitmap_t *);
index 938f8f5..6884643 100644 (file)
@@ -79,6 +79,20 @@ void OSD_BASE::set_vm_screen_size(int screen_width, int screen_height, int windo
 
 scrntype_t* OSD_BASE::get_vm_screen_buffer(int y)
 {
+       if(mapped_screen_status) {
+               if((mapped_screen_width > 0) && (mapped_screen_pointer != NULL)){
+                       if(y < mapped_screen_height) {
+                               int offset = y * mapped_screen_width;
+                               uint8_t *p = (uint8_t *)mapped_screen_pointer;
+                               p = p + offset;
+                               return (scrntype_t *)p;
+                       } else {
+                               return NULL;
+                       }
+               } else {
+                       return NULL;
+               }
+       }
        return get_buffer(&vm_screen_buffer, y);
 }
 
@@ -90,6 +104,21 @@ scrntype_t* OSD_BASE::get_buffer(bitmap_t *p, int y)
        return (scrntype_t *)p->pImage.scanLine(y);
 }
 
+void OSD_BASE::do_set_screen_map_texture_address(scrntype_t *p, int width, int height)
+{
+       if((p != NULL) && (width > 0) && (height > 0)) {
+               mapped_screen_pointer = p;
+               mapped_screen_width = width;
+               mapped_screen_height = height;
+               mapped_screen_status = true;
+       } else {
+               mapped_screen_pointer = NULL;
+               mapped_screen_width = 0;
+               mapped_screen_height = 0;
+               mapped_screen_status = false;
+       }
+}
+
 int OSD_BASE::draw_screen()
 {
        // draw screen