| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 return; | 687 return; |
| 688 } else { | 688 } else { |
| 689 DeleteResourceInternal(it, NORMAL); | 689 DeleteResourceInternal(it, NORMAL); |
| 690 } | 690 } |
| 691 } | 691 } |
| 692 | 692 |
| 693 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 693 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| 694 DeleteStyle style) { | 694 DeleteStyle style) { |
| 695 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); | 695 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); |
| 696 Resource* resource = &it->second; | 696 Resource* resource = &it->second; |
| 697 bool lost_resource = resource->lost; |
| 698 |
| 697 DCHECK(resource->exported_count == 0 || style != NORMAL); | 699 DCHECK(resource->exported_count == 0 || style != NORMAL); |
| 698 | 700 if (style == FOR_SHUTDOWN && resource->exported_count > 0) |
| 699 // Exported resources are lost on shutdown. | 701 lost_resource = true; |
| 700 bool exported_resource_lost = | |
| 701 style == FOR_SHUTDOWN && resource->exported_count > 0; | |
| 702 // GPU resources are lost when output surface is lost. | |
| 703 bool gpu_resource_lost = | |
| 704 IsGpuResourceType(resource->type) && lost_output_surface_; | |
| 705 bool lost_resource = | |
| 706 resource->lost || exported_resource_lost || gpu_resource_lost; | |
| 707 | |
| 708 if (!lost_resource && | |
| 709 resource->synchronization_state() == Resource::NEEDS_WAIT) { | |
| 710 DCHECK(resource->allocated); | |
| 711 DCHECK(IsGpuResourceType(resource->type)); | |
| 712 GLES2Interface* gl = ContextGL(); | |
| 713 DCHECK(gl); | |
| 714 resource->WaitSyncToken(gl); | |
| 715 } | |
| 716 | 702 |
| 717 if (resource->image_id) { | 703 if (resource->image_id) { |
| 718 DCHECK(resource->origin == Resource::INTERNAL); | 704 DCHECK(resource->origin == Resource::INTERNAL); |
| 719 GLES2Interface* gl = ContextGL(); | 705 GLES2Interface* gl = ContextGL(); |
| 720 DCHECK(gl); | 706 DCHECK(gl); |
| 721 gl->DestroyImageCHROMIUM(resource->image_id); | 707 gl->DestroyImageCHROMIUM(resource->image_id); |
| 722 } | 708 } |
| 723 if (resource->gl_upload_query_id) { | 709 if (resource->gl_upload_query_id) { |
| 724 DCHECK(resource->origin == Resource::INTERNAL); | 710 DCHECK(resource->origin == Resource::INTERNAL); |
| 725 GLES2Interface* gl = ContextGL(); | 711 GLES2Interface* gl = ContextGL(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 736 DCHECK(resource->origin == Resource::INTERNAL); | 722 DCHECK(resource->origin == Resource::INTERNAL); |
| 737 GLES2Interface* gl = ContextGL(); | 723 GLES2Interface* gl = ContextGL(); |
| 738 DCHECK(gl); | 724 DCHECK(gl); |
| 739 gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id); | 725 gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id); |
| 740 } | 726 } |
| 741 if (resource->origin == Resource::EXTERNAL) { | 727 if (resource->origin == Resource::EXTERNAL) { |
| 742 DCHECK(resource->mailbox().IsValid()); | 728 DCHECK(resource->mailbox().IsValid()); |
| 743 gpu::SyncToken sync_token = resource->mailbox().sync_token(); | 729 gpu::SyncToken sync_token = resource->mailbox().sync_token(); |
| 744 if (IsGpuResourceType(resource->type)) { | 730 if (IsGpuResourceType(resource->type)) { |
| 745 DCHECK(resource->mailbox().IsTexture()); | 731 DCHECK(resource->mailbox().IsTexture()); |
| 732 lost_resource |= lost_output_surface_; |
| 746 GLES2Interface* gl = ContextGL(); | 733 GLES2Interface* gl = ContextGL(); |
| 747 DCHECK(gl); | 734 DCHECK(gl); |
| 748 if (resource->gl_id) { | 735 if (resource->gl_id) { |
| 749 gl->DeleteTextures(1, &resource->gl_id); | 736 gl->DeleteTextures(1, &resource->gl_id); |
| 750 resource->gl_id = 0; | 737 resource->gl_id = 0; |
| 751 if (!lost_resource) { | 738 if (!lost_resource) { |
| 752 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); | 739 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 753 gl->ShallowFlushCHROMIUM(); | 740 gl->ShallowFlushCHROMIUM(); |
| 754 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 741 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 755 } | 742 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 DCHECK(resource->allocated); | 808 DCHECK(resource->allocated); |
| 822 DCHECK_EQ(RGBA_8888, resource->format); | 809 DCHECK_EQ(RGBA_8888, resource->format); |
| 823 SkImageInfo source_info = | 810 SkImageInfo source_info = |
| 824 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); | 811 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); |
| 825 size_t image_stride = image_size.width() * 4; | 812 size_t image_stride = image_size.width() * 4; |
| 826 | 813 |
| 827 ScopedWriteLockSoftware lock(this, id); | 814 ScopedWriteLockSoftware lock(this, id); |
| 828 SkCanvas dest(lock.sk_bitmap()); | 815 SkCanvas dest(lock.sk_bitmap()); |
| 829 dest.writePixels(source_info, image, image_stride, 0, 0); | 816 dest.writePixels(source_info, image, image_stride, 0, 0); |
| 830 } else { | 817 } else { |
| 831 ScopedWriteLockGL lock(this, id, false); | 818 ScopedWriteLockGL lock(this, id); |
| 832 unsigned resource_texture_id = lock.texture_id(); | 819 DCHECK(lock.texture_id()); |
| 833 DCHECK(resource_texture_id); | |
| 834 GLES2Interface* gl = ContextGL(); | 820 GLES2Interface* gl = ContextGL(); |
| 835 DCHECK(gl); | 821 DCHECK(gl); |
| 836 gl->BindTexture(resource->target, resource_texture_id); | 822 gl->BindTexture(resource->target, lock.texture_id()); |
| 837 if (resource->format == ETC1) { | 823 if (resource->format == ETC1) { |
| 838 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 824 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 839 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); | 825 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); |
| 840 gl->CompressedTexImage2D(resource->target, 0, GLInternalFormat(ETC1), | 826 gl->CompressedTexImage2D(resource->target, 0, GLInternalFormat(ETC1), |
| 841 image_size.width(), image_size.height(), 0, | 827 image_size.width(), image_size.height(), 0, |
| 842 image_bytes, image); | 828 image_bytes, image); |
| 843 } else { | 829 } else { |
| 844 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), | 830 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), |
| 845 image_size.height(), GLDataFormat(resource->format), | 831 image_size.height(), GLDataFormat(resource->format), |
| 846 GLDataType(resource->format), image); | 832 GLDataType(resource->format), image); |
| 847 } | 833 } |
| 848 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 834 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 849 gl->OrderingBarrierCHROMIUM(); | 835 gl->OrderingBarrierCHROMIUM(); |
| 850 gpu::SyncToken sync_token; | 836 gpu::SyncToken sync_token; |
| 851 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 837 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 852 lock.set_sync_token(sync_token); | 838 lock.UpdateResourceSyncToken(sync_token); |
| 853 lock.set_synchronized(true); | |
| 854 } | 839 } |
| 855 } | 840 } |
| 856 | 841 |
| 857 void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) { | 842 void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) { |
| 858 Resource* resource = GetResource(resource_id); | 843 Resource* resource = GetResource(resource_id); |
| 859 if (!resource->needs_sync_token()) | 844 if (!resource->needs_sync_token()) |
| 860 return; | 845 return; |
| 861 | 846 |
| 862 gpu::SyncToken sync_token; | 847 gpu::SyncToken sync_token; |
| 863 GLES2Interface* gl = ContextGL(); | 848 GLES2Interface* gl = ContextGL(); |
| 864 DCHECK(gl); | 849 DCHECK(gl); |
| 865 | 850 |
| 866 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 851 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 867 gl->OrderingBarrierCHROMIUM(); | 852 gl->OrderingBarrierCHROMIUM(); |
| 868 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 853 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 869 | 854 |
| 870 resource->UpdateSyncToken(sync_token); | 855 resource->UpdateSyncToken(sync_token); |
| 871 resource->SetSynchronized(); | |
| 872 } | 856 } |
| 873 | 857 |
| 874 void ResourceProvider::GenerateSyncTokenForResources( | 858 void ResourceProvider::GenerateSyncTokenForResources( |
| 875 const ResourceIdArray& resource_ids) { | 859 const ResourceIdArray& resource_ids) { |
| 876 gpu::SyncToken sync_token; | 860 gpu::SyncToken sync_token; |
| 877 bool created_sync_token = false; | 861 bool created_sync_token = false; |
| 878 for (ResourceId id : resource_ids) { | 862 for (ResourceId id : resource_ids) { |
| 879 Resource* resource = GetResource(id); | 863 Resource* resource = GetResource(id); |
| 880 if (resource->needs_sync_token()) { | 864 if (resource->needs_sync_token()) { |
| 881 if (!created_sync_token) { | 865 if (!created_sync_token) { |
| 882 GLES2Interface* gl = ContextGL(); | 866 GLES2Interface* gl = ContextGL(); |
| 883 DCHECK(gl); | 867 DCHECK(gl); |
| 884 | 868 |
| 885 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 869 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 886 gl->OrderingBarrierCHROMIUM(); | 870 gl->OrderingBarrierCHROMIUM(); |
| 887 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 871 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 888 created_sync_token = true; | 872 created_sync_token = true; |
| 889 } | 873 } |
| 890 | 874 |
| 891 resource->UpdateSyncToken(sync_token); | 875 resource->UpdateSyncToken(sync_token); |
| 892 resource->SetSynchronized(); | |
| 893 } | 876 } |
| 894 } | 877 } |
| 895 } | 878 } |
| 896 | 879 |
| 897 ResourceProvider::Resource* ResourceProvider::InsertResource( | 880 ResourceProvider::Resource* ResourceProvider::InsertResource( |
| 898 ResourceId id, | 881 ResourceId id, |
| 899 Resource resource) { | 882 Resource resource) { |
| 900 std::pair<ResourceMap::iterator, bool> result = | 883 std::pair<ResourceMap::iterator, bool> result = |
| 901 resources_.insert(ResourceMap::value_type(id, std::move(resource))); | 884 resources_.insert(ResourceMap::value_type(id, std::move(resource))); |
| 902 DCHECK(result.second); | 885 DCHECK(result.second); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 ResourceIdArray unused; | 958 ResourceIdArray unused; |
| 976 unused.push_back(id); | 959 unused.push_back(id); |
| 977 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); | 960 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); |
| 978 } | 961 } |
| 979 } | 962 } |
| 980 } | 963 } |
| 981 | 964 |
| 982 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { | 965 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { |
| 983 Resource* resource = GetResource(id); | 966 Resource* resource = GetResource(id); |
| 984 DCHECK(CanLockForWrite(id)); | 967 DCHECK(CanLockForWrite(id)); |
| 985 if (resource->allocated) | 968 DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state()); |
| 986 WaitSyncTokenIfNeeded(id); | |
| 987 resource->locked_for_write = true; | 969 resource->locked_for_write = true; |
| 988 resource->SetLocallyUsed(); | 970 resource->SetLocallyUsed(); |
| 989 return resource; | 971 return resource; |
| 990 } | 972 } |
| 991 | 973 |
| 992 bool ResourceProvider::CanLockForWrite(ResourceId id) { | 974 bool ResourceProvider::CanLockForWrite(ResourceId id) { |
| 993 Resource* resource = GetResource(id); | 975 Resource* resource = GetResource(id); |
| 994 return !resource->locked_for_write && !resource->lock_for_read_count && | 976 return !resource->locked_for_write && !resource->lock_for_read_count && |
| 995 !resource->exported_count && resource->origin == Resource::INTERNAL && | 977 !resource->exported_count && resource->origin == Resource::INTERNAL && |
| 996 !resource->lost && ReadLockFenceHasPassed(resource); | 978 !resource->lost && ReadLockFenceHasPassed(resource); |
| 997 } | 979 } |
| 998 | 980 |
| 999 bool ResourceProvider::IsOverlayCandidate(ResourceId id) { | 981 bool ResourceProvider::IsOverlayCandidate(ResourceId id) { |
| 1000 Resource* resource = GetResource(id); | 982 Resource* resource = GetResource(id); |
| 1001 return resource->is_overlay_candidate; | 983 return resource->is_overlay_candidate; |
| 1002 } | 984 } |
| 1003 | 985 |
| 1004 void ResourceProvider::UnlockForWrite(Resource* resource) { | 986 void ResourceProvider::UnlockForWrite(ResourceProvider::Resource* resource) { |
| 1005 DCHECK(resource->locked_for_write); | 987 DCHECK(resource->locked_for_write); |
| 1006 DCHECK_EQ(resource->exported_count, 0); | 988 DCHECK_EQ(resource->exported_count, 0); |
| 1007 DCHECK(resource->origin == Resource::INTERNAL); | 989 DCHECK(resource->origin == Resource::INTERNAL); |
| 1008 resource->locked_for_write = false; | 990 resource->locked_for_write = false; |
| 991 resource->SetSynchronized(); |
| 1009 } | 992 } |
| 1010 | 993 |
| 1011 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) { | 994 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) { |
| 1012 Resource* resource = GetResource(id); | 995 Resource* resource = GetResource(id); |
| 1013 DCHECK(resource); | 996 DCHECK(resource); |
| 1014 resource->read_lock_fences_enabled = true; | 997 resource->read_lock_fences_enabled = true; |
| 1015 } | 998 } |
| 1016 | 999 |
| 1017 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( | 1000 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( |
| 1018 ResourceProvider* resource_provider, | 1001 ResourceProvider* resource_provider, |
| 1019 ResourceId resource_id) | 1002 ResourceId resource_id) |
| 1020 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1003 : resource_provider_(resource_provider), |
| 1021 const Resource* resource = resource_provider->LockForRead(resource_id); | 1004 resource_id_(resource_id), |
| 1022 texture_id_ = resource->gl_id; | 1005 resource_(resource_provider->LockForRead(resource_id)) { |
| 1023 target_ = resource->target; | 1006 DCHECK(resource_); |
| 1024 size_ = resource->size; | |
| 1025 } | 1007 } |
| 1026 | 1008 |
| 1027 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { | 1009 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { |
| 1028 resource_provider_->UnlockForRead(resource_id_); | 1010 resource_provider_->UnlockForRead(resource_id_); |
| 1029 } | 1011 } |
| 1030 | 1012 |
| 1031 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( | 1013 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( |
| 1032 ResourceProvider* resource_provider, | 1014 ResourceProvider* resource_provider, |
| 1033 ResourceId resource_id, | 1015 ResourceId resource_id, |
| 1034 GLenum filter) | 1016 GLenum filter) |
| 1035 : resource_lock_(resource_provider, resource_id), | 1017 : ScopedReadLockGL(resource_provider, resource_id), |
| 1036 unit_(GL_TEXTURE0), | 1018 unit_(GL_TEXTURE0), |
| 1037 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) {} | 1019 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) {} |
| 1038 | 1020 |
| 1039 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( | 1021 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( |
| 1040 ResourceProvider* resource_provider, | 1022 ResourceProvider* resource_provider, |
| 1041 ResourceId resource_id, | 1023 ResourceId resource_id, |
| 1042 GLenum unit, | 1024 GLenum unit, |
| 1043 GLenum filter) | 1025 GLenum filter) |
| 1044 : resource_lock_(resource_provider, resource_id), | 1026 : ScopedReadLockGL(resource_provider, resource_id), |
| 1045 unit_(unit), | 1027 unit_(unit), |
| 1046 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) {} | 1028 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) {} |
| 1047 | 1029 |
| 1048 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() {} | 1030 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() {} |
| 1049 | 1031 |
| 1050 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( | 1032 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( |
| 1051 ResourceProvider* resource_provider, | 1033 ResourceProvider* resource_provider, |
| 1052 ResourceId resource_id, | 1034 ResourceId resource_id) |
| 1053 bool create_mailbox) | |
| 1054 : resource_provider_(resource_provider), | 1035 : resource_provider_(resource_provider), |
| 1055 resource_id_(resource_id), | 1036 resource_(resource_provider->LockForWrite(resource_id)), |
| 1056 synchronized_(false) { | 1037 texture_id_(0), |
| 1057 DCHECK(thread_checker_.CalledOnValidThread()); | 1038 set_sync_token_(false) { |
| 1058 Resource* resource = resource_provider->LockForWrite(resource_id); | 1039 resource_provider_->LazyAllocate(resource_); |
| 1059 resource_provider_->LazyAllocate(resource); | 1040 texture_id_ = resource_->gl_id; |
| 1060 if (resource->image_id && resource->dirty_image) | 1041 DCHECK(texture_id_); |
| 1061 resource_provider_->BindImageForSampling(resource); | 1042 if (resource_->image_id && resource_->dirty_image) |
| 1062 if (create_mailbox) { | 1043 resource_provider_->BindImageForSampling(resource_); |
| 1063 resource_provider_->CreateMailboxAndBindResource( | |
| 1064 resource_provider_->ContextGL(), resource); | |
| 1065 } | |
| 1066 texture_id_ = resource->gl_id; | |
| 1067 target_ = resource->target; | |
| 1068 format_ = resource->format; | |
| 1069 size_ = resource->size; | |
| 1070 mailbox_ = resource->mailbox(); | |
| 1071 } | 1044 } |
| 1072 | 1045 |
| 1073 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1046 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
| 1074 DCHECK(thread_checker_.CalledOnValidThread()); | 1047 if (set_sync_token_) |
| 1075 Resource* resource = resource_provider_->GetResource(resource_id_); | 1048 resource_->UpdateSyncToken(sync_token_); |
| 1076 DCHECK(resource->locked_for_write); | 1049 resource_provider_->UnlockForWrite(resource_); |
| 1077 if (sync_token_.HasData()) | |
| 1078 resource->UpdateSyncToken(sync_token_); | |
| 1079 if (synchronized_) | |
| 1080 resource->SetSynchronized(); | |
| 1081 resource_provider_->UnlockForWrite(resource); | |
| 1082 } | 1050 } |
| 1083 | 1051 |
| 1084 ResourceProvider::ScopedTextureProvider::ScopedTextureProvider( | 1052 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 1085 gpu::gles2::GLES2Interface* gl, | 1053 const Resource* resource) { |
| 1086 ScopedWriteLockGL* resource_lock, | 1054 DCHECK_EQ(RGBA_8888, resource->format); |
| 1087 bool use_mailbox) | 1055 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), |
| 1088 : gl_(gl), use_mailbox_(use_mailbox) { | 1056 resource->size.height()); |
| 1089 if (use_mailbox_) { | 1057 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
| 1090 texture_id_ = gl_->CreateAndConsumeTextureCHROMIUM( | |
| 1091 resource_lock->target(), resource_lock->mailbox().name()); | |
| 1092 } else { | |
| 1093 texture_id_ = resource_lock->texture_id(); | |
| 1094 } | |
| 1095 DCHECK(texture_id_); | |
| 1096 } | 1058 } |
| 1097 | 1059 |
| 1098 ResourceProvider::ScopedTextureProvider::~ScopedTextureProvider() { | 1060 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
| 1099 if (use_mailbox_) | 1061 ResourceProvider* resource_provider, |
| 1100 gl_->DeleteTextures(1, &texture_id_); | 1062 ResourceId resource_id) |
| 1063 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1064 const Resource* resource = resource_provider->LockForRead(resource_id); |
| 1065 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
| 1101 } | 1066 } |
| 1102 | 1067 |
| 1103 ResourceProvider::ScopedSkSurfaceProvider::ScopedSkSurfaceProvider( | 1068 ResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() { |
| 1104 ContextProvider* context_provider, | 1069 resource_provider_->UnlockForRead(resource_id_); |
| 1105 ScopedWriteLockGL* resource_lock, | 1070 } |
| 1106 bool use_mailbox, | 1071 |
| 1072 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( |
| 1073 ResourceProvider* resource_provider, |
| 1074 ResourceId resource_id) |
| 1075 : resource_provider_(resource_provider), |
| 1076 resource_(resource_provider->LockForWrite(resource_id)) { |
| 1077 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource_); |
| 1078 DCHECK(valid()); |
| 1079 } |
| 1080 |
| 1081 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
| 1082 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1083 resource_provider_->UnlockForWrite(resource_); |
| 1084 } |
| 1085 |
| 1086 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1087 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
| 1088 ResourceId resource_id) |
| 1089 : resource_provider_(resource_provider), |
| 1090 resource_(resource_provider->LockForWrite(resource_id)) { |
| 1091 DCHECK(IsGpuResourceType(resource_->type)); |
| 1092 gpu_memory_buffer_ = std::move(resource_->gpu_memory_buffer); |
| 1093 resource_->gpu_memory_buffer = nullptr; |
| 1094 } |
| 1095 |
| 1096 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1097 ~ScopedWriteLockGpuMemoryBuffer() { |
| 1098 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1099 resource_provider_->UnlockForWrite(resource_); |
| 1100 if (!gpu_memory_buffer_) |
| 1101 return; |
| 1102 |
| 1103 DCHECK(!resource_->gpu_memory_buffer); |
| 1104 resource_provider_->LazyCreate(resource_); |
| 1105 resource_->gpu_memory_buffer = std::move(gpu_memory_buffer_); |
| 1106 resource_->allocated = true; |
| 1107 resource_provider_->LazyCreateImage(resource_); |
| 1108 resource_->dirty_image = true; |
| 1109 resource_->is_overlay_candidate = true; |
| 1110 resource_->SetSynchronized(); |
| 1111 |
| 1112 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
| 1113 // Read lock fences are required to ensure that we're not trying to map a |
| 1114 // buffer that is currently in-use by the GPU. |
| 1115 resource_->read_lock_fences_enabled = true; |
| 1116 } |
| 1117 |
| 1118 gfx::GpuMemoryBuffer* |
| 1119 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { |
| 1120 if (!gpu_memory_buffer_) { |
| 1121 gpu_memory_buffer_ = |
| 1122 resource_provider_->gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
| 1123 resource_->size, BufferFormat(resource_->format), |
| 1124 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); |
| 1125 } |
| 1126 return gpu_memory_buffer_.get(); |
| 1127 } |
| 1128 |
| 1129 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( |
| 1130 ResourceProvider* resource_provider, |
| 1131 ResourceId resource_id) |
| 1132 : resource_provider_(resource_provider), |
| 1133 resource_(resource_provider->LockForWrite(resource_id)), |
| 1134 set_sync_token_(false) { |
| 1135 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1136 resource_provider_->LazyAllocate(resource_); |
| 1137 if (resource_->image_id && resource_->dirty_image) |
| 1138 resource_provider_->BindImageForSampling(resource_); |
| 1139 } |
| 1140 |
| 1141 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
| 1142 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1143 DCHECK(resource_->locked_for_write); |
| 1144 if (set_sync_token_) |
| 1145 resource_->UpdateSyncToken(sync_token_); |
| 1146 |
| 1147 resource_provider_->UnlockForWrite(resource_); |
| 1148 } |
| 1149 |
| 1150 void ResourceProvider::ScopedWriteLockGr::InitSkSurface( |
| 1151 GrContext* gr_context, |
| 1107 bool use_distance_field_text, | 1152 bool use_distance_field_text, |
| 1108 bool can_use_lcd_text, | 1153 bool can_use_lcd_text, |
| 1109 int msaa_sample_count) | 1154 int msaa_sample_count) { |
| 1110 : texture_provider_(context_provider->ContextGL(), | 1155 DCHECK(resource_->locked_for_write); |
| 1111 resource_lock, | 1156 |
| 1112 use_mailbox) { | |
| 1113 GrGLTextureInfo texture_info; | 1157 GrGLTextureInfo texture_info; |
| 1114 texture_info.fID = texture_provider_.texture_id(); | 1158 texture_info.fID = resource_->gl_id; |
| 1115 texture_info.fTarget = resource_lock->target(); | 1159 texture_info.fTarget = resource_->target; |
| 1116 GrBackendTextureDesc desc; | 1160 GrBackendTextureDesc desc; |
| 1117 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1161 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 1118 desc.fWidth = resource_lock->size().width(); | 1162 desc.fWidth = resource_->size.width(); |
| 1119 desc.fHeight = resource_lock->size().height(); | 1163 desc.fHeight = resource_->size.height(); |
| 1120 desc.fConfig = ToGrPixelConfig(resource_lock->format()); | 1164 desc.fConfig = ToGrPixelConfig(resource_->format); |
| 1121 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1165 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 1122 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | 1166 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); |
| 1123 desc.fSampleCnt = msaa_sample_count; | 1167 desc.fSampleCnt = msaa_sample_count; |
| 1124 | 1168 |
| 1125 uint32_t flags = | 1169 uint32_t flags = |
| 1126 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | 1170 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
| 1127 // Use unknown pixel geometry to disable LCD text. | 1171 // Use unknown pixel geometry to disable LCD text. |
| 1128 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | 1172 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 1129 if (can_use_lcd_text) { | 1173 if (can_use_lcd_text) { |
| 1130 // LegacyFontHost will get LCD text and skia figures out what type to use. | 1174 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 1131 surface_props = | 1175 surface_props = |
| 1132 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 1176 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 1133 } | 1177 } |
| 1134 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | 1178 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( |
| 1135 context_provider->GrContext(), desc, &surface_props); | 1179 gr_context, desc, &surface_props); |
| 1136 } | 1180 } |
| 1137 | 1181 |
| 1138 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { | 1182 void ResourceProvider::ScopedWriteLockGr::ReleaseSkSurface() { |
| 1139 if (sk_surface_.get()) { | 1183 DCHECK(sk_surface_); |
| 1140 sk_surface_->prepareForExternalIO(); | 1184 sk_surface_->prepareForExternalIO(); |
| 1141 sk_surface_.reset(); | 1185 sk_surface_.reset(); |
| 1142 } | |
| 1143 } | |
| 1144 | |
| 1145 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | |
| 1146 const Resource* resource) { | |
| 1147 DCHECK_EQ(RGBA_8888, resource->format); | |
| 1148 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), | |
| 1149 resource->size.height()); | |
| 1150 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | |
| 1151 } | |
| 1152 | |
| 1153 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | |
| 1154 ResourceProvider* resource_provider, | |
| 1155 ResourceId resource_id) | |
| 1156 : resource_provider_(resource_provider), resource_id_(resource_id) { | |
| 1157 const Resource* resource = resource_provider->LockForRead(resource_id); | |
| 1158 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); | |
| 1159 } | |
| 1160 | |
| 1161 ResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() { | |
| 1162 resource_provider_->UnlockForRead(resource_id_); | |
| 1163 } | |
| 1164 | |
| 1165 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( | |
| 1166 ResourceProvider* resource_provider, | |
| 1167 ResourceId resource_id) | |
| 1168 : resource_provider_(resource_provider), resource_id_(resource_id) { | |
| 1169 ResourceProvider::PopulateSkBitmapWithResource( | |
| 1170 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); | |
| 1171 DCHECK(valid()); | |
| 1172 } | |
| 1173 | |
| 1174 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | |
| 1175 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1176 Resource* resource = resource_provider_->GetResource(resource_id_); | |
| 1177 DCHECK(resource); | |
| 1178 resource->SetSynchronized(); | |
| 1179 resource_provider_->UnlockForWrite(resource); | |
| 1180 } | |
| 1181 | |
| 1182 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | |
| 1183 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | |
| 1184 ResourceId resource_id) | |
| 1185 : resource_provider_(resource_provider), resource_id_(resource_id) { | |
| 1186 Resource* resource = resource_provider->LockForWrite(resource_id); | |
| 1187 DCHECK(IsGpuResourceType(resource->type)); | |
| 1188 format_ = resource->format; | |
| 1189 size_ = resource->size; | |
| 1190 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); | |
| 1191 resource->gpu_memory_buffer = nullptr; | |
| 1192 } | |
| 1193 | |
| 1194 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | |
| 1195 ~ScopedWriteLockGpuMemoryBuffer() { | |
| 1196 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1197 Resource* resource = resource_provider_->GetResource(resource_id_); | |
| 1198 DCHECK(resource); | |
| 1199 if (gpu_memory_buffer_) { | |
| 1200 DCHECK(!resource->gpu_memory_buffer); | |
| 1201 resource_provider_->LazyCreate(resource); | |
| 1202 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_); | |
| 1203 resource->allocated = true; | |
| 1204 resource_provider_->LazyCreateImage(resource); | |
| 1205 resource->dirty_image = true; | |
| 1206 resource->is_overlay_candidate = true; | |
| 1207 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | |
| 1208 // Read lock fences are required to ensure that we're not trying to map a | |
| 1209 // buffer that is currently in-use by the GPU. | |
| 1210 resource->read_lock_fences_enabled = true; | |
| 1211 } | |
| 1212 resource->SetSynchronized(); | |
| 1213 resource_provider_->UnlockForWrite(resource); | |
| 1214 } | |
| 1215 | |
| 1216 gfx::GpuMemoryBuffer* | |
| 1217 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { | |
| 1218 if (!gpu_memory_buffer_) { | |
| 1219 gpu_memory_buffer_ = | |
| 1220 resource_provider_->gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | |
| 1221 size_, BufferFormat(format_), | |
| 1222 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); | |
| 1223 } | |
| 1224 return gpu_memory_buffer_.get(); | |
| 1225 } | 1186 } |
| 1226 | 1187 |
| 1227 ResourceProvider::SynchronousFence::SynchronousFence( | 1188 ResourceProvider::SynchronousFence::SynchronousFence( |
| 1228 gpu::gles2::GLES2Interface* gl) | 1189 gpu::gles2::GLES2Interface* gl) |
| 1229 : gl_(gl), has_synchronized_(true) {} | 1190 : gl_(gl), has_synchronized_(true) {} |
| 1230 | 1191 |
| 1231 ResourceProvider::SynchronousFence::~SynchronousFence() {} | 1192 ResourceProvider::SynchronousFence::~SynchronousFence() {} |
| 1232 | 1193 |
| 1233 void ResourceProvider::SynchronousFence::Set() { | 1194 void ResourceProvider::SynchronousFence::Set() { |
| 1234 has_synchronized_ = false; | 1195 has_synchronized_ = false; |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1765 ResourceFormat format = resource->format; | 1726 ResourceFormat format = resource->format; |
| 1766 gl->BindTexture(resource->target, resource->gl_id); | 1727 gl->BindTexture(resource->target, resource->gl_id); |
| 1767 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { | 1728 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { |
| 1768 resource->gpu_memory_buffer = | 1729 resource->gpu_memory_buffer = |
| 1769 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1730 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
| 1770 size, BufferFormat(format), | 1731 size, BufferFormat(format), |
| 1771 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); | 1732 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); |
| 1772 LazyCreateImage(resource); | 1733 LazyCreateImage(resource); |
| 1773 resource->dirty_image = true; | 1734 resource->dirty_image = true; |
| 1774 resource->is_overlay_candidate = true; | 1735 resource->is_overlay_candidate = true; |
| 1775 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | |
| 1776 // Read lock fences are required to ensure that we're not trying to map a | |
| 1777 // buffer that is currently in-use by the GPU. | |
| 1778 resource->read_lock_fences_enabled = true; | |
| 1779 } else if (use_texture_storage_ext_ && | 1736 } else if (use_texture_storage_ext_ && |
| 1780 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && | 1737 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && |
| 1781 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | 1738 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { |
| 1782 GLenum storage_format = TextureToStorageFormat(format); | 1739 GLenum storage_format = TextureToStorageFormat(format); |
| 1783 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), | 1740 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), |
| 1784 size.height()); | 1741 size.height()); |
| 1785 } else { | 1742 } else { |
| 1786 // ETC1 does not support preallocation. | 1743 // ETC1 does not support preallocation. |
| 1787 if (format != ETC1) { | 1744 if (format != ETC1) { |
| 1788 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), | 1745 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1945 | 1902 |
| 1946 const int kImportance = 2; | 1903 const int kImportance = 2; |
| 1947 pmd->CreateSharedGlobalAllocatorDump(guid); | 1904 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 1948 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1905 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 1949 } | 1906 } |
| 1950 | 1907 |
| 1951 return true; | 1908 return true; |
| 1952 } | 1909 } |
| 1953 | 1910 |
| 1954 } // namespace cc | 1911 } // namespace cc |
| OLD | NEW |