| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 CC_RESOURCES_RESOURCE_PROVIDER_H_ | 5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ | 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 | 73 |
| 74 // Producer interface. | 74 // Producer interface. |
| 75 | 75 |
| 76 ResourceType default_resource_type() const { return default_resource_type_; } | 76 ResourceType default_resource_type() const { return default_resource_type_; } |
| 77 ResourceType GetResourceType(ResourceId id); | 77 ResourceType GetResourceType(ResourceId id); |
| 78 | 78 |
| 79 // Creates a resource of the default resource type. | 79 // Creates a resource of the default resource type. |
| 80 ResourceId CreateResource(gfx::Size size, | 80 ResourceId CreateResource(gfx::Size size, |
| 81 GLenum format, | 81 GLenum format, |
| 82 GLint wrap_mode, |
| 82 TextureUsageHint hint); | 83 TextureUsageHint hint); |
| 83 | 84 |
| 84 // Creates a resource which is tagged as being managed for GPU memory | 85 // Creates a resource which is tagged as being managed for GPU memory |
| 85 // accounting purposes. | 86 // accounting purposes. |
| 86 ResourceId CreateManagedResource(gfx::Size size, | 87 ResourceId CreateManagedResource(gfx::Size size, |
| 87 GLenum format, | 88 GLenum format, |
| 89 GLint wrap_mode, |
| 88 TextureUsageHint hint); | 90 TextureUsageHint hint); |
| 89 | 91 |
| 90 // You can also explicitly create a specific resource type. | 92 // You can also explicitly create a specific resource type. |
| 91 ResourceId CreateGLTexture(gfx::Size size, | 93 ResourceId CreateGLTexture(gfx::Size size, |
| 92 GLenum format, | 94 GLenum format, |
| 93 GLenum texture_pool, | 95 GLenum texture_pool, |
| 96 GLint wrap_mode, |
| 94 TextureUsageHint hint); | 97 TextureUsageHint hint); |
| 95 | 98 |
| 96 ResourceId CreateBitmap(gfx::Size size); | 99 ResourceId CreateBitmap(gfx::Size size); |
| 97 // Wraps an external texture into a GL resource. | 100 // Wraps an external texture into a GL resource. |
| 98 ResourceId CreateResourceFromExternalTexture( | 101 ResourceId CreateResourceFromExternalTexture( |
| 99 unsigned texture_target, | 102 unsigned texture_target, |
| 100 unsigned texture_id); | 103 unsigned texture_id); |
| 101 | 104 |
| 102 // Wraps an external texture mailbox into a GL resource. | 105 // Wraps an external texture mailbox into a GL resource. |
| 103 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); | 106 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // Returns the stride for the image. | 306 // Returns the stride for the image. |
| 304 int GetImageStride(ResourceId id); | 307 int GetImageStride(ResourceId id); |
| 305 | 308 |
| 306 // For tests only! This prevents detecting uninitialized reads. | 309 // For tests only! This prevents detecting uninitialized reads. |
| 307 // Use SetPixels or LockForWrite to allocate implicitly. | 310 // Use SetPixels or LockForWrite to allocate implicitly. |
| 308 void AllocateForTesting(ResourceId id); | 311 void AllocateForTesting(ResourceId id); |
| 309 | 312 |
| 310 // For tests only! | 313 // For tests only! |
| 311 void CreateForTesting(ResourceId id); | 314 void CreateForTesting(ResourceId id); |
| 312 | 315 |
| 316 GLint WrapModeForTesting(ResourceId id); |
| 317 |
| 313 // Sets the current read fence. If a resource is locked for read | 318 // Sets the current read fence. If a resource is locked for read |
| 314 // and has read fences enabled, the resource will not allow writes | 319 // and has read fences enabled, the resource will not allow writes |
| 315 // until this fence has passed. | 320 // until this fence has passed. |
| 316 void SetReadLockFence(scoped_refptr<Fence> fence) { | 321 void SetReadLockFence(scoped_refptr<Fence> fence) { |
| 317 current_read_lock_fence_ = fence; | 322 current_read_lock_fence_ = fence; |
| 318 } | 323 } |
| 319 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } | 324 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } |
| 320 | 325 |
| 321 // Enable read lock fences for a specific resource. | 326 // Enable read lock fences for a specific resource. |
| 322 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); | 327 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); |
| 323 | 328 |
| 324 // Indicates if we can currently lock this resource for write. | 329 // Indicates if we can currently lock this resource for write. |
| 325 bool CanLockForWrite(ResourceId id); | 330 bool CanLockForWrite(ResourceId id); |
| 326 | 331 |
| 327 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); | 332 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); |
| 328 | 333 |
| 329 private: | 334 private: |
| 330 struct Resource { | 335 struct Resource { |
| 331 Resource(); | 336 Resource(); |
| 332 ~Resource(); | 337 ~Resource(); |
| 333 Resource(unsigned texture_id, | 338 Resource(unsigned texture_id, |
| 334 gfx::Size size, | 339 gfx::Size size, |
| 335 GLenum format, | 340 GLenum format, |
| 336 GLenum filter, | 341 GLenum filter, |
| 337 GLenum texture_pool, | 342 GLenum texture_pool, |
| 343 GLint wrap_mode, |
| 338 TextureUsageHint hint); | 344 TextureUsageHint hint); |
| 339 Resource(uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter); | 345 Resource(uint8_t* pixels, |
| 346 gfx::Size size, |
| 347 GLenum format, |
| 348 GLenum filter, |
| 349 GLint wrap_mode); |
| 340 | 350 |
| 341 unsigned gl_id; | 351 unsigned gl_id; |
| 342 // Pixel buffer used for set pixels without unnecessary copying. | 352 // Pixel buffer used for set pixels without unnecessary copying. |
| 343 unsigned gl_pixel_buffer_id; | 353 unsigned gl_pixel_buffer_id; |
| 344 // Query used to determine when asynchronous set pixels complete. | 354 // Query used to determine when asynchronous set pixels complete. |
| 345 unsigned gl_upload_query_id; | 355 unsigned gl_upload_query_id; |
| 346 TextureMailbox mailbox; | 356 TextureMailbox mailbox; |
| 347 uint8_t* pixels; | 357 uint8_t* pixels; |
| 348 uint8_t* pixel_buffer; | 358 uint8_t* pixel_buffer; |
| 349 int lock_for_read_count; | 359 int lock_for_read_count; |
| 350 int imported_count; | 360 int imported_count; |
| 351 int exported_count; | 361 int exported_count; |
| 352 bool locked_for_write; | 362 bool locked_for_write; |
| 353 bool external; | 363 bool external; |
| 354 bool marked_for_deletion; | 364 bool marked_for_deletion; |
| 355 bool pending_set_pixels; | 365 bool pending_set_pixels; |
| 356 bool set_pixels_completion_forced; | 366 bool set_pixels_completion_forced; |
| 357 bool allocated; | 367 bool allocated; |
| 358 bool enable_read_lock_fences; | 368 bool enable_read_lock_fences; |
| 359 scoped_refptr<Fence> read_lock_fence; | 369 scoped_refptr<Fence> read_lock_fence; |
| 360 gfx::Size size; | 370 gfx::Size size; |
| 361 GLenum format; | 371 GLenum format; |
| 362 // TODO(skyostil): Use a separate sampler object for filter state. | 372 // TODO(skyostil): Use a separate sampler object for filter state. |
| 363 GLenum filter; | 373 GLenum filter; |
| 364 unsigned image_id; | 374 unsigned image_id; |
| 365 GLenum texture_pool; | 375 GLenum texture_pool; |
| 376 GLint wrap_mode; |
| 366 TextureUsageHint hint; | 377 TextureUsageHint hint; |
| 367 ResourceType type; | 378 ResourceType type; |
| 368 }; | 379 }; |
| 369 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 380 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
| 370 struct Child { | 381 struct Child { |
| 371 Child(); | 382 Child(); |
| 372 ~Child(); | 383 ~Child(); |
| 373 | 384 |
| 374 ResourceIdMap child_to_parent_map; | 385 ResourceIdMap child_to_parent_map; |
| 375 ResourceIdMap parent_to_child_map; | 386 ResourceIdMap parent_to_child_map; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 base::ThreadChecker thread_checker_; | 449 base::ThreadChecker thread_checker_; |
| 439 | 450 |
| 440 scoped_refptr<Fence> current_read_lock_fence_; | 451 scoped_refptr<Fence> current_read_lock_fence_; |
| 441 | 452 |
| 442 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 453 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 443 }; | 454 }; |
| 444 | 455 |
| 445 } // namespace cc | 456 } // namespace cc |
| 446 | 457 |
| 447 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 458 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |