| 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 "device/generic_sensor/platform_sensor_provider_base.h" | 5 #include "device/generic_sensor/platform_sensor_provider_base.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h" | 10 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h" |
| 11 | 11 |
| 12 namespace device { | 12 namespace device { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 const uint64_t kSharedBufferSizeInBytes = | 16 const uint64_t kSharedBufferSizeInBytes = |
| 17 mojom::SensorInitParams::kReadBufferSize * | 17 PlatformSensor::kReadingBufferSize * |
| 18 static_cast<uint64_t>(mojom::SensorType::LAST); | 18 static_cast<uint64_t>(mojom::SensorType::LAST); |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 PlatformSensorProviderBase::PlatformSensorProviderBase() = default; | 22 PlatformSensorProviderBase::PlatformSensorProviderBase() = default; |
| 23 PlatformSensorProviderBase::~PlatformSensorProviderBase() = default; | 23 PlatformSensorProviderBase::~PlatformSensorProviderBase() = default; |
| 24 | 24 |
| 25 scoped_refptr<PlatformSensor> PlatformSensorProviderBase::CreateSensor( | 25 scoped_refptr<PlatformSensor> PlatformSensorProviderBase::CreateSensor( |
| 26 mojom::SensorType type, | 26 mojom::SensorType type) { |
| 27 uint64_t size, | |
| 28 uint64_t offset) { | |
| 29 DCHECK(CalledOnValidThread()); | 27 DCHECK(CalledOnValidThread()); |
| 30 | 28 |
| 31 if (!CreateSharedBufferIfNeeded()) | 29 if (!CreateSharedBufferIfNeeded()) |
| 32 return nullptr; | 30 return nullptr; |
| 33 | 31 |
| 34 mojo::ScopedSharedBufferMapping mapping = | 32 mojo::ScopedSharedBufferMapping mapping = shared_buffer_handle_->MapAtOffset( |
| 35 shared_buffer_handle_->MapAtOffset(size, offset); | 33 PlatformSensor::kReadingBufferSize, GetSharedBufferOffset(type)); |
| 36 if (!mapping) | 34 if (!mapping) |
| 37 return nullptr; | 35 return nullptr; |
| 38 | 36 |
| 39 scoped_refptr<PlatformSensor> new_sensor = | 37 scoped_refptr<PlatformSensor> new_sensor = |
| 40 CreateSensorInternal(type, std::move(mapping), size); | 38 CreateSensorInternal(type, std::move(mapping)); |
| 41 if (!new_sensor) | 39 if (!new_sensor) |
| 42 return nullptr; | 40 return nullptr; |
| 43 | 41 |
| 44 DCHECK(!ContainsKey(sensor_map_, type)); | 42 DCHECK(!ContainsKey(sensor_map_, type)); |
| 45 sensor_map_[type] = new_sensor.get(); | 43 sensor_map_[type] = new_sensor.get(); |
| 46 | 44 |
| 47 return new_sensor; | 45 return new_sensor; |
| 48 } | 46 } |
| 49 | 47 |
| 50 scoped_refptr<PlatformSensor> PlatformSensorProviderBase::GetSensor( | 48 scoped_refptr<PlatformSensor> PlatformSensorProviderBase::GetSensor( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 76 shared_buffer_handle_.reset(); | 74 shared_buffer_handle_.reset(); |
| 77 } | 75 } |
| 78 | 76 |
| 79 mojo::ScopedSharedBufferHandle | 77 mojo::ScopedSharedBufferHandle |
| 80 PlatformSensorProviderBase::CloneSharedBufferHandle() { | 78 PlatformSensorProviderBase::CloneSharedBufferHandle() { |
| 81 DCHECK(CalledOnValidThread()); | 79 DCHECK(CalledOnValidThread()); |
| 82 CreateSharedBufferIfNeeded(); | 80 CreateSharedBufferIfNeeded(); |
| 83 return shared_buffer_handle_->Clone(); | 81 return shared_buffer_handle_->Clone(); |
| 84 } | 82 } |
| 85 | 83 |
| 84 uint64_t PlatformSensorProviderBase::GetSharedBufferOffset( |
| 85 mojom::SensorType type) { |
| 86 return (static_cast<uint64_t>(mojom::SensorType::LAST) - |
| 87 static_cast<uint64_t>(type)) * |
| 88 PlatformSensor::kReadingBufferSize; |
| 89 } |
| 90 |
| 86 } // namespace device | 91 } // namespace device |
| OLD | NEW |