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

Side by Side Diff: gpu/command_buffer/service/texture_manager.h

Issue 14188053: gpu: Change Produce/ConsumeTexture to allow texture sharing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 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 | Annotate | Revision Log
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 <list> 8 #include <list>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
14 #include "base/logging.h" 14 #include "base/logging.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/gl/gl_image.h" 20 #include "ui/gl/gl_image.h"
21 21
22 namespace gpu { 22 namespace gpu {
23 namespace gles2 { 23 namespace gles2 {
24 24
25 class GLES2Decoder; 25 class GLES2Decoder;
26 class Display; 26 class Display;
27 class ErrorState; 27 class ErrorState;
28 class FeatureInfo; 28 class FeatureInfo;
29 class FramebufferManager; 29 class FramebufferManager;
30 class TextureDefinition; 30 class MailboxManager;
31 class TextureManager; 31 class TextureManager;
32 class TextureRef; 32 class TextureRef;
33 33
34 // Info about Textures currently in the system. 34 // Info about Textures currently in the system.
35 // This class wraps a real GL texture, keeping track of its meta-data. It is 35 // This class wraps a real GL texture, keeping track of its meta-data. It is
36 // jointly owned by possibly multiple TextureRef. 36 // jointly owned by possibly multiple TextureRef.
37 class GPU_EXPORT Texture { 37 class GPU_EXPORT Texture {
38 public: 38 public:
39 explicit Texture(GLuint service_id); 39 explicit Texture(GLuint service_id);
40 40
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 // Whether a particular level/face is cleared. 164 // Whether a particular level/face is cleared.
165 bool IsLevelCleared(GLenum target, GLint level) const; 165 bool IsLevelCleared(GLenum target, GLint level) const;
166 166
167 // Whether the texture has been defined 167 // Whether the texture has been defined
168 bool IsDefined() const { 168 bool IsDefined() const {
169 return estimated_size() > 0; 169 return estimated_size() > 0;
170 } 170 }
171 171
172 private: 172 private:
173 friend class MailboxManager;
173 friend class TextureManager; 174 friend class TextureManager;
174 friend class TextureRef; 175 friend class TextureRef;
175 friend class TextureTestHelper; 176 friend class TextureTestHelper;
176 177
177 ~Texture(); 178 ~Texture();
178 void AddTextureRef(TextureRef* ref); 179 void AddTextureRef(TextureRef* ref);
179 void RemoveTextureRef(TextureRef* ref, bool have_context); 180 void RemoveTextureRef(TextureRef* ref, bool have_context);
180 MemoryTypeTracker* GetMemTracker(); 181 MemoryTypeTracker* GetMemTracker();
181 182
182 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it 183 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 const FeatureInfo* feature_info, 298 const FeatureInfo* feature_info,
298 GLenum target, 299 GLenum target,
299 GLint level, 300 GLint level,
300 gfx::GLImage* image); 301 gfx::GLImage* image);
301 302
302 // Appends a signature for the given level. 303 // Appends a signature for the given level.
303 void AddToSignature( 304 void AddToSignature(
304 const FeatureInfo* feature_info, 305 const FeatureInfo* feature_info,
305 GLenum target, GLint level, std::string* signature) const; 306 GLenum target, GLint level, std::string* signature) const;
306 307
308 void SetMailboxManager(MailboxManager* mailbox_manager);
309
307 // Updates the unsafe textures count in all the managers referencing this 310 // Updates the unsafe textures count in all the managers referencing this
308 // texture. 311 // texture.
309 void UpdateSafeToRenderFrom(bool cleared); 312 void UpdateSafeToRenderFrom(bool cleared);
310 313
311 // Updates the uncleared mip count in all the managers referencing this 314 // Updates the uncleared mip count in all the managers referencing this
312 // texture. 315 // texture.
313 void UpdateMipCleared(LevelInfo* info, bool cleared); 316 void UpdateMipCleared(LevelInfo* info, bool cleared);
314 317
315 // Computes the CanRenderCondition flag. 318 // Computes the CanRenderCondition flag.
316 CanRenderCondition GetCanRenderCondition() const; 319 CanRenderCondition GetCanRenderCondition() const;
317 320
318 // Updates the unrenderable texture count in all the managers referencing this 321 // Updates the unrenderable texture count in all the managers referencing this
319 // texture. 322 // texture.
320 void UpdateCanRenderCondition(); 323 void UpdateCanRenderCondition();
321 324
322 // Increment the framebuffer state change count in all the managers 325 // Increment the framebuffer state change count in all the managers
323 // referencing this texture. 326 // referencing this texture.
324 void IncAllFramebufferStateChangeCount(); 327 void IncAllFramebufferStateChangeCount();
325 328
329 MailboxManager* mailbox_manager_;
330
326 // Info about each face and level of texture. 331 // Info about each face and level of texture.
327 std::vector<std::vector<LevelInfo> > level_infos_; 332 std::vector<std::vector<LevelInfo> > level_infos_;
328 333
329 // The texture refs that point to this Texture. 334 // The texture refs that point to this Texture.
330 typedef std::set<TextureRef*> RefSet; 335 typedef std::set<TextureRef*> RefSet;
331 RefSet refs_; 336 RefSet refs_;
332 337
333 // The single TextureRef that accounts for memory for this texture. Must be 338 // The single TextureRef that accounts for memory for this texture. Must be
334 // one of refs_. 339 // one of refs_.
335 TextureRef* memory_tracking_ref_; 340 TextureRef* memory_tracking_ref_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 395
391 DISALLOW_COPY_AND_ASSIGN(Texture); 396 DISALLOW_COPY_AND_ASSIGN(Texture);
392 }; 397 };
393 398
394 // This class represents a texture in a client context group. It's mostly 1:1 399 // This class represents a texture in a client context group. It's mostly 1:1
395 // with a client id, though it can outlive the client id if it's still bound to 400 // with a client id, though it can outlive the client id if it's still bound to
396 // a FBO or another context when destroyed. 401 // a FBO or another context when destroyed.
397 // Multiple TextureRef can point to the same texture with cross-context sharing. 402 // Multiple TextureRef can point to the same texture with cross-context sharing.
398 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> { 403 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> {
399 public: 404 public:
400 TextureRef(TextureManager* manager, Texture* texture); 405 TextureRef(TextureManager* manager, GLuint client_id, Texture* texture);
401 static scoped_refptr<TextureRef> Create(TextureManager* manager, 406 static scoped_refptr<TextureRef> Create(TextureManager* manager,
407 GLuint client_id,
402 GLuint service_id); 408 GLuint service_id);
403 const Texture* texture() const { return texture_; } 409 const Texture* texture() const { return texture_; }
404 Texture* texture() { return texture_; } 410 Texture* texture() { return texture_; }
411 GLuint client_id() const { return client_id_; }
greggman 2013/05/23 17:36:19 I'm not sure I follow the need for this. Is it onl
piman 2013/05/23 18:02:38 It's there to be able to do the Delete in Consume.
405 GLuint service_id() const { return texture_->service_id(); } 412 GLuint service_id() const { return texture_->service_id(); }
406 413
407 // Sets the async transfer state for this texture. Only a single TextureRef 414 // Sets the async transfer state for this texture. Only a single TextureRef
408 // can set this on a given texture at any time. 415 // can set this on a given texture at any time.
409 // NOTE: this should be per-context rather than per-texture. crbug.com/240504 416 // NOTE: this should be per-context rather than per-texture. crbug.com/240504
410 void SetAsyncTransferState( 417 void SetAsyncTransferState(
411 scoped_ptr<AsyncPixelTransferState> state) { 418 scoped_ptr<AsyncPixelTransferState> state) {
412 DCHECK(!state || !texture_->GetAsyncTransferState()); 419 DCHECK(!state || !texture_->GetAsyncTransferState());
413 async_transfer_state_ = state.Pass(); 420 async_transfer_state_ = state.Pass();
414 } 421 }
415 422
416 private: 423 private:
417 friend class base::RefCounted<TextureRef>; 424 friend class base::RefCounted<TextureRef>;
418 friend class Texture; 425 friend class Texture;
419 friend class TextureManager; 426 friend class TextureManager;
420 427
421 ~TextureRef(); 428 ~TextureRef();
422 const TextureManager* manager() const { return manager_; } 429 const TextureManager* manager() const { return manager_; }
423 TextureManager* manager() { return manager_; } 430 TextureManager* manager() { return manager_; }
424 AsyncPixelTransferState* async_transfer_state() const { 431 AsyncPixelTransferState* async_transfer_state() const {
425 return async_transfer_state_.get(); 432 return async_transfer_state_.get();
426 } 433 }
434 void reset_client_id() { client_id_ = 0; }
427 435
428 TextureManager* manager_; 436 TextureManager* manager_;
429 Texture* texture_; 437 Texture* texture_;
438 GLuint client_id_;
430 439
431 // State to facilitate async transfers on this texture. 440 // State to facilitate async transfers on this texture.
432 scoped_ptr<AsyncPixelTransferState> async_transfer_state_; 441 scoped_ptr<AsyncPixelTransferState> async_transfer_state_;
433 442
434 DISALLOW_COPY_AND_ASSIGN(TextureRef); 443 DISALLOW_COPY_AND_ASSIGN(TextureRef);
435 }; 444 };
436 445
437 // This class keeps track of the textures and their sizes so we can do NPOT and 446 // This class keeps track of the textures and their sizes so we can do NPOT and
438 // texture complete checking. 447 // texture complete checking.
439 // 448 //
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // Adapter to call above function. 545 // Adapter to call above function.
537 void SetLevelInfoFromParams(TextureRef* ref, 546 void SetLevelInfoFromParams(TextureRef* ref,
538 const gpu::AsyncTexImage2DParams& params) { 547 const gpu::AsyncTexImage2DParams& params) {
539 SetLevelInfo( 548 SetLevelInfo(
540 ref, params.target, params.level, params.internal_format, 549 ref, params.target, params.level, params.internal_format,
541 params.width, params.height, 1 /* depth */, 550 params.width, params.height, 1 /* depth */,
542 params.border, params.format, 551 params.border, params.format,
543 params.type, true /* cleared */ ); 552 params.type, true /* cleared */ );
544 } 553 }
545 554
546 // Save the texture definition and leave it undefined. 555 Texture* Produce(TextureRef* ref);
547 TextureDefinition* Save(TextureRef* ref);
548 556
549 // Redefine all the levels from the texture definition. 557 // Maps an existing texture into the texture manager, at a given client ID.
550 bool Restore( 558 TextureRef* Consume(GLuint client_id, Texture* texture);
551 const char* function_name,
552 GLES2Decoder* decoder,
553 TextureRef* ref,
554 TextureDefinition* definition);
555 559
556 // Sets a mip as cleared. 560 // Sets a mip as cleared.
557 void SetLevelCleared(TextureRef* ref, GLenum target, 561 void SetLevelCleared(TextureRef* ref, GLenum target,
558 GLint level, bool cleared); 562 GLint level, bool cleared);
559 563
560 // Sets a texture parameter of a Texture 564 // Sets a texture parameter of a Texture
561 // Returns GL_NO_ERROR on success. Otherwise the error to generate. 565 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
562 // TODO(gman): Expand to SetParameteri,f,iv,fv 566 // TODO(gman): Expand to SetParameteri,f,iv,fv
563 void SetParameter( 567 void SetParameter(
564 const char* function_name, ErrorState* error_state, 568 const char* function_name, ErrorState* error_state,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 // The default textures for each target (texture name = 0) 706 // The default textures for each target (texture name = 0)
703 scoped_refptr<TextureRef> default_textures_[kNumDefaultTextures]; 707 scoped_refptr<TextureRef> default_textures_[kNumDefaultTextures];
704 708
705 DISALLOW_COPY_AND_ASSIGN(TextureManager); 709 DISALLOW_COPY_AND_ASSIGN(TextureManager);
706 }; 710 };
707 711
708 } // namespace gles2 712 } // namespace gles2
709 } // namespace gpu 713 } // namespace gpu
710 714
711 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 715 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698