mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
WindowServer: Clang-Format
This commit is contained in:
parent
29a9430246
commit
c72953cf06
3 changed files with 61 additions and 37 deletions
|
@ -80,7 +80,7 @@ void WSCompositor::compose()
|
||||||
dbgprintf("[WM] compose #%u (%u rects)\n", ++m_compose_count, dirty_rects.rects().size());
|
dbgprintf("[WM] compose #%u (%u rects)\n", ++m_compose_count, dirty_rects.rects().size());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto any_dirty_rect_intersects_window = [&dirty_rects] (const WSWindow& window) {
|
auto any_dirty_rect_intersects_window = [&dirty_rects](const WSWindow& window) {
|
||||||
auto window_frame_rect = window.frame().rect();
|
auto window_frame_rect = window.frame().rect();
|
||||||
for (auto& dirty_rect : dirty_rects.rects()) {
|
for (auto& dirty_rect : dirty_rects.rects()) {
|
||||||
if (dirty_rect.intersects(window_frame_rect))
|
if (dirty_rect.intersects(window_frame_rect))
|
||||||
|
@ -97,22 +97,22 @@ void WSCompositor::compose()
|
||||||
if (m_wallpaper_mode == WallpaperMode::Simple) {
|
if (m_wallpaper_mode == WallpaperMode::Simple) {
|
||||||
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
||||||
} else if (m_wallpaper_mode == WallpaperMode::Center) {
|
} else if (m_wallpaper_mode == WallpaperMode::Center) {
|
||||||
Point offset{ ws.size().width() / 2 - m_wallpaper->size().width() / 2,
|
Point offset { ws.size().width() / 2 - m_wallpaper->size().width() / 2,
|
||||||
ws.size().height() / 2 - m_wallpaper->size().height() / 2 };
|
ws.size().height() / 2 - m_wallpaper->size().height() / 2 };
|
||||||
m_back_painter->blit_offset(dirty_rect.location(), *m_wallpaper,
|
m_back_painter->blit_offset(dirty_rect.location(), *m_wallpaper,
|
||||||
dirty_rect, offset);
|
dirty_rect, offset);
|
||||||
} else if (m_wallpaper_mode == WallpaperMode::Tile) {
|
} else if (m_wallpaper_mode == WallpaperMode::Tile) {
|
||||||
m_back_painter->blit_tiled(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
m_back_painter->blit_tiled(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: Does not work: offset rect creates trails.
|
// FIXME: Does not work: offset rect creates trails.
|
||||||
m_back_painter->draw_scaled_bitmap(dirty_rect, *m_wallpaper,
|
m_back_painter->draw_scaled_bitmap(dirty_rect, *m_wallpaper,
|
||||||
{ dirty_rect.location(),
|
{ dirty_rect.location(),
|
||||||
m_wallpaper->size() });
|
m_wallpaper->size() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto compose_window = [&] (WSWindow& window) -> IterationDecision {
|
auto compose_window = [&](WSWindow& window) -> IterationDecision {
|
||||||
if (!any_dirty_rect_intersects_window(window))
|
if (!any_dirty_rect_intersects_window(window))
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
PainterStateSaver saver(*m_back_painter);
|
PainterStateSaver saver(*m_back_painter);
|
||||||
|
@ -154,7 +154,7 @@ void WSCompositor::compose()
|
||||||
if (auto* fullscreen_window = wm.active_fullscreen_window()) {
|
if (auto* fullscreen_window = wm.active_fullscreen_window()) {
|
||||||
compose_window(*fullscreen_window);
|
compose_window(*fullscreen_window);
|
||||||
} else {
|
} else {
|
||||||
wm.for_each_visible_window_from_back_to_front([&] (WSWindow& window) {
|
wm.for_each_visible_window_from_back_to_front([&](WSWindow& window) {
|
||||||
return compose_window(window);
|
return compose_window(window);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ bool WSCompositor::set_wallpaper(const String& path, Function<void(bool)>&& call
|
||||||
context->path = path;
|
context->path = path;
|
||||||
context->callback = move(callback);
|
context->callback = move(callback);
|
||||||
|
|
||||||
int rc = create_thread([] (void* ctx) -> int {
|
int rc = create_thread([](void* ctx) -> int {
|
||||||
OwnPtr<Context> context((Context*)ctx);
|
OwnPtr<Context> context((Context*)ctx);
|
||||||
context->bitmap = load_png(context->path);
|
context->bitmap = load_png(context->path);
|
||||||
if (!context->bitmap) {
|
if (!context->bitmap) {
|
||||||
|
@ -242,13 +242,14 @@ bool WSCompositor::set_wallpaper(const String& path, Function<void(bool)>&& call
|
||||||
exit_thread(0);
|
exit_thread(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
the().deferred_invoke([context = move(context)] (auto&) {
|
the().deferred_invoke([context = move(context)](auto&) {
|
||||||
the().finish_setting_wallpaper(context->path, *context->bitmap);
|
the().finish_setting_wallpaper(context->path, *context->bitmap);
|
||||||
context->callback(true);
|
context->callback(true);
|
||||||
});
|
});
|
||||||
exit_thread(0);
|
exit_thread(0);
|
||||||
return 0;
|
return 0;
|
||||||
}, context.leak_ptr());
|
},
|
||||||
|
context.leak_ptr());
|
||||||
ASSERT(rc == 0);
|
ASSERT(rc == 0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -275,7 +276,7 @@ void WSCompositor::set_resolution(int width, int height)
|
||||||
auto screen_rect = WSScreen::the().rect();
|
auto screen_rect = WSScreen::the().rect();
|
||||||
if (screen_rect.width() == width && screen_rect.height() == height)
|
if (screen_rect.width() == width && screen_rect.height() == height)
|
||||||
return;
|
return;
|
||||||
m_wallpaper_path = { };
|
m_wallpaper_path = {};
|
||||||
m_wallpaper = nullptr;
|
m_wallpaper = nullptr;
|
||||||
WSScreen::the().set_resolution(width, height);
|
WSScreen::the().set_resolution(width, height);
|
||||||
m_front_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, { width, height }, WSScreen::the().scanline(0));
|
m_front_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, { width, height }, WSScreen::the().scanline(0));
|
||||||
|
@ -303,7 +304,7 @@ void WSCompositor::draw_geometry_label()
|
||||||
auto& wm = WSWindowManager::the();
|
auto& wm = WSWindowManager::the();
|
||||||
auto* window_being_moved_or_resized = wm.m_drag_window ? wm.m_drag_window.ptr() : (wm.m_resize_window ? wm.m_resize_window.ptr() : nullptr);
|
auto* window_being_moved_or_resized = wm.m_drag_window ? wm.m_drag_window.ptr() : (wm.m_resize_window ? wm.m_resize_window.ptr() : nullptr);
|
||||||
if (!window_being_moved_or_resized) {
|
if (!window_being_moved_or_resized) {
|
||||||
m_last_geometry_label_rect = { };
|
m_last_geometry_label_rect = {};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto geometry_string = window_being_moved_or_resized->rect().to_string();
|
auto geometry_string = window_being_moved_or_resized->rect().to_string();
|
||||||
|
@ -340,7 +341,7 @@ void WSCompositor::draw_menubar()
|
||||||
m_back_painter->fill_rect(menubar_rect, Color::LightGray);
|
m_back_painter->fill_rect(menubar_rect, Color::LightGray);
|
||||||
m_back_painter->draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, Color::MidGray);
|
m_back_painter->draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, Color::MidGray);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
wm.for_each_active_menubar_menu([&] (WSMenu& menu) {
|
wm.for_each_active_menubar_menu([&](WSMenu& menu) {
|
||||||
Color text_color = Color::Black;
|
Color text_color = Color::Black;
|
||||||
if (&menu == wm.current_menu()) {
|
if (&menu == wm.current_menu()) {
|
||||||
m_back_painter->fill_rect(menu.rect_in_menubar(), wm.menu_selection_color());
|
m_back_painter->fill_rect(menu.rect_in_menubar(), wm.menu_selection_color());
|
||||||
|
@ -351,8 +352,7 @@ void WSCompositor::draw_menubar()
|
||||||
menu.name(),
|
menu.name(),
|
||||||
index == 1 ? wm.app_menu_font() : wm.menu_font(),
|
index == 1 ? wm.app_menu_font() : wm.menu_font(),
|
||||||
TextAlignment::CenterLeft,
|
TextAlignment::CenterLeft,
|
||||||
text_color
|
text_color);
|
||||||
);
|
|
||||||
++index;
|
++index;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#include "Painter.h"
|
#include "Painter.h"
|
||||||
#include "Font.h"
|
#include "Font.h"
|
||||||
#include "GraphicsBitmap.h"
|
#include "GraphicsBitmap.h"
|
||||||
#include <SharedGraphics/CharacterBitmap.h>
|
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <unistd.h>
|
#include <SharedGraphics/CharacterBitmap.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#pragma GCC optimize("O3")
|
#pragma GCC optimize("O3")
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
|
||||||
RGBA32* dst = m_target->scanline(clipped_rect.top()) + clipped_rect.left();
|
RGBA32* dst = m_target->scanline(clipped_rect.top()) + clipped_rect.left();
|
||||||
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
|
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
|
||||||
|
|
||||||
float increment = (1.0/((rect.width())/255.0));
|
float increment = (1.0 / ((rect.width()) / 255.0));
|
||||||
|
|
||||||
int r2 = gradient_start.red();
|
int r2 = gradient_start.red();
|
||||||
int g2 = gradient_start.green();
|
int g2 = gradient_start.green();
|
||||||
|
@ -104,8 +104,8 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
|
||||||
dst[j] = Color(
|
dst[j] = Color(
|
||||||
r1 / 255.0 * c + r2 / 255.0 * (255 - c),
|
r1 / 255.0 * c + r2 / 255.0 * (255 - c),
|
||||||
g1 / 255.0 * c + g2 / 255.0 * (255 - c),
|
g1 / 255.0 * c + g2 / 255.0 * (255 - c),
|
||||||
b1 / 255.0 * c + b2 / 255.0 * (255 - c)
|
b1 / 255.0 * c + b2 / 255.0 * (255 - c))
|
||||||
).value();
|
.value();
|
||||||
c += increment;
|
c += increment;
|
||||||
}
|
}
|
||||||
dst += dst_skip;
|
dst += dst_skip;
|
||||||
|
@ -289,7 +289,7 @@ void Painter::blit_tiled(const Point& position, const GraphicsBitmap& source, co
|
||||||
int x_start = first_column + src_rect.left();
|
int x_start = first_column + src_rect.left();
|
||||||
for (int row = first_row; row <= last_row; ++row) {
|
for (int row = first_row; row <= last_row; ++row) {
|
||||||
const RGBA32* sl = source.scanline((row + src_rect.top())
|
const RGBA32* sl = source.scanline((row + src_rect.top())
|
||||||
% source.size().height());
|
% source.size().height());
|
||||||
for (int x = x_start; x < clipped_rect.width() + x_start; ++x) {
|
for (int x = x_start; x < clipped_rect.width() + x_start; ++x) {
|
||||||
dst[x - x_start] = sl[x % source.size().width()];
|
dst[x - x_start] = sl[x % source.size().width()];
|
||||||
}
|
}
|
||||||
|
@ -302,9 +302,9 @@ void Painter::blit_tiled(const Point& position, const GraphicsBitmap& source, co
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::blit_offset(const Point& position,
|
void Painter::blit_offset(const Point& position,
|
||||||
const GraphicsBitmap& source,
|
const GraphicsBitmap& source,
|
||||||
const Rect& src_rect,
|
const Rect& src_rect,
|
||||||
const Point& offset)
|
const Point& offset)
|
||||||
{
|
{
|
||||||
auto dst_rect = Rect(position, src_rect.size()).translated(translation());
|
auto dst_rect = Rect(position, src_rect.size()).translated(translation());
|
||||||
auto clipped_rect = dst_rect.intersected(clip_rect());
|
auto clipped_rect = dst_rect.intersected(clip_rect());
|
||||||
|
@ -483,17 +483,33 @@ void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& s
|
||||||
|
|
||||||
if (source.has_alpha_channel()) {
|
if (source.has_alpha_channel()) {
|
||||||
switch (source.format()) {
|
switch (source.format()) {
|
||||||
case GraphicsBitmap::Format::RGB32: do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); break;
|
case GraphicsBitmap::Format::RGB32:
|
||||||
case GraphicsBitmap::Format::RGBA32: do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); break;
|
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>);
|
||||||
case GraphicsBitmap::Format::Indexed8: do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>); break;
|
break;
|
||||||
default: do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>); break;
|
case GraphicsBitmap::Format::RGBA32:
|
||||||
|
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>);
|
||||||
|
break;
|
||||||
|
case GraphicsBitmap::Format::Indexed8:
|
||||||
|
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (source.format()) {
|
switch (source.format()) {
|
||||||
case GraphicsBitmap::Format::RGB32: do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); break;
|
case GraphicsBitmap::Format::RGB32:
|
||||||
case GraphicsBitmap::Format::RGBA32: do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); break;
|
do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>);
|
||||||
case GraphicsBitmap::Format::Indexed8: do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>); break;
|
break;
|
||||||
default: do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>); break;
|
case GraphicsBitmap::Format::RGBA32:
|
||||||
|
do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>);
|
||||||
|
break;
|
||||||
|
case GraphicsBitmap::Format::Indexed8:
|
||||||
|
do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
#include "Rect.h"
|
#include "Rect.h"
|
||||||
#include "Size.h"
|
#include "Size.h"
|
||||||
|
#include <AK/AKString.h>
|
||||||
#include <SharedGraphics/TextAlignment.h>
|
#include <SharedGraphics/TextAlignment.h>
|
||||||
#include <SharedGraphics/TextElision.h>
|
#include <SharedGraphics/TextElision.h>
|
||||||
#include <AK/AKString.h>
|
|
||||||
|
|
||||||
class CharacterBitmap;
|
class CharacterBitmap;
|
||||||
class GlyphBitmap;
|
class GlyphBitmap;
|
||||||
|
@ -38,7 +38,11 @@ public:
|
||||||
const Font& font() const { return *state().font; }
|
const Font& font() const { return *state().font; }
|
||||||
void set_font(const Font& font) { state().font = &font; }
|
void set_font(const Font& font) { state().font = &font; }
|
||||||
|
|
||||||
enum class DrawOp { Copy, Xor };
|
enum class DrawOp
|
||||||
|
{
|
||||||
|
Copy,
|
||||||
|
Xor
|
||||||
|
};
|
||||||
void set_draw_op(DrawOp op) { state().draw_op = op; }
|
void set_draw_op(DrawOp op) { state().draw_op = op; }
|
||||||
DrawOp draw_op() const { return state().draw_op; }
|
DrawOp draw_op() const { return state().draw_op; }
|
||||||
|
|
||||||
|
@ -54,7 +58,11 @@ public:
|
||||||
GraphicsBitmap* target() { return m_target.ptr(); }
|
GraphicsBitmap* target() { return m_target.ptr(); }
|
||||||
|
|
||||||
void save() { m_state_stack.append(m_state_stack.last()); }
|
void save() { m_state_stack.append(m_state_stack.last()); }
|
||||||
void restore() { ASSERT(m_state_stack.size() > 1); m_state_stack.take_last(); }
|
void restore()
|
||||||
|
{
|
||||||
|
ASSERT(m_state_stack.size() > 1);
|
||||||
|
m_state_stack.take_last();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void set_pixel_with_draw_op(dword& pixel, const Color&);
|
void set_pixel_with_draw_op(dword& pixel, const Color&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue