File Coverage

blib/lib/X11/Protocol/Ext/MIT_SHM.pm
Criterion Covered Total %
statement 13 36 36.1
branch 0 4 0.0
condition 0 3 0.0
subroutine 5 10 50.0
pod 0 1 0.0
total 18 54 33.3


line stmt bran cond sub pod time code
1             # Copyright 2011, 2012, 2013, 2014, 2017 Kevin Ryde
2              
3             # This file is part of X11-Protocol-Other.
4             #
5             # X11-Protocol-Other is free software; you can redistribute it and/or
6             # modify it under the terms of the GNU General Public License as published
7             # by the Free Software Foundation; either version 3, or (at your option) any
8             # later version.
9             #
10             # X11-Protocol-Other is distributed in the hope that it will be useful,
11             # but WITHOUT ANY WARRANTY; without even the implied warranty of
12             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13             # Public License for more details.
14             #
15             # You should have received a copy of the GNU General Public License along
16             # with X11-Protocol-Other. If not, see .
17              
18 1     1   502 BEGIN { require 5 }
19             package X11::Protocol::Ext::MIT_SHM;
20 1     1   10 use strict;
  1         2  
  1         23  
21 1     1   5 use Carp;
  1         2  
  1         94  
22 1     1   796 use X11::Protocol;
  1         22537  
  1         91  
23              
24 1     1   13 use vars '$VERSION', '@CARP_NOT';
  1         2  
  1         784  
25             $VERSION = 31;
26             @CARP_NOT = ('X11::Protocol');
27              
28             # uncomment this to run the ### lines
29             #use Smart::Comments;
30              
31             # /usr/share/doc/x11proto-xext-dev/shm.txt.gz
32             # /usr/share/doc/x11proto-core-dev/x11protocol.txt.gz
33             #
34             # /usr/include/X11/extensions/shm.h
35             # /usr/include/X11/extensions/shmproto.h
36             # /usr/include/X11/extensions/shmstr.h
37             #
38             # /usr/share/doc/libxext-dev/
39             # /usr/include/X11/extensions/Xshm.h
40             # Xlib
41             #
42              
43             ### MIT_SHM.pm loads
44              
45             #------------------------------------------------------------------------------
46             # events
47              
48             # "major_opcode", "minor_opcode" names as per GraphicsExposure and NoExpose
49             my $MitShmCompletion_event = [ 'xxxxLSCxLLx12',
50             'drawable',
51             'minor_opcode',
52             'major_opcode',
53             'shmseg',
54             'offset',
55             ];
56              
57             #------------------------------------------------------------------------------
58              
59             my $reqs =
60             [
61             [ 'MitShmQueryVersion', # 0
62             \&_request_empty,
63             sub {
64             my ($X, $data) = @_;
65             my ($shared_pixmaps, $major, $minor, $uid, $gid, $pixmap_format)
66             = unpack 'xCx6SSSSC', $data;
67             return ($major, $minor, $uid, $gid,
68             $shared_pixmaps,
69             $X->interp('ImageFormat', $pixmap_format));
70             }],
71              
72             [ 'MitShmAttach', # 1
73             sub {
74             my ($X, $shmseg, $shmid, $readonly) = @_;
75             return pack 'LLCxxx', $shmseg, $shmid, $readonly;
76             } ],
77              
78             [ 'MitShmDetach', # 2
79             \&_request_card32s ], # ($X, $shmseg)
80              
81             [ 'MitShmPutImage', # 3
82             sub {
83             my $self = shift;
84             my ($drawable, $gc, $depth,
85             $total_width, $total_height,
86             $src_x, $src_y,
87             $src_width, $src_height,
88             $dst_x, $dst_y,
89             $format,
90             $send_event,
91             $shmseg, $offset) = @_;
92             return pack("LLSSssSSssCCCxLL",
93             $drawable, $gc,
94             $total_width, $total_height,
95             $src_x, $src_y,
96             $src_width, $src_height,
97             $dst_x, $dst_y,
98             $depth,
99             $self->num('ImageFormat',$format),
100             $send_event,
101             $shmseg, $offset);
102             }],
103              
104             [ 'MitShmGetImage', # 4
105             sub {
106             my $self = shift;
107             my ($drawable, $x, $y, $width, $height,
108             $planemask, $format,
109             $shmseg, $offset) = @_;
110             $format = $self->num('ImageFormat', $format);
111             return pack ('LssSSLCxxxLL',
112             $drawable, $x, $y, $width, $height,
113             $planemask, $format,
114             $shmseg, $offset);
115             }, sub {
116             my ($X, $data) = @_;
117             ### $data
118             my ($depth, $visual, $size) = unpack 'xCx6LL', $data;
119             return ($depth, _interp_none($X,$visual), $size);
120             } ],
121              
122             [ 'MitShmCreatePixmap', # 5
123             sub {
124             my ($X, $pixmap, $drawable, $depth, $width, $height, $shmseg, $offset)
125             = @_;
126             return pack ('LLSSCxxxLL',
127             $pixmap, $drawable,
128             $width, $height, $depth,
129             $shmseg, $offset);
130             } ],
131              
132             ];
133              
134             sub new {
135 0     0 0   my ($class, $X, $request_num, $event_num, $error_num) = @_;
136             ### MIT_SHM new() ...
137              
138             # Errors
139 0           $X->{'ext_const'}->{'Error'}->[$error_num] = 'ShmSeg';
140 0           $X->{'ext_const_num'}->{'Error'}->{'ShmSeg'} = $error_num;
141 0           $X->{'ext_error_type'}->[$error_num] = 1; # bad resource
142              
143             # Requests
144 0           _ext_requests_install ($X, $request_num, $reqs);
145              
146             # Events
147 0           $X->{'ext_const'}{'Events'}[$event_num] = 'MitShmCompletion';
148 0           $X->{'ext_events'}[$event_num] = $MitShmCompletion_event;
149              
150 0           return bless { }, $class;
151             }
152              
153             sub _ext_requests_install {
154 0     0     my ($X, $request_num, $reqs) = @_;
155              
156 0           $X->{'ext_request'}->{$request_num} = $reqs;
157 0           my $href = $X->{'ext_request_num'};
158 0           my $i;
159 0           foreach $i (0 .. $#$reqs) {
160 0           $href->{$reqs->[$i]->[0]} = [$request_num, $i];
161             }
162             }
163              
164             sub _request_empty {
165             # ($X)
166 0 0   0     if (@_ > 1) {
167 0           croak "No parameters in this request";
168             }
169 0           return '';
170             }
171              
172             sub _request_card32s {
173 0     0     shift; # ($X, $card32...)
174             ### _request_card32s(): @_
175 0           return pack 'L*', @_;
176             }
177              
178             sub _interp_none {
179 0     0     my ($X, $id) = @_;
180 0 0 0       if ($X->{'do_interp'} && $id == 0) {
181 0           return 'None';
182             } else {
183 0           return $id;
184             }
185             }
186              
187             1;
188             __END__