| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # The X Rendering Extension | ||
| 4 | package X11::Protocol::Ext::RENDER; | ||
| 5 | |||
| 6 | # Copyright (C) 2004 Stephen McCamant. All rights reserved. This program | ||
| 7 | # is free software; you can redistribute and/or modify it under the same | ||
| 8 | # terms as Perl itself. | ||
| 9 | |||
| 10 | use X11::Protocol qw(pad padding padded make_num_hash); | ||
| 11 | use Carp; | ||
| 12 | |||
| 13 | use strict; | ||
| 14 | use vars '$VERSION'; | ||
| 15 | |||
| 16 | $VERSION = 0.01; | ||
| 17 | |||
| 18 | sub new | ||
| 19 | { | ||
| 20 | my($pkg, $x, $request_num, $event_num, $error_num) = @_; | ||
| 21 | my($self) = {}; | ||
| 22 | |||
| 23 | # Constants | ||
| 24 | |||
| 25 | $x->{'ext_const'}{'PictType'} = ['Indexed', 'Direct']; | ||
| 26 | $x->{'ext_const_num'}{'PictType'} = | ||
| 27 | {make_num_hash($x->{'ext_const'}{'PictType'})}; | ||
| 28 | |||
| 29 | $x->{'ext_const'}{'PictOp'} = | ||
| 30 | ['Clear', 'Src', 'Dst', 'Over', 'OverReverse', 'In', 'InReverse', | ||
| 31 | 'Out', 'OutReverse', 'Atop', 'AtopReverse', 'Xor', 'Add', 'Saturate', | ||
| 32 | undef, undef, | ||
| 33 | 'DisjointClear', 'DisjointSrc', 'DisjointDst', 'DisjointOver', | ||
| 34 | 'DisjointOverReverse', 'DisjointIn', 'DisjointInReverse', | ||
| 35 | 'DisjointOut', 'DisjointOutReverse', 'DisjointAtop', | ||
| 36 | 'DisjointAtopReverse', 'DisjointXor', | ||
| 37 | undef, undef, undef, undef, | ||
| 38 | 'ConjointClear', 'ConjointSrc', 'ConjointDst', 'ConjointOver', | ||
| 39 | 'ConjointOverReverse', 'ConjointIn', 'ConjointInReverse', | ||
| 40 | 'ConjointOut', 'ConjointOutReverse', 'ConjointAtop', | ||
| 41 | 'ConjointAtopReverse', 'ConjointXor']; | ||
| 42 | $x->{'ext_const_num'}{'PictOp'} = | ||
| 43 | {make_num_hash($x->{'ext_const'}{'PictOp'})}; | ||
| 44 | |||
| 45 | $x->{'ext_const'}{'SubPixel'} = | ||
| 46 | ['Unknown', 'HorizontalRGB', 'HorizontalBGR', 'VerticalRGB', | ||
| 47 | 'VerticalBGR', 'None']; | ||
| 48 | $x->{'ext_const_num'}{'SubPixel'} = | ||
| 49 | {make_num_hash($x->{'ext_const'}{'SubPixel'})}; | ||
| 50 | |||
| 51 | $x->{'ext_const'}{'PolyEdge'} = ['Sharp', 'Smooth']; | ||
| 52 | $x->{'ext_const_num'}{'PolyEdge'} = | ||
| 53 | {make_num_hash($x->{'ext_const'}{'PolyEdge'})}; | ||
| 54 | |||
| 55 | $x->{'ext_const'}{'PolyMode'} = ['Precise', 'Imprecise']; | ||
| 56 | $x->{'ext_const_num'}{'PolyMode'} = | ||
| 57 | {make_num_hash($x->{'ext_const'}{'PolyMode'})}; | ||
| 58 | |||
| 59 | my @errors = ('PictFormat', 'Picture', 'PictOp', 'GlyphSet', 'Glyph'); | ||
| 60 | my @error_types = (1, 1, 1, 1, 1); | ||
| 61 | my $err; | ||
| 62 | for $err (@errors) { | ||
| 63 | $x->{'ext_const'}{'Error'}[$error_num] = $err; | ||
| 64 | $x->{'ext_error_type'}[$error_num] = shift @error_types; | ||
| 65 | $error_num++; | ||
| 66 | } | ||
| 67 | $x->{'ext_const_num'}{'Error'} = | ||
| 68 | {make_num_hash($x->{'ext_const'}{'Error'})}; | ||
| 69 | |||
| 70 | # Events: none | ||
| 71 | |||
| 72 | my($Card16, $Int16, $Card8, $Int8); | ||
| 73 | if (pack("L", 1) eq "\0\0\0\1") { | ||
| 74 | $Int8 = "xxxc"; | ||
| 75 | $Card8 = "xxxC"; | ||
| 76 | $Int16 = "xxs"; | ||
| 77 | $Card16 = "xxS"; | ||
| 78 | } elsif (pack("L", 1) eq "\1\0\0\0") { | ||
| 79 | $Int8 = "cxxx"; | ||
| 80 | $Card8 = "Cxxx"; | ||
| 81 | $Int16 = "sxx"; | ||
| 82 | $Card16 = "Sxx"; | ||
| 83 | } else { | ||
| 84 | croak "Can't determine byte order!\n"; | ||
| 85 | } | ||
| 86 | |||
| 87 | my @Attributes_ValueMask = | ||
| 88 | (['repeat', sub { pack($Card8, $_[1]) }], | ||
| 89 | # ['fill_nearest', sub { pack($Card8, $_[1]) }], | ||
| 90 | ['alpha_map', sub { $_[1] = 0 if $_[1] eq "None"; pack("L", $_[1]) }], | ||
| 91 | ['alpha_x_origin', sub { pack($Int16, $_[1]) }], | ||
| 92 | ['alpha_y_origin', sub { pack($Int16, $_[1]) }], | ||
| 93 | ['clip_x_origin', sub { pack($Int16, $_[1]) }], | ||
| 94 | ['clip_y_origin', sub { pack($Int16, $_[1]) }], | ||
| 95 | ['clip_mask', sub { $_[1] = 0 if $_[1] eq "None"; pack("L", $_[1]) }], | ||
| 96 | ['graphics_exposures', sub { pack($Card8, $_[1]) }], | ||
| 97 | ['subwindow_mode', sub { | ||
| 98 | $_[1] = $_[0]->num('GCSubwindowMode', $_[1]); | ||
| 99 | pack($Card8, $_[1]); | ||
| 100 | }], | ||
| 101 | ['poly_edge', sub { | ||
| 102 | $_[1] = $_[0]->num('PolyEdge', $_[1]); | ||
| 103 | pack($Card8, $_[1]); | ||
| 104 | }], | ||
| 105 | ['poly_mode', sub { | ||
| 106 | $_[1] = $_[0]->num('PolyMode', $_[1]); | ||
| 107 | pack($Card8, $_[1]); | ||
| 108 | }], | ||
| 109 | ['dither', sub { $_[1] = 0 if $_[1] eq "None"; pack("L", $_[1]) }], | ||
| 110 | ['component_alpha', sub { pack($Card8, $_[1]) }], | ||
| 111 | ); | ||
| 112 | |||
| 113 | # Requests | ||
| 114 | $x->{'ext_request'}{$request_num} = | ||
| 115 | [ | ||
| 116 | ["RenderQueryVersion", sub { | ||
| 117 | my $self = shift; | ||
| 118 | return pack("LL", 0, 8); # We suport version 0.8 | ||
| 119 | }, sub { | ||
| 120 | my $self = shift; | ||
| 121 | my($data) = @_; | ||
| 122 | my($major, $minor) = unpack("xxxxxxxxLLxxxxxxxxxxxxxxx", | ||
| 123 | $data); | ||
| 124 | return ($major, $minor); | ||
| 125 | }], | ||
| 126 | ["RenderQueryPictFormats", sub { | ||
| 127 | my $self = shift; | ||
| 128 | return ""; | ||
| 129 | }, sub { | ||
| 130 | my $self = shift; | ||
| 131 | my($data) = @_; | ||
| 132 | my($num_formats, $num_screens, $num_depths, $num_visuals, | ||
| 133 | $num_subpixel) = unpack("xxxxxxxxLLLLLxxxx", | ||
| 134 | substr($data, 0, 32)); | ||
| 135 | my(@formats, @screens, @subpixels); | ||
| 136 | my $index = 32; | ||
| 137 | for (0 .. $num_formats - 1) { | ||
| 138 | push @formats, [unpack("LCCxxSSSSSSSSL", | ||
| 139 | substr($data, $index, 28))]; | ||
| 140 | $formats[$#formats][1] = | ||
| 141 | $self->interp('PictType', $formats[$#formats][1]); | ||
| 142 | $index += 28; | ||
| 143 | } | ||
| 144 | for (0 .. $num_screens - 1) { | ||
| 145 | my($ndepths, $fallback) = | ||
| 146 | unpack("LL", substr($data, $index, 8)); | ||
| 147 | $index += 8; | ||
| 148 | my @depths; | ||
| 149 | for (0 .. $ndepths - 1) { | ||
| 150 | my($depth, $nvisuals) = | ||
| 151 | unpack("CxSxxxx", substr($data, $index, 8)); | ||
| 152 | $index += 8; | ||
| 153 | my @visuals; | ||
| 154 | for (0 .. $nvisuals - 1) { | ||
| 155 | my($visual, $format) = | ||
| 156 | unpack("LL", substr($data, $index, 8)); | ||
| 157 | $index += 8; | ||
| 158 | push @visuals, [$visual, $format]; | ||
| 159 | } | ||
| 160 | push @depths, [$depth, @visuals]; | ||
| 161 | } | ||
| 162 | push @screens, [$fallback, @depths]; | ||
| 163 | } | ||
| 164 | for (0 .. $num_subpixel - 1) { | ||
| 165 | my $sp = unpack("L", substr($data, $index, 4)); | ||
| 166 | $index += 4; | ||
| 167 | $sp = $self->interp('SubPixel', $sp); | ||
| 168 | push @subpixels, $sp; | ||
| 169 | } | ||
| 170 | return ([@formats], [@screens], [@subpixels]); | ||
| 171 | }], | ||
| 172 | ["RenderQueryPictIndexValues", sub { | ||
| 173 | my $self = shift; | ||
| 174 | my($format) = @_; | ||
| 175 | return pack("L", $format); | ||
| 176 | }, sub { | ||
| 177 | my($self) = shift; | ||
| 178 | my($data) = @_; | ||
| 179 | my($num_vals) = unpack("xxxxxxxxLxxxxxxxxxxxxxxxxxxxx", | ||
| 180 | substr($data, 0, 32)); | ||
| 181 | my @values; | ||
| 182 | for my $index (0 .. $num_vals - 1) { | ||
| 183 | my($pixel, $r, $g, $b, $alpha) =\ | ||
| 184 | unpack("LSSSS", substr($data, 32 + 12*$index, 12)); | ||
| 185 | push @values, [$index, $r, $g, $b, $alpha]; | ||
| 186 | } | ||
| 187 | return @values; | ||
| 188 | }], | ||
| 189 | ["RenderQueryDithers", sub { | ||
| 190 | die "RenderQueryDithers is unspecified"; | ||
| 191 | }, sub { | ||
| 192 | die "RenderQueryDithers is unspecified"; | ||
| 193 | }], | ||
| 194 | ["RenderCreatePicture", sub { | ||
| 195 | my $self = shift; | ||
| 196 | my($pid, $drawable, $format, %values) = @_; | ||
| 197 | my($mask, $i, @values); | ||
| 198 | for $i (0 .. 12) { | ||
| 199 | if (exists $values{$Attributes_ValueMask[$i][0]}) { | ||
| 200 | $mask |= (1 << $i); | ||
| 201 | push @values, | ||
| 202 | &{$Attributes_ValueMask[$i][1]} | ||
| 203 | ($self, $values{$Attributes_ValueMask[$i][0]}); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | return pack("LLLL", $pid, $drawable, $format, $mask) | ||
| 207 | . join("", @values); | ||
| 208 | }], | ||
| 209 | ["RenderChangePicture", sub { | ||
| 210 | my $self = shift; | ||
| 211 | my($pid, %values) = @_; | ||
| 212 | my($mask, $i, @values); | ||
| 213 | for $i (0 .. 12) { | ||
| 214 | if (exists $values{$Attributes_ValueMask[$i][0]}) { | ||
| 215 | $mask |= (1 << $i); | ||
| 216 | push @values, | ||
| 217 | &{$Attributes_ValueMask[$i][1]} | ||
| 218 | ($self, $values{$Attributes_ValueMask[$i][0]}); | ||
| 219 | } | ||
| 220 | } | ||
| 221 | return pack("LL", $pid, $mask) . join("", @values); | ||
| 222 | }], | ||
| 223 | ["RenderSetPictureClipRectangles", sub { | ||
| 224 | my $self = shift; | ||
| 225 | my($picture, $x_origin, $y_origin, @rects) = @_; | ||
| 226 | my $r; | ||
| 227 | for $r (@rects) { | ||
| 228 | $r = pack("ssSS", @$r); | ||
| 229 | } | ||
| 230 | return pack("Lss", $picture, $x_origin, $y_origin) | ||
| 231 | . join("", @rects); | ||
| 232 | }], | ||
| 233 | ["RenderFreePicture", sub { | ||
| 234 | my $self = shift; | ||
| 235 | my($picture) = @_; | ||
| 236 | return pack("L", $picture); | ||
| 237 | }], | ||
| 238 | ["RenderComposite", sub { | ||
| 239 | my $self = shift; | ||
| 240 | my($op, $src, $mask, $dst, $src_x, $src_y, $mask_x, $mask_y, | ||
| 241 | $dst_x, $dst_y, $width, $height) = @_; | ||
| 242 | $op = $self->num('PictOp', $op); | ||
| 243 | $mask = 0 if $mask eq "None"; | ||
| 244 | return pack("CxxxLLLssssssSS", $op, $src, $mask, $dst, | ||
| 245 | $src_x, $src_y, $mask_x, $mask_y, | ||
| 246 | $dst_x, $dst_y, $width, $height); | ||
| 247 | }], | ||
| 248 | ["RenderScale", sub { | ||
| 249 | die "RenderScale is unspecified"; | ||
| 250 | }], | ||
| 251 | ["RenderTrapezoids", sub { | ||
| 252 | my $self = shift; | ||
| 253 | my($op, $src, $src_x, $src_y, $dst, $mask_format, @traps) = @_; | ||
| 254 | $op = $self->num('PictOp', $op); | ||
| 255 | $mask_format = 0 if $mask_format eq "None"; | ||
| 256 | my $trap; | ||
| 257 | for $trap (@traps) { | ||
| 258 | my($top, $bottom, $lx1, $ly1, $lx2, $ly2, | ||
| 259 | $rx1, $ry1, $rx2, $ry2) = @$trap; | ||
| 260 | $top *= 2**16; $bottom *= 2**16; | ||
| 261 | $lx1 *= 2**16; $ly1 *= 2**16; | ||
| 262 | $lx2 *= 2**16; $ly2 *= 2**16; | ||
| 263 | $rx1 *= 2**16; $ry1 *= 2**16; | ||
| 264 | $rx2 *= 2**16; $ry2 *= 2**16; | ||
| 265 | $trap = pack("llllllllll", $top, $bottom, | ||
| 266 | $lx1, $ly1, $lx2, $ly2, | ||
| 267 | $rx1, $ry1, $rx2, $ry2); | ||
| 268 | } | ||
| 269 | return pack("CxxxLLLss", $op, $src, $dst, $mask_format, | ||
| 270 | $src_x, $src_y) . join("", @traps); | ||
| 271 | }], | ||
| 272 | ["RenderTriangles", sub { | ||
| 273 | my $self = shift; | ||
| 274 | my($op, $src, $src_x, $src_y, $dst, $mask_format, @tris) = @_; | ||
| 275 | $op = $self->num('PictOp', $op); | ||
| 276 | $mask_format = 0 if $mask_format eq "None"; | ||
| 277 | my $tri; | ||
| 278 | for $tri (@tris) { | ||
| 279 | my($x1, $y1, $x2, $y2, $x3, $y3) = @$tri; | ||
| 280 | $x1 *= 2**16; $y1 *= 2**16; | ||
| 281 | $x2 *= 2**16; $y2 *= 2**16; | ||
| 282 | $x3 *= 2**16; $y3 *= 2**16; | ||
| 283 | $tri = pack("llllll", $x1, $y1, $x2, $y2, $x3, $y3); | ||
| 284 | } | ||
| 285 | return pack("CxxxLLLss", $op, $src, $dst, $mask_format, | ||
| 286 | $src_x, $src_y) . join("", @tris); | ||
| 287 | }], | ||
| 288 | ["RenderTriStrip", sub { | ||
| 289 | my $self = shift; | ||
| 290 | my($op, $src, $src_x, $src_y, $dst, $mask_format, @points) = @_; | ||
| 291 | $op = $self->num('PictOp', $op); | ||
| 292 | $mask_format = 0 if $mask_format eq "None"; | ||
| 293 | my $pt; | ||
| 294 | for $pt (@points) { | ||
| 295 | my($x, $y) = @$pt; | ||
| 296 | $x *= 2**16; $y *= 2**16; | ||
| 297 | $pt = pack("ll", $x, $y); | ||
| 298 | } | ||
| 299 | return pack("CxxxLLLss", $op, $src, $dst, $mask_format, | ||
| 300 | $src_x, $src_y) . join("", @points); | ||
| 301 | }], | ||
| 302 | ["RenderTriFan", sub { | ||
| 303 | my $self = shift; | ||
| 304 | my($op, $src, $src_x, $src_y, $dst, $mask_format, @points) = @_; | ||
| 305 | $op = $self->num('PictOp', $op); | ||
| 306 | $mask_format = 0 if $mask_format eq "None"; | ||
| 307 | my $pt; | ||
| 308 | for $pt (@points) { | ||
| 309 | my($x, $y) = @$pt; | ||
| 310 | $x *= 2**16; $y *= 2**16; | ||
| 311 | $pt = pack("ll", $x, $y); | ||
| 312 | } | ||
| 313 | return pack("CxxxLLLss", $op, $src, $dst, $mask_format, | ||
| 314 | $src_x, $src_y) . join("", @points); | ||
| 315 | }], | ||
| 316 | ["RenderColorTrapezoids", sub { | ||
| 317 | die "RenderColorTrapezoids is unimplemented"; | ||
| 318 | # Also unimplemented in the XFree86 server, BTW. | ||
| 319 | }], | ||
| 320 | ["RenderColorTriangles", sub { | ||
| 321 | # N.B. This is not implemented in XFree86 yet, so it will | ||
| 322 | # always give a BadImplementation error. | ||
| 323 | my $self = shift; | ||
| 324 | my($op, $dst, @color_tris) = @_; | ||
| 325 | $op = $self->num('PictOp', $op); | ||
| 326 | my $ct; | ||
| 327 | for $ct (@color_tris) { | ||
| 328 | my($x1, $y1, $r1, $g1, $b1, $a1, | ||
| 329 | $x2, $y2, $r2, $g2, $b2, $a2, | ||
| 330 | $x3, $y3, $r3, $g3, $b3, $a3) = @$ct; | ||
| 331 | $x1 *= 2**16; $y1 *= 2**16; | ||
| 332 | $x2 *= 2**16; $y2 *= 2**16; | ||
| 333 | $x3 *= 2**16; $y3 *= 2**16; | ||
| 334 | $ct = pack("llSSSS llSSSS llSSSS", | ||
| 335 | $x1, $y1, $r1, $g1, $b1, $a1, | ||
| 336 | $x2, $y2, $r2, $g2, $b2, $a2, | ||
| 337 | $x3, $y3, $r3, $g3, $b3, $a3); | ||
| 338 | } | ||
| 339 | return pack("CxxxL", $op, $dst) . join("", @color_tris); | ||
| 340 | }], | ||
| 341 | ["RenderTransform", sub { | ||
| 342 | die "RenderTransform is unspecified " . | ||
| 343 | "(did you mean RenderSetPictureTransform?)"; | ||
| 344 | }], | ||
| 345 | ["RenderCreateGlyphSet", sub { | ||
| 346 | my $self = shift; | ||
| 347 | my($gsid, $format) = @_; | ||
| 348 | return pack("LL", $gsid, $format); | ||
| 349 | }], | ||
| 350 | ["RenderReferenceGlyphSet", sub { | ||
| 351 | my $self = shift; | ||
| 352 | my($new, $existing) = @_; | ||
| 353 | return pack("LL", $new, $existing); | ||
| 354 | }], | ||
| 355 | ["RenderFreeGlyphSet", sub { | ||
| 356 | my $self = shift; | ||
| 357 | my($gsid) = @_; | ||
| 358 | return pack("L", $gsid); | ||
| 359 | }], | ||
| 360 | ["RenderAddGlyphs", sub { | ||
| 361 | my $self = shift; | ||
| 362 | my($gsid, @glyphs) = @_; | ||
| 363 | my $g; | ||
| 364 | my(@gids, @infos, @datas); | ||
| 365 | for $g (@glyphs) { | ||
| 366 | my($id, $width, $height, $x, $y, $x_off, $y_off, $data) = @$g; | ||
| 367 | push @gids, $id; | ||
| 368 | push @infos, pack("SSssss", $width, $height, $x, $y, | ||
| 369 | $x_off, $y_off); | ||
| 370 | push @datas, pack(padded($data), $data); | ||
| 371 | } | ||
| 372 | return pack("LLL*", $gsid, scalar @glyphs, @gids) | ||
| 373 | . join("", @infos) . join("", @datas); | ||
| 374 | }], | ||
| 375 | ["RenderAddGlyphsFromPicture", sub { | ||
| 376 | die "RenderAddGlyphsFromPicture is unimplemented"; | ||
| 377 | # And the specification is broken, since it doesn't say | ||
| 378 | # which glyphs you're adding! | ||
| 379 | }], | ||
| 380 | ["RenderFreeGlyphs", sub { | ||
| 381 | my $self = shift; | ||
| 382 | my($gsid, @glyphs) = @_; | ||
| 383 | return pack("LL*", $gsid, @glyphs); | ||
| 384 | }], | ||
| 385 | ["RenderCompositeGlyphs8", sub { | ||
| 386 | my $self = shift; | ||
| 387 | my($op, $src, $dst, $mask_format, $glyphable, $src_x, $src_y, | ||
| 388 | @items) = @_; | ||
| 389 | $op = $self->num('PictOp', $op); | ||
| 390 | $mask_format = 0 if $mask_format eq "None"; | ||
| 391 | my $it; | ||
| 392 | for $it (@items) { | ||
| 393 | if (ref($it) eq "ARRAY") { | ||
| 394 | my($dx, $dy, $str) = @$it; | ||
| 395 | $it = pack("Cxxxss".padded($str), length($str), | ||
| 396 | $dx, $dy, $str); | ||
| 397 | } else { | ||
| 398 | $it = pack("CxxxxxxxL", 255, $it); | ||
| 399 | } | ||
| 400 | } | ||
| 401 | return pack("CxxxLLLLss", $op, $src, $dst, $mask_format, | ||
| 402 | $glyphable, $src_x, $src_y) . join("", @items); | ||
| 403 | }], | ||
| 404 | ["RenderCompositeGlyphs16", sub { | ||
| 405 | my $self = shift; | ||
| 406 | my($op, $src, $dst, $mask_format, $glyphable, $src_x, $src_y, | ||
| 407 | @items) = @_; | ||
| 408 | $op = $self->num('PictOp', $op); | ||
| 409 | $mask_format = 0 if $mask_format eq "None"; | ||
| 410 | my $it; | ||
| 411 | for $it (@items) { | ||
| 412 | if (ref($it) eq "ARRAY") { | ||
| 413 | my($dx, $dy, $str) = @$it; | ||
| 414 | $it = pack("Cxxxss".padded($str), length($str)/2, | ||
| 415 | $dx, $dy, $str); | ||
| 416 | } else { | ||
| 417 | $it = pack("CxxxxxxxL", 255, $it); | ||
| 418 | } | ||
| 419 | } | ||
| 420 | return pack("CxxxLLLLss", $op, $src, $dst, $mask_format, | ||
| 421 | $glyphable, $src_x, $src_y) . join("", @items); | ||
| 422 | }], | ||
| 423 | ["RenderCompositeGlyphs32", sub { | ||
| 424 | my $self = shift; | ||
| 425 | my($op, $src, $dst, $mask_format, $glyphable, $src_x, $src_y, | ||
| 426 | @items) = @_; | ||
| 427 | $op = $self->num('PictOp', $op); | ||
| 428 | $mask_format = 0 if $mask_format eq "None"; | ||
| 429 | my $it; | ||
| 430 | for $it (@items) { | ||
| 431 | if (ref($it) eq "ARRAY") { | ||
| 432 | my($dx, $dy, $str) = @$it; | ||
| 433 | $it = pack("Cxxxss".padded($str), length($str)/4, | ||
| 434 | $dx, $dy, $str); | ||
| 435 | } else { | ||
| 436 | $it = pack("CxxxxxxxL", 255, $it); | ||
| 437 | } | ||
| 438 | } | ||
| 439 | return pack("CxxxLLLLss", $op, $src, $dst, $mask_format, | ||
| 440 | $glyphable, $src_x, $src_y) . join("", @items); | ||
| 441 | }], | ||
| 442 | ["RenderFillRectangles", sub { | ||
| 443 | my $self = shift; | ||
| 444 | my($op, $dst, $color, @rects) = @_; | ||
| 445 | $op = $self->num('PictOp', $op); | ||
| 446 | $color = pack("SSSS", @$color); | ||
| 447 | my $r; | ||
| 448 | for $r (@rects) { | ||
| 449 | $r = pack("ssSS", @$r); | ||
| 450 | } | ||
| 451 | return pack("CxxxL", $op, $dst) . $color . join("", @rects); | ||
| 452 | }], | ||
| 453 | ["RenderCreateCursor", sub { | ||
| 454 | my $self = shift; | ||
| 455 | my($cid, $src, $x, $y) = @_; | ||
| 456 | return pack("LLSS", $cid, $src, $x, $y); | ||
| 457 | }], | ||
| 458 | ["RenderSetPictureTransform", sub { | ||
| 459 | my $self = shift; | ||
| 460 | my($pict, @trans) = @_; | ||
| 461 | my $trans = pack("l9", map($_ * 2**16, @trans)); | ||
| 462 | return pack("L", $pict) . $trans; | ||
| 463 | }], | ||
| 464 | ["RenderQueryFilters", sub { | ||
| 465 | my $self = shift; | ||
| 466 | my($drawable) = @_; | ||
| 467 | return pack("L", $drawable); | ||
| 468 | }, sub { | ||
| 469 | my $self = shift; | ||
| 470 | my($data) = @_; | ||
| 471 | my(@aliases, @filters); | ||
| 472 | my($num_al, $num_filt) = | ||
| 473 | unpack("xxxxxxxxLLxxxxxxxxxxxxxxxx", substr($data, 0, 32)); | ||
| 474 | my $index = 32; | ||
| 475 | for (0 .. $num_al - 1) { | ||
| 476 | my $alias = unpack("S", substr($data, $index, 2)); | ||
| 477 | $index += 2; | ||
| 478 | push @aliases, $alias; | ||
| 479 | } | ||
| 480 | $index += padding($index); | ||
| 481 | for (0 .. $num_filt) { | ||
| 482 | my $len = unpack("C", substr($data, $index, 1)); | ||
| 483 | $index++; | ||
| 484 | my $str = substr($data, $index, $len); | ||
| 485 | $index += $len; | ||
| 486 | push @filters, $str; | ||
| 487 | } | ||
| 488 | return ([@filters], [@aliases]); | ||
| 489 | }], | ||
| 490 | ["RenderSetPictureFilter", sub { | ||
| 491 | my $self = shift; | ||
| 492 | my($picture, $filter, @args) = @_; | ||
| 493 | return pack("LSxx".padded($filter)."L*", $picture, length($filter), | ||
| 494 | $filter, map($_ * 2**16, @args)); | ||
| 495 | }], | ||
| 496 | ["RenderCreateAnimCursor", sub { | ||
| 497 | my $self = shift; | ||
| 498 | my($cid, @frames) = @_; | ||
| 499 | my $fr; | ||
| 500 | for $fr (@frames) { | ||
| 501 | $fr = pack("LL", @$fr); | ||
| 502 | } | ||
| 503 | return pack("L", $cid) . join("", @frames); | ||
| 504 | }], | ||
| 505 | ]; | ||
| 506 | my($i); | ||
| 507 | for $i (0 .. $#{$x->{'ext_request'}{$request_num}}) { | ||
| 508 | $x->{'ext_request_num'}{$x->{'ext_request'}{$request_num}[$i][0]} = | ||
| 509 | [$request_num, $i]; | ||
| 510 | } | ||
| 511 | ($self->{'major'}, $self->{'minor'}) | ||
| 512 | = $x->req('RenderQueryVersion', 0, 8); | ||
| 513 | if ($self->{'major'} != 0) { | ||
| 514 | carp "Wrong RENDER version ($self->{'major'} != 0)"; | ||
| 515 | return 0; | ||
| 516 | } | ||
| 517 | return bless $self, $pkg; | ||
| 518 | } | ||
| 519 | |||
| 520 | 1; | ||
| 521 | __END__ |