| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/hid/hid_report_descriptor.h" | 5 #include "device/hid/hid_report_descriptor.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 | 8 |
| 9 namespace device { | 9 namespace device { |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 items_.push_back(linked_ptr<HidReportDescriptorItem>(item)); | 22 items_.push_back(linked_ptr<HidReportDescriptorItem>(item)); |
| 23 header_index += item->GetSize(); | 23 header_index += item->GetSize(); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 HidReportDescriptor::~HidReportDescriptor() {} | 27 HidReportDescriptor::~HidReportDescriptor() {} |
| 28 | 28 |
| 29 void HidReportDescriptor::GetDetails( | 29 void HidReportDescriptor::GetDetails( |
| 30 std::vector<HidCollectionInfo>* top_level_collections, | 30 std::vector<HidCollectionInfo>* top_level_collections, |
| 31 bool* has_report_id, | 31 bool* has_report_id, |
| 32 uint16_t* max_input_report_size, | 32 size_t* max_input_report_size, |
| 33 uint16_t* max_output_report_size, | 33 size_t* max_output_report_size, |
| 34 uint16_t* max_feature_report_size) { | 34 size_t* max_feature_report_size) { |
| 35 DCHECK(top_level_collections); | 35 DCHECK(top_level_collections); |
| 36 DCHECK(max_input_report_size); | 36 DCHECK(max_input_report_size); |
| 37 DCHECK(max_output_report_size); | 37 DCHECK(max_output_report_size); |
| 38 DCHECK(max_feature_report_size); | 38 DCHECK(max_feature_report_size); |
| 39 STLClearObject(top_level_collections); | 39 STLClearObject(top_level_collections); |
| 40 | 40 |
| 41 *has_report_id = false; | 41 *has_report_id = false; |
| 42 *max_input_report_size = 0; | 42 *max_input_report_size = 0; |
| 43 *max_output_report_size = 0; | 43 *max_output_report_size = 0; |
| 44 *max_feature_report_size = 0; | 44 *max_feature_report_size = 0; |
| 45 | 45 |
| 46 // Global tags data: | 46 // Global tags data: |
| 47 HidUsageAndPage::Page current_usage_page = HidUsageAndPage::kPageUndefined; | 47 HidUsageAndPage::Page current_usage_page = HidUsageAndPage::kPageUndefined; |
| 48 uint16_t current_report_count = 0; | 48 size_t current_report_count = 0; |
| 49 uint16_t cached_report_count = 0; | 49 size_t cached_report_count = 0; |
| 50 uint16_t current_report_size = 0; | 50 size_t current_report_size = 0; |
| 51 uint16_t cached_report_size = 0; | 51 size_t cached_report_size = 0; |
| 52 uint16_t current_input_report_size = 0; | 52 size_t current_input_report_size = 0; |
| 53 uint16_t current_output_report_size = 0; | 53 size_t current_output_report_size = 0; |
| 54 uint16_t current_feature_report_size = 0; | 54 size_t current_feature_report_size = 0; |
| 55 | 55 |
| 56 // Local tags data: | 56 // Local tags data: |
| 57 uint16_t current_usage = 0; | 57 uint32_t current_usage = 0; |
| 58 | 58 |
| 59 for (std::vector<linked_ptr<HidReportDescriptorItem> >::const_iterator | 59 for (std::vector<linked_ptr<HidReportDescriptorItem> >::const_iterator |
| 60 items_iter = items().begin(); | 60 items_iter = items().begin(); |
| 61 items_iter != items().end(); | 61 items_iter != items().end(); |
| 62 ++items_iter) { | 62 ++items_iter) { |
| 63 linked_ptr<HidReportDescriptorItem> current_item = *items_iter; | 63 linked_ptr<HidReportDescriptorItem> current_item = *items_iter; |
| 64 | 64 |
| 65 switch (current_item->tag()) { | 65 switch (current_item->tag()) { |
| 66 // Main tags: | 66 // Main tags: |
| 67 case HidReportDescriptorItem::kTagCollection: | 67 case HidReportDescriptorItem::kTagCollection: |
| 68 if (!current_item->parent()) { | 68 if (!current_item->parent() && |
| 69 (current_usage <= std::numeric_limits<uint16_t>::max())) { |
| 69 // This is a top-level collection. | 70 // This is a top-level collection. |
| 70 HidCollectionInfo collection; | 71 HidCollectionInfo collection; |
| 71 collection.usage = HidUsageAndPage(current_usage, current_usage_page); | 72 collection.usage = HidUsageAndPage( |
| 73 static_cast<uint16_t>(current_usage), current_usage_page); |
| 72 top_level_collections->push_back(collection); | 74 top_level_collections->push_back(collection); |
| 73 } | 75 } |
| 74 break; | 76 break; |
| 75 case HidReportDescriptorItem::kTagInput: | 77 case HidReportDescriptorItem::kTagInput: |
| 76 current_input_report_size += current_report_count * current_report_size; | 78 current_input_report_size += current_report_count * current_report_size; |
| 77 break; | 79 break; |
| 78 case HidReportDescriptorItem::kTagOutput: | 80 case HidReportDescriptorItem::kTagOutput: |
| 79 current_output_report_size += | 81 current_output_report_size += |
| 80 current_report_count * current_report_size; | 82 current_report_count * current_report_size; |
| 81 break; | 83 break; |
| 82 case HidReportDescriptorItem::kTagFeature: | 84 case HidReportDescriptorItem::kTagFeature: |
| 83 current_feature_report_size += | 85 current_feature_report_size += |
| 84 current_report_count * current_report_size; | 86 current_report_count * current_report_size; |
| 85 break; | 87 break; |
| 86 | 88 |
| 87 // Global tags: | 89 // Global tags: |
| 88 case HidReportDescriptorItem::kTagUsagePage: | 90 case HidReportDescriptorItem::kTagUsagePage: |
| 89 current_usage_page = | 91 current_usage_page = |
| 90 (HidUsageAndPage::Page)current_item->GetShortData(); | 92 static_cast<HidUsageAndPage::Page>(current_item->GetShortData()); |
| 91 break; | 93 break; |
| 92 case HidReportDescriptorItem::kTagReportId: | 94 case HidReportDescriptorItem::kTagReportId: |
| 93 if (top_level_collections->size() > 0) { | 95 if (top_level_collections->size() > 0) { |
| 94 // Store report ID. | 96 // Store report ID. |
| 95 top_level_collections->back().report_ids.insert( | 97 top_level_collections->back().report_ids.insert( |
| 96 current_item->GetShortData()); | 98 current_item->GetShortData()); |
| 97 *has_report_id = true; | 99 *has_report_id = true; |
| 98 | 100 |
| 99 // Update max report sizes. | 101 // Update max report sizes. |
| 100 *max_input_report_size = | 102 *max_input_report_size = |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 *max_feature_report_size = | 150 *max_feature_report_size = |
| 149 std::max(*max_feature_report_size, current_feature_report_size); | 151 std::max(*max_feature_report_size, current_feature_report_size); |
| 150 | 152 |
| 151 // Convert bits into bytes | 153 // Convert bits into bytes |
| 152 *max_input_report_size /= kBitsPerByte; | 154 *max_input_report_size /= kBitsPerByte; |
| 153 *max_output_report_size /= kBitsPerByte; | 155 *max_output_report_size /= kBitsPerByte; |
| 154 *max_feature_report_size /= kBitsPerByte; | 156 *max_feature_report_size /= kBitsPerByte; |
| 155 } | 157 } |
| 156 | 158 |
| 157 } // namespace device | 159 } // namespace device |
| OLD | NEW |