Chromium Code Reviews| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; | 45 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; |
| 46 enum TextureUsageHint { | 46 enum TextureUsageHint { |
| 47 TextureUsageAny, | 47 TextureUsageAny, |
| 48 TextureUsageFramebuffer, | 48 TextureUsageFramebuffer, |
| 49 }; | 49 }; |
| 50 enum ResourceType { | 50 enum ResourceType { |
| 51 InvalidType = 0, | 51 InvalidType = 0, |
| 52 GLTexture = 1, | 52 GLTexture = 1, |
| 53 Bitmap, | 53 Bitmap, |
| 54 }; | 54 }; |
| 55 enum TextureType { | |
| 56 INVALID_TYPE, | |
|
reveman
2013/09/11 20:19:13
Do we need INVALID_TYPE? It's easier to maintain a
kaanb
2013/09/12 07:53:44
There were cases where 0 was being used as the GL
| |
| 57 RGBA_8888, | |
| 58 RGBA_4444, | |
| 59 BGRA_8888, | |
| 60 }; | |
| 55 | 61 |
| 56 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, | 62 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, |
| 57 int highp_threshold_min); | 63 int highp_threshold_min); |
| 58 | 64 |
| 59 virtual ~ResourceProvider(); | 65 virtual ~ResourceProvider(); |
| 60 | 66 |
| 61 void InitializeSoftware(); | 67 void InitializeSoftware(); |
| 62 bool InitializeGL(); | 68 bool InitializeGL(); |
| 63 | 69 |
| 64 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 70 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
| 65 | 71 |
| 66 int max_texture_size() const { return max_texture_size_; } | 72 int max_texture_size() const { return max_texture_size_; } |
| 67 GLenum best_texture_format() const { return best_texture_format_; } | 73 GLenum best_texture_format() const { return best_texture_format_; } |
| 68 size_t num_resources() const { return resources_.size(); } | 74 size_t num_resources() const { return resources_.size(); } |
| 69 | 75 |
| 70 // Checks whether a resource is in use by a consumer. | 76 // Checks whether a resource is in use by a consumer. |
| 71 bool InUseByConsumer(ResourceId id); | 77 bool InUseByConsumer(ResourceId id); |
| 72 | 78 |
| 73 | 79 |
| 74 // Producer interface. | 80 // Producer interface. |
| 75 | 81 |
| 76 ResourceType default_resource_type() const { return default_resource_type_; } | 82 ResourceType default_resource_type() const { return default_resource_type_; } |
| 77 ResourceType GetResourceType(ResourceId id); | 83 ResourceType GetResourceType(ResourceId id); |
| 78 | 84 |
| 79 // Creates a resource of the default resource type. | 85 // Creates a resource of the default resource type. |
| 80 ResourceId CreateResource(gfx::Size size, | 86 ResourceId CreateResource(gfx::Size size, |
| 81 GLenum format, | 87 GLenum format, |
| 82 GLint wrap_mode, | 88 GLint wrap_mode, |
| 83 TextureUsageHint hint); | 89 TextureUsageHint hint, |
| 90 TextureType texture_type); | |
|
epennerAtGoogle
2013/09/11 19:21:04
This is nice, IMO :)
reveman
2013/09/11 20:19:13
Could the enum type be TextureFormat instead and r
kaanb
2013/09/12 07:53:44
Done.
| |
| 84 | 91 |
| 85 // Creates a resource which is tagged as being managed for GPU memory | 92 // Creates a resource which is tagged as being managed for GPU memory |
| 86 // accounting purposes. | 93 // accounting purposes. |
| 87 ResourceId CreateManagedResource(gfx::Size size, | 94 ResourceId CreateManagedResource(gfx::Size size, |
| 88 GLenum format, | 95 GLenum format, |
| 89 GLint wrap_mode, | 96 GLint wrap_mode, |
| 90 TextureUsageHint hint); | 97 TextureUsageHint hint, |
| 98 TextureType texture_type); | |
| 91 | 99 |
| 92 // You can also explicitly create a specific resource type. | 100 // You can also explicitly create a specific resource type. |
| 93 ResourceId CreateGLTexture(gfx::Size size, | 101 ResourceId CreateGLTexture(gfx::Size size, |
| 94 GLenum format, | 102 GLenum format, |
| 95 GLenum texture_pool, | 103 GLenum texture_pool, |
| 96 GLint wrap_mode, | 104 GLint wrap_mode, |
| 97 TextureUsageHint hint); | 105 TextureUsageHint hint, |
| 106 TextureType texture_type); | |
| 98 | 107 |
| 99 ResourceId CreateBitmap(gfx::Size size); | 108 ResourceId CreateBitmap(gfx::Size size); |
| 100 // Wraps an external texture into a GL resource. | 109 // Wraps an external texture into a GL resource. |
| 101 ResourceId CreateResourceFromExternalTexture( | 110 ResourceId CreateResourceFromExternalTexture( |
| 102 unsigned texture_target, | 111 unsigned texture_target, |
| 103 unsigned texture_id); | 112 unsigned texture_id); |
| 104 | 113 |
| 105 // Wraps an external texture mailbox into a GL resource. | 114 // Wraps an external texture mailbox into a GL resource. |
| 106 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); | 115 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); |
| 107 | 116 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 } | 332 } |
| 324 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } | 333 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } |
| 325 | 334 |
| 326 // Enable read lock fences for a specific resource. | 335 // Enable read lock fences for a specific resource. |
| 327 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); | 336 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); |
| 328 | 337 |
| 329 // Indicates if we can currently lock this resource for write. | 338 // Indicates if we can currently lock this resource for write. |
| 330 bool CanLockForWrite(ResourceId id); | 339 bool CanLockForWrite(ResourceId id); |
| 331 | 340 |
| 332 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); | 341 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); |
| 342 static size_t BytesPerPixel(GLenum format, TextureType type); | |
| 343 static GLenum GetTextureDataType(GLenum texture_type); | |
|
epennerAtGoogle
2013/09/11 19:21:04
Could we call this GetGLTextureType, and also add
reveman
2013/09/11 20:19:13
Yes, something like the following set of helper fu
kaanb
2013/09/12 07:53:44
Done.
| |
| 333 | 344 |
| 334 private: | 345 private: |
| 335 struct Resource { | 346 struct Resource { |
| 336 Resource(); | 347 Resource(); |
| 337 ~Resource(); | 348 ~Resource(); |
| 338 Resource(unsigned texture_id, | 349 Resource(unsigned texture_id, |
| 339 gfx::Size size, | 350 gfx::Size size, |
| 340 GLenum format, | 351 GLenum format, |
| 341 GLenum filter, | 352 GLenum filter, |
| 342 GLenum texture_pool, | 353 GLenum texture_pool, |
| 343 GLint wrap_mode, | 354 GLint wrap_mode, |
| 344 TextureUsageHint hint); | 355 TextureUsageHint hint, |
| 356 TextureType texture_type); | |
| 345 Resource(uint8_t* pixels, | 357 Resource(uint8_t* pixels, |
| 346 gfx::Size size, | 358 gfx::Size size, |
| 347 GLenum format, | 359 GLenum format, |
| 348 GLenum filter, | 360 GLenum filter, |
| 349 GLint wrap_mode); | 361 GLint wrap_mode); |
| 350 | 362 |
| 351 unsigned gl_id; | 363 unsigned gl_id; |
| 352 // Pixel buffer used for set pixels without unnecessary copying. | 364 // Pixel buffer used for set pixels without unnecessary copying. |
| 353 unsigned gl_pixel_buffer_id; | 365 unsigned gl_pixel_buffer_id; |
| 354 // Query used to determine when asynchronous set pixels complete. | 366 // Query used to determine when asynchronous set pixels complete. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 369 scoped_refptr<Fence> read_lock_fence; | 381 scoped_refptr<Fence> read_lock_fence; |
| 370 gfx::Size size; | 382 gfx::Size size; |
| 371 GLenum format; | 383 GLenum format; |
| 372 // TODO(skyostil): Use a separate sampler object for filter state. | 384 // TODO(skyostil): Use a separate sampler object for filter state. |
| 373 GLenum filter; | 385 GLenum filter; |
| 374 unsigned image_id; | 386 unsigned image_id; |
| 375 GLenum texture_pool; | 387 GLenum texture_pool; |
| 376 GLint wrap_mode; | 388 GLint wrap_mode; |
| 377 TextureUsageHint hint; | 389 TextureUsageHint hint; |
| 378 ResourceType type; | 390 ResourceType type; |
| 391 TextureType texture_type; | |
| 379 }; | 392 }; |
| 380 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 393 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
| 381 struct Child { | 394 struct Child { |
| 382 Child(); | 395 Child(); |
| 383 ~Child(); | 396 ~Child(); |
| 384 | 397 |
| 385 ResourceIdMap child_to_parent_map; | 398 ResourceIdMap child_to_parent_map; |
| 386 ResourceIdMap parent_to_child_map; | 399 ResourceIdMap parent_to_child_map; |
| 387 }; | 400 }; |
| 388 typedef base::hash_map<int, Child> ChildMap; | 401 typedef base::hash_map<int, Child> ChildMap; |
| 389 | 402 |
| 390 bool ReadLockFenceHasPassed(Resource* resource) { | 403 bool ReadLockFenceHasPassed(Resource* resource) { |
| 391 return !resource->read_lock_fence.get() || | 404 return !resource->read_lock_fence.get() || |
| 392 resource->read_lock_fence->HasPassed(); | 405 resource->read_lock_fence->HasPassed(); |
| 393 } | 406 } |
| 394 | 407 |
| 395 explicit ResourceProvider(OutputSurface* output_surface, | 408 ResourceProvider(OutputSurface* output_surface, |
| 396 int highp_threshold_min); | 409 int highp_threshold_min); |
| 397 | 410 |
| 398 void CleanUpGLIfNeeded(); | 411 void CleanUpGLIfNeeded(); |
| 399 | 412 |
| 400 Resource* GetResource(ResourceId id); | 413 Resource* GetResource(ResourceId id); |
| 401 const Resource* LockForRead(ResourceId id); | 414 const Resource* LockForRead(ResourceId id); |
| 402 void UnlockForRead(ResourceId id); | 415 void UnlockForRead(ResourceId id); |
| 403 const Resource* LockForWrite(ResourceId id); | 416 const Resource* LockForWrite(ResourceId id); |
| 404 void UnlockForWrite(ResourceId id); | 417 void UnlockForWrite(ResourceId id); |
| 405 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 418 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 406 const Resource* resource); | 419 const Resource* resource); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 base::ThreadChecker thread_checker_; | 462 base::ThreadChecker thread_checker_; |
| 450 | 463 |
| 451 scoped_refptr<Fence> current_read_lock_fence_; | 464 scoped_refptr<Fence> current_read_lock_fence_; |
| 452 | 465 |
| 453 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 466 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 454 }; | 467 }; |
| 455 | 468 |
| 456 } // namespace cc | 469 } // namespace cc |
| 457 | 470 |
| 458 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 471 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |