File: shape.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (769 lines) | stat: -rw-r--r-- 18,215 bytes parent folder | download | duplicates (9)
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
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file was automatically generated with:
// ../../ui/gfx/x/gen_xproto.py \
//    ../../third_party/xcbproto/src \
//    gen/ui/gfx/x \
//    bigreq \
//    dri3 \
//    glx \
//    randr \
//    render \
//    screensaver \
//    shape \
//    shm \
//    sync \
//    xfixes \
//    xinput \
//    xkb \
//    xproto \
//    xtest

#include "shape.h"

#include <unistd.h>
#include <xcb/xcb.h>
#include <xcb/xcbext.h>

#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/xproto_internal.h"

namespace x11 {

Shape::Shape(Connection* connection, const x11::QueryExtensionReply& info)
    : connection_(connection), info_(info) {}

template <>
COMPONENT_EXPORT(X11)
void ReadEvent<Shape::NotifyEvent>(Shape::NotifyEvent* event_,
                                   ReadBuffer* buffer) {
  auto& buf = *buffer;

  auto& shape_kind = (*event_).shape_kind;
  auto& sequence = (*event_).sequence;
  auto& affected_window = (*event_).affected_window;
  auto& extents_x = (*event_).extents_x;
  auto& extents_y = (*event_).extents_y;
  auto& extents_width = (*event_).extents_width;
  auto& extents_height = (*event_).extents_height;
  auto& server_time = (*event_).server_time;
  auto& shaped = (*event_).shaped;

  // response_type
  uint8_t response_type;
  Read(&response_type, &buf);

  // shape_kind
  uint8_t tmp0;
  Read(&tmp0, &buf);
  shape_kind = static_cast<Shape::Sk>(tmp0);

  // sequence
  Read(&sequence, &buf);

  // affected_window
  Read(&affected_window, &buf);

  // extents_x
  Read(&extents_x, &buf);

  // extents_y
  Read(&extents_y, &buf);

  // extents_width
  Read(&extents_width, &buf);

  // extents_height
  Read(&extents_height, &buf);

  // server_time
  Read(&server_time, &buf);

  // shaped
  Read(&shaped, &buf);

  // pad0
  Pad(&buf, 11);

  CHECK_LE(buf.offset, 32ul);
}

Future<Shape::QueryVersionReply> Shape::QueryVersion(
    const Shape::QueryVersionRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 0;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  Align(&buf, 4);

  return connection_->SendRequest<Shape::QueryVersionReply>(
      &buf, "Shape::QueryVersion", false);
}

Future<Shape::QueryVersionReply> Shape::QueryVersion() {
  return Shape::QueryVersion(Shape::QueryVersionRequest{});
}

template <>
COMPONENT_EXPORT(X11)
std::unique_ptr<Shape::QueryVersionReply> detail::ReadReply<
    Shape::QueryVersionReply>(ReadBuffer* buffer) {
  auto& buf = *buffer;
  auto reply = std::make_unique<Shape::QueryVersionReply>();

  auto& sequence = (*reply).sequence;
  auto& major_version = (*reply).major_version;
  auto& minor_version = (*reply).minor_version;

  // response_type
  uint8_t response_type;
  Read(&response_type, &buf);

  // pad0
  Pad(&buf, 1);

  // sequence
  Read(&sequence, &buf);

  // length
  uint32_t length;
  Read(&length, &buf);

  // major_version
  Read(&major_version, &buf);

  // minor_version
  Read(&minor_version, &buf);

  Align(&buf, 4);
  CHECK_EQ(buf.offset < 32 ? 0 : buf.offset - 32, 4 * length);

  return reply;
}

Future<void> Shape::Rectangles(const Shape::RectanglesRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  auto& operation = request.operation;
  auto& destination_kind = request.destination_kind;
  auto& ordering = request.ordering;
  auto& destination_window = request.destination_window;
  auto& x_offset = request.x_offset;
  auto& y_offset = request.y_offset;
  auto& rectangles = request.rectangles;
  size_t rectangles_len = rectangles.size();

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 1;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  // operation
  uint8_t tmp1;
  tmp1 = static_cast<uint8_t>(operation);
  buf.Write(&tmp1);

  // destination_kind
  uint8_t tmp2;
  tmp2 = static_cast<uint8_t>(destination_kind);
  buf.Write(&tmp2);

  // ordering
  uint8_t tmp3;
  tmp3 = static_cast<uint8_t>(ordering);
  buf.Write(&tmp3);

  // pad0
  Pad(&buf, 1);

  // destination_window
  buf.Write(&destination_window);

  // x_offset
  buf.Write(&x_offset);

  // y_offset
  buf.Write(&y_offset);

  // rectangles
  CHECK_EQ(static_cast<size_t>(rectangles_len), rectangles.size());
  for (auto& rectangles_elem : rectangles) {
    // rectangles_elem
    {
      auto& x = rectangles_elem.x;
      auto& y = rectangles_elem.y;
      auto& width = rectangles_elem.width;
      auto& height = rectangles_elem.height;

      // x
      buf.Write(&x);

      // y
      buf.Write(&y);

      // width
      buf.Write(&width);

      // height
      buf.Write(&height);
    }
  }

  Align(&buf, 4);

  return connection_->SendRequest<void>(&buf, "Shape::Rectangles", false);
}

Future<void> Shape::Rectangles(const So& operation,
                               const Sk& destination_kind,
                               const ClipOrdering& ordering,
                               const Window& destination_window,
                               const int16_t& x_offset,
                               const int16_t& y_offset,
                               const std::vector<Rectangle>& rectangles) {
  return Shape::Rectangles(Shape::RectanglesRequest{
      operation, destination_kind, ordering, destination_window, x_offset,
      y_offset, rectangles});
}

Future<void> Shape::Mask(const Shape::MaskRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  auto& operation = request.operation;
  auto& destination_kind = request.destination_kind;
  auto& destination_window = request.destination_window;
  auto& x_offset = request.x_offset;
  auto& y_offset = request.y_offset;
  auto& source_bitmap = request.source_bitmap;

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 2;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  // operation
  uint8_t tmp4;
  tmp4 = static_cast<uint8_t>(operation);
  buf.Write(&tmp4);

  // destination_kind
  uint8_t tmp5;
  tmp5 = static_cast<uint8_t>(destination_kind);
  buf.Write(&tmp5);

  // pad0
  Pad(&buf, 2);

  // destination_window
  buf.Write(&destination_window);

  // x_offset
  buf.Write(&x_offset);

  // y_offset
  buf.Write(&y_offset);

  // source_bitmap
  buf.Write(&source_bitmap);

  Align(&buf, 4);

  return connection_->SendRequest<void>(&buf, "Shape::Mask", false);
}

Future<void> Shape::Mask(const So& operation,
                         const Sk& destination_kind,
                         const Window& destination_window,
                         const int16_t& x_offset,
                         const int16_t& y_offset,
                         const Pixmap& source_bitmap) {
  return Shape::Mask(Shape::MaskRequest{operation, destination_kind,
                                        destination_window, x_offset, y_offset,
                                        source_bitmap});
}

Future<void> Shape::Combine(const Shape::CombineRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  auto& operation = request.operation;
  auto& destination_kind = request.destination_kind;
  auto& source_kind = request.source_kind;
  auto& destination_window = request.destination_window;
  auto& x_offset = request.x_offset;
  auto& y_offset = request.y_offset;
  auto& source_window = request.source_window;

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 3;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  // operation
  uint8_t tmp6;
  tmp6 = static_cast<uint8_t>(operation);
  buf.Write(&tmp6);

  // destination_kind
  uint8_t tmp7;
  tmp7 = static_cast<uint8_t>(destination_kind);
  buf.Write(&tmp7);

  // source_kind
  uint8_t tmp8;
  tmp8 = static_cast<uint8_t>(source_kind);
  buf.Write(&tmp8);

  // pad0
  Pad(&buf, 1);

  // destination_window
  buf.Write(&destination_window);

  // x_offset
  buf.Write(&x_offset);

  // y_offset
  buf.Write(&y_offset);

  // source_window
  buf.Write(&source_window);

  Align(&buf, 4);

  return connection_->SendRequest<void>(&buf, "Shape::Combine", false);
}

Future<void> Shape::Combine(const So& operation,
                            const Sk& destination_kind,
                            const Sk& source_kind,
                            const Window& destination_window,
                            const int16_t& x_offset,
                            const int16_t& y_offset,
                            const Window& source_window) {
  return Shape::Combine(Shape::CombineRequest{
      operation, destination_kind, source_kind, destination_window, x_offset,
      y_offset, source_window});
}

Future<void> Shape::Offset(const Shape::OffsetRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  auto& destination_kind = request.destination_kind;
  auto& destination_window = request.destination_window;
  auto& x_offset = request.x_offset;
  auto& y_offset = request.y_offset;

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 4;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  // destination_kind
  uint8_t tmp9;
  tmp9 = static_cast<uint8_t>(destination_kind);
  buf.Write(&tmp9);

  // pad0
  Pad(&buf, 3);

  // destination_window
  buf.Write(&destination_window);

  // x_offset
  buf.Write(&x_offset);

  // y_offset
  buf.Write(&y_offset);

  Align(&buf, 4);

  return connection_->SendRequest<void>(&buf, "Shape::Offset", false);
}

Future<void> Shape::Offset(const Sk& destination_kind,
                           const Window& destination_window,
                           const int16_t& x_offset,
                           const int16_t& y_offset) {
  return Shape::Offset(Shape::OffsetRequest{
      destination_kind, destination_window, x_offset, y_offset});
}

Future<Shape::QueryExtentsReply> Shape::QueryExtents(
    const Shape::QueryExtentsRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  auto& destination_window = request.destination_window;

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 5;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  // destination_window
  buf.Write(&destination_window);

  Align(&buf, 4);

  return connection_->SendRequest<Shape::QueryExtentsReply>(
      &buf, "Shape::QueryExtents", false);
}

Future<Shape::QueryExtentsReply> Shape::QueryExtents(
    const Window& destination_window) {
  return Shape::QueryExtents(Shape::QueryExtentsRequest{destination_window});
}

template <>
COMPONENT_EXPORT(X11)
std::unique_ptr<Shape::QueryExtentsReply> detail::ReadReply<
    Shape::QueryExtentsReply>(ReadBuffer* buffer) {
  auto& buf = *buffer;
  auto reply = std::make_unique<Shape::QueryExtentsReply>();

  auto& sequence = (*reply).sequence;
  auto& bounding_shaped = (*reply).bounding_shaped;
  auto& clip_shaped = (*reply).clip_shaped;
  auto& bounding_shape_extents_x = (*reply).bounding_shape_extents_x;
  auto& bounding_shape_extents_y = (*reply).bounding_shape_extents_y;
  auto& bounding_shape_extents_width = (*reply).bounding_shape_extents_width;
  auto& bounding_shape_extents_height = (*reply).bounding_shape_extents_height;
  auto& clip_shape_extents_x = (*reply).clip_shape_extents_x;
  auto& clip_shape_extents_y = (*reply).clip_shape_extents_y;
  auto& clip_shape_extents_width = (*reply).clip_shape_extents_width;
  auto& clip_shape_extents_height = (*reply).clip_shape_extents_height;

  // response_type
  uint8_t response_type;
  Read(&response_type, &buf);

  // pad0
  Pad(&buf, 1);

  // sequence
  Read(&sequence, &buf);

  // length
  uint32_t length;
  Read(&length, &buf);

  // bounding_shaped
  Read(&bounding_shaped, &buf);

  // clip_shaped
  Read(&clip_shaped, &buf);

  // pad1
  Pad(&buf, 2);

  // bounding_shape_extents_x
  Read(&bounding_shape_extents_x, &buf);

  // bounding_shape_extents_y
  Read(&bounding_shape_extents_y, &buf);

  // bounding_shape_extents_width
  Read(&bounding_shape_extents_width, &buf);

  // bounding_shape_extents_height
  Read(&bounding_shape_extents_height, &buf);

  // clip_shape_extents_x
  Read(&clip_shape_extents_x, &buf);

  // clip_shape_extents_y
  Read(&clip_shape_extents_y, &buf);

  // clip_shape_extents_width
  Read(&clip_shape_extents_width, &buf);

  // clip_shape_extents_height
  Read(&clip_shape_extents_height, &buf);

  Align(&buf, 4);
  CHECK_EQ(buf.offset < 32 ? 0 : buf.offset - 32, 4 * length);

  return reply;
}

Future<void> Shape::SelectInput(const Shape::SelectInputRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  auto& destination_window = request.destination_window;
  auto& enable = request.enable;

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 6;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  // destination_window
  buf.Write(&destination_window);

  // enable
  buf.Write(&enable);

  // pad0
  Pad(&buf, 3);

  Align(&buf, 4);

  return connection_->SendRequest<void>(&buf, "Shape::SelectInput", false);
}

Future<void> Shape::SelectInput(const Window& destination_window,
                                const uint8_t& enable) {
  return Shape::SelectInput(
      Shape::SelectInputRequest{destination_window, enable});
}

Future<Shape::InputSelectedReply> Shape::InputSelected(
    const Shape::InputSelectedRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  auto& destination_window = request.destination_window;

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 7;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  // destination_window
  buf.Write(&destination_window);

  Align(&buf, 4);

  return connection_->SendRequest<Shape::InputSelectedReply>(
      &buf, "Shape::InputSelected", false);
}

Future<Shape::InputSelectedReply> Shape::InputSelected(
    const Window& destination_window) {
  return Shape::InputSelected(Shape::InputSelectedRequest{destination_window});
}

template <>
COMPONENT_EXPORT(X11)
std::unique_ptr<Shape::InputSelectedReply> detail::ReadReply<
    Shape::InputSelectedReply>(ReadBuffer* buffer) {
  auto& buf = *buffer;
  auto reply = std::make_unique<Shape::InputSelectedReply>();

  auto& enabled = (*reply).enabled;
  auto& sequence = (*reply).sequence;

  // response_type
  uint8_t response_type;
  Read(&response_type, &buf);

  // enabled
  Read(&enabled, &buf);

  // sequence
  Read(&sequence, &buf);

  // length
  uint32_t length;
  Read(&length, &buf);

  Align(&buf, 4);
  CHECK_EQ(buf.offset < 32 ? 0 : buf.offset - 32, 4 * length);

  return reply;
}

Future<Shape::GetRectanglesReply> Shape::GetRectangles(
    const Shape::GetRectanglesRequest& request) {
  if (!connection_->Ready() || !present())
    return {};

  WriteBuffer buf;

  auto& window = request.window;
  auto& source_kind = request.source_kind;

  // major_opcode
  uint8_t major_opcode = info_.major_opcode;
  buf.Write(&major_opcode);

  // minor_opcode
  uint8_t minor_opcode = 8;
  buf.Write(&minor_opcode);

  // length
  // Caller fills in length for writes.
  Pad(&buf, sizeof(uint16_t));

  // window
  buf.Write(&window);

  // source_kind
  uint8_t tmp10;
  tmp10 = static_cast<uint8_t>(source_kind);
  buf.Write(&tmp10);

  // pad0
  Pad(&buf, 3);

  Align(&buf, 4);

  return connection_->SendRequest<Shape::GetRectanglesReply>(
      &buf, "Shape::GetRectangles", false);
}

Future<Shape::GetRectanglesReply> Shape::GetRectangles(const Window& window,
                                                       const Sk& source_kind) {
  return Shape::GetRectangles(Shape::GetRectanglesRequest{window, source_kind});
}

template <>
COMPONENT_EXPORT(X11)
std::unique_ptr<Shape::GetRectanglesReply> detail::ReadReply<
    Shape::GetRectanglesReply>(ReadBuffer* buffer) {
  auto& buf = *buffer;
  auto reply = std::make_unique<Shape::GetRectanglesReply>();

  auto& ordering = (*reply).ordering;
  auto& sequence = (*reply).sequence;
  uint32_t rectangles_len{};
  auto& rectangles = (*reply).rectangles;

  // response_type
  uint8_t response_type;
  Read(&response_type, &buf);

  // ordering
  uint8_t tmp11;
  Read(&tmp11, &buf);
  ordering = static_cast<ClipOrdering>(tmp11);

  // sequence
  Read(&sequence, &buf);

  // length
  uint32_t length;
  Read(&length, &buf);

  // rectangles_len
  Read(&rectangles_len, &buf);

  // pad0
  Pad(&buf, 20);

  // rectangles
  rectangles.resize(rectangles_len);
  for (auto& rectangles_elem : rectangles) {
    // rectangles_elem
    {
      auto& x = rectangles_elem.x;
      auto& y = rectangles_elem.y;
      auto& width = rectangles_elem.width;
      auto& height = rectangles_elem.height;

      // x
      Read(&x, &buf);

      // y
      Read(&y, &buf);

      // width
      Read(&width, &buf);

      // height
      Read(&height, &buf);
    }
  }

  Align(&buf, 4);
  CHECK_EQ(buf.offset < 32 ? 0 : buf.offset - 32, 4 * length);

  return reply;
}

}  // namespace x11