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

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

Issue 69343011: cc: Rationalize sync points and lost status for returned resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« 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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 lock_for_read_count(0), 173 lock_for_read_count(0),
174 imported_count(0), 174 imported_count(0),
175 exported_count(0), 175 exported_count(0),
176 locked_for_write(false), 176 locked_for_write(false),
177 external(false), 177 external(false),
178 marked_for_deletion(false), 178 marked_for_deletion(false),
179 pending_set_pixels(false), 179 pending_set_pixels(false),
180 set_pixels_completion_forced(false), 180 set_pixels_completion_forced(false),
181 allocated(false), 181 allocated(false),
182 enable_read_lock_fences(false), 182 enable_read_lock_fences(false),
183 sync_point_is_from_client(false),
183 read_lock_fence(NULL), 184 read_lock_fence(NULL),
184 size(), 185 size(),
185 target(0), 186 target(0),
186 original_filter(0), 187 original_filter(0),
187 filter(0), 188 filter(0),
188 image_id(0), 189 image_id(0),
189 bound_image_id(0), 190 bound_image_id(0),
190 dirty_image(false), 191 dirty_image(false),
191 texture_pool(0), 192 texture_pool(0),
192 wrap_mode(0), 193 wrap_mode(0),
(...skipping 22 matching lines...) Expand all
215 lock_for_read_count(0), 216 lock_for_read_count(0),
216 imported_count(0), 217 imported_count(0),
217 exported_count(0), 218 exported_count(0),
218 locked_for_write(false), 219 locked_for_write(false),
219 external(false), 220 external(false),
220 marked_for_deletion(false), 221 marked_for_deletion(false),
221 pending_set_pixels(false), 222 pending_set_pixels(false),
222 set_pixels_completion_forced(false), 223 set_pixels_completion_forced(false),
223 allocated(false), 224 allocated(false),
224 enable_read_lock_fences(false), 225 enable_read_lock_fences(false),
226 sync_point_is_from_client(false),
225 read_lock_fence(NULL), 227 read_lock_fence(NULL),
226 size(size), 228 size(size),
227 target(target), 229 target(target),
228 original_filter(filter), 230 original_filter(filter),
229 filter(filter), 231 filter(filter),
230 image_id(0), 232 image_id(0),
231 bound_image_id(0), 233 bound_image_id(0),
232 dirty_image(false), 234 dirty_image(false),
233 texture_pool(texture_pool), 235 texture_pool(texture_pool),
234 wrap_mode(wrap_mode), 236 wrap_mode(wrap_mode),
(...skipping 19 matching lines...) Expand all
254 lock_for_read_count(0), 256 lock_for_read_count(0),
255 imported_count(0), 257 imported_count(0),
256 exported_count(0), 258 exported_count(0),
257 locked_for_write(false), 259 locked_for_write(false),
258 external(false), 260 external(false),
259 marked_for_deletion(false), 261 marked_for_deletion(false),
260 pending_set_pixels(false), 262 pending_set_pixels(false),
261 set_pixels_completion_forced(false), 263 set_pixels_completion_forced(false),
262 allocated(false), 264 allocated(false),
263 enable_read_lock_fences(false), 265 enable_read_lock_fences(false),
266 sync_point_is_from_client(false),
264 read_lock_fence(NULL), 267 read_lock_fence(NULL),
265 size(size), 268 size(size),
266 target(0), 269 target(0),
267 original_filter(filter), 270 original_filter(filter),
268 filter(filter), 271 filter(filter),
269 image_id(0), 272 image_id(0),
270 bound_image_id(0), 273 bound_image_id(0),
271 dirty_image(false), 274 dirty_image(false),
272 texture_pool(0), 275 texture_pool(0),
273 wrap_mode(wrap_mode), 276 wrap_mode(wrap_mode),
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 477 }
475 resource = Resource(pixels, 478 resource = Resource(pixels,
476 shared_bitmap.release(), 479 shared_bitmap.release(),
477 mailbox.shared_memory_size(), 480 mailbox.shared_memory_size(),
478 GL_LINEAR, 481 GL_LINEAR,
479 GL_CLAMP_TO_EDGE); 482 GL_CLAMP_TO_EDGE);
480 } 483 }
481 resource.external = true; 484 resource.external = true;
482 resource.allocated = true; 485 resource.allocated = true;
483 resource.mailbox = mailbox; 486 resource.mailbox = mailbox;
487 resource.sync_point_is_from_client = true;
484 resource.release_callback = 488 resource.release_callback =
485 base::Bind(&SingleReleaseCallback::Run, 489 base::Bind(&SingleReleaseCallback::Run,
486 base::Owned(release_callback.release())); 490 base::Owned(release_callback.release()));
487 return id; 491 return id;
488 } 492 }
489 493
490 void ResourceProvider::DeleteResource(ResourceId id) { 494 void ResourceProvider::DeleteResource(ResourceId id) {
491 DCHECK(thread_checker_.CalledOnValidThread()); 495 DCHECK(thread_checker_.CalledOnValidThread());
492 ResourceMap::iterator it = resources_.find(id); 496 ResourceMap::iterator it = resources_.find(id);
493 CHECK(it != resources_.end()); 497 CHECK(it != resources_.end());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 DCHECK(context3d); 535 DCHECK(context3d);
532 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); 536 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id));
533 } 537 }
534 if (resource->gl_pixel_buffer_id) { 538 if (resource->gl_pixel_buffer_id) {
535 WebGraphicsContext3D* context3d = Context3d(); 539 WebGraphicsContext3D* context3d = Context3d();
536 DCHECK(context3d); 540 DCHECK(context3d);
537 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); 541 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id));
538 } 542 }
539 if (resource->mailbox.IsValid() && resource->external) { 543 if (resource->mailbox.IsValid() && resource->external) {
540 unsigned sync_point = resource->mailbox.sync_point(); 544 unsigned sync_point = resource->mailbox.sync_point();
545 if (resource->sync_point_is_from_client)
546 sync_point = 0;
541 if (resource->mailbox.IsTexture()) { 547 if (resource->mailbox.IsTexture()) {
542 lost_resource |= lost_output_surface_; 548 lost_resource |= lost_output_surface_;
543 WebGraphicsContext3D* context3d = Context3d(); 549 WebGraphicsContext3D* context3d = Context3d();
544 DCHECK(context3d); 550 DCHECK(context3d);
545 if (resource->gl_id) 551 if (resource->gl_id)
546 GLC(context3d, context3d->deleteTexture(resource->gl_id)); 552 GLC(context3d, context3d->deleteTexture(resource->gl_id));
547 if (!lost_resource && resource->gl_id) 553 if (!lost_resource && resource->gl_id) {
554 DCHECK(!sync_point);
548 sync_point = context3d->insertSyncPoint(); 555 sync_point = context3d->insertSyncPoint();
556 }
549 } else { 557 } else {
550 DCHECK(resource->mailbox.IsSharedMemory()); 558 DCHECK(resource->mailbox.IsSharedMemory());
551 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); 559 base::SharedMemory* shared_memory = resource->mailbox.shared_memory();
552 if (resource->pixels && shared_memory) { 560 if (resource->pixels && shared_memory) {
553 DCHECK(shared_memory->memory() == resource->pixels); 561 DCHECK(shared_memory->memory() == resource->pixels);
554 resource->pixels = NULL; 562 resource->pixels = NULL;
555 delete resource->shared_bitmap; 563 delete resource->shared_bitmap;
556 resource->shared_bitmap = NULL; 564 resource->shared_bitmap = NULL;
557 } 565 }
558 } 566 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { 710 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) {
703 Resource* resource = GetResource(id); 711 Resource* resource = GetResource(id);
704 DCHECK(!resource->locked_for_write || 712 DCHECK(!resource->locked_for_write ||
705 resource->set_pixels_completion_forced) << 713 resource->set_pixels_completion_forced) <<
706 "locked for write: " << resource->locked_for_write << 714 "locked for write: " << resource->locked_for_write <<
707 " pixels completion forced: " << resource->set_pixels_completion_forced; 715 " pixels completion forced: " << resource->set_pixels_completion_forced;
708 DCHECK_EQ(resource->exported_count, 0); 716 DCHECK_EQ(resource->exported_count, 0);
709 // Uninitialized! Call SetPixels or LockForWrite first. 717 // Uninitialized! Call SetPixels or LockForWrite first.
710 DCHECK(resource->allocated); 718 DCHECK(resource->allocated);
711 719
712 LazyCreate(resource); 720 if (!resource->gl_id && resource->mailbox.IsTexture()) {
713 721 WebGraphicsContext3D* context3d = Context3d();
714 if (resource->external) { 722 DCHECK(context3d);
715 if (!resource->gl_id && resource->mailbox.IsTexture()) { 723 resource->sync_point_is_from_client = false;
716 WebGraphicsContext3D* context3d = Context3d(); 724 if (resource->mailbox.sync_point()) {
717 DCHECK(context3d); 725 GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point()));
718 if (resource->mailbox.sync_point()) { 726 resource->mailbox.ResetSyncPoint();
719 GLC(context3d,
720 context3d->waitSyncPoint(resource->mailbox.sync_point()));
721 resource->mailbox.ResetSyncPoint();
722 }
723 resource->gl_id = texture_id_allocator_->NextId();
724 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id));
725 GLC(context3d,
726 context3d->consumeTextureCHROMIUM(resource->target,
727 resource->mailbox.data()));
728 } 727 }
728 resource->gl_id = texture_id_allocator_->NextId();
729 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id));
730 GLC(context3d,
731 context3d->consumeTextureCHROMIUM(resource->target,
732 resource->mailbox.data()));
733 } else {
734 LazyCreate(resource);
729 } 735 }
730 736
731 resource->lock_for_read_count++; 737 resource->lock_for_read_count++;
732 if (resource->enable_read_lock_fences) 738 if (resource->enable_read_lock_fences)
733 resource->read_lock_fence = current_read_lock_fence_; 739 resource->read_lock_fence = current_read_lock_fence_;
734 740
735 return resource; 741 return resource;
736 } 742 }
737 743
738 void ResourceProvider::UnlockForRead(ResourceId id) { 744 void ResourceProvider::UnlockForRead(ResourceId id) {
739 Resource* resource = GetResource(id); 745 Resource* resource = GetResource(id);
740 DCHECK_GT(resource->lock_for_read_count, 0); 746 DCHECK_GT(resource->lock_for_read_count, 0);
741 DCHECK_EQ(resource->exported_count, 0); 747 DCHECK_EQ(resource->exported_count, 0);
742 resource->lock_for_read_count--; 748 resource->lock_for_read_count--;
743 } 749 }
744 750
745 const ResourceProvider::Resource* ResourceProvider::LockForWrite( 751 const ResourceProvider::Resource* ResourceProvider::LockForWrite(
746 ResourceId id) { 752 ResourceId id) {
747 Resource* resource = GetResource(id); 753 Resource* resource = GetResource(id);
748 DCHECK(!resource->locked_for_write); 754 DCHECK(!resource->locked_for_write);
749 DCHECK(!resource->lock_for_read_count); 755 DCHECK(!resource->lock_for_read_count);
750 DCHECK_EQ(resource->exported_count, 0); 756 DCHECK_EQ(resource->exported_count, 0);
751 DCHECK(!resource->external); 757 DCHECK(!resource->external);
752 DCHECK(!resource->lost); 758 DCHECK(!resource->lost);
753 DCHECK(ReadLockFenceHasPassed(resource)); 759 DCHECK(ReadLockFenceHasPassed(resource));
754 LazyAllocate(resource); 760 LazyAllocate(resource);
755 761
762 resource->mailbox.ResetSyncPoint();
756 resource->locked_for_write = true; 763 resource->locked_for_write = true;
757 return resource; 764 return resource;
758 } 765 }
759 766
760 bool ResourceProvider::CanLockForWrite(ResourceId id) { 767 bool ResourceProvider::CanLockForWrite(ResourceId id) {
761 Resource* resource = GetResource(id); 768 Resource* resource = GetResource(id);
762 return !resource->locked_for_write && !resource->lock_for_read_count && 769 return !resource->locked_for_write && !resource->lock_for_read_count &&
763 !resource->exported_count && !resource->external && !resource->lost && 770 !resource->exported_count && !resource->external && !resource->lost &&
764 ReadLockFenceHasPassed(resource); 771 ReadLockFenceHasPassed(resource);
765 } 772 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 child_info.return_callback.Run(to_return); 1071 child_info.return_callback.Run(to_return);
1065 continue; 1072 continue;
1066 } 1073 }
1067 1074
1068 ResourceId local_id = next_id_++; 1075 ResourceId local_id = next_id_++;
1069 Resource& resource = resources_[local_id]; 1076 Resource& resource = resources_[local_id];
1070 if (it->is_software) { 1077 if (it->is_software) {
1071 resource = Resource( 1078 resource = Resource(
1072 pixels, bitmap.release(), it->size, GL_LINEAR, GL_CLAMP_TO_EDGE); 1079 pixels, bitmap.release(), it->size, GL_LINEAR, GL_CLAMP_TO_EDGE);
1073 } else { 1080 } else {
1074 unsigned texture_id; 1081 resource = Resource(0,
1075 // NOTE: If the parent is a browser and the child a renderer, the parent
1076 // is not supposed to have its context wait, because that could induce
1077 // deadlocks and/or security issues. The caller is responsible for
1078 // waiting asynchronously, and resetting sync_point before calling this.
1079 // However if the parent is a renderer (e.g. browser tag), it may be ok
1080 // (and is simpler) to wait.
1081 if (it->sync_point)
1082 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
1083 texture_id = texture_id_allocator_->NextId();
1084 GLC(context3d, context3d->bindTexture(it->target, texture_id));
1085 GLC(context3d,
1086 context3d->consumeTextureCHROMIUM(it->target, it->mailbox.name));
1087 resource = Resource(texture_id,
1088 it->size, 1082 it->size,
1089 it->target, 1083 it->target,
1090 it->filter, 1084 it->filter,
1091 0, 1085 0,
1092 GL_CLAMP_TO_EDGE, 1086 GL_CLAMP_TO_EDGE,
1093 TextureUsageAny, 1087 TextureUsageAny,
1094 it->format); 1088 it->format);
1095 resource.mailbox.SetName(it->mailbox); 1089 resource.mailbox = TextureMailbox(it->mailbox, it->sync_point);
1090 resource.sync_point_is_from_client = true;
1096 } 1091 }
1097 resource.child_id = child; 1092 resource.child_id = child;
1098 // Don't allocate a texture for a child. 1093 // Don't allocate a texture for a child.
1099 resource.allocated = true; 1094 resource.allocated = true;
1100 resource.imported_count = 1; 1095 resource.imported_count = 1;
1101 child_info.parent_to_child_map[local_id] = it->id; 1096 child_info.parent_to_child_map[local_id] = it->id;
1102 child_info.child_to_parent_map[it->id] = local_id; 1097 child_info.child_to_parent_map[it->id] = local_id;
1103 } 1098 }
1104 } 1099 }
1105 1100
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 ResourceMap::iterator& map_iterator = sorted_resources[i].second; 1179 ResourceMap::iterator& map_iterator = sorted_resources[i].second;
1185 ResourceId local_id = map_iterator->first; 1180 ResourceId local_id = map_iterator->first;
1186 Resource* resource = &map_iterator->second; 1181 Resource* resource = &map_iterator->second;
1187 1182
1188 CHECK_GE(resource->exported_count, returned.count); 1183 CHECK_GE(resource->exported_count, returned.count);
1189 resource->exported_count -= returned.count; 1184 resource->exported_count -= returned.count;
1190 resource->lost |= returned.lost; 1185 resource->lost |= returned.lost;
1191 if (resource->exported_count) 1186 if (resource->exported_count)
1192 continue; 1187 continue;
1193 1188
1194 if (resource->gl_id) { 1189 if (returned.sync_point) {
1195 if (returned.sync_point) 1190 DCHECK(!resource->shared_bitmap);
1191 resource->sync_point_is_from_client = false;
1192 if (resource->gl_id) {
1196 GLC(context3d, context3d->waitSyncPoint(returned.sync_point)); 1193 GLC(context3d, context3d->waitSyncPoint(returned.sync_point));
1197 } else if (!resource->shared_bitmap) { 1194 resource->mailbox.ResetSyncPoint();
1198 resource->mailbox = 1195 } else {
1199 TextureMailbox(resource->mailbox.name(), returned.sync_point); 1196 resource->mailbox =
1197 TextureMailbox(resource->mailbox.name(), returned.sync_point);
1198 }
1200 } 1199 }
1201 1200
1202 if (!resource->marked_for_deletion) 1201 if (!resource->marked_for_deletion)
1203 continue; 1202 continue;
1204 1203
1205 if (!resource->child_id) { 1204 if (!resource->child_id) {
1206 // The resource belongs to this ResourceProvider, so it can be destroyed. 1205 // The resource belongs to this ResourceProvider, so it can be destroyed.
1207 DeleteResourceInternal(map_iterator, Normal); 1206 DeleteResourceInternal(map_iterator, Normal);
1208 continue; 1207 continue;
1209 } 1208 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 GLC(context, 1258 GLC(context,
1260 context->produceTextureCHROMIUM(resource->target, 1259 context->produceTextureCHROMIUM(resource->target,
1261 resource->mailbox.name)); 1260 resource->mailbox.name));
1262 source->mailbox.SetName(resource->mailbox); 1261 source->mailbox.SetName(resource->mailbox);
1263 } else { 1262 } else {
1264 DCHECK(source->mailbox.IsTexture()); 1263 DCHECK(source->mailbox.IsTexture());
1265 // This is either an external resource, or a compositor resource that we 1264 // This is either an external resource, or a compositor resource that we
1266 // already exported. Make sure to forward the sync point that we were given. 1265 // already exported. Make sure to forward the sync point that we were given.
1267 resource->mailbox = source->mailbox.name(); 1266 resource->mailbox = source->mailbox.name();
1268 resource->sync_point = source->mailbox.sync_point(); 1267 resource->sync_point = source->mailbox.sync_point();
1269 source->mailbox.ResetSyncPoint();
1270 } 1268 }
1271 } 1269 }
1272 1270
1273 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( 1271 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild(
1274 ChildMap::iterator child_it, 1272 ChildMap::iterator child_it,
1275 DeleteStyle style, 1273 DeleteStyle style,
1276 const ResourceIdArray& unused) { 1274 const ResourceIdArray& unused) {
1277 DCHECK(thread_checker_.CalledOnValidThread()); 1275 DCHECK(thread_checker_.CalledOnValidThread());
1278 DCHECK(child_it != children_.end()); 1276 DCHECK(child_it != children_.end());
1279 Child* child_info = &child_it->second; 1277 Child* child_info = &child_it->second;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 GL_TEXTURE_MIN_FILTER, 1324 GL_TEXTURE_MIN_FILTER,
1327 resource.original_filter)); 1325 resource.original_filter));
1328 GLC(context3d, 1326 GLC(context3d,
1329 context3d->texParameteri(resource.target, 1327 context3d->texParameteri(resource.target,
1330 GL_TEXTURE_MAG_FILTER, 1328 GL_TEXTURE_MAG_FILTER,
1331 resource.original_filter)); 1329 resource.original_filter));
1332 } 1330 }
1333 1331
1334 ReturnedResource returned; 1332 ReturnedResource returned;
1335 returned.id = child_id; 1333 returned.id = child_id;
1336 returned.sync_point = resource.mailbox.sync_point(); 1334 if (!resource.sync_point_is_from_client) {
1337 if (!returned.sync_point && !resource.shared_bitmap) 1335 returned.sync_point = resource.mailbox.sync_point();
1338 need_sync_point = true; 1336 if (!returned.sync_point && !resource.shared_bitmap)
1337 need_sync_point = true;
1338 }
1339 returned.count = resource.imported_count; 1339 returned.count = resource.imported_count;
1340 returned.lost = is_lost; 1340 returned.lost = is_lost;
1341 to_return.push_back(returned); 1341 to_return.push_back(returned);
1342 1342
1343 child_info->parent_to_child_map.erase(local_id); 1343 child_info->parent_to_child_map.erase(local_id);
1344 child_info->child_to_parent_map.erase(child_id); 1344 child_info->child_to_parent_map.erase(child_id);
1345 resource.imported_count = 0; 1345 resource.imported_count = 0;
1346 DeleteResourceInternal(it, style); 1346 DeleteResourceInternal(it, style);
1347 } 1347 }
1348 if (need_sync_point) { 1348 if (need_sync_point) {
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1826 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1827 return active_unit; 1827 return active_unit;
1828 } 1828 }
1829 1829
1830 blink::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1830 blink::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1831 ContextProvider* context_provider = output_surface_->context_provider(); 1831 ContextProvider* context_provider = output_surface_->context_provider();
1832 return context_provider ? context_provider->Context3d() : NULL; 1832 return context_provider ? context_provider->Context3d() : NULL;
1833 } 1833 }
1834 1834
1835 } // namespace cc 1835 } // 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