Chromium Code Reviews| Index: chrome/browser/android/vr_shell/vr_controller_model.cc |
| diff --git a/chrome/browser/android/vr_shell/vr_controller_model.cc b/chrome/browser/android/vr_shell/vr_controller_model.cc |
| index ab8d41555d762919f3196bdba90bf4f4c946209c..c9b4a97722e14ff2b9b76f4e940300f29ae76383 100644 |
| --- a/chrome/browser/android/vr_shell/vr_controller_model.cc |
| +++ b/chrome/browser/android/vr_shell/vr_controller_model.cc |
| @@ -4,15 +4,13 @@ |
| #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/path_service.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/SkRect.h" |
| #include "third_party/skia/include/core/SkSurface.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/codec/png_codec.h" |
| namespace vr_shell { |
| @@ -20,38 +18,28 @@ namespace vr_shell { |
| namespace { |
| enum { |
| - ELEMENTS_BUFFER_ID = 2, |
| - INDICES_BUFFER_ID = 3, |
| + ELEMENTS_BUFFER_ID = 0, |
| + INDICES_BUFFER_ID = 1, |
| }; |
| constexpr char kPosition[] = "POSITION"; |
| constexpr char kTexCoord[] = "TEXCOORD_0"; |
| -// TODO(acondor): Remove these hardcoded paths once VrShell resources |
| -// are delivered through component updater. |
| -constexpr char const kComponentName[] = "VrShell"; |
| -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 int kTexturePatchesResources[] = { |
| + -1, IDR_VR_SHELL_DDCONTROLLER_TOUCHPAD_PATCH, |
| + IDR_VR_SHELL_DDCONTROLLER_APP_PATCH, IDR_VR_SHELL_DDCONTROLLER_SYSTEM_PATCH, |
| }; |
| const gfx::Point kPatchesLocations[] = {{}, {5, 5}, {47, 165}, {47, 234}}; |
| -sk_sp<SkImage> LoadPng(const base::FilePath& path) { |
| - std::string data; |
| +sk_sp<SkImage> LoadPng(int resource_id) { |
| + auto data = |
|
Nico
2017/05/01 17:21:43
only use auto when type of rhs is clear
acondor_
2017/05/02 18:18:23
Done.
|
| + ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
| SkBitmap bitmap; |
| - if (!base::ReadFileToString(path, &data) || |
| - !gfx::PNGCodec::Decode( |
| - reinterpret_cast<const unsigned char*>(data.data()), data.size(), |
| - &bitmap) || |
| - bitmap.colorType() != kRGBA_8888_SkColorType) { |
| - return nullptr; |
| - } |
| + bool decoded = |
| + gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(data.data()), |
| + data.size(), &bitmap); |
| + DCHECK(decoded); |
| + DCHECK(bitmap.colorType() == kRGBA_8888_SkColorType); |
| return SkImage::MakeFromBitmap(bitmap); |
| } |
| @@ -154,50 +142,21 @@ const gltf::Accessor* VrControllerModel::Accessor( |
| } |
| 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::string model_data; |
| - base::ReadFileToString(model_path, &model_data); |
| - auto asset = BinaryGltfParser::Parse(base::StringPiece(model_data), &buffers); |
| - if (!asset) { |
| - LOG(ERROR) << "Failed to read controller model"; |
| - return nullptr; |
| - } |
| + auto model_data = ResourceBundle::GetSharedInstance().GetRawDataResource( |
| + IDR_VR_SHELL_DDCONTROLLER_MODEL); |
| + auto asset = BinaryGltfParser::Parse(model_data, &buffers); |
|
Nico
2017/05/01 17:21:43
likewise.
also, for pointers use `auto* asset` (b
acondor_
2017/05/02 18:18:23
Done.
|
| + DCHECK(asset); |
| auto controller_model = |
| base::MakeUnique<VrControllerModel>(std::move(asset), std::move(buffers)); |
| - |
| - 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; |
| - } |
| + auto base_texture = LoadPng(IDR_VR_SHELL_DDCONTROLLER_IDLE_TEXTURE); |
|
Nico
2017/05/01 17:21:43
likewise (controller_model is fine since its type
acondor_
2017/05/02 18:18:23
Done.
|
| controller_model->SetBaseTexture(std::move(base_texture)); |
| for (int i = 0; i < VrControllerModel::STATE_COUNT; i++) { |
| - if (!kTexturePatchesFilenames[i][0]) |
| - continue; |
| - auto patch_image = |
| - LoadPng(textures_path.Append(kTexturePatchesFilenames[i])); |
| - if (!patch_image) { |
| - LOG(ERROR) << "Failed to read controller texture patch"; |
| + if (kTexturePatchesResources[i] == -1) |
| continue; |
| - } |
| + auto patch_image = LoadPng(kTexturePatchesResources[i]); |
| controller_model->SetTexturePatch(i, patch_image); |
| } |