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 #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 <algorithm> | 8 #include <algorithm> |
9 #include <list> | 9 #include <list> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" | 16 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
17 #include "gpu/command_buffer/service/gl_utils.h" | 17 #include "gpu/command_buffer/service/gl_utils.h" |
18 #include "gpu/command_buffer/service/memory_tracking.h" | 18 #include "gpu/command_buffer/service/memory_tracking.h" |
19 #include "gpu/gpu_export.h" | 19 #include "gpu/gpu_export.h" |
| 20 #include "ui/gfx/geometry/rect.h" |
20 #include "ui/gl/gl_image.h" | 21 #include "ui/gl/gl_image.h" |
21 | 22 |
22 namespace gpu { | 23 namespace gpu { |
23 namespace gles2 { | 24 namespace gles2 { |
24 | 25 |
25 class GLES2Decoder; | 26 class GLES2Decoder; |
26 struct ContextState; | 27 struct ContextState; |
27 struct DecoderFramebufferState; | 28 struct DecoderFramebufferState; |
28 class Display; | 29 class Display; |
29 class ErrorState; | 30 class ErrorState; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 86 } |
86 | 87 |
87 GLint base_level() const { | 88 GLint base_level() const { |
88 return base_level_; | 89 return base_level_; |
89 } | 90 } |
90 | 91 |
91 GLint max_level() const { | 92 GLint max_level() const { |
92 return max_level_; | 93 return max_level_; |
93 } | 94 } |
94 | 95 |
95 int num_uncleared_mips() const { | |
96 return num_uncleared_mips_; | |
97 } | |
98 | |
99 uint32 estimated_size() const { | 96 uint32 estimated_size() const { |
100 return estimated_size_; | 97 return estimated_size_; |
101 } | 98 } |
102 | 99 |
103 bool CanRenderTo() const { | 100 bool CanRenderTo() const { |
104 return target_ != GL_TEXTURE_EXTERNAL_OES; | 101 return target_ != GL_TEXTURE_EXTERNAL_OES; |
105 } | 102 } |
106 | 103 |
107 // The service side OpenGL id of the texture. | 104 // The service side OpenGL id of the texture. |
108 GLuint service_id() const { | 105 GLuint service_id() const { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 172 } |
176 | 173 |
177 void SetImmutable(bool immutable) { | 174 void SetImmutable(bool immutable) { |
178 immutable_ = immutable; | 175 immutable_ = immutable; |
179 } | 176 } |
180 | 177 |
181 bool IsImmutable() const { | 178 bool IsImmutable() const { |
182 return immutable_; | 179 return immutable_; |
183 } | 180 } |
184 | 181 |
| 182 // Get the cleared rectangle for a particular level. Returns an empty |
| 183 // rectangle if level does not exist. |
| 184 gfx::Rect GetLevelClearedRect(GLenum target, GLint level) const; |
| 185 |
185 // Whether a particular level/face is cleared. | 186 // Whether a particular level/face is cleared. |
186 bool IsLevelCleared(GLenum target, GLint level) const; | 187 bool IsLevelCleared(GLenum target, GLint level) const; |
187 | 188 |
188 // Whether the texture has been defined | 189 // Whether the texture has been defined |
189 bool IsDefined() const { | 190 bool IsDefined() const { |
190 return estimated_size() > 0; | 191 return estimated_size() > 0; |
191 } | 192 } |
192 | 193 |
193 // Initialize TEXTURE_MAX_ANISOTROPY to 1 if we haven't done so yet. | 194 // Initialize TEXTURE_MAX_ANISOTROPY to 1 if we haven't done so yet. |
194 void InitTextureMaxAnisotropyIfNeeded(GLenum target); | 195 void InitTextureMaxAnisotropyIfNeeded(GLenum target); |
(...skipping 25 matching lines...) Expand all Loading... |
220 CAN_RENDER_ALWAYS, | 221 CAN_RENDER_ALWAYS, |
221 CAN_RENDER_NEVER, | 222 CAN_RENDER_NEVER, |
222 CAN_RENDER_ONLY_IF_NPOT | 223 CAN_RENDER_ONLY_IF_NPOT |
223 }; | 224 }; |
224 | 225 |
225 struct LevelInfo { | 226 struct LevelInfo { |
226 LevelInfo(); | 227 LevelInfo(); |
227 LevelInfo(const LevelInfo& rhs); | 228 LevelInfo(const LevelInfo& rhs); |
228 ~LevelInfo(); | 229 ~LevelInfo(); |
229 | 230 |
230 bool cleared; | 231 gfx::Rect cleared_rect; |
231 GLenum target; | 232 GLenum target; |
232 GLint level; | 233 GLint level; |
233 GLenum internal_format; | 234 GLenum internal_format; |
234 GLsizei width; | 235 GLsizei width; |
235 GLsizei height; | 236 GLsizei height; |
236 GLsizei depth; | 237 GLsizei depth; |
237 GLint border; | 238 GLint border; |
238 GLenum format; | 239 GLenum format; |
239 GLenum type; | 240 GLenum type; |
240 scoped_refptr<gfx::GLImage> image; | 241 scoped_refptr<gfx::GLImage> image; |
241 uint32 estimated_size; | 242 uint32 estimated_size; |
242 }; | 243 }; |
243 | 244 |
244 struct FaceInfo { | 245 struct FaceInfo { |
245 FaceInfo(); | 246 FaceInfo(); |
246 ~FaceInfo(); | 247 ~FaceInfo(); |
247 | 248 |
248 GLsizei num_mip_levels; | 249 GLsizei num_mip_levels; |
249 std::vector<LevelInfo> level_infos; | 250 std::vector<LevelInfo> level_infos; |
250 }; | 251 }; |
251 | 252 |
252 // Set the info for a particular level. | 253 // Set the info for a particular level. |
253 void SetLevelInfo( | 254 void SetLevelInfo(const FeatureInfo* feature_info, |
254 const FeatureInfo* feature_info, | 255 GLenum target, |
255 GLenum target, | 256 GLint level, |
256 GLint level, | 257 GLenum internal_format, |
257 GLenum internal_format, | 258 GLsizei width, |
258 GLsizei width, | 259 GLsizei height, |
259 GLsizei height, | 260 GLsizei depth, |
260 GLsizei depth, | 261 GLint border, |
261 GLint border, | 262 GLenum format, |
262 GLenum format, | 263 GLenum type, |
263 GLenum type, | 264 const gfx::Rect& cleared_rect); |
264 bool cleared); | |
265 | 265 |
266 // In GLES2 "texture complete" means it has all required mips for filtering | 266 // In GLES2 "texture complete" means it has all required mips for filtering |
267 // down to a 1x1 pixel texture, they are in the correct order, they are all | 267 // down to a 1x1 pixel texture, they are in the correct order, they are all |
268 // the same format. | 268 // the same format. |
269 bool texture_complete() const { | 269 bool texture_complete() const { |
270 return texture_complete_; | 270 return texture_complete_; |
271 } | 271 } |
272 | 272 |
273 // In GLES2 "cube complete" means all 6 faces level 0 are defined, all the | 273 // In GLES2 "cube complete" means all 6 faces level 0 are defined, all the |
274 // same format, all the same dimensions and all width = height. | 274 // same format, all the same dimensions and all width = height. |
275 bool cube_complete() const { | 275 bool cube_complete() const { |
276 return cube_complete_; | 276 return cube_complete_; |
277 } | 277 } |
278 | 278 |
279 // Whether or not this texture is a non-power-of-two texture. | 279 // Whether or not this texture is a non-power-of-two texture. |
280 bool npot() const { | 280 bool npot() const { |
281 return npot_; | 281 return npot_; |
282 } | 282 } |
283 | 283 |
| 284 // Marks a |rect| of a particular level as cleared. |
| 285 void SetLevelClearedRect(GLenum target, |
| 286 GLint level, |
| 287 const gfx::Rect& cleared_rect); |
| 288 |
284 // Marks a particular level as cleared or uncleared. | 289 // Marks a particular level as cleared or uncleared. |
285 void SetLevelCleared(GLenum target, GLint level, bool cleared); | 290 void SetLevelCleared(GLenum target, GLint level, bool cleared); |
286 | 291 |
287 // Updates the cleared flag for this texture by inspecting all the mips. | |
288 void UpdateCleared(); | |
289 | |
290 // Clears any renderable uncleared levels. | 292 // Clears any renderable uncleared levels. |
291 // Returns false if a GL error was generated. | 293 // Returns false if a GL error was generated. |
292 bool ClearRenderableLevels(GLES2Decoder* decoder); | 294 bool ClearRenderableLevels(GLES2Decoder* decoder); |
293 | 295 |
294 // Clears the level. | 296 // Clears the level. |
295 // Returns false if a GL error was generated. | 297 // Returns false if a GL error was generated. |
296 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level); | 298 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level); |
297 | 299 |
298 // Sets a texture parameter. | 300 // Sets a texture parameter. |
299 // TODO(gman): Expand to SetParameteriv,fv | 301 // TODO(gman): Expand to SetParameteriv,fv |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 365 |
364 // Appends a signature for the given level. | 366 // Appends a signature for the given level. |
365 void AddToSignature( | 367 void AddToSignature( |
366 const FeatureInfo* feature_info, | 368 const FeatureInfo* feature_info, |
367 GLenum target, GLint level, std::string* signature) const; | 369 GLenum target, GLint level, std::string* signature) const; |
368 | 370 |
369 void SetMailboxManager(MailboxManager* mailbox_manager); | 371 void SetMailboxManager(MailboxManager* mailbox_manager); |
370 | 372 |
371 // Updates the unsafe textures count in all the managers referencing this | 373 // Updates the unsafe textures count in all the managers referencing this |
372 // texture. | 374 // texture. |
373 void UpdateSafeToRenderFrom(bool cleared); | 375 void UpdateSafeToRenderFrom(); |
374 | |
375 // Updates the uncleared mip count in all the managers referencing this | |
376 // texture. | |
377 void UpdateMipCleared(LevelInfo* info, bool cleared); | |
378 | 376 |
379 // Computes the CanRenderCondition flag. | 377 // Computes the CanRenderCondition flag. |
380 CanRenderCondition GetCanRenderCondition() const; | 378 CanRenderCondition GetCanRenderCondition() const; |
381 | 379 |
382 // Updates the unrenderable texture count in all the managers referencing this | 380 // Updates the unrenderable texture count in all the managers referencing this |
383 // texture. | 381 // texture. |
384 void UpdateCanRenderCondition(); | 382 void UpdateCanRenderCondition(); |
385 | 383 |
386 // Updates the images count in all the managers referencing this | 384 // Updates the images count in all the managers referencing this |
387 // texture. | 385 // texture. |
(...skipping 15 matching lines...) Expand all Loading... |
403 // The single TextureRef that accounts for memory for this texture. Must be | 401 // The single TextureRef that accounts for memory for this texture. Must be |
404 // one of refs_. | 402 // one of refs_. |
405 TextureRef* memory_tracking_ref_; | 403 TextureRef* memory_tracking_ref_; |
406 | 404 |
407 // The id of the texure | 405 // The id of the texure |
408 GLuint service_id_; | 406 GLuint service_id_; |
409 | 407 |
410 // Whether all renderable mips of this texture have been cleared. | 408 // Whether all renderable mips of this texture have been cleared. |
411 bool cleared_; | 409 bool cleared_; |
412 | 410 |
413 int num_uncleared_mips_; | |
414 int num_npot_faces_; | 411 int num_npot_faces_; |
415 | 412 |
416 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. | 413 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. |
417 // Or GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3). | 414 // Or GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3). |
418 GLenum target_; | 415 GLenum target_; |
419 | 416 |
420 // Texture parameters. | 417 // Texture parameters. |
421 GLenum min_filter_; | 418 GLenum min_filter_; |
422 GLenum mag_filter_; | 419 GLenum mag_filter_; |
423 GLenum wrap_r_; | 420 GLenum wrap_r_; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 // Sets the Texture's target | 639 // Sets the Texture's target |
643 // Parameters: | 640 // Parameters: |
644 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 641 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
645 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3) | 642 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3) |
646 // max_levels: The maximum levels this type of target can have. | 643 // max_levels: The maximum levels this type of target can have. |
647 void SetTarget( | 644 void SetTarget( |
648 TextureRef* ref, | 645 TextureRef* ref, |
649 GLenum target); | 646 GLenum target); |
650 | 647 |
651 // Set the info for a particular level in a TexureInfo. | 648 // Set the info for a particular level in a TexureInfo. |
652 void SetLevelInfo( | 649 void SetLevelInfo(TextureRef* ref, |
653 TextureRef* ref, | 650 GLenum target, |
654 GLenum target, | 651 GLint level, |
655 GLint level, | 652 GLenum internal_format, |
656 GLenum internal_format, | 653 GLsizei width, |
657 GLsizei width, | 654 GLsizei height, |
658 GLsizei height, | 655 GLsizei depth, |
659 GLsizei depth, | 656 GLint border, |
660 GLint border, | 657 GLenum format, |
661 GLenum format, | 658 GLenum type, |
662 GLenum type, | 659 const gfx::Rect& cleared_rect); |
663 bool cleared); | |
664 | 660 |
665 // Adapter to call above function. | 661 // Adapter to call above function. |
666 void SetLevelInfoFromParams(TextureRef* ref, | 662 void SetLevelInfoFromParams(TextureRef* ref, |
667 const gpu::AsyncTexImage2DParams& params) { | 663 const gpu::AsyncTexImage2DParams& params) { |
668 SetLevelInfo( | 664 SetLevelInfo(ref, params.target, params.level, params.internal_format, |
669 ref, params.target, params.level, params.internal_format, | 665 params.width, params.height, 1 /* depth */, params.border, |
670 params.width, params.height, 1 /* depth */, | 666 params.format, params.type, |
671 params.border, params.format, | 667 gfx::Rect(params.width, params.height) /* cleared_rect */); |
672 params.type, true /* cleared */); | |
673 } | 668 } |
674 | 669 |
675 Texture* Produce(TextureRef* ref); | 670 Texture* Produce(TextureRef* ref); |
676 | 671 |
677 // Maps an existing texture into the texture manager, at a given client ID. | 672 // Maps an existing texture into the texture manager, at a given client ID. |
678 TextureRef* Consume(GLuint client_id, Texture* texture); | 673 TextureRef* Consume(GLuint client_id, Texture* texture); |
679 | 674 |
| 675 // Sets |rect| of mip as cleared. |
| 676 void SetLevelClearedRect(TextureRef* ref, |
| 677 GLenum target, |
| 678 GLint level, |
| 679 const gfx::Rect& cleared_rect); |
| 680 |
680 // Sets a mip as cleared. | 681 // Sets a mip as cleared. |
681 void SetLevelCleared(TextureRef* ref, GLenum target, | 682 void SetLevelCleared(TextureRef* ref, GLenum target, |
682 GLint level, bool cleared); | 683 GLint level, bool cleared); |
683 | 684 |
684 // Sets a texture parameter of a Texture | 685 // Sets a texture parameter of a Texture |
685 // Returns GL_NO_ERROR on success. Otherwise the error to generate. | 686 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
686 // TODO(gman): Expand to SetParameteriv,fv | 687 // TODO(gman): Expand to SetParameteriv,fv |
687 void SetParameteri( | 688 void SetParameteri( |
688 const char* function_name, ErrorState* error_state, | 689 const char* function_name, ErrorState* error_state, |
689 TextureRef* ref, GLenum pname, GLint param); | 690 TextureRef* ref, GLenum pname, GLint param); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 } | 733 } |
733 | 734 |
734 bool HaveUnrenderableTextures() const { | 735 bool HaveUnrenderableTextures() const { |
735 return num_unrenderable_textures_ > 0; | 736 return num_unrenderable_textures_ > 0; |
736 } | 737 } |
737 | 738 |
738 bool HaveUnsafeTextures() const { | 739 bool HaveUnsafeTextures() const { |
739 return num_unsafe_textures_ > 0; | 740 return num_unsafe_textures_ > 0; |
740 } | 741 } |
741 | 742 |
742 bool HaveUnclearedMips() const { | |
743 return num_uncleared_mips_ > 0; | |
744 } | |
745 | |
746 bool HaveImages() const { | 743 bool HaveImages() const { |
747 return num_images_ > 0; | 744 return num_images_ > 0; |
748 } | 745 } |
749 | 746 |
750 GLuint black_texture_id(GLenum target) const { | 747 GLuint black_texture_id(GLenum target) const { |
751 switch (target) { | 748 switch (target) { |
752 case GL_SAMPLER_2D: | 749 case GL_SAMPLER_2D: |
753 return black_texture_ids_[kTexture2D]; | 750 return black_texture_ids_[kTexture2D]; |
754 case GL_SAMPLER_CUBE: | 751 case GL_SAMPLER_CUBE: |
755 return black_texture_ids_[kCubeMap]; | 752 return black_texture_ids_[kCubeMap]; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 DecoderTextureState* texture_state, | 852 DecoderTextureState* texture_state, |
856 ErrorState* error_state, | 853 ErrorState* error_state, |
857 DecoderFramebufferState* framebuffer_state, | 854 DecoderFramebufferState* framebuffer_state, |
858 TextureRef* texture_ref, | 855 TextureRef* texture_ref, |
859 const DoTexImageArguments& args); | 856 const DoTexImageArguments& args); |
860 | 857 |
861 void StartTracking(TextureRef* texture); | 858 void StartTracking(TextureRef* texture); |
862 void StopTracking(TextureRef* texture); | 859 void StopTracking(TextureRef* texture); |
863 | 860 |
864 void UpdateSafeToRenderFrom(int delta); | 861 void UpdateSafeToRenderFrom(int delta); |
865 void UpdateUnclearedMips(int delta); | |
866 void UpdateCanRenderCondition(Texture::CanRenderCondition old_condition, | 862 void UpdateCanRenderCondition(Texture::CanRenderCondition old_condition, |
867 Texture::CanRenderCondition new_condition); | 863 Texture::CanRenderCondition new_condition); |
868 void UpdateNumImages(int delta); | 864 void UpdateNumImages(int delta); |
869 void IncFramebufferStateChangeCount(); | 865 void IncFramebufferStateChangeCount(); |
870 | 866 |
871 GLenum AdjustTexFormat(GLenum format) const; | 867 GLenum AdjustTexFormat(GLenum format) const; |
872 | 868 |
873 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); | 869 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); |
874 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; | 870 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; |
875 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; | 871 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; |
(...skipping 11 matching lines...) Expand all Loading... |
887 GLsizei max_rectangle_texture_size_; | 883 GLsizei max_rectangle_texture_size_; |
888 GLsizei max_3d_texture_size_; | 884 GLsizei max_3d_texture_size_; |
889 GLint max_levels_; | 885 GLint max_levels_; |
890 GLint max_cube_map_levels_; | 886 GLint max_cube_map_levels_; |
891 GLint max_3d_levels_; | 887 GLint max_3d_levels_; |
892 | 888 |
893 const bool use_default_textures_; | 889 const bool use_default_textures_; |
894 | 890 |
895 int num_unrenderable_textures_; | 891 int num_unrenderable_textures_; |
896 int num_unsafe_textures_; | 892 int num_unsafe_textures_; |
897 int num_uncleared_mips_; | |
898 int num_images_; | 893 int num_images_; |
899 | 894 |
900 // Counts the number of Textures allocated with 'this' as its manager. | 895 // Counts the number of Textures allocated with 'this' as its manager. |
901 // Allows to check no Texture will outlive this. | 896 // Allows to check no Texture will outlive this. |
902 unsigned int texture_count_; | 897 unsigned int texture_count_; |
903 | 898 |
904 bool have_context_; | 899 bool have_context_; |
905 | 900 |
906 // Black (0,0,0,1) textures for when non-renderable textures are used. | 901 // Black (0,0,0,1) textures for when non-renderable textures are used. |
907 // NOTE: There is no corresponding Texture for these textures. | 902 // NOTE: There is no corresponding Texture for these textures. |
(...skipping 17 matching lines...) Expand all Loading... |
925 private: | 920 private: |
926 DecoderTextureState* texture_state_; | 921 DecoderTextureState* texture_state_; |
927 base::TimeTicks begin_time_; | 922 base::TimeTicks begin_time_; |
928 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer); | 923 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer); |
929 }; | 924 }; |
930 | 925 |
931 } // namespace gles2 | 926 } // namespace gles2 |
932 } // namespace gpu | 927 } // namespace gpu |
933 | 928 |
934 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 929 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
OLD | NEW |