summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/ShareableBitmap.cpp
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2021-01-19 12:10:47 -0500
committerAndreas Kling <kling@serenityos.org>2021-01-20 10:28:27 +0100
commit5f9c42c404a5acfa66461a3c6568592f5326e9de (patch)
tree9d29f3caeea87721d8ec9a3d754e526bb5d253b9 /Userland/Libraries/LibGfx/ShareableBitmap.cpp
parentc6726f331ea53bc7ee5679a84c6c10af65428a4b (diff)
downloadserenity-5f9c42c404a5acfa66461a3c6568592f5326e9de.zip
LibGfx: Give Bitmap a scale factor
Gfx::Bitmap can now store its scale factor. Normally it's 1, but in high dpi mode it can be 2. If a Bitmap with a scale factor of 2 is blitted to a Painter with scale factor of 2, the pixels can be copied over without any resampling. (When blitting a Bitmap with a scale factor of 1 to a Painter with scale factor of 2, the Bitmap is painted at twice its width and height at paint time. Blitting a Bitmap with a scale factor of 2 to a Painter with scale factor 1 is not supported.) A Bitmap with scale factor of 2 reports the same width() and height() as one with scale factor 1. That's important because many places in the codebase use a bitmap's width() and height() to layout Widgets, and all widget coordinates are in logical coordinates as well, per Documentation/HighDPI.md. Bitmap grows physical_width() / physical_height() to access the actual pixel size. Update a few callers that work with pixels to call this instead. Make Painter's constructor take its scale factor from the target bitmap that's passed in, and update its various blit() methods to handle blitting a 2x bitmap to a 2x painter. This allows removing some gnarly code in Compositor. (In return, put some new gnarly code in LibGfxScaleDemo to preserve behavior there.) No intended behavior change.
Diffstat (limited to 'Userland/Libraries/LibGfx/ShareableBitmap.cpp')
-rw-r--r--Userland/Libraries/LibGfx/ShareableBitmap.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.cpp b/Userland/Libraries/LibGfx/ShareableBitmap.cpp
index c59a2d0dad..9babcd7ea2 100644
--- a/Userland/Libraries/LibGfx/ShareableBitmap.cpp
+++ b/Userland/Libraries/LibGfx/ShareableBitmap.cpp
@@ -55,6 +55,7 @@ bool encode(Encoder& encoder, const Gfx::ShareableBitmap& shareable_bitmap)
auto& bitmap = *shareable_bitmap.bitmap();
encoder << IPC::File(bitmap.anon_fd());
encoder << bitmap.size();
+ encoder << bitmap.scale();
encoder << (u32)bitmap.format();
if (bitmap.is_indexed()) {
auto palette = bitmap.palette_to_vector();
@@ -78,6 +79,9 @@ bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
Gfx::IntSize size;
if (!decoder.decode(size))
return false;
+ u32 scale;
+ if (!decoder.decode(scale))
+ return false;
u32 raw_bitmap_format;
if (!decoder.decode(raw_bitmap_format))
return false;
@@ -89,7 +93,7 @@ bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
if (!decoder.decode(palette))
return false;
}
- auto bitmap = Gfx::Bitmap::create_with_anon_fd(bitmap_format, anon_file.take_fd(), size, palette, Gfx::Bitmap::ShouldCloseAnonymousFile::Yes);
+ auto bitmap = Gfx::Bitmap::create_with_anon_fd(bitmap_format, anon_file.take_fd(), size, scale, palette, Gfx::Bitmap::ShouldCloseAnonymousFile::Yes);
if (!bitmap)
return false;
shareable_bitmap = Gfx::ShareableBitmap { bitmap.release_nonnull(), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap };