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 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1080 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
1081 size_, ToGpuMemoryBufferFormat(format_), gfx::GpuMemoryBuffer::MAP); | 1081 size_, ToGpuMemoryBufferFormat(format_), gfx::GpuMemoryBuffer::MAP); |
1082 gpu_memory_buffer_ = gpu_memory_buffer.release(); | 1082 gpu_memory_buffer_ = gpu_memory_buffer.release(); |
1083 } | 1083 } |
1084 | 1084 |
1085 return gpu_memory_buffer_; | 1085 return gpu_memory_buffer_; |
1086 } | 1086 } |
1087 | 1087 |
1088 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( | 1088 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( |
1089 ResourceProvider* resource_provider, | 1089 ResourceProvider* resource_provider, |
1090 ResourceProvider::ResourceId resource_id) | 1090 ResourceProvider::ResourceId resource_id, |
| 1091 bool use_distance_field_text, |
| 1092 bool can_use_lcd_text, |
| 1093 int msaa_sample_count) |
1091 : resource_provider_(resource_provider), | 1094 : resource_provider_(resource_provider), |
1092 resource_(resource_provider->LockForWrite(resource_id)) { | 1095 resource_(resource_provider->LockForWrite(resource_id)) { |
1093 } | 1096 // Create the sk_surface. |
1094 | |
1095 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | |
1096 DCHECK(thread_checker_.CalledOnValidThread()); | |
1097 resource_provider_->UnlockForWrite(resource_); | |
1098 } | |
1099 | |
1100 SkSurface* ResourceProvider::ScopedWriteLockGr::GetSkSurface( | |
1101 bool use_distance_field_text, | |
1102 bool can_use_lcd_text) { | |
1103 DCHECK(thread_checker_.CalledOnValidThread()); | 1097 DCHECK(thread_checker_.CalledOnValidThread()); |
1104 DCHECK(resource_->locked_for_write); | 1098 DCHECK(resource_->locked_for_write); |
1105 | 1099 |
1106 bool create_surface = | 1100 resource_provider_->LazyAllocate(resource_); |
1107 !resource_->sk_surface.get() || | |
1108 !SurfaceHasMatchingProperties(use_distance_field_text, can_use_lcd_text); | |
1109 if (create_surface) { | |
1110 resource_provider_->LazyAllocate(resource_); | |
1111 | 1101 |
1112 GrBackendTextureDesc desc; | 1102 GrBackendTextureDesc desc; |
1113 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1103 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
1114 desc.fWidth = resource_->size.width(); | 1104 desc.fWidth = resource_->size.width(); |
1115 desc.fHeight = resource_->size.height(); | 1105 desc.fHeight = resource_->size.height(); |
1116 desc.fConfig = ToGrPixelConfig(resource_->format); | 1106 desc.fConfig = ToGrPixelConfig(resource_->format); |
1117 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1107 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
1118 desc.fTextureHandle = resource_->gl_id; | 1108 desc.fTextureHandle = resource_->gl_id; |
| 1109 desc.fSampleCnt = msaa_sample_count; |
1119 | 1110 |
1120 class GrContext* gr_context = resource_provider_->GrContext(); | 1111 class GrContext* gr_context = resource_provider_->GrContext(); |
1121 skia::RefPtr<GrTexture> gr_texture = | 1112 skia::RefPtr<GrTexture> gr_texture = |
1122 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | 1113 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
1123 if (!gr_texture) | 1114 if (gr_texture) { |
1124 return nullptr; | |
1125 uint32_t flags = use_distance_field_text | 1115 uint32_t flags = use_distance_field_text |
1126 ? SkSurfaceProps::kUseDistanceFieldFonts_Flag | 1116 ? SkSurfaceProps::kUseDistanceFieldFonts_Flag |
1127 : 0; | 1117 : 0; |
1128 // Use unknown pixel geometry to disable LCD text. | 1118 // Use unknown pixel geometry to disable LCD text. |
1129 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | 1119 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
1130 if (can_use_lcd_text) { | 1120 if (can_use_lcd_text) { |
1131 // LegacyFontHost will get LCD text and skia figures out what type to use. | 1121 // LegacyFontHost will get LCD text and skia figures out what type to use. |
1132 surface_props = | 1122 surface_props = |
1133 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 1123 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
1134 } | 1124 } |
1135 resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( | 1125 sk_surface_ = skia::AdoptRef(SkSurface::NewRenderTargetDirect( |
1136 gr_texture->asRenderTarget(), &surface_props)); | 1126 gr_texture->asRenderTarget(), &surface_props)); |
1137 } | 1127 } |
1138 return resource_->sk_surface.get(); | |
1139 } | 1128 } |
1140 | 1129 |
1141 bool ResourceProvider::ScopedWriteLockGr::SurfaceHasMatchingProperties( | 1130 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
1142 bool use_distance_field_text, | 1131 DCHECK(thread_checker_.CalledOnValidThread()); |
1143 bool can_use_lcd_text) const { | 1132 resource_provider_->UnlockForWrite(resource_); |
1144 const SkSurface* surface = resource_->sk_surface.get(); | |
1145 bool surface_uses_distance_field_text = | |
1146 surface->props().isUseDistanceFieldFonts(); | |
1147 bool surface_can_use_lcd_text = | |
1148 surface->props().pixelGeometry() != kUnknown_SkPixelGeometry; | |
1149 return use_distance_field_text == surface_uses_distance_field_text && | |
1150 can_use_lcd_text == surface_can_use_lcd_text; | |
1151 } | 1133 } |
1152 | 1134 |
1153 ResourceProvider::SynchronousFence::SynchronousFence( | 1135 ResourceProvider::SynchronousFence::SynchronousFence( |
1154 gpu::gles2::GLES2Interface* gl) | 1136 gpu::gles2::GLES2Interface* gl) |
1155 : gl_(gl), has_synchronized_(true) { | 1137 : gl_(gl), has_synchronized_(true) { |
1156 } | 1138 } |
1157 | 1139 |
1158 ResourceProvider::SynchronousFence::~SynchronousFence() { | 1140 ResourceProvider::SynchronousFence::~SynchronousFence() { |
1159 } | 1141 } |
1160 | 1142 |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2152 ContextProvider* context_provider = output_surface_->context_provider(); | 2134 ContextProvider* context_provider = output_surface_->context_provider(); |
2153 return context_provider ? context_provider->ContextGL() : NULL; | 2135 return context_provider ? context_provider->ContextGL() : NULL; |
2154 } | 2136 } |
2155 | 2137 |
2156 class GrContext* ResourceProvider::GrContext() const { | 2138 class GrContext* ResourceProvider::GrContext() const { |
2157 ContextProvider* context_provider = output_surface_->context_provider(); | 2139 ContextProvider* context_provider = output_surface_->context_provider(); |
2158 return context_provider ? context_provider->GrContext() : NULL; | 2140 return context_provider ? context_provider->GrContext() : NULL; |
2159 } | 2141 } |
2160 | 2142 |
2161 } // namespace cc | 2143 } // namespace cc |
OLD | NEW |