blob: 0688c944d8a3c19578f92287f5fd499431a1b62a [file] [log] [blame]
Alex Vakulenkoe4eec202017-01-27 14:41:04 -08001#ifndef VR_WINDOW_MANAGER_SHELL_VIEW_H_
2#define VR_WINDOW_MANAGER_SHELL_VIEW_H_
3
4#include <private/dvr/graphics/mesh.h>
5#include <private/dvr/graphics/shader_program.h>
6#include <android/dvr/IVirtualTouchpadService.h>
7
8#include <deque>
9
10#include "application.h"
11#include "reticle.h"
12#include "surface_flinger_view.h"
13
14namespace android {
15namespace dvr {
16
17class ShellView : public Application, public HwcCallback::Client {
18 public:
19 ShellView();
20 virtual ~ShellView();
21
22 int Initialize(JNIEnv* env, jobject app_context,
23 jobject class_loader) override;
24
25 int AllocateResources() override;
26 void DeallocateResources() override;
27
28 void EnableDebug(bool debug);
29 void VrMode(bool mode);
30
31 protected:
32 void DrawEye(EyeType eye, const mat4& perspective, const mat4& eye_matrix,
33 const mat4& head_matrix) override;
34 void OnVisibilityChanged(bool visible) override;
35
36 void DrawOverlays(const mat4& perspective, const mat4& eye_matrix,
37 const mat4& head_matrix);
38 void DrawReticle(const mat4& perspective, const mat4& eye_matrix,
39 const mat4& head_matrix);
40 void DrawIme();
41 void DrawDimOverlay(const mat4& mvp, const TextureLayer& layer,
42 const vec2& top_left, const vec2& bottom_right);
43 void DrawController(const mat4& perspective, const mat4& eye_matrix,
44 const mat4& head_matrix);
45
46 bool IsHit(const vec3& view_location, const vec3& view_direction,
47 vec3* hit_location, vec2* hit_location_in_window_coord,
48 bool test_ime);
49 bool IsImeHit(const vec3& view_location, const vec3& view_direction,
50 vec3 *hit_location);
51 bool InitializeTouch();
52 void Touch();
53
54 void OnDrawFrame() override;
55 void DrawWithTransform(const mat4& transform, const ShaderProgram& program);
56
57 bool OnClick(bool down);
58
59 // HwcCallback::Client:
60 void OnFrame(std::unique_ptr<HwcCallback::Frame> frame) override;
61
62 std::unique_ptr<ShaderProgram> program_;
63 std::unique_ptr<ShaderProgram> overlay_program_;
64 std::unique_ptr<ShaderProgram> controller_program_;
65
66 uint32_t current_vr_app_;
67
68 // Used to center the scene when the shell becomes visible.
69 bool should_recenter_ = true;
70 mat4 initial_head_matrix_;
71 mat4 scale_;
72 mat4 translate_;
73 mat4 ime_translate_;
74 vec2 size_;
75
76 std::unique_ptr<SurfaceFlingerView> surface_flinger_view_;
77 std::unique_ptr<Reticle> reticle_;
78 sp<IVirtualTouchpadService> virtual_touchpad_;
79 std::vector<TextureLayer> textures_;
80 TextureLayer ime_texture_;
81
82 bool is_touching_ = false;
83 bool allow_input_ = false;
84 vec2 hit_location_in_window_coord_;
85 vec2 ime_top_left_;
86 vec2 ime_size_;
87 bool has_ime_ = false;
88
89 std::unique_ptr<Mesh<vec3, vec3, vec2>> controller_mesh_;
90
91 struct PendingFrame {
92 PendingFrame() = default;
93 PendingFrame(std::unique_ptr<HwcCallback::Frame>&& frame, bool visibility)
94 : frame(std::move(frame)), visibility(visibility) {}
95 PendingFrame(PendingFrame&& r)
96 : frame(std::move(r.frame)), visibility(r.visibility) {}
97
98 void operator=(PendingFrame&& r) {
99 frame.reset(r.frame.release());
100 visibility = r.visibility;
101 }
102
103 std::unique_ptr<HwcCallback::Frame> frame;
104 bool visibility = false;
105 };
106 std::deque<PendingFrame> pending_frames_;
107 std::mutex pending_frame_mutex_;
108 PendingFrame current_frame_;
109
110 mat4 controller_translate_;
111
112 ShellView(const ShellView&) = delete;
113 void operator=(const ShellView&) = delete;
114};
115
116} // namespace dvr
117} // namespace android
118
119#endif // VR_WINDOW_MANAGER_SHELL_VIEW_H_