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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« cc/resources/resource_provider.h ('K') | « cc/resources/resource_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/resource_provider.cc
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
index ded347763485a32184d0aa950f329e685ce204c4..dc8e76231daaedc954876c05838f5a75a901600a 100644
--- a/cc/resources/resource_provider.cc
+++ b/cc/resources/resource_provider.cc
@@ -995,6 +995,35 @@ void ResourceProvider::UnlockForWriteToGpuMemoryBuffer(ResourceId id) {
resource->read_lock_fences_enabled = true;
}
+SkSurface* ResourceProvider::CreateSkSurface(ResourceId id,
+ bool use_distance_field_text) {
+ Resource* resource = GetResource(id);
+ DCHECK(resource->locked_for_write);
+
+ class GrContext* gr_context = GrContext();
+ // TODO(alokp): Implement TestContextProvider::GrContext().
+ if (!gr_context)
+ return nullptr;
+
+ 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->sk_surface.get();
+}
+
const ResourceProvider::Resource* ResourceProvider::LockForWriteToSkSurface(
ResourceId id) {
Resource* resource = GetResource(id);
@@ -1002,28 +1031,9 @@ const ResourceProvider::Resource* ResourceProvider::LockForWriteToSkSurface(
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));
+ CreateSkSurface(id, use_distance_field_text_);
reveman 2014/10/15 17:34:09 Let's not bother to create the surface here if you
}
return resource;
@@ -1151,6 +1161,19 @@ ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() {
resource_provider_->UnlockForWriteToSkSurface(resource_id_);
}
+void ResourceProvider::ScopedWriteLockGr::SetUseDistanceFieldText(
+ bool use_distance_field_text) {
+ bool surface_uses_distance_field =
+ resource_provider_->use_distance_field_text_ || use_distance_field_text;
reveman 2014/10/15 17:34:09 what is ResourceProvider::use_distance_field_text_
+ // If the surface doesn't have the correct dff setting, recreate the surface
+ // within the resource.
+ if (surface_uses_distance_field !=
+ sk_surface_->props().isUseDistanceFieldFonts()) {
+ sk_surface_ = resource_provider_->CreateSkSurface(resource_id_,
+ use_distance_field_text);
+ }
+}
+
ResourceProvider::ResourceProvider(
OutputSurface* output_surface,
SharedBitmapManager* shared_bitmap_manager,
« cc/resources/resource_provider.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