| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Contains various validation functions for the GLES2 service. | 5 // Contains various validation functions for the GLES2 service. |
| 6 | 6 |
| 7 #ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_VALIDATION_H_ | 7 #ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_VALIDATION_H_ |
| 8 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_VALIDATION_H_ | 8 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_VALIDATION_H_ |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <vector> | 11 #include <vector> |
| 12 #define GLES2_GPU_SERVICE 1 | 12 #define GLES2_GPU_SERVICE 1 |
| 13 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 14 | 14 |
| 15 namespace gpu { | 15 namespace gpu { |
| 16 namespace gles2 { | 16 namespace gles2 { |
| 17 | 17 |
| 18 // ValueValidator returns true if a value is valid. | 18 // ValueValidator returns true if a value is valid. |
| 19 template <typename T> | 19 template <typename T> |
| 20 class ValueValidator { | 20 class ValueValidator { |
| 21 public: | 21 public: |
| 22 ValueValidator() {} | 22 ValueValidator() {} |
| 23 | 23 |
| 24 ValueValidator(const T* valid_values, int num_values) { | 24 ValueValidator(const T* valid_values, int num_values) { |
| 25 for (int ii = 0; ii < num_values; ++ii) { | 25 AddValues(valid_values, num_values); |
| 26 AddValue(valid_values[ii]); | |
| 27 } | |
| 28 } | 26 } |
| 29 | 27 |
| 30 void AddValue(const T value) { | 28 void AddValue(const T value) { |
| 31 if (!IsValid(value)) { | 29 if (!IsValid(value)) { |
| 32 valid_values_.push_back(value); | 30 valid_values_.push_back(value); |
| 33 } | 31 } |
| 34 } | 32 } |
| 35 | 33 |
| 34 void AddValues(const T* valid_values, int num_values) { |
| 35 for (int ii = 0; ii < num_values; ++ii) { |
| 36 AddValue(valid_values[ii]); |
| 37 } |
| 38 } |
| 39 |
| 36 bool IsValid(const T value) const { | 40 bool IsValid(const T value) const { |
| 37 return std::find(valid_values_.begin(), valid_values_.end(), value) != | 41 return std::find(valid_values_.begin(), valid_values_.end(), value) != |
| 38 valid_values_.end(); | 42 valid_values_.end(); |
| 39 } | 43 } |
| 40 | 44 |
| 41 const std::vector<T>& GetValues() const { | 45 const std::vector<T>& GetValues() const { |
| 42 return valid_values_; | 46 return valid_values_; |
| 43 } | 47 } |
| 44 | 48 |
| 45 private: | 49 private: |
| 46 std::vector<T> valid_values_; | 50 std::vector<T> valid_values_; |
| 47 }; | 51 }; |
| 48 | 52 |
| 49 struct Validators { | 53 struct Validators { |
| 50 Validators(); | 54 Validators(); |
| 55 |
| 56 void AddES3Values(); |
| 57 |
| 51 #include "gpu/command_buffer/service/gles2_cmd_validation_autogen.h" | 58 #include "gpu/command_buffer/service/gles2_cmd_validation_autogen.h" |
| 52 }; | 59 }; |
| 53 | 60 |
| 54 } // namespace gles2 | 61 } // namespace gles2 |
| 55 } // namespace gpu | 62 } // namespace gpu |
| 56 | 63 |
| 57 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_VALIDATION_H_ | 64 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_VALIDATION_H_ |
| 58 | 65 |
| OLD | NEW |