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 24 matching lines...) Expand all Loading... |
35 | 35 |
36 class GrContext; | 36 class GrContext; |
37 | 37 |
38 namespace gpu { | 38 namespace gpu { |
39 namespace gles { | 39 namespace gles { |
40 class GLES2Interface; | 40 class GLES2Interface; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 namespace gfx { | 44 namespace gfx { |
| 45 class GpuMemoryBuffer; |
45 class Rect; | 46 class Rect; |
46 class Vector2d; | 47 class Vector2d; |
47 } | 48 } |
48 | 49 |
49 namespace cc { | 50 namespace cc { |
50 class BlockingTaskRunner; | 51 class BlockingTaskRunner; |
| 52 class GpuMemoryBufferManager; |
51 class IdAllocator; | 53 class IdAllocator; |
52 class SharedBitmap; | 54 class SharedBitmap; |
53 class SharedBitmapManager; | 55 class SharedBitmapManager; |
54 class TextureUploader; | 56 class TextureUploader; |
55 | 57 |
56 // This class is not thread-safe and can only be called from the thread it was | 58 // This class is not thread-safe and can only be called from the thread it was |
57 // created on (in practice, the impl thread). | 59 // created on (in practice, the impl thread). |
58 class CC_EXPORT ResourceProvider { | 60 class CC_EXPORT ResourceProvider { |
59 public: | 61 public: |
60 typedef unsigned ResourceId; | 62 typedef unsigned ResourceId; |
61 typedef std::vector<ResourceId> ResourceIdArray; | 63 typedef std::vector<ResourceId> ResourceIdArray; |
62 typedef std::set<ResourceId> ResourceIdSet; | 64 typedef std::set<ResourceId> ResourceIdSet; |
63 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; | 65 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; |
64 enum TextureHint { | 66 enum TextureHint { |
65 TextureHintDefault = 0x0, | 67 TextureHintDefault = 0x0, |
66 TextureHintImmutable = 0x1, | 68 TextureHintImmutable = 0x1, |
67 TextureHintFramebuffer = 0x2, | 69 TextureHintFramebuffer = 0x2, |
68 TextureHintImmutableFramebuffer = | 70 TextureHintImmutableFramebuffer = |
69 TextureHintImmutable | TextureHintFramebuffer | 71 TextureHintImmutable | TextureHintFramebuffer |
70 }; | 72 }; |
71 enum ResourceType { | 73 enum ResourceType { |
72 InvalidType = 0, | 74 InvalidType = 0, |
73 GLTexture = 1, | 75 GLTexture = 1, |
74 Bitmap, | 76 Bitmap, |
75 }; | 77 }; |
76 | 78 |
77 static scoped_ptr<ResourceProvider> Create( | 79 static scoped_ptr<ResourceProvider> Create( |
78 OutputSurface* output_surface, | 80 OutputSurface* output_surface, |
79 SharedBitmapManager* shared_bitmap_manager, | 81 SharedBitmapManager* shared_bitmap_manager, |
| 82 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
80 BlockingTaskRunner* blocking_main_thread_task_runner, | 83 BlockingTaskRunner* blocking_main_thread_task_runner, |
81 int highp_threshold_min, | 84 int highp_threshold_min, |
82 bool use_rgba_4444_texture_format, | 85 bool use_rgba_4444_texture_format, |
83 size_t id_allocation_chunk_size, | 86 size_t id_allocation_chunk_size, |
84 bool use_distance_field_text); | 87 bool use_distance_field_text); |
85 virtual ~ResourceProvider(); | 88 virtual ~ResourceProvider(); |
86 | 89 |
87 void InitializeSoftware(); | 90 void InitializeSoftware(); |
88 void InitializeGL(); | 91 void InitializeGL(); |
89 | 92 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 305 |
303 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); | 306 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); |
304 }; | 307 }; |
305 | 308 |
306 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { | 309 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { |
307 public: | 310 public: |
308 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 311 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
309 ResourceProvider::ResourceId resource_id); | 312 ResourceProvider::ResourceId resource_id); |
310 ~ScopedWriteLockGpuMemoryBuffer(); | 313 ~ScopedWriteLockGpuMemoryBuffer(); |
311 | 314 |
312 void* gpu_memory_buffer() { return gpu_memory_buffer_; } | 315 gfx::GpuMemoryBuffer* gpu_memory_buffer() { return gpu_memory_buffer_; } |
313 int stride() const { return stride_; } | |
314 | 316 |
315 private: | 317 private: |
316 ResourceProvider* resource_provider_; | 318 ResourceProvider* resource_provider_; |
317 ResourceProvider::ResourceId resource_id_; | 319 ResourceProvider::ResourceId resource_id_; |
318 unsigned image_id_; | 320 gfx::GpuMemoryBuffer* gpu_memory_buffer_; |
319 void* gpu_memory_buffer_; | |
320 int stride_; | |
321 | 321 |
322 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); | 322 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); |
323 }; | 323 }; |
324 | 324 |
325 class CC_EXPORT ScopedWriteLockGr { | 325 class CC_EXPORT ScopedWriteLockGr { |
326 public: | 326 public: |
327 ScopedWriteLockGr(ResourceProvider* resource_provider, | 327 ScopedWriteLockGr(ResourceProvider* resource_provider, |
328 ResourceProvider::ResourceId resource_id); | 328 ResourceProvider::ResourceId resource_id); |
329 ~ScopedWriteLockGr(); | 329 ~ScopedWriteLockGr(); |
330 | 330 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 GLenum filter; | 449 GLenum filter; |
450 unsigned image_id; | 450 unsigned image_id; |
451 unsigned bound_image_id; | 451 unsigned bound_image_id; |
452 GLenum texture_pool; | 452 GLenum texture_pool; |
453 GLint wrap_mode; | 453 GLint wrap_mode; |
454 TextureHint hint; | 454 TextureHint hint; |
455 ResourceType type; | 455 ResourceType type; |
456 ResourceFormat format; | 456 ResourceFormat format; |
457 SharedBitmapId shared_bitmap_id; | 457 SharedBitmapId shared_bitmap_id; |
458 SharedBitmap* shared_bitmap; | 458 SharedBitmap* shared_bitmap; |
| 459 gfx::GpuMemoryBuffer* gpu_memory_buffer; |
459 skia::RefPtr<SkSurface> sk_surface; | 460 skia::RefPtr<SkSurface> sk_surface; |
460 }; | 461 }; |
461 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 462 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
462 | 463 |
463 static bool CompareResourceMapIteratorsByChildId( | 464 static bool CompareResourceMapIteratorsByChildId( |
464 const std::pair<ReturnedResource, ResourceMap::iterator>& a, | 465 const std::pair<ReturnedResource, ResourceMap::iterator>& a, |
465 const std::pair<ReturnedResource, ResourceMap::iterator>& b); | 466 const std::pair<ReturnedResource, ResourceMap::iterator>& b); |
466 | 467 |
467 struct Child { | 468 struct Child { |
468 Child(); | 469 Child(); |
469 ~Child(); | 470 ~Child(); |
470 | 471 |
471 ResourceIdMap child_to_parent_map; | 472 ResourceIdMap child_to_parent_map; |
472 ResourceIdMap parent_to_child_map; | 473 ResourceIdMap parent_to_child_map; |
473 ReturnCallback return_callback; | 474 ReturnCallback return_callback; |
474 ResourceIdSet in_use_resources; | 475 ResourceIdSet in_use_resources; |
475 bool marked_for_deletion; | 476 bool marked_for_deletion; |
476 }; | 477 }; |
477 typedef base::hash_map<int, Child> ChildMap; | 478 typedef base::hash_map<int, Child> ChildMap; |
478 | 479 |
479 bool ReadLockFenceHasPassed(const Resource* resource) { | 480 bool ReadLockFenceHasPassed(const Resource* resource) { |
480 return !resource->read_lock_fence.get() || | 481 return !resource->read_lock_fence.get() || |
481 resource->read_lock_fence->HasPassed(); | 482 resource->read_lock_fence->HasPassed(); |
482 } | 483 } |
483 | 484 |
484 ResourceProvider(OutputSurface* output_surface, | 485 ResourceProvider(OutputSurface* output_surface, |
485 SharedBitmapManager* shared_bitmap_manager, | 486 SharedBitmapManager* shared_bitmap_manager, |
| 487 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
486 BlockingTaskRunner* blocking_main_thread_task_runner, | 488 BlockingTaskRunner* blocking_main_thread_task_runner, |
487 int highp_threshold_min, | 489 int highp_threshold_min, |
488 bool use_rgba_4444_texture_format, | 490 bool use_rgba_4444_texture_format, |
489 size_t id_allocation_chunk_size, | 491 size_t id_allocation_chunk_size, |
490 bool use_distance_field_text); | 492 bool use_distance_field_text); |
491 | 493 |
492 void CleanUpGLIfNeeded(); | 494 void CleanUpGLIfNeeded(); |
493 | 495 |
494 Resource* GetResource(ResourceId id); | 496 Resource* GetResource(ResourceId id); |
495 const Resource* LockForRead(ResourceId id); | 497 const Resource* LockForRead(ResourceId id); |
(...skipping 28 matching lines...) Expand all Loading... |
524 // specified filter for both minification and magnification. Returns the | 526 // specified filter for both minification and magnification. Returns the |
525 // texture target used. The resource must be locked for reading. | 527 // texture target used. The resource must be locked for reading. |
526 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); | 528 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); |
527 | 529 |
528 // Returns NULL if the output_surface_ does not have a ContextProvider. | 530 // Returns NULL if the output_surface_ does not have a ContextProvider. |
529 gpu::gles2::GLES2Interface* ContextGL() const; | 531 gpu::gles2::GLES2Interface* ContextGL() const; |
530 class GrContext* GrContext() const; | 532 class GrContext* GrContext() const; |
531 | 533 |
532 OutputSurface* output_surface_; | 534 OutputSurface* output_surface_; |
533 SharedBitmapManager* shared_bitmap_manager_; | 535 SharedBitmapManager* shared_bitmap_manager_; |
| 536 GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
534 BlockingTaskRunner* blocking_main_thread_task_runner_; | 537 BlockingTaskRunner* blocking_main_thread_task_runner_; |
535 bool lost_output_surface_; | 538 bool lost_output_surface_; |
536 int highp_threshold_min_; | 539 int highp_threshold_min_; |
537 ResourceId next_id_; | 540 ResourceId next_id_; |
538 ResourceMap resources_; | 541 ResourceMap resources_; |
539 int next_child_; | 542 int next_child_; |
540 ChildMap children_; | 543 ChildMap children_; |
541 | 544 |
542 ResourceType default_resource_type_; | 545 ResourceType default_resource_type_; |
543 bool use_texture_storage_ext_; | 546 bool use_texture_storage_ext_; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 return format_gl_data_format[format]; | 612 return format_gl_data_format[format]; |
610 } | 613 } |
611 | 614 |
612 inline GLenum GLInternalFormat(ResourceFormat format) { | 615 inline GLenum GLInternalFormat(ResourceFormat format) { |
613 return GLDataFormat(format); | 616 return GLDataFormat(format); |
614 } | 617 } |
615 | 618 |
616 } // namespace cc | 619 } // namespace cc |
617 | 620 |
618 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 621 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |