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

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

Issue 1666203003: Separate out resource mailbox creation and fix synchronization issue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months 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 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 ChildMap::const_iterator it = children_.find(child); 1143 ChildMap::const_iterator it = children_.find(child);
1144 DCHECK(it != children_.end()); 1144 DCHECK(it != children_.end());
1145 DCHECK(!it->second.marked_for_deletion); 1145 DCHECK(!it->second.marked_for_deletion);
1146 return it->second.child_to_parent_map; 1146 return it->second.child_to_parent_map;
1147 } 1147 }
1148 1148
1149 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, 1149 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources,
1150 TransferableResourceArray* list) { 1150 TransferableResourceArray* list) {
1151 DCHECK(thread_checker_.CalledOnValidThread()); 1151 DCHECK(thread_checker_.CalledOnValidThread());
1152 GLES2Interface* gl = ContextGL(); 1152 GLES2Interface* gl = ContextGL();
1153 bool need_sync_token = false;
1154 1153
1155 gpu::SyncToken new_sync_token; 1154 // Lazily create any mailboxes and verify all unverified sync tokens.
1156 std::vector<size_t> unverified_token_indexes; 1155 std::vector<GLbyte*> unverified_sync_tokens;
1156 std::vector<ResourceIdArray::const_iterator> need_synchronization_indexes;
1157 for (ResourceIdArray::const_iterator it = resources.begin(); 1157 for (ResourceIdArray::const_iterator it = resources.begin();
1158 it != resources.end(); 1158 it != resources.end();
1159 ++it) { 1159 ++it) {
1160 TransferableResource resource; 1160 Resource* resource = GetResource(*it);
1161 TransferResource(gl, *it, &resource); 1161 bool need_synchronization = CreateMailboxAndBindResource(gl, resource);
1162 need_sync_token |= (!resource.mailbox_holder.sync_token.HasData() &&
1163 !resource.is_software);
1164 1162
1165 if (resource.mailbox_holder.sync_token.HasData() && 1163 // TODO(dyen): Temporarily add missing sync tokens, eventually this should
1166 !resource.mailbox_holder.sync_token.verified_flush()) { 1164 // be removed as we guarantee all resources have associated sync tokens.
1167 unverified_token_indexes.push_back(list->size()); 1165 need_synchronization |= (resource->type != RESOURCE_TYPE_BITMAP &&
1166 !resource->mailbox.HasSyncToken());
1167
1168 if (output_surface_->capabilities().delegated_sync_points_required &&
1169 need_synchronization) {
1170 need_synchronization_indexes.push_back(it);
David Yen 2016/02/04 19:09:27 From piman@: We don't need to create sync tokens i
David Yen 2016/02/04 19:13:29 Done. Added delegated_sync_points_required check.
1171 } else if (resource->mailbox.HasSyncToken() &&
1172 !resource->mailbox.sync_token().verified_flush()) {
1173 unverified_sync_tokens.push_back(resource->mailbox.GetSyncTokenData());
1168 } 1174 }
1169
1170 ++resources_.find(*it)->second.exported_count;
1171 list->push_back(resource);
1172 } 1175 }
1173 1176
1174 // Fill out unverified sync tokens array. 1177 // Insert sync point to synchronize the mailbox creation or bound textures.
1175 std::vector<GLbyte*> unverified_sync_tokens; 1178 gpu::SyncToken new_sync_token;
1176 unverified_sync_tokens.reserve(unverified_token_indexes.size() + 1); 1179 if (!need_synchronization_indexes.empty()) {
1177 for (auto it = unverified_token_indexes.begin();
1178 it != unverified_token_indexes.end(); ++it) {
1179 unverified_sync_tokens.push_back(
1180 list->at(*it).mailbox_holder.sync_token.GetData());
1181 }
1182
1183 if (need_sync_token &&
1184 output_surface_->capabilities().delegated_sync_points_required) {
1185 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 1180 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
1186 gl->OrderingBarrierCHROMIUM(); 1181 gl->OrderingBarrierCHROMIUM();
1187 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); 1182 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
1188 unverified_sync_tokens.push_back(new_sync_token.GetData()); 1183 unverified_sync_tokens.push_back(new_sync_token.GetData());
1189 } 1184 }
1190 1185
1191 if (!unverified_sync_tokens.empty()) { 1186 if (!unverified_sync_tokens.empty()) {
1192 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), 1187 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
1193 unverified_sync_tokens.size()); 1188 unverified_sync_tokens.size());
1194 } 1189 }
1195 1190
1196 if (new_sync_token.HasData()) { 1191 for (ResourceIdArray::const_iterator it : need_synchronization_indexes) {
1197 for (TransferableResourceArray::iterator it = list->begin(); 1192 GetResource(*it)->mailbox.set_sync_token(new_sync_token);
1198 it != list->end(); 1193 }
1199 ++it) { 1194
1200 if (!it->mailbox_holder.sync_token.HasData()) 1195 // Transfer Resources
1201 it->mailbox_holder.sync_token = new_sync_token; 1196 for (ResourceIdArray::const_iterator it = resources.begin();
1202 } 1197 it != resources.end(); ++it) {
1198 TransferableResource resource;
1199 TransferResource(gl, *it, &resource);
1200
1201 DCHECK(!output_surface_->capabilities().delegated_sync_points_required ||
1202 resource.mailbox_holder.sync_token.HasData() ||
1203 resource.is_software);
1204
1205 ++resources_.find(*it)->second.exported_count;
1206 list->push_back(resource);
1203 } 1207 }
1204 } 1208 }
1205 1209
1206 void ResourceProvider::ReceiveFromChild( 1210 void ResourceProvider::ReceiveFromChild(
1207 int child, const TransferableResourceArray& resources) { 1211 int child, const TransferableResourceArray& resources) {
1208 DCHECK(thread_checker_.CalledOnValidThread()); 1212 DCHECK(thread_checker_.CalledOnValidThread());
1209 GLES2Interface* gl = ContextGL(); 1213 GLES2Interface* gl = ContextGL();
1210 Child& child_info = children_.find(child)->second; 1214 Child& child_info = children_.find(child)->second;
1211 DCHECK(!child_info.marked_for_deletion); 1215 DCHECK(!child_info.marked_for_deletion);
1212 for (TransferableResourceArray::const_iterator it = resources.begin(); 1216 for (TransferableResourceArray::const_iterator it = resources.begin();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 resources_for_child[resource->child_id].push_back(local_id); 1331 resources_for_child[resource->child_id].push_back(local_id);
1328 } 1332 }
1329 1333
1330 for (const auto& children : resources_for_child) { 1334 for (const auto& children : resources_for_child) {
1331 ChildMap::iterator child_it = children_.find(children.first); 1335 ChildMap::iterator child_it = children_.find(children.first);
1332 DCHECK(child_it != children_.end()); 1336 DCHECK(child_it != children_.end());
1333 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); 1337 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second);
1334 } 1338 }
1335 } 1339 }
1336 1340
1341 bool ResourceProvider::CreateMailboxAndBindResource(
1342 gpu::gles2::GLES2Interface* gl, Resource* resource) {
1343 if (resource->type != RESOURCE_TYPE_BITMAP) {
1344 bool did_create_or_bind = false;
1345 if (!resource->mailbox.IsValid()) {
1346 LazyCreate(resource);
1347
1348 gpu::MailboxHolder mailbox_holder;
1349 mailbox_holder.texture_target = resource->target;
1350 gl->GenMailboxCHROMIUM(mailbox_holder.mailbox.name);
1351 gl->ProduceTextureDirectCHROMIUM(resource->gl_id,
1352 mailbox_holder.texture_target,
1353 mailbox_holder.mailbox.name);
1354 resource->mailbox = TextureMailbox(mailbox_holder);
1355 did_create_or_bind = true;
1356 }
1357
1358 if (resource->image_id && resource->dirty_image) {
1359 DCHECK(resource->gl_id);
1360 DCHECK(resource->origin == Resource::INTERNAL);
1361 BindImageForSampling(resource);
1362 did_create_or_bind = true;
1363 }
1364
1365 return did_create_or_bind;
1366 }
1367 return false;
1368 }
1369
1337 void ResourceProvider::TransferResource(GLES2Interface* gl, 1370 void ResourceProvider::TransferResource(GLES2Interface* gl,
1338 ResourceId id, 1371 ResourceId id,
1339 TransferableResource* resource) { 1372 TransferableResource* resource) {
1340 Resource* source = GetResource(id); 1373 Resource* source = GetResource(id);
1341 DCHECK(!source->locked_for_write); 1374 DCHECK(!source->locked_for_write);
1342 DCHECK(!source->lock_for_read_count); 1375 DCHECK(!source->lock_for_read_count);
1343 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); 1376 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid());
1344 DCHECK(source->allocated); 1377 DCHECK(source->allocated);
1345 resource->id = id; 1378 resource->id = id;
1346 resource->format = source->format; 1379 resource->format = source->format;
1347 resource->mailbox_holder.texture_target = source->target; 1380 resource->mailbox_holder.texture_target = source->target;
1348 resource->filter = source->filter; 1381 resource->filter = source->filter;
1349 resource->size = source->size; 1382 resource->size = source->size;
1350 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; 1383 resource->read_lock_fences_enabled = source->read_lock_fences_enabled;
1351 resource->is_overlay_candidate = source->is_overlay_candidate; 1384 resource->is_overlay_candidate = source->is_overlay_candidate;
1352 1385
1353 if (source->type == RESOURCE_TYPE_BITMAP) { 1386 if (source->type == RESOURCE_TYPE_BITMAP) {
1354 resource->mailbox_holder.mailbox = source->shared_bitmap_id; 1387 resource->mailbox_holder.mailbox = source->shared_bitmap_id;
1355 resource->is_software = true; 1388 resource->is_software = true;
1356 } else if (!source->mailbox.IsValid()) {
1357 LazyCreate(source);
1358 DCHECK(source->gl_id);
1359 DCHECK(source->origin == Resource::INTERNAL);
1360 if (source->image_id && source->dirty_image)
1361 BindImageForSampling(source);
1362 // This is a resource allocated by the compositor, we need to produce it.
1363 // Don't set a sync point, the caller will do it.
1364 gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name);
1365 gl->ProduceTextureDirectCHROMIUM(source->gl_id,
1366 resource->mailbox_holder.texture_target,
1367 resource->mailbox_holder.mailbox.name);
1368
1369 source->mailbox = TextureMailbox(resource->mailbox_holder);
1370 } else { 1389 } else {
1390 DCHECK(source->mailbox.IsValid());
1371 DCHECK(source->mailbox.IsTexture()); 1391 DCHECK(source->mailbox.IsTexture());
1372 if (source->image_id && source->dirty_image) {
1373 DCHECK(source->gl_id);
1374 DCHECK(source->origin == Resource::INTERNAL);
1375 BindImageForSampling(source);
1376 }
1377 // This is either an external resource, or a compositor resource that we 1392 // This is either an external resource, or a compositor resource that we
1378 // already exported. Make sure to forward the sync point that we were given. 1393 // already exported. Make sure to forward the sync point that we were given.
1379 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); 1394 resource->mailbox_holder.mailbox = source->mailbox.mailbox();
1380 resource->mailbox_holder.texture_target = source->mailbox.target(); 1395 resource->mailbox_holder.texture_target = source->mailbox.target();
1381 resource->mailbox_holder.sync_token = source->mailbox.sync_token(); 1396 resource->mailbox_holder.sync_token = source->mailbox.sync_token();
1382 source->mailbox.set_sync_token(gpu::SyncToken());
1383 } 1397 }
1384 } 1398 }
1385 1399
1386 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( 1400 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild(
1387 ChildMap::iterator child_it, 1401 ChildMap::iterator child_it,
1388 DeleteStyle style, 1402 DeleteStyle style,
1389 const ResourceIdArray& unused) { 1403 const ResourceIdArray& unused) {
1390 DCHECK(thread_checker_.CalledOnValidThread()); 1404 DCHECK(thread_checker_.CalledOnValidThread());
1391 DCHECK(child_it != children_.end()); 1405 DCHECK(child_it != children_.end());
1392 Child* child_info = &child_it->second; 1406 Child* child_info = &child_it->second;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 1751
1738 const int kImportance = 2; 1752 const int kImportance = 2;
1739 pmd->CreateSharedGlobalAllocatorDump(guid); 1753 pmd->CreateSharedGlobalAllocatorDump(guid);
1740 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 1754 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
1741 } 1755 }
1742 1756
1743 return true; 1757 return true;
1744 } 1758 }
1745 1759
1746 } // namespace cc 1760 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698