Annotation of nono/vm/renderer.h, revision 1.1.1.16

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
1.1       root        7: //
1.1.1.15  root        8: // ビデオレンダラ
1.1       root        9: //
                     10: 
                     11: #pragma once
                     12: 
1.1.1.7   root       13: #include "thread.h"
                     14: #include "bitmap.h"
1.1.1.11  root       15: #include "fixedqueue.h"
1.1       root       16: #include <condition_variable>
                     17: #include <mutex>
                     18: 
1.1.1.12  root       19: class ConsoleDevice;
1.1.1.9   root       20: class PlaneVRAMDevice;
                     21: class Syncer;
1.1.1.14  root       22: class UIMessage;
1.1.1.10  root       23: class VideoCtlrDevice;
1.1.1.7   root       24: 
1.1.1.15  root       25: class VideoRenderer : public ThreadDevice
1.1.1.7   root       26: {
                     27:        using inherited = ThreadDevice;
                     28:  public:
1.1       root       29:        static const uint REQ_TERMINATE         = 0x01; // スレッド終了指示
1.1.1.11  root       30:        static const uint REQ_SCREENOFF         = 0x02; // 電源オフ時の描画指示
                     31:        static const uint REQ_RENDER            = 0x04; // 通常の描画指示
                     32:        static const uint REQ_RESIZE            = 0x08; // リサイズ指示
                     33:        static const uint REQ_POST                      = 0x10; // UI への通知指示
1.1.1.7   root       34: 
1.1       root       35:  public:
1.1.1.15  root       36:        VideoRenderer();
                     37:        ~VideoRenderer() override;
1.1       root       38: 
1.1.1.9   root       39:        bool Init() override;
1.1.1.7   root       40:        void ResetHard(bool poweron) override;
                     41:        void PowerOff() override;
1.1       root       42: 
1.1.1.11  root       43:        // 出力ビットマップが有効なら取得。
                     44:        // (wxImage に渡すため const なし)
                     45:        BitmapRGB *GetBitmap() {
                     46:                if (__predict_true(bitmap24_valid)) {
                     47:                        return bitmap24.get();
                     48:                } else {
                     49:                        return NULL;
                     50:                }
                     51:        }
1.1.1.7   root       52: 
1.1.1.11  root       53:        // 画面合成処理の指示 (CRTC/CRTC2 から呼ばれる)
                     54:        void NotifyRender();
1.1       root       55: 
1.1.1.11  root       56:        // 表示画面サイズを設定 (GUI から呼ばれる)
                     57:        void ResizeView(uint width_, uint height_);
                     58: 
1.1       root       59:        // 仮想画面幅(ピクセル)を取得
1.1.1.11  root       60:        uint GetWidth() const { return width; }
1.1       root       61: 
                     62:        // 仮想画面高さ(ピクセル)を取得
1.1.1.11  root       63:        uint GetHeight() const { return height; }
1.1       root       64: 
1.1.1.7   root       65:        // 描画更新(通知)間隔を設定 (GUI から呼ばれる)
1.1.1.16! root       66:        void SetRefreshInterval(uint64 msec);
1.1       root       67: 
                     68:  protected:
1.1.1.7   root       69:        // レンダリングスレッド
                     70:        void ThreadRun() override;
                     71: 
1.1.1.11  root       72:        // 描画する。
                     73:        int64 DoRender(uint32 req);
                     74: 
                     75:        // 画面合成。更新があれば true を返す。(派生クラス側で用意)
                     76:        virtual bool RenderMD() = 0;
1.1.1.10  root       77: 
1.1.1.14  root       78:        void PrintPerf();
                     79: 
1.1.1.16! root       80:        DECLARE_MONITOR_SCREEN(MonitorScreen);
1.1.1.7   root       81: 
1.1       root       82:        // ウィンドウとして表示される画面はオプションや設定などで縮尺を変える
                     83:        // ことが出来るが (こっちを実画面とする)、ここで扱う仮想画面とはそれに
                     84:        // 関わらず常にその機種の最大描画面積を指す。
                     85:        // LUNA でいう 1280 x 1024 のこと。
                     86: 
                     87:        // 仮想画面幅(ピクセル)
1.1.1.11  root       88:        uint width {};
1.1       root       89: 
                     90:        // 仮想画面高さ(ピクセル)
1.1.1.11  root       91:        uint height {};
1.1       root       92: 
1.1.1.7   root       93:        // レンダリング結果のビットマップ
1.1.1.11  root       94:        BitmapRGBX bitmap {};
1.1       root       95: 
1.1.1.11  root       96:        // wxWidgets 用表示ビットマップ
                     97:        std::unique_ptr<BitmapRGB> bitmap24 /*{}*/;
                     98: 
                     99:        // 表示ビットマップの大きさ
                    100:        Rect viewrect {};
1.1.1.6   root      101: 
1.1       root      102:        // リクエストフラグ
1.1.1.4   root      103:        uint32 request {};
1.1       root      104:        std::mutex mtx {};
                    105:        std::condition_variable cv {};
1.1.1.2   root      106: 
1.1.1.11  root      107:        // リサイズ時の要求サイズ
                    108:        uint new_viewwidth {};
                    109:        uint new_viewheight {};
                    110: 
                    111:        // レンダラ有効フラグ (GUI なら true)
1.1.1.7   root      112:        bool enable {};
                    113: 
1.1.1.11  root      114:        // 初期化やリサイズ後に一度でも bitmap24 を更新すれば true。
                    115:        bool bitmap24_valid {};
                    116: 
1.1.1.7   root      117:        // 画面更新を UI に通知する間隔
                    118:        uint64 refresh_interval {};
                    119:        // 次回更新を通知する実時刻
                    120:        uint64 next_refresh_rtime {};
                    121: 
                    122:        // 統計情報
1.1.1.11  root      123:        uint64 stat_input_count {};             // 入力通知回数
                    124:        uint64 last_input_time {};              // 前回の入力通知 VM 時刻
                    125:        FixedQueue<uint64, 4> ma_input_span {};         // 入力通知間隔
                    126:        uint64 stat_render_count {};    // RenderMD() の実行回数
                    127:        uint64 stat_noupdate_count {};  // bitmap24 への更新が不要だった回数
                    128:        uint64 stat_nobitmap_count {};  // bitmap24 が用意できてなかった回数
                    129:        uint64 stat_output_count {};    // UI への出力通知回数
                    130:        uint64 last_output_time {};             // 前回の出力通知 RT 時刻
                    131:        FixedQueue<uint64, 4> ma_output_span {};        // 出力通知間隔
                    132: 
1.1.1.9   root      133:        Syncer *syncer {};
1.1.1.14  root      134:        UIMessage *uimessage {};
1.1.1.7   root      135: 
1.1.1.12  root      136:        Monitor *monitor {};
1.1.1.7   root      137: 
                    138:  private:
1.1.1.2   root      139:        // スレッドの終了を指示
1.1.1.7   root      140:        void Terminate() override;
1.1       root      141: };
                    142: 
                    143: //
                    144: // X68030 レンダラ
                    145: //
1.1.1.15  root      146: class X68030VideoRenderer : public VideoRenderer
1.1       root      147: {
1.1.1.15  root      148:        using inherited = VideoRenderer;
1.1       root      149:  public:
1.1.1.15  root      150:        X68030VideoRenderer();
                    151:        ~X68030VideoRenderer() override;
1.1       root      152: 
1.1.1.10  root      153:        bool Init() override;
1.1.1.11  root      154:        bool RenderMD() override;
1.1.1.10  root      155: 
                    156:  private:
                    157:        VideoCtlrDevice *videoctlr {};
1.1       root      158: };
                    159: 
                    160: //
                    161: // LUNA レンダラ
                    162: //
1.1.1.15  root      163: class LunaVideoRenderer : public VideoRenderer
1.1       root      164: {
1.1.1.15  root      165:        using inherited = VideoRenderer;
1.1       root      166:  public:
1.1.1.15  root      167:        LunaVideoRenderer();
                    168:        ~LunaVideoRenderer() override;
1.1       root      169: 
1.1.1.10  root      170:        bool Init() override;
1.1.1.11  root      171:        bool RenderMD() override;
1.1.1.10  root      172: 
                    173:  private:
1.1.1.11  root      174:        PlaneVRAMDevice *planevram {};
1.1       root      175: };
                    176: 
1.1.1.9   root      177: //
1.1.1.12  root      178: // コンソールレンダラ
1.1.1.9   root      179: //
1.1.1.15  root      180: class ConsoleRenderer : public VideoRenderer
1.1.1.9   root      181: {
1.1.1.15  root      182:        using inherited = VideoRenderer;
1.1.1.12  root      183: 
1.1.1.9   root      184:  public:
1.1.1.12  root      185:        // フチ [pixel]
                    186:        static const uint Padding = 3;
1.1.1.9   root      187: 
1.1.1.12  root      188:  public:
                    189:        ConsoleRenderer();
                    190:        ~ConsoleRenderer() override;
                    191: 
                    192:        bool Init() override;
1.1.1.11  root      193:        bool RenderMD() override;
1.1.1.12  root      194: 
                    195:  private:
                    196:        ConsoleDevice *console {};
1.1.1.9   root      197: };
                    198: 
1.1.1.16! root      199: inline VideoRenderer *GetVideoRenderer() {
1.1.1.15  root      200:        return Object::GetObject<VideoRenderer>(OBJ_VIDEO_RENDERER);
1.1.1.9   root      201: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.