Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / gpu / command_buffer / service / texture_manager.h
blobbc4c5c8592b5deb41e019022b706c650025df5ab
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
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
8 #include <algorithm>
9 #include <list>
10 #include <set>
11 #include <string>
12 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/containers/hash_tables.h"
15 #include "base/memory/ref_counted.h"
16 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
17 #include "gpu/command_buffer/service/gl_utils.h"
18 #include "gpu/command_buffer/service/memory_tracking.h"
19 #include "gpu/gpu_export.h"
20 #include "ui/gl/gl_image.h"
22 namespace gpu {
23 namespace gles2 {
25 class GLES2Decoder;
26 struct ContextState;
27 struct DecoderFramebufferState;
28 class Display;
29 class ErrorState;
30 class FeatureInfo;
31 class FramebufferManager;
32 class MailboxManager;
33 class TextureManager;
34 class TextureRef;
36 // Info about Textures currently in the system.
37 // This class wraps a real GL texture, keeping track of its meta-data. It is
38 // jointly owned by possibly multiple TextureRef.
39 class GPU_EXPORT Texture {
40 public:
41 explicit Texture(GLuint service_id);
43 GLenum min_filter() const {
44 return min_filter_;
47 GLenum mag_filter() const {
48 return mag_filter_;
51 GLenum wrap_r() const {
52 return wrap_r_;
55 GLenum wrap_s() const {
56 return wrap_s_;
59 GLenum wrap_t() const {
60 return wrap_t_;
63 GLenum usage() const {
64 return usage_;
67 GLenum pool() const {
68 return pool_;
71 GLenum compare_func() const {
72 return compare_func_;
75 GLenum compare_mode() const {
76 return compare_mode_;
79 GLfloat max_lod() const {
80 return max_lod_;
83 GLfloat min_lod() const {
84 return min_lod_;
87 GLint base_level() const {
88 return base_level_;
91 GLint max_level() const {
92 return max_level_;
95 int num_uncleared_mips() const {
96 return num_uncleared_mips_;
99 uint32 estimated_size() const {
100 return estimated_size_;
103 bool CanRenderTo() const {
104 return target_ != GL_TEXTURE_EXTERNAL_OES;
107 // The service side OpenGL id of the texture.
108 GLuint service_id() const {
109 return service_id_;
112 void SetServiceId(GLuint service_id) {
113 DCHECK(service_id);
114 service_id_ = service_id;
117 // Returns the target this texure was first bound to or 0 if it has not
118 // been bound. Once a texture is bound to a specific target it can never be
119 // bound to a different target.
120 GLenum target() const {
121 return target_;
124 bool SafeToRenderFrom() const {
125 return cleared_;
128 // Get the width/height/depth for a particular level. Returns false if level
129 // does not exist.
130 // |depth| is optional and can be nullptr.
131 bool GetLevelSize(
132 GLint target, GLint level,
133 GLsizei* width, GLsizei* height, GLsizei* depth) const;
135 // Get the type of a level. Returns false if level does not exist.
136 bool GetLevelType(
137 GLint target, GLint level, GLenum* type, GLenum* internal_format) const;
139 // Get the image bound to a particular level. Returns NULL if level
140 // does not exist.
141 gfx::GLImage* GetLevelImage(GLint target, GLint level) const;
143 bool HasImages() const {
144 return has_images_;
147 // Returns true of the given dimensions are inside the dimensions of the
148 // level and if the type matches the level.
149 bool ValidForTexture(
150 GLint target,
151 GLint level,
152 GLint xoffset,
153 GLint yoffset,
154 GLint zoffset,
155 GLsizei width,
156 GLsizei height,
157 GLsizei depth,
158 GLenum type) const;
160 bool IsValid() const {
161 return !!target();
164 bool IsAttachedToFramebuffer() const {
165 return framebuffer_attachment_count_ != 0;
168 void AttachToFramebuffer() {
169 ++framebuffer_attachment_count_;
172 void DetachFromFramebuffer() {
173 DCHECK_GT(framebuffer_attachment_count_, 0);
174 --framebuffer_attachment_count_;
177 void SetImmutable(bool immutable) {
178 immutable_ = immutable;
181 bool IsImmutable() const {
182 return immutable_;
185 // Whether a particular level/face is cleared.
186 bool IsLevelCleared(GLenum target, GLint level) const;
188 // Whether the texture has been defined
189 bool IsDefined() const {
190 return estimated_size() > 0;
193 // Initialize TEXTURE_MAX_ANISOTROPY to 1 if we haven't done so yet.
194 void InitTextureMaxAnisotropyIfNeeded(GLenum target);
196 void OnWillModifyPixels();
197 void OnDidModifyPixels();
199 private:
200 friend class MailboxManagerImpl;
201 friend class MailboxManagerSync;
202 friend class MailboxManagerTest;
203 friend class TextureDefinition;
204 friend class TextureManager;
205 friend class TextureRef;
206 friend class TextureTestHelper;
208 ~Texture();
209 void AddTextureRef(TextureRef* ref);
210 void RemoveTextureRef(TextureRef* ref, bool have_context);
211 MemoryTypeTracker* GetMemTracker();
213 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it
214 // depends on context support for non-power-of-two textures (i.e. will be
215 // renderable if NPOT support is in the context, otherwise not, e.g. texture
216 // with a NPOT level). ALWAYS means it doesn't depend on context features
217 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g.
218 // incomplete).
219 enum CanRenderCondition {
220 CAN_RENDER_ALWAYS,
221 CAN_RENDER_NEVER,
222 CAN_RENDER_ONLY_IF_NPOT
225 struct LevelInfo {
226 LevelInfo();
227 LevelInfo(const LevelInfo& rhs);
228 ~LevelInfo();
230 bool cleared;
231 GLenum target;
232 GLint level;
233 GLenum internal_format;
234 GLsizei width;
235 GLsizei height;
236 GLsizei depth;
237 GLint border;
238 GLenum format;
239 GLenum type;
240 scoped_refptr<gfx::GLImage> image;
241 uint32 estimated_size;
244 struct FaceInfo {
245 FaceInfo();
246 ~FaceInfo();
248 GLsizei num_mip_levels;
249 std::vector<LevelInfo> level_infos;
252 // Set the info for a particular level.
253 void SetLevelInfo(
254 const FeatureInfo* feature_info,
255 GLenum target,
256 GLint level,
257 GLenum internal_format,
258 GLsizei width,
259 GLsizei height,
260 GLsizei depth,
261 GLint border,
262 GLenum format,
263 GLenum type,
264 bool cleared);
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
268 // the same format.
269 bool texture_complete() const {
270 return texture_complete_;
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.
275 bool cube_complete() const {
276 return cube_complete_;
279 // Whether or not this texture is a non-power-of-two texture.
280 bool npot() const {
281 return npot_;
284 // Marks a particular level as cleared or uncleared.
285 void SetLevelCleared(GLenum target, GLint level, bool cleared);
287 // Updates the cleared flag for this texture by inspecting all the mips.
288 void UpdateCleared();
290 // Clears any renderable uncleared levels.
291 // Returns false if a GL error was generated.
292 bool ClearRenderableLevels(GLES2Decoder* decoder);
294 // Clears the level.
295 // Returns false if a GL error was generated.
296 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level);
298 // Sets a texture parameter.
299 // TODO(gman): Expand to SetParameteriv,fv
300 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
301 GLenum SetParameteri(
302 const FeatureInfo* feature_info, GLenum pname, GLint param);
303 GLenum SetParameterf(
304 const FeatureInfo* feature_info, GLenum pname, GLfloat param);
306 // Makes each of the mip levels as though they were generated.
307 bool MarkMipmapsGenerated(const FeatureInfo* feature_info);
309 bool NeedsMips() const {
310 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR;
313 // True if this texture meets all the GLES2 criteria for rendering.
314 // See section 3.8.2 of the GLES2 spec.
315 bool CanRender(const FeatureInfo* feature_info) const;
317 // Returns true if mipmaps can be generated by GL.
318 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const;
320 // Returns true if any of the texture dimensions are not a power of two.
321 static bool TextureIsNPOT(GLsizei width, GLsizei height, GLsizei depth);
323 // Returns true if texture face is complete relative to the first face.
324 static bool TextureFaceComplete(const Texture::LevelInfo& first_face,
325 size_t face_index,
326 GLenum target,
327 GLenum internal_format,
328 GLsizei width,
329 GLsizei height,
330 GLsizei depth,
331 GLenum format,
332 GLenum type);
334 // Returns true if texture mip level is complete relative to first level.
335 static bool TextureMipComplete(const Texture::LevelInfo& level0_face,
336 GLenum target,
337 GLint level,
338 GLenum internal_format,
339 GLsizei width,
340 GLsizei height,
341 GLsizei depth,
342 GLenum format,
343 GLenum type);
345 // Sets the Texture's target
346 // Parameters:
347 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or
348 // GL_TEXTURE_EXTERNAL_OES or GL_TEXTURE_RECTANGLE_ARB
349 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3)
350 // max_levels: The maximum levels this type of target can have.
351 void SetTarget(
352 const FeatureInfo* feature_info, GLenum target, GLint max_levels);
354 // Update info about this texture.
355 void Update(const FeatureInfo* feature_info);
357 // Set the image for a particular level.
358 void SetLevelImage(
359 const FeatureInfo* feature_info,
360 GLenum target,
361 GLint level,
362 gfx::GLImage* image);
364 // Appends a signature for the given level.
365 void AddToSignature(
366 const FeatureInfo* feature_info,
367 GLenum target, GLint level, std::string* signature) const;
369 void SetMailboxManager(MailboxManager* mailbox_manager);
371 // Updates the unsafe textures count in all the managers referencing this
372 // texture.
373 void UpdateSafeToRenderFrom(bool cleared);
375 // Updates the uncleared mip count in all the managers referencing this
376 // texture.
377 void UpdateMipCleared(LevelInfo* info, bool cleared);
379 // Computes the CanRenderCondition flag.
380 CanRenderCondition GetCanRenderCondition() const;
382 // Updates the unrenderable texture count in all the managers referencing this
383 // texture.
384 void UpdateCanRenderCondition();
386 // Updates the images count in all the managers referencing this
387 // texture.
388 void UpdateHasImages();
390 // Increment the framebuffer state change count in all the managers
391 // referencing this texture.
392 void IncAllFramebufferStateChangeCount();
394 MailboxManager* mailbox_manager_;
396 // Info about each face and level of texture.
397 std::vector<FaceInfo> face_infos_;
399 // The texture refs that point to this Texture.
400 typedef std::set<TextureRef*> RefSet;
401 RefSet refs_;
403 // The single TextureRef that accounts for memory for this texture. Must be
404 // one of refs_.
405 TextureRef* memory_tracking_ref_;
407 // The id of the texure
408 GLuint service_id_;
410 // Whether all renderable mips of this texture have been cleared.
411 bool cleared_;
413 int num_uncleared_mips_;
414 int num_npot_faces_;
416 // 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).
418 GLenum target_;
420 // Texture parameters.
421 GLenum min_filter_;
422 GLenum mag_filter_;
423 GLenum wrap_r_;
424 GLenum wrap_s_;
425 GLenum wrap_t_;
426 GLenum usage_;
427 GLenum pool_;
428 GLenum compare_func_;
429 GLenum compare_mode_;
430 GLfloat max_lod_;
431 GLfloat min_lod_;
432 GLint base_level_;
433 GLint max_level_;
435 // The maximum level that has been set.
436 GLint max_level_set_;
438 // Whether or not this texture is "texture complete"
439 bool texture_complete_;
441 // Whether mip levels have changed and should be reverified.
442 bool texture_mips_dirty_;
443 bool texture_mips_complete_;
445 // Whether or not this texture is "cube complete"
446 bool cube_complete_;
448 // Whether any level 0 faces have changed and should be reverified.
449 bool texture_level0_dirty_;
450 bool texture_level0_complete_;
452 // Whether or not this texture is non-power-of-two
453 bool npot_;
455 // Whether this texture has ever been bound.
456 bool has_been_bound_;
458 // The number of framebuffers this texture is attached to.
459 int framebuffer_attachment_count_;
461 // Whether the texture is immutable and no further changes to the format
462 // or dimensions of the texture object can be made.
463 bool immutable_;
465 // Whether or not this texture has images.
466 bool has_images_;
468 // Size in bytes this texture is assumed to take in memory.
469 uint32 estimated_size_;
471 // Cache of the computed CanRenderCondition flag.
472 CanRenderCondition can_render_condition_;
474 // Whether we have initialized TEXTURE_MAX_ANISOTROPY to 1.
475 bool texture_max_anisotropy_initialized_;
477 DISALLOW_COPY_AND_ASSIGN(Texture);
480 // This class represents a texture in a client context group. It's mostly 1:1
481 // with a client id, though it can outlive the client id if it's still bound to
482 // a FBO or another context when destroyed.
483 // Multiple TextureRef can point to the same texture with cross-context sharing.
484 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> {
485 public:
486 TextureRef(TextureManager* manager, GLuint client_id, Texture* texture);
487 static scoped_refptr<TextureRef> Create(TextureManager* manager,
488 GLuint client_id,
489 GLuint service_id);
491 void AddObserver() { num_observers_++; }
492 void RemoveObserver() { num_observers_--; }
494 const Texture* texture() const { return texture_; }
495 Texture* texture() { return texture_; }
496 GLuint client_id() const { return client_id_; }
497 GLuint service_id() const { return texture_->service_id(); }
498 GLint num_observers() const { return num_observers_; }
500 private:
501 friend class base::RefCounted<TextureRef>;
502 friend class Texture;
503 friend class TextureManager;
505 ~TextureRef();
506 const TextureManager* manager() const { return manager_; }
507 TextureManager* manager() { return manager_; }
508 void reset_client_id() { client_id_ = 0; }
510 TextureManager* manager_;
511 Texture* texture_;
512 GLuint client_id_;
513 GLint num_observers_;
515 DISALLOW_COPY_AND_ASSIGN(TextureRef);
518 // Holds data that is per gles2_cmd_decoder, but is related to to the
519 // TextureManager.
520 struct DecoderTextureState {
521 // total_texture_upload_time automatically initialized to 0 in default
522 // constructor.
523 explicit DecoderTextureState(bool texsubimage_faster_than_teximage)
524 : tex_image_failed(false),
525 texture_upload_count(0),
526 texsubimage_faster_than_teximage(texsubimage_faster_than_teximage) {}
528 // This indicates all the following texSubImage*D calls that are part of the
529 // failed texImage*D call should be ignored.
530 // TODO(zmo): This mechanism is buggy. crbug.com/492852
531 bool tex_image_failed;
533 // Command buffer stats.
534 int texture_upload_count;
535 base::TimeDelta total_texture_upload_time;
537 bool texsubimage_faster_than_teximage;
540 // This class keeps track of the textures and their sizes so we can do NPOT and
541 // texture complete checking.
543 // NOTE: To support shared resources an instance of this class will need to be
544 // shared by multiple GLES2Decoders.
545 class GPU_EXPORT TextureManager {
546 public:
547 class GPU_EXPORT DestructionObserver {
548 public:
549 DestructionObserver();
550 virtual ~DestructionObserver();
552 // Called in ~TextureManager.
553 virtual void OnTextureManagerDestroying(TextureManager* manager) = 0;
555 // Called via ~TextureRef.
556 virtual void OnTextureRefDestroying(TextureRef* texture) = 0;
558 private:
559 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
562 enum DefaultAndBlackTextures {
563 kTexture2D,
564 kCubeMap,
565 kExternalOES,
566 kRectangleARB,
567 kNumDefaultTextures
570 TextureManager(MemoryTracker* memory_tracker,
571 FeatureInfo* feature_info,
572 GLsizei max_texture_size,
573 GLsizei max_cube_map_texture_size,
574 GLsizei max_rectangle_texture_size,
575 GLsizei max_3d_texture_size,
576 bool use_default_textures);
577 ~TextureManager();
579 void set_framebuffer_manager(FramebufferManager* manager) {
580 framebuffer_manager_ = manager;
583 // Init the texture manager.
584 bool Initialize();
586 // Must call before destruction.
587 void Destroy(bool have_context);
589 // Returns the maximum number of levels.
590 GLint MaxLevelsForTarget(GLenum target) const {
591 switch (target) {
592 case GL_TEXTURE_2D:
593 return max_levels_;
594 case GL_TEXTURE_EXTERNAL_OES:
595 return 1;
596 case GL_TEXTURE_3D:
597 case GL_TEXTURE_2D_ARRAY:
598 return max_3d_levels_;
599 default:
600 return max_cube_map_levels_;
604 // Returns the maximum size.
605 GLsizei MaxSizeForTarget(GLenum target) const {
606 switch (target) {
607 case GL_TEXTURE_2D:
608 case GL_TEXTURE_EXTERNAL_OES:
609 return max_texture_size_;
610 case GL_TEXTURE_RECTANGLE:
611 return max_rectangle_texture_size_;
612 case GL_TEXTURE_3D:
613 case GL_TEXTURE_2D_ARRAY:
614 return max_3d_texture_size_;
615 default:
616 return max_cube_map_texture_size_;
620 // Returns the maxium number of levels a texture of the given size can have.
621 static GLsizei ComputeMipMapCount(GLenum target,
622 GLsizei width,
623 GLsizei height,
624 GLsizei depth);
626 // Checks if a dimensions are valid for a given target.
627 bool ValidForTarget(
628 GLenum target, GLint level,
629 GLsizei width, GLsizei height, GLsizei depth);
631 // True if this texture meets all the GLES2 criteria for rendering.
632 // See section 3.8.2 of the GLES2 spec.
633 bool CanRender(const TextureRef* ref) const {
634 return ref->texture()->CanRender(feature_info_.get());
637 // Returns true if mipmaps can be generated by GL.
638 bool CanGenerateMipmaps(const TextureRef* ref) const {
639 return ref->texture()->CanGenerateMipmaps(feature_info_.get());
642 // Sets the Texture's target
643 // Parameters:
644 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP
645 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3)
646 // max_levels: The maximum levels this type of target can have.
647 void SetTarget(
648 TextureRef* ref,
649 GLenum target);
651 // Set the info for a particular level in a TexureInfo.
652 void SetLevelInfo(
653 TextureRef* ref,
654 GLenum target,
655 GLint level,
656 GLenum internal_format,
657 GLsizei width,
658 GLsizei height,
659 GLsizei depth,
660 GLint border,
661 GLenum format,
662 GLenum type,
663 bool cleared);
665 // Adapter to call above function.
666 void SetLevelInfoFromParams(TextureRef* ref,
667 const gpu::AsyncTexImage2DParams& params) {
668 SetLevelInfo(
669 ref, params.target, params.level, params.internal_format,
670 params.width, params.height, 1 /* depth */,
671 params.border, params.format,
672 params.type, true /* cleared */);
675 Texture* Produce(TextureRef* ref);
677 // Maps an existing texture into the texture manager, at a given client ID.
678 TextureRef* Consume(GLuint client_id, Texture* texture);
680 // Sets a mip as cleared.
681 void SetLevelCleared(TextureRef* ref, GLenum target,
682 GLint level, bool cleared);
684 // Sets a texture parameter of a Texture
685 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
686 // TODO(gman): Expand to SetParameteriv,fv
687 void SetParameteri(
688 const char* function_name, ErrorState* error_state,
689 TextureRef* ref, GLenum pname, GLint param);
690 void SetParameterf(
691 const char* function_name, ErrorState* error_state,
692 TextureRef* ref, GLenum pname, GLfloat param);
694 // Makes each of the mip levels as though they were generated.
695 // Returns false if that's not allowed for the given texture.
696 bool MarkMipmapsGenerated(TextureRef* ref);
698 // Clears any uncleared renderable levels.
699 bool ClearRenderableLevels(GLES2Decoder* decoder, TextureRef* ref);
701 // Clear a specific level.
702 bool ClearTextureLevel(
703 GLES2Decoder* decoder, TextureRef* ref, GLenum target, GLint level);
705 // Creates a new texture info.
706 TextureRef* CreateTexture(GLuint client_id, GLuint service_id);
708 // Gets the texture info for the given texture.
709 TextureRef* GetTexture(GLuint client_id) const;
711 // Removes a texture info.
712 void RemoveTexture(GLuint client_id);
714 // Gets a Texture for a given service id (note: it assumes the texture object
715 // is still mapped in this TextureManager).
716 Texture* GetTextureForServiceId(GLuint service_id) const;
718 TextureRef* GetDefaultTextureInfo(GLenum target) {
719 switch (target) {
720 case GL_TEXTURE_2D:
721 return default_textures_[kTexture2D].get();
722 case GL_TEXTURE_CUBE_MAP:
723 return default_textures_[kCubeMap].get();
724 case GL_TEXTURE_EXTERNAL_OES:
725 return default_textures_[kExternalOES].get();
726 case GL_TEXTURE_RECTANGLE_ARB:
727 return default_textures_[kRectangleARB].get();
728 default:
729 NOTREACHED();
730 return NULL;
734 bool HaveUnrenderableTextures() const {
735 return num_unrenderable_textures_ > 0;
738 bool HaveUnsafeTextures() const {
739 return num_unsafe_textures_ > 0;
742 bool HaveUnclearedMips() const {
743 return num_uncleared_mips_ > 0;
746 bool HaveImages() const {
747 return num_images_ > 0;
750 GLuint black_texture_id(GLenum target) const {
751 switch (target) {
752 case GL_SAMPLER_2D:
753 return black_texture_ids_[kTexture2D];
754 case GL_SAMPLER_CUBE:
755 return black_texture_ids_[kCubeMap];
756 case GL_SAMPLER_EXTERNAL_OES:
757 return black_texture_ids_[kExternalOES];
758 case GL_SAMPLER_2D_RECT_ARB:
759 return black_texture_ids_[kRectangleARB];
760 default:
761 NOTREACHED();
762 return 0;
766 size_t mem_represented() const {
767 return
768 memory_tracker_managed_->GetMemRepresented() +
769 memory_tracker_unmanaged_->GetMemRepresented();
772 void SetLevelImage(
773 TextureRef* ref,
774 GLenum target,
775 GLint level,
776 gfx::GLImage* image);
778 size_t GetSignatureSize() const;
780 void AddToSignature(
781 TextureRef* ref,
782 GLenum target,
783 GLint level,
784 std::string* signature) const;
786 void AddObserver(DestructionObserver* observer) {
787 destruction_observers_.push_back(observer);
790 void RemoveObserver(DestructionObserver* observer) {
791 for (unsigned int i = 0; i < destruction_observers_.size(); i++) {
792 if (destruction_observers_[i] == observer) {
793 std::swap(destruction_observers_[i], destruction_observers_.back());
794 destruction_observers_.pop_back();
795 return;
798 NOTREACHED();
801 struct DoTexImageArguments {
802 enum TexImageCommandType {
803 kTexImage2D,
804 kTexImage3D,
807 GLenum target;
808 GLint level;
809 GLenum internal_format;
810 GLsizei width;
811 GLsizei height;
812 GLsizei depth;
813 GLint border;
814 GLenum format;
815 GLenum type;
816 const void* pixels;
817 uint32 pixels_size;
818 TexImageCommandType command_type;
821 bool ValidateTexImage(
822 ContextState* state,
823 const char* function_name,
824 const DoTexImageArguments& args,
825 // Pointer to TextureRef filled in if validation successful.
826 // Presumes the pointer is valid.
827 TextureRef** texture_ref);
829 void ValidateAndDoTexImage(
830 DecoderTextureState* texture_state,
831 ContextState* state,
832 DecoderFramebufferState* framebuffer_state,
833 const char* function_name,
834 const DoTexImageArguments& args);
836 // TODO(kloveless): Make GetTexture* private once this is no longer called
837 // from gles2_cmd_decoder.
838 TextureRef* GetTextureInfoForTarget(ContextState* state, GLenum target);
839 TextureRef* GetTextureInfoForTargetUnlessDefault(
840 ContextState* state, GLenum target);
842 bool ValidateFormatAndTypeCombination(
843 ErrorState* error_state, const char* function_name,
844 GLenum format, GLenum type);
846 // Note that internal_format is only checked in relation to the format
847 // parameter, so that this function may be used to validate texSubImage2D.
848 bool ValidateTextureParameters(
849 ErrorState* error_state, const char* function_name,
850 GLenum format, GLenum type, GLenum internal_format, GLint level);
852 private:
853 friend class Texture;
854 friend class TextureRef;
856 // Helper for Initialize().
857 scoped_refptr<TextureRef> CreateDefaultAndBlackTextures(
858 GLenum target,
859 GLuint* black_texture);
861 void DoTexImage(
862 DecoderTextureState* texture_state,
863 ErrorState* error_state,
864 DecoderFramebufferState* framebuffer_state,
865 const char* function_name,
866 TextureRef* texture_ref,
867 const DoTexImageArguments& args);
869 void StartTracking(TextureRef* texture);
870 void StopTracking(TextureRef* texture);
872 void UpdateSafeToRenderFrom(int delta);
873 void UpdateUnclearedMips(int delta);
874 void UpdateCanRenderCondition(Texture::CanRenderCondition old_condition,
875 Texture::CanRenderCondition new_condition);
876 void UpdateNumImages(int delta);
877 void IncFramebufferStateChangeCount();
879 GLenum AdjustTexFormat(GLenum format) const;
881 MemoryTypeTracker* GetMemTracker(GLenum texture_pool);
882 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_;
883 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_;
885 scoped_refptr<FeatureInfo> feature_info_;
887 FramebufferManager* framebuffer_manager_;
889 // Info for each texture in the system.
890 typedef base::hash_map<GLuint, scoped_refptr<TextureRef> > TextureMap;
891 TextureMap textures_;
893 GLsizei max_texture_size_;
894 GLsizei max_cube_map_texture_size_;
895 GLsizei max_rectangle_texture_size_;
896 GLsizei max_3d_texture_size_;
897 GLint max_levels_;
898 GLint max_cube_map_levels_;
899 GLint max_3d_levels_;
901 const bool use_default_textures_;
903 int num_unrenderable_textures_;
904 int num_unsafe_textures_;
905 int num_uncleared_mips_;
906 int num_images_;
908 // Counts the number of Textures allocated with 'this' as its manager.
909 // Allows to check no Texture will outlive this.
910 unsigned int texture_count_;
912 bool have_context_;
914 // Black (0,0,0,1) textures for when non-renderable textures are used.
915 // NOTE: There is no corresponding Texture for these textures.
916 // TextureInfos are only for textures the client side can access.
917 GLuint black_texture_ids_[kNumDefaultTextures];
919 // The default textures for each target (texture name = 0)
920 scoped_refptr<TextureRef> default_textures_[kNumDefaultTextures];
922 std::vector<DestructionObserver*> destruction_observers_;
924 DISALLOW_COPY_AND_ASSIGN(TextureManager);
927 // This class records texture upload time when in scope.
928 class ScopedTextureUploadTimer {
929 public:
930 explicit ScopedTextureUploadTimer(DecoderTextureState* texture_state);
931 ~ScopedTextureUploadTimer();
933 private:
934 DecoderTextureState* texture_state_;
935 base::TimeTicks begin_time_;
936 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer);
939 } // namespace gles2
940 } // namespace gpu
942 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_