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