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

gdi32 palette functions #49

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

gdi32 palette functions #49

wants to merge 4 commits into from

Conversation

LinusU
Copy link
Contributor

@LinusU LinusU commented Sep 14, 2024

No description provided.

@LinusU LinusU mentioned this pull request Sep 14, 2024
27 tasks
@@ -134,7 +136,8 @@ pub fn GetDeviceCaps(
GetDeviceCapsArg::NUMCOLORS => -1i32 as u32, // true color
GetDeviceCapsArg::HORZRES => 640,
GetDeviceCapsArg::VERTRES => 480,
_ => unimplemented!(),
GetDeviceCapsArg::RASTERCAPS => 0x100, // RC_PALETTE
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to depend on the underlying device? I think this is making this function say that all our DCs support palettes, when I think in practice none (?) of them do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure here, but what I assumed when I wrote it was that the palettes would be handled by some code that I will write soon. But with that said, I'm not really sure what these paletts do, and how they are used at the moment 😅

Maybe it's better to hold of on this one until I have gotten more of it to work...

@@ -98,6 +99,7 @@ pub fn SelectObject(machine: &mut Machine, hdc: HDC, hGdiObj: HGDIOBJ) -> HGDIOB
DCTarget::DirectDrawSurface(_) => todo!(),
},
Object::Brush(_) => std::mem::replace(&mut dc.brush, hGdiObj),
Object::Palette(_) => panic!("SelectObject called with a palette (use SelectPalette)"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the author of the exe is unlikely to see this recommendation :)

(The panic is fine, but if a program ends up going down this codepath we'll need to eventually figure out what behavior they expected)


#[win32_derive::dllexport]
pub fn CreatePalette(machine: &mut Machine, plpal: u32) -> HGDIOBJ {
let header = machine.mem().view::<LOGPALETTE_HEADER>(plpal).clone();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better as:

let header = machine.mem().get_pod::<LOGPALETTE_HEADER>(plpal);

(Ultimately I think I might need to remove the .view() methods, because Rust is unhappy if the underlying pointers aren't aligned)

let header = machine.mem().view::<LOGPALETTE_HEADER>(plpal).clone();

let entries = plpal + size_of::<LOGPALETTE_HEADER>() as u32;
let entries = machine.mem().view_n::<PALETTEENTRY>(entries, header.palNumEntries as u32).to_vec();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(...but don't worry about changing view_n, I will need to revisit this API...)

Object::Bitmap(_) => panic!("SelectPalette called with a bitmap (use SelectObject)"),
Object::Brush(_) => panic!("SelectPalette called with a brush (use SelectObject)"),
Object::Palette(_) => std::mem::replace(&mut dc.palette, hpal),
Object::Pen(_) => panic!("SelectPalette called with a pen (use SelectObject)"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same comment here about the panic!()s, they might be better expressed as todo()s given that if they're ever called we will need to figure what to do

#[win32_derive::dllexport]
pub fn RealizePalette(machine: &mut Machine, hdc: HDC) -> u32 {
let dc = match machine.state.gdi32.dcs.get_mut(hdc) {
None => return !0,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...oh interesting, I think this is basically saying the palette supports 2^32 entries?

Could you put a module-level comment about how you are thinking about this? I guess returning RC_PALETTE above is correct if this is a legal value here (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the value of GDI_ERROR is !0, my intention was to return GDI_ERROR. I should have made it a constant though 😅

Comment on lines +69 to +72
Object::Bitmap(_) => panic!("RealizePalette called with a bitmap"),
Object::Brush(_) => panic!("RealizePalette called with a brush"),
Object::Palette(palette) => palette.1.len() as u32,
Object::Pen(_) => panic!("RealizePalette called with a pen"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could perhaps just handle the Palette case and add a _ => todo! branch otherwise, unless you think it's common

@LinusU LinusU mentioned this pull request Sep 22, 2024
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.

2 participants