Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_gl.cc

Issue 2807293002: VR: Rename ContentRectangle to UiElement (Closed)
Patch Set: Rebase onto Michael's landed GVR types CL. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h"
6 6
7 #include <chrono> 7 #include <chrono>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" 16 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h"
17 #include "chrome/browser/android/vr_shell/ui_elements.h" 17 #include "chrome/browser/android/vr_shell/ui_element.h"
18 #include "chrome/browser/android/vr_shell/ui_interface.h" 18 #include "chrome/browser/android/vr_shell/ui_interface.h"
19 #include "chrome/browser/android/vr_shell/ui_scene.h" 19 #include "chrome/browser/android/vr_shell/ui_scene.h"
20 #include "chrome/browser/android/vr_shell/vr_controller.h" 20 #include "chrome/browser/android/vr_shell/vr_controller.h"
21 #include "chrome/browser/android/vr_shell/vr_gl_util.h" 21 #include "chrome/browser/android/vr_shell/vr_gl_util.h"
22 #include "chrome/browser/android/vr_shell/vr_shell.h" 22 #include "chrome/browser/android/vr_shell/vr_shell.h"
23 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 23 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
24 #include "device/vr/android/gvr/gvr_delegate.h" 24 #include "device/vr/android/gvr/gvr_delegate.h"
25 #include "device/vr/android/gvr/gvr_device.h" 25 #include "device/vr/android/gvr/gvr_device.h"
26 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" 26 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h"
27 #include "device/vr/vr_math.h" 27 #include "device/vr/vr_math.h"
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 // Non-WebVR mode, enable depth testing and clear the primary buffers. 892 // Non-WebVR mode, enable depth testing and clear the primary buffers.
893 glEnable(GL_CULL_FACE); 893 glEnable(GL_CULL_FACE);
894 glEnable(GL_DEPTH_TEST); 894 glEnable(GL_DEPTH_TEST);
895 glDepthMask(GL_TRUE); 895 glDepthMask(GL_TRUE);
896 896
897 const vr::Colorf& backgroundColor = scene_->GetBackgroundColor(); 897 const vr::Colorf& backgroundColor = scene_->GetBackgroundColor();
898 glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, 898 glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b,
899 backgroundColor.a); 899 backgroundColor.a);
900 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 900 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
901 } 901 }
902 std::vector<const ContentRectangle*> elements = scene_->GetWorldElements(); 902 std::vector<const UiElement*> elements = scene_->GetWorldElements();
903 DrawUiView(head_pose, elements, render_size_primary_, 903 DrawUiView(head_pose, elements, render_size_primary_,
904 kViewportListPrimaryOffset, !ShouldDrawWebVr()); 904 kViewportListPrimaryOffset, !ShouldDrawWebVr());
905 } 905 }
906 906
907 void VrShellGl::DrawHeadLockedElements() { 907 void VrShellGl::DrawHeadLockedElements() {
908 TRACE_EVENT0("gpu", "VrShellGl::DrawHeadLockedElements"); 908 TRACE_EVENT0("gpu", "VrShellGl::DrawHeadLockedElements");
909 std::vector<const ContentRectangle*> elements = 909 std::vector<const UiElement*> elements = scene_->GetHeadLockedElements();
910 scene_->GetHeadLockedElements();
911 910
912 // Add head-locked viewports. The list gets reset to just 911 // Add head-locked viewports. The list gets reset to just
913 // the recommended viewports (for the primary buffer) each frame. 912 // the recommended viewports (for the primary buffer) each frame.
914 buffer_viewport_list_->SetBufferViewport( 913 buffer_viewport_list_->SetBufferViewport(
915 kViewportListHeadlockedOffset + GVR_LEFT_EYE, *headlocked_left_viewport_); 914 kViewportListHeadlockedOffset + GVR_LEFT_EYE, *headlocked_left_viewport_);
916 buffer_viewport_list_->SetBufferViewport( 915 buffer_viewport_list_->SetBufferViewport(
917 kViewportListHeadlockedOffset + GVR_RIGHT_EYE, 916 kViewportListHeadlockedOffset + GVR_RIGHT_EYE,
918 *headlocked_right_viewport_); 917 *headlocked_right_viewport_);
919 918
920 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 919 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
921 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 920 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
922 vr::Mat4f identity_matrix; 921 vr::Mat4f identity_matrix;
923 vr::SetIdentityM(&identity_matrix); 922 vr::SetIdentityM(&identity_matrix);
924 DrawUiView(identity_matrix, elements, render_size_headlocked_, 923 DrawUiView(identity_matrix, elements, render_size_headlocked_,
925 kViewportListHeadlockedOffset, false); 924 kViewportListHeadlockedOffset, false);
926 } 925 }
927 926
928 void VrShellGl::DrawUiView(const vr::Mat4f& head_pose, 927 void VrShellGl::DrawUiView(const vr::Mat4f& head_pose,
929 const std::vector<const ContentRectangle*>& elements, 928 const std::vector<const UiElement*>& elements,
930 const gfx::Size& render_size, 929 const gfx::Size& render_size,
931 int viewport_offset, 930 int viewport_offset,
932 bool draw_cursor) { 931 bool draw_cursor) {
933 TRACE_EVENT0("gpu", "VrShellGl::DrawUiView"); 932 TRACE_EVENT0("gpu", "VrShellGl::DrawUiView");
934 933
935 auto elementsInDrawOrder = GetElementsInDrawOrder(head_pose, elements); 934 auto elementsInDrawOrder = GetElementsInDrawOrder(head_pose, elements);
936 935
937 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { 936 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) {
938 buffer_viewport_list_->GetBufferViewport(eye + viewport_offset, 937 buffer_viewport_list_->GetBufferViewport(eye + viewport_offset,
939 buffer_viewport_.get()); 938 buffer_viewport_.get());
(...skipping 19 matching lines...) Expand all
959 vr::MatrixMul(perspective_matrix, eye_view_matrix, &render_matrix); 958 vr::MatrixMul(perspective_matrix, eye_view_matrix, &render_matrix);
960 959
961 DrawElements(render_matrix, elementsInDrawOrder); 960 DrawElements(render_matrix, elementsInDrawOrder);
962 if (draw_cursor) { 961 if (draw_cursor) {
963 DrawCursor(render_matrix); 962 DrawCursor(render_matrix);
964 DrawController(render_matrix); 963 DrawController(render_matrix);
965 } 964 }
966 } 965 }
967 } 966 }
968 967
969 void VrShellGl::DrawElements( 968 void VrShellGl::DrawElements(const vr::Mat4f& view_proj_matrix,
970 const vr::Mat4f& view_proj_matrix, 969 const std::vector<const UiElement*>& elements) {
971 const std::vector<const ContentRectangle*>& elements) {
972 for (const auto* rect : elements) { 970 for (const auto* rect : elements) {
973 vr::Mat4f transform; 971 vr::Mat4f transform;
974 vr::MatrixMul(view_proj_matrix, rect->TransformMatrix(), &transform); 972 vr::MatrixMul(view_proj_matrix, rect->TransformMatrix(), &transform);
975 973
976 switch (rect->fill) { 974 switch (rect->fill) {
977 case Fill::SPRITE: { 975 case Fill::SPRITE: {
978 gfx::RectF copy_rect( 976 gfx::RectF copy_rect(
979 static_cast<float>(rect->copy_rect.x()) / ui_tex_css_width_, 977 static_cast<float>(rect->copy_rect.x()) / ui_tex_css_width_,
980 static_cast<float>(rect->copy_rect.y()) / ui_tex_css_height_, 978 static_cast<float>(rect->copy_rect.y()) / ui_tex_css_height_,
981 static_cast<float>(rect->copy_rect.width()) / ui_tex_css_width_, 979 static_cast<float>(rect->copy_rect.width()) / ui_tex_css_width_,
(...skipping 25 matching lines...) Expand all
1007 break; 1005 break;
1008 } 1006 }
1009 default: 1007 default:
1010 break; 1008 break;
1011 } 1009 }
1012 } 1010 }
1013 1011
1014 vr_shell_renderer_->GetTexturedQuadRenderer()->Flush(); 1012 vr_shell_renderer_->GetTexturedQuadRenderer()->Flush();
1015 } 1013 }
1016 1014
1017 std::vector<const ContentRectangle*> VrShellGl::GetElementsInDrawOrder( 1015 std::vector<const UiElement*> VrShellGl::GetElementsInDrawOrder(
1018 const vr::Mat4f& view_matrix, 1016 const vr::Mat4f& view_matrix,
1019 const std::vector<const ContentRectangle*>& elements) { 1017 const std::vector<const UiElement*>& elements) {
1020 typedef std::pair<float, const ContentRectangle*> DistanceElementPair; 1018 typedef std::pair<float, const UiElement*> DistanceElementPair;
1021 std::vector<DistanceElementPair> zOrderedElementPairs; 1019 std::vector<DistanceElementPair> zOrderedElementPairs;
1022 zOrderedElementPairs.reserve(elements.size()); 1020 zOrderedElementPairs.reserve(elements.size());
1023 1021
1024 for (const auto* element : elements) { 1022 for (const auto* element : elements) {
1025 // Distance is the abs(z) value in view space. 1023 // Distance is the abs(z) value in view space.
1026 gfx::Vector3dF element_position = 1024 gfx::Vector3dF element_position =
1027 vr::GetTranslation(element->TransformMatrix()); 1025 vr::GetTranslation(element->TransformMatrix());
1028 1026
1029 float distance = 1027 float distance =
1030 std::fabs(vr::MatrixVectorMul(view_matrix, element_position).z()); 1028 std::fabs(vr::MatrixVectorMul(view_matrix, element_position).z());
1031 zOrderedElementPairs.push_back(std::make_pair(distance, element)); 1029 zOrderedElementPairs.push_back(std::make_pair(distance, element));
1032 } 1030 }
1033 1031
1034 // Sort elements primarily based on their draw phase (lower draw phase first) 1032 // Sort elements primarily based on their draw phase (lower draw phase first)
1035 // and secondarily based on their distance (larger distance first). 1033 // and secondarily based on their distance (larger distance first).
1036 std::sort( 1034 std::sort(
1037 zOrderedElementPairs.begin(), zOrderedElementPairs.end(), 1035 zOrderedElementPairs.begin(), zOrderedElementPairs.end(),
1038 [](const DistanceElementPair& first, const DistanceElementPair& second) { 1036 [](const DistanceElementPair& first, const DistanceElementPair& second) {
1039 if (first.second->draw_phase != second.second->draw_phase) { 1037 if (first.second->draw_phase != second.second->draw_phase) {
1040 return first.second->draw_phase < second.second->draw_phase; 1038 return first.second->draw_phase < second.second->draw_phase;
1041 } else { 1039 } else {
1042 return first.first > second.first; 1040 return first.first > second.first;
1043 } 1041 }
1044 }); 1042 });
1045 1043
1046 std::vector<const ContentRectangle*> zOrderedElements; 1044 std::vector<const UiElement*> zOrderedElements;
1047 zOrderedElements.reserve(elements.size()); 1045 zOrderedElements.reserve(elements.size());
1048 for (auto distanceElementPair : zOrderedElementPairs) { 1046 for (auto distanceElementPair : zOrderedElementPairs) {
1049 zOrderedElements.push_back(distanceElementPair.second); 1047 zOrderedElements.push_back(distanceElementPair.second);
1050 } 1048 }
1051 return zOrderedElements; 1049 return zOrderedElements;
1052 } 1050 }
1053 1051
1054 void VrShellGl::DrawCursor(const vr::Mat4f& render_matrix) { 1052 void VrShellGl::DrawCursor(const vr::Mat4f& render_matrix) {
1055 vr::Mat4f mat; 1053 vr::Mat4f mat;
1056 vr::SetIdentityM(&mat); 1054 vr::SetIdentityM(&mat);
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 // InitializeGl. Revisit if the initialization order changes. 1332 // InitializeGl. Revisit if the initialization order changes.
1335 device::mojom::VRDisplayInfoPtr info = 1333 device::mojom::VRDisplayInfoPtr info =
1336 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), 1334 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(),
1337 webvr_surface_size_, device_id); 1335 webvr_surface_size_, device_id);
1338 main_thread_task_runner_->PostTask( 1336 main_thread_task_runner_->PostTask(
1339 FROM_HERE, 1337 FROM_HERE,
1340 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); 1338 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1341 } 1339 }
1342 1340
1343 } // namespace vr_shell 1341 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698