1 // Copyright 2020 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 
5 #ifndef DEVICE_VR_PUBLIC_MOJOM_RGBA_TUPLE_F16_H_
6 #define DEVICE_VR_PUBLIC_MOJOM_RGBA_TUPLE_F16_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 namespace device {
12 
13 struct RgbaTupleF16 {
14   // Because C++ does not have a native 16-bit floating point type,
15   // the components are stored as |uint16_t|s.
16   using Component = uint16_t;
17   static constexpr size_t kNumComponents = 4;
18 
RgbaTupleF16RgbaTupleF1619   RgbaTupleF16() : RgbaTupleF16(0, 0, 0, 0) {}
RgbaTupleF16RgbaTupleF1620   RgbaTupleF16(uint16_t red, uint16_t green, uint16_t blue, uint16_t alpha)
21       : components{red, green, blue, alpha} {}
22 
redRgbaTupleF1623   uint16_t red() const { return components[0]; }
set_redRgbaTupleF1624   void set_red(uint16_t red) { components[0] = red; }
greenRgbaTupleF1625   uint16_t green() const { return components[1]; }
set_greenRgbaTupleF1626   void set_green(uint16_t green) { components[1] = green; }
blueRgbaTupleF1627   uint16_t blue() const { return components[2]; }
set_blueRgbaTupleF1628   void set_blue(uint16_t blue) { components[2] = blue; }
alphaRgbaTupleF1629   uint16_t alpha() const { return components[3]; }
set_alphaRgbaTupleF1630   void set_alpha(uint16_t alpha) { components[3] = alpha; }
31 
32   uint16_t components[kNumComponents];
33 };
34 
35 static_assert(sizeof(RgbaTupleF16) == sizeof(RgbaTupleF16::Component) *
36                                           RgbaTupleF16::kNumComponents,
37               "RgbaTupleF16 must be contiguous");
38 
39 }  // namespace device
40 
41 #endif  // DEVICE_VR_PUBLIC_MOJOM_RGBA_TUPLE_F16_H_
42