/tools/winscope/src/flickerlib/windows/WindowState.ts

https://github.com/android/platform_development · TypeScript · 127 lines · 102 code · 10 blank · 15 comment · 57 complexity · 86027e965883a7c4a4abbc010f04bddf MD5 · raw file

  1. /*
  2. * Copyright 2020, The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { getPropertiesForDisplay, shortenName } from '../mixin'
  17. import { asRawTreeViewObject } from '../../utils/diff.js'
  18. import { toRect, Bounds, WindowState, WindowLayoutParams } from "../common"
  19. import { VISIBLE_CHIP } from '../treeview/Chips'
  20. import WindowContainer from "./WindowContainer"
  21. WindowState.fromProto = function (proto, isActivityInTree: Boolean): WindowState {
  22. if (proto == null) {
  23. return null
  24. } else {
  25. const identifierName = proto.windowContainer.identifier?.title ?? proto.identifier?.title ?? ""
  26. var windowType = 0
  27. if (identifierName.startsWith(WindowState.STARTING_WINDOW_PREFIX)) {
  28. windowType = WindowState.WINDOW_TYPE_STARTING
  29. } else if (proto.animatingExit) {
  30. windowType = WindowState.WINDOW_TYPE_EXITING
  31. } else if (identifierName.startsWith(WindowState.DEBUGGER_WINDOW_PREFIX)) {
  32. windowType = WindowState.WINDOW_TYPE_STARTING
  33. }
  34. var nameOverride = identifierName
  35. if (identifierName.startsWith(WindowState.STARTING_WINDOW_PREFIX)) {
  36. nameOverride = identifierName.substring(WindowState.STARTING_WINDOW_PREFIX.length)
  37. } else if (identifierName.startsWith(WindowState.DEBUGGER_WINDOW_PREFIX)) {
  38. nameOverride = identifierName.substring(WindowState.DEBUGGER_WINDOW_PREFIX.length)
  39. }
  40. const children = proto.windowContainer.children.reverse()
  41. .filter(it => it != null)
  42. .map(it => WindowContainer.childrenFromProto(it, isActivityInTree))
  43. const windowContainer = WindowContainer.fromProto({
  44. proto: proto.windowContainer,
  45. children: children,
  46. nameOverride: nameOverride,
  47. identifierOverride: proto.identifier})
  48. if (windowContainer == null) {
  49. throw "Window container should not be null: " + JSON.stringify(proto)
  50. }
  51. const entry = new WindowState(
  52. newWindowLayoutParams(proto.attributes),
  53. proto.displayId,
  54. proto.stackId,
  55. proto.animator?.surface?.layer ?? 0,
  56. proto.animator?.surface?.shown ?? false,
  57. windowType,
  58. new Bounds(proto.requestedWidth, proto.requestedHeight),
  59. toRect(proto.surfacePosition),
  60. toRect(proto.windowFrames?.frame ?? null),
  61. toRect(proto.windowFrames?.containingFrame ?? null),
  62. toRect(proto.windowFrames?.parentFrame ?? null),
  63. toRect(proto.windowFrames?.contentFrame ?? null),
  64. toRect(proto.windowFrames?.contentInsets ?? null),
  65. toRect(proto.surfaceInsets),
  66. toRect(proto.givenContentInsets),
  67. toRect(proto.animator?.lastClipRect ?? null),
  68. windowContainer,
  69. /* isAppWindow */ isActivityInTree
  70. )
  71. entry.kind = entry.constructor.name
  72. entry.rect = entry.frame
  73. entry.rect.ref = entry
  74. entry.rect.label = entry.name
  75. entry.obj = getPropertiesForDisplay(proto, entry)
  76. entry.shortName = shortenName(entry.name)
  77. entry.visible = entry.isVisible ?? false
  78. entry.chips = entry.isVisible ? [VISIBLE_CHIP] : []
  79. entry.rawTreeViewObject = asRawTreeViewObject(entry)
  80. return entry
  81. }
  82. }
  83. function newWindowLayoutParams(proto): WindowLayoutParams {
  84. return new WindowLayoutParams(
  85. /* type */ proto?.type ?? 0,
  86. /* x */ proto?.x ?? 0,
  87. /* y */ proto?.y ?? 0,
  88. /* width */ proto?.width ?? 0,
  89. /* height */ proto?.height ?? 0,
  90. /* horizontalMargin */ proto?.horizontalMargin ?? 0,
  91. /* verticalMargin */ proto?.verticalMargin ?? 0,
  92. /* gravity */ proto?.gravity ?? 0,
  93. /* softInputMode */ proto?.softInputMode ?? 0,
  94. /* format */ proto?.format ?? 0,
  95. /* windowAnimations */ proto?.windowAnimations ?? 0,
  96. /* alpha */ proto?.alpha ?? 0,
  97. /* screenBrightness */ proto?.screenBrightness ?? 0,
  98. /* buttonBrightness */ proto?.buttonBrightness ?? 0,
  99. /* rotationAnimation */ proto?.rotationAnimation ?? 0,
  100. /* preferredRefreshRate */ proto?.preferredRefreshRate ?? 0,
  101. /* preferredDisplayModeId */ proto?.preferredDisplayModeId ?? 0,
  102. /* hasSystemUiListeners */ proto?.hasSystemUiListeners ?? false,
  103. /* inputFeatureFlags */ proto?.inputFeatureFlags ?? 0,
  104. /* userActivityTimeout */ proto?.userActivityTimeout ?? 0,
  105. /* colorMode */ proto?.colorMode ?? 0,
  106. /* flags */ proto?.flags ?? 0,
  107. /* privateFlags */ proto?.privateFlags ?? 0,
  108. /* systemUiVisibilityFlags */ proto?.systemUiVisibilityFlags ?? 0,
  109. /* subtreeSystemUiVisibilityFlags */ proto?.subtreeSystemUiVisibilityFlags ?? 0,
  110. /* appearance */ proto?.appearance ?? 0,
  111. /* behavior */ proto?.behavior ?? 0,
  112. /* fitInsetsTypes */ proto?.fitInsetsTypes ?? 0,
  113. /* fitInsetsSides */ proto?.fitInsetsSides ?? 0,
  114. /* fitIgnoreVisibility */ proto?.fitIgnoreVisibility ?? false
  115. )
  116. }
  117. export default WindowState