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 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
| 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 Loading... |
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, |
| 1343 Resource* resource) { |
| 1344 if (resource->type != RESOURCE_TYPE_BITMAP) { |
| 1345 bool did_create_or_bind = false; |
| 1346 if (!resource->mailbox.IsValid()) { |
| 1347 LazyCreate(resource); |
| 1348 |
| 1349 gpu::MailboxHolder mailbox_holder; |
| 1350 mailbox_holder.texture_target = resource->target; |
| 1351 gl->GenMailboxCHROMIUM(mailbox_holder.mailbox.name); |
| 1352 gl->ProduceTextureDirectCHROMIUM(resource->gl_id, |
| 1353 mailbox_holder.texture_target, |
| 1354 mailbox_holder.mailbox.name); |
| 1355 resource->mailbox = TextureMailbox(mailbox_holder); |
| 1356 did_create_or_bind = true; |
| 1357 } |
| 1358 |
| 1359 if (resource->image_id && resource->dirty_image) { |
| 1360 DCHECK(resource->gl_id); |
| 1361 DCHECK(resource->origin == Resource::INTERNAL); |
| 1362 BindImageForSampling(resource); |
| 1363 did_create_or_bind = true; |
| 1364 } |
| 1365 |
| 1366 return did_create_or_bind; |
| 1367 } |
| 1368 return false; |
| 1369 } |
| 1370 |
1337 void ResourceProvider::TransferResource(GLES2Interface* gl, | 1371 void ResourceProvider::TransferResource(GLES2Interface* gl, |
1338 ResourceId id, | 1372 ResourceId id, |
1339 TransferableResource* resource) { | 1373 TransferableResource* resource) { |
1340 Resource* source = GetResource(id); | 1374 Resource* source = GetResource(id); |
1341 DCHECK(!source->locked_for_write); | 1375 DCHECK(!source->locked_for_write); |
1342 DCHECK(!source->lock_for_read_count); | 1376 DCHECK(!source->lock_for_read_count); |
1343 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); | 1377 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); |
1344 DCHECK(source->allocated); | 1378 DCHECK(source->allocated); |
1345 resource->id = id; | 1379 resource->id = id; |
1346 resource->format = source->format; | 1380 resource->format = source->format; |
1347 resource->mailbox_holder.texture_target = source->target; | 1381 resource->mailbox_holder.texture_target = source->target; |
1348 resource->filter = source->filter; | 1382 resource->filter = source->filter; |
1349 resource->size = source->size; | 1383 resource->size = source->size; |
1350 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; | 1384 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; |
1351 resource->is_overlay_candidate = source->is_overlay_candidate; | 1385 resource->is_overlay_candidate = source->is_overlay_candidate; |
1352 | 1386 |
1353 if (source->type == RESOURCE_TYPE_BITMAP) { | 1387 if (source->type == RESOURCE_TYPE_BITMAP) { |
1354 resource->mailbox_holder.mailbox = source->shared_bitmap_id; | 1388 resource->mailbox_holder.mailbox = source->shared_bitmap_id; |
1355 resource->is_software = true; | 1389 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 { | 1390 } else { |
| 1391 DCHECK(source->mailbox.IsValid()); |
1371 DCHECK(source->mailbox.IsTexture()); | 1392 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 | 1393 // 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. | 1394 // already exported. Make sure to forward the sync point that we were given. |
1379 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); | 1395 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); |
1380 resource->mailbox_holder.texture_target = source->mailbox.target(); | 1396 resource->mailbox_holder.texture_target = source->mailbox.target(); |
1381 resource->mailbox_holder.sync_token = source->mailbox.sync_token(); | 1397 resource->mailbox_holder.sync_token = source->mailbox.sync_token(); |
1382 source->mailbox.set_sync_token(gpu::SyncToken()); | |
1383 } | 1398 } |
1384 } | 1399 } |
1385 | 1400 |
1386 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( | 1401 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( |
1387 ChildMap::iterator child_it, | 1402 ChildMap::iterator child_it, |
1388 DeleteStyle style, | 1403 DeleteStyle style, |
1389 const ResourceIdArray& unused) { | 1404 const ResourceIdArray& unused) { |
1390 DCHECK(thread_checker_.CalledOnValidThread()); | 1405 DCHECK(thread_checker_.CalledOnValidThread()); |
1391 DCHECK(child_it != children_.end()); | 1406 DCHECK(child_it != children_.end()); |
1392 Child* child_info = &child_it->second; | 1407 Child* child_info = &child_it->second; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 | 1752 |
1738 const int kImportance = 2; | 1753 const int kImportance = 2; |
1739 pmd->CreateSharedGlobalAllocatorDump(guid); | 1754 pmd->CreateSharedGlobalAllocatorDump(guid); |
1740 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1755 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
1741 } | 1756 } |
1742 | 1757 |
1743 return true; | 1758 return true; |
1744 } | 1759 } |
1745 | 1760 |
1746 } // namespace cc | 1761 } // namespace cc |
OLD | NEW |