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 <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
19 #include "cc/output/context_provider.h" | 19 #include "cc/output/context_provider.h" |
20 #include "cc/output/output_surface.h" | 20 #include "cc/output/output_surface.h" |
21 #include "cc/resources/release_callback.h" | 21 #include "cc/resources/release_callback.h" |
| 22 #include "cc/resources/return_callback.h" |
22 #include "cc/resources/single_release_callback.h" | 23 #include "cc/resources/single_release_callback.h" |
23 #include "cc/resources/texture_mailbox.h" | 24 #include "cc/resources/texture_mailbox.h" |
24 #include "cc/resources/transferable_resource.h" | 25 #include "cc/resources/transferable_resource.h" |
25 #include "third_party/khronos/GLES2/gl2.h" | 26 #include "third_party/khronos/GLES2/gl2.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "third_party/skia/include/core/SkCanvas.h" | 28 #include "third_party/skia/include/core/SkCanvas.h" |
28 #include "ui/gfx/size.h" | 29 #include "ui/gfx/size.h" |
29 | 30 |
30 namespace WebKit { class WebGraphicsContext3D; } | 31 namespace WebKit { class WebGraphicsContext3D; } |
31 | 32 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 134 |
134 // Finish all context operations, causing any pending callbacks to be | 135 // Finish all context operations, causing any pending callbacks to be |
135 // scheduled. | 136 // scheduled. |
136 void Finish(); | 137 void Finish(); |
137 | 138 |
138 // Only flush the command buffer if supported. | 139 // Only flush the command buffer if supported. |
139 // Returns true if the shallow flush occurred, false otherwise. | 140 // Returns true if the shallow flush occurred, false otherwise. |
140 bool ShallowFlushIfSupported(); | 141 bool ShallowFlushIfSupported(); |
141 | 142 |
142 // Creates accounting for a child. Returns a child ID. | 143 // Creates accounting for a child. Returns a child ID. |
143 int CreateChild(); | 144 int CreateChild(const ReturnCallback& return_callback); |
144 | 145 |
145 // Destroys accounting for the child, deleting all accounted resources. | 146 // Destroys accounting for the child, deleting all accounted resources. |
146 void DestroyChild(int child); | 147 void DestroyChild(int child); |
147 | 148 |
148 // Gets the child->parent resource ID map. | 149 // Gets the child->parent resource ID map. |
149 const ResourceIdMap& GetChildToParentMap(int child) const; | 150 const ResourceIdMap& GetChildToParentMap(int child) const; |
150 | 151 |
151 // Prepares resources to be transfered to the parent, moving them to | 152 // Prepares resources to be transfered to the parent, moving them to |
152 // mailboxes and serializing meta-data into TransferableResources. | 153 // mailboxes and serializing meta-data into TransferableResources. |
153 // Resources are not removed from the ResourceProvider, but are marked as | 154 // Resources are not removed from the ResourceProvider, but are marked as |
154 // "in use". | 155 // "in use". |
155 void PrepareSendToParent(const ResourceIdArray& resources, | 156 void PrepareSendToParent(const ResourceIdArray& resources, |
156 TransferableResourceArray* transferable_resources); | 157 TransferableResourceArray* transferable_resources); |
157 | 158 |
158 // Prepares resources to be transfered back to the child, moving them to | |
159 // mailboxes and serializing meta-data into TransferableResources. | |
160 // Resources are removed from the ResourceProvider. Note: the resource IDs | |
161 // passed are in the parent namespace and will be translated to the child | |
162 // namespace when returned. | |
163 void PrepareSendReturnsToChild(int child, | |
164 const ResourceIdArray& resources, | |
165 ReturnedResourceArray* returned_resources); | |
166 | |
167 // Receives resources from a child, moving them from mailboxes. Resource IDs | 159 // Receives resources from a child, moving them from mailboxes. Resource IDs |
168 // passed are in the child namespace, and will be translated to the parent | 160 // passed are in the child namespace, and will be translated to the parent |
169 // namespace, added to the child->parent map. | 161 // namespace, added to the child->parent map. |
| 162 // This adds the resources to the working set in the ResourceProvider without |
| 163 // declaring which resources are in use. Use DeclareUsedResourcesFromChild |
| 164 // after calling this method to do that. All calls to ReceiveFromChild should |
| 165 // be followed by a DeclareUsedResourcesFromChild. |
170 // NOTE: if the sync_point is set on any TransferableResource, this will | 166 // NOTE: if the sync_point is set on any TransferableResource, this will |
171 // wait on it. | 167 // wait on it. |
172 void ReceiveFromChild( | 168 void ReceiveFromChild( |
173 int child, const TransferableResourceArray& transferable_resources); | 169 int child, const TransferableResourceArray& transferable_resources); |
174 | 170 |
| 171 // Once a set of resources have been received, they may or may not be used. |
| 172 // This declares what set of resources are currently in use from the child, |
| 173 // releasing any other resources back to the child. |
| 174 void DeclareUsedResourcesFromChild( |
| 175 int child, |
| 176 const ResourceIdArray& resources_from_child); |
| 177 |
175 // Receives resources from the parent, moving them from mailboxes. Resource | 178 // Receives resources from the parent, moving them from mailboxes. Resource |
176 // IDs passed are in the child namespace. | 179 // IDs passed are in the child namespace. |
177 // NOTE: if the sync_point is set on any TransferableResource, this will | 180 // NOTE: if the sync_point is set on any TransferableResource, this will |
178 // wait on it. | 181 // wait on it. |
179 void ReceiveReturnsFromParent( | 182 void ReceiveReturnsFromParent( |
180 const ReturnedResourceArray& transferable_resources); | 183 const ReturnedResourceArray& transferable_resources); |
181 | 184 |
182 // The following lock classes are part of the ResourceProvider API and are | 185 // The following lock classes are part of the ResourceProvider API and are |
183 // needed to read and write the resource contents. The user must ensure | 186 // needed to read and write the resource contents. The user must ensure |
184 // that they only use GL locks on GL resources, etc, and this is enforced | 187 // that they only use GL locks on GL resources, etc, and this is enforced |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 GLenum filter, | 348 GLenum filter, |
346 GLenum texture_pool, | 349 GLenum texture_pool, |
347 GLint wrap_mode, | 350 GLint wrap_mode, |
348 TextureUsageHint hint); | 351 TextureUsageHint hint); |
349 Resource(uint8_t* pixels, | 352 Resource(uint8_t* pixels, |
350 gfx::Size size, | 353 gfx::Size size, |
351 GLenum format, | 354 GLenum format, |
352 GLenum filter, | 355 GLenum filter, |
353 GLint wrap_mode); | 356 GLint wrap_mode); |
354 | 357 |
| 358 int child_id; |
355 unsigned gl_id; | 359 unsigned gl_id; |
356 // Pixel buffer used for set pixels without unnecessary copying. | 360 // Pixel buffer used for set pixels without unnecessary copying. |
357 unsigned gl_pixel_buffer_id; | 361 unsigned gl_pixel_buffer_id; |
358 // Query used to determine when asynchronous set pixels complete. | 362 // Query used to determine when asynchronous set pixels complete. |
359 unsigned gl_upload_query_id; | 363 unsigned gl_upload_query_id; |
360 TextureMailbox mailbox; | 364 TextureMailbox mailbox; |
361 ReleaseCallback release_callback; | 365 ReleaseCallback release_callback; |
362 uint8_t* pixels; | 366 uint8_t* pixels; |
363 uint8_t* pixel_buffer; | 367 uint8_t* pixel_buffer; |
364 int lock_for_read_count; | 368 int lock_for_read_count; |
(...skipping 19 matching lines...) Expand all Loading... |
384 TextureUsageHint hint; | 388 TextureUsageHint hint; |
385 ResourceType type; | 389 ResourceType type; |
386 }; | 390 }; |
387 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 391 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
388 struct Child { | 392 struct Child { |
389 Child(); | 393 Child(); |
390 ~Child(); | 394 ~Child(); |
391 | 395 |
392 ResourceIdMap child_to_parent_map; | 396 ResourceIdMap child_to_parent_map; |
393 ResourceIdMap parent_to_child_map; | 397 ResourceIdMap parent_to_child_map; |
| 398 ReturnCallback return_callback; |
| 399 ResourceIdSet in_use_resources; |
394 }; | 400 }; |
395 typedef base::hash_map<int, Child> ChildMap; | 401 typedef base::hash_map<int, Child> ChildMap; |
396 | 402 |
397 bool ReadLockFenceHasPassed(Resource* resource) { | 403 bool ReadLockFenceHasPassed(Resource* resource) { |
398 return !resource->read_lock_fence.get() || | 404 return !resource->read_lock_fence.get() || |
399 resource->read_lock_fence->HasPassed(); | 405 resource->read_lock_fence->HasPassed(); |
400 } | 406 } |
401 | 407 |
402 explicit ResourceProvider(OutputSurface* output_surface, | 408 explicit ResourceProvider(OutputSurface* output_surface, |
403 int highp_threshold_min); | 409 int highp_threshold_min); |
404 | 410 |
405 void CleanUpGLIfNeeded(); | 411 void CleanUpGLIfNeeded(); |
406 | 412 |
407 Resource* GetResource(ResourceId id); | 413 Resource* GetResource(ResourceId id); |
408 const Resource* LockForRead(ResourceId id); | 414 const Resource* LockForRead(ResourceId id); |
409 void UnlockForRead(ResourceId id); | 415 void UnlockForRead(ResourceId id); |
410 const Resource* LockForWrite(ResourceId id); | 416 const Resource* LockForWrite(ResourceId id); |
411 void UnlockForWrite(ResourceId id); | 417 void UnlockForWrite(ResourceId id); |
412 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 418 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
413 const Resource* resource); | 419 const Resource* resource); |
414 | 420 |
415 void TransferResource(WebKit::WebGraphicsContext3D* context, | 421 void TransferResource(WebKit::WebGraphicsContext3D* context, |
416 ResourceId id, | 422 ResourceId id, |
417 TransferableResource* resource); | 423 TransferableResource* resource); |
418 enum DeleteStyle { | 424 enum DeleteStyle { |
419 Normal, | 425 Normal, |
420 ForShutdown, | 426 ForShutdown, |
421 }; | 427 }; |
422 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); | 428 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); |
| 429 void DeleteAndReturnUnusedResourcesToChild(Child* child_info, |
| 430 DeleteStyle style, |
| 431 const ResourceIdArray& unused); |
423 void LazyCreate(Resource* resource); | 432 void LazyCreate(Resource* resource); |
424 void LazyAllocate(Resource* resource); | 433 void LazyAllocate(Resource* resource); |
425 | 434 |
426 // Binds the given GL resource to a texture target for sampling using the | 435 // Binds the given GL resource to a texture target for sampling using the |
427 // specified filter for both minification and magnification. The resource | 436 // specified filter for both minification and magnification. The resource |
428 // must be locked for reading. | 437 // must be locked for reading. |
429 void BindForSampling(ResourceProvider::ResourceId resource_id, | 438 void BindForSampling(ResourceProvider::ResourceId resource_id, |
430 GLenum target, | 439 GLenum target, |
431 GLenum unit, | 440 GLenum unit, |
432 GLenum filter); | 441 GLenum filter); |
(...skipping 23 matching lines...) Expand all Loading... |
456 base::ThreadChecker thread_checker_; | 465 base::ThreadChecker thread_checker_; |
457 | 466 |
458 scoped_refptr<Fence> current_read_lock_fence_; | 467 scoped_refptr<Fence> current_read_lock_fence_; |
459 | 468 |
460 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 469 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
461 }; | 470 }; |
462 | 471 |
463 } // namespace cc | 472 } // namespace cc |
464 | 473 |
465 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 474 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |