| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 // This file contains a helper template class used to access bit fields in | 33 // This file contains a helper template class used to access bit fields in |
| 34 // unsigned int_ts. | 34 // unsigned int_ts. |
| 35 | 35 |
| 36 #ifndef GPU_COMMAND_BUFFER_COMMON_CROSS_BITFIELD_HELPERS_H_ | 36 #ifndef GPU_COMMAND_BUFFER_COMMON_BITFIELD_HELPERS_H_ |
| 37 #define GPU_COMMAND_BUFFER_COMMON_CROSS_BITFIELD_HELPERS_H_ | 37 #define GPU_COMMAND_BUFFER_COMMON_BITFIELD_HELPERS_H_ |
| 38 | 38 |
| 39 namespace command_buffer { | 39 namespace gpu { |
| 40 | 40 |
| 41 // Bitfield template class, used to access bit fields in unsigned int_ts. | 41 // Bitfield template class, used to access bit fields in unsigned int_ts. |
| 42 template<int shift, int length> class BitField { | 42 template<int shift, int length> class BitField { |
| 43 public: | 43 public: |
| 44 static const unsigned int kShift = shift; | 44 static const unsigned int kShift = shift; |
| 45 static const unsigned int kLength = length; | 45 static const unsigned int kLength = length; |
| 46 // the following is really (1<<length)-1 but also work for length == 32 | 46 // the following is really (1<<length)-1 but also work for length == 32 |
| 47 // without compiler warning. | 47 // without compiler warning. |
| 48 static const unsigned int kMask = 1U + ((1U << (length-1)) - 1U) * 2U; | 48 static const unsigned int kMask = 1U + ((1U << (length-1)) - 1U) * 2U; |
| 49 | 49 |
| 50 // Gets the value contained in this field. | 50 // Gets the value contained in this field. |
| 51 static unsigned int Get(unsigned int container) { | 51 static unsigned int Get(unsigned int container) { |
| 52 return (container >> kShift) & kMask; | 52 return (container >> kShift) & kMask; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Makes a value that can be or-ed into this field. | 55 // Makes a value that can be or-ed into this field. |
| 56 static unsigned int MakeValue(unsigned int value) { | 56 static unsigned int MakeValue(unsigned int value) { |
| 57 return (value & kMask) << kShift; | 57 return (value & kMask) << kShift; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Changes the value of this field. | 60 // Changes the value of this field. |
| 61 static void Set(unsigned int *container, unsigned int field_value) { | 61 static void Set(unsigned int *container, unsigned int field_value) { |
| 62 *container = (*container & ~(kMask << kShift)) | MakeValue(field_value); | 62 *container = (*container & ~(kMask << kShift)) | MakeValue(field_value); |
| 63 } | 63 } |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 } // namespace command_buffer | 66 } // namespace gpu |
| 67 | 67 |
| 68 #endif // GPU_COMMAND_BUFFER_COMMON_CROSS_BITFIELD_HELPERS_H_ | 68 #endif // GPU_COMMAND_BUFFER_COMMON_BITFIELD_HELPERS_H_ |
| OLD | NEW |