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

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

Issue 1674313002: Reland of Separate out resource mailbox creation and fix synchronization issue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Applied fixes 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
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
1157 for (ResourceIdArray::const_iterator it = resources.begin(); 1156 std::vector<Resource*> need_synchronization_resources;
1158 it != resources.end(); 1157 for (const ResourceId id : resources) {
1159 ++it) { 1158 Resource* resource = GetResource(id);
1160 TransferableResource resource; 1159 bool need_synchronization = CreateMailboxAndBindResource(gl, resource);
1161 TransferResource(gl, *it, &resource);
1162 need_sync_token |= (!resource.mailbox_holder.sync_token.HasData() &&
1163 !resource.is_software);
1164 1160
1165 if (resource.mailbox_holder.sync_token.HasData() && 1161 // TODO(dyen): Temporarily add missing sync tokens, eventually this should
1166 !resource.mailbox_holder.sync_token.verified_flush()) { 1162 // be removed as we guarantee all resources have associated sync tokens.
1167 unverified_token_indexes.push_back(list->size()); 1163 need_synchronization |= (resource->type != RESOURCE_TYPE_BITMAP &&
1164 !resource->mailbox.HasSyncToken());
1165
1166 if (output_surface_->capabilities().delegated_sync_points_required &&
1167 need_synchronization) {
1168 need_synchronization_resources.push_back(resource);
1169 } else if (resource->mailbox.HasSyncToken() &&
1170 !resource->mailbox.sync_token().verified_flush()) {
1171 unverified_sync_tokens.push_back(resource->mailbox.GetSyncTokenData());
1168 } 1172 }
1169
1170 ++resources_.find(*it)->second.exported_count;
1171 list->push_back(resource);
1172 } 1173 }
1173 1174
1174 // Fill out unverified sync tokens array. 1175 // Insert sync point to synchronize the mailbox creation or bound textures.
1175 std::vector<GLbyte*> unverified_sync_tokens; 1176 gpu::SyncToken new_sync_token;
1176 unverified_sync_tokens.reserve(unverified_token_indexes.size() + 1); 1177 if (!need_synchronization_resources.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(); 1178 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
1186 gl->OrderingBarrierCHROMIUM(); 1179 gl->OrderingBarrierCHROMIUM();
1187 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); 1180 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
1188 unverified_sync_tokens.push_back(new_sync_token.GetData()); 1181 unverified_sync_tokens.push_back(new_sync_token.GetData());
1189 } 1182 }
1190 1183
1191 if (!unverified_sync_tokens.empty()) { 1184 if (!unverified_sync_tokens.empty()) {
1192 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), 1185 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
1193 unverified_sync_tokens.size()); 1186 unverified_sync_tokens.size());
1194 } 1187 }
1195 1188
1196 if (new_sync_token.HasData()) { 1189 for (Resource* resource : need_synchronization_resources) {
1197 for (TransferableResourceArray::iterator it = list->begin(); 1190 resource->mailbox.set_sync_token(new_sync_token);
1198 it != list->end(); 1191 }
1199 ++it) { 1192
1200 if (!it->mailbox_holder.sync_token.HasData()) 1193 // Transfer Resources
1201 it->mailbox_holder.sync_token = new_sync_token; 1194 for (const ResourceId id : resources) {
1202 } 1195 TransferableResource resource;
1196 TransferResource(gl, id, &resource);
1197
1198 DCHECK(!output_surface_->capabilities().delegated_sync_points_required ||
1199 resource.mailbox_holder.sync_token.HasData() ||
1200 resource.is_software);
1201
1202 ++resources_.find(id)->second.exported_count;
1203 list->push_back(resource);
1204 }
1205
1206 // TODO(dyen): This is necessary because we do not guarantee all resource
1207 // updates will insert sync tokens currently. Otherwise there is no way to
1208 // know if a sync token is out of date or not. This can also be removed once
1209 // proper resource state tracking is completed. Note that this used to be done
1210 // in the TransferResource step, but will now fail if a resource is used in
1211 // the same resource list twice.
1212 for (const ResourceId id : resources) {
1213 Resource* resource = GetResource(id);
1214 resource->mailbox.set_sync_token(gpu::SyncToken());
1203 } 1215 }
1204 } 1216 }
1205 1217
1206 void ResourceProvider::ReceiveFromChild( 1218 void ResourceProvider::ReceiveFromChild(
1207 int child, const TransferableResourceArray& resources) { 1219 int child, const TransferableResourceArray& resources) {
1208 DCHECK(thread_checker_.CalledOnValidThread()); 1220 DCHECK(thread_checker_.CalledOnValidThread());
1209 GLES2Interface* gl = ContextGL(); 1221 GLES2Interface* gl = ContextGL();
1210 Child& child_info = children_.find(child)->second; 1222 Child& child_info = children_.find(child)->second;
1211 DCHECK(!child_info.marked_for_deletion); 1223 DCHECK(!child_info.marked_for_deletion);
1212 for (TransferableResourceArray::const_iterator it = resources.begin(); 1224 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); 1339 resources_for_child[resource->child_id].push_back(local_id);
1328 } 1340 }
1329 1341
1330 for (const auto& children : resources_for_child) { 1342 for (const auto& children : resources_for_child) {
1331 ChildMap::iterator child_it = children_.find(children.first); 1343 ChildMap::iterator child_it = children_.find(children.first);
1332 DCHECK(child_it != children_.end()); 1344 DCHECK(child_it != children_.end());
1333 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); 1345 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second);
1334 } 1346 }
1335 } 1347 }
1336 1348
1349 bool ResourceProvider::CreateMailboxAndBindResource(
1350 gpu::gles2::GLES2Interface* gl,
1351 Resource* resource) {
1352 if (resource->type != RESOURCE_TYPE_BITMAP) {
1353 bool did_create_or_bind = false;
1354 if (!resource->mailbox.IsValid()) {
1355 LazyCreate(resource);
1356
1357 gpu::MailboxHolder mailbox_holder;
1358 mailbox_holder.texture_target = resource->target;
1359 gl->GenMailboxCHROMIUM(mailbox_holder.mailbox.name);
1360 gl->ProduceTextureDirectCHROMIUM(resource->gl_id,
1361 mailbox_holder.texture_target,
1362 mailbox_holder.mailbox.name);
1363 resource->mailbox = TextureMailbox(mailbox_holder);
1364 did_create_or_bind = true;
1365 }
1366
1367 if (resource->image_id && resource->dirty_image) {
1368 DCHECK(resource->gl_id);
1369 DCHECK(resource->origin == Resource::INTERNAL);
1370 BindImageForSampling(resource);
1371 did_create_or_bind = true;
1372 }
1373
1374 return did_create_or_bind;
1375 }
1376 return false;
1377 }
1378
1337 void ResourceProvider::TransferResource(GLES2Interface* gl, 1379 void ResourceProvider::TransferResource(GLES2Interface* gl,
1338 ResourceId id, 1380 ResourceId id,
1339 TransferableResource* resource) { 1381 TransferableResource* resource) {
1340 Resource* source = GetResource(id); 1382 Resource* source = GetResource(id);
1341 DCHECK(!source->locked_for_write); 1383 DCHECK(!source->locked_for_write);
1342 DCHECK(!source->lock_for_read_count); 1384 DCHECK(!source->lock_for_read_count);
1343 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); 1385 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid());
1344 DCHECK(source->allocated); 1386 DCHECK(source->allocated);
1345 resource->id = id; 1387 resource->id = id;
1346 resource->format = source->format; 1388 resource->format = source->format;
1347 resource->mailbox_holder.texture_target = source->target; 1389 resource->mailbox_holder.texture_target = source->target;
1348 resource->filter = source->filter; 1390 resource->filter = source->filter;
1349 resource->size = source->size; 1391 resource->size = source->size;
1350 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; 1392 resource->read_lock_fences_enabled = source->read_lock_fences_enabled;
1351 resource->is_overlay_candidate = source->is_overlay_candidate; 1393 resource->is_overlay_candidate = source->is_overlay_candidate;
1352 1394
1353 if (source->type == RESOURCE_TYPE_BITMAP) { 1395 if (source->type == RESOURCE_TYPE_BITMAP) {
1354 resource->mailbox_holder.mailbox = source->shared_bitmap_id; 1396 resource->mailbox_holder.mailbox = source->shared_bitmap_id;
1355 resource->is_software = true; 1397 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 { 1398 } else {
1399 DCHECK(source->mailbox.IsValid());
1371 DCHECK(source->mailbox.IsTexture()); 1400 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 1401 // 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. 1402 // already exported. Make sure to forward the sync point that we were given.
1379 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); 1403 resource->mailbox_holder.mailbox = source->mailbox.mailbox();
1380 resource->mailbox_holder.texture_target = source->mailbox.target(); 1404 resource->mailbox_holder.texture_target = source->mailbox.target();
1381 resource->mailbox_holder.sync_token = source->mailbox.sync_token(); 1405 resource->mailbox_holder.sync_token = source->mailbox.sync_token();
1382 source->mailbox.set_sync_token(gpu::SyncToken());
1383 } 1406 }
1384 } 1407 }
1385 1408
1386 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( 1409 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild(
1387 ChildMap::iterator child_it, 1410 ChildMap::iterator child_it,
1388 DeleteStyle style, 1411 DeleteStyle style,
1389 const ResourceIdArray& unused) { 1412 const ResourceIdArray& unused) {
1390 DCHECK(thread_checker_.CalledOnValidThread()); 1413 DCHECK(thread_checker_.CalledOnValidThread());
1391 DCHECK(child_it != children_.end()); 1414 DCHECK(child_it != children_.end());
1392 Child* child_info = &child_it->second; 1415 Child* child_info = &child_it->second;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 1760
1738 const int kImportance = 2; 1761 const int kImportance = 2;
1739 pmd->CreateSharedGlobalAllocatorDump(guid); 1762 pmd->CreateSharedGlobalAllocatorDump(guid);
1740 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 1763 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
1741 } 1764 }
1742 1765
1743 return true; 1766 return true;
1744 } 1767 }
1745 1768
1746 } // namespace cc 1769 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698