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 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 : resource_provider_(resource_provider), | 1105 : resource_provider_(resource_provider), |
1106 resource_(resource_provider->LockForWrite(resource_id)) { | 1106 resource_(resource_provider->LockForWrite(resource_id)) { |
1107 } | 1107 } |
1108 | 1108 |
1109 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | 1109 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
1110 DCHECK(thread_checker_.CalledOnValidThread()); | 1110 DCHECK(thread_checker_.CalledOnValidThread()); |
1111 resource_provider_->UnlockForWrite(resource_); | 1111 resource_provider_->UnlockForWrite(resource_); |
1112 } | 1112 } |
1113 | 1113 |
1114 SkSurface* ResourceProvider::ScopedWriteLockGr::GetSkSurface( | 1114 SkSurface* ResourceProvider::ScopedWriteLockGr::GetSkSurface( |
1115 bool use_distance_field_text) { | 1115 bool use_distance_field_text, |
| 1116 bool can_use_lcd_text) { |
1116 DCHECK(thread_checker_.CalledOnValidThread()); | 1117 DCHECK(thread_checker_.CalledOnValidThread()); |
1117 DCHECK(resource_->locked_for_write); | 1118 DCHECK(resource_->locked_for_write); |
1118 | 1119 |
1119 // If the surface doesn't exist, or doesn't have the correct dff setting, | 1120 bool create_surface = |
1120 // recreate the surface within the resource. | 1121 !resource_->sk_surface.get() || |
1121 if (!resource_->sk_surface || | 1122 !SurfaceHasMatchingProperties(use_distance_field_text, can_use_lcd_text); |
1122 use_distance_field_text != | 1123 if (create_surface) { |
1123 resource_->sk_surface->props().isUseDistanceFieldFonts()) { | |
1124 class GrContext* gr_context = resource_provider_->GrContext(); | 1124 class GrContext* gr_context = resource_provider_->GrContext(); |
1125 // TODO(alokp): Implement TestContextProvider::GrContext(). | 1125 // TODO(alokp): Implement TestContextProvider::GrContext(). |
1126 if (!gr_context) | 1126 if (!gr_context) |
1127 return nullptr; | 1127 return nullptr; |
1128 | 1128 |
1129 resource_provider_->LazyAllocate(resource_); | 1129 resource_provider_->LazyAllocate(resource_); |
1130 | 1130 |
1131 GrBackendTextureDesc desc; | 1131 GrBackendTextureDesc desc; |
1132 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1132 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
1133 desc.fWidth = resource_->size.width(); | 1133 desc.fWidth = resource_->size.width(); |
1134 desc.fHeight = resource_->size.height(); | 1134 desc.fHeight = resource_->size.height(); |
1135 desc.fConfig = ToGrPixelConfig(resource_->format); | 1135 desc.fConfig = ToGrPixelConfig(resource_->format); |
1136 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1136 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
1137 desc.fTextureHandle = resource_->gl_id; | 1137 desc.fTextureHandle = resource_->gl_id; |
1138 skia::RefPtr<GrTexture> gr_texture = | 1138 skia::RefPtr<GrTexture> gr_texture = |
1139 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | 1139 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
1140 if (!gr_texture) | 1140 if (!gr_texture) |
1141 return nullptr; | 1141 return nullptr; |
1142 SkSurface::TextRenderMode text_render_mode = | 1142 uint32_t flags = use_distance_field_text |
1143 use_distance_field_text ? SkSurface::kDistanceField_TextRenderMode | 1143 ? SkSurfaceProps::kUseDistanceFieldFonts_Flag |
1144 : SkSurface::kStandard_TextRenderMode; | 1144 : 0; |
| 1145 // Use unknown pixel geometry to disable LCD text. |
| 1146 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 1147 if (can_use_lcd_text) { |
| 1148 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 1149 surface_props = |
| 1150 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 1151 } |
1145 resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( | 1152 resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( |
1146 gr_texture->asRenderTarget(), text_render_mode)); | 1153 gr_texture->asRenderTarget(), &surface_props)); |
1147 } | 1154 } |
1148 return resource_->sk_surface.get(); | 1155 return resource_->sk_surface.get(); |
1149 } | 1156 } |
1150 | 1157 |
| 1158 bool ResourceProvider::ScopedWriteLockGr::SurfaceHasMatchingProperties( |
| 1159 bool use_distance_field_text, |
| 1160 bool can_use_lcd_text) const { |
| 1161 const SkSurface* surface = resource_->sk_surface.get(); |
| 1162 bool surface_uses_distance_field_text = |
| 1163 surface->props().isUseDistanceFieldFonts(); |
| 1164 bool surface_can_use_lcd_text = |
| 1165 surface->props().pixelGeometry() != kUnknown_SkPixelGeometry; |
| 1166 return use_distance_field_text == surface_uses_distance_field_text && |
| 1167 can_use_lcd_text == surface_can_use_lcd_text; |
| 1168 } |
| 1169 |
1151 ResourceProvider::SynchronousFence::SynchronousFence( | 1170 ResourceProvider::SynchronousFence::SynchronousFence( |
1152 gpu::gles2::GLES2Interface* gl) | 1171 gpu::gles2::GLES2Interface* gl) |
1153 : gl_(gl), has_synchronized_(true) { | 1172 : gl_(gl), has_synchronized_(true) { |
1154 } | 1173 } |
1155 | 1174 |
1156 ResourceProvider::SynchronousFence::~SynchronousFence() { | 1175 ResourceProvider::SynchronousFence::~SynchronousFence() { |
1157 } | 1176 } |
1158 | 1177 |
1159 void ResourceProvider::SynchronousFence::Set() { | 1178 void ResourceProvider::SynchronousFence::Set() { |
1160 has_synchronized_ = false; | 1179 has_synchronized_ = false; |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 ContextProvider* context_provider = output_surface_->context_provider(); | 2155 ContextProvider* context_provider = output_surface_->context_provider(); |
2137 return context_provider ? context_provider->ContextGL() : NULL; | 2156 return context_provider ? context_provider->ContextGL() : NULL; |
2138 } | 2157 } |
2139 | 2158 |
2140 class GrContext* ResourceProvider::GrContext() const { | 2159 class GrContext* ResourceProvider::GrContext() const { |
2141 ContextProvider* context_provider = output_surface_->context_provider(); | 2160 ContextProvider* context_provider = output_surface_->context_provider(); |
2142 return context_provider ? context_provider->GrContext() : NULL; | 2161 return context_provider ? context_provider->GrContext() : NULL; |
2143 } | 2162 } |
2144 | 2163 |
2145 } // namespace cc | 2164 } // namespace cc |
OLD | NEW |