OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 service_id_ = 0; | 199 service_id_ = 0; |
200 deleted_ = true; | 200 deleted_ = true; |
201 } | 201 } |
202 | 202 |
203 bool NeedsMips() const { | 203 bool NeedsMips() const { |
204 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; | 204 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; |
205 } | 205 } |
206 | 206 |
207 // Sets the TextureInfo's target | 207 // Sets the TextureInfo's target |
208 // Parameters: | 208 // Parameters: |
209 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 209 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or |
| 210 // GL_TEXTURE_EXTERNAL_OES |
210 // max_levels: The maximum levels this type of target can have. | 211 // max_levels: The maximum levels this type of target can have. |
211 void SetTarget(GLenum target, GLint max_levels) { | 212 void SetTarget(GLenum target, GLint max_levels); |
212 DCHECK_EQ(0u, target_); // you can only set this once. | |
213 target_ = target; | |
214 size_t num_faces = (target == GL_TEXTURE_2D) ? 1 : 6; | |
215 level_infos_.resize(num_faces); | |
216 for (size_t ii = 0; ii < num_faces; ++ii) { | |
217 level_infos_[ii].resize(max_levels); | |
218 } | |
219 } | |
220 | 213 |
221 // Update info about this texture. | 214 // Update info about this texture. |
222 void Update(const FeatureInfo* feature_info); | 215 void Update(const FeatureInfo* feature_info); |
223 | 216 |
224 // Info about each face and level of texture. | 217 // Info about each face and level of texture. |
225 std::vector<std::vector<LevelInfo> > level_infos_; | 218 std::vector<std::vector<LevelInfo> > level_infos_; |
226 | 219 |
227 // The id of the texure | 220 // The id of the texure |
228 GLuint service_id_; | 221 GLuint service_id_; |
229 | 222 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 bool owned_; | 255 bool owned_; |
263 | 256 |
264 DISALLOW_COPY_AND_ASSIGN(TextureInfo); | 257 DISALLOW_COPY_AND_ASSIGN(TextureInfo); |
265 }; | 258 }; |
266 | 259 |
267 TextureManager(GLsizei max_texture_size, | 260 TextureManager(GLsizei max_texture_size, |
268 GLsizei max_cube_map_texture_size); | 261 GLsizei max_cube_map_texture_size); |
269 ~TextureManager(); | 262 ~TextureManager(); |
270 | 263 |
271 // Init the texture manager. | 264 // Init the texture manager. |
272 bool Initialize(); | 265 bool Initialize(const FeatureInfo* feature_info); |
273 | 266 |
274 // Must call before destruction. | 267 // Must call before destruction. |
275 void Destroy(bool have_context); | 268 void Destroy(bool have_context); |
276 | 269 |
277 // Returns the maximum number of levels. | 270 // Returns the maximum number of levels. |
278 GLint MaxLevelsForTarget(GLenum target) const { | 271 GLint MaxLevelsForTarget(GLenum target) const { |
279 return (target == GL_TEXTURE_2D) ? max_levels_ : max_cube_map_levels_; | 272 switch (target) { |
| 273 case GL_TEXTURE_2D: |
| 274 return max_levels_; |
| 275 case GL_TEXTURE_EXTERNAL_OES: |
| 276 return 1; |
| 277 default: |
| 278 return max_cube_map_levels_; |
| 279 } |
280 } | 280 } |
281 | 281 |
282 // Returns the maximum size. | 282 // Returns the maximum size. |
283 GLsizei MaxSizeForTarget(GLenum target) const { | 283 GLsizei MaxSizeForTarget(GLenum target) const { |
284 return (target == GL_TEXTURE_2D) ? max_texture_size_ : | 284 switch (target) { |
285 max_cube_map_texture_size_; | 285 case GL_TEXTURE_2D: |
| 286 case GL_TEXTURE_EXTERNAL_OES: |
| 287 return max_texture_size_; |
| 288 default: |
| 289 return max_cube_map_texture_size_; |
| 290 } |
286 } | 291 } |
287 | 292 |
288 // Checks if a dimensions are valid for a given target. | 293 // Checks if a dimensions are valid for a given target. |
289 bool ValidForTarget( | 294 bool ValidForTarget( |
290 const FeatureInfo* feature_info, | 295 const FeatureInfo* feature_info, |
291 GLenum target, GLint level, | 296 GLenum target, GLint level, |
292 GLsizei width, GLsizei height, GLsizei depth); | 297 GLsizei width, GLsizei height, GLsizei depth); |
293 | 298 |
294 // Sets the TextureInfo's target | 299 // Sets the TextureInfo's target |
295 // Parameters: | 300 // Parameters: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // Gets the texture info for the given texture. | 338 // Gets the texture info for the given texture. |
334 TextureInfo* GetTextureInfo(GLuint client_id); | 339 TextureInfo* GetTextureInfo(GLuint client_id); |
335 | 340 |
336 // Removes a texture info. | 341 // Removes a texture info. |
337 void RemoveTextureInfo(const FeatureInfo* feature_info, GLuint client_id); | 342 void RemoveTextureInfo(const FeatureInfo* feature_info, GLuint client_id); |
338 | 343 |
339 // Gets a client id for a given service id. | 344 // Gets a client id for a given service id. |
340 bool GetClientId(GLuint service_id, GLuint* client_id) const; | 345 bool GetClientId(GLuint service_id, GLuint* client_id) const; |
341 | 346 |
342 TextureInfo* GetDefaultTextureInfo(GLenum target) { | 347 TextureInfo* GetDefaultTextureInfo(GLenum target) { |
343 return target == GL_TEXTURE_2D ? default_texture_2d_ : | 348 switch (target) { |
344 default_texture_cube_map_; | 349 case GL_TEXTURE_2D: |
| 350 return default_texture_2d_; |
| 351 case GL_TEXTURE_CUBE_MAP: |
| 352 return default_texture_cube_map_; |
| 353 case GL_TEXTURE_EXTERNAL_OES: |
| 354 return default_texture_external_oes_; |
| 355 default: |
| 356 NOTREACHED(); |
| 357 return NULL; |
| 358 } |
345 } | 359 } |
346 | 360 |
347 bool HaveUnrenderableTextures() const { | 361 bool HaveUnrenderableTextures() const { |
348 return num_unrenderable_textures_ > 0; | 362 return num_unrenderable_textures_ > 0; |
349 } | 363 } |
350 | 364 |
351 GLuint black_texture_id(GLenum target) const { | 365 GLuint black_texture_id(GLenum target) const { |
352 return target == GL_SAMPLER_2D ? black_2d_texture_id_ : | 366 switch (target) { |
353 black_cube_texture_id_; | 367 case GL_SAMPLER_2D: |
| 368 return black_2d_texture_id_; |
| 369 case GL_SAMPLER_CUBE: |
| 370 return black_cube_texture_id_; |
| 371 case GL_SAMPLER_EXTERNAL_OES: |
| 372 return black_oes_external_texture_id_; |
| 373 default: |
| 374 NOTREACHED(); |
| 375 return 0; |
| 376 } |
354 } | 377 } |
355 | 378 |
356 private: | 379 private: |
357 // Info for each texture in the system. | 380 // Info for each texture in the system. |
358 typedef base::hash_map<GLuint, TextureInfo::Ref> TextureInfoMap; | 381 typedef base::hash_map<GLuint, TextureInfo::Ref> TextureInfoMap; |
359 TextureInfoMap texture_infos_; | 382 TextureInfoMap texture_infos_; |
360 | 383 |
361 GLsizei max_texture_size_; | 384 GLsizei max_texture_size_; |
362 GLsizei max_cube_map_texture_size_; | 385 GLsizei max_cube_map_texture_size_; |
363 GLint max_levels_; | 386 GLint max_levels_; |
364 GLint max_cube_map_levels_; | 387 GLint max_cube_map_levels_; |
365 | 388 |
366 int num_unrenderable_textures_; | 389 int num_unrenderable_textures_; |
367 | 390 |
368 // Black (0,0,0,1) textures for when non-renderable textures are used. | 391 // Black (0,0,0,1) textures for when non-renderable textures are used. |
369 // NOTE: There is no corresponding TextureInfo for these textures. | 392 // NOTE: There is no corresponding TextureInfo for these textures. |
370 // TextureInfos are only for textures the client side can access. | 393 // TextureInfos are only for textures the client side can access. |
371 GLuint black_2d_texture_id_; | 394 GLuint black_2d_texture_id_; |
372 GLuint black_cube_texture_id_; | 395 GLuint black_cube_texture_id_; |
| 396 GLuint black_oes_external_texture_id_; |
373 | 397 |
374 // The default textures for each target (texture name = 0) | 398 // The default textures for each target (texture name = 0) |
375 TextureInfo::Ref default_texture_2d_; | 399 TextureInfo::Ref default_texture_2d_; |
376 TextureInfo::Ref default_texture_cube_map_; | 400 TextureInfo::Ref default_texture_cube_map_; |
| 401 TextureInfo::Ref default_texture_external_oes_; |
377 | 402 |
378 DISALLOW_COPY_AND_ASSIGN(TextureManager); | 403 DISALLOW_COPY_AND_ASSIGN(TextureManager); |
379 }; | 404 }; |
380 | 405 |
381 } // namespace gles2 | 406 } // namespace gles2 |
382 } // namespace gpu | 407 } // namespace gpu |
383 | 408 |
384 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 409 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
OLD | NEW |