OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "data_fetcher_shared_memory.h" | 5 #include "data_fetcher_shared_memory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/device_motion_hardware_buffer.h" | 8 #include "content/common/device_motion_hardware_buffer.h" |
9 #include "content/common/device_orientation/device_orientation_hardware_buffer.h
" | 9 #include "content/common/device_orientation/device_orientation_hardware_buffer.h
" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 static bool SetMotionBuffer(content::DeviceMotionHardwareBuffer* buffer, | 13 static bool SetMotionBuffer(content::DeviceMotionHardwareBuffer* buffer, |
14 bool enabled) { | 14 bool enabled) { |
15 DCHECK(buffer); | 15 if (!buffer) |
| 16 return false; |
16 buffer->seqlock.WriteBegin(); | 17 buffer->seqlock.WriteBegin(); |
17 buffer->data.allAvailableSensorsAreActive = enabled; | 18 buffer->data.allAvailableSensorsAreActive = enabled; |
18 buffer->seqlock.WriteEnd(); | 19 buffer->seqlock.WriteEnd(); |
19 return true; | 20 return true; |
20 } | 21 } |
21 | 22 |
22 } | 23 } |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
26 DataFetcherSharedMemory::DataFetcherSharedMemory() { | 27 DataFetcherSharedMemory::DataFetcherSharedMemory() { |
27 } | 28 } |
28 | 29 |
29 DataFetcherSharedMemory::~DataFetcherSharedMemory() { | 30 DataFetcherSharedMemory::~DataFetcherSharedMemory() { |
30 } | 31 } |
31 | 32 |
32 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type) { | 33 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { |
33 void* buffer = GetSharedMemoryBuffer(consumer_type); | |
34 DCHECK(buffer); | 34 DCHECK(buffer); |
35 | 35 |
36 switch (consumer_type) { | 36 switch (consumer_type) { |
37 case CONSUMER_TYPE_MOTION: | 37 case CONSUMER_TYPE_MOTION: |
38 return SetMotionBuffer( | 38 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); |
39 static_cast<DeviceMotionHardwareBuffer*>(buffer), true); | 39 return SetMotionBuffer(motion_buffer_, true); |
40 case CONSUMER_TYPE_ORIENTATION: | 40 case CONSUMER_TYPE_ORIENTATION: |
41 NOTIMPLEMENTED(); | 41 NOTIMPLEMENTED(); |
42 break; | 42 break; |
43 default: | 43 default: |
44 NOTREACHED(); | 44 NOTREACHED(); |
45 } | 45 } |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { | 49 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { |
50 void* buffer = GetSharedMemoryBuffer(consumer_type); | |
51 DCHECK(buffer); | |
52 | 50 |
53 switch (consumer_type) { | 51 switch (consumer_type) { |
54 case CONSUMER_TYPE_MOTION: | 52 case CONSUMER_TYPE_MOTION: |
55 return SetMotionBuffer( | 53 return SetMotionBuffer(motion_buffer_, false); |
56 static_cast<DeviceMotionHardwareBuffer*>(buffer), false); | |
57 case CONSUMER_TYPE_ORIENTATION: | 54 case CONSUMER_TYPE_ORIENTATION: |
58 NOTIMPLEMENTED(); | 55 NOTIMPLEMENTED(); |
59 break; | 56 break; |
60 default: | 57 default: |
61 NOTREACHED(); | 58 NOTREACHED(); |
62 } | 59 } |
63 return false; | 60 return false; |
64 } | 61 } |
65 | 62 |
66 } // namespace content | 63 } // namespace content |
OLD | NEW |