OLD | NEW |
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/async_pixel_transfer_delegate.h" | 16 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.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/gpu_export.h" | 19 #include "gpu/gpu_export.h" |
| 20 #include "ui/gfx/geometry/rect.h" |
20 #include "ui/gl/gl_image.h" | 21 #include "ui/gl/gl_image.h" |
21 | 22 |
22 namespace gpu { | 23 namespace gpu { |
23 namespace gles2 { | 24 namespace gles2 { |
24 | 25 |
25 class GLES2Decoder; | 26 class GLES2Decoder; |
26 struct ContextState; | 27 struct ContextState; |
27 struct DecoderFramebufferState; | 28 struct DecoderFramebufferState; |
28 class Display; | 29 class Display; |
29 class ErrorState; | 30 class ErrorState; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 176 } |
176 | 177 |
177 void SetImmutable(bool immutable) { | 178 void SetImmutable(bool immutable) { |
178 immutable_ = immutable; | 179 immutable_ = immutable; |
179 } | 180 } |
180 | 181 |
181 bool IsImmutable() const { | 182 bool IsImmutable() const { |
182 return immutable_; | 183 return immutable_; |
183 } | 184 } |
184 | 185 |
| 186 // Get the cleared rectangle for a particular level. Returns an empty |
| 187 // rectangle if level does not exist. |
| 188 gfx::Rect GetLevelClearedRect(GLenum target, GLint level) const; |
| 189 |
185 // Whether a particular level/face is cleared. | 190 // Whether a particular level/face is cleared. |
186 bool IsLevelCleared(GLenum target, GLint level) const; | 191 bool IsLevelCleared(GLenum target, GLint level) const; |
187 | 192 |
188 // Whether the texture has been defined | 193 // Whether the texture has been defined |
189 bool IsDefined() const { | 194 bool IsDefined() const { |
190 return estimated_size() > 0; | 195 return estimated_size() > 0; |
191 } | 196 } |
192 | 197 |
193 // Initialize TEXTURE_MAX_ANISOTROPY to 1 if we haven't done so yet. | 198 // Initialize TEXTURE_MAX_ANISOTROPY to 1 if we haven't done so yet. |
194 void InitTextureMaxAnisotropyIfNeeded(GLenum target); | 199 void InitTextureMaxAnisotropyIfNeeded(GLenum target); |
(...skipping 25 matching lines...) Expand all Loading... |
220 CAN_RENDER_ALWAYS, | 225 CAN_RENDER_ALWAYS, |
221 CAN_RENDER_NEVER, | 226 CAN_RENDER_NEVER, |
222 CAN_RENDER_ONLY_IF_NPOT | 227 CAN_RENDER_ONLY_IF_NPOT |
223 }; | 228 }; |
224 | 229 |
225 struct LevelInfo { | 230 struct LevelInfo { |
226 LevelInfo(); | 231 LevelInfo(); |
227 LevelInfo(const LevelInfo& rhs); | 232 LevelInfo(const LevelInfo& rhs); |
228 ~LevelInfo(); | 233 ~LevelInfo(); |
229 | 234 |
230 bool cleared; | 235 gfx::Rect cleared_rect; |
231 GLenum target; | 236 GLenum target; |
232 GLint level; | 237 GLint level; |
233 GLenum internal_format; | 238 GLenum internal_format; |
234 GLsizei width; | 239 GLsizei width; |
235 GLsizei height; | 240 GLsizei height; |
236 GLsizei depth; | 241 GLsizei depth; |
237 GLint border; | 242 GLint border; |
238 GLenum format; | 243 GLenum format; |
239 GLenum type; | 244 GLenum type; |
240 scoped_refptr<gfx::GLImage> image; | 245 scoped_refptr<gfx::GLImage> image; |
241 uint32 estimated_size; | 246 uint32 estimated_size; |
242 }; | 247 }; |
243 | 248 |
244 struct FaceInfo { | 249 struct FaceInfo { |
245 FaceInfo(); | 250 FaceInfo(); |
246 ~FaceInfo(); | 251 ~FaceInfo(); |
247 | 252 |
248 GLsizei num_mip_levels; | 253 GLsizei num_mip_levels; |
249 std::vector<LevelInfo> level_infos; | 254 std::vector<LevelInfo> level_infos; |
250 }; | 255 }; |
251 | 256 |
252 // Set the info for a particular level. | 257 // Set the info for a particular level. |
253 void SetLevelInfo( | 258 void SetLevelInfo(const FeatureInfo* feature_info, |
254 const FeatureInfo* feature_info, | 259 GLenum target, |
255 GLenum target, | 260 GLint level, |
256 GLint level, | 261 GLenum internal_format, |
257 GLenum internal_format, | 262 GLsizei width, |
258 GLsizei width, | 263 GLsizei height, |
259 GLsizei height, | 264 GLsizei depth, |
260 GLsizei depth, | 265 GLint border, |
261 GLint border, | 266 GLenum format, |
262 GLenum format, | 267 GLenum type, |
263 GLenum type, | 268 const gfx::Rect& cleared_rect); |
264 bool cleared); | |
265 | 269 |
266 // In GLES2 "texture complete" means it has all required mips for filtering | 270 // 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 | 271 // down to a 1x1 pixel texture, they are in the correct order, they are all |
268 // the same format. | 272 // the same format. |
269 bool texture_complete() const { | 273 bool texture_complete() const { |
270 return texture_complete_; | 274 return texture_complete_; |
271 } | 275 } |
272 | 276 |
273 // In GLES2 "cube complete" means all 6 faces level 0 are defined, all the | 277 // 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. | 278 // same format, all the same dimensions and all width = height. |
275 bool cube_complete() const { | 279 bool cube_complete() const { |
276 return cube_complete_; | 280 return cube_complete_; |
277 } | 281 } |
278 | 282 |
279 // Whether or not this texture is a non-power-of-two texture. | 283 // Whether or not this texture is a non-power-of-two texture. |
280 bool npot() const { | 284 bool npot() const { |
281 return npot_; | 285 return npot_; |
282 } | 286 } |
283 | 287 |
| 288 // Marks a |rect| of a particular level as cleared. |
| 289 void SetLevelClearedRect(GLenum target, |
| 290 GLint level, |
| 291 const gfx::Rect& cleared_rect); |
| 292 |
284 // Marks a particular level as cleared or uncleared. | 293 // Marks a particular level as cleared or uncleared. |
285 void SetLevelCleared(GLenum target, GLint level, bool cleared); | 294 void SetLevelCleared(GLenum target, GLint level, bool cleared); |
286 | 295 |
287 // Updates the cleared flag for this texture by inspecting all the mips. | 296 // Updates the cleared flag for this texture by inspecting all the mips. |
288 void UpdateCleared(); | 297 void UpdateCleared(); |
289 | 298 |
290 // Clears any renderable uncleared levels. | 299 // Clears any renderable uncleared levels. |
291 // Returns false if a GL error was generated. | 300 // Returns false if a GL error was generated. |
292 bool ClearRenderableLevels(GLES2Decoder* decoder); | 301 bool ClearRenderableLevels(GLES2Decoder* decoder); |
293 | 302 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 GLenum target, GLint level, std::string* signature) const; | 376 GLenum target, GLint level, std::string* signature) const; |
368 | 377 |
369 void SetMailboxManager(MailboxManager* mailbox_manager); | 378 void SetMailboxManager(MailboxManager* mailbox_manager); |
370 | 379 |
371 // Updates the unsafe textures count in all the managers referencing this | 380 // Updates the unsafe textures count in all the managers referencing this |
372 // texture. | 381 // texture. |
373 void UpdateSafeToRenderFrom(bool cleared); | 382 void UpdateSafeToRenderFrom(bool cleared); |
374 | 383 |
375 // Updates the uncleared mip count in all the managers referencing this | 384 // Updates the uncleared mip count in all the managers referencing this |
376 // texture. | 385 // texture. |
377 void UpdateMipCleared(LevelInfo* info, bool cleared); | 386 void UpdateMipCleared(LevelInfo* info, |
| 387 GLsizei width, |
| 388 GLsizei height, |
| 389 const gfx::Rect& cleared_rect); |
378 | 390 |
379 // Computes the CanRenderCondition flag. | 391 // Computes the CanRenderCondition flag. |
380 CanRenderCondition GetCanRenderCondition() const; | 392 CanRenderCondition GetCanRenderCondition() const; |
381 | 393 |
382 // Updates the unrenderable texture count in all the managers referencing this | 394 // Updates the unrenderable texture count in all the managers referencing this |
383 // texture. | 395 // texture. |
384 void UpdateCanRenderCondition(); | 396 void UpdateCanRenderCondition(); |
385 | 397 |
386 // Updates the images count in all the managers referencing this | 398 // Updates the images count in all the managers referencing this |
387 // texture. | 399 // texture. |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 // Sets the Texture's target | 654 // Sets the Texture's target |
643 // Parameters: | 655 // Parameters: |
644 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 656 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
645 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3) | 657 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3) |
646 // max_levels: The maximum levels this type of target can have. | 658 // max_levels: The maximum levels this type of target can have. |
647 void SetTarget( | 659 void SetTarget( |
648 TextureRef* ref, | 660 TextureRef* ref, |
649 GLenum target); | 661 GLenum target); |
650 | 662 |
651 // Set the info for a particular level in a TexureInfo. | 663 // Set the info for a particular level in a TexureInfo. |
652 void SetLevelInfo( | 664 void SetLevelInfo(TextureRef* ref, |
653 TextureRef* ref, | 665 GLenum target, |
654 GLenum target, | 666 GLint level, |
655 GLint level, | 667 GLenum internal_format, |
656 GLenum internal_format, | 668 GLsizei width, |
657 GLsizei width, | 669 GLsizei height, |
658 GLsizei height, | 670 GLsizei depth, |
659 GLsizei depth, | 671 GLint border, |
660 GLint border, | 672 GLenum format, |
661 GLenum format, | 673 GLenum type, |
662 GLenum type, | 674 const gfx::Rect& cleared_rect); |
663 bool cleared); | |
664 | 675 |
665 // Adapter to call above function. | 676 // Adapter to call above function. |
666 void SetLevelInfoFromParams(TextureRef* ref, | 677 void SetLevelInfoFromParams(TextureRef* ref, |
667 const gpu::AsyncTexImage2DParams& params) { | 678 const gpu::AsyncTexImage2DParams& params) { |
668 SetLevelInfo( | 679 SetLevelInfo(ref, params.target, params.level, params.internal_format, |
669 ref, params.target, params.level, params.internal_format, | 680 params.width, params.height, 1 /* depth */, params.border, |
670 params.width, params.height, 1 /* depth */, | 681 params.format, params.type, |
671 params.border, params.format, | 682 gfx::Rect(params.width, params.height) /* cleared_rect */); |
672 params.type, true /* cleared */); | |
673 } | 683 } |
674 | 684 |
675 Texture* Produce(TextureRef* ref); | 685 Texture* Produce(TextureRef* ref); |
676 | 686 |
677 // Maps an existing texture into the texture manager, at a given client ID. | 687 // Maps an existing texture into the texture manager, at a given client ID. |
678 TextureRef* Consume(GLuint client_id, Texture* texture); | 688 TextureRef* Consume(GLuint client_id, Texture* texture); |
679 | 689 |
| 690 // Sets |rect| of mip as cleared. |
| 691 void SetLevelClearedRect(TextureRef* ref, |
| 692 GLenum target, |
| 693 GLint level, |
| 694 const gfx::Rect& cleared_rect); |
| 695 |
680 // Sets a mip as cleared. | 696 // Sets a mip as cleared. |
681 void SetLevelCleared(TextureRef* ref, GLenum target, | 697 void SetLevelCleared(TextureRef* ref, GLenum target, |
682 GLint level, bool cleared); | 698 GLint level, bool cleared); |
683 | 699 |
684 // Sets a texture parameter of a Texture | 700 // Sets a texture parameter of a Texture |
685 // Returns GL_NO_ERROR on success. Otherwise the error to generate. | 701 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
686 // TODO(gman): Expand to SetParameteriv,fv | 702 // TODO(gman): Expand to SetParameteriv,fv |
687 void SetParameteri( | 703 void SetParameteri( |
688 const char* function_name, ErrorState* error_state, | 704 const char* function_name, ErrorState* error_state, |
689 TextureRef* ref, GLenum pname, GLint param); | 705 TextureRef* ref, GLenum pname, GLint param); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 private: | 949 private: |
934 DecoderTextureState* texture_state_; | 950 DecoderTextureState* texture_state_; |
935 base::TimeTicks begin_time_; | 951 base::TimeTicks begin_time_; |
936 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer); | 952 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer); |
937 }; | 953 }; |
938 | 954 |
939 } // namespace gles2 | 955 } // namespace gles2 |
940 } // namespace gpu | 956 } // namespace gpu |
941 | 957 |
942 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 958 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
OLD | NEW |