Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 2508203004: Add hints for potential overlay promotion on android. (Closed)
Patch Set: added CC_EXPORT Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 if (resource->wants_promotion_hint)
709 wants_promotion_hints_set_.insert(id);
710 #endif
690 resource->color_space = mailbox.color_space(); 711 resource->color_space = mailbox.color_space();
691 712
692 return id; 713 return id;
693 } 714 }
694 715
695 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 716 ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
696 const TextureMailbox& mailbox, 717 const TextureMailbox& mailbox,
697 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { 718 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) {
698 return CreateResourceFromTextureMailbox( 719 return CreateResourceFromTextureMailbox(
699 mailbox, std::move(release_callback_impl), false); 720 mailbox, std::move(release_callback_impl), false);
(...skipping 16 matching lines...) Expand all
716 DeleteResourceInternal(it, NORMAL); 737 DeleteResourceInternal(it, NORMAL);
717 } 738 }
718 } 739 }
719 740
720 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, 741 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it,
721 DeleteStyle style) { 742 DeleteStyle style) {
722 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); 743 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal");
723 Resource* resource = &it->second; 744 Resource* resource = &it->second;
724 DCHECK(resource->exported_count == 0 || style != NORMAL); 745 DCHECK(resource->exported_count == 0 || style != NORMAL);
725 746
747 #if defined(OS_ANDROID)
748 // If this resource was interested in promotion hints, then remove it from
749 // the set of resources that we'll notify.
750 if (resource->wants_promotion_hint)
751 wants_promotion_hints_set_.erase(it->first);
752 #endif
753
726 // Exported resources are lost on shutdown. 754 // Exported resources are lost on shutdown.
727 bool exported_resource_lost = 755 bool exported_resource_lost =
728 style == FOR_SHUTDOWN && resource->exported_count > 0; 756 style == FOR_SHUTDOWN && resource->exported_count > 0;
729 // GPU resources are lost when context is lost. 757 // GPU resources are lost when context is lost.
730 bool gpu_resource_lost = 758 bool gpu_resource_lost =
731 IsGpuResourceType(resource->type) && lost_context_provider_; 759 IsGpuResourceType(resource->type) && lost_context_provider_;
732 bool lost_resource = 760 bool lost_resource =
733 resource->lost || exported_resource_lost || gpu_resource_lost; 761 resource->lost || exported_resource_lost || gpu_resource_lost;
734 762
735 // Wait on sync token before deleting resources we own. 763 // Wait on sync token before deleting resources we own.
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 return !resource->locked_for_write && !resource->lock_for_read_count && 1072 return !resource->locked_for_write && !resource->lock_for_read_count &&
1045 !resource->exported_count && resource->origin == Resource::INTERNAL && 1073 !resource->exported_count && resource->origin == Resource::INTERNAL &&
1046 !resource->lost && ReadLockFenceHasPassed(resource); 1074 !resource->lost && ReadLockFenceHasPassed(resource);
1047 } 1075 }
1048 1076
1049 bool ResourceProvider::IsOverlayCandidate(ResourceId id) { 1077 bool ResourceProvider::IsOverlayCandidate(ResourceId id) {
1050 Resource* resource = GetResource(id); 1078 Resource* resource = GetResource(id);
1051 return resource->is_overlay_candidate; 1079 return resource->is_overlay_candidate;
1052 } 1080 }
1053 1081
1082 #if defined(OS_ANDROID)
1083 bool ResourceProvider::IsBackedBySurfaceTexture(ResourceId id) {
1084 Resource* resource = GetResource(id);
1085 return resource->is_backed_by_surface_texture;
1086 }
1087
1088 bool ResourceProvider::WantsPromotionHint(ResourceId id) {
1089 return wants_promotion_hints_set_.count(id) > 0;
1090 }
1091
1092 size_t ResourceProvider::CountPromotionHintRequestsForTesting() {
1093 return wants_promotion_hints_set_.size();
1094 }
1095 #endif
1096
1054 void ResourceProvider::UnlockForWrite(Resource* resource) { 1097 void ResourceProvider::UnlockForWrite(Resource* resource) {
1055 DCHECK(resource->locked_for_write); 1098 DCHECK(resource->locked_for_write);
1056 DCHECK_EQ(resource->exported_count, 0); 1099 DCHECK_EQ(resource->exported_count, 0);
1057 DCHECK(resource->origin == Resource::INTERNAL); 1100 DCHECK(resource->origin == Resource::INTERNAL);
1058 resource->locked_for_write = false; 1101 resource->locked_for_write = false;
1059 } 1102 }
1060 1103
1061 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) { 1104 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) {
1062 Resource* resource = GetResource(id); 1105 Resource* resource = GetResource(id);
1063 DCHECK(resource); 1106 DCHECK(resource);
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 resource = InsertResource( 1574 resource = InsertResource(
1532 local_id, Resource(0, it->size, Resource::DELEGATED, 1575 local_id, Resource(0, it->size, Resource::DELEGATED,
1533 it->mailbox_holder.texture_target, it->filter, 1576 it->mailbox_holder.texture_target, it->filter,
1534 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, 1577 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE,
1535 it->format)); 1578 it->format));
1536 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox, 1579 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox,
1537 it->mailbox_holder.sync_token, 1580 it->mailbox_holder.sync_token,
1538 it->mailbox_holder.texture_target)); 1581 it->mailbox_holder.texture_target));
1539 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; 1582 resource->read_lock_fences_enabled = it->read_lock_fences_enabled;
1540 resource->is_overlay_candidate = it->is_overlay_candidate; 1583 resource->is_overlay_candidate = it->is_overlay_candidate;
1584 #if defined(OS_ANDROID)
1585 resource->is_backed_by_surface_texture = it->is_backed_by_surface_texture;
1586 resource->wants_promotion_hint = it->wants_promotion_hint;
1587 if (resource->wants_promotion_hint)
1588 wants_promotion_hints_set_.insert(local_id);
1589 #endif
1541 resource->color_space = it->color_space; 1590 resource->color_space = it->color_space;
1542 } 1591 }
1543 resource->child_id = child; 1592 resource->child_id = child;
1544 // Don't allocate a texture for a child. 1593 // Don't allocate a texture for a child.
1545 resource->allocated = true; 1594 resource->allocated = true;
1546 resource->imported_count = 1; 1595 resource->imported_count = 1;
1547 child_info.parent_to_child_map[local_id] = it->id; 1596 child_info.parent_to_child_map[local_id] = it->id;
1548 child_info.child_to_parent_map[it->id] = local_id; 1597 child_info.child_to_parent_map[it->id] = local_id;
1549 } 1598 }
1550 } 1599 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 resources_for_child[resource->child_id].push_back(local_id); 1668 resources_for_child[resource->child_id].push_back(local_id);
1620 } 1669 }
1621 1670
1622 for (const auto& children : resources_for_child) { 1671 for (const auto& children : resources_for_child) {
1623 ChildMap::iterator child_it = children_.find(children.first); 1672 ChildMap::iterator child_it = children_.find(children.first);
1624 DCHECK(child_it != children_.end()); 1673 DCHECK(child_it != children_.end());
1625 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); 1674 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second);
1626 } 1675 }
1627 } 1676 }
1628 1677
1678 #if defined(OS_ANDROID)
1679 void ResourceProvider::SendPromotionHints(
1680 const ResourceIdSet& promotable_hints) {
1681 for (const auto& it : wants_promotion_hints_set_) {
piman 2016/12/05 20:19:06 nit: "id" or "resource_id" instead of "it"? This i
liberato (no reviews please) 2016/12/05 21:50:47 Done.
1682 const Resource* resource = LockForRead(it);
1683 DCHECK(resource->wants_promotion_hint);
1684
1685 // Insist that this is backed by a GPU texture.
1686 if (IsGpuResourceType(resource->type)) {
1687 DCHECK(resource->gl_id);
1688 // Here we would either construct a set to send all at once, or send the
1689 // promotion hint individually to resource->gl_id, based on whether
1690 // promtable_hints.count(it->first) > 0 .
piman 2016/12/05 20:19:06 nit: add a TODO(liberato), maybe link to a bug?
liberato (no reviews please) 2016/12/05 21:50:47 Done.
1691 }
1692 UnlockForRead(it);
1693 }
1694 }
1695 #endif
1696
1629 void ResourceProvider::CreateMailboxAndBindResource( 1697 void ResourceProvider::CreateMailboxAndBindResource(
1630 gpu::gles2::GLES2Interface* gl, 1698 gpu::gles2::GLES2Interface* gl,
1631 Resource* resource) { 1699 Resource* resource) {
1632 DCHECK(IsGpuResourceType(resource->type)); 1700 DCHECK(IsGpuResourceType(resource->type));
1633 DCHECK(gl); 1701 DCHECK(gl);
1634 1702
1635 if (!resource->mailbox().IsValid()) { 1703 if (!resource->mailbox().IsValid()) {
1636 LazyCreate(resource); 1704 LazyCreate(resource);
1637 1705
1638 gpu::MailboxHolder mailbox_holder; 1706 gpu::MailboxHolder mailbox_holder;
(...skipping 19 matching lines...) Expand all
1658 DCHECK(!source->lock_for_read_count); 1726 DCHECK(!source->lock_for_read_count);
1659 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); 1727 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid());
1660 DCHECK(source->allocated); 1728 DCHECK(source->allocated);
1661 resource->id = id; 1729 resource->id = id;
1662 resource->format = source->format; 1730 resource->format = source->format;
1663 resource->mailbox_holder.texture_target = source->target; 1731 resource->mailbox_holder.texture_target = source->target;
1664 resource->filter = source->filter; 1732 resource->filter = source->filter;
1665 resource->size = source->size; 1733 resource->size = source->size;
1666 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; 1734 resource->read_lock_fences_enabled = source->read_lock_fences_enabled;
1667 resource->is_overlay_candidate = source->is_overlay_candidate; 1735 resource->is_overlay_candidate = source->is_overlay_candidate;
1736 #if defined(OS_ANDROID)
1737 resource->is_backed_by_surface_texture = source->is_backed_by_surface_texture;
1738 resource->wants_promotion_hint = source->wants_promotion_hint;
1739 #endif
1668 resource->color_space = source->color_space; 1740 resource->color_space = source->color_space;
1669 1741
1670 if (source->type == RESOURCE_TYPE_BITMAP) { 1742 if (source->type == RESOURCE_TYPE_BITMAP) {
1671 resource->mailbox_holder.mailbox = source->shared_bitmap_id; 1743 resource->mailbox_holder.mailbox = source->shared_bitmap_id;
1672 resource->is_software = true; 1744 resource->is_software = true;
1673 } else { 1745 } else {
1674 DCHECK(source->mailbox().IsValid()); 1746 DCHECK(source->mailbox().IsValid());
1675 DCHECK(source->mailbox().IsTexture()); 1747 DCHECK(source->mailbox().IsTexture());
1676 DCHECK(!source->image_id || !source->dirty_image); 1748 DCHECK(!source->image_id || !source->dirty_image);
1677 // This is either an external resource, or a compositor resource that we 1749 // This is either an external resource, or a compositor resource that we
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 2136
2065 const int kImportance = 2; 2137 const int kImportance = 2;
2066 pmd->CreateSharedGlobalAllocatorDump(guid); 2138 pmd->CreateSharedGlobalAllocatorDump(guid);
2067 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 2139 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2068 } 2140 }
2069 2141
2070 return true; 2142 return true;
2071 } 2143 }
2072 2144
2073 } // namespace cc 2145 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698