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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 unpack_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 unpack_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. |
| 139 // Note the returned |size| includes |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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 bool fail_if_major_perf_caveat; | 275 bool fail_if_major_perf_caveat; |
250 bool lose_context_when_out_of_memory; | 276 bool lose_context_when_out_of_memory; |
251 ContextType context_type; | 277 ContextType context_type; |
252 }; | 278 }; |
253 | 279 |
254 } // namespace gles2 | 280 } // namespace gles2 |
255 } // namespace gpu | 281 } // namespace gpu |
256 | 282 |
257 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ | 283 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ |
258 | 284 |
OLD | NEW |