Commit a62b9317 authored by acondor's avatar acondor Committed by Commit bot

Adding Daydream controller resources for VrShell

- Model is in binary glTF format with no inline shaders.
- Textures are composed by one base texture and three patches of minimal size.
- We also considered using WebP, but decoders are implemented only within blink.
- Monochrome APK size is increased by 40Kb.

BUG=644562
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2850893002
Cr-Original-Commit-Position: refs/heads/master@{#468806}
Committed: https://chromium.googlesource.com/chromium/src/+/c5582157f1ac2b92e412e5164c3fd49088fd7fff
Review-Url: https://codereview.chromium.org/2850893002
Cr-Commit-Position: refs/heads/master@{#469051}
parent 7ae4d36b
...@@ -82,6 +82,8 @@ per-file test_presubmit.py=dbeam@chromium.org ...@@ -82,6 +82,8 @@ per-file test_presubmit.py=dbeam@chromium.org
per-file unload_browsertest.cc=file://content/OWNERS per-file unload_browsertest.cc=file://content/OWNERS
per-file vr_shell_resources.grdp=file://chrome/browser/android/vr_shell/OWNERS
per-file web_bluetooth*=jyasskin@chromium.org per-file web_bluetooth*=jyasskin@chromium.org
per-file web_bluetooth*=ortuno@chromium.org per-file web_bluetooth*=ortuno@chromium.org
per-file web_bluetooth*=scheib@chromium.org per-file web_bluetooth*=scheib@chromium.org
...@@ -82,6 +82,7 @@ if (current_cpu == "arm" || current_cpu == "arm64") { ...@@ -82,6 +82,7 @@ if (current_cpu == "arm" || current_cpu == "arm64") {
":vr_shell_jni_headers", ":vr_shell_jni_headers",
"//base", "//base",
"//cc", "//cc",
"//chrome:resources",
"//components/omnibox/browser", "//components/omnibox/browser",
"//components/rappor", "//components/rappor",
"//components/security_state/core", "//components/security_state/core",
......
...@@ -4,15 +4,13 @@ ...@@ -4,15 +4,13 @@
#include "chrome/browser/android/vr_shell/vr_controller_model.h" #include "chrome/browser/android/vr_shell/vr_controller_model.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/path_service.h"
#include "chrome/browser/android/vr_shell/gltf_parser.h" #include "chrome/browser/android/vr_shell/gltf_parser.h"
#include "components/component_updater/component_updater_paths.h" #include "chrome/grit/browser_resources.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
namespace vr_shell { namespace vr_shell {
...@@ -20,38 +18,28 @@ namespace vr_shell { ...@@ -20,38 +18,28 @@ namespace vr_shell {
namespace { namespace {
enum { enum {
ELEMENTS_BUFFER_ID = 2, ELEMENTS_BUFFER_ID = 0,
INDICES_BUFFER_ID = 3, INDICES_BUFFER_ID = 1,
}; };
constexpr char kPosition[] = "POSITION"; constexpr char kPosition[] = "POSITION";
constexpr char kTexCoord[] = "TEXCOORD_0"; constexpr char kTexCoord[] = "TEXCOORD_0";
// TODO(acondor): Remove these hardcoded paths once VrShell resources const int kTexturePatchesResources[] = {
// are delivered through component updater. -1, IDR_VR_SHELL_DDCONTROLLER_TOUCHPAD_PATCH,
constexpr char const kComponentName[] = "VrShell"; IDR_VR_SHELL_DDCONTROLLER_APP_PATCH, IDR_VR_SHELL_DDCONTROLLER_SYSTEM_PATCH,
constexpr char const kDefaultVersion[] = "0";
constexpr char const kModelsDirectory[] = "models";
constexpr char const kModelFilename[] = "ddcontroller.glb";
constexpr char const kTexturesDirectory[] = "tex";
constexpr char const kBaseTextureFilename[] = "ddcontroller_idle.png";
constexpr char const* kTexturePatchesFilenames[] = {
"", "ddcontroller_touchpad.png", "ddcontroller_app.png",
"ddcontroller_system.png",
}; };
const gfx::Point kPatchesLocations[] = {{}, {5, 5}, {47, 165}, {47, 234}}; const gfx::Point kPatchesLocations[] = {{}, {5, 5}, {47, 165}, {47, 234}};
sk_sp<SkImage> LoadPng(const base::FilePath& path) { sk_sp<SkImage> LoadPng(int resource_id) {
std::string data; base::StringPiece data =
ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id);
SkBitmap bitmap; SkBitmap bitmap;
if (!base::ReadFileToString(path, &data) || bool decoded =
!gfx::PNGCodec::Decode( gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(data.data()),
reinterpret_cast<const unsigned char*>(data.data()), data.size(), data.size(), &bitmap);
&bitmap) || DCHECK(decoded);
bitmap.colorType() != kRGBA_8888_SkColorType) { DCHECK(bitmap.colorType() == kRGBA_8888_SkColorType);
return nullptr;
}
return SkImage::MakeFromBitmap(bitmap); return SkImage::MakeFromBitmap(bitmap);
} }
...@@ -154,50 +142,22 @@ const gltf::Accessor* VrControllerModel::Accessor( ...@@ -154,50 +142,22 @@ const gltf::Accessor* VrControllerModel::Accessor(
} }
std::unique_ptr<VrControllerModel> VrControllerModel::LoadFromComponent() { std::unique_ptr<VrControllerModel> VrControllerModel::LoadFromComponent() {
base::FilePath models_path;
PathService::Get(component_updater::DIR_COMPONENT_USER, &models_path);
models_path = models_path.Append(kComponentName)
.Append(kDefaultVersion)
.Append(kModelsDirectory);
auto model_path = models_path.Append(kModelFilename);
// No further action if model file is not present
if (!base::PathExists(model_path)) {
LOG(WARNING) << "Controller model files not found";
return nullptr;
}
std::vector<std::unique_ptr<gltf::Buffer>> buffers; std::vector<std::unique_ptr<gltf::Buffer>> buffers;
auto model_data = ResourceBundle::GetSharedInstance().GetRawDataResource(
std::string model_data; IDR_VR_SHELL_DDCONTROLLER_MODEL);
base::ReadFileToString(model_path, &model_data); std::unique_ptr<gltf::Asset> asset =
auto asset = BinaryGltfParser::Parse(base::StringPiece(model_data), &buffers); BinaryGltfParser::Parse(model_data, &buffers);
if (!asset) { DCHECK(asset);
LOG(ERROR) << "Failed to read controller model";
return nullptr;
}
auto controller_model = auto controller_model =
base::MakeUnique<VrControllerModel>(std::move(asset), std::move(buffers)); base::MakeUnique<VrControllerModel>(std::move(asset), std::move(buffers));
sk_sp<SkImage> base_texture = LoadPng(IDR_VR_SHELL_DDCONTROLLER_IDLE_TEXTURE);
auto textures_path = models_path.Append(kTexturesDirectory);
auto base_texture = LoadPng(textures_path.Append(kBaseTextureFilename));
if (!base_texture) {
LOG(ERROR) << "Failed to read controller base texture";
return nullptr;
}
controller_model->SetBaseTexture(std::move(base_texture)); controller_model->SetBaseTexture(std::move(base_texture));
for (int i = 0; i < VrControllerModel::STATE_COUNT; i++) { for (int i = 0; i < VrControllerModel::STATE_COUNT; i++) {
if (!kTexturePatchesFilenames[i][0]) if (kTexturePatchesResources[i] == -1)
continue;
auto patch_image =
LoadPng(textures_path.Append(kTexturePatchesFilenames[i]));
if (!patch_image) {
LOG(ERROR) << "Failed to read controller texture patch";
continue; continue;
} auto patch_image = LoadPng(kTexturePatchesResources[i]);
controller_model->SetTexturePatch(i, patch_image); controller_model->SetTexturePatch(i, patch_image);
} }
......
...@@ -238,6 +238,7 @@ ...@@ -238,6 +238,7 @@
<include name="IDR_SNIPPETS_INTERNALS_HTML" file="resources\snippets_internals.html" allowexternalscript="true" compress="gzip" type="BINDATA" /> <include name="IDR_SNIPPETS_INTERNALS_HTML" file="resources\snippets_internals.html" allowexternalscript="true" compress="gzip" type="BINDATA" />
<include name="IDR_SNIPPETS_INTERNALS_CSS" file="resources\snippets_internals.css" compress="gzip" type="BINDATA" /> <include name="IDR_SNIPPETS_INTERNALS_CSS" file="resources\snippets_internals.css" compress="gzip" type="BINDATA" />
<include name="IDR_SNIPPETS_INTERNALS_JS" file="resources\snippets_internals.js" compress="gzip" type="BINDATA" /> <include name="IDR_SNIPPETS_INTERNALS_JS" file="resources\snippets_internals.js" compress="gzip" type="BINDATA" />
<part file="vr_shell_resources.grdp" />
</if> </if>
<include name="IDR_SUPERVISED_USER_INTERNALS_HTML" file="resources\supervised_user_internals.html" allowexternalscript="true" compress="gzip" type="BINDATA" /> <include name="IDR_SUPERVISED_USER_INTERNALS_HTML" file="resources\supervised_user_internals.html" allowexternalscript="true" compress="gzip" type="BINDATA" />
<include name="IDR_SUPERVISED_USER_INTERNALS_CSS" file="resources\supervised_user_internals.css" compress="gzip" type="BINDATA" /> <include name="IDR_SUPERVISED_USER_INTERNALS_CSS" file="resources\supervised_user_internals.css" compress="gzip" type="BINDATA" />
......
file://chrome/browser/android/vr_shell/OWNERS
# COMPONENT: UI>Browser>VR
<?xml version="1.0" encoding="UTF-8"?>
<grit-part>
<if expr="enable_vr">
<include name="IDR_VR_SHELL_DDCONTROLLER_MODEL" file="resources\vr_shell\ddcontroller.glb" type="BINDATA" />
<include name="IDR_VR_SHELL_DDCONTROLLER_IDLE_TEXTURE" file="resources\vr_shell\tex\ddcontroller_idle.png" type="BINDATA" />
<include name="IDR_VR_SHELL_DDCONTROLLER_APP_PATCH" file="resources\vr_shell\tex\ddcontroller_app.png" type="BINDATA" />
<include name="IDR_VR_SHELL_DDCONTROLLER_TOUCHPAD_PATCH" file="resources\vr_shell\tex\ddcontroller_touchpad.png" type="BINDATA" />
<include name="IDR_VR_SHELL_DDCONTROLLER_SYSTEM_PATCH" file="resources\vr_shell\tex\ddcontroller_system.png" type="BINDATA" />
</if>
</grit-part>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment