1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
|
# Copyright 2011, 2012, 2013 Kevin Ryde
# This file is part of X11-Protocol-Other.
#
# X11-Protocol-Other is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3, or (at your option) any
# later version.
#
# X11-Protocol-Other 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 General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
# 2.0 bits:
# SetMode two flags fields
# byte_order "Significance" ?
# Protocol 1.0:
# http://cvsweb.xfree86.org/cvsweb/xc/programs/Xserver/hw/xfree86/doc/man/Attic/XF86DGA.man?rev=3.10&hideattic=0&sortby=log&content-type=text/vnd.viewcvs-markup
#
# /so/xfree/xfree86-3.3.2.3a/programs/Xserver/hw/xfree86/doc/README.DGA
# /so/xfree/xfree86-3.3.2.3a/lib/Xxf86dga/XF86DGA.c
# Xlib
#
# /so/xfree/xfree86-3.3.2.3a/include/extensions/xf86dga.h
# /so/xfree/xfree86-3.3.2.3a/include/extensions/xf86dgastr.h
#
# /usr/include/X11/extensions/xf86dga1const.h
# /usr/include/X11/extensions/xf86dga1proto.h
#
# /so/xf86dga/XF86DGA.man
#
# /so/xfree/xfree86-3.3.2.3a/programs/Xserver/Xext/xf86dga.c
# server code
#
# Protocol 2.0:
# /usr/share/doc/xserver-xfree86/README.DGA.gz
# /so/xfree4/unpacked/usr/share/doc/xserver-xfree86/README.DGA.gz
#
# /usr/include/X11/extensions/xf86dgaconst.h
# /usr/include/X11/extensions/xf86dgaproto.h
#
# /so/xorg/xorg-server-1.10.0/hw/xfree86/dixmods/extmod/xf86dga2.c
# /so/xorg/xorg-server-1.10.0/hw/xfree86/common/xf86DGA.c
# server code
#
# XDGA(3) man page
# /so/xf86dga/libXxf86dga-1.1.2/src/XF86DGA2.c
# Xlib
#
# Other:
# /usr/share/doc/x11proto-core-dev/x11protocol.txt.gz
BEGIN { require 5 }
package X11::Protocol::Ext::XFree86_DGA;
use strict;
use Carp;
use X11::Protocol;
use vars '$VERSION', '@CARP_NOT';
$VERSION = 28;
@CARP_NOT = ('X11::Protocol');
# uncomment this to run the ### lines
# use Smart::Comments;
# these not documented yet ...
use constant CLIENT_MAJOR_VERSION => 1;
use constant CLIENT_MINOR_VERSION => 0;
#------------------------------------------------------------------------------
# symbolic constants
use constant constants_list =>
(XDGAPixmapMode => ['Large','Small'],
);
sub _ext_constants_install {
my ($X, $constants_arrayref) = @_;
foreach (my $i = 0; $i <= $#$constants_arrayref; $i+=2) {
my $name = $constants_arrayref->[$i];
my $aref = $constants_arrayref->[$i+1];
$X->{'ext_const'}->{$name} = $aref;
$X->{'ext_const_num'}->{$name} = { X11::Protocol::make_num_hash($aref) };
}
}
#------------------------------------------------------------------------------
# events
# =head1 EVENTS
#
# Protocol version 2.0 sends key, button and pointer motion events selected
# by C<XDGASelectInput()> described above.
#
# Each event has the usual fields
#
# name "SyncCounterNotify" etc
# synthetic true if from a SendEvent
# code integer opcode
# sequence_number integer
#
# plus event-specific fields described below.
#
# =over
#
# =item C<XDGAKeyPressEvent>, C<XDGAKeyReleaseEvent>
#
# The "detail", "time" and "state" fields are the same as the core KeyPress
# and KeyRelease events,
#
# detail keycode (integer)
# time server timestamp (integer)
# screen screen number (integer)
# state keyboard modifiers (integer shift, control, etc)
#
# =item C<XDGAButtonPressEvent>, C<XDGAButtonReleaseEvent>
#
# The "detail", "time" and "state" fields are the same as the core
# ButtonPress and ButtonRelease events,
#
# detail button number 1 to 5
# time server timestamp (integer)
# screen screen number (integer)
# state keyboard modifiers (integer shift, control, etc)
#
# =item C<XDGAMotionEvent>
#
# The "time" and "state" fields are the same as the core key press and
# release events,
#
# dx \ pointer move in pixels, integer + or -
# dy /
# time server timestamp (integer)
# screen screen number (integer)
# state keyboard modifiers (integer shift, control, etc)
#
# =back
# xf86dgaproto.h struct dgaEvent has INT16 for screen, so "s" here, though
# normally a screen number will be >=0.
#
use constant events_list =>
do {
# struct dgaEvent has dx,dy fields for key and button events, but server
# DGAStealButtonEvent() and DGAStealKeyEvent() always puts 0 in them, so
# omit.
#
my $kb = [ 'xCxxLxxxxsSx16',
'detail',
'time',
'screen',
'state',
];
(XDGAKeyPress => $kb, # +2
XDGAKeyRelease => $kb, # +3
XDGAButtonPress => $kb, # +4
XDGAButtonRelease => $kb, # +5
# struct dgaEvent has a "detail" field for motion event, but server
# DGAStealMotionEvent() always puts 0 in it, so omit.
#
XDGAMotionNotify => # +6
[ 'xxxxLsssSx16',
'time',
'dx',
'dy',
'screen',
'state',
])
};
sub _ext_events_install {
my ($X, $event_num, $events_arrayref) = @_;
foreach (my $i = 0; $i <= $#$events_arrayref; $i += 2) {
my $name = $events_arrayref->[$i];
if (defined (my $already = $X->{'ext_const'}->{'Events'}->[$event_num])) {
carp "Event $event_num $already overwritten with $name";
}
$X->{'ext_const'}->{'Events'}->[$event_num] = $name;
$X->{'ext_events'}->[$event_num] = $events_arrayref->[$i+1]; # pack/unpack
$event_num++;
}
}
#------------------------------------------------------------------------------
# requests
my $reqs =
[
['XF86DGAQueryVersion', # 0
\&_request_empty,
sub {
my ($X, $data) = @_;
### XF86DGAQueryVersion() reply ...
return unpack 'x8SS', $data;
}],
['XF86DGAGetVideoLL', # 1
\&_request_screen16,
sub {
my ($X, $data) = @_;
return unpack 'x8L4', $data; # (address,width,bank_size,ram_size)
},
],
['XF86DGADirectVideo', # 2
sub {
my ($X, $screen, $enable) = @_;
return pack 'SS', $screen, $enable;
} ],
['XF86DGAGetViewPortSize', # 3
\&_request_screen16,
sub {
my ($X, $data) = @_;
return unpack 'x8LL', $data; # (width,height)
},
],
['XF86DGASetViewPort', # 4
sub {
shift; # ($X, $screen, $x, $y)
return pack 'SxxLL', @_;
},
],
['XF86DGAGetVidPage', # 5
\&_request_screen16,
sub {
my ($X, $data) = @_;
return unpack 'x8L', $data; # (vidpage)
},
],
['XF86DGASetVidPage', # 6
sub {
shift; # ($X, $screen, $vidpage)
return pack 'SS', @_;
},
],
['XF86DGAInstallColormap', # 7
sub {
my ($X, $screen, $colormap) = @_;
return pack 'SxxL', $screen, $colormap;
}],
['XF86DGAQueryDirectVideo', # 8
\&_request_screen16,
sub {
my ($X, $data) = @_;
return unpack 'x8L', $data; # (flags)
},
],
['XF86DGAViewPortChanged', # 9
sub {
shift; # ($X, $screen, $num_pages)
return pack 'SS', @_;
},
sub {
my ($X, $data) = @_;
return unpack 'x8L', $data; # (bool)
} ],
#---------------------------------------------------------------------------
# version 2.0
undef, # 10
undef, # 11
# =item C<($mode_num =E<gt> $hashref, ...) = $X-E<gt>XDGAQueryModes($screen_num)>
#
# Return a list of available DGA modes and information. Each mode is
# returned as a pair
#
# $mode_num => $hashref
#
# where C<$hashref> contains the following fields
#
# mode_num
# byte_order Significance enum
# "LeastSignificant" or "MostSignificant"
# depth bits per pixel with usable data, eg. 24
# bpp bits per pixel including padding, eg. 32
# name string name of mode from xorg.conf
# vsync_num \ vertical refresh rate as fraction num/den
# vsync_den / retraces per second (Hertz)
# flags bits
# 1 Concurrent Access
# 2 Solid Fill Rect
# 4 Blit Rect
# 8 Blit Trans Rect
# 16 Pixmap
# image_width \
# image_height /
# pixmap_width \ size of the video part accessible by
# pixmap_height / pixmap of XDGASetMode()
# bytes_per_scanline
# red_mask \ pixel bit-masks as per a visual
# green_mask |
# blue_mask /
# visual_class VisualClass enum "TrueColor", "PseudoColor", etc
# viewport_width \ size of the visible part of the video
# viewport_height /
# viewport_xstep \ granularity of X,Y position
# viewport_ystep / for XDGASetViewport()
# viewport_xmax \ maximum X,Y position
# viewport_ymax / for XDGASetViewport()
# viewport_flags
#
# The return list can be put into a hash to lookup by mode number,
#
# my %h = $X->XDGAQueryModes($screen_num);
# my $info = $h{$mode_num};
# print "$mode_num name is ",$info->{'name'},"\n";
#
['XDGAQueryModes', # 12
\&_request_card32s,
sub {
my ($X, $data) = @_;
my ($num_modes) = unpack 'x8L', $data;
my $pos = 32;
# use Data::HexDump::XXD;
# print scalar(Data::HexDump::XXD::xxd($data));
# print "\n";
return map {my $h = _unpack_info($X,$data,$pos);
$pos += 72;
($h->{'num'} => $h)
} 1 .. $num_modes;
} ],
# =item C<(key=E<gt>value,...) = $X-E<gt>XDGASetMode($screen_num, $mode_num, $pixmap)>
#
# Put screen C<$screen_num> into DGA mode C<$mode_num>. Or if
# C<$mode_num> is 0 then leave DGA mode.
#
# C<$pixmap> is a new integer XID which is for X protocol access to the
# video memory while in DGA mode. This is only possible if the "Pixmap"
# bit is set in the mode flags (C<XDGAQueryModes()> above).
#
# The return is a list of key/value pairs with mode information. The
# fields are C<XDGAQueryModes()> above for C<$mode_num>, and in addition
#
# offset => offset into video memory (integer)
# set_flags => ... (integer)
#
['XDGASetMode', # 13
sub {
shift; # ($X, $screen_num, $mode_num, $pixmap)
return pack 'L3', @_;
},
sub {
my ($X, $data) = @_;
my ($offset, $flags) = unpack 'x8LL', $data;
my $h = _unpack_info($X, $data, 32);
return (offset => $offset,
set_flags => $flags,
%$h);
},
],
# =item C<$X-E<gt>XDGASetViewport($screen_num, $x, $y, $flags)>
#
# Set the C<$x,$y> position of the top-left corner of the visible part of
# the video memory.
#
# The hardware might support only certain positions, as per
# C<viewport_xstep>,C<viewport_ystep> fields of C<XDGAQueryModes()>
# above. C<$x,$y> will round them to the next step if necessary.
#
# C<$flags> (an integer) can be bits
#
# 1 Flip Immediate
# 2 Flip Retrace
#
# Flip retrace means to queue the viewport change to occur on the next
# vertical retrace, so as not to flicker in the middle of the screen.
#
[ 'XDGASetViewport', # 14
sub {
shift; # ($X, $screen, $x, $y, $flags)
return pack 'LSSL', @_;
},
],
# =item C<$X-E<gt>XDGAInstallColormap($screen_num, $colormap)>
#
# Install C<$colormap> in DGA mode. The core
# C<$X-E<gt>InstallColormap()> cannot be used in DGA mode.
#
[ 'XDGAInstallColormap', # 15
sub {
shift; # ($X, $screen, $colormap)
return pack 'SxxL', @_;
} ],
# =item C<$X-E<gt>XDGASelectInput($screen_num, $event_mask)>
#
# Select key, button and mouse motion events while in DGA mode.
# C<$event_mask> is as per the core C<$X-E<gt>pack_event()> with mask
# bits
#
# KeyPress
# KeyRelease
# ButtonPress
# ButtonRelease
# PointerMotion
# Button1Motion
# Button2Motion
# Button3Motion
# Button4Motion
# Button5Motion
# ButtonMotion
#
[ 'XDGASelectInput', # 16
\&_request_card32s ], # ($X, $screen, $mask)
# =item C<$X-E<gt>XDGAFillRectangle($screen_num, $x,$y, $width,$height, $pixel)>
#
# Fill the rectangle C<$x,$y, $width,$height> with pixel value C<$pixel>.
#
# This request is supported if the "Solid Fill Rect" bit is set in the
# mode flags (C<XDGAQueryModes()> above).
#
[ 'XDGAFillRectangle', # 17
sub {
shift; # ($X, $screen, $x, $y, $width, $height, $color)
return pack 'LSSSSL', @_;
} ],
# =item C<$X-E<gt>XDGACopyArea($screen_num, $src_x,$src_y, $width,$height, $dst_x,$dst_y)>
#
# Copy the rectangle C<$src_x,$src_y, $width,$height> to
# C<$dst_x,$dst_y>.
#
# This request is supported if the "Blit Rect" bit is set in the mode
# flags (C<XDGAQueryModes()> above).
#
[ 'XDGACopyArea', # 18
sub {
shift; # ($X, $screen, $src_x,$src_y, $width,$height, $dst_x,$dst_y)
return pack 'LS*', @_; # x,y's are CARD16s, so unsigned
} ],
# This request is supported if the "Blit Trans Rect" bit is set in the
# mode flags (C<XDGAQueryModes()> above).
#
[ 'XDGACopyTransparentArea', # 19
sub {
shift;
# ($X, $screen, $src_x,$src_y, $width,$height, $dst_x,$dst_y, $key)
return pack 'LS6L', @_; # x,y's are CARD16s, so unsigned
} ],
# =item C<$status = $X-E<gt>XDGAGetViewportStatus($screen_num)>
#
[ 'XDGAGetViewportStatus', # 20
\&_request_card32s, # ($X,$screen_num)
sub {
my ($X, $data) = @_;
return unpack 'x8L', $data;
} ],
# =item C<$X-E<gt>XDGASync($screen_num)>
#
# Block until all server drawing to the video memory is complete, either
# ordinary X drawing or the Copy and Fill requests above.
#
# The server or hardware might queue drawing requests. C<XDGASync()> is
# a round-trip which ensures the video memory contains all drawing
# requested.
#
# If "Concurrent Access" is set in the mode flags (C<XDGAQueryModes()>
# above) then a client and the server can act on the video concurrently,
# though care would be needed not to make a mess of each other's drawing.
#
# If "Concurrent Access" is not set then the client and server must not
# act on the video concurrently. The client must C<XDGASync()> to ensure
# the server has finished.
#
[ 'XDGASync', # 21
\&_request_card32s, # ($X,$screen_num)
sub { # ($X, $data) empty
return;
} ],
# =item C<($device_name, $addr, $size, $offset, $extra) = $X-E<gt>XDGAOpenFramebuffer($screen_num)>
#
# Get the location of the video RAM memory framebuffer. The client can
# use this to open the framebuffer by an C<mmap()> or other means for use
# when in DGA mode.
#
# C<$device_name> (a string) is the name of a device file to access the
# framebuffer. If it's an empty string then the framebuffer is in
# physical memory (so whatever system-dependent device F</dev/mem> or
# F</dev/pmem> etc).
#
# C<$addr> (an integer) is the address within the device or physical
# memory. This might be 64-bits on a 64-bit system. If Perl has only
# 32-bit UV when the address is 64-bits then C<$addr> is returned as a
# C<Math::BigInt>.
#
# C<$offset> is an offset from C<$addr>. C<$size> is the size of the
# framebuffer memory, in bytes, at that C<$addr+$offset> location.
#
# C<$extra> is extra information. It can be a bit
#
# 1 client will need root permissions
#
[ 'XDGAOpenFramebuffer', # 22
\&_request_card32s,
sub {
my ($X, $data) = @_;
### head: unpack('CCSL', $data)
### data: unpack('x8L5', $data)
### devname: substr($data,32)
# (devlen,mem1,mem2,size,offset,extra)
my ($length, $mem_lo, $mem_hi, @rest) = unpack 'x4L6', $data;
# "\0" terminated within $length many CARD32s
(my $devname = substr($data,32,4*$length)) =~ s/\0.*//;
return ($devname,
_hilo_to_card64($mem_hi,$mem_lo),
@rest);
} ],
# =item C<$X-E<gt>XDGACloseFramebuffer($screen_num)>
#
# Tell the server that the client is no longer accessing the framebuffer
# memory of C<XDGAOpenFramebuffer()> above.
#
[ 'XDGACloseFramebuffer', # 23
\&_request_card32s ],
# =item C<$X-E<gt>XDGASetClientVersion($client_major, $client_minor)>
#
[ 'XDGASetClientVersion', # 24
sub {
shift; # ($X, $client_major, $client_minor)
return pack 'SS', @_;
} ],
# =item C<($x,$y) = $X-E<gt>XDGAChangePixmapMode($screen_num, $x,$y, $mode)>
#
# Change the position of the C<$pixmap> of C<XDGASetMode()> within the
# video memory.
#
# C<$mode> is a XDGAPixmapMode enum,
#
# "Large" (0) pixmap_width,pixmap_height
# "Small" (1) viewport_width,viewport_height and $x,$y
#
# Large mode means the pixmap is as big as possible, the C<pixmap_width>
# and C<pixmap_height> per the mode info.
#
# Small mode means the pixmap is only the size of the viewport,
# C<viewport_width> and C<viewport_height> per the mode info. In this
# case C<$x> and C<$y> are the top-left corner of the pixmap within the
# full memory. The position can be different from the visible viewport,
# but it must be within the C<pixmap_width>,C<pixmap_height> limit.
#
[ 'XDGAChangePixmapMode', # 25
sub {
my ($X, $screen_num, $x, $y, $mode) = @_;
return pack 'LSSL',
$screen_num, $x, $y, $X->interp('XDGAPixmapMode',$mode);
},
sub {
my ($X, $data) = @_;
return unpack 'x8SS', $data; # (x,y)
},
],
# =item C<$X-E<gt>XDGACreateColormap($screen_num, $colormap, $mode_num, $alloc)>
#
# Create C<$colormap> (a new XID) as a colormap for use with DGA
# C<$screen_num> and C<$mode_num>.
#
# This is similar to the core C<CreateColormap()>, but there might not
# be a core visual corresponding to C<$mode_num> depth etc, hence this
# separate way to create a colormap.
#
# C<$colormap> can be used the same as core protocol colormaps and can
# be freed with C<$X-E<gt>FreeColormap($colormap)>.
#
#
[ 'XDGACreateColormap', # 26
sub {
shift; # ($X, $screen, $id, $mode, $alloc)
return pack 'LLLCxxx', @_;
} ],
];
sub new {
my ($class, $X, $request_num, $event_num, $error_num) = @_;
### XF86DGA new() ...
my $self = bless { }, $class;
_ext_requests_install ($X, $request_num, $reqs);
_ext_constants_install ($X, [ $self->constants_list ]);
my ($server_major, $server_minor) = $X->XF86DGAQueryVersion;
$self->{'major'} = $server_major;
$self->{'minor'} = $server_minor;
_ext_const_error_install ($X, $error_num,
'XF86DGAClientNotLocal', # 0
'XF86DGANoDirectVideoMode', # 1
'XF86DGAScreenNotActive', # 2
'XF86DGADirectNotActivated', # 3
($server_major >= 2
? 'XF86DGAOperationNotSupported' # 4
: ()));
if ($server_major >= 2) {
_ext_events_install ($X,
$event_num+2, # to start at $event_num+2
[ $self->events_list ]);
}
return $self;
}
sub _unpack_info {
my ($X, $data, $pos) = @_;
my %h;
@h{qw(byte_order depth
num bpp name_len
vsync_num vsync_den flags
image_width image_height pixmap_width pixmap_height
bytes_per_scanline red_mask green_mask blue_mask
visual_class
viewport_width viewport_height
viewport_xstep viewport_ystep
viewport_xmax viewport_ymax
viewport_flags
)}
= unpack 'C2S3L3S4L4SxxS6L', substr($data,$pos,72);
$pos += 72;
### %h
# name_len a multiple of 4, string \0 nul-terminated
# within that length
my $name_len = delete $h{'name_len'};
($h{'name'} = substr($data, $pos, $name_len)) =~ s/\0.*//;
# cf unpack 'Z', new in perl 5.6
# $h{'name'} = unpack 'Z*', substr($data, $pos, $name_len);
$pos += $name_len;
### $name_len
### name: $h{'name'}
$h{'byte_order'} = $X->interp('Significance', $h{'byte_order'});
$h{'visual_class'} = $X->interp('VisualClass', $h{'visual_class'});
return \%h;
}
#------------------------------------------------------------------------------
# 64-bits
{
my $uv = ~0;
my $bits = 0;
while ($uv && $bits < 64) {
$uv >>= 1;
$bits++;
}
if ($bits >= 64) {
eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE' or die;
sub _hilo_to_card64 {
my ($hi,$lo) = @_;
### _hilo_to_sv(): "$hi $lo, result ".(($hi << 32) + $lo)
return ($hi << 32) + $lo;
}
1;
HERE
} else {
eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE' or die;
sub _hilo_to_card64 {
my ($hi,$lo) = @_;
if ($hi) {
require Math::BigInt;
return Math::BigInt->new($hi)->blsft(32)->badd($lo);
} else {
return $lo;
}
}
1;
HERE
}
}
#------------------------------------------------------------------------------
# generic
sub _request_card32s {
shift;
### _request_card32s(): @_
return pack 'L*', @_;
}
sub _request_screen16 {
shift; # ($X, $screen)
@_ == 1 or croak "Single screen number parameter expected";
return pack 'Sxx', @_;
}
sub _num_none {
my ($xid) = @_;
if (defined $xid && $xid eq "None") {
return 0;
} else {
return $xid;
}
}
sub _request_empty {
# ($X)
### _request_empty() ...
if (@_ > 1) {
croak "No parameters in this request";
}
return '';
}
sub _ext_requests_install {
my ($X, $request_num, $reqs) = @_;
$X->{'ext_request'}->{$request_num} = $reqs;
my $href = $X->{'ext_request_num'};
my $i;
foreach $i (0 .. $#$reqs) {
if (defined $reqs->[$i]) {
$href->{$reqs->[$i]->[0]} = [$request_num, $i];
}
}
}
sub _ext_const_error_install {
my $X = shift; # ($X, $errname1,$errname2,...)
### _ext_const_error_install: @_
my $error_num = shift;
my $aref = $X->{'ext_const'}{'Error'} # copy
= [ @{$X->{'ext_const'}{'Error'} || []} ];
my $href = $X->{'ext_const_num'}{'Error'} # copy
= { %{$X->{'ext_const_num'}{'Error'} || {}} };
my $i;
foreach $i (0 .. $#_) {
$aref->[$error_num + $i] = $_[$i];
$href->{$_[$i]} = $error_num + $i;
}
}
1;
__END__
=for stopwords XID Ryde XFree86 DGA XFree86-DGA eg viewport colormap multi-buffering N-multi-buffering
=head1 NAME
X11::Protocol::Ext::XFree86_DGA - direct video memory access
=head1 SYNOPSIS
use X11::Protocol;
my $X = X11::Protocol->new;
$X->init_extension('XFree86-DGA')
or print "XFree86-DGA extension not available";
=head1 DESCRIPTION
The XFree86-DGA extension provides direct access to the video RAM of the
server display. A client program running on the same machine can use this
to read or write directly instead of going through the X protocol.
Accessing video memory will require some system-dependent trickery. Under
the Linux kernel for example video RAM is part of the F</dev/mem> physical
address space and can be brought into program address space with an
C<mmap()> or accessed with C<sysread()> and C<syswrite()>. This normally
requires root permissions.
The requests offered here are only XFree86-DGA version 1.0 as yet and they
don't say anything about the pixel layout etc in the memory -- that has to
be divined separately. (Version 2.0 has more for that.)
=head1 REQUESTS
The following requests are made available with an C<init_extension()>, as
per L<X11::Protocol/EXTENSIONS>.
my $ext_available = $X->init_extension('XFree86-DGA');
=head2 XFree86-DGA 1.0
=over
=item C<($server_major, $server_minor) = $X-E<gt>XF86DGAQueryVersion()>
Return the DGA protocol version implemented by the server.
=item C<$flags = $X-E<gt>XF86DGAQueryDirectVideo ($screen_num)>
Get flags describing direct video access on C<$screen_num> (integer 0
upwards). The only flag bit is
0x0001 direct video available
It's possible to have the extension available but no direct video on a
particular screen, or even on no screens at all. When no direct video the
requests below give protocol error C<XF86DGANoDirectVideoMode>.
=item C<($address, $width, $bank_size_bytes, $ram_size_kbytes) = $X-E<gt>XF86DGAGetVideoLL ($screen_num)>
Return the location and size of the video memory for C<$screen_num> (integer
0 upwards).
C<$address> is a raw physical 32-bit address as an integer. C<$width> is in
pixels.
C<$bank_size_bytes> is the size in bytes accessible at a given time.
C<$ram_size_kbytes> is the total memory in 1024 byte blocks. If
C<$ram_size_kbytes*1024> is bigger than C<$bank_size_bytes> then
C<$X-E<gt>XF86DGASetVidPage()> below must be used to switch among the banks
to access all the RAM.
=item C<$X-E<gt>XF86DGADirectVideo ($screen_num, $flags)>
Enable or disable direct video access on C<$screen_num> (integer 0 upwards).
C<$flags> is bits
0x0002 enable direct video graphics
0x0004 enable mouse pointer reporting as relative
0x0008 enable direct keyboard event reporting
When direct video graphics is enabled (bit 0x0002) the server gives up
control to the client program.
If the graphics card doesn't have a direct video mode then an
C<XF86DGANoDirectVideoMode> error results, or if the screen is not active
(eg. switched away to a different virtual terminal) then
C<XF86DGAScreenNotActive>.
=item C<($width, $height) = $X-E<gt>XF86DGAGetViewPortSize ($screen_num)>
Get the size of the viewport on C<$screen_num> (integer 0 upwards). This is
the part of the video memory actually visible on the monitor. The memory
might be bigger than the monitor.
=item C<$X-E<gt>XF86DGASetViewPort ($screen_num, $x, $y)>
Set the coordinates of the top-left corner of the visible part of the video
memory on C<$screen_num> (integer 0 upwards).
This can be used when the video memory is bigger than the monitor to pan
around that bigger area. It can also be used for some double-buffering to
display one part of memory while drawing to another.
=item C<$vidpage = $X-E<gt>XF86DGAGetVidPage ($screen_num)>
=item C<$X-E<gt>XF86DGASetVidPage ($screen_num, $vidpage)>
Get or set the video page (bank) on C<$screen_num> (integer 0 upwards).
C<$vidpage> is an integer 0 upwards.
This is used to access all the RAM when when the bank size is less than the
total memory size (per C<XF86DGAGetVideoLL()> above).
=item C<$vidpage = $X-E<gt>XF86DGAInstallColormap ($screen_num, $colormap)>
Set the colormap on C<$screen_num> to C<$colormap> (integer XID).
This can only be used while direct video is enabled (per
C<XF86DGADirectVideo()> above) or an error C<XF86DGAScreenNotActive> or
C<XF86DGADirectNotActivated> results.
=item C<$bool = $X-E<gt>XF86DGAViewPortChanged ($screen_num, $num_pages)>
Check whether a previous C<XF86DGASetViewPort()> on C<$screen_num> (integer
0 upwards) has completed, meaning a vertical retrace has occurred since that
viewport location was set.
This is used for double-buffering (or N-multi-buffering) to check a viewport
change has become visible. C<$num_pages> should be 2 for double-buffering
and can be higher for multi-buffering.
=back
=head1 SEE ALSO
L<X11::Protocol>
F</usr/share/doc/xserver-xfree86/README.DGA.gz>
=head1 HOME PAGE
L<http://user42.tuxfamily.org/x11-protocol-other/index.html>
=head1 LICENSE
Copyright 2011, 2012, 2013 Kevin Ryde
X11-Protocol-Other is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
X11-Protocol-Other 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 General Public License for
more details.
You should have received a copy of the GNU General Public License along with
X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
=cut
|