Comments (5)
Notes from API review
Looks good as proposed.
API breakdown (click to expand):
namespace ABI {
namespace Microsoft {
namespace Graphics {
namespace Canvas {
class __declspec(uuid("040AB731-08F1-469F-9BF9-5B1160F27224"))
ICanvasSwapChainFactoryNative : public IUnknown
{
public:
IFACEMETHOD(CreateForHwnd)(
ICanvasResourceCreator* resourceCreator,
HWND hwnd,
uint32_t width,
uint32_t height,
float dpi,
DirectXPixelFormat format,
int32_t bufferCount,
ICanvasSwapChain** canvasSwapChain) = 0;
};
} } } }
namespace Microsoft.Graphics.Canvas;
public sealed class CanvasSwapChain
{
public static CanvasSwapChain CreateForHwnd(
IntPtr hwnd,
uint width,
uint height);
public static CanvasSwapChain CreateForHwnd(
IntPtr hwnd,
uint width,
uint height,
DirectXPixelFormat format,
int bufferCount);
}
The C# APIs added to CanvasSwapChain
will use GetDpiForWindow
to set the initial DPI value. It is up to developers to then monitor DPI changes (through WM_DPICHANGE
) and call the appropriate Resize
overload to update the DPI value. This matches the general behavior of CanvasSwapChain
when used with composition or CoreWindow
as well. Additionally, CanvasSwapChain
as a whole is meant to be a lower-level helper API anyway. The new APIs introduced in this proposal will already make it significantly easier for developers to get a swapchain running on a raw HWND. For those needing more control over how the swapchain is created, they can keep using the existing approach of manually creating the swapchain and then using GetOrCreate
from the CanvasDevice
activation factory interop interface to get the WinRT wrapper for it.
from win2d.
Can't you retrieve the window DPI with GetDpiForWindow?
from win2d.
Right, we could use that to automatically get the initial DPIs, and remove the dpi
parameter form the static constructors, that'd work nicely. The only thing I'm not exactly sure how to handle is the fact the effective DPI might change after creating the swap chain (eg. if you move the window to another screen with a different DPI, or if you change the DPIs on your screen), but the swap chain wouldn't really respond to that, and its internal DPI value would become "out of sync".
Should we just not worry about this scenario? Users are still able to override the DPI value by calling the Resize
overload, is that enough? As in, they could detect a DPI change on their end, and then call Resize
with 0
for width and height, and the right value for the new DPI. The swap chain would resize automatically and then update the internal DPI value.
Maybe that's sufficient? 🤔
from win2d.
You could subclass the window to capture the WM_DPICHANGE message. Am I understanding correctly that Win2D tracks its own DPI values?
from win2d.
I guess it does when you use higher level objects that handle that for you (eg. CanvasAnimatedControl
, which is a wrapper around CanvasSwapChain
, which subscribes to DPI changes automatically). Double checking things, CanvasSwapChain
does not in fact handle this automatically, as it's meant to be a lower level object, so I guess that makes sense. If you want to update DPIs you can just monitor DPI change events on your own and call Resize
on the panel when needing, and pass the new DPI value from there to update it. It seems like that should be enough. 🤔
from win2d.
Related Issues (20)
- what is win2d ?is same to direct2d? HOT 6
- Somthing is wrong with `Microsoft::Graphics::Canvas::CanvasBitmap::CreateFromBytes` (not straight forward to call it)
- Use non-version-specific RID folders in NuGet package HOT 2
- Upgrade to v1.1.0 causes compiler error HOT 4
- `CanvasDrawingSession.DrawGlyphRun` renders emojis in monochrome when using color font and `CanvasDrawTextOptions.EnableColorFont` option HOT 2
- A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll HOT 1
- How to enable Windows 11's Auto HDR feature on Win2D?
- Changelog for Win2D.uwp 1.27.1 HOT 3
- CanvasTextFormat throws in Unpackaged apps HOT 17
- Microsoft.Graphics.Canvas.winmd cannot be referenced HOT 5
- Microsoft.Graphics.Win2D fail to work with winui after 1.1.0 HOT 3
- Doc Bug in readme.md
- .net8 Cannot create instance of type Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl HOT 1
- Installing the NuGet package results in a fatal error HOT 3
- Exception thrown: 'System.TypeInitializationException' in Microsoft.Graphics.Canvas.Interop.dll
- Strange problem with Microsoft.Graphics.Canvas.Geometry.CanvasPathBuilder HOT 13
- Question about performance
- Error installing Win2D NuGet in WinUI3 app HOT 2
- Text Color Bleeding Out of Outline HOT 2
- The print preview is very blurry at 200% zoom.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from win2d.