| 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 15 matching lines...) Expand all Loading... |
| 26 #include "cc/resources/return_callback.h" | 26 #include "cc/resources/return_callback.h" |
| 27 #include "cc/resources/shared_bitmap.h" | 27 #include "cc/resources/shared_bitmap.h" |
| 28 #include "cc/resources/single_release_callback_impl.h" | 28 #include "cc/resources/single_release_callback_impl.h" |
| 29 #include "cc/resources/texture_mailbox.h" | 29 #include "cc/resources/texture_mailbox.h" |
| 30 #include "cc/resources/transferable_resource.h" | 30 #include "cc/resources/transferable_resource.h" |
| 31 #include "third_party/khronos/GLES2/gl2.h" | 31 #include "third_party/khronos/GLES2/gl2.h" |
| 32 #include "third_party/khronos/GLES2/gl2ext.h" | 32 #include "third_party/khronos/GLES2/gl2ext.h" |
| 33 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
| 34 #include "third_party/skia/include/core/SkCanvas.h" | 34 #include "third_party/skia/include/core/SkCanvas.h" |
| 35 #include "ui/gfx/geometry/size.h" | 35 #include "ui/gfx/geometry/size.h" |
| 36 #include "ui/gfx/gpu_memory_buffer.h" |
| 36 | 37 |
| 37 class GrContext; | 38 class GrContext; |
| 38 | 39 |
| 39 namespace gpu { | 40 namespace gpu { |
| 40 class GpuMemoryBufferManager; | 41 class GpuMemoryBufferManager; |
| 41 namespace gles { | 42 namespace gles { |
| 42 class GLES2Interface; | 43 class GLES2Interface; |
| 43 } | 44 } |
| 44 } | 45 } |
| 45 | 46 |
| 46 namespace gfx { | 47 namespace gfx { |
| 47 class GpuMemoryBuffer; | |
| 48 class Rect; | 48 class Rect; |
| 49 class Vector2d; | 49 class Vector2d; |
| 50 } | 50 } |
| 51 | 51 |
| 52 namespace cc { | 52 namespace cc { |
| 53 class BlockingTaskRunner; | 53 class BlockingTaskRunner; |
| 54 class IdAllocator; | 54 class IdAllocator; |
| 55 class SharedBitmap; | 55 class SharedBitmap; |
| 56 class SharedBitmapManager; | 56 class SharedBitmapManager; |
| 57 | 57 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 77 RESOURCE_TYPE_BITMAP, | 77 RESOURCE_TYPE_BITMAP, |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 static scoped_ptr<ResourceProvider> Create( | 80 static scoped_ptr<ResourceProvider> Create( |
| 81 OutputSurface* output_surface, | 81 OutputSurface* output_surface, |
| 82 SharedBitmapManager* shared_bitmap_manager, | 82 SharedBitmapManager* shared_bitmap_manager, |
| 83 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 83 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 84 BlockingTaskRunner* blocking_main_thread_task_runner, | 84 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 85 int highp_threshold_min, | 85 int highp_threshold_min, |
| 86 bool use_rgba_4444_texture_format, | 86 bool use_rgba_4444_texture_format, |
| 87 size_t id_allocation_chunk_size, | 87 size_t id_allocation_chunk_size); |
| 88 bool use_persistent_map_for_gpu_memory_buffers); | |
| 89 virtual ~ResourceProvider(); | 88 virtual ~ResourceProvider(); |
| 90 | 89 |
| 91 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 90 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
| 92 | 91 |
| 93 int max_texture_size() const { return max_texture_size_; } | 92 int max_texture_size() const { return max_texture_size_; } |
| 94 ResourceFormat memory_efficient_texture_format() const { | 93 ResourceFormat memory_efficient_texture_format() const { |
| 95 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; | 94 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; |
| 96 } | 95 } |
| 97 ResourceFormat best_texture_format() const { return best_texture_format_; } | 96 ResourceFormat best_texture_format() const { return best_texture_format_; } |
| 98 ResourceFormat best_render_buffer_format() const { | 97 ResourceFormat best_render_buffer_format() const { |
| 99 return best_render_buffer_format_; | 98 return best_render_buffer_format_; |
| 100 } | 99 } |
| 101 ResourceFormat yuv_resource_format() const { return yuv_resource_format_; } | 100 ResourceFormat yuv_resource_format() const { return yuv_resource_format_; } |
| 102 bool use_sync_query() const { return use_sync_query_; } | 101 bool use_sync_query() const { return use_sync_query_; } |
| 103 bool use_persistent_map_for_gpu_memory_buffers() const { | 102 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() { |
| 104 return use_persistent_map_for_gpu_memory_buffers_; | 103 return gpu_memory_buffer_manager_; |
| 105 } | 104 } |
| 106 size_t num_resources() const { return resources_.size(); } | 105 size_t num_resources() const { return resources_.size(); } |
| 107 | 106 |
| 108 // Checks whether a resource is in use by a consumer. | 107 // Checks whether a resource is in use by a consumer. |
| 109 bool InUseByConsumer(ResourceId id); | 108 bool InUseByConsumer(ResourceId id); |
| 110 | 109 |
| 111 bool IsLost(ResourceId id); | 110 bool IsLost(ResourceId id); |
| 112 | 111 |
| 113 void LoseResourceForTesting(ResourceId id); | 112 void LoseResourceForTesting(ResourceId id); |
| 114 void EnableReadLockFencesForTesting(ResourceId id); | 113 void EnableReadLockFencesForTesting(ResourceId id); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 GLenum TargetForTesting(ResourceId id); | 415 GLenum TargetForTesting(ResourceId id); |
| 417 | 416 |
| 418 // Sets the current read fence. If a resource is locked for read | 417 // Sets the current read fence. If a resource is locked for read |
| 419 // and has read fences enabled, the resource will not allow writes | 418 // and has read fences enabled, the resource will not allow writes |
| 420 // until this fence has passed. | 419 // until this fence has passed. |
| 421 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } | 420 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } |
| 422 | 421 |
| 423 // Indicates if we can currently lock this resource for write. | 422 // Indicates if we can currently lock this resource for write. |
| 424 bool CanLockForWrite(ResourceId id); | 423 bool CanLockForWrite(ResourceId id); |
| 425 | 424 |
| 426 // Copy |rect| pixels from source to destination. | |
| 427 void CopyResource(ResourceId source_id, | |
| 428 ResourceId dest_id, | |
| 429 const gfx::Rect& rect); | |
| 430 | |
| 431 void WaitSyncPointIfNeeded(ResourceId id); | 425 void WaitSyncPointIfNeeded(ResourceId id); |
| 432 | 426 |
| 433 void WaitReadLockIfNeeded(ResourceId id); | |
| 434 | |
| 435 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); | 427 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); |
| 436 | 428 |
| 437 OutputSurface* output_surface() { return output_surface_; } | 429 OutputSurface* output_surface() { return output_surface_; } |
| 438 | 430 |
| 439 void ValidateResource(ResourceId id) const; | 431 void ValidateResource(ResourceId id) const; |
| 440 | 432 |
| 441 protected: | 433 protected: |
| 442 ResourceProvider(OutputSurface* output_surface, | 434 ResourceProvider(OutputSurface* output_surface, |
| 443 SharedBitmapManager* shared_bitmap_manager, | 435 SharedBitmapManager* shared_bitmap_manager, |
| 444 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 436 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 445 BlockingTaskRunner* blocking_main_thread_task_runner, | 437 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 446 int highp_threshold_min, | 438 int highp_threshold_min, |
| 447 bool use_rgba_4444_texture_format, | 439 bool use_rgba_4444_texture_format, |
| 448 size_t id_allocation_chunk_size, | 440 size_t id_allocation_chunk_size); |
| 449 bool use_persistent_map_for_gpu_memory_buffers); | |
| 450 void Initialize(); | 441 void Initialize(); |
| 451 | 442 |
| 452 private: | 443 private: |
| 453 struct Resource { | 444 struct Resource { |
| 454 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; | 445 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; |
| 455 | 446 |
| 456 ~Resource(); | 447 ~Resource(); |
| 457 Resource(unsigned texture_id, | 448 Resource(unsigned texture_id, |
| 458 const gfx::Size& size, | 449 const gfx::Size& size, |
| 459 Origin origin, | 450 Origin origin, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 base::ThreadChecker thread_checker_; | 585 base::ThreadChecker thread_checker_; |
| 595 | 586 |
| 596 scoped_refptr<Fence> current_read_lock_fence_; | 587 scoped_refptr<Fence> current_read_lock_fence_; |
| 597 bool use_rgba_4444_texture_format_; | 588 bool use_rgba_4444_texture_format_; |
| 598 | 589 |
| 599 const size_t id_allocation_chunk_size_; | 590 const size_t id_allocation_chunk_size_; |
| 600 scoped_ptr<IdAllocator> texture_id_allocator_; | 591 scoped_ptr<IdAllocator> texture_id_allocator_; |
| 601 scoped_ptr<IdAllocator> buffer_id_allocator_; | 592 scoped_ptr<IdAllocator> buffer_id_allocator_; |
| 602 | 593 |
| 603 bool use_sync_query_; | 594 bool use_sync_query_; |
| 604 bool use_persistent_map_for_gpu_memory_buffers_; | |
| 605 // Fence used for CopyResource if CHROMIUM_sync_query is not supported. | |
| 606 scoped_refptr<SynchronousFence> synchronous_fence_; | |
| 607 | 595 |
| 608 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 596 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 609 }; | 597 }; |
| 610 | 598 |
| 611 } // namespace cc | 599 } // namespace cc |
| 612 | 600 |
| 613 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 601 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |