From 5885cc245d90c21f54d669eb618852ab442cf764 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 5 May 2018 18:47:08 +0300 Subject: [PATCH] Optional power led dims when audio filter is disabled. --- cfgfile.cpp | 2 + cia.cpp | 4 +- include/options.h | 1 + od-win32/direct3d.cpp | 53 ++++++++++++++++++++++---- od-win32/direct3d11.cpp | 82 ++++++++++++++++++++++++++++------------- od-win32/win32gui.cpp | 1 + 6 files changed, 109 insertions(+), 34 deletions(-) diff --git a/cfgfile.cpp b/cfgfile.cpp index d43aac1a..aa6d70b1 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -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 58acfd5c..3adedb93 100644 --- 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 (); } diff --git a/include/options.h b/include/options.h index 9cc6d022..ce6e9187 100644 --- a/include/options.h +++ b/include/options.h @@ -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; diff --git a/od-win32/direct3d.cpp b/od-win32/direct3d.cpp index 795b1b29..632b05e6 100644 --- a/od-win32/direct3d.cpp +++ b/od-win32/direct3d.cpp @@ -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(); + } } } } diff --git a/od-win32/direct3d11.cpp b/od-win32/direct3d11.cpp index da148f31..48f5969c 100644 --- a/od-win32/direct3d11.cpp +++ b/od-win32/direct3d11.cpp @@ -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, diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index 780960bc..92d30db0 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -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 } }; -- 2.47.3