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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 return; | 688 return; |
689 } else { | 689 } else { |
690 DeleteResourceInternal(it, NORMAL); | 690 DeleteResourceInternal(it, NORMAL); |
691 } | 691 } |
692 } | 692 } |
693 | 693 |
694 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 694 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
695 DeleteStyle style) { | 695 DeleteStyle style) { |
696 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); | 696 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); |
697 Resource* resource = &it->second; | 697 Resource* resource = &it->second; |
698 bool lost_resource = resource->lost; | 698 DCHECK(resource->exported_count == 0 || style != NORMAL); |
699 | 699 |
700 DCHECK(resource->exported_count == 0 || style != NORMAL); | 700 bool lost_resource = |
701 if (style == FOR_SHUTDOWN && resource->exported_count > 0) | 701 resource->lost || |
702 lost_resource = true; | 702 (style == FOR_SHUTDOWN && resource->exported_count > 0) || |
703 (IsGpuResourceType(resource->type) && lost_output_surface_); | |
704 | |
705 if (!lost_resource && | |
706 resource->synchronization_state() == Resource::NEEDS_WAIT) { | |
707 DCHECK(resource->allocated); | |
708 DCHECK(IsGpuResourceType(resource->type)); | |
709 GLES2Interface* gl = ContextGL(); | |
710 DCHECK(gl); | |
711 resource->WaitSyncToken(gl); | |
712 } | |
703 | 713 |
704 if (resource->image_id) { | 714 if (resource->image_id) { |
705 DCHECK(resource->origin == Resource::INTERNAL); | 715 DCHECK(resource->origin == Resource::INTERNAL); |
706 GLES2Interface* gl = ContextGL(); | 716 GLES2Interface* gl = ContextGL(); |
707 DCHECK(gl); | 717 DCHECK(gl); |
708 gl->DestroyImageCHROMIUM(resource->image_id); | 718 gl->DestroyImageCHROMIUM(resource->image_id); |
709 } | 719 } |
710 if (resource->gl_upload_query_id) { | 720 if (resource->gl_upload_query_id) { |
711 DCHECK(resource->origin == Resource::INTERNAL); | 721 DCHECK(resource->origin == Resource::INTERNAL); |
712 GLES2Interface* gl = ContextGL(); | 722 GLES2Interface* gl = ContextGL(); |
(...skipping 10 matching lines...) Expand all Loading... | |
723 DCHECK(resource->origin == Resource::INTERNAL); | 733 DCHECK(resource->origin == Resource::INTERNAL); |
724 GLES2Interface* gl = ContextGL(); | 734 GLES2Interface* gl = ContextGL(); |
725 DCHECK(gl); | 735 DCHECK(gl); |
726 gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id); | 736 gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id); |
727 } | 737 } |
728 if (resource->origin == Resource::EXTERNAL) { | 738 if (resource->origin == Resource::EXTERNAL) { |
729 DCHECK(resource->mailbox().IsValid()); | 739 DCHECK(resource->mailbox().IsValid()); |
730 gpu::SyncToken sync_token = resource->mailbox().sync_token(); | 740 gpu::SyncToken sync_token = resource->mailbox().sync_token(); |
731 if (IsGpuResourceType(resource->type)) { | 741 if (IsGpuResourceType(resource->type)) { |
732 DCHECK(resource->mailbox().IsTexture()); | 742 DCHECK(resource->mailbox().IsTexture()); |
733 lost_resource |= lost_output_surface_; | |
734 GLES2Interface* gl = ContextGL(); | 743 GLES2Interface* gl = ContextGL(); |
735 DCHECK(gl); | 744 DCHECK(gl); |
736 if (resource->gl_id) { | 745 if (resource->gl_id) { |
737 gl->DeleteTextures(1, &resource->gl_id); | 746 gl->DeleteTextures(1, &resource->gl_id); |
738 resource->gl_id = 0; | 747 resource->gl_id = 0; |
739 if (!lost_resource) { | 748 if (!lost_resource) { |
740 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); | 749 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); |
741 gl->ShallowFlushCHROMIUM(); | 750 gl->ShallowFlushCHROMIUM(); |
742 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 751 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
743 } | 752 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 DCHECK(resource->allocated); | 818 DCHECK(resource->allocated); |
810 DCHECK_EQ(RGBA_8888, resource->format); | 819 DCHECK_EQ(RGBA_8888, resource->format); |
811 SkImageInfo source_info = | 820 SkImageInfo source_info = |
812 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); | 821 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); |
813 size_t image_stride = image_size.width() * 4; | 822 size_t image_stride = image_size.width() * 4; |
814 | 823 |
815 ScopedWriteLockSoftware lock(this, id); | 824 ScopedWriteLockSoftware lock(this, id); |
816 SkCanvas dest(lock.sk_bitmap()); | 825 SkCanvas dest(lock.sk_bitmap()); |
817 dest.writePixels(source_info, image, image_stride, 0, 0); | 826 dest.writePixels(source_info, image, image_stride, 0, 0); |
818 } else { | 827 } else { |
819 ScopedWriteLockGL lock(this, id); | 828 ScopedWriteLockGL lock(this, id, false); |
820 DCHECK(lock.texture_id()); | 829 unsigned resource_texture_id = lock.texture_id(); |
830 DCHECK(resource_texture_id); | |
821 GLES2Interface* gl = ContextGL(); | 831 GLES2Interface* gl = ContextGL(); |
822 DCHECK(gl); | 832 DCHECK(gl); |
823 gl->BindTexture(resource->target, lock.texture_id()); | 833 gl->BindTexture(resource->target, resource_texture_id); |
824 if (resource->format == ETC1) { | 834 if (resource->format == ETC1) { |
825 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 835 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
826 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); | 836 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); |
827 gl->CompressedTexImage2D(resource->target, 0, GLInternalFormat(ETC1), | 837 gl->CompressedTexImage2D(resource->target, 0, GLInternalFormat(ETC1), |
828 image_size.width(), image_size.height(), 0, | 838 image_size.width(), image_size.height(), 0, |
829 image_bytes, image); | 839 image_bytes, image); |
830 } else { | 840 } else { |
831 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), | 841 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), |
832 image_size.height(), GLDataFormat(resource->format), | 842 image_size.height(), GLDataFormat(resource->format), |
833 GLDataType(resource->format), image); | 843 GLDataType(resource->format), image); |
834 } | 844 } |
835 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 845 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
836 gl->OrderingBarrierCHROMIUM(); | 846 gl->OrderingBarrierCHROMIUM(); |
837 gpu::SyncToken sync_token; | 847 gpu::SyncToken sync_token; |
838 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 848 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
839 lock.UpdateResourceSyncToken(sync_token); | 849 lock.set_sync_token(sync_token); |
840 } | 850 } |
841 } | 851 } |
842 | 852 |
843 void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) { | 853 void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) { |
844 Resource* resource = GetResource(resource_id); | 854 Resource* resource = GetResource(resource_id); |
845 if (!resource->needs_sync_token()) | 855 if (!resource->needs_sync_token()) |
846 return; | 856 return; |
847 | 857 |
848 gpu::SyncToken sync_token; | 858 gpu::SyncToken sync_token; |
849 GLES2Interface* gl = ContextGL(); | 859 GLES2Interface* gl = ContextGL(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
900 bool create_gpu_memory_buffer) { | 910 bool create_gpu_memory_buffer) { |
901 Resource* resource = GetResource(id); | 911 Resource* resource = GetResource(id); |
902 DCHECK(!resource->locked_for_write) << "locked for write: " | 912 DCHECK(!resource->locked_for_write) << "locked for write: " |
903 << resource->locked_for_write; | 913 << resource->locked_for_write; |
904 DCHECK_EQ(resource->exported_count, 0); | 914 DCHECK_EQ(resource->exported_count, 0); |
905 // Uninitialized! Call SetPixels or LockForWrite first. | 915 // Uninitialized! Call SetPixels or LockForWrite first. |
906 DCHECK(resource->allocated); | 916 DCHECK(resource->allocated); |
907 | 917 |
908 // Mailbox sync_tokens must be processed by a call to | 918 // Mailbox sync_tokens must be processed by a call to |
909 // WaitSyncTokenIfNeeded() prior to calling LockForRead(). | 919 // WaitSyncTokenIfNeeded() prior to calling LockForRead(). |
910 DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state()); | 920 // DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state()); |
piman
2016/06/10 22:57:01
nit: I think you should leave this (and remove the
sunnyps
2016/06/11 01:29:52
Done.
| |
921 | |
922 WaitSyncTokenIfNeeded(id); | |
911 | 923 |
912 LazyCreate(resource); | 924 LazyCreate(resource); |
913 | 925 |
914 if (IsGpuResourceType(resource->type) && !resource->gl_id) { | 926 if (IsGpuResourceType(resource->type) && !resource->gl_id) { |
915 DCHECK(resource->origin != Resource::INTERNAL); | 927 DCHECK(resource->origin != Resource::INTERNAL); |
916 DCHECK(resource->mailbox().IsTexture()); | 928 DCHECK(resource->mailbox().IsTexture()); |
917 | 929 |
918 GLES2Interface* gl = ContextGL(); | 930 GLES2Interface* gl = ContextGL(); |
919 DCHECK(gl); | 931 DCHECK(gl); |
920 resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM( | 932 resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 ResourceIdArray unused; | 987 ResourceIdArray unused; |
976 unused.push_back(id); | 988 unused.push_back(id); |
977 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); | 989 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); |
978 } | 990 } |
979 } | 991 } |
980 } | 992 } |
981 | 993 |
982 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { | 994 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { |
983 Resource* resource = GetResource(id); | 995 Resource* resource = GetResource(id); |
984 DCHECK(CanLockForWrite(id)); | 996 DCHECK(CanLockForWrite(id)); |
985 DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state()); | 997 // DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state()); |
piman
2016/06/10 22:57:01
nit: remove
sunnyps
2016/06/11 01:29:52
Done.
| |
998 if (resource->allocated) | |
999 WaitSyncTokenIfNeeded(id); | |
986 resource->locked_for_write = true; | 1000 resource->locked_for_write = true; |
987 resource->SetLocallyUsed(); | 1001 resource->SetLocallyUsed(); |
988 return resource; | 1002 return resource; |
989 } | 1003 } |
990 | 1004 |
991 bool ResourceProvider::CanLockForWrite(ResourceId id) { | 1005 bool ResourceProvider::CanLockForWrite(ResourceId id) { |
992 Resource* resource = GetResource(id); | 1006 Resource* resource = GetResource(id); |
993 return !resource->locked_for_write && !resource->lock_for_read_count && | 1007 return !resource->locked_for_write && !resource->lock_for_read_count && |
994 !resource->exported_count && resource->origin == Resource::INTERNAL && | 1008 !resource->exported_count && resource->origin == Resource::INTERNAL && |
995 !resource->lost && ReadLockFenceHasPassed(resource); | 1009 !resource->lost && ReadLockFenceHasPassed(resource); |
996 } | 1010 } |
997 | 1011 |
998 bool ResourceProvider::IsOverlayCandidate(ResourceId id) { | 1012 bool ResourceProvider::IsOverlayCandidate(ResourceId id) { |
999 Resource* resource = GetResource(id); | 1013 Resource* resource = GetResource(id); |
1000 return resource->is_overlay_candidate; | 1014 return resource->is_overlay_candidate; |
1001 } | 1015 } |
1002 | 1016 |
1003 void ResourceProvider::UnlockForWrite(ResourceProvider::Resource* resource) { | 1017 void ResourceProvider::UnlockForWrite(Resource* resource) { |
1004 DCHECK(resource->locked_for_write); | 1018 DCHECK(resource->locked_for_write); |
1005 DCHECK_EQ(resource->exported_count, 0); | 1019 DCHECK_EQ(resource->exported_count, 0); |
1006 DCHECK(resource->origin == Resource::INTERNAL); | 1020 DCHECK(resource->origin == Resource::INTERNAL); |
1007 resource->locked_for_write = false; | 1021 resource->locked_for_write = false; |
1008 resource->SetSynchronized(); | 1022 // resource->SetSynchronized(); |
piman
2016/06/10 22:57:01
nit: remove.
sunnyps
2016/06/11 01:29:52
Done.
| |
1009 } | 1023 } |
1010 | 1024 |
1011 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) { | 1025 void ResourceProvider::EnableReadLockFencesForTesting(ResourceId id) { |
1012 Resource* resource = GetResource(id); | 1026 Resource* resource = GetResource(id); |
1013 DCHECK(resource); | 1027 DCHECK(resource); |
1014 resource->read_lock_fences_enabled = true; | 1028 resource->read_lock_fences_enabled = true; |
1015 } | 1029 } |
1016 | 1030 |
1017 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( | 1031 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( |
1018 ResourceProvider* resource_provider, | 1032 ResourceProvider* resource_provider, |
1019 ResourceId resource_id) | 1033 ResourceId resource_id) |
1020 : resource_provider_(resource_provider), | 1034 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1021 resource_id_(resource_id), | 1035 const Resource* resource = resource_provider->LockForRead(resource_id, false); |
1022 resource_(resource_provider->LockForRead(resource_id, false)) { | 1036 texture_id_ = resource->gl_id; |
1023 DCHECK(resource_); | 1037 target_ = resource->target; |
1038 size_ = resource->size; | |
1024 } | 1039 } |
1025 | 1040 |
1026 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { | 1041 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { |
1027 resource_provider_->UnlockForRead(resource_id_); | 1042 resource_provider_->UnlockForRead(resource_id_); |
1028 } | 1043 } |
1029 | 1044 |
1030 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( | 1045 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( |
1031 ResourceProvider* resource_provider, | 1046 ResourceProvider* resource_provider, |
1032 ResourceId resource_id, | 1047 ResourceId resource_id, |
1033 GLenum filter) | 1048 GLenum filter) |
1034 : ScopedReadLockGL(resource_provider, resource_id), | 1049 : resource_lock_(resource_provider, resource_id), |
1035 unit_(GL_TEXTURE0), | 1050 unit_(GL_TEXTURE0), |
1036 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) { | 1051 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) {} |
1037 } | |
1038 | 1052 |
1039 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( | 1053 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( |
1040 ResourceProvider* resource_provider, | 1054 ResourceProvider* resource_provider, |
1041 ResourceId resource_id, | 1055 ResourceId resource_id, |
1042 GLenum unit, | 1056 GLenum unit, |
1043 GLenum filter) | 1057 GLenum filter) |
1044 : ScopedReadLockGL(resource_provider, resource_id), | 1058 : resource_lock_(resource_provider, resource_id), |
1045 unit_(unit), | 1059 unit_(unit), |
1046 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) { | 1060 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) {} |
1047 } | |
1048 | 1061 |
1049 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() { | 1062 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() { |
1050 } | 1063 } |
1051 | 1064 |
1052 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( | 1065 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( |
1053 ResourceProvider* resource_provider, | 1066 ResourceProvider* resource_provider, |
1054 ResourceId resource_id) | 1067 ResourceId resource_id, |
1055 : resource_provider_(resource_provider), | 1068 bool create_mailbox) |
1056 resource_(resource_provider->LockForWrite(resource_id)), | 1069 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1057 texture_id_(0), | 1070 DCHECK(thread_checker_.CalledOnValidThread()); |
1058 set_sync_token_(false) { | 1071 Resource* resource = resource_provider->LockForWrite(resource_id); |
1059 resource_provider_->LazyAllocate(resource_); | 1072 resource_provider_->LazyAllocate(resource); |
1060 texture_id_ = resource_->gl_id; | 1073 if (resource->image_id && resource->dirty_image) |
1061 DCHECK(texture_id_); | 1074 resource_provider_->BindImageForSampling(resource); |
1062 if (resource_->image_id && resource_->dirty_image) | 1075 if (create_mailbox) { |
1063 resource_provider_->BindImageForSampling(resource_); | 1076 resource_provider_->CreateMailboxAndBindResource( |
1077 resource_provider_->ContextGL(), resource); | |
1078 } | |
1079 texture_id_ = resource->gl_id; | |
1080 target_ = resource->target; | |
1081 format_ = resource->format; | |
1082 size_ = resource->size; | |
1083 mailbox_ = resource->mailbox(); | |
1064 } | 1084 } |
1065 | 1085 |
1066 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1086 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
1067 if (set_sync_token_) | 1087 DCHECK(thread_checker_.CalledOnValidThread()); |
1068 resource_->UpdateSyncToken(sync_token_); | 1088 Resource* resource = resource_provider_->GetResource(resource_id_); |
1069 resource_provider_->UnlockForWrite(resource_); | 1089 DCHECK(resource->locked_for_write); |
1090 if (sync_token_.HasData()) | |
1091 resource->UpdateSyncToken(sync_token_); | |
1092 resource_provider_->UnlockForWrite(resource); | |
1093 } | |
1094 | |
1095 ResourceProvider::ScopedTextureProvider::ScopedTextureProvider( | |
1096 gpu::gles2::GLES2Interface* gl, | |
1097 ScopedWriteLockGL* resource_lock, | |
1098 bool use_mailbox) | |
1099 : gl_(gl), use_mailbox_(use_mailbox) { | |
1100 if (use_mailbox_) { | |
1101 texture_id_ = gl_->CreateAndConsumeTextureCHROMIUM( | |
1102 resource_lock->target(), resource_lock->mailbox().name()); | |
1103 } else { | |
1104 texture_id_ = resource_lock->texture_id(); | |
1105 } | |
1106 DCHECK(texture_id_); | |
1107 } | |
1108 | |
1109 ResourceProvider::ScopedTextureProvider::~ScopedTextureProvider() { | |
1110 if (use_mailbox_) | |
1111 gl_->DeleteTextures(1, &texture_id_); | |
1112 } | |
1113 | |
1114 ResourceProvider::ScopedSkSurfaceProvider::ScopedSkSurfaceProvider( | |
1115 ContextProvider* context_provider, | |
1116 ScopedWriteLockGL* resource_lock, | |
1117 bool use_mailbox, | |
1118 bool use_distance_field_text, | |
1119 bool can_use_lcd_text, | |
1120 int msaa_sample_count) | |
1121 : texture_provider_(context_provider->ContextGL(), | |
1122 resource_lock, | |
1123 use_mailbox) { | |
1124 GrGLTextureInfo texture_info; | |
1125 texture_info.fID = texture_provider_.texture_id(); | |
1126 texture_info.fTarget = resource_lock->target(); | |
1127 GrBackendTextureDesc desc; | |
1128 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
1129 desc.fWidth = resource_lock->size().width(); | |
1130 desc.fHeight = resource_lock->size().height(); | |
1131 desc.fConfig = ToGrPixelConfig(resource_lock->format()); | |
1132 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
1133 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | |
1134 desc.fSampleCnt = msaa_sample_count; | |
1135 | |
1136 uint32_t flags = | |
1137 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | |
1138 // Use unknown pixel geometry to disable LCD text. | |
1139 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | |
1140 if (can_use_lcd_text) { | |
1141 // LegacyFontHost will get LCD text and skia figures out what type to use. | |
1142 surface_props = | |
1143 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | |
1144 } | |
1145 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | |
1146 context_provider->GrContext(), desc, &surface_props); | |
1147 } | |
1148 | |
1149 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { | |
1150 if (sk_surface_.get()) { | |
1151 sk_surface_->prepareForExternalIO(); | |
1152 sk_surface_.reset(); | |
1153 } | |
1070 } | 1154 } |
1071 | 1155 |
1072 void ResourceProvider::PopulateSkBitmapWithResource( | 1156 void ResourceProvider::PopulateSkBitmapWithResource( |
1073 SkBitmap* sk_bitmap, const Resource* resource) { | 1157 SkBitmap* sk_bitmap, const Resource* resource) { |
1074 DCHECK_EQ(RGBA_8888, resource->format); | 1158 DCHECK_EQ(RGBA_8888, resource->format); |
1075 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), | 1159 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), |
1076 resource->size.height()); | 1160 resource->size.height()); |
1077 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | 1161 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
1078 } | 1162 } |
1079 | 1163 |
1080 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1164 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
1081 ResourceProvider* resource_provider, | 1165 ResourceProvider* resource_provider, |
1082 ResourceId resource_id) | 1166 ResourceId resource_id) |
1083 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1167 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1084 const Resource* resource = resource_provider->LockForRead(resource_id, false); | 1168 const Resource* resource = resource_provider->LockForRead(resource_id, false); |
1085 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1169 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
1086 } | 1170 } |
1087 | 1171 |
1088 ResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() { | 1172 ResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() { |
1089 resource_provider_->UnlockForRead(resource_id_); | 1173 resource_provider_->UnlockForRead(resource_id_); |
1090 } | 1174 } |
1091 | 1175 |
1092 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( | 1176 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( |
1093 ResourceProvider* resource_provider, | 1177 ResourceProvider* resource_provider, |
1094 ResourceId resource_id) | 1178 ResourceId resource_id) |
1095 : resource_provider_(resource_provider), | 1179 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1096 resource_(resource_provider->LockForWrite(resource_id)) { | 1180 ResourceProvider::PopulateSkBitmapWithResource( |
1097 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource_); | 1181 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); |
1098 DCHECK(valid()); | 1182 DCHECK(valid()); |
1099 } | 1183 } |
1100 | 1184 |
1101 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 1185 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
1102 DCHECK(thread_checker_.CalledOnValidThread()); | 1186 DCHECK(thread_checker_.CalledOnValidThread()); |
1103 resource_provider_->UnlockForWrite(resource_); | 1187 resource_provider_->UnlockForWrite( |
1188 resource_provider_->GetResource(resource_id_)); | |
1104 } | 1189 } |
1105 | 1190 |
1106 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1191 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
1107 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 1192 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
1108 ResourceId resource_id) | 1193 ResourceId resource_id) |
1109 : resource_provider_(resource_provider), | 1194 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1110 resource_(resource_provider->LockForWrite(resource_id)) { | 1195 Resource* resource = resource_provider->LockForWrite(resource_id); |
1111 DCHECK(IsGpuResourceType(resource_->type)); | 1196 DCHECK(IsGpuResourceType(resource->type)); |
1112 gpu_memory_buffer_ = std::move(resource_->gpu_memory_buffer); | 1197 format_ = resource->format; |
1113 resource_->gpu_memory_buffer = nullptr; | 1198 size_ = resource->size; |
1199 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); | |
1200 resource->gpu_memory_buffer = nullptr; | |
1114 } | 1201 } |
1115 | 1202 |
1116 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1203 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
1117 ~ScopedWriteLockGpuMemoryBuffer() { | 1204 ~ScopedWriteLockGpuMemoryBuffer() { |
1118 DCHECK(thread_checker_.CalledOnValidThread()); | 1205 DCHECK(thread_checker_.CalledOnValidThread()); |
1119 resource_provider_->UnlockForWrite(resource_); | 1206 Resource* resource = resource_provider_->GetResource(resource_id_); |
1120 if (!gpu_memory_buffer_) | 1207 if (gpu_memory_buffer_) { |
1121 return; | 1208 DCHECK(!resource->gpu_memory_buffer); |
1122 | 1209 resource_provider_->LazyCreate(resource); |
1123 DCHECK(!resource_->gpu_memory_buffer); | 1210 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_); |
1124 resource_provider_->LazyCreate(resource_); | 1211 if (resource->gpu_memory_buffer) |
1125 resource_->gpu_memory_buffer = std::move(gpu_memory_buffer_); | 1212 resource->gpu_memory_buffer_id = resource->gpu_memory_buffer->GetId(); |
1126 if (resource_->gpu_memory_buffer) | 1213 resource->allocated = true; |
1127 resource_->gpu_memory_buffer_id = resource_->gpu_memory_buffer->GetId(); | 1214 resource_provider_->LazyCreateImage(resource); |
1128 resource_->allocated = true; | 1215 resource->dirty_image = true; |
1129 resource_provider_->LazyCreateImage(resource_); | 1216 resource->is_overlay_candidate = true; |
1130 resource_->dirty_image = true; | 1217 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
1131 resource_->is_overlay_candidate = true; | 1218 // Read lock fences are required to ensure that we're not trying to map a |
1132 resource_->SetSynchronized(); | 1219 // buffer that is currently in-use by the GPU. |
1133 | 1220 resource->read_lock_fences_enabled = true; |
1134 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | 1221 } |
1135 // Read lock fences are required to ensure that we're not trying to map a | 1222 resource_provider_->UnlockForWrite(resource); |
1136 // buffer that is currently in-use by the GPU. | |
1137 resource_->read_lock_fences_enabled = true; | |
1138 } | 1223 } |
1139 | 1224 |
1140 gfx::GpuMemoryBuffer* | 1225 gfx::GpuMemoryBuffer* |
1141 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { | 1226 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { |
1142 if (!gpu_memory_buffer_) { | 1227 if (!gpu_memory_buffer_) { |
1143 gpu_memory_buffer_ = | 1228 gpu_memory_buffer_ = |
1144 resource_provider_->gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1229 resource_provider_->gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
1145 resource_->size, BufferFormat(resource_->format), | 1230 size_, BufferFormat(format_), |
1146 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); | 1231 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); |
1147 } | 1232 } |
1148 return gpu_memory_buffer_.get(); | 1233 return gpu_memory_buffer_.get(); |
1149 } | 1234 } |
1150 | 1235 |
1151 ResourceProvider::ScopedReadLockGpuMemoryBuffer::ScopedReadLockGpuMemoryBuffer( | 1236 ResourceProvider::ScopedReadLockGpuMemoryBuffer::ScopedReadLockGpuMemoryBuffer( |
1152 ResourceProvider* resource_provider, | 1237 ResourceProvider* resource_provider, |
1153 ResourceId resource_id) | 1238 ResourceId resource_id) |
1154 : resource_provider_(resource_provider), | 1239 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1155 resource_id_(resource_id), | 1240 const Resource* resource = resource_provider->LockForRead(resource_id, true); |
1156 resource_(resource_provider->LockForRead(resource_id, true)) {} | 1241 gpu_memory_buffer_ = resource->gpu_memory_buffer.get(); |
1242 texture_id_ = resource->gl_id; | |
1243 } | |
1157 | 1244 |
1158 ResourceProvider::ScopedReadLockGpuMemoryBuffer:: | 1245 ResourceProvider::ScopedReadLockGpuMemoryBuffer:: |
1159 ~ScopedReadLockGpuMemoryBuffer() { | 1246 ~ScopedReadLockGpuMemoryBuffer() { |
1160 DCHECK(thread_checker_.CalledOnValidThread()); | 1247 DCHECK(thread_checker_.CalledOnValidThread()); |
1161 resource_provider_->UnlockForRead(resource_id_); | 1248 resource_provider_->UnlockForRead(resource_id_); |
1162 } | 1249 } |
1163 | 1250 |
1164 gfx::GpuMemoryBuffer* | |
1165 ResourceProvider::ScopedReadLockGpuMemoryBuffer::GetGpuMemoryBuffer() const { | |
1166 return resource_->gpu_memory_buffer.get(); | |
1167 } | |
1168 | |
1169 unsigned ResourceProvider::ScopedReadLockGpuMemoryBuffer::GetTextureId() const { | |
1170 return resource_->gl_id; | |
1171 } | |
1172 | |
1173 ResourceId ResourceProvider::ScopedReadLockGpuMemoryBuffer::GetResourceId() | |
1174 const { | |
1175 return resource_id_; | |
1176 } | |
1177 | |
1178 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( | |
1179 ResourceProvider* resource_provider, | |
1180 ResourceId resource_id) | |
1181 : resource_provider_(resource_provider), | |
1182 resource_(resource_provider->LockForWrite(resource_id)), | |
1183 set_sync_token_(false) { | |
1184 DCHECK(thread_checker_.CalledOnValidThread()); | |
1185 resource_provider_->LazyAllocate(resource_); | |
1186 if (resource_->image_id && resource_->dirty_image) | |
1187 resource_provider_->BindImageForSampling(resource_); | |
1188 } | |
1189 | |
1190 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | |
1191 DCHECK(thread_checker_.CalledOnValidThread()); | |
1192 DCHECK(resource_->locked_for_write); | |
1193 if (set_sync_token_) | |
1194 resource_->UpdateSyncToken(sync_token_); | |
1195 | |
1196 resource_provider_->UnlockForWrite(resource_); | |
1197 } | |
1198 | |
1199 void ResourceProvider::ScopedWriteLockGr::InitSkSurface( | |
1200 GrContext* gr_context, | |
1201 bool use_distance_field_text, | |
1202 bool can_use_lcd_text, | |
1203 int msaa_sample_count) { | |
1204 DCHECK(resource_->locked_for_write); | |
1205 | |
1206 GrGLTextureInfo texture_info; | |
1207 texture_info.fID = resource_->gl_id; | |
1208 texture_info.fTarget = resource_->target; | |
1209 GrBackendTextureDesc desc; | |
1210 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
1211 desc.fWidth = resource_->size.width(); | |
1212 desc.fHeight = resource_->size.height(); | |
1213 desc.fConfig = ToGrPixelConfig(resource_->format); | |
1214 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
1215 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | |
1216 desc.fSampleCnt = msaa_sample_count; | |
1217 | |
1218 uint32_t flags = | |
1219 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | |
1220 // Use unknown pixel geometry to disable LCD text. | |
1221 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | |
1222 if (can_use_lcd_text) { | |
1223 // LegacyFontHost will get LCD text and skia figures out what type to use. | |
1224 surface_props = | |
1225 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | |
1226 } | |
1227 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | |
1228 gr_context, desc, &surface_props); | |
1229 } | |
1230 | |
1231 void ResourceProvider::ScopedWriteLockGr::ReleaseSkSurface() { | |
1232 DCHECK(sk_surface_); | |
1233 sk_surface_->prepareForExternalIO(); | |
1234 sk_surface_.reset(); | |
1235 } | |
1236 | |
1237 ResourceProvider::SynchronousFence::SynchronousFence( | 1251 ResourceProvider::SynchronousFence::SynchronousFence( |
1238 gpu::gles2::GLES2Interface* gl) | 1252 gpu::gles2::GLES2Interface* gl) |
1239 : gl_(gl), has_synchronized_(true) { | 1253 : gl_(gl), has_synchronized_(true) { |
1240 } | 1254 } |
1241 | 1255 |
1242 ResourceProvider::SynchronousFence::~SynchronousFence() { | 1256 ResourceProvider::SynchronousFence::~SynchronousFence() { |
1243 } | 1257 } |
1244 | 1258 |
1245 void ResourceProvider::SynchronousFence::Set() { | 1259 void ResourceProvider::SynchronousFence::Set() { |
1246 has_synchronized_ = false; | 1260 has_synchronized_ = false; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1366 gl->OrderingBarrierCHROMIUM(); | 1380 gl->OrderingBarrierCHROMIUM(); |
1367 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); | 1381 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); |
1368 unverified_sync_tokens.push_back(new_sync_token.GetData()); | 1382 unverified_sync_tokens.push_back(new_sync_token.GetData()); |
1369 } | 1383 } |
1370 | 1384 |
1371 if (!unverified_sync_tokens.empty()) { | 1385 if (!unverified_sync_tokens.empty()) { |
1372 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), | 1386 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), |
1373 unverified_sync_tokens.size()); | 1387 unverified_sync_tokens.size()); |
1374 } | 1388 } |
1375 } | 1389 } |
1376 for (Resource* resource : need_synchronization_resources) { | 1390 for (Resource* resource : need_synchronization_resources) |
1377 resource->UpdateSyncToken(new_sync_token); | 1391 resource->UpdateSyncToken(new_sync_token); |
1378 resource->SetSynchronized(); | |
1379 } | |
1380 | 1392 |
1381 // Transfer Resources | 1393 // Transfer Resources |
1382 DCHECK_EQ(resources.size(), resource_ids.size()); | 1394 DCHECK_EQ(resources.size(), resource_ids.size()); |
1383 for (size_t i = 0; i < resources.size(); ++i) { | 1395 for (size_t i = 0; i < resources.size(); ++i) { |
1384 Resource* source = resources[i]; | 1396 Resource* source = resources[i]; |
1385 const ResourceId id = resource_ids[i]; | 1397 const ResourceId id = resource_ids[i]; |
1386 | 1398 |
1387 DCHECK(!delegated_sync_points_required_ || !source->needs_sync_token()); | 1399 DCHECK(!delegated_sync_points_required_ || !source->needs_sync_token()); |
1388 DCHECK(!delegated_sync_points_required_ || | 1400 DCHECK(!delegated_sync_points_required_ || |
1389 Resource::LOCALLY_USED != source->synchronization_state()); | 1401 Resource::LOCALLY_USED != source->synchronization_state()); |
1390 | 1402 |
1391 TransferableResource resource; | 1403 TransferableResource resource; |
1392 TransferResource(source, id, &resource); | 1404 TransferResource(source, id, &resource); |
1393 | 1405 |
1406 source->SetSynchronized(); | |
piman
2016/06/10 22:57:01
Is this right?
If a resource comes from the raster
sunnyps
2016/06/11 01:29:52
Done.
| |
1394 source->exported_count++; | 1407 source->exported_count++; |
1395 list->push_back(resource); | 1408 list->push_back(resource); |
1396 } | 1409 } |
1397 } | 1410 } |
1398 | 1411 |
1399 void ResourceProvider::ReceiveFromChild( | 1412 void ResourceProvider::ReceiveFromChild( |
1400 int child, const TransferableResourceArray& resources) { | 1413 int child, const TransferableResourceArray& resources) { |
1401 DCHECK(thread_checker_.CalledOnValidThread()); | 1414 DCHECK(thread_checker_.CalledOnValidThread()); |
1402 GLES2Interface* gl = ContextGL(); | 1415 GLES2Interface* gl = ContextGL(); |
1403 Child& child_info = children_.find(child)->second; | 1416 Child& child_info = children_.find(child)->second; |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1783 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { | 1796 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { |
1784 resource->gpu_memory_buffer = | 1797 resource->gpu_memory_buffer = |
1785 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1798 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
1786 size, BufferFormat(format), | 1799 size, BufferFormat(format), |
1787 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); | 1800 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); |
1788 if (resource->gpu_memory_buffer) | 1801 if (resource->gpu_memory_buffer) |
1789 resource->gpu_memory_buffer_id = resource->gpu_memory_buffer->GetId(); | 1802 resource->gpu_memory_buffer_id = resource->gpu_memory_buffer->GetId(); |
1790 LazyCreateImage(resource); | 1803 LazyCreateImage(resource); |
1791 resource->dirty_image = true; | 1804 resource->dirty_image = true; |
1792 resource->is_overlay_candidate = true; | 1805 resource->is_overlay_candidate = true; |
1806 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | |
1807 // Read lock fences are required to ensure that we're not trying to map a | |
1808 // buffer that is currently in-use by the GPU. | |
1809 resource->read_lock_fences_enabled = true; | |
1793 } else if (use_texture_storage_ext_ && | 1810 } else if (use_texture_storage_ext_ && |
1794 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && | 1811 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && |
1795 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | 1812 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { |
1796 GLenum storage_format = TextureToStorageFormat(format); | 1813 GLenum storage_format = TextureToStorageFormat(format); |
1797 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), | 1814 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), |
1798 size.height()); | 1815 size.height()); |
1799 } else { | 1816 } else { |
1800 // ETC1 does not support preallocation. | 1817 // ETC1 does not support preallocation. |
1801 if (format != ETC1) { | 1818 if (format != ETC1) { |
1802 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), | 1819 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1959 | 1976 |
1960 const int kImportance = 2; | 1977 const int kImportance = 2; |
1961 pmd->CreateSharedGlobalAllocatorDump(guid); | 1978 pmd->CreateSharedGlobalAllocatorDump(guid); |
1962 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1979 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
1963 } | 1980 } |
1964 | 1981 |
1965 return true; | 1982 return true; |
1966 } | 1983 } |
1967 | 1984 |
1968 } // namespace cc | 1985 } // namespace cc |
OLD | NEW |