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