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/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 } | 558 } |
559 if (resource->gl_pixel_buffer_id) { | 559 if (resource->gl_pixel_buffer_id) { |
560 DCHECK(resource->origin == Resource::INTERNAL); | 560 DCHECK(resource->origin == Resource::INTERNAL); |
561 GLES2Interface* gl = ContextGL(); | 561 GLES2Interface* gl = ContextGL(); |
562 DCHECK(gl); | 562 DCHECK(gl); |
563 gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id); | 563 gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id); |
564 } | 564 } |
565 if (resource->origin == Resource::EXTERNAL) { | 565 if (resource->origin == Resource::EXTERNAL) { |
566 DCHECK(resource->mailbox.IsValid()); | 566 DCHECK(resource->mailbox.IsValid()); |
567 GLuint sync_point = resource->mailbox.sync_point(); | 567 GLuint sync_point = resource->mailbox.sync_point(); |
| 568 gpu::SyncToken sync_token; |
568 if (resource->type == RESOURCE_TYPE_GL_TEXTURE) { | 569 if (resource->type == RESOURCE_TYPE_GL_TEXTURE) { |
569 DCHECK(resource->mailbox.IsTexture()); | 570 DCHECK(resource->mailbox.IsTexture()); |
570 lost_resource |= lost_output_surface_; | 571 lost_resource |= lost_output_surface_; |
571 GLES2Interface* gl = ContextGL(); | 572 GLES2Interface* gl = ContextGL(); |
572 DCHECK(gl); | 573 DCHECK(gl); |
573 if (resource->gl_id) { | 574 if (resource->gl_id) { |
574 gl->DeleteTextures(1, &resource->gl_id); | 575 gl->DeleteTextures(1, &resource->gl_id); |
575 resource->gl_id = 0; | 576 resource->gl_id = 0; |
576 if (!lost_resource) | 577 if (!lost_resource) |
577 sync_point = gl->InsertSyncPointCHROMIUM(); | 578 sync_point = gl->InsertSyncPointCHROMIUM(); |
578 } | 579 } |
579 } else { | 580 } else { |
580 DCHECK(resource->mailbox.IsSharedMemory()); | 581 DCHECK(resource->mailbox.IsSharedMemory()); |
581 resource->shared_bitmap = nullptr; | 582 resource->shared_bitmap = nullptr; |
582 resource->pixels = nullptr; | 583 resource->pixels = nullptr; |
583 } | 584 } |
584 resource->release_callback_impl.Run( | 585 resource->release_callback_impl.Run(sync_point, sync_token, lost_resource, |
585 sync_point, lost_resource, blocking_main_thread_task_runner_); | 586 blocking_main_thread_task_runner_); |
586 } | 587 } |
587 if (resource->gl_id) { | 588 if (resource->gl_id) { |
588 GLES2Interface* gl = ContextGL(); | 589 GLES2Interface* gl = ContextGL(); |
589 DCHECK(gl); | 590 DCHECK(gl); |
590 gl->DeleteTextures(1, &resource->gl_id); | 591 gl->DeleteTextures(1, &resource->gl_id); |
591 resource->gl_id = 0; | 592 resource->gl_id = 0; |
592 } | 593 } |
593 if (resource->shared_bitmap) { | 594 if (resource->shared_bitmap) { |
594 DCHECK(resource->origin != Resource::EXTERNAL); | 595 DCHECK(resource->origin != Resource::EXTERNAL); |
595 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 596 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 | 687 |
687 LazyCreate(resource); | 688 LazyCreate(resource); |
688 | 689 |
689 if (resource->type == RESOURCE_TYPE_GL_TEXTURE && !resource->gl_id) { | 690 if (resource->type == RESOURCE_TYPE_GL_TEXTURE && !resource->gl_id) { |
690 DCHECK(resource->origin != Resource::INTERNAL); | 691 DCHECK(resource->origin != Resource::INTERNAL); |
691 DCHECK(resource->mailbox.IsTexture()); | 692 DCHECK(resource->mailbox.IsTexture()); |
692 | 693 |
693 // Mailbox sync_points must be processed by a call to | 694 // Mailbox sync_points must be processed by a call to |
694 // WaitSyncPointIfNeeded() prior to calling LockForRead(). | 695 // WaitSyncPointIfNeeded() prior to calling LockForRead(). |
695 DCHECK(!resource->mailbox.sync_point()); | 696 DCHECK(!resource->mailbox.sync_point()); |
| 697 DCHECK(!resource->mailbox.sync_token().HasData()); |
696 | 698 |
697 GLES2Interface* gl = ContextGL(); | 699 GLES2Interface* gl = ContextGL(); |
698 DCHECK(gl); | 700 DCHECK(gl); |
699 resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM( | 701 resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM( |
700 resource->mailbox.target(), resource->mailbox.name()); | 702 resource->mailbox.target(), resource->mailbox.name()); |
701 } | 703 } |
702 | 704 |
703 if (!resource->pixels && resource->has_shared_bitmap_id && | 705 if (!resource->pixels && resource->has_shared_bitmap_id && |
704 shared_bitmap_manager_) { | 706 shared_bitmap_manager_) { |
705 scoped_ptr<SharedBitmap> bitmap = | 707 scoped_ptr<SharedBitmap> bitmap = |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, | 1137 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, |
1136 TransferableResourceArray* list) { | 1138 TransferableResourceArray* list) { |
1137 DCHECK(thread_checker_.CalledOnValidThread()); | 1139 DCHECK(thread_checker_.CalledOnValidThread()); |
1138 GLES2Interface* gl = ContextGL(); | 1140 GLES2Interface* gl = ContextGL(); |
1139 bool need_sync_point = false; | 1141 bool need_sync_point = false; |
1140 for (ResourceIdArray::const_iterator it = resources.begin(); | 1142 for (ResourceIdArray::const_iterator it = resources.begin(); |
1141 it != resources.end(); | 1143 it != resources.end(); |
1142 ++it) { | 1144 ++it) { |
1143 TransferableResource resource; | 1145 TransferableResource resource; |
1144 TransferResource(gl, *it, &resource); | 1146 TransferResource(gl, *it, &resource); |
1145 if (!resource.mailbox_holder.sync_point && !resource.is_software) | 1147 need_sync_point |= (!resource.mailbox_holder.sync_point && |
1146 need_sync_point = true; | 1148 !resource.mailbox_holder.sync_token.HasData() && |
| 1149 !resource.is_software); |
1147 ++resources_.find(*it)->second.exported_count; | 1150 ++resources_.find(*it)->second.exported_count; |
1148 list->push_back(resource); | 1151 list->push_back(resource); |
1149 } | 1152 } |
1150 if (need_sync_point && | 1153 if (need_sync_point && |
1151 output_surface_->capabilities().delegated_sync_points_required) { | 1154 output_surface_->capabilities().delegated_sync_points_required) { |
1152 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); | 1155 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); |
1153 for (TransferableResourceArray::iterator it = list->begin(); | 1156 for (TransferableResourceArray::iterator it = list->begin(); |
1154 it != list->end(); | 1157 it != list->end(); |
1155 ++it) { | 1158 ++it) { |
1156 if (!it->mailbox_holder.sync_point) | 1159 if (!it->mailbox_holder.sync_point) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 Resource* resource = nullptr; | 1194 Resource* resource = nullptr; |
1192 if (it->is_software) { | 1195 if (it->is_software) { |
1193 resource = InsertResource(local_id, | 1196 resource = InsertResource(local_id, |
1194 Resource(it->mailbox_holder.mailbox, it->size, | 1197 Resource(it->mailbox_holder.mailbox, it->size, |
1195 Resource::DELEGATED, GL_LINEAR)); | 1198 Resource::DELEGATED, GL_LINEAR)); |
1196 } else { | 1199 } else { |
1197 resource = InsertResource( | 1200 resource = InsertResource( |
1198 local_id, Resource(0, it->size, Resource::DELEGATED, | 1201 local_id, Resource(0, it->size, Resource::DELEGATED, |
1199 it->mailbox_holder.texture_target, it->filter, | 1202 it->mailbox_holder.texture_target, it->filter, |
1200 TEXTURE_HINT_IMMUTABLE, it->format)); | 1203 TEXTURE_HINT_IMMUTABLE, it->format)); |
1201 resource->mailbox = TextureMailbox(it->mailbox_holder.mailbox, | 1204 resource->mailbox = TextureMailbox( |
1202 it->mailbox_holder.texture_target, | 1205 it->mailbox_holder.mailbox, it->mailbox_holder.texture_target, |
1203 it->mailbox_holder.sync_point); | 1206 it->mailbox_holder.sync_point, it->mailbox_holder.sync_token); |
1204 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; | 1207 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; |
1205 resource->is_overlay_candidate = it->is_overlay_candidate; | 1208 resource->is_overlay_candidate = it->is_overlay_candidate; |
1206 } | 1209 } |
1207 resource->child_id = child; | 1210 resource->child_id = child; |
1208 // Don't allocate a texture for a child. | 1211 // Don't allocate a texture for a child. |
1209 resource->allocated = true; | 1212 resource->allocated = true; |
1210 resource->imported_count = 1; | 1213 resource->imported_count = 1; |
1211 child_info.parent_to_child_map[local_id] = it->id; | 1214 child_info.parent_to_child_map[local_id] = it->id; |
1212 child_info.child_to_parent_map[it->id] = local_id; | 1215 child_info.child_to_parent_map[it->id] = local_id; |
1213 } | 1216 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 continue; | 1254 continue; |
1252 | 1255 |
1253 Resource* resource = &map_iterator->second; | 1256 Resource* resource = &map_iterator->second; |
1254 | 1257 |
1255 CHECK_GE(resource->exported_count, returned.count); | 1258 CHECK_GE(resource->exported_count, returned.count); |
1256 resource->exported_count -= returned.count; | 1259 resource->exported_count -= returned.count; |
1257 resource->lost |= returned.lost; | 1260 resource->lost |= returned.lost; |
1258 if (resource->exported_count) | 1261 if (resource->exported_count) |
1259 continue; | 1262 continue; |
1260 | 1263 |
1261 if (returned.sync_point) { | 1264 if (returned.sync_point || returned.sync_token.HasData()) { |
1262 DCHECK(!resource->has_shared_bitmap_id); | 1265 DCHECK(!resource->has_shared_bitmap_id); |
1263 if (resource->origin == Resource::INTERNAL) { | 1266 if (resource->origin == Resource::INTERNAL) { |
1264 DCHECK(resource->gl_id); | 1267 DCHECK(resource->gl_id); |
1265 gl->WaitSyncPointCHROMIUM(returned.sync_point); | 1268 gl->WaitSyncPointCHROMIUM(returned.sync_point, |
| 1269 returned.sync_token.GetConstData()); |
1266 } else { | 1270 } else { |
1267 DCHECK(!resource->gl_id); | 1271 DCHECK(!resource->gl_id); |
1268 resource->mailbox.set_sync_point(returned.sync_point); | 1272 resource->mailbox.set_sync_point(returned.sync_point, |
| 1273 returned.sync_token); |
1269 } | 1274 } |
1270 } | 1275 } |
1271 | 1276 |
1272 if (!resource->marked_for_deletion) | 1277 if (!resource->marked_for_deletion) |
1273 continue; | 1278 continue; |
1274 | 1279 |
1275 if (!resource->child_id) { | 1280 if (!resource->child_id) { |
1276 // The resource belongs to this ResourceProvider, so it can be destroyed. | 1281 // The resource belongs to this ResourceProvider, so it can be destroyed. |
1277 DeleteResourceInternal(map_iterator, NORMAL); | 1282 DeleteResourceInternal(map_iterator, NORMAL); |
1278 continue; | 1283 continue; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 DCHECK(source->gl_id); | 1336 DCHECK(source->gl_id); |
1332 DCHECK(source->origin == Resource::INTERNAL); | 1337 DCHECK(source->origin == Resource::INTERNAL); |
1333 gl->BindTexture(resource->mailbox_holder.texture_target, source->gl_id); | 1338 gl->BindTexture(resource->mailbox_holder.texture_target, source->gl_id); |
1334 BindImageForSampling(source); | 1339 BindImageForSampling(source); |
1335 } | 1340 } |
1336 // This is either an external resource, or a compositor resource that we | 1341 // This is either an external resource, or a compositor resource that we |
1337 // already exported. Make sure to forward the sync point that we were given. | 1342 // already exported. Make sure to forward the sync point that we were given. |
1338 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); | 1343 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); |
1339 resource->mailbox_holder.texture_target = source->mailbox.target(); | 1344 resource->mailbox_holder.texture_target = source->mailbox.target(); |
1340 resource->mailbox_holder.sync_point = source->mailbox.sync_point(); | 1345 resource->mailbox_holder.sync_point = source->mailbox.sync_point(); |
1341 source->mailbox.set_sync_point(0); | 1346 resource->mailbox_holder.sync_token = source->mailbox.sync_token(); |
| 1347 source->mailbox.set_sync_point(0, gpu::SyncToken()); |
1342 } | 1348 } |
1343 } | 1349 } |
1344 | 1350 |
1345 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( | 1351 void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( |
1346 ChildMap::iterator child_it, | 1352 ChildMap::iterator child_it, |
1347 DeleteStyle style, | 1353 DeleteStyle style, |
1348 const ResourceIdArray& unused) { | 1354 const ResourceIdArray& unused) { |
1349 DCHECK(thread_checker_.CalledOnValidThread()); | 1355 DCHECK(thread_checker_.CalledOnValidThread()); |
1350 DCHECK(child_it != children_.end()); | 1356 DCHECK(child_it != children_.end()); |
1351 Child* child_info = &child_it->second; | 1357 Child* child_info = &child_it->second; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 gl->BindTexture(resource.target, resource.gl_id); | 1406 gl->BindTexture(resource.target, resource.gl_id); |
1401 gl->TexParameteri(resource.target, GL_TEXTURE_MIN_FILTER, | 1407 gl->TexParameteri(resource.target, GL_TEXTURE_MIN_FILTER, |
1402 resource.original_filter); | 1408 resource.original_filter); |
1403 gl->TexParameteri(resource.target, GL_TEXTURE_MAG_FILTER, | 1409 gl->TexParameteri(resource.target, GL_TEXTURE_MAG_FILTER, |
1404 resource.original_filter); | 1410 resource.original_filter); |
1405 } | 1411 } |
1406 | 1412 |
1407 ReturnedResource returned; | 1413 ReturnedResource returned; |
1408 returned.id = child_id; | 1414 returned.id = child_id; |
1409 returned.sync_point = resource.mailbox.sync_point(); | 1415 returned.sync_point = resource.mailbox.sync_point(); |
1410 if (!returned.sync_point && resource.type == RESOURCE_TYPE_GL_TEXTURE) | 1416 returned.sync_token = resource.mailbox.sync_token(); |
1411 need_sync_point = true; | 1417 need_sync_point |= |
| 1418 (!returned.sync_point && !returned.sync_token.HasData() && |
| 1419 resource.type == RESOURCE_TYPE_GL_TEXTURE); |
1412 returned.count = resource.imported_count; | 1420 returned.count = resource.imported_count; |
1413 returned.lost = is_lost; | 1421 returned.lost = is_lost; |
1414 to_return.push_back(returned); | 1422 to_return.push_back(returned); |
1415 | 1423 |
1416 child_info->parent_to_child_map.erase(local_id); | 1424 child_info->parent_to_child_map.erase(local_id); |
1417 child_info->child_to_parent_map.erase(child_id); | 1425 child_info->child_to_parent_map.erase(child_id); |
1418 resource.imported_count = 0; | 1426 resource.imported_count = 0; |
1419 DeleteResourceInternal(it, style); | 1427 DeleteResourceInternal(it, style); |
1420 } | 1428 } |
1421 if (need_sync_point && child_info->needs_sync_points) { | 1429 if (need_sync_point && child_info->needs_sync_points) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 resource->bound_image_id = resource->image_id; | 1554 resource->bound_image_id = resource->image_id; |
1547 resource->dirty_image = false; | 1555 resource->dirty_image = false; |
1548 } | 1556 } |
1549 | 1557 |
1550 void ResourceProvider::WaitSyncPointIfNeeded(ResourceId id) { | 1558 void ResourceProvider::WaitSyncPointIfNeeded(ResourceId id) { |
1551 Resource* resource = GetResource(id); | 1559 Resource* resource = GetResource(id); |
1552 DCHECK_EQ(resource->exported_count, 0); | 1560 DCHECK_EQ(resource->exported_count, 0); |
1553 DCHECK(resource->allocated); | 1561 DCHECK(resource->allocated); |
1554 if (resource->type != RESOURCE_TYPE_GL_TEXTURE || resource->gl_id) | 1562 if (resource->type != RESOURCE_TYPE_GL_TEXTURE || resource->gl_id) |
1555 return; | 1563 return; |
1556 if (!resource->mailbox.sync_point()) | 1564 if (resource->mailbox.sync_point() || |
1557 return; | 1565 resource->mailbox.sync_token().HasData()) { |
1558 DCHECK(resource->mailbox.IsValid()); | 1566 DCHECK(resource->mailbox.IsValid()); |
1559 GLES2Interface* gl = ContextGL(); | 1567 GLES2Interface* gl = ContextGL(); |
1560 DCHECK(gl); | 1568 DCHECK(gl); |
1561 gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point()); | 1569 gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point(), |
1562 resource->mailbox.set_sync_point(0); | 1570 resource->mailbox.sync_token().GetConstData()); |
| 1571 resource->mailbox.set_sync_point(0, gpu::SyncToken()); |
| 1572 } |
1563 } | 1573 } |
1564 | 1574 |
1565 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { | 1575 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { |
1566 GLint active_unit = 0; | 1576 GLint active_unit = 0; |
1567 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1577 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1568 return active_unit; | 1578 return active_unit; |
1569 } | 1579 } |
1570 | 1580 |
1571 GLenum ResourceProvider::GetImageTextureTarget(ResourceFormat format) { | 1581 GLenum ResourceProvider::GetImageTextureTarget(ResourceFormat format) { |
1572 gfx::BufferFormat buffer_format = BufferFormat(format); | 1582 gfx::BufferFormat buffer_format = BufferFormat(format); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 const int kImportance = 2; | 1650 const int kImportance = 2; |
1641 pmd->CreateSharedGlobalAllocatorDump(guid); | 1651 pmd->CreateSharedGlobalAllocatorDump(guid); |
1642 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1652 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
1643 } | 1653 } |
1644 } | 1654 } |
1645 | 1655 |
1646 return true; | 1656 return true; |
1647 } | 1657 } |
1648 | 1658 |
1649 } // namespace cc | 1659 } // namespace cc |
OLD | NEW |