| 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 17 matching lines...) Expand all Loading... |
| 28 #include "cc/resources/return_callback.h" | 28 #include "cc/resources/return_callback.h" |
| 29 #include "cc/resources/shared_bitmap.h" | 29 #include "cc/resources/shared_bitmap.h" |
| 30 #include "cc/resources/single_release_callback_impl.h" | 30 #include "cc/resources/single_release_callback_impl.h" |
| 31 #include "cc/resources/texture_mailbox.h" | 31 #include "cc/resources/texture_mailbox.h" |
| 32 #include "cc/resources/transferable_resource.h" | 32 #include "cc/resources/transferable_resource.h" |
| 33 #include "third_party/khronos/GLES2/gl2.h" | 33 #include "third_party/khronos/GLES2/gl2.h" |
| 34 #include "third_party/khronos/GLES2/gl2ext.h" | 34 #include "third_party/khronos/GLES2/gl2ext.h" |
| 35 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
| 36 #include "third_party/skia/include/core/SkCanvas.h" | 36 #include "third_party/skia/include/core/SkCanvas.h" |
| 37 #include "ui/gfx/geometry/size.h" | 37 #include "ui/gfx/geometry/size.h" |
| 38 #include "ui/gfx/gpu_memory_buffer.h" |
| 38 | 39 |
| 39 class GrContext; | 40 class GrContext; |
| 40 | 41 |
| 41 namespace gpu { | 42 namespace gpu { |
| 42 class GpuMemoryBufferManager; | 43 class GpuMemoryBufferManager; |
| 43 namespace gles { | 44 namespace gles { |
| 44 class GLES2Interface; | 45 class GLES2Interface; |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 namespace gfx { | 49 namespace gfx { |
| 49 class GpuMemoryBuffer; | |
| 50 class Rect; | 50 class Rect; |
| 51 class Vector2d; | 51 class Vector2d; |
| 52 } | 52 } |
| 53 | 53 |
| 54 namespace cc { | 54 namespace cc { |
| 55 class BlockingTaskRunner; | 55 class BlockingTaskRunner; |
| 56 class IdAllocator; | 56 class IdAllocator; |
| 57 class SharedBitmap; | 57 class SharedBitmap; |
| 58 class SharedBitmapManager; | 58 class SharedBitmapManager; |
| 59 | 59 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 static scoped_ptr<ResourceProvider> Create( | 83 static scoped_ptr<ResourceProvider> Create( |
| 84 OutputSurface* output_surface, | 84 OutputSurface* output_surface, |
| 85 SharedBitmapManager* shared_bitmap_manager, | 85 SharedBitmapManager* shared_bitmap_manager, |
| 86 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 86 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 87 BlockingTaskRunner* blocking_main_thread_task_runner, | 87 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 88 int highp_threshold_min, | 88 int highp_threshold_min, |
| 89 bool use_rgba_4444_texture_format, | 89 bool use_rgba_4444_texture_format, |
| 90 size_t id_allocation_chunk_size, | 90 size_t id_allocation_chunk_size, |
| 91 bool use_persistent_map_for_gpu_memory_buffers, | |
| 92 const std::vector<unsigned>& use_image_texture_targets); | 91 const std::vector<unsigned>& use_image_texture_targets); |
| 93 ~ResourceProvider() override; | 92 ~ResourceProvider() override; |
| 94 | 93 |
| 95 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 94 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
| 96 | 95 |
| 97 int max_texture_size() const { return max_texture_size_; } | 96 int max_texture_size() const { return max_texture_size_; } |
| 98 ResourceFormat memory_efficient_texture_format() const { | 97 ResourceFormat memory_efficient_texture_format() const { |
| 99 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; | 98 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; |
| 100 } | 99 } |
| 101 ResourceFormat best_texture_format() const { return best_texture_format_; } | 100 ResourceFormat best_texture_format() const { return best_texture_format_; } |
| 102 ResourceFormat best_render_buffer_format() const { | 101 ResourceFormat best_render_buffer_format() const { |
| 103 return best_render_buffer_format_; | 102 return best_render_buffer_format_; |
| 104 } | 103 } |
| 105 ResourceFormat yuv_resource_format() const { return yuv_resource_format_; } | 104 ResourceFormat yuv_resource_format() const { return yuv_resource_format_; } |
| 106 bool use_sync_query() const { return use_sync_query_; } | 105 bool use_sync_query() const { return use_sync_query_; } |
| 107 bool use_persistent_map_for_gpu_memory_buffers() const { | 106 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() { |
| 108 return use_persistent_map_for_gpu_memory_buffers_; | 107 return gpu_memory_buffer_manager_; |
| 109 } | 108 } |
| 110 size_t num_resources() const { return resources_.size(); } | 109 size_t num_resources() const { return resources_.size(); } |
| 111 | 110 |
| 112 // Checks whether a resource is in use by a consumer. | 111 // Checks whether a resource is in use by a consumer. |
| 113 bool InUseByConsumer(ResourceId id); | 112 bool InUseByConsumer(ResourceId id); |
| 114 | 113 |
| 115 bool IsLost(ResourceId id); | 114 bool IsLost(ResourceId id); |
| 116 | 115 |
| 117 void LoseResourceForTesting(ResourceId id); | 116 void LoseResourceForTesting(ResourceId id); |
| 118 void EnableReadLockFencesForTesting(ResourceId id); | 117 void EnableReadLockFencesForTesting(ResourceId id); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 GLenum TargetForTesting(ResourceId id); | 419 GLenum TargetForTesting(ResourceId id); |
| 421 | 420 |
| 422 // Sets the current read fence. If a resource is locked for read | 421 // Sets the current read fence. If a resource is locked for read |
| 423 // and has read fences enabled, the resource will not allow writes | 422 // and has read fences enabled, the resource will not allow writes |
| 424 // until this fence has passed. | 423 // until this fence has passed. |
| 425 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } | 424 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } |
| 426 | 425 |
| 427 // Indicates if we can currently lock this resource for write. | 426 // Indicates if we can currently lock this resource for write. |
| 428 bool CanLockForWrite(ResourceId id); | 427 bool CanLockForWrite(ResourceId id); |
| 429 | 428 |
| 430 // Copy |rect| pixels from source to destination. | |
| 431 void CopyResource(ResourceId source_id, | |
| 432 ResourceId dest_id, | |
| 433 const gfx::Rect& rect); | |
| 434 | |
| 435 void WaitSyncPointIfNeeded(ResourceId id); | 429 void WaitSyncPointIfNeeded(ResourceId id); |
| 436 | 430 |
| 437 void WaitReadLockIfNeeded(ResourceId id); | |
| 438 | |
| 439 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); | 431 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); |
| 440 | 432 |
| 441 OutputSurface* output_surface() { return output_surface_; } | 433 OutputSurface* output_surface() { return output_surface_; } |
| 442 | 434 |
| 443 void ValidateResource(ResourceId id) const; | 435 void ValidateResource(ResourceId id) const; |
| 444 | 436 |
| 445 GLenum GetImageTextureTarget(ResourceFormat format); | 437 GLenum GetImageTextureTarget(ResourceFormat format); |
| 446 | 438 |
| 447 // base::trace_event::MemoryDumpProvider implementation. | 439 // base::trace_event::MemoryDumpProvider implementation. |
| 448 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 440 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 449 base::trace_event::ProcessMemoryDump* pmd) override; | 441 base::trace_event::ProcessMemoryDump* pmd) override; |
| 450 | 442 |
| 451 int tracing_id() const { return tracing_id_; } | 443 int tracing_id() const { return tracing_id_; } |
| 452 | 444 |
| 453 protected: | 445 protected: |
| 454 ResourceProvider(OutputSurface* output_surface, | 446 ResourceProvider(OutputSurface* output_surface, |
| 455 SharedBitmapManager* shared_bitmap_manager, | 447 SharedBitmapManager* shared_bitmap_manager, |
| 456 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 448 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 457 BlockingTaskRunner* blocking_main_thread_task_runner, | 449 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 458 int highp_threshold_min, | 450 int highp_threshold_min, |
| 459 bool use_rgba_4444_texture_format, | 451 bool use_rgba_4444_texture_format, |
| 460 size_t id_allocation_chunk_size, | 452 size_t id_allocation_chunk_size, |
| 461 bool use_persistent_map_for_gpu_memory_buffers, | |
| 462 const std::vector<unsigned>& use_image_texture_targets); | 453 const std::vector<unsigned>& use_image_texture_targets); |
| 463 void Initialize(); | 454 void Initialize(); |
| 464 | 455 |
| 465 private: | 456 private: |
| 466 struct Resource { | 457 struct Resource { |
| 467 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; | 458 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; |
| 468 | 459 |
| 469 ~Resource(); | 460 ~Resource(); |
| 470 Resource(unsigned texture_id, | 461 Resource(unsigned texture_id, |
| 471 const gfx::Size& size, | 462 const gfx::Size& size, |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 base::ThreadChecker thread_checker_; | 598 base::ThreadChecker thread_checker_; |
| 608 | 599 |
| 609 scoped_refptr<Fence> current_read_lock_fence_; | 600 scoped_refptr<Fence> current_read_lock_fence_; |
| 610 bool use_rgba_4444_texture_format_; | 601 bool use_rgba_4444_texture_format_; |
| 611 | 602 |
| 612 const size_t id_allocation_chunk_size_; | 603 const size_t id_allocation_chunk_size_; |
| 613 scoped_ptr<IdAllocator> texture_id_allocator_; | 604 scoped_ptr<IdAllocator> texture_id_allocator_; |
| 614 scoped_ptr<IdAllocator> buffer_id_allocator_; | 605 scoped_ptr<IdAllocator> buffer_id_allocator_; |
| 615 | 606 |
| 616 bool use_sync_query_; | 607 bool use_sync_query_; |
| 617 bool use_persistent_map_for_gpu_memory_buffers_; | |
| 618 // Fence used for CopyResource if CHROMIUM_sync_query is not supported. | |
| 619 scoped_refptr<SynchronousFence> synchronous_fence_; | |
| 620 std::vector<unsigned> use_image_texture_targets_; | 608 std::vector<unsigned> use_image_texture_targets_; |
| 621 | 609 |
| 622 // A process-unique ID used for disambiguating memory dumps from different | 610 // A process-unique ID used for disambiguating memory dumps from different |
| 623 // resource providers. | 611 // resource providers. |
| 624 int tracing_id_; | 612 int tracing_id_; |
| 625 | 613 |
| 626 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 614 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 627 }; | 615 }; |
| 628 | 616 |
| 629 } // namespace cc | 617 } // namespace cc |
| 630 | 618 |
| 631 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 619 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |