OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 8 #include <vector> |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | |
14 #include "gpu/command_buffer/service/gl_utils.h" | 13 #include "gpu/command_buffer/service/gl_utils.h" |
15 | 14 |
16 namespace gpu { | 15 namespace gpu { |
17 namespace gles2 { | 16 namespace gles2 { |
18 | 17 |
19 class FeatureInfo; | 18 class FeatureInfo; |
20 | 19 |
21 // This class keeps track of the textures and their sizes so we can do NPOT and | 20 // This class keeps track of the textures and their sizes so we can do NPOT and |
22 // texture complete checking. | 21 // texture complete checking. |
23 // | 22 // |
24 // NOTE: To support shared resources an instance of this class will need to be | 23 // NOTE: To support shared resources an instance of this class will need to be |
25 // shared by multiple GLES2Decoders. | 24 // shared by multiple GLES2Decoders. |
26 class TextureManager : public base::SupportsWeakPtr<TextureManager> { | 25 class TextureManager { |
27 public: | 26 public: |
28 // Info about Textures currently in the system. | 27 // Info about Textures currently in the system. |
29 class TextureInfo : public base::RefCounted<TextureInfo> { | 28 class TextureInfo : public base::RefCounted<TextureInfo> { |
30 public: | 29 public: |
31 typedef scoped_refptr<TextureInfo> Ref; | 30 typedef scoped_refptr<TextureInfo> Ref; |
32 | 31 |
33 explicit TextureInfo(GLuint service_id) | 32 explicit TextureInfo(GLuint service_id) |
34 : service_id_(service_id), | 33 : service_id_(service_id), |
35 deleted_(false), | 34 deleted_(false), |
36 target_(0), | 35 target_(0), |
37 min_filter_(GL_NEAREST_MIPMAP_LINEAR), | 36 min_filter_(GL_NEAREST_MIPMAP_LINEAR), |
38 mag_filter_(GL_LINEAR), | 37 mag_filter_(GL_LINEAR), |
39 wrap_s_(GL_REPEAT), | 38 wrap_s_(GL_REPEAT), |
40 wrap_t_(GL_REPEAT), | 39 wrap_t_(GL_REPEAT), |
41 max_level_set_(-1), | 40 max_level_set_(-1), |
42 texture_complete_(false), | 41 texture_complete_(false), |
43 cube_complete_(false), | 42 cube_complete_(false), |
44 npot_(false), | 43 npot_(false), |
45 has_been_bound_(false), | 44 has_been_bound_(false), |
46 framebuffer_attachment_count_(0) { | 45 framebuffer_attachment_count_(0), |
| 46 owned_(true) { |
47 } | 47 } |
48 | 48 |
49 GLenum min_filter() const { | 49 GLenum min_filter() const { |
50 return min_filter_; | 50 return min_filter_; |
51 } | 51 } |
52 | 52 |
53 GLenum mag_filter() const { | 53 GLenum mag_filter() const { |
54 return mag_filter_; | 54 return mag_filter_; |
55 } | 55 } |
56 | 56 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // same format, all the same dimensions and all width = height. | 89 // same format, all the same dimensions and all width = height. |
90 bool cube_complete() const { | 90 bool cube_complete() const { |
91 return cube_complete_; | 91 return cube_complete_; |
92 } | 92 } |
93 | 93 |
94 // Whether or not this texture is a non-power-of-two texture. | 94 // Whether or not this texture is a non-power-of-two texture. |
95 bool npot() const { | 95 bool npot() const { |
96 return npot_; | 96 return npot_; |
97 } | 97 } |
98 | 98 |
99 TextureManager* owner() const { | |
100 return owner_.get(); | |
101 } | |
102 | |
103 // Returns true if mipmaps can be generated by GL. | 99 // Returns true if mipmaps can be generated by GL. |
104 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; | 100 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; |
105 | 101 |
106 // Get the width and height for a particular level. Returns false if level | 102 // Get the width and height for a particular level. Returns false if level |
107 // does not exist. | 103 // does not exist. |
108 bool GetLevelSize( | 104 bool GetLevelSize( |
109 GLint face, GLint level, GLsizei* width, GLsizei* height) const; | 105 GLint face, GLint level, GLsizei* width, GLsizei* height) const; |
110 | 106 |
111 // Get the type of a level. Returns false if level does not exist. | 107 // Get the type of a level. Returns false if level does not exist. |
112 bool GetLevelType( | 108 bool GetLevelType( |
(...skipping 12 matching lines...) Expand all Loading... |
125 GLint yoffset, | 121 GLint yoffset, |
126 GLsizei width, | 122 GLsizei width, |
127 GLsizei height, | 123 GLsizei height, |
128 GLenum format, | 124 GLenum format, |
129 GLenum type) const; | 125 GLenum type) const; |
130 | 126 |
131 bool IsValid() const { | 127 bool IsValid() const { |
132 return target() && !IsDeleted(); | 128 return target() && !IsDeleted(); |
133 } | 129 } |
134 | 130 |
| 131 void SetNotOwned() { |
| 132 owned_ = false; |
| 133 } |
| 134 |
135 bool IsAttachedToFramebuffer() const { | 135 bool IsAttachedToFramebuffer() const { |
136 return framebuffer_attachment_count_ != 0; | 136 return framebuffer_attachment_count_ != 0; |
137 } | 137 } |
138 | 138 |
139 void AttachToFramebuffer() { | 139 void AttachToFramebuffer() { |
140 ++framebuffer_attachment_count_; | 140 ++framebuffer_attachment_count_; |
141 } | 141 } |
142 | 142 |
143 void DetachFromFramebuffer() { | 143 void DetachFromFramebuffer() { |
144 DCHECK(framebuffer_attachment_count_ > 0); | 144 DCHECK(framebuffer_attachment_count_ > 0); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 // Whether or not this texture is non-power-of-two | 244 // Whether or not this texture is non-power-of-two |
245 bool npot_; | 245 bool npot_; |
246 | 246 |
247 // Whether this texture has ever been bound. | 247 // Whether this texture has ever been bound. |
248 bool has_been_bound_; | 248 bool has_been_bound_; |
249 | 249 |
250 // The number of framebuffers this texture is attached to. | 250 // The number of framebuffers this texture is attached to. |
251 int framebuffer_attachment_count_; | 251 int framebuffer_attachment_count_; |
252 | 252 |
253 // The framebuffer manager that controls the lifetime of this framebuffer | 253 // Whether the associated context group owns this texture and should delete |
254 // or NULL if it has been deleted. | 254 // it. |
255 base::WeakPtr<TextureManager> owner_; | 255 bool owned_; |
256 | 256 |
257 DISALLOW_COPY_AND_ASSIGN(TextureInfo); | 257 DISALLOW_COPY_AND_ASSIGN(TextureInfo); |
258 }; | 258 }; |
259 | 259 |
260 TextureManager(GLsizei max_texture_size, | 260 TextureManager(GLsizei max_texture_size, |
261 GLsizei max_cube_map_texture_size); | 261 GLsizei max_cube_map_texture_size); |
262 ~TextureManager(); | 262 ~TextureManager(); |
263 | 263 |
264 // Init the texture manager. | 264 // Init the texture manager. |
265 bool Initialize(const FeatureInfo* feature_info); | 265 bool Initialize(const FeatureInfo* feature_info); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 const FeatureInfo* feature_info, | 331 const FeatureInfo* feature_info, |
332 TextureManager::TextureInfo* info); | 332 TextureManager::TextureInfo* info); |
333 | 333 |
334 // Creates a new texture info. | 334 // Creates a new texture info. |
335 TextureInfo* CreateTextureInfo( | 335 TextureInfo* CreateTextureInfo( |
336 const FeatureInfo* feature_info, GLuint client_id, GLuint service_id); | 336 const FeatureInfo* feature_info, GLuint client_id, GLuint service_id); |
337 | 337 |
338 // Gets the texture info for the given texture. | 338 // Gets the texture info for the given texture. |
339 TextureInfo* GetTextureInfo(GLuint client_id); | 339 TextureInfo* GetTextureInfo(GLuint client_id); |
340 | 340 |
341 // Adds a texture info for a texture owned by another texture | |
342 // manager. | |
343 void AddTextureInfo(const FeatureInfo* feature_info, | |
344 GLuint client_id, | |
345 TextureInfo* info); | |
346 | |
347 // Removes a texture info. | 341 // Removes a texture info. |
348 void RemoveTextureInfo(const FeatureInfo* feature_info, GLuint client_id); | 342 void RemoveTextureInfo(const FeatureInfo* feature_info, GLuint client_id); |
349 | 343 |
350 // Gets a client id for a given service id. | 344 // Gets a client id for a given service id. |
351 bool GetClientId(GLuint service_id, GLuint* client_id) const; | 345 bool GetClientId(GLuint service_id, GLuint* client_id) const; |
352 | 346 |
353 TextureInfo* GetDefaultTextureInfo(GLenum target) { | 347 TextureInfo* GetDefaultTextureInfo(GLenum target) { |
354 switch (target) { | 348 switch (target) { |
355 case GL_TEXTURE_2D: | 349 case GL_TEXTURE_2D: |
356 return default_texture_2d_; | 350 return default_texture_2d_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 TextureInfo::Ref default_texture_cube_map_; | 400 TextureInfo::Ref default_texture_cube_map_; |
407 TextureInfo::Ref default_texture_external_oes_; | 401 TextureInfo::Ref default_texture_external_oes_; |
408 | 402 |
409 DISALLOW_COPY_AND_ASSIGN(TextureManager); | 403 DISALLOW_COPY_AND_ASSIGN(TextureManager); |
410 }; | 404 }; |
411 | 405 |
412 } // namespace gles2 | 406 } // namespace gles2 |
413 } // namespace gpu | 407 } // namespace gpu |
414 | 408 |
415 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 409 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
OLD | NEW |