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