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 EnableReadLockFencesForTesting(ResourceId id); | 112 void EnableReadLockFencesForTesting(ResourceId id); |
114 | 113 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 GLenum TargetForTesting(ResourceId id); | 414 GLenum TargetForTesting(ResourceId id); |
416 | 415 |
417 // Sets the current read fence. If a resource is locked for read | 416 // Sets the current read fence. If a resource is locked for read |
418 // and has read fences enabled, the resource will not allow writes | 417 // and has read fences enabled, the resource will not allow writes |
419 // until this fence has passed. | 418 // until this fence has passed. |
420 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } | 419 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } |
421 | 420 |
422 // Indicates if we can currently lock this resource for write. | 421 // Indicates if we can currently lock this resource for write. |
423 bool CanLockForWrite(ResourceId id); | 422 bool CanLockForWrite(ResourceId id); |
424 | 423 |
425 // Copy |rect| pixels from source to destination. | |
426 void CopyResource(ResourceId source_id, | |
427 ResourceId dest_id, | |
428 const gfx::Rect& rect); | |
429 | |
430 void WaitSyncPointIfNeeded(ResourceId id); | 424 void WaitSyncPointIfNeeded(ResourceId id); |
431 | 425 |
432 void WaitReadLockIfNeeded(ResourceId id); | |
433 | |
434 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); | 426 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); |
435 | 427 |
436 OutputSurface* output_surface() { return output_surface_; } | 428 OutputSurface* output_surface() { return output_surface_; } |
437 | 429 |
438 void ValidateResource(ResourceId id) const; | 430 void ValidateResource(ResourceId id) const; |
439 | 431 |
440 protected: | 432 protected: |
441 ResourceProvider(OutputSurface* output_surface, | 433 ResourceProvider(OutputSurface* output_surface, |
442 SharedBitmapManager* shared_bitmap_manager, | 434 SharedBitmapManager* shared_bitmap_manager, |
443 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 435 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
444 BlockingTaskRunner* blocking_main_thread_task_runner, | 436 BlockingTaskRunner* blocking_main_thread_task_runner, |
445 int highp_threshold_min, | 437 int highp_threshold_min, |
446 bool use_rgba_4444_texture_format, | 438 bool use_rgba_4444_texture_format, |
447 size_t id_allocation_chunk_size, | 439 size_t id_allocation_chunk_size); |
448 bool use_persistent_map_for_gpu_memory_buffers); | |
449 void Initialize(); | 440 void Initialize(); |
450 | 441 |
451 private: | 442 private: |
452 struct Resource { | 443 struct Resource { |
453 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; | 444 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; |
454 | 445 |
455 ~Resource(); | 446 ~Resource(); |
456 Resource(unsigned texture_id, | 447 Resource(unsigned texture_id, |
457 const gfx::Size& size, | 448 const gfx::Size& size, |
458 Origin origin, | 449 Origin origin, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 base::ThreadChecker thread_checker_; | 584 base::ThreadChecker thread_checker_; |
594 | 585 |
595 scoped_refptr<Fence> current_read_lock_fence_; | 586 scoped_refptr<Fence> current_read_lock_fence_; |
596 bool use_rgba_4444_texture_format_; | 587 bool use_rgba_4444_texture_format_; |
597 | 588 |
598 const size_t id_allocation_chunk_size_; | 589 const size_t id_allocation_chunk_size_; |
599 scoped_ptr<IdAllocator> texture_id_allocator_; | 590 scoped_ptr<IdAllocator> texture_id_allocator_; |
600 scoped_ptr<IdAllocator> buffer_id_allocator_; | 591 scoped_ptr<IdAllocator> buffer_id_allocator_; |
601 | 592 |
602 bool use_sync_query_; | 593 bool use_sync_query_; |
603 bool use_persistent_map_for_gpu_memory_buffers_; | |
604 // Fence used for CopyResource if CHROMIUM_sync_query is not supported. | |
605 scoped_refptr<SynchronousFence> synchronous_fence_; | |
606 | 594 |
607 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 595 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
608 }; | 596 }; |
609 | 597 |
610 // TODO(epenner): Move these format conversions to resource_format.h | 598 // TODO(epenner): Move these format conversions to resource_format.h |
611 // once that builds on mac (npapi.h currently #includes OpenGL.h). | 599 // once that builds on mac (npapi.h currently #includes OpenGL.h). |
612 inline int BitsPerPixel(ResourceFormat format) { | 600 inline int BitsPerPixel(ResourceFormat format) { |
613 switch (format) { | 601 switch (format) { |
614 case BGRA_8888: | 602 case BGRA_8888: |
615 case RGBA_8888: | 603 case RGBA_8888: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 GL_ETC1_RGB8_OES, // ETC1 | 643 GL_ETC1_RGB8_OES, // ETC1 |
656 GL_RED_EXT // RED_8 | 644 GL_RED_EXT // RED_8 |
657 }; | 645 }; |
658 return format_gl_data_format[format]; | 646 return format_gl_data_format[format]; |
659 } | 647 } |
660 | 648 |
661 inline GLenum GLInternalFormat(ResourceFormat format) { | 649 inline GLenum GLInternalFormat(ResourceFormat format) { |
662 return GLDataFormat(format); | 650 return GLDataFormat(format); |
663 } | 651 } |
664 | 652 |
| 653 inline gfx::GpuMemoryBuffer::Format ToGpuMemoryBufferFormat( |
| 654 ResourceFormat format) { |
| 655 switch (format) { |
| 656 case RGBA_8888: |
| 657 return gfx::GpuMemoryBuffer::RGBA_8888; |
| 658 case BGRA_8888: |
| 659 return gfx::GpuMemoryBuffer::BGRA_8888; |
| 660 case RGBA_4444: |
| 661 return gfx::GpuMemoryBuffer::RGBA_4444; |
| 662 case ALPHA_8: |
| 663 case LUMINANCE_8: |
| 664 case RGB_565: |
| 665 case ETC1: |
| 666 case RED_8: |
| 667 break; |
| 668 } |
| 669 NOTREACHED(); |
| 670 return gfx::GpuMemoryBuffer::RGBA_8888; |
| 671 } |
| 672 |
665 } // namespace cc | 673 } // namespace cc |
666 | 674 |
667 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 675 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |