Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / common / bitfield_helpers.h
blob62841eec5ad8dcd609f3365066f1814dcbb3cd0a
1 // Copyright (c) 2009 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 // This file contains a helper template class used to access bit fields in
6 // unsigned int_ts.
8 #ifndef GPU_COMMAND_BUFFER_COMMON_BITFIELD_HELPERS_H_
9 #define GPU_COMMAND_BUFFER_COMMON_BITFIELD_HELPERS_H_
11 namespace gpu {
13 // Bitfield template class, used to access bit fields in unsigned int_ts.
14 template<int shift, int length> class BitField {
15 public:
16 static const unsigned int kShift = shift;
17 static const unsigned int kLength = length;
18 // the following is really (1<<length)-1 but also work for length == 32
19 // without compiler warning.
20 static const unsigned int kMask = 1U + ((1U << (length-1)) - 1U) * 2U;
22 // Gets the value contained in this field.
23 static unsigned int Get(unsigned int container) {
24 return (container >> kShift) & kMask;
27 // Makes a value that can be or-ed into this field.
28 static unsigned int MakeValue(unsigned int value) {
29 return (value & kMask) << kShift;
32 // Changes the value of this field.
33 static void Set(unsigned int *container, unsigned int field_value) {
34 *container = (*container & ~(kMask << kShift)) | MakeValue(field_value);
38 } // namespace gpu
40 #endif // GPU_COMMAND_BUFFER_COMMON_BITFIELD_HELPERS_H_