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

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

Issue 648293006: cc: turn on distance field text on animated layers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: "removed test code" Created 6 years, 2 months 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 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const ResourceProvider::Resource* ResourceProvider::LockForWriteToSkSurface( 998 void ResourceProvider::LockForWriteToSkSurface(ResourceId id) {
999 ResourceId id) {
1000 Resource* resource = GetResource(id); 999 Resource* resource = GetResource(id);
1001 DCHECK_EQ(GLTexture, resource->type); 1000 DCHECK_EQ(GLTexture, resource->type);
1002 DCHECK(CanLockForWrite(id)); 1001 DCHECK(CanLockForWrite(id));
1003 1002
1004 resource->locked_for_write = true; 1003 resource->locked_for_write = true;
1005 if (!resource->sk_surface) {
1006 class GrContext* gr_context = GrContext();
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 }
1028
1029 return resource;
1030 } 1004 }
1031 1005
1032 void ResourceProvider::UnlockForWriteToSkSurface(ResourceId id) { 1006 void ResourceProvider::UnlockForWriteToSkSurface(ResourceId id) {
1033 Resource* resource = GetResource(id); 1007 Resource* resource = GetResource(id);
1034 DCHECK(resource->locked_for_write); 1008 DCHECK(resource->locked_for_write);
1035 DCHECK_EQ(resource->exported_count, 0); 1009 DCHECK_EQ(resource->exported_count, 0);
1036 DCHECK(resource->origin == Resource::Internal); 1010 DCHECK(resource->origin == Resource::Internal);
1037 DCHECK_EQ(GLTexture, resource->type); 1011 DCHECK_EQ(GLTexture, resource->type);
1038 resource->locked_for_write = false; 1012 resource->locked_for_write = false;
1039 } 1013 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 } 1108 }
1135 1109
1136 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: 1110 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::
1137 ~ScopedWriteLockGpuMemoryBuffer() { 1111 ~ScopedWriteLockGpuMemoryBuffer() {
1138 resource_provider_->UnlockForWriteToGpuMemoryBuffer(resource_id_); 1112 resource_provider_->UnlockForWriteToGpuMemoryBuffer(resource_id_);
1139 } 1113 }
1140 1114
1141 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( 1115 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr(
1142 ResourceProvider* resource_provider, 1116 ResourceProvider* resource_provider,
1143 ResourceProvider::ResourceId resource_id) 1117 ResourceProvider::ResourceId resource_id)
1144 : resource_provider_(resource_provider), 1118 : resource_provider_(resource_provider), resource_id_(resource_id) {
1145 resource_id_(resource_id), 1119 resource_provider->LockForWriteToSkSurface(resource_id);
1146 sk_surface_(resource_provider->LockForWriteToSkSurface(resource_id)
1147 ->sk_surface.get()) {
1148 } 1120 }
1149 1121
1150 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { 1122 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() {
1151 resource_provider_->UnlockForWriteToSkSurface(resource_id_); 1123 resource_provider_->UnlockForWriteToSkSurface(resource_id_);
1152 } 1124 }
1153 1125
1126 SkSurface* ResourceProvider::ScopedWriteLockGr::GetSkSurface(
1127 bool use_distance_field_text) {
1128 Resource* resource = resource_provider_->GetResource(resource_id_);
1129 DCHECK(resource->locked_for_write);
1130
1131 bool surface_uses_distance_field =
1132 resource_provider_->use_distance_field_text_ || use_distance_field_text;
reveman 2014/10/20 18:38:29 ResourceProvider::use_distance_field_text_ should
1133 // If the surface doesn't have the correct dff setting, recreate the surface
1134 // within the resource.
1135 if (!resource->sk_surface ||
1136 surface_uses_distance_field !=
1137 resource->sk_surface->props().isUseDistanceFieldFonts()) {
1138 class GrContext* gr_context = resource_provider_->GrContext();
1139 // TODO(alokp): Implement TestContextProvider::GrContext().
1140 if (!gr_context)
1141 return nullptr;
1142
1143 resource_provider_->LazyAllocate(resource);
1144
1145 GrBackendTextureDesc desc;
1146 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
1147 desc.fWidth = resource->size.width();
1148 desc.fHeight = resource->size.height();
1149 desc.fConfig = ToGrPixelConfig(resource->format);
1150 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
1151 desc.fTextureHandle = resource->gl_id;
1152 skia::RefPtr<GrTexture> gr_texture =
1153 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
1154 SkSurface::TextRenderMode text_render_mode =
1155 surface_uses_distance_field ? SkSurface::kDistanceField_TextRenderMode
1156 : SkSurface::kStandard_TextRenderMode;
1157 resource->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect(
1158 gr_texture->asRenderTarget(), text_render_mode));
1159 }
1160 return resource->sk_surface.get();
1161 }
1162
1154 ResourceProvider::ResourceProvider( 1163 ResourceProvider::ResourceProvider(
1155 OutputSurface* output_surface, 1164 OutputSurface* output_surface,
1156 SharedBitmapManager* shared_bitmap_manager, 1165 SharedBitmapManager* shared_bitmap_manager,
1157 GpuMemoryBufferManager* gpu_memory_buffer_manager, 1166 GpuMemoryBufferManager* gpu_memory_buffer_manager,
1158 BlockingTaskRunner* blocking_main_thread_task_runner, 1167 BlockingTaskRunner* blocking_main_thread_task_runner,
1159 int highp_threshold_min, 1168 int highp_threshold_min,
1160 bool use_rgba_4444_texture_format, 1169 bool use_rgba_4444_texture_format,
1161 size_t id_allocation_chunk_size, 1170 size_t id_allocation_chunk_size,
1162 bool use_distance_field_text) 1171 bool use_distance_field_text)
1163 : output_surface_(output_surface), 1172 : output_surface_(output_surface),
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 ContextProvider* context_provider = output_surface_->context_provider(); 2100 ContextProvider* context_provider = output_surface_->context_provider();
2092 return context_provider ? context_provider->ContextGL() : NULL; 2101 return context_provider ? context_provider->ContextGL() : NULL;
2093 } 2102 }
2094 2103
2095 class GrContext* ResourceProvider::GrContext() const { 2104 class GrContext* ResourceProvider::GrContext() const {
2096 ContextProvider* context_provider = output_surface_->context_provider(); 2105 ContextProvider* context_provider = output_surface_->context_provider();
2097 return context_provider ? context_provider->GrContext() : NULL; 2106 return context_provider ? context_provider->GrContext() : NULL;
2098 } 2107 }
2099 2108
2100 } // namespace cc 2109 } // namespace cc
OLDNEW
« cc/resources/picture_pile_impl.h ('K') | « cc/resources/resource_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698