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 <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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 WebGraphicsContext3D* context3d = Context3d(); | 542 WebGraphicsContext3D* context3d = Context3d(); |
543 DCHECK(context3d); | 543 DCHECK(context3d); |
544 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); | 544 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); |
545 } | 545 } |
546 if (resource->gl_pixel_buffer_id) { | 546 if (resource->gl_pixel_buffer_id) { |
547 WebGraphicsContext3D* context3d = Context3d(); | 547 WebGraphicsContext3D* context3d = Context3d(); |
548 DCHECK(context3d); | 548 DCHECK(context3d); |
549 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); | 549 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); |
550 } | 550 } |
551 if (resource->mailbox.IsValid() && resource->external) { | 551 if (resource->mailbox.IsValid() && resource->external) { |
552 unsigned sync_point = resource->mailbox.sync_point(); | 552 uint32 sync_point = resource->mailbox.sync_point(); |
553 if (resource->mailbox.IsTexture()) { | 553 if (resource->mailbox.IsTexture()) { |
554 lost_resource |= lost_output_surface_; | 554 lost_resource |= lost_output_surface_; |
555 WebGraphicsContext3D* context3d = Context3d(); | 555 WebGraphicsContext3D* context3d = Context3d(); |
556 DCHECK(context3d); | 556 DCHECK(context3d); |
557 if (resource->gl_id) | 557 if (resource->gl_id) |
558 GLC(context3d, context3d->deleteTexture(resource->gl_id)); | 558 GLC(context3d, context3d->deleteTexture(resource->gl_id)); |
559 if (!lost_resource && resource->gl_id) | 559 if (!lost_resource && resource->gl_id) |
560 sync_point = context3d->insertSyncPoint(); | 560 sync_point = context3d->insertSyncPoint(); |
561 } else { | 561 } else { |
562 DCHECK(resource->mailbox.IsSharedMemory()); | 562 DCHECK(resource->mailbox.IsSharedMemory()); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 | 738 |
739 LazyCreate(resource); | 739 LazyCreate(resource); |
740 | 740 |
741 if (resource->external) { | 741 if (resource->external) { |
742 if (!resource->gl_id && resource->mailbox.IsTexture()) { | 742 if (!resource->gl_id && resource->mailbox.IsTexture()) { |
743 WebGraphicsContext3D* context3d = Context3d(); | 743 WebGraphicsContext3D* context3d = Context3d(); |
744 DCHECK(context3d); | 744 DCHECK(context3d); |
745 if (resource->mailbox.sync_point()) { | 745 if (resource->mailbox.sync_point()) { |
746 GLC(context3d, | 746 GLC(context3d, |
747 context3d->waitSyncPoint(resource->mailbox.sync_point())); | 747 context3d->waitSyncPoint(resource->mailbox.sync_point())); |
748 resource->mailbox.ResetSyncPoint(); | 748 resource->mailbox.set_sync_point(0); |
749 } | 749 } |
750 resource->gl_id = texture_id_allocator_->NextId(); | 750 resource->gl_id = texture_id_allocator_->NextId(); |
751 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id)); | 751 GLC(context3d, context3d->bindTexture(resource->target, resource->gl_id)); |
752 GLC(context3d, | 752 GLC(context3d, |
753 context3d->consumeTextureCHROMIUM(resource->target, | 753 context3d->consumeTextureCHROMIUM(resource->target, |
754 resource->mailbox.data())); | 754 resource->mailbox.mailbox().name)); |
755 } | 755 } |
756 } | 756 } |
757 | 757 |
758 resource->lock_for_read_count++; | 758 resource->lock_for_read_count++; |
759 if (resource->enable_read_lock_fences) | 759 if (resource->enable_read_lock_fences) |
760 resource->read_lock_fence = current_read_lock_fence_; | 760 resource->read_lock_fence = current_read_lock_fence_; |
761 | 761 |
762 return resource; | 762 return resource; |
763 } | 763 } |
764 | 764 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 it != resources.end(); | 1037 it != resources.end(); |
1038 ++it) { | 1038 ++it) { |
1039 TransferableResource resource; | 1039 TransferableResource resource; |
1040 TransferResource(context3d, *it, &resource); | 1040 TransferResource(context3d, *it, &resource); |
1041 if (!resource.sync_point && !resource.is_software) | 1041 if (!resource.sync_point && !resource.is_software) |
1042 need_sync_point = true; | 1042 need_sync_point = true; |
1043 ++resources_.find(*it)->second.exported_count; | 1043 ++resources_.find(*it)->second.exported_count; |
1044 list->push_back(resource); | 1044 list->push_back(resource); |
1045 } | 1045 } |
1046 if (need_sync_point) { | 1046 if (need_sync_point) { |
1047 unsigned int sync_point = context3d->insertSyncPoint(); | 1047 uint32 sync_point = context3d->insertSyncPoint(); |
1048 for (TransferableResourceArray::iterator it = list->begin(); | 1048 for (TransferableResourceArray::iterator it = list->begin(); |
1049 it != list->end(); | 1049 it != list->end(); |
1050 ++it) { | 1050 ++it) { |
1051 if (!it->sync_point) | 1051 if (!it->sync_point) |
1052 it->sync_point = sync_point; | 1052 it->sync_point = sync_point; |
1053 } | 1053 } |
1054 } | 1054 } |
1055 } | 1055 } |
1056 | 1056 |
1057 void ResourceProvider::ReceiveFromChild( | 1057 void ResourceProvider::ReceiveFromChild( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 GLC(context3d, | 1110 GLC(context3d, |
1111 context3d->consumeTextureCHROMIUM(it->target, it->mailbox.name)); | 1111 context3d->consumeTextureCHROMIUM(it->target, it->mailbox.name)); |
1112 resource = Resource(texture_id, | 1112 resource = Resource(texture_id, |
1113 it->size, | 1113 it->size, |
1114 it->target, | 1114 it->target, |
1115 it->filter, | 1115 it->filter, |
1116 0, | 1116 0, |
1117 GL_CLAMP_TO_EDGE, | 1117 GL_CLAMP_TO_EDGE, |
1118 TextureUsageAny, | 1118 TextureUsageAny, |
1119 it->format); | 1119 it->format); |
1120 resource.mailbox.SetName(it->mailbox); | 1120 resource.mailbox = cc::TextureMailbox(it->mailbox, it->target, 0); |
1121 } | 1121 } |
1122 resource.child_id = child; | 1122 resource.child_id = child; |
1123 // Don't allocate a texture for a child. | 1123 // Don't allocate a texture for a child. |
1124 resource.allocated = true; | 1124 resource.allocated = true; |
1125 resource.imported_count = 1; | 1125 resource.imported_count = 1; |
1126 child_info.parent_to_child_map[local_id] = it->id; | 1126 child_info.parent_to_child_map[local_id] = it->id; |
1127 child_info.child_to_parent_map[it->id] = local_id; | 1127 child_info.child_to_parent_map[it->id] = local_id; |
1128 } | 1128 } |
1129 } | 1129 } |
1130 | 1130 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 CHECK_GE(resource->exported_count, returned.count); | 1213 CHECK_GE(resource->exported_count, returned.count); |
1214 resource->exported_count -= returned.count; | 1214 resource->exported_count -= returned.count; |
1215 resource->lost |= returned.lost; | 1215 resource->lost |= returned.lost; |
1216 if (resource->exported_count) | 1216 if (resource->exported_count) |
1217 continue; | 1217 continue; |
1218 | 1218 |
1219 if (resource->gl_id) { | 1219 if (resource->gl_id) { |
1220 if (returned.sync_point) | 1220 if (returned.sync_point) |
1221 GLC(context3d, context3d->waitSyncPoint(returned.sync_point)); | 1221 GLC(context3d, context3d->waitSyncPoint(returned.sync_point)); |
1222 } else if (!resource->shared_bitmap) { | 1222 } else if (!resource->shared_bitmap) { |
1223 resource->mailbox = | 1223 resource->mailbox.set_sync_point(returned.sync_point); |
1224 TextureMailbox(resource->mailbox.name(), returned.sync_point); | |
1225 } | 1224 } |
1226 | 1225 |
1227 if (!resource->marked_for_deletion) | 1226 if (!resource->marked_for_deletion) |
1228 continue; | 1227 continue; |
1229 | 1228 |
1230 if (!resource->child_id) { | 1229 if (!resource->child_id) { |
1231 // The resource belongs to this ResourceProvider, so it can be destroyed. | 1230 // The resource belongs to this ResourceProvider, so it can be destroyed. |
1232 DeleteResourceInternal(map_iterator, Normal); | 1231 DeleteResourceInternal(map_iterator, Normal); |
1233 continue; | 1232 continue; |
1234 } | 1233 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 resource->is_software = true; | 1277 resource->is_software = true; |
1279 } else if (!source->mailbox.IsValid()) { | 1278 } else if (!source->mailbox.IsValid()) { |
1280 // This is a resource allocated by the compositor, we need to produce it. | 1279 // This is a resource allocated by the compositor, we need to produce it. |
1281 // Don't set a sync point, the caller will do it. | 1280 // Don't set a sync point, the caller will do it. |
1282 DCHECK(source->gl_id); | 1281 DCHECK(source->gl_id); |
1283 GLC(context, context->bindTexture(resource->target, source->gl_id)); | 1282 GLC(context, context->bindTexture(resource->target, source->gl_id)); |
1284 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 1283 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
1285 GLC(context, | 1284 GLC(context, |
1286 context->produceTextureCHROMIUM(resource->target, | 1285 context->produceTextureCHROMIUM(resource->target, |
1287 resource->mailbox.name)); | 1286 resource->mailbox.name)); |
1288 source->mailbox.SetName(resource->mailbox); | 1287 source->mailbox = |
| 1288 cc::TextureMailbox(resource->mailbox, resource->target, 0); |
1289 } else { | 1289 } else { |
1290 DCHECK(source->mailbox.IsTexture()); | 1290 DCHECK(source->mailbox.IsTexture()); |
1291 // This is either an external resource, or a compositor resource that we | 1291 // This is either an external resource, or a compositor resource that we |
1292 // already exported. Make sure to forward the sync point that we were given. | 1292 // already exported. Make sure to forward the sync point that we were given. |
1293 resource->mailbox = source->mailbox.name(); | 1293 resource->mailbox = source->mailbox.mailbox(); |
1294 resource->sync_point = source->mailbox.sync_point(); | 1294 resource->sync_point = source->mailbox.sync_point(); |
1295 source->mailbox.ResetSyncPoint(); | 1295 source->mailbox.set_sync_point(0); |
1296 } | 1296 } |
1297 } | 1297 } |
1298 | 1298 |
1299 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( | 1299 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( |
1300 ChildMap::iterator child_it, | 1300 ChildMap::iterator child_it, |
1301 DeleteStyle style, | 1301 DeleteStyle style, |
1302 const ResourceIdArray& unused) { | 1302 const ResourceIdArray& unused) { |
1303 DCHECK(thread_checker_.CalledOnValidThread()); | 1303 DCHECK(thread_checker_.CalledOnValidThread()); |
1304 DCHECK(child_it != children_.end()); | 1304 DCHECK(child_it != children_.end()); |
1305 Child* child_info = &child_it->second; | 1305 Child* child_info = &child_it->second; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 returned.lost = is_lost; | 1366 returned.lost = is_lost; |
1367 to_return.push_back(returned); | 1367 to_return.push_back(returned); |
1368 | 1368 |
1369 child_info->parent_to_child_map.erase(local_id); | 1369 child_info->parent_to_child_map.erase(local_id); |
1370 child_info->child_to_parent_map.erase(child_id); | 1370 child_info->child_to_parent_map.erase(child_id); |
1371 resource.imported_count = 0; | 1371 resource.imported_count = 0; |
1372 DeleteResourceInternal(it, style); | 1372 DeleteResourceInternal(it, style); |
1373 } | 1373 } |
1374 if (need_sync_point) { | 1374 if (need_sync_point) { |
1375 DCHECK(context3d); | 1375 DCHECK(context3d); |
1376 unsigned int sync_point = context3d->insertSyncPoint(); | 1376 uint32 sync_point = context3d->insertSyncPoint(); |
1377 for (size_t i = 0; i < to_return.size(); ++i) { | 1377 for (size_t i = 0; i < to_return.size(); ++i) { |
1378 if (!to_return[i].sync_point) | 1378 if (!to_return[i].sync_point) |
1379 to_return[i].sync_point = sync_point; | 1379 to_return[i].sync_point = sync_point; |
1380 } | 1380 } |
1381 } | 1381 } |
1382 | 1382 |
1383 if (!to_return.empty()) | 1383 if (!to_return.empty()) |
1384 child_info->return_callback.Run(to_return); | 1384 child_info->return_callback.Run(to_return); |
1385 | 1385 |
1386 if (child_info->marked_for_deletion && | 1386 if (child_info->marked_for_deletion && |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1851 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1852 return active_unit; | 1852 return active_unit; |
1853 } | 1853 } |
1854 | 1854 |
1855 blink::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1855 blink::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
1856 ContextProvider* context_provider = output_surface_->context_provider(); | 1856 ContextProvider* context_provider = output_surface_->context_provider(); |
1857 return context_provider ? context_provider->Context3d() : NULL; | 1857 return context_provider ? context_provider->Context3d() : NULL; |
1858 } | 1858 } |
1859 | 1859 |
1860 } // namespace cc | 1860 } // namespace cc |
OLD | NEW |