| Index: cc/resources/resource_provider.cc
|
| diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
|
| index ded347763485a32184d0aa950f329e685ce204c4..17ae2456e61d7a31bc952bea73fbfea5b3fa0b30 100644
|
| --- a/cc/resources/resource_provider.cc
|
| +++ b/cc/resources/resource_provider.cc
|
| @@ -995,38 +995,19 @@ 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);
|
| + class GrContext* gr_context = GrContext();
|
| + // TODO(alokp): Implement TestContextProvider::GrContext().
|
| + if (!gr_context)
|
| + return;
|
|
|
| - 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));
|
| - }
|
| + LazyAllocate(resource);
|
|
|
| - return resource;
|
| + resource->locked_for_write = true;
|
| }
|
|
|
| void ResourceProvider::UnlockForWriteToSkSurface(ResourceId id) {
|
| @@ -1141,16 +1122,50 @@ 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;
|
| + // 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;
|
| +
|
| + 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();
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| ResourceProvider::ResourceProvider(
|
| OutputSurface* output_surface,
|
| SharedBitmapManager* shared_bitmap_manager,
|
|
|