| 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 |
| 55 // Utilties for GLES2 support. | 73 // Utilties for GLES2 support. |
| 56 class GLES2_UTILS_EXPORT GLES2Util { | 74 class GLES2_UTILS_EXPORT GLES2Util { |
| 57 public: | 75 public: |
| 58 static const int kNumFaces = 6; | 76 static const int kNumFaces = 6; |
| 59 | 77 |
| 60 // Bits returned by GetChannelsForFormat | 78 // Bits returned by GetChannelsForFormat |
| 61 enum ChannelBits { | 79 enum ChannelBits { |
| 62 kRed = 0x1, | 80 kRed = 0x1, |
| 63 kGreen = 0x2, | 81 kGreen = 0x2, |
| 64 kBlue = 0x4, | 82 kBlue = 0x4, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 116 |
| 99 // Gets the number of values a particular id will return when a glGet | 117 // Gets the number of values a particular id will return when a glGet |
| 100 // function is called. If 0 is returned the id is invalid. | 118 // function is called. If 0 is returned the id is invalid. |
| 101 int GLGetNumValuesReturned(int id) const; | 119 int GLGetNumValuesReturned(int id) const; |
| 102 | 120 |
| 103 // Computes the size of a single group of elements from a format and type pair | 121 // Computes the size of a single group of elements from a format and type pair |
| 104 static uint32_t ComputeImageGroupSize(int format, int type); | 122 static uint32_t ComputeImageGroupSize(int format, int type); |
| 105 | 123 |
| 106 // Computes the size of an image row including alignment padding | 124 // Computes the size of an image row including alignment padding |
| 107 static bool ComputeImagePaddedRowSize( | 125 static bool ComputeImagePaddedRowSize( |
| 108 int width, int format, int type, int unpack_alignment, | 126 int width, int format, int type, int alignment, |
| 109 uint32_t* padded_row_size); | 127 uint32_t* padded_row_size); |
| 110 | 128 |
| 111 // Computes the size of image data for TexImage2D and TexSubImage2D. | 129 // Computes the size of image data for TexImage2D and TexSubImage2D. |
| 112 // Optionally the unpadded and padded row sizes can be returned. If height < 2 | 130 // Optionally the unpadded and padded row sizes can be returned. |
| 113 // then the padded_row_size will be the same as the unpadded_row_size since | |
| 114 // padding is not necessary. | |
| 115 static bool ComputeImageDataSizes( | 131 static bool ComputeImageDataSizes( |
| 116 int width, int height, int depth, int format, int type, | 132 int width, int height, int depth, int format, int type, |
| 117 int unpack_alignment, uint32_t* size, uint32_t* unpadded_row_size, | 133 int alignment, uint32_t* size, uint32_t* opt_unpadded_row_size, |
| 118 uint32_t* padded_row_size); | 134 uint32_t* opt_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); |
| 119 | 146 |
| 120 static size_t RenderbufferBytesPerPixel(int format); | 147 static size_t RenderbufferBytesPerPixel(int format); |
| 121 | 148 |
| 122 // Return the element's number of bytes. | 149 // Return the element's number of bytes. |
| 123 // For example, GL_FLOAT_MAT3 returns sizeof(GLfloat). | 150 // For example, GL_FLOAT_MAT3 returns sizeof(GLfloat). |
| 124 static uint32_t GetElementSizeForUniformType(int type); | 151 static uint32_t GetElementSizeForUniformType(int type); |
| 125 // Return the number of elements. | 152 // Return the number of elements. |
| 126 // For example, GL_FLOAT_MAT3 returns 9. | 153 // For example, GL_FLOAT_MAT3 returns 9. |
| 127 static uint32_t GetElementCountForUniformType(int type); | 154 static uint32_t GetElementCountForUniformType(int type); |
| 128 | 155 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 static bool IsSignedIntegerFormat(uint32_t internal_format); | 212 static bool IsSignedIntegerFormat(uint32_t internal_format); |
| 186 static bool IsIntegerFormat(uint32_t internal_format); | 213 static bool IsIntegerFormat(uint32_t internal_format); |
| 187 static bool IsFloatFormat(uint32_t internal_format); | 214 static bool IsFloatFormat(uint32_t internal_format); |
| 188 | 215 |
| 189 #include "../common/gles2_cmd_utils_autogen.h" | 216 #include "../common/gles2_cmd_utils_autogen.h" |
| 190 | 217 |
| 191 private: | 218 private: |
| 192 static std::string GetQualifiedEnumString( | 219 static std::string GetQualifiedEnumString( |
| 193 const EnumToString* table, size_t count, uint32_t value); | 220 const EnumToString* table, size_t count, uint32_t value); |
| 194 | 221 |
| 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 |
| 195 static const EnumToString* const enum_to_string_table_; | 226 static const EnumToString* const enum_to_string_table_; |
| 196 static const size_t enum_to_string_table_len_; | 227 static const size_t enum_to_string_table_len_; |
| 197 | 228 |
| 198 int num_compressed_texture_formats_; | 229 int num_compressed_texture_formats_; |
| 199 int num_shader_binary_formats_; | 230 int num_shader_binary_formats_; |
| 200 }; | 231 }; |
| 201 | 232 |
| 202 class GLES2_UTILS_EXPORT GLSLArrayName { | 233 class GLES2_UTILS_EXPORT GLSLArrayName { |
| 203 public: | 234 public: |
| 204 explicit GLSLArrayName(const std::string& name); | 235 explicit GLSLArrayName(const std::string& name); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 bool fail_if_major_perf_caveat; | 280 bool fail_if_major_perf_caveat; |
| 250 bool lose_context_when_out_of_memory; | 281 bool lose_context_when_out_of_memory; |
| 251 ContextType context_type; | 282 ContextType context_type; |
| 252 }; | 283 }; |
| 253 | 284 |
| 254 } // namespace gles2 | 285 } // namespace gles2 |
| 255 } // namespace gpu | 286 } // namespace gpu |
| 256 | 287 |
| 257 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ | 288 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ |
| 258 | 289 |
| OLD | NEW |