File: vr_browser_renderer_thread.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, 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 (122 lines) | stat: -rw-r--r-- 4,131 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
115
116
117
118
119
120
121
122
// Copyright 2018 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_VR_BROWSER_RENDERER_THREAD_H_
#define CHROME_BROWSER_VR_VR_BROWSER_RENDERER_THREAD_H_

#include <memory>

#include "base/cancelable_callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "chrome/browser/vr/browser_renderer.h"
#include "chrome/browser/vr/model/capturing_state_model.h"
#include "chrome/browser/vr/model/web_vr_model.h"
#include "chrome/browser/vr/vr_export.h"
#include "content/public/browser/web_contents.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
#include "device/vr/public/mojom/vr_service.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"

namespace vr {

class BrowserUiInterface;
class SchedulerUiInterface;
class GraphicsDelegate;

class VR_EXPORT VRBrowserRendererThread {
 public:
  VRBrowserRendererThread(
      mojo::PendingRemote<device::mojom::ImmersiveOverlay> overlay,
      const std::vector<device::mojom::XRViewPtr>& views);
  ~VRBrowserRendererThread();

  void SetFramesThrottled(bool throttled);

  // The below function(s) affect(s) whether UI is drawn or not.
  void SetVisibleExternalPromptNotification(
      ExternalPromptNotificationType prompt);
  void SetIndicatorsVisible(bool visible);
  void SetCapturingState(const CapturingStateModel& active_capturing,
                         const CapturingStateModel& background_capturing,
                         const CapturingStateModel& potential_capturing);

  static VRBrowserRendererThread* GetInstanceForTesting();
  BrowserRenderer* GetBrowserRendererForTesting();
  static void DisableOverlayForTesting();

 private:
  class DrawState {
   public:
    // State changing methods.
    bool SetPrompt(ExternalPromptNotificationType prompt);
    bool SetSpinnerVisible(bool visible);
    bool SetIndicatorsVisible(bool visible);

    // State querying methods.
    bool ShouldDrawUI();
    bool ShouldDrawWebXR();

   private:
    ExternalPromptNotificationType prompt_ =
        ExternalPromptNotificationType::kPromptNone;

    bool spinner_visible_ = false;
    bool indicators_visible_ = false;
  };

  void OnGraphicsReady(std::unique_ptr<GraphicsDelegate> initializing_graphics);
  void OnPose(int request_id, device::mojom::XRRenderInfoPtr data);
  bool PreRender();
  void SubmitResult(bool success);
  void SubmitFrame(int16_t frame_id);
  void StartOverlay();
  void StopOverlay();
  void OnWebXRSubmitted();
  void OnSpinnerVisibilityChanged(bool visible);
  void OnWebXrTimeoutImminent();
  void OnWebXrTimedOut();
  void StartWebXrTimeout();
  void StopWebXrTimeout();
  int GetNextRequestId();

  void UpdateOverlayState();

  std::unique_ptr<BrowserRenderer> browser_renderer_;

  // Raw pointers to objects owned by browser_renderer_:
  raw_ptr<GraphicsDelegate, DanglingUntriaged> graphics_ = nullptr;
  raw_ptr<BrowserUiInterface, DanglingUntriaged> ui_ = nullptr;
  raw_ptr<SchedulerUiInterface, DanglingUntriaged> scheduler_ui_ = nullptr;

  DrawState draw_state_;
  bool started_ = false;
  bool frame_timeout_running_ = true;
  bool waiting_for_webxr_frame_ = false;
  bool frames_throttled_ = false;
  int current_request_id_ = 0;
  std::vector<device::mojom::XRViewPtr> default_views_;

  mojo::Remote<device::mojom::ImmersiveOverlay> overlay_;

  base::CancelableOnceClosure webxr_frame_timeout_closure_;
  base::CancelableOnceClosure webxr_spinner_timeout_closure_;

  base::OnceClosure pending_overlay_update_;

  // This class is effectively a singleton, although it's not actually
  // implemented as one. Since tests need to access the thread to post tasks,
  // just keep a static reference to the existing instance.
  static VRBrowserRendererThread* instance_for_testing_;

  scoped_refptr<base::SingleThreadTaskRunner> task_runner_;

  base::WeakPtrFactory<VRBrowserRendererThread> weak_ptr_factory_{this};
};

}  // namespace vr

#endif  // CHROME_BROWSER_VR_VR_BROWSER_RENDERER_THREAD_H_