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 void detach(CoreController*);
27
28signals:
29 void dataAvailable();
30 void eventPosted(int);
31
32public slots:
33 void processData();
34 void reset();
35 void handleEvent(int);
36
37private:
38 void init();
39 void deinit();
40
41 bool writeData(const void* data, size_t length);
42 bool readData(void* data, size_t length, bool block);
43 void postEvent(enum mVideoLoggerEvent event);
44
45 void lock();
46 void unlock();
47 void wait();
48 void wake(int y);
49
50 template<typename T, typename... A> struct callback {
51 using type = T (VideoProxy::*)(A...);
52
53 template<type F> static T func(mVideoLogger* logger, A... args) {
54 VideoProxy* proxy = reinterpret_cast<Logger*>(logger)->p;
55 return (proxy->*F)(args...);
56 }
57 };
58
59 template<void (VideoProxy::*F)()> static void cbind(mVideoLogger* logger) { callback<void>::func<F>(logger); }
60
61 struct Logger {
62 mVideoLogger d;
63 VideoProxy* p;
64 } m_logger = {{}, this};
65
66 RingFIFO m_dirtyQueue;
67 QMutex m_mutex;
68 QWaitCondition m_toThreadCond;
69 QWaitCondition m_fromThreadCond;
70};
71
72}