mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-29 00:24:42 +01:00
clean up x2
This commit is contained in:
@@ -137,7 +137,7 @@ namespace
|
||||
|
||||
void DrawBoundsToolTick(const CommonState& commonState,
|
||||
const BoundsToolState& toolState,
|
||||
HWND overlayWindow,
|
||||
const HWND overlayWindow,
|
||||
const D2DState& d2dState)
|
||||
{
|
||||
if (const auto it = toolState.measurementsByScreen.find(overlayWindow); it != end(toolState.measurementsByScreen))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
void DrawBoundsToolTick(const CommonState& commonState,
|
||||
const BoundsToolState& toolState,
|
||||
HWND overlayWindow,
|
||||
const HWND overlayWindow,
|
||||
const D2DState& d2dState);
|
||||
|
||||
LRESULT CALLBACK BoundsToolWndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||
@@ -9,7 +9,7 @@ void SetClipBoardToText(const std::wstring_view text)
|
||||
return;
|
||||
}
|
||||
|
||||
wil::unique_hglobal handle{ GlobalAlloc(GMEM_MOVEABLE, static_cast<size_t>((text.length() + 1) * sizeof(wchar_t))) };
|
||||
const wil::unique_hglobal handle{ GlobalAlloc(GMEM_MOVEABLE, static_cast<size_t>((text.length() + 1) * sizeof(wchar_t))) };
|
||||
if (!handle)
|
||||
{
|
||||
CloseClipboard();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
void DetermineScreenQuadrant(HWND window, long x, long y, bool& inLeftHalf, bool& inTopHalf)
|
||||
void DetermineScreenQuadrant(const HWND window, long x, long y, bool& inLeftHalf, bool& inTopHalf)
|
||||
{
|
||||
RECT windowRect{};
|
||||
GetWindowRect(window, &windowRect);
|
||||
@@ -18,7 +18,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
D2DState::D2DState(HWND overlayWindow, std::vector<D2D1::ColorF> solidBrushesColors)
|
||||
D2DState::D2DState(const HWND overlayWindow, std::vector<D2D1::ColorF> solidBrushesColors)
|
||||
{
|
||||
RECT clientRect = {};
|
||||
|
||||
@@ -61,7 +61,7 @@ D2DState::D2DState(HWND overlayWindow, std::vector<D2D1::ColorF> solidBrushesCol
|
||||
winrt::check_hresult(rt->CreateSolidColorBrush(solidBrushesColors[i], &solidBrushes[i]));
|
||||
}
|
||||
|
||||
auto deviceContext = rt.query<ID2D1DeviceContext>();
|
||||
const auto deviceContext = rt.query<ID2D1DeviceContext>();
|
||||
winrt::check_hresult(deviceContext->CreateEffect(CLSID_D2D1Shadow, &shadowEffect));
|
||||
winrt::check_hresult(shadowEffect->SetValue(D2D1_SHADOW_PROP_BLUR_STANDARD_DEVIATION, consts::SHADOW_RADIUS));
|
||||
winrt::check_hresult(shadowEffect->SetValue(D2D1_SHADOW_PROP_COLOR, D2D1::ColorF(0.f, 0.f, 0.f, consts::SHADOW_OPACITY)));
|
||||
@@ -78,7 +78,7 @@ void D2DState::DrawTextBox(const wchar_t* text,
|
||||
const float centerX,
|
||||
const float centerY,
|
||||
const bool screenQuadrantAware,
|
||||
HWND window) const
|
||||
const HWND window) const
|
||||
{
|
||||
wil::com_ptr<IDWriteTextLayout> textLayout;
|
||||
winrt::check_hresult(writeFactory->CreateTextLayout(text,
|
||||
@@ -135,9 +135,10 @@ void D2DState::DrawTextBox(const wchar_t* text,
|
||||
bitmapRt->GetBitmap(&rtBitmap);
|
||||
|
||||
shadowEffect->SetInput(0, rtBitmap.get());
|
||||
const auto shadowMatrix = D2D1::Matrix3x2F::Translation(consts::SHADOW_OFFSET * dpiScale,
|
||||
consts::SHADOW_OFFSET * dpiScale);
|
||||
winrt::check_hresult(affineTransformEffect->SetValue(D2D1_2DAFFINETRANSFORM_PROP_TRANSFORM_MATRIX,
|
||||
D2D1::Matrix3x2F::Translation(consts::SHADOW_OFFSET * dpiScale,
|
||||
consts::SHADOW_OFFSET * dpiScale)));
|
||||
shadowMatrix));
|
||||
auto deviceContext = rt.query<ID2D1DeviceContext>();
|
||||
deviceContext->DrawImage(affineTransformEffect.get(), D2D1_INTERPOLATION_MODE_LINEAR);
|
||||
|
||||
@@ -148,6 +149,7 @@ void D2DState::DrawTextBox(const wchar_t* text,
|
||||
textBoxRect.rect.top += TEXT_BOX_PADDING;
|
||||
textBoxRect.rect.left += TEXT_BOX_PADDING;
|
||||
textBoxRect.rect.right -= TEXT_BOX_PADDING;
|
||||
|
||||
// Draw text & its box
|
||||
rt->FillRoundedRectangle(textBoxRect, solidBrushes[Brush::background].get());
|
||||
|
||||
|
||||
@@ -31,12 +31,12 @@ struct D2DState
|
||||
|
||||
float dpiScale = 1.f;
|
||||
|
||||
D2DState(HWND window, std::vector<D2D1::ColorF> solidBrushesColors);
|
||||
D2DState(const HWND window, std::vector<D2D1::ColorF> solidBrushesColors);
|
||||
void DrawTextBox(const wchar_t* text,
|
||||
const uint32_t textLen,
|
||||
const std::optional<size_t> halfOpaqueSymbolPos,
|
||||
const float centerX,
|
||||
const float centerY,
|
||||
const bool screenQuadrantAware,
|
||||
HWND window) const;
|
||||
const HWND window) const;
|
||||
};
|
||||
|
||||
@@ -76,7 +76,9 @@ inline long FindEdge(const BGRATextureView& texture, const POINT centerPoint, co
|
||||
}
|
||||
|
||||
template<bool PerChannel, bool ContinuousCapture>
|
||||
inline RECT DetectEdgesInternal(const BGRATextureView& texture, const POINT centerPoint, const uint8_t tolerance)
|
||||
inline RECT DetectEdgesInternal(const BGRATextureView& texture,
|
||||
const POINT centerPoint,
|
||||
const uint8_t tolerance)
|
||||
{
|
||||
return RECT{ .left = FindEdge<PerChannel,
|
||||
ContinuousCapture,
|
||||
@@ -105,6 +107,6 @@ RECT DetectEdges(const BGRATextureView& texture,
|
||||
auto function = perChannel ? &DetectEdgesInternal<true, false> : DetectEdgesInternal<false, false>;
|
||||
if (continuousCapture)
|
||||
function = perChannel ? &DetectEdgesInternal<true, true> : &DetectEdgesInternal<false, true>;
|
||||
|
||||
|
||||
return function(texture, centerPoint, tolerance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,12 +148,11 @@ void D3DCaptureState::OnFrameArrived(const winrt::Direct3D11CaptureFramePool& se
|
||||
GetCursorPos(&cursorPos);
|
||||
|
||||
auto frame = sender.TryGetNextFrame();
|
||||
winrt::check_bool(frame);
|
||||
if (monitorArea.inside(cursorPos) || captureOutsideOfMonitor)
|
||||
{
|
||||
winrt::com_ptr<ID3D11Texture2D> texture;
|
||||
{
|
||||
winrt::check_bool(frame);
|
||||
|
||||
if (auto newFrameSize = frame.ContentSize(); newFrameSize != frameSize)
|
||||
{
|
||||
winrt::check_hresult(swapChain->ResizeBuffers(2,
|
||||
@@ -174,6 +173,8 @@ void D3DCaptureState::OnFrameArrived(const winrt::Direct3D11CaptureFramePool& se
|
||||
}
|
||||
}
|
||||
|
||||
frame.Close();
|
||||
|
||||
DXGI_PRESENT_PARAMETERS presentParameters = {};
|
||||
swapChain->Present1(1, 0, &presentParameters);
|
||||
|
||||
@@ -223,18 +224,17 @@ std::unique_ptr<D3DCaptureState> D3DCaptureState::Create(const winrt::GraphicsCa
|
||||
winrt::com_ptr<IInspectable> d3dDeviceInspectable;
|
||||
winrt::check_hresult(CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.get(), d3dDeviceInspectable.put()));
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 desc = {};
|
||||
desc.Width = static_cast<uint32_t>(item.Size().Width);
|
||||
desc.Height = static_cast<uint32_t>(item.Size().Height);
|
||||
desc.Format = static_cast<DXGI_FORMAT>(pixelFormat);
|
||||
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.BufferCount = 2;
|
||||
desc.Scaling = DXGI_SCALING_STRETCH;
|
||||
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED;
|
||||
auto dxgiDevice2 = d3dDevice.as<IDXGIDevice2>();
|
||||
const DXGI_SWAP_CHAIN_DESC1 desc = {
|
||||
.Width = static_cast<uint32_t>(item.Size().Width),
|
||||
.Height = static_cast<uint32_t>(item.Size().Height),
|
||||
.Format = static_cast<DXGI_FORMAT>(pixelFormat),
|
||||
.SampleDesc = { .Count = 1, .Quality = 0 },
|
||||
.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
|
||||
.BufferCount = 2,
|
||||
.Scaling = DXGI_SCALING_STRETCH,
|
||||
.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL,
|
||||
.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED,
|
||||
};
|
||||
winrt::com_ptr<IDXGIAdapter> adapter;
|
||||
winrt::check_hresult(dxgiDevice->GetParent(winrt::guid_of<IDXGIAdapter>(), adapter.put_void()));
|
||||
winrt::com_ptr<IDXGIFactory2> factory;
|
||||
@@ -265,6 +265,7 @@ D3DCaptureState::~D3DCaptureState()
|
||||
std::unique_lock callbackLock{ destructorMutex };
|
||||
StopCapture();
|
||||
framePool.Close();
|
||||
device.Close();
|
||||
}
|
||||
|
||||
void D3DCaptureState::StartSessionInPreferredMode()
|
||||
|
||||
Reference in New Issue
Block a user