| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_controller_model.h" | 5 #include "chrome/browser/android/vr_shell/vr_controller_model.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/trace_event/trace_event.h" |
| 8 #include "chrome/browser/android/vr_shell/gltf_parser.h" | 9 #include "chrome/browser/android/vr_shell/gltf_parser.h" |
| 9 #include "chrome/grit/browser_resources.h" | 10 #include "chrome/grit/browser_resources.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkRect.h" | 12 #include "third_party/skia/include/core/SkRect.h" |
| 12 #include "third_party/skia/include/core/SkSurface.h" | 13 #include "third_party/skia/include/core/SkSurface.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/codec/png_codec.h" | 15 #include "ui/gfx/codec/png_codec.h" |
| 15 | 16 |
| 16 namespace vr_shell { | 17 namespace vr_shell { |
| 17 | 18 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 135 |
| 135 const gltf::Accessor* VrControllerModel::Accessor( | 136 const gltf::Accessor* VrControllerModel::Accessor( |
| 136 const std::string& key) const { | 137 const std::string& key) const { |
| 137 const gltf::Mesh* mesh = gltf_asset_->GetMesh(0); | 138 const gltf::Mesh* mesh = gltf_asset_->GetMesh(0); |
| 138 DCHECK(mesh && mesh->primitives.size()); | 139 DCHECK(mesh && mesh->primitives.size()); |
| 139 auto it = mesh->primitives[0]->attributes.find(key); | 140 auto it = mesh->primitives[0]->attributes.find(key); |
| 140 DCHECK(it != mesh->primitives[0]->attributes.begin()); | 141 DCHECK(it != mesh->primitives[0]->attributes.begin()); |
| 141 return it->second; | 142 return it->second; |
| 142 } | 143 } |
| 143 | 144 |
| 144 std::unique_ptr<VrControllerModel> VrControllerModel::LoadFromComponent() { | 145 std::unique_ptr<VrControllerModel> VrControllerModel::LoadFromResources() { |
| 146 TRACE_EVENT0("gpu", "VrControllerModel::LoadFromComponent"); |
| 145 std::vector<std::unique_ptr<gltf::Buffer>> buffers; | 147 std::vector<std::unique_ptr<gltf::Buffer>> buffers; |
| 146 auto model_data = ResourceBundle::GetSharedInstance().GetRawDataResource( | 148 auto model_data = ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 147 IDR_VR_SHELL_DDCONTROLLER_MODEL); | 149 IDR_VR_SHELL_DDCONTROLLER_MODEL); |
| 148 std::unique_ptr<gltf::Asset> asset = | 150 std::unique_ptr<gltf::Asset> asset = |
| 149 BinaryGltfParser::Parse(model_data, &buffers); | 151 BinaryGltfParser::Parse(model_data, &buffers); |
| 150 DCHECK(asset); | 152 DCHECK(asset); |
| 151 | 153 |
| 152 auto controller_model = | 154 auto controller_model = |
| 153 base::MakeUnique<VrControllerModel>(std::move(asset), std::move(buffers)); | 155 base::MakeUnique<VrControllerModel>(std::move(asset), std::move(buffers)); |
| 154 sk_sp<SkImage> base_texture = LoadPng(IDR_VR_SHELL_DDCONTROLLER_IDLE_TEXTURE); | 156 sk_sp<SkImage> base_texture = LoadPng(IDR_VR_SHELL_DDCONTROLLER_IDLE_TEXTURE); |
| 155 controller_model->SetBaseTexture(std::move(base_texture)); | 157 controller_model->SetBaseTexture(std::move(base_texture)); |
| 156 | 158 |
| 157 for (int i = 0; i < VrControllerModel::STATE_COUNT; i++) { | 159 for (int i = 0; i < VrControllerModel::STATE_COUNT; i++) { |
| 158 if (kTexturePatchesResources[i] == -1) | 160 if (kTexturePatchesResources[i] == -1) |
| 159 continue; | 161 continue; |
| 160 auto patch_image = LoadPng(kTexturePatchesResources[i]); | 162 auto patch_image = LoadPng(kTexturePatchesResources[i]); |
| 161 controller_model->SetTexturePatch(i, patch_image); | 163 controller_model->SetTexturePatch(i, patch_image); |
| 162 } | 164 } |
| 163 | 165 |
| 164 return controller_model; | 166 return controller_model; |
| 165 } | 167 } |
| 166 | 168 |
| 167 } // namespace vr_shell | 169 } // namespace vr_shell |
| OLD | NEW |