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

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

Issue 1678613002: Revert of 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
« 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;
1153 1154
1154 // Lazily create any mailboxes and verify all unverified sync tokens. 1155 gpu::SyncToken new_sync_token;
1155 std::vector<GLbyte*> unverified_sync_tokens; 1156 std::vector<size_t> unverified_token_indexes;
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 Resource* resource = GetResource(*it); 1160 TransferableResource resource;
1161 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);
1162 1164
1163 // TODO(dyen): Temporarily add missing sync tokens, eventually this should 1165 if (resource.mailbox_holder.sync_token.HasData() &&
1164 // be removed as we guarantee all resources have associated sync tokens. 1166 !resource.mailbox_holder.sync_token.verified_flush()) {
1165 need_synchronization |= (resource->type != RESOURCE_TYPE_BITMAP && 1167 unverified_token_indexes.push_back(list->size());
1166 !resource->mailbox.HasSyncToken()); 1168 }
1167 1169
1168 if (output_surface_->capabilities().delegated_sync_points_required && 1170 ++resources_.find(*it)->second.exported_count;
1169 need_synchronization) { 1171 list->push_back(resource);
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());
1174 }
1175 } 1172 }
1176 1173
1177 // Insert sync point to synchronize the mailbox creation or bound textures. 1174 // Fill out unverified sync tokens array.
1178 gpu::SyncToken new_sync_token; 1175 std::vector<GLbyte*> unverified_sync_tokens;
1179 if (!need_synchronization_indexes.empty()) { 1176 unverified_sync_tokens.reserve(unverified_token_indexes.size() + 1);
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) {
1180 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 1185 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
1181 gl->OrderingBarrierCHROMIUM(); 1186 gl->OrderingBarrierCHROMIUM();
1182 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); 1187 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
1183 unverified_sync_tokens.push_back(new_sync_token.GetData()); 1188 unverified_sync_tokens.push_back(new_sync_token.GetData());
1184 } 1189 }
1185 1190
1186 if (!unverified_sync_tokens.empty()) { 1191 if (!unverified_sync_tokens.empty()) {
1187 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), 1192 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
1188 unverified_sync_tokens.size()); 1193 unverified_sync_tokens.size());
1189 } 1194 }
1190 1195
1191 for (ResourceIdArray::const_iterator it : need_synchronization_indexes) { 1196 if (new_sync_token.HasData()) {
1192 GetResource(*it)->mailbox.set_sync_token(new_sync_token); 1197 for (TransferableResourceArray::iterator it = list->begin();
1193 } 1198 it != list->end();
1194 1199 ++it) {
1195 // Transfer Resources 1200 if (!it->mailbox_holder.sync_token.HasData())
1196 for (ResourceIdArray::const_iterator it = resources.begin(); 1201 it->mailbox_holder.sync_token = new_sync_token;
1197 it != resources.end(); ++it) { 1202 }
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);
1207 } 1203 }
1208 } 1204 }
1209 1205
1210 void ResourceProvider::ReceiveFromChild( 1206 void ResourceProvider::ReceiveFromChild(
1211 int child, const TransferableResourceArray& resources) { 1207 int child, const TransferableResourceArray& resources) {
1212 DCHECK(thread_checker_.CalledOnValidThread()); 1208 DCHECK(thread_checker_.CalledOnValidThread());
1213 GLES2Interface* gl = ContextGL(); 1209 GLES2Interface* gl = ContextGL();
1214 Child& child_info = children_.find(child)->second; 1210 Child& child_info = children_.find(child)->second;
1215 DCHECK(!child_info.marked_for_deletion); 1211 DCHECK(!child_info.marked_for_deletion);
1216 for (TransferableResourceArray::const_iterator it = resources.begin(); 1212 for (TransferableResourceArray::const_iterator it = resources.begin();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 resources_for_child[resource->child_id].push_back(local_id); 1327 resources_for_child[resource->child_id].push_back(local_id);
1332 } 1328 }
1333 1329
1334 for (const auto& children : resources_for_child) { 1330 for (const auto& children : resources_for_child) {
1335 ChildMap::iterator child_it = children_.find(children.first); 1331 ChildMap::iterator child_it = children_.find(children.first);
1336 DCHECK(child_it != children_.end()); 1332 DCHECK(child_it != children_.end());
1337 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); 1333 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second);
1338 } 1334 }
1339 } 1335 }
1340 1336
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
1371 void ResourceProvider::TransferResource(GLES2Interface* gl, 1337 void ResourceProvider::TransferResource(GLES2Interface* gl,
1372 ResourceId id, 1338 ResourceId id,
1373 TransferableResource* resource) { 1339 TransferableResource* resource) {
1374 Resource* source = GetResource(id); 1340 Resource* source = GetResource(id);
1375 DCHECK(!source->locked_for_write); 1341 DCHECK(!source->locked_for_write);
1376 DCHECK(!source->lock_for_read_count); 1342 DCHECK(!source->lock_for_read_count);
1377 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); 1343 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid());
1378 DCHECK(source->allocated); 1344 DCHECK(source->allocated);
1379 resource->id = id; 1345 resource->id = id;
1380 resource->format = source->format; 1346 resource->format = source->format;
1381 resource->mailbox_holder.texture_target = source->target; 1347 resource->mailbox_holder.texture_target = source->target;
1382 resource->filter = source->filter; 1348 resource->filter = source->filter;
1383 resource->size = source->size; 1349 resource->size = source->size;
1384 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; 1350 resource->read_lock_fences_enabled = source->read_lock_fences_enabled;
1385 resource->is_overlay_candidate = source->is_overlay_candidate; 1351 resource->is_overlay_candidate = source->is_overlay_candidate;
1386 1352
1387 if (source->type == RESOURCE_TYPE_BITMAP) { 1353 if (source->type == RESOURCE_TYPE_BITMAP) {
1388 resource->mailbox_holder.mailbox = source->shared_bitmap_id; 1354 resource->mailbox_holder.mailbox = source->shared_bitmap_id;
1389 resource->is_software = true; 1355 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);
1390 } else { 1370 } else {
1391 DCHECK(source->mailbox.IsValid());
1392 DCHECK(source->mailbox.IsTexture()); 1371 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 }
1393 // This is either an external resource, or a compositor resource that we 1377 // This is either an external resource, or a compositor resource that we
1394 // already exported. Make sure to forward the sync point that we were given. 1378 // already exported. Make sure to forward the sync point that we were given.
1395 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); 1379 resource->mailbox_holder.mailbox = source->mailbox.mailbox();
1396 resource->mailbox_holder.texture_target = source->mailbox.target(); 1380 resource->mailbox_holder.texture_target = source->mailbox.target();
1397 resource->mailbox_holder.sync_token = source->mailbox.sync_token(); 1381 resource->mailbox_holder.sync_token = source->mailbox.sync_token();
1382 source->mailbox.set_sync_token(gpu::SyncToken());
1398 } 1383 }
1399 } 1384 }
1400 1385
1401 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( 1386 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild(
1402 ChildMap::iterator child_it, 1387 ChildMap::iterator child_it,
1403 DeleteStyle style, 1388 DeleteStyle style,
1404 const ResourceIdArray& unused) { 1389 const ResourceIdArray& unused) {
1405 DCHECK(thread_checker_.CalledOnValidThread()); 1390 DCHECK(thread_checker_.CalledOnValidThread());
1406 DCHECK(child_it != children_.end()); 1391 DCHECK(child_it != children_.end());
1407 Child* child_info = &child_it->second; 1392 Child* child_info = &child_it->second;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 1737
1753 const int kImportance = 2; 1738 const int kImportance = 2;
1754 pmd->CreateSharedGlobalAllocatorDump(guid); 1739 pmd->CreateSharedGlobalAllocatorDump(guid);
1755 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 1740 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
1756 } 1741 }
1757 1742
1758 return true; 1743 return true;
1759 } 1744 }
1760 1745
1761 } // namespace cc 1746 } // 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