Index: chrome/browser/android/vr_shell/vr_shell.cc |
diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc |
index edcbb68f0fe05e2c0f75e96229e281b9e33a5b32..8d178e953992873f59c2e88dfd663c34a4bf02d4 100644 |
--- a/chrome/browser/android/vr_shell/vr_shell.cc |
+++ b/chrome/browser/android/vr_shell/vr_shell.cc |
@@ -10,8 +10,11 @@ |
#include <utility> |
#include "base/android/jni_string.h" |
+#include "base/files/file_path.h" |
+#include "base/json/json_file_value_serializer.h" |
#include "base/memory/ptr_util.h" |
#include "base/metrics/histogram_macros.h" |
+#include "base/path_service.h" |
#include "base/threading/platform_thread.h" |
#include "base/threading/thread.h" |
#include "base/threading/thread_restrictions.h" |
@@ -19,13 +22,18 @@ |
#include "base/values.h" |
#include "chrome/browser/android/tab_android.h" |
#include "chrome/browser/android/vr_shell/android_ui_gesture_target.h" |
+#include "chrome/browser/android/vr_shell/gltf_parser.h" |
+#include "chrome/browser/android/vr_shell/ui_interface.h" |
#include "chrome/browser/android/vr_shell/vr_compositor.h" |
+#include "chrome/browser/android/vr_shell/vr_controller_model.h" |
#include "chrome/browser/android/vr_shell/vr_gl_thread.h" |
#include "chrome/browser/android/vr_shell/vr_input_manager.h" |
#include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
#include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
#include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
#include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
+#include "components/component_updater/component_updater_paths.h" |
+#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/navigation_controller.h" |
#include "content/public/browser/render_view_host.h" |
#include "content/public/browser/render_widget_host.h" |
@@ -44,6 +52,7 @@ |
#include "ui/base/page_transition_types.h" |
#include "ui/display/display.h" |
#include "ui/display/screen.h" |
+#include "ui/gfx/codec/png_codec.h" |
#include "ui/gfx/transform.h" |
#include "ui/gfx/transform_util.h" |
@@ -69,6 +78,53 @@ void SetIsInVR(content::WebContents* contents, bool is_in_vr) { |
contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); |
} |
+void LoadControllerModelTask( |
+ base::WeakPtr<VrShell> weak_vr_shell, |
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { |
+ base::FilePath models_path; |
+ PathService::Get(component_updater::DIR_COMPONENT_USER, &models_path); |
+ models_path = models_path.Append(VrControllerModel::kComponentName) |
+ .Append(VrControllerModel::kDefaultVersion) |
cjgrant
2017/03/29 13:20:54
Formatting looks off here.
acondor_
2017/03/29 20:13:26
This is what cl format does, even if I try to chan
cjgrant
2017/03/29 20:22:37
Acknowledged.
|
+ .Append(VrControllerModel::kModelsDirectory); |
+ auto model_path = models_path.Append(VrControllerModel::kModelFilename); |
+ |
+ // No further action if model file is not present |
+ if (!base::PathExists(model_path)) |
cjgrant
2017/03/29 13:20:54
Is this worth a warning-level print?
acondor_
2017/03/29 20:13:26
Done.
|
+ return; |
+ |
+ GltfParser gltf_parser; |
+ auto asset = gltf_parser.Parse(model_path); |
+ if (!asset) { |
+ LOG(ERROR) << "LoadControllerModelTask: Failed to parse model."; |
+ return; |
+ } |
+ |
+ auto controller_model = base::MakeUnique<VrControllerModel>(std::move(asset)); |
+ |
+ auto textures_path = |
+ models_path.Append(VrControllerModel::kTexturesDirectory); |
+ |
+ for (int i = 0; i < VrControllerModel::STATE_COUNT; i++) { |
+ auto texture_path = |
+ textures_path.Append(VrControllerModel::kTextureFilenames[i]); |
+ std::string data; |
+ auto bitmap = base::MakeUnique<SkBitmap>(); |
+ if (!base::ReadFileToString(texture_path, &data) || |
+ !gfx::PNGCodec::Decode( |
+ reinterpret_cast<const unsigned char*>(data.data()), data.size(), |
+ bitmap.get()) || |
+ bitmap->colorType() != kRGBA_8888_SkColorType) { |
+ LOG(ERROR) << "LoadControllerModelTask: Failed to read texture"; |
cjgrant
2017/03/29 13:20:54
Rather than including the function name, how about
acondor_
2017/03/29 20:13:26
Done.
|
+ return; |
+ } |
+ controller_model->SetTexture(i, std::move(bitmap)); |
+ } |
+ |
+ main_thread_task_runner->PostTask( |
+ FROM_HERE, base::Bind(&VrShell::SubmitControllerModel, weak_vr_shell, |
+ base::Passed(&controller_model))); |
+} |
+ |
} // namespace |
VrShell::VrShell(JNIEnv* env, |
@@ -110,6 +166,11 @@ VrShell::VrShell(JNIEnv* env, |
html_interface_ = base::MakeUnique<UiInterface>( |
for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD); |
+ |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::FILE, FROM_HERE, |
+ base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(), |
+ main_thread_task_runner_)); |
} |
void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
@@ -349,6 +410,12 @@ void VrShell::SubmitWebVRFrame(int16_t frame_index, |
mailbox)); |
} |
+void VrShell::SubmitControllerModel(std::unique_ptr<VrControllerModel> model) { |
+ PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetControllerModel, |
+ gl_thread_->GetVrShellGl(), |
+ base::Passed(&model))); |
+} |
+ |
void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, |
const gvr::Rectf& left_bounds, |
const gvr::Rectf& right_bounds, |