Chromium Code Reviews| Index: cc/resources/resource_provider.cc |
| diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc |
| index 578c2e9096bea25b12ba3724d39af5633528e9d8..e19da9c890e5ffd1f8ef43f21e31498b28db0f85 100644 |
| --- a/cc/resources/resource_provider.cc |
| +++ b/cc/resources/resource_provider.cc |
| @@ -995,38 +995,12 @@ void ResourceProvider::UnlockForWriteToGpuMemoryBuffer(ResourceId id) { |
| resource->read_lock_fences_enabled = true; |
| } |
| -const ResourceProvider::Resource* ResourceProvider::LockForWriteToSkSurface( |
| - ResourceId id) { |
| +void ResourceProvider::LockForWriteToSkSurface(ResourceId id) { |
| Resource* resource = GetResource(id); |
| DCHECK_EQ(GLTexture, resource->type); |
| DCHECK(CanLockForWrite(id)); |
| resource->locked_for_write = true; |
| - if (!resource->sk_surface) { |
| - class GrContext* gr_context = GrContext(); |
| - // TODO(alokp): Implement TestContextProvider::GrContext(). |
| - if (!gr_context) |
| - return resource; |
| - |
| - LazyAllocate(resource); |
| - |
| - GrBackendTextureDesc desc; |
| - desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| - desc.fWidth = resource->size.width(); |
| - desc.fHeight = resource->size.height(); |
| - desc.fConfig = ToGrPixelConfig(resource->format); |
| - desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| - desc.fTextureHandle = resource->gl_id; |
| - skia::RefPtr<GrTexture> gr_texture = |
| - skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
| - SkSurface::TextRenderMode text_render_mode = |
| - use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode |
| - : SkSurface::kStandard_TextRenderMode; |
| - resource->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( |
| - gr_texture->asRenderTarget(), text_render_mode)); |
| - } |
| - |
| - return resource; |
| } |
| void ResourceProvider::UnlockForWriteToSkSurface(ResourceId id) { |
| @@ -1141,16 +1115,51 @@ ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( |
| ResourceProvider* resource_provider, |
| ResourceProvider::ResourceId resource_id) |
| - : resource_provider_(resource_provider), |
| - resource_id_(resource_id), |
| - sk_surface_(resource_provider->LockForWriteToSkSurface(resource_id) |
| - ->sk_surface.get()) { |
| + : resource_provider_(resource_provider), resource_id_(resource_id) { |
| + resource_provider->LockForWriteToSkSurface(resource_id); |
| } |
| ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
| resource_provider_->UnlockForWriteToSkSurface(resource_id_); |
| } |
| +SkSurface* ResourceProvider::ScopedWriteLockGr::GetSkSurface( |
| + bool use_distance_field_text) { |
| + Resource* resource = resource_provider_->GetResource(resource_id_); |
| + DCHECK(resource->locked_for_write); |
| + |
| + bool surface_uses_distance_field = |
| + resource_provider_->use_distance_field_text_ || use_distance_field_text; |
|
reveman
2014/10/20 18:38:29
ResourceProvider::use_distance_field_text_ should
|
| + // If the surface doesn't have the correct dff setting, recreate the surface |
| + // within the resource. |
| + if (!resource->sk_surface || |
| + surface_uses_distance_field != |
| + resource->sk_surface->props().isUseDistanceFieldFonts()) { |
| + class GrContext* gr_context = resource_provider_->GrContext(); |
| + // TODO(alokp): Implement TestContextProvider::GrContext(). |
| + if (!gr_context) |
| + return nullptr; |
| + |
| + resource_provider_->LazyAllocate(resource); |
| + |
| + GrBackendTextureDesc desc; |
| + desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| + desc.fWidth = resource->size.width(); |
| + desc.fHeight = resource->size.height(); |
| + desc.fConfig = ToGrPixelConfig(resource->format); |
| + desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| + desc.fTextureHandle = resource->gl_id; |
| + skia::RefPtr<GrTexture> gr_texture = |
| + skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
| + SkSurface::TextRenderMode text_render_mode = |
| + surface_uses_distance_field ? SkSurface::kDistanceField_TextRenderMode |
| + : SkSurface::kStandard_TextRenderMode; |
| + resource->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( |
| + gr_texture->asRenderTarget(), text_render_mode)); |
| + } |
| + return resource->sk_surface.get(); |
| +} |
| + |
| ResourceProvider::ResourceProvider( |
| OutputSurface* output_surface, |
| SharedBitmapManager* shared_bitmap_manager, |