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

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

Powered by Google App Engine
This is Rietveld 408576698