File: ui_scene.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; 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 (114 lines) | stat: -rw-r--r-- 3,431 bytes parent folder | download | duplicates (3)
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
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_VR_UI_SCENE_H_
#define CHROME_BROWSER_VR_UI_SCENE_H_

#include <memory>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "chrome/browser/vr/elements/ui_element.h"
#include "chrome/browser/vr/elements/ui_element_name.h"
#include "chrome/browser/vr/vr_ui_export.h"
#include "third_party/skia/include/core/SkColor.h"

namespace base {
class TimeTicks;
}  // namespace base

namespace gfx {
class Transform;
}  // namespace gfx

namespace vr {

class UiElement;

class VR_UI_EXPORT UiScene {
 public:
  typedef base::RepeatingCallback<void()> PerFrameCallback;

  UiScene();

  UiScene(const UiScene&) = delete;
  UiScene& operator=(const UiScene&) = delete;

  ~UiScene();

  void AddUiElement(UiElementName parent, std::unique_ptr<UiElement> element);
  void AddParentUiElement(UiElementName child,
                          std::unique_ptr<UiElement> element);

  std::unique_ptr<UiElement> RemoveUiElement(int element_id);

  // Handles per-frame updates, giving each element the opportunity to update,
  // if necessary (eg, for animations). NB: |current_time| is the shared,
  // absolute begin frame time.
  // Returns true if *anything* was updated.
  bool OnBeginFrame(const base::TimeTicks& current_time,
                    const gfx::Transform& head_pose);

  // Returns true if any visible textures need to be redrawn.
  bool HasDirtyTextures() const;

  void UpdateTextures();

  UiElement& root_element();

  UiElement* GetUiElementById(int element_id) const;
  UiElement* GetUiElementByName(UiElementName name) const;

  typedef std::vector<const UiElement*> Elements;
  typedef std::vector<UiElement*> MutableElements;

  std::vector<raw_ptr<UiElement, VectorExperimental>>& GetAllElements();
  Elements GetElementsToDraw();
  bool HasWebXrOverlayElementsToDraw();
  Elements GetWebVrOverlayElementsToDraw();

  float background_distance() const { return background_distance_; }
  void set_background_distance(float d) { background_distance_ = d; }

  void set_dirty() { is_dirty_ = true; }

  void OnGlInitialized(SkiaSurfaceProvider* provider);

  // The callback to call on every new frame. This is used for things we want to
  // do every frame regardless of element or subtree visibility.
  void AddPerFrameCallback(PerFrameCallback callback);

  SkiaSurfaceProvider* SurfaceProviderForTesting() { return provider_; }

  void RunFirstFrameForTest();

 private:
  void InitializeElement(UiElement* element);

  MutableElements GetVisibleElementsMutable();

  std::unique_ptr<UiElement> root_element_;

  float background_distance_ = 10.0f;
  bool gl_initialized_ = false;
  bool initialized_scene_ = false;

  // TODO(mthiesse): Convert everything that manipulates UI elements to bindings
  // or layout updates. Don't allow any code to go in and manipulate UI elements
  // outside of these phases so that we can more easily compute dirtiness.
  bool is_dirty_ = false;

  // This is used to advance animations to completion on the first frame.
  bool first_frame_ = true;

  std::vector<raw_ptr<UiElement, VectorExperimental>> all_elements_;

  std::vector<PerFrameCallback> per_frame_callback_;

  raw_ptr<SkiaSurfaceProvider, DanglingUntriaged> provider_ = nullptr;
};

}  // namespace vr

#endif  // CHROME_BROWSER_VR_UI_SCENE_H_