| OLD | NEW |
| 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/fps_meter.h" | 16 #include "chrome/browser/android/vr_shell/fps_meter.h" |
| 17 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" | 17 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" |
| 18 #include "chrome/browser/android/vr_shell/ui_element.h" | 18 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
| 19 #include "chrome/browser/android/vr_shell/ui_interface.h" | 19 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 20 #include "chrome/browser/android/vr_shell/ui_scene.h" | 20 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 21 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" | 21 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" |
| 22 #include "chrome/browser/android/vr_shell/vr_controller.h" | 22 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 23 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 23 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
| 24 #include "chrome/browser/android/vr_shell/vr_shell.h" | 24 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 25 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 25 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 26 #include "device/vr/android/gvr/gvr_delegate.h" | 26 #include "device/vr/android/gvr/gvr_delegate.h" |
| 27 #include "device/vr/android/gvr/gvr_device.h" | 27 #include "device/vr/android/gvr/gvr_device.h" |
| 28 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" | 28 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 CreateContentSurface(); | 287 CreateContentSurface(); |
| 288 content_surface_texture_->SetFrameAvailableCallback(base::Bind( | 288 content_surface_texture_->SetFrameAvailableCallback(base::Bind( |
| 289 &VrShellGl::OnContentFrameAvailable, weak_ptr_factory_.GetWeakPtr())); | 289 &VrShellGl::OnContentFrameAvailable, weak_ptr_factory_.GetWeakPtr())); |
| 290 webvr_surface_texture_->SetFrameAvailableCallback(base::Bind( | 290 webvr_surface_texture_->SetFrameAvailableCallback(base::Bind( |
| 291 &VrShellGl::OnWebVRFrameAvailable, weak_ptr_factory_.GetWeakPtr())); | 291 &VrShellGl::OnWebVRFrameAvailable, weak_ptr_factory_.GetWeakPtr())); |
| 292 content_surface_texture_->SetDefaultBufferSize( | 292 content_surface_texture_->SetDefaultBufferSize( |
| 293 content_tex_physical_size_.width(), content_tex_physical_size_.height()); | 293 content_tex_physical_size_.width(), content_tex_physical_size_.height()); |
| 294 | 294 |
| 295 InitializeRenderer(); | 295 InitializeRenderer(); |
| 296 | 296 |
| 297 scene_->OnGLInitialized(); |
| 298 |
| 297 gfx::Size webvr_size = | 299 gfx::Size webvr_size = |
| 298 device::GvrDelegate::GetRecommendedWebVrSize(gvr_api_.get()); | 300 device::GvrDelegate::GetRecommendedWebVrSize(gvr_api_.get()); |
| 299 DVLOG(1) << __FUNCTION__ << ": resize initial to " << webvr_size.width() | 301 DVLOG(1) << __FUNCTION__ << ": resize initial to " << webvr_size.width() |
| 300 << "x" << webvr_size.height(); | 302 << "x" << webvr_size.height(); |
| 301 | 303 |
| 302 CreateOrResizeWebVRSurface(webvr_size); | 304 CreateOrResizeWebVRSurface(webvr_size); |
| 303 | 305 |
| 304 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); | 306 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); |
| 305 OnVSync(); | 307 OnVSync(); |
| 306 | 308 |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 } | 989 } |
| 988 } | 990 } |
| 989 | 991 |
| 990 void VrShellGl::DrawElements(const vr::Mat4f& view_proj_matrix, | 992 void VrShellGl::DrawElements(const vr::Mat4f& view_proj_matrix, |
| 991 const std::vector<const UiElement*>& elements) { | 993 const std::vector<const UiElement*>& elements) { |
| 992 for (const auto* rect : elements) { | 994 for (const auto* rect : elements) { |
| 993 vr::Mat4f transform; | 995 vr::Mat4f transform; |
| 994 vr::MatrixMul(view_proj_matrix, rect->TransformMatrix(), &transform); | 996 vr::MatrixMul(view_proj_matrix, rect->TransformMatrix(), &transform); |
| 995 | 997 |
| 996 switch (rect->fill) { | 998 switch (rect->fill) { |
| 997 case Fill::SKIA: { | |
| 998 break; | |
| 999 } | |
| 1000 case Fill::OPAQUE_GRADIENT: { | 999 case Fill::OPAQUE_GRADIENT: { |
| 1001 vr_shell_renderer_->GetTexturedQuadRenderer()->Flush(); | |
| 1002 vr_shell_renderer_->GetGradientQuadRenderer()->Draw( | 1000 vr_shell_renderer_->GetGradientQuadRenderer()->Draw( |
| 1003 transform, rect->edge_color, rect->center_color, | 1001 transform, rect->edge_color, rect->center_color, |
| 1004 rect->computed_opacity); | 1002 rect->computed_opacity); |
| 1005 break; | 1003 break; |
| 1006 } | 1004 } |
| 1007 case Fill::GRID_GRADIENT: { | 1005 case Fill::GRID_GRADIENT: { |
| 1008 vr_shell_renderer_->GetTexturedQuadRenderer()->Flush(); | |
| 1009 vr_shell_renderer_->GetGradientGridRenderer()->Draw( | 1006 vr_shell_renderer_->GetGradientGridRenderer()->Draw( |
| 1010 transform, rect->edge_color, rect->center_color, | 1007 transform, rect->edge_color, rect->center_color, |
| 1011 rect->gridline_count, rect->computed_opacity); | 1008 rect->gridline_count, rect->computed_opacity); |
| 1012 break; | 1009 break; |
| 1013 } | 1010 } |
| 1014 case Fill::CONTENT: { | 1011 case Fill::CONTENT: { |
| 1015 gfx::RectF copy_rect(0, 0, 1, 1); | 1012 gfx::RectF copy_rect(0, 0, 1, 1); |
| 1016 vr_shell_renderer_->GetTexturedQuadRenderer()->AddQuad( | 1013 vr_shell_renderer_->GetExternalTexturedQuadRenderer()->Draw( |
| 1017 content_texture_id_, transform, copy_rect, rect->computed_opacity); | 1014 content_texture_id_, transform, copy_rect, rect->computed_opacity); |
| 1018 break; | 1015 break; |
| 1019 } | 1016 } |
| 1017 case Fill::SELF: { |
| 1018 rect->Render(vr_shell_renderer_.get(), transform); |
| 1019 break; |
| 1020 } |
| 1020 default: | 1021 default: |
| 1021 break; | 1022 break; |
| 1022 } | 1023 } |
| 1023 } | 1024 } |
| 1024 | 1025 vr_shell_renderer_->Flush(); |
| 1025 vr_shell_renderer_->GetTexturedQuadRenderer()->Flush(); | |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 std::vector<const UiElement*> VrShellGl::GetElementsInDrawOrder( | 1028 std::vector<const UiElement*> VrShellGl::GetElementsInDrawOrder( |
| 1029 const vr::Mat4f& view_matrix, | 1029 const vr::Mat4f& view_matrix, |
| 1030 const std::vector<const UiElement*>& elements) { | 1030 const std::vector<const UiElement*>& elements) { |
| 1031 typedef std::pair<float, const UiElement*> DistanceElementPair; | 1031 typedef std::pair<float, const UiElement*> DistanceElementPair; |
| 1032 std::vector<DistanceElementPair> zOrderedElementPairs; | 1032 std::vector<DistanceElementPair> zOrderedElementPairs; |
| 1033 zOrderedElementPairs.reserve(elements.size()); | 1033 zOrderedElementPairs.reserve(elements.size()); |
| 1034 | 1034 |
| 1035 for (const auto* element : elements) { | 1035 for (const auto* element : elements) { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 // InitializeGl. Revisit if the initialization order changes. | 1325 // InitializeGl. Revisit if the initialization order changes. |
| 1326 device::mojom::VRDisplayInfoPtr info = | 1326 device::mojom::VRDisplayInfoPtr info = |
| 1327 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1327 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
| 1328 webvr_surface_size_, device_id); | 1328 webvr_surface_size_, device_id); |
| 1329 main_thread_task_runner_->PostTask( | 1329 main_thread_task_runner_->PostTask( |
| 1330 FROM_HERE, | 1330 FROM_HERE, |
| 1331 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1331 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1332 } | 1332 } |
| 1333 | 1333 |
| 1334 } // namespace vr_shell | 1334 } // namespace vr_shell |
| OLD | NEW |