all repos — mgba @ fc3e47a4bab1465b91e7368c6396b222f65f51cb

mGBA Game Boy Advance Emulator

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