Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: cc/resources/resource_provider.cc

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

Powered by Google App Engine
This is Rietveld 408576698