Add common GLFence::IsSupported() check
[chromium-blink-merge.git] / device / hid / hid_report_descriptor.cc
blobf2cb0f4901f10419b16079c372e2391d7d4bd40b
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
3 // found in the LICENSE file.
5 #include "device/hid/hid_report_descriptor.h"
7 #include "base/stl_util.h"
9 namespace device {
11 HidReportDescriptor::HidReportDescriptor(const uint8_t* bytes, size_t size) {
12 size_t header_index = 0;
13 HidReportDescriptorItem* item = NULL;
14 while (header_index < size) {
15 item = new HidReportDescriptorItem(&bytes[header_index], item);
16 items_.push_back(linked_ptr<HidReportDescriptorItem>(item));
17 header_index += item->GetSize();
21 HidReportDescriptor::~HidReportDescriptor() {}
23 void HidReportDescriptor::GetTopLevelCollections(
24 std::vector<HidUsageAndPage>* topLevelCollections) {
25 DCHECK(topLevelCollections);
26 STLClearObject(topLevelCollections);
28 for (std::vector<linked_ptr<HidReportDescriptorItem> >::const_iterator
29 items_iter = items().begin();
30 items_iter != items().end();
31 ++items_iter) {
32 linked_ptr<HidReportDescriptorItem> item = *items_iter;
34 bool isTopLevelCollection =
35 item->tag() == HidReportDescriptorItem::kTagCollection &&
36 item->parent() == NULL;
38 if (isTopLevelCollection) {
39 uint16_t collection_usage = 0;
40 HidUsageAndPage::Page collection_usage_page =
41 HidUsageAndPage::kPageUndefined;
43 HidReportDescriptorItem* usage = item->previous();
44 if (usage && usage->tag() == HidReportDescriptorItem::kTagUsage) {
45 collection_usage = usage->GetShortData();
48 HidReportDescriptorItem* usage_page = usage->previous();
49 if (usage_page &&
50 usage_page->tag() == HidReportDescriptorItem::kTagUsagePage) {
51 collection_usage_page =
52 (HidUsageAndPage::Page)usage_page->GetShortData();
55 topLevelCollections->push_back(
56 HidUsageAndPage(collection_usage, collection_usage_page));
61 } // namespace device