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 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 imported_count(0), | 229 imported_count(0), |
230 exported_count(0), | 230 exported_count(0), |
231 dirty_image(false), | 231 dirty_image(false), |
232 locked_for_write(false), | 232 locked_for_write(false), |
233 lost(false), | 233 lost(false), |
234 marked_for_deletion(false), | 234 marked_for_deletion(false), |
235 allocated(false), | 235 allocated(false), |
236 read_lock_fences_enabled(false), | 236 read_lock_fences_enabled(false), |
237 has_shared_bitmap_id(false), | 237 has_shared_bitmap_id(false), |
238 is_overlay_candidate(false), | 238 is_overlay_candidate(false), |
239 #if defined(OS_ANDROID) | |
240 is_backed_by_surface_texture(false), | |
241 wants_promotion_hint(false), | |
242 #endif | |
239 read_lock_fence(nullptr), | 243 read_lock_fence(nullptr), |
240 size(size), | 244 size(size), |
241 origin(origin), | 245 origin(origin), |
242 target(target), | 246 target(target), |
243 original_filter(filter), | 247 original_filter(filter), |
244 filter(filter), | 248 filter(filter), |
245 image_id(0), | 249 image_id(0), |
246 bound_image_id(0), | 250 bound_image_id(0), |
247 hint(hint), | 251 hint(hint), |
248 type(type), | 252 type(type), |
249 usage(gfx::BufferUsage::GPU_READ_CPU_READ_WRITE), | 253 usage(gfx::BufferUsage::GPU_READ_CPU_READ_WRITE), |
250 format(format), | 254 format(format), |
251 shared_bitmap(nullptr) {} | 255 shared_bitmap(nullptr) { |
256 } | |
252 | 257 |
253 ResourceProvider::Resource::Resource(uint8_t* pixels, | 258 ResourceProvider::Resource::Resource(uint8_t* pixels, |
254 SharedBitmap* bitmap, | 259 SharedBitmap* bitmap, |
255 const gfx::Size& size, | 260 const gfx::Size& size, |
256 Origin origin, | 261 Origin origin, |
257 GLenum filter) | 262 GLenum filter) |
258 : child_id(0), | 263 : child_id(0), |
259 gl_id(0), | 264 gl_id(0), |
260 gl_pixel_buffer_id(0), | 265 gl_pixel_buffer_id(0), |
261 gl_upload_query_id(0), | 266 gl_upload_query_id(0), |
262 gl_read_lock_query_id(0), | 267 gl_read_lock_query_id(0), |
263 pixels(pixels), | 268 pixels(pixels), |
264 lock_for_read_count(0), | 269 lock_for_read_count(0), |
265 imported_count(0), | 270 imported_count(0), |
266 exported_count(0), | 271 exported_count(0), |
267 dirty_image(false), | 272 dirty_image(false), |
268 locked_for_write(false), | 273 locked_for_write(false), |
269 lost(false), | 274 lost(false), |
270 marked_for_deletion(false), | 275 marked_for_deletion(false), |
271 allocated(false), | 276 allocated(false), |
272 read_lock_fences_enabled(false), | 277 read_lock_fences_enabled(false), |
273 has_shared_bitmap_id(!!bitmap), | 278 has_shared_bitmap_id(!!bitmap), |
274 is_overlay_candidate(false), | 279 is_overlay_candidate(false), |
280 #if defined(OS_ANDROID) | |
281 is_backed_by_surface_texture(false), | |
282 wants_promotion_hint(false), | |
283 #endif | |
275 read_lock_fence(nullptr), | 284 read_lock_fence(nullptr), |
276 size(size), | 285 size(size), |
277 origin(origin), | 286 origin(origin), |
278 target(0), | 287 target(0), |
279 original_filter(filter), | 288 original_filter(filter), |
280 filter(filter), | 289 filter(filter), |
281 image_id(0), | 290 image_id(0), |
282 bound_image_id(0), | 291 bound_image_id(0), |
283 hint(TEXTURE_HINT_IMMUTABLE), | 292 hint(TEXTURE_HINT_IMMUTABLE), |
284 type(RESOURCE_TYPE_BITMAP), | 293 type(RESOURCE_TYPE_BITMAP), |
(...skipping 18 matching lines...) Expand all Loading... | |
303 imported_count(0), | 312 imported_count(0), |
304 exported_count(0), | 313 exported_count(0), |
305 dirty_image(false), | 314 dirty_image(false), |
306 locked_for_write(false), | 315 locked_for_write(false), |
307 lost(false), | 316 lost(false), |
308 marked_for_deletion(false), | 317 marked_for_deletion(false), |
309 allocated(false), | 318 allocated(false), |
310 read_lock_fences_enabled(false), | 319 read_lock_fences_enabled(false), |
311 has_shared_bitmap_id(true), | 320 has_shared_bitmap_id(true), |
312 is_overlay_candidate(false), | 321 is_overlay_candidate(false), |
322 #if defined(OS_ANDROID) | |
323 is_backed_by_surface_texture(false), | |
324 wants_promotion_hint(false), | |
325 #endif | |
313 read_lock_fence(nullptr), | 326 read_lock_fence(nullptr), |
314 size(size), | 327 size(size), |
315 origin(origin), | 328 origin(origin), |
316 target(0), | 329 target(0), |
317 original_filter(filter), | 330 original_filter(filter), |
318 filter(filter), | 331 filter(filter), |
319 image_id(0), | 332 image_id(0), |
320 bound_image_id(0), | 333 bound_image_id(0), |
321 hint(TEXTURE_HINT_IMMUTABLE), | 334 hint(TEXTURE_HINT_IMMUTABLE), |
322 type(RESOURCE_TYPE_BITMAP), | 335 type(RESOURCE_TYPE_BITMAP), |
323 format(RGBA_8888), | 336 format(RGBA_8888), |
324 shared_bitmap_id(bitmap_id), | 337 shared_bitmap_id(bitmap_id), |
325 shared_bitmap(nullptr) {} | 338 shared_bitmap(nullptr) { |
339 } | |
326 | 340 |
327 ResourceProvider::Resource::Resource(Resource&& other) = default; | 341 ResourceProvider::Resource::Resource(Resource&& other) = default; |
328 | 342 |
329 void ResourceProvider::Resource::set_mailbox(const TextureMailbox& mailbox) { | 343 void ResourceProvider::Resource::set_mailbox(const TextureMailbox& mailbox) { |
330 mailbox_ = mailbox; | 344 mailbox_ = mailbox; |
331 if (IsGpuResourceType(type)) { | 345 if (IsGpuResourceType(type)) { |
332 synchronization_state_ = | 346 synchronization_state_ = |
333 (mailbox.sync_token().HasData() ? NEEDS_WAIT : LOCALLY_USED); | 347 (mailbox.sync_token().HasData() ? NEEDS_WAIT : LOCALLY_USED); |
334 needs_sync_token_ = !mailbox.sync_token().HasData(); | 348 needs_sync_token_ = !mailbox.sync_token().HasData(); |
335 } else { | 349 } else { |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 Resource::EXTERNAL, GL_LINEAR)); | 694 Resource::EXTERNAL, GL_LINEAR)); |
681 } | 695 } |
682 resource->allocated = true; | 696 resource->allocated = true; |
683 resource->set_mailbox(mailbox); | 697 resource->set_mailbox(mailbox); |
684 resource->color_space = mailbox.color_space(); | 698 resource->color_space = mailbox.color_space(); |
685 resource->release_callback_impl = | 699 resource->release_callback_impl = |
686 base::Bind(&SingleReleaseCallbackImpl::Run, | 700 base::Bind(&SingleReleaseCallbackImpl::Run, |
687 base::Owned(release_callback_impl.release())); | 701 base::Owned(release_callback_impl.release())); |
688 resource->read_lock_fences_enabled = read_lock_fences_enabled; | 702 resource->read_lock_fences_enabled = read_lock_fences_enabled; |
689 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); | 703 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); |
704 #if defined(OS_ANDROID) | |
705 resource->is_backed_by_surface_texture = | |
706 mailbox.is_backed_by_surface_texture(); | |
707 resource->wants_promotion_hint = mailbox.wants_promotion_hint(); | |
708 #endif | |
690 resource->color_space = mailbox.color_space(); | 709 resource->color_space = mailbox.color_space(); |
691 | 710 |
692 return id; | 711 return id; |
693 } | 712 } |
694 | 713 |
695 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 714 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
696 const TextureMailbox& mailbox, | 715 const TextureMailbox& mailbox, |
697 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { | 716 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { |
698 return CreateResourceFromTextureMailbox( | 717 return CreateResourceFromTextureMailbox( |
699 mailbox, std::move(release_callback_impl), false); | 718 mailbox, std::move(release_callback_impl), false); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 return !resource->locked_for_write && !resource->lock_for_read_count && | 1063 return !resource->locked_for_write && !resource->lock_for_read_count && |
1045 !resource->exported_count && resource->origin == Resource::INTERNAL && | 1064 !resource->exported_count && resource->origin == Resource::INTERNAL && |
1046 !resource->lost && ReadLockFenceHasPassed(resource); | 1065 !resource->lost && ReadLockFenceHasPassed(resource); |
1047 } | 1066 } |
1048 | 1067 |
1049 bool ResourceProvider::IsOverlayCandidate(ResourceId id) { | 1068 bool ResourceProvider::IsOverlayCandidate(ResourceId id) { |
1050 Resource* resource = GetResource(id); | 1069 Resource* resource = GetResource(id); |
1051 return resource->is_overlay_candidate; | 1070 return resource->is_overlay_candidate; |
1052 } | 1071 } |
1053 | 1072 |
1073 #if defined(OS_ANDROID) | |
1074 bool ResourceProvider::IsBackedBySurfaceTexture(ResourceId id) { | |
1075 Resource* resource = GetResource(id); | |
1076 return resource->is_backed_by_surface_texture; | |
1077 } | |
1078 #endif | |
1079 | |
1054 void ResourceProvider::UnlockForWrite(Resource* resource) { | 1080 void ResourceProvider::UnlockForWrite(Resource* resource) { |
1055 DCHECK(resource->locked_for_write); | 1081 DCHECK(resource->locked_for_write); |
1056 DCHECK_EQ(resource->exported_count, 0); | 1082 DCHECK_EQ(resource->exported_count, 0); |
1057 DCHECK(resource->origin == Resource::INTERNAL); | 1083 DCHECK(resource->origin == Resource::INTERNAL); |
1058 resource->locked_for_write = false; | 1084 resource->locked_for_write = false; |
1059 } | 1085 } |
1060 | 1086 |
1061 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) { | 1087 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) { |
1062 Resource* resource = GetResource(id); | 1088 Resource* resource = GetResource(id); |
1063 DCHECK(resource); | 1089 DCHECK(resource); |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1531 resource = InsertResource( | 1557 resource = InsertResource( |
1532 local_id, Resource(0, it->size, Resource::DELEGATED, | 1558 local_id, Resource(0, it->size, Resource::DELEGATED, |
1533 it->mailbox_holder.texture_target, it->filter, | 1559 it->mailbox_holder.texture_target, it->filter, |
1534 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, | 1560 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, |
1535 it->format)); | 1561 it->format)); |
1536 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox, | 1562 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox, |
1537 it->mailbox_holder.sync_token, | 1563 it->mailbox_holder.sync_token, |
1538 it->mailbox_holder.texture_target)); | 1564 it->mailbox_holder.texture_target)); |
1539 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; | 1565 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; |
1540 resource->is_overlay_candidate = it->is_overlay_candidate; | 1566 resource->is_overlay_candidate = it->is_overlay_candidate; |
1567 #if defined(OS_ANDROID) | |
1568 resource->is_backed_by_surface_texture = it->is_backed_by_surface_texture; | |
1569 resource->wants_promotion_hint = it->wants_promotion_hint; | |
1570 #endif | |
1541 resource->color_space = it->color_space; | 1571 resource->color_space = it->color_space; |
1542 } | 1572 } |
1543 resource->child_id = child; | 1573 resource->child_id = child; |
1544 // Don't allocate a texture for a child. | 1574 // Don't allocate a texture for a child. |
1545 resource->allocated = true; | 1575 resource->allocated = true; |
1546 resource->imported_count = 1; | 1576 resource->imported_count = 1; |
1547 child_info.parent_to_child_map[local_id] = it->id; | 1577 child_info.parent_to_child_map[local_id] = it->id; |
1548 child_info.child_to_parent_map[it->id] = local_id; | 1578 child_info.child_to_parent_map[it->id] = local_id; |
1549 } | 1579 } |
1550 } | 1580 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1619 resources_for_child[resource->child_id].push_back(local_id); | 1649 resources_for_child[resource->child_id].push_back(local_id); |
1620 } | 1650 } |
1621 | 1651 |
1622 for (const auto& children : resources_for_child) { | 1652 for (const auto& children : resources_for_child) { |
1623 ChildMap::iterator child_it = children_.find(children.first); | 1653 ChildMap::iterator child_it = children_.find(children.first); |
1624 DCHECK(child_it != children_.end()); | 1654 DCHECK(child_it != children_.end()); |
1625 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); | 1655 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); |
1626 } | 1656 } |
1627 } | 1657 } |
1628 | 1658 |
1659 #if defined(OS_ANDROID) | |
1660 void ResourceProvider::SendPromotionHints(const ResourceIdSet& promotable_set) { | |
1661 GLES2Interface* gl = ContextGL(); | |
1662 DCHECK(gl); | |
1663 | |
1664 for (const auto& it : resources_) { | |
piman
2016/12/01 21:55:25
This sounds mildly expensive to go over all resour
liberato (no reviews please)
2016/12/05 18:14:01
Done.
| |
1665 const Resource& resource = it.second; | |
1666 // The resource must care about promotion hints. | |
1667 if (!resource.wants_promotion_hint) | |
1668 continue; | |
1669 | |
1670 // Insist that this is backed by a GPU texture. | |
1671 if (!IsGpuResourceType(resource.type)) | |
1672 continue; | |
1673 | |
1674 // TODO(liberato): I'm unsure why we can assume that |gl_id| is set yet | |
1675 // without using a read lock. | |
piman
2016/12/01 21:55:25
I don't think you can, actually, gl_id is set (and
liberato (no reviews please)
2016/12/05 18:14:01
Done.
| |
1676 DCHECK(resource.gl_id); | |
1677 // gl->SetStreamTexturePromotionHintCHROMIUM(resource.gl_id, | |
piman
2016/12/01 21:55:25
Do you expect we'll be doing a lot of these every
liberato (no reviews please)
2016/12/05 18:14:01
good question. it'll be one per video element tha
| |
1678 // promotable_set.count(it->first) > 0); | |
1679 } | |
1680 } | |
1681 #endif | |
1682 | |
1629 void ResourceProvider::CreateMailboxAndBindResource( | 1683 void ResourceProvider::CreateMailboxAndBindResource( |
1630 gpu::gles2::GLES2Interface* gl, | 1684 gpu::gles2::GLES2Interface* gl, |
1631 Resource* resource) { | 1685 Resource* resource) { |
1632 DCHECK(IsGpuResourceType(resource->type)); | 1686 DCHECK(IsGpuResourceType(resource->type)); |
1633 DCHECK(gl); | 1687 DCHECK(gl); |
1634 | 1688 |
1635 if (!resource->mailbox().IsValid()) { | 1689 if (!resource->mailbox().IsValid()) { |
1636 LazyCreate(resource); | 1690 LazyCreate(resource); |
1637 | 1691 |
1638 gpu::MailboxHolder mailbox_holder; | 1692 gpu::MailboxHolder mailbox_holder; |
(...skipping 19 matching lines...) Expand all Loading... | |
1658 DCHECK(!source->lock_for_read_count); | 1712 DCHECK(!source->lock_for_read_count); |
1659 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); | 1713 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); |
1660 DCHECK(source->allocated); | 1714 DCHECK(source->allocated); |
1661 resource->id = id; | 1715 resource->id = id; |
1662 resource->format = source->format; | 1716 resource->format = source->format; |
1663 resource->mailbox_holder.texture_target = source->target; | 1717 resource->mailbox_holder.texture_target = source->target; |
1664 resource->filter = source->filter; | 1718 resource->filter = source->filter; |
1665 resource->size = source->size; | 1719 resource->size = source->size; |
1666 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; | 1720 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; |
1667 resource->is_overlay_candidate = source->is_overlay_candidate; | 1721 resource->is_overlay_candidate = source->is_overlay_candidate; |
1722 #if defined(OS_ANDROID) | |
1723 resource->is_backed_by_surface_texture = source->is_backed_by_surface_texture; | |
1724 resource->wants_promotion_hint = source->wants_promotion_hint; | |
1725 #endif | |
1668 resource->color_space = source->color_space; | 1726 resource->color_space = source->color_space; |
1669 | 1727 |
1670 if (source->type == RESOURCE_TYPE_BITMAP) { | 1728 if (source->type == RESOURCE_TYPE_BITMAP) { |
1671 resource->mailbox_holder.mailbox = source->shared_bitmap_id; | 1729 resource->mailbox_holder.mailbox = source->shared_bitmap_id; |
1672 resource->is_software = true; | 1730 resource->is_software = true; |
1673 } else { | 1731 } else { |
1674 DCHECK(source->mailbox().IsValid()); | 1732 DCHECK(source->mailbox().IsValid()); |
1675 DCHECK(source->mailbox().IsTexture()); | 1733 DCHECK(source->mailbox().IsTexture()); |
1676 DCHECK(!source->image_id || !source->dirty_image); | 1734 DCHECK(!source->image_id || !source->dirty_image); |
1677 // This is either an external resource, or a compositor resource that we | 1735 // This is either an external resource, or a compositor resource that we |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2064 | 2122 |
2065 const int kImportance = 2; | 2123 const int kImportance = 2; |
2066 pmd->CreateSharedGlobalAllocatorDump(guid); | 2124 pmd->CreateSharedGlobalAllocatorDump(guid); |
2067 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2125 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
2068 } | 2126 } |
2069 | 2127 |
2070 return true; | 2128 return true; |
2071 } | 2129 } |
2072 | 2130 |
2073 } // namespace cc | 2131 } // namespace cc |
OLD | NEW |