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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 GLES2Interface* gl = ContextGL(); | 537 GLES2Interface* gl = ContextGL(); |
538 DCHECK(gl); | 538 DCHECK(gl); |
539 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); | 539 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); |
540 } | 540 } |
541 if (resource->gl_pixel_buffer_id) { | 541 if (resource->gl_pixel_buffer_id) { |
542 GLES2Interface* gl = ContextGL(); | 542 GLES2Interface* gl = ContextGL(); |
543 DCHECK(gl); | 543 DCHECK(gl); |
544 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); | 544 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); |
545 } | 545 } |
546 if (resource->mailbox.IsValid() && resource->external) { | 546 if (resource->mailbox.IsValid() && resource->external) { |
547 GLuint sync_point = resource->mailbox.sync_point(); | 547 uint32 sync_point = resource->mailbox.sync_point(); |
548 if (resource->mailbox.IsTexture()) { | 548 if (resource->mailbox.IsTexture()) { |
549 lost_resource |= lost_output_surface_; | 549 lost_resource |= lost_output_surface_; |
550 GLES2Interface* gl = ContextGL(); | 550 GLES2Interface* gl = ContextGL(); |
551 DCHECK(gl); | 551 DCHECK(gl); |
552 if (resource->gl_id) | 552 if (resource->gl_id) |
553 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); | 553 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
554 if (!lost_resource && resource->gl_id) | 554 if (!lost_resource && resource->gl_id) |
555 sync_point = gl->InsertSyncPointCHROMIUM(); | 555 sync_point = gl->InsertSyncPointCHROMIUM(); |
556 } else { | 556 } else { |
557 DCHECK(resource->mailbox.IsSharedMemory()); | 557 DCHECK(resource->mailbox.IsSharedMemory()); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 DCHECK(resource->allocated); | 732 DCHECK(resource->allocated); |
733 | 733 |
734 LazyCreate(resource); | 734 LazyCreate(resource); |
735 | 735 |
736 if (resource->external) { | 736 if (resource->external) { |
737 if (!resource->gl_id && resource->mailbox.IsTexture()) { | 737 if (!resource->gl_id && resource->mailbox.IsTexture()) { |
738 GLES2Interface* gl = ContextGL(); | 738 GLES2Interface* gl = ContextGL(); |
739 DCHECK(gl); | 739 DCHECK(gl); |
740 if (resource->mailbox.sync_point()) { | 740 if (resource->mailbox.sync_point()) { |
741 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); | 741 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); |
742 resource->mailbox.ResetSyncPoint(); | 742 resource->mailbox.set_sync_point(0); |
743 } | 743 } |
744 resource->gl_id = texture_id_allocator_->NextId(); | 744 resource->gl_id = texture_id_allocator_->NextId(); |
745 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); | 745 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); |
746 GLC(gl, | 746 GLC(gl, |
747 gl->ConsumeTextureCHROMIUM(resource->target, | 747 gl->ConsumeTextureCHROMIUM(resource->target, |
748 resource->mailbox.data())); | 748 resource->mailbox.mailbox().name)); |
danakj
2014/01/06 20:13:42
Law of Demeter is sad about this. Can we have a na
sheu
2014/01/06 22:44:44
We need to have the mailbox() accessible for other
danakj
2014/01/06 23:28:33
As it's just an accessor, I'd prefer a 2nd path he
sheu
2014/01/07 01:41:00
Done.
| |
749 } | 749 } |
750 } | 750 } |
751 | 751 |
752 resource->lock_for_read_count++; | 752 resource->lock_for_read_count++; |
753 if (resource->enable_read_lock_fences) | 753 if (resource->enable_read_lock_fences) |
754 resource->read_lock_fence = current_read_lock_fence_; | 754 resource->read_lock_fence = current_read_lock_fence_; |
755 | 755 |
756 return resource; | 756 return resource; |
757 } | 757 } |
758 | 758 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, | 1014 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, |
1015 TransferableResourceArray* list) { | 1015 TransferableResourceArray* list) { |
1016 DCHECK(thread_checker_.CalledOnValidThread()); | 1016 DCHECK(thread_checker_.CalledOnValidThread()); |
1017 GLES2Interface* gl = ContextGL(); | 1017 GLES2Interface* gl = ContextGL(); |
1018 bool need_sync_point = false; | 1018 bool need_sync_point = false; |
1019 for (ResourceIdArray::const_iterator it = resources.begin(); | 1019 for (ResourceIdArray::const_iterator it = resources.begin(); |
1020 it != resources.end(); | 1020 it != resources.end(); |
1021 ++it) { | 1021 ++it) { |
1022 TransferableResource resource; | 1022 TransferableResource resource; |
1023 TransferResource(gl, *it, &resource); | 1023 TransferResource(gl, *it, &resource); |
1024 if (!resource.sync_point && !resource.is_software) | 1024 if (!resource.mailbox_holder.sync_point && !resource.is_software) |
1025 need_sync_point = true; | 1025 need_sync_point = true; |
1026 ++resources_.find(*it)->second.exported_count; | 1026 ++resources_.find(*it)->second.exported_count; |
1027 list->push_back(resource); | 1027 list->push_back(resource); |
1028 } | 1028 } |
1029 if (need_sync_point) { | 1029 if (need_sync_point) { |
1030 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); | 1030 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); |
1031 for (TransferableResourceArray::iterator it = list->begin(); | 1031 for (TransferableResourceArray::iterator it = list->begin(); |
1032 it != list->end(); | 1032 it != list->end(); |
1033 ++it) { | 1033 ++it) { |
1034 if (!it->sync_point) | 1034 if (!it->mailbox_holder.sync_point) |
1035 it->sync_point = sync_point; | 1035 it->mailbox_holder.sync_point = sync_point; |
1036 } | 1036 } |
1037 } | 1037 } |
1038 } | 1038 } |
1039 | 1039 |
1040 void ResourceProvider::ReceiveFromChild( | 1040 void ResourceProvider::ReceiveFromChild( |
1041 int child, const TransferableResourceArray& resources) { | 1041 int child, const TransferableResourceArray& resources) { |
1042 DCHECK(thread_checker_.CalledOnValidThread()); | 1042 DCHECK(thread_checker_.CalledOnValidThread()); |
1043 GLES2Interface* gl = ContextGL(); | 1043 GLES2Interface* gl = ContextGL(); |
1044 Child& child_info = children_.find(child)->second; | 1044 Child& child_info = children_.find(child)->second; |
1045 DCHECK(!child_info.marked_for_deletion); | 1045 DCHECK(!child_info.marked_for_deletion); |
1046 for (TransferableResourceArray::const_iterator it = resources.begin(); | 1046 for (TransferableResourceArray::const_iterator it = resources.begin(); |
1047 it != resources.end(); | 1047 it != resources.end(); |
1048 ++it) { | 1048 ++it) { |
1049 ResourceIdMap::iterator resource_in_map_it = | 1049 ResourceIdMap::iterator resource_in_map_it = |
1050 child_info.child_to_parent_map.find(it->id); | 1050 child_info.child_to_parent_map.find(it->id); |
1051 if (resource_in_map_it != child_info.child_to_parent_map.end()) { | 1051 if (resource_in_map_it != child_info.child_to_parent_map.end()) { |
1052 resources_[resource_in_map_it->second].imported_count++; | 1052 resources_[resource_in_map_it->second].imported_count++; |
1053 continue; | 1053 continue; |
1054 } | 1054 } |
1055 | 1055 |
1056 scoped_ptr<SharedBitmap> bitmap; | 1056 scoped_ptr<SharedBitmap> bitmap; |
1057 uint8_t* pixels = NULL; | 1057 uint8_t* pixels = NULL; |
1058 if (it->is_software) { | 1058 if (it->is_software) { |
1059 if (shared_bitmap_manager_) | 1059 if (shared_bitmap_manager_) { |
1060 bitmap = shared_bitmap_manager_->GetSharedBitmapFromId(it->size, | 1060 bitmap = shared_bitmap_manager_->GetSharedBitmapFromId( |
1061 it->mailbox); | 1061 it->size, it->mailbox_holder.mailbox); |
1062 } | |
1062 if (bitmap) | 1063 if (bitmap) |
1063 pixels = bitmap->pixels(); | 1064 pixels = bitmap->pixels(); |
1064 } | 1065 } |
1065 | 1066 |
1066 if ((!it->is_software && !gl) || (it->is_software && !pixels)) { | 1067 if ((!it->is_software && !gl) || (it->is_software && !pixels)) { |
1067 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); | 1068 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); |
1068 ReturnedResourceArray to_return; | 1069 ReturnedResourceArray to_return; |
1069 to_return.push_back(it->ToReturnedResource()); | 1070 to_return.push_back(it->ToReturnedResource()); |
1070 child_info.return_callback.Run(to_return); | 1071 child_info.return_callback.Run(to_return); |
1071 continue; | 1072 continue; |
1072 } | 1073 } |
1073 | 1074 |
1074 ResourceId local_id = next_id_++; | 1075 ResourceId local_id = next_id_++; |
1075 Resource& resource = resources_[local_id]; | 1076 Resource& resource = resources_[local_id]; |
1076 if (it->is_software) { | 1077 if (it->is_software) { |
1077 resource = Resource( | 1078 resource = Resource( |
1078 pixels, bitmap.release(), it->size, GL_LINEAR, GL_CLAMP_TO_EDGE); | 1079 pixels, bitmap.release(), it->size, GL_LINEAR, GL_CLAMP_TO_EDGE); |
1079 } else { | 1080 } else { |
1080 GLuint texture_id; | 1081 GLuint texture_id; |
1081 // NOTE: If the parent is a browser and the child a renderer, the parent | 1082 // NOTE: If the parent is a browser and the child a renderer, the parent |
1082 // is not supposed to have its context wait, because that could induce | 1083 // is not supposed to have its context wait, because that could induce |
1083 // deadlocks and/or security issues. The caller is responsible for | 1084 // deadlocks and/or security issues. The caller is responsible for |
1084 // waiting asynchronously, and resetting sync_point before calling this. | 1085 // waiting asynchronously, and resetting sync_point before calling this. |
1085 // However if the parent is a renderer (e.g. browser tag), it may be ok | 1086 // However if the parent is a renderer (e.g. browser tag), it may be ok |
1086 // (and is simpler) to wait. | 1087 // (and is simpler) to wait. |
1087 if (it->sync_point) | 1088 if (it->mailbox_holder.sync_point) |
1088 GLC(gl, gl->WaitSyncPointCHROMIUM(it->sync_point)); | 1089 GLC(gl, gl->WaitSyncPointCHROMIUM(it->mailbox_holder.sync_point)); |
1089 texture_id = texture_id_allocator_->NextId(); | 1090 texture_id = texture_id_allocator_->NextId(); |
1090 GLC(gl, gl->BindTexture(it->target, texture_id)); | 1091 GLC(gl, gl->BindTexture(it->mailbox_holder.texture_target, texture_id)); |
1091 GLC(gl, gl->ConsumeTextureCHROMIUM(it->target, it->mailbox.name)); | 1092 GLC(gl, |
1093 gl->ConsumeTextureCHROMIUM(it->mailbox_holder.texture_target, | |
1094 it->mailbox_holder.mailbox.name)); | |
1092 resource = Resource(texture_id, | 1095 resource = Resource(texture_id, |
1093 it->size, | 1096 it->size, |
1094 it->target, | 1097 it->mailbox_holder.texture_target, |
1095 it->filter, | 1098 it->filter, |
1096 0, | 1099 0, |
1097 GL_CLAMP_TO_EDGE, | 1100 GL_CLAMP_TO_EDGE, |
1098 TextureUsageAny, | 1101 TextureUsageAny, |
1099 it->format); | 1102 it->format); |
1100 resource.mailbox.SetName(it->mailbox); | 1103 resource.mailbox = TextureMailbox( |
1104 it->mailbox_holder.mailbox, it->mailbox_holder.texture_target, 0); | |
1101 } | 1105 } |
1102 resource.child_id = child; | 1106 resource.child_id = child; |
1103 // Don't allocate a texture for a child. | 1107 // Don't allocate a texture for a child. |
1104 resource.allocated = true; | 1108 resource.allocated = true; |
1105 resource.imported_count = 1; | 1109 resource.imported_count = 1; |
1106 child_info.parent_to_child_map[local_id] = it->id; | 1110 child_info.parent_to_child_map[local_id] = it->id; |
1107 child_info.child_to_parent_map[it->id] = local_id; | 1111 child_info.child_to_parent_map[it->id] = local_id; |
1108 } | 1112 } |
1109 } | 1113 } |
1110 | 1114 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 CHECK_GE(resource->exported_count, returned.count); | 1195 CHECK_GE(resource->exported_count, returned.count); |
1192 resource->exported_count -= returned.count; | 1196 resource->exported_count -= returned.count; |
1193 resource->lost |= returned.lost; | 1197 resource->lost |= returned.lost; |
1194 if (resource->exported_count) | 1198 if (resource->exported_count) |
1195 continue; | 1199 continue; |
1196 | 1200 |
1197 if (resource->gl_id) { | 1201 if (resource->gl_id) { |
1198 if (returned.sync_point) | 1202 if (returned.sync_point) |
1199 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); | 1203 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); |
1200 } else if (!resource->shared_bitmap) { | 1204 } else if (!resource->shared_bitmap) { |
1201 resource->mailbox = | 1205 resource->mailbox.set_sync_point(returned.sync_point); |
1202 TextureMailbox(resource->mailbox.name(), returned.sync_point); | |
1203 } | 1206 } |
1204 | 1207 |
1205 if (!resource->marked_for_deletion) | 1208 if (!resource->marked_for_deletion) |
1206 continue; | 1209 continue; |
1207 | 1210 |
1208 if (!resource->child_id) { | 1211 if (!resource->child_id) { |
1209 // The resource belongs to this ResourceProvider, so it can be destroyed. | 1212 // The resource belongs to this ResourceProvider, so it can be destroyed. |
1210 DeleteResourceInternal(map_iterator, Normal); | 1213 DeleteResourceInternal(map_iterator, Normal); |
1211 continue; | 1214 continue; |
1212 } | 1215 } |
(...skipping 27 matching lines...) Expand all Loading... | |
1240 ResourceId id, | 1243 ResourceId id, |
1241 TransferableResource* resource) { | 1244 TransferableResource* resource) { |
1242 Resource* source = GetResource(id); | 1245 Resource* source = GetResource(id); |
1243 DCHECK(!source->locked_for_write); | 1246 DCHECK(!source->locked_for_write); |
1244 DCHECK(!source->lock_for_read_count); | 1247 DCHECK(!source->lock_for_read_count); |
1245 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); | 1248 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); |
1246 DCHECK(source->allocated); | 1249 DCHECK(source->allocated); |
1247 DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE); | 1250 DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE); |
1248 resource->id = id; | 1251 resource->id = id; |
1249 resource->format = source->format; | 1252 resource->format = source->format; |
1250 resource->target = source->target; | 1253 resource->mailbox_holder.texture_target = source->target; |
1251 resource->filter = source->filter; | 1254 resource->filter = source->filter; |
1252 resource->size = source->size; | 1255 resource->size = source->size; |
1253 | 1256 |
1254 if (source->shared_bitmap) { | 1257 if (source->shared_bitmap) { |
1255 resource->mailbox = source->shared_bitmap->id(); | 1258 resource->mailbox_holder.mailbox = source->shared_bitmap->id(); |
1256 resource->is_software = true; | 1259 resource->is_software = true; |
1257 } else if (!source->mailbox.IsValid()) { | 1260 } else if (!source->mailbox.IsValid()) { |
1258 // This is a resource allocated by the compositor, we need to produce it. | 1261 // This is a resource allocated by the compositor, we need to produce it. |
1259 // Don't set a sync point, the caller will do it. | 1262 // Don't set a sync point, the caller will do it. |
1260 DCHECK(source->gl_id); | 1263 DCHECK(source->gl_id); |
1261 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); | |
1262 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox.name)); | |
1263 GLC(gl, | 1264 GLC(gl, |
1264 gl->ProduceTextureCHROMIUM(resource->target, resource->mailbox.name)); | 1265 gl->BindTexture(resource->mailbox_holder.texture_target, |
1265 source->mailbox.SetName(resource->mailbox); | 1266 source->gl_id)); |
1267 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name)); | |
1268 GLC(gl, | |
1269 gl->ProduceTextureCHROMIUM(resource->mailbox_holder.texture_target, | |
1270 resource->mailbox_holder.mailbox.name)); | |
1271 source->mailbox = TextureMailbox(resource->mailbox_holder); | |
1266 } else { | 1272 } else { |
1267 DCHECK(source->mailbox.IsTexture()); | 1273 DCHECK(source->mailbox.IsTexture()); |
1268 // This is either an external resource, or a compositor resource that we | 1274 // This is either an external resource, or a compositor resource that we |
1269 // already exported. Make sure to forward the sync point that we were given. | 1275 // already exported. Make sure to forward the sync point that we were given. |
1270 resource->mailbox = source->mailbox.name(); | 1276 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); |
1271 resource->sync_point = source->mailbox.sync_point(); | 1277 resource->mailbox_holder.texture_target = source->mailbox.target(); |
1272 source->mailbox.ResetSyncPoint(); | 1278 resource->mailbox_holder.sync_point = source->mailbox.sync_point(); |
1279 source->mailbox.set_sync_point(0); | |
1273 } | 1280 } |
1274 } | 1281 } |
1275 | 1282 |
1276 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( | 1283 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( |
1277 ChildMap::iterator child_it, | 1284 ChildMap::iterator child_it, |
1278 DeleteStyle style, | 1285 DeleteStyle style, |
1279 const ResourceIdArray& unused) { | 1286 const ResourceIdArray& unused) { |
1280 DCHECK(thread_checker_.CalledOnValidThread()); | 1287 DCHECK(thread_checker_.CalledOnValidThread()); |
1281 DCHECK(child_it != children_.end()); | 1288 DCHECK(child_it != children_.end()); |
1282 Child* child_info = &child_it->second; | 1289 Child* child_info = &child_it->second; |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1804 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1811 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1805 return active_unit; | 1812 return active_unit; |
1806 } | 1813 } |
1807 | 1814 |
1808 GLES2Interface* ResourceProvider::ContextGL() const { | 1815 GLES2Interface* ResourceProvider::ContextGL() const { |
1809 ContextProvider* context_provider = output_surface_->context_provider(); | 1816 ContextProvider* context_provider = output_surface_->context_provider(); |
1810 return context_provider ? context_provider->ContextGL() : NULL; | 1817 return context_provider ? context_provider->ContextGL() : NULL; |
1811 } | 1818 } |
1812 | 1819 |
1813 } // namespace cc | 1820 } // namespace cc |
OLD | NEW |