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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 DCHECK(gl); | 535 DCHECK(gl); |
536 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); | 536 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); |
537 } | 537 } |
538 if (resource->gl_pixel_buffer_id) { | 538 if (resource->gl_pixel_buffer_id) { |
539 DCHECK(resource->origin == Resource::Internal); | 539 DCHECK(resource->origin == Resource::Internal); |
540 GLES2Interface* gl = ContextGL(); | 540 GLES2Interface* gl = ContextGL(); |
541 DCHECK(gl); | 541 DCHECK(gl); |
542 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); | 542 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); |
543 } | 543 } |
544 if (resource->mailbox.IsValid() && resource->origin == Resource::External) { | 544 if (resource->mailbox.IsValid() && resource->origin == Resource::External) { |
545 GLuint sync_point = resource->mailbox.sync_point(); | 545 uint32 sync_point = resource->mailbox.sync_point(); |
546 if (resource->mailbox.IsTexture()) { | 546 if (resource->mailbox.IsTexture()) { |
547 lost_resource |= lost_output_surface_; | 547 lost_resource |= lost_output_surface_; |
548 GLES2Interface* gl = ContextGL(); | 548 GLES2Interface* gl = ContextGL(); |
549 DCHECK(gl); | 549 DCHECK(gl); |
550 if (resource->gl_id) { | 550 if (resource->gl_id) { |
551 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); | 551 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
552 resource->gl_id = 0; | 552 resource->gl_id = 0; |
553 if (!lost_resource) | 553 if (!lost_resource) |
554 sync_point = gl->InsertSyncPointCHROMIUM(); | 554 sync_point = gl->InsertSyncPointCHROMIUM(); |
555 } | 555 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 DCHECK(resource->allocated); | 746 DCHECK(resource->allocated); |
747 | 747 |
748 LazyCreate(resource); | 748 LazyCreate(resource); |
749 | 749 |
750 if (!resource->gl_id && resource->mailbox.IsTexture()) { | 750 if (!resource->gl_id && resource->mailbox.IsTexture()) { |
751 DCHECK(resource->origin != Resource::Internal); | 751 DCHECK(resource->origin != Resource::Internal); |
752 GLES2Interface* gl = ContextGL(); | 752 GLES2Interface* gl = ContextGL(); |
753 DCHECK(gl); | 753 DCHECK(gl); |
754 if (resource->mailbox.sync_point()) { | 754 if (resource->mailbox.sync_point()) { |
755 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); | 755 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); |
756 resource->mailbox.ResetSyncPoint(); | 756 resource->mailbox.set_sync_point(0); |
757 } | 757 } |
758 resource->gl_id = texture_id_allocator_->NextId(); | 758 resource->gl_id = texture_id_allocator_->NextId(); |
759 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); | 759 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); |
760 GLC(gl, | 760 GLC(gl, |
761 gl->ConsumeTextureCHROMIUM(resource->target, | 761 gl->ConsumeTextureCHROMIUM(resource->mailbox.target(), |
762 resource->mailbox.data())); | 762 resource->mailbox.name())); |
763 } | 763 } |
764 | 764 |
765 resource->lock_for_read_count++; | 765 resource->lock_for_read_count++; |
766 if (resource->enable_read_lock_fences) | 766 if (resource->enable_read_lock_fences) |
767 resource->read_lock_fence = current_read_lock_fence_; | 767 resource->read_lock_fence = current_read_lock_fence_; |
768 | 768 |
769 return resource; | 769 return resource; |
770 } | 770 } |
771 | 771 |
772 void ResourceProvider::UnlockForRead(ResourceId id) { | 772 void ResourceProvider::UnlockForRead(ResourceId id) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, | 1027 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, |
1028 TransferableResourceArray* list) { | 1028 TransferableResourceArray* list) { |
1029 DCHECK(thread_checker_.CalledOnValidThread()); | 1029 DCHECK(thread_checker_.CalledOnValidThread()); |
1030 GLES2Interface* gl = ContextGL(); | 1030 GLES2Interface* gl = ContextGL(); |
1031 bool need_sync_point = false; | 1031 bool need_sync_point = false; |
1032 for (ResourceIdArray::const_iterator it = resources.begin(); | 1032 for (ResourceIdArray::const_iterator it = resources.begin(); |
1033 it != resources.end(); | 1033 it != resources.end(); |
1034 ++it) { | 1034 ++it) { |
1035 TransferableResource resource; | 1035 TransferableResource resource; |
1036 TransferResource(gl, *it, &resource); | 1036 TransferResource(gl, *it, &resource); |
1037 if (!resource.sync_point && !resource.is_software) | 1037 if (!resource.mailbox_holder.sync_point && !resource.is_software) |
1038 need_sync_point = true; | 1038 need_sync_point = true; |
1039 ++resources_.find(*it)->second.exported_count; | 1039 ++resources_.find(*it)->second.exported_count; |
1040 list->push_back(resource); | 1040 list->push_back(resource); |
1041 } | 1041 } |
1042 if (need_sync_point) { | 1042 if (need_sync_point) { |
1043 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); | 1043 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); |
1044 for (TransferableResourceArray::iterator it = list->begin(); | 1044 for (TransferableResourceArray::iterator it = list->begin(); |
1045 it != list->end(); | 1045 it != list->end(); |
1046 ++it) { | 1046 ++it) { |
1047 if (!it->sync_point) | 1047 if (!it->mailbox_holder.sync_point) |
1048 it->sync_point = sync_point; | 1048 it->mailbox_holder.sync_point = sync_point; |
1049 } | 1049 } |
1050 } | 1050 } |
1051 } | 1051 } |
1052 | 1052 |
1053 void ResourceProvider::ReceiveFromChild( | 1053 void ResourceProvider::ReceiveFromChild( |
1054 int child, const TransferableResourceArray& resources) { | 1054 int child, const TransferableResourceArray& resources) { |
1055 DCHECK(thread_checker_.CalledOnValidThread()); | 1055 DCHECK(thread_checker_.CalledOnValidThread()); |
1056 GLES2Interface* gl = ContextGL(); | 1056 GLES2Interface* gl = ContextGL(); |
1057 Child& child_info = children_.find(child)->second; | 1057 Child& child_info = children_.find(child)->second; |
1058 DCHECK(!child_info.marked_for_deletion); | 1058 DCHECK(!child_info.marked_for_deletion); |
1059 for (TransferableResourceArray::const_iterator it = resources.begin(); | 1059 for (TransferableResourceArray::const_iterator it = resources.begin(); |
1060 it != resources.end(); | 1060 it != resources.end(); |
1061 ++it) { | 1061 ++it) { |
1062 ResourceIdMap::iterator resource_in_map_it = | 1062 ResourceIdMap::iterator resource_in_map_it = |
1063 child_info.child_to_parent_map.find(it->id); | 1063 child_info.child_to_parent_map.find(it->id); |
1064 if (resource_in_map_it != child_info.child_to_parent_map.end()) { | 1064 if (resource_in_map_it != child_info.child_to_parent_map.end()) { |
1065 resources_[resource_in_map_it->second].imported_count++; | 1065 resources_[resource_in_map_it->second].imported_count++; |
1066 continue; | 1066 continue; |
1067 } | 1067 } |
1068 | 1068 |
1069 scoped_ptr<SharedBitmap> bitmap; | 1069 scoped_ptr<SharedBitmap> bitmap; |
1070 uint8_t* pixels = NULL; | 1070 uint8_t* pixels = NULL; |
1071 if (it->is_software) { | 1071 if (it->is_software) { |
1072 if (shared_bitmap_manager_) | 1072 if (shared_bitmap_manager_) { |
1073 bitmap = shared_bitmap_manager_->GetSharedBitmapFromId(it->size, | 1073 bitmap = shared_bitmap_manager_->GetSharedBitmapFromId( |
1074 it->mailbox); | 1074 it->size, it->mailbox_holder.mailbox); |
| 1075 } |
1075 if (bitmap) | 1076 if (bitmap) |
1076 pixels = bitmap->pixels(); | 1077 pixels = bitmap->pixels(); |
1077 } | 1078 } |
1078 | 1079 |
1079 if ((!it->is_software && !gl) || (it->is_software && !pixels)) { | 1080 if ((!it->is_software && !gl) || (it->is_software && !pixels)) { |
1080 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); | 1081 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); |
1081 ReturnedResourceArray to_return; | 1082 ReturnedResourceArray to_return; |
1082 to_return.push_back(it->ToReturnedResource()); | 1083 to_return.push_back(it->ToReturnedResource()); |
1083 child_info.return_callback.Run(to_return); | 1084 child_info.return_callback.Run(to_return); |
1084 continue; | 1085 continue; |
1085 } | 1086 } |
1086 | 1087 |
1087 ResourceId local_id = next_id_++; | 1088 ResourceId local_id = next_id_++; |
1088 Resource& resource = resources_[local_id]; | 1089 Resource& resource = resources_[local_id]; |
1089 if (it->is_software) { | 1090 if (it->is_software) { |
1090 resource = Resource( | 1091 resource = Resource( |
1091 pixels, bitmap.release(), it->size, GL_LINEAR, GL_CLAMP_TO_EDGE); | 1092 pixels, bitmap.release(), it->size, GL_LINEAR, GL_CLAMP_TO_EDGE); |
1092 } else { | 1093 } else { |
1093 resource = Resource(0, | 1094 resource = Resource(0, |
1094 it->size, | 1095 it->size, |
1095 it->target, | 1096 it->mailbox_holder.texture_target, |
1096 it->filter, | 1097 it->filter, |
1097 0, | 1098 0, |
1098 GL_CLAMP_TO_EDGE, | 1099 GL_CLAMP_TO_EDGE, |
1099 TextureUsageAny, | 1100 TextureUsageAny, |
1100 it->format); | 1101 it->format); |
1101 resource.mailbox = | 1102 resource.mailbox = TextureMailbox(it->mailbox_holder.mailbox, |
1102 TextureMailbox(it->mailbox, it->target, it->sync_point); | 1103 it->mailbox_holder.texture_target, |
| 1104 it->mailbox_holder.sync_point); |
1103 } | 1105 } |
1104 resource.child_id = child; | 1106 resource.child_id = child; |
1105 resource.origin = Resource::Delegated; | 1107 resource.origin = Resource::Delegated; |
1106 // Don't allocate a texture for a child. | 1108 // Don't allocate a texture for a child. |
1107 resource.allocated = true; | 1109 resource.allocated = true; |
1108 resource.imported_count = 1; | 1110 resource.imported_count = 1; |
1109 child_info.parent_to_child_map[local_id] = it->id; | 1111 child_info.parent_to_child_map[local_id] = it->id; |
1110 child_info.child_to_parent_map[it->id] = local_id; | 1112 child_info.child_to_parent_map[it->id] = local_id; |
1111 } | 1113 } |
1112 } | 1114 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 | 1206 |
1205 if (returned.sync_point) { | 1207 if (returned.sync_point) { |
1206 DCHECK(!resource->shared_bitmap); | 1208 DCHECK(!resource->shared_bitmap); |
1207 if (resource->origin == Resource::Internal) { | 1209 if (resource->origin == Resource::Internal) { |
1208 DCHECK(resource->gl_id); | 1210 DCHECK(resource->gl_id); |
1209 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); | 1211 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); |
1210 } else { | 1212 } else { |
1211 // Because CreateResourceFromExternalTexture() never be called, | 1213 // Because CreateResourceFromExternalTexture() never be called, |
1212 // when enabling delegated compositor. | 1214 // when enabling delegated compositor. |
1213 DCHECK(!resource->gl_id); | 1215 DCHECK(!resource->gl_id); |
1214 resource->mailbox = | 1216 resource->mailbox.set_sync_point(returned.sync_point); |
1215 TextureMailbox(resource->mailbox.name(), | |
1216 resource->mailbox.target(), | |
1217 returned.sync_point); | |
1218 } | 1217 } |
1219 } | 1218 } |
1220 | 1219 |
1221 if (!resource->marked_for_deletion) | 1220 if (!resource->marked_for_deletion) |
1222 continue; | 1221 continue; |
1223 | 1222 |
1224 if (!resource->child_id) { | 1223 if (!resource->child_id) { |
1225 // The resource belongs to this ResourceProvider, so it can be destroyed. | 1224 // The resource belongs to this ResourceProvider, so it can be destroyed. |
1226 DeleteResourceInternal(map_iterator, Normal); | 1225 DeleteResourceInternal(map_iterator, Normal); |
1227 continue; | 1226 continue; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 DCHECK(!source->lock_for_read_count); | 1260 DCHECK(!source->lock_for_read_count); |
1262 // Because CreateResourceFromExternalTexture() never be called, | 1261 // Because CreateResourceFromExternalTexture() never be called, |
1263 // when enabling delegated compositor. | 1262 // when enabling delegated compositor. |
1264 DCHECK(source->origin == Resource::Internal || | 1263 DCHECK(source->origin == Resource::Internal || |
1265 source->origin == Resource::Delegated || | 1264 source->origin == Resource::Delegated || |
1266 (source->origin == Resource::External && source->mailbox.IsValid())); | 1265 (source->origin == Resource::External && source->mailbox.IsValid())); |
1267 DCHECK(source->allocated); | 1266 DCHECK(source->allocated); |
1268 DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE); | 1267 DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE); |
1269 resource->id = id; | 1268 resource->id = id; |
1270 resource->format = source->format; | 1269 resource->format = source->format; |
1271 resource->target = source->target; | 1270 resource->mailbox_holder.texture_target = source->target; |
1272 resource->filter = source->filter; | 1271 resource->filter = source->filter; |
1273 resource->size = source->size; | 1272 resource->size = source->size; |
1274 | 1273 |
1275 if (source->shared_bitmap) { | 1274 if (source->shared_bitmap) { |
1276 resource->mailbox = source->shared_bitmap->id(); | 1275 resource->mailbox_holder.mailbox = source->shared_bitmap->id(); |
1277 resource->is_software = true; | 1276 resource->is_software = true; |
1278 } else if (!source->mailbox.IsValid()) { | 1277 } else if (!source->mailbox.IsValid()) { |
1279 LazyCreate(source); | 1278 LazyCreate(source); |
1280 DCHECK(source->gl_id); | 1279 DCHECK(source->gl_id); |
1281 DCHECK(source->origin == Resource::Internal); | 1280 DCHECK(source->origin == Resource::Internal); |
1282 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); | 1281 GLC(gl, |
| 1282 gl->BindTexture(resource->mailbox_holder.texture_target, |
| 1283 source->gl_id)); |
1283 if (source->image_id) { | 1284 if (source->image_id) { |
1284 DCHECK(source->dirty_image); | 1285 DCHECK(source->dirty_image); |
1285 BindImageForSampling(source); | 1286 BindImageForSampling(source); |
1286 } | 1287 } |
1287 // This is a resource allocated by the compositor, we need to produce it. | 1288 // This is a resource allocated by the compositor, we need to produce it. |
1288 // Don't set a sync point, the caller will do it. | 1289 // Don't set a sync point, the caller will do it. |
1289 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox.name)); | 1290 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name)); |
1290 GLC(gl, | 1291 GLC(gl, |
1291 gl->ProduceTextureCHROMIUM(resource->target, resource->mailbox.name)); | 1292 gl->ProduceTextureCHROMIUM(resource->mailbox_holder.texture_target, |
1292 source->mailbox.SetName(resource->mailbox); | 1293 resource->mailbox_holder.mailbox.name)); |
| 1294 source->mailbox = TextureMailbox(resource->mailbox_holder); |
1293 } else { | 1295 } else { |
1294 DCHECK(source->mailbox.IsTexture()); | 1296 DCHECK(source->mailbox.IsTexture()); |
1295 if (source->image_id && source->dirty_image) { | 1297 if (source->image_id && source->dirty_image) { |
1296 DCHECK(source->gl_id); | 1298 DCHECK(source->gl_id); |
1297 DCHECK(source->origin == Resource::Internal); | 1299 DCHECK(source->origin == Resource::Internal); |
1298 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); | 1300 GLC(gl, |
| 1301 gl->BindTexture(resource->mailbox_holder.texture_target, |
| 1302 source->gl_id)); |
1299 BindImageForSampling(source); | 1303 BindImageForSampling(source); |
1300 } | 1304 } |
1301 // This is either an external resource, or a compositor resource that we | 1305 // This is either an external resource, or a compositor resource that we |
1302 // already exported. Make sure to forward the sync point that we were given. | 1306 // already exported. Make sure to forward the sync point that we were given. |
1303 resource->mailbox = source->mailbox.name(); | 1307 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); |
1304 resource->sync_point = source->mailbox.sync_point(); | 1308 resource->mailbox_holder.texture_target = source->mailbox.target(); |
1305 source->mailbox.ResetSyncPoint(); | 1309 resource->mailbox_holder.sync_point = source->mailbox.sync_point(); |
| 1310 source->mailbox.set_sync_point(0); |
1306 } | 1311 } |
1307 } | 1312 } |
1308 | 1313 |
1309 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( | 1314 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( |
1310 ChildMap::iterator child_it, | 1315 ChildMap::iterator child_it, |
1311 DeleteStyle style, | 1316 DeleteStyle style, |
1312 const ResourceIdArray& unused) { | 1317 const ResourceIdArray& unused) { |
1313 DCHECK(thread_checker_.CalledOnValidThread()); | 1318 DCHECK(thread_checker_.CalledOnValidThread()); |
1314 DCHECK(child_it != children_.end()); | 1319 DCHECK(child_it != children_.end()); |
1315 Child* child_info = &child_it->second; | 1320 Child* child_info = &child_it->second; |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1851 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1847 return active_unit; | 1852 return active_unit; |
1848 } | 1853 } |
1849 | 1854 |
1850 GLES2Interface* ResourceProvider::ContextGL() const { | 1855 GLES2Interface* ResourceProvider::ContextGL() const { |
1851 ContextProvider* context_provider = output_surface_->context_provider(); | 1856 ContextProvider* context_provider = output_surface_->context_provider(); |
1852 return context_provider ? context_provider->ContextGL() : NULL; | 1857 return context_provider ? context_provider->ContextGL() : NULL; |
1853 } | 1858 } |
1854 | 1859 |
1855 } // namespace cc | 1860 } // namespace cc |
OLD | NEW |