Compare commits

...
Author SHA1 Message Date
7252e1f97f
Bump version to 2.24.34 2026-10-19 11:30:36 +02:00
4e44546d6b
file operations: Undo and Redo more careful: one stopped halfway keeps what is left to do, only one runs at a time and none while files are being copied, nothing that is there now is overwritten by a file that comes back from the trash, and from the Recycle Bin of Windows only the file that was trashed comes back; a question whose window went away cancels instead of waiting forever 2026-10-19 11:30:36 +02:00
4f99a52c7e
selection: no critical when the callback of a retrieval destroys its widget, as the clipboard does with the widgets of requests that run at the same time 2026-10-19 11:30:36 +02:00
bc6cc6a5d3
win32: gdk_keymap_get_entries_for_keyval() with NULL for the default keymap, as documented, no longer crashes 2026-10-19 11:30:36 +02:00
f0e53e088e
clipboard: files cut or copied in GTK+ programs can be pasted in Explorer and the Finder, and files cut or copied in Explorer can be pasted in GTK+ programs, as with file managers on X11 (CF_HDROP and Preferred DropEffect on Windows, NSFilenamesPboardType on the Mac) 2026-10-19 11:30:35 +02:00
276e0d2b13
file chooser: Connect to Server as in GTK+ 3, Nautilus and the Finder: a place opens a dialog for the address, with the servers used before (shared with GTK+ 3 and Nautilus) and examples of the protocols there are; GVfs mounts the server and asks for the password, on Windows the shell connects to \\server\share, on the Mac the Finder (Command+K); the place is there where servers can be reached 2026-10-19 11:30:35 +02:00
d8165b608b
file chooser: drives, volumes and mounts (also of servers) have an eject button on their place and Unmount and Eject in its menu, as in GTK+ 3; the dialog leaves a folder that goes with them; the tooltips of places show the free space; a copy that does not fit asks first 2026-10-19 11:30:35 +02:00
2299a1a77e
file chooser: drag and drop of files as in file managers, within the dialog and with other programs: onto folders of the list, the path bar and the places to copy or move (a move within one file system, Ctrl copies, Shift moves, both link, Option and Command on the Mac, a menu when the source asks), with progress and Undo; a drop on the list still selects the files; files that the source saves itself (XdndDirectSave of Firefox, Chromium, archive managers) and paths as text; folders open when a drag stays on them and the list scrolls at its edges; a press on an unselected file drags it; Paste Into Folder; only folders become bookmarks 2026-10-19 11:30:35 +02:00
7369cf5c54
file chooser: Undo and Redo of copies, moves, the trash, renames and new folders, for all file choosers of a program (Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y, Command+Z on the Mac, and in the menu), also of a cancelled copy; what was trashed comes back by the information of the freedesktop.org trash, with or without GVfs, from where the Mac put it, or through the shell from the Recycle Bin of Windows; a folder that is shown and goes away is left for the one above it; trashing has progress and Cancel as copying 2026-10-19 11:30:35 +02:00
3022ee44f3
file chooser: Back and Forward through the folders shown, as in file managers: buttons before the view, Alt+Left and Alt+Right, the Back and Forward keys, Command+[ and ] on the Mac, the back and forward buttons of mice and so the swipes of touchpads 2026-10-19 11:30:35 +02:00
9e5e20b57d
file chooser: a Type column in the list view as in GTK+ 3, with the kind of file (Image, Text, Archive ...) so that formats of one kind sort together, Show Type Column in the menu and Sort by Type in the icon view; TypeFormat=description or mime in gtkfilechooser.ini shows the description or the MIME type 2026-10-19 11:30:35 +02:00
a72c02150c
file chooser: Cut, Copy and Paste of files (menu, Ctrl+X/C/V) as in file managers and with them: folders with all in them, a progress row with Cancel, questions for names that are there (skip, replace or merge, rename, for all) and for errors, moves as renames where possible; the clipboard of Nautilus, Caja, Thunar, PCManFM and Dolphin, cut files dimmed 2026-10-19 11:30:35 +02:00
0c629f2b6e
file chooser: hidden files and backups have a half transparent icon, made once with the icon, as in file managers (from warning-cleanups) 2026-10-19 11:30:35 +02:00
cedae2d805
po: German translations of the menu of the file chooser (from warning-cleanups) 2026-10-19 11:30:35 +02:00
d279af874a
file chooser: in Open and Select Folder mode the location entry shows the path of the current folder and follows it until a name is typed, selected while it has the focus; programs get the same files as with the empty entry before (from warning-cleanups) 2026-10-19 11:30:34 +02:00
e00a21dc62
file chooser: Copy in the menu of the file list and Ctrl+C put the selected files on the clipboard as file managers take them (and their locations as text), and the menu counts the selection once (from warning-cleanups) 2026-10-19 11:30:34 +02:00
ad6401647c
gail and icon view: positions come from atk_component_get_extents() instead of the deprecated atk_component_get_position(), as atk did anyway; gail tests without unused values (from warning-cleanups) 2026-10-19 11:30:34 +02:00
dc44051a08
gtk, gdk/win32: the string of g_string_free() is taken from its result, which newer GLib wants used (from warning-cleanups) 2026-10-19 11:30:34 +02:00
07b11347a4
gtk: GTK+'s own widgets that scroll let a pinch of the touchpad pass, so that it zooms where the program zooms and scrolls nothing, and the scrolled window that has just taken the wheel does not keep it 2026-10-19 11:30:34 +02:00
c15841cb42
quartz: the pinch and the three-finger swipe of trackpads (Mac OS X 10.5.2 and later) become the wheel with Ctrl and the back and forward buttons, as on X11 2026-10-19 11:30:34 +02:00
59874d924a
gdk: touchpad gestures for programs that know nothing of them, as Windows does for its old programs: a pinch is the wheel with Ctrl (a step for every 15 %, up for larger), a swipe sideways the back or forward button, marked for gdk_event_get_touchpad_emulated(); on X11 from XInput 2.4 (libXi 1.8 and an X server that has it) 2026-10-19 11:30:34 +02:00
d6c51afa25
quartz: holding a key down shows the window of accented characters again (10.7 and later) and the chosen character replaces the typed one, as in GTK+ 3.24; any command from Cocoa leaves the key to GTK+ 2026-10-19 11:30:34 +02:00
a69c08008f
quartz: gdk_window_set_functions() enables and disables the close, minimize and zoom buttons of the title bar, so gtk_window_set_deletable() works on Mac OS X (10.2 and later) 2026-10-19 11:30:34 +02:00
b796cdb367
widgets: selections to a vanished window and drags without targets are safe, drag source events no longer leak, tooltips hide on scroll and their window is freed with the display, menu paging reads no stale heights, a paned keeps a position set to its current value, hidden active radio buttons let focus in, small pages scroll at most half a page per wheel step, icon-less tool buttons show their label, a NULL title clears it, as in GTK+ 3 2026-10-19 11:30:33 +02:00
5dcf0992da
tree view, sort model and combo box: a custom search entry is released with the view, deleting a row with a selected child emits changed, the first pixel of a column belongs to it, grid lines in right-to-left order, row deletions reach views that do not ref rows, autosize columns outside a view are quiet, combo popups free paths and read no uninitialized cells, as in GTK+ 3 2026-10-19 11:30:33 +02:00
c787fa9d78
text, entry and labels: setters during the first style of a text view no longer crash, a text view destroyed during a selection drag keeps its buffer, tags up to the end relayout, a link handler that changes the label is safe, label selections survive the same text, keypad cut/copy/paste, Select All only with text, IM cursor positions in characters, accelerator labels without XF86, spin buttons take digits of other scripts, as in GTK+ 3 2026-10-19 11:30:33 +02:00
16d92e39b4
file chooser, recent files and icons: no use of a freed chooser or path bar after closing, a file selected in a hidden dialog stays selected, too long names and existing files in create-folder mode get an error, insensitive accept buttons stay unused, the first row no longer overwrites typed names, the button follows menu and drops, private recent items stay hidden, unknown MIME types are quiet, icon cache and thin icons fixed, as in GTK+ 3 2026-10-19 11:30:33 +02:00
eef0419304
printing: PPD options in the language of the user, Print to File writes to Documents and adds the file to recent files, the scale is applied after rotation and margins, cancel stops a preview, conflicts are checked for a new printer, option widgets let go of their option and radio options take their mnemonic, as in GTK+ 3 2026-10-19 11:30:33 +02:00
9621328939
gdk: client-side windows get visibility events when they ask for them, a monitor unplugged while RandR is read no longer kills the program, transient-for an offscreen window is ignored, win32 event times survive 49.7 days of uptime and modifier keys are marked as such, quartz moves windows in begin_move_drag and skips offscreen windows on monitor changes, as in GTK+ 3 2026-10-19 11:30:33 +02:00
edc807f32d
widgets: show-hidden set by the program is not overridden by the saved setting, tool palette groups move where asked, tool item group headers and unknown builder action widgets no longer leak, an entry icon replaced during a click keeps its release, the sort order of the default sort column changes, and scales and spin buttons show 0 instead of -0, as in GTK+ 3 2026-10-19 11:30:33 +02:00
4b70a0872b
printing: a printer list callback stops when a handler destroys the backend, CUPS job titles are cut to 255 bytes at a character boundary, a second source file no longer leaks the first, and on Windows the driver settings are kept for their printer without overwriting the stack, as in GTK+ 3 2026-10-19 11:30:33 +02:00
c16dc4bc10
gdk: an event filter removed while it runs and added again runs again; on X11 an untrusted client no longer dies on a beep and a Flatpak sandbox no longer sets a pid the window manager could kill; quartz drops the pointers of a destroyed window; win32 centers on a fully set rectangle; as in GTK+ 3 2026-10-19 11:30:33 +02:00
255aea9751
widgets: mnemonics of markup labels work with hidden underlines, selecting in a label without a screen is quiet, notebook action widgets get their requested size, a window presented while hidden keeps the timestamp, drag destinations start zeroed, about dialog cursors belong to its display, radio menu items accept a NULL group, as in GTK+ 3 2026-10-19 11:30:33 +02:00
b4be017769
tree and list stores convert set values of a transformable type instead of refusing them, and dragging a tree view column header shows a window of that column's size, as in GTK+ 3 2026-10-19 11:30:32 +02:00
b00da61b6d
file chooser and recent files: the error about choosing a file where a folder is wanted is shown again, bookmark reordering no longer leaks the name, the recent files menu frees an unfinished fill, and a NULL filter unsets the filter, as in GTK+ 3 2026-10-19 11:30:32 +02:00
86fbdafb66
icon theme: pixbufs given as GIcon are used as they are instead of going through PNG at another size, and theme icons tell SVG by their suffix without a content type query that leaked its result, as in GTK+ 3 2026-10-19 11:30:32 +02:00
3fb8186709
printing: the CUPS backend no longer leaks a connection and a request with every job, closes a borrowed connection only once, frees the TXT records of network printers, and Avahi requests close their own connections 2026-10-19 11:30:32 +02:00
f6a18ffb89
x11: the caps lock state is asked for when it is first needed instead of being unknown until the next key event, and the translate queue is freed with its display, as in GTK+ 3 2026-10-19 11:30:32 +02:00
abb24d44ca
win32: gtk-font-name follows the message font of Windows (Segoe UI 9, Tahoma 8 on XP) as in GTK+ 3, left to pango before 1.43 for any font but Segoe UI; a theme that sets the font still wins 2026-10-19 11:30:32 +02:00
7833d27619
widgets: about dialog links, assistant pages changed in prepare, radio menu items joining a group with an active item, scale marks, tool palettes, notebook tab drags, menu scrolling, tooltips, startup notification of popups and window group lists fixed as in GTK+ 3 2026-10-19 11:30:32 +02:00
9d93158f4e
file chooser, recent files and mounts: search results, the location entry in local-only mode, folder activation, long bookmark names, recent filters by MIME type, the process list of mount operations and icon caches fixed as in GTK+ 3 2026-10-19 11:30:32 +02:00
188847cbfb
printing: custom CUPS option values are checked before use, Kerberos printers no longer ask for a password, options of printer instances stay with the instance, a resolution from the settings wins, and printer references no longer leak 2026-10-19 11:30:32 +02:00
ae1e89a7ff
tree view, icon view and combo box: drags from empty views, extra mouse buttons, keys that only close the search, cursor changes during destruction, filter reordering, expander clicks in combo popups and combo box text items split by markup fixed as in GTK+ 3 2026-10-19 11:30:31 +02:00
3a6a25bf41
entry and text view: icon activatable defaults, display text ranges, primary selection ownership, empty inserts, tag toggles at the end, justified line width and control characters in input methods fixed as in GTK+ 3 2026-10-19 11:30:31 +02:00
d9ba173bf3
quartz: consumed modifiers of key presses, clicks on the title bar, page up and down, Escape in input methods, the clipboard owner and clearing the drag pasteboard fixed as in GTK+ 3 2026-10-19 11:30:31 +02:00
e6c754e1f6
win32: frameless windows are maximized without covering the taskbar, the IME windows follow the scale, monitor info and selection names are read without overflow or leak, and opacity on child windows is ignored quietly, as in GTK+ 3 2026-10-19 11:30:31 +02:00
094b95e9d9
gdk: event freeing, child shapes, root coordinates of destroyed windows and implicit grabs fixed as in GTK+ 3, and windows that do not accept focus no longer offer WM_TAKE_FOCUS 2026-10-19 11:30:31 +02:00
9de26ffeaf
printing: waiting for the list of printers ends after five seconds without news from any backend, so a print server that never answers no longer blocks a print dialog forever 2026-10-19 11:30:31 +02:00
1f8646aaf0
file chooser: the model of a large folder is freed in slices when idle, so closing the dialog does not pause the program 2026-10-19 11:30:31 +02:00
8db41e2c6c
recent manager: the file of recently used items is read when the items are first needed, and not read back after our own write 2026-10-19 11:30:31 +02:00
24693cefa1
pixbuf engine: the kept pieces of theme images also stay in the X server, so drawing a widget composites them there instead of uploading the image again each time 2026-10-19 11:30:31 +02:00
407343ef63
gdk/x11: HiDPI per monitor: on monitors of different scales (the resolution of each output on Xlibre, or GDK_MONITOR_SCALES) each window takes the scale of the monitor it is on and changes it when it is moved there, keeping its size in GDK's pixels; root coordinates go on in each monitor's own pixels of GDK, struts, work area and drag and drop with them; a changed scale of the desktop or of a monitor applies at once 2026-10-19 11:30:31 +02:00
e80dbec5bb
quartz: on Retina screens icons and other pictures with a picture of more pixels are drawn with it, sharp; gdk_window_get_scale_factor() and gdk_screen_get_monitor_scale_factor() give the scale of the screen 2026-10-19 11:30:30 +02:00
cc2e7b9fd4
ms-windows theme: on a screen of a higher scale the parts of the Windows theme are drawn by Windows in its pixels, with the pictures of the theme for that resolution, and sizes of Windows become those of GTK+ 2026-10-19 11:30:30 +02:00
f56dd2d499
gdk/win32: HiDPI: GDK tells Windows that it handles the resolution itself and, at 192 dpi and more (or GDK_SCALE), draws each of its pixels as 2 or more of Windows: sharp text, pictures and lines in the same proportions, windows of the same size as at 96 dpi; what remains of a fraction of the scale goes to the fonts; GDK_WIN32_DPI_AWARE=0 leaves it to Windows 2026-10-19 11:30:30 +02:00
15f80d7bfa
icons: on a screen of a higher scale, icons of the icon theme and stock icons come with a picture of that many more pixels, which GDK draws sharp; also insensitive and prelight 2026-10-19 11:30:30 +02:00
3b97b5209b
gdk/x11: HiDPI as in GTK+ 3: on a screen of scale 2 or more (GDK_SCALE, Gdk/WindowScalingFactor, the resolution of each output on Xlibre, Xft.dpi) everything is drawn in the pixels of the X server, sharp and in the same proportions, while programs keep their sizes; gdk_window_get_scale_factor() and gdk_screen_get_monitor_scale_factor() 2026-10-19 11:30:30 +02:00
ab7ab08dde
gdk/x11: a cursor made of a pixbuf without alpha has its picture, not the first pixel of each row over the whole first row 2026-10-19 11:30:30 +02:00
647b3edd7b
quartz: from macOS 10.14 exposes exactly what GDK and AppKit invalidated, not the merged rectangles of layer-backed views; gdk_quartz_set_use_cocoa_invalidation() and GDK_QUARTZ_COCOA_INVALIDATION go back (from Ardour's YTK) 2026-10-19 11:30:30 +02:00
0adaec6679
quartz: a view drawn before its window is mapped takes the window's background colour, so that dark themes do not flash light first (from Ardour's YTK) 2026-10-19 11:30:30 +02:00
39940768b5
quartz: a native view of the program inside a GDK window (plugin interface, video, web view) keeps its clicks and drags, which GDK took before (from Ardour's YTK) 2026-10-19 11:30:29 +02:00
60fbffd133
scrolled window: dragging with a finger scrolls, and a swipe goes on, in old programs too (kinetic-scrolling of GTK+ 3); a tap or a resting finger goes to the widgets as before 2026-10-19 11:30:29 +02:00
80ff7532db
win32: touches of Windows 7 and later (WM_TOUCH) for windows with GDK_TOUCH_MASK; the mouse messages Windows makes of a finger are marked as emulated 2026-10-19 11:30:29 +02:00
f33ba1b8f2
gtk: the touch-event signal of GTK+ 3, for widgets whose window asks for GDK_TOUCH_MASK 2026-10-19 11:30:29 +02:00
c0caea027d
gdk: touch events as in GTK+ 3 (GDK_TOUCH_MASK, the touch event types, XInput 2.2 on X11); windows without the mask get the pointer of the first finger, marked as emulated 2026-10-19 11:30:29 +02:00
d35ef12fda
filechooser: Enter in the location entry of a file chooser in a window of the program's own opens the folder or chooses the file (file-activated), where no default button takes it (from Ardour's YTK) 2026-10-19 11:30:29 +02:00
b024119172
GDK_NO_XSETTINGS leaves the settings of the desktop unread, GTK_LOCALEDIR points to the translations of GTK+ (from Ardour's YTK) 2026-10-19 11:30:29 +02:00
2933cdb857
modules: theme engines and input methods are also looked for in /usr/lib/gtk-2.0 where GTK+ is in a multiarch folder, as Debian does 2026-10-19 11:30:29 +02:00
64daa2e278
win32: two casts that newer compilers ask for (from Ardour's YTK) 2026-10-19 11:30:29 +02:00
5ef9c33fcc
recentmanager: the folder of the list is made when it is not there, as on Mac OS X and new accounts, where nothing was saved (from Ardour's YTK) 2026-10-19 11:30:29 +02:00
bcf701c2b9
hsv: the pixels of the color wheel live as long as cairo's surface of them, which cairo-quartz still read after they were freed (from Ardour's YTK) 2026-10-19 11:30:28 +02:00
fed3570d95
quartz: enter and leave events on macOS 13 and newer, a redraw after a window comes back from the Dock, and the 10.4 SDK builds again (from Ardour's YTK) 2026-10-19 11:30:28 +02:00
2bff52b2d3
quartz: full screen of GDK in the full screen of the system no longer throws, a window that a program puts back where it was no longer goes up by the height of the title bar, and the modal hint is kept (from Ardour's YTK) 2026-10-19 11:30:28 +02:00
8d7e09e32e
quartz: the resolution no longer asks for userSpaceScaleFactor where macOS has no such message any more, which threw at start (from Ardour's YTK) 2026-10-19 11:30:28 +02:00
7fdb214b02
entry, text view: the emoji chooser of GTK+ 3.22 with Ctrl+. and Ctrl+; and in the context menu: search in the language of the desktop, the recently used first, one grid drawn only where exposed; the data of GTK+ 3 is installed and mapped when the chooser first opens 2026-10-19 11:30:28 +02:00
f6d9ad543d
entry, text view: placeholder text as in GTK+ 3.2, and the input purpose and hints of GTK+ 3.6 for input methods; a hidden entry tells them it is a password, a spin button that it takes a number 2026-10-19 11:30:28 +02:00
65a408417c
GtkFileChooserNative and GtkNativeDialog with the API of GTK+ 3.20: the file dialog of Windows (IFileDialog, and the common dialogs on XP and ReactOS), of Mac OS X (NSOpenPanel and NSSavePanel from 10.4 on) and of the desktop portal where GTK_USE_PORTAL=1 or in Flatpak, else the GTK+ dialog; Pale Moon uses it with widget.allow-gtk-native-file-chooser; gtk_file_filter_to_gvariant() and _new_from_gvariant() as in 3.22 2026-10-19 11:30:28 +02:00
6e530d1cf2
gdk: GDK_SMOOTH_SCROLL_MASK as in GTK+ 3.4: a window that asks for it gets smooth scroll events with the distance from high resolution wheels and touchpads, and not the whole steps made of them; every other window keeps the steps 2026-10-19 11:30:28 +02:00
d9f1f0748c
gdk: the pixmap behind an expose is made only when a double-buffered widget draws into it, so windows that draw themselves (video players, GL, Pale Moon after an expose) no longer have one the size of the exposed area made and freed in the X server each time 2026-10-19 11:30:28 +02:00
57961c4441
gdk/x11: before the main loop waits, the X connection is no longer read from (twice) when nothing can have come in that the wait would not see; an empty turn of the main loop, of which Pale Moon makes tens of thousands a second, costs a third of what it did 2026-10-19 11:30:28 +02:00
d04fb4cd10
gdk/x11: gdk_window_get_origin() keeps where a native window is until something that can move windows happens (or half a second), instead of asking the X server each time; Pale Moon asked thousands of times a second while the mouse moved 2026-10-19 11:30:27 +02:00
9c1a8b2652
filechooser: thumbnails are shown from the next larger size made smaller with the quick bilinear filter, and one smaller than the icon, of a small picture, is no longer enlarged 2026-10-19 11:30:27 +02:00
ce11158cb1
icontheme: sizes a theme has no picture of are made as Mac OS X does: an SVG is drawn at twice the size, a bitmap is taken from one of twice the size or more where there is one, and both are made smaller with a Lanczos filter instead of the averaging bilinear one 2026-10-19 11:30:27 +02:00
a822ded39c
stock icons: all sizes GTK+ asks for (16, 18, 20, 24, 32, 48) are made from the SVGs as Mac OS X does, drawn at twice the size and made smaller with a Lanczos filter, instead of scaled at run time from the next size there is; an icon of exactly the size wins over one within the threshold 2026-10-19 11:30:27 +02:00
7b4448388b
configure: --enable-win32-time64 builds for 32-bit Windows with a 64-bit time_t, which msvcrt.dll has had since Windows 2000, so also on XP and ReactOS; gtk+-2.0.pc passes it on to the programs, whose time_t must be the same 2026-10-19 11:30:27 +02:00
1c59cdb971
recentmanager: gtk_recent_info_get_added_unix(), _modified_unix(), _visited_unix() and gtk_recent_info_get_application_info_unix(), the times as 64-bit seconds next to the time_t ones, which end in 2038 where time_t has 32 bits 2026-10-19 11:30:27 +02:00
e5425116ec
gdk/directfb: event times from the 64-bit wall clock instead of the GTimeVal, whose glong ends in 2038 on 32-bit systems 2026-10-19 11:30:27 +02:00
f74a593f91
cups: the size of the document to send is taken from the end of the file where fstat() fails, as it does for a file written after 2038 where time_t has 32 bits 2026-10-19 11:30:27 +02:00
d89e5651ec
thumbnails: the device of a FUSE mount is looked up with the 64-bit stat, so a folder changed after 2038 is still known as local 2026-10-19 11:30:27 +02:00
b85626343b
recentmanager: gtk_recent_info_exists() asks whether the file is there instead of for its times, which stat() cannot give for files changed after 2038 where time_t has 32 bits 2026-10-19 11:30:27 +02:00
679dad58ce
search: the simple search walks the folders itself instead of with nftw(), which did not go into folders changed after 2038 where time_t has 32 bits and which Windows does not have, where the search found nothing 2026-10-19 11:30:26 +02:00
0420ad70ab
fileselection: folders are read and recognised by their 64-bit times, so a folder changed after 2038 still opens where time_t has 32 bits 2026-10-19 11:30:26 +02:00
721715ca20
icontheme, gdk: the pause between two looks for changed themes, between two checks for the window manager and between two flushes on Quartz is measured with the monotonic clock 2026-10-19 11:30:26 +02:00
abb3c12457
the time of now for the age of recent items, Today and Yesterday in the file chooser, the day of the calendar and the CUPS print time also after 2038 where time_t has 32 bits, from clock_gettime64 on Linux 2026-10-19 11:30:26 +02:00
abea33b3ee
gtktimeprivate.h: file times as 64-bit seconds where stat() has 32 (statx on Linux, the FILETIME of Windows, the unsigned reading of a 32-bit time elsewhere); rc files, icon themes, the icon cache and gtk-update-icon-cache use them, which after 2038 failed to see changes, gave up the icon cache, or left icons out of it 2026-10-19 11:30:26 +02:00
cf6ff8c484
filechooser: the preview names an image by its format where the system has no name for its file type, instead of showing ".jpg filetype" 2026-10-19 11:30:26 +02:00
7e44fbde30
thumbnails: the Exif orientation of a JPEG is read along with its frame header, so photos also come out upright where the image loader does not report it (as GDI+ under Wine) 2026-10-19 11:30:26 +02:00
80218dd9bd
icontheme: small bitmap icons enlarged by a factor that is not whole, such as 2.5, get pixel blocks all of the same size and only the rest of the factor filtered, instead of blocks alternating between two and three pixels 2026-10-19 11:30:26 +02:00
bbdabcad59
style: the default theme draws arrows, check boxes, radio buttons and expanders with a cairo context clipped only around the area drawn, not with the whole clip of the window 2026-10-19 11:30:26 +02:00
65167e9ba8
gdk: theme engines built outside GTK+ find gdk_cairo_create_in_area_libgtk_only() as type data of GdkDrawable, so that the same engine also loads into other builds of GTK+ 2, where it uses gdk_cairo_create() 2026-10-19 11:30:26 +02:00
b591ae2797
pixbuf engine: the parts of an image are drawn with a cairo context clipped only around them, not with the whole clip of the window, which during an expose was most of the work of a pixmap theme 2026-10-19 11:30:26 +02:00
fe44ec039e
gdkcairo: gdk_cairo_create_in_area_libgtk_only() for the theme engines of GTK+, a cairo context with only the rectangles of the window clip that meet the area drawn, which within that area is the same clip 2026-10-19 11:30:25 +02:00
2b9d739cb0
menus and launching: the time since a submenu opened and the time a program takes to start are measured with the monotonic clock, so setting the clock meanwhile does not shorten or lengthen them 2026-10-19 11:30:25 +02:00
725236c4c2
cups: the time to print at is turned into UTC with the offset of local time from GDateTime, not with time(), which has no answer after 2038 where time_t is 32 bits, and in seconds, so zones with quarter hours, such as Nepal, no longer come out an hour wrong 2026-10-19 11:30:25 +02:00
ec29783922
gdkcolor-x11: the pause between two syncs of a colormap is measured with the monotonic clock, not with time(), which on 32-bit systems stops after 2038 and then let no colormap be synced again 2026-10-19 11:30:25 +02:00
04ab40425e
filechooser: the modification time of a file is read as the 64-bit seconds of GIO, without the GTimeVal fallback for older GLib that ends in 2038 on 32-bit systems and on Windows, and without making a GDateTime for every cell drawn 2026-10-19 11:30:25 +02:00
3c5d8d0ac5
recentchooser: sorting by the time of use compares the 64-bit times instead of returning their difference, which overflowed for items more than 68 years apart and mixed up the order 2026-10-19 11:30:25 +02:00
469caa6587
recentmanager: the age of an item and the clamping by age take the time of now from g_get_real_time(), not from a time_t, which on 32-bit systems ends in 2038, and compare the 64-bit times as they are 2026-10-19 11:30:25 +02:00
7422001fd4
fontsel: the family list is as wide as its widest family again, with the scrollbar below, as with the autosized column of GTK+, but measured in one go, kept for the next font selection with the same fonts, and in slices while idle with thousands of fonts 2026-10-19 11:30:25 +02:00
3fbad76041
filechoosersettings: the name of the settings folder made when it is missing is freed after use, not lost in a second variable of the same name inside the block 2026-10-19 11:30:25 +02:00
dff2bb0eef
gtk-demo: the application window, builder and images demos free their action group, builder with its about dialog, and loaded image, instead of keeping them after each run 2026-10-19 11:30:25 +02:00
430516ae7f
gdkwindow: a new window, not mapped yet, does not have the clip of all its siblings and its parent computed again 2026-10-19 11:30:25 +02:00
a34a0ab004
gdkwindow: a window shown, hidden, raised or lowered in its place has the clip computed again only for the siblings it overlaps, not for all children of its parent 2026-10-19 11:30:24 +02:00
3af8f826d6
sizegroup: a resize asked for in a size group finds the groups of widgets by a flag and marks the visited ones in a set instead of object data, and does not go through the same widgets a second time when all groups are of both modes 2026-10-19 11:30:24 +02:00
3776f89ea4
gdkwindow: showing, moving or restacking an input-only window does not compute the clip of all its siblings and its parent again, which it takes no part in 2026-10-19 11:30:24 +02:00
dc82fc7b01
gtk-demo: the assistant demo forgets its window when it is destroyed, not only when it is closed or cancelled 2026-10-19 11:30:24 +02:00
6a7985ece4
gdkpixmap: making a pixmap from XPM sets the mask to NULL when the image cannot be read, as with a gdk-pixbuf without its XPM loader, instead of leaving the caller's variable as it was 2026-10-19 11:30:24 +02:00
32a3932ecb
rc: the rc sets a widget path, class path or type name matches are kept for the next widgets with the same path until the sets change, instead of matching every pattern of the theme for each widget 2026-10-19 11:30:24 +02:00
cc15589b82
rc: the types named in the class path of a widget are looked up once for all widget_class patterns of a theme, not once per pattern and place 2026-10-19 11:30:24 +02:00
3768153fbb
gtk-demo: the list store demo stops its spinner when its window is destroyed, not only when it is closed, instead of running on a freed model 2026-10-19 11:30:24 +02:00
86f24665ef
entry: which invisible character the font has is found once per style and font map, not by laying out the candidates for every entry at its start and at every new style 2026-10-19 11:30:24 +02:00
8ca795ac37
scale: the size of the value text for the bounds is measured at the size request and kept for the changes of the value, instead of laying out both bounds at each 2026-10-19 11:30:24 +02:00
a623c64741
gtkwidget: where a container without a window draws, with its children, is kept until an allocation, mapping, parent or style changes, so an expose does not walk through all children of each container away from the exposed area 2026-10-19 11:30:23 +02:00
05fb549c65
gdkwindow: drawing with a GC into a window inside the paint of its parent leaves the clip of the window on the GC for the next drawing, instead of taking it off and making it anew each time 2026-10-19 11:30:23 +02:00
4e73f3a53d
x11: flushing a GC does not send again the clip rectangles and the tile origin the X server has from the last flush 2026-10-19 11:30:23 +02:00
b914c7068f
cellrenderertext: the cache of laid out cells finds a text through buckets by its hash and keeps the order of use in a list, instead of comparing with every entry 2026-10-19 11:30:23 +02:00
06aee2698b
textlayout: a text view in which no line wraps does not lay out every line again when its width changes 2026-10-19 11:30:23 +02:00
b71408562d
liststore: comparing two rows does not walk up the tree of the sequence for each row to check that it belongs to the store 2026-10-19 11:30:23 +02:00
2cc62ee220
liststore: sorting by a column with its own comparison reads every value once and compares strings by collation key 2026-10-19 11:30:23 +02:00
e96131d0bf
treedatalist: sorting a store or a sort model by a column with its own comparison reads every value once and compares strings by collation key, instead of reading and collating two values at each comparison 2026-10-19 11:30:23 +02:00
037a75fb54
gdk: text drawn with gdk_draw_layout() is clipped only to the parts of the window clip around it, not to every rectangle of a clip with many 2026-10-19 11:30:23 +02:00
a66814b91b
gdk: a new cairo context for drawing with a GC is not clipped to the window a second time 2026-10-19 11:30:23 +02:00
c0b83eba96
filethumbnail: on Windows, images whose type the registry does not name are known by the extensions gdk-pixbuf reads, and a one-pixel answer of the shell is not taken for a thumbnail 2026-10-19 11:30:23 +02:00
5dfb786724
filechooser: on Windows, Delete moves files to the Recycle Bin through the shell, without the shell's own confirmation box that GLib's call brings up for each file 2026-10-19 11:30:22 +02:00
1bba6211a7
ms-windows engine: get the size of windows and pixmaps without the deprecated call the engine is built without, which newer compilers refuse 2026-10-19 11:30:22 +02:00
73357d22fb
build: no symbol aliases on Windows, where a GLib built with clang reports visibility support although the Windows sources define no aliases 2026-10-19 11:30:22 +02:00
8d260c9f50
pixbuf engine: keep the stretched pieces of theme images that were drawn last, ready for cairo, instead of scaling and converting them for every widget 2026-10-19 11:30:22 +02:00
24dd1ff3d7
icontheme: gtk_icon_theme_load_icon hands out copies of the small icons it loaded last, instead of reading and scaling the file for every row of a list 2026-10-19 11:30:22 +02:00
be75930573
textlayout: keep the laid out lines that were drawn last, not just one, so redrawing and scrolling a text view does not lay out the same lines again 2026-10-19 11:30:22 +02:00
20beff85b8
textbtree: asking whether a character has a tag that is applied nowhere answers at once, without scanning the lines before it 2026-10-19 11:30:22 +02:00
bc155671d4
textview: a buffer without tags does not look up the character under the pointer on every event, as only tags take those events 2026-10-19 11:30:22 +02:00
e6668b4319
textbtree: keep the path from the root on the stack when finding the top or character offset of a line, instead of building a list 2026-10-19 11:30:22 +02:00
d5aa46be1d
liststore, treestore, container: collect values from the argument list in one step, without initializing them first 2026-10-19 11:30:22 +02:00
3124dc081b
gdkevents-x11: look up the atom of a window manager hint once, not once per supported hint 2026-10-19 11:30:21 +02:00
a25586b882
gdkwindow: processing updates with the children walks client side windows without copying and referencing them, as only windows with an impl of their own have updates left 2026-10-19 11:30:21 +02:00
0c8ccbc6e1
container: an expose is not passed on to children outside the exposed area 2026-10-19 11:30:21 +02:00
1ea7f262e9
gdkwindow: an expose leaves out the child windows outside the exposed area before any region work 2026-10-19 11:30:21 +02:00
78d6c37be9
tooltip: the text and icon of a tooltip are cleared only when the query does not set them again, so moving over a widget does not lay out its tooltip text twice per motion 2026-10-19 11:30:21 +02:00
184ccc2b17
spinner: turn only while mapped, so a hidden spinner does not wake the program a dozen times a second 2026-10-19 11:30:21 +02:00
6768dbe3d2
iconview: a row added after the one found last is linked in at once, so filling a view of n rows no longer takes n² steps 2026-10-19 11:30:21 +02:00
4369163fd1
gdkwindow: raising a window that is already on top of its siblings skips the work on visible regions 2026-10-19 11:30:21 +02:00
8d89acbc9a
label: setting the same plain text or markup again does not lay out the label anew or resize the window 2026-10-19 11:30:21 +02:00
e52ee5e8ae
textbtree: in a buffer where no applied tag sets invisible, a character is visible at once, without scanning its tags 2026-10-19 11:30:21 +02:00
7caf2e02b1
treeview: ask the X server for the pointer while drawing only for an expander arrow that is held down, not on every expose with expanders 2026-10-19 11:30:20 +02:00
029cc403c6
gtkicontheme: leave out the directories of a theme that hold no icons, instead of walking them at every lookup 2026-10-19 11:30:20 +02:00
e6fcd0eea9
gail: build ferret, the accessibility explorer, on demand only, and do not install it 2026-10-19 11:30:20 +02:00
25527d924a
gtksettings: the cursor stops blinking after 10 seconds, as in GTK+ 3, so idle programs stay asleep 2026-10-19 11:30:20 +02:00
5992de664d
update-icon-cache: stop on options it cannot read, instead of taking an option for the icon folder, and print messages that do not convert to the locale as they are 2026-10-19 11:30:20 +02:00
06b08cf7cb
headers: the _get_type and _quark functions are no longer marked const, as they register types and newer compilers drop calls made only for that 2026-10-19 11:30:20 +02:00
e81412eee2
gtk: export again the nine marshallers that GTK+ 2.24.32 exported by accident, for programs built against it 2026-10-19 11:30:20 +02:00
e239d77f4b
gdk-win32: wait only for the kinds of input GDK handles, so programs built with newer headers neither spin on Windows 8 nor miss events on XP and 7 2026-10-19 11:30:20 +02:00
5edca821db
icontheme: hand out a copy of the load error, so loading a broken icon twice does not free it twice 2026-10-19 11:30:20 +02:00
28ca11f2d2
dnd: keep the vertical hot spot of the drag icon, not the horizontal one twice, while the default icon is made 2026-10-19 11:30:20 +02:00
3c5749e5c4
linkbutton: free the tooltip texts it looks at 2026-10-19 11:30:19 +02:00
649195ae05
printunixdialog: release the parent folder after asking whether to overwrite a file 2026-10-19 11:30:19 +02:00
4598155941
textbufferserialize: free the list of tags when serializing 2026-10-19 11:30:19 +02:00
24699973c5
clipboard: free the old cached targets before storing new ones 2026-10-19 11:30:19 +02:00
bbcc68ddd8
menushell: free the list of matching keys after a mnemonic in a menu was activated 2026-10-19 11:30:19 +02:00
0e4684bec1
printbackends: a failed write to the output ends the job with an error instead of looping forever 2026-10-19 11:30:19 +02:00
60fc01ff43
colorbutton: hold the button while color-set runs, so a handler that destroys it does not leave it freed under the notifications 2026-10-19 11:30:19 +02:00
a89b3631b5
clipboard: forget the store timeout once it has fired, so it is not removed a second time 2026-10-19 11:30:19 +02:00
ca311b1883
applaunchcontext-x11: a file without a base name, such as a network root, takes its URI as display name instead of crashing 2026-10-19 11:30:19 +02:00
7bf40bbc6f
entrycompletion: a theme that gives the rows no height no longer makes the popup divide by zero 2026-10-19 11:30:19 +02:00
86202a71d3
gdkwindow-x11: a second emulated move or resize while one is going on is ignored instead of hitting an assertion 2026-10-19 11:30:19 +02:00
69c26f8721
gdkdnd-x11: looking up a drag context with another display's context in the list no longer loops forever 2026-10-19 11:30:18 +02:00
777e1ecaed
selection: a request whose requesting window is already gone is ignored instead of crashing 2026-10-19 11:30:18 +02:00
16d7aefbde
textiter: gtk_text_iter_inside_sentence no longer reads before the start of the line's attributes 2026-10-19 11:30:18 +02:00
376beeae9d
textlayout: moving the cursor visually by zero no longer frees a line display that is not there 2026-10-19 11:30:18 +02:00
862bbb61e9
gdkkeys-x11: keep the column of the shift level apart, so later entries of the key type do not read past the key's symbols 2026-10-19 11:30:18 +02:00
4abf46f2bd
gdkasync: a child window that is already gone is skipped when listing children, as was meant, instead of failing the whole list 2026-10-19 11:30:18 +02:00
cf96ee2e02
treestore: reordering the children of a row that has none warns instead of crashing 2026-10-19 11:30:18 +02:00
c06ca43a1c
icontheme: listing the contexts of a theme whose directories have no Context key no longer crashes 2026-10-19 11:30:18 +02:00
f858b2690b
immulticontext: also disconnect the surrounding text handlers from the old input method, which could call into a freed context 2026-10-19 11:30:18 +02:00
c110a4a5c3
recentchooser: dragging recent files no longer asserts, as the list is not a filter model 2026-10-19 11:30:18 +02:00
c335acc270
printer: gtk_enumerate_printers stops when its last backend is gone, instead of using the freed list 2026-10-19 11:30:18 +02:00
d0f4c65e17
textbufferserialize: reject sections whose length is negative or runs past the data, instead of hanging or reading beyond it 2026-10-19 11:30:17 +02:00
07d46a2c76
notebook: a button release on a notebook without pages no longer crashes 2026-10-19 11:30:17 +02:00
7da50ae143
build: drop fallbacks for versions older than the required ones, and say which those are 2026-10-19 11:30:17 +02:00
91725d307b
gtkmodules: use module paths as module directories only from GTK_PATH 2026-10-19 11:30:17 +02:00
e097c0a321
gtk-update-icon-cache: read directories in name order and stat each file once 2026-10-19 11:30:17 +02:00
786452b6d6
gdkscreen-x11: room for all eight visual depths 2026-10-19 11:30:17 +02:00
7970268707
po: "Remember password" translations from GTK+ 3 2026-10-19 11:30:17 +02:00
bf77fb897d
cups: remember job passwords in the keyring, as GTK+ 3 does 2026-10-19 11:30:17 +02:00
a0716f2213
cups: do not leak the password the user typed 2026-10-19 11:30:16 +02:00
733e59b871
gtkfontsel: list the styles of a family together with its preview 2026-10-19 11:30:16 +02:00
69d0ff191b
gtkfontsel: keep the style when choosing another family 2026-10-19 11:30:16 +02:00
b57c271808
gtkfontsel: update the preview after the lists are redrawn 2026-10-19 11:30:16 +02:00
3d0d8c6fad
gtkfontsel: list thousands of fonts quickly 2026-10-19 11:30:16 +02:00
6f334f801a
filechooser: a preferences dialog, with size limits for thumbnails, also for network shares 2026-10-19 11:30:16 +02:00
c2ff30b474
filechooser: use the thumbnails Explorer and Quick Look already have, on Windows and macOS 2026-10-19 11:30:16 +02:00
efdb0098e1
filechooser: use the thumbnails other file managers made, in any size, and check them as GLib does 2026-10-19 11:30:16 +02:00
f8705d4038
quartz: dragging several files to the Finder gives it all of them 2026-10-19 11:30:16 +02:00
d342e73380
filechooser: drag several selected files at once 2026-10-19 11:30:16 +02:00
edcfa22894
filechooser: selected files of the icon view in the order they are shown 2026-10-19 11:30:16 +02:00
21e2004e90
iconview: a double click works after a click on another item 2026-10-19 11:30:15 +02:00
bf41a56254
filechooser: tell network shares from local disks on every system, for thumbnails 2026-10-19 11:30:15 +02:00
bc5e1169b9
filechooser: on the Mac, files go to the trash of the Finder, and Command+Backspace puts them there 2026-10-19 11:30:15 +02:00
40b362303a
filechooser: a preview of its own beside the files, for programs that have none 2026-10-19 11:30:15 +02:00
67a59dd589
filechooser: a compact view, small icons beside the names 2026-10-19 11:30:15 +02:00
90ab7b5049
filechooser: show names that are cut short in a tooltip 2026-10-19 11:30:15 +02:00
75233a7e5f
filechooser: "Visit File" shows a found or recent file in its folder 2026-10-19 11:30:15 +02:00
2abbe2d865
filechooser: move files to the trash with Delete or the context menu 2026-10-19 11:30:15 +02:00
c3651fec43
filechooser: rename a file in place with F2 or the context menu 2026-10-19 11:30:15 +02:00
6c418413d6
filechooser: make thumbnails of images for the icon view, and drop outdated ones 2026-10-19 11:30:15 +02:00
8e80537cd1
quartz: smooth scrolling builds with SDKs older than 10.7 again 2026-10-19 11:30:15 +02:00
06d0c842ff
Smooth scrolls leave the steps of a direction they do not use 2026-10-19 11:30:14 +02:00
d2bd382b15
A scrolled window keeps the wheel while it scrolls 2026-10-19 11:30:14 +02:00
36f1bab5db
Wheel steps glide, and shift with the wheel scrolls sideways 2026-10-19 11:30:14 +02:00
bd5a82428e
Smooth scrolling on Windows and macOS 2026-10-19 11:30:14 +02:00
f50d9b18d6
Smooth scrolling for high resolution wheels and touchpads 2026-10-19 11:30:14 +02:00
e02b716780
gdkrgb: the media instructions of ARMv6, for the Raspberry Pi 1 and Zero 2026-10-19 11:30:14 +02:00
aff0e29467
gdkcairo: without vector units, read and write a pixel as one word, and multiply red and blue together 2026-10-19 11:30:14 +02:00
d08bb11aef
gdkrgb: AVX2 for the loops of four-byte pixels 2026-10-19 11:30:14 +02:00
d52c9cd2b3
gdkrgb: SSSE3 kernels for Atom and Core 2 2026-10-19 11:30:14 +02:00
0e8ad2b09a
gdk: rgbsimdbench checks and times the vector kernels on a machine 2026-10-19 11:30:14 +02:00
038eacde64
gdkrgb: pshufw, pmulhuw and 3DNow! kernels, chosen one by one 2026-10-19 11:30:13 +02:00
7b12e554c8
gdkrgb: vector kernels for 15-bit pixels too 2026-10-19 11:30:13 +02:00
2ef8d35f50
gdkcairo: convert pixbufs for cairo with the vector units too 2026-10-19 11:30:13 +02:00
44a1b0bd38
gdkrgb: NEON for ARMv7 and AArch64 2026-10-19 11:30:13 +02:00
b0938af704
gdkrgb: AltiVec for PowerPC G4 and G5 2026-10-19 11:30:13 +02:00
74b8339ced
gdkrgb: MMX for CPUs without SSE2 2026-10-19 11:30:13 +02:00
daa05081ac
gdkrgb: SSE2 for the busiest loops, chosen at run time 2026-10-19 11:30:13 +02:00
f849f756b2
gtkstyle: check a style property request only before it goes into the cache 2026-10-19 11:30:13 +02:00
b30eb08cc4
gdkcairo: convert a cached theme icon for cairo once, not at every draw 2026-10-19 11:30:13 +02:00
17bfc653f7
gtkwidget: no walk through all children of a widget that covers the exposed region 2026-10-19 11:30:13 +02:00
c8d098e5fb
gdkgc-x11: no XChangeGC when only the origins change 2026-10-19 11:30:13 +02:00
596204312e
gdkregion: intersect with a rectangle without the general band walk 2026-10-19 11:30:12 +02:00
fe26bf13ae
gtkwidget: read the draw border in place instead of copying it at every expose 2026-10-19 11:30:12 +02:00
65a92fda3f
gtkwidget: remember which style property a name stands for 2026-10-19 11:30:12 +02:00
b1d1195416
gtkstyle: draw dotted focus frames by edge instead of dash by dash 2026-10-19 11:30:12 +02:00
d6124dc980
gtkcellrenderertext: lay out the text of a cell once, not at every measure and draw 2026-10-19 11:30:12 +02:00
120c6e5457
gdkpixbuf-drawable: one reader for all visuals and depths, shared with GdkRGB 2026-10-19 11:30:12 +02:00
3d3969ab23
gdk: drop mediaLib, nothing uses it any more 2026-10-19 11:30:12 +02:00
e782c550d5
gdkdrawable-x11: blend with RENDER except where GdkRGB does it better 2026-10-19 11:30:12 +02:00
e9d0d05ce7
gdk: blend pixbufs on TrueColor drawables of any depth in their own format 2026-10-19 11:30:12 +02:00
f35ba2a424
gdkrgb: one conversion engine for all depths, with gdkrgb16.c merged in 2026-10-19 11:30:12 +02:00
02716d0767
gdkimage-x11: 1-bit images use their byte order for the bits too 2026-10-19 11:30:12 +02:00
7fb43ac250
gdkrgb: choose visuals by their color bits, 30-bit ones included 2026-10-19 11:30:11 +02:00
9c57bdb881
gdkrgb: walk the colormap lut lists to their end 2026-10-19 11:30:11 +02:00
1085 changed files with 38367 additions and 9339 deletions

View file

@ -4,8 +4,8 @@ Prerequisites
GTK+ requires the following packages:
- The GLib, Pango, GdkPixbuf, ATK and cairo libraries, available at the same
location as GTK+. GTK+ @GTK_VERSION@ requires at least GLib 2.28.0,
Pango 1.20, GdkPixbuf 2.21.0, ATK 1.29.2 and cairo 1.6.0.
location as GTK+. GTK+ @GTK_VERSION@ requires at least GLib 2.38.0,
Pango 1.22, GdkPixbuf 2.21.0, ATK 1.29.2, cairo 1.6 and FriBidi 0.19.2.
- gobject-introspection 0.9.3 or newer.

View file

@ -150,12 +150,6 @@
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if sys/sysinfo.h is available */
/* #undef HAVE_SYS_SYSINFO_H */
/* Define to 1 if sys/systeminfo.h is available */
/* #undef HAVE_SYS_SYSTEMINFO_H */
/* Define to 1 if you have the <sys/time.h> header file. */
#ifndef _MSC_VER
#define HAVE_SYS_TIME_H 1
@ -280,12 +274,6 @@
/* Whether to load modules via .la files rather than directly */
/* #undef USE_LA_MODULES */
/* Define to 1 if medialib is available and should be used */
/* #undef USE_MEDIALIB */
/* Define to 1 if medialib 2.5 is available */
/* #undef USE_MEDIALIB25 */
/* Define to 1 if XXM is available and should be used */
#ifndef _MSC_VER
# define USE_MMX 1

View file

@ -13,8 +13,8 @@ AC_PREREQ(2.62)
m4_define([gtk_major_version], [2])
m4_define([gtk_minor_version], [24])
m4_define([gtk_micro_version], [33])
m4_define([gtk_interface_age], [33])
m4_define([gtk_micro_version], [34])
m4_define([gtk_interface_age], [34])
m4_define([gtk_binary_age],
[m4_eval(100 * gtk_minor_version + gtk_micro_version)])
m4_define([gtk_version],
@ -32,6 +32,8 @@ m4_define([gtk_api_version], [2.0])
m4_define([gtk_binary_version], [2.10.0])
# required versions of other packages
# What the code needs, no more: newer API is used only where a version
# check allows it (GLib 2.38 for g_file_trash_async)
m4_define([glib_required_version], [2.38.0])
m4_define([pango_required_version], [1.22])
m4_define([atk_required_version], [1.29.2])
@ -250,6 +252,10 @@ AC_ARG_ENABLE(xrandr,
[AS_HELP_STRING([--enable-xrandr],
[support XRandR extension if available [default=yes]])],,
[enable_xrandr="yes"])
AC_ARG_ENABLE(xinput2,
[AS_HELP_STRING([--enable-xinput2],
[smooth scrolling with XInput 2.1 if available [default=yes]])],,
[enable_xinput2="yes"])
AC_ARG_ENABLE(xfixes,
[AS_HELP_STRING([--enable-xfixes],
[support XFixes extension if available [default=yes]])],,
@ -347,6 +353,25 @@ changequote([,])dnl
CPPFLAGS="$CPPFLAGS -DG_DISABLE_SINGLE_INCLUDES -DATK_DISABLE_SINGLE_INCLUDES -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES -DGTK_DISABLE_SINGLE_INCLUDES"
# A 64-bit time_t on 32-bit Windows: msvcrt.dll has had the 64-bit time
# functions since Windows 2000 (so XP and ReactOS have them), but MinGW
# keeps time_t at 32 bits there unless asked. It changes the ABI of the
# time_t functions of GtkRecentInfo, so programs must be built the same
# way; gtk+-2.0.pc passes the flag on. The _unix functions of
# GtkRecentInfo give 64-bit times either way.
AC_ARG_ENABLE(win32-time64,
[AS_HELP_STRING([--enable-win32-time64],
[on 32-bit Windows, build with a 64-bit time_t (changes the ABI of the time_t functions of GtkRecentInfo) [default=no]])],,
[enable_win32_time64=no])
win32_time64_cflags=
if test x"$os_win32" = xyes && test x"$enable_win32_time64" = xyes; then
case "$host" in
x86_64-*|aarch64-*) ;;
*) win32_time64_cflags='-D__MINGW_USE_VC2005_COMPAT'
CFLAGS="$CFLAGS $win32_time64_cflags" ;;
esac
fi
# Ensure MSVC-compatible struct packing convention is used when
# compiling for Win32 with gcc.
# What flag to depends on gcc version: gcc3 uses "-mms-bitfields", while
@ -477,6 +502,100 @@ AC_SUBST(REBUILD)
AC_CHECK_FUNCS(lstat mkstemp flockfile getc_unlocked _getc_nolock)
AC_CHECK_FUNCS(localtime_r)
#
# Vector instructions for GdkRGB. Each instruction set has a file of its
# own, compiled with the flags found here; CPUs without it are told apart
# at run time (getauxval() or elf_aux_info() where cpuid doesn't).
#
AC_CHECK_FUNCS(getauxval elf_aux_info)
dnl GTK_CHECK_SIMD_FLAGS(NAME, FLAGS|OTHER FLAGS, PROLOGUE, BODY):
dnl sets NAME_CFLAGS to the first flags the test compiles with
AC_DEFUN([GTK_CHECK_SIMD_FLAGS],
[AC_MSG_CHECKING([for flags to compile $1 code])
$1_CFLAGS=
gtk_save_CFLAGS="$CFLAGS"
gtk_simd_list='$2'
gtk_save_IFS="$IFS"
IFS='|'
for gtk_simd_flags in $gtk_simd_list; do
IFS="$gtk_save_IFS"
CFLAGS="$gtk_save_CFLAGS $gtk_simd_flags"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[$3]], [[$4]])],
[$1_CFLAGS="$gtk_simd_flags"
break])
done
IFS="$gtk_save_IFS"
CFLAGS="$gtk_save_CFLAGS"
AC_MSG_RESULT([${$1_CFLAGS:-none}])
AC_SUBST($1_CFLAGS)])
MMX_CFLAGS=
SSE2_CFLAGS=
SSSE3_CFLAGS=
AVX2_CFLAGS=
ALTIVEC_CFLAGS=
ARMV6_CFLAGS=
NEON_CFLAGS=
case "$host_cpu" in
i?86|x86_64|amd64)
GTK_CHECK_SIMD_FLAGS([MMX], [-mmmx],
[#include <mmintrin.h>
#ifndef __MMX__
#error no MMX
#endif],
[__m64 v = _mm_setzero_si64 (); v = _mm_mullo_pi16 (v, v); _mm_empty ();])
GTK_CHECK_SIMD_FLAGS([SSE2], [-msse2],
[#include <emmintrin.h>
#ifndef __SSE2__
#error no SSE2
#endif],
[__m128i v = _mm_setzero_si128 (); v = _mm_mullo_epi16 (v, v); (void) v;])
GTK_CHECK_SIMD_FLAGS([SSSE3], [-mssse3],
[#include <tmmintrin.h>
#ifndef __SSSE3__
#error no SSSE3
#endif],
[__m128i v = _mm_setzero_si128 (); v = _mm_shuffle_epi8 (v, v); (void) v;])
dnl not with MinGW: GCC does not align its stack for AVX there (GCC
dnl bug 54412), and unoptimized builds would crash on spills
case "$host_os" in
mingw*|cygwin*) ;;
*)
GTK_CHECK_SIMD_FLAGS([AVX2], [-mavx2],
[#include <immintrin.h>
#ifndef __AVX2__
#error no AVX2
#endif],
[__m256i v = _mm256_setzero_si256 (); v = _mm256_shuffle_epi8 (v, v); (void) v;])
;;
esac
;;
powerpc*|ppc*)
GTK_CHECK_SIMD_FLAGS([ALTIVEC], [-maltivec],
[#include <altivec.h>
#if !defined(__ALTIVEC__) || !defined(__BIG_ENDIAN__)
#error no big endian AltiVec
#endif],
[vector unsigned short v = vec_splats ((unsigned short) 1); v = vec_mladd (v, v, v); (void) v;])
;;
arm*)
dnl the media instructions of ARMv6, for builds for older ARMs too
GTK_CHECK_SIMD_FLAGS([ARMV6], [|-march=armv6],
[#if !defined(__ARM_ARCH_6__) && !(defined(__ARM_ARCH) && __ARM_ARCH >= 6)
#error no ARMv6
#endif],
[unsigned int r, x = 1; __asm__ ("uxtab16 %0, %1, %2, ror #8" : "=r" (r) : "r" (x), "r" (x)); (void) r;])
dnl toolchains for the Raspberry Pi 1 default to ARMv6, which has no NEON
GTK_CHECK_SIMD_FLAGS([NEON], [-mfpu=neon|-march=armv7-a -mfpu=neon],
[#include <arm_neon.h>
#if !defined(__ARM_NEON) && !defined(__ARM_NEON__)
#error no NEON
#endif],
[uint8x8x4_t v = vld4_u8 ((const unsigned char *) 0); (void) v;])
;;
esac
# _NL_TIME_FIRST_WEEKDAY is an enum and not a define
AC_MSG_CHECKING([for _NL_TIME_FIRST_WEEKDAY])
AC_LINK_IFELSE(
@ -958,38 +1077,6 @@ AM_CONDITIONAL(INCLUDE_IM_XIM, [test x"$INCLUDE_xim" = xyes])
AC_HEADER_SYS_WAIT
# Checks to see whether we should include mediaLib
# support.
#
AC_CHECK_HEADER(sys/systeminfo.h,
AC_DEFINE(HAVE_SYS_SYSTEMINFO_H, 1,
[Define to 1 if sys/systeminfo.h is available]))
AC_CHECK_HEADER(sys/sysinfo.h,
AC_DEFINE(HAVE_SYS_SYSINFO_H, 1,
[Define to 1 if sys/sysinfo.h is available]))
AC_MSG_CHECKING(for mediaLib 2.3)
use_mlib25=no
# Check for a mediaLib 2.3 function since that is what the GTK+ mediaLib
# patch requires.
AC_CHECK_LIB(mlib, mlib_ImageSetStruct, use_mlib=yes, use_mlib=no)
if test $use_mlib = yes; then
AC_DEFINE(USE_MEDIALIB, 1,
[Define to 1 if medialib is available and should be used])
MEDIA_LIB=-lmlib
AC_MSG_CHECKING(for mediaLib 2.5)
# Check for a mediaLib 2.5 function since that is what is needed for
# gdk_rgb_convert integration.
AC_CHECK_LIB(mlib, mlib_VideoColorRGBint_to_BGRAint, use_mlib25=yes, use_mlib25=no)
if test $use_mlib25 = yes; then
AC_DEFINE(USE_MEDIALIB25, 1,
[Define to 1 if medialib 2.5 is available])
fi
fi
AM_CONDITIONAL(USE_MEDIALIB, test $use_mlib = yes)
AM_CONDITIONAL(USE_MEDIALIB25, test $use_mlib25 = yes)
dnl Look for a host system's gdk-pixbuf-csource if we are cross-compiling
AM_CONDITIONAL(CROSS_COMPILING, test $cross_compiling = yes)
@ -1274,6 +1361,24 @@ if test "x$gdktarget" = "xx11"; then
AM_CONDITIONAL(XINPUT_XFREE, test x$with_xinput = xxfree || test x$with_xinput = xyes)
# XInput 2.1 has the scroll valuators of high resolution wheels and
# touchpads; it is independent of the XInput 1 devices above
if test "x$enable_xinput2" != "xno" && $PKG_CONFIG --exists "xi >= 1.5" ; then
AC_DEFINE(HAVE_XINPUT2, 1, [Have XInput 2.1 for smooth scrolling])
# libXi 1.8 knows the touchpad gestures of XInput 2.4; whether the
# X server has them is asked at run time
if $PKG_CONFIG --exists "xi >= 1.8" ; then
AC_DEFINE(HAVE_XINPUT2_GESTURES, 1, [Have libXi 1.8 for the touchpad gestures of XInput 2.4])
fi
case " $X_PACKAGES " in
*" xi "*) ;;
*) X_PACKAGES="$X_PACKAGES xi" ;;
esac
fi
# Check for the RANDR extension
if test "x$enable_xrandr" != "xno" && $PKG_CONFIG --exists "xrandr >= 1.2.99" ; then
AC_DEFINE(HAVE_RANDR, 1, [Have the Xrandr extension library])
@ -1478,7 +1583,7 @@ GTK_DEP_LIBS="$GDK_EXTRA_LIBS $GTK_DEP_LIBS_FOR_X `$PKG_CONFIG --libs $PANGO_PAC
GTK_DEP_CFLAGS="`$PKG_CONFIG --cflags gthread-2.0 $GDK_PACKAGES $GTK_PACKAGES` $GDK_EXTRA_CFLAGS $GTK_EXTRA_CFLAGS"
if test x"$os_win32" = xyes; then
GTK_EXTRA_CFLAGS="$msnative_struct"
GTK_EXTRA_CFLAGS="$msnative_struct $win32_time64_cflags"
fi
GLIB_PREFIX="`$PKG_CONFIG --variable=prefix glib-2.0`"

View file

@ -466,6 +466,7 @@ do_appwindow (GtkWidget *do_widget)
g_object_set_data_full (G_OBJECT (window), "ui-manager", merge,
g_object_unref);
gtk_ui_manager_insert_action_group (merge, action_group, 0);
g_object_unref (action_group);
gtk_window_add_accel_group (GTK_WINDOW (window),
gtk_ui_manager_get_accel_group (merge));

View file

@ -194,6 +194,8 @@ do_assistant (GtkWidget *do_widget)
create_page3 (assistant);
create_page4 (assistant);
g_signal_connect (assistant, "destroy",
G_CALLBACK (gtk_widget_destroyed), &assistant);
g_signal_connect (G_OBJECT (assistant), "cancel",
G_CALLBACK (on_assistant_close_cancel), &assistant);
g_signal_connect (G_OBJECT (assistant), "close",

View file

@ -27,6 +27,19 @@ about_activate (GtkAction *action)
gtk_widget_hide (about_dlg);
}
/* the about dialog and the builder go with the window */
static void
window_destroyed (GtkWidget *window,
gpointer user_data)
{
GObject *about_dlg = gtk_builder_get_object (builder, "aboutdialog1");
if (about_dlg)
gtk_widget_destroy (GTK_WIDGET (about_dlg));
g_object_unref (builder);
builder = NULL;
}
GtkWidget *
do_builder (GtkWidget *do_widget)
{
@ -51,6 +64,8 @@ do_builder (GtkWidget *do_widget)
gtk_widget_get_screen (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_signal_connect (window, "destroy",
G_CALLBACK (window_destroyed), NULL);
}
if (!gtk_widget_get_visible (window))

View file

@ -389,6 +389,8 @@ do_images (GtkWidget *do_widget)
}
image = gtk_image_new_from_pixbuf (pixbuf);
if (pixbuf)
g_object_unref (pixbuf);
gtk_container_add (GTK_CONTAINER (frame), image);

View file

@ -216,6 +216,14 @@ window_closed (GtkWidget *widget,
return FALSE;
}
/* destroyed without being closed, the spinner must stop all the same */
static void
window_destroyed (GtkWidget *widget,
gpointer user_data)
{
window_closed (widget, NULL, user_data);
}
GtkWidget *
do_list_store (GtkWidget *do_widget)
{
@ -233,7 +241,7 @@ do_list_store (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "GtkListStore demo");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
G_CALLBACK (window_destroyed), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 8);
vbox = gtk_vbox_new (FALSE, 8);

View file

@ -1174,6 +1174,8 @@ gdk_get_show_events
gdk_set_show_events
gdk_event_set_screen
gdk_event_get_screen
gdk_event_get_scroll_deltas
gdk_event_get_pointer_emulated
<SUBSECTION>
gdk_setting_get

View file

@ -34,13 +34,6 @@ created in grayscale and direct color modes, and the visual is changed
in cases where a "better" visual than the default is available.
</para>
<para>
If GDK is built with the Sun mediaLib library, the GdkRGB functions are
accelerated using mediaLib, which provides hardware acceleration on Intel,
AMD, and Sparc chipsets. If desired, mediaLib support can be turned off
by setting the GDK_DISABLE_MEDIALIB environment variable.
</para>
<example>
<title>A simple example program using GdkRGB</title>
<programlisting>

View file

@ -407,6 +407,33 @@ nevertheless.
</para>
</formalpara>
<formalpara>
<title><envar>GDK_CORE_DEVICE_EVENTS</envar></title>
<para>
If set, GDK does not use XInput 2.1 and scrolls only by whole
wheel steps, as before smooth scrolling.
</para>
</formalpara>
<formalpara>
<title><envar>GDK_DISABLE_SIMD</envar>, <envar>GDK_RGB_SIMD</envar></title>
<para>
GDK converts and blends pixels with the vector instructions of the
CPU where it has them (MMX, the integer part of SSE, 3DNow!, SSE2, SSSE3,
AltiVec, NEON), with the same results as its C code. If
<envar>GDK_DISABLE_SIMD</envar> is set to anything but 0, only the
C code is used. <envar>GDK_RGB_SIMD</envar> chooses by hand, to
compare: <literal>c</literal> for none, the name of an instruction
set for that one, or <literal>kernel=set</literal> for a single
kernel, several separated by commas. The program
<command>rgbsimdbench</command> in the <filename>gdk</filename>
directory of the sources (<literal>make rgbsimdbench</literal>)
lists the kernels and sets and times them on the machine.
</para>
</formalpara>
<formalpara>
<title><envar>XDG_DATA_HOME</envar>, <envar>XDG_DATA_DIRS</envar></title>

View file

@ -22,7 +22,6 @@ EXTRA_DIST += \
gdkkeysyms-update.pl \
gdk.def \
gdkmarshalers.list \
gdkmedialib.h \
gdkwindowimpl.h \
makeenums.pl \
makefile.msc \
@ -51,7 +50,7 @@ endif
# libtool stuff: set version and export symbols for resolving
# since automake doesn't support conditionalized libsomething_la_LDFLAGS
# we use the general approach here
LDADD = \
gdk_ldflags = \
$(GTK_LINK_FLAGS) \
-version-info $(LT_VERSION_INFO) \
-export-dynamic \
@ -59,13 +58,6 @@ LDADD = \
$(no_undefined) \
$(LIBTOOL_EXPORT_OPTIONS)
if USE_MEDIALIB
medialib_sources = \
gdkmedialib.c
else
medialib_sources =
endif
#
# setup source file variables
#
@ -115,11 +107,11 @@ gdk_built_private_headers = \
gdk_private_headers = \
gdkinternals.h \
gdkintl.h \
gdkrgbsimd.h \
gdkpoly-generic.h \
gdkregion-generic.h
gdk_c_sources = \
$(medialib_sources) \
gdk.c \
gdkapplaunchcontext.c \
gdkcairo.c \
@ -145,7 +137,7 @@ gdk_c_sources = \
gdkrectangle.c \
gdkregion-generic.c \
gdkrgb.c \
gdkrgb16.c \
gdkrgbsimd.c \
gdkscreen.c \
gdkselection.c \
gdkvisual.c \
@ -174,22 +166,59 @@ common_sources = \
gdkmarshalers.c \
gdkmarshalers.h
# Vector versions of GdkRGB loops, each built with the flags of its
# instruction set. configure leaves the flags empty where the compiler
# can't do them, and the file then has nothing but an empty function.
noinst_LTLIBRARIES = \
libgdk-rgb-mmx.la \
libgdk-rgb-sse2.la \
libgdk-rgb-ssse3.la \
libgdk-rgb-avx2.la \
libgdk-rgb-altivec.la \
libgdk-rgb-armv6.la \
libgdk-rgb-neon.la
libgdk_rgb_mmx_la_SOURCES = gdkrgb-mmx.c
libgdk_rgb_mmx_la_CFLAGS = $(MMX_CFLAGS)
libgdk_rgb_sse2_la_SOURCES = gdkrgb-sse2.c
libgdk_rgb_sse2_la_CFLAGS = $(SSE2_CFLAGS)
libgdk_rgb_ssse3_la_SOURCES = gdkrgb-ssse3.c
libgdk_rgb_ssse3_la_CFLAGS = $(SSSE3_CFLAGS)
libgdk_rgb_avx2_la_SOURCES = gdkrgb-avx2.c
libgdk_rgb_avx2_la_CFLAGS = $(AVX2_CFLAGS)
libgdk_rgb_altivec_la_SOURCES = gdkrgb-altivec.c
libgdk_rgb_altivec_la_CFLAGS = $(ALTIVEC_CFLAGS)
libgdk_rgb_armv6_la_SOURCES = gdkrgb-armv6.c
libgdk_rgb_armv6_la_CFLAGS = $(ARMV6_CFLAGS)
libgdk_rgb_neon_la_SOURCES = gdkrgb-neon.c
libgdk_rgb_neon_la_CFLAGS = $(NEON_CFLAGS)
gdk_rgb_simd_libs = $(noinst_LTLIBRARIES)
# Checks and times the kernels on this machine against the C code:
# make rgbsimdbench && ./rgbsimdbench
EXTRA_PROGRAMS = rgbsimdbench
rgbsimdbench_SOURCES = rgbsimdbench.c gdkrgbsimd.c
rgbsimdbench_CFLAGS = $(AM_CFLAGS)
rgbsimdbench_LDADD = $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS)
CLEANFILES += rgbsimdbench
libgdk_directfb_2_0_la_SOURCES = $(common_sources)
libgdk_directfb_2_0_la_LIBADD = directfb/libgdk-directfb.la $(GDK_DEP_LIBS)
libgdk_directfb_2_0_la_LDFLAGS = $(LDADD)
libgdk_directfb_2_0_la_LIBADD = directfb/libgdk-directfb.la $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS)
libgdk_directfb_2_0_la_LDFLAGS = $(gdk_ldflags)
libgdk_x11_2_0_la_SOURCES = $(common_sources)
libgdk_x11_2_0_la_LIBADD = x11/libgdk-x11.la $(GDK_DEP_LIBS)
libgdk_x11_2_0_la_LDFLAGS = $(LDADD)
libgdk_x11_2_0_la_LIBADD = x11/libgdk-x11.la $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS)
libgdk_x11_2_0_la_LDFLAGS = $(gdk_ldflags)
libgdk_quartz_2_0_la_SOURCES = $(common_sources) gdkkeynames.c
libgdk_quartz_2_0_la_LIBADD = quartz/libgdk-quartz.la $(GDK_DEP_LIBS)
libgdk_quartz_2_0_la_LDFLAGS = $(LDADD)
libgdk_quartz_2_0_la_LIBADD = quartz/libgdk-quartz.la $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS)
libgdk_quartz_2_0_la_LDFLAGS = $(gdk_ldflags)
libgdk_win32_2_0_la_SOURCES = $(common_sources) gdkkeynames.c
libgdk_win32_2_0_la_LIBADD = win32/libgdk-win32.la $(GDK_DEP_LIBS)
libgdk_win32_2_0_la_DEPENDENCIES = win32/libgdk-win32.la win32/rc/gdk-win32-res.o gdk.def
libgdk_win32_2_0_la_LDFLAGS = -Wl,win32/rc/gdk-win32-res.o -export-symbols $(srcdir)/gdk.def $(LDADD)
libgdk_win32_2_0_la_LIBADD = win32/libgdk-win32.la $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS)
libgdk_win32_2_0_la_DEPENDENCIES = win32/libgdk-win32.la $(gdk_rgb_simd_libs) win32/rc/gdk-win32-res.o gdk.def
libgdk_win32_2_0_la_LDFLAGS = -Wl,win32/rc/gdk-win32-res.o -export-symbols $(srcdir)/gdk.def $(gdk_ldflags)
if HAVE_INTROSPECTION
@ -478,7 +507,7 @@ INTROSPECTION_INTERMEDIATE_ITEMS = \
$(top_builddir)/build/win32/Gdk-2.0.gir.msvc.introspect \
$(top_builddir)/build/win32/Gdk_2_0_gir_list
Gdk_2_0_gir_MSVC_FILES = $(filter-out gdkmedialib.c, $(base_introspection_files))
Gdk_2_0_gir_MSVC_FILES = $(base_introspection_files)
Gdk_2_0_gir_MSVC_EXPORT_PACKAGES = $(Gdk_2_0_gir_EXPORT_PACKAGES)
Gdk_2_0_gir_MSVC_INCLUDE_GIRS = $(Gdk_2_0_gir_INCLUDES)
Gdk_2_0_gir_MSVC_LIBS = gdk-win32-2.0

View file

@ -366,11 +366,9 @@ gdk_event_send_client_message_for_display (GdkDisplay *display,
guint32
gdk_directfb_get_time (void)
{
GTimeVal tv;
g_get_current_time (&tv);
return (guint32) tv.tv_sec * 1000 + tv.tv_usec / 1000;
/* milliseconds of the wall clock, as before, from the 64-bit time
* instead of the GTimeVal whose glong ends in 2038 on 32-bit systems */
return (guint32) (g_get_real_time () / 1000);
}
void

View file

@ -250,5 +250,20 @@ gdk_screen_is_composited (GdkScreen *screen)
return FALSE;
}
/* HiDPI: not scaled by this backend (yet) */
gint
_gdk_windowing_drawable_get_scale (GdkDrawable *drawable)
{
return 1;
}
gint
_gdk_windowing_screen_get_monitor_scale (GdkScreen *screen,
gint monitor_num)
{
return 1;
}
#define __GDK_SCREEN_X11_C__
#include "gdkaliasdef.c"

View file

@ -155,7 +155,7 @@ void gdk_rectangle_union (const GdkRectangle *src1,
const GdkRectangle *src2,
GdkRectangle *dest);
GType gdk_rectangle_get_type (void) G_GNUC_CONST;
GType gdk_rectangle_get_type (void);
#define GDK_TYPE_RECTANGLE (gdk_rectangle_get_type ())

View file

@ -44,11 +44,15 @@ gdk_event_free
gdk_event_get
gdk_event_get_axis
gdk_event_get_coords
gdk_event_get_event_sequence
gdk_event_get_root_coords
gdk_event_get_pointer_emulated
gdk_event_get_touchpad_emulated
gdk_event_get_screen
gdk_event_get_scroll_deltas
gdk_event_get_state
gdk_event_get_time
gdk_event_get_type G_GNUC_CONST
gdk_event_get_type
gdk_event_handler_set
gdk_event_new
gdk_event_peek
@ -186,7 +190,7 @@ gdk_utf8_to_compound_text
#if IN_HEADER(__GDK_PROPERTY_H__)
#if IN_FILE(__GDK_C__)
gdk_atom_get_type G_GNUC_CONST
gdk_atom_get_type
#endif
#endif
@ -229,54 +233,54 @@ gdk_x11_free_text_list
#if IN_HEADER(__GDK_ENUM_TYPES_H__)
#if IN_FILE(__GDK_ENUM_TYPES_C__)
gdk_rgb_dither_get_type G_GNUC_CONST
gdk_drag_protocol_get_type G_GNUC_CONST
gdk_input_source_get_type G_GNUC_CONST
gdk_input_condition_get_type G_GNUC_CONST
gdk_input_mode_get_type G_GNUC_CONST
gdk_axis_use_get_type G_GNUC_CONST
gdk_byte_order_get_type G_GNUC_CONST
gdk_cap_style_get_type G_GNUC_CONST
gdk_crossing_mode_get_type G_GNUC_CONST
gdk_extension_mode_get_type G_GNUC_CONST
gdk_event_mask_get_type G_GNUC_CONST
gdk_event_type_get_type G_GNUC_CONST
gdk_fill_get_type G_GNUC_CONST
gdk_rgb_dither_get_type
gdk_drag_protocol_get_type
gdk_input_source_get_type
gdk_input_condition_get_type
gdk_input_mode_get_type
gdk_axis_use_get_type
gdk_byte_order_get_type
gdk_cap_style_get_type
gdk_crossing_mode_get_type
gdk_extension_mode_get_type
gdk_event_mask_get_type
gdk_event_type_get_type
gdk_fill_get_type
#ifndef GDK_DISABLE_DEPRECATED
gdk_fill_rule_get_type G_GNUC_CONST
gdk_fill_rule_get_type
#endif
gdk_filter_return_get_type G_GNUC_CONST
gdk_function_get_type G_GNUC_CONST
gdk_grab_status_get_type G_GNUC_CONST
gdk_gravity_get_type G_GNUC_CONST
gdk_join_style_get_type G_GNUC_CONST
gdk_line_style_get_type G_GNUC_CONST
gdk_modifier_type_get_type G_GNUC_CONST
gdk_notify_type_get_type G_GNUC_CONST
gdk_overlap_type_get_type G_GNUC_CONST
gdk_owner_change_get_type G_GNUC_CONST
gdk_property_state_get_type G_GNUC_CONST
gdk_prop_mode_get_type G_GNUC_CONST
gdk_scroll_direction_get_type G_GNUC_CONST
gdk_setting_action_get_type G_GNUC_CONST
gdk_status_get_type G_GNUC_CONST
gdk_subwindow_mode_get_type G_GNUC_CONST
gdk_visibility_state_get_type G_GNUC_CONST
gdk_wm_decoration_get_type G_GNUC_CONST
gdk_wm_function_get_type G_GNUC_CONST
gdk_font_type_get_type G_GNUC_CONST
gdk_cursor_type_get_type G_GNUC_CONST
gdk_drag_action_get_type G_GNUC_CONST
gdk_gc_values_mask_get_type G_GNUC_CONST
gdk_window_attributes_type_get_type G_GNUC_CONST
gdk_window_class_get_type G_GNUC_CONST
gdk_window_edge_get_type G_GNUC_CONST
gdk_window_hints_get_type G_GNUC_CONST
gdk_window_state_get_type G_GNUC_CONST
gdk_window_type_get_type G_GNUC_CONST
gdk_window_type_hint_get_type G_GNUC_CONST
gdk_image_type_get_type G_GNUC_CONST
gdk_visual_type_get_type G_GNUC_CONST
gdk_filter_return_get_type
gdk_function_get_type
gdk_grab_status_get_type
gdk_gravity_get_type
gdk_join_style_get_type
gdk_line_style_get_type
gdk_modifier_type_get_type
gdk_notify_type_get_type
gdk_overlap_type_get_type
gdk_owner_change_get_type
gdk_property_state_get_type
gdk_prop_mode_get_type
gdk_scroll_direction_get_type
gdk_setting_action_get_type
gdk_status_get_type
gdk_subwindow_mode_get_type
gdk_visibility_state_get_type
gdk_wm_decoration_get_type
gdk_wm_function_get_type
gdk_font_type_get_type
gdk_cursor_type_get_type
gdk_drag_action_get_type
gdk_gc_values_mask_get_type
gdk_window_attributes_type_get_type
gdk_window_class_get_type
gdk_window_edge_get_type
gdk_window_hints_get_type
gdk_window_state_get_type
gdk_window_type_get_type
gdk_window_type_hint_get_type
gdk_image_type_get_type
gdk_visual_type_get_type
#endif
#endif
@ -285,7 +289,7 @@ gdk_visual_type_get_type G_GNUC_CONST
#ifndef GDK_DISABLE_DEPRECATED
gdk_font_from_description
#endif
gdk_font_get_type G_GNUC_CONST
gdk_font_get_type
gdk_font_ref
gdk_font_unref
#ifndef GDK_DISABLE_DEPRECATED
@ -325,6 +329,7 @@ gdk_fontset_load_for_display
#if IN_HEADER(__GDK_CAIRO_H__)
#if IN_FILE(__GDK_CAIRO_C__)
gdk_cairo_create
gdk_cairo_create_in_area_libgtk_only
gdk_cairo_reset_clip
gdk_cairo_set_source_color
gdk_cairo_set_source_pixbuf
@ -346,7 +351,7 @@ gdk_color_alloc
gdk_color_copy
gdk_color_equal
gdk_color_free
gdk_color_get_type G_GNUC_CONST
gdk_color_get_type
gdk_color_hash
gdk_colormap_alloc_color
gdk_colormap_get_system
@ -363,7 +368,7 @@ gdk_color_to_string
#if IN_HEADER(__GDK_COLOR_H__)
#if IN_FILE(__GDK_COLOR_X11_C__)
gdk_colormap_new
gdk_colormap_get_type G_GNUC_CONST
gdk_colormap_get_type
#ifndef GDK_DISABLE_DEPRECATED
gdk_colormap_change
gdk_colors_alloc
@ -380,7 +385,7 @@ gdk_colormap_get_screen
#if IN_HEADER(__GDK_CURSOR_H__)
#if IN_FILE(__GDK_CURSOR_C__)
gdk_cursor_get_type G_GNUC_CONST
gdk_cursor_get_type
gdk_cursor_get_cursor_type
gdk_cursor_new
gdk_cursor_ref
@ -412,7 +417,7 @@ gdk_device_get_name
gdk_device_get_n_axes
gdk_device_get_n_keys
gdk_device_get_source
gdk_device_get_type G_GNUC_CONST
gdk_device_get_type
gdk_device_set_axis_use
gdk_device_set_key
gdk_device_set_source
@ -458,7 +463,7 @@ gdk_display_close
gdk_display_get_core_pointer
gdk_display_get_event
gdk_display_get_pointer
gdk_display_get_type G_GNUC_CONST
gdk_display_get_type
gdk_display_get_window_at_pointer
gdk_display_is_closed
gdk_display_peek_event
@ -533,7 +538,7 @@ gdk_display_set_double_click_time
#if IN_HEADER(__GDK_DISPLAY_MANAGER_H__)
#if IN_FILE(__GDK_DISPLAY_MANAGER_C__)
gdk_display_manager_get
gdk_display_manager_get_type G_GNUC_CONST
gdk_display_manager_get_type
gdk_display_manager_list_displays
gdk_display_manager_set_default_display
gdk_display_manager_get_default_display
@ -544,7 +549,7 @@ gdk_display_manager_get_default_display
#if IN_FILE(__GDK_DND_X11_C__)
gdk_drag_abort
gdk_drag_begin
gdk_drag_context_get_type G_GNUC_CONST
gdk_drag_context_get_type
#ifndef GDK_DISABLE_DEPRECATED
gdk_drag_context_new
gdk_drag_context_ref
@ -598,7 +603,7 @@ gdk_drawable_get_visual
#endif
gdk_drawable_get_depth
gdk_drawable_get_image
gdk_drawable_get_type G_GNUC_CONST
gdk_drawable_get_type
gdk_drawable_get_visible_region
gdk_drawable_set_colormap
gdk_draw_arc
@ -630,7 +635,7 @@ gdk_draw_layout_with_colors
#if IN_HEADER(__GDK_GC_H__)
#if IN_FILE(__GDK_GC_C__)
gdk_gc_new
gdk_gc_get_type G_GNUC_CONST
gdk_gc_get_type
gdk_gc_new_with_values
#ifndef GDK_DISABLE_DEPRECATED
gdk_gc_ref
@ -672,7 +677,7 @@ gdk_gc_get_screen
#if IN_HEADER(__GDK_PIXMAP_X11_H__)
#if IN_FILE(__GDK_PIXMAP_X11_C__)
#ifdef GDK_WINDOWING_X11
gdk_pixmap_impl_x11_get_type G_GNUC_CONST
gdk_pixmap_impl_x11_get_type
#endif
#endif
#endif
@ -680,7 +685,7 @@ gdk_pixmap_impl_x11_get_type G_GNUC_CONST
#if IN_HEADER(__GDK_WINDOW_X11_H__)
#if IN_FILE(__GDK_WINDOW_X11_C__)
#ifdef GDK_WINDOWING_X11
gdk_window_impl_x11_get_type G_GNUC_CONST
gdk_window_impl_x11_get_type
#endif
#endif
#endif
@ -767,7 +772,7 @@ gdk_window_is_input_only
gdk_window_is_shaped
gdk_window_is_viewable
gdk_window_is_visible
gdk_window_object_get_type G_GNUC_CONST
gdk_window_object_get_type
gdk_window_peek_children
gdk_window_process_all_updates
gdk_window_process_updates
@ -777,6 +782,7 @@ gdk_window_remove_redirection
gdk_window_set_debug_updates
gdk_window_set_user_data
gdk_window_thaw_toplevel_updates_libgtk_only
gdk_window_set_touch_emulation_libgtk_only
gdk_window_thaw_updates
gdk_window_set_composited
gdk_pointer_grab
@ -788,6 +794,7 @@ gdk_window_get_display
gdk_window_get_visual
gdk_window_get_width
gdk_window_get_height
gdk_window_get_scale_factor
#endif
#endif
@ -801,7 +808,7 @@ gdk_offscreen_window_get_embedder
#if IN_HEADER(__GDK_INTERNALS_H__)
#if IN_FILE(__GDK_OFFSCREEN_WINDOW_C__)
gdk_offscreen_window_get_type G_GNUC_CONST
gdk_offscreen_window_get_type
#endif
#endif
@ -892,14 +899,14 @@ gdk_image_new_bitmap
#endif
gdk_image_get_pixel
gdk_image_put_pixel
gdk_image_get_type G_GNUC_CONST
gdk_image_get_type
#endif
#endif
#if IN_HEADER(__GDK_KEYS_H__)
#if IN_FILE(__GDK_KEYS_C__)
gdk_keymap_get_default
gdk_keymap_get_type G_GNUC_CONST
gdk_keymap_get_type
gdk_keyval_is_lower G_GNUC_CONST
gdk_keyval_is_upper G_GNUC_CONST
gdk_keyval_to_lower G_GNUC_CONST
@ -974,7 +981,7 @@ gdk_visual_get_best_with_both
gdk_visual_get_best_with_depth
gdk_visual_get_best_with_type
gdk_visual_get_screen
gdk_visual_get_type G_GNUC_CONST
gdk_visual_get_type
#endif
#endif
@ -999,7 +1006,7 @@ gdk_pango_context_set_colormap
gdk_pango_layout_get_clip_region
gdk_pango_layout_line_get_clip_region
gdk_pango_renderer_get_default
gdk_pango_renderer_get_type G_GNUC_CONST
gdk_pango_renderer_get_type
gdk_pango_renderer_new
gdk_pango_renderer_set_drawable
gdk_pango_renderer_set_gc
@ -1036,7 +1043,7 @@ gdk_pixmap_create_from_xpm
gdk_pixmap_colormap_create_from_xpm_d
gdk_pixmap_create_from_xpm_d
gdk_pixmap_get_size
gdk_pixmap_get_type G_GNUC_CONST
gdk_pixmap_get_type
gdk_pixmap_new
#endif
#endif
@ -1093,7 +1100,7 @@ gdk_region_polygon
#if IN_FILE(__GDK_RGB_C__)
gdk_rgb_cmap_free
gdk_rgb_cmap_copy
gdk_rgb_cmap_get_type G_GNUC_CONST
gdk_rgb_cmap_get_type
gdk_rgb_cmap_new
gdk_rgb_colormap_ditherable
gdk_rgb_ditherable
@ -1119,7 +1126,7 @@ gdk_draw_rgb_image_dithalign
#endif
#if IN_HEADER(__GDK_RGB_H__)
#if IN_FILE(__GDK_RGB16_C__)
#if IN_FILE(__GDK_RGB_C__)
gdk_draw_rgb_48_image
gdk_draw_rgb_48_image_dithalign
gdk_draw_rgbx_64_image
@ -1129,13 +1136,14 @@ gdk_draw_rgbx_64_image_dithalign
#if IN_HEADER(__GDK_SCREEN_H__)
#if IN_FILE(__GDK_SCREEN_C__)
gdk_screen_get_type G_GNUC_CONST
gdk_screen_get_type
gdk_screen_get_monitor_at_point
gdk_screen_get_monitor_at_window
gdk_screen_set_font_options
gdk_screen_get_font_options
gdk_screen_set_resolution
gdk_screen_get_resolution
gdk_screen_get_monitor_scale_factor
#endif
#endif
@ -1302,7 +1310,7 @@ gdk_win32_selection_add_targets
#if IN_HEADER(__GDK_WIN32_H__)
#if IN_FILE(__GDK_KEYS_WIN32_C__)
gdk_win32_keymap_get_type G_GNUC_CONST
gdk_win32_keymap_get_type
gdk_win32_keymap_check_compose
#endif
#endif
@ -1417,7 +1425,7 @@ gdk_xid_table_lookup_for_display
#if IN_HEADER(__GDK_APP_LAUNCH_CONTEXT_H__)
#if IN_FILE(__GDK_APP_LAUNCH_CONTEXT_C__)
gdk_app_launch_context_get_type G_GNUC_CONST
gdk_app_launch_context_get_type
gdk_app_launch_context_new
gdk_app_launch_context_set_display
gdk_app_launch_context_set_screen
@ -1430,7 +1438,7 @@ gdk_app_launch_context_set_icon_name
#if IN_HEADER(__GDK_WINDOW_IMPL_H__)
#if IN_FILE(__GDK_WINDOW_IMPL_C__)
gdk_window_impl_get_type G_GNUC_CONST
gdk_window_impl_get_type
#endif
#endif

View file

@ -17,7 +17,10 @@
* Boston, MA 02111-1307, USA.
*/
#include <string.h>
#include "gdkcairo.h"
#include "gdkrgbsimd.h"
#include "gdkdrawable.h"
#include "gdkinternals.h"
#include "gdkregion-generic.h"
@ -30,6 +33,8 @@ gdk_ensure_surface_flush (gpointer surface)
cairo_surface_destroy (surface);
}
static const cairo_user_data_key_t surface_flush_key;
/**
* gdk_cairo_create:
* @drawable: a #GdkDrawable
@ -50,7 +55,6 @@ gdk_ensure_surface_flush (gpointer surface)
cairo_t *
gdk_cairo_create (GdkDrawable *drawable)
{
static const cairo_user_data_key_t key;
cairo_surface_t *surface;
cairo_t *cr;
@ -67,11 +71,60 @@ gdk_cairo_create (GdkDrawable *drawable)
* on X11 (where flushing is a no-op). For details, see
* https://bugzilla.gnome.org/show_bug.cgi?id=628291
*/
cairo_set_user_data (cr, &key, surface, gdk_ensure_surface_flush);
cairo_set_user_data (cr, &surface_flush_key, surface, gdk_ensure_surface_flush);
return cr;
}
/* gdk_cairo_create() for drawing that stays within @area (in the
* coordinates of @drawable): for a window whose clip has many
* rectangles, only those parts of it within @area make the clip */
cairo_t *
_gdk_cairo_create_in_area (GdkDrawable *drawable,
const GdkRectangle *area)
{
cairo_surface_t *surface;
cairo_t *cr;
if (!GDK_IS_WINDOW (drawable) ||
_gdk_window_get_cairo_clip_n_rects ((GdkWindow *) drawable) <= 2)
return gdk_cairo_create (drawable);
surface = _gdk_drawable_ref_cairo_surface (drawable);
cr = cairo_create (surface);
_gdk_window_set_cairo_clip_in_area ((GdkWindow *) drawable, cr, area);
cairo_set_user_data (cr, &surface_flush_key, surface, gdk_ensure_surface_flush);
return cr;
}
/**
* gdk_cairo_create_in_area_libgtk_only:
* @drawable: a #GdkDrawable
* @area: the area that will be drawn
*
* Like gdk_cairo_create(), for drawing that stays inside @area: of the
* clip of a window only the rectangles meeting @area are given to cairo,
* which within @area is the same clip. Theme engines that clip to the
* area they are given anyway spare cairo the whole clip of the window,
* which during an expose can be many rectangles, for each part they
* draw. Private to GTK+ and its modules.
*
* Return value: A newly created Cairo context. Free with
* cairo_destroy() when you are done drawing.
**/
cairo_t *
gdk_cairo_create_in_area_libgtk_only (GdkDrawable *drawable,
const GdkRectangle *area)
{
g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
if (!area)
return gdk_cairo_create (drawable);
return _gdk_cairo_create_in_area (drawable, area);
}
/**
* gdk_cairo_reset_clip:
* @cr: a #cairo_t
@ -173,24 +226,8 @@ gdk_cairo_region (cairo_t *cr,
boxes[i].y2 - boxes[i].y1);
}
/**
* gdk_cairo_set_source_pixbuf:
* @cr: a #Cairo context
* @pixbuf: a #GdkPixbuf
* @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf
* @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf
*
* Sets the given pixbuf as the source pattern for the Cairo context.
* The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
* so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y
*
* Since: 2.8
**/
void
gdk_cairo_set_source_pixbuf (cairo_t *cr,
const GdkPixbuf *pixbuf,
double pixbuf_x,
double pixbuf_y)
static cairo_surface_t *
gdk_cairo_surface_from_pixbuf (const GdkPixbuf *pixbuf)
{
gint width = gdk_pixbuf_get_width (pixbuf);
gint height = gdk_pixbuf_get_height (pixbuf);
@ -202,6 +239,7 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr,
cairo_format_t format;
cairo_surface_t *surface;
static const cairo_user_data_key_t key;
const GdkRgbSimd *simd = _gdk_rgb_simd_get ();
cairo_status_t status;
int j;
@ -228,52 +266,60 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr,
{
guchar *p = gdk_pixels;
guchar *q = cairo_pixels;
gint done = 0;
/* vector code where there is some, C for the rest of the row */
if (n_channels == 3 && simd->rgb_to_x888)
done = simd->rgb_to_x888 ((guint32 *) q, p, width);
else if (n_channels == 4 && simd->rgba_to_argb)
done = simd->rgba_to_argb ((guint32 *) q, p, width);
p += done * n_channels;
q += done * 4;
/* One word out for each pixel, so that machines without vector
* units, the PowerPC G3 or ARMv5, store once, not three or four
* times; and the unused byte of RGB24 gets a value */
if (n_channels == 3)
{
guchar *end = p + 3 * width;
guchar *end = gdk_pixels + 3 * width;
guint32 *q32 = (guint32 *) q;
while (p < end)
{
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
q[0] = p[2];
q[1] = p[1];
q[2] = p[0];
#else
q[1] = p[0];
q[2] = p[1];
q[3] = p[2];
#endif
p += 3;
q += 4;
}
for (; p < end; p += 3)
*q32++ = 0xff000000 | ((guint32) p[0] << 16) | (p[1] << 8) | p[2];
}
else
{
guchar *end = p + 4 * width;
guint t1,t2,t3;
guchar *end = gdk_pixels + 4 * width;
guint32 *q32 = (guint32 *) q;
#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x80; d = ((t >> 8) + t) >> 8; } G_STMT_END
while (p < end)
/* Red and blue 16 bits apart in one register, multiplied by
* alpha at once: c * a / 255 to the nearest, as
* ((t >> 8) + t) >> 8 with t = c * a + 0x80, which does not
* carry from one into the other. The pixel is read as one word
* as well. */
for (; p < end; p += 4)
{
guint32 w, a, rb, g;
memcpy (&w, p, 4);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
MULT(q[0], p[2], p[3], t1);
MULT(q[1], p[1], p[3], t2);
MULT(q[2], p[0], p[3], t3);
q[3] = p[3];
a = w >> 24;
rb = w & 0x00ff00ff; /* B << 16 | R */
g = (w >> 8) & 0xff;
#else
q[0] = p[3];
MULT(q[1], p[0], p[3], t1);
MULT(q[2], p[1], p[3], t2);
MULT(q[3], p[2], p[3], t3);
a = w & 0xff;
rb = (w >> 8) & 0x00ff00ff; /* R << 16 | B */
g = (w >> 16) & 0xff;
#endif
p += 4;
q += 4;
rb = rb * a + 0x00800080;
rb = ((((rb >> 8) & 0x00ff00ff) + rb) >> 8) & 0x00ff00ff;
g = g * a + 0x80;
g = ((g >> 8) + g) >> 8;
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
rb = (rb << 16) | (rb >> 16); /* R << 16 | B */
#endif
*q32++ = (a << 24) | rb | (g << 8);
}
#undef MULT
}
gdk_pixels += gdk_rowstride;
@ -281,6 +327,104 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr,
}
out:
return surface;
}
/* GTK marks the pixbufs it renders for its icon caches with this,
* as no one may change them; their cairo surface is kept with them,
* so that a cached icon is neither converted nor uploaded again. */
#define PIXBUF_SHARED_KEY "gdk-pixbuf-shared"
static const cairo_user_data_key_t gdk_cairo_hidpi_key;
void
_gdk_cairo_surface_set_hidpi_scale (cairo_surface_t *surface,
gint scale)
{
cairo_surface_set_user_data (surface, &gdk_cairo_hidpi_key,
GINT_TO_POINTER (scale > 1 ? scale : 0), NULL);
}
/**
* gdk_cairo_set_source_pixbuf:
* @cr: a #Cairo context
* @pixbuf: a #GdkPixbuf
* @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf
* @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf
*
* Sets the given pixbuf as the source pattern for the Cairo context.
* The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
* so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y
*
* Since: 2.8
**/
void
gdk_cairo_set_source_pixbuf (cairo_t *cr,
const GdkPixbuf *pixbuf,
double pixbuf_x,
double pixbuf_y)
{
static GQuark quark_shared, quark_surface;
cairo_surface_t *surface;
if (!quark_shared)
{
quark_shared = g_quark_from_static_string (PIXBUF_SHARED_KEY);
quark_surface = g_quark_from_static_string ("gdk-cairo-surface");
}
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0)
{
/* HiDPI: on a surface of the window system with more pixels than
* GDK's, the pixbuf's own picture of that resolution, if it has
* one, else its pixels as sharp blocks (where it is not scaled) */
gdouble sx = 1, sy = 1;
cairo_matrix_t m;
GdkPixbuf *hires;
cairo_surface_get_device_scale (cairo_get_target (cr), &sx, &sy);
if (sx == 1 && sy == 1)
sx = sy = GPOINTER_TO_INT (cairo_surface_get_user_data (cairo_get_target (cr),
&gdk_cairo_hidpi_key));
if (sx > 1 && sx == sy && sx == (gint) sx)
{
hires = _gdk_pixbuf_get_hires ((GdkPixbuf *) pixbuf, (gint) sx);
if (hires)
{
surface = gdk_cairo_surface_from_pixbuf (hires);
cairo_surface_set_device_scale (surface, sx, sy);
cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y);
cairo_surface_destroy (surface);
return;
}
cairo_get_matrix (cr, &m);
if (m.xx == 1 && m.yy == 1 && m.xy == 0 && m.yx == 0)
{
surface = gdk_cairo_surface_from_pixbuf (pixbuf);
cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y);
cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
cairo_surface_destroy (surface);
return;
}
}
}
#endif
if (g_object_get_qdata (G_OBJECT (pixbuf), quark_shared))
{
surface = g_object_get_qdata (G_OBJECT (pixbuf), quark_surface);
if (!surface)
{
surface = gdk_cairo_surface_from_pixbuf (pixbuf);
g_object_set_qdata_full (G_OBJECT (pixbuf), quark_surface, surface,
(GDestroyNotify) cairo_surface_destroy);
}
cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y);
return;
}
surface = gdk_cairo_surface_from_pixbuf (pixbuf);
cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y);
cairo_surface_destroy (surface);
}

View file

@ -31,6 +31,10 @@
G_BEGIN_DECLS
cairo_t *gdk_cairo_create (GdkDrawable *drawable);
/* private, for the theme engines of GTK+ */
cairo_t *gdk_cairo_create_in_area_libgtk_only (GdkDrawable *drawable,
const GdkRectangle *area);
void gdk_cairo_reset_clip (cairo_t *cr,
GdkDrawable *drawable);

View file

@ -86,7 +86,7 @@ struct _GdkColormapClass
};
GType gdk_colormap_get_type (void) G_GNUC_CONST;
GType gdk_colormap_get_type (void);
GdkColormap* gdk_colormap_new (GdkVisual *visual,
gboolean allocate);
@ -140,7 +140,7 @@ gboolean gdk_color_equal (const GdkColor *colora,
const GdkColor *colorb);
gchar * gdk_color_to_string (const GdkColor *color);
GType gdk_color_get_type (void) G_GNUC_CONST;
GType gdk_color_get_type (void);
/* The following functions are deprecated */
#ifndef GDK_DISABLE_DEPRECATED

View file

@ -134,7 +134,7 @@ struct _GdkCursor
/* Cursors
*/
GType gdk_cursor_get_type (void) G_GNUC_CONST;
GType gdk_cursor_get_type (void);
GdkCursor* gdk_cursor_new_for_display (GdkDisplay *display,
GdkCursorType cursor_type);

View file

@ -138,7 +138,7 @@ struct _GdkDisplayPointerHooks
gint *win_y);
};
GType gdk_display_get_type (void) G_GNUC_CONST;
GType gdk_display_get_type (void);
GdkDisplay *gdk_display_open (const gchar *display_name);
const gchar * gdk_display_get_name (GdkDisplay *display);

View file

@ -54,7 +54,7 @@ struct _GdkDisplayManagerClass
GdkDisplay *display);
};
GType gdk_display_manager_get_type (void) G_GNUC_CONST;
GType gdk_display_manager_get_type (void);
GdkDisplayManager *gdk_display_manager_get (void);
GdkDisplay * gdk_display_manager_get_default_display (GdkDisplayManager *display_manager);

View file

@ -103,7 +103,7 @@ struct _GdkDragContextClass {
/* Drag and Drop */
GType gdk_drag_context_get_type (void) G_GNUC_CONST;
GType gdk_drag_context_get_type (void);
#if !defined (GDK_DISABLE_DEPRECATED) || defined (GDK_COMPILATION)
GdkDragContext * gdk_drag_context_new (void);
#endif

View file

@ -84,6 +84,13 @@ gdk_drawable_class_init (GdkDrawableClass *klass)
klass->get_visible_region = gdk_drawable_real_get_visible_region;
klass->draw_pixbuf = gdk_drawable_real_draw_pixbuf;
klass->draw_drawable = gdk_drawable_real_draw_drawable;
/* how theme engines built outside GTK+, which must load into other
* builds of GTK+ 2 too, find gdk_cairo_create_in_area_libgtk_only():
* where this is not set they use gdk_cairo_create() */
g_type_set_qdata (G_TYPE_FROM_CLASS (klass),
g_quark_from_static_string ("gdk-cairo-create-in-area"),
(gpointer) gdk_cairo_create_in_area_libgtk_only);
}
static void
@ -794,12 +801,6 @@ gdk_draw_image (GdkDrawable *drawable,
* On older X servers, rendering pixbufs with an alpha channel involves round
* trips to the X server, and may be somewhat slow.
*
* If GDK is built with the Sun mediaLib library, the gdk_draw_pixbuf
* function is accelerated using mediaLib, which provides hardware
* acceleration on Intel, AMD, and Sparc chipsets. If desired, mediaLib
* support can be turned off by setting the GDK_DISABLE_MEDIALIB environment
* variable.
*
* Since: 2.2
*
* Deprecated: 2.22: Use gdk_cairo_set_source_pixbuf() and cairo_paint() or
@ -948,7 +949,7 @@ real_draw_glyphs (GdkDrawable *drawable,
cairo_t *cr;
cr = gdk_cairo_create (drawable);
_gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable);
_gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable, TRUE);
if (matrix)
{
@ -1078,7 +1079,7 @@ gdk_draw_trapezoids (GdkDrawable *drawable,
g_return_if_fail (n_trapezoids == 0 || trapezoids != NULL);
cr = gdk_cairo_create (drawable);
_gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable);
_gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable, TRUE);
for (i = 0; i < n_trapezoids; i++)
{
@ -1403,174 +1404,62 @@ composite (guchar *src_buf,
}
}
static void
composite_0888 (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
/* Blends @pixbuf over the drawable piece by piece, in the drawable's
* own pixel format. Returns FALSE, having drawn nothing, where GdkRGB
* can't do that (palettes, gray levels, dithering). */
static gboolean
composite_on_images (GdkDrawable *drawable,
GdkDrawable *real_drawable,
GdkGC *gc,
GdkPixbuf *pixbuf,
gint src_x,
gint src_y,
gint dest_x,
gint dest_y,
gint width,
gint height,
GdkRgbDither dither)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
GdkColormap *colormap = gdk_drawable_get_colormap (drawable);
guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
gint rowstride = gdk_pixbuf_get_rowstride (pixbuf);
gint x0, y0;
while (height--)
if (!colormap)
return FALSE;
for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT)
{
gint twidth = width;
guchar *p = src;
guchar *q = dest;
gint height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT);
if (dest_byte_order == GDK_LSB_FIRST)
for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH)
{
while (twidth--)
{
guint t;
gint width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH);
gint xs0, ys0;
GdkImage *image;
t = p[3] * p[2] + (255 - p[3]) * q[0] + 0x80;
q[0] = (t + (t >> 8)) >> 8;
t = p[3] * p[1] + (255 - p[3]) * q[1] + 0x80;
q[1] = (t + (t >> 8)) >> 8;
t = p[3] * p[0] + (255 - p[3]) * q[2] + 0x80;
q[2] = (t + (t >> 8)) >> 8;
p += 4;
q += 4;
}
image = _gdk_image_get_scratch (gdk_drawable_get_screen (drawable),
width1, height1,
gdk_drawable_get_depth (drawable), &xs0, &ys0);
gdk_drawable_copy_to_image (drawable, image,
dest_x + x0, dest_y + y0,
xs0, ys0,
width1, height1);
/* this fails for the first piece or for none */
if (!_gdk_rgb_composite (colormap, image, xs0, ys0, width1, height1,
pixels + (src_y + y0) * rowstride + (src_x + x0) * 4,
rowstride, dither))
return FALSE;
gdk_draw_image (real_drawable, gc, image,
xs0, ys0,
dest_x + x0, dest_y + y0,
width1, height1);
}
else
{
while (twidth--)
{
guint t;
t = p[3] * p[0] + (255 - p[3]) * q[1] + 0x80;
q[1] = (t + (t >> 8)) >> 8;
t = p[3] * p[1] + (255 - p[3]) * q[2] + 0x80;
q[2] = (t + (t >> 8)) >> 8;
t = p[3] * p[2] + (255 - p[3]) * q[3] + 0x80;
q[3] = (t + (t >> 8)) >> 8;
p += 4;
q += 4;
}
}
src += src_rowstride;
dest += dest_rowstride;
}
}
#ifdef USE_MEDIALIB
static void
composite_0888_medialib (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
mlib_image img_src, img_dst;
mlib_ImageSetStruct (&img_dst,
MLIB_BYTE,
4,
width,
height,
dest_rowstride,
dest_buf);
mlib_ImageSetStruct (&img_src,
MLIB_BYTE,
4,
width,
height,
src_rowstride,
src_buf);
if (dest_byte_order == GDK_LSB_FIRST)
mlib_ImageBlendRGBA2BGRA (&img_dst, &img_src);
else
mlib_ImageBlendRGBA2ARGB (&img_dst, &img_src);
}
#endif
static void
composite_565 (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
while (height--)
{
gint twidth = width;
guchar *p = src;
gushort *q = (gushort *)dest;
while (twidth--)
{
guchar a = p[3];
guint tr, tg, tb;
guint tr1, tg1, tb1;
guint tmp = *q;
#if 1
/* This is fast, and corresponds to what composite() above does
* if we converted to 8-bit first.
*/
tr = (tmp & 0xf800);
tr1 = a * p[0] + (255 - a) * ((tr >> 8) + (tr >> 13)) + 0x80;
tg = (tmp & 0x07e0);
tg1 = a * p[1] + (255 - a) * ((tg >> 3) + (tg >> 9)) + 0x80;
tb = (tmp & 0x001f);
tb1 = a * p[2] + (255 - a) * ((tb << 3) + (tb >> 2)) + 0x80;
*q = (((tr1 + (tr1 >> 8)) & 0xf800) |
(((tg1 + (tg1 >> 8)) & 0xfc00) >> 5) |
((tb1 + (tb1 >> 8)) >> 11));
#else
/* This version correspond to the result we get with XRENDER -
* a bit of precision is lost since we convert to 8 bit after premultiplying
* instead of at the end
*/
guint tr2, tg2, tb2;
guint tr3, tg3, tb3;
tr = (tmp & 0xf800);
tr1 = (255 - a) * ((tr >> 8) + (tr >> 13)) + 0x80;
tr2 = a * p[0] + 0x80;
tr3 = ((tr1 + (tr1 >> 8)) >> 8) + ((tr2 + (tr2 >> 8)) >> 8);
tg = (tmp & 0x07e0);
tg1 = (255 - a) * ((tg >> 3) + (tg >> 9)) + 0x80;
tg2 = a * p[0] + 0x80;
tg3 = ((tg1 + (tg1 >> 8)) >> 8) + ((tg2 + (tg2 >> 8)) >> 8);
tb = (tmp & 0x001f);
tb1 = (255 - a) * ((tb << 3) + (tb >> 2)) + 0x80;
tb2 = a * p[0] + 0x80;
tb3 = ((tb1 + (tb1 >> 8)) >> 8) + ((tb2 + (tb2 >> 8)) >> 8);
*q = (((tr3 & 0xf8) << 8) |
((tg3 & 0xfc) << 3) |
((tb3 >> 3)));
#endif
p += 4;
q++;
}
src += src_rowstride;
dest += dest_rowstride;
}
return TRUE;
}
/* Implementation of the old vfunc in terms of the new one
@ -1706,101 +1595,26 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable *drawable,
if (gdk_pixbuf_get_has_alpha (pixbuf))
{
GdkVisual *visual = gdk_drawable_get_visual (drawable);
void (*composite_func) (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height) = NULL;
if (composite_on_images (drawable, real_drawable, gc, pixbuf,
src_x, src_y, dest_x, dest_y, width, height, dither))
return;
/* First we see if we have a visual-specific composition function that can composite
* the pixbuf data directly onto the image
/* Palettes, gray levels, dithering: composite against the
* drawable as 24-bit RGB, and convert back.
*/
if (visual)
{
gint bits_per_pixel = _gdk_windowing_get_bits_for_depth (gdk_drawable_get_display (drawable),
visual->depth);
composited = gdk_pixbuf_get_from_drawable (NULL,
drawable,
NULL,
dest_x, dest_y,
0, 0,
width, height);
if (visual->byte_order == (G_BYTE_ORDER == G_BIG_ENDIAN ? GDK_MSB_FIRST : GDK_LSB_FIRST) &&
visual->depth == 16 &&
visual->red_mask == 0xf800 &&
visual->green_mask == 0x07e0 &&
visual->blue_mask == 0x001f)
composite_func = composite_565;
else if (visual->depth == 24 && bits_per_pixel == 32 &&
visual->red_mask == 0xff0000 &&
visual->green_mask == 0x00ff00 &&
visual->blue_mask == 0x0000ff)
{
#ifdef USE_MEDIALIB
if (_gdk_use_medialib ())
composite_func = composite_0888_medialib;
else
composite_func = composite_0888;
#else
composite_func = composite_0888;
#endif
}
}
/* We can't use our composite func if we are required to dither
*/
if (composite_func && !(dither == GDK_RGB_DITHER_MAX && visual->depth != 24))
{
gint x0, y0;
for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT)
{
gint height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT);
for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH)
{
gint xs0, ys0;
gint width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH);
GdkImage *image = _gdk_image_get_scratch (gdk_drawable_get_screen (drawable),
width1, height1,
gdk_drawable_get_depth (drawable), &xs0, &ys0);
gdk_drawable_copy_to_image (drawable, image,
dest_x + x0, dest_y + y0,
xs0, ys0,
width1, height1);
(*composite_func) (gdk_pixbuf_get_pixels (pixbuf) + (src_y + y0) * gdk_pixbuf_get_rowstride (pixbuf) + (src_x + x0) * 4,
gdk_pixbuf_get_rowstride (pixbuf),
(guchar*)image->mem + ys0 * image->bpl + xs0 * image->bpp,
image->bpl,
visual->byte_order,
width1, height1);
gdk_draw_image (real_drawable, gc, image,
xs0, ys0,
dest_x + x0, dest_y + y0,
width1, height1);
}
}
goto out;
}
else
{
/* No special composition func, convert dest to 24 bit RGB data, composite against
* that, and convert back.
*/
composited = gdk_pixbuf_get_from_drawable (NULL,
drawable,
NULL,
dest_x, dest_y,
0, 0,
width, height);
if (composited)
composite (gdk_pixbuf_get_pixels (pixbuf) + src_y * gdk_pixbuf_get_rowstride (pixbuf) + src_x * 4,
gdk_pixbuf_get_rowstride (pixbuf),
gdk_pixbuf_get_pixels (composited),
gdk_pixbuf_get_rowstride (composited),
width, height);
}
if (composited)
composite (gdk_pixbuf_get_pixels (pixbuf) + src_y * gdk_pixbuf_get_rowstride (pixbuf) + src_x * 4,
gdk_pixbuf_get_rowstride (pixbuf),
gdk_pixbuf_get_pixels (composited),
gdk_pixbuf_get_rowstride (composited),
width, height);
}
if (composited)
@ -1833,7 +1647,6 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable *drawable,
x_dither, y_dither);
}
out:
if (composited)
g_object_unref (composited);
}
@ -1975,5 +1788,30 @@ _gdk_drawable_create_cairo_surface (GdkDrawable *drawable,
}
/* HiDPI: a pixbuf of GTK+ can carry one with as many more pixels as a
* scale (icons of the icon theme and the stock icons do); drawn on a
* drawable of that scale, its pixels are those of the X server */
GdkPixbuf *
_gdk_pixbuf_get_hires (GdkPixbuf *pixbuf,
gint scale)
{
gchar key[32];
GdkPixbuf *hires;
if (scale <= 1)
return NULL;
g_snprintf (key, sizeof key, "gdk-pixbuf-hires-%d", scale);
hires = g_object_get_data (G_OBJECT (pixbuf), key);
if (hires &&
gdk_pixbuf_get_width (hires) == gdk_pixbuf_get_width (pixbuf) * scale &&
gdk_pixbuf_get_height (hires) == gdk_pixbuf_get_height (pixbuf) * scale &&
gdk_pixbuf_get_n_channels (hires) == gdk_pixbuf_get_n_channels (pixbuf) &&
gdk_pixbuf_get_has_alpha (hires) == gdk_pixbuf_get_has_alpha (pixbuf))
return hires;
return NULL;
}
#define __GDK_DRAW_C__
#include "gdkaliasdef.c"

View file

@ -236,7 +236,7 @@ struct _GdkTrapezoid
double y1, x11, x21, y2, x12, x22;
};
GType gdk_drawable_get_type (void) G_GNUC_CONST;
GType gdk_drawable_get_type (void);
/* Manipulation of drawables
*/

View file

@ -17,7 +17,7 @@ G_BEGIN_DECLS
/*** END file-production ***/
/*** BEGIN value-header ***/
GType @enum_name@_get_type (void) G_GNUC_CONST;
GType @enum_name@_get_type (void);
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
/*** END value-header ***/

View file

@ -32,6 +32,10 @@
#include "gdkprivate.h"
#include "gdkalias.h"
/* the touch event of GTK+ 3 fits in the GdkEvent of GTK+ 2, whose size
* is ABI: on LP64 88 bytes, on i386 68, on 32-bit Windows 72 */
G_STATIC_ASSERT (sizeof (GdkEventTouch) <= sizeof (GdkEventCrossing));
/* See gdkprivate.h for why this avoids g_memdup(). */
#if !GLIB_CHECK_VERSION (2, 68, 0)
gpointer
@ -412,6 +416,15 @@ gdk_event_new (GdkEventType type)
new_event->scroll.x_root = 0.;
new_event->scroll.y_root = 0.;
break;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
case GDK_TOUCH_CANCEL:
new_event->touch.x = 0.;
new_event->touch.y = 0.;
new_event->touch.x_root = 0.;
new_event->touch.y_root = 0.;
break;
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
new_event->crossing.x = 0.;
@ -465,6 +478,11 @@ gdk_event_copy (const GdkEvent *event)
GdkEventPrivate *private = (GdkEventPrivate *)event;
new_private->screen = private->screen;
new_private->flags |= private->flags & (GDK_EVENT_POINTER_EMULATED |
GDK_EVENT_TOUCHPAD_EMULATED);
if (event->any.type == GDK_SCROLL &&
event->scroll.direction == GDK_SCROLL_SMOOTH)
new_private->delta = private->delta;
}
switch (event->any.type)
@ -500,6 +518,8 @@ gdk_event_copy (const GdkEvent *event)
break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
if (event->button.axes)
new_event->button.axes = _gdk_memdup2 (event->button.axes,
@ -559,10 +579,13 @@ gdk_event_free (GdkEvent *event)
case GDK_DRAG_STATUS:
case GDK_DROP_START:
case GDK_DROP_FINISHED:
g_object_unref (event->dnd.context);
if (event->dnd.context != NULL)
g_object_unref (event->dnd.context);
break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
g_free (event->button.axes);
break;
@ -615,6 +638,11 @@ gdk_event_get_time (const GdkEvent *event)
return event->button.time;
case GDK_SCROLL:
return event->scroll.time;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
case GDK_TOUCH_CANCEL:
return event->touch.time;
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
return event->key.time;
@ -694,6 +722,12 @@ gdk_event_get_state (const GdkEvent *event,
case GDK_SCROLL:
*state = event->scroll.state;
return TRUE;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
case GDK_TOUCH_CANCEL:
*state = event->touch.state;
return TRUE;
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
*state = event->key.state;
@ -703,8 +737,6 @@ gdk_event_get_state (const GdkEvent *event,
*state = event->crossing.state;
return TRUE;
case GDK_PROPERTY_NOTIFY:
*state = event->property.state;
return TRUE;
case GDK_VISIBILITY_NOTIFY:
case GDK_CLIENT_EVENT:
case GDK_NO_EXPOSE:
@ -776,6 +808,13 @@ gdk_event_get_coords (const GdkEvent *event,
x = event->scroll.x;
y = event->scroll.y;
break;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
case GDK_TOUCH_CANCEL:
x = event->touch.x;
y = event->touch.y;
break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
@ -830,6 +869,13 @@ gdk_event_get_root_coords (const GdkEvent *event,
x = event->scroll.x_root;
y = event->scroll.y_root;
break;
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
case GDK_TOUCH_CANCEL:
x = event->touch.x_root;
y = event->touch.y_root;
break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
@ -1034,6 +1080,354 @@ gdk_event_get_screen (const GdkEvent *event)
return NULL;
}
/**
* gdk_event_get_scroll_deltas:
* @event: a #GdkEvent
* @delta_x: (out): return location for the steps to the right
* @delta_y: (out): return location for the steps down
*
* Gets how far a %GDK_SCROLL_SMOOTH event scrolls, in steps of a
* mouse wheel: high resolution wheels and touchpads give fractions.
* On Quartz, trackpads give pixels, as in GTK+ 3.
* The same movement also arrives as ordinary scroll events, one per
* whole step, which gdk_event_get_pointer_emulated() tells apart.
*
* Return value: %TRUE if @event is a smooth scroll event
*
* Since: 2.24
**/
gboolean
gdk_event_get_scroll_deltas (const GdkEvent *event,
gdouble *delta_x,
gdouble *delta_y)
{
const GdkEventPrivate *private = (const GdkEventPrivate *) event;
if (!event || event->type != GDK_SCROLL ||
event->scroll.direction != GDK_SCROLL_SMOOTH ||
!gdk_event_is_allocated (event))
return FALSE;
if (delta_x)
*delta_x = private->delta.x;
if (delta_y)
*delta_y = private->delta.y;
return TRUE;
}
/**
* gdk_event_get_event_sequence:
* @event: a #GdkEvent
*
* If @event is a touch event, returns the #GdkEventSequence to which
* the event belongs, as in GTK+ 3.4. Otherwise, return %NULL.
*
* Returns: (transfer none): the event sequence that the event belongs to
*
* Since: 2.24
**/
GdkEventSequence *
gdk_event_get_event_sequence (const GdkEvent *event)
{
if (!event)
return NULL;
if (event->type == GDK_TOUCH_BEGIN ||
event->type == GDK_TOUCH_UPDATE ||
event->type == GDK_TOUCH_END ||
event->type == GDK_TOUCH_CANCEL)
return event->touch.sequence;
return NULL;
}
/**
* gdk_event_get_pointer_emulated:
* @event: a #GdkEvent
*
* Tells whether a scroll event of a whole wheel step repeats what a
* %GDK_SCROLL_SMOOTH event has already given; whoever handles the
* smooth events ignores these.
*
* Return value: %TRUE if the event is emulated
*
* Since: 2.24
**/
gboolean
gdk_event_get_pointer_emulated (GdkEvent *event)
{
return event && gdk_event_is_allocated (event) &&
(((GdkEventPrivate *) event)->flags & GDK_EVENT_POINTER_EMULATED) != 0;
}
/**
* gdk_event_get_touchpad_emulated:
* @event: a #GdkEvent
*
* Tells whether @event was made of a gesture on a touchpad, for
* programs that know nothing of those: a pinch arrives as scroll
* events up (larger) and down (smaller) with %GDK_CONTROL_MASK, which
* most programs that zoom take for zooming; a swipe sideways arrives
* as a press and release of button 8 (back, swiping to the right) or
* 9 (forward). GTK+'s own widgets do not scroll on such a pinch.
*
* Return value: %TRUE if the event was made of a touchpad gesture
*
* Since: 2.24
**/
gboolean
gdk_event_get_touchpad_emulated (GdkEvent *event)
{
return event && gdk_event_is_allocated (event) &&
(((GdkEventPrivate *) event)->flags & GDK_EVENT_TOUCHPAD_EMULATED) != 0;
}
/* Touchpad gestures, as Windows hands them to its old programs: a
* pinch is the wheel with Ctrl, one step for each 15 % the fingers
* spread or close (up for larger, as browsers and image programs zoom
* in then); a swipe sideways is the back or forward button. Nothing
* is made unless a gesture comes. */
#define TOUCHPAD_PINCH_STEP 0.14 /* ln 1.15 */
static GdkEvent *
touchpad_event (const GdkEvent *template_event,
GdkEventType type)
{
GdkEvent *event = gdk_event_new (type);
GdkEventPrivate *private = (GdkEventPrivate *) event;
if (type == GDK_SCROLL)
{
event->scroll = template_event->scroll;
event->scroll.type = GDK_SCROLL;
event->scroll.state |= GDK_CONTROL_MASK;
}
else
{
event->button.type = type;
event->button.send_event = template_event->scroll.send_event;
event->button.time = template_event->scroll.time;
event->button.x = template_event->scroll.x;
event->button.y = template_event->scroll.y;
event->button.x_root = template_event->scroll.x_root;
event->button.y_root = template_event->scroll.y_root;
event->button.state = template_event->scroll.state;
event->button.device = template_event->scroll.device;
event->button.axes = NULL;
}
event->any.window = template_event->any.window;
if (event->any.window)
g_object_ref (event->any.window);
if (gdk_event_is_allocated (template_event))
gdk_event_set_screen (event, ((GdkEventPrivate *) template_event)->screen);
private->flags |= GDK_EVENT_TOUCHPAD_EMULATED;
return event;
}
/* The scroll steps of a pinch whose scale changed by @log_scale (its
* logarithm) since the last call; @rest keeps what makes no whole step
* yet, 0 when a pinch begins. @template_event is a scroll event with
* window, time, place, state and device. */
GList *
_gdk_event_touchpad_pinch (const GdkEvent *template_event,
gdouble log_scale,
gdouble *rest)
{
GList *events = NULL;
gint n;
/* turning the other way starts afresh */
if (log_scale * *rest < 0)
*rest = 0;
*rest += log_scale;
n = (gint) CLAMP (*rest / TOUCHPAD_PINCH_STEP, -16, 16);
*rest -= n * TOUCHPAD_PINCH_STEP;
for (; n != 0; n += n > 0 ? -1 : 1)
{
GdkEvent *event = touchpad_event (template_event, GDK_SCROLL);
event->scroll.direction = n > 0 ? GDK_SCROLL_UP : GDK_SCROLL_DOWN;
events = g_list_prepend (events, event);
}
return g_list_reverse (events);
}
/* The press and release of the back button (8) for a swipe of @dx > 0
* (to the right) or the forward button (9) for @dx < 0 */
GList *
_gdk_event_touchpad_swipe (const GdkEvent *template_event,
gdouble dx)
{
GdkEvent *press, *release;
guint button = dx > 0 ? 8 : 9;
if (dx == 0)
return NULL;
press = touchpad_event (template_event, GDK_BUTTON_PRESS);
press->button.button = button;
release = touchpad_event (template_event, GDK_BUTTON_RELEASE);
release->button.button = button;
/* buttons past 5 have no bit in the state */
return g_list_append (g_list_append (NULL, press), release);
}
/* GDK makes smooth scroll events only for GTK+'s event handler, which
* knows who can take them; libgtk leaves it here when it sets it. A
* program with a handler of its own sees what it always saw. */
gboolean
_gdk_event_handler_takes_smooth (void)
{
static GQuark quark;
if (!quark)
quark = g_quark_from_static_string ("gdk-smooth-scroll-handler");
return _gdk_event_func != NULL &&
(gpointer) _gdk_event_func == g_object_get_qdata (G_OBJECT (gdk_display_manager_get ()), quark);
}
/* Whether any window has asked for GDK_SMOOTH_SCROLL_MASK: then smooth
* scroll events are made for other event handlers than that of GTK+
* as well, and gdk_window's event routing gives them only to those
* windows (see _gdk_event_scroll_for_window()) */
static gboolean smooth_scroll_wanted;
void
_gdk_event_note_event_mask (GdkEventMask mask)
{
if (mask & GDK_SMOOTH_SCROLL_MASK)
smooth_scroll_wanted = TRUE;
}
/* Whether smooth scroll events are to be made at all */
gboolean
_gdk_event_smooth_scroll_wanted (void)
{
return smooth_scroll_wanted || _gdk_event_handler_takes_smooth ();
}
/* Whether the scroll event @event goes to @window: a window with
* GDK_SMOOTH_SCROLL_MASK takes the smooth events and not the whole
* steps made of them, others the other way round. The event handler
* of GTK+ gets them all and sorts them out per widget (gtkmain.c),
* as GTK+'s own scrolled windows take smooth events too. */
gboolean
_gdk_event_scroll_for_window (GdkEvent *event,
GdkWindow *window)
{
gboolean smooth_window;
if (event->type != GDK_SCROLL || _gdk_event_handler_takes_smooth ())
return TRUE;
smooth_window = (gdk_window_get_events (window) & GDK_SMOOTH_SCROLL_MASK) != 0;
if (event->scroll.direction == GDK_SCROLL_SMOOTH)
return smooth_window;
return !(smooth_window && gdk_event_get_pointer_emulated (event));
}
void
_gdk_event_set_scroll_deltas (GdkEvent *event,
gdouble delta_x,
gdouble delta_y)
{
GdkEventPrivate *private = (GdkEventPrivate *) event;
event->scroll.direction = GDK_SCROLL_SMOOTH;
private->delta.x = delta_x;
private->delta.y = delta_y;
}
static GdkEvent *
scroll_event_from (GdkEvent **first,
const GdkEvent *template_event)
{
GdkEvent *event = *first ? *first : gdk_event_new (GDK_SCROLL);
*first = NULL;
event->scroll = template_event->scroll;
event->scroll.type = GDK_SCROLL;
return event;
}
/* For backends whose system tells how far to scroll: makes of
* @template_event (a scroll event but for the direction) a smooth
* event of @delta_x, @delta_y if asked and GTK+ takes those, and the
* whole steps of the wheel that @steps_x, @steps_y complete in @rest,
* marked as emulated when the smooth event goes out as well. The
* first event made goes into @first if there is one, the others to
* @append, which takes their references. Returns whether any event
* was made. */
gboolean
_gdk_event_emit_scroll (GdkEvent *first,
const GdkEvent *template_event,
gboolean smooth,
gdouble delta_x,
gdouble delta_y,
gdouble steps_x,
gdouble steps_y,
gdouble rest[2],
void (*append) (GdkEvent *event))
{
static const GdkScrollDirection direction[2][2] = {
{ GDK_SCROLL_LEFT, GDK_SCROLL_RIGHT },
{ GDK_SCROLL_UP, GDK_SCROLL_DOWN }
};
gdouble steps[2];
gboolean made = FALSE;
gint a, n;
steps[0] = steps_x;
steps[1] = steps_y;
if (smooth && (delta_x != 0 || delta_y != 0) && _gdk_event_smooth_scroll_wanted ())
{
gboolean into_first = first != NULL;
GdkEvent *event = scroll_event_from (&first, template_event);
_gdk_event_set_scroll_deltas (event, delta_x, delta_y);
if (!into_first)
append (event);
made = TRUE;
}
else
smooth = FALSE;
for (a = 0; a < 2; a++)
{
/* turning the other way starts afresh */
if (steps[a] * rest[a] < 0)
rest[a] = 0;
rest[a] += steps[a];
n = (gint) CLAMP (rest[a] + (rest[a] > 0 ? 1e-9 : -1e-9), -64, 64);
rest[a] -= n;
for (; n != 0; n += n > 0 ? -1 : 1)
{
gboolean into_first = first != NULL;
GdkEvent *event = scroll_event_from (&first, template_event);
event->scroll.direction = direction[a][n > 0];
if (smooth)
((GdkEventPrivate *) event)->flags |= GDK_EVENT_POINTER_EMULATED;
if (!into_first)
append (event);
made = TRUE;
}
}
return made;
}
/**
* gdk_set_show_events:
* @show_events: %TRUE to output event debugging information.

View file

@ -64,6 +64,8 @@ typedef struct _GdkEventDND GdkEventDND;
typedef struct _GdkEventWindowState GdkEventWindowState;
typedef struct _GdkEventSetting GdkEventSetting;
typedef struct _GdkEventGrabBroken GdkEventGrabBroken;
typedef struct _GdkEventTouch GdkEventTouch;
typedef struct _GdkEventSequence GdkEventSequence;
typedef union _GdkEvent GdkEvent;
@ -152,6 +154,11 @@ typedef enum
GDK_OWNER_CHANGE = 34,
GDK_GRAB_BROKEN = 35,
GDK_DAMAGE = 36,
/* as in GTK+ 3.4, for windows with GDK_TOUCH_MASK */
GDK_TOUCH_BEGIN = 37,
GDK_TOUCH_UPDATE = 38,
GDK_TOUCH_END = 39,
GDK_TOUCH_CANCEL = 40,
GDK_EVENT_LAST /* helper variable for decls */
} GdkEventType;
@ -181,9 +188,25 @@ typedef enum
GDK_PROXIMITY_OUT_MASK = 1 << 19,
GDK_SUBSTRUCTURE_MASK = 1 << 20,
GDK_SCROLL_MASK = 1 << 21,
/* as in GTK+ 3.4: the events of the fingers on a touch screen,
* GDK_TOUCH_BEGIN to GDK_TOUCH_CANCEL; GDK makes pointer events of
* the first finger for the windows that did not ask (see
* gdk_event_get_pointer_emulated()). Not in GDK_ALL_EVENTS_MASK: a
* program that does not ask keeps getting a touch as the pointer. */
GDK_TOUCH_MASK = 1 << 22,
/* as in GTK+ 3.4: %GDK_SCROLL_SMOOTH events with the distance (see
* gdk_event_get_scroll_deltas()), and none of the whole wheel steps
* made of them; not part of GDK_ALL_EVENTS_MASK, which old programs
* use and which keeps the steps for them */
GDK_SMOOTH_SCROLL_MASK = 1 << 23,
GDK_ALL_EVENTS_MASK = 0x3FFFFE
} GdkEventMask;
/* so that programs can ask with #ifdef whether GDK has it (GTK+ 2 from
* gtk2-ng; GTK+ 3 has it from 3.4 on) */
#define GDK_SMOOTH_SCROLL_MASK GDK_SMOOTH_SCROLL_MASK
#define GDK_TOUCH_MASK GDK_TOUCH_MASK
typedef enum
{
GDK_VISIBILITY_UNOBSCURED,
@ -196,7 +219,8 @@ typedef enum
GDK_SCROLL_UP,
GDK_SCROLL_DOWN,
GDK_SCROLL_LEFT,
GDK_SCROLL_RIGHT
GDK_SCROLL_RIGHT,
GDK_SCROLL_SMOOTH
} GdkScrollDirection;
/* Types of enter/leave notifications.
@ -488,6 +512,47 @@ struct _GdkEventDND {
gshort x_root, y_root;
};
/**
* GdkEventTouch:
* @type: the type of the event (%GDK_TOUCH_BEGIN, %GDK_TOUCH_UPDATE,
* %GDK_TOUCH_END, %GDK_TOUCH_CANCEL)
* @window: the window which received the event
* @send_event: %TRUE if the event was sent explicitly
* @time: the time of the event in milliseconds
* @x: the x coordinate of the touch relative to the window
* @y: the y coordinate of the touch relative to the window
* @axes: %NULL
* @state: the modifier keys
* @emulating_pointer: whether the event is the one of the finger that
* also moves the pointer (the first one)
* @sequence: what tells the touches of the fingers apart; the same
* for all events of one finger, from begin to end
* @device: the device where the event originated
* @x_root: the x coordinate of the touch relative to the root of the screen
* @y_root: the y coordinate of the touch relative to the root of the screen
*
* A touch on a touch screen, as in GTK+ 3.4, with the same fields;
* @emulating_pointer comes before @sequence here, so that the event
* fits in the GdkEvent of GTK+ 2.
*
* Since: 2.24
*/
struct _GdkEventTouch
{
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
gdouble x;
gdouble y;
gdouble *axes;
guint state;
gboolean emulating_pointer;
GdkEventSequence *sequence;
GdkDevice *device;
gdouble x_root, y_root;
};
union _GdkEvent
{
GdkEventType type;
@ -511,9 +576,10 @@ union _GdkEvent
GdkEventWindowState window_state;
GdkEventSetting setting;
GdkEventGrabBroken grab_broken;
GdkEventTouch touch;
};
GType gdk_event_get_type (void) G_GNUC_CONST;
GType gdk_event_get_type (void);
gboolean gdk_events_pending (void);
GdkEvent* gdk_event_get (void);
@ -549,6 +615,13 @@ void gdk_event_set_screen (GdkEvent *event,
GdkScreen *screen);
GdkScreen *gdk_event_get_screen (const GdkEvent *event);
gboolean gdk_event_get_scroll_deltas (const GdkEvent *event,
gdouble *delta_x,
gdouble *delta_y);
gboolean gdk_event_get_pointer_emulated (GdkEvent *event);
gboolean gdk_event_get_touchpad_emulated (GdkEvent *event);
GdkEventSequence *gdk_event_get_event_sequence (const GdkEvent *event);
void gdk_set_show_events (gboolean show_events);
gboolean gdk_get_show_events (void);

View file

@ -53,7 +53,7 @@ struct _GdkFont
gint descent;
};
GType gdk_font_get_type (void) G_GNUC_CONST;
GType gdk_font_get_type (void);
GdkFont* gdk_font_ref (GdkFont *font);
void gdk_font_unref (GdkFont *font);

View file

@ -61,6 +61,9 @@ struct _GdkGCPrivate
guint subwindow_mode : 1;
guint fill : 2;
guint exposures : 2;
/* the clip of a window stays on after a drawing, see
* _gdk_gc_set_draw_origins() */
guint drawable_clip_kept : 1;
};
#define GDK_GC_GET_PRIVATE(o) ((GdkGCPrivate *) gdk_gc_get_instance_private (GDK_GC (o)))
@ -758,11 +761,66 @@ _gdk_gc_add_drawable_clip (GdkGC *gc,
priv->region_tag_offset_y = offset_y;
}
/* For drawing to a window inside the paint of a parent: moves the clip
* and tile origins of @gc there for the drawing, and back after it
* (@drawing_done), without taking off the clip of the window that
* _gdk_gc_add_drawable_clip() puts on, as setting the clip origin does.
* That clip is relative to the clip origin of the caller, which these
* moves keep, so the next drawing to the window finds it still in
* place, instead of making it anew and sending it to the X server.
*
* Where a GC is used for drawing directly by the caller, with
* gdk_x11_gc_get_xgc(), the clip of the window is taken off first, as
* it was before. Other backends set the clip of a GC for each drawing
* themselves, from the same region the raw drawing functions use, so
* the clip of the window is taken off after a drawing there. */
void
_gdk_gc_set_draw_origins (GdkGC *gc,
gint clip_x,
gint clip_y,
gint ts_x,
gint ts_y,
gboolean drawing_done)
{
GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
GdkGCValues values;
#ifndef GDK_WINDOWING_X11
if (drawing_done)
{
gdk_gc_set_clip_origin (gc, clip_x, clip_y);
gdk_gc_set_ts_origin (gc, ts_x, ts_y);
return;
}
#endif
priv->drawable_clip_kept = drawing_done && priv->region_tag_applied != 0;
gc->clip_x_origin = values.clip_x_origin = clip_x;
gc->clip_y_origin = values.clip_y_origin = clip_y;
gc->ts_x_origin = values.ts_x_origin = ts_x;
gc->ts_y_origin = values.ts_y_origin = ts_y;
GDK_GC_GET_CLASS (gc)->set_values (gc, &values,
GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN |
GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
}
/* Takes off a clip of a window that _gdk_gc_set_draw_origins() left on */
void
_gdk_gc_remove_kept_drawable_clip (GdkGC *gc)
{
if (GDK_GC_GET_PRIVATE (gc)->drawable_clip_kept)
_gdk_gc_remove_drawable_clip (gc);
}
void
_gdk_gc_remove_drawable_clip (GdkGC *gc)
{
GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc);
priv->drawable_clip_kept = FALSE;
if (priv->region_tag_applied)
{
priv->region_tag_applied = 0;
@ -1194,6 +1252,7 @@ gdk_gc_copy (GdkGC *dst_gc,
dst_priv->clip_region = NULL;
dst_priv->region_tag_applied = src_priv->region_tag_applied;
dst_priv->drawable_clip_kept = src_priv->drawable_clip_kept;
if (dst_priv->old_clip_region)
gdk_region_destroy (dst_priv->old_clip_region);
@ -1453,6 +1512,8 @@ gc_get_background (GdkGC *gc,
* last call to this function
* @target_drawable: The drawable you're drawing in. If passed in
* this is used for client side window clip emulation.
* @cr_is_new: %TRUE if @cr comes straight from gdk_cairo_create()
* on @target_drawable, which has set the window clip already
*
* Set the attributes of a cairo context to match those of a #GdkGC
* as far as possible. Some aspects of a #GdkGC, such as clip masks
@ -1464,7 +1525,8 @@ _gdk_gc_update_context (GdkGC *gc,
const GdkColor *override_foreground,
GdkBitmap *override_stipple,
gboolean gc_changed,
GdkDrawable *target_drawable)
GdkDrawable *target_drawable,
gboolean cr_is_new)
{
GdkGCPrivate *priv;
GdkFill fill;
@ -1570,10 +1632,15 @@ _gdk_gc_update_context (GdkGC *gc,
if (!gc_changed)
return;
cairo_reset_clip (cr);
/* The reset above resets the window clip rect, so we want to re-set that */
if (target_drawable && GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip)
GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip (target_drawable, cr);
/* a new context has the window clip and no other: building the
* window clip again from its region is work for nothing */
if (!cr_is_new)
{
cairo_reset_clip (cr);
/* The reset above resets the window clip rect, so we want to re-set that */
if (target_drawable && GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip)
GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip (target_drawable, cr);
}
if (priv->clip_region)
{

View file

@ -221,7 +221,7 @@ struct _GdkGCClass
#ifndef GDK_DISABLE_DEPRECATED
GType gdk_gc_get_type (void) G_GNUC_CONST;
GType gdk_gc_get_type (void);
GdkGC *gdk_gc_new (GdkDrawable *drawable);
GdkGC *gdk_gc_new_with_values (GdkDrawable *drawable,
GdkGCValues *values,

View file

@ -655,5 +655,66 @@ gdk_image_new (GdkImageType type,
visual, width, height, -1);
}
/**
* _gdk_image_read_row:
* @image: a #GdkImage
* @x: the first pixel
* @y: the row
* @width: how many pixels
* @pixels: where to put the pixel values
*
* Reads pixel values of any number of bits per pixel and either byte
* order; for less than 8 bits, the byte order is the order of the
* pixels in a byte, too.
*/
void
_gdk_image_read_row (GdkImage *image,
gint x,
gint y,
gint width,
guint32 *pixels)
{
const guchar *in = (const guchar *) image->mem + y * image->bpl;
const gboolean msb = image->byte_order == GDK_MSB_FIRST;
const gint bits = image->bits_per_pixel;
gint i;
if (bits < 8)
{
const guint mask = (1 << bits) - 1;
for (i = 0; i < width; i++)
{
const gint bit = (x + i) * bits;
pixels[i] = (in[bit >> 3] >> (msb ? 8 - bits - (bit & 7) : bit & 7)) & mask;
}
return;
}
in += x * (bits / 8);
switch (bits)
{
case 8:
for (i = 0; i < width; i++)
pixels[i] = in[i];
break;
case 16:
for (i = 0; i < width; i++, in += 2)
pixels[i] = msb ? (in[0] << 8) | in[1] : in[0] | (in[1] << 8);
break;
case 24:
for (i = 0; i < width; i++, in += 3)
pixels[i] = msb ? (in[0] << 16) | (in[1] << 8) | in[2]
: in[0] | (in[1] << 8) | (in[2] << 16);
break;
case 32:
for (i = 0; i < width; i++, in += 4)
pixels[i] = msb ? ((guint32) in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3]
: in[0] | (in[1] << 8) | (in[2] << 16) | ((guint32) in[3] << 24);
break;
}
}
#define __GDK_IMAGE_C__
#include "gdkaliasdef.c"

View file

@ -90,7 +90,7 @@ struct _GdkImageClass
GObjectClass parent_class;
};
GType gdk_image_get_type (void) G_GNUC_CONST;
GType gdk_image_get_type (void);
#ifndef GDK_DISABLE_DEPRECATED
GdkImage* gdk_image_new (GdkImageType type,

View file

@ -123,7 +123,7 @@ struct _GdkTimeCoord
gdouble axes[GDK_MAX_TIMECOORD_AXES];
};
GType gdk_device_get_type (void) G_GNUC_CONST;
GType gdk_device_get_type (void);
#ifndef GDK_MULTIHEAD_SAFE
/* Returns a list of GdkDevice * */

View file

@ -33,9 +33,6 @@
#include <gdk/gdktypes.h>
#include <gdk/gdkwindow.h>
#include <gdk/gdkprivate.h>
#ifdef USE_MEDIALIB
#include <gdk/gdkmedialib.h>
#endif
G_BEGIN_DECLS
@ -166,7 +163,19 @@ typedef enum
/* Following flag is set for events on the event queue during
* translation and cleared afterwards.
*/
GDK_EVENT_PENDING = 1 << 0
GDK_EVENT_PENDING = 1 << 0,
/* A scroll event from a wheel step that a smooth scroll event with
* the same time has already given */
GDK_EVENT_POINTER_EMULATED = 1 << 1,
/* A touch for which the window system sends the pointer events of
* the first finger itself (Windows), so GDK need not make them */
GDK_EVENT_TOUCH_SYSTEM_POINTER = 1 << 2,
/* A scroll or button event made of a touchpad gesture for programs
* that know nothing of those (gdk_event_get_touchpad_emulated()) */
GDK_EVENT_TOUCHPAD_EMULATED = 1 << 3
} GdkEventFlags;
struct _GdkEventPrivate
@ -174,7 +183,16 @@ struct _GdkEventPrivate
GdkEvent event;
guint flags;
GdkScreen *screen;
gpointer windowing_data;
#ifdef GDK_WINDOWING_QUARTZ
gpointer windowing_data; /* the NSEvent */
#endif
/* the steps of a GDK_SCROLL_SMOOTH event, where elsewhere a
* windowing_data pointer nobody used was */
struct
{
gfloat x;
gfloat y;
} delta;
};
/* Tracks information about the pointer grab on this display */
@ -291,6 +309,30 @@ extern GdkEventFunc _gdk_event_func; /* Callback for events */
extern gpointer _gdk_event_data;
extern GDestroyNotify _gdk_event_notify;
gboolean _gdk_event_handler_takes_smooth (void);
gboolean _gdk_event_smooth_scroll_wanted (void);
GList *_gdk_event_touchpad_pinch (const GdkEvent *template_event,
gdouble log_scale,
gdouble *rest);
GList *_gdk_event_touchpad_swipe (const GdkEvent *template_event,
gdouble dx);
void _gdk_event_note_event_mask (GdkEventMask mask);
gboolean _gdk_event_scroll_for_window (GdkEvent *event,
GdkWindow *window);
void _gdk_event_set_scroll_deltas (GdkEvent *event,
gdouble delta_x,
gdouble delta_y);
gboolean _gdk_event_emit_scroll (GdkEvent *first,
const GdkEvent *template_event,
gboolean smooth,
gdouble delta_x,
gdouble delta_y,
gdouble steps_x,
gdouble steps_y,
gdouble rest[2],
void (*append) (GdkEvent *event));
extern GSList *_gdk_displays;
extern gchar *_gdk_display_name;
extern gint _gdk_screen_number;
@ -335,6 +377,11 @@ GdkImage* _gdk_image_new_for_depth (GdkScreen *screen,
gint width,
gint height,
gint depth);
void _gdk_image_read_row (GdkImage *image,
gint x,
gint y,
gint width,
guint32 *pixels);
GdkImage *_gdk_image_get_scratch (GdkScreen *screen,
gint width,
gint height,
@ -361,14 +408,36 @@ cairo_surface_t * _gdk_drawable_create_cairo_surface (GdkDrawable *drawable,
/* GC caching */
GdkGC *_gdk_drawable_get_scratch_gc (GdkDrawable *drawable,
gboolean graphics_exposures);
GdkGC *_gdk_drawable_get_subwindow_scratch_gc (GdkDrawable *drawable);
/* GdkRGB */
gboolean _gdk_rgb_composite (GdkColormap *colormap,
GdkImage *image,
gint x0,
gint y0,
gint width,
gint height,
const guchar *rgba,
gint rowstride,
GdkRgbDither dither);
gboolean _gdk_rgb_prefers_own_blending (GdkColormap *colormap,
GdkRgbDither dither);
gint _gdk_window_get_cairo_clip_n_rects (GdkWindow *window);
void _gdk_window_set_cairo_clip_in_area (GdkWindow *window,
cairo_t *cr,
const GdkRectangle *area);
cairo_t *_gdk_cairo_create_in_area (GdkDrawable *drawable,
const GdkRectangle *area);
void _gdk_gc_update_context (GdkGC *gc,
cairo_t *cr,
const GdkColor *override_foreground,
GdkBitmap *override_stipple,
gboolean gc_changed,
GdkDrawable *target_drawable);
GdkDrawable *target_drawable,
gboolean cr_is_new);
/*************************************
* Interfaces used by windowing code *
@ -429,6 +498,13 @@ void _gdk_gc_add_drawable_clip (GdkGC *gc,
int offset_x,
int offset_y);
void _gdk_gc_remove_drawable_clip (GdkGC *gc);
void _gdk_gc_set_draw_origins (GdkGC *gc,
gint clip_x,
gint clip_y,
gint ts_x,
gint ts_y,
gboolean drawing_done);
void _gdk_gc_remove_kept_drawable_clip (GdkGC *gc);
void _gdk_gc_set_clip_region_internal (GdkGC *gc,
GdkRegion *region,
gboolean reset_origin);
@ -538,11 +614,11 @@ struct _GdkPaintableIface
void (* end_paint) (GdkPaintable *paintable);
};
GType _gdk_paintable_get_type (void) G_GNUC_CONST;
GType _gdk_paintable_get_type (void);
/* Implementation types */
GType _gdk_window_impl_get_type (void) G_GNUC_CONST;
GType _gdk_pixmap_impl_get_type (void) G_GNUC_CONST;
GType _gdk_window_impl_get_type (void);
GType _gdk_pixmap_impl_get_type (void);
/**
@ -630,6 +706,24 @@ void _gdk_display_enable_motion_hints (GdkDisplay *display);
void _gdk_window_invalidate_for_expose (GdkWindow *window,
GdkRegion *region);
void _gdk_window_reapply_shapes (GdkWindow *window);
/* HiDPI: how many pixels of the window system make one of GDK in each
* direction, for a drawable (window, pixmap or their implementation) and
* for a monitor (-1: the screen's default); 1 where the backend does not
* scale */
gint _gdk_windowing_drawable_get_scale (GdkDrawable *drawable);
GdkPixbuf *_gdk_pixbuf_get_hires (GdkPixbuf *pixbuf,
gint scale);
gint _gdk_windowing_screen_get_monitor_scale (GdkScreen *screen,
gint monitor_num);
void _gdk_cairo_surface_set_device_offset (cairo_surface_t *surface,
gdouble x,
gdouble y);
/* HiDPI: for surfaces whose window system scales by itself, without a
* device scale of cairo (Quartz): its pixels per pixel of GDK */
void _gdk_cairo_surface_set_hidpi_scale (cairo_surface_t *surface,
gint scale);
void _gdk_windowing_set_cairo_surface_size (cairo_surface_t *surface,
int width,

View file

@ -78,7 +78,7 @@ struct _GdkKeymapClass
void (*state_changed) (GdkKeymap *keymap);
};
GType gdk_keymap_get_type (void) G_GNUC_CONST;
GType gdk_keymap_get_type (void);
#ifndef GDK_MULTIHEAD_SAFE
GdkKeymap* gdk_keymap_get_default (void);

View file

@ -1,120 +0,0 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 2001-2007 Sun Microsystems, Inc. All rights reserved.
* (Brian Cameron, Dmitriy Demin, James Cheng, Padraig O'Briain)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2007. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <stdlib.h>
#include <dlfcn.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#if defined(HAVE_SYS_SYSTEMINFO_H)
#include <sys/systeminfo.h>
#elif defined(HAVE_SYS_SYSINFO_H)
#include <sys/sysinfo.h>
#endif
#include "gdkmedialib.h"
typedef char * (*ml_version) (void);
static ml_version medialib_version = mlib_version;
gboolean
_gdk_use_medialib (void)
{
char *mlib_version_string;
char sys_info[257];
long count;
/*
* Sun mediaLib(tm) support.
*
* http://www.sun.com/processors/vis/mlib.html
*
*/
if (getenv ("GDK_DISABLE_MEDIALIB"))
return FALSE;
/*
* The imaging functions we want to use were added in mediaLib version 2.
* So turn off mediaLib support if the user has an older version.
* mlib_version returns a string in this format:
*
* mediaLib:0210:20011101:v8plusa
* ^^^^^^^^ ^^^^ ^^^^^^^^ ^^^^^^^
* libname vers build ISALIST identifier
* date (in this case sparcv8plus+vis)
*
* The first 2 digits of the version are the major version. The 3rd digit
* is the minor version, and the 4th digit is the micro version. So the
* above string corresponds to version 2.1.0.In the following test we only
* care about the major version.
*/
mlib_version_string = medialib_version ();
count = sysinfo (SI_ARCHITECTURE, &sys_info[0], 257);
if (count != -1)
{
if (strcmp (sys_info, "i386") == 0)
{
char *mlib_target_isa = &mlib_version_string[23];
/*
* For x86 processors mediaLib generic C implementation
* does not give any performance advantage so disable it.
*/
if (strncmp (mlib_target_isa, "sse", 3) != 0)
{
return FALSE;
}
/*
* For x86 processors use of libumem conflicts with
* mediaLib, so avoid using it.
*/
if (dlsym (RTLD_PROBE, "umem_alloc") != NULL)
{
return FALSE;
}
}
}
else
{
/* Failed to get system architecture, disable mediaLib */
return FALSE;
}
return TRUE;
}

View file

@ -59,6 +59,12 @@ struct _GdkPangoRendererPrivate
GdkGC *base_gc;
gboolean gc_changed;
/* what gdk_draw_layout[_line]_with_colors() draws, where, for the
* clip (see get_cairo_context()) */
PangoLayout *area_layout;
PangoLayoutLine *area_line;
gint area_x, area_y;
};
static PangoAttrType gdk_pango_attr_stipple_type;
@ -155,18 +161,62 @@ color_equal (const PangoColor *c1, const PangoColor *c2)
return FALSE;
}
/* Where gdk_draw_layout[_line]_with_colors() draws: the ink and the
* logical extents, with room around for the emboss and for pixels of
* glyphs that antialiasing puts a little outside their ink. Only asked
* for when the clip of the window has more than a few rectangles. */
#define DRAW_AREA_MARGIN 4
static gboolean
get_draw_area (GdkPangoRendererPrivate *priv,
GdkRectangle *area)
{
PangoRectangle ink, logical;
if (priv->area_layout)
pango_layout_get_pixel_extents (priv->area_layout, &ink, &logical);
else if (priv->area_line)
pango_layout_line_get_pixel_extents (priv->area_line, &ink, &logical);
else
return FALSE;
if (ink.width <= 0 || ink.height <= 0)
ink = logical;
area->x = MIN (ink.x, logical.x);
area->y = MIN (ink.y, logical.y);
area->width = MAX (ink.x + ink.width, logical.x + logical.width) - area->x;
area->height = MAX (ink.y + ink.height, logical.y + logical.height) - area->y;
area->x += priv->area_x - DRAW_AREA_MARGIN;
area->y += priv->area_y - DRAW_AREA_MARGIN;
area->width += 2 * DRAW_AREA_MARGIN;
area->height += 2 * DRAW_AREA_MARGIN;
return TRUE;
}
static cairo_t *
get_cairo_context (GdkPangoRenderer *gdk_renderer,
PangoRenderPart part)
{
PangoRenderer *renderer = PANGO_RENDERER (gdk_renderer);
GdkPangoRendererPrivate *priv = gdk_renderer->priv;
gboolean cr_is_new = FALSE;
if (!priv->cr)
{
const PangoMatrix *matrix;
GdkRectangle area;
priv->cr = gdk_cairo_create (priv->drawable);
if ((priv->area_layout || priv->area_line) &&
GDK_IS_WINDOW (priv->drawable) &&
_gdk_window_get_cairo_clip_n_rects ((GdkWindow *) priv->drawable) > 2 &&
get_draw_area (priv, &area))
priv->cr = _gdk_cairo_create_in_area (priv->drawable, &area);
else
priv->cr = gdk_cairo_create (priv->drawable);
cr_is_new = TRUE;
matrix = pango_renderer_get_matrix (renderer);
if (matrix)
@ -216,7 +266,8 @@ get_cairo_context (GdkPangoRenderer *gdk_renderer,
color,
priv->stipple[part],
priv->gc_changed,
priv->drawable);
priv->drawable,
cr_is_new);
}
priv->last_part = part;
@ -839,6 +890,9 @@ release_renderer (PangoRenderer *renderer)
gdk_pango_renderer_set_drawable (gdk_renderer, NULL);
gdk_pango_renderer_set_gc (gdk_renderer, NULL);
gdk_renderer->priv->area_layout = NULL;
gdk_renderer->priv->area_line = NULL;
}
/**
@ -911,7 +965,16 @@ gdk_draw_layout_line_with_colors (GdkDrawable *drawable,
y = 0;
}
else
pango_renderer_set_matrix (renderer, NULL);
{
GdkPangoRendererPrivate *priv = GDK_PANGO_RENDERER (renderer)->priv;
pango_renderer_set_matrix (renderer, NULL);
/* without a matrix, the extents of the line say where it goes */
priv->area_line = line;
priv->area_x = x;
priv->area_y = y;
}
pango_renderer_draw_layout_line (renderer, line, x * PANGO_SCALE, y * PANGO_SCALE);
@ -991,7 +1054,16 @@ gdk_draw_layout_with_colors (GdkDrawable *drawable,
y = 0;
}
else
pango_renderer_set_matrix (renderer, NULL);
{
GdkPangoRendererPrivate *priv = GDK_PANGO_RENDERER (renderer)->priv;
pango_renderer_set_matrix (renderer, NULL);
/* without a matrix, the extents of the layout say where it goes */
priv->area_layout = layout;
priv->area_x = x;
priv->area_y = y;
}
pango_renderer_draw_layout (renderer, layout, x * PANGO_SCALE, y * PANGO_SCALE);

View file

@ -86,7 +86,7 @@ struct _GdkPangoRendererClass
PangoRendererClass parent_class;
};
GType gdk_pango_renderer_get_type (void) G_GNUC_CONST;
GType gdk_pango_renderer_get_type (void);
PangoRenderer *gdk_pango_renderer_new (GdkScreen *screen);
PangoRenderer *gdk_pango_renderer_get_default (GdkScreen *screen);

File diff suppressed because it is too large Load diff

View file

@ -740,6 +740,12 @@ gdk_pixmap_colormap_create_from_xpm (GdkDrawable *drawable,
if (colormap == NULL)
colormap = gdk_drawable_get_colormap (drawable);
/* no mask either if the image cannot be read (gdk-pixbuf may come
* without its XPM loader): callers use it without looking at the
* pixmap first */
if (mask)
*mask = NULL;
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
if (!pixbuf)
return NULL;
@ -823,6 +829,12 @@ gdk_pixmap_colormap_create_from_xpm_d (GdkDrawable *drawable,
if (colormap == NULL)
colormap = gdk_drawable_get_colormap (drawable);
/* no mask either if the image cannot be read (gdk-pixbuf may come
* without its XPM loader): callers use it without looking at the
* pixmap first */
if (mask)
*mask = NULL;
pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **)data);
if (!pixbuf)
return NULL;

View file

@ -62,7 +62,7 @@ struct _GdkPixmapObjectClass
};
GType gdk_pixmap_get_type (void) G_GNUC_CONST;
GType gdk_pixmap_get_type (void);
/* Pixmaps
*/

View file

@ -42,7 +42,7 @@ typedef enum
GDK_PROP_MODE_APPEND
} GdkPropMode;
GType gdk_atom_get_type (void) G_GNUC_CONST;
GType gdk_atom_get_type (void);
GdkAtom gdk_atom_intern (const gchar *atom_name,
gboolean only_if_exists);
GdkAtom gdk_atom_intern_static_string (const gchar *atom_name);

View file

@ -611,6 +611,36 @@ gdk_region_intersect (GdkRegion *source1,
if ((!(source1->numRects)) || (!(source2->numRects)) ||
(!EXTENTCHECK(&source1->extents, &source2->extents)))
source1->numRects = 0;
/* Mostly one of the two is a rectangle: an expose area, a window,
* a clip rectangle. Then a rectangle around the other is the other,
* and two rectangles meet in one. */
else if (source2->numRects == 1 &&
source2->extents.x1 <= source1->extents.x1 &&
source2->extents.y1 <= source1->extents.y1 &&
source2->extents.x2 >= source1->extents.x2 &&
source2->extents.y2 >= source1->extents.y2)
return;
else if (source1->numRects == 1 &&
source1->extents.x1 <= source2->extents.x1 &&
source1->extents.y1 <= source2->extents.y1 &&
source1->extents.x2 >= source2->extents.x2 &&
source1->extents.y2 >= source2->extents.y2)
{
miRegionCopy (source1, source2);
return;
}
else if (source1->numRects == 1 && source2->numRects == 1)
{
GdkRegionBox box;
box.x1 = MAX (source1->extents.x1, source2->extents.x1);
box.y1 = MAX (source1->extents.y1, source2->extents.y1);
box.x2 = MIN (source1->extents.x2, source2->extents.x2);
box.y2 = MIN (source1->extents.y2, source2->extents.y2);
source1->rects[0] = box;
source1->extents = box;
return;
}
else
miRegionOp (source1, source1, source2,
miIntersectO, (nonOverlapFunc) NULL, (nonOverlapFunc) NULL);

433
gdk/gdkrgb-altivec.c Normal file
View file

@ -0,0 +1,433 @@
/* GDK - The GIMP Drawing Kit
* GdkRGB loops for AltiVec (PowerPC G4 and G5)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include "gdkrgbsimd.h"
#if defined(__ALTIVEC__) && defined(__BIG_ENDIAN__)
#include <altivec.h>
/* An x888 pixel is the bytes 0xff, R, G, B; a 565 pixel is a big
* endian 16-bit word. Vector loads and stores need 16-byte aligned
* addresses: loads are put together from two, and each loop starts
* with single pixels until the output is aligned. */
typedef vector unsigned char vu8;
typedef vector unsigned short vu16;
typedef vector unsigned int vu32;
#define VU8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
((vu8) { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p })
/* Reads 16 bytes after 16 bytes from any address, one aligned load
* each; never reads a block that holds none of the bytes asked for.
* Set up only when at least 16 bytes will be read. */
typedef struct
{
const guchar *p;
vu8 perm, last;
gboolean aligned;
} Reader;
static inline void
reader_init (Reader *r, const guchar *p)
{
r->p = p;
r->aligned = ((gsize) p & 15) == 0;
r->perm = vec_lvsl (0, p);
r->last = vec_ld (0, p);
}
static inline vu8
reader_next (Reader *r)
{
vu8 v;
if (r->aligned)
v = vec_ld (0, r->p);
else
{
/* the block of the 16th byte follows the block of the first */
vu8 next = vec_ld (15, r->p);
v = vec_perm (r->last, next, r->perm);
r->last = next;
}
r->p += 16;
return v;
}
static inline gboolean
aligned (const void *p)
{
return ((gsize) p & 15) == 0;
}
static inline guint32
x888 (const guchar *p)
{
return 0xff000000 | (p[0] << 16) | (p[1] << 8) | p[2];
}
static inline guint16
rgb565 (const guchar *p)
{
return ((p[0] & 0xf8) << 8) | ((p[1] & 0xfc) << 3) | (p[2] >> 3);
}
/* with the unused bit set, as all of GdkRGB does */
static inline guint16
rgb555 (const guchar *p)
{
return 0x8000 | ((p[0] & 0xf8) << 7) | ((p[1] & 0xf8) << 2) | (p[2] >> 3);
}
static inline guint
blend8 (guint a, guint s, guint d)
{
guint t = a * s + (255 - a) * d + 0x80;
return (t + (t >> 8)) >> 8;
}
static inline void
composite1_x888 (guint32 *pixel, const guchar *s)
{
guint32 d = *pixel;
if (s[3] != 0)
*pixel = 0xff000000 |
(blend8 (s[3], s[0], (d >> 16) & 0xff) << 16) |
(blend8 (s[3], s[1], (d >> 8) & 0xff) << 8) |
blend8 (s[3], s[2], d & 0xff);
}
static inline void
composite1_565 (guint16 *pixel, const guchar *s)
{
guint d = *pixel, r = d >> 11, g = (d >> 5) & 0x3f, b = d & 0x1f;
r = blend8 (s[3], s[0], (r << 3) | (r >> 2));
g = blend8 (s[3], s[1], (g << 2) | (g >> 4));
b = blend8 (s[3], s[2], (b << 3) | (b >> 2));
*pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
}
static inline void
composite1_555 (guint16 *pixel, const guchar *s)
{
guint d = *pixel, r = (d >> 10) & 0x1f, g = (d >> 5) & 0x1f, b = d & 0x1f;
r = blend8 (s[3], s[0], (r << 3) | (r >> 2));
g = blend8 (s[3], s[1], (g << 3) | (g >> 2));
b = blend8 (s[3], s[2], (b << 3) | (b >> 2));
*pixel = 0x8000 | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
}
/* 0xff in the first byte of each pixel */
static inline vu8
fill_x888 (void)
{
/* -8 shifts by 24 */
return (vu8) vec_sl (vec_splat_u32 (-1), vec_splat_u32 (-8));
}
static gint
rgb_to_x888 (guint32 *out, const guchar *rgb, gint n)
{
const vu8 fill = fill_x888 ();
const vu8 p0 = VU8 (0, 0, 1, 2, 0, 3, 4, 5, 0, 6, 7, 8, 0, 9, 10, 11);
const vu8 p1 = VU8 (0, 12, 13, 14, 0, 15, 16, 17, 0, 18, 19, 20, 0, 21, 22, 23);
const vu8 p2 = VU8 (0, 8, 9, 10, 0, 11, 12, 13, 0, 14, 15, 16, 0, 17, 18, 19);
const vu8 p3 = VU8 (0, 4, 5, 6, 0, 7, 8, 9, 0, 10, 11, 12, 0, 13, 14, 15);
Reader r;
gint i;
for (i = 0; i < n && !aligned (out + i); i++, rgb += 3)
out[i] = x888 (rgb);
if (i + 16 <= n)
reader_init (&r, rgb);
for (; i + 16 <= n; i += 16)
{
vu8 a = reader_next (&r), b = reader_next (&r), c = reader_next (&r);
vec_st (vec_or (vec_perm (a, a, p0), fill), 0, (guchar *) (out + i));
vec_st (vec_or (vec_perm (a, b, p1), fill), 16, (guchar *) (out + i));
vec_st (vec_or (vec_perm (b, c, p2), fill), 32, (guchar *) (out + i));
vec_st (vec_or (vec_perm (c, c, p3), fill), 48, (guchar *) (out + i));
}
return i;
}
static gint
rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n)
{
const vu8 fill = fill_x888 ();
const vu8 p = VU8 (0, 0, 1, 2, 0, 4, 5, 6, 0, 8, 9, 10, 0, 12, 13, 14);
Reader r;
gint i;
for (i = 0; i < n && !aligned (out + i); i++, rgbx += 4)
out[i] = x888 (rgbx);
if (i + 4 <= n)
reader_init (&r, rgbx);
for (; i + 4 <= n; i += 4)
{
vu8 a = reader_next (&r);
vec_st (vec_or (vec_perm (a, a, p), fill), 0, (guchar *) (out + i));
}
return i;
}
/* Bytes of eight RGB pixels as 16-bit lanes, for one channel */
static inline vu16
channel (vu8 a, vu8 b, vu8 p)
{
return vec_and ((vu16) vec_perm (a, b, p), vec_splats ((unsigned short) 0xff));
}
static inline vu16
pack565 (vu16 r, vu16 g, vu16 b)
{
return vec_or (vec_or (vec_sl (vec_and (r, vec_splats ((unsigned short) 0xf8)), vec_splats ((unsigned short) 8)),
vec_sl (vec_and (g, vec_splats ((unsigned short) 0xfc)), vec_splats ((unsigned short) 3))),
vec_sr (b, vec_splats ((unsigned short) 3)));
}
static inline vu16
pack555 (vu16 r, vu16 g, vu16 b)
{
return vec_or (vec_or (vec_sl (vec_and (r, vec_splats ((unsigned short) 0xf8)), vec_splats ((unsigned short) 7)),
vec_sl (vec_and (g, vec_splats ((unsigned short) 0xf8)), vec_splats ((unsigned short) 2))),
vec_or (vec_sr (b, vec_splats ((unsigned short) 3)), vec_splats ((unsigned short) 0x8000)));
}
static inline vu16
pack16 (vu16 r, vu16 g, vu16 b, const gint green_bits)
{
return green_bits == 6 ? pack565 (r, g, b) : pack555 (r, g, b);
}
static inline gint
rgb_to_16 (guint16 *out, const guchar *rgb, gint n, const gint green_bits)
{
/* the channel byte of pixel k in both bytes of lane k */
const vu8 r0 = VU8 (0, 0, 3, 3, 6, 6, 9, 9, 12, 12, 15, 15, 18, 18, 21, 21);
const vu8 g0 = VU8 (1, 1, 4, 4, 7, 7, 10, 10, 13, 13, 16, 16, 19, 19, 22, 22);
const vu8 b0 = VU8 (2, 2, 5, 5, 8, 8, 11, 11, 14, 14, 17, 17, 20, 20, 23, 23);
const vu8 r1 = VU8 (8, 8, 11, 11, 14, 14, 17, 17, 20, 20, 23, 23, 26, 26, 29, 29);
const vu8 g1 = VU8 (9, 9, 12, 12, 15, 15, 18, 18, 21, 21, 24, 24, 27, 27, 30, 30);
const vu8 b1 = VU8 (10, 10, 13, 13, 16, 16, 19, 19, 22, 22, 25, 25, 28, 28, 31, 31);
Reader r;
gint i;
for (i = 0; i < n && !aligned (out + i); i++, rgb += 3)
out[i] = green_bits == 6 ? rgb565 (rgb) : rgb555 (rgb);
if (i + 16 <= n)
reader_init (&r, rgb);
for (; i + 16 <= n; i += 16)
{
vu8 a = reader_next (&r), b = reader_next (&r), c = reader_next (&r);
vec_st (pack16 (channel (a, b, r0), channel (a, b, g0), channel (a, b, b0), green_bits), 0, out + i);
vec_st (pack16 (channel (b, c, r1), channel (b, c, g1), channel (b, c, b1), green_bits), 0, out + i + 8);
}
return i;
}
static gint
rgb_to_565 (guint16 *out, const guchar *rgb, gint n)
{
return rgb_to_16 (out, rgb, n, 6);
}
static gint
rgb_to_555 (guint16 *out, const guchar *rgb, gint n)
{
return rgb_to_16 (out, rgb, n, 5);
}
/* (a * s + (255 - a) * d) / 255, rounded, in 16-bit lanes */
static inline vu16
blend (vu16 t)
{
t = vec_add (t, vec_splats ((unsigned short) 0x80));
return vec_sr (vec_add (t, vec_sr (t, vec_splats ((unsigned short) 8))),
vec_splats ((unsigned short) 8));
}
static gint
composite_x888 (guint32 *pixels, const guchar *rgba, gint n)
{
const vu8 fill = fill_x888 ();
const vu8 argb = VU8 (3, 0, 1, 2, 7, 4, 5, 6, 11, 8, 9, 10, 15, 12, 13, 14);
const vu8 alpha = VU8 (3, 3, 3, 3, 7, 7, 7, 7, 11, 11, 11, 11, 15, 15, 15, 15);
const vu8 merge = VU8 (1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31);
Reader r;
gint i;
for (i = 0; i < n && !aligned (pixels + i); i++, rgba += 4)
composite1_x888 (pixels + i, rgba);
if (i + 4 <= n)
reader_init (&r, rgba);
for (; i + 4 <= n; i += 4)
{
vu8 s = reader_next (&r);
vu8 d = vec_ld (0, (guchar *) (pixels + i));
vu8 a = vec_perm (s, s, alpha);
vu8 inv = vec_nor (a, a);
vu16 even, odd;
vu8 v;
s = vec_perm (s, s, argb);
even = blend (vec_add (vec_mule (s, a), vec_mule (d, inv)));
odd = blend (vec_add (vec_mulo (s, a), vec_mulo (d, inv)));
v = vec_or (vec_perm ((vu8) even, (vu8) odd, merge), fill);
/* fully transparent pixels stay as they are */
vec_st (vec_sel (v, d, vec_cmpeq (a, vec_splat_u8 (0))), 0, (guchar *) (pixels + i));
}
return i;
}
static inline gint
composite_16 (guint16 *pixels, const guchar *rgba, gint n, const gint green_bits)
{
const vu8 pr = VU8 (0, 0, 4, 4, 8, 8, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28);
const vu8 pg = VU8 (1, 1, 5, 5, 9, 9, 13, 13, 17, 17, 21, 21, 25, 25, 29, 29);
const vu8 pb = VU8 (2, 2, 6, 6, 10, 10, 14, 14, 18, 18, 22, 22, 26, 26, 30, 30);
const vu8 pa = VU8 (3, 3, 7, 7, 11, 11, 15, 15, 19, 19, 23, 23, 27, 27, 31, 31);
const vu16 c255 = vec_splats ((unsigned short) 255);
Reader r;
gint i;
for (i = 0; i < n && !aligned (pixels + i); i++, rgba += 4)
if (rgba[3] != 0)
{
if (green_bits == 6)
composite1_565 (pixels + i, rgba);
else
composite1_555 (pixels + i, rgba);
}
if (i + 8 <= n)
reader_init (&r, rgba);
for (; i + 8 <= n; i += 8)
{
vu8 s0 = reader_next (&r), s1 = reader_next (&r);
vu16 d = vec_ld (0, pixels + i);
vu16 a = channel (s0, s1, pa), inv = vec_sub (c255, a);
vu16 dr = vec_and (vec_sr (d, vec_splats ((unsigned short) (5 + green_bits))), vec_splats ((unsigned short) 0x1f));
vu16 dg = vec_and (vec_sr (d, vec_splats ((unsigned short) 5)), vec_splats ((unsigned short) ((1 << green_bits) - 1)));
vu16 db = vec_and (d, vec_splats ((unsigned short) 0x1f));
vu16 v;
/* the bits of the pixel repeated up to 8 */
dr = vec_or (vec_sl (dr, vec_splats ((unsigned short) 3)), vec_sr (dr, vec_splats ((unsigned short) 2)));
if (green_bits == 6)
dg = vec_or (vec_sl (dg, vec_splats ((unsigned short) 2)), vec_sr (dg, vec_splats ((unsigned short) 4)));
else
dg = vec_or (vec_sl (dg, vec_splats ((unsigned short) 3)), vec_sr (dg, vec_splats ((unsigned short) 2)));
db = vec_or (vec_sl (db, vec_splats ((unsigned short) 3)), vec_sr (db, vec_splats ((unsigned short) 2)));
v = pack16 (blend (vec_mladd (channel (s0, s1, pr), a, vec_mladd (dr, inv, vec_splats ((unsigned short) 0)))),
blend (vec_mladd (channel (s0, s1, pg), a, vec_mladd (dg, inv, vec_splats ((unsigned short) 0)))),
blend (vec_mladd (channel (s0, s1, pb), a, vec_mladd (db, inv, vec_splats ((unsigned short) 0)))),
green_bits);
/* where nothing is drawn the unused bit of 555 stays as it was */
if (green_bits == 5)
v = vec_sel (v, d, vec_cmpeq (a, vec_splats ((unsigned short) 0)));
vec_st (v, 0, pixels + i);
}
return i;
}
static gint
rgba_to_argb (guint32 *out, const guchar *rgba, gint n)
{
const vu8 argb = VU8 (3, 0, 1, 2, 7, 4, 5, 6, 11, 8, 9, 10, 15, 12, 13, 14);
/* a for R, G and B; 255 for the alpha, which a * 255 / 255 keeps */
const vu8 factors = VU8 (16, 3, 3, 3, 16, 7, 7, 7, 16, 11, 11, 11, 16, 15, 15, 15);
const vu8 merge = VU8 (1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31);
const vu8 ones = vec_splat_u8 (-1);
Reader r;
gint i;
for (i = 0; i < n && !aligned (out + i); i++, rgba += 4)
{
guint a = rgba[3];
out[i] = (a << 24) | (blend8 (a, rgba[0], 0) << 16) |
(blend8 (a, rgba[1], 0) << 8) | blend8 (a, rgba[2], 0);
}
if (i + 4 <= n)
reader_init (&r, rgba);
for (; i + 4 <= n; i += 4)
{
vu8 s = reader_next (&r);
vu8 m = vec_perm (s, ones, factors);
s = vec_perm (s, s, argb);
vec_st (vec_perm ((vu8) blend (vec_mule (s, m)), (vu8) blend (vec_mulo (s, m)), merge),
0, (guchar *) (out + i));
}
return i;
}
static gint
composite_565 (guint16 *pixels, const guchar *rgba, gint n)
{
return composite_16 (pixels, rgba, n, 6);
}
static gint
composite_555 (guint16 *pixels, const guchar *rgba, gint n)
{
return composite_16 (pixels, rgba, n, 5);
}
void
_gdk_rgb_simd_init_altivec (GdkRgbSimd *simd)
{
simd->name = "altivec";
simd->rgb_to_x888 = rgb_to_x888;
simd->rgbx_to_x888 = rgbx_to_x888;
simd->rgb_to_565 = rgb_to_565;
simd->rgb_to_555 = rgb_to_555;
simd->composite_x888 = composite_x888;
simd->composite_565 = composite_565;
simd->composite_555 = composite_555;
simd->rgba_to_argb = rgba_to_argb;
}
#else
void
_gdk_rgb_simd_init_altivec (GdkRgbSimd *simd)
{
}
#endif

318
gdk/gdkrgb-armv6.c Normal file
View file

@ -0,0 +1,318 @@
/* GDK - The GIMP Drawing Kit
* GdkRGB loops for the media instructions of ARMv6 (the ARM11 of the
* Raspberry Pi 1 and Zero), which has no NEON: two channels of a pixel
* 16 bits apart in one register, multiplied at once, with UXTB16 and
* UXTAB16 taking bytes apart and adding them in both halves; REV puts
* the bytes of a pixel in the other order. A pixel goes in and out as
* one word, not byte by byte.
*
* GDK_RGB_ARMV6_C builds the same loops with C for the instructions,
* to check them on other machines.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include "gdkrgbsimd.h"
/* ARMv6 or later in ARM or Thumb-2 code, little endian */
#if defined(__arm__) && !defined(__ARMEB__) && \
(!defined(__thumb__) || defined(__thumb2__)) && \
(defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \
defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) || \
(defined(__ARM_ARCH) && __ARM_ARCH >= 6))
#define ARMV6_ASM 1
#endif
#if defined(ARMV6_ASM) || defined(GDK_RGB_ARMV6_C)
#ifdef ARMV6_ASM
/* bytes 0 and 2 in the two halves */
static inline guint32
uxtb16 (guint32 x)
{
guint32 r;
__asm__ ("uxtb16 %0, %1" : "=r" (r) : "r" (x));
return r;
}
/* bytes 1 and 3 */
static inline guint32
uxtb16_ror8 (guint32 x)
{
guint32 r;
__asm__ ("uxtb16 %0, %1, ror #8" : "=r" (r) : "r" (x));
return r;
}
/* @acc plus bytes 1 and 3 of @x, in each half */
static inline guint32
uxtab16_ror8 (guint32 acc, guint32 x)
{
guint32 r;
__asm__ ("uxtab16 %0, %1, %2, ror #8" : "=r" (r) : "r" (acc), "r" (x));
return r;
}
static inline guint32
rev (guint32 x)
{
guint32 r;
__asm__ ("rev %0, %1" : "=r" (r) : "r" (x));
return r;
}
#else
static inline guint32 uxtb16 (guint32 x) { return x & 0x00ff00ff; }
static inline guint32 uxtb16_ror8 (guint32 x) { return (x >> 8 | x << 24) & 0x00ff00ff; }
static inline guint32
uxtab16_ror8 (guint32 acc, guint32 x)
{
guint32 b = uxtb16_ror8 (x);
return ((acc + b) & 0xffff) | ((acc & 0xffff0000) + (b & 0xffff0000));
}
static inline guint32
rev (guint32 x)
{
return x >> 24 | (x >> 8 & 0xff00) | (x << 8 & 0xff0000) | x << 24;
}
#endif
/* A word of pixels, at an address of a whole word: rows of pixbufs
* start there, and the loops take words from the start. Rows that do
* not are left to the C code, as ARMv6 compilers read words byte by
* byte where they are not sure. */
typedef guint32 __attribute__ ((may_alias)) word;
#define ALIGNED(p) (((gsize) (p) & 3) == 0)
static inline guint32
load32 (const guchar *p)
{
return *(const word *) p;
}
/* t / 255 rounded, in both halves, for t = c * a + 0x80 (no carries
* between the halves: t stays below 65536) */
static inline guint32
div255 (guint32 t)
{
return uxtb16_ror8 (uxtab16_ror8 (t, t));
}
/* Of each three RGB pixels: R G B R | G B R G | B R G B in three words */
static gint
rgb_to_x888 (guint32 *out, const guchar *rgb, gint n)
{
gint i;
if (!ALIGNED (rgb))
return 0;
for (i = 0; i + 4 <= n; i += 4, rgb += 12)
{
guint32 w0 = load32 (rgb), w1 = load32 (rgb + 4), w2 = load32 (rgb + 8);
/* B G R x, reversed and moved down, is R << 16 | G << 8 | B */
out[i] = (rev (w0) >> 8) | 0xff000000;
out[i + 1] = (rev ((w0 >> 24) | (w1 << 8)) >> 8) | 0xff000000;
out[i + 2] = (rev ((w1 >> 16) | (w2 << 16)) >> 8) | 0xff000000;
out[i + 3] = (rev (w2) & 0xffffff) | 0xff000000;
}
return i;
}
/* Lanes R | G << 8 | B << 16 to 565 or 555 */
static inline guint32
rgb16_of (guint32 v, const gint green_bits)
{
if (green_bits == 6)
return ((v & 0xf8) << 8) | ((v >> 5) & 0x7e0) | ((v >> 19) & 0x1f);
else
return ((v & 0xf8) << 7) | ((v >> 6) & 0x3e0) | ((v >> 19) & 0x1f) | 0x8000;
}
static inline gint
rgb_to_16 (guint16 *out, const guchar *rgb, gint n, const gint green_bits)
{
guint32 *out32 = (guint32 *) out;
gint i;
/* two pixels to a word of the output; the words of both at their
* places, or the C code does the row */
if (!ALIGNED (rgb) || !ALIGNED (out))
return 0;
for (i = 0; i + 4 <= n; i += 4, rgb += 12, out32 += 2)
{
guint32 w0 = load32 (rgb), w1 = load32 (rgb + 4), w2 = load32 (rgb + 8);
out32[0] = rgb16_of (w0, green_bits) |
(rgb16_of ((w0 >> 24) | (w1 << 8), green_bits) << 16);
out32[1] = rgb16_of ((w1 >> 16) | (w2 << 16), green_bits) |
(rgb16_of (w2 >> 8, green_bits) << 16);
}
return i;
}
static gint
rgb_to_565 (guint16 *out, const guchar *rgb, gint n)
{
return rgb_to_16 (out, rgb, n, 6);
}
static gint
rgb_to_555 (guint16 *out, const guchar *rgb, gint n)
{
return rgb_to_16 (out, rgb, n, 5);
}
/* c * a / 255 to the nearest for the channels of the RGBA word @w:
* red and blue together, green and alpha together */
static gint
rgba_to_argb (guint32 *out, const guchar *rgba, gint n)
{
gint i;
if (!ALIGNED (rgba))
return 0;
for (i = 0; i < n; i++, rgba += 4)
{
guint32 w = load32 (rgba);
guint32 a = w >> 24;
guint32 rb = div255 (uxtb16 (w) * a + 0x00800080); /* R | B << 16 */
guint32 g = div255 (uxtb16_ror8 (w) * a + 0x80) & 0xff;
/* B | R << 16, which a rotation is */
out[i] = (a << 24) | (g << 8) | (rb >> 16) | (rb << 16);
}
return i;
}
/* a * s + (255 - a) * d, rounded, for two channels at once */
static inline guint32
blend2 (guint32 s, guint32 d, guint32 a)
{
return div255 (s * a + d * (255 - a) + 0x00800080);
}
static gint
composite_x888 (guint32 *pixels, const guchar *rgba, gint n)
{
gint i;
if (!ALIGNED (rgba))
return 0;
for (i = 0; i < n; i++, rgba += 4)
{
guint32 w = load32 (rgba);
guint32 a = w >> 24;
guint32 d, rb, g;
if (a == 0)
continue;
if (a == 255)
{
pixels[i] = (rev (w) >> 8) | 0xff000000;
continue;
}
/* the pixel is B | G << 8 | R << 16: blue and red as in @w swapped */
d = pixels[i];
rb = blend2 (uxtb16 (w), ((d >> 16) & 0xff) | ((d & 0xff) << 16), a);
g = blend2 ((w >> 8) & 0xff, (d >> 8) & 0xff, a) & 0xff;
pixels[i] = 0xff000000 | ((rb & 0xff) << 16) | (g << 8) | (rb >> 16);
}
return i;
}
/* The bits of a channel repeated up to 8, as GdkRGB unpacks them */
#define WIDEN5(c) (((c) << 3) | ((c) >> 2))
#define WIDEN6(c) (((c) << 2) | ((c) >> 4))
static inline gint
composite_16 (guint16 *pixels, const guchar *rgba, gint n, const gint green_bits)
{
const gint red_shift = 5 + green_bits;
gint i;
if (!ALIGNED (rgba))
return 0;
for (i = 0; i < n; i++, rgba += 4)
{
guint32 w = load32 (rgba);
guint32 a = w >> 24;
guint32 d, dr, dg, db, rb, g, v;
if (a == 0)
continue;
d = pixels[i];
dr = (d >> red_shift) & 0x1f;
dg = (d >> 5) & ((1 << green_bits) - 1);
db = d & 0x1f;
dr = WIDEN5 (dr);
dg = green_bits == 6 ? WIDEN6 (dg) : WIDEN5 (dg);
db = WIDEN5 (db);
rb = blend2 (uxtb16 (w), dr | (db << 16), a); /* R | B << 16 */
g = blend2 ((w >> 8) & 0xff, dg, a) & 0xff;
v = (((rb & 0xff) >> 3) << red_shift) | ((g >> (8 - green_bits)) << 5) | (rb >> 19);
if (green_bits == 5)
v |= 0x8000;
pixels[i] = v;
}
return i;
}
static gint
composite_565 (guint16 *pixels, const guchar *rgba, gint n)
{
return composite_16 (pixels, rgba, n, 6);
}
static gint
composite_555 (guint16 *pixels, const guchar *rgba, gint n)
{
return composite_16 (pixels, rgba, n, 5);
}
void
_gdk_rgb_simd_init_armv6 (GdkRgbSimd *simd)
{
simd->name = "armv6";
simd->rgb_to_x888 = rgb_to_x888;
simd->rgb_to_565 = rgb_to_565;
simd->rgb_to_555 = rgb_to_555;
simd->composite_x888 = composite_x888;
simd->composite_565 = composite_565;
simd->composite_555 = composite_555;
simd->rgba_to_argb = rgba_to_argb;
}
#else
void
_gdk_rgb_simd_init_armv6 (GdkRgbSimd *simd)
{
}
#endif

136
gdk/gdkrgb-avx2.c Normal file
View file

@ -0,0 +1,136 @@
/* GDK - The GIMP Drawing Kit
* GdkRGB loops for AVX2 (Haswell, Zen and later): the SSSE3 loops eight
* pixels at a time, for the pixels of four bytes, where the lanes of 128
* bits do not mix. Pixels of three bytes would cross the two halves of
* a register and need permutes; those stay with SSSE3.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include "gdkrgbsimd.h"
#if defined(__AVX2__)
#include <immintrin.h>
/* x86 is little endian: an x888 pixel is the bytes B, G, R, 0xff */
#define SPLAT(v) _mm256_set1_epi32 ((gint) (v))
/* the same order of bytes in both halves */
#define BYTES(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
_mm256_setr_epi8 (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, \
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
static gint
rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n)
{
const __m256i order = BYTES (2, 1, 0, -1, 6, 5, 4, -1, 10, 9, 8, -1, 14, 13, 12, -1);
gint i;
for (i = 0; i + 8 <= n; i += 8, rgbx += 32)
_mm256_storeu_si256 ((__m256i *) (out + i),
_mm256_or_si256 (_mm256_shuffle_epi8 (_mm256_loadu_si256 ((const __m256i *) rgbx), order),
SPLAT (0xff000000)));
return i;
}
/* The alpha of each pixel in its four 16-bit lanes */
static inline __m256i
alpha_of (__m256i v)
{
return _mm256_shuffle_epi8 (v, BYTES (6, 7, 6, 7, 6, 7, 6, 7, 14, 15, 14, 15, 14, 15, 14, 15));
}
/* (a * s + (255 - a) * d) / 255, rounded as GdkRGB's C code does */
static inline __m256i
blend (__m256i s, __m256i d, __m256i a)
{
__m256i t = _mm256_add_epi16 (_mm256_add_epi16 (_mm256_mullo_epi16 (s, a),
_mm256_mullo_epi16 (d, _mm256_sub_epi16 (_mm256_set1_epi16 (255), a))),
_mm256_set1_epi16 (0x80));
return _mm256_mulhi_epu16 (t, _mm256_set1_epi16 (257));
}
static gint
composite_x888 (guint32 *pixels, const guchar *rgba, gint n)
{
const __m256i zero = _mm256_setzero_si256 ();
const __m256i order = BYTES (2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15);
gint i;
for (i = 0; i + 8 <= n; i += 8, rgba += 32)
{
__m256i s = _mm256_loadu_si256 ((const __m256i *) rgba);
__m256i d = _mm256_loadu_si256 ((const __m256i *) (pixels + i));
__m256i transparent = _mm256_cmpeq_epi32 (_mm256_srli_epi32 (s, 24), zero);
__m256i lo, hi, v;
/* RGBA to BGRA, the order of the pixels */
s = _mm256_shuffle_epi8 (s, order);
lo = _mm256_unpacklo_epi8 (s, zero);
hi = _mm256_unpackhi_epi8 (s, zero);
lo = blend (lo, _mm256_unpacklo_epi8 (d, zero), alpha_of (lo));
hi = blend (hi, _mm256_unpackhi_epi8 (d, zero), alpha_of (hi));
v = _mm256_or_si256 (_mm256_packus_epi16 (lo, hi), SPLAT (0xff000000));
/* fully transparent pixels stay as they are */
v = _mm256_blendv_epi8 (v, d, transparent);
_mm256_storeu_si256 ((__m256i *) (pixels + i), v);
}
return i;
}
/* c * a / 255 to the nearest, which (c * a + 0x80) * 257 >> 16 is */
static gint
rgba_to_argb (guint32 *out, const guchar *rgba, gint n)
{
const __m256i zero = _mm256_setzero_si256 ();
const __m256i order = BYTES (2, 1, 0, -1, 6, 5, 4, -1, 10, 9, 8, -1, 14, 13, 12, -1);
gint i;
for (i = 0; i + 8 <= n; i += 8, rgba += 32)
{
__m256i s = _mm256_loadu_si256 ((const __m256i *) rgba);
__m256i lo = _mm256_unpacklo_epi8 (s, zero);
__m256i hi = _mm256_unpackhi_epi8 (s, zero);
lo = _mm256_mulhi_epu16 (_mm256_add_epi16 (_mm256_mullo_epi16 (lo, alpha_of (lo)), _mm256_set1_epi16 (0x80)),
_mm256_set1_epi16 (257));
hi = _mm256_mulhi_epu16 (_mm256_add_epi16 (_mm256_mullo_epi16 (hi, alpha_of (hi)), _mm256_set1_epi16 (0x80)),
_mm256_set1_epi16 (257));
/* R, G, B to B, G, R, and the alpha byte as it was */
_mm256_storeu_si256 ((__m256i *) (out + i),
_mm256_or_si256 (_mm256_shuffle_epi8 (_mm256_packus_epi16 (lo, hi), order),
_mm256_and_si256 (s, SPLAT (0xff000000))));
}
return i;
}
void
_gdk_rgb_simd_init_avx2 (GdkRgbSimd *simd)
{
simd->name = "avx2";
simd->rgbx_to_x888 = rgbx_to_x888;
simd->composite_x888 = composite_x888;
simd->rgba_to_argb = rgba_to_argb;
}
#else
void
_gdk_rgb_simd_init_avx2 (GdkRgbSimd *simd)
{
}
#endif

480
gdk/gdkrgb-mmx.c Normal file
View file

@ -0,0 +1,480 @@
/* GDK - The GIMP Drawing Kit
* GdkRGB loops for MMX, and for what came later on the same registers:
* the integer SSE instructions of the Pentium III and Athlon (pshufw,
* pmulhuw), and 3DNow! of the K6-2, Athlon and Geode LX (pmulhrw)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include <string.h>
#include "gdkrgbsimd.h"
/* x86-64 always has SSE2, which does all of this better */
#if defined(__MMX__) && !defined(__x86_64__)
#include <mmintrin.h>
/* The file is compiled for plain MMX. The later instructions are
* written as assembler, so the compiler uses them nowhere else, and
* the kernels with them are only called on CPUs that have them. */
#if defined(__GNUC__)
#define KERNEL static inline __attribute__ ((always_inline))
#else
#define KERNEL static inline
#endif
/* How a kernel does what MMX has no instruction for */
enum
{
PLAIN, /* MMX only */
EXT, /* pshufw and pmulhuw */
AMD3D, /* pmulhrw */
AMD3D_EXT /* all three */
};
#define SPLAT(v) _mm_set1_pi32 ((gint) (v))
static inline __m64
load8 (const void *p)
{
__m64 v;
memcpy (&v, p, 8);
return v;
}
static inline void
store8 (void *p, __m64 v)
{
memcpy (p, &v, 8);
}
static inline __m64
load4 (const void *p)
{
gint32 v;
memcpy (&v, p, 4);
return _mm_cvtsi32_si64 (v);
}
#if defined(__i386__) && defined(__GNUC__)
#define HAVE_LATER_MMX 1
#define PSHUFW(v, imm) G_STMT_START { \
__asm__ ("pshufw $" #imm ", %0, %0" : "+y" (v)); \
} G_STMT_END
static inline __m64
pmulhuw (__m64 a, __m64 b)
{
__asm__ ("pmulhuw %1, %0" : "+y" (a) : "y" (b));
return a;
}
static inline __m64
pmulhrw (__m64 a, __m64 b)
{
__asm__ ("pmulhrw %1, %0" : "+y" (a) : "y" (b));
return a;
}
#else
/* never used: only plain kernels are made here */
#define PSHUFW(v, imm) G_STMT_START { } G_STMT_END
#define pmulhuw(a, b) ((void) (b), (a))
#define pmulhrw(a, b) ((void) (b), (a))
#endif
/* The 6 bytes of two RGB pixels as lanes R | G << 8 | B << 16 */
static inline __m64
rgb_lanes (__m64 v)
{
return _mm_unpacklo_pi32 (v, _mm_srli_si64 (v, 24));
}
static inline __m64
x888_of (__m64 v)
{
return _mm_or_si64 (_mm_or_si64 (_mm_slli_pi32 (_mm_and_si64 (v, SPLAT (0xff)), 16),
_mm_and_si64 (v, SPLAT (0xff00))),
_mm_or_si64 (_mm_and_si64 (_mm_srli_pi32 (v, 16), SPLAT (0xff)),
SPLAT (0xff000000)));
}
/* Lanes R | G << 8 | B << 16 to 565 or 555, sign extended for packing.
* The bit 555 has no use for is set, as in all of GdkRGB's pixels. */
static inline __m64
rgb565_of (__m64 v)
{
v = _mm_or_si64 (_mm_or_si64 (_mm_slli_pi32 (_mm_and_si64 (v, SPLAT (0xf8)), 8),
_mm_srli_pi32 (_mm_and_si64 (v, SPLAT (0xfc00)), 5)),
_mm_and_si64 (_mm_srli_pi32 (v, 19), SPLAT (0x1f)));
return _mm_srai_pi32 (_mm_slli_pi32 (v, 16), 16);
}
static inline __m64
rgb555_of (__m64 v)
{
v = _mm_or_si64 (_mm_or_si64 (_mm_slli_pi32 (_mm_and_si64 (v, SPLAT (0xf8)), 7),
_mm_srli_pi32 (_mm_and_si64 (v, SPLAT (0xf800)), 6)),
_mm_or_si64 (_mm_and_si64 (_mm_srli_pi32 (v, 19), SPLAT (0x1f)),
SPLAT (0x8000)));
return _mm_srai_pi32 (_mm_slli_pi32 (v, 16), 16);
}
static gint
rgb_to_x888 (guint32 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 4 <= n; i += 4, rgb += 12)
{
__m64 a = load8 (rgb);
__m64 b = _mm_or_si64 (_mm_srli_si64 (a, 48), _mm_slli_si64 (load4 (rgb + 8), 16));
store8 (out + i, x888_of (rgb_lanes (a)));
store8 (out + i + 2, x888_of (rgb_lanes (b)));
}
_mm_empty ();
return i;
}
static gint
rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n)
{
gint i;
for (i = 0; i + 2 <= n; i += 2, rgbx += 8)
store8 (out + i, x888_of (load8 (rgbx)));
_mm_empty ();
return i;
}
static gint
rgb_to_565 (guint16 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 4 <= n; i += 4, rgb += 12)
{
__m64 a = load8 (rgb);
__m64 b = _mm_or_si64 (_mm_srli_si64 (a, 48), _mm_slli_si64 (load4 (rgb + 8), 16));
store8 (out + i, _mm_packs_pi32 (rgb565_of (rgb_lanes (a)), rgb565_of (rgb_lanes (b))));
}
_mm_empty ();
return i;
}
static gint
rgb_to_555 (guint16 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 4 <= n; i += 4, rgb += 12)
{
__m64 a = load8 (rgb);
__m64 b = _mm_or_si64 (_mm_srli_si64 (a, 48), _mm_slli_si64 (load4 (rgb + 8), 16));
store8 (out + i, _mm_packs_pi32 (rgb555_of (rgb_lanes (a)), rgb555_of (rgb_lanes (b))));
}
_mm_empty ();
return i;
}
/* (a * s + (255 - a) * d) / 255, rounded as GdkRGB's C code does, in
* 16-bit lanes. 3DNow! does it as d + (s - d) * a / 255: pmulhrw
* rounds the signed difference times a * 257, a correction makes up
* for a * 257 not fitting a signed lane from a = 128 on. That is the
* same in all 16777216 cases. */
KERNEL __m64
blend (__m64 s, __m64 d, __m64 a, const gint how)
{
if (how == AMD3D || how == AMD3D_EXT)
{
__m64 scaled = _mm_slli_pi16 (a, 8);
__m64 mask = _mm_srai_pi16 (scaled, 15);
__m64 coeff = _mm_sub_pi16 (_mm_add_pi16 (a, scaled), mask);
__m64 delta = _mm_sub_pi16 (s, d);
return _mm_add_pi16 (_mm_add_pi16 (pmulhrw (delta, coeff), _mm_and_si64 (delta, mask)), d);
}
else
{
__m64 t = _mm_add_pi16 (_mm_add_pi16 (_mm_mullo_pi16 (s, a),
_mm_mullo_pi16 (d, _mm_sub_pi16 (_mm_set1_pi16 (255), a))),
_mm_set1_pi16 (0x80));
/* t * 257 >> 16 is (t + (t >> 8)) >> 8 */
if (how == EXT)
return pmulhuw (t, _mm_set1_pi16 (257));
return _mm_srli_pi16 (_mm_add_pi16 (t, _mm_srli_pi16 (t, 8)), 8);
}
}
/* c * a / 255, rounded the same way */
KERNEL __m64
premultiply (__m64 c, __m64 a, const gint how)
{
if (how == AMD3D || how == AMD3D_EXT)
return blend (c, _mm_setzero_si64 (), a, how);
else
{
__m64 t = _mm_add_pi16 (_mm_mullo_pi16 (c, a), _mm_set1_pi16 (0x80));
if (how == EXT)
return pmulhuw (t, _mm_set1_pi16 (257));
return _mm_srli_pi16 (_mm_add_pi16 (t, _mm_srli_pi16 (t, 8)), 8);
}
}
/* The alpha of a pixel in 16-bit lanes in all four lanes */
KERNEL __m64
alpha_of (__m64 v, const gint how)
{
if (how == EXT || how == AMD3D_EXT)
{
PSHUFW (v, 0xff);
return v;
}
v = _mm_srli_si64 (v, 48);
v = _mm_unpacklo_pi16 (v, v);
return _mm_unpacklo_pi32 (v, v);
}
/* Two RGBA pixels as 16-bit lanes B, G, R, A each: the order of the
* bytes of 0xAARRGGBB */
KERNEL void
unpack_bgra (__m64 s, __m64 *lo, __m64 *hi, const gint how)
{
const __m64 zero = _mm_setzero_si64 ();
if (how == EXT || how == AMD3D_EXT)
{
__m64 l = _mm_unpacklo_pi8 (s, zero);
__m64 h = _mm_unpackhi_pi8 (s, zero);
PSHUFW (l, 0xc6);
PSHUFW (h, 0xc6);
*lo = l;
*hi = h;
}
else
{
s = _mm_or_si64 (_mm_and_si64 (s, SPLAT (0xff00ff00)),
_mm_or_si64 (_mm_slli_pi32 (_mm_and_si64 (s, SPLAT (0xff)), 16),
_mm_and_si64 (_mm_srli_pi32 (s, 16), SPLAT (0xff))));
*lo = _mm_unpacklo_pi8 (s, zero);
*hi = _mm_unpackhi_pi8 (s, zero);
}
}
KERNEL gint
composite_x888_k (guint32 *pixels, const guchar *rgba, gint n, const gint how)
{
const __m64 zero = _mm_setzero_si64 ();
gint i;
for (i = 0; i + 2 <= n; i += 2, rgba += 8)
{
__m64 s = load8 (rgba);
__m64 d = load8 (pixels + i);
__m64 transparent = _mm_cmpeq_pi32 (_mm_srli_pi32 (s, 24), zero);
__m64 lo, hi, v;
unpack_bgra (s, &lo, &hi, how);
lo = blend (lo, _mm_unpacklo_pi8 (d, zero), alpha_of (lo, how), how);
hi = blend (hi, _mm_unpackhi_pi8 (d, zero), alpha_of (hi, how), how);
v = _mm_or_si64 (_mm_packs_pu16 (lo, hi), SPLAT (0xff000000));
/* fully transparent pixels stay as they are */
store8 (pixels + i, _mm_or_si64 (_mm_and_si64 (transparent, d),
_mm_andnot_si64 (transparent, v)));
}
_mm_empty ();
return i;
}
/* Four 565 or 555 pixels at a time, each channel in a register */
KERNEL gint
composite_16_k (guint16 *pixels, const guchar *rgba, gint n, const gint green_bits, const gint how)
{
const gint red_shift = 5 + green_bits;
const __m64 zero = _mm_setzero_si64 ();
gint i;
for (i = 0; i + 4 <= n; i += 4, rgba += 16)
{
__m64 s0 = load8 (rgba);
__m64 s1 = load8 (rgba + 8);
__m64 d = load8 (pixels + i);
__m64 r = _mm_packs_pi32 (_mm_and_si64 (s0, SPLAT (0xff)), _mm_and_si64 (s1, SPLAT (0xff)));
__m64 g = _mm_packs_pi32 (_mm_and_si64 (_mm_srli_pi32 (s0, 8), SPLAT (0xff)),
_mm_and_si64 (_mm_srli_pi32 (s1, 8), SPLAT (0xff)));
__m64 b = _mm_packs_pi32 (_mm_and_si64 (_mm_srli_pi32 (s0, 16), SPLAT (0xff)),
_mm_and_si64 (_mm_srli_pi32 (s1, 16), SPLAT (0xff)));
__m64 a = _mm_packs_pi32 (_mm_srli_pi32 (s0, 24), _mm_srli_pi32 (s1, 24));
__m64 dr = _mm_and_si64 (_mm_srli_pi16 (d, red_shift), _mm_set1_pi16 (0x1f));
__m64 dg = _mm_and_si64 (_mm_srli_pi16 (d, 5), _mm_set1_pi16 ((1 << green_bits) - 1));
__m64 db = _mm_and_si64 (d, _mm_set1_pi16 (0x1f));
__m64 v;
/* the bits of the pixel repeated up to 8 */
dr = _mm_or_si64 (_mm_slli_pi16 (dr, 3), _mm_srli_pi16 (dr, 2));
if (green_bits == 6)
dg = _mm_or_si64 (_mm_slli_pi16 (dg, 2), _mm_srli_pi16 (dg, 4));
else
dg = _mm_or_si64 (_mm_slli_pi16 (dg, 3), _mm_srli_pi16 (dg, 2));
db = _mm_or_si64 (_mm_slli_pi16 (db, 3), _mm_srli_pi16 (db, 2));
r = blend (r, dr, a, how);
g = blend (g, dg, a, how);
b = blend (b, db, a, how);
v = _mm_or_si64 (_mm_or_si64 (_mm_slli_pi16 (_mm_srli_pi16 (r, 3), red_shift),
_mm_slli_pi16 (_mm_srli_pi16 (g, 8 - green_bits), 5)),
_mm_srli_pi16 (b, 3));
if (green_bits == 5)
{
/* the unused bit is set, except where nothing is drawn */
__m64 transparent = _mm_cmpeq_pi16 (a, zero);
v = _mm_or_si64 (_mm_and_si64 (transparent, d),
_mm_andnot_si64 (transparent, _mm_or_si64 (v, _mm_set1_pi16 ((gshort) 0x8000))));
}
store8 (pixels + i, v);
}
_mm_empty ();
return i;
}
KERNEL gint
rgba_to_argb_k (guint32 *out, const guchar *rgba, gint n, const gint how)
{
gint i;
for (i = 0; i + 2 <= n; i += 2, rgba += 8)
{
__m64 s = load8 (rgba);
__m64 lo, hi;
unpack_bgra (s, &lo, &hi, how);
lo = premultiply (lo, alpha_of (lo, how), how);
hi = premultiply (hi, alpha_of (hi, how), how);
/* the alpha byte as it was */
store8 (out + i, _mm_or_si64 (_mm_and_si64 (_mm_packs_pu16 (lo, hi), SPLAT (0x00ffffff)),
_mm_and_si64 (s, SPLAT (0xff000000))));
}
_mm_empty ();
return i;
}
#define DEFINE_KERNELS(suffix, how) \
static gint \
composite_x888_##suffix (guint32 *pixels, const guchar *rgba, gint n) \
{ \
return composite_x888_k (pixels, rgba, n, how); \
} \
\
static gint \
composite_565_##suffix (guint16 *pixels, const guchar *rgba, gint n) \
{ \
return composite_16_k (pixels, rgba, n, 6, how); \
} \
\
static gint \
composite_555_##suffix (guint16 *pixels, const guchar *rgba, gint n) \
{ \
return composite_16_k (pixels, rgba, n, 5, how); \
} \
\
static gint \
rgba_to_argb_##suffix (guint32 *out, const guchar *rgba, gint n) \
{ \
return rgba_to_argb_k (out, rgba, n, how); \
} \
\
static void \
init_##suffix (GdkRgbSimd *simd, const gchar *name) \
{ \
simd->name = name; \
simd->rgb_to_x888 = rgb_to_x888; \
simd->rgbx_to_x888 = rgbx_to_x888; \
simd->rgb_to_565 = rgb_to_565; \
simd->rgb_to_555 = rgb_to_555; \
simd->composite_x888 = composite_x888_##suffix; \
simd->composite_565 = composite_565_##suffix; \
simd->composite_555 = composite_555_##suffix; \
simd->rgba_to_argb = rgba_to_argb_##suffix; \
}
DEFINE_KERNELS (mmx, PLAIN)
void
_gdk_rgb_simd_init_mmx (GdkRgbSimd *simd)
{
init_mmx (simd, "mmx");
}
#if defined(HAVE_LATER_MMX)
DEFINE_KERNELS (ext, EXT)
DEFINE_KERNELS (3dnow, AMD3D)
DEFINE_KERNELS (3dnowext, AMD3D_EXT)
void
_gdk_rgb_simd_init_mmxext (GdkRgbSimd *simd)
{
init_ext (simd, "mmxext");
}
void
_gdk_rgb_simd_init_3dnow (GdkRgbSimd *simd)
{
init_3dnow (simd, "3dnow");
}
void
_gdk_rgb_simd_init_3dnowext (GdkRgbSimd *simd)
{
init_3dnowext (simd, "3dnowext");
}
#else
void _gdk_rgb_simd_init_mmxext (GdkRgbSimd *simd) { }
void _gdk_rgb_simd_init_3dnow (GdkRgbSimd *simd) { }
void _gdk_rgb_simd_init_3dnowext (GdkRgbSimd *simd) { }
#endif
#else
void _gdk_rgb_simd_init_mmx (GdkRgbSimd *simd) { }
void _gdk_rgb_simd_init_mmxext (GdkRgbSimd *simd) { }
void _gdk_rgb_simd_init_3dnow (GdkRgbSimd *simd) { }
void _gdk_rgb_simd_init_3dnowext (GdkRgbSimd *simd) { }
#endif

251
gdk/gdkrgb-neon.c Normal file
View file

@ -0,0 +1,251 @@
/* GDK - The GIMP Drawing Kit
* GdkRGB loops for NEON (ARMv7 with NEON, AArch64)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include "gdkrgbsimd.h"
#if (defined(__ARM_NEON) || defined(__ARM_NEON__)) && !defined(__ARM_BIG_ENDIAN)
#include <arm_neon.h>
/* An x888 pixel is the bytes B, G, R, 0xff. The structure loads and
* stores take the channels apart and put them together. */
/* (a * s + (255 - a) * d) / 255, rounded */
static inline uint8x8_t
blend (uint8x8_t s, uint8x8_t d, uint8x8_t a, uint8x8_t inv)
{
uint16x8_t t = vmlal_u8 (vmull_u8 (s, a), d, inv);
return vrshrn_n_u16 (vrsraq_n_u16 (t, t, 8), 8);
}
static inline uint16x8_t
pack565 (uint8x8_t r, uint8x8_t g, uint8x8_t b)
{
uint16x8_t v = vshll_n_u8 (r, 8);
v = vsriq_n_u16 (v, vshll_n_u8 (g, 8), 5);
return vsriq_n_u16 (v, vshll_n_u8 (b, 8), 11);
}
/* with the unused bit set, as all of GdkRGB does */
static inline uint16x8_t
pack555 (uint8x8_t r, uint8x8_t g, uint8x8_t b)
{
uint16x8_t v = vshll_n_u8 (r, 7);
v = vsriq_n_u16 (v, vshll_n_u8 (g, 8), 6);
v = vsriq_n_u16 (v, vshll_n_u8 (b, 8), 11);
return vorrq_u16 (v, vdupq_n_u16 (0x8000));
}
static gint
rgb_to_x888 (guint32 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 16 <= n; i += 16, rgb += 48)
{
uint8x16x3_t s = vld3q_u8 (rgb);
uint8x16x4_t d;
d.val[0] = s.val[2];
d.val[1] = s.val[1];
d.val[2] = s.val[0];
d.val[3] = vdupq_n_u8 (0xff);
vst4q_u8 ((guchar *) (out + i), d);
}
return i;
}
static gint
rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n)
{
gint i;
for (i = 0; i + 16 <= n; i += 16, rgbx += 64)
{
uint8x16x4_t s = vld4q_u8 (rgbx);
uint8x16x4_t d;
d.val[0] = s.val[2];
d.val[1] = s.val[1];
d.val[2] = s.val[0];
d.val[3] = vdupq_n_u8 (0xff);
vst4q_u8 ((guchar *) (out + i), d);
}
return i;
}
static gint
rgb_to_565 (guint16 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgb += 24)
{
uint8x8x3_t s = vld3_u8 (rgb);
vst1q_u16 (out + i, pack565 (s.val[0], s.val[1], s.val[2]));
}
return i;
}
static gint
rgb_to_555 (guint16 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgb += 24)
{
uint8x8x3_t s = vld3_u8 (rgb);
vst1q_u16 (out + i, pack555 (s.val[0], s.val[1], s.val[2]));
}
return i;
}
static gint
composite_x888 (guint32 *pixels, const guchar *rgba, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgba += 32)
{
uint8x8x4_t s = vld4_u8 (rgba);
uint8x8x4_t d = vld4_u8 ((const guchar *) (pixels + i));
uint8x8_t a = s.val[3], inv = vmvn_u8 (a);
uint8x8_t transparent = vceq_u8 (a, vdup_n_u8 (0));
uint8x8x4_t v;
v.val[0] = vbsl_u8 (transparent, d.val[0], blend (s.val[2], d.val[0], a, inv));
v.val[1] = vbsl_u8 (transparent, d.val[1], blend (s.val[1], d.val[1], a, inv));
v.val[2] = vbsl_u8 (transparent, d.val[2], blend (s.val[0], d.val[2], a, inv));
v.val[3] = vbsl_u8 (transparent, d.val[3], vdup_n_u8 (0xff));
vst4_u8 ((guchar *) (pixels + i), v);
}
return i;
}
static gint
composite_565 (guint16 *pixels, const guchar *rgba, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgba += 32)
{
uint8x8x4_t s = vld4_u8 (rgba);
uint16x8_t d = vld1q_u16 (pixels + i);
uint8x8_t a = s.val[3], inv = vmvn_u8 (a);
uint8x8_t r = vmovn_u16 (vshrq_n_u16 (d, 8));
uint8x8_t g = vmovn_u16 (vshrq_n_u16 (d, 3));
uint8x8_t b = vmovn_u16 (vshlq_n_u16 (d, 3));
/* the bits of the pixel repeated up to 8 */
r = vsri_n_u8 (r, r, 5);
g = vsri_n_u8 (vand_u8 (g, vdup_n_u8 (0xfc)), g, 6);
b = vsri_n_u8 (b, b, 5);
vst1q_u16 (pixels + i, pack565 (blend (s.val[0], r, a, inv),
blend (s.val[1], g, a, inv),
blend (s.val[2], b, a, inv)));
}
return i;
}
/* c * a / 255 to the nearest */
static gint
rgba_to_argb (guint32 *out, const guchar *rgba, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgba += 32)
{
uint8x8x4_t s = vld4_u8 (rgba);
uint8x8x4_t v;
uint16x8_t t;
t = vmull_u8 (s.val[2], s.val[3]);
v.val[0] = vrshrn_n_u16 (vrsraq_n_u16 (t, t, 8), 8);
t = vmull_u8 (s.val[1], s.val[3]);
v.val[1] = vrshrn_n_u16 (vrsraq_n_u16 (t, t, 8), 8);
t = vmull_u8 (s.val[0], s.val[3]);
v.val[2] = vrshrn_n_u16 (vrsraq_n_u16 (t, t, 8), 8);
v.val[3] = s.val[3];
vst4_u8 ((guchar *) (out + i), v);
}
return i;
}
static gint
composite_555 (guint16 *pixels, const guchar *rgba, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgba += 32)
{
uint8x8x4_t s = vld4_u8 (rgba);
uint16x8_t d = vld1q_u16 (pixels + i);
uint8x8_t a = s.val[3], inv = vmvn_u8 (a);
uint8x8_t r = vmovn_u16 (vshrq_n_u16 (d, 7));
uint8x8_t g = vmovn_u16 (vshrq_n_u16 (d, 2));
uint8x8_t b = vmovn_u16 (vshlq_n_u16 (d, 3));
uint16x8_t v;
/* the bits of the pixel repeated up to 8 */
r = vsri_n_u8 (r, r, 5);
g = vsri_n_u8 (g, g, 5);
b = vsri_n_u8 (b, b, 5);
v = pack555 (blend (s.val[0], r, a, inv),
blend (s.val[1], g, a, inv),
blend (s.val[2], b, a, inv));
/* where nothing is drawn the unused bit stays as it was */
vst1q_u16 (pixels + i,
vbslq_u16 (vreinterpretq_u16_s16 (vmovl_s8 (vreinterpret_s8_u8 (vceq_u8 (a, vdup_n_u8 (0))))),
d, v));
}
return i;
}
void
_gdk_rgb_simd_init_neon (GdkRgbSimd *simd)
{
simd->name = "neon";
simd->rgb_to_x888 = rgb_to_x888;
simd->rgbx_to_x888 = rgbx_to_x888;
simd->rgb_to_565 = rgb_to_565;
simd->rgb_to_555 = rgb_to_555;
simd->composite_x888 = composite_x888;
simd->composite_565 = composite_565;
simd->composite_555 = composite_555;
simd->rgba_to_argb = rgba_to_argb;
}
#else
void
_gdk_rgb_simd_init_neon (GdkRgbSimd *simd)
{
}
#endif

300
gdk/gdkrgb-sse2.c Normal file
View file

@ -0,0 +1,300 @@
/* GDK - The GIMP Drawing Kit
* GdkRGB loops for SSE2
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include "gdkrgbsimd.h"
#if defined(__SSE2__)
#include <emmintrin.h>
/* x86 is little endian: an x888 pixel is the bytes B, G, R, 0xff */
#define SPLAT(v) _mm_set1_epi32 ((gint) (v))
/* The 12 bytes of four RGB pixels as lanes R | G << 8 | B << 16 */
static inline __m128i
rgb_lanes (__m128i v)
{
__m128i lo = _mm_unpacklo_epi32 (v, _mm_srli_si128 (v, 3));
__m128i hi = _mm_unpacklo_epi32 (_mm_srli_si128 (v, 6), _mm_srli_si128 (v, 9));
return _mm_unpacklo_epi64 (lo, hi);
}
/* Lanes R | G << 8 | B << 16 to x888 */
static inline __m128i
x888_of (__m128i v)
{
return _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xff)), 16),
_mm_and_si128 (v, SPLAT (0xff00))),
_mm_or_si128 (_mm_and_si128 (_mm_srli_epi32 (v, 16), SPLAT (0xff)),
SPLAT (0xff000000)));
}
/* Lanes R | G << 8 | B << 16 to 565, sign extended for packing */
static inline __m128i
rgb565_of (__m128i v)
{
v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xf8)), 8),
_mm_srli_epi32 (_mm_and_si128 (v, SPLAT (0xfc00)), 5)),
_mm_and_si128 (_mm_srli_epi32 (v, 19), SPLAT (0x1f)));
return _mm_srai_epi32 (_mm_slli_epi32 (v, 16), 16);
}
/* The same to 555, with the unused bit set as all of GdkRGB does */
static inline __m128i
rgb555_of (__m128i v)
{
v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xf8)), 7),
_mm_srli_epi32 (_mm_and_si128 (v, SPLAT (0xf800)), 6)),
_mm_or_si128 (_mm_and_si128 (_mm_srli_epi32 (v, 19), SPLAT (0x1f)),
SPLAT (0x8000)));
return _mm_srai_epi32 (_mm_slli_epi32 (v, 16), 16);
}
static gint
rgb_to_x888 (guint32 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgb += 24)
{
__m128i a = _mm_loadu_si128 ((const __m128i *) rgb);
__m128i b = _mm_loadl_epi64 ((const __m128i *) (rgb + 16));
__m128i c = _mm_or_si128 (_mm_srli_si128 (a, 12), _mm_slli_si128 (b, 4));
_mm_storeu_si128 ((__m128i *) (out + i), x888_of (rgb_lanes (a)));
_mm_storeu_si128 ((__m128i *) (out + i + 4), x888_of (rgb_lanes (c)));
}
return i;
}
static gint
rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n)
{
gint i;
for (i = 0; i + 4 <= n; i += 4, rgbx += 16)
_mm_storeu_si128 ((__m128i *) (out + i),
x888_of (_mm_loadu_si128 ((const __m128i *) rgbx)));
return i;
}
static gint
rgb_to_565 (guint16 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgb += 24)
{
__m128i a = _mm_loadu_si128 ((const __m128i *) rgb);
__m128i b = _mm_loadl_epi64 ((const __m128i *) (rgb + 16));
__m128i c = _mm_or_si128 (_mm_srli_si128 (a, 12), _mm_slli_si128 (b, 4));
_mm_storeu_si128 ((__m128i *) (out + i),
_mm_packs_epi32 (rgb565_of (rgb_lanes (a)),
rgb565_of (rgb_lanes (c))));
}
return i;
}
static gint
rgb_to_555 (guint16 *out, const guchar *rgb, gint n)
{
gint i;
for (i = 0; i + 8 <= n; i += 8, rgb += 24)
{
__m128i a = _mm_loadu_si128 ((const __m128i *) rgb);
__m128i b = _mm_loadl_epi64 ((const __m128i *) (rgb + 16));
__m128i c = _mm_or_si128 (_mm_srli_si128 (a, 12), _mm_slli_si128 (b, 4));
_mm_storeu_si128 ((__m128i *) (out + i),
_mm_packs_epi32 (rgb555_of (rgb_lanes (a)),
rgb555_of (rgb_lanes (c))));
}
return i;
}
/* (a * s + (255 - a) * d) / 255, rounded, in 16-bit lanes */
static inline __m128i
blend (__m128i s, __m128i d, __m128i a)
{
__m128i t = _mm_add_epi16 (_mm_add_epi16 (_mm_mullo_epi16 (s, a),
_mm_mullo_epi16 (d, _mm_sub_epi16 (_mm_set1_epi16 (255), a))),
_mm_set1_epi16 (0x80));
return _mm_srli_epi16 (_mm_add_epi16 (t, _mm_srli_epi16 (t, 8)), 8);
}
/* Alpha of each pixel in all four 16-bit lanes of the pixel */
static inline __m128i
alpha_of (__m128i v)
{
return _mm_shufflehi_epi16 (_mm_shufflelo_epi16 (v, 0xff), 0xff);
}
static gint
composite_x888 (guint32 *pixels, const guchar *rgba, gint n)
{
const __m128i zero = _mm_setzero_si128 ();
gint i;
for (i = 0; i + 4 <= n; i += 4, rgba += 16)
{
__m128i s = _mm_loadu_si128 ((const __m128i *) rgba);
__m128i d = _mm_loadu_si128 ((const __m128i *) (pixels + i));
__m128i transparent = _mm_cmpeq_epi32 (_mm_srli_epi32 (s, 24), zero);
__m128i lo, hi, v;
/* RGBA to BGRA, the order of the pixels */
s = _mm_or_si128 (_mm_and_si128 (s, SPLAT (0xff00ff00)),
_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (s, SPLAT (0xff)), 16),
_mm_and_si128 (_mm_srli_epi32 (s, 16), SPLAT (0xff))));
lo = _mm_unpacklo_epi8 (s, zero);
hi = _mm_unpackhi_epi8 (s, zero);
lo = blend (lo, _mm_unpacklo_epi8 (d, zero), alpha_of (lo));
hi = blend (hi, _mm_unpackhi_epi8 (d, zero), alpha_of (hi));
v = _mm_or_si128 (_mm_packus_epi16 (lo, hi), SPLAT (0xff000000));
/* fully transparent pixels stay as they are */
v = _mm_or_si128 (_mm_and_si128 (transparent, d), _mm_andnot_si128 (transparent, v));
_mm_storeu_si128 ((__m128i *) (pixels + i), v);
}
return i;
}
/* Eight 565 or 555 pixels at a time, each channel in a register */
static inline gint
composite_16 (guint16 *pixels, const guchar *rgba, gint n, const gint green_bits)
{
const gint red_shift = 5 + green_bits;
gint i;
for (i = 0; i + 8 <= n; i += 8, rgba += 32)
{
__m128i s0 = _mm_loadu_si128 ((const __m128i *) rgba);
__m128i s1 = _mm_loadu_si128 ((const __m128i *) (rgba + 16));
__m128i d = _mm_loadu_si128 ((const __m128i *) (pixels + i));
__m128i r = _mm_packs_epi32 (_mm_and_si128 (s0, SPLAT (0xff)),
_mm_and_si128 (s1, SPLAT (0xff)));
__m128i g = _mm_packs_epi32 (_mm_and_si128 (_mm_srli_epi32 (s0, 8), SPLAT (0xff)),
_mm_and_si128 (_mm_srli_epi32 (s1, 8), SPLAT (0xff)));
__m128i b = _mm_packs_epi32 (_mm_and_si128 (_mm_srli_epi32 (s0, 16), SPLAT (0xff)),
_mm_and_si128 (_mm_srli_epi32 (s1, 16), SPLAT (0xff)));
__m128i a = _mm_packs_epi32 (_mm_srli_epi32 (s0, 24), _mm_srli_epi32 (s1, 24));
__m128i dr = _mm_and_si128 (_mm_srli_epi16 (d, red_shift), _mm_set1_epi16 (0x1f));
__m128i dg = _mm_and_si128 (_mm_srli_epi16 (d, 5), _mm_set1_epi16 ((1 << green_bits) - 1));
__m128i db = _mm_and_si128 (d, _mm_set1_epi16 (0x1f));
__m128i v;
/* the bits of the pixel repeated up to 8 */
dr = _mm_or_si128 (_mm_slli_epi16 (dr, 3), _mm_srli_epi16 (dr, 2));
if (green_bits == 6)
dg = _mm_or_si128 (_mm_slli_epi16 (dg, 2), _mm_srli_epi16 (dg, 4));
else
dg = _mm_or_si128 (_mm_slli_epi16 (dg, 3), _mm_srli_epi16 (dg, 2));
db = _mm_or_si128 (_mm_slli_epi16 (db, 3), _mm_srli_epi16 (db, 2));
r = blend (r, dr, a);
g = blend (g, dg, a);
b = blend (b, db, a);
v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi16 (_mm_srli_epi16 (r, 3), red_shift),
_mm_slli_epi16 (_mm_srli_epi16 (g, 8 - green_bits), 5)),
_mm_srli_epi16 (b, 3));
if (green_bits == 5)
{
/* the unused bit is set, except where nothing is drawn */
__m128i transparent = _mm_cmpeq_epi16 (a, _mm_setzero_si128 ());
v = _mm_or_si128 (_mm_and_si128 (transparent, d),
_mm_andnot_si128 (transparent, _mm_or_si128 (v, _mm_set1_epi16 ((gshort) 0x8000))));
}
_mm_storeu_si128 ((__m128i *) (pixels + i), v);
}
return i;
}
static gint
composite_565 (guint16 *pixels, const guchar *rgba, gint n)
{
return composite_16 (pixels, rgba, n, 6);
}
static gint
composite_555 (guint16 *pixels, const guchar *rgba, gint n)
{
return composite_16 (pixels, rgba, n, 5);
}
/* c * a / 255 to the nearest, which (c * a + 0x80) * 257 >> 16 is */
static gint
rgba_to_argb (guint32 *out, const guchar *rgba, gint n)
{
const __m128i zero = _mm_setzero_si128 ();
gint i;
for (i = 0; i + 4 <= n; i += 4, rgba += 16)
{
__m128i s = _mm_loadu_si128 ((const __m128i *) rgba);
__m128i lo = _mm_unpacklo_epi8 (s, zero);
__m128i hi = _mm_unpackhi_epi8 (s, zero);
lo = _mm_mulhi_epu16 (_mm_add_epi16 (_mm_mullo_epi16 (lo, alpha_of (lo)), _mm_set1_epi16 (0x80)),
_mm_set1_epi16 (257));
hi = _mm_mulhi_epu16 (_mm_add_epi16 (_mm_mullo_epi16 (hi, alpha_of (hi)), _mm_set1_epi16 (0x80)),
_mm_set1_epi16 (257));
/* R, G, B to B, G, R: the bytes of 0xAARRGGBB */
lo = _mm_shufflehi_epi16 (_mm_shufflelo_epi16 (lo, 0xc6), 0xc6);
hi = _mm_shufflehi_epi16 (_mm_shufflelo_epi16 (hi, 0xc6), 0xc6);
/* the alpha byte as it was */
_mm_storeu_si128 ((__m128i *) (out + i),
_mm_or_si128 (_mm_and_si128 (_mm_packus_epi16 (lo, hi), SPLAT (0x00ffffff)),
_mm_and_si128 (s, SPLAT (0xff000000))));
}
return i;
}
void
_gdk_rgb_simd_init_sse2 (GdkRgbSimd *simd)
{
simd->name = "sse2";
simd->rgb_to_x888 = rgb_to_x888;
simd->rgbx_to_x888 = rgbx_to_x888;
simd->rgb_to_565 = rgb_to_565;
simd->rgb_to_555 = rgb_to_555;
simd->composite_x888 = composite_x888;
simd->composite_565 = composite_565;
simd->composite_555 = composite_555;
simd->rgba_to_argb = rgba_to_argb;
}
#else
void
_gdk_rgb_simd_init_sse2 (GdkRgbSimd *simd)
{
}
#endif

224
gdk/gdkrgb-ssse3.c Normal file
View file

@ -0,0 +1,224 @@
/* GDK - The GIMP Drawing Kit
* GdkRGB loops for SSSE3 (Atom, Core 2 and later): pshufb moves the
* bytes of pixels where SSE2 takes a row of shifts and masks
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include "gdkrgbsimd.h"
#if defined(__SSSE3__)
#include <tmmintrin.h>
/* x86 is little endian: an x888 pixel is the bytes B, G, R, 0xff */
#define SPLAT(v) _mm_set1_epi32 ((gint) (v))
#define BYTES(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
_mm_setr_epi8 (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
/* The first 12 bytes of four RGB pixels to B, G, R, 0 each */
static inline __m128i
bgr0_of_rgb (__m128i v)
{
return _mm_shuffle_epi8 (v, BYTES (2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1));
}
/* ... and to lanes R | G << 8 | B << 16, which SSE2 calls them */
static inline __m128i
rgb0_of_rgb (__m128i v)
{
return _mm_shuffle_epi8 (v, BYTES (0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, -1));
}
static gint
rgb_to_x888 (guint32 *out, const guchar *rgb, gint n)
{
const __m128i fill = SPLAT (0xff000000);
gint i;
for (i = 0; i + 16 <= n; i += 16, rgb += 48)
{
__m128i a = _mm_loadu_si128 ((const __m128i *) rgb);
__m128i b = _mm_loadu_si128 ((const __m128i *) (rgb + 16));
__m128i c = _mm_loadu_si128 ((const __m128i *) (rgb + 32));
_mm_storeu_si128 ((__m128i *) (out + i), _mm_or_si128 (bgr0_of_rgb (a), fill));
_mm_storeu_si128 ((__m128i *) (out + i + 4),
_mm_or_si128 (bgr0_of_rgb (_mm_alignr_epi8 (b, a, 12)), fill));
_mm_storeu_si128 ((__m128i *) (out + i + 8),
_mm_or_si128 (bgr0_of_rgb (_mm_alignr_epi8 (c, b, 8)), fill));
_mm_storeu_si128 ((__m128i *) (out + i + 12),
_mm_or_si128 (bgr0_of_rgb (_mm_srli_si128 (c, 4)), fill));
}
return i;
}
static gint
rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n)
{
const __m128i order = BYTES (2, 1, 0, -1, 6, 5, 4, -1, 10, 9, 8, -1, 14, 13, 12, -1);
gint i;
for (i = 0; i + 4 <= n; i += 4, rgbx += 16)
_mm_storeu_si128 ((__m128i *) (out + i),
_mm_or_si128 (_mm_shuffle_epi8 (_mm_loadu_si128 ((const __m128i *) rgbx), order),
SPLAT (0xff000000)));
return i;
}
/* Lanes R | G << 8 | B << 16 to 565 or 555, sign extended for packing.
* The bit 555 has no use for is set, as in all of GdkRGB's pixels. */
static inline __m128i
rgb16_of (__m128i v, const gint green_bits)
{
if (green_bits == 6)
v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xf8)), 8),
_mm_srli_epi32 (_mm_and_si128 (v, SPLAT (0xfc00)), 5)),
_mm_and_si128 (_mm_srli_epi32 (v, 19), SPLAT (0x1f)));
else
v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xf8)), 7),
_mm_srli_epi32 (_mm_and_si128 (v, SPLAT (0xf800)), 6)),
_mm_or_si128 (_mm_and_si128 (_mm_srli_epi32 (v, 19), SPLAT (0x1f)),
SPLAT (0x8000)));
return _mm_srai_epi32 (_mm_slli_epi32 (v, 16), 16);
}
static inline gint
rgb_to_16 (guint16 *out, const guchar *rgb, gint n, const gint green_bits)
{
gint i;
for (i = 0; i + 16 <= n; i += 16, rgb += 48)
{
__m128i a = _mm_loadu_si128 ((const __m128i *) rgb);
__m128i b = _mm_loadu_si128 ((const __m128i *) (rgb + 16));
__m128i c = _mm_loadu_si128 ((const __m128i *) (rgb + 32));
_mm_storeu_si128 ((__m128i *) (out + i),
_mm_packs_epi32 (rgb16_of (rgb0_of_rgb (a), green_bits),
rgb16_of (rgb0_of_rgb (_mm_alignr_epi8 (b, a, 12)), green_bits)));
_mm_storeu_si128 ((__m128i *) (out + i + 8),
_mm_packs_epi32 (rgb16_of (rgb0_of_rgb (_mm_alignr_epi8 (c, b, 8)), green_bits),
rgb16_of (rgb0_of_rgb (_mm_srli_si128 (c, 4)), green_bits)));
}
return i;
}
static gint
rgb_to_565 (guint16 *out, const guchar *rgb, gint n)
{
return rgb_to_16 (out, rgb, n, 6);
}
static gint
rgb_to_555 (guint16 *out, const guchar *rgb, gint n)
{
return rgb_to_16 (out, rgb, n, 5);
}
/* The alpha of each pixel in its four 16-bit lanes */
static inline __m128i
alpha_of (__m128i v)
{
return _mm_shuffle_epi8 (v, BYTES (6, 7, 6, 7, 6, 7, 6, 7, 14, 15, 14, 15, 14, 15, 14, 15));
}
/* (a * s + (255 - a) * d) / 255, rounded as GdkRGB's C code does */
static inline __m128i
blend (__m128i s, __m128i d, __m128i a)
{
__m128i t = _mm_add_epi16 (_mm_add_epi16 (_mm_mullo_epi16 (s, a),
_mm_mullo_epi16 (d, _mm_sub_epi16 (_mm_set1_epi16 (255), a))),
_mm_set1_epi16 (0x80));
return _mm_mulhi_epu16 (t, _mm_set1_epi16 (257));
}
static gint
composite_x888 (guint32 *pixels, const guchar *rgba, gint n)
{
const __m128i zero = _mm_setzero_si128 ();
const __m128i order = BYTES (2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15);
gint i;
for (i = 0; i + 4 <= n; i += 4, rgba += 16)
{
__m128i s = _mm_loadu_si128 ((const __m128i *) rgba);
__m128i d = _mm_loadu_si128 ((const __m128i *) (pixels + i));
__m128i transparent = _mm_cmpeq_epi32 (_mm_srli_epi32 (s, 24), zero);
__m128i lo, hi, v;
/* RGBA to BGRA, the order of the pixels */
s = _mm_shuffle_epi8 (s, order);
lo = _mm_unpacklo_epi8 (s, zero);
hi = _mm_unpackhi_epi8 (s, zero);
lo = blend (lo, _mm_unpacklo_epi8 (d, zero), alpha_of (lo));
hi = blend (hi, _mm_unpackhi_epi8 (d, zero), alpha_of (hi));
v = _mm_or_si128 (_mm_packus_epi16 (lo, hi), SPLAT (0xff000000));
/* fully transparent pixels stay as they are */
v = _mm_or_si128 (_mm_and_si128 (transparent, d), _mm_andnot_si128 (transparent, v));
_mm_storeu_si128 ((__m128i *) (pixels + i), v);
}
return i;
}
/* c * a / 255 to the nearest, which (c * a + 0x80) * 257 >> 16 is */
static gint
rgba_to_argb (guint32 *out, const guchar *rgba, gint n)
{
const __m128i zero = _mm_setzero_si128 ();
const __m128i order = BYTES (2, 1, 0, -1, 6, 5, 4, -1, 10, 9, 8, -1, 14, 13, 12, -1);
gint i;
for (i = 0; i + 4 <= n; i += 4, rgba += 16)
{
__m128i s = _mm_loadu_si128 ((const __m128i *) rgba);
__m128i lo = _mm_unpacklo_epi8 (s, zero);
__m128i hi = _mm_unpackhi_epi8 (s, zero);
lo = _mm_mulhi_epu16 (_mm_add_epi16 (_mm_mullo_epi16 (lo, alpha_of (lo)), _mm_set1_epi16 (0x80)),
_mm_set1_epi16 (257));
hi = _mm_mulhi_epu16 (_mm_add_epi16 (_mm_mullo_epi16 (hi, alpha_of (hi)), _mm_set1_epi16 (0x80)),
_mm_set1_epi16 (257));
/* R, G, B to B, G, R, and the alpha byte as it was */
_mm_storeu_si128 ((__m128i *) (out + i),
_mm_or_si128 (_mm_shuffle_epi8 (_mm_packus_epi16 (lo, hi), order),
_mm_and_si128 (s, SPLAT (0xff000000))));
}
return i;
}
void
_gdk_rgb_simd_init_ssse3 (GdkRgbSimd *simd)
{
simd->name = "ssse3";
simd->rgb_to_x888 = rgb_to_x888;
simd->rgbx_to_x888 = rgbx_to_x888;
simd->rgb_to_565 = rgb_to_565;
simd->rgb_to_555 = rgb_to_555;
simd->composite_x888 = composite_x888;
simd->rgba_to_argb = rgba_to_argb;
}
#else
void
_gdk_rgb_simd_init_ssse3 (GdkRgbSimd *simd)
{
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -127,7 +127,7 @@ void gdk_draw_indexed_image (GdkDrawable *drawable,
const guchar *buf,
gint rowstride,
GdkRgbCmap *cmap);
GType gdk_rgb_cmap_get_type (void) G_GNUC_CONST;
GType gdk_rgb_cmap_get_type (void);
GdkRgbCmap *gdk_rgb_cmap_copy (const GdkRgbCmap *cmap);
GdkRgbCmap *gdk_rgb_cmap_new (guint32 *colors,
gint n_colors);

View file

@ -1,742 +0,0 @@
/* GTK - The GIMP Toolkit
* High-precision GdkRGB image conversion
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include <string.h>
#include "gdkinternals.h"
#include "gdkrgb.h"
#include "gdkscreen.h"
#include "gdkalias.h"
typedef void (*GdkRgb16ConvFunc) (GdkImage *image,
gint x0,
gint y0,
gint width,
gint height,
const guint16 *buf,
gint rowstride);
#define GDK_RGB16_STORE_RGB(p, r, g, b, a) G_STMT_START { \
(p)[0] = (r) >> 8; \
(p)[1] = (g) >> 8; \
(p)[2] = (b) >> 8; \
(p) += 3; \
} G_STMT_END
#define GDK_RGB16_STORE_BGR(p, r, g, b, a) G_STMT_START { \
(p)[0] = (b) >> 8; \
(p)[1] = (g) >> 8; \
(p)[2] = (r) >> 8; \
(p) += 3; \
} G_STMT_END
#define GDK_RGB16_STORE_BGRA(p, r, g, b, a) G_STMT_START { \
(p)[0] = (b) >> 8; \
(p)[1] = (g) >> 8; \
(p)[2] = (r) >> 8; \
(p)[3] = 0xff; \
(p) += 4; \
} G_STMT_END
#define GDK_RGB16_STORE_ARGB(p, r, g, b, a) G_STMT_START { \
(p)[0] = 0xff; \
(p)[1] = (r) >> 8; \
(p)[2] = (g) >> 8; \
(p)[3] = (b) >> 8; \
(p) += 4; \
} G_STMT_END
#define GDK_RGB16_STORE_RGB0_NATIVE(p, r, g, b, a) G_STMT_START { \
guint32 pixel__ = (((b) >> 8) << 16) | \
(((g) >> 8) << 8) | \
((r) >> 8); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 4; \
} G_STMT_END
#define GDK_RGB16_STORE_565(p, r, g, b, a) G_STMT_START { \
guint16 pixel__ = ((r) & 0xf800) | \
(((g) & 0xfc00) >> 5) | \
((b) >> 11); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 2; \
} G_STMT_END
#define GDK_RGB16_STORE_565_BR(p, r, g, b, a) G_STMT_START { \
guint16 pixel__ = ((r) & 0xf800) | \
(((g) & 0xfc00) >> 5) | \
((b) >> 11); \
pixel__ = (pixel__ >> 8) | (pixel__ << 8); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 2; \
} G_STMT_END
#define GDK_RGB16_STORE_555(p, r, g, b, a) G_STMT_START { \
guint16 pixel__ = (((r) & 0xf800) >> 1) | \
(((g) & 0xf800) >> 6) | \
((b) >> 11); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 2; \
} G_STMT_END
#define GDK_RGB16_STORE_555_BR(p, r, g, b, a) G_STMT_START { \
guint16 pixel__ = (((r) & 0xf800) >> 1) | \
(((g) & 0xf800) >> 6) | \
((b) >> 11); \
pixel__ = (pixel__ >> 8) | (pixel__ << 8); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 2; \
} G_STMT_END
#define GDK_RGB16_STORE_101010_R_LOW_LE(p, r, g, b, a) \
G_STMT_START { \
guint32 pixel__ = (a) | \
(((b) >> 6) << 20) | \
(((g) >> 6) << 10) | \
((r) >> 6); \
pixel__ = GUINT32_TO_LE (pixel__); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 4; \
} G_STMT_END
#define GDK_RGB16_STORE_101010_B_LOW_LE(p, r, g, b, a) \
G_STMT_START { \
guint32 pixel__ = (a) | \
(((r) >> 6) << 20) | \
(((g) >> 6) << 10) | \
((b) >> 6); \
pixel__ = GUINT32_TO_LE (pixel__); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 4; \
} G_STMT_END
#define GDK_RGB16_STORE_101010_R_LOW_BE(p, r, g, b, a) \
G_STMT_START { \
guint32 pixel__ = (a) | \
(((b) >> 6) << 20) | \
(((g) >> 6) << 10) | \
((r) >> 6); \
pixel__ = GUINT32_TO_BE (pixel__); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 4; \
} G_STMT_END
#define GDK_RGB16_STORE_101010_B_LOW_BE(p, r, g, b, a) \
G_STMT_START { \
guint32 pixel__ = (a) | \
(((r) >> 6) << 20) | \
(((g) >> 6) << 10) | \
((b) >> 6); \
pixel__ = GUINT32_TO_BE (pixel__); \
memcpy ((p), &pixel__, sizeof (pixel__)); \
(p) += 4; \
} G_STMT_END
#define DEFINE_GDK_RGB16_CONVERTER(name, words, pixel_bytes, store) \
static void \
name (GdkImage *image, \
gint x0, \
gint y0, \
gint width, \
gint height, \
const guint16 *buf, \
gint rowstride) \
{ \
const guchar *row; \
const guint16 *src; \
guchar *dst_row; \
guchar *dst; \
guint32 r, g, b; \
guint32 alpha_mask; \
gint x, y; \
\
row = (const guchar *) buf; \
dst_row = ((guchar *) image->mem) + \
y0 * image->bpl + x0 * (pixel_bytes); \
alpha_mask = image->depth == 32 ? 0xc0000000U : 0; \
(void) alpha_mask; \
\
for (y = 0; y < height; y++) \
{ \
src = (const guint16 *) row; \
dst = dst_row; \
\
for (x = 0; x < width; x++) \
{ \
r = src[0]; \
g = src[1]; \
b = src[2]; \
src += (words); \
store (dst, r, g, b, alpha_mask); \
} \
\
row += rowstride; \
dst_row += image->bpl; \
} \
}
#define DEFINE_GDK_RGB16_PAIR(suffix, pixel_bytes, store) \
DEFINE_GDK_RGB16_CONVERTER (gdk_rgb48_convert_ ## suffix, \
3, pixel_bytes, store) \
DEFINE_GDK_RGB16_CONVERTER (gdk_rgbx64_convert_ ## suffix, \
4, pixel_bytes, store)
DEFINE_GDK_RGB16_PAIR (rgb, 3, GDK_RGB16_STORE_RGB)
DEFINE_GDK_RGB16_PAIR (bgr, 3, GDK_RGB16_STORE_BGR)
DEFINE_GDK_RGB16_PAIR (bgra, 4, GDK_RGB16_STORE_BGRA)
DEFINE_GDK_RGB16_PAIR (argb, 4, GDK_RGB16_STORE_ARGB)
DEFINE_GDK_RGB16_PAIR (rgb0_native, 4, GDK_RGB16_STORE_RGB0_NATIVE)
DEFINE_GDK_RGB16_PAIR (565, 2, GDK_RGB16_STORE_565)
DEFINE_GDK_RGB16_PAIR (565_br, 2, GDK_RGB16_STORE_565_BR)
DEFINE_GDK_RGB16_PAIR (555, 2, GDK_RGB16_STORE_555)
DEFINE_GDK_RGB16_PAIR (555_br, 2, GDK_RGB16_STORE_555_BR)
DEFINE_GDK_RGB16_PAIR (101010_r_low_le, 4,
GDK_RGB16_STORE_101010_R_LOW_LE)
DEFINE_GDK_RGB16_PAIR (101010_b_low_le, 4,
GDK_RGB16_STORE_101010_B_LOW_LE)
DEFINE_GDK_RGB16_PAIR (101010_r_low_be, 4,
GDK_RGB16_STORE_101010_R_LOW_BE)
DEFINE_GDK_RGB16_PAIR (101010_b_low_be, 4,
GDK_RGB16_STORE_101010_B_LOW_BE)
#undef DEFINE_GDK_RGB16_PAIR
#undef DEFINE_GDK_RGB16_CONVERTER
#undef GDK_RGB16_STORE_RGB
#undef GDK_RGB16_STORE_BGR
#undef GDK_RGB16_STORE_BGRA
#undef GDK_RGB16_STORE_ARGB
#undef GDK_RGB16_STORE_RGB0_NATIVE
#undef GDK_RGB16_STORE_565
#undef GDK_RGB16_STORE_565_BR
#undef GDK_RGB16_STORE_555
#undef GDK_RGB16_STORE_555_BR
#undef GDK_RGB16_STORE_101010_R_LOW_LE
#undef GDK_RGB16_STORE_101010_B_LOW_LE
#undef GDK_RGB16_STORE_101010_R_LOW_BE
#undef GDK_RGB16_STORE_101010_B_LOW_BE
static GdkRgb16ConvFunc
gdk_rgb16_select_converter (GdkDrawable *drawable,
gboolean is_rgbx,
GdkRgbDither dith)
{
GdkVisual *visual;
GdkByteOrder byte_order;
GdkScreen *screen;
guint32 red_mask, green_mask, blue_mask;
gint depth;
gint bits_per_pixel;
gboolean byte_reversed;
gboolean mask_rgb;
gboolean mask_bgr;
#define SELECT_PAIR(suffix) \
return is_rgbx ? gdk_rgbx64_convert_ ## suffix \
: gdk_rgb48_convert_ ## suffix
/*
* Preserve the existing GdkRGB dither path for maximum dithering
* and for unknown future values.
*/
if (dith != GDK_RGB_DITHER_NONE &&
dith != GDK_RGB_DITHER_NORMAL)
return NULL;
visual = gdk_drawable_get_visual (drawable);
if (visual == NULL)
return NULL;
if (gdk_visual_get_visual_type (visual) != GDK_VISUAL_TRUE_COLOR)
return NULL;
screen = gdk_visual_get_screen (visual);
depth = gdk_visual_get_depth (visual);
byte_order = gdk_visual_get_byte_order (visual);
gdk_visual_get_red_pixel_details (visual, &red_mask, NULL, NULL);
gdk_visual_get_green_pixel_details (visual, &green_mask, NULL, NULL);
gdk_visual_get_blue_pixel_details (visual, &blue_mask, NULL, NULL);
bits_per_pixel = _gdk_windowing_get_bits_for_depth
(gdk_screen_get_display (screen), depth);
#if G_BYTE_ORDER == G_BIG_ENDIAN
byte_reversed = byte_order == GDK_LSB_FIRST;
#else
byte_reversed = byte_order == GDK_MSB_FIRST;
#endif
mask_rgb = red_mask == 0xff0000 &&
green_mask == 0x00ff00 &&
blue_mask == 0x0000ff;
mask_bgr = red_mask == 0x0000ff &&
green_mask == 0x00ff00 &&
blue_mask == 0xff0000;
if (bits_per_pixel == 16 &&
depth == 16 &&
red_mask == 0xf800 &&
green_mask == 0x07e0 &&
blue_mask == 0x001f)
{
if (byte_reversed)
SELECT_PAIR (565_br);
SELECT_PAIR (565);
}
if (bits_per_pixel == 16 &&
depth == 15 &&
red_mask == 0x7c00 &&
green_mask == 0x03e0 &&
blue_mask == 0x001f)
{
if (byte_reversed)
SELECT_PAIR (555_br);
SELECT_PAIR (555);
}
if (bits_per_pixel == 24 &&
depth == 24 &&
((mask_rgb && byte_order == GDK_LSB_FIRST) ||
(mask_bgr && byte_order == GDK_MSB_FIRST)))
SELECT_PAIR (bgr);
if (bits_per_pixel == 24 &&
depth == 24 &&
((mask_rgb && byte_order == GDK_MSB_FIRST) ||
(mask_bgr && byte_order == GDK_LSB_FIRST)))
SELECT_PAIR (rgb);
if (bits_per_pixel == 32 &&
(depth == 24 || depth == 32) &&
mask_rgb &&
byte_order == GDK_MSB_FIRST)
SELECT_PAIR (argb);
if (bits_per_pixel == 32 &&
(depth == 24 || depth == 32) &&
mask_rgb &&
byte_order == GDK_LSB_FIRST)
SELECT_PAIR (bgra);
#if G_BYTE_ORDER == G_BIG_ENDIAN
if (bits_per_pixel == 32 &&
depth == 24 &&
mask_bgr &&
byte_order == GDK_MSB_FIRST)
SELECT_PAIR (rgb0_native);
#else
if (bits_per_pixel == 32 &&
depth == 24 &&
mask_bgr &&
byte_order == GDK_LSB_FIRST)
SELECT_PAIR (rgb0_native);
#endif
if (bits_per_pixel == 32 &&
(depth == 30 || depth == 32) &&
byte_order == GDK_LSB_FIRST &&
red_mask == 0x000003ff &&
green_mask == 0x000ffc00 &&
blue_mask == 0x3ff00000)
SELECT_PAIR (101010_r_low_le);
if (bits_per_pixel == 32 &&
(depth == 30 || depth == 32) &&
byte_order == GDK_LSB_FIRST &&
red_mask == 0x3ff00000 &&
green_mask == 0x000ffc00 &&
blue_mask == 0x000003ff)
SELECT_PAIR (101010_b_low_le);
if (bits_per_pixel == 32 &&
(depth == 30 || depth == 32) &&
byte_order == GDK_MSB_FIRST &&
red_mask == 0x000003ff &&
green_mask == 0x000ffc00 &&
blue_mask == 0x3ff00000)
SELECT_PAIR (101010_r_low_be);
if (bits_per_pixel == 32 &&
(depth == 30 || depth == 32) &&
byte_order == GDK_MSB_FIRST &&
red_mask == 0x3ff00000 &&
green_mask == 0x000ffc00 &&
blue_mask == 0x000003ff)
SELECT_PAIR (101010_b_low_be);
#undef SELECT_PAIR
return NULL;
}
static void
gdk_rgb16_draw_direct (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
const guint16 *buf,
gint pixel_words,
gint rowstride,
GdkRgb16ConvFunc converter)
{
GdkScreen *screen;
GdkImage *image;
const guint16 *tile;
gint depth;
gint x0, y0;
gint xs0, ys0;
gint width1, height1;
screen = gdk_drawable_get_screen (drawable);
depth = gdk_drawable_get_depth (drawable);
for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT)
{
height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT);
for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH)
{
width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH);
tile = (const guint16 *)
((const guchar *) buf +
y0 * rowstride +
x0 * pixel_words * sizeof (guint16));
image = _gdk_image_get_scratch (screen,
width1,
height1,
depth,
&xs0,
&ys0);
converter (image,
xs0,
ys0,
width1,
height1,
tile,
rowstride);
gdk_draw_image (drawable,
gc,
image,
xs0,
ys0,
x + x0,
y + y0,
width1,
height1);
}
}
}
static void
gdk_rgb16_draw_fallback (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
GdkRgbDither dith,
const guint16 *buf,
gint pixel_words,
gint rowstride,
gint xdith,
gint ydith)
{
const guchar *input_row;
const guint16 *input;
guchar *stage;
guchar *output;
gint stage_rowstride;
gint x0, y0;
gint x1, y1;
gint width1, height1;
stage = g_malloc (MIN (width, GDK_SCRATCH_IMAGE_WIDTH) *
MIN (height, GDK_SCRATCH_IMAGE_HEIGHT) * 3);
for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT)
{
height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT);
for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH)
{
width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH);
stage_rowstride = width1 * 3;
input_row = (const guchar *) buf +
y0 * rowstride +
x0 * pixel_words * sizeof (guint16);
output = stage;
for (y1 = 0; y1 < height1; y1++)
{
input = (const guint16 *) input_row;
for (x1 = 0; x1 < width1; x1++)
{
*output++ = input[0] >> 8;
*output++ = input[1] >> 8;
*output++ = input[2] >> 8;
input += pixel_words;
}
input_row += rowstride;
}
gdk_draw_rgb_image_dithalign (drawable,
gc,
x + x0,
y + y0,
width1,
height1,
dith,
stage,
stage_rowstride,
xdith,
ydith);
}
}
g_free (stage);
}
static void
gdk_draw_rgb16_image (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
GdkRgbDither dith,
const guint16 *buf,
gint rowstride,
gint xdith,
gint ydith,
gboolean is_rgbx)
{
GdkRgb16ConvFunc converter;
gint pixel_words;
g_return_if_fail (GDK_IS_DRAWABLE (drawable));
g_return_if_fail (GDK_IS_GC (gc));
g_return_if_fail (buf != NULL);
g_return_if_fail ((((guintptr) buf) & 1) == 0);
g_return_if_fail ((rowstride & 1) == 0);
if (width <= 0 || height <= 0)
return;
pixel_words = is_rgbx ? 4 : 3;
converter = gdk_rgb16_select_converter (drawable, is_rgbx, dith);
if (converter != NULL)
gdk_rgb16_draw_direct (drawable,
gc,
x,
y,
width,
height,
buf,
pixel_words,
rowstride,
converter);
else
gdk_rgb16_draw_fallback (drawable,
gc,
x,
y,
width,
height,
dith,
buf,
pixel_words,
rowstride,
xdith,
ydith);
}
/**
* gdk_draw_rgb_48_image:
* @drawable: a #GdkDrawable
* @gc: a #GdkGC
* @x: destination X coordinate
* @y: destination Y coordinate
* @width: image width
* @height: image height
* @dith: dithering mode
* @rgb_buf: host-endian RGB data with three 16-bit channels per pixel
* @rowstride: number of bytes between consecutive rows
*
* Draws 48-bit RGB image data.
**/
void
gdk_draw_rgb_48_image (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
GdkRgbDither dith,
const guint16 *rgb_buf,
gint rowstride)
{
gdk_draw_rgb16_image (drawable,
gc,
x,
y,
width,
height,
dith,
rgb_buf,
rowstride,
0,
0,
FALSE);
}
/**
* gdk_draw_rgb_48_image_dithalign:
* @drawable: a #GdkDrawable
* @gc: a #GdkGC
* @x: destination X coordinate
* @y: destination Y coordinate
* @width: image width
* @height: image height
* @dith: dithering mode
* @rgb_buf: host-endian RGB data with three 16-bit channels per pixel
* @rowstride: number of bytes between consecutive rows
* @xdith: X dither offset
* @ydith: Y dither offset
*
* Draws 48-bit RGB image data with explicit dither alignment.
**/
void
gdk_draw_rgb_48_image_dithalign (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
GdkRgbDither dith,
const guint16 *rgb_buf,
gint rowstride,
gint xdith,
gint ydith)
{
gdk_draw_rgb16_image (drawable,
gc,
x,
y,
width,
height,
dith,
rgb_buf,
rowstride,
xdith,
ydith,
FALSE);
}
/**
* gdk_draw_rgbx_64_image:
* @drawable: a #GdkDrawable
* @gc: a #GdkGC
* @x: destination X coordinate
* @y: destination Y coordinate
* @width: image width
* @height: image height
* @dith: dithering mode
* @rgbx_buf: host-endian RGBX data with four 16-bit channels per pixel
* @rowstride: number of bytes between consecutive rows
*
* Draws 64-bit RGBX image data. The X channel is ignored.
**/
void
gdk_draw_rgbx_64_image (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
GdkRgbDither dith,
const guint16 *rgbx_buf,
gint rowstride)
{
gdk_draw_rgb16_image (drawable,
gc,
x,
y,
width,
height,
dith,
rgbx_buf,
rowstride,
0,
0,
TRUE);
}
/**
* gdk_draw_rgbx_64_image_dithalign:
* @drawable: a #GdkDrawable
* @gc: a #GdkGC
* @x: destination X coordinate
* @y: destination Y coordinate
* @width: image width
* @height: image height
* @dith: dithering mode
* @rgbx_buf: host-endian RGBX data with four 16-bit channels per pixel
* @rowstride: number of bytes between consecutive rows
* @xdith: X dither offset
* @ydith: Y dither offset
*
* Draws 64-bit RGBX image data with explicit dither alignment.
* The X channel is ignored.
**/
void
gdk_draw_rgbx_64_image_dithalign (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
GdkRgbDither dith,
const guint16 *rgbx_buf,
gint rowstride,
gint xdith,
gint ydith)
{
gdk_draw_rgb16_image (drawable,
gc,
x,
y,
width,
height,
dith,
rgbx_buf,
rowstride,
xdith,
ydith,
TRUE);
}
#define __GDK_RGB16_C__
#include "gdkaliasdef.c"

304
gdk/gdkrgbsimd.c Normal file
View file

@ -0,0 +1,304 @@
/* GDK - The GIMP Drawing Kit
* Choosing the vector versions of GdkRGB loops for this CPU
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include "gdkrgbsimd.h"
#if defined(__i386__) || defined(__x86_64__)
#if defined(__GNUC__)
#include <cpuid.h>
#endif
#elif defined(__powerpc__) || defined(__ppc__) || defined(__arm__)
#if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)
#include <sys/auxv.h>
#elif defined(__APPLE__)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#endif
/* All instruction sets, from the least to the most preferred: each
* kernel comes from the last set that has it and the CPU can run */
static const GdkRgbSimdSet all_sets[] =
{
{ "mmx", _gdk_rgb_simd_init_mmx },
{ "mmxext", _gdk_rgb_simd_init_mmxext },
{ "3dnow", _gdk_rgb_simd_init_3dnow },
{ "3dnowext", _gdk_rgb_simd_init_3dnowext },
{ "sse2", _gdk_rgb_simd_init_sse2 },
{ "ssse3", _gdk_rgb_simd_init_ssse3 },
{ "avx2", _gdk_rgb_simd_init_avx2 },
{ "altivec", _gdk_rgb_simd_init_altivec },
{ "armv6", _gdk_rgb_simd_init_armv6 },
{ "neon", _gdk_rgb_simd_init_neon },
};
static const GdkRgbSimdOp all_ops[] =
{
{ "rgb_to_x888", G_STRUCT_OFFSET (GdkRgbSimd, rgb_to_x888) },
{ "rgbx_to_x888", G_STRUCT_OFFSET (GdkRgbSimd, rgbx_to_x888) },
{ "rgb_to_565", G_STRUCT_OFFSET (GdkRgbSimd, rgb_to_565) },
{ "rgb_to_555", G_STRUCT_OFFSET (GdkRgbSimd, rgb_to_555) },
{ "composite_x888", G_STRUCT_OFFSET (GdkRgbSimd, composite_x888) },
{ "composite_565", G_STRUCT_OFFSET (GdkRgbSimd, composite_565) },
{ "composite_555", G_STRUCT_OFFSET (GdkRgbSimd, composite_555) },
{ "rgba_to_argb", G_STRUCT_OFFSET (GdkRgbSimd, rgba_to_argb) },
};
#define OP(simd, i) G_STRUCT_MEMBER (gpointer, (simd), all_ops[i].offset)
/* The CPU's hardware capabilities word, as the kernel tells them */
#if (defined(__powerpc__) || defined(__arm__)) && \
(defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO))
static unsigned long
hwcap (void)
{
#if defined(HAVE_GETAUXVAL)
return getauxval (AT_HWCAP);
#else
unsigned long caps = 0;
if (elf_aux_info (AT_HWCAP, &caps, sizeof (caps)) != 0)
return 0;
return caps;
#endif
}
#endif
#if (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__)
/* AVX2: the CPU has it, and the system saves the wide registers
* (OSXSAVE, then XCR0 says SSE and AVX state) */
static gboolean
cpu_has_avx2 (unsigned int ecx)
{
unsigned int eax, ebx, ecx7, edx, xcr0_low, xcr0_high;
if ((ecx & (1 << 27)) == 0 || (ecx & (1 << 28)) == 0 ||
__get_cpuid_max (0, NULL) < 7)
return FALSE;
__cpuid_count (7, 0, eax, ebx, ecx7, edx);
if ((ebx & (1 << 5)) == 0)
return FALSE;
__asm__ (".byte 0x0f, 0x01, 0xd0" /* xgetbv, which old assemblers do not know */
: "=a" (xcr0_low), "=d" (xcr0_high) : "c" (0));
return (xcr0_low & 6) == 6;
}
#endif
/* Whether this CPU can run the set */
static gboolean
cpu_has (const gchar *set)
{
#if defined(__x86_64__)
unsigned int eax, ebx, ecx, edx;
/* every x86-64 CPU has SSE2, which beats the older sets */
if (strcmp (set, "sse2") == 0)
return TRUE;
if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
return FALSE;
if (strcmp (set, "ssse3") == 0)
return (ecx & (1 << 9)) != 0;
if (strcmp (set, "avx2") == 0)
return cpu_has_avx2 (ecx);
return FALSE;
#elif defined(__i386__) && defined(__GNUC__)
unsigned int eax, ebx, ecx, edx, ext = 0, max_ext;
if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
return FALSE;
/* CPUs without the extended leaves answer with something else */
max_ext = __get_cpuid_max (0x80000000, NULL);
if ((max_ext & 0xffff0000) == 0x80000000 && max_ext >= 0x80000001)
{
unsigned int a, b, c;
__cpuid (0x80000001, a, b, c, ext);
}
if (strcmp (set, "mmx") == 0)
return (edx & (1 << 23)) != 0;
/* the integer part of SSE, or AMD's extensions to MMX */
if (strcmp (set, "mmxext") == 0)
return (edx & (1 << 25)) != 0 || (ext & (1 << 22)) != 0;
if (strcmp (set, "3dnow") == 0)
return (ext & (1u << 31)) != 0;
if (strcmp (set, "3dnowext") == 0)
return (ext & (1 << 30)) != 0 && (ext & (1u << 31)) != 0 && (ext & (1 << 22)) != 0;
if (strcmp (set, "sse2") == 0)
return (edx & (1 << 26)) != 0;
if (strcmp (set, "ssse3") == 0)
return (ecx & (1 << 9)) != 0;
if (strcmp (set, "avx2") == 0)
return cpu_has_avx2 (ecx);
return FALSE;
#elif defined(__aarch64__)
return strcmp (set, "neon") == 0;
#elif defined(__arm__) && (defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO))
if (strcmp (set, "armv6") == 0)
{
#if defined(__ARM_ARCH) && __ARM_ARCH >= 6
return TRUE; /* what all of this is built for */
#elif defined(HAVE_GETAUXVAL)
/* "v6l", "v7l", "v8l" */
const gchar *platform = (const gchar *) getauxval (AT_PLATFORM);
return platform && platform[0] == 'v' && atoi (platform + 1) >= 6;
#else
return FALSE;
#endif
}
return strcmp (set, "neon") == 0 && (hwcap () & (1 << 12)) != 0; /* HWCAP_NEON */
#elif defined(__powerpc__) && (defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO))
return strcmp (set, "altivec") == 0 && (hwcap () & 0x10000000) != 0; /* PPC_FEATURE_HAS_ALTIVEC */
#elif defined(__ppc__) && defined(__APPLE__)
int vector_unit = 0;
size_t size = sizeof (vector_unit);
return strcmp (set, "altivec") == 0 &&
sysctlbyname ("hw.vectorunit", &vector_unit, &size, NULL, 0) == 0 && vector_unit;
#else
return FALSE;
#endif
}
/**
* _gdk_rgb_simd_sets:
* @n_sets: the number of sets
*
* The instruction sets this CPU can run, least preferred first. The
* init function of a set fills in only what is in it.
*/
const GdkRgbSimdSet *
_gdk_rgb_simd_sets (gint *n_sets)
{
static GdkRgbSimdSet sets[G_N_ELEMENTS (all_sets)];
static gint n = -1;
guint i;
if (n < 0)
{
n = 0;
for (i = 0; i < G_N_ELEMENTS (all_sets); i++)
if (cpu_has (all_sets[i].name))
{
GdkRgbSimd probe = { NULL, };
/* a set the compiler couldn't build fills in nothing */
all_sets[i].init (&probe);
if (probe.name)
sets[n++] = all_sets[i];
}
}
*n_sets = n;
return sets;
}
/**
* _gdk_rgb_simd_ops:
* @n_ops: the number of operations
*
* The names of the kernels and where they are in a #GdkRgbSimd.
*/
const GdkRgbSimdOp *
_gdk_rgb_simd_ops (gint *n_ops)
{
*n_ops = G_N_ELEMENTS (all_ops);
return all_ops;
}
/* GDK_RGB_SIMD picks sets by hand, to try them: "c" for none, a set
* for that one wherever it has a kernel, "op=set" or "op=c" for one
* kernel; several of these separated by commas, applied in order. */
static void
choose_by_hand (GdkRgbSimd *simd,
const gchar *spec,
const GdkRgbSimdSet *sets,
gint n_sets)
{
gchar **items = g_strsplit (spec, ",", -1);
gint i, k, s;
for (i = 0; items[i]; i++)
{
gchar *item = g_strstrip (items[i]);
gchar *eq = strchr (item, '=');
const gchar *set = eq ? eq + 1 : item;
GdkRgbSimd from = { NULL, };
if (eq)
*eq = '\0';
for (s = 0; s < n_sets; s++)
if (strcmp (sets[s].name, set) == 0)
{
sets[s].init (&from);
break;
}
if (s == n_sets && strcmp (set, "c") != 0)
{
g_warning ("GDK_RGB_SIMD: %s is not an instruction set this CPU has", set);
continue;
}
for (k = 0; k < (gint) G_N_ELEMENTS (all_ops); k++)
if (!eq || strcmp (item, all_ops[k].name) == 0)
OP (simd, k) = OP (&from, k);
}
simd->name = "by hand";
g_strfreev (items);
}
const GdkRgbSimd *
_gdk_rgb_simd_get (void)
{
static GdkRgbSimd simd = { "none", };
static gboolean done = FALSE;
if (!done)
{
const gchar *disable = g_getenv ("GDK_DISABLE_SIMD");
const gchar *spec = g_getenv ("GDK_RGB_SIMD");
const GdkRgbSimdSet *sets;
gint n_sets, s, k;
done = TRUE;
if (disable && *disable && *disable != '0')
return &simd;
sets = _gdk_rgb_simd_sets (&n_sets);
for (s = 0; s < n_sets; s++)
{
GdkRgbSimd set = { NULL, };
sets[s].init (&set);
for (k = 0; k < (gint) G_N_ELEMENTS (all_ops); k++)
if (OP (&set, k))
OP (&simd, k) = OP (&set, k);
simd.name = set.name;
}
if (spec && *spec)
choose_by_hand (&simd, spec, sets, n_sets);
}
return &simd;
}

84
gdk/gdkrgbsimd.h Normal file
View file

@ -0,0 +1,84 @@
/* GDK - The GIMP Drawing Kit
* Vector versions of GdkRGB loops
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
/* Vector versions of the busiest GdkRGB loops.
*
* Each converts pixels from the start of a row, as many as it likes, and
* returns how many; the C code does the rest. Pixels are words in the
* byte order of the machine:
*
* x888 0xffRRGGBB, 32 bits
* 565 RRRRRGGG GGGBBBBB, 16 bits
* 555 1RRRRRGG GGGBBBBB, 16 bits, with the unused bit set
* argb 0xAARRGGBB, 32 bits, R, G and B multiplied by A / 255,
* rounded to the nearest: cairo's ARGB32
*
* RGB and RGBA are bytes in that order; RGBA is not premultiplied.
* Blending rounds as GdkRGB's C code does, so the results are the same.
* No alignment is required of any pointer.
*/
#ifndef __GDK_RGB_SIMD_H__
#define __GDK_RGB_SIMD_H__
#include <glib.h>
G_BEGIN_DECLS
typedef struct _GdkRgbSimd GdkRgbSimd;
struct _GdkRgbSimd
{
const gchar *name;
gint (*rgb_to_x888) (guint32 *out, const guchar *rgb, gint n);
gint (*rgbx_to_x888) (guint32 *out, const guchar *rgbx, gint n);
gint (*rgb_to_565) (guint16 *out, const guchar *rgb, gint n);
gint (*rgb_to_555) (guint16 *out, const guchar *rgb, gint n);
gint (*composite_x888) (guint32 *pixels, const guchar *rgba, gint n);
gint (*composite_565) (guint16 *pixels, const guchar *rgba, gint n);
gint (*composite_555) (guint16 *pixels, const guchar *rgba, gint n);
gint (*rgba_to_argb) (guint32 *out, const guchar *rgba, gint n);
};
typedef struct
{
const gchar *name;
void (*init) (GdkRgbSimd *simd);
} GdkRgbSimdSet;
typedef struct
{
const gchar *name;
glong offset;
} GdkRgbSimdOp;
/* Each fills in what its instruction set does better than C; they are
* only called when the CPU has it. */
void _gdk_rgb_simd_init_mmx (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_mmxext (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_3dnow (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_3dnowext (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_sse2 (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_ssse3 (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_avx2 (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_altivec (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_armv6 (GdkRgbSimd *simd);
void _gdk_rgb_simd_init_neon (GdkRgbSimd *simd);
/* The kernels for this CPU, or none with GDK_DISABLE_SIMD set */
const GdkRgbSimd *_gdk_rgb_simd_get (void);
/* For trying them: the sets this CPU has and the kernels by name */
const GdkRgbSimdSet *_gdk_rgb_simd_sets (gint *n_sets);
const GdkRgbSimdOp *_gdk_rgb_simd_ops (gint *n_ops);
G_END_DECLS
#endif /* __GDK_RGB_SIMD_H__ */

View file

@ -27,6 +27,7 @@
#include "gdkwindow.h"
#include "gdkscreen.h"
#include "gdkintl.h"
#include "gdkinternals.h"
#include "gdkalias.h"
static void gdk_screen_dispose (GObject *object);
@ -541,5 +542,30 @@ gdk_screen_set_property (GObject *object,
}
}
/**
* gdk_screen_get_monitor_scale_factor:
* @screen: a #GdkScreen
* @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
*
* Returns the internal scale factor that maps from monitor coordinates
* to the actual device pixels, as in GTK+ 3: on traditional systems
* this is 1, on high density outputs it can be higher (typically 2).
* The coordinates of GDK and GTK+ stay in units of the scale 1.
*
* Returns: the scale factor
*
* Since: 2.24
*/
gint
gdk_screen_get_monitor_scale_factor (GdkScreen *screen,
gint monitor_num)
{
g_return_val_if_fail (GDK_IS_SCREEN (screen), 1);
g_return_val_if_fail (monitor_num >= 0, 1);
g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), 1);
return _gdk_windowing_screen_get_monitor_scale (screen, monitor_num);
}
#define __GDK_SCREEN_C__
#include "gdkaliasdef.c"

View file

@ -66,7 +66,7 @@ struct _GdkScreenClass
void (*monitors_changed) (GdkScreen *screen);
};
GType gdk_screen_get_type (void) G_GNUC_CONST;
GType gdk_screen_get_type (void);
GdkColormap *gdk_screen_get_default_colormap (GdkScreen *screen);
void gdk_screen_set_default_colormap (GdkScreen *screen,
GdkColormap *colormap);
@ -106,6 +106,8 @@ gint gdk_screen_get_monitor_height_mm (GdkScreen *screen,
gint monitor_num);
gchar * gdk_screen_get_monitor_plug_name (GdkScreen *screen,
gint monitor_num);
gint gdk_screen_get_monitor_scale_factor (GdkScreen *screen,
gint monitor_num);
void gdk_screen_broadcast_client_message (GdkScreen *screen,
GdkEvent *event);

View file

@ -97,7 +97,7 @@ struct _GdkVisual
gint GSEAL (blue_prec);
};
GType gdk_visual_get_type (void) G_GNUC_CONST;
GType gdk_visual_get_type (void);
#ifndef GDK_MULTIHEAD_SAFE
gint gdk_visual_get_best_depth (void);

File diff suppressed because it is too large Load diff

View file

@ -328,7 +328,7 @@ struct _GdkWindowObjectClass
/* Windows
*/
GType gdk_window_object_get_type (void) G_GNUC_CONST;
GType gdk_window_object_get_type (void);
GdkWindow* gdk_window_new (GdkWindow *parent,
GdkWindowAttr *attributes,
gint attributes_mask);
@ -341,6 +341,7 @@ GdkDisplay* gdk_window_get_display (GdkWindow *window);
GdkVisual* gdk_window_get_visual (GdkWindow *window);
int gdk_window_get_width (GdkWindow *window);
int gdk_window_get_height (GdkWindow *window);
gint gdk_window_get_scale_factor (GdkWindow *window);
GdkWindow* gdk_window_at_pointer (gint *win_x,
gint *win_y);
@ -679,6 +680,7 @@ void gdk_window_thaw_updates (GdkWindow *window);
void gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window);
void gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window);
void gdk_window_set_touch_emulation_libgtk_only (GdkWindow *window);
void gdk_window_process_all_updates (void);
void gdk_window_process_updates (GdkWindow *window,

View file

@ -150,7 +150,7 @@ struct _GdkWindowImplIface
};
/* Interface Functions */
GType gdk_window_impl_get_type (void) G_GNUC_CONST;
GType gdk_window_impl_get_type (void);
/* private definitions from gdkwindow.h */

View file

@ -92,7 +92,14 @@ gdk_OBJECTS = \
gdkrectangle.obj \
gdkregion-generic.obj \
gdkrgb.obj \
gdkrgb16.obj \
gdkrgbsimd.obj \
gdkrgb-mmx.obj \
gdkrgb-sse2.obj \
gdkrgb-ssse3.obj \
gdkrgb-avx2.obj \
gdkrgb-altivec.obj \
gdkrgb-armv6.obj \
gdkrgb-neon.obj \
gdkscreen.obj \
gdkselection.obj \
gdkvisual.obj \

View file

@ -14,7 +14,7 @@ print <<EOF;
#include <glib.h>
#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__)
#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__) && !defined(G_OS_WIN32)
EOF

View file

@ -32,7 +32,9 @@
if ((self = [super initWithFrame: frameRect]))
{
markedRange = NSMakeRange (NSNotFound, 0);
selectedRange = NSMakeRange (NSNotFound, 0);
/* the caret, not NSNotFound: without a location, macOS shows no
* window of accented characters when a key is held down */
selectedRange = NSMakeRange (0, 0);
}
return self;
@ -59,6 +61,14 @@
-(void) keyDown: (NSEvent *) theEvent
{
GDK_NOTE (EVENTS, g_print ("keyDown\n"));
/* A key held down for the window of accented characters (10.7 and
* later) calls none of the methods below while it repeats: the key is
* the input method's then. Any text, marked text or command clears
* or replaces this. */
g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY,
GUINT_TO_POINTER (GIC_FILTER_FILTERED));
[self interpretKeyEvents: [NSArray arrayWithObject: theEvent]];
}
@ -126,7 +136,8 @@
{
GDK_NOTE (EVENTS, g_print ("unmarkText\n"));
gchar *prev_str;
markedRange = selectedRange = NSMakeRange (NSNotFound, 0);
selectedRange = NSMakeRange (0, 0);
markedRange = NSMakeRange (NSNotFound, 0);
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT);
if (prev_str)
@ -184,11 +195,21 @@
GDK_NOTE (EVENTS, g_print ("doCommandBySelector\n"));
if ([self respondsToSelector: aSelector])
[self performSelector: aSelector];
/* whatever the command, GTK+ handles the key itself (as in GTK+ 3.24) */
g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY,
GUINT_TO_POINTER (GIC_FILTER_PASSTHRU));
}
/* This gets called on OS X 10.6 and upwards from interpretKeyEvents */
-(void)insertText: (id)aString replacementRange: (NSRange)replacementRange
{
/* the window of accented characters replaces the character typed
* before it: the input method deletes it around the cursor */
if (replacementRange.location != NSNotFound && replacementRange.length > 0)
g_object_set_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT_REPLACE_LEN,
GINT_TO_POINTER (replacementRange.length));
[self insertText:aString];
}
@ -223,6 +244,7 @@
else
{
str = [string UTF8String];
selectedRange = NSMakeRange ([string length], 0);
}
prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT);
@ -530,6 +552,20 @@
GUINT_TO_POINTER (GIC_FILTER_PASSTHRU));
}
-(void)scrollPageDown: (id)sender
{
GDK_NOTE (EVENTS, g_message ("scrollPageDown"));
g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY,
GUINT_TO_POINTER (GIC_FILTER_PASSTHRU));
}
-(void)scrollPageUp: (id)sender
{
GDK_NOTE (EVENTS, g_message ("scrollPageUp"));
g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY,
GUINT_TO_POINTER (GIC_FILTER_PASSTHRU));
}
-(void)selectAll: (id)sender
{
GDK_NOTE (EVENTS, g_print ("selectAll\n"));
@ -618,6 +654,45 @@
[super viewWillDraw];
}
/* What AppKit invalidates goes into GDK's bookkeeping too, so that
* drawRect: knows all of it (see _gdk_quartz_use_gdk_invalidation()) */
-(void)noteNeedsDisplayInRect: (NSRect)rect
{
GdkWindowImplQuartz *impl;
GdkRectangle gdk_rect;
NSRect bounds = [self bounds];
if (!gdk_window || GDK_WINDOW_DESTROYED (gdk_window) ||
!_gdk_quartz_use_gdk_invalidation ())
return;
impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (gdk_window)->impl);
rect = NSIntersectionRect (rect, bounds);
if (NSIsEmptyRect (rect))
return;
gdk_rect.x = floor (rect.origin.x);
gdk_rect.y = floor (rect.origin.y);
gdk_rect.width = ceil (rect.origin.x + rect.size.width) - gdk_rect.x;
gdk_rect.height = ceil (rect.origin.y + rect.size.height) - gdk_rect.y;
if (!impl->needs_display_region)
impl->needs_display_region = gdk_region_new ();
gdk_region_union_with_rect (impl->needs_display_region, &gdk_rect);
}
-(void)setNeedsDisplayInRect: (NSRect)rect
{
[self noteNeedsDisplayInRect: rect];
[super setNeedsDisplayInRect: rect];
}
-(void)setNeedsDisplay: (BOOL)flag
{
if (flag)
[self noteNeedsDisplayInRect: [self bounds]];
[super setNeedsDisplay: flag];
}
-(void)drawRect: (NSRect)rect
{
GdkRectangle gdk_rect;
@ -626,7 +701,7 @@
const NSRect *drawn_rects;
NSInteger count;
int i;
GdkRegion *region;
GdkRegion *region, *needs;
if (GDK_WINDOW_DESTROYED (gdk_window))
return;
@ -648,7 +723,13 @@
*/
[NSGraphicsContext saveGraphicsState];
[[NSColor windowBackgroundColor] setFill];
if (impl->background_color_set)
[[NSColor colorWithCalibratedRed: impl->background_color.red / 65535.0
green: impl->background_color.green / 65535.0
blue: impl->background_color.blue / 65535.0
alpha: 1.0] setFill];
else
[[NSColor windowBackgroundColor] setFill];
[NSBezierPath fillRect: rect];
[NSGraphicsContext restoreGraphicsState];
@ -656,25 +737,49 @@
return;
}
/* Clear our own bookkeeping of regions that need display */
if (impl->needs_display_region)
/* Our own bookkeeping of what needs display; taken here, as an
* expose may invalidate again */
needs = impl->needs_display_region;
impl->needs_display_region = NULL;
if (needs && _gdk_quartz_use_gdk_invalidation () &&
!NSContainsRect (rect, [self bounds]))
{
gdk_region_destroy (impl->needs_display_region);
impl->needs_display_region = NULL;
/* Layer-backed views (10.14 and newer) merge the invalidated
* rects into one, or give the whole view: the windows of two
* small meters in opposite corners would expose all between.
* What GDK and AppKit invalidated is known here exactly (from
* Ardour's YTK). */
GdkRegion *drawing;
gdk_rect.x = rect.origin.x;
gdk_rect.y = rect.origin.y;
gdk_rect.width = rect.size.width;
gdk_rect.height = rect.size.height;
drawing = gdk_region_rectangle (&gdk_rect);
region = needs;
needs = NULL;
gdk_region_intersect (region, drawing);
gdk_region_destroy (drawing);
}
else
{
[self getRectsBeingDrawn: &drawn_rects count: &count];
region = gdk_region_new ();
for (i = 0; i < count; i++)
{
gdk_rect.x = drawn_rects[i].origin.x;
gdk_rect.y = drawn_rects[i].origin.y;
gdk_rect.width = drawn_rects[i].size.width;
gdk_rect.height = drawn_rects[i].size.height;
gdk_region_union_with_rect (region, &gdk_rect);
}
}
[self getRectsBeingDrawn: &drawn_rects count: &count];
region = gdk_region_new ();
for (i = 0; i < count; i++)
{
gdk_rect.x = drawn_rects[i].origin.x;
gdk_rect.y = drawn_rects[i].origin.y;
gdk_rect.width = drawn_rects[i].size.width;
gdk_rect.height = drawn_rects[i].size.height;
gdk_region_union_with_rect (region, &gdk_rect);
}
if (needs)
gdk_region_destroy (needs);
impl->in_paint_rect_count++;
_gdk_window_process_updates_recurse (gdk_window, region);

View file

@ -26,6 +26,7 @@
#define TIC_SELECTED_POS "tic-selected-pos"
#define TIC_SELECTED_LEN "tic-selected-len"
#define TIC_INSERT_TEXT "tic-insert-text"
#define TIC_INSERT_TEXT_REPLACE_LEN "tic-insert-text-replace-len"
#define TIC_IN_KEY_DOWN "tic-in-key-down"
/* GtkIMContext */

View file

@ -69,6 +69,9 @@
_gdk_quartz_window_attach_to_parent (window);
gdk_synthesize_window_state (window, GDK_WINDOW_STATE_ICONIFIED, 0);
/* newer systems may come back with stale contents (Ardour) */
[[self contentView] setNeedsDisplay:YES];
}
-(void)windowDidBecomeKey:(NSNotification *)aNotification
@ -429,9 +432,13 @@
return YES;
}
-(BOOL)isInManualResize
/* Used by gdkevents-quartz.c to decide if our sendEvent() handler above
* will see the event or if it will be subjected to standard processing
* by GDK.
*/
-(BOOL)isInManualResizeOrMove
{
return inManualResize;
return inManualResize || inManualMove;
}
-(void)beginManualResize

View file

@ -39,7 +39,7 @@
-(BOOL)isInMove;
-(void)beginManualMove;
-(BOOL)trackManualMove;
-(BOOL)isInManualResize;
-(BOOL)isInManualResizeOrMove;
-(void)beginManualResize;
-(BOOL)trackManualResize;
-(void)showAndMakeKey:(BOOL)makeKey;

View file

@ -79,6 +79,11 @@ _gdk_windowing_create_cairo_surface (GdkDrawable *drawable,
surface_data,
gdk_quartz_cairo_surface_destroy);
/* HiDPI: AppKit puts the points on the pixels of a Retina screen;
* pixbufs with a picture of those pixels use it */
if (cg_context && GDK_IS_WINDOW_IMPL_QUARTZ (drawable))
_gdk_cairo_surface_set_hidpi_scale (surface, _gdk_windowing_drawable_get_scale (drawable));
return surface;
}
@ -100,7 +105,13 @@ gdk_quartz_ref_cairo_surface (GdkDrawable *drawable)
width, height);
}
else
cairo_surface_reference (impl->cairo_surface);
{
cairo_surface_reference (impl->cairo_surface);
/* HiDPI: the window may be on a screen of another scale by now */
if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable))
_gdk_cairo_surface_set_hidpi_scale (impl->cairo_surface,
_gdk_windowing_drawable_get_scale (drawable));
}
return impl->cairo_surface;
}
@ -652,21 +663,34 @@ gdk_quartz_draw_pixbuf (GdkDrawable *drawable,
void *data;
int rowstride, pixbuf_width, pixbuf_height;
gboolean has_alpha;
GdkPixbuf *picture = pixbuf;
if (!context)
return;
pixbuf_width = gdk_pixbuf_get_width (pixbuf);
pixbuf_height = gdk_pixbuf_get_height (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
data = gdk_pixbuf_get_pixels (pixbuf);
/* HiDPI: on a Retina screen the picture made for it, drawn into the
* same points */
if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable))
{
GdkPixbuf *hires = _gdk_pixbuf_get_hires (pixbuf, _gdk_windowing_drawable_get_scale (drawable));
if (hires)
picture = hires;
}
rowstride = gdk_pixbuf_get_rowstride (picture);
has_alpha = gdk_pixbuf_get_has_alpha (picture);
data = gdk_pixbuf_get_pixels (picture);
colorspace = CGColorSpaceCreateDeviceRGB ();
data_provider = CGDataProviderCreateWithData (NULL, data, pixbuf_height * rowstride, NULL);
data_provider = CGDataProviderCreateWithData (NULL, data,
gdk_pixbuf_get_height (picture) * rowstride, NULL);
image = CGImageCreate (pixbuf_width, pixbuf_height, 8,
image = CGImageCreate (gdk_pixbuf_get_width (picture), gdk_pixbuf_get_height (picture), 8,
has_alpha ? 32 : 24, rowstride,
colorspace,
has_alpha ? kCGImageAlphaLast : 0,
@ -844,14 +868,16 @@ gdk_quartz_drawable_get_context (GdkDrawable *drawable,
void
_gdk_quartz_drawable_flush (GdkDrawable *drawable)
{
static struct timeval prev_tv;
/* intervals on the monotonic clock: setting the clock, or a 32-bit
* time_t after 2038, does not stop the flushing */
static gint64 prev_time;
static gint intervals[4];
static gint index;
struct timeval tv;
gint64 now;
gint ms;
gettimeofday (&tv, NULL);
ms = (tv.tv_sec - prev_tv.tv_sec) * 1000 + (tv.tv_usec - prev_tv.tv_usec) / 1000;
now = g_get_monotonic_time ();
ms = (gint) MIN ((now - prev_time) / 1000, G_MAXINT / 8);
intervals[index++ % 4] = ms;
if (drawable)
@ -868,11 +894,11 @@ _gdk_quartz_drawable_flush (GdkDrawable *drawable)
[window_impl->toplevel flushWindow];
}
prev_tv = tv;
prev_time = now;
}
}
else
prev_tv = tv;
prev_time = now;
}
void

View file

@ -25,6 +25,7 @@
#include <sys/sysctl.h>
#include <pthread.h>
#include <unistd.h>
#include <math.h>
#import <Cocoa/Cocoa.h>
#include <Carbon/Carbon.h>
@ -225,6 +226,19 @@ _gdk_quartz_events_break_all_grabs (guint32 time)
_gdk_display_pointer_grab_update (_gdk_display, 0);
}
/* The touchpad gestures of Mac OS X 10.5.2 and later: a pinch
* (magnify) and a swipe with three fingers. Older SDKs do not know
* them; Mac OS X before 10.5.2 never sends them. */
#define GDK_QUARTZ_EVENT_MAGNIFY 30
#define GDK_QUARTZ_EVENT_SWIPE 31
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
@interface NSEvent (GdkTouchpadGestures)
- (CGFloat)magnification;
@end
#endif
static void
fixup_event (GdkEvent *event)
{
@ -250,6 +264,12 @@ append_event (GdkEvent *event,
_gdk_windowing_got_event (_gdk_display, node, event, 0);
}
static void
append_scroll_event (GdkEvent *event)
{
append_event (event, TRUE);
}
static gint
gdk_event_apply_filters (NSEvent *nsevent,
GdkEvent *event,
@ -400,11 +420,14 @@ get_event_mask_from_ns_event (NSEvent *nsevent)
case NSMouseMoved:
return GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK;
case NSScrollWheel:
case GDK_QUARTZ_EVENT_MAGNIFY: /* scroll steps with Ctrl */
/* Since applications that want button press events can get
* scroll events on X11 (since scroll wheel events are really
* button press events there), we need to use GDK_BUTTON_PRESS_MASK too.
*/
return GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK;
case GDK_QUARTZ_EVENT_SWIPE: /* the back and forward buttons */
return GDK_BUTTON_PRESS_MASK;
case NSLeftMouseDragged:
return (GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK |
@ -545,6 +568,29 @@ get_toplevel_from_ns_event (NSEvent *nsevent,
* here, not very nice.
*/
_gdk_quartz_events_break_all_grabs (get_time_from_ns_event (nsevent));
/* Check if the event occurred on the titlebar. If it did,
* explicitly return NULL to prevent going through the
* fallback path, which could match the window that is
* directly under the titlebar.
*/
if (view_point.y < 0 &&
view_point.x >= view_frame.origin.x &&
view_point.x < view_frame.origin.x + view_frame.size.width)
{
NSView *superview = [view superview];
if (superview)
{
NSRect superview_frame = [superview frame];
int titlebar_height = superview_frame.size.height -
view_frame.size.height;
if (titlebar_height > 0 && view_point.y >= -titlebar_height)
{
return NULL;
}
}
}
}
else
{
@ -714,6 +760,48 @@ find_toplevel_under_pointer (GdkDisplay *display,
/* This function finds the correct window to send an event to, taking
* into account grabs, event propagation, and event masks.
*/
/* A native view of the program inside a GDK window (a plugin's interface,
* video, a web view) that took a mouse button; the pointer events stay
* with Cocoa until the button is up (from Ardour's YTK) */
static NSView *foreign_mouse_down_view;
/* whether the pointer is over a view of the program's own, not GDK's,
* inside @toplevel; a press there keeps the following events for it */
static gboolean
pointer_on_foreign_view (NSEvent *nsevent,
GdkWindow *toplevel)
{
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl);
NSView *content, *hit;
NSPoint point;
if (!impl || !impl->view || [nsevent window] != impl->toplevel)
return FALSE;
content = impl->view;
if ([[content subviews] count] == 0)
return FALSE;
point = [nsevent locationInWindow];
if ([content superview])
point = [[content superview] convertPoint:point fromView:nil];
hit = [content hitTest:point];
if (hit == nil || [hit isKindOfClass:[GdkQuartzView class]])
return FALSE;
switch ([nsevent type])
{
case NSLeftMouseDown:
case NSRightMouseDown:
case NSOtherMouseDown:
foreign_mouse_down_view = hit;
break;
default:
break;
}
return TRUE;
}
static GdkWindow *
find_window_for_ns_event (NSEvent *nsevent,
gint *x,
@ -745,6 +833,8 @@ find_window_for_ns_event (NSEvent *nsevent,
case NSOtherMouseUp:
case NSMouseMoved:
case NSScrollWheel:
case GDK_QUARTZ_EVENT_MAGNIFY:
case GDK_QUARTZ_EVENT_SWIPE:
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged:
@ -752,6 +842,14 @@ find_window_for_ns_event (NSEvent *nsevent,
GdkDisplay *display;
GdkPointerGrabInfo *grab;
if (foreign_mouse_down_view)
{
if (event_type == NSLeftMouseUp || event_type == NSRightMouseUp ||
event_type == NSOtherMouseUp)
foreign_mouse_down_view = nil;
return NULL;
}
display = gdk_drawable_get_display (toplevel);
/* From the docs for XGrabPointer:
@ -845,6 +943,9 @@ find_window_for_ns_event (NSEvent *nsevent,
*y = y_tmp;
}
if (pointer_on_foreign_view (nsevent, toplevel))
return NULL;
return toplevel;
}
}
@ -857,8 +958,36 @@ find_window_for_ns_event (NSEvent *nsevent,
*/
if ([view trackingRect] == [nsevent trackingNumber])
return toplevel;
else
return NULL;
/* macOS 13 no longer sends the events of the tracking rect, but
* those of the cursor rects, which earlier ones were left out:
* they come 4 pixels outside the frame of the window (the same
* fix as GTK+ 3 and Ardour's YTK) */
if (gdk_quartz_osx_version () >= GDK_OSX_VENTURA &&
(![nsevent respondsToSelector:@selector(trackingArea)] ||
[(id) nsevent trackingArea] == nil))
{
const CGFloat border_width = 4;
NSRect frame = [[nsevent window] frame];
gboolean inside, at_edge;
frame.origin.x -= border_width;
frame.origin.y -= border_width;
frame.size.width += 2 * border_width;
frame.size.height += 2 * border_width;
inside = (screen_point.x >= frame.origin.x &&
screen_point.x <= frame.origin.x + frame.size.width &&
screen_point.y >= frame.origin.y &&
screen_point.y <= frame.origin.y + frame.size.height);
at_edge = (screen_point.x >= frame.origin.x - 1 &&
screen_point.x <= frame.origin.x + frame.size.width + 1 &&
screen_point.y >= frame.origin.y - 1 &&
screen_point.y <= frame.origin.y + frame.size.height + 1);
if ((event_type == NSMouseEntered && inside) || at_edge)
return toplevel;
}
return NULL;
case NSKeyDown:
case NSKeyUp:
@ -1004,6 +1133,72 @@ fill_scroll_event (GdkWindow *window,
event->scroll.device = _gdk_display->core_pointer;
}
/* A pinch becomes scroll steps with Ctrl and a swipe the back or
* forward button, for programs that know nothing of gestures
* (gdkevents.c); the first event goes into @event */
static gboolean
touchpad_gesture_event (GdkWindow *window,
GdkEvent *event,
NSEvent *nsevent,
gint x,
gint y,
gint x_root,
gint y_root)
{
static gdouble pinch_rest;
static NSTimeInterval pinch_time;
GdkEvent template_event;
GList *events, *l;
memset (&template_event, 0, sizeof template_event);
fill_scroll_event (window, &template_event, nsevent, x, y, x_root, y_root, GDK_SCROLL_UP);
if ([nsevent type] == GDK_QUARTZ_EVENT_MAGNIFY)
{
CGFloat magnification;
if (![nsevent respondsToSelector:@selector(magnification)])
return FALSE;
magnification = [nsevent magnification];
if (magnification <= -1)
return FALSE;
/* a pause starts a new pinch */
if ([nsevent timestamp] - pinch_time > 0.3)
pinch_rest = 0;
pinch_time = [nsevent timestamp];
events = _gdk_event_touchpad_pinch (&template_event, log1p (magnification), &pinch_rest);
}
else
{
/* deltaX is 1 for a swipe to the left: forward, as on X11 */
events = _gdk_event_touchpad_swipe (&template_event, - [nsevent deltaX]);
}
if (!events)
return FALSE;
/* the first one is @event, the window of which gets its reference
* from the caller */
*event = *(GdkEvent *) events->data;
((GdkEventPrivate *) event)->flags |= GDK_EVENT_TOUCHPAD_EMULATED;
gdk_event_free (events->data);
for (l = events->next; l; l = l->next)
{
GdkEvent *other = l->data;
/* append_event() takes a reference of its own */
g_object_unref (other->any.window);
append_event (other, TRUE);
}
g_list_free (events);
return TRUE;
}
static void
fill_key_event (GdkWindow *window,
GdkEvent *event,
@ -1387,10 +1582,10 @@ gdk_event_translate (GdkEvent *event,
return FALSE;
}
/* Also when in a manual resize, we ignore events so that these are
* pushed to GdkQuartzWindow's sendEvent handler.
/* Also when in a manual resize or move, we ignore events so that
* these are pushed to GdkQuartzWindow's sendEvent handler.
*/
if ([(GdkQuartzWindow *)nswindow isInManualResize])
if ([(GdkQuartzWindow *)nswindow isInManualResizeOrMove])
return FALSE;
/* Find the right GDK window to send the event to, taking grabs and
@ -1489,32 +1684,46 @@ gdk_event_translate (GdkEvent *event,
case NSScrollWheel:
{
float dx = [nsevent deltaX];
float dy = [nsevent deltaY];
GdkScrollDirection direction;
/* Trackpads and the Magic Mouse tell how far to scroll in
* pixels, as GTK+ 3 takes them, and in lines, which make up
* whole steps of the wheel; a plain wheel just turns, a step
* each time, as before */
static gdouble rest[2];
GdkEvent scroll;
gdouble dx = [nsevent deltaX];
gdouble dy = [nsevent deltaY];
gdouble px = 0, py = 0;
gboolean precise = FALSE;
if (dy != 0)
/* from 10.7; older SDKs do not know these */
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
precise = [nsevent respondsToSelector:@selector(hasPreciseScrollingDeltas)] &&
[nsevent hasPreciseScrollingDeltas];
if (precise)
{
if (dy < 0.0)
direction = GDK_SCROLL_DOWN;
else
direction = GDK_SCROLL_UP;
fill_scroll_event (window, event, nsevent, x, y, x_root, y_root, direction);
px = - [nsevent scrollingDeltaX];
py = - [nsevent scrollingDeltaY];
}
else
#endif
{
dx = dx > 0 ? 1 : dx < 0 ? -1 : 0;
dy = dy > 0 ? 1 : dy < 0 ? -1 : 0;
rest[0] = rest[1] = 0;
}
if (dx != 0)
{
if (dx < 0.0)
direction = GDK_SCROLL_RIGHT;
else
direction = GDK_SCROLL_LEFT;
fill_scroll_event (window, event, nsevent, x, y, x_root, y_root, direction);
}
memset (&scroll, 0, sizeof scroll);
fill_scroll_event (window, &scroll, nsevent, x, y, x_root, y_root, GDK_SCROLL_SMOOTH);
_gdk_event_emit_scroll (event, &scroll, precise, px, py, - dx, - dy, rest,
append_scroll_event);
}
break;
case GDK_QUARTZ_EVENT_MAGNIFY:
case GDK_QUARTZ_EVENT_SWIPE:
return_val = touchpad_gesture_event (window, event, nsevent, x, y, x_root, y_root);
break;
case NSMouseExited:
if (WINDOW_IS_TOPLEVEL (window))
[[NSCursor arrowCursor] set];

View file

@ -22,6 +22,8 @@
#include "gdktypes.h"
#include "gdkprivate.h"
#include "gdkquartz.h"
#include "gdkprivate-quartz.h"
#include <stdlib.h>
GdkDisplay *_gdk_display = NULL;
GdkScreen *_gdk_screen = NULL;
@ -57,3 +59,43 @@ gdk_quartz_osx_version (void)
else
return minor;
}
/* -1: not set, GDK_QUARTZ_COCOA_INVALIDATION or the version decide */
static gint use_cocoa_invalidation = -1;
/**
* gdk_quartz_set_use_cocoa_invalidation:
* @use: %TRUE to expose what AppKit says is being drawn
*
* From macOS 10.14 GDK exposes exactly what it and AppKit invalidated,
* not the merged rectangles of the layer-backed views; %TRUE goes back
* to those (as in Ardour's YTK). The environment variable
* GDK_QUARTZ_COCOA_INVALIDATION=1 does the same.
*/
void
gdk_quartz_set_use_cocoa_invalidation (gboolean use)
{
use_cocoa_invalidation = use != FALSE;
}
gboolean
gdk_quartz_get_use_cocoa_invalidation (void)
{
return !_gdk_quartz_use_gdk_invalidation ();
}
gboolean
_gdk_quartz_use_gdk_invalidation (void)
{
if (use_cocoa_invalidation < 0)
{
const gchar *env = g_getenv ("GDK_QUARTZ_COCOA_INVALIDATION");
if (env && *env)
use_cocoa_invalidation = atoi (env) != 0;
else
use_cocoa_invalidation = gdk_quartz_osx_version () < GDK_OSX_MOJAVE;
}
return !use_cocoa_invalidation;
}

View file

@ -145,9 +145,19 @@ _gdk_quartz_image_copy_to_image (GdkDrawable *drawable,
if (GDK_WINDOW_IMPL_QUARTZ (drawable) == GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (_gdk_root)->impl))
{
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
/* the screen cannot be read before 10.5 (CGWindowListCreateImage) */
return image;
#else
/* Special case for the root window. */
CGRect rect = CGRectMake (src_x, src_y, width, height);
CGImageRef root_image_ref = CGWindowListCreateImage (rect,
CGImageRef root_image_ref;
/* weakly linked where 10.4 is the oldest system */
if (CGWindowListCreateImage == NULL)
return image;
root_image_ref = CGWindowListCreateImage (rect,
kCGWindowListOptionOnScreenOnly,
kCGNullWindowID,
kCGWindowImageDefault);
@ -170,6 +180,7 @@ _gdk_quartz_image_copy_to_image (GdkDrawable *drawable,
rep = [[NSBitmapImageRep alloc] initWithCGImage: root_image_ref];
CGImageRelease (root_image_ref);
#endif
}
else
{

View file

@ -470,7 +470,8 @@ update_keymap (void)
p[0] = known_numeric_keys[i].keypad_keyval;
}
g_signal_emit_by_name (default_keymap, "keys-changed");
if (default_keymap != NULL)
g_signal_emit_by_name (default_keymap, "keys-changed");
}
static void
@ -696,7 +697,6 @@ gdk_keymap_translate_keyboard_state (GdkKeymap *keymap,
{
guint tmp_keyval;
GdkModifierType bit;
guint tmp_modifiers = 0;
g_return_val_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap), FALSE);
g_return_val_if_fail (group >= 0 && group <= 1, FALSE);
@ -716,24 +716,23 @@ gdk_keymap_translate_keyboard_state (GdkKeymap *keymap,
if (hardware_keycode < 0 || hardware_keycode >= NUM_KEYCODES)
return FALSE;
/* Check if modifiers modify the keyval */
for (bit = GDK_SHIFT_MASK; bit < GDK_BUTTON1_MASK; bit <<= 1)
{
if (translate_keysym (hardware_keycode,
(bit == GDK_MOD1_MASK) ? 0 : group,
state & ~bit,
NULL, NULL) !=
translate_keysym (hardware_keycode,
(bit == GDK_MOD1_MASK) ? 1 : group,
state | bit,
NULL, NULL))
tmp_modifiers |= bit;
}
tmp_keyval = translate_keysym (hardware_keycode, group, state, level, effective_group);
/* Check if modifiers modify the keyval */
if (consumed_modifiers)
*consumed_modifiers = tmp_modifiers;
{
guint tmp_modifiers = (state & GDK_MODIFIER_MASK);
for (bit = 1; bit <= tmp_modifiers; bit <<= 1)
{
if ((bit & tmp_modifiers) &&
translate_keysym (hardware_keycode, group, state & ~bit,
NULL, NULL) == tmp_keyval)
tmp_modifiers &= ~bit;
}
*consumed_modifiers = tmp_modifiers;
}
if (keyval)
*keyval = tmp_keyval;

View file

@ -219,4 +219,6 @@ gboolean _gdk_quartz_window_queue_antiexpose (GdkWindow *window,
/* Pixmap */
CGImageRef _gdk_pixmap_get_cgimage (GdkPixmap *pixmap);
gboolean _gdk_quartz_use_gdk_invalidation (void);
#endif /* __GDK_PRIVATE_QUARTZ_H__ */

View file

@ -71,6 +71,8 @@ NSImage *gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf
id gdk_quartz_drag_context_get_dragging_info_libgtk_only (GdkDragContext *context);
NSEvent *gdk_quartz_event_get_nsevent (GdkEvent *event);
GdkOSXVersion gdk_quartz_osx_version (void);
void gdk_quartz_set_use_cocoa_invalidation (gboolean use);
gboolean gdk_quartz_get_use_cocoa_invalidation (void);
GdkAtom gdk_quartz_pasteboard_type_to_atom_libgtk_only (NSString *type);
NSString *gdk_quartz_target_to_pasteboard_type_libgtk_only (const gchar *target);

View file

@ -62,6 +62,7 @@
static void gdk_screen_quartz_dispose (GObject *object);
static void gdk_screen_quartz_finalize (GObject *object);
static void gdk_screen_quartz_calculate_layout (GdkScreenQuartz *screen);
static CGFloat gdk_quartz_screen_user_space_scale (NSScreen *screen);
static void display_reconfiguration_callback (CGDirectDisplayID display,
CGDisplayChangeSummaryFlags flags,
@ -89,7 +90,7 @@ _gdk_screen_quartz_init (GdkScreenQuartz *screen_quartz)
nsscreen = [[NSScreen screens] objectAtIndex:0];
gdk_screen_set_resolution (screen,
72.0 * [nsscreen userSpaceScaleFactor]);
72.0 * gdk_quartz_screen_user_space_scale (nsscreen));
gdk_screen_quartz_calculate_layout (screen_quartz);
@ -354,6 +355,17 @@ gdk_screen_get_height (GdkScreen *screen)
return GDK_SCREEN_QUARTZ (screen)->height;
}
/* -userSpaceScaleFactor is the scale of the resolution independence of
* 10.4 to 10.6; newer systems no longer have the message, and sending
* it there throws (as Ardour found) */
static CGFloat
gdk_quartz_screen_user_space_scale (NSScreen *screen)
{
if ([screen respondsToSelector:@selector(userSpaceScaleFactor)])
return (CGFloat) [(id) screen userSpaceScaleFactor];
return 1.0;
}
static gint
get_mm_from_pixels (NSScreen *screen, int pixels)
{
@ -362,7 +374,7 @@ get_mm_from_pixels (NSScreen *screen, int pixels)
* and 25.4 is the number of millimeters per inch.
*/
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
float dpi = [screen userSpaceScaleFactor] * 72.0;
float dpi = gdk_quartz_screen_user_space_scale (screen) * 72.0;
#else
float dpi = 96.0 / 72.0;
#endif
@ -493,3 +505,58 @@ gdk_screen_is_composited (GdkScreen *screen)
return TRUE;
}
/* HiDPI: AppKit already draws GDK's points in the pixels of Retina
* screens (10.7 and later), sharp for paths and text; GDK coordinates
* stay the points. These scales only let pictures of more pixels be
* used (icons, see gdk_quartz_draw_pixbuf () and
* gdk_cairo_set_source_pixbuf ()); pixmaps stay at one pixel per point. */
static gint
gdk_quartz_nsscreen_get_scale (NSScreen *nsscreen)
{
CGFloat scale = 1.0;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (nsscreen && [nsscreen respondsToSelector:@selector(backingScaleFactor)])
scale = [nsscreen backingScaleFactor];
#endif
return MAX ((gint) (scale + 0.5), 1);
}
gint
_gdk_windowing_drawable_get_scale (GdkDrawable *drawable)
{
CGFloat scale = 1.0;
if (GDK_IS_WINDOW (drawable))
drawable = GDK_WINDOW_OBJECT (drawable)->impl;
if (!GDK_IS_WINDOW_IMPL_QUARTZ (drawable))
return 1;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
{
GdkWindow *toplevel = gdk_window_get_toplevel (GDK_DRAWABLE_IMPL_QUARTZ (drawable)->wrapper);
NSWindow *nswindow = toplevel ? GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl)->toplevel : nil;
if (nswindow && [nswindow respondsToSelector:@selector(backingScaleFactor)])
scale = [nswindow backingScaleFactor];
}
#endif
return MAX ((gint) (scale + 0.5), 1);
}
gint
_gdk_windowing_screen_get_monitor_scale (GdkScreen *screen,
gint monitor_num)
{
gint scale;
GDK_QUARTZ_ALLOC_POOL;
scale = gdk_quartz_nsscreen_get_scale (get_nsscreen_for_monitor (monitor_num));
GDK_QUARTZ_RELEASE_POOL;
return scale;
}

View file

@ -207,6 +207,7 @@ gdk_window_impl_quartz_finalize (GObject *object)
if (impl->transient_for)
g_object_unref (impl->transient_for);
impl->transient_for = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -1130,7 +1131,13 @@ _gdk_windowing_update_window_sizes (GdkScreen *screen)
windows = gdk_screen_get_toplevel_windows (screen);
for (list = windows; list; list = list->next)
_gdk_quartz_window_update_position (list->data);
{
/* Offscreen windows have no NSWindow to take the position from */
if (GDK_WINDOW_TYPE (list->data) == GDK_WINDOW_OFFSCREEN)
continue;
_gdk_quartz_window_update_position (list->data);
}
g_list_free (windows);
}
@ -1202,6 +1209,12 @@ _gdk_quartz_window_destroy (GdkWindow *window,
else if (impl->view)
[impl->view removeFromSuperview];
/* The window is released when closed (and with it its view), a
* view removed from its superview is released; don't keep
* dangling pointers to them. */
impl->view = NULL;
impl->toplevel = NULL;
GDK_QUARTZ_RELEASE_POOL;
}
}
@ -1749,9 +1762,16 @@ static void
gdk_window_quartz_set_background (GdkWindow *window,
const GdkColor *color)
{
/* FIXME: We could theoretically set the background color for toplevels
* here. (Currently we draw the background before emitting expose events)
*/
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl);
/* The background is drawn before the expose events; this colour is
* only for a view that is drawn before its window is mapped, so that
* a dark theme does not flash light first */
if (color)
{
impl->background_color = *color;
impl->background_color_set = TRUE;
}
}
static void
@ -1941,11 +1961,29 @@ gdk_window_get_root_origin (GdkWindow *window,
gint *y)
{
GdkRectangle rect;
GdkWindow *toplevel;
GdkWindowImplQuartz *impl;
rect.x = 0;
rect.y = 0;
gdk_window_get_frame_extents (window, &rect);
/* Where gdk_window_move() puts a toplevel is the top left of its
* content (Quartz places the content rect), so that is what this
* gives, for gtk_window_get_position(): with the frame, a window
* that a program puts back where it was went up by the height of
* the title bar each time (as Ardour found) */
toplevel = gdk_window_get_effective_toplevel (window);
impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl);
if (impl->toplevel)
{
NSRect ns_rect = [impl->toplevel contentRectForFrameRect:[impl->toplevel frame]];
_gdk_quartz_window_xy_to_gdk_xy (ns_rect.origin.x,
ns_rect.origin.y + ns_rect.size.height,
&rect.x, &rect.y);
}
else
gdk_window_get_frame_extents (window, &rect);
if (x)
*x = rect.x;
@ -2271,8 +2309,11 @@ gdk_window_set_transient_for (GdkWindow *window,
GdkWindowImplQuartz *window_impl;
GdkWindowImplQuartz *parent_impl;
/* an offscreen window, or a child of one, has no NSWindow to be
* transient for */
if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (parent) ||
!WINDOW_IS_TOPLEVEL (window))
!WINDOW_IS_TOPLEVEL (window) ||
!GDK_IS_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (parent)->impl))
return;
window_impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl);
@ -2559,7 +2600,8 @@ gdk_window_set_modal_hint (GdkWindow *window,
!WINDOW_IS_TOPLEVEL (window))
return;
/* FIXME: Implement */
/* kept, so that gdk_window_get_modal_hint() is right (Ardour) */
((GdkWindowObject *) window)->modal_hint = modal;
}
void
@ -2842,9 +2884,45 @@ void
gdk_window_set_functions (GdkWindow *window,
GdkWMFunction functions)
{
GdkWindowImplQuartz *impl;
gboolean close, minimize, maximize;
g_return_if_fail (GDK_IS_WINDOW (window));
/* FIXME: Implement */
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL (window))
return;
impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl);
if (!impl->toplevel)
return;
/* GDK_FUNC_ALL turns the meaning of the other bits around, as on X11 */
if (functions & GDK_FUNC_ALL)
{
close = !(functions & GDK_FUNC_CLOSE);
minimize = !(functions & GDK_FUNC_MINIMIZE);
maximize = !(functions & GDK_FUNC_MAXIMIZE);
}
else
{
close = (functions & GDK_FUNC_CLOSE) != 0;
minimize = (functions & GDK_FUNC_MINIMIZE) != 0;
maximize = (functions & GDK_FUNC_MAXIMIZE) != 0;
}
/* The buttons of the title bar, so that gtk_window_set_deletable()
* works. Enabling and disabling them works from Mac OS X 10.2 on and
* leaves the style of the window (and whether it can be resized, which
* the geometry hints decide) alone; a window without a title bar has
* no buttons, so nothing happens there. */
GDK_QUARTZ_ALLOC_POOL;
[[impl->toplevel standardWindowButton:NSWindowCloseButton] setEnabled:close];
[[impl->toplevel standardWindowButton:NSWindowMiniaturizeButton] setEnabled:minimize];
[[impl->toplevel standardWindowButton:NSWindowZoomButton] setEnabled:maximize];
GDK_QUARTZ_RELEASE_POOL;
}
gboolean
@ -3000,6 +3078,12 @@ gdk_window_fullscreen (GdkWindow *window)
!WINDOW_IS_TOPLEVEL (window))
return;
/* In the full screen of the system already (the green button, 10.7
* and newer): changing the decorations there throws (as Ardour
* found). The bit of NSFullScreenWindowMask, for older SDKs. */
if ([impl->toplevel styleMask] & (1 << 14))
return;
geometry = get_fullscreen_geometry (window);
if (!geometry)
{

View file

@ -60,6 +60,10 @@ struct _GdkWindowImplQuartz
GList *sorted_children;
GdkRegion *needs_display_region;
/* drawn before the first expose (from Ardour's YTK) */
GdkColor background_color;
gboolean background_color_set;
};
struct _GdkWindowImplQuartzClass

310
gdk/rgbsimdbench.c Normal file
View file

@ -0,0 +1,310 @@
/* rgbsimdbench: checks and times GdkRGB's vector kernels on this machine
*
* Every kernel of every instruction set the CPU has is run against the
* C code it stands in for: first on random data, which must come out
* the same, then for speed. The table at the end shows millions of
* pixels per second; the fastest of each row is marked.
*
* make -C gdk rgbsimdbench && gdk/rgbsimdbench
*
* GDK_RGB_SIMD="op=set,..." tries a choice in a running program.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "gdkrgbsimd.h"
#define WIDTH 256
#define ROWS 64
typedef gint (*Kernel) (gpointer out, gconstpointer in, gint n);
static guint32 seed = 1;
static guint
rnd (void)
{
seed = seed * 1103515245 + 12345;
return seed >> 8;
}
static inline guint
blend8 (guint a, guint s, guint d)
{
guint t = a * s + (255 - a) * d + 0x80;
return (t + (t >> 8)) >> 8;
}
/* The C code of GdkRGB and gdk_cairo_set_source_pixbuf(), as plain as
* there, for one pixel at position i */
static void
c_pixel (gint op, gpointer out, const guchar *s, gint i)
{
guint32 *o32 = (guint32 *) out + i;
guint16 *o16 = (guint16 *) out + i;
guint r, g, b;
switch (op)
{
case 0: /* rgb_to_x888 */
case 1: /* rgbx_to_x888 */
*o32 = 0xff000000 | (s[0] << 16) | (s[1] << 8) | s[2];
break;
case 2: /* rgb_to_565 */
*o16 = ((s[0] & 0xf8) << 8) | ((s[1] & 0xfc) << 3) | (s[2] >> 3);
break;
case 3: /* rgb_to_555 */
*o16 = 0x8000 | ((s[0] & 0xf8) << 7) | ((s[1] & 0xf8) << 2) | (s[2] >> 3);
break;
case 4: /* composite_x888 */
if (s[3] == 0)
break;
if (s[3] == 255)
*o32 = 0xff000000 | (s[0] << 16) | (s[1] << 8) | s[2];
else
*o32 = 0xff000000 | (blend8 (s[3], s[0], (*o32 >> 16) & 0xff) << 16) |
(blend8 (s[3], s[1], (*o32 >> 8) & 0xff) << 8) | blend8 (s[3], s[2], *o32 & 0xff);
break;
case 5: /* composite_565 */
if (s[3] == 0)
break;
r = *o16 >> 11, g = (*o16 >> 5) & 0x3f, b = *o16 & 0x1f;
r = blend8 (s[3], s[0], (r << 3) | (r >> 2));
g = blend8 (s[3], s[1], (g << 2) | (g >> 4));
b = blend8 (s[3], s[2], (b << 3) | (b >> 2));
*o16 = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
break;
case 6: /* composite_555 */
if (s[3] == 0)
break;
r = (*o16 >> 10) & 0x1f, g = (*o16 >> 5) & 0x1f, b = *o16 & 0x1f;
r = blend8 (s[3], s[0], (r << 3) | (r >> 2));
g = blend8 (s[3], s[1], (g << 3) | (g >> 2));
b = blend8 (s[3], s[2], (b << 3) | (b >> 2));
*o16 = 0x8000 | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
break;
case 7: /* rgba_to_argb */
*o32 = ((guint32) s[3] << 24) | (blend8 (s[3], s[0], 0) << 16) |
(blend8 (s[3], s[1], 0) << 8) | blend8 (s[3], s[2], 0);
break;
}
}
static gint
in_bytes (gint op)
{
return op == 0 || op == 2 || op == 3 ? 3 : 4;
}
static gint
out_bytes (gint op)
{
return op == 2 || op == 3 || op == 5 || op == 6 ? 2 : 4;
}
static void
run_c (gint op, gpointer out, const guchar *in, gint n)
{
gint i, step = in_bytes (op);
for (i = 0; i < n; i++)
c_pixel (op, out, in + i * step, i);
}
static void
run (gint op, Kernel kernel, gpointer out, const guchar *in, gint n)
{
gint done = kernel ? kernel (out, in, n) : 0, i, step = in_bytes (op);
/* the C code does the rest of the row */
for (i = done; i < n; i++)
c_pixel (op, out, in + i * step, i);
}
/* Source rows: for the alpha either like icons, mostly nothing or
* everything, or like soft shadows, everything in between */
static void
fill_source (guchar *in, gint op, gboolean icons)
{
gint i, n = ROWS * WIDTH * in_bytes (op);
for (i = 0; i < n; i++)
in[i] = rnd ();
if (in_bytes (op) == 4)
for (i = 3; i < n; i += 4)
{
guint k = rnd () % 10;
if (icons && k < 4)
in[i] = 0;
else if (icons && k < 8)
in[i] = 255;
}
}
static gboolean
check (gint op, Kernel kernel)
{
static guchar in[WIDTH * 4 + 16], a[WIDTH * 4 + 16], b[WIDTH * 4 + 16];
gint t, i;
for (t = 0; t < 2000; t++)
{
gint n = rnd () % WIDTH, ia = rnd () % 16, oa = (rnd () % 8) * 2;
for (i = 0; i < (gint) sizeof in; i++)
in[i] = rnd ();
for (i = 3; i < (gint) sizeof in; i += 4)
if (rnd () % 3 == 0)
in[i] = rnd () % 2 ? 0 : 255;
for (i = 0; i < (gint) sizeof a; i++)
a[i] = b[i] = rnd ();
run_c (op, a + oa, in + ia, n);
run (op, kernel, b + oa, in + ia, n);
if (memcmp (a, b, sizeof a) != 0)
return FALSE;
}
return TRUE;
}
/* Millions of pixels per second */
static gdouble
measure (gint op, Kernel kernel, gboolean c_only, gboolean icons)
{
static guchar in[ROWS * WIDTH * 4], out[ROWS * WIDTH * 4];
gint64 start, elapsed;
gint rounds = 0, y;
seed = 7;
fill_source (in, op, icons);
for (y = 0; y < (gint) sizeof out; y++)
out[y] = rnd ();
start = g_get_monotonic_time ();
do
{
for (y = 0; y < ROWS; y++)
{
const guchar *src = in + y * WIDTH * in_bytes (op);
guchar *dst = out + y * WIDTH * out_bytes (op);
if (c_only)
run_c (op, dst, src, WIDTH);
else
run (op, kernel, dst, src, WIDTH);
}
rounds++;
elapsed = g_get_monotonic_time () - start;
}
while (elapsed < 300000);
return (gdouble) rounds * ROWS * WIDTH / elapsed;
}
static void
print_cpu (void)
{
gchar *info = NULL, **lines;
gint i, shown = 0;
if (!g_file_get_contents ("/proc/cpuinfo", &info, NULL, NULL))
return;
lines = g_strsplit (info, "\n", -1);
for (i = 0; lines[i] && shown < 4; i++)
if (g_str_has_prefix (lines[i], "model name") || g_str_has_prefix (lines[i], "cpu\t") ||
g_str_has_prefix (lines[i], "vendor_id") || g_str_has_prefix (lines[i], "flags") ||
g_str_has_prefix (lines[i], "Features") || g_str_has_prefix (lines[i], "CPU part") ||
g_str_has_prefix (lines[i], "Hardware"))
{
printf ("%.150s\n", lines[i]);
shown++;
}
g_strfreev (lines);
g_free (info);
}
int
main (int argc, char **argv)
{
const GdkRgbSimdSet *sets;
const GdkRgbSimdOp *ops;
const GdkRgbSimd *chosen;
gint n_sets, n_ops, s, k, pass;
gboolean all_good = TRUE;
print_cpu ();
sets = _gdk_rgb_simd_sets (&n_sets);
ops = _gdk_rgb_simd_ops (&n_ops);
chosen = _gdk_rgb_simd_get ();
printf ("\nMillions of pixels per second, * the fastest, < what GDK takes now\n\n");
printf ("%-22s %8s", "", "c");
for (s = 0; s < n_sets; s++)
printf (" %9s", sets[s].name);
printf ("\n");
for (k = 0; k < n_ops; k++)
for (pass = 0; pass < (in_bytes (k) == 4 && k != 1 ? 2 : 1); pass++)
{
gdouble speed[16], best = 0;
const gchar *mark[16];
gchar label[64];
Kernel now = G_STRUCT_MEMBER (Kernel, chosen, ops[k].offset);
g_snprintf (label, sizeof label, "%s%s", ops[k].name,
in_bytes (k) == 4 && k != 1 ? (pass ? " soft" : " icons") : "");
speed[0] = measure (k, NULL, TRUE, !pass);
best = speed[0];
for (s = 0; s < n_sets; s++)
{
GdkRgbSimd set;
Kernel kernel;
memset (&set, 0, sizeof set);
sets[s].init (&set);
kernel = G_STRUCT_MEMBER (Kernel, &set, ops[k].offset);
speed[s + 1] = -1;
mark[s + 1] = " ";
if (!kernel)
continue;
if (!check (k, kernel))
{
printf ("%s of %s does not give what the C code does!\n", ops[k].name, sets[s].name);
all_good = FALSE;
continue;
}
speed[s + 1] = measure (k, kernel, FALSE, !pass);
if (speed[s + 1] > best)
best = speed[s + 1];
if (kernel == now)
mark[s + 1] = "<";
}
printf ("%-22s %7.1f%s", label, speed[0], speed[0] == best ? "*" : (now ? " " : "<"));
for (s = 0; s < n_sets; s++)
{
if (speed[s + 1] < 0)
printf (" %9s", "-");
else
printf (" %8.1f%s", speed[s + 1], speed[s + 1] == best ? "*" : mark[s + 1]);
}
printf ("\n");
}
if (!all_good)
printf ("\nSome kernels are wrong on this machine; please send this output.\n");
return all_good ? 0 : 1;
}

View file

@ -66,6 +66,7 @@ hcursor_from_type (GdkCursorType cursor_type)
gint i, j, x, y, ofs;
HCURSOR rv;
gint w, h;
gint s = _gdk_win32_scale;
guchar *and_plane, *xor_plane;
if (cursor_type != GDK_BLANK_CURSOR)
@ -84,6 +85,12 @@ hcursor_from_type (GdkCursorType cursor_type)
w = GetSystemMetrics (SM_CXCURSOR);
h = GetSystemMetrics (SM_CYCURSOR);
/* HiDPI: each pixel of the X cursor as s x s pixels of Windows */
if (cursor_type != GDK_BLANK_CURSOR && s > 1)
{
w = MAX (w, (cursors[i].width * s + 31) / 32 * 32);
h = MAX (h, cursors[i].height * s);
}
and_plane = g_malloc ((w/8) * h);
memset (and_plane, 0xff, (w/8) * h);
@ -96,16 +103,18 @@ hcursor_from_type (GdkCursorType cursor_type)
#define SET_BIT(v,b) (v |= (1 << b))
#define RESET_BIT(v,b) (v &= ~(1 << b))
for (j = 0, y = 0; y < cursors[i].height && y < h ; y++)
for (y = 0; y < cursors[i].height * s && y < h ; y++)
{
ofs = (y * w) / 8;
j = y * cursors[i].width;
for (x = 0; x < cursors[i].width && x < w ; x++, j++)
for (x = 0; x < cursors[i].width * s && x < w ; x++)
{
gint pofs = ofs + x / 8;
guchar data = (cursors[i].data[j/4] & (0xc0 >> (2 * (j%4)))) >> (2 * (3 - (j%4)));
gint bit = 7 - (j % cursors[i].width) % 8;
guchar data;
gint bit = 7 - x % 8;
j = (y / s) * cursors[i].width + x / s;
data = (cursors[i].data[j/4] & (0xc0 >> (2 * (j%4)))) >> (2 * (3 - (j%4)));
if (data)
{
@ -119,7 +128,9 @@ hcursor_from_type (GdkCursorType cursor_type)
#undef SET_BIT
#undef RESET_BIT
rv = CreateCursor (_gdk_app_hmodule, cursors[i].hotx, cursors[i].hoty,
rv = CreateCursor (_gdk_app_hmodule,
cursors[i].hotx * s + s / 2,
cursors[i].hoty * s + s / 2,
w, h, and_plane, xor_plane);
}
else
@ -210,14 +221,24 @@ gdk_cursor_new_from_pixmap (GdkPixmap *source,
g_return_val_if_fail (source_impl->width == mask_impl->width
&& source_impl->height == mask_impl->height,
NULL);
width = source_impl->width;
height = source_impl->height;
g_return_val_if_fail (source_impl->scale == mask_impl->scale, NULL);
/* HiDPI: the bits are in pixels of Windows, and so is the cursor */
width = source_impl->width * MAX (source_impl->scale, 1);
height = source_impl->height * MAX (source_impl->scale, 1);
x = x * MAX (source_impl->scale, 1) + MAX (source_impl->scale, 1) / 2;
y = y * MAX (source_impl->scale, 1) + MAX (source_impl->scale, 1) / 2;
cursor_width = GetSystemMetrics (SM_CXCURSOR);
cursor_height = GetSystemMetrics (SM_CYCURSOR);
g_return_val_if_fail (width <= cursor_width && height <= cursor_height,
g_return_val_if_fail (source_impl->width <= cursor_width / _gdk_win32_scale &&
source_impl->height <= cursor_height / _gdk_win32_scale,
NULL);
/* a cursor as large as the scaled bits when Windows' size is not */
cursor_width = MAX (cursor_width, (width + 31) / 32 * 32);
cursor_height = MAX (cursor_height, height);
residue = (1 << ((8-(width%8))%8)) - 1;
source_bits = source_impl->bits;
@ -228,7 +249,7 @@ gdk_cursor_new_from_pixmap (GdkPixmap *source,
NULL);
source_bpl = ((width - 1)/32 + 1)*4;
mask_bpl = ((mask_impl->width - 1)/32 + 1)*4;
mask_bpl = source_bpl;
GDK_NOTE (CURSOR, {
g_print ("gdk_cursor_new_from_pixmap: source=%p:\n",
@ -626,7 +647,27 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display,
g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
hcursor = _gdk_win32_pixbuf_to_hcursor (pixbuf, x, y);
if (_gdk_win32_scale > 1)
{
/* HiDPI: the cursor in pixels of Windows, from the picture made
* for it if there is one */
GdkPixbuf *hires = _gdk_pixbuf_get_hires (pixbuf, _gdk_win32_scale);
gint s = _gdk_win32_scale;
if (hires)
g_object_ref (hires);
else
hires = gdk_pixbuf_scale_simple (pixbuf,
gdk_pixbuf_get_width (pixbuf) * s,
gdk_pixbuf_get_height (pixbuf) * s,
GDK_INTERP_NEAREST);
if (!hires)
return NULL;
hcursor = _gdk_win32_pixbuf_to_hcursor (hires, x * s + s / 2, y * s + s / 2);
g_object_unref (hires);
}
else
hcursor = _gdk_win32_pixbuf_to_hcursor (pixbuf, x, y);
if (!hcursor)
return NULL;
return cursor_new_from_hcursor (hcursor, GDK_CURSOR_IS_PIXMAP);
@ -653,7 +694,8 @@ gdk_display_get_default_cursor_size (GdkDisplay *display)
{
g_return_val_if_fail (display == _gdk_display, 0);
return MIN (GetSystemMetrics (SM_CXCURSOR), GetSystemMetrics (SM_CYCURSOR));
/* in pixels of GDK (HiDPI) */
return MAX (MIN (GetSystemMetrics (SM_CXCURSOR), GetSystemMetrics (SM_CYCURSOR)) / _gdk_win32_scale, 1);
}
void
@ -663,10 +705,11 @@ gdk_display_get_maximal_cursor_size (GdkDisplay *display,
{
g_return_if_fail (display == _gdk_display);
/* in pixels of GDK (HiDPI) */
if (width)
*width = GetSystemMetrics (SM_CXCURSOR);
*width = MAX (GetSystemMetrics (SM_CXCURSOR) / _gdk_win32_scale, 1);
if (height)
*height = GetSystemMetrics (SM_CYCURSOR);
*height = MAX (GetSystemMetrics (SM_CYCURSOR) / _gdk_win32_scale, 1);
}

View file

@ -91,7 +91,7 @@ enum_monitor (HMONITOR hmonitor,
monitor = _gdk_monitors + *index;
monitor_info.cbSize = sizeof (MONITORINFOEX);
monitor_info.cbSize = sizeof (MONITORINFOEXA2);
GetMonitorInfoA (hmonitor, (MONITORINFO *) &monitor_info);
#ifndef MONITORINFOF_PRIMARY
@ -159,11 +159,17 @@ _gdk_monitor_init (void)
GDK_NOTE (MISC, g_print ("Multi-monitor offset: (%d,%d)\n",
_gdk_offset_x, _gdk_offset_y));
/* Translate monitor coords into GDK coordinate space */
/* Translate monitor coords into GDK coordinate space, also in its
* pixels (HiDPI) */
for (i = 0; i < _gdk_num_monitors; i++)
{
_gdk_monitors[i].rect.x += _gdk_offset_x;
_gdk_monitors[i].rect.y += _gdk_offset_y;
GdkRectangle *r = &_gdk_monitors[i].rect;
gint x2 = r->x + r->width + _gdk_offset_x, y2 = r->y + r->height + _gdk_offset_y;
r->x = _gdk_win32_unscale (r->x + _gdk_offset_x);
r->y = _gdk_win32_unscale (r->y + _gdk_offset_y);
r->width = _gdk_win32_unscale (x2) - r->x;
r->height = _gdk_win32_unscale (y2) - r->y;
GDK_NOTE (MISC, g_print ("Monitor %d: %dx%d@%+d%+d\n",
i, _gdk_monitors[i].rect.width,
_gdk_monitors[i].rect.height,
@ -183,8 +189,8 @@ _gdk_monitor_init (void)
ReleaseDC (NULL, hDC);
_gdk_monitors[0].rect.x = 0;
_gdk_monitors[0].rect.y = 0;
_gdk_monitors[0].rect.width = GetSystemMetrics (SM_CXSCREEN);
_gdk_monitors[0].rect.height = GetSystemMetrics (SM_CYSCREEN);
_gdk_monitors[0].rect.width = _gdk_win32_unscale (GetSystemMetrics (SM_CXSCREEN));
_gdk_monitors[0].rect.height = _gdk_win32_unscale (GetSystemMetrics (SM_CYSCREEN));
_gdk_offset_x = 0;
_gdk_offset_y = 0;
#endif
@ -216,6 +222,24 @@ gdk_display_open (const gchar *display_name)
_gdk_monitor_init ();
_gdk_visual_init ();
/* HiDPI: fonts are laid out in pixels of GDK and drawn in those of
* Windows; widths rounded to GDK's pixels would space the letters
* unevenly */
if (_gdk_win32_scale > 1)
{
cairo_font_options_t *options = cairo_font_options_create ();
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
gdk_screen_set_font_options (_gdk_screen, options);
cairo_font_options_destroy (options);
}
/* HiDPI: the resolution of fonts in pixels of GDK; Pango would take
* that of Windows, in its pixels (GTK+ sets it from gtk-xft-dpi only
* on X11) */
if (_gdk_win32_font_dpi () > 0)
gdk_screen_set_resolution (_gdk_screen, _gdk_win32_font_dpi ());
gdk_screen_set_default_colormap (_gdk_screen,
gdk_screen_get_system_colormap (_gdk_screen));
_gdk_windowing_window_init (_gdk_screen);
@ -505,10 +529,11 @@ gdk_display_request_selection_notification (GdkDisplay *display,
{
static HWND hwndViewer = NULL;
gboolean ret = FALSE;
gchar *selection_name = gdk_atom_name (selection);
GDK_NOTE (DND,
g_print ("gdk_display_request_selection_notification (..., %s)",
gdk_atom_name (selection)));
selection_name));
if (selection == GDK_SELECTION_CLIPBOARD ||
selection == GDK_SELECTION_PRIMARY)
@ -526,6 +551,8 @@ gdk_display_request_selection_notification (GdkDisplay *display,
ret = FALSE;
}
g_free (selection_name);
GDK_NOTE (DND, g_print (" -> %s\n", ret ? "TRUE" : "FALSE"));
return ret;
}

View file

@ -454,8 +454,8 @@ dnd_event_put (GdkEventType type,
e.dnd.send_event = FALSE;
e.dnd.context = context;
e.dnd.time = GDK_CURRENT_TIME;
e.dnd.x_root = pt.x + _gdk_offset_x;
e.dnd.y_root = pt.x + _gdk_offset_y;
e.dnd.x_root = GDK_WIN32_SCREEN_TO_ROOT_X (pt.x);
e.dnd.y_root = GDK_WIN32_SCREEN_TO_ROOT_Y (pt.y);
g_object_ref (e.dnd.context);
if (e.dnd.window != NULL)
@ -1477,8 +1477,8 @@ gdk_dropfiles_filter (GdkXEvent *xev,
DragQueryPoint (hdrop, &pt);
ClientToScreen (msg->hwnd, &pt);
event->dnd.x_root = pt.x + _gdk_offset_x;
event->dnd.y_root = pt.y + _gdk_offset_y;
event->dnd.x_root = GDK_WIN32_SCREEN_TO_ROOT_X (pt.x);
event->dnd.y_root = GDK_WIN32_SCREEN_TO_ROOT_Y (pt.y);
event->dnd.time = _gdk_win32_get_next_tick (msg->time);
nfiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
@ -1551,8 +1551,7 @@ gdk_dropfiles_filter (GdkXEvent *xev,
g_free (fileName);
g_string_append (result, "\015\012");
}
_gdk_dropfiles_store (result->str);
g_string_free (result, FALSE);
_gdk_dropfiles_store (g_string_free (result, FALSE));
DragFinish (hdrop);
@ -1736,8 +1735,8 @@ local_send_motion (GdkDragContext *context,
tmp_event.dnd.x_root = x_root;
tmp_event.dnd.y_root = y_root;
PRIVATE_DATA (current_dest_drag)->last_pt.x = x_root - _gdk_offset_x;
PRIVATE_DATA (current_dest_drag)->last_pt.y = y_root - _gdk_offset_y;
PRIVATE_DATA (current_dest_drag)->last_pt.x = GDK_WIN32_ROOT_TO_SCREEN_X (x_root);
PRIVATE_DATA (current_dest_drag)->last_pt.y = GDK_WIN32_ROOT_TO_SCREEN_Y (y_root);
PRIVATE_DATA (context)->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
@ -1770,8 +1769,8 @@ local_send_drop (GdkDragContext *context,
tmp_event.dnd.context = current_dest_drag;
tmp_event.dnd.time = GDK_CURRENT_TIME;
tmp_event.dnd.x_root = private->last_pt.x + _gdk_offset_x;
tmp_event.dnd.y_root = private->last_pt.y + _gdk_offset_y;
tmp_event.dnd.x_root = GDK_WIN32_SCREEN_TO_ROOT_X (private->last_pt.x);
tmp_event.dnd.y_root = GDK_WIN32_SCREEN_TO_ROOT_Y (private->last_pt.y);
current_dest_drag = NULL;
@ -2023,8 +2022,8 @@ gdk_drag_find_window_for_screen (GdkDragContext *context,
GdkWindow *dw;
find_window_enum_arg a;
a.x = x_root - _gdk_offset_x;
a.y = y_root - _gdk_offset_y;
a.x = GDK_WIN32_ROOT_TO_SCREEN_X (x_root);
a.y = GDK_WIN32_ROOT_TO_SCREEN_Y (y_root);
a.ignore = drag_window ? GDK_WINDOW_HWND (drag_window) : NULL;
a.result = NULL;
@ -2154,8 +2153,8 @@ gdk_drag_motion (GdkDragContext *context,
/* Send a drag-motion event */
private->last_pt.x = x_root - _gdk_offset_x;
private->last_pt.y = y_root - _gdk_offset_y;
private->last_pt.x = GDK_WIN32_ROOT_TO_SCREEN_X (x_root);
private->last_pt.y = GDK_WIN32_ROOT_TO_SCREEN_Y (y_root);
if (context->dest_window)
{

View file

@ -689,11 +689,20 @@ generic_draw (GdkDrawable *drawable,
* the areas where mask is one. (It is filled with said pattern.)
*/
GDI_CALL (MaskBlt, (hdc, region->extents.x1, region->extents.y1,
width, height,
tile_hdc, 0, 0,
GDK_PIXMAP_HBITMAP (mask_pixmap), 0, 0,
MAKEROP4 (rop2_to_rop3 (gcwin32->rop2), ROP3_D)));
/* the mask's bits are in pixels of Windows, so all is (HiDPI) */
{
gint s = _gdk_win32_scale;
_gdk_win32_dc_set_scale (hdc, 1);
_gdk_win32_dc_set_scale (tile_hdc, 1);
GDI_CALL (MaskBlt, (hdc, region->extents.x1 * s, region->extents.y1 * s,
width * s, height * s,
tile_hdc, 0, 0,
GDK_PIXMAP_HBITMAP (mask_pixmap), 0, 0,
MAKEROP4 (rop2_to_rop3 (gcwin32->rop2), ROP3_D)));
_gdk_win32_dc_set_scale (tile_hdc, s);
_gdk_win32_dc_set_scale (hdc, _gdk_win32_drawable_scale (drawable));
}
/* Cleanup */
gdk_win32_hdc_release (mask_pixmap, mask_gc, blitting_mask);
@ -1386,6 +1395,63 @@ gdk_win32_draw_lines (GdkDrawable *drawable,
g_free (pts);
}
/* HiDPI: the scale of a drawable, pixels of its bitmap or window for
* one of GDK */
gint
_gdk_win32_drawable_scale (GdkDrawable *drawable)
{
if (GDK_IS_PIXMAP (drawable))
drawable = GDK_PIXMAP_OBJECT (drawable)->impl;
if (GDK_IS_PIXMAP_IMPL_WIN32 (drawable))
return MAX (GDK_PIXMAP_IMPL_WIN32 (drawable)->scale, 1);
return _gdk_win32_scale;
}
/* HiDPI: a BitBlt () in pixels of GDK from a DC of @ss pixels per pixel
* of GDK to one with @ds, done in the pixels themselves; the DCs keep
* the mapping they had */
static BOOL
blit_scaled (HDC hdc,
gint ds,
gint xdest,
gint ydest,
gint width,
gint height,
HDC srcdc,
gint ss,
gint xsrc,
gint ysrc,
DWORD rop)
{
BOOL ok;
if (_gdk_win32_scale <= 1)
return BitBlt (hdc, xdest, ydest, width, height, srcdc, xsrc, ysrc, rop);
_gdk_win32_dc_set_scale (hdc, 1);
if (srcdc != hdc)
_gdk_win32_dc_set_scale (srcdc, 1);
if (ds == ss)
ok = BitBlt (hdc, xdest * ds, ydest * ds, width * ds, height * ds,
srcdc, xsrc * ss, ysrc * ss, rop);
else
{
/* a GdkImage, which has GDK's pixels: the nearest pixel, as
* everywhere else in GDK */
int old_mode = SetStretchBltMode (hdc, COLORONCOLOR);
ok = StretchBlt (hdc, xdest * ds, ydest * ds, width * ds, height * ds,
srcdc, xsrc * ss, ysrc * ss, width * ss, height * ss, rop);
SetStretchBltMode (hdc, old_mode);
}
_gdk_win32_dc_set_scale (hdc, ds);
return ok;
}
static void
blit_from_pixmap (gboolean use_fg_bg,
GdkDrawableImplWin32 *dest,
@ -1503,8 +1569,10 @@ blit_from_pixmap (gboolean use_fg_bg,
}
if (ok)
if (!BitBlt (hdc, xdest, ydest, width, height,
srcdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2)) &&
if (!blit_scaled (hdc, _gdk_win32_drawable_scale (GDK_DRAWABLE (dest)),
xdest, ydest, width, height,
srcdc, MAX (src->scale, 1), xsrc, ysrc,
rop2_to_rop3 (gcwin32->rop2)) &&
GetLastError () != ERROR_INVALID_HANDLE)
WIN32_GDI_FAILED ("BitBlt");
@ -1549,15 +1617,23 @@ blit_inside_drawable (HDC hdc,
HRGN updateRgn;
GdkRegion *update_region;
clipRect.left = xdest;
clipRect.top = ydest;
clipRect.right = xdest + width;
clipRect.bottom = ydest + height;
BOOL scrolled;
/* in pixels of Windows (HiDPI) */
clipRect.left = GDK_WIN32_SC (xdest);
clipRect.top = GDK_WIN32_SC (ydest);
clipRect.right = GDK_WIN32_SC (xdest + width);
clipRect.bottom = GDK_WIN32_SC (ydest + height);
SetRectEmpty (&emptyRect);
updateRgn = CreateRectRgnIndirect (&emptyRect);
if (!ScrollDC (hdc, xdest - xsrc, ydest - ysrc, NULL, &clipRect, updateRgn, NULL))
_gdk_win32_dc_set_scale (hdc, 1);
scrolled = ScrollDC (hdc, GDK_WIN32_SC (xdest - xsrc), GDK_WIN32_SC (ydest - ysrc),
NULL, &clipRect, updateRgn, NULL);
_gdk_win32_dc_set_scale (hdc, _gdk_win32_scale);
if (!scrolled)
WIN32_GDI_FAILED ("ScrollDC");
else
{
@ -1573,13 +1649,17 @@ blit_inside_drawable (HDC hdc,
}
else
{
GDI_CALL (BitBlt, (hdc, xdest, ydest, width, height,
hdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2)));
gint s = _gdk_win32_drawable_scale (GDK_DRAWABLE (src));
if (!blit_scaled (hdc, s, xdest, ydest, width, height,
hdc, s, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2)))
WIN32_GDI_FAILED ("BitBlt");
}
}
static void
blit_from_window (HDC hdc,
GdkDrawableImplWin32 *dest,
GdkGCWin32 *gcwin32,
GdkDrawableImplWin32 *src,
gint xsrc,
@ -1615,8 +1695,11 @@ blit_from_window (HDC hdc,
g_print ("blit_from_window: realized %d\n", k));
}
GDI_CALL (BitBlt, (hdc, xdest, ydest, width, height,
srcdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2)));
if (!blit_scaled (hdc, _gdk_win32_drawable_scale (GDK_DRAWABLE (dest)),
xdest, ydest, width, height,
srcdc, _gdk_win32_scale, xsrc, ysrc,
rop2_to_rop3 (gcwin32->rop2)))
WIN32_GDI_FAILED ("BitBlt");
if (holdpal != NULL)
GDI_CALL (SelectPalette, (srcdc, holdpal, FALSE));
@ -1656,8 +1739,9 @@ _gdk_win32_blit (gboolean use_fg_bg,
if (src == ((GdkWindowObject *)_gdk_root)->impl)
{
GDK_NOTE (DRAW, g_print ("... offsetting src coords\n"));
xsrc -= _gdk_offset_x;
ysrc -= _gdk_offset_y;
/* in pixels of GDK (HiDPI) */
xsrc -= _gdk_win32_unscale (_gdk_offset_x);
ysrc -= _gdk_win32_unscale (_gdk_offset_y);
}
if (GDK_IS_DRAWABLE_IMPL_WIN32 (src))
@ -1728,6 +1812,7 @@ _gdk_win32_blit (gboolean use_fg_bg,
else if (comb != NULLREGION)
{
OffsetRgn (outside_rgn, xdest, ydest);
outside_rgn = _gdk_win32_hrgn_scale (outside_rgn);
GDK_NOTE (DRAW, (GetRgnBox (outside_rgn, &r),
g_print ("... InvalidateRgn "
"bbox: %ldx%ld@%+ld%+ld\n",
@ -1772,7 +1857,7 @@ _gdk_win32_blit (gboolean use_fg_bg,
(GdkPixmapImplWin32 *) src_impl, gc,
xsrc, ysrc, xdest, ydest, width, height);
else
blit_from_window (hdc, GDK_GC_WIN32 (gc), src_impl,
blit_from_window (hdc, draw_impl, GDK_GC_WIN32 (gc), src_impl,
xsrc, ysrc, xdest, ydest, width, height);
gdk_win32_hdc_release (&draw_impl->parent_instance, gc, GDK_GC_FOREGROUND);
@ -1931,6 +2016,16 @@ _gdk_windowing_create_cairo_surface (GdkDrawable *drawable,
surface = cairo_win32_surface_create (hdc);
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0)
/* HiDPI: drawn on in pixels of GDK */
{
gint s = _gdk_win32_drawable_scale (drawable);
if (s > 1)
cairo_surface_set_device_scale (surface, s, s);
}
#endif
/* Whenever the cairo surface is destroyed, we need to release the
* HDC that was acquired */
cairo_surface_set_user_data (surface, &gdk_win32_cairo_hdc_key,

View file

@ -87,6 +87,13 @@
#define SYNAPSIS_ICON_WINDOW_CLASS "SynTrackCursorWindowClass"
/* The input GDK waits for. Headers for Windows 8 and later add touch
* and pointer messages to QS_ALLINPUT: with those GDK keeps waking up
* for messages it does not take from the queue, and Windows 7 and
* earlier refuse the unknown flags and report nothing at all. */
#define GDK_QS_INPUT (QS_KEY | QS_MOUSEMOVE | QS_MOUSEBUTTON | QS_POSTMESSAGE | \
QS_TIMER | QS_PAINT | QS_HOTKEY | QS_SENDMESSAGE | 0x0400 /* QS_RAWINPUT */)
static gboolean gdk_event_translate (MSG *msg,
gint *ret_valp);
static void handle_wm_paint (MSG *msg,
@ -176,7 +183,9 @@ _gdk_win32_get_next_tick (gulong suggested_tick)
if (suggested_tick == 0)
suggested_tick = GetTickCount ();
if (suggested_tick <= cur_tick)
/* Ticks eventually wrap around.
* This works as long as the interval between ticks is < 2147483648ms */
if (suggested_tick <= cur_tick && ((cur_tick - suggested_tick) < 0x7FFFFFFF))
return cur_tick;
else
return cur_tick = suggested_tick;
@ -383,7 +392,7 @@ gdk_events_pending (void)
{
return (_gdk_event_queue_find_first (_gdk_display) ||
(modal_win32_dialog == NULL &&
GetQueueStatus (QS_ALLINPUT) != 0));
GetQueueStatus (GDK_QS_INPUT) != 0));
}
GdkEvent*
@ -1261,10 +1270,10 @@ send_crossing_event (GdkDisplay *display,
event->crossing.window = (GdkWindow *)window;
event->crossing.subwindow = subwindow;
event->crossing.time = _gdk_win32_get_next_tick (time_);
event->crossing.x = pt.x;
event->crossing.y = pt.y;
event->crossing.x_root = screen_pt->x + _gdk_offset_x;
event->crossing.y_root = screen_pt->y + _gdk_offset_y;
event->crossing.x = GDK_WIN32_UNSCALE_D (pt.x);
event->crossing.y = GDK_WIN32_UNSCALE_D (pt.y);
event->crossing.x_root = GDK_WIN32_SCREEN_TO_ROOT_D (screen_pt->x, _gdk_offset_x);
event->crossing.y_root = GDK_WIN32_SCREEN_TO_ROOT_D (screen_pt->y, _gdk_offset_y);
event->crossing.mode = mode;
event->crossing.detail = notify_type;
event->crossing.mode = mode;
@ -1482,10 +1491,11 @@ synthesize_expose_events (GdkWindow *window)
{
event = gdk_event_new (GDK_EXPOSE);
event->expose.window = window;
event->expose.area.x = r.left;
event->expose.area.y = r.top;
event->expose.area.width = r.right - r.left;
event->expose.area.height = r.bottom - r.top;
/* HiDPI: in pixels of GDK, all that is touched */
event->expose.area.x = _gdk_win32_unscale (r.left);
event->expose.area.y = _gdk_win32_unscale (r.top);
event->expose.area.width = _gdk_win32_unscale_up (r.right) - event->expose.area.x;
event->expose.area.height = _gdk_win32_unscale_up (r.bottom) - event->expose.area.y;
event->expose.region = gdk_region_rectangle (&(event->expose.area));
event->expose.count = 0;
@ -1669,9 +1679,18 @@ _gdk_win32_emit_configure_event (GdkWindow *window)
if (gdk_window_get_parent (window) == _gdk_root)
{
ClientToScreen (hwnd, &point);
point.x += _gdk_offset_x;
point.y += _gdk_offset_y;
point.x = GDK_WIN32_SCREEN_TO_ROOT_X (point.x);
point.y = GDK_WIN32_SCREEN_TO_ROOT_Y (point.y);
}
else
{
point.x = _gdk_win32_unscale (point.x);
point.y = _gdk_win32_unscale (point.y);
}
/* HiDPI: a size of Windows not divisible by the scale is covered */
client_rect.right = client_rect.left + _gdk_win32_unscale_up (client_rect.right - client_rect.left);
client_rect.bottom = client_rect.top + _gdk_win32_unscale_up (client_rect.bottom - client_rect.top);
window_object->width = client_rect.right - client_rect.left;
window_object->height = client_rect.bottom - client_rect.top;
@ -1727,10 +1746,11 @@ _gdk_win32_hrgn_to_region (HRGN hrgn)
{
GdkRectangle r;
r.x = rects[i].left;
r.y = rects[i].top;
r.width = rects[i].right - r.x;
r.height = rects[i].bottom - r.y;
/* in pixels of GDK, all that is partly in it */
r.x = _gdk_win32_unscale (rects[i].left);
r.y = _gdk_win32_unscale (rects[i].top);
r.width = _gdk_win32_unscale_up (rects[i].right) - r.x;
r.height = _gdk_win32_unscale_up (rects[i].bottom) - r.y;
gdk_region_union_with_rect (result, &r);
}
@ -1795,11 +1815,9 @@ handle_wm_paint (MSG *msg,
*event = gdk_event_new (GDK_EXPOSE);
(*event)->expose.window = window;
(*event)->expose.area.x = paintstruct.rcPaint.left;
(*event)->expose.area.y = paintstruct.rcPaint.top;
(*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
(*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
(*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
/* in pixels of GDK (HiDPI), as the region */
gdk_region_get_clipbox ((*event)->expose.region, &(*event)->expose.area);
(*event)->expose.count = 0;
while (list != NULL)
@ -1892,6 +1910,154 @@ handle_display_change (void)
g_signal_emit_by_name (_gdk_screen, "size_changed");
}
/* Touches of Windows 7 and later, from user32 when there: RegisterTouchWindow()
* for the windows with GDK_TOUCH_MASK, which then get WM_TOUCH. Windows
* keeps sending the mouse messages of the first finger, marked in
* GetMessageExtraInfo(), which GDK keeps from the windows that take
* touches (gdkwindow.c). Windows XP and Vista: no touches, as before. */
#define GDK_WM_TOUCH 0x0240
#define GDK_TOUCHEVENTF_MOVE 0x0001
#define GDK_TOUCHEVENTF_DOWN 0x0002
#define GDK_TOUCHEVENTF_UP 0x0004
#define GDK_TOUCHEVENTF_PRIMARY 0x0010
#define GDK_MI_WP_SIGNATURE 0xFF515700
#define GDK_MI_SIGNATURE_MASK 0xFFFFFF00
#define GDK_MI_TOUCH 0x80
typedef struct
{
LONG x, y; /* hundredths of a screen pixel */
HANDLE hSource;
DWORD dwID;
DWORD dwFlags;
DWORD dwMask;
DWORD dwTime;
ULONG_PTR dwExtraInfo;
DWORD cxContact, cyContact;
} GdkTouchInput;
typedef BOOL (WINAPI *t_RegisterTouchWindow) (HWND, ULONG);
typedef BOOL (WINAPI *t_UnregisterTouchWindow) (HWND);
typedef BOOL (WINAPI *t_GetTouchInputInfo) (HANDLE, UINT, GdkTouchInput *, int);
typedef BOOL (WINAPI *t_CloseTouchInputHandle) (HANDLE);
static t_RegisterTouchWindow p_RegisterTouchWindow;
static t_UnregisterTouchWindow p_UnregisterTouchWindow;
static t_GetTouchInputInfo p_GetTouchInputInfo;
static t_CloseTouchInputHandle p_CloseTouchInputHandle;
static gboolean
touch_api (void)
{
static gint state; /* 0 not looked, 1 there, 2 not */
if (state == 0)
{
HMODULE user32 = GetModuleHandleW (L"user32.dll");
p_RegisterTouchWindow = (t_RegisterTouchWindow) GetProcAddress (user32, "RegisterTouchWindow");
p_UnregisterTouchWindow = (t_UnregisterTouchWindow) GetProcAddress (user32, "UnregisterTouchWindow");
p_GetTouchInputInfo = (t_GetTouchInputInfo) GetProcAddress (user32, "GetTouchInputInfo");
p_CloseTouchInputHandle = (t_CloseTouchInputHandle) GetProcAddress (user32, "CloseTouchInputHandle");
state = p_RegisterTouchWindow && p_UnregisterTouchWindow &&
p_GetTouchInputInfo && p_CloseTouchInputHandle ? 1 : 2;
}
return state == 1;
}
void
_gdk_win32_window_update_touch (GdkWindow *window,
gboolean touch)
{
HWND hwnd;
if (GDK_WINDOW_DESTROYED (window) || !touch_api ())
return;
hwnd = GDK_WINDOW_HWND (window);
if (hwnd == NULL || GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
GDK_WINDOW_TYPE (window) == GDK_WINDOW_FOREIGN)
return;
if (touch)
p_RegisterTouchWindow (hwnd, 0);
else
p_UnregisterTouchWindow (hwnd);
}
/* a mouse message that Windows made of a finger */
static gboolean
mouse_message_from_touch (void)
{
LPARAM extra = GetMessageExtraInfo ();
return (extra & GDK_MI_SIGNATURE_MASK) == GDK_MI_WP_SIGNATURE &&
(extra & GDK_MI_TOUCH) != 0;
}
static gboolean
handle_wm_touch (GdkWindow *window,
MSG *msg)
{
UINT n = LOWORD (msg->wParam), i;
GdkTouchInput *inputs;
POINT origin = { 0, 0 };
guint state;
if (n == 0 || !touch_api () || GDK_WINDOW_DESTROYED (window))
return FALSE;
inputs = g_new (GdkTouchInput, n);
if (!p_GetTouchInputInfo ((HANDLE) msg->lParam, n, inputs, sizeof (GdkTouchInput)))
{
g_free (inputs);
return FALSE;
}
ClientToScreen (GDK_WINDOW_HWND (window), &origin);
state = build_pointer_event_state (msg) &
~(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | GDK_BUTTON5_MASK);
for (i = 0; i < n; i++)
{
GdkEvent *event;
GdkEventType type;
gdouble sx = inputs[i].x / 100.0, sy = inputs[i].y / 100.0;
if (inputs[i].dwFlags & GDK_TOUCHEVENTF_DOWN)
type = GDK_TOUCH_BEGIN;
else if (inputs[i].dwFlags & GDK_TOUCHEVENTF_UP)
type = GDK_TOUCH_END;
else if (inputs[i].dwFlags & GDK_TOUCHEVENTF_MOVE)
type = GDK_TOUCH_UPDATE;
else
continue;
event = gdk_event_new (type);
event->touch.window = window;
event->touch.time = _gdk_win32_get_next_tick (msg->time);
event->touch.x = GDK_WIN32_UNSCALE_D (sx - origin.x);
event->touch.y = GDK_WIN32_UNSCALE_D (sy - origin.y);
event->touch.x_root = GDK_WIN32_SCREEN_TO_ROOT_D (sx, _gdk_offset_x);
event->touch.y_root = GDK_WIN32_SCREEN_TO_ROOT_D (sy, _gdk_offset_y);
event->touch.axes = NULL;
event->touch.state = state;
/* the ids of Windows may be 0 */
event->touch.sequence = GUINT_TO_POINTER (inputs[i].dwID + 1);
event->touch.emulating_pointer = (inputs[i].dwFlags & GDK_TOUCHEVENTF_PRIMARY) != 0;
event->touch.device = _gdk_display->core_pointer;
((GdkEventPrivate *) event)->flags |= GDK_EVENT_TOUCH_SYSTEM_POINTER;
_gdk_win32_append_event (event);
}
p_CloseTouchInputHandle ((HANDLE) msg->lParam);
g_free (inputs);
return TRUE;
}
static void
generate_button_event (GdkEventType type,
gint button,
@ -1900,12 +2066,17 @@ generate_button_event (GdkEventType type,
{
GdkEvent *event = gdk_event_new (type);
if (mouse_message_from_touch ())
((GdkEventPrivate *) event)->flags |= GDK_EVENT_POINTER_EMULATED;
event->button.window = window;
event->button.time = _gdk_win32_get_next_tick (msg->time);
event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
event->button.x_root = msg->pt.x + _gdk_offset_x;
event->button.y_root = msg->pt.y + _gdk_offset_y;
current_x = (gint16) GET_X_LPARAM (msg->lParam);
current_y = (gint16) GET_Y_LPARAM (msg->lParam);
event->button.x = GDK_WIN32_UNSCALE_D (current_x);
event->button.y = GDK_WIN32_UNSCALE_D (current_y);
event->button.x_root = GDK_WIN32_SCREEN_TO_ROOT_D (msg->pt.x, _gdk_offset_x);
event->button.y_root = GDK_WIN32_SCREEN_TO_ROOT_D (msg->pt.y, _gdk_offset_y);
event->button.axes = NULL;
event->button.state = build_pointer_event_state (msg);
event->button.button = button;
@ -2352,6 +2523,10 @@ gdk_event_translate (MSG *msg,
LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (GDK_WIN32_KEYMAP (gdk_keymap_get_default ())))
event->key.hardware_keycode = VK_RSHIFT;
event->key.is_modifier = (msg->wParam == VK_CONTROL ||
msg->wParam == VK_SHIFT ||
msg->wParam == VK_MENU);
/* g_print ("ctrl:%02x lctrl:%02x rctrl:%02x alt:%02x lalt:%02x ralt:%02x\n", key_state[VK_CONTROL], key_state[VK_LCONTROL], key_state[VK_RCONTROL], key_state[VK_MENU], key_state[VK_LMENU], key_state[VK_RMENU]); */
build_key_event_state (event, key_state);
@ -2666,20 +2841,32 @@ gdk_event_translate (MSG *msg,
event = gdk_event_new (GDK_MOTION_NOTIFY);
event->motion.window = window;
event->motion.time = _gdk_win32_get_next_tick (msg->time);
event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
event->motion.x_root = current_root_x;
event->motion.y_root = current_root_y;
current_x = (gint16) GET_X_LPARAM (msg->lParam);
current_y = (gint16) GET_Y_LPARAM (msg->lParam);
event->motion.x = GDK_WIN32_UNSCALE_D (current_x);
event->motion.y = GDK_WIN32_UNSCALE_D (current_y);
event->motion.x_root = GDK_WIN32_UNSCALE_D (current_root_x);
event->motion.y_root = GDK_WIN32_UNSCALE_D (current_root_y);
event->motion.axes = NULL;
event->motion.state = build_pointer_event_state (msg);
event->motion.is_hint = FALSE;
event->motion.device = _gdk_display->core_pointer;
if (mouse_message_from_touch ())
((GdkEventPrivate *) event)->flags |= GDK_EVENT_POINTER_EMULATED;
_gdk_win32_append_event (event);
return_val = TRUE;
break;
case GDK_WM_TOUCH:
if (handle_wm_touch (window, msg))
{
*ret_valp = 0;
return_val = TRUE;
}
break;
case WM_NCMOUSEMOVE:
GDK_NOTE (EVENTS,
g_print (" (%d,%d)",
@ -2778,28 +2965,35 @@ gdk_event_translate (MSG *msg,
ScreenToClient (msg->hwnd, &point);
event = gdk_event_new (GDK_SCROLL);
event->scroll.window = window;
{
/* What the wheel turned, in steps of WHEEL_DELTA: precision
* touchpads and fine wheels send fractions, which become
* smooth scroll events and, once they make up a step, the
* usual ones as well */
static gdouble rest[2];
GdkEvent scroll;
gdouble delta = (short) HIWORD (msg->wParam) / (gdouble) WHEEL_DELTA;
gdouble dx = 0, dy = 0;
if (msg->message == WM_MOUSEWHEEL)
{
event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
GDK_SCROLL_UP : GDK_SCROLL_DOWN;
}
else if (msg->message == WM_MOUSEHWHEEL)
{
event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
GDK_SCROLL_RIGHT : GDK_SCROLL_LEFT;
}
event->scroll.time = _gdk_win32_get_next_tick (msg->time);
event->scroll.x = (gint16) point.x;
event->scroll.y = (gint16) point.y;
event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
event->scroll.state = build_pointer_event_state (msg);
event->scroll.device = _gdk_display->core_pointer;
if (msg->message == WM_MOUSEWHEEL)
dy = - delta;
else
dx = delta;
_gdk_win32_append_event (event);
memset (&scroll, 0, sizeof scroll);
scroll.scroll.type = GDK_SCROLL;
scroll.scroll.window = window;
scroll.scroll.time = _gdk_win32_get_next_tick (msg->time);
scroll.scroll.x = GDK_WIN32_UNSCALE_D ((gint16) point.x);
scroll.scroll.y = GDK_WIN32_UNSCALE_D ((gint16) point.y);
scroll.scroll.x_root = GDK_WIN32_SCREEN_TO_ROOT_D ((gint16) GET_X_LPARAM (msg->lParam), _gdk_offset_x);
scroll.scroll.y_root = GDK_WIN32_SCREEN_TO_ROOT_D ((gint16) GET_Y_LPARAM (msg->lParam), _gdk_offset_y);
scroll.scroll.state = build_pointer_event_state (msg);
scroll.scroll.device = _gdk_display->core_pointer;
_gdk_event_emit_scroll (NULL, &scroll, TRUE, dx, dy, dx, dy, rest,
_gdk_win32_append_event);
}
return_val = TRUE;
break;
@ -3169,8 +3363,8 @@ gdk_event_translate (MSG *msg,
{
/* Resize in increments relative to the base size */
rect.left = rect.top = 0;
rect.right = impl->hints.base_width;
rect.bottom = impl->hints.base_height;
rect.right = GDK_WIN32_SC (impl->hints.base_width);
rect.bottom = GDK_WIN32_SC (impl->hints.base_height);
_gdk_win32_adjust_client_rect (window, &rect);
point.x = rect.left;
point.y = rect.top;
@ -3192,53 +3386,53 @@ gdk_event_translate (MSG *msg,
case WMSZ_BOTTOM:
if (drag->bottom == rect.bottom)
break;
adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
adjust_drag (&drag->bottom, rect.bottom, GDK_WIN32_SC (impl->hints.height_inc));
break;
case WMSZ_BOTTOMLEFT:
if (drag->bottom == rect.bottom && drag->left == rect.left)
break;
adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
adjust_drag (&drag->bottom, rect.bottom, GDK_WIN32_SC (impl->hints.height_inc));
adjust_drag (&drag->left, rect.left, GDK_WIN32_SC (impl->hints.width_inc));
break;
case WMSZ_LEFT:
if (drag->left == rect.left)
break;
adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
adjust_drag (&drag->left, rect.left, GDK_WIN32_SC (impl->hints.width_inc));
break;
case WMSZ_TOPLEFT:
if (drag->top == rect.top && drag->left == rect.left)
break;
adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
adjust_drag (&drag->top, rect.top, GDK_WIN32_SC (impl->hints.height_inc));
adjust_drag (&drag->left, rect.left, GDK_WIN32_SC (impl->hints.width_inc));
break;
case WMSZ_TOP:
if (drag->top == rect.top)
break;
adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
adjust_drag (&drag->top, rect.top, GDK_WIN32_SC (impl->hints.height_inc));
break;
case WMSZ_TOPRIGHT:
if (drag->top == rect.top && drag->right == rect.right)
break;
adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
adjust_drag (&drag->top, rect.top, GDK_WIN32_SC (impl->hints.height_inc));
adjust_drag (&drag->right, rect.right, GDK_WIN32_SC (impl->hints.width_inc));
break;
case WMSZ_RIGHT:
if (drag->right == rect.right)
break;
adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
adjust_drag (&drag->right, rect.right, GDK_WIN32_SC (impl->hints.width_inc));
break;
case WMSZ_BOTTOMRIGHT:
if (drag->bottom == rect.bottom && drag->right == rect.right)
break;
adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
adjust_drag (&drag->bottom, rect.bottom, GDK_WIN32_SC (impl->hints.height_inc));
adjust_drag (&drag->right, rect.right, GDK_WIN32_SC (impl->hints.width_inc));
break;
}
@ -3375,8 +3569,8 @@ gdk_event_translate (MSG *msg,
if (impl->hint_flags & GDK_HINT_MIN_SIZE)
{
rect.left = rect.top = 0;
rect.right = impl->hints.min_width;
rect.bottom = impl->hints.min_height;
rect.right = GDK_WIN32_SC (impl->hints.min_width);
rect.bottom = GDK_WIN32_SC (impl->hints.min_height);
_gdk_win32_adjust_client_rect (window, &rect);
@ -3389,8 +3583,8 @@ gdk_event_translate (MSG *msg,
int maxw, maxh;
rect.left = rect.top = 0;
rect.right = impl->hints.max_width;
rect.bottom = impl->hints.max_height;
rect.right = GDK_WIN32_SC (impl->hints.max_width);
rect.bottom = GDK_WIN32_SC (impl->hints.max_height);
_gdk_win32_adjust_client_rect (window, &rect);
@ -3402,8 +3596,36 @@ gdk_event_translate (MSG *msg,
}
else
{
/* Apparently, this is just a very big number (bigger than any widget
* could realistically be) to make sure the window is as big as
* possible when maximized.
*/
mmi->ptMaxTrackSize.x = 30000;
mmi->ptMaxTrackSize.y = 30000;
/* A window without a frame would be maximized over the whole
* monitor, taskbar included. Windows wants the maximized position
* and size as if the window were on the primary monitor, so only
* the taskbar of the nearest monitor is taken into account.
*/
if ((GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE) &
(WS_BORDER | WS_THICKFRAME)) == 0)
{
HMONITOR nearest_monitor;
MONITORINFO nearest_info;
nearest_monitor = MonitorFromWindow (GDK_WINDOW_HWND (window),
MONITOR_DEFAULTTONEAREST);
nearest_info.cbSize = sizeof (nearest_info);
if (GetMonitorInfoA (nearest_monitor, &nearest_info))
{
mmi->ptMaxPosition.x = nearest_info.rcWork.left - nearest_info.rcMonitor.left;
mmi->ptMaxPosition.y = nearest_info.rcWork.top - nearest_info.rcMonitor.top;
mmi->ptMaxSize.x = nearest_info.rcWork.right - nearest_info.rcWork.left;
mmi->ptMaxSize.y = nearest_info.rcWork.bottom - nearest_info.rcWork.top;
}
}
}
if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
@ -3533,6 +3755,21 @@ gdk_event_translate (MSG *msg,
break;
}
}
else if (msg->wParam == CF_HDROP)
{
/* the URIs of the clipboard as files for Explorer */
_delayed_rendering_data =
_gdk_win32_selection_convert_to_hdrop (_delayed_rendering_data);
if (!_delayed_rendering_data)
break;
}
else if (msg->wParam == _cf_preferred_drop_effect)
{
_delayed_rendering_data =
_gdk_win32_selection_convert_to_drop_effect (_delayed_rendering_data);
if (!_delayed_rendering_data)
break;
}
/* The requestor is holding the clipboard, no
* OpenClipboard() is required/possible
@ -3654,7 +3891,7 @@ gdk_event_prepare (GSource *source,
retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
(modal_win32_dialog == NULL &&
GetQueueStatus (QS_ALLINPUT) != 0));
GetQueueStatus (GDK_QS_INPUT) != 0));
GDK_THREADS_LEAVE ();
@ -3672,7 +3909,7 @@ gdk_event_check (GSource *source)
{
retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
(modal_win32_dialog == NULL &&
GetQueueStatus (QS_ALLINPUT) != 0));
GetQueueStatus (GDK_QS_INPUT) != 0));
}
else
{

View file

@ -745,7 +745,7 @@ static GdkDrawableImplWin32 *
get_impl_drawable (GdkDrawable *drawable)
{
if (GDK_IS_OFFSCREEN_WINDOW (drawable))
return _gdk_offscreen_window_get_real_drawable (GDK_OFFSCREEN_WINDOW (drawable));
return GDK_DRAWABLE_IMPL_WIN32 (_gdk_offscreen_window_get_real_drawable (GDK_OFFSCREEN_WINDOW (drawable)));
if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable))
return GDK_DRAWABLE_IMPL_WIN32(drawable);
else if (GDK_IS_WINDOW (drawable))
@ -808,6 +808,49 @@ get_impl_drawable (GdkDrawable *drawable)
*
* Return value: The HDC.
**/
/* HiDPI: a logical unit of the DC as @scale of its pixels (1 for the
* pixels themselves) */
void
_gdk_win32_dc_set_scale (HDC hdc,
gint scale)
{
if (_gdk_win32_scale <= 1)
return;
if (scale > 1)
{
SetMapMode (hdc, MM_ANISOTROPIC);
SetWindowExtEx (hdc, 1, 1, NULL);
SetViewportExtEx (hdc, scale, scale, NULL);
}
else
SetMapMode (hdc, MM_TEXT);
}
/* an HRGN of logical units of GDK as one of Windows */
HRGN
_gdk_win32_hrgn_scale (HRGN hrgn)
{
XFORM xform = { 0 };
DWORD size;
RGNDATA *data;
HRGN result;
if (_gdk_win32_scale <= 1 || (size = GetRegionData (hrgn, 0, NULL)) == 0)
return hrgn;
data = g_malloc (size);
GetRegionData (hrgn, size, data);
xform.eM11 = xform.eM22 = (FLOAT) _gdk_win32_scale;
result = ExtCreateRegion (&xform, size, data);
g_free (data);
if (!result)
return hrgn;
DeleteObject (hrgn);
return result;
}
HDC
gdk_win32_hdc_get (GdkDrawable *drawable,
GdkGC *gc,
@ -830,6 +873,11 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
WIN32_GDI_FAILED ("SaveDC"), ok = FALSE;
/* HiDPI: GDK draws in its pixels, Windows maps them to its own (the
* DC goes back to them with RestoreDC in gdk_win32_hdc_release) */
if (ok)
_gdk_win32_dc_set_scale (win32_gc->hdc, _gdk_win32_drawable_scale (GDK_DRAWABLE (impl)));
if (ok && (usage & (GDK_GC_FOREGROUND | GDK_GC_BACKGROUND)))
ok = predraw (gc, impl->colormap);
@ -873,6 +921,23 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
style = win32_gc->pen_dashes;
}
/* a cosmetic pen is one pixel of Windows wide, whatever the
* mapping; a geometric one gets as wide as GDK's pixel */
if (_gdk_win32_scale > 1 &&
(win32_gc->pen_style & PS_TYPE_MASK) == PS_COSMETIC)
win32_gc->pen_style = (win32_gc->pen_style & ~(PS_TYPE_MASK | PS_STYLE_MASK)) |
PS_GEOMETRIC | PS_ENDCAP_FLAT |
((win32_gc->pen_style & PS_STYLE_MASK) == PS_ALTERNATE
? PS_USERSTYLE : (win32_gc->pen_style & PS_STYLE_MASK));
if ((win32_gc->pen_style & PS_STYLE_MASK) == PS_USERSTYLE && !style)
{
static const DWORD dots[2] = { 1, 1 };
style_count = win32_gc->pen_dashes ? win32_gc->pen_num_dashes : 2;
style = win32_gc->pen_dashes ? win32_gc->pen_dashes : dots;
}
if ((hpen = ExtCreatePen (win32_gc->pen_style,
MAX (win32_gc->pen_width, 1),
&logbrush,
@ -906,6 +971,7 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
if (ok && win32_gc->values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN) &&
OffsetClipRgn (win32_gc->hdc,
/* logical units: the mapping scales them */
win32_gc->values_mask & GDK_GC_CLIP_X_ORIGIN ? gc->clip_x_origin : 0,
win32_gc->values_mask & GDK_GC_CLIP_Y_ORIGIN ? gc->clip_y_origin : 0) == ERROR)
WIN32_API_FAILED ("OffsetClipRgn"), ok = FALSE;
@ -1010,8 +1076,11 @@ _gdk_win32_bitmap_to_hrgn (GdkPixmap *pixmap)
g_assert (GDK_PIXMAP_OBJECT(pixmap)->depth == 1);
bits = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->bits;
/* the bits, so an HRGN in pixels of Windows (HiDPI) */
width = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->width;
height = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->height;
width *= MAX (GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->scale, 1);
height *= MAX (GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->scale, 1);
bpl = ((width - 1)/32 + 1)*4;
/* For better performances, we will use the ExtCreateRegion()
@ -1104,6 +1173,10 @@ _gdk_win32_bitmap_to_hrgn (GdkPixmap *pixmap)
/* Clean up*/
g_free (pData);
/* a bitmap of a GdkImage has GDK's pixels (HiDPI) */
if (hRgn && GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->scale <= 1)
hRgn = _gdk_win32_hrgn_scale (hRgn);
return hRgn;
}
@ -1131,10 +1204,11 @@ _gdk_win32_gdkregion_to_hrgn (const GdkRegion *region,
{
rect = ((RECT *) rgndata->Buffer) + rgndata->rdh.nCount++;
rect->left = boxes[i].x1 + x_origin;
rect->right = boxes[i].x2 + x_origin;
rect->top = boxes[i].y1 + y_origin;
rect->bottom = boxes[i].y2 + y_origin;
/* a region of GDK, an HRGN in pixels of Windows */
rect->left = GDK_WIN32_SC (boxes[i].x1 + x_origin);
rect->right = GDK_WIN32_SC (boxes[i].x2 + x_origin);
rect->top = GDK_WIN32_SC (boxes[i].y1 + y_origin);
rect->bottom = GDK_WIN32_SC (boxes[i].y2 + y_origin);
if (rect->left < rgndata->rdh.rcBound.left)
rgndata->rdh.rcBound.left = rect->left;

View file

@ -97,8 +97,9 @@ _gdk_window_move_resize_child (GdkWindow *window,
width, height));
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
obj->x + obj->parent->abs_x, obj->y + obj->parent->abs_y,
width, height,
GDK_WIN32_SC (obj->x + obj->parent->abs_x),
GDK_WIN32_SC (obj->y + obj->parent->abs_y),
GDK_WIN32_SC (width), GDK_WIN32_SC (height),
SWP_NOACTIVATE | SWP_NOZORDER));
//_gdk_win32_window_tmp_reset_parent_bg (window);

View file

@ -37,6 +37,7 @@ gint _gdk_num_monitors;
GdkWin32Monitor *_gdk_monitors = NULL;
gint _gdk_offset_x, _gdk_offset_y;
gint _gdk_win32_scale = 1;
HDC _gdk_display_hdc;
HINSTANCE _gdk_dll_hinstance;
@ -69,6 +70,8 @@ UINT _cf_png;
UINT _cf_jfif;
UINT _cf_gif;
UINT _cf_url;
UINT _cf_preferred_drop_effect;
GdkAtom _gnome_copied_files;
UINT _cf_html_format;
UINT _cf_text_html;

View file

@ -175,7 +175,7 @@ gdk_image_new_bitmap (GdkVisual *visual,
gint data_bpl = (w-1)/8 + 1;
gint i;
pixmap = gdk_pixmap_new (NULL, w, h, 1);
pixmap = _gdk_win32_pixmap_new_unscaled (w, h, 1);
if (pixmap == NULL)
return NULL;
@ -223,7 +223,7 @@ _gdk_image_new_for_depth (GdkScreen *screen,
if (visual)
depth = visual->depth;
pixmap = gdk_pixmap_new (NULL, width, height, depth);
pixmap = _gdk_win32_pixmap_new_unscaled (width, height, depth);
if (pixmap == NULL)
return NULL;

View file

@ -778,9 +778,9 @@ gdk_input_get_root_relative_geometry (HWND w,
ClientToScreen (w, &pt);
if (x_ret)
*x_ret = pt.x + _gdk_offset_x;
*x_ret = GDK_WIN32_SCREEN_TO_ROOT_X (pt.x);
if (y_ret)
*y_ret = pt.y + _gdk_offset_y;
*y_ret = GDK_WIN32_SCREEN_TO_ROOT_Y (pt.y);
}
void

View file

@ -1289,7 +1289,7 @@ gdk_keymap_get_entries_for_keyval (GdkKeymap *gdk_keymap,
else
keymap = GDK_WIN32_KEYMAP (gdk_keymap);
update_keymap (gdk_keymap);
update_keymap (GDK_KEYMAP (keymap));
for (vk = 0; vk < KEY_STATE_SIZE; vk++)
{

View file

@ -74,6 +74,65 @@ DllMain (HINSTANCE hinstDLL,
return TRUE;
}
/* HiDPI. Without telling Windows that it handles the resolution itself,
* a program is drawn at 96 dpi and enlarged by Windows (blurred, from
* 150 %), or (XP, and below 150 % with "XP style" scaling) its fonts
* just stay small. So GDK tells it (Vista: SetProcessDPIAware, from
* 8.1 the system resolution of SetProcessDpiAwareness) and scales by
* itself: at 192 dpi and more each of its pixels is 2 of Windows (as on
* X11, see _gdk_x11_screen_new()), what remains of a fraction goes to
* the fonts (120 dpi: 1 with fonts of 120 dpi). GDK_SCALE sets the
* scale; GDK_WIN32_DPI_AWARE=0 leaves it to Windows as before. */
static gint win32_font_dpi = 0;
gint
_gdk_win32_font_dpi (void)
{
return win32_font_dpi;
}
void
_gdk_win32_init_scale (void)
{
typedef HRESULT (WINAPI *t_SetProcessDpiAwareness) (int);
typedef BOOL (WINAPI *t_SetProcessDPIAware) (void);
const gchar *env = g_getenv ("GDK_WIN32_DPI_AWARE");
const gchar *scale_env = g_getenv ("GDK_SCALE");
gboolean aware = !(env && env[0] == '0');
HDC hdc;
gint dpi;
if (aware)
{
HMODULE shcore = LoadLibraryA ("shcore.dll");
t_SetProcessDpiAwareness set_awareness = shcore ?
(t_SetProcessDpiAwareness) GetProcAddress (shcore, "SetProcessDpiAwareness") : NULL;
t_SetProcessDPIAware set_aware = (t_SetProcessDPIAware)
GetProcAddress (GetModuleHandleA ("user32.dll"), "SetProcessDPIAware");
/* 1: PROCESS_SYSTEM_DPI_AWARE; fails where a manifest said it */
if (!set_awareness || set_awareness (1) != S_OK)
if (set_aware)
set_aware ();
}
hdc = GetDC (NULL);
dpi = GetDeviceCaps (hdc, LOGPIXELSY);
ReleaseDC (NULL, hdc);
if (dpi <= 0)
dpi = 96;
_gdk_win32_scale = 1;
if (scale_env && atoi (scale_env) >= 1)
_gdk_win32_scale = MIN (atoi (scale_env), 8);
else if (aware)
_gdk_win32_scale = CLAMP ((gint) (dpi / 96.0 + 0.25), 1, 8);
/* fonts: the resolution in pixels of GDK, where Windows has another */
if (aware && (dpi != 96 || _gdk_win32_scale > 1))
win32_font_dpi = dpi / _gdk_win32_scale >= 72 ? dpi / _gdk_win32_scale : dpi;
}
void
_gdk_windowing_init (void)
{
@ -88,6 +147,7 @@ _gdk_windowing_init (void)
GdiSetBatchLimit (1);
_gdk_app_hmodule = GetModuleHandle (NULL);
_gdk_win32_init_scale ();
_gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL);
_gdk_input_locale = GetKeyboardLayout (0);
_gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (gdk_keymap_get_default ()), _gdk_input_locale);
@ -130,6 +190,9 @@ _gdk_windowing_init (void)
_cf_gif = RegisterClipboardFormat ("GIF");
_cf_url = RegisterClipboardFormat ("UniformResourceLocatorW");
/* Explorer: whether files on the clipboard were cut or copied */
_cf_preferred_drop_effect = RegisterClipboardFormat ("Preferred DropEffect");
_gnome_copied_files = gdk_atom_intern_static_string ("x-special/gnome-copied-files");
_cf_html_format = RegisterClipboardFormat ("HTML Format");
_cf_text_html = RegisterClipboardFormat ("text/html");
@ -178,13 +241,13 @@ gdk_screen_get_height (GdkScreen *screen)
gint
gdk_screen_get_width_mm (GdkScreen *screen)
{
return (double) gdk_screen_get_width (screen) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSX) * 25.4;
return (double) GDK_WIN32_SC (gdk_screen_get_width (screen)) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSX) * 25.4;
}
gint
gdk_screen_get_height_mm (GdkScreen *screen)
{
return (double) gdk_screen_get_height (screen) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSY) * 25.4;
return (double) GDK_WIN32_SC (gdk_screen_get_height (screen)) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSY) * 25.4;
}
void

View file

@ -86,6 +86,25 @@ gdk_pixmap_impl_win32_init (GdkPixmapImplWin32 *impl)
{
impl->width = 1;
impl->height = 1;
impl->scale = 1;
}
static gboolean pixmap_unscaled = FALSE;
/* a pixmap whose bitmap has one pixel for each of GDK (HiDPI), for
* GdkImage */
GdkPixmap *
_gdk_win32_pixmap_new_unscaled (gint width,
gint height,
gint depth)
{
GdkPixmap *pixmap;
pixmap_unscaled = TRUE;
pixmap = gdk_pixmap_new (NULL, width, height, depth);
pixmap_unscaled = FALSE;
return pixmap;
}
static void
@ -221,6 +240,11 @@ _gdk_pixmap_new (GdkDrawable *drawable,
pixmap_impl->height = height;
GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
/* HiDPI: the bitmap in pixels of Windows */
pixmap_impl->scale = pixmap_unscaled ? 1 : _gdk_win32_scale;
width *= pixmap_impl->scale;
height *= pixmap_impl->scale;
if (depth == window_depth)
{
cmap = gdk_drawable_get_colormap (drawable);
@ -336,6 +360,11 @@ _gdk_pixmap_new (GdkDrawable *drawable,
/* No need to create a new surface when needed, as we have one already */
drawable_impl->cairo_surface = dib_surface;
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0)
/* HiDPI: drawn on in pixels of GDK */
if (pixmap_impl->scale > 1)
cairo_surface_set_device_scale (dib_surface, pixmap_impl->scale, pixmap_impl->scale);
#endif
drawable_impl->handle = hbitmap;
pixmap_impl->bits = bits;
@ -407,11 +436,27 @@ _gdk_bitmap_create_from_data (GdkDrawable *drawable,
pixmap_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl);
bits = pixmap_impl->bits;
data_bpl = ((width - 1) / 8 + 1);
pixmap_bpl = ((width - 1)/32 + 1)*4;
for (i = 0; i < height; i++)
for (j = 0; j < data_bpl; j++)
bits[i*pixmap_bpl + j] = mirror[(guchar) data[i*data_bpl + j]];
if (pixmap_impl->scale > 1)
{
/* HiDPI: each bit as a block of the bitmap's pixels */
gint s = pixmap_impl->scale, dw = width * s;
pixmap_bpl = ((dw - 1)/32 + 1)*4;
memset (bits, 0, pixmap_bpl * height * s);
for (i = 0; i < height * s; i++)
for (j = 0; j < dw; j++)
if ((guchar) data[(i / s) * data_bpl + (j / s) / 8] & (1 << ((j / s) % 8)))
bits[i * pixmap_bpl + j / 8] |= 0x80 >> (j % 8);
}
else
{
pixmap_bpl = ((width - 1)/32 + 1)*4;
for (i = 0; i < height; i++)
for (j = 0; j < data_bpl; j++)
bits[i*pixmap_bpl + j] = mirror[(guchar) data[i*data_bpl + j]];
}
GDK_NOTE (PIXMAP, g_print ("gdk_bitmap_create_from_data: %dx%d=%p\n",
width, height, GDK_PIXMAP_HBITMAP (pixmap)));
@ -519,8 +564,10 @@ gdk_pixmap_foreign_new (GdkNativeWindow anid)
draw_impl->handle = hbitmap;
draw_impl->colormap = NULL;
pix_impl->is_foreign = TRUE;
pix_impl->width = size.cx;
pix_impl->height = size.cy;
/* in pixels of GDK */
pix_impl->scale = _gdk_win32_scale;
pix_impl->width = MAX (size.cx / _gdk_win32_scale, 1);
pix_impl->height = MAX (size.cy / _gdk_win32_scale, 1);
pix_impl->bits = NULL;
gdk_win32_handle_table_insert (&GDK_PIXMAP_HBITMAP (pixmap), pixmap);

View file

@ -54,6 +54,9 @@ struct _GdkPixmapImplWin32
guchar *bits;
guint is_foreign : 1;
guint is_allocated : 1;
/* HiDPI: pixels of the bitmap for one of GDK (1 for the pixmaps
* behind a GdkImage, whose memory programs use directly) */
gint scale;
};
struct _GdkPixmapImplWin32Class

View file

@ -396,6 +396,41 @@ extern GdkWin32Monitor *_gdk_monitors;
*/
extern gint _gdk_offset_x, _gdk_offset_y;
/* HiDPI: pixels of Windows for one of GDK, in each direction (see
* _gdk_win32_init_scale()); sizes and window coordinates of GDK are
* multiplied by it for Windows, root coordinates also moved by the
* offset of the virtual screen, which is in pixels of Windows */
extern gint _gdk_win32_scale;
static inline gint
_gdk_win32_unscale (gint value)
{
gint s = _gdk_win32_scale;
return value >= 0 ? value / s : - ((- value + s - 1) / s);
}
static inline gint
_gdk_win32_unscale_up (gint value)
{
return - _gdk_win32_unscale (- value);
}
#define GDK_WIN32_SC(v) ((v) * _gdk_win32_scale)
/* for coordinates of events, which keep the fraction */
#define GDK_WIN32_UNSCALE_D(v) ((gdouble) (v) / _gdk_win32_scale)
#define GDK_WIN32_SCREEN_TO_ROOT_D(x, off) (((gdouble) (x) + (off)) / _gdk_win32_scale)
#define GDK_WIN32_ROOT_TO_SCREEN_X(x) ((x) * _gdk_win32_scale - _gdk_offset_x)
#define GDK_WIN32_ROOT_TO_SCREEN_Y(y) ((y) * _gdk_win32_scale - _gdk_offset_y)
#define GDK_WIN32_SCREEN_TO_ROOT_X(x) (_gdk_win32_unscale ((x) + _gdk_offset_x))
#define GDK_WIN32_SCREEN_TO_ROOT_Y(y) (_gdk_win32_unscale ((y) + _gdk_offset_y))
void _gdk_win32_init_scale (void);
gint _gdk_win32_font_dpi (void);
void _gdk_win32_dc_set_scale (HDC hdc, gint scale);
gint _gdk_win32_drawable_scale (GdkDrawable *drawable);
GdkPixmap *_gdk_win32_pixmap_new_unscaled (gint width, gint height, gint depth);
HRGN _gdk_win32_hrgn_scale (HRGN hrgn);
extern HDC _gdk_display_hdc;
extern HINSTANCE _gdk_dll_hinstance;
extern HINSTANCE _gdk_app_hmodule;
@ -435,6 +470,13 @@ extern UINT _cf_png;
extern UINT _cf_jfif;
extern UINT _cf_gif;
extern UINT _cf_url;
extern UINT _cf_preferred_drop_effect;
gchar *_gdk_win32_hdrop_to_uri_list (HGLOBAL hdata,
const gchar *separator);
HGLOBAL _gdk_win32_selection_convert_to_hdrop (HGLOBAL hdata);
HGLOBAL _gdk_win32_selection_convert_to_drop_effect (HGLOBAL hdata);
extern GdkAtom _gnome_copied_files;
extern UINT _cf_html_format;
extern UINT _cf_text_html;
@ -494,6 +536,10 @@ HICON _gdk_win32_pixbuf_to_hcursor (GdkPixbuf *pixbuf,
gint y_hotspot);
gboolean _gdk_win32_pixbuf_to_hicon_supports_alpha (void);
/* Windows 7 touches (WM_TOUCH) for windows with GDK_TOUCH_MASK */
void _gdk_win32_window_update_touch (GdkWindow *window,
gboolean touch);
void _gdk_win32_append_event (GdkEvent *event);
void _gdk_win32_emit_configure_event (GdkWindow *window);
GdkWindow *_gdk_win32_find_window_for_mouse_event (GdkWindow* reported_window,

View file

@ -29,6 +29,7 @@
#include <string.h>
#include <stdlib.h>
#include <glib/gprintf.h>
#include <pango/pangowin32.h>
#include "gdkscreen.h"
#include "gdkproperty.h"
@ -311,6 +312,49 @@ gdk_property_delete (GdkWindow *window,
}
}
/* the message font of Windows as a pango font name with its size in
* points, or NULL; bitmap fonts are left out, pango can not use them */
static gchar *
get_system_font_name (HDC hdc)
{
NONCLIENTMETRICSW ncm;
PangoFontDescription *font_desc;
gchar *result, *font_desc_string;
int logpixelsy;
gint font_size;
/* without iPaddedBorderWidth, which Windows before Vista refuses */
ncm.cbSize = G_STRUCT_OFFSET (NONCLIENTMETRICSW, lfMessageFont) + sizeof (LOGFONTW);
if (!SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0))
return NULL;
if (ncm.lfMessageFont.lfFaceName[0] == 0 ||
ncm.lfMessageFont.lfOutPrecision == OUT_STRING_PRECIS ||
ncm.lfMessageFont.lfHeight >= 0)
return NULL;
logpixelsy = GetDeviceCaps (hdc, LOGPIXELSY);
if (logpixelsy <= 0)
return NULL;
font_desc = pango_win32_font_description_from_logfontw (&ncm.lfMessageFont);
pango_font_description_unset_fields (font_desc, PANGO_FONT_MASK_SIZE);
font_desc_string = pango_font_description_to_string (font_desc);
pango_font_description_free (font_desc);
font_size = -MulDiv (ncm.lfMessageFont.lfHeight, 72, logpixelsy);
if (font_size <= 0)
{
g_free (font_desc_string);
return NULL;
}
result = g_strdup_printf ("%s %d", font_desc_string, font_size);
g_free (font_desc_string);
return result;
}
/*
For reference, from gdk/x11/gdksettings.c:
@ -390,18 +434,24 @@ gdk_screen_get_setting (GdkScreen *screen,
}
else if (strcmp ("gtk-double-click-distance", name) == 0)
{
gint i = MAX(GetSystemMetrics (SM_CXDOUBLECLK), GetSystemMetrics (SM_CYDOUBLECLK));
gint i = MAX (_gdk_win32_unscale_up (MAX(GetSystemMetrics (SM_CXDOUBLECLK), GetSystemMetrics (SM_CYDOUBLECLK))), 1);
GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
g_value_set_int (value, i);
return TRUE;
}
else if (strcmp ("gtk-dnd-drag-threshold", name) == 0)
{
gint i = MAX(GetSystemMetrics (SM_CXDRAG), GetSystemMetrics (SM_CYDRAG));
gint i = MAX (_gdk_win32_unscale_up (MAX(GetSystemMetrics (SM_CXDRAG), GetSystemMetrics (SM_CYDRAG))), 1);
GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i));
g_value_set_int (value, i);
return TRUE;
}
else if (strcmp ("gtk-xft-dpi", name) == 0 && _gdk_win32_font_dpi () > 0)
{
/* HiDPI: the resolution of Windows for fonts in pixels of GDK */
g_value_set_int (value, _gdk_win32_font_dpi () * 1024);
return TRUE;
}
else if (strcmp ("gtk-split-cursor", name) == 0)
{
GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : FALSE\n", name));
@ -420,41 +470,29 @@ gdk_screen_get_setting (GdkScreen *screen,
g_value_set_boolean (value, TRUE);
return TRUE;
}
#if 0
/*
* With 'MS Sans Serif' as windows menu font (default on win98se) you'll get a
* bunch of :
* WARNING **: Couldn't load font "MS Sans Serif 8" falling back to "Sans 8"
* at least with testfilechooser (regardless of the bitmap check below)
* so just disabling this code seems to be the best we can do --hb
*/
else if (strcmp ("gtk-font-name", name) == 0)
{
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, FALSE))
{
/* Pango finally uses GetDeviceCaps to scale, we use simple
* approximation here.
*/
int nHeight = (0 > ncm.lfMenuFont.lfHeight ? -3*ncm.lfMenuFont.lfHeight/4 : 10);
if (OUT_STRING_PRECIS == ncm.lfMenuFont.lfOutPrecision)
GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : ignoring bitmap font '%s'\n",
name, ncm.lfMenuFont.lfFaceName));
else if (ncm.lfMenuFont.lfFaceName && strlen(ncm.lfMenuFont.lfFaceName) > 0 &&
/* Avoid issues like those described in bug #135098 */
g_utf8_validate (ncm.lfMenuFont.lfFaceName, -1, NULL))
{
char* s = g_strdup_printf ("%s %d", ncm.lfMenuFont.lfFaceName, nHeight);
GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : %s\n", name, s));
g_value_set_string (value, s);
/* The message font of Windows ("Segoe UI 9", "Tahoma 8" on XP), as
* in GTK+ 3. A theme that sets gtk-font-name still wins. Before
* pango 1.43 the fallback list of pango only gave a good coverage
* of glyphs for "Segoe UI", so any other font is left to pango. */
gchar *font_name = get_system_font_name (_gdk_display_hdc);
g_free(s);
return TRUE;
}
if (font_name &&
pango_version_check (1, 43, 0) != NULL &&
g_ascii_strncasecmp (font_name, "Segoe UI", strlen ("Segoe UI")) != 0)
{
g_free (font_name);
font_name = NULL;
}
if (font_name)
{
GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %s\n", name, font_name));
g_value_take_string (value, font_name);
return TRUE;
}
}
#endif
return FALSE;
}

View file

@ -182,3 +182,18 @@ gdk_screen_is_composited (GdkScreen *screen)
return FALSE;
}
/* HiDPI: one scale for the program (see _gdk_win32_init_scale()) */
gint
_gdk_windowing_drawable_get_scale (GdkDrawable *drawable)
{
return _gdk_win32_drawable_scale (drawable);
}
gint
_gdk_windowing_screen_get_monitor_scale (GdkScreen *screen,
gint monitor_num)
{
return _gdk_win32_scale;
}

View file

@ -35,6 +35,8 @@
#include "gdkdisplay.h"
#include "gdkprivate-win32.h"
#include <shlobj.h> /* DROPFILES, DROPEFFECT_* of Explorer */
/* We emulate the GDK_SELECTION window properties of windows (as used
* in the X11 backend) by using a hash table from window handles to
* GdkSelProp structs.
@ -420,11 +422,14 @@ gdk_selection_convert (GdkWindow *requestor,
gboolean has_text = FALSE;
gboolean has_png = FALSE;
gboolean has_bmp = FALSE;
gboolean has_uris = FALSE;
gboolean has_copied_files = FALSE;
if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor))))
return;
targets = g_new (GdkAtom, CountClipboardFormats ());
/* CF_HDROP can stand for two */
targets = g_new (GdkAtom, CountClipboardFormats () + 2);
ntargets = 0;
for (fmt = 0; 0 != (fmt = EnumClipboardFormats (fmt)); )
@ -475,9 +480,31 @@ gdk_selection_convert (GdkWindow *requestor,
if (!has_png)
targets[ntargets++] = _image_gif;
}
else if (fmt == CF_HDROP)
{
/* files from Explorer, for programs that take URIs and for
* file managers, as long as they are not there as such */
if (!has_uris)
targets[ntargets++] = _text_uri_list;
if (!has_copied_files)
targets[ntargets++] = _gnome_copied_files;
has_uris = has_copied_files = TRUE;
}
else if (GetClipboardFormatName (fmt, sFormat, 80) > 0)
{
if (strcmp (sFormat, "image/bmp") == 0 ||
if (strcmp (sFormat, "text/uri-list") == 0)
{
if (!has_uris)
targets[ntargets++] = _text_uri_list;
has_uris = TRUE;
}
else if (strcmp (sFormat, "x-special/gnome-copied-files") == 0)
{
if (!has_copied_files)
targets[ntargets++] = _gnome_copied_files;
has_copied_files = TRUE;
}
else if (strcmp (sFormat, "image/bmp") == 0 ||
strcmp (sFormat, "image/x-bmp") == 0 ||
strcmp (sFormat, "image/x-MS-bmp") == 0 ||
strcmp (sFormat, "image/x-icon") == 0 ||
@ -740,6 +767,55 @@ gdk_selection_convert (GdkWindow *requestor,
}
}
API_CALL (CloseClipboard, ());
}
else if (selection == GDK_SELECTION_CLIPBOARD &&
(target == _text_uri_list || target == _gnome_copied_files) &&
!IsClipboardFormatAvailable (RegisterClipboardFormat (target == _text_uri_list
? "text/uri-list"
: "x-special/gnome-copied-files")) &&
IsClipboardFormatAvailable (CF_HDROP))
{
/* files from Explorer */
gchar *text = NULL;
if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor))))
return;
if ((hdata = GetClipboardData (CF_HDROP)) != NULL)
{
HGLOBAL effect_data = GetClipboardData (_cf_preferred_drop_effect);
DWORD effect = DROPEFFECT_COPY;
gchar *uris = _gdk_win32_hdrop_to_uri_list (hdata, target == _text_uri_list ? "\r\n" : "\n");
if (effect_data != NULL && GlobalSize (effect_data) >= sizeof (DWORD))
{
DWORD *ptr = GlobalLock (effect_data);
if (ptr)
{
effect = *ptr;
GlobalUnlock (effect_data);
}
}
if (target == _text_uri_list)
text = uris;
else
{
/* as Nautilus: no newline after the last */
if (g_str_has_suffix (uris, "\n"))
uris[strlen (uris) - 1] = '\0';
text = g_strconcat ((effect & DROPEFFECT_MOVE) ? "cut\n" : "copy\n", uris, NULL);
g_free (uris);
}
}
if (text)
selection_property_store (requestor, target, 8, (guchar *) text, strlen (text));
else
property = GDK_NONE;
API_CALL (CloseClipboard, ());
}
else if (selection == GDK_SELECTION_CLIPBOARD)
@ -1244,6 +1320,26 @@ gdk_win32_selection_add_targets (GdkWindow *owner,
targets[i] == text_plain)
continue;
/* files: Explorer takes them as CF_HDROP, and whether they were
* cut from Preferred DropEffect, made from the list of the
* clipboard of file managers when asked for */
if (targets[i] == _text_uri_list)
{
g_hash_table_replace (_format_atom_table,
GINT_TO_POINTER (CF_HDROP),
targets[i]);
GDK_NOTE (DND, g_print ("... SetClipboardData(CF_HDROP,NULL)\n"));
SetClipboardData (CF_HDROP, NULL);
}
else if (targets[i] == _gnome_copied_files)
{
g_hash_table_replace (_format_atom_table,
GINT_TO_POINTER (_cf_preferred_drop_effect),
targets[i]);
GDK_NOTE (DND, g_print ("... SetClipboardData(Preferred DropEffect,NULL)\n"));
SetClipboardData (_cf_preferred_drop_effect, NULL);
}
target_name = gdk_atom_name (targets[i]);
if (g_str_has_prefix (target_name, "text/plain;charset="))
@ -1310,3 +1406,118 @@ _gdk_win32_selection_convert_to_dib (HGLOBAL hdata,
return NULL;
}
/* The files of CF_HDROP (Explorer) as URIs, each followed by @separator */
gchar *
_gdk_win32_hdrop_to_uri_list (HGLOBAL hdata,
const gchar *separator)
{
HDROP hdrop = (HDROP) hdata;
GString *result = g_string_new (NULL);
UINT i, n;
n = DragQueryFileW (hdrop, 0xFFFFFFFF, NULL, 0);
for (i = 0; i < n; i++)
{
UINT length = DragQueryFileW (hdrop, i, NULL, 0);
wchar_t *wpath = g_new0 (wchar_t, length + 1);
gchar *path, *uri;
DragQueryFileW (hdrop, i, wpath, length + 1);
path = g_utf16_to_utf8 (wpath, -1, NULL, NULL, NULL);
uri = path ? g_filename_to_uri (path, NULL, NULL) : NULL;
if (uri)
{
g_string_append (result, uri);
g_string_append (result, separator);
}
g_free (uri);
g_free (path);
g_free (wpath);
}
return g_string_free (result, FALSE);
}
/* A list of URIs (text/uri-list), as rendered by the owner of the
* clipboard, as CF_HDROP for Explorer: the local files of it. Takes
* @hdata. */
HGLOBAL
_gdk_win32_selection_convert_to_hdrop (HGLOBAL hdata)
{
gchar *text, **uris;
GArray *paths;
HGLOBAL result = NULL;
gint i;
text = g_strndup (GlobalLock (hdata), GlobalSize (hdata));
GlobalUnlock (hdata);
GlobalFree (hdata);
uris = g_uri_list_extract_uris (text);
g_free (text);
paths = g_array_new (FALSE, FALSE, sizeof (wchar_t));
for (i = 0; uris && uris[i]; i++)
{
gchar *path = g_filename_from_uri (uris[i], NULL, NULL);
gunichar2 *wpath;
glong length;
if (path == NULL)
continue;
wpath = g_utf8_to_utf16 (path, -1, NULL, &length, NULL);
if (wpath)
g_array_append_vals (paths, wpath, length + 1);
g_free (wpath);
g_free (path);
}
g_strfreev (uris);
if (paths->len > 0)
{
wchar_t zero = 0;
DROPFILES *drop;
g_array_append_val (paths, zero);
result = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
sizeof (DROPFILES) + paths->len * sizeof (wchar_t));
if (result)
{
drop = GlobalLock (result);
drop->pFiles = sizeof (DROPFILES);
drop->fWide = TRUE;
memcpy ((guchar *) drop + sizeof (DROPFILES), paths->data, paths->len * sizeof (wchar_t));
GlobalUnlock (result);
}
}
g_array_free (paths, TRUE);
return result;
}
/* The clipboard of file managers ("cut" or "copy" and URIs) as the
* Preferred DropEffect of Explorer. Takes @hdata. */
HGLOBAL
_gdk_win32_selection_convert_to_drop_effect (HGLOBAL hdata)
{
gchar *text = g_strndup (GlobalLock (hdata), GlobalSize (hdata));
HGLOBAL result;
DWORD effect;
GlobalUnlock (hdata);
GlobalFree (hdata);
effect = g_str_has_prefix (text, "cut") ? DROPEFFECT_MOVE : (DROPEFFECT_COPY | DROPEFFECT_LINK);
g_free (text);
result = GlobalAlloc (GMEM_MOVEABLE, sizeof (DWORD));
if (result)
{
DWORD *ptr = GlobalLock (result);
*ptr = effect;
GlobalUnlock (result);
}
return result;
}

View file

@ -679,17 +679,18 @@ _gdk_window_impl_new (GdkWindow *window,
g_assert_not_reached ();
}
/* in pixels of Windows (HiDPI) */
if (private->window_type != GDK_WINDOW_CHILD)
{
rect.left = private->x;
rect.top = private->y;
rect.right = private->width + private->x;
rect.bottom = private->height + private->y;
rect.left = GDK_WIN32_SC (private->x);
rect.top = GDK_WIN32_SC (private->y);
rect.right = GDK_WIN32_SC (private->width + private->x);
rect.bottom = GDK_WIN32_SC (private->height + private->y);
AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
real_x = private->x - offset_x;
real_y = private->y - offset_y;
real_x = GDK_WIN32_SC (private->x) - offset_x;
real_y = GDK_WIN32_SC (private->y) - offset_y;
if (private->window_type == GDK_WINDOW_TOPLEVEL ||
private->window_type == GDK_WINDOW_DIALOG)
@ -711,11 +712,11 @@ _gdk_window_impl_new (GdkWindow *window,
else
{
/* adjust position relative to real_parent */
window_width = private->width;
window_height = private->height;
window_width = GDK_WIN32_SC (private->width);
window_height = GDK_WIN32_SC (private->height);
/* use given position for initial placement, native coordinates */
x = private->x + private->parent->abs_x - offset_x;
y = private->y + private->parent->abs_y - offset_y;
x = GDK_WIN32_SC (private->x + private->parent->abs_x) - offset_x;
y = GDK_WIN32_SC (private->y + private->parent->abs_y) - offset_y;
}
klass = RegisterGdkClass (private->window_type, impl->type_hint);
@ -796,6 +797,9 @@ _gdk_window_impl_new (GdkWindow *window,
// if (!from_set_skip_taskbar_hint && private->window_type == GDK_WINDOW_TEMP)
// gdk_window_set_skip_taskbar_hint (window, TRUE);
if (event_mask & GDK_TOUCH_MASK)
_gdk_win32_window_update_touch (window, TRUE);
if (attributes_mask & GDK_WA_CURSOR)
gdk_window_set_cursor (window, attributes->cursor);
}
@ -843,10 +847,10 @@ gdk_win32_window_foreign_new_for_display (GdkDisplay *display,
ClientToScreen ((HWND) anid, &point);
if (parent != GetDesktopWindow ())
ScreenToClient (parent, &point);
private->x = point.x;
private->y = point.y;
private->width = rect.right - rect.left;
private->height = rect.bottom - rect.top;
private->x = _gdk_win32_unscale (point.x);
private->y = _gdk_win32_unscale (point.y);
private->width = _gdk_win32_unscale_up (rect.right - rect.left);
private->height = _gdk_win32_unscale_up (rect.bottom - rect.top);
private->window_type = GDK_WINDOW_FOREIGN;
private->destroyed = FALSE;
private->event_mask = GDK_ALL_EVENTS_MASK; /* XXX */
@ -968,9 +972,10 @@ get_outer_rect (GdkWindow *window,
gint height,
RECT *rect)
{
/* the size of GDK, the rectangle of Windows */
rect->left = rect->top = 0;
rect->right = width;
rect->bottom = height;
rect->right = GDK_WIN32_SC (width);
rect->bottom = GDK_WIN32_SC (height);
_gdk_win32_adjust_client_rect (window, rect);
}
@ -999,14 +1004,14 @@ adjust_for_gravity_hints (GdkWindow *window,
case GDK_GRAVITY_CENTER:
case GDK_GRAVITY_SOUTH:
*x -= (outer_rect->right - outer_rect->left) / 2;
*x += obj->width / 2;
*x += GDK_WIN32_SC (obj->width) / 2;
break;
case GDK_GRAVITY_SOUTH_EAST:
case GDK_GRAVITY_EAST:
case GDK_GRAVITY_NORTH_EAST:
*x -= outer_rect->right - outer_rect->left;
*x += obj->width;
*x += GDK_WIN32_SC (obj->width);
break;
case GDK_GRAVITY_STATIC:
@ -1023,14 +1028,14 @@ adjust_for_gravity_hints (GdkWindow *window,
case GDK_GRAVITY_CENTER:
case GDK_GRAVITY_EAST:
*y -= (outer_rect->bottom - outer_rect->top) / 2;
*y += obj->height / 2;
*y += GDK_WIN32_SC (obj->height) / 2;
break;
case GDK_GRAVITY_SOUTH_WEST:
case GDK_GRAVITY_SOUTH:
case GDK_GRAVITY_SOUTH_EAST:
*y -= outer_rect->bottom - outer_rect->top;
*y += obj->height;
*y += GDK_WIN32_SC (obj->height);
break;
case GDK_GRAVITY_STATIC:
@ -1153,7 +1158,7 @@ show_window_internal (GdkWindow *window,
else
{
center_on_rect.left = 0;
center_on_rect.right = 0;
center_on_rect.top = 0;
center_on_rect.right = GetSystemMetrics (SM_CXSCREEN);
center_on_rect.bottom = GetSystemMetrics (SM_CYSCREEN);
}
@ -1164,10 +1169,10 @@ show_window_internal (GdkWindow *window,
{
GdkWindowObject *owner = GDK_WINDOW_OBJECT (window_impl->transient_owner);
/* Center on transient parent */
center_on_rect.left = owner->x;
center_on_rect.top = owner->y;
center_on_rect.right = center_on_rect.left + owner->width;
center_on_rect.bottom = center_on_rect.top + owner->height;
center_on_rect.left = GDK_WIN32_ROOT_TO_SCREEN_X (owner->x);
center_on_rect.top = GDK_WIN32_ROOT_TO_SCREEN_Y (owner->y);
center_on_rect.right = center_on_rect.left + GDK_WIN32_SC (owner->width);
center_on_rect.bottom = center_on_rect.top + GDK_WIN32_SC (owner->height);
_gdk_win32_adjust_client_rect (GDK_WINDOW (owner), &center_on_rect);
center = TRUE;
}
@ -1176,8 +1181,8 @@ show_window_internal (GdkWindow *window,
{
window_rect.left = 0;
window_rect.top = 0;
window_rect.right = private->width;
window_rect.bottom = private->height;
window_rect.right = GDK_WIN32_SC (private->width);
window_rect.bottom = GDK_WIN32_SC (private->height);
_gdk_win32_adjust_client_rect (window, &window_rect);
x = center_on_rect.left + ((center_on_rect.right - center_on_rect.left) - (window_rect.right - window_rect.left)) / 2;
@ -1378,6 +1383,8 @@ gdk_win32_window_move (GdkWindow *window,
get_outer_rect (window, private->width, private->height, &outer_rect);
x = GDK_WIN32_SC (x);
y = GDK_WIN32_SC (y);
adjust_for_gravity_hints (window, &outer_rect, &x, &y);
GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,0,0,"
@ -1481,6 +1488,8 @@ gdk_win32_window_move_resize_internal (GdkWindow *window,
get_outer_rect (window, width, height, &outer_rect);
x = GDK_WIN32_SC (x);
y = GDK_WIN32_SC (y);
adjust_for_gravity_hints (window, &outer_rect, &x, &y);
GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,%ld,%ld,"
@ -1589,7 +1598,9 @@ gdk_win32_window_reparent (GdkWindow *window,
GDK_WINDOW_HWND (new_parent)));
API_CALL (MoveWindow, (GDK_WINDOW_HWND (window),
x, y, window_private->width, window_private->height, TRUE));
GDK_WIN32_SC (x), GDK_WIN32_SC (y),
GDK_WIN32_SC (window_private->width), GDK_WIN32_SC (window_private->height),
TRUE));
/* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
* the root window
@ -1679,8 +1690,8 @@ erase_background (GdkWindow *window,
* fetch the parent. (And if the same goes for the parent, fetch
* the grandparent, etc.)
*/
x_offset += ((GdkWindowObject *) window)->x;
y_offset += ((GdkWindowObject *) window)->y;
x_offset += GDK_WIN32_SC (((GdkWindowObject *) window)->x);
y_offset += GDK_WIN32_SC (((GdkWindowObject *) window)->y);
window = GDK_WINDOW (((GdkWindowObject *) window)->parent);
}
@ -1704,7 +1715,7 @@ erase_background (GdkWindow *window,
GdkPixmapImplWin32 *pixmap_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl);
if (x_offset == 0 && y_offset == 0 &&
pixmap_impl->width <= 8 && pixmap_impl->height <= 8)
GDK_WIN32_SC (pixmap_impl->width) <= 8 && GDK_WIN32_SC (pixmap_impl->height) <= 8)
{
if (!(hbr = CreatePatternBrush (GDK_PIXMAP_HBITMAP (pixmap))))
WIN32_GDI_FAILED ("CreatePatternBrush");
@ -1731,15 +1742,15 @@ erase_background (GdkWindow *window,
x = -x_offset;
while (x < rect.right)
{
if (x + pixmap_impl->width >= rect.left)
if (x + GDK_WIN32_SC (pixmap_impl->width) >= rect.left)
{
y = -y_offset;
while (y < rect.bottom)
{
if (y + pixmap_impl->height >= rect.top)
if (y + GDK_WIN32_SC (pixmap_impl->height) >= rect.top)
{
if (!BitBlt (hdc, x, y,
pixmap_impl->width, pixmap_impl->height,
GDK_WIN32_SC (pixmap_impl->width), GDK_WIN32_SC (pixmap_impl->height),
bgdc, 0, 0, SRCCOPY))
{
WIN32_GDI_FAILED ("BitBlt");
@ -1748,10 +1759,10 @@ erase_background (GdkWindow *window,
return;
}
}
y += pixmap_impl->height;
y += GDK_WIN32_SC (pixmap_impl->height);
}
}
x += pixmap_impl->width;
x += GDK_WIN32_SC (pixmap_impl->width);
}
SelectObject (bgdc, oldbitmap);
DeleteDC (bgdc);
@ -1786,7 +1797,8 @@ gdk_win32_window_clear_area (GdkWindow *window,
"%dx%d@%+d%+d\n",
GDK_WINDOW_HWND (window),
width, height, x, y));
IntersectClipRect (hdc, x, y, x + width, y + height);
IntersectClipRect (hdc, GDK_WIN32_SC (x), GDK_WIN32_SC (y),
GDK_WIN32_SC (x + width), GDK_WIN32_SC (y + height));
erase_background (window, hdc);
GDI_CALL (ReleaseDC, (GDK_WINDOW_HWND (window), hdc));
}
@ -1794,14 +1806,15 @@ gdk_win32_window_clear_area (GdkWindow *window,
{
/* The background should be erased before the expose event is
generated */
IntersectClipRect (hdc, x, y, x + width, y + height);
IntersectClipRect (hdc, GDK_WIN32_SC (x), GDK_WIN32_SC (y),
GDK_WIN32_SC (x + width), GDK_WIN32_SC (y + height));
erase_background (window, hdc);
GDI_CALL (ReleaseDC, (GDK_WINDOW_HWND (window), hdc));
rect.left = x;
rect.right = x + width;
rect.top = y;
rect.bottom = y + height;
rect.left = GDK_WIN32_SC (x);
rect.right = GDK_WIN32_SC (x + width);
rect.top = GDK_WIN32_SC (y);
rect.bottom = GDK_WIN32_SC (y + height);
GDI_CALL (InvalidateRect, (GDK_WINDOW_HWND (window), &rect, TRUE));
UpdateWindow (GDK_WINDOW_HWND (window));
@ -2154,12 +2167,20 @@ gdk_window_set_transient_for (GdkWindow *window,
GdkWindow *parent)
{
HWND window_id, parent_id;
GdkWindowImplWin32 *window_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
GdkWindowImplWin32 *window_impl;
GdkWindowImplWin32 *parent_impl = NULL;
GSList *item;
g_return_if_fail (GDK_IS_WINDOW (window));
/* an offscreen window, or a child of one, has no HWND and no
* GdkWindowImplWin32 to keep the transient relationship in */
if (!GDK_IS_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl) ||
(parent != NULL &&
!GDK_IS_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (parent)->impl)))
return;
window_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
window_id = GDK_WINDOW_HWND (window);
parent_id = parent != NULL ? GDK_WINDOW_HWND (parent) : NULL;
@ -2492,14 +2513,15 @@ gdk_win32_window_get_geometry (GdkWindow *window,
}
}
/* in pixels of GDK */
if (x)
*x = rect.left;
*x = _gdk_win32_unscale (rect.left);
if (y)
*y = rect.top;
*y = _gdk_win32_unscale (rect.top);
if (width)
*width = rect.right - rect.left;
*width = _gdk_win32_unscale_up (rect.right - rect.left);
if (height)
*height = rect.bottom - rect.top;
*height = _gdk_win32_unscale_up (rect.bottom - rect.top);
if (depth)
*depth = gdk_drawable_get_visual (window)->depth;
@ -2522,21 +2544,20 @@ gdk_win32_window_get_root_coords (GdkWindow *window,
gint ty;
POINT pt;
pt.x = x;
pt.y = y;
pt.x = 0;
pt.y = 0;
ClientToScreen (GDK_WINDOW_HWND (window), &pt);
tx = pt.x;
ty = pt.y;
tx = GDK_WIN32_SCREEN_TO_ROOT_X (pt.x) + x;
ty = GDK_WIN32_SCREEN_TO_ROOT_Y (pt.y) + y;
if (root_x)
*root_x = tx + _gdk_offset_x;
*root_x = tx;
if (root_y)
*root_y = ty + _gdk_offset_y;
*root_y = ty;
GDK_NOTE (MISC, g_print ("gdk_win32_window_get_root_coords: %p: %+d%+d %+d%+d\n",
GDK_WINDOW_HWND (window),
x, y,
tx + _gdk_offset_x, ty + _gdk_offset_y));
x, y, tx, ty));
return 1;
}
@ -2636,6 +2657,15 @@ gdk_window_get_frame_extents (GdkWindow *window,
rect->y = r.top + _gdk_offset_y;
rect->width = r.right - r.left;
rect->height = r.bottom - r.top;
{
/* in pixels of GDK */
gint x2 = rect->x + rect->width, y2 = rect->y + rect->height;
rect->x = _gdk_win32_unscale (rect->x);
rect->y = _gdk_win32_unscale (rect->y);
rect->width = _gdk_win32_unscale_up (x2) - rect->x;
rect->height = _gdk_win32_unscale_up (y2) - rect->y;
}
GDK_NOTE (MISC, g_print ("gdk_window_get_frame_extents: %p: %ldx%ld@%+ld%+ld\n",
GDK_WINDOW_HWND (window),
@ -2688,13 +2718,15 @@ gdk_window_win32_get_pointer (GdkWindow *window,
GetCursorPos (&point);
ScreenToClient (hwnd, &point);
*x = point.x;
*y = point.y;
if (window == _gdk_root)
{
*x += _gdk_offset_x;
*y += _gdk_offset_y;
*x = GDK_WIN32_SCREEN_TO_ROOT_X (point.x);
*y = GDK_WIN32_SCREEN_TO_ROOT_Y (point.y);
}
else
{
*x = _gdk_win32_unscale (point.x);
*y = _gdk_win32_unscale (point.y);
}
hwndc = ChildWindowFromPoint (hwnd, point);
@ -2720,8 +2752,8 @@ _gdk_windowing_get_pointer (GdkDisplay *display,
*screen = _gdk_screen;
GetCursorPos (&point);
*x = point.x + _gdk_offset_x;
*y = point.y + _gdk_offset_y;
*x = GDK_WIN32_SCREEN_TO_ROOT_X (point.x);
*y = GDK_WIN32_SCREEN_TO_ROOT_Y (point.y);
*mask = get_current_mask ();
}
@ -2735,7 +2767,7 @@ gdk_display_warp_pointer (GdkDisplay *display,
g_return_if_fail (display == _gdk_display);
g_return_if_fail (screen == _gdk_screen);
SetCursorPos (x - _gdk_offset_x, y - _gdk_offset_y);
SetCursorPos (GDK_WIN32_ROOT_TO_SCREEN_X (x), GDK_WIN32_ROOT_TO_SCREEN_Y (y));
}
static void
@ -2811,9 +2843,9 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display,
if (hwnd == NULL)
{
if (win_x)
*win_x = screen_pt.x + _gdk_offset_x;
*win_x = GDK_WIN32_SCREEN_TO_ROOT_X (screen_pt.x);
if (win_y)
*win_y = screen_pt.y + _gdk_offset_y;
*win_y = GDK_WIN32_SCREEN_TO_ROOT_Y (screen_pt.y);
return _gdk_root;
}
@ -2823,9 +2855,9 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display,
if (window && (win_x || win_y))
{
if (win_x)
*win_x = client_pt.x;
*win_x = _gdk_win32_unscale (client_pt.x);
if (win_y)
*win_y = client_pt.y;
*win_y = _gdk_win32_unscale (client_pt.y);
}
GDK_NOTE (MISC, g_print ("_gdk_windowing_window_at_pointer: %+d%+d %p%s\n",
@ -2861,6 +2893,9 @@ gdk_win32_window_set_events (GdkWindow *window,
* set it here, too. Not that I know or remember why it is
* necessary, will have to test some day.
*/
if ((impl->native_event_mask ^ event_mask) & GDK_TOUCH_MASK)
_gdk_win32_window_update_touch (window, (event_mask & GDK_TOUCH_MASK) != 0);
impl->native_event_mask = GDK_STRUCTURE_MASK | event_mask;
}
@ -2875,7 +2910,7 @@ do_shape_combine_region (GdkWindow *window,
_gdk_win32_adjust_client_rect (window, &rect);
OffsetRgn (hrgn, -rect.left, -rect.top);
OffsetRgn (hrgn, x, y);
OffsetRgn (hrgn, GDK_WIN32_SC (x), GDK_WIN32_SC (y));
/* If this is a top-level window, add the title bar to the region */
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL)
@ -3425,7 +3460,7 @@ gdk_window_begin_resize_drag (GdkWindow *window,
}
DefWindowProcW (GDK_WINDOW_HWND (window), WM_NCLBUTTONDOWN, winedge,
MAKELPARAM (root_x - _gdk_offset_x, root_y - _gdk_offset_y));
MAKELPARAM (GDK_WIN32_ROOT_TO_SCREEN_X (root_x), GDK_WIN32_ROOT_TO_SCREEN_Y (root_y)));
}
void
@ -3455,7 +3490,7 @@ gdk_window_begin_move_drag (GdkWindow *window,
gdk_display_pointer_ungrab (_gdk_display, 0);
DefWindowProcW (GDK_WINDOW_HWND (window), WM_NCLBUTTONDOWN, HTCAPTION,
MAKELPARAM (root_x - _gdk_offset_x, root_y - _gdk_offset_y));
MAKELPARAM (GDK_WIN32_ROOT_TO_SCREEN_X (root_x), GDK_WIN32_ROOT_TO_SCREEN_Y (root_y)));
}
@ -3948,9 +3983,8 @@ gdk_window_set_opacity (GdkWindow *window,
PFN_SetLayeredWindowAttributes setLayeredWindowAttributes = NULL;
g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (WINDOW_IS_TOPLEVEL (window));
if (GDK_WINDOW_DESTROYED (window))
if (!WINDOW_IS_TOPLEVEL (window) || GDK_WINDOW_DESTROYED (window))
return;
if (opacity < 0)
@ -4065,7 +4099,7 @@ _gdk_win32_window_queue_translation (GdkWindow *window,
WIN32_API_FAILED ("CombineRgn");
else if (ret != NULLREGION)
{
OffsetRgn (update, dx, dy);
OffsetRgn (update, GDK_WIN32_SC (dx), GDK_WIN32_SC (dy));
API_CALL (InvalidateRgn, (GDK_WINDOW_HWND (window), update, TRUE));
}
DeleteObject (update);

View file

@ -42,6 +42,7 @@ libgdk_x11_la_SOURCES = \
gdkpixmap-x11.h \
gdkproperty-x11.c \
gdkscreen-x11.c \
gdkscroll-x11.c \
gdkscreen-x11.h \
gdkselection-x11.c \
gdkspawn-x11.c \

View file

@ -49,6 +49,9 @@ get_display_name (GFile *file,
if (name == NULL)
{
name = g_file_get_basename (file);
if (name == NULL)
name = g_file_get_uri (file);
if (!g_utf8_validate (name, -1, NULL))
{
tmp = name;
@ -175,10 +178,12 @@ free_startup_timeout (void *data)
g_free (std);
}
/* for the time a startup takes: not the wall clock, which may be set
* meanwhile */
static gint64
get_current_time_usec (void)
{
return g_get_real_time ();
return g_get_monotonic_time ();
}
static gboolean

Some files were not shown because too many files have changed in this diff Show more