Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / gpu / command_buffer / service / texture_manager.h
blob348d86290dd2ea94a84dd77b43de3f9c4e1141a6
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_s() const {
52 return wrap_s_;
55 GLenum wrap_t() const {
56 return wrap_t_;
59 GLenum usage() const {
60 return usage_;
63 GLenum pool() const {
64 return pool_;
67 int num_uncleared_mips() const {
68 return num_uncleared_mips_;
71 uint32 estimated_size() const {
72 return estimated_size_;
75 bool CanRenderTo() const {
76 return target_ != GL_TEXTURE_EXTERNAL_OES;
79 // The service side OpenGL id of the texture.
80 GLuint service_id() const {
81 return service_id_;
84 void SetServiceId(GLuint service_id) {
85 DCHECK(service_id);
86 service_id_ = service_id;
89 // Returns the target this texure was first bound to or 0 if it has not
90 // been bound. Once a texture is bound to a specific target it can never be
91 // bound to a different target.
92 GLenum target() const {
93 return target_;
96 bool SafeToRenderFrom() const {
97 return cleared_;
100 // Get the width and height for a particular level. Returns false if level
101 // does not exist.
102 bool GetLevelSize(
103 GLint target, GLint level, GLsizei* width, GLsizei* height) const;
105 // Get the type of a level. Returns false if level does not exist.
106 bool GetLevelType(
107 GLint target, GLint level, GLenum* type, GLenum* internal_format) const;
109 // Get the image bound to a particular level. Returns NULL if level
110 // does not exist.
111 gfx::GLImage* GetLevelImage(GLint target, GLint level) const;
113 bool HasImages() const {
114 return has_images_;
117 // Returns true of the given dimensions are inside the dimensions of the
118 // level and if the type matches the level.
119 bool ValidForTexture(
120 GLint target,
121 GLint level,
122 GLint xoffset,
123 GLint yoffset,
124 GLsizei width,
125 GLsizei height,
126 GLenum type) const;
128 bool IsValid() const {
129 return !!target();
132 bool IsAttachedToFramebuffer() const {
133 return framebuffer_attachment_count_ != 0;
136 void AttachToFramebuffer() {
137 ++framebuffer_attachment_count_;
140 void DetachFromFramebuffer() {
141 DCHECK_GT(framebuffer_attachment_count_, 0);
142 --framebuffer_attachment_count_;
145 void SetImmutable(bool immutable) {
146 immutable_ = immutable;
149 bool IsImmutable() const {
150 return immutable_;
153 // Whether a particular level/face is cleared.
154 bool IsLevelCleared(GLenum target, GLint level) const;
156 // Whether the texture has been defined
157 bool IsDefined() const {
158 return estimated_size() > 0;
161 // Initialize TEXTURE_MAX_ANISOTROPY to 1 if we haven't done so yet.
162 void InitTextureMaxAnisotropyIfNeeded(GLenum target);
164 void OnWillModifyPixels();
165 void OnDidModifyPixels();
167 private:
168 friend class MailboxManagerImpl;
169 friend class MailboxManagerSync;
170 friend class MailboxManagerTest;
171 friend class TextureDefinition;
172 friend class TextureManager;
173 friend class TextureRef;
174 friend class TextureTestHelper;
176 ~Texture();
177 void AddTextureRef(TextureRef* ref);
178 void RemoveTextureRef(TextureRef* ref, bool have_context);
179 MemoryTypeTracker* GetMemTracker();
181 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it
182 // depends on context support for non-power-of-two textures (i.e. will be
183 // renderable if NPOT support is in the context, otherwise not, e.g. texture
184 // with a NPOT level). ALWAYS means it doesn't depend on context features
185 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g.
186 // incomplete).
187 enum CanRenderCondition {
188 CAN_RENDER_ALWAYS,
189 CAN_RENDER_NEVER,
190 CAN_RENDER_ONLY_IF_NPOT
193 struct LevelInfo {
194 LevelInfo();
195 LevelInfo(const LevelInfo& rhs);
196 ~LevelInfo();
198 bool cleared;
199 GLenum target;
200 GLint level;
201 GLenum internal_format;
202 GLsizei width;
203 GLsizei height;
204 GLsizei depth;
205 GLint border;
206 GLenum format;
207 GLenum type;
208 scoped_refptr<gfx::GLImage> image;
209 uint32 estimated_size;
212 struct FaceInfo {
213 FaceInfo();
214 ~FaceInfo();
216 GLsizei num_mip_levels;
217 std::vector<LevelInfo> level_infos;
220 // Set the info for a particular level.
221 void SetLevelInfo(
222 const FeatureInfo* feature_info,
223 GLenum target,
224 GLint level,
225 GLenum internal_format,
226 GLsizei width,
227 GLsizei height,
228 GLsizei depth,
229 GLint border,
230 GLenum format,
231 GLenum type,
232 bool cleared);
234 // In GLES2 "texture complete" means it has all required mips for filtering
235 // down to a 1x1 pixel texture, they are in the correct order, they are all
236 // the same format.
237 bool texture_complete() const {
238 return texture_complete_;
241 // In GLES2 "cube complete" means all 6 faces level 0 are defined, all the
242 // same format, all the same dimensions and all width = height.
243 bool cube_complete() const {
244 return cube_complete_;
247 // Whether or not this texture is a non-power-of-two texture.
248 bool npot() const {
249 return npot_;
252 // Marks a particular level as cleared or uncleared.
253 void SetLevelCleared(GLenum target, GLint level, bool cleared);
255 // Updates the cleared flag for this texture by inspecting all the mips.
256 void UpdateCleared();
258 // Clears any renderable uncleared levels.
259 // Returns false if a GL error was generated.
260 bool ClearRenderableLevels(GLES2Decoder* decoder);
262 // Clears the level.
263 // Returns false if a GL error was generated.
264 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level);
266 // Sets a texture parameter.
267 // TODO(gman): Expand to SetParameteriv,fv
268 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
269 GLenum SetParameteri(
270 const FeatureInfo* feature_info, GLenum pname, GLint param);
271 GLenum SetParameterf(
272 const FeatureInfo* feature_info, GLenum pname, GLfloat param);
274 // Makes each of the mip levels as though they were generated.
275 bool MarkMipmapsGenerated(const FeatureInfo* feature_info);
277 bool NeedsMips() const {
278 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR;
281 // True if this texture meets all the GLES2 criteria for rendering.
282 // See section 3.8.2 of the GLES2 spec.
283 bool CanRender(const FeatureInfo* feature_info) const;
285 // Returns true if mipmaps can be generated by GL.
286 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const;
288 // Returns true if any of the texture dimensions are not a power of two.
289 static bool TextureIsNPOT(GLsizei width, GLsizei height, GLsizei depth);
291 // Returns true if texture face is complete relative to the first face.
292 static bool TextureFaceComplete(const Texture::LevelInfo& first_face,
293 size_t face_index,
294 GLenum target,
295 GLenum internal_format,
296 GLsizei width,
297 GLsizei height,
298 GLsizei depth,
299 GLenum format,
300 GLenum type);
302 // Returns true if texture mip level is complete relative to first level.
303 static bool TextureMipComplete(const Texture::LevelInfo& level0_face,
304 GLenum target,
305 GLint level,
306 GLenum internal_format,
307 GLsizei width,
308 GLsizei height,
309 GLsizei depth,
310 GLenum format,
311 GLenum type);
313 // Sets the Texture's target
314 // Parameters:
315 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or
316 // GL_TEXTURE_EXTERNAL_OES or GL_TEXTURE_RECTANGLE_ARB
317 // max_levels: The maximum levels this type of target can have.
318 void SetTarget(
319 const FeatureInfo* feature_info, GLenum target, GLint max_levels);
321 // Update info about this texture.
322 void Update(const FeatureInfo* feature_info);
324 // Set the image for a particular level.
325 void SetLevelImage(
326 const FeatureInfo* feature_info,
327 GLenum target,
328 GLint level,
329 gfx::GLImage* image);
331 // Appends a signature for the given level.
332 void AddToSignature(
333 const FeatureInfo* feature_info,
334 GLenum target, GLint level, std::string* signature) const;
336 void SetMailboxManager(MailboxManager* mailbox_manager);
338 // Updates the unsafe textures count in all the managers referencing this
339 // texture.
340 void UpdateSafeToRenderFrom(bool cleared);
342 // Updates the uncleared mip count in all the managers referencing this
343 // texture.
344 void UpdateMipCleared(LevelInfo* info, bool cleared);
346 // Computes the CanRenderCondition flag.
347 CanRenderCondition GetCanRenderCondition() const;
349 // Updates the unrenderable texture count in all the managers referencing this
350 // texture.
351 void UpdateCanRenderCondition();
353 // Updates the images count in all the managers referencing this
354 // texture.
355 void UpdateHasImages();
357 // Increment the framebuffer state change count in all the managers
358 // referencing this texture.
359 void IncAllFramebufferStateChangeCount();
361 MailboxManager* mailbox_manager_;
363 // Info about each face and level of texture.
364 std::vector<FaceInfo> face_infos_;
366 // The texture refs that point to this Texture.
367 typedef std::set<TextureRef*> RefSet;
368 RefSet refs_;
370 // The single TextureRef that accounts for memory for this texture. Must be
371 // one of refs_.
372 TextureRef* memory_tracking_ref_;
374 // The id of the texure
375 GLuint service_id_;
377 // Whether all renderable mips of this texture have been cleared.
378 bool cleared_;
380 int num_uncleared_mips_;
381 int num_npot_faces_;
383 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
384 GLenum target_;
386 // Texture parameters.
387 GLenum min_filter_;
388 GLenum mag_filter_;
389 GLenum wrap_s_;
390 GLenum wrap_t_;
391 GLenum usage_;
392 GLenum pool_;
394 // The maximum level that has been set.
395 GLint max_level_set_;
397 // Whether or not this texture is "texture complete"
398 bool texture_complete_;
400 // Whether mip levels have changed and should be reverified.
401 bool texture_mips_dirty_;
402 bool texture_mips_complete_;
404 // Whether or not this texture is "cube complete"
405 bool cube_complete_;
407 // Whether any level 0 faces have changed and should be reverified.
408 bool texture_level0_dirty_;
409 bool texture_level0_complete_;
411 // Whether or not this texture is non-power-of-two
412 bool npot_;
414 // Whether this texture has ever been bound.
415 bool has_been_bound_;
417 // The number of framebuffers this texture is attached to.
418 int framebuffer_attachment_count_;
420 // Whether the texture is immutable and no further changes to the format
421 // or dimensions of the texture object can be made.
422 bool immutable_;
424 // Whether or not this texture has images.
425 bool has_images_;
427 // Size in bytes this texture is assumed to take in memory.
428 uint32 estimated_size_;
430 // Cache of the computed CanRenderCondition flag.
431 CanRenderCondition can_render_condition_;
433 // Whether we have initialized TEXTURE_MAX_ANISOTROPY to 1.
434 bool texture_max_anisotropy_initialized_;
436 DISALLOW_COPY_AND_ASSIGN(Texture);
439 // This class represents a texture in a client context group. It's mostly 1:1
440 // with a client id, though it can outlive the client id if it's still bound to
441 // a FBO or another context when destroyed.
442 // Multiple TextureRef can point to the same texture with cross-context sharing.
443 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> {
444 public:
445 TextureRef(TextureManager* manager, GLuint client_id, Texture* texture);
446 static scoped_refptr<TextureRef> Create(TextureManager* manager,
447 GLuint client_id,
448 GLuint service_id);
450 void AddObserver() { num_observers_++; }
451 void RemoveObserver() { num_observers_--; }
453 const Texture* texture() const { return texture_; }
454 Texture* texture() { return texture_; }
455 GLuint client_id() const { return client_id_; }
456 GLuint service_id() const { return texture_->service_id(); }
457 GLint num_observers() const { return num_observers_; }
459 private:
460 friend class base::RefCounted<TextureRef>;
461 friend class Texture;
462 friend class TextureManager;
464 ~TextureRef();
465 const TextureManager* manager() const { return manager_; }
466 TextureManager* manager() { return manager_; }
467 void reset_client_id() { client_id_ = 0; }
469 TextureManager* manager_;
470 Texture* texture_;
471 GLuint client_id_;
472 GLint num_observers_;
474 DISALLOW_COPY_AND_ASSIGN(TextureRef);
477 // Holds data that is per gles2_cmd_decoder, but is related to to the
478 // TextureManager.
479 struct DecoderTextureState {
480 // total_texture_upload_time automatically initialized to 0 in default
481 // constructor.
482 explicit DecoderTextureState(bool texsubimage2d_faster_than_teximage2d)
483 : tex_image_2d_failed(false),
484 texture_upload_count(0),
485 texsubimage2d_faster_than_teximage2d(
486 texsubimage2d_faster_than_teximage2d) {}
488 // This indicates all the following texSubImage2D calls that are part of the
489 // failed texImage2D call should be ignored.
490 bool tex_image_2d_failed;
492 // Command buffer stats.
493 int texture_upload_count;
494 base::TimeDelta total_texture_upload_time;
496 bool texsubimage2d_faster_than_teximage2d;
499 // This class keeps track of the textures and their sizes so we can do NPOT and
500 // texture complete checking.
502 // NOTE: To support shared resources an instance of this class will need to be
503 // shared by multiple GLES2Decoders.
504 class GPU_EXPORT TextureManager {
505 public:
506 class GPU_EXPORT DestructionObserver {
507 public:
508 DestructionObserver();
509 virtual ~DestructionObserver();
511 // Called in ~TextureManager.
512 virtual void OnTextureManagerDestroying(TextureManager* manager) = 0;
514 // Called via ~TextureRef.
515 virtual void OnTextureRefDestroying(TextureRef* texture) = 0;
517 private:
518 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
521 enum DefaultAndBlackTextures {
522 kTexture2D,
523 kCubeMap,
524 kExternalOES,
525 kRectangleARB,
526 kNumDefaultTextures
529 TextureManager(MemoryTracker* memory_tracker,
530 FeatureInfo* feature_info,
531 GLsizei max_texture_size,
532 GLsizei max_cube_map_texture_size,
533 GLsizei max_rectangle_texture_size,
534 GLsizei max_3d_texture_size,
535 bool use_default_textures);
536 ~TextureManager();
538 void set_framebuffer_manager(FramebufferManager* manager) {
539 framebuffer_manager_ = manager;
542 // Init the texture manager.
543 bool Initialize();
545 // Must call before destruction.
546 void Destroy(bool have_context);
548 // Returns the maximum number of levels.
549 GLint MaxLevelsForTarget(GLenum target) const {
550 switch (target) {
551 case GL_TEXTURE_2D:
552 return max_levels_;
553 case GL_TEXTURE_EXTERNAL_OES:
554 return 1;
555 case GL_TEXTURE_3D:
556 case GL_TEXTURE_2D_ARRAY:
557 return max_3d_levels_;
558 default:
559 return max_cube_map_levels_;
563 // Returns the maximum size.
564 GLsizei MaxSizeForTarget(GLenum target) const {
565 switch (target) {
566 case GL_TEXTURE_2D:
567 case GL_TEXTURE_EXTERNAL_OES:
568 return max_texture_size_;
569 case GL_TEXTURE_RECTANGLE:
570 return max_rectangle_texture_size_;
571 case GL_TEXTURE_3D:
572 case GL_TEXTURE_2D_ARRAY:
573 return max_3d_texture_size_;
574 default:
575 return max_cube_map_texture_size_;
579 // Returns the maxium number of levels a texture of the given size can have.
580 static GLsizei ComputeMipMapCount(GLenum target,
581 GLsizei width,
582 GLsizei height,
583 GLsizei depth);
585 // Checks if a dimensions are valid for a given target.
586 bool ValidForTarget(
587 GLenum target, GLint level,
588 GLsizei width, GLsizei height, GLsizei depth);
590 // True if this texture meets all the GLES2 criteria for rendering.
591 // See section 3.8.2 of the GLES2 spec.
592 bool CanRender(const TextureRef* ref) const {
593 return ref->texture()->CanRender(feature_info_.get());
596 // Returns true if mipmaps can be generated by GL.
597 bool CanGenerateMipmaps(const TextureRef* ref) const {
598 return ref->texture()->CanGenerateMipmaps(feature_info_.get());
601 // Sets the Texture's target
602 // Parameters:
603 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP
604 // max_levels: The maximum levels this type of target can have.
605 void SetTarget(
606 TextureRef* ref,
607 GLenum target);
609 // Set the info for a particular level in a TexureInfo.
610 void SetLevelInfo(
611 TextureRef* ref,
612 GLenum target,
613 GLint level,
614 GLenum internal_format,
615 GLsizei width,
616 GLsizei height,
617 GLsizei depth,
618 GLint border,
619 GLenum format,
620 GLenum type,
621 bool cleared);
623 // Adapter to call above function.
624 void SetLevelInfoFromParams(TextureRef* ref,
625 const gpu::AsyncTexImage2DParams& params) {
626 SetLevelInfo(
627 ref, params.target, params.level, params.internal_format,
628 params.width, params.height, 1 /* depth */,
629 params.border, params.format,
630 params.type, true /* cleared */);
633 Texture* Produce(TextureRef* ref);
635 // Maps an existing texture into the texture manager, at a given client ID.
636 TextureRef* Consume(GLuint client_id, Texture* texture);
638 // Sets a mip as cleared.
639 void SetLevelCleared(TextureRef* ref, GLenum target,
640 GLint level, bool cleared);
642 // Sets a texture parameter of a Texture
643 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
644 // TODO(gman): Expand to SetParameteriv,fv
645 void SetParameteri(
646 const char* function_name, ErrorState* error_state,
647 TextureRef* ref, GLenum pname, GLint param);
648 void SetParameterf(
649 const char* function_name, ErrorState* error_state,
650 TextureRef* ref, GLenum pname, GLfloat param);
652 // Makes each of the mip levels as though they were generated.
653 // Returns false if that's not allowed for the given texture.
654 bool MarkMipmapsGenerated(TextureRef* ref);
656 // Clears any uncleared renderable levels.
657 bool ClearRenderableLevels(GLES2Decoder* decoder, TextureRef* ref);
659 // Clear a specific level.
660 bool ClearTextureLevel(
661 GLES2Decoder* decoder, TextureRef* ref, GLenum target, GLint level);
663 // Creates a new texture info.
664 TextureRef* CreateTexture(GLuint client_id, GLuint service_id);
666 // Gets the texture info for the given texture.
667 TextureRef* GetTexture(GLuint client_id) const;
669 // Removes a texture info.
670 void RemoveTexture(GLuint client_id);
672 // Gets a Texture for a given service id (note: it assumes the texture object
673 // is still mapped in this TextureManager).
674 Texture* GetTextureForServiceId(GLuint service_id) const;
676 TextureRef* GetDefaultTextureInfo(GLenum target) {
677 switch (target) {
678 case GL_TEXTURE_2D:
679 return default_textures_[kTexture2D].get();
680 case GL_TEXTURE_CUBE_MAP:
681 return default_textures_[kCubeMap].get();
682 case GL_TEXTURE_EXTERNAL_OES:
683 return default_textures_[kExternalOES].get();
684 case GL_TEXTURE_RECTANGLE_ARB:
685 return default_textures_[kRectangleARB].get();
686 default:
687 NOTREACHED();
688 return NULL;
692 bool HaveUnrenderableTextures() const {
693 return num_unrenderable_textures_ > 0;
696 bool HaveUnsafeTextures() const {
697 return num_unsafe_textures_ > 0;
700 bool HaveUnclearedMips() const {
701 return num_uncleared_mips_ > 0;
704 bool HaveImages() const {
705 return num_images_ > 0;
708 GLuint black_texture_id(GLenum target) const {
709 switch (target) {
710 case GL_SAMPLER_2D:
711 return black_texture_ids_[kTexture2D];
712 case GL_SAMPLER_CUBE:
713 return black_texture_ids_[kCubeMap];
714 case GL_SAMPLER_EXTERNAL_OES:
715 return black_texture_ids_[kExternalOES];
716 case GL_SAMPLER_2D_RECT_ARB:
717 return black_texture_ids_[kRectangleARB];
718 default:
719 NOTREACHED();
720 return 0;
724 size_t mem_represented() const {
725 return
726 memory_tracker_managed_->GetMemRepresented() +
727 memory_tracker_unmanaged_->GetMemRepresented();
730 void SetLevelImage(
731 TextureRef* ref,
732 GLenum target,
733 GLint level,
734 gfx::GLImage* image);
736 size_t GetSignatureSize() const;
738 void AddToSignature(
739 TextureRef* ref,
740 GLenum target,
741 GLint level,
742 std::string* signature) const;
744 void AddObserver(DestructionObserver* observer) {
745 destruction_observers_.push_back(observer);
748 void RemoveObserver(DestructionObserver* observer) {
749 for (unsigned int i = 0; i < destruction_observers_.size(); i++) {
750 if (destruction_observers_[i] == observer) {
751 std::swap(destruction_observers_[i], destruction_observers_.back());
752 destruction_observers_.pop_back();
753 return;
756 NOTREACHED();
759 struct DoTextImage2DArguments {
760 GLenum target;
761 GLint level;
762 GLenum internal_format;
763 GLsizei width;
764 GLsizei height;
765 GLint border;
766 GLenum format;
767 GLenum type;
768 const void* pixels;
769 uint32 pixels_size;
772 bool ValidateTexImage2D(
773 ContextState* state,
774 const char* function_name,
775 const DoTextImage2DArguments& args,
776 // Pointer to TextureRef filled in if validation successful.
777 // Presumes the pointer is valid.
778 TextureRef** texture_ref);
780 void ValidateAndDoTexImage2D(
781 DecoderTextureState* texture_state,
782 ContextState* state,
783 DecoderFramebufferState* framebuffer_state,
784 const DoTextImage2DArguments& args);
786 // TODO(kloveless): Make GetTexture* private once this is no longer called
787 // from gles2_cmd_decoder.
788 TextureRef* GetTextureInfoForTarget(ContextState* state, GLenum target);
789 TextureRef* GetTextureInfoForTargetUnlessDefault(
790 ContextState* state, GLenum target);
792 bool ValidateFormatAndTypeCombination(
793 ErrorState* error_state, const char* function_name,
794 GLenum format, GLenum type);
796 // Note that internal_format is only checked in relation to the format
797 // parameter, so that this function may be used to validate texSubImage2D.
798 bool ValidateTextureParameters(
799 ErrorState* error_state, const char* function_name,
800 GLenum format, GLenum type, GLenum internal_format, GLint level);
802 private:
803 friend class Texture;
804 friend class TextureRef;
806 // Helper for Initialize().
807 scoped_refptr<TextureRef> CreateDefaultAndBlackTextures(
808 GLenum target,
809 GLuint* black_texture);
811 void DoTexImage2D(
812 DecoderTextureState* texture_state,
813 ErrorState* error_state,
814 DecoderFramebufferState* framebuffer_state,
815 TextureRef* texture_ref,
816 const DoTextImage2DArguments& args);
818 void StartTracking(TextureRef* texture);
819 void StopTracking(TextureRef* texture);
821 void UpdateSafeToRenderFrom(int delta);
822 void UpdateUnclearedMips(int delta);
823 void UpdateCanRenderCondition(Texture::CanRenderCondition old_condition,
824 Texture::CanRenderCondition new_condition);
825 void UpdateNumImages(int delta);
826 void IncFramebufferStateChangeCount();
828 GLenum AdjustTexFormat(GLenum format) const;
830 MemoryTypeTracker* GetMemTracker(GLenum texture_pool);
831 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_;
832 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_;
834 scoped_refptr<FeatureInfo> feature_info_;
836 FramebufferManager* framebuffer_manager_;
838 // Info for each texture in the system.
839 typedef base::hash_map<GLuint, scoped_refptr<TextureRef> > TextureMap;
840 TextureMap textures_;
842 GLsizei max_texture_size_;
843 GLsizei max_cube_map_texture_size_;
844 GLsizei max_rectangle_texture_size_;
845 GLsizei max_3d_texture_size_;
846 GLint max_levels_;
847 GLint max_cube_map_levels_;
848 GLint max_3d_levels_;
850 const bool use_default_textures_;
852 int num_unrenderable_textures_;
853 int num_unsafe_textures_;
854 int num_uncleared_mips_;
855 int num_images_;
857 // Counts the number of Textures allocated with 'this' as its manager.
858 // Allows to check no Texture will outlive this.
859 unsigned int texture_count_;
861 bool have_context_;
863 // Black (0,0,0,1) textures for when non-renderable textures are used.
864 // NOTE: There is no corresponding Texture for these textures.
865 // TextureInfos are only for textures the client side can access.
866 GLuint black_texture_ids_[kNumDefaultTextures];
868 // The default textures for each target (texture name = 0)
869 scoped_refptr<TextureRef> default_textures_[kNumDefaultTextures];
871 std::vector<DestructionObserver*> destruction_observers_;
873 DISALLOW_COPY_AND_ASSIGN(TextureManager);
876 // This class records texture upload time when in scope.
877 class ScopedTextureUploadTimer {
878 public:
879 explicit ScopedTextureUploadTimer(DecoderTextureState* texture_state);
880 ~ScopedTextureUploadTimer();
882 private:
883 DecoderTextureState* texture_state_;
884 base::TimeTicks begin_time_;
885 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer);
888 } // namespace gles2
889 } // namespace gpu
891 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_