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* unpadded_row_size, |
118 uint32_t* padded_row_size); | 134 uint32_t* padded_row_size); |
119 | 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. | |
Ken Russell (switch to Gerrit)
2015/12/09 00:05:50
How are they optionally returned? All of the outgo
Zhenyao Mo
2015/12/09 00:27:57
They are optional in the sense they can be nullptr
| |
139 // Note the returned |size| does NOT include |skip_size|. | |
140 static bool ComputeImageDataSizes( | |
141 int width, int height, int depth, int format, int type, | |
142 const PixelStoreParams& params, | |
143 uint32_t* size, uint32_t* unpadded_row_size, | |
144 uint32_t* padded_row_size, uint32_t* skip_size); | |
145 | |
120 static size_t RenderbufferBytesPerPixel(int format); | 146 static size_t RenderbufferBytesPerPixel(int format); |
121 | 147 |
122 // Return the element's number of bytes. | 148 // Return the element's number of bytes. |
123 // For example, GL_FLOAT_MAT3 returns sizeof(GLfloat). | 149 // For example, GL_FLOAT_MAT3 returns sizeof(GLfloat). |
124 static uint32_t GetElementSizeForUniformType(int type); | 150 static uint32_t GetElementSizeForUniformType(int type); |
125 // Return the number of elements. | 151 // Return the number of elements. |
126 // For example, GL_FLOAT_MAT3 returns 9. | 152 // For example, GL_FLOAT_MAT3 returns 9. |
127 static uint32_t GetElementCountForUniformType(int type); | 153 static uint32_t GetElementCountForUniformType(int type); |
128 | 154 |
129 static size_t GetGLTypeSizeForTexturesAndBuffers(uint32_t type); | 155 static size_t GetGLTypeSizeForTexturesAndBuffers(uint32_t type); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 static bool IsSignedIntegerFormat(uint32_t internal_format); | 211 static bool IsSignedIntegerFormat(uint32_t internal_format); |
186 static bool IsIntegerFormat(uint32_t internal_format); | 212 static bool IsIntegerFormat(uint32_t internal_format); |
187 static bool IsFloatFormat(uint32_t internal_format); | 213 static bool IsFloatFormat(uint32_t internal_format); |
188 | 214 |
189 #include "../common/gles2_cmd_utils_autogen.h" | 215 #include "../common/gles2_cmd_utils_autogen.h" |
190 | 216 |
191 private: | 217 private: |
192 static std::string GetQualifiedEnumString( | 218 static std::string GetQualifiedEnumString( |
193 const EnumToString* table, size_t count, uint32_t value); | 219 const EnumToString* table, size_t count, uint32_t value); |
194 | 220 |
221 static bool ComputeImageRowSizeHelper( | |
222 int width, uint32 bytes_per_group, int alignment, | |
223 uint32* rt_unpadded_row_size, uint32* rt_padded_row_size); | |
224 | |
195 static const EnumToString* const enum_to_string_table_; | 225 static const EnumToString* const enum_to_string_table_; |
196 static const size_t enum_to_string_table_len_; | 226 static const size_t enum_to_string_table_len_; |
197 | 227 |
198 int num_compressed_texture_formats_; | 228 int num_compressed_texture_formats_; |
199 int num_shader_binary_formats_; | 229 int num_shader_binary_formats_; |
200 }; | 230 }; |
201 | 231 |
202 class GLES2_UTILS_EXPORT GLSLArrayName { | 232 class GLES2_UTILS_EXPORT GLSLArrayName { |
203 public: | 233 public: |
204 explicit GLSLArrayName(const std::string& name); | 234 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; | 279 bool fail_if_major_perf_caveat; |
250 bool lose_context_when_out_of_memory; | 280 bool lose_context_when_out_of_memory; |
251 ContextType context_type; | 281 ContextType context_type; |
252 }; | 282 }; |
253 | 283 |
254 } // namespace gles2 | 284 } // namespace gles2 |
255 } // namespace gpu | 285 } // namespace gpu |
256 | 286 |
257 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ | 287 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ |
258 | 288 |
OLD | NEW |