src/platform/qt/VideoProxy.h (view raw)
1/* Copyright (c) 2013-2018 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#pragma once
7
8#include <QMutex>
9#include <QObject>
10#include <QWaitCondition>
11
12#include <mgba/feature/video-logger.h>
13#include <mgba-util/ring-fifo.h>
14
15namespace QGBA {
16
17class CoreController;
18
19class VideoProxy : public QObject {
20Q_OBJECT
21
22public:
23 VideoProxy();
24
25 void attach(CoreController*);
26
27signals:
28 void dataAvailable();
29 void eventPosted(int);
30
31public slots:
32 void processData();
33 void reset();
34 void handleEvent(int);
35
36private:
37 void init();
38 void deinit();
39
40 bool writeData(const void* data, size_t length);
41 bool readData(void* data, size_t length, bool block);
42 void postEvent(enum mVideoLoggerEvent event);
43
44 void lock();
45 void unlock();
46 void wait();
47 void wake(int y);
48
49 template<typename T, typename... A> struct callback {
50 using type = T (VideoProxy::*)(A...);
51
52 template<type F> static T func(mVideoLogger* logger, A... args) {
53 VideoProxy* proxy = reinterpret_cast<Logger*>(logger)->p;
54 return (proxy->*F)(args...);
55 }
56 };
57
58 template<void (VideoProxy::*F)()> static void cbind(mVideoLogger* logger) { callback<void>::func<F>(logger); }
59
60 struct Logger {
61 mVideoLogger d;
62 VideoProxy* p;
63 } m_logger = {{}, this};
64
65 RingFIFO m_dirtyQueue;
66 QMutex m_mutex;
67 QWaitCondition m_toThreadCond;
68 QWaitCondition m_fromThreadCond;
69};
70
71}