OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 library geometry_mojom; | 5 library geometry_mojom; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:mojo/bindings.dart' as bindings; | 9 import 'package:mojo/bindings.dart' as bindings; |
10 import 'package:mojo/core.dart' as core; | 10 import 'package:mojo/core.dart' as core; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 Map map = new Map(); | 420 Map map = new Map(); |
421 map["x"] = x; | 421 map["x"] = x; |
422 map["y"] = y; | 422 map["y"] = y; |
423 map["width"] = width; | 423 map["width"] = width; |
424 map["height"] = height; | 424 map["height"] = height; |
425 return map; | 425 return map; |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 | 429 |
| 430 class RRect extends bindings.Struct { |
| 431 static const List<bindings.StructDataHeader> kVersions = const [ |
| 432 const bindings.StructDataHeader(56, 0) |
| 433 ]; |
| 434 int x = 0; |
| 435 int y = 0; |
| 436 int width = 0; |
| 437 int height = 0; |
| 438 int topLeftRadiusX = 0; |
| 439 int topLeftRadiusY = 0; |
| 440 int topRightRadiusX = 0; |
| 441 int topRightRadiusY = 0; |
| 442 int bottomLeftRadiusX = 0; |
| 443 int bottomLeftRadiusY = 0; |
| 444 int bottomRightRadiusX = 0; |
| 445 int bottomRightRadiusY = 0; |
| 446 |
| 447 RRect() : super(kVersions.last.size); |
| 448 |
| 449 static RRect deserialize(bindings.Message message) { |
| 450 var decoder = new bindings.Decoder(message); |
| 451 var result = decode(decoder); |
| 452 if (decoder.excessHandles != null) { |
| 453 decoder.excessHandles.forEach((h) => h.close()); |
| 454 } |
| 455 return result; |
| 456 } |
| 457 |
| 458 static RRect decode(bindings.Decoder decoder0) { |
| 459 if (decoder0 == null) { |
| 460 return null; |
| 461 } |
| 462 RRect result = new RRect(); |
| 463 |
| 464 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 465 if (mainDataHeader.version <= kVersions.last.version) { |
| 466 // Scan in reverse order to optimize for more recent versions. |
| 467 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 468 if (mainDataHeader.version >= kVersions[i].version) { |
| 469 if (mainDataHeader.size == kVersions[i].size) { |
| 470 // Found a match. |
| 471 break; |
| 472 } |
| 473 throw new bindings.MojoCodecError( |
| 474 'Header size doesn\'t correspond to known version size.'); |
| 475 } |
| 476 } |
| 477 } else if (mainDataHeader.size < kVersions.last.size) { |
| 478 throw new bindings.MojoCodecError( |
| 479 'Message newer than the last known version cannot be shorter than ' |
| 480 'required by the last known version.'); |
| 481 } |
| 482 if (mainDataHeader.version >= 0) { |
| 483 |
| 484 result.x = decoder0.decodeInt32(8); |
| 485 } |
| 486 if (mainDataHeader.version >= 0) { |
| 487 |
| 488 result.y = decoder0.decodeInt32(12); |
| 489 } |
| 490 if (mainDataHeader.version >= 0) { |
| 491 |
| 492 result.width = decoder0.decodeInt32(16); |
| 493 } |
| 494 if (mainDataHeader.version >= 0) { |
| 495 |
| 496 result.height = decoder0.decodeInt32(20); |
| 497 } |
| 498 if (mainDataHeader.version >= 0) { |
| 499 |
| 500 result.topLeftRadiusX = decoder0.decodeInt32(24); |
| 501 } |
| 502 if (mainDataHeader.version >= 0) { |
| 503 |
| 504 result.topLeftRadiusY = decoder0.decodeInt32(28); |
| 505 } |
| 506 if (mainDataHeader.version >= 0) { |
| 507 |
| 508 result.topRightRadiusX = decoder0.decodeInt32(32); |
| 509 } |
| 510 if (mainDataHeader.version >= 0) { |
| 511 |
| 512 result.topRightRadiusY = decoder0.decodeInt32(36); |
| 513 } |
| 514 if (mainDataHeader.version >= 0) { |
| 515 |
| 516 result.bottomLeftRadiusX = decoder0.decodeInt32(40); |
| 517 } |
| 518 if (mainDataHeader.version >= 0) { |
| 519 |
| 520 result.bottomLeftRadiusY = decoder0.decodeInt32(44); |
| 521 } |
| 522 if (mainDataHeader.version >= 0) { |
| 523 |
| 524 result.bottomRightRadiusX = decoder0.decodeInt32(48); |
| 525 } |
| 526 if (mainDataHeader.version >= 0) { |
| 527 |
| 528 result.bottomRightRadiusY = decoder0.decodeInt32(52); |
| 529 } |
| 530 return result; |
| 531 } |
| 532 |
| 533 void encode(bindings.Encoder encoder) { |
| 534 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 535 |
| 536 encoder0.encodeInt32(x, 8); |
| 537 |
| 538 encoder0.encodeInt32(y, 12); |
| 539 |
| 540 encoder0.encodeInt32(width, 16); |
| 541 |
| 542 encoder0.encodeInt32(height, 20); |
| 543 |
| 544 encoder0.encodeInt32(topLeftRadiusX, 24); |
| 545 |
| 546 encoder0.encodeInt32(topLeftRadiusY, 28); |
| 547 |
| 548 encoder0.encodeInt32(topRightRadiusX, 32); |
| 549 |
| 550 encoder0.encodeInt32(topRightRadiusY, 36); |
| 551 |
| 552 encoder0.encodeInt32(bottomLeftRadiusX, 40); |
| 553 |
| 554 encoder0.encodeInt32(bottomLeftRadiusY, 44); |
| 555 |
| 556 encoder0.encodeInt32(bottomRightRadiusX, 48); |
| 557 |
| 558 encoder0.encodeInt32(bottomRightRadiusY, 52); |
| 559 } |
| 560 |
| 561 String toString() { |
| 562 return "RRect(" |
| 563 "x: $x" ", " |
| 564 "y: $y" ", " |
| 565 "width: $width" ", " |
| 566 "height: $height" ", " |
| 567 "topLeftRadiusX: $topLeftRadiusX" ", " |
| 568 "topLeftRadiusY: $topLeftRadiusY" ", " |
| 569 "topRightRadiusX: $topRightRadiusX" ", " |
| 570 "topRightRadiusY: $topRightRadiusY" ", " |
| 571 "bottomLeftRadiusX: $bottomLeftRadiusX" ", " |
| 572 "bottomLeftRadiusY: $bottomLeftRadiusY" ", " |
| 573 "bottomRightRadiusX: $bottomRightRadiusX" ", " |
| 574 "bottomRightRadiusY: $bottomRightRadiusY" ")"; |
| 575 } |
| 576 |
| 577 Map toJson() { |
| 578 Map map = new Map(); |
| 579 map["x"] = x; |
| 580 map["y"] = y; |
| 581 map["width"] = width; |
| 582 map["height"] = height; |
| 583 map["topLeftRadiusX"] = topLeftRadiusX; |
| 584 map["topLeftRadiusY"] = topLeftRadiusY; |
| 585 map["topRightRadiusX"] = topRightRadiusX; |
| 586 map["topRightRadiusY"] = topRightRadiusY; |
| 587 map["bottomLeftRadiusX"] = bottomLeftRadiusX; |
| 588 map["bottomLeftRadiusY"] = bottomLeftRadiusY; |
| 589 map["bottomRightRadiusX"] = bottomRightRadiusX; |
| 590 map["bottomRightRadiusY"] = bottomRightRadiusY; |
| 591 return map; |
| 592 } |
| 593 } |
| 594 |
| 595 |
430 class Transform extends bindings.Struct { | 596 class Transform extends bindings.Struct { |
431 static const List<bindings.StructDataHeader> kVersions = const [ | 597 static const List<bindings.StructDataHeader> kVersions = const [ |
432 const bindings.StructDataHeader(16, 0) | 598 const bindings.StructDataHeader(16, 0) |
433 ]; | 599 ]; |
434 List<double> matrix = null; | 600 List<double> matrix = null; |
435 | 601 |
436 Transform() : super(kVersions.last.size); | 602 Transform() : super(kVersions.last.size); |
437 | 603 |
438 static Transform deserialize(bindings.Message message) { | 604 static Transform deserialize(bindings.Message message) { |
439 var decoder = new bindings.Decoder(message); | 605 var decoder = new bindings.Decoder(message); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 } | 653 } |
488 | 654 |
489 Map toJson() { | 655 Map toJson() { |
490 Map map = new Map(); | 656 Map map = new Map(); |
491 map["matrix"] = matrix; | 657 map["matrix"] = matrix; |
492 return map; | 658 return map; |
493 } | 659 } |
494 } | 660 } |
495 | 661 |
496 | 662 |
OLD | NEW |