Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: gpu/command_buffer/common/gles2_cmd_utils.h

Issue 268063002: Remove command_buffer/common/types.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include <stdint.h>
12
11 #include <limits> 13 #include <limits>
12 #include <string> 14 #include <string>
13 #include <vector> 15 #include <vector>
14 16
15 #include "gpu/command_buffer/common/gles2_utils_export.h" 17 #include "gpu/command_buffer/common/gles2_utils_export.h"
16 #include "gpu/command_buffer/common/types.h"
17 18
18 namespace gpu { 19 namespace gpu {
19 namespace gles2 { 20 namespace gles2 {
20 21
21 // Does a multiply and checks for overflow. If the multiply did not overflow 22 // Does a multiply and checks for overflow. If the multiply did not overflow
22 // returns true. 23 // returns true.
23 24
24 // Multiplies 2 32 bit unsigned numbers checking for overflow. 25 // Multiplies 2 32 bit unsigned numbers checking for overflow.
25 // If there was no overflow returns true. 26 // If there was no overflow returns true.
26 inline bool SafeMultiplyUint32(uint32 a, uint32 b, uint32* dst) { 27 inline bool SafeMultiplyUint32(uint32_t a, uint32_t b, uint32_t* dst) {
27 if (b == 0) { 28 if (b == 0) {
28 *dst = 0; 29 *dst = 0;
29 return true; 30 return true;
30 } 31 }
31 uint32 v = a * b; 32 uint32_t v = a * b;
32 if (v / b != a) { 33 if (v / b != a) {
33 *dst = 0; 34 *dst = 0;
34 return false; 35 return false;
35 } 36 }
36 *dst = v; 37 *dst = v;
37 return true; 38 return true;
38 } 39 }
39 40
40 // Does an add checking for overflow. If there was no overflow returns true. 41 // Does an add checking for overflow. If there was no overflow returns true.
41 inline bool SafeAddUint32(uint32 a, uint32 b, uint32* dst) { 42 inline bool SafeAddUint32(uint32_t a, uint32_t b, uint32_t* dst) {
42 if (a + b < a) { 43 if (a + b < a) {
43 *dst = 0; 44 *dst = 0;
44 return false; 45 return false;
45 } 46 }
46 *dst = a + b; 47 *dst = a + b;
47 return true; 48 return true;
48 } 49 }
49 50
50 // Does an add checking for overflow. If there was no overflow returns true. 51 // Does an add checking for overflow. If there was no overflow returns true.
51 inline bool SafeAddInt32(int32 a, int32 b, int32* dst) { 52 inline bool SafeAddInt32(int32_t a, int32_t b, int32_t* dst) {
52 int64 sum64 = static_cast<int64>(a) + b; 53 int64_t sum64 = static_cast<int64_t>(a) + b;
53 int32 sum32 = static_cast<int32>(sum64); 54 int32_t sum32 = static_cast<int32_t>(sum64);
54 bool safe = sum64 == static_cast<int64>(sum32); 55 bool safe = sum64 == static_cast<int64_t>(sum32);
55 *dst = safe ? sum32 : 0; 56 *dst = safe ? sum32 : 0;
56 return safe; 57 return safe;
57 } 58 }
58 59
59 // Return false if |value| is more than a 32 bit integer can represent. 60 // Return false if |value| is more than a 32 bit integer can represent.
60 template<typename T> 61 template<typename T>
61 inline bool FitInt32NonNegative(T value) { 62 inline bool FitInt32NonNegative(T value) {
62 const int32 max = std::numeric_limits<int32>::max(); 63 const int32_t max = std::numeric_limits<int32_t>::max();
63 return (std::numeric_limits<T>::max() <= max || 64 return (std::numeric_limits<T>::max() <= max ||
64 value <= static_cast<T>(max)); 65 value <= static_cast<T>(max));
65 } 66 }
66 67
67 // Utilties for GLES2 support. 68 // Utilties for GLES2 support.
68 class GLES2_UTILS_EXPORT GLES2Util { 69 class GLES2_UTILS_EXPORT GLES2Util {
69 public: 70 public:
70 static const int kNumFaces = 6; 71 static const int kNumFaces = 6;
71 72
72 // Bits returned by GetChannelsForFormat 73 // Bits returned by GetChannelsForFormat
73 enum ChannelBits { 74 enum ChannelBits {
74 kRed = 0x1, 75 kRed = 0x1,
75 kGreen = 0x2, 76 kGreen = 0x2,
76 kBlue = 0x4, 77 kBlue = 0x4,
77 kAlpha = 0x8, 78 kAlpha = 0x8,
78 kDepth = 0x10000, 79 kDepth = 0x10000,
79 kStencil = 0x20000, 80 kStencil = 0x20000,
80 81
81 kRGB = kRed | kGreen | kBlue, 82 kRGB = kRed | kGreen | kBlue,
82 kRGBA = kRGB | kAlpha 83 kRGBA = kRGB | kAlpha
83 }; 84 };
84 85
85 struct EnumToString { 86 struct EnumToString {
86 uint32 value; 87 uint32_t value;
87 const char* name; 88 const char* name;
88 }; 89 };
89 90
90 GLES2Util() 91 GLES2Util()
91 : num_compressed_texture_formats_(0), 92 : num_compressed_texture_formats_(0),
92 num_shader_binary_formats_(0) { 93 num_shader_binary_formats_(0) {
93 } 94 }
94 95
95 int num_compressed_texture_formats() const { 96 int num_compressed_texture_formats() const {
96 return num_compressed_texture_formats_; 97 return num_compressed_texture_formats_;
97 } 98 }
98 99
99 void set_num_compressed_texture_formats(int num_compressed_texture_formats) { 100 void set_num_compressed_texture_formats(int num_compressed_texture_formats) {
100 num_compressed_texture_formats_ = num_compressed_texture_formats; 101 num_compressed_texture_formats_ = num_compressed_texture_formats;
101 } 102 }
102 103
103 int num_shader_binary_formats() const { 104 int num_shader_binary_formats() const {
104 return num_shader_binary_formats_; 105 return num_shader_binary_formats_;
105 } 106 }
106 107
107 void set_num_shader_binary_formats(int num_shader_binary_formats) { 108 void set_num_shader_binary_formats(int num_shader_binary_formats) {
108 num_shader_binary_formats_ = num_shader_binary_formats; 109 num_shader_binary_formats_ = num_shader_binary_formats;
109 } 110 }
110 111
111 // Gets the number of values a particular id will return when a glGet 112 // Gets the number of values a particular id will return when a glGet
112 // function is called. If 0 is returned the id is invalid. 113 // function is called. If 0 is returned the id is invalid.
113 int GLGetNumValuesReturned(int id) const; 114 int GLGetNumValuesReturned(int id) const;
114 115
115 // Computes the size of a single group of elements from a format and type pair 116 // Computes the size of a single group of elements from a format and type pair
116 static uint32 ComputeImageGroupSize(int format, int type); 117 static uint32_t ComputeImageGroupSize(int format, int type);
117 118
118 // Computes the size of an image row including alignment padding 119 // Computes the size of an image row including alignment padding
119 static bool ComputeImagePaddedRowSize( 120 static bool ComputeImagePaddedRowSize(
120 int width, int format, int type, int unpack_alignment, 121 int width, int format, int type, int unpack_alignment,
121 uint32* padded_row_size); 122 uint32_t* padded_row_size);
122 123
123 // Computes the size of image data for TexImage2D and TexSubImage2D. 124 // Computes the size of image data for TexImage2D and TexSubImage2D.
124 // Optionally the unpadded and padded row sizes can be returned. If height < 2 125 // Optionally the unpadded and padded row sizes can be returned. If height < 2
125 // then the padded_row_size will be the same as the unpadded_row_size since 126 // then the padded_row_size will be the same as the unpadded_row_size since
126 // padding is not necessary. 127 // padding is not necessary.
127 static bool ComputeImageDataSizes( 128 static bool ComputeImageDataSizes(
128 int width, int height, int format, int type, int unpack_alignment, 129 int width, int height, int format, int type, int unpack_alignment,
129 uint32* size, uint32* unpadded_row_size, uint32* padded_row_size); 130 uint32_t* size, uint32_t* unpadded_row_size, uint32_t* padded_row_size);
130 131
131 static size_t RenderbufferBytesPerPixel(int format); 132 static size_t RenderbufferBytesPerPixel(int format);
132 133
133 static uint32 GetGLDataTypeSizeForUniforms(int type); 134 static uint32_t GetGLDataTypeSizeForUniforms(int type);
134 135
135 static size_t GetGLTypeSizeForTexturesAndBuffers(uint32 type); 136 static size_t GetGLTypeSizeForTexturesAndBuffers(uint32_t type);
136 137
137 static uint32 GLErrorToErrorBit(uint32 gl_error); 138 static uint32_t GLErrorToErrorBit(uint32_t gl_error);
138 139
139 static uint32 GLErrorBitToGLError(uint32 error_bit); 140 static uint32_t GLErrorBitToGLError(uint32_t error_bit);
140 141
141 static uint32 IndexToGLFaceTarget(int index); 142 static uint32_t IndexToGLFaceTarget(int index);
142 143
143 static uint32 GetPreferredGLReadPixelsFormat(uint32 internal_format); 144 static uint32_t GetPreferredGLReadPixelsFormat(uint32_t internal_format);
144 145
145 static uint32 GetPreferredGLReadPixelsType( 146 static uint32_t GetPreferredGLReadPixelsType(
146 uint32 internal_format, uint32 texture_type); 147 uint32_t internal_format, uint32_t texture_type);
147 148
148 // Returns a bitmask for the channels the given format supports. 149 // Returns a bitmask for the channels the given format supports.
149 // See ChannelBits. 150 // See ChannelBits.
150 static uint32 GetChannelsForFormat(int format); 151 static uint32_t GetChannelsForFormat(int format);
151 152
152 // Returns a bitmask for the channels the given attachment type needs. 153 // Returns a bitmask for the channels the given attachment type needs.
153 static uint32 GetChannelsNeededForAttachmentType( 154 static uint32_t GetChannelsNeededForAttachmentType(
154 int type, uint32 max_color_attachments); 155 int type, uint32_t max_color_attachments);
155 156
156 static bool IsNPOT(uint32 value) { 157 static bool IsNPOT(uint32_t value) {
157 return value > 0 && (value & (value - 1)) != 0; 158 return value > 0 && (value & (value - 1)) != 0;
158 } 159 }
159 160
160 static std::string GetStringEnum(uint32 value); 161 static std::string GetStringEnum(uint32_t value);
161 static std::string GetStringBool(uint32 value); 162 static std::string GetStringBool(uint32_t value);
162 static std::string GetStringError(uint32 value); 163 static std::string GetStringError(uint32_t value);
163 164
164 // Parses a uniform name. 165 // Parses a uniform name.
165 // array_pos: the position of the last '[' character in name. 166 // array_pos: the position of the last '[' character in name.
166 // element_index: the index of the array element specifed in the name. 167 // element_index: the index of the array element specifed in the name.
167 // getting_array: True if name refers to array. 168 // getting_array: True if name refers to array.
168 // returns true of parsing was successful. Returing true does NOT mean 169 // returns true of parsing was successful. Returing true does NOT mean
169 // it's a valid uniform name. On the otherhand, returning false does mean 170 // it's a valid uniform name. On the otherhand, returning false does mean
170 // it's an invalid uniform name. 171 // it's an invalid uniform name.
171 static bool ParseUniformName( 172 static bool ParseUniformName(
172 const std::string& name, 173 const std::string& name,
173 size_t* array_pos, 174 size_t* array_pos,
174 int* element_index, 175 int* element_index,
175 bool* getting_array); 176 bool* getting_array);
176 177
177 #include "../common/gles2_cmd_utils_autogen.h" 178 #include "../common/gles2_cmd_utils_autogen.h"
178 179
179 private: 180 private:
180 static std::string GetQualifiedEnumString( 181 static std::string GetQualifiedEnumString(
181 const EnumToString* table, size_t count, uint32 value); 182 const EnumToString* table, size_t count, uint32_t value);
182 183
183 static const EnumToString* const enum_to_string_table_; 184 static const EnumToString* const enum_to_string_table_;
184 static const size_t enum_to_string_table_len_; 185 static const size_t enum_to_string_table_len_;
185 186
186 int num_compressed_texture_formats_; 187 int num_compressed_texture_formats_;
187 int num_shader_binary_formats_; 188 int num_shader_binary_formats_;
188 }; 189 };
189 190
190 class GLES2_UTILS_EXPORT ContextCreationAttribHelper { 191 class GLES2_UTILS_EXPORT ContextCreationAttribHelper {
191 public: 192 public:
192 ContextCreationAttribHelper(); 193 ContextCreationAttribHelper();
193 194
194 void Serialize(std::vector<int32>* attribs); 195 void Serialize(std::vector<int32_t>* attribs);
195 bool Parse(const std::vector<int32>& attribs); 196 bool Parse(const std::vector<int32_t>& attribs);
196 197
197 // -1 if invalid or unspecified. 198 // -1 if invalid or unspecified.
198 int32 alpha_size_; 199 int32_t alpha_size_;
199 int32 blue_size_; 200 int32_t blue_size_;
200 int32 green_size_; 201 int32_t green_size_;
201 int32 red_size_; 202 int32_t red_size_;
202 int32 depth_size_; 203 int32_t depth_size_;
203 int32 stencil_size_; 204 int32_t stencil_size_;
204 int32 samples_; 205 int32_t samples_;
205 int32 sample_buffers_; 206 int32_t sample_buffers_;
206 bool buffer_preserved_; 207 bool buffer_preserved_;
207 bool share_resources_; 208 bool share_resources_;
208 bool bind_generates_resource_; 209 bool bind_generates_resource_;
209 bool fail_if_major_perf_caveat_; 210 bool fail_if_major_perf_caveat_;
210 bool lose_context_when_out_of_memory_; 211 bool lose_context_when_out_of_memory_;
211 }; 212 };
212 213
213 } // namespace gles2 214 } // namespace gles2
214 } // namespace gpu 215 } // namespace gpu
215 216
216 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ 217 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_
217 218
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698