| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file is here so other GLES2 related files can have a common set of | 5 // This file is here so other GLES2 related files can have a common set of |
| 6 // includes where appropriate. | 6 // includes where appropriate. |
| 7 | 7 |
| 8 #ifndef GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ | 8 #ifndef GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ |
| 9 #define GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ | 9 #define GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // Does an add checking for overflow. If there was no overflow returns true. | 46 // Does an add checking for overflow. If there was no overflow returns true. |
| 47 inline bool SafeAddInt32(int32_t a, int32_t b, int32_t* dst) { | 47 inline bool SafeAddInt32(int32_t a, int32_t b, int32_t* dst) { |
| 48 DCHECK(dst); | 48 DCHECK(dst); |
| 49 base::CheckedNumeric<int32_t> checked = a; | 49 base::CheckedNumeric<int32_t> checked = a; |
| 50 checked += b; | 50 checked += b; |
| 51 *dst = checked.ValueOrDefault(0); | 51 *dst = checked.ValueOrDefault(0); |
| 52 return checked.IsValid(); | 52 return checked.IsValid(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 struct GLES2_UTILS_EXPORT PixelStoreParams { | |
| 56 PixelStoreParams() | |
| 57 : alignment(4), | |
| 58 row_length(0), | |
| 59 image_height(0), | |
| 60 skip_pixels(0), | |
| 61 skip_rows(0), | |
| 62 skip_images(0) { | |
| 63 } | |
| 64 | |
| 65 int32_t alignment; | |
| 66 int32_t row_length; | |
| 67 int32_t image_height; | |
| 68 int32_t skip_pixels; | |
| 69 int32_t skip_rows; | |
| 70 int32_t skip_images; | |
| 71 }; | |
| 72 | |
| 73 // Utilties for GLES2 support. | 55 // Utilties for GLES2 support. |
| 74 class GLES2_UTILS_EXPORT GLES2Util { | 56 class GLES2_UTILS_EXPORT GLES2Util { |
| 75 public: | 57 public: |
| 76 static const int kNumFaces = 6; | 58 static const int kNumFaces = 6; |
| 77 | 59 |
| 78 // Bits returned by GetChannelsForFormat | 60 // Bits returned by GetChannelsForFormat |
| 79 enum ChannelBits { | 61 enum ChannelBits { |
| 80 kRed = 0x1, | 62 kRed = 0x1, |
| 81 kGreen = 0x2, | 63 kGreen = 0x2, |
| 82 kBlue = 0x4, | 64 kBlue = 0x4, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 98 |
| 117 // Gets the number of values a particular id will return when a glGet | 99 // Gets the number of values a particular id will return when a glGet |
| 118 // function is called. If 0 is returned the id is invalid. | 100 // function is called. If 0 is returned the id is invalid. |
| 119 int GLGetNumValuesReturned(int id) const; | 101 int GLGetNumValuesReturned(int id) const; |
| 120 | 102 |
| 121 // Computes the size of a single group of elements from a format and type pair | 103 // Computes the size of a single group of elements from a format and type pair |
| 122 static uint32_t ComputeImageGroupSize(int format, int type); | 104 static uint32_t ComputeImageGroupSize(int format, int type); |
| 123 | 105 |
| 124 // Computes the size of an image row including alignment padding | 106 // Computes the size of an image row including alignment padding |
| 125 static bool ComputeImagePaddedRowSize( | 107 static bool ComputeImagePaddedRowSize( |
| 126 int width, int format, int type, int alignment, | 108 int width, int format, int type, int unpack_alignment, |
| 127 uint32_t* padded_row_size); | 109 uint32_t* padded_row_size); |
| 128 | 110 |
| 129 // Computes the size of image data for TexImage2D and TexSubImage2D. | 111 // Computes the size of image data for TexImage2D and TexSubImage2D. |
| 130 // Optionally the unpadded and padded row sizes can be returned. | 112 // Optionally the unpadded and padded row sizes can be returned. If height < 2 |
| 113 // then the padded_row_size will be the same as the unpadded_row_size since |
| 114 // padding is not necessary. |
| 131 static bool ComputeImageDataSizes( | 115 static bool ComputeImageDataSizes( |
| 132 int width, int height, int depth, int format, int type, | 116 int width, int height, int depth, int format, int type, |
| 133 int alignment, uint32_t* size, uint32_t* opt_unpadded_row_size, | 117 int unpack_alignment, uint32_t* size, uint32_t* unpadded_row_size, |
| 134 uint32_t* opt_padded_row_size); | 118 uint32_t* padded_row_size); |
| 135 | |
| 136 // Similar to the above function, but taking into consideration all ES3 | |
| 137 // pixel pack/unpack parameters. | |
| 138 // Optionally the skipped bytes in the beginning can be returned. | |
| 139 // Note the returned |size| does NOT include |skip_size|. | |
| 140 // TODO(zmo): merging ComputeImageDataSize and ComputeImageDataSizeES3. | |
| 141 static bool ComputeImageDataSizesES3( | |
| 142 int width, int height, int depth, int format, int type, | |
| 143 const PixelStoreParams& params, | |
| 144 uint32_t* size, uint32_t* opt_unpadded_row_size, | |
| 145 uint32_t* opt_padded_row_size, uint32_t* opt_skip_size); | |
| 146 | 119 |
| 147 static size_t RenderbufferBytesPerPixel(int format); | 120 static size_t RenderbufferBytesPerPixel(int format); |
| 148 | 121 |
| 149 // Return the element's number of bytes. | 122 // Return the element's number of bytes. |
| 150 // For example, GL_FLOAT_MAT3 returns sizeof(GLfloat). | 123 // For example, GL_FLOAT_MAT3 returns sizeof(GLfloat). |
| 151 static uint32_t GetElementSizeForUniformType(int type); | 124 static uint32_t GetElementSizeForUniformType(int type); |
| 152 // Return the number of elements. | 125 // Return the number of elements. |
| 153 // For example, GL_FLOAT_MAT3 returns 9. | 126 // For example, GL_FLOAT_MAT3 returns 9. |
| 154 static uint32_t GetElementCountForUniformType(int type); | 127 static uint32_t GetElementCountForUniformType(int type); |
| 155 | 128 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 static bool IsSignedIntegerFormat(uint32_t internal_format); | 185 static bool IsSignedIntegerFormat(uint32_t internal_format); |
| 213 static bool IsIntegerFormat(uint32_t internal_format); | 186 static bool IsIntegerFormat(uint32_t internal_format); |
| 214 static bool IsFloatFormat(uint32_t internal_format); | 187 static bool IsFloatFormat(uint32_t internal_format); |
| 215 | 188 |
| 216 #include "../common/gles2_cmd_utils_autogen.h" | 189 #include "../common/gles2_cmd_utils_autogen.h" |
| 217 | 190 |
| 218 private: | 191 private: |
| 219 static std::string GetQualifiedEnumString( | 192 static std::string GetQualifiedEnumString( |
| 220 const EnumToString* table, size_t count, uint32_t value); | 193 const EnumToString* table, size_t count, uint32_t value); |
| 221 | 194 |
| 222 static bool ComputeImageRowSizeHelper( | |
| 223 int width, uint32 bytes_per_group, int alignment, | |
| 224 uint32* rt_unpadded_row_size, uint32* rt_padded_row_size); | |
| 225 | |
| 226 static const EnumToString* const enum_to_string_table_; | 195 static const EnumToString* const enum_to_string_table_; |
| 227 static const size_t enum_to_string_table_len_; | 196 static const size_t enum_to_string_table_len_; |
| 228 | 197 |
| 229 int num_compressed_texture_formats_; | 198 int num_compressed_texture_formats_; |
| 230 int num_shader_binary_formats_; | 199 int num_shader_binary_formats_; |
| 231 }; | 200 }; |
| 232 | 201 |
| 233 class GLES2_UTILS_EXPORT GLSLArrayName { | 202 class GLES2_UTILS_EXPORT GLSLArrayName { |
| 234 public: | 203 public: |
| 235 explicit GLSLArrayName(const std::string& name); | 204 explicit GLSLArrayName(const std::string& name); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 bool fail_if_major_perf_caveat; | 249 bool fail_if_major_perf_caveat; |
| 281 bool lose_context_when_out_of_memory; | 250 bool lose_context_when_out_of_memory; |
| 282 ContextType context_type; | 251 ContextType context_type; |
| 283 }; | 252 }; |
| 284 | 253 |
| 285 } // namespace gles2 | 254 } // namespace gles2 |
| 286 } // namespace gpu | 255 } // namespace gpu |
| 287 | 256 |
| 288 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ | 257 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ |
| 289 | 258 |
| OLD | NEW |