summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/graphics/gpu/xr_frame_transport.h
blob: f416c8821d41e9ffc2f1bd70d3581a2098b20ad6 (plain)
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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_GPU_XR_FRAME_TRANSPORT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_GPU_XR_FRAME_TRANSPORT_H_

#include "device/vr/public/mojom/vr_service.mojom-blink.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "third_party/blink/public/platform/web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/platform/graphics/gpu/drawing_buffer.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/time.h"

namespace gfx {
class GpuFence;
}

namespace gpu {
namespace gles2 {
class GLES2Interface;
}
}  // namespace gpu

namespace blink {

class GpuMemoryBufferImageCopy;
class Image;

class PLATFORM_EXPORT XRFrameTransport final
    : public GarbageCollectedFinalized<XRFrameTransport>,
      public device::mojom::blink::VRSubmitFrameClient {
 public:
  explicit XRFrameTransport();
  ~XRFrameTransport();

  device::mojom::blink::VRSubmitFrameClientPtr GetSubmitFrameClient();

  void PresentChange();

  void SetTransportOptions(
      device::mojom::blink::VRDisplayFrameTransportOptionsPtr);

  bool DrawingIntoSharedBuffer();

  // Call before finalizing the frame's image snapshot.
  void FramePreImage(gpu::gles2::GLES2Interface*);

  void FrameSubmit(device::mojom::blink::VRPresentationProvider*,
                   gpu::gles2::GLES2Interface*,
                   DrawingBuffer::Client*,
                   scoped_refptr<Image> image_ref,
                   std::unique_ptr<viz::SingleReleaseCallback>,
                   int16_t vr_frame_id,
                   bool needs_copy);

  void FrameSubmitMissing(device::mojom::blink::VRPresentationProvider*,
                          gpu::gles2::GLES2Interface*,
                          int16_t vr_frame_id);

  virtual void Trace(blink::Visitor*);

 private:
  void WaitForPreviousTransfer();
  WTF::TimeDelta WaitForPreviousRenderToFinish();
  WTF::TimeDelta WaitForGpuFenceReceived();
  void CallPreviousFrameCallback();

  // VRSubmitFrameClient
  void OnSubmitFrameTransferred(bool success) override;
  void OnSubmitFrameRendered() override;
  void OnSubmitFrameGpuFence(const gfx::GpuFenceHandle&) override;

  mojo::Binding<device::mojom::blink::VRSubmitFrameClient>
      submit_frame_client_binding_;

  // Used to keep the image alive until the next frame if using
  // waitForPreviousTransferToFinish.
  scoped_refptr<Image> previous_image_;
  std::unique_ptr<viz::SingleReleaseCallback> previous_image_release_callback_;

  bool waiting_for_previous_frame_transfer_ = false;
  bool last_transfer_succeeded_ = false;
  WTF::TimeDelta frame_wait_time_;
  bool waiting_for_previous_frame_render_ = false;
  // If using GpuFence to separate frames, need to wait for the previous
  // frame's fence, but not if this is the first frame. Separately track
  // if we're expecting a fence and the received fence itself.
  bool waiting_for_previous_frame_fence_ = false;
  std::unique_ptr<gfx::GpuFence> previous_frame_fence_;

  device::mojom::blink::VRDisplayFrameTransportOptionsPtr transport_options_;

  std::unique_ptr<GpuMemoryBufferImageCopy> frame_copier_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_GPU_XR_FRAME_TRANSPORT_H_