Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 988 | 988 |
| 989 resource->locked_for_write = false; | 989 resource->locked_for_write = false; |
| 990 resource->dirty_image = true; | 990 resource->dirty_image = true; |
| 991 | 991 |
| 992 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | 992 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
| 993 // Read lock fences are required to ensure that we're not trying to map a | 993 // Read lock fences are required to ensure that we're not trying to map a |
| 994 // buffer that is currently in-use by the GPU. | 994 // buffer that is currently in-use by the GPU. |
| 995 resource->read_lock_fences_enabled = true; | 995 resource->read_lock_fences_enabled = true; |
| 996 } | 996 } |
| 997 | 997 |
| 998 SkSurface* ResourceProvider::CreateSkSurface(ResourceId id, | |
| 999 bool use_distance_field_text) { | |
| 1000 Resource* resource = GetResource(id); | |
| 1001 DCHECK(resource->locked_for_write); | |
| 1002 | |
| 1003 class GrContext* gr_context = GrContext(); | |
| 1004 // TODO(alokp): Implement TestContextProvider::GrContext(). | |
| 1005 if (!gr_context) | |
| 1006 return nullptr; | |
| 1007 | |
| 1008 LazyAllocate(resource); | |
| 1009 | |
| 1010 GrBackendTextureDesc desc; | |
| 1011 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
| 1012 desc.fWidth = resource->size.width(); | |
| 1013 desc.fHeight = resource->size.height(); | |
| 1014 desc.fConfig = ToGrPixelConfig(resource->format); | |
| 1015 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 1016 desc.fTextureHandle = resource->gl_id; | |
| 1017 skia::RefPtr<GrTexture> gr_texture = | |
| 1018 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | |
| 1019 SkSurface::TextRenderMode text_render_mode = | |
| 1020 use_distance_field_text ? SkSurface::kDistanceField_TextRenderMode | |
| 1021 : SkSurface::kStandard_TextRenderMode; | |
| 1022 resource->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( | |
| 1023 gr_texture->asRenderTarget(), text_render_mode)); | |
| 1024 return resource->sk_surface.get(); | |
| 1025 } | |
| 1026 | |
| 998 const ResourceProvider::Resource* ResourceProvider::LockForWriteToSkSurface( | 1027 const ResourceProvider::Resource* ResourceProvider::LockForWriteToSkSurface( |
| 999 ResourceId id) { | 1028 ResourceId id) { |
| 1000 Resource* resource = GetResource(id); | 1029 Resource* resource = GetResource(id); |
| 1001 DCHECK_EQ(GLTexture, resource->type); | 1030 DCHECK_EQ(GLTexture, resource->type); |
| 1002 DCHECK(CanLockForWrite(id)); | 1031 DCHECK(CanLockForWrite(id)); |
| 1003 | 1032 |
| 1004 resource->locked_for_write = true; | 1033 resource->locked_for_write = true; |
| 1034 | |
| 1005 if (!resource->sk_surface) { | 1035 if (!resource->sk_surface) { |
| 1006 class GrContext* gr_context = GrContext(); | 1036 CreateSkSurface(id, use_distance_field_text_); |
|
reveman
2014/10/15 17:34:09
Let's not bother to create the surface here if you
| |
| 1007 // TODO(alokp): Implement TestContextProvider::GrContext(). | |
| 1008 if (!gr_context) | |
| 1009 return resource; | |
| 1010 | |
| 1011 LazyAllocate(resource); | |
| 1012 | |
| 1013 GrBackendTextureDesc desc; | |
| 1014 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
| 1015 desc.fWidth = resource->size.width(); | |
| 1016 desc.fHeight = resource->size.height(); | |
| 1017 desc.fConfig = ToGrPixelConfig(resource->format); | |
| 1018 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 1019 desc.fTextureHandle = resource->gl_id; | |
| 1020 skia::RefPtr<GrTexture> gr_texture = | |
| 1021 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | |
| 1022 SkSurface::TextRenderMode text_render_mode = | |
| 1023 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode | |
| 1024 : SkSurface::kStandard_TextRenderMode; | |
| 1025 resource->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( | |
| 1026 gr_texture->asRenderTarget(), text_render_mode)); | |
| 1027 } | 1037 } |
| 1028 | 1038 |
| 1029 return resource; | 1039 return resource; |
| 1030 } | 1040 } |
| 1031 | 1041 |
| 1032 void ResourceProvider::UnlockForWriteToSkSurface(ResourceId id) { | 1042 void ResourceProvider::UnlockForWriteToSkSurface(ResourceId id) { |
| 1033 Resource* resource = GetResource(id); | 1043 Resource* resource = GetResource(id); |
| 1034 DCHECK(resource->locked_for_write); | 1044 DCHECK(resource->locked_for_write); |
| 1035 DCHECK_EQ(resource->exported_count, 0); | 1045 DCHECK_EQ(resource->exported_count, 0); |
| 1036 DCHECK(resource->origin == Resource::Internal); | 1046 DCHECK(resource->origin == Resource::Internal); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1144 : resource_provider_(resource_provider), | 1154 : resource_provider_(resource_provider), |
| 1145 resource_id_(resource_id), | 1155 resource_id_(resource_id), |
| 1146 sk_surface_(resource_provider->LockForWriteToSkSurface(resource_id) | 1156 sk_surface_(resource_provider->LockForWriteToSkSurface(resource_id) |
| 1147 ->sk_surface.get()) { | 1157 ->sk_surface.get()) { |
| 1148 } | 1158 } |
| 1149 | 1159 |
| 1150 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | 1160 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
| 1151 resource_provider_->UnlockForWriteToSkSurface(resource_id_); | 1161 resource_provider_->UnlockForWriteToSkSurface(resource_id_); |
| 1152 } | 1162 } |
| 1153 | 1163 |
| 1164 void ResourceProvider::ScopedWriteLockGr::SetUseDistanceFieldText( | |
| 1165 bool use_distance_field_text) { | |
| 1166 bool surface_uses_distance_field = | |
| 1167 resource_provider_->use_distance_field_text_ || use_distance_field_text; | |
|
reveman
2014/10/15 17:34:09
what is ResourceProvider::use_distance_field_text_
| |
| 1168 // If the surface doesn't have the correct dff setting, recreate the surface | |
| 1169 // within the resource. | |
| 1170 if (surface_uses_distance_field != | |
| 1171 sk_surface_->props().isUseDistanceFieldFonts()) { | |
| 1172 sk_surface_ = resource_provider_->CreateSkSurface(resource_id_, | |
| 1173 use_distance_field_text); | |
| 1174 } | |
| 1175 } | |
| 1176 | |
| 1154 ResourceProvider::ResourceProvider( | 1177 ResourceProvider::ResourceProvider( |
| 1155 OutputSurface* output_surface, | 1178 OutputSurface* output_surface, |
| 1156 SharedBitmapManager* shared_bitmap_manager, | 1179 SharedBitmapManager* shared_bitmap_manager, |
| 1157 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 1180 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 1158 BlockingTaskRunner* blocking_main_thread_task_runner, | 1181 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 1159 int highp_threshold_min, | 1182 int highp_threshold_min, |
| 1160 bool use_rgba_4444_texture_format, | 1183 bool use_rgba_4444_texture_format, |
| 1161 size_t id_allocation_chunk_size, | 1184 size_t id_allocation_chunk_size, |
| 1162 bool use_distance_field_text) | 1185 bool use_distance_field_text) |
| 1163 : output_surface_(output_surface), | 1186 : output_surface_(output_surface), |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2091 ContextProvider* context_provider = output_surface_->context_provider(); | 2114 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2092 return context_provider ? context_provider->ContextGL() : NULL; | 2115 return context_provider ? context_provider->ContextGL() : NULL; |
| 2093 } | 2116 } |
| 2094 | 2117 |
| 2095 class GrContext* ResourceProvider::GrContext() const { | 2118 class GrContext* ResourceProvider::GrContext() const { |
| 2096 ContextProvider* context_provider = output_surface_->context_provider(); | 2119 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2097 return context_provider ? context_provider->GrContext() : NULL; | 2120 return context_provider ? context_provider->GrContext() : NULL; |
| 2098 } | 2121 } |
| 2099 | 2122 |
| 2100 } // namespace cc | 2123 } // namespace cc |
| OLD | NEW |