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> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
20 #include "cc/base/cc_export.h" | 20 #include "cc/base/cc_export.h" |
21 #include "cc/output/context_provider.h" | 21 #include "cc/output/context_provider.h" |
22 #include "cc/output/output_surface.h" | 22 #include "cc/output/output_surface.h" |
23 #include "cc/resources/raster_buffer.h" | 23 #include "cc/resources/raster_buffer.h" |
24 #include "cc/resources/release_callback.h" | 24 #include "cc/resources/release_callback_impl.h" |
25 #include "cc/resources/resource_format.h" | 25 #include "cc/resources/resource_format.h" |
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.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/size.h" | 35 #include "ui/gfx/size.h" |
36 | 36 |
37 class GrContext; | 37 class GrContext; |
38 | 38 |
39 namespace gpu { | 39 namespace gpu { |
40 namespace gles { | 40 namespace gles { |
41 class GLES2Interface; | 41 class GLES2Interface; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 namespace gfx { | 45 namespace gfx { |
46 class Rect; | 46 class Rect; |
47 class Vector2d; | 47 class Vector2d; |
48 } | 48 } |
49 | 49 |
50 namespace cc { | 50 namespace cc { |
| 51 class BlockingTaskRunner; |
51 class IdAllocator; | 52 class IdAllocator; |
52 class SharedBitmap; | 53 class SharedBitmap; |
53 class SharedBitmapManager; | 54 class SharedBitmapManager; |
54 class TextureUploader; | 55 class TextureUploader; |
55 | 56 |
56 // This class is not thread-safe and can only be called from the thread it was | 57 // This class is not thread-safe and can only be called from the thread it was |
57 // created on (in practice, the impl thread). | 58 // created on (in practice, the impl thread). |
58 class CC_EXPORT ResourceProvider { | 59 class CC_EXPORT ResourceProvider { |
59 public: | 60 public: |
60 typedef unsigned ResourceId; | 61 typedef unsigned ResourceId; |
61 typedef std::vector<ResourceId> ResourceIdArray; | 62 typedef std::vector<ResourceId> ResourceIdArray; |
62 typedef std::set<ResourceId> ResourceIdSet; | 63 typedef std::set<ResourceId> ResourceIdSet; |
63 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; | 64 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; |
64 enum TextureHint { | 65 enum TextureHint { |
65 TextureHintDefault = 0x0, | 66 TextureHintDefault = 0x0, |
66 TextureHintImmutable = 0x1, | 67 TextureHintImmutable = 0x1, |
67 TextureHintFramebuffer = 0x2, | 68 TextureHintFramebuffer = 0x2, |
68 TextureHintImmutableFramebuffer = | 69 TextureHintImmutableFramebuffer = |
69 TextureHintImmutable | TextureHintFramebuffer | 70 TextureHintImmutable | TextureHintFramebuffer |
70 }; | 71 }; |
71 enum ResourceType { | 72 enum ResourceType { |
72 InvalidType = 0, | 73 InvalidType = 0, |
73 GLTexture = 1, | 74 GLTexture = 1, |
74 Bitmap, | 75 Bitmap, |
75 }; | 76 }; |
76 | 77 |
77 static scoped_ptr<ResourceProvider> Create( | 78 static scoped_ptr<ResourceProvider> Create( |
78 OutputSurface* output_surface, | 79 OutputSurface* output_surface, |
79 SharedBitmapManager* shared_bitmap_manager, | 80 SharedBitmapManager* shared_bitmap_manager, |
| 81 BlockingTaskRunner* blocking_main_thread_task_runner, |
80 int highp_threshold_min, | 82 int highp_threshold_min, |
81 bool use_rgba_4444_texture_format, | 83 bool use_rgba_4444_texture_format, |
82 size_t id_allocation_chunk_size, | 84 size_t id_allocation_chunk_size, |
83 bool use_distance_field_text); | 85 bool use_distance_field_text); |
84 virtual ~ResourceProvider(); | 86 virtual ~ResourceProvider(); |
85 | 87 |
86 void InitializeSoftware(); | 88 void InitializeSoftware(); |
87 void InitializeGL(); | 89 void InitializeGL(); |
88 | 90 |
89 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 91 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ResourceFormat format); | 132 ResourceFormat format); |
131 | 133 |
132 ResourceId CreateBitmap(const gfx::Size& size, GLint wrap_mode); | 134 ResourceId CreateBitmap(const gfx::Size& size, GLint wrap_mode); |
133 // Wraps an IOSurface into a GL resource. | 135 // Wraps an IOSurface into a GL resource. |
134 ResourceId CreateResourceFromIOSurface(const gfx::Size& size, | 136 ResourceId CreateResourceFromIOSurface(const gfx::Size& size, |
135 unsigned io_surface_id); | 137 unsigned io_surface_id); |
136 | 138 |
137 // Wraps an external texture mailbox into a GL resource. | 139 // Wraps an external texture mailbox into a GL resource. |
138 ResourceId CreateResourceFromTextureMailbox( | 140 ResourceId CreateResourceFromTextureMailbox( |
139 const TextureMailbox& mailbox, | 141 const TextureMailbox& mailbox, |
140 scoped_ptr<SingleReleaseCallback> release_callback); | 142 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl); |
141 | 143 |
142 void DeleteResource(ResourceId id); | 144 void DeleteResource(ResourceId id); |
143 | 145 |
144 // Update pixels from image, copying source_rect (in image) to dest_offset (in | 146 // Update pixels from image, copying source_rect (in image) to dest_offset (in |
145 // the resource). | 147 // the resource). |
146 void SetPixels(ResourceId id, | 148 void SetPixels(ResourceId id, |
147 const uint8_t* image, | 149 const uint8_t* image, |
148 const gfx::Rect& image_rect, | 150 const gfx::Rect& image_rect, |
149 const gfx::Rect& source_rect, | 151 const gfx::Rect& source_rect, |
150 const gfx::Vector2d& dest_offset); | 152 const gfx::Vector2d& dest_offset); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 407 |
406 int child_id; | 408 int child_id; |
407 unsigned gl_id; | 409 unsigned gl_id; |
408 // Pixel buffer used for set pixels without unnecessary copying. | 410 // Pixel buffer used for set pixels without unnecessary copying. |
409 unsigned gl_pixel_buffer_id; | 411 unsigned gl_pixel_buffer_id; |
410 // Query used to determine when asynchronous set pixels complete. | 412 // Query used to determine when asynchronous set pixels complete. |
411 unsigned gl_upload_query_id; | 413 unsigned gl_upload_query_id; |
412 // Query used to determine when read lock fence has passed. | 414 // Query used to determine when read lock fence has passed. |
413 unsigned gl_read_lock_query_id; | 415 unsigned gl_read_lock_query_id; |
414 TextureMailbox mailbox; | 416 TextureMailbox mailbox; |
415 ReleaseCallback release_callback; | 417 ReleaseCallbackImpl release_callback_impl; |
416 uint8_t* pixels; | 418 uint8_t* pixels; |
417 int lock_for_read_count; | 419 int lock_for_read_count; |
418 int imported_count; | 420 int imported_count; |
419 int exported_count; | 421 int exported_count; |
420 bool dirty_image : 1; | 422 bool dirty_image : 1; |
421 bool locked_for_write : 1; | 423 bool locked_for_write : 1; |
422 bool lost : 1; | 424 bool lost : 1; |
423 bool marked_for_deletion : 1; | 425 bool marked_for_deletion : 1; |
424 bool pending_set_pixels : 1; | 426 bool pending_set_pixels : 1; |
425 bool set_pixels_completion_forced : 1; | 427 bool set_pixels_completion_forced : 1; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 }; | 531 }; |
530 typedef base::hash_map<int, Child> ChildMap; | 532 typedef base::hash_map<int, Child> ChildMap; |
531 | 533 |
532 bool ReadLockFenceHasPassed(const Resource* resource) { | 534 bool ReadLockFenceHasPassed(const Resource* resource) { |
533 return !resource->read_lock_fence.get() || | 535 return !resource->read_lock_fence.get() || |
534 resource->read_lock_fence->HasPassed(); | 536 resource->read_lock_fence->HasPassed(); |
535 } | 537 } |
536 | 538 |
537 ResourceProvider(OutputSurface* output_surface, | 539 ResourceProvider(OutputSurface* output_surface, |
538 SharedBitmapManager* shared_bitmap_manager, | 540 SharedBitmapManager* shared_bitmap_manager, |
| 541 BlockingTaskRunner* blocking_main_thread_task_runner, |
539 int highp_threshold_min, | 542 int highp_threshold_min, |
540 bool use_rgba_4444_texture_format, | 543 bool use_rgba_4444_texture_format, |
541 size_t id_allocation_chunk_size, | 544 size_t id_allocation_chunk_size, |
542 bool use_distance_field_text); | 545 bool use_distance_field_text); |
543 | 546 |
544 void CleanUpGLIfNeeded(); | 547 void CleanUpGLIfNeeded(); |
545 | 548 |
546 Resource* GetResource(ResourceId id); | 549 Resource* GetResource(ResourceId id); |
547 const Resource* LockForRead(ResourceId id); | 550 const Resource* LockForRead(ResourceId id); |
548 void UnlockForRead(ResourceId id); | 551 void UnlockForRead(ResourceId id); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, | 595 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, |
593 GLenum unit, | 596 GLenum unit, |
594 GLenum filter); | 597 GLenum filter); |
595 | 598 |
596 // Returns NULL if the output_surface_ does not have a ContextProvider. | 599 // Returns NULL if the output_surface_ does not have a ContextProvider. |
597 gpu::gles2::GLES2Interface* ContextGL() const; | 600 gpu::gles2::GLES2Interface* ContextGL() const; |
598 class GrContext* GrContext() const; | 601 class GrContext* GrContext() const; |
599 | 602 |
600 OutputSurface* output_surface_; | 603 OutputSurface* output_surface_; |
601 SharedBitmapManager* shared_bitmap_manager_; | 604 SharedBitmapManager* shared_bitmap_manager_; |
| 605 BlockingTaskRunner* blocking_main_thread_task_runner_; |
602 bool lost_output_surface_; | 606 bool lost_output_surface_; |
603 int highp_threshold_min_; | 607 int highp_threshold_min_; |
604 ResourceId next_id_; | 608 ResourceId next_id_; |
605 ResourceMap resources_; | 609 ResourceMap resources_; |
606 int next_child_; | 610 int next_child_; |
607 ChildMap children_; | 611 ChildMap children_; |
608 | 612 |
609 ResourceType default_resource_type_; | 613 ResourceType default_resource_type_; |
610 bool use_texture_storage_ext_; | 614 bool use_texture_storage_ext_; |
611 bool use_texture_format_bgra_; | 615 bool use_texture_format_bgra_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 return format_gl_data_format[format]; | 680 return format_gl_data_format[format]; |
677 } | 681 } |
678 | 682 |
679 inline GLenum GLInternalFormat(ResourceFormat format) { | 683 inline GLenum GLInternalFormat(ResourceFormat format) { |
680 return GLDataFormat(format); | 684 return GLDataFormat(format); |
681 } | 685 } |
682 | 686 |
683 } // namespace cc | 687 } // namespace cc |
684 | 688 |
685 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 689 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |