Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 684543006: cc: Toggle LCD text at raster time instead of record time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lcdraster: bettertestsyay Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 doesn't have the correct dff setting,
1108 // recreate the surface within the resource. 1109 // recreate the surface within the resource.
reveman 2014/11/11 21:16:49 this comment needs an update.
danakj 2014/11/12 17:22:10 Done.
1109 if (!resource_->sk_surface || 1110 bool create_surface = !resource_->sk_surface;
1110 use_distance_field_text != 1111 if (!create_surface) {
reveman 2014/11/11 21:16:49 this conditional seems overkill. Temporary variabl
danakj 2014/11/11 21:56:44 It avoids 2 virtual function calls per resource in
reveman 2014/11/13 17:23:15 What are the virtual function calls we avoid here?
danakj 2014/11/13 17:30:32 Mmh.. oh I was thinking of the CanUseLcdText funct
danakj 2014/11/13 19:20:50 OK I split this into a ShouldCreateSurface() funct
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;
1133 resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( 1144 if (can_use_lcd_text) {
1134 gr_texture->asRenderTarget(), text_render_mode)); 1145 // LegacyFontHost will get LCD text and skia figures out what type to use.
1146 SkSurfaceProps surface_props(flags,
1147 SkSurfaceProps::kLegacyFontHost_InitType);
1148 resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect(
1149 gr_texture->asRenderTarget(), &surface_props));
1150 } else {
1151 // Use unknown pixel geometry to disable LCD text.
1152 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry);
1153 resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect(
reveman 2014/11/11 21:16:49 Please avoid duplication of this line. I had to sp
danakj 2014/11/11 21:56:44 OK. I had it that way first but it looked really u
danakj 2014/11/12 17:22:10 Done.
1154 gr_texture->asRenderTarget(), &surface_props));
1155 }
1135 } 1156 }
1136 return resource_->sk_surface.get(); 1157 return resource_->sk_surface.get();
1137 } 1158 }
1138 1159
1139 ResourceProvider::SynchronousFence::SynchronousFence( 1160 ResourceProvider::SynchronousFence::SynchronousFence(
1140 gpu::gles2::GLES2Interface* gl) 1161 gpu::gles2::GLES2Interface* gl)
1141 : gl_(gl), has_synchronized_(true) { 1162 : gl_(gl), has_synchronized_(true) {
1142 } 1163 }
1143 1164
1144 ResourceProvider::SynchronousFence::~SynchronousFence() { 1165 ResourceProvider::SynchronousFence::~SynchronousFence() {
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 ContextProvider* context_provider = output_surface_->context_provider(); 2145 ContextProvider* context_provider = output_surface_->context_provider();
2125 return context_provider ? context_provider->ContextGL() : NULL; 2146 return context_provider ? context_provider->ContextGL() : NULL;
2126 } 2147 }
2127 2148
2128 class GrContext* ResourceProvider::GrContext() const { 2149 class GrContext* ResourceProvider::GrContext() const {
2129 ContextProvider* context_provider = output_surface_->context_provider(); 2150 ContextProvider* context_provider = output_surface_->context_provider();
2130 return context_provider ? context_provider->GrContext() : NULL; 2151 return context_provider ? context_provider->GrContext() : NULL;
2131 } 2152 }
2132 2153
2133 } // namespace cc 2154 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698