accelerator_ids.h 983 B

123456789101112131415161718192021222324252627282930
  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
  3. // found in the LICENSE file.
  4. #ifndef ASH_ACCELERATORS_ACCELERATOR_IDS_H_
  5. #define ASH_ACCELERATORS_ACCELERATOR_IDS_H_
  6. namespace ash {
  7. // Accelerator ids consist of two parts:
  8. // . Upper 16 bits identifies source (namespace part).
  9. // . Lower 16 supplied from client (local part).
  10. constexpr uint16_t kLocalIdMask = 0xFFFF;
  11. inline uint32_t ComputeAcceleratorId(uint16_t accelerator_namespace,
  12. uint16_t local_id) {
  13. return (accelerator_namespace << 16) | local_id;
  14. }
  15. inline uint16_t GetAcceleratorLocalId(uint32_t accelerator_id) {
  16. return static_cast<uint16_t>(accelerator_id & kLocalIdMask);
  17. }
  18. inline uint16_t GetAcceleratorNamespaceId(uint32_t accelerator_id) {
  19. return static_cast<uint16_t>((accelerator_id >> 16) & kLocalIdMask);
  20. }
  21. } // namespace ash
  22. #endif // ASH_ACCELERATORS_ACCELERATOR_IDS_H_