Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to PDN 5.1 and BitmapEffect #62

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

rickbrew
Copy link

No description provided.

`bmpCommitted` is mostly used in methods that operate on `S.D.Bitmap`. However, the new effect system in PDN 5.0+ operates on `IBitmap`s. In order to safely interoperate between these, without having expensive copies, the bitmap must be allocated as an `IBitmap` with an aliased `S.D.Bitmap`.

This ensures that lifetime can be controlled by the `IBitmap`, which supports reference counting (via `CreateRef()`/`TryCreateRef()`). `S.D.Bitmap` has no way to link itself to another object, so the constructor overload that takes a pointer to bitmap data is very prone to use-after-free errors. The `IBitmap` implements a "link" from the `S.D.Bitmap` to itself via `ConditionalWeakTable`, which ensures that the `IBitmap` won't be garbage collected if the only reference to it is through the "link" from `S.D.Bitmap`. (so you could create the `InteropBitmap`, then use `AsGdipBitmap()`, and then forget/drop the reference to the `InteropBitmap`, and it still wouldn't get freed until the `S.D.Bitmap` is garbage collected.)

Also, PDN does not provide a built-in way to create a "shared" `IBitmap` that points to memory allocated elsewhere (for good reason -- it immediately causes major bug hazards that I did see tripped over during PDN 5.0's private alpha period!). So this custom mechanism was required.
This was never supposed to have any public APIs in it, and anything left in there is now `internal` or `[Obsolete]`
Still a few things left that aren't compiling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant