]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Optional power led dims when audio filter is disabled.
authorToni Wilen <twilen@winuae.net>
Sat, 5 May 2018 15:47:08 +0000 (18:47 +0300)
committerToni Wilen <twilen@winuae.net>
Sat, 5 May 2018 15:47:08 +0000 (18:47 +0300)
cfgfile.cpp
cia.cpp
include/options.h
od-win32/direct3d.cpp
od-win32/direct3d11.cpp
od-win32/win32gui.cpp

index d43aac1aece0f7c0364e200573f310be63217e7c..aa6d70b15c9f8128eb0503b70621b85c65e6482b 100644 (file)
@@ -2064,6 +2064,7 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type)
        write_leds(f, _T("show_leds_enabled"), p->leds_on_screen_mask[0]);
        write_leds(f, _T("show_leds_enabled_rtg"), p->leds_on_screen_mask[1]);
        cfgfile_dwrite_bool(f, _T("show_refresh_indicator"), p->refresh_indicator);
+       cfgfile_dwrite_bool(f, _T("power_led_dim"), p->power_led_dim);
 
        if (p->osd_pos.y || p->osd_pos.x) {
                cfgfile_dwrite (f, _T("osd_position"), _T("%.1f%s:%.1f%s"),
@@ -3108,6 +3109,7 @@ static int cfgfile_parse_host (struct uae_prefs *p, TCHAR *option, TCHAR *value)
                || cfgfile_yesno(option, value, _T("show_refresh_indicator"), &p->refresh_indicator)
                || cfgfile_yesno(option, value, _T("warp"), &p->turbo_emulation)
                || cfgfile_yesno(option, value, _T("headless"), &p->headless)
+               || cfgfile_yesno(option, value, _T("power_led_dim"), &p->power_led_dim)
                || cfgfile_yesno(option, value, _T("clipboard_sharing"), &p->clipboard_sharing)
                || cfgfile_yesno(option, value, _T("native_code"), &p->native_code)
                || cfgfile_yesno(option, value, _T("tablet_library"), &p->tablet_library)
diff --git a/cia.cpp b/cia.cpp
index 58acfd5cc2b4c6a215c7d3ba5bd75ed0e55a34ca..3adedb93a48fd559314e4878c302e890781525cb 100644 (file)
--- a/cia.cpp
+++ b/cia.cpp
@@ -898,13 +898,15 @@ static void led_vsync (void)
                v = 255;
        if (v < 0)
                v = 0;
+       if (currprefs.power_led_dim && v < 96)
+               v = 96;
        if (v > 255)
                v = 255;
        gui_data.powerled_brightness = v;
        led_cycles_on = 0;
        led_cycles_off = 0;
        if (led_old_brightness != gui_data.powerled_brightness) {
-               gui_data.powerled = gui_data.powerled_brightness > 127;
+               gui_data.powerled = gui_data.powerled_brightness > 96;
                gui_led (LED_POWER, gui_data.powerled, gui_data.powerled_brightness);
                led_filter_audio ();
        }
index 9cc6d02223fb19db2dd90258a361500a4e57a5da..ce6e91877b79adc8d0e54f6ca11285727034c5c4 100644 (file)
@@ -553,6 +553,7 @@ struct uae_prefs {
        int collision_level;
        int leds_on_screen;
        int leds_on_screen_mask[2];
+       bool power_led_dim;
        struct wh osd_pos;
        int keyboard_leds[3];
        bool keyboard_leds_in_use;
index 795b1b29d9f7983c62f448dae760d00d4bdd31b0..632b05e6bfce3de55bd34ef0b754869c16a8152e 100644 (file)
@@ -150,7 +150,7 @@ struct d3dstruct
        IDirect3DDevice9Ex *d3ddevex;
        D3DSURFACE_DESC dsdbb;
        LPDIRECT3DTEXTURE9 texture, sltexture, ledtexture, blanktexture;
-       LPDIRECT3DTEXTURE9 mask2texture, mask2textureleds[9];
+       LPDIRECT3DTEXTURE9 mask2texture, mask2textureleds[9], mask2textureled_power_dim;
        int mask2textureledoffsets[9 * 2];
        IDirect3DQuery9 *query;
        float mask2texture_w, mask2texture_h, mask2texture_ww, mask2texture_wh;
@@ -1710,6 +1710,10 @@ static void narrowimg(struct uae_image *img, int *xop, int *yop, const TCHAR *na
        img->data = d;
 }
 
+static uae_u8 dimming(uae_u8 v)
+{
+       return v / 3;
+}
 
 static int createmask2texture (struct d3dstruct *d3d, const TCHAR *filename)
 {
@@ -1730,6 +1734,9 @@ static int createmask2texture (struct d3dstruct *d3d, const TCHAR *filename)
                        d3d->mask2textureleds[i]->Release();
                d3d->mask2textureleds[i] = NULL;
        }
+       if (d3d->mask2textureled_power_dim)
+               d3d->mask2textureled_power_dim->Release();
+       d3d->mask2textureled_power_dim = NULL;
 
        if (filename[0] == 0 || WIN32GFX_IsPicassoScreen(mon))
                return 0;
@@ -1908,6 +1915,27 @@ static int createmask2texture (struct d3dstruct *d3d, const TCHAR *filename)
                                                        d3d->mask2textureleds[i]->UnlockRect(0);
                                                }
                                        }
+                                       if (ledtypes[i] == LED_POWER) {
+                                               d3d->mask2textureled_power_dim = createtext(d3d, ledimg.width, ledimg.height, D3DFMT_A8R8G8B8);
+                                               if (d3d->mask2textureled_power_dim) {
+                                                       hr = d3d->mask2textureled_power_dim->LockRect(0, &locked, NULL, 0);
+                                                       if (SUCCEEDED(hr)) {
+                                                               for (int j = 0; j < ledimg.height; j++) {
+                                                                       uae_u8 *pd = (uae_u8*)locked.pBits + j * locked.Pitch;
+                                                                       uae_u8 *ps = ledimg.data + j * ledimg.pitch;
+                                                                       for (int k = 0; k < ledimg.width; k++) {
+                                                                               pd[0] = dimming(ps[0]);
+                                                                               pd[1] = dimming(ps[1]);
+                                                                               pd[2] = dimming(ps[2]);
+                                                                               pd[3] = ps[3];
+                                                                               pd += 4;
+                                                                               ps += 4;
+                                                                       }
+                                                               }
+                                                               d3d->mask2textureled_power_dim->UnlockRect(0);
+                                                       }
+                                               }
+                                       }
                                } else {
                                        write_log(_T("Overlay led '%s' size mismatch.\n"), tmp1);
                                }
@@ -2370,6 +2398,10 @@ static void invalidatedeviceobjects (struct d3dstruct *d3d)
                        d3d->mask2textureleds[i]->Release();
                d3d->mask2textureleds[i] = NULL;
        }
+       if (d3d->mask2textureled_power_dim) {
+               d3d->mask2textureled_power_dim->Release();
+               d3d->mask2textureled_power_dim = NULL;
+       }
        if (d3d->blanktexture) {
                d3d->blanktexture->Release ();
                d3d->blanktexture = NULL;
@@ -2728,7 +2760,7 @@ static const TCHAR *D3D_init2 (struct d3dstruct *d3d, HWND ahwnd, int w_w, int w
        d3d->dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
        d3d->dpp.BackBufferWidth = w_w;
        d3d->dpp.BackBufferHeight = w_h;
-       d3d->dpp.PresentationInterval = d3d->variablerefresh ? D3DPRESENT_INTERVAL_DEFAULT : (!ap.gfx_vflip ? D3DPRESENT_INTERVAL_IMMEDIATE : D3DPRESENT_INTERVAL_ONE);
+       d3d->dpp.PresentationInterval = d3d->variablerefresh ? D3DPRESENT_INTERVAL_DEFAULT : ((!ap.gfx_vflip || monid) ? D3DPRESENT_INTERVAL_IMMEDIATE : D3DPRESENT_INTERVAL_ONE);
 
        d3d->modeex.Width = w_w;
        d3d->modeex.Height = w_h;
@@ -3610,12 +3642,17 @@ static void D3D_render2(struct d3dstruct *d3d, int mode)
                                d3d->sprite->Flush();
                                for (int i = 0; overlayleds[i]; i++) {
                                        bool led = leds[ledtypes[i]] != 0;
-                                       if (led && d3d->mask2textureleds[i]) {
-                                               v.x = d3d->mask2texture_offsetw / w + d3d->mask2textureledoffsets[i * 2 + 0];
-                                               v.y = d3d->mask2textureledoffsets[i * 2 + 1];
-                                               v.z = 0;
-                                               d3d->sprite->Draw(d3d->mask2textureleds[i], NULL, NULL, &v, 0xffffffff);
-                                               d3d->sprite->Flush();
+                                       if (led || (ledtypes[i] == LED_POWER && currprefs.power_led_dim)) {
+                                               LPDIRECT3DTEXTURE9 spr = d3d->mask2textureleds[i];
+                                               if (!led && ledtypes[i] == LED_POWER && currprefs.power_led_dim)
+                                                       spr = d3d->mask2textureled_power_dim;
+                                               if (spr) {
+                                                       v.x = d3d->mask2texture_offsetw / w + d3d->mask2textureledoffsets[i * 2 + 0];
+                                                       v.y = d3d->mask2textureledoffsets[i * 2 + 1];
+                                                       v.z = 0;
+                                                       d3d->sprite->Draw(spr, NULL, NULL, &v, 0xffffffff);
+                                                       d3d->sprite->Flush();
+                                               }
                                        }
                                }
                        }
index da148f31fcaf7803701a8b53ed6398c9ba38616e..48f5969c4c6beb116aecb0762228109bc0c78e57 100644 (file)
@@ -269,7 +269,7 @@ struct d3d11struct
        struct d3d11sprite osd;
        struct d3d11sprite hwsprite;
        struct d3d11sprite mask2texture;
-       struct d3d11sprite mask2textureleds[9];
+       struct d3d11sprite mask2textureleds[9], mask2textureled_power_dim;
        int mask2textureledoffsets[9 * 2];
        struct d3d11sprite blanksprite;
 
@@ -1714,6 +1714,7 @@ static void FreeTextures(struct d3d11struct *d3d)
        for (int i = 0; overlayleds[i]; i++) {
                freesprite(&d3d->mask2textureleds[i]);
        }
+       freesprite(&d3d->mask2textureled_power_dim);
        freesprite(&d3d->blanksprite);
 
        for (int i = 0; i < MAX_SHADERS; i++) {
@@ -2382,6 +2383,11 @@ static void narrowimg(struct uae_image *img, int *xop, int *yop, const TCHAR *na
 
 }
 
+static uae_u8 dimming(uae_u8 v)
+{
+       return v / 3;
+}
+
 static int createmask2texture(struct d3d11struct *d3d, const TCHAR *filename)
 {
        struct AmigaMonitor *mon = &AMonitors[d3d - d3d11data];
@@ -2395,6 +2401,7 @@ static int createmask2texture(struct d3d11struct *d3d, const TCHAR *filename)
        for (int i = 0; overlayleds[i]; i++) {
                freesprite(&d3d->mask2textureleds[i]);
        }
+       freesprite(&d3d->mask2textureled_power_dim);
        freesprite(&d3d->blanksprite);
 
        if (filename[0] == 0 || WIN32GFX_IsPicassoScreen(mon))
@@ -2563,7 +2570,7 @@ static int createmask2texture(struct d3d11struct *d3d, const TCHAR *filename)
                        struct uae_image ledimg;
                        if (load_png_image(zf, &ledimg)) {
                                if (ledimg.width == img.width && ledimg.height == img.height) {
-                                       narrowimg(&ledimg, &d3d->mask2textureledoffsets[i * 2 + 0], &d3d->mask2textureledoffsets[i * 2 + 1], tmp1);                             
+                                       narrowimg(&ledimg, &d3d->mask2textureledoffsets[i * 2 + 0], &d3d->mask2textureledoffsets[i * 2 + 1], tmp1);
                                        if (allocsprite(d3d, &d3d->mask2textureleds[i], ledimg.width, ledimg.height, true)) {
                                                D3D11_MAPPED_SUBRESOURCE map;
                                                hr = d3d->m_deviceContext->Map(d3d->mask2textureleds[i].texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
@@ -2575,6 +2582,28 @@ static int createmask2texture(struct d3d11struct *d3d, const TCHAR *filename)
                                                }
                                                d3d->mask2textureleds[i].enabled = true;
                                                d3d->mask2textureleds[i].bilinear = true;
+                                               if (ledtypes[i] == LED_POWER) {
+                                                       if (allocsprite(d3d, &d3d->mask2textureled_power_dim, ledimg.width, ledimg.height, true)) {
+                                                               hr = d3d->m_deviceContext->Map(d3d->mask2textureled_power_dim.texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
+                                                               if (SUCCEEDED(hr)) {
+                                                                       for (int j = 0; j < ledimg.height; j++) {
+                                                                               uae_u8 *pd = (uae_u8*)map.pData + j * map.RowPitch;
+                                                                               uae_u8 *ps = ledimg.data + j * ledimg.pitch;
+                                                                               for (int k = 0; k < ledimg.width; k++) {
+                                                                                       pd[0] = dimming(ps[0]);
+                                                                                       pd[1] = dimming(ps[1]);
+                                                                                       pd[2] = dimming(ps[2]);
+                                                                                       pd[3] = ps[3];
+                                                                                       pd += 4;
+                                                                                       ps += 4;
+                                                                               }
+                                                                       }
+                                                                       d3d->m_deviceContext->Unmap(d3d->mask2textureled_power_dim.texture, 0);
+                                                               }
+                                                               d3d->mask2textureled_power_dim.enabled = true;
+                                                               d3d->mask2textureled_power_dim.bilinear = true;
+                                                       }
+                                               }
                                        }
                                } else {
                                        write_log(_T("Overlay led '%s' size mismatch.\n"), tmp1);
@@ -3518,11 +3547,13 @@ static int xxD3D11_init2(HWND ahwnd, int monid, int w_w, int w_h, int t_w, int t
                d3d->swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
        }
 
-       d3d->vblankintervals = 1;
+       d3d->vblankintervals = 0;
+       if (!monid && apm->gfx_backbuffers > 2 && !isvsync())
+               d3d->vblankintervals = 1;
        cannoclear = false;
+
        if (apm->gfx_vsyncmode) {
                cannoclear = true;
-               d3d->vblankintervals = 0;
        }
 
        d3d->swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
@@ -3532,32 +3563,31 @@ static int xxD3D11_init2(HWND ahwnd, int monid, int w_w, int w_h, int t_w, int t
        d3d->swapChainDesc.Scaling = (d3d->swapChainDesc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL || d3d->swapChainDesc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD) ? DXGI_SCALING_NONE : DXGI_SCALING_STRETCH;
 
        d3d->blackscreen = false;
-       if (!apm->gfx_backbuffers) {
-               int hzmult = 0;
-               getvsyncrate(monid, *freq, &hzmult);
-               if (hzmult < 0) {
-                       if (!apm->gfx_strobo) {
-                               if (isfullscreen() > 0) {
-                                       d3d->vblankintervals++;
+       if (!monid) {
+               if (!apm->gfx_backbuffers) {
+                       int hzmult = 0;
+                       getvsyncrate(monid, *freq, &hzmult);
+                       if (hzmult < 0) {
+                               if (!apm->gfx_strobo) {
+                                       if (isfullscreen() > 0) {
+                                               d3d->vblankintervals++;
+                                       }
+                               } else {
+                                       d3d->blackscreen = true;
                                }
-                       } else {
-                               d3d->blackscreen = true;
                        }
                }
-       }
-       int vsync = isvsync();
-       if (vsync > 0 && !apm->gfx_vsyncmode) {
-               int hzmult;
-               getvsyncrate(monid, hz, &hzmult);
-               if (hzmult > 0) {
-                       d3d->vblankintervals = hzmult + (d3d->blackscreen ? 0 : 1);
+               int vsync = isvsync();
+               if (vsync > 0 && !apm->gfx_vsyncmode) {
+                       d3d->vblankintervals = 1;
+                       int hzmult;
+                       getvsyncrate(monid, hz, &hzmult);
+                       if (hzmult > 0) {
+                               d3d->vblankintervals = hzmult + (d3d->blackscreen ? 0 : 1);
+                       }
                }
        }
 
-       if (monid) {
-               d3d->vblankintervals = 0;
-       }
-
        // Create the swap chain, Direct3D device, and Direct3D device context.
        result = factory2->CreateSwapChainForHwnd(d3d->m_device, ahwnd, &d3d->swapChainDesc, isfs(d3d) > 0 ? &d3d->fsSwapChainDesc : NULL, NULL, &d3d->m_swapChain);
        if (FAILED(result)) {
@@ -3944,8 +3974,10 @@ static void renderoverlay(struct d3d11struct *d3d)
 
        for (int i = 0; overlayleds[i]; i++) {
                bool led = leds[ledtypes[i]] != 0;
-               if (led) {
+               if (led || (ledtypes[i] == LED_POWER && currprefs.power_led_dim)) {
                        struct d3d11sprite *sprled = &d3d->mask2textureleds[i];
+                       if (!led && ledtypes[i] == LED_POWER && currprefs.power_led_dim)
+                               sprled = &d3d->mask2textureled_power_dim;
                        if (sprled) {
                                setspritescaling(sprled, d3d->mask2texture_multx, d3d->mask2texture_multy);
                                setsprite(d3d, sprled,
index 780960bc19cf18cf665cb50878742801d04cdd31..92d30db03da424736fc74e780e2a8dd7658d8e81 100644 (file)
@@ -4397,6 +4397,7 @@ static const struct miscentry misclist[] = {
        { 0, 1, _T("Right Control = Right Windows key"), &workprefs.right_control_is_right_win_key },
        { 0, 0, _T("Windows shutdown/logoff notification"), &workprefs.win32_shutdown_notification },
        { 0, 1, _T("Warn when attempting to close window"), &workprefs.win32_warn_exit },
+       { 0, 1, _T("Power led dims when audio filter is disabled"), &workprefs.power_led_dim },
        { 0, NULL }
 };