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 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 : resource_provider_(resource_provider), | 1093 : resource_provider_(resource_provider), |
1094 resource_(resource_provider->LockForWrite(resource_id)) { | 1094 resource_(resource_provider->LockForWrite(resource_id)) { |
1095 } | 1095 } |
1096 | 1096 |
1097 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | 1097 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
1098 DCHECK(thread_checker_.CalledOnValidThread()); | 1098 DCHECK(thread_checker_.CalledOnValidThread()); |
1099 resource_provider_->UnlockForWrite(resource_); | 1099 resource_provider_->UnlockForWrite(resource_); |
1100 } | 1100 } |
1101 | 1101 |
1102 SkSurface* ResourceProvider::ScopedWriteLockGr::GetSkSurface( | 1102 SkSurface* ResourceProvider::ScopedWriteLockGr::GetSkSurface( |
1103 bool use_distance_field_text) { | 1103 bool use_distance_field_text, |
| 1104 bool can_use_lcd_text) { |
1104 DCHECK(thread_checker_.CalledOnValidThread()); | 1105 DCHECK(thread_checker_.CalledOnValidThread()); |
1105 DCHECK(resource_->locked_for_write); | 1106 DCHECK(resource_->locked_for_write); |
1106 | 1107 |
1107 // If the surface doesn't exist, or doesn't have the correct dff setting, | 1108 // If the surface doesn't exist, or its properties need to be updated, |
1108 // recreate the surface within the resource. | 1109 // recreate the surface within the resource. |
1109 if (!resource_->sk_surface || | 1110 bool create_surface = !resource_->sk_surface; |
1110 use_distance_field_text != | 1111 if (!create_surface) { |
1111 resource_->sk_surface->props().isUseDistanceFieldFonts()) { | 1112 bool surface_uses_distance_field_text = |
| 1113 resource_->sk_surface->props().isUseDistanceFieldFonts(); |
| 1114 if (use_distance_field_text != surface_uses_distance_field_text) |
| 1115 create_surface = true; |
| 1116 bool surface_can_use_lcd_text = |
| 1117 resource_->sk_surface->props().pixelGeometry() != |
| 1118 kUnknown_SkPixelGeometry; |
| 1119 if (can_use_lcd_text != surface_can_use_lcd_text) |
| 1120 create_surface = true; |
| 1121 } |
| 1122 if (create_surface) { |
1112 class GrContext* gr_context = resource_provider_->GrContext(); | 1123 class GrContext* gr_context = resource_provider_->GrContext(); |
1113 // TODO(alokp): Implement TestContextProvider::GrContext(). | 1124 // TODO(alokp): Implement TestContextProvider::GrContext(). |
1114 if (!gr_context) | 1125 if (!gr_context) |
1115 return nullptr; | 1126 return nullptr; |
1116 | 1127 |
1117 resource_provider_->LazyAllocate(resource_); | 1128 resource_provider_->LazyAllocate(resource_); |
1118 | 1129 |
1119 GrBackendTextureDesc desc; | 1130 GrBackendTextureDesc desc; |
1120 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1131 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
1121 desc.fWidth = resource_->size.width(); | 1132 desc.fWidth = resource_->size.width(); |
1122 desc.fHeight = resource_->size.height(); | 1133 desc.fHeight = resource_->size.height(); |
1123 desc.fConfig = ToGrPixelConfig(resource_->format); | 1134 desc.fConfig = ToGrPixelConfig(resource_->format); |
1124 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1135 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
1125 desc.fTextureHandle = resource_->gl_id; | 1136 desc.fTextureHandle = resource_->gl_id; |
1126 skia::RefPtr<GrTexture> gr_texture = | 1137 skia::RefPtr<GrTexture> gr_texture = |
1127 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | 1138 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
1128 if (!gr_texture) | 1139 if (!gr_texture) |
1129 return nullptr; | 1140 return nullptr; |
1130 SkSurface::TextRenderMode text_render_mode = | 1141 uint32_t flags = use_distance_field_text |
1131 use_distance_field_text ? SkSurface::kDistanceField_TextRenderMode | 1142 ? SkSurfaceProps::kUseDistanceFieldFonts_Flag |
1132 : SkSurface::kStandard_TextRenderMode; | 1143 : 0; |
| 1144 // Use unknown pixel geometry to disable LCD text. |
| 1145 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 1146 if (can_use_lcd_text) { |
| 1147 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 1148 surface_props = |
| 1149 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 1150 } |
1133 resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( | 1151 resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( |
1134 gr_texture->asRenderTarget(), text_render_mode)); | 1152 gr_texture->asRenderTarget(), &surface_props)); |
1135 } | 1153 } |
1136 return resource_->sk_surface.get(); | 1154 return resource_->sk_surface.get(); |
1137 } | 1155 } |
1138 | 1156 |
1139 ResourceProvider::SynchronousFence::SynchronousFence( | 1157 ResourceProvider::SynchronousFence::SynchronousFence( |
1140 gpu::gles2::GLES2Interface* gl) | 1158 gpu::gles2::GLES2Interface* gl) |
1141 : gl_(gl), has_synchronized_(true) { | 1159 : gl_(gl), has_synchronized_(true) { |
1142 } | 1160 } |
1143 | 1161 |
1144 ResourceProvider::SynchronousFence::~SynchronousFence() { | 1162 ResourceProvider::SynchronousFence::~SynchronousFence() { |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2124 ContextProvider* context_provider = output_surface_->context_provider(); | 2142 ContextProvider* context_provider = output_surface_->context_provider(); |
2125 return context_provider ? context_provider->ContextGL() : NULL; | 2143 return context_provider ? context_provider->ContextGL() : NULL; |
2126 } | 2144 } |
2127 | 2145 |
2128 class GrContext* ResourceProvider::GrContext() const { | 2146 class GrContext* ResourceProvider::GrContext() const { |
2129 ContextProvider* context_provider = output_surface_->context_provider(); | 2147 ContextProvider* context_provider = output_surface_->context_provider(); |
2130 return context_provider ? context_provider->GrContext() : NULL; | 2148 return context_provider ? context_provider->GrContext() : NULL; |
2131 } | 2149 } |
2132 | 2150 |
2133 } // namespace cc | 2151 } // namespace cc |
OLD | NEW |