X11/Protocol/Ext/DAMAGE.pm

filter: Statementstmt 28.7% 23 / 80 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 31.5% 6 / 19 Podpod 0.0% 0 / 1 totaltotal 25.2% 29 / 115 CC 8 SCAR 15.0
CC
8
Cov
25%
_num_none
12.0
__ANON__
6.0
__ANON__
6.0
CRAP 4.5
« X11/Protocol/Ext/XFIXES.pm ↑ Summary X11/Protocol/Ext/MIT_SHM.pm »
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 <http://www.gnu.org/licenses/>.
17  
18  
19 # /usr/share/doc/x11proto-damage-dev/damageproto.txt.gz
20 # http://cgit.freedesktop.org/xorg/proto/damageproto/tree/damageproto.txt
21 #
22 # /usr/include/X11/extensions/Xdamage.h
23 # /usr/include/X11/extensions/damageproto.h
24 # /usr/include/X11/extensions/damagewire.h
25 #
26 # server side source:
27 # http://cgit.freedesktop.org/xorg/xserver/tree/damageext/damageext.c
28 #
29  
30  
31 1 ▶BEGIN { require 5 }
Subroutine BEGIN: called CC=1 SCAR=0.0
32 package X11::Protocol::Ext::DAMAGE;
33 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use X11::Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 ▶use vars '$VERSION', '@CARP_NOT';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 $VERSION = 31;
38 1 @CARP_NOT = ('X11::Protocol');
39  
40 # uncomment this to run the ### lines
41 #use Smart::Comments;
42  
43  
44 # these not documented yet ...
45 1 ▶use constant CLIENT_MAJOR_VERSION => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use constant CLIENT_MINOR_VERSION => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 my $reqs
49 = [
50 #------------
51 # version 1.0
52  
53 ["DamageQueryVersion", # 0
54 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 my ($X, $major, $minor) = @_;
56 ### DamageQueryVersion request
57 0 return pack 'LL', $major, $minor;
58 },
59 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
60 0 my ($X, $data) = @_;
61 ### DamageQueryVersion reply
62 0 my @ret = unpack 'x8LL', $data;
63  
64 # Any interest in holding onto the version?
65 # Remove DamageAdd if downgrading?
66 0 my $self;
67 0 ▶ if ($self = $X->{'ext'}->{'DAMAGE'}->[3]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self = $X->{"ext"}{"DAMAGE"}[3]) 0 0 0
68 0 ($self->{'major'}, $self->{'minor'}) = @ret;
69 }
70 0 return @ret;
71 }],
72  
73 ["DamageCreate", # 1
74 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 my ($X, $damage, $drawable, $level) = @_;
76 ### DamageCreate
77 0 return pack ('LLCxxx',
78 $damage,
79 $drawable,
80 $X->num('DamageReportLevel',$level));
81 1 }],
82  
83 ["DamageDestroy", # 2
84 \&_request_xids ], # ($damage)
85  
86 ["DamageSubtract", # 3
87 \&_request_xids ], # ($damage, $repair_region, $parts_region)
88  
89 #------------
90 # version 1.1
91  
92 ["DamageAdd", # 4
93 \&_request_xids ], # ($damage, $region)
94 ];
95  
96 my $DamageNotify_event
97 0 ▶ = [ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 0 my $X = shift;
99 0 my $data = shift;
100 ### DamageNotify unpack: @_[1..$#_]
101 0 my ($level, $drawable, $damage, $time, $area, $geometry)
102 = unpack 'xCxxL3a8a8', $data;
103 ### fields: $level, $drawable, $damage, $time, $area, $geometry
104 ### area: _unpack_rectangle($area)
105 ### geometry: _unpack_rectangle($geometry)
106 0 my $more = ($level >> 7) & 1; # bit 0x80
107 0 $level &= 0x7F;
108 0 return (@_, # base fields
109 drawable => $drawable,
110 damage => $damage,
111 level => $X->interp('DamageReportLevel',$level),
112 more => $more,
113 time => _interp_time($time),
114 area => _unpack_rectangle($area),
115 geometry => _unpack_rectangle($geometry),
116 );
117 0 ▶ }, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
118 0 my ($X, %h) = @_;
119 my $level = ($X->num('DamageReportLevel', $h{'level'})
120 0 ▶ + ($h{'more'} ? 0x80 : 0));
Branch: 1 branch
BranchTrueFalseTotal
$h{'more'} ? : 0 0 0
121 return (pack('xCxxL3ssSSssSS',
122 $level,
123 $h{'drawable'},
124 $h{'damage'},
125 _num_time($h{'time'}),
126 0 @{$h{'area'}}, # [$x,$y,$w,$h]
127 0 @{$h{'geometry'}}), # [$x,$y,$w,$h]
128 1); # "do_seq" put in sequence number
129 1 } ];
130  
131 1 my $DamageReportLevel_array = [ 'RawRectangles',
132 'DeltaRectangles',
133 'BoundingBox',
134 'NonEmpty' ];
135 1 my $DamageReportLevel_hash
136 = { X11::Protocol::make_num_hash($DamageReportLevel_array) };
137  
138 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
139 0 my ($class, $X, $request_num, $event_num, $error_num) = @_;
140 ### DAMAGE new()
141  
142 # Constants
143 0 $X->{'ext_const'}->{'DamageReportLevel'} = $DamageReportLevel_array;
144 0 $X->{'ext_const_num'}->{'DamageReportLevel'} = $DamageReportLevel_hash;
145  
146 # Errors
147 0 $X->{'ext_const'}->{'Error'}->[$error_num] = 'Damage';
148 0 $X->{'ext_const_num'}->{'Error'}->{'Damage'} = $error_num;
149 0 $X->{'ext_error_type'}->[$error_num] = 1; # bad resource
150  
151 # Events
152 0 $X->{'ext_const'}->{'Events'}->[$event_num] = 'DamageNotify';
153 0 $X->{'ext_events'}->[$event_num] = $DamageNotify_event;
154  
155 # Requests
156 0 _ext_requests_install ($X, $request_num, $reqs);
157  
158 # Must DamageQueryVersion to negotiate desired version, or at least X.org
159 # server 1.9.x gives "Opcode" errors to all other requests if not.
160 0 my ($major, $minor) = $X->req ('DamageQueryVersion',
161 CLIENT_MAJOR_VERSION,
162 CLIENT_MINOR_VERSION);
163 0 return bless { major => $major,
164 minor => $minor,
165 }, $class;
166 }
167  
168 0 ▶sub _ext_requests_install {
Subroutine _ext_requests_install: not called CC=2 SCAR=17.9
169 0 my ($X, $request_num, $reqs) = @_;
170  
171 0 $X->{'ext_request'}->{$request_num} = $reqs;
172 0 my $href = $X->{'ext_request_num'};
173 0 my $i;
174 0 foreach $i (0 .. $#$reqs) {
175 0 $href->{$reqs->[$i]->[0]} = [$request_num, $i];
176 }
177 }
178  
179 0 ▶sub _request_xids {
Subroutine _request_xids: not called CC=1 SCAR=6.9
180 0 my $X = shift;
181 ### _request_xids(): @_
182 0 return _request_card32s ($X, map {_num_none($_)} @_);
183 }
184 0 ▶sub _request_card32s {
Subroutine _request_card32s: not called CC=1 SCAR=6.9
185 0 shift;
186 ### _request_card32s(): @_
187 0 return pack 'L*', @_;
188 }
189 0 ▶sub _num_none {
Subroutine _num_none: not called CC=3 SCAR=24.8
190 0 my ($xid) = @_;
191 0 ▶ if (defined $xid && $xid eq 'None') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xid and $xid eq 'None') { } 0 0 0
Condition0%0/3
defined $xid and $xid eq "None"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $xid and $xid eq "None"
defined $xid $xid eq "None"
Truth table0%0/3
A and B
A= defined $xidB= $xid eq "None"
ABresult
0X0
100
111
192 0 return 0;
193 } else {
194 0 return $xid;
195 }
196 }
197  
198 0 ▶sub _unpack_rectangle {
Subroutine _unpack_rectangle: not called CC=1 SCAR=6.9
199 0 my ($data) = @_;
200 0 return [ unpack 'ssSS', $data ];
201 }
202  
203 0 ▶sub _interp_time {
Subroutine _interp_time: not called CC=2 SCAR=17.9
204 0 my ($time) = @_;
205 0 ▶ if ($time == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time == 0) { } 0 0 0
206 0 return 'CurrentTime';
207 } else {
208 0 return $time;
209 }
210 }
211 0 ▶sub _num_time {
Subroutine _num_time: not called CC=2 SCAR=17.9
212 0 my ($time) = @_;
213 0 ▶ if ($time eq 'CurrentTime') {
Branch: 1 branch
BranchTrueFalseTotal
if ($time eq 'CurrentTime') { } 0 0 0
214 0 return 0;
215 } else {
216 0 return $time;
217 }
218 }
219  
220 1 1;
221 __END__
« X11/Protocol/Ext/XFIXES.pm ↑ Summary X11/Protocol/Ext/MIT_SHM.pm »