| 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 <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
| 17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 20 #include "cc/base/cc_export.h" | 20 #include "cc/base/cc_export.h" |
| 21 #include "cc/base/tile_compression_method.h" |
| 21 #include "cc/output/context_provider.h" | 22 #include "cc/output/context_provider.h" |
| 22 #include "cc/output/output_surface.h" | 23 #include "cc/output/output_surface.h" |
| 23 #include "cc/resources/release_callback_impl.h" | 24 #include "cc/resources/release_callback_impl.h" |
| 24 #include "cc/resources/resource_format.h" | 25 #include "cc/resources/resource_format.h" |
| 25 #include "cc/resources/return_callback.h" | 26 #include "cc/resources/return_callback.h" |
| 26 #include "cc/resources/shared_bitmap.h" | 27 #include "cc/resources/shared_bitmap.h" |
| 27 #include "cc/resources/single_release_callback_impl.h" | 28 #include "cc/resources/single_release_callback_impl.h" |
| 28 #include "cc/resources/texture_mailbox.h" | 29 #include "cc/resources/texture_mailbox.h" |
| 29 #include "cc/resources/transferable_resource.h" | 30 #include "cc/resources/transferable_resource.h" |
| 30 #include "third_party/khronos/GLES2/gl2.h" | 31 #include "third_party/khronos/GLES2/gl2.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 Bitmap, | 80 Bitmap, |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 static scoped_ptr<ResourceProvider> Create( | 83 static scoped_ptr<ResourceProvider> Create( |
| 83 OutputSurface* output_surface, | 84 OutputSurface* output_surface, |
| 84 SharedBitmapManager* shared_bitmap_manager, | 85 SharedBitmapManager* shared_bitmap_manager, |
| 85 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 86 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 86 BlockingTaskRunner* blocking_main_thread_task_runner, | 87 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 87 int highp_threshold_min, | 88 int highp_threshold_min, |
| 88 bool use_rgba_4444_texture_format, | 89 bool use_rgba_4444_texture_format, |
| 90 bool use_texture_compression, |
| 89 size_t id_allocation_chunk_size); | 91 size_t id_allocation_chunk_size); |
| 90 virtual ~ResourceProvider(); | 92 virtual ~ResourceProvider(); |
| 91 | 93 |
| 92 void InitializeSoftware(); | 94 void InitializeSoftware(); |
| 93 void InitializeGL(); | 95 void InitializeGL(); |
| 94 | 96 |
| 95 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 97 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
| 96 | 98 |
| 97 int max_texture_size() const { return max_texture_size_; } | 99 int max_texture_size() const { return max_texture_size_; } |
| 98 ResourceFormat memory_efficient_texture_format() const { | 100 ResourceFormat memory_efficient_texture_format( |
| 99 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; | 101 ResourceFormatUsage usage) const; |
| 100 } | |
| 101 ResourceFormat best_texture_format() const { return best_texture_format_; } | 102 ResourceFormat best_texture_format() const { return best_texture_format_; } |
| 102 ResourceFormat yuv_resource_format() const { return yuv_resource_format_; } | 103 ResourceFormat yuv_resource_format() const { return yuv_resource_format_; } |
| 103 bool use_sync_query() const { return use_sync_query_; } | 104 bool use_sync_query() const { return use_sync_query_; } |
| 104 size_t num_resources() const { return resources_.size(); } | 105 size_t num_resources() const { return resources_.size(); } |
| 105 | 106 |
| 106 // Checks whether a resource is in use by a consumer. | 107 // Checks whether a resource is in use by a consumer. |
| 107 bool InUseByConsumer(ResourceId id); | 108 bool InUseByConsumer(ResourceId id); |
| 108 | 109 |
| 109 bool IsLost(ResourceId id); | 110 bool IsLost(ResourceId id); |
| 110 bool AllowOverlay(ResourceId id); | 111 bool AllowOverlay(ResourceId id); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 141 ResourceId CreateResourceFromIOSurface(const gfx::Size& size, | 142 ResourceId CreateResourceFromIOSurface(const gfx::Size& size, |
| 142 unsigned io_surface_id); | 143 unsigned io_surface_id); |
| 143 | 144 |
| 144 // Wraps an external texture mailbox into a GL resource. | 145 // Wraps an external texture mailbox into a GL resource. |
| 145 ResourceId CreateResourceFromTextureMailbox( | 146 ResourceId CreateResourceFromTextureMailbox( |
| 146 const TextureMailbox& mailbox, | 147 const TextureMailbox& mailbox, |
| 147 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl); | 148 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl); |
| 148 | 149 |
| 149 void DeleteResource(ResourceId id); | 150 void DeleteResource(ResourceId id); |
| 150 | 151 |
| 152 void set_preferred_tile_compression_method(TileCompressionMethod method) { |
| 153 preferred_tile_compression_method_ = method; |
| 154 } |
| 155 |
| 151 // Update pixels from image, copying source_rect (in image) to dest_offset (in | 156 // Update pixels from image, copying source_rect (in image) to dest_offset (in |
| 152 // the resource). | 157 // the resource). |
| 153 void SetPixels(ResourceId id, | 158 void SetPixels(ResourceId id, |
| 154 const uint8_t* image, | 159 const uint8_t* image, |
| 155 const gfx::Rect& image_rect, | 160 const gfx::Rect& image_rect, |
| 156 const gfx::Rect& source_rect, | 161 const gfx::Rect& source_rect, |
| 157 const gfx::Vector2d& dest_offset); | 162 const gfx::Vector2d& dest_offset); |
| 158 | 163 |
| 159 // Check upload status. | 164 // Check upload status. |
| 160 size_t NumBlockingUploads(); | 165 size_t NumBlockingUploads(); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 const gfx::Size& size, | 451 const gfx::Size& size, |
| 447 Origin origin, | 452 Origin origin, |
| 448 GLenum filter, | 453 GLenum filter, |
| 449 GLint wrap_mode); | 454 GLint wrap_mode); |
| 450 Resource(const SharedBitmapId& bitmap_id, | 455 Resource(const SharedBitmapId& bitmap_id, |
| 451 const gfx::Size& size, | 456 const gfx::Size& size, |
| 452 Origin origin, | 457 Origin origin, |
| 453 GLenum filter, | 458 GLenum filter, |
| 454 GLint wrap_mode); | 459 GLint wrap_mode); |
| 455 | 460 |
| 461 bool IsCompressed() const; |
| 462 size_t CompressedSize() const; |
| 463 |
| 456 int child_id; | 464 int child_id; |
| 457 unsigned gl_id; | 465 unsigned gl_id; |
| 458 // Pixel buffer used for set pixels without unnecessary copying. | 466 // Pixel buffer used for set pixels without unnecessary copying. |
| 459 unsigned gl_pixel_buffer_id; | 467 unsigned gl_pixel_buffer_id; |
| 460 // Query used to determine when asynchronous set pixels complete. | 468 // Query used to determine when asynchronous set pixels complete. |
| 461 unsigned gl_upload_query_id; | 469 unsigned gl_upload_query_id; |
| 462 // Query used to determine when read lock fence has passed. | 470 // Query used to determine when read lock fence has passed. |
| 463 unsigned gl_read_lock_query_id; | 471 unsigned gl_read_lock_query_id; |
| 464 TextureMailbox mailbox; | 472 TextureMailbox mailbox; |
| 465 ReleaseCallbackImpl release_callback_impl; | 473 ReleaseCallbackImpl release_callback_impl; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 return !resource->read_lock_fence.get() || | 526 return !resource->read_lock_fence.get() || |
| 519 resource->read_lock_fence->HasPassed(); | 527 resource->read_lock_fence->HasPassed(); |
| 520 } | 528 } |
| 521 | 529 |
| 522 ResourceProvider(OutputSurface* output_surface, | 530 ResourceProvider(OutputSurface* output_surface, |
| 523 SharedBitmapManager* shared_bitmap_manager, | 531 SharedBitmapManager* shared_bitmap_manager, |
| 524 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 532 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 525 BlockingTaskRunner* blocking_main_thread_task_runner, | 533 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 526 int highp_threshold_min, | 534 int highp_threshold_min, |
| 527 bool use_rgba_4444_texture_format, | 535 bool use_rgba_4444_texture_format, |
| 536 bool use_texture_compression, |
| 528 size_t id_allocation_chunk_size); | 537 size_t id_allocation_chunk_size); |
| 529 | 538 |
| 530 void CleanUpGLIfNeeded(); | 539 void CleanUpGLIfNeeded(); |
| 531 | 540 |
| 532 Resource* GetResource(ResourceId id); | 541 Resource* GetResource(ResourceId id); |
| 533 const Resource* LockForRead(ResourceId id); | 542 const Resource* LockForRead(ResourceId id); |
| 534 void UnlockForRead(ResourceId id); | 543 void UnlockForRead(ResourceId id); |
| 535 Resource* LockForWrite(ResourceId id); | 544 Resource* LockForWrite(ResourceId id); |
| 536 void UnlockForWrite(Resource* resource); | 545 void UnlockForWrite(Resource* resource); |
| 537 | 546 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 int highp_threshold_min_; | 580 int highp_threshold_min_; |
| 572 ResourceId next_id_; | 581 ResourceId next_id_; |
| 573 ResourceMap resources_; | 582 ResourceMap resources_; |
| 574 int next_child_; | 583 int next_child_; |
| 575 ChildMap children_; | 584 ChildMap children_; |
| 576 | 585 |
| 577 ResourceType default_resource_type_; | 586 ResourceType default_resource_type_; |
| 578 bool use_texture_storage_ext_; | 587 bool use_texture_storage_ext_; |
| 579 bool use_texture_format_bgra_; | 588 bool use_texture_format_bgra_; |
| 580 bool use_texture_usage_hint_; | 589 bool use_texture_usage_hint_; |
| 590 bool use_compressed_texture_atc_; |
| 591 bool use_compressed_texture_dxt_; |
| 581 bool use_compressed_texture_etc1_; | 592 bool use_compressed_texture_etc1_; |
| 582 ResourceFormat yuv_resource_format_; | 593 ResourceFormat yuv_resource_format_; |
| 583 scoped_ptr<TextureUploader> texture_uploader_; | 594 scoped_ptr<TextureUploader> texture_uploader_; |
| 584 int max_texture_size_; | 595 int max_texture_size_; |
| 585 ResourceFormat best_texture_format_; | 596 ResourceFormat best_texture_format_; |
| 586 | 597 |
| 587 base::ThreadChecker thread_checker_; | 598 base::ThreadChecker thread_checker_; |
| 588 | 599 |
| 589 scoped_refptr<Fence> current_read_lock_fence_; | 600 scoped_refptr<Fence> current_read_lock_fence_; |
| 590 bool use_rgba_4444_texture_format_; | 601 bool use_rgba_4444_texture_format_; |
| 602 bool use_texture_compression_; |
| 603 TileCompressionMethod preferred_tile_compression_method_; |
| 591 | 604 |
| 592 const size_t id_allocation_chunk_size_; | 605 const size_t id_allocation_chunk_size_; |
| 593 scoped_ptr<IdAllocator> texture_id_allocator_; | 606 scoped_ptr<IdAllocator> texture_id_allocator_; |
| 594 scoped_ptr<IdAllocator> buffer_id_allocator_; | 607 scoped_ptr<IdAllocator> buffer_id_allocator_; |
| 595 | 608 |
| 596 bool use_sync_query_; | 609 bool use_sync_query_; |
| 597 // Fence used for CopyResource if CHROMIUM_sync_query is not supported. | 610 // Fence used for CopyResource if CHROMIUM_sync_query is not supported. |
| 598 scoped_refptr<SynchronousFence> synchronous_fence_; | 611 scoped_refptr<SynchronousFence> synchronous_fence_; |
| 599 | 612 |
| 600 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 613 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 601 }; | 614 }; |
| 602 | 615 |
| 603 // TODO(epenner): Move these format conversions to resource_format.h | 616 // TODO(epenner): Move these format conversions to resource_format.h |
| 604 // once that builds on mac (npapi.h currently #includes OpenGL.h). | 617 // once that builds on mac (npapi.h currently #includes OpenGL.h). |
| 605 inline unsigned BitsPerPixel(ResourceFormat format) { | 618 inline unsigned BitsPerPixel(ResourceFormat format) { |
| 606 switch (format) { | 619 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 607 case BGRA_8888: | 620 static const unsigned format_bits_per_pixel[RESOURCE_FORMAT_MAX + 1] = { |
| 608 case RGBA_8888: | 621 32, // RGBA_8888 |
| 609 return 32; | 622 16, // RGBA_4444 |
| 610 case RGBA_4444: | 623 32, // BGRA_8888 |
| 611 case RGB_565: | 624 8, // ALPHA_8 |
| 612 return 16; | 625 8, // LUMINANCE_8 |
| 613 case ALPHA_8: | 626 16, // RGB_565, |
| 614 case LUMINANCE_8: | 627 4, // ATC |
| 615 case RED_8: | 628 8, // ATC_IA |
| 616 return 8; | 629 4, // DXT1 |
| 617 case ETC1: | 630 8, // DXT5 |
| 618 return 4; | 631 4, // ETC1 |
| 619 } | 632 8 // RED_8 |
| 620 NOTREACHED(); | 633 }; |
| 621 return 0; | 634 return format_bits_per_pixel[format]; |
| 622 } | 635 } |
| 623 | 636 |
| 624 inline GLenum GLDataType(ResourceFormat format) { | 637 inline GLenum GLDataType(ResourceFormat format) { |
| 625 DCHECK_LE(format, RESOURCE_FORMAT_MAX); | 638 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 626 static const unsigned format_gl_data_type[RESOURCE_FORMAT_MAX + 1] = { | 639 static const unsigned format_gl_data_type[RESOURCE_FORMAT_MAX + 1] = { |
| 627 GL_UNSIGNED_BYTE, // RGBA_8888 | 640 GL_UNSIGNED_BYTE, // RGBA_8888 |
| 628 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 | 641 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 |
| 629 GL_UNSIGNED_BYTE, // BGRA_8888 | 642 GL_UNSIGNED_BYTE, // BGRA_8888 |
| 630 GL_UNSIGNED_BYTE, // ALPHA_8 | 643 GL_UNSIGNED_BYTE, // ALPHA_8 |
| 631 GL_UNSIGNED_BYTE, // LUMINANCE_8 | 644 GL_UNSIGNED_BYTE, // LUMINANCE_8 |
| 632 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, | 645 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, |
| 646 GL_UNSIGNED_BYTE, // ATC |
| 647 GL_UNSIGNED_BYTE, // ATC_IA |
| 648 GL_UNSIGNED_BYTE, // DXT1 |
| 649 GL_UNSIGNED_BYTE, // DXT5 |
| 633 GL_UNSIGNED_BYTE, // ETC1 | 650 GL_UNSIGNED_BYTE, // ETC1 |
| 634 GL_UNSIGNED_BYTE // RED_8 | 651 GL_UNSIGNED_BYTE // RED_8 |
| 635 }; | 652 }; |
| 636 return format_gl_data_type[format]; | 653 return format_gl_data_type[format]; |
| 637 } | 654 } |
| 638 | 655 |
| 639 inline GLenum GLDataFormat(ResourceFormat format) { | 656 inline GLenum GLDataFormat(ResourceFormat format) { |
| 640 DCHECK_LE(format, RESOURCE_FORMAT_MAX); | 657 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 641 static const unsigned format_gl_data_format[RESOURCE_FORMAT_MAX + 1] = { | 658 static const unsigned format_gl_data_format[RESOURCE_FORMAT_MAX + 1] = { |
| 642 GL_RGBA, // RGBA_8888 | 659 GL_RGBA, // RGBA_8888 |
| 643 GL_RGBA, // RGBA_4444 | 660 GL_RGBA, // RGBA_4444 |
| 644 GL_BGRA_EXT, // BGRA_8888 | 661 GL_BGRA_EXT, // BGRA_8888 |
| 645 GL_ALPHA, // ALPHA_8 | 662 GL_ALPHA, // ALPHA_8 |
| 646 GL_LUMINANCE, // LUMINANCE_8 | 663 GL_LUMINANCE, // LUMINANCE_8 |
| 647 GL_RGB, // RGB_565 | 664 GL_RGB, // RGB_565 |
| 648 GL_ETC1_RGB8_OES, // ETC1 | 665 GL_ATC_RGB_AMD, // ATC |
| 649 GL_RED_EXT // RED_8 | 666 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, // ATC_IA |
| 667 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, // DXT1 |
| 668 GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, // DXT5 |
| 669 GL_ETC1_RGB8_OES, // ETC1 |
| 670 GL_RED_EXT // RED_8 |
| 650 }; | 671 }; |
| 651 return format_gl_data_format[format]; | 672 return format_gl_data_format[format]; |
| 652 } | 673 } |
| 653 | 674 |
| 654 inline GLenum GLInternalFormat(ResourceFormat format) { | 675 inline GLenum GLInternalFormat(ResourceFormat format) { |
| 655 return GLDataFormat(format); | 676 return GLDataFormat(format); |
| 656 } | 677 } |
| 657 | 678 |
| 658 } // namespace cc | 679 } // namespace cc |
| 659 | 680 |
| 660 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 681 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |