aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-03-20 10:34:10 +1100
committerNeil <nyamatongwe@gmail.com>2025-03-20 10:34:10 +1100
commitb1823dea90391e67d4a5ee96a4a997230035fe58 (patch)
tree735de10d8b36dbab95e609833992bdc139107c6c
parent443df5997d71ad8af6b7456eba124e6909118480 (diff)
downloadscintilla-mirror-b1823dea90391e67d4a5ee96a4a997230035fe58.tar.gz
Standardize render target initialization.
Use symbolic names for DPI instead of inline value 96.
-rw-r--r--win32/PlatWin.cxx15
-rw-r--r--win32/PlatWin.h1
-rw-r--r--win32/ScintillaWin.cxx68
3 files changed, 40 insertions, 44 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 9cd792e09..6a4f9d146 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -1770,7 +1770,7 @@ void SurfaceD2D::SetDeviceScaleFactor(const ID2D1RenderTarget *const pD2D1Render
FLOAT dpiX = 0.f;
FLOAT dpiY = 0.f;
pD2D1RenderTarget->GetDpi(&dpiX, &dpiY);
- deviceScaleFactor = static_cast<int>(dpiX / 96.f);
+ deviceScaleFactor = static_cast<int>(dpiX / dpiDefault);
}
int SurfaceD2D::PixelDivisions() {
@@ -3012,16 +3012,9 @@ public:
return false;
}
- D2D1_RENDER_TARGET_PROPERTIES drtp {};
- drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
- drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE;
- drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
- drtp.dpiX = 96.f;
- drtp.dpiY = 96.f;
- drtp.pixelFormat = D2D1::PixelFormat(
- DXGI_FORMAT_B8G8R8A8_UNORM,
- D2D1_ALPHA_MODE_PREMULTIPLIED
- );
+ const D2D1_RENDER_TARGET_PROPERTIES drtp = D2D1::RenderTargetProperties(
+ D2D1_RENDER_TARGET_TYPE_DEFAULT,
+ { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED });
DCRenderTarget pTarget;
HRESULT hr = CreateDCRenderTarget(&drtp, pTarget);
diff --git a/win32/PlatWin.h b/win32/PlatWin.h
index de99a5fc0..dcda7c944 100644
--- a/win32/PlatWin.h
+++ b/win32/PlatWin.h
@@ -13,6 +13,7 @@ namespace Scintilla::Internal {
#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
#endif
+constexpr FLOAT dpiDefault = USER_DEFAULT_SCREEN_DPI;
extern void Platform_Initialise(void *hInstance) noexcept;
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index a64ba2499..7cd8ff086 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -832,20 +832,14 @@ HRESULT ScintillaWin::Create3D() noexcept {
void ScintillaWin::CreateRenderTarget() {
HWND hw = MainHWND();
- const RECT rc = GetClientRect(hw);
// Create a Direct2D render target.
- D2D1_RENDER_TARGET_PROPERTIES drtp{};
- drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
- drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE;
- drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
if (technology == Technology::DirectWriteDC) {
- drtp.dpiX = 96.f;
- drtp.dpiY = 96.f;
- // Explicit pixel format needed.
- drtp.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
- D2D1_ALPHA_MODE_IGNORE);
+ const D2D1_RENDER_TARGET_PROPERTIES drtp = D2D1::RenderTargetProperties(
+ D2D1_RENDER_TARGET_TYPE_DEFAULT,
+ { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE },
+ dpiDefault, dpiDefault);
const HRESULT hr = CreateDCRenderTarget(&drtp, targets.pDCRT);
if (FAILED(hr)) {
@@ -870,18 +864,25 @@ void ScintillaWin::CreateRenderTarget() {
}
} else { // DirectWrite or DirectWriteRetain
+
+ const RECT rc = GetClientRect(hw);
+
const int integralDeviceScaleFactor = GetFirstIntegralMultipleDeviceScaleFactor();
- drtp.dpiX = 96.f * integralDeviceScaleFactor;
- drtp.dpiY = 96.f * integralDeviceScaleFactor;
- drtp.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN,
- D2D1_ALPHA_MODE_UNKNOWN);
-
- D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp{};
- dhrtp.hwnd = hw;
- dhrtp.pixelSize = ::GetSizeUFromRect(rc, integralDeviceScaleFactor);
- dhrtp.presentOptions = (technology == Technology::DirectWriteRetain) ?
+ const FLOAT dpiTarget = dpiDefault * integralDeviceScaleFactor;
+
+ const D2D1_RENDER_TARGET_PROPERTIES drtp = D2D1::RenderTargetProperties(
+ D2D1_RENDER_TARGET_TYPE_DEFAULT,
+ { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_UNKNOWN },
+ dpiTarget, dpiTarget);
+
+ const D2D1_PRESENT_OPTIONS presentOptions = (technology == Technology::DirectWriteRetain) ?
D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
+ const D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp = D2D1::HwndRenderTargetProperties(
+ hw,
+ ::GetSizeUFromRect(rc, integralDeviceScaleFactor),
+ presentOptions);
+
const HRESULT hr = CreateHwndRenderTarget(&drtp, &dhrtp, targets.pHwndRT);
if (FAILED(hr)) {
Platform::DebugPrintf("Failed CreateHwndRenderTarget 0x%lx\n", hr);
@@ -3908,20 +3909,21 @@ void ScintillaWin::CTPaint(HWND hWnd) {
const int scaleFactor = GetFirstIntegralMultipleDeviceScaleFactor();
// Create a Direct2D render target.
- D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp{};
- dhrtp.hwnd = hWnd;
- dhrtp.pixelSize = ::GetSizeUFromRect(rc, scaleFactor);
- dhrtp.presentOptions = (technology == Technology::DirectWriteRetain) ?
- D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
-
- D2D1_RENDER_TARGET_PROPERTIES drtp{};
- drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
- drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN;
- drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN;
- drtp.dpiX = 96.f * scaleFactor;
- drtp.dpiY = 96.f * scaleFactor;
- drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE;
- drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
+
+ const FLOAT dpiTarget = dpiDefault * scaleFactor;
+
+ const D2D1_RENDER_TARGET_PROPERTIES drtp = D2D1::RenderTargetProperties(
+ D2D1_RENDER_TARGET_TYPE_DEFAULT,
+ { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_UNKNOWN },
+ dpiTarget, dpiTarget);
+
+ const D2D1_PRESENT_OPTIONS presentOptions = (technology == Technology::DirectWriteRetain) ?
+ D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
+
+ const D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp = D2D1::HwndRenderTargetProperties(
+ hWnd,
+ ::GetSizeUFromRect(rc, scaleFactor),
+ presentOptions);
const HRESULT hr = CreateHwndRenderTarget(&drtp, &dhrtp, pCTRenderTarget);
if (!SUCCEEDED(hr)) {