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

Side by Side Diff: gpu/command_buffer/service/texture_manager.h

Issue 1505343003: Updating texture validation to account for sampler objects in ES3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed most of piman@'s feedback. Created 5 years 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
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 #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/feature_info.h" 16 #include "gpu/command_buffer/service/feature_info.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/command_buffer/service/sampler_manager.h"
19 #include "gpu/gpu_export.h" 20 #include "gpu/gpu_export.h"
20 #include "ui/gfx/geometry/rect.h" 21 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gl/gl_image.h" 22 #include "ui/gl/gl_image.h"
22 23
23 namespace gpu { 24 namespace gpu {
24 namespace gles2 { 25 namespace gles2 {
25 26
26 class GLES2Decoder; 27 class GLES2Decoder;
27 struct ContextState; 28 struct ContextState;
28 struct DecoderFramebufferState; 29 struct DecoderFramebufferState;
(...skipping 21 matching lines...) Expand all
50 // Image state is set to COPIED if the contents of the image has been 51 // Image state is set to COPIED if the contents of the image has been
51 // copied to the texture. Sampling from the texture will be equivalent 52 // copied to the texture. Sampling from the texture will be equivalent
52 // to sampling out the image (assuming image has not been changed since 53 // to sampling out the image (assuming image has not been changed since
53 // it was copied). Using the texture as a target for drawing will only 54 // it was copied). Using the texture as a target for drawing will only
54 // modify the texture and not the image. 55 // modify the texture and not the image.
55 COPIED 56 COPIED
56 }; 57 };
57 58
58 explicit Texture(GLuint service_id); 59 explicit Texture(GLuint service_id);
59 60
61 const SamplerState& sampler_state() const {
62 return sampler_state_;
63 }
64
60 GLenum min_filter() const { 65 GLenum min_filter() const {
61 return min_filter_; 66 return sampler_state_.min_filter;
62 } 67 }
63 68
64 GLenum mag_filter() const { 69 GLenum mag_filter() const {
65 return mag_filter_; 70 return sampler_state_.mag_filter;
66 } 71 }
67 72
68 GLenum wrap_r() const { 73 GLenum wrap_r() const {
69 return wrap_r_; 74 return sampler_state_.wrap_r;
70 } 75 }
71 76
72 GLenum wrap_s() const { 77 GLenum wrap_s() const {
73 return wrap_s_; 78 return sampler_state_.wrap_s;
74 } 79 }
75 80
76 GLenum wrap_t() const { 81 GLenum wrap_t() const {
77 return wrap_t_; 82 return sampler_state_.wrap_t;
78 } 83 }
79 84
80 GLenum usage() const { 85 GLenum usage() const {
81 return usage_; 86 return usage_;
82 } 87 }
83 88
84 GLenum compare_func() const { 89 GLenum compare_func() const {
85 return compare_func_; 90 return sampler_state_.compare_func;
86 } 91 }
87 92
88 GLenum compare_mode() const { 93 GLenum compare_mode() const {
89 return compare_mode_; 94 return sampler_state_.compare_mode;
90 } 95 }
91 96
92 GLfloat max_lod() const { 97 GLfloat max_lod() const {
93 return max_lod_; 98 return sampler_state_.max_lod;
94 } 99 }
95 100
96 GLfloat min_lod() const { 101 GLfloat min_lod() const {
97 return min_lod_; 102 return sampler_state_.min_lod;
98 } 103 }
99 104
100 GLint base_level() const { 105 GLint base_level() const {
101 return base_level_; 106 return base_level_;
102 } 107 }
103 108
104 GLint max_level() const { 109 GLint max_level() const {
105 return max_level_; 110 return max_level_;
106 } 111 }
107 112
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 friend class TextureDefinition; 234 friend class TextureDefinition;
230 friend class TextureManager; 235 friend class TextureManager;
231 friend class TextureRef; 236 friend class TextureRef;
232 friend class TextureTestHelper; 237 friend class TextureTestHelper;
233 238
234 ~Texture(); 239 ~Texture();
235 void AddTextureRef(TextureRef* ref); 240 void AddTextureRef(TextureRef* ref);
236 void RemoveTextureRef(TextureRef* ref, bool have_context); 241 void RemoveTextureRef(TextureRef* ref, bool have_context);
237 MemoryTypeTracker* GetMemTracker(); 242 MemoryTypeTracker* GetMemTracker();
238 243
239 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it 244 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it
Ken Russell (switch to Gerrit) 2015/12/14 23:22:44 Comment needs to be updated.
240 // depends on context support for non-power-of-two textures (i.e. will be 245 // depends on context support for non-power-of-two textures (i.e. will be
241 // renderable if NPOT support is in the context, otherwise not, e.g. texture 246 // renderable if NPOT support is in the context, otherwise not, e.g. texture
242 // with a NPOT level). ALWAYS means it doesn't depend on context features 247 // with a NPOT level). ALWAYS means it doesn't depend on context features
243 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g. 248 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g.
244 // incomplete). 249 // incomplete).
245 enum CanRenderCondition { 250 enum CanRenderCondition {
246 CAN_RENDER_ALWAYS, 251 CAN_RENDER_ALWAYS,
247 CAN_RENDER_NEVER, 252 CAN_RENDER_NEVER,
248 CAN_RENDER_ONLY_IF_NPOT 253 CAN_RENDER_NEEDS_VALIDATION,
249 }; 254 };
250 255
251 struct LevelInfo { 256 struct LevelInfo {
252 LevelInfo(); 257 LevelInfo();
253 LevelInfo(const LevelInfo& rhs); 258 LevelInfo(const LevelInfo& rhs);
254 ~LevelInfo(); 259 ~LevelInfo();
255 260
256 gfx::Rect cleared_rect; 261 gfx::Rect cleared_rect;
257 GLenum target; 262 GLenum target;
258 GLint level; 263 GLint level;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Returns GL_NO_ERROR on success. Otherwise the error to generate. 338 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
334 GLenum SetParameteri( 339 GLenum SetParameteri(
335 const FeatureInfo* feature_info, GLenum pname, GLint param); 340 const FeatureInfo* feature_info, GLenum pname, GLint param);
336 GLenum SetParameterf( 341 GLenum SetParameterf(
337 const FeatureInfo* feature_info, GLenum pname, GLfloat param); 342 const FeatureInfo* feature_info, GLenum pname, GLfloat param);
338 343
339 // Makes each of the mip levels as though they were generated. 344 // Makes each of the mip levels as though they were generated.
340 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); 345 bool MarkMipmapsGenerated(const FeatureInfo* feature_info);
341 346
342 bool NeedsMips() const { 347 bool NeedsMips() const {
343 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; 348 return sampler_state_.min_filter != GL_NEAREST &&
349 sampler_state_.min_filter != GL_LINEAR;
344 } 350 }
345 351
346 // True if this texture meets all the GLES2 criteria for rendering. 352 // True if this texture meets all the GLES2 criteria for rendering.
347 // See section 3.8.2 of the GLES2 spec. 353 // See section 3.8.2 of the GLES2 spec.
348 bool CanRender(const FeatureInfo* feature_info) const; 354 bool CanRender(const FeatureInfo* feature_info) const;
355 bool CanRenderWithSampler(const FeatureInfo* feature_info,
356 const SamplerState& sampler_state) const;
349 357
350 // Returns true if mipmaps can be generated by GL. 358 // Returns true if mipmaps can be generated by GL.
351 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; 359 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const;
352 360
353 // Returns true if any of the texture dimensions are not a power of two. 361 // Returns true if any of the texture dimensions are not a power of two.
354 static bool TextureIsNPOT(GLsizei width, GLsizei height, GLsizei depth); 362 static bool TextureIsNPOT(GLsizei width, GLsizei height, GLsizei depth);
355 363
356 // Returns true if texture face is complete relative to the first face. 364 // Returns true if texture face is complete relative to the first face.
357 static bool TextureFaceComplete(const Texture::LevelInfo& first_face, 365 static bool TextureFaceComplete(const Texture::LevelInfo& first_face,
358 size_t face_index, 366 size_t face_index,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 bool cleared_; 453 bool cleared_;
446 454
447 int num_uncleared_mips_; 455 int num_uncleared_mips_;
448 int num_npot_faces_; 456 int num_npot_faces_;
449 457
450 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. 458 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
451 // Or GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3). 459 // Or GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3).
452 GLenum target_; 460 GLenum target_;
453 461
454 // Texture parameters. 462 // Texture parameters.
455 GLenum min_filter_; 463 SamplerState sampler_state_;
456 GLenum mag_filter_;
457 GLenum wrap_r_;
458 GLenum wrap_s_;
459 GLenum wrap_t_;
460 GLenum usage_; 464 GLenum usage_;
461 GLenum compare_func_;
462 GLenum compare_mode_;
463 GLfloat max_lod_;
464 GLfloat min_lod_;
465 GLint base_level_; 465 GLint base_level_;
466 GLint max_level_; 466 GLint max_level_;
467 467
468 // The maximum level that has been set. 468 // The maximum level that has been set.
469 GLint max_level_set_; 469 GLint max_level_set_;
470 470
471 // Whether or not this texture is "texture complete" 471 // Whether or not this texture is "texture complete"
472 bool texture_complete_; 472 bool texture_complete_;
473 473
474 // Whether mip levels have changed and should be reverified. 474 // Whether mip levels have changed and should be reverified.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 bool ValidForTarget( 671 bool ValidForTarget(
672 GLenum target, GLint level, 672 GLenum target, GLint level,
673 GLsizei width, GLsizei height, GLsizei depth); 673 GLsizei width, GLsizei height, GLsizei depth);
674 674
675 // True if this texture meets all the GLES2 criteria for rendering. 675 // True if this texture meets all the GLES2 criteria for rendering.
676 // See section 3.8.2 of the GLES2 spec. 676 // See section 3.8.2 of the GLES2 spec.
677 bool CanRender(const TextureRef* ref) const { 677 bool CanRender(const TextureRef* ref) const {
678 return ref->texture()->CanRender(feature_info_.get()); 678 return ref->texture()->CanRender(feature_info_.get());
679 } 679 }
680 680
681 bool CanRenderWithSampler(
682 const TextureRef* ref, const SamplerState& sampler_state) const {
683 return ref->texture()->CanRenderWithSampler(
684 feature_info_.get(), sampler_state);
685 }
686
681 // Returns true if mipmaps can be generated by GL. 687 // Returns true if mipmaps can be generated by GL.
682 bool CanGenerateMipmaps(const TextureRef* ref) const { 688 bool CanGenerateMipmaps(const TextureRef* ref) const {
683 return ref->texture()->CanGenerateMipmaps(feature_info_.get()); 689 return ref->texture()->CanGenerateMipmaps(feature_info_.get());
684 } 690 }
685 691
686 // Sets the Texture's target 692 // Sets the Texture's target
687 // Parameters: 693 // Parameters:
688 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP 694 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP
689 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3) 695 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3)
690 // max_levels: The maximum levels this type of target can have. 696 // max_levels: The maximum levels this type of target can have.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 case GL_TEXTURE_EXTERNAL_OES: 773 case GL_TEXTURE_EXTERNAL_OES:
768 return default_textures_[kExternalOES].get(); 774 return default_textures_[kExternalOES].get();
769 case GL_TEXTURE_RECTANGLE_ARB: 775 case GL_TEXTURE_RECTANGLE_ARB:
770 return default_textures_[kRectangleARB].get(); 776 return default_textures_[kRectangleARB].get();
771 default: 777 default:
772 NOTREACHED(); 778 NOTREACHED();
773 return NULL; 779 return NULL;
774 } 780 }
775 } 781 }
776 782
777 bool HaveUnrenderableTextures() const {
778 return num_unrenderable_textures_ > 0;
779 }
780
781 bool HaveUnsafeTextures() const { 783 bool HaveUnsafeTextures() const {
782 return num_unsafe_textures_ > 0; 784 return num_unsafe_textures_ > 0;
783 } 785 }
784 786
785 bool HaveUnclearedMips() const { 787 bool HaveUnclearedMips() const {
786 return num_uncleared_mips_ > 0; 788 return num_uncleared_mips_ > 0;
787 } 789 }
788 790
789 bool HaveImages() const { 791 bool HaveImages() const {
790 return num_images_ > 0; 792 return num_images_ > 0;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 GLsizei max_texture_size_; 981 GLsizei max_texture_size_;
980 GLsizei max_cube_map_texture_size_; 982 GLsizei max_cube_map_texture_size_;
981 GLsizei max_rectangle_texture_size_; 983 GLsizei max_rectangle_texture_size_;
982 GLsizei max_3d_texture_size_; 984 GLsizei max_3d_texture_size_;
983 GLint max_levels_; 985 GLint max_levels_;
984 GLint max_cube_map_levels_; 986 GLint max_cube_map_levels_;
985 GLint max_3d_levels_; 987 GLint max_3d_levels_;
986 988
987 const bool use_default_textures_; 989 const bool use_default_textures_;
988 990
989 int num_unrenderable_textures_;
990 int num_unsafe_textures_; 991 int num_unsafe_textures_;
991 int num_uncleared_mips_; 992 int num_uncleared_mips_;
992 int num_images_; 993 int num_images_;
993 994
994 // Counts the number of Textures allocated with 'this' as its manager. 995 // Counts the number of Textures allocated with 'this' as its manager.
995 // Allows to check no Texture will outlive this. 996 // Allows to check no Texture will outlive this.
996 unsigned int texture_count_; 997 unsigned int texture_count_;
997 998
998 bool have_context_; 999 bool have_context_;
999 1000
(...skipping 19 matching lines...) Expand all
1019 private: 1020 private:
1020 DecoderTextureState* texture_state_; 1021 DecoderTextureState* texture_state_;
1021 base::TimeTicks begin_time_; 1022 base::TimeTicks begin_time_;
1022 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer); 1023 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer);
1023 }; 1024 };
1024 1025
1025 } // namespace gles2 1026 } // namespace gles2
1026 } // namespace gpu 1027 } // namespace gpu
1027 1028
1028 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 1029 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698