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

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

Issue 2508203004: Add hints for potential overlay promotion on android. (Closed)
Patch Set: #include and comment cleanup Created 4 years, 1 month 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 #endif
239 read_lock_fence(nullptr), 242 read_lock_fence(nullptr),
240 size(size), 243 size(size),
241 origin(origin), 244 origin(origin),
242 target(target), 245 target(target),
243 original_filter(filter), 246 original_filter(filter),
244 filter(filter), 247 filter(filter),
245 image_id(0), 248 image_id(0),
246 bound_image_id(0), 249 bound_image_id(0),
247 hint(hint), 250 hint(hint),
248 type(type), 251 type(type),
249 usage(gfx::BufferUsage::GPU_READ_CPU_READ_WRITE), 252 usage(gfx::BufferUsage::GPU_READ_CPU_READ_WRITE),
250 format(format), 253 format(format),
251 shared_bitmap(nullptr) {} 254 shared_bitmap(nullptr) {
255 }
252 256
253 ResourceProvider::Resource::Resource(uint8_t* pixels, 257 ResourceProvider::Resource::Resource(uint8_t* pixels,
254 SharedBitmap* bitmap, 258 SharedBitmap* bitmap,
255 const gfx::Size& size, 259 const gfx::Size& size,
256 Origin origin, 260 Origin origin,
257 GLenum filter) 261 GLenum filter)
258 : child_id(0), 262 : child_id(0),
259 gl_id(0), 263 gl_id(0),
260 gl_pixel_buffer_id(0), 264 gl_pixel_buffer_id(0),
261 gl_upload_query_id(0), 265 gl_upload_query_id(0),
262 gl_read_lock_query_id(0), 266 gl_read_lock_query_id(0),
263 pixels(pixels), 267 pixels(pixels),
264 lock_for_read_count(0), 268 lock_for_read_count(0),
265 imported_count(0), 269 imported_count(0),
266 exported_count(0), 270 exported_count(0),
267 dirty_image(false), 271 dirty_image(false),
268 locked_for_write(false), 272 locked_for_write(false),
269 lost(false), 273 lost(false),
270 marked_for_deletion(false), 274 marked_for_deletion(false),
271 allocated(false), 275 allocated(false),
272 read_lock_fences_enabled(false), 276 read_lock_fences_enabled(false),
273 has_shared_bitmap_id(!!bitmap), 277 has_shared_bitmap_id(!!bitmap),
274 is_overlay_candidate(false), 278 is_overlay_candidate(false),
279 #if defined(OS_ANDROID)
280 is_backed_by_surface_texture(false),
281 #endif
275 read_lock_fence(nullptr), 282 read_lock_fence(nullptr),
276 size(size), 283 size(size),
277 origin(origin), 284 origin(origin),
278 target(0), 285 target(0),
279 original_filter(filter), 286 original_filter(filter),
280 filter(filter), 287 filter(filter),
281 image_id(0), 288 image_id(0),
282 bound_image_id(0), 289 bound_image_id(0),
283 hint(TEXTURE_HINT_IMMUTABLE), 290 hint(TEXTURE_HINT_IMMUTABLE),
284 type(RESOURCE_TYPE_BITMAP), 291 type(RESOURCE_TYPE_BITMAP),
(...skipping 18 matching lines...) Expand all
303 imported_count(0), 310 imported_count(0),
304 exported_count(0), 311 exported_count(0),
305 dirty_image(false), 312 dirty_image(false),
306 locked_for_write(false), 313 locked_for_write(false),
307 lost(false), 314 lost(false),
308 marked_for_deletion(false), 315 marked_for_deletion(false),
309 allocated(false), 316 allocated(false),
310 read_lock_fences_enabled(false), 317 read_lock_fences_enabled(false),
311 has_shared_bitmap_id(true), 318 has_shared_bitmap_id(true),
312 is_overlay_candidate(false), 319 is_overlay_candidate(false),
320 #if defined(OS_ANDROID)
321 is_backed_by_surface_texture(false),
322 #endif
313 read_lock_fence(nullptr), 323 read_lock_fence(nullptr),
314 size(size), 324 size(size),
315 origin(origin), 325 origin(origin),
316 target(0), 326 target(0),
317 original_filter(filter), 327 original_filter(filter),
318 filter(filter), 328 filter(filter),
319 image_id(0), 329 image_id(0),
320 bound_image_id(0), 330 bound_image_id(0),
321 hint(TEXTURE_HINT_IMMUTABLE), 331 hint(TEXTURE_HINT_IMMUTABLE),
322 type(RESOURCE_TYPE_BITMAP), 332 type(RESOURCE_TYPE_BITMAP),
323 format(RGBA_8888), 333 format(RGBA_8888),
324 shared_bitmap_id(bitmap_id), 334 shared_bitmap_id(bitmap_id),
325 shared_bitmap(nullptr) {} 335 shared_bitmap(nullptr) {
336 }
326 337
327 ResourceProvider::Resource::Resource(Resource&& other) = default; 338 ResourceProvider::Resource::Resource(Resource&& other) = default;
328 339
329 void ResourceProvider::Resource::set_mailbox(const TextureMailbox& mailbox) { 340 void ResourceProvider::Resource::set_mailbox(const TextureMailbox& mailbox) {
330 mailbox_ = mailbox; 341 mailbox_ = mailbox;
331 if (IsGpuResourceType(type)) { 342 if (IsGpuResourceType(type)) {
332 synchronization_state_ = 343 synchronization_state_ =
333 (mailbox.sync_token().HasData() ? NEEDS_WAIT : LOCALLY_USED); 344 (mailbox.sync_token().HasData() ? NEEDS_WAIT : LOCALLY_USED);
334 needs_sync_token_ = !mailbox.sync_token().HasData(); 345 needs_sync_token_ = !mailbox.sync_token().HasData();
335 } else { 346 } else {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 Resource::EXTERNAL, GL_LINEAR)); 691 Resource::EXTERNAL, GL_LINEAR));
681 } 692 }
682 resource->allocated = true; 693 resource->allocated = true;
683 resource->set_mailbox(mailbox); 694 resource->set_mailbox(mailbox);
684 resource->color_space = mailbox.color_space(); 695 resource->color_space = mailbox.color_space();
685 resource->release_callback_impl = 696 resource->release_callback_impl =
686 base::Bind(&SingleReleaseCallbackImpl::Run, 697 base::Bind(&SingleReleaseCallbackImpl::Run,
687 base::Owned(release_callback_impl.release())); 698 base::Owned(release_callback_impl.release()));
688 resource->read_lock_fences_enabled = read_lock_fences_enabled; 699 resource->read_lock_fences_enabled = read_lock_fences_enabled;
689 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); 700 resource->is_overlay_candidate = mailbox.is_overlay_candidate();
701 #if defined(OS_ANDROID)
702 resource->is_backed_by_surface_texture =
703 mailbox.is_backed_by_surface_texture();
704 #endif
690 resource->color_space = mailbox.color_space(); 705 resource->color_space = mailbox.color_space();
691 706
692 return id; 707 return id;
693 } 708 }
694 709
695 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 710 ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
696 const TextureMailbox& mailbox, 711 const TextureMailbox& mailbox,
697 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { 712 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) {
698 return CreateResourceFromTextureMailbox( 713 return CreateResourceFromTextureMailbox(
699 mailbox, std::move(release_callback_impl), false); 714 mailbox, std::move(release_callback_impl), false);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 return !resource->locked_for_write && !resource->lock_for_read_count && 1056 return !resource->locked_for_write && !resource->lock_for_read_count &&
1042 !resource->exported_count && resource->origin == Resource::INTERNAL && 1057 !resource->exported_count && resource->origin == Resource::INTERNAL &&
1043 !resource->lost && ReadLockFenceHasPassed(resource); 1058 !resource->lost && ReadLockFenceHasPassed(resource);
1044 } 1059 }
1045 1060
1046 bool ResourceProvider::IsOverlayCandidate(ResourceId id) { 1061 bool ResourceProvider::IsOverlayCandidate(ResourceId id) {
1047 Resource* resource = GetResource(id); 1062 Resource* resource = GetResource(id);
1048 return resource->is_overlay_candidate; 1063 return resource->is_overlay_candidate;
1049 } 1064 }
1050 1065
1066 #if defined(OS_ANDROID)
1067 bool ResourceProvider::IsBackedBySurfaceTexture(ResourceId id) {
1068 Resource* resource = GetResource(id);
1069 return resource->is_backed_by_surface_texture;
1070 }
1071 #endif
1072
1051 void ResourceProvider::UnlockForWrite(Resource* resource) { 1073 void ResourceProvider::UnlockForWrite(Resource* resource) {
1052 DCHECK(resource->locked_for_write); 1074 DCHECK(resource->locked_for_write);
1053 DCHECK_EQ(resource->exported_count, 0); 1075 DCHECK_EQ(resource->exported_count, 0);
1054 DCHECK(resource->origin == Resource::INTERNAL); 1076 DCHECK(resource->origin == Resource::INTERNAL);
1055 resource->locked_for_write = false; 1077 resource->locked_for_write = false;
1056 } 1078 }
1057 1079
1058 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) { 1080 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) {
1059 Resource* resource = GetResource(id); 1081 Resource* resource = GetResource(id);
1060 DCHECK(resource); 1082 DCHECK(resource);
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 resource = InsertResource( 1547 resource = InsertResource(
1526 local_id, Resource(0, it->size, Resource::DELEGATED, 1548 local_id, Resource(0, it->size, Resource::DELEGATED,
1527 it->mailbox_holder.texture_target, it->filter, 1549 it->mailbox_holder.texture_target, it->filter,
1528 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, 1550 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE,
1529 it->format)); 1551 it->format));
1530 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox, 1552 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox,
1531 it->mailbox_holder.sync_token, 1553 it->mailbox_holder.sync_token,
1532 it->mailbox_holder.texture_target)); 1554 it->mailbox_holder.texture_target));
1533 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; 1555 resource->read_lock_fences_enabled = it->read_lock_fences_enabled;
1534 resource->is_overlay_candidate = it->is_overlay_candidate; 1556 resource->is_overlay_candidate = it->is_overlay_candidate;
1557 #if defined(OS_ANDROID)
1558 resource->is_backed_by_surface_texture = it->is_backed_by_surface_texture;
piman 2016/11/23 00:37:25 note, however we will use this, we can't trust tha
liberato (no reviews please) 2016/12/01 20:59:11 currently, the renderer can always mark the mailbo
1559 #endif
1535 resource->color_space = it->color_space; 1560 resource->color_space = it->color_space;
1536 } 1561 }
1537 resource->child_id = child; 1562 resource->child_id = child;
1538 // Don't allocate a texture for a child. 1563 // Don't allocate a texture for a child.
1539 resource->allocated = true; 1564 resource->allocated = true;
1540 resource->imported_count = 1; 1565 resource->imported_count = 1;
1541 child_info.parent_to_child_map[local_id] = it->id; 1566 child_info.parent_to_child_map[local_id] = it->id;
1542 child_info.child_to_parent_map[it->id] = local_id; 1567 child_info.child_to_parent_map[it->id] = local_id;
1543 } 1568 }
1544 } 1569 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 DCHECK(!source->lock_for_read_count); 1677 DCHECK(!source->lock_for_read_count);
1653 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); 1678 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid());
1654 DCHECK(source->allocated); 1679 DCHECK(source->allocated);
1655 resource->id = id; 1680 resource->id = id;
1656 resource->format = source->format; 1681 resource->format = source->format;
1657 resource->mailbox_holder.texture_target = source->target; 1682 resource->mailbox_holder.texture_target = source->target;
1658 resource->filter = source->filter; 1683 resource->filter = source->filter;
1659 resource->size = source->size; 1684 resource->size = source->size;
1660 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; 1685 resource->read_lock_fences_enabled = source->read_lock_fences_enabled;
1661 resource->is_overlay_candidate = source->is_overlay_candidate; 1686 resource->is_overlay_candidate = source->is_overlay_candidate;
1687 #if defined(OS_ANDROID)
1688 resource->is_backed_by_surface_texture = source->is_backed_by_surface_texture;
1689 #endif
1662 resource->color_space = source->color_space; 1690 resource->color_space = source->color_space;
1663 1691
1664 if (source->type == RESOURCE_TYPE_BITMAP) { 1692 if (source->type == RESOURCE_TYPE_BITMAP) {
1665 resource->mailbox_holder.mailbox = source->shared_bitmap_id; 1693 resource->mailbox_holder.mailbox = source->shared_bitmap_id;
1666 resource->is_software = true; 1694 resource->is_software = true;
1667 } else { 1695 } else {
1668 DCHECK(source->mailbox().IsValid()); 1696 DCHECK(source->mailbox().IsValid());
1669 DCHECK(source->mailbox().IsTexture()); 1697 DCHECK(source->mailbox().IsTexture());
1670 DCHECK(!source->image_id || !source->dirty_image); 1698 DCHECK(!source->image_id || !source->dirty_image);
1671 // This is either an external resource, or a compositor resource that we 1699 // This is either an external resource, or a compositor resource that we
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 2086
2059 const int kImportance = 2; 2087 const int kImportance = 2;
2060 pmd->CreateSharedGlobalAllocatorDump(guid); 2088 pmd->CreateSharedGlobalAllocatorDump(guid);
2061 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 2089 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2062 } 2090 }
2063 2091
2064 return true; 2092 return true;
2065 } 2093 }
2066 2094
2067 } // namespace cc 2095 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698