-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
xr_webgl_layer.h
121 lines (91 loc) · 4.4 KB
/
xr_webgl_layer.h
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
// 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_MODULES_XR_XR_WEBGL_LAYER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_WEBGL_LAYER_H_
#include "device/vr/public/mojom/vr_service.mojom-blink.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_typedefs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_xr_webgl_layer_init.h"
#include "third_party/blink/renderer/modules/webgl/webgl2_rendering_context.h"
#include "third_party/blink/renderer/modules/webgl/webgl_rendering_context.h"
#include "third_party/blink/renderer/modules/webgl/webgl_unowned_texture.h"
#include "third_party/blink/renderer/modules/xr/xr_layer.h"
#include "third_party/blink/renderer/modules/xr/xr_utils.h"
#include "third_party/blink/renderer/modules/xr/xr_view.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/graphics/gpu/xr_webgl_drawing_buffer.h"
#include "third_party/blink/renderer/platform/wtf/ref_counted.h"
namespace blink {
class ExceptionState;
class HTMLCanvasElement;
class WebGLFramebuffer;
class WebGLRenderingContextBase;
class XRSession;
class XRViewport;
class XRWebGLLayer final : public XRLayer {
DEFINE_WRAPPERTYPEINFO();
public:
XRWebGLLayer(XRSession*,
WebGLRenderingContextBase*,
scoped_refptr<XRWebGLDrawingBuffer>,
WebGLFramebuffer*,
double framebuffer_scale,
bool ignore_depth_values);
~XRWebGLLayer() override;
static XRWebGLLayer* Create(XRSession*,
const V8XRWebGLRenderingContext*,
const XRWebGLLayerInit*,
ExceptionState&);
WebGLRenderingContextBase* context() const { return webgl_context_; }
WebGLFramebuffer* framebuffer() const { return framebuffer_; }
uint32_t framebufferWidth() const;
uint32_t framebufferHeight() const;
bool antialias() const;
bool ignoreDepthValues() const { return ignore_depth_values_; }
XRViewport* getViewport(XRView*);
static double getNativeFramebufferScaleFactor(XRSession* session);
XRViewport* GetViewportForEye(device::mojom::blink::XREye);
void UpdateViewports();
HTMLCanvasElement* output_canvas() const;
// Returns WebGLTexture (actually a WebGLUnownedTexture instance)
// corresponding to the camera image.
// The texture is owned by the XRWebGLLayer and will be freed in OnFrameEnd().
// When the texture is deleted by the layer, the returned object will have its
// texture name set to 0 to avoid using stale texture names in case the user
// code still holds references to this object.
// The consumers should not attempt to delete the texture themselves.
WebGLTexture* GetCameraTexture();
void OnFrameStart(
const absl::optional<gpu::MailboxHolder>& buffer_mailbox_holder,
const absl::optional<gpu::MailboxHolder>& camera_image_mailbox_holder);
void OnFrameEnd();
void OnResize();
// Called from XRSession::OnFrame handler. Params are background texture
// mailbox holder and its size respectively.
void HandleBackgroundImage(const gpu::MailboxHolder&, const IntSize&) {}
scoped_refptr<StaticBitmapImage> TransferToStaticBitmapImage();
void Trace(Visitor*) const override;
private:
uint32_t GetBufferTextureId(
const absl::optional<gpu::MailboxHolder>& buffer_mailbox_holder);
void BindCameraBufferTexture(
const absl::optional<gpu::MailboxHolder>& buffer_mailbox_holder);
Member<XRViewport> left_viewport_;
Member<XRViewport> right_viewport_;
Member<WebGLRenderingContextBase> webgl_context_;
scoped_refptr<XRWebGLDrawingBuffer> drawing_buffer_;
Member<WebGLFramebuffer> framebuffer_;
double framebuffer_scale_ = 1.0;
bool viewports_dirty_ = true;
bool is_direct_draw_frame = false;
bool ignore_depth_values_ = false;
uint32_t clean_frame_count = 0;
uint32_t camera_image_texture_id_;
// WebGL texture that points to the |camera_image_texture_|. Must be notified
// via a call to |WebGLUnownedTexture::OnGLDeleteTextures()| when
// |camera_image_texture_id_| is deleted.
Member<WebGLUnownedTexture> camera_image_texture_;
absl::optional<gpu::MailboxHolder> camera_image_mailbox_holder_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_WEBGL_LAYER_H_