| Index: content/browser/device_orientation/data_fetcher_shared_memory_win.cc
|
| diff --git a/content/browser/device_orientation/data_fetcher_impl_win.cc b/content/browser/device_orientation/data_fetcher_shared_memory_win.cc
|
| similarity index 59%
|
| copy from content/browser/device_orientation/data_fetcher_impl_win.cc
|
| copy to content/browser/device_orientation/data_fetcher_shared_memory_win.cc
|
| index d08ed446ad623f4c8e577cc7fd97fdf01f14f559..24caf3fe159488e16bdf9239961758b59268e667 100644
|
| --- a/content/browser/device_orientation/data_fetcher_impl_win.cc
|
| +++ b/content/browser/device_orientation/data_fetcher_shared_memory_win.cc
|
| @@ -1,8 +1,8 @@
|
| -// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/browser/device_orientation/data_fetcher_impl_win.h"
|
| +#include "data_fetcher_shared_memory.h"
|
|
|
| #include <InitGuid.h>
|
| #include <PortableDeviceTypes.h>
|
| @@ -11,22 +11,20 @@
|
| #include "base/logging.h"
|
| #include "base/win/iunknown_impl.h"
|
| #include "base/win/windows_version.h"
|
| -#include "content/browser/device_orientation/orientation.h"
|
|
|
| namespace {
|
|
|
| -// This should match ProviderImpl::kDesiredSamplingIntervalMs.
|
| const int kPeriodInMilliseconds = 100;
|
|
|
| } // namespace
|
|
|
| namespace content {
|
|
|
| -class DataFetcherImplWin::SensorEventSink : public ISensorEvents,
|
| - public base::win::IUnknownImpl {
|
| +class DataFetcherSharedMemory::SensorEventSink
|
| + : public ISensorEvents, public base::win::IUnknownImpl {
|
| public:
|
| - explicit SensorEventSink(DataFetcherImplWin* const fetcher)
|
| - : fetcher_(fetcher) {}
|
| + explicit SensorEventSink(DeviceOrientationHardwareBuffer* buffer)
|
| + : buffer_(buffer) {}
|
|
|
| virtual ~SensorEventSink() {}
|
|
|
| @@ -61,28 +59,47 @@ class DataFetcherImplWin::SensorEventSink : public ISensorEvents,
|
| return E_INVALIDARG;
|
|
|
| PROPVARIANT value = {};
|
| - scoped_refptr<Orientation> orientation = new Orientation();
|
| + double alpha = 0;
|
| + bool has_alpha = false;
|
| + double beta = 0;
|
| + bool has_beta = false;
|
| + double gamma = 0;
|
| + bool has_gamma = false;
|
|
|
| if (SUCCEEDED(new_data->GetSensorValue(
|
| - SENSOR_DATA_TYPE_TILT_X_DEGREES, &value))) {
|
| - orientation->set_beta(value.fltVal);
|
| + SENSOR_DATA_TYPE_TILT_X_DEGREES, &value))) {
|
| + beta = value.fltVal;
|
| + has_beta = true;
|
| }
|
| PropVariantClear(&value);
|
|
|
| if (SUCCEEDED(new_data->GetSensorValue(
|
| - SENSOR_DATA_TYPE_TILT_Y_DEGREES, &value))) {
|
| - orientation->set_gamma(value.fltVal);
|
| + SENSOR_DATA_TYPE_TILT_Y_DEGREES, &value))) {
|
| + gamma = value.fltVal;
|
| + has_gamma = true;
|
| }
|
| PropVariantClear(&value);
|
|
|
| if (SUCCEEDED(new_data->GetSensorValue(
|
| - SENSOR_DATA_TYPE_TILT_Z_DEGREES, &value))) {
|
| - orientation->set_alpha(value.fltVal);
|
| + SENSOR_DATA_TYPE_TILT_Z_DEGREES, &value))) {
|
| + alpha = value.fltVal;
|
| + has_alpha = true;
|
| }
|
| PropVariantClear(&value);
|
|
|
| - orientation->set_absolute(true);
|
| - fetcher_->OnOrientationData(orientation.get());
|
| + if (buffer_) {
|
| + buffer_->seqlock.WriteBegin();
|
| + buffer_->data.alpha = alpha;
|
| + buffer_->data.hasAlpha = has_alpha;
|
| + buffer_->data.beta = beta;
|
| + buffer_->data.hasBeta = has_beta;
|
| + buffer_->data.gamma = gamma;
|
| + buffer_->data.hasGamma = has_gamma;
|
| + buffer_->data.absolute = true;
|
| + buffer_->data.hasAbsolute = has_alpha || has_beta || has_gamma;
|
| + buffer_->data.allAvailableSensorsAreActive = true;
|
| + buffer_->seqlock.WriteEnd();
|
| + }
|
|
|
| return S_OK;
|
| }
|
| @@ -96,56 +113,32 @@ class DataFetcherImplWin::SensorEventSink : public ISensorEvents,
|
| }
|
|
|
| private:
|
| - DataFetcherImplWin* const fetcher_;
|
| + DeviceOrientationHardwareBuffer* buffer_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(SensorEventSink);
|
| };
|
|
|
| -// Create a DataFetcherImplWin object and return NULL if no valid sensor found.
|
| -// static
|
| -DataFetcher* DataFetcherImplWin::Create() {
|
| - scoped_ptr<DataFetcherImplWin> fetcher(new DataFetcherImplWin);
|
| - if (fetcher->Initialize())
|
| - return fetcher.release();
|
| -
|
| - LOG(ERROR) << "DataFetcherImplWin::Initialize failed!";
|
| - return NULL;
|
| -}
|
| -
|
| -DataFetcherImplWin::~DataFetcherImplWin() {
|
| - if (sensor_)
|
| - sensor_->SetEventSink(NULL);
|
| -}
|
| -
|
| -DataFetcherImplWin::DataFetcherImplWin() {
|
| -}
|
|
|
| -void DataFetcherImplWin::OnOrientationData(Orientation* orientation) {
|
| - // This method is called on Windows sensor thread.
|
| - base::AutoLock autolock(next_orientation_lock_);
|
| - next_orientation_ = orientation;
|
| +DataFetcherSharedMemory::DataFetcherSharedMemory()
|
| + : motion_buffer_(NULL),
|
| + orientation_buffer_(NULL) {
|
| }
|
|
|
| -const DeviceData* DataFetcherImplWin::GetDeviceData(DeviceData::Type type) {
|
| - if (type != DeviceData::kTypeOrientation)
|
| - return NULL;
|
| - return GetOrientation();
|
| +DataFetcherSharedMemory::~DataFetcherSharedMemory() {
|
| }
|
|
|
| -const Orientation* DataFetcherImplWin::GetOrientation() {
|
| - if (next_orientation_.get()) {
|
| - base::AutoLock autolock(next_orientation_lock_);
|
| - next_orientation_.swap(current_orientation_);
|
| - }
|
| - if (!current_orientation_.get())
|
| - return new Orientation();
|
| - return current_orientation_.get();
|
| -}
|
| +bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
|
| + DCHECK(buffer);
|
|
|
| -bool DataFetcherImplWin::Initialize() {
|
| if (base::win::GetVersion() < base::win::VERSION_WIN7)
|
| return false;
|
|
|
| + if (consumer_type != CONSUMER_TYPE_ORIENTATION)
|
| + return false;
|
| +
|
| + orientation_buffer_ = static_cast<DeviceOrientationHardwareBuffer*>(buffer);
|
| + DCHECK(orientation_buffer_);
|
| +
|
| base::win::ScopedComPtr<ISensorManager> sensor_manager;
|
| HRESULT hr = sensor_manager.CreateInstance(CLSID_SensorManager);
|
| if (FAILED(hr) || !sensor_manager)
|
| @@ -170,13 +163,15 @@ bool DataFetcherImplWin::Initialize() {
|
| base::win::ScopedComPtr<IPortableDeviceValues> device_values;
|
| if (SUCCEEDED(device_values.CreateInstance(CLSID_PortableDeviceValues))) {
|
| if (SUCCEEDED(device_values->SetUnsignedIntegerValue(
|
| - SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL, kPeriodInMilliseconds))) {
|
| + SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL, kPeriodInMilliseconds))) {
|
| base::win::ScopedComPtr<IPortableDeviceValues> return_values;
|
| sensor_->SetProperties(device_values.get(), return_values.Receive());
|
| }
|
| }
|
|
|
| - scoped_refptr<SensorEventSink> sensor_event_impl(new SensorEventSink(this));
|
| + scoped_refptr<SensorEventSink> sensor_event_impl(new SensorEventSink(
|
| + orientation_buffer_));
|
| +
|
| base::win::ScopedComPtr<ISensorEvents> sensor_events;
|
| hr = sensor_event_impl->QueryInterface(
|
| __uuidof(ISensorEvents), sensor_events.ReceiveVoid());
|
| @@ -190,4 +185,23 @@ bool DataFetcherImplWin::Initialize() {
|
| return true;
|
| }
|
|
|
| +bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
|
| + if (consumer_type != CONSUMER_TYPE_ORIENTATION)
|
| + return false;
|
| +
|
| + if (sensor_)
|
| + sensor_->SetEventSink(NULL);
|
| +
|
| + if (orientation_buffer_) {
|
| + orientation_buffer_->seqlock.WriteBegin();
|
| + orientation_buffer_->data.allAvailableSensorsAreActive = false;
|
| + orientation_buffer_->seqlock.WriteEnd();
|
| + orientation_buffer_ = NULL;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +
|
| } // namespace content
|
| +
|
|
|