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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
| 19 #include "cc/output/context_provider.h" | 19 #include "cc/output/context_provider.h" |
| 20 #include "cc/output/output_surface.h" | 20 #include "cc/output/output_surface.h" |
| 21 #include "cc/resources/resource_format.h" | |
| 21 #include "cc/resources/texture_mailbox.h" | 22 #include "cc/resources/texture_mailbox.h" |
| 22 #include "cc/resources/transferable_resource.h" | 23 #include "cc/resources/transferable_resource.h" |
| 23 #include "third_party/khronos/GLES2/gl2.h" | 24 #include "third_party/khronos/GLES2/gl2.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
| 26 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
| 27 | 28 |
| 28 namespace WebKit { class WebGraphicsContext3D; } | 29 namespace WebKit { class WebGraphicsContext3D; } |
| 29 | 30 |
| 30 namespace gfx { | 31 namespace gfx { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 47 TextureUsageAny, | 48 TextureUsageAny, |
| 48 TextureUsageFramebuffer, | 49 TextureUsageFramebuffer, |
| 49 }; | 50 }; |
| 50 enum ResourceType { | 51 enum ResourceType { |
| 51 InvalidType = 0, | 52 InvalidType = 0, |
| 52 GLTexture = 1, | 53 GLTexture = 1, |
| 53 Bitmap, | 54 Bitmap, |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, | 57 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, |
| 57 int highp_threshold_min); | 58 int highp_threshold_min, |
| 58 | 59 bool use_rgba_4444_texture_format); |
|
epenner
2013/09/17 19:29:28
Nit: Can we remove this and just pass in both 'bes
| |
| 59 virtual ~ResourceProvider(); | 60 virtual ~ResourceProvider(); |
| 60 | 61 |
| 61 void InitializeSoftware(); | 62 void InitializeSoftware(); |
| 62 bool InitializeGL(); | 63 bool InitializeGL(); |
| 63 | 64 |
| 64 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 65 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
| 65 | 66 |
| 66 int max_texture_size() const { return max_texture_size_; } | 67 int max_texture_size() const { return max_texture_size_; } |
| 67 GLenum best_texture_format() const { return best_texture_format_; } | 68 ResourceFormat memory_efficient_texture_format() const { |
| 69 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; | |
| 70 } | |
| 71 ResourceFormat best_texture_format() const { return best_texture_format_; } | |
| 68 size_t num_resources() const { return resources_.size(); } | 72 size_t num_resources() const { return resources_.size(); } |
| 69 | 73 |
| 70 // Checks whether a resource is in use by a consumer. | 74 // Checks whether a resource is in use by a consumer. |
| 71 bool InUseByConsumer(ResourceId id); | 75 bool InUseByConsumer(ResourceId id); |
| 72 | 76 |
| 73 | 77 |
| 74 // Producer interface. | 78 // Producer interface. |
| 75 | 79 |
| 76 ResourceType default_resource_type() const { return default_resource_type_; } | 80 ResourceType default_resource_type() const { return default_resource_type_; } |
| 77 ResourceType GetResourceType(ResourceId id); | 81 ResourceType GetResourceType(ResourceId id); |
| 78 | 82 |
| 79 // Creates a resource of the default resource type. | 83 // Creates a resource of the default resource type. |
| 80 ResourceId CreateResource(gfx::Size size, | 84 ResourceId CreateResource(gfx::Size size, |
| 81 GLenum format, | |
| 82 GLint wrap_mode, | 85 GLint wrap_mode, |
| 83 TextureUsageHint hint); | 86 TextureUsageHint hint, |
| 87 ResourceFormat format); | |
| 84 | 88 |
| 85 // Creates a resource which is tagged as being managed for GPU memory | 89 // Creates a resource which is tagged as being managed for GPU memory |
| 86 // accounting purposes. | 90 // accounting purposes. |
| 87 ResourceId CreateManagedResource(gfx::Size size, | 91 ResourceId CreateManagedResource(gfx::Size size, |
| 88 GLenum format, | |
| 89 GLint wrap_mode, | 92 GLint wrap_mode, |
| 90 TextureUsageHint hint); | 93 TextureUsageHint hint, |
| 94 ResourceFormat format); | |
| 91 | 95 |
| 92 // You can also explicitly create a specific resource type. | 96 // You can also explicitly create a specific resource type. |
| 93 ResourceId CreateGLTexture(gfx::Size size, | 97 ResourceId CreateGLTexture(gfx::Size size, |
| 94 GLenum format, | |
| 95 GLenum texture_pool, | 98 GLenum texture_pool, |
| 96 GLint wrap_mode, | 99 GLint wrap_mode, |
| 97 TextureUsageHint hint); | 100 TextureUsageHint hint, |
| 101 ResourceFormat format); | |
| 98 | 102 |
| 99 ResourceId CreateBitmap(gfx::Size size); | 103 ResourceId CreateBitmap(gfx::Size size); |
| 100 // Wraps an external texture into a GL resource. | 104 // Wraps an external texture into a GL resource. |
| 101 ResourceId CreateResourceFromExternalTexture( | 105 ResourceId CreateResourceFromExternalTexture( |
| 102 unsigned texture_target, | 106 unsigned texture_target, |
| 103 unsigned texture_id); | 107 unsigned texture_id); |
| 104 | 108 |
| 105 // Wraps an external texture mailbox into a GL resource. | 109 // Wraps an external texture mailbox into a GL resource. |
| 106 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); | 110 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); |
| 107 | 111 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 } | 327 } |
| 324 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } | 328 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } |
| 325 | 329 |
| 326 // Enable read lock fences for a specific resource. | 330 // Enable read lock fences for a specific resource. |
| 327 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); | 331 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); |
| 328 | 332 |
| 329 // Indicates if we can currently lock this resource for write. | 333 // Indicates if we can currently lock this resource for write. |
| 330 bool CanLockForWrite(ResourceId id); | 334 bool CanLockForWrite(ResourceId id); |
| 331 | 335 |
| 332 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); | 336 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); |
| 337 static size_t BytesPerPixel(ResourceFormat format); | |
| 338 static GLenum GetGLDataType(ResourceFormat format); | |
| 339 static GLenum GetGLDataFormat(ResourceFormat format); | |
| 340 static GLenum GetGLInternalFormat(ResourceFormat format); | |
| 333 | 341 |
| 334 private: | 342 private: |
| 335 struct Resource { | 343 struct Resource { |
| 336 Resource(); | 344 Resource(); |
| 337 ~Resource(); | 345 ~Resource(); |
| 338 Resource(unsigned texture_id, | 346 Resource(unsigned texture_id, |
| 339 gfx::Size size, | 347 gfx::Size size, |
| 340 GLenum format, | |
| 341 GLenum filter, | 348 GLenum filter, |
| 342 GLenum texture_pool, | 349 GLenum texture_pool, |
| 343 GLint wrap_mode, | 350 GLint wrap_mode, |
| 344 TextureUsageHint hint); | 351 TextureUsageHint hint, |
| 352 ResourceFormat format); | |
| 345 Resource(uint8_t* pixels, | 353 Resource(uint8_t* pixels, |
| 346 gfx::Size size, | 354 gfx::Size size, |
| 347 GLenum format, | |
| 348 GLenum filter, | 355 GLenum filter, |
| 349 GLint wrap_mode); | 356 GLint wrap_mode); |
| 350 | 357 |
| 351 unsigned gl_id; | 358 unsigned gl_id; |
| 352 // Pixel buffer used for set pixels without unnecessary copying. | 359 // Pixel buffer used for set pixels without unnecessary copying. |
| 353 unsigned gl_pixel_buffer_id; | 360 unsigned gl_pixel_buffer_id; |
| 354 // Query used to determine when asynchronous set pixels complete. | 361 // Query used to determine when asynchronous set pixels complete. |
| 355 unsigned gl_upload_query_id; | 362 unsigned gl_upload_query_id; |
| 356 TextureMailbox mailbox; | 363 TextureMailbox mailbox; |
| 357 uint8_t* pixels; | 364 uint8_t* pixels; |
| 358 uint8_t* pixel_buffer; | 365 uint8_t* pixel_buffer; |
| 359 int lock_for_read_count; | 366 int lock_for_read_count; |
| 360 int imported_count; | 367 int imported_count; |
| 361 int exported_count; | 368 int exported_count; |
| 362 bool locked_for_write; | 369 bool locked_for_write; |
| 363 bool external; | 370 bool external; |
| 364 bool marked_for_deletion; | 371 bool marked_for_deletion; |
| 365 bool pending_set_pixels; | 372 bool pending_set_pixels; |
| 366 bool set_pixels_completion_forced; | 373 bool set_pixels_completion_forced; |
| 367 bool allocated; | 374 bool allocated; |
| 368 bool enable_read_lock_fences; | 375 bool enable_read_lock_fences; |
| 369 scoped_refptr<Fence> read_lock_fence; | 376 scoped_refptr<Fence> read_lock_fence; |
| 370 gfx::Size size; | 377 gfx::Size size; |
| 371 GLenum format; | |
| 372 // TODO(skyostil): Use a separate sampler object for filter state. | 378 // TODO(skyostil): Use a separate sampler object for filter state. |
| 373 GLenum original_filter; | 379 GLenum original_filter; |
| 374 GLenum filter; | 380 GLenum filter; |
| 375 GLenum target; | 381 GLenum target; |
| 376 unsigned image_id; | 382 unsigned image_id; |
| 377 GLenum texture_pool; | 383 GLenum texture_pool; |
| 378 GLint wrap_mode; | 384 GLint wrap_mode; |
| 379 TextureUsageHint hint; | 385 TextureUsageHint hint; |
| 380 ResourceType type; | 386 ResourceType type; |
| 387 ResourceFormat format; | |
| 381 }; | 388 }; |
| 382 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 389 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
| 383 struct Child { | 390 struct Child { |
| 384 Child(); | 391 Child(); |
| 385 ~Child(); | 392 ~Child(); |
| 386 | 393 |
| 387 ResourceIdMap child_to_parent_map; | 394 ResourceIdMap child_to_parent_map; |
| 388 ResourceIdMap parent_to_child_map; | 395 ResourceIdMap parent_to_child_map; |
| 389 }; | 396 }; |
| 390 typedef base::hash_map<int, Child> ChildMap; | 397 typedef base::hash_map<int, Child> ChildMap; |
| 391 | 398 |
| 392 bool ReadLockFenceHasPassed(Resource* resource) { | 399 bool ReadLockFenceHasPassed(Resource* resource) { |
| 393 return !resource->read_lock_fence.get() || | 400 return !resource->read_lock_fence.get() || |
| 394 resource->read_lock_fence->HasPassed(); | 401 resource->read_lock_fence->HasPassed(); |
| 395 } | 402 } |
| 396 | 403 |
| 397 explicit ResourceProvider(OutputSurface* output_surface, | 404 ResourceProvider(OutputSurface* output_surface, |
| 398 int highp_threshold_min); | 405 int highp_threshold_min, |
| 406 bool use_rgba_4444_texture_format); | |
| 399 | 407 |
| 400 void CleanUpGLIfNeeded(); | 408 void CleanUpGLIfNeeded(); |
| 401 | 409 |
| 402 Resource* GetResource(ResourceId id); | 410 Resource* GetResource(ResourceId id); |
| 403 const Resource* LockForRead(ResourceId id); | 411 const Resource* LockForRead(ResourceId id); |
| 404 void UnlockForRead(ResourceId id); | 412 void UnlockForRead(ResourceId id); |
| 405 const Resource* LockForWrite(ResourceId id); | 413 const Resource* LockForWrite(ResourceId id); |
| 406 void UnlockForWrite(ResourceId id); | 414 void UnlockForWrite(ResourceId id); |
| 407 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 415 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 408 const Resource* resource); | 416 const Resource* resource); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 439 ResourceMap resources_; | 447 ResourceMap resources_; |
| 440 int next_child_; | 448 int next_child_; |
| 441 ChildMap children_; | 449 ChildMap children_; |
| 442 | 450 |
| 443 ResourceType default_resource_type_; | 451 ResourceType default_resource_type_; |
| 444 bool use_texture_storage_ext_; | 452 bool use_texture_storage_ext_; |
| 445 bool use_texture_usage_hint_; | 453 bool use_texture_usage_hint_; |
| 446 bool use_shallow_flush_; | 454 bool use_shallow_flush_; |
| 447 scoped_ptr<TextureUploader> texture_uploader_; | 455 scoped_ptr<TextureUploader> texture_uploader_; |
| 448 int max_texture_size_; | 456 int max_texture_size_; |
| 449 GLenum best_texture_format_; | 457 ResourceFormat best_texture_format_; |
| 450 | 458 |
| 451 base::ThreadChecker thread_checker_; | 459 base::ThreadChecker thread_checker_; |
| 452 | 460 |
| 453 scoped_refptr<Fence> current_read_lock_fence_; | 461 scoped_refptr<Fence> current_read_lock_fence_; |
| 462 bool use_rgba_4444_texture_format_; | |
| 454 | 463 |
| 455 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 464 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 456 }; | 465 }; |
| 457 | 466 |
| 458 } // namespace cc | 467 } // namespace cc |
| 459 | 468 |
| 460 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 469 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |