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

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

Issue 266743003: Add flag to enable rendering of text using signed distance fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix uses of ResourceProvider::Create() outside of Chrome proper. Created 6 years, 7 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
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 424
425 if (locked_canvas_) { 425 if (locked_canvas_) {
426 locked_canvas_->restoreToCount(canvas_save_count_); 426 locked_canvas_->restoreToCount(canvas_save_count_);
427 locked_canvas_ = NULL; 427 locked_canvas_ = NULL;
428 } 428 }
429 return DoUnlockForWrite(); 429 return DoUnlockForWrite();
430 } 430 }
431 431
432 ResourceProvider::DirectRasterBuffer::DirectRasterBuffer( 432 ResourceProvider::DirectRasterBuffer::DirectRasterBuffer(
433 const Resource* resource, 433 const Resource* resource,
434 ResourceProvider* resource_provider) 434 ResourceProvider* resource_provider,
435 : RasterBuffer(resource, resource_provider), surface_generation_id_(0u) {} 435 bool use_distance_field_text )
436 : RasterBuffer(resource, resource_provider),
437 surface_generation_id_(0u),
438 use_distance_field_text_(use_distance_field_text) {}
436 439
437 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {} 440 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {}
438 441
439 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() { 442 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() {
440 if (!surface_) 443 if (!surface_)
441 surface_ = CreateSurface(); 444 surface_ = CreateSurface();
442 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; 445 surface_generation_id_ = surface_ ? surface_->generationID() : 0u;
443 return surface_ ? surface_->getCanvas() : NULL; 446 return surface_ ? surface_->getCanvas() : NULL;
444 } 447 }
445 448
(...skipping 13 matching lines...) Expand all
459 if (gr_context) { 462 if (gr_context) {
460 GrBackendTextureDesc desc; 463 GrBackendTextureDesc desc;
461 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 464 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
462 desc.fWidth = resource()->size.width(); 465 desc.fWidth = resource()->size.width();
463 desc.fHeight = resource()->size.height(); 466 desc.fHeight = resource()->size.height();
464 desc.fConfig = ToGrPixelConfig(resource()->format); 467 desc.fConfig = ToGrPixelConfig(resource()->format);
465 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 468 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
466 desc.fTextureHandle = resource()->gl_id; 469 desc.fTextureHandle = resource()->gl_id;
467 skia::RefPtr<GrTexture> gr_texture = 470 skia::RefPtr<GrTexture> gr_texture =
468 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); 471 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
469 surface = skia::AdoptRef( 472 SkSurface::TextRenderMode text_render_mode =
470 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); 473 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode
474 : SkSurface::kStandard_TextRenderMode;
475 surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect(
476 gr_texture->asRenderTarget(), text_render_mode));
471 } 477 }
472 break; 478 break;
473 } 479 }
474 case Bitmap: { 480 case Bitmap: {
475 DCHECK(resource()->pixels); 481 DCHECK(resource()->pixels);
476 DCHECK_EQ(RGBA_8888, resource()->format); 482 DCHECK_EQ(RGBA_8888, resource()->format);
477 SkImageInfo image_info = SkImageInfo::MakeN32Premul( 483 SkImageInfo image_info = SkImageInfo::MakeN32Premul(
478 resource()->size.width(), resource()->size.height()); 484 resource()->size.width(), resource()->size.height());
479 surface = skia::AdoptRef(SkSurface::NewRasterDirect( 485 surface = skia::AdoptRef(SkSurface::NewRasterDirect(
480 image_info, resource()->pixels, image_info.minRowBytes())); 486 image_info, resource()->pixels, image_info.minRowBytes()));
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 591
586 ResourceProvider::Child::Child() : marked_for_deletion(false) {} 592 ResourceProvider::Child::Child() : marked_for_deletion(false) {}
587 593
588 ResourceProvider::Child::~Child() {} 594 ResourceProvider::Child::~Child() {}
589 595
590 scoped_ptr<ResourceProvider> ResourceProvider::Create( 596 scoped_ptr<ResourceProvider> ResourceProvider::Create(
591 OutputSurface* output_surface, 597 OutputSurface* output_surface,
592 SharedBitmapManager* shared_bitmap_manager, 598 SharedBitmapManager* shared_bitmap_manager,
593 int highp_threshold_min, 599 int highp_threshold_min,
594 bool use_rgba_4444_texture_format, 600 bool use_rgba_4444_texture_format,
595 size_t id_allocation_chunk_size) { 601 size_t id_allocation_chunk_size,
602 bool use_distance_field_text) {
596 scoped_ptr<ResourceProvider> resource_provider( 603 scoped_ptr<ResourceProvider> resource_provider(
597 new ResourceProvider(output_surface, 604 new ResourceProvider(output_surface,
598 shared_bitmap_manager, 605 shared_bitmap_manager,
599 highp_threshold_min, 606 highp_threshold_min,
600 use_rgba_4444_texture_format, 607 use_rgba_4444_texture_format,
601 id_allocation_chunk_size)); 608 id_allocation_chunk_size,
609 use_distance_field_text));
602 610
603 if (resource_provider->ContextGL()) 611 if (resource_provider->ContextGL())
604 resource_provider->InitializeGL(); 612 resource_provider->InitializeGL();
605 else 613 else
606 resource_provider->InitializeSoftware(); 614 resource_provider->InitializeSoftware();
607 615
608 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); 616 DCHECK_NE(InvalidType, resource_provider->default_resource_type());
609 return resource_provider.Pass(); 617 return resource_provider.Pass();
610 } 618 }
611 619
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 } 1248 }
1241 1249
1242 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { 1250 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
1243 resource_provider_->UnlockForWrite(resource_id_); 1251 resource_provider_->UnlockForWrite(resource_id_);
1244 } 1252 }
1245 1253
1246 ResourceProvider::ResourceProvider(OutputSurface* output_surface, 1254 ResourceProvider::ResourceProvider(OutputSurface* output_surface,
1247 SharedBitmapManager* shared_bitmap_manager, 1255 SharedBitmapManager* shared_bitmap_manager,
1248 int highp_threshold_min, 1256 int highp_threshold_min,
1249 bool use_rgba_4444_texture_format, 1257 bool use_rgba_4444_texture_format,
1250 size_t id_allocation_chunk_size) 1258 size_t id_allocation_chunk_size,
1259 bool use_distance_field_text)
1251 : output_surface_(output_surface), 1260 : output_surface_(output_surface),
1252 shared_bitmap_manager_(shared_bitmap_manager), 1261 shared_bitmap_manager_(shared_bitmap_manager),
1253 lost_output_surface_(false), 1262 lost_output_surface_(false),
1254 highp_threshold_min_(highp_threshold_min), 1263 highp_threshold_min_(highp_threshold_min),
1255 next_id_(1), 1264 next_id_(1),
1256 next_child_(1), 1265 next_child_(1),
1257 default_resource_type_(InvalidType), 1266 default_resource_type_(InvalidType),
1258 use_texture_storage_ext_(false), 1267 use_texture_storage_ext_(false),
1259 use_texture_usage_hint_(false), 1268 use_texture_usage_hint_(false),
1260 use_compressed_texture_etc1_(false), 1269 use_compressed_texture_etc1_(false),
1261 max_texture_size_(0), 1270 max_texture_size_(0),
1262 best_texture_format_(RGBA_8888), 1271 best_texture_format_(RGBA_8888),
1263 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), 1272 use_rgba_4444_texture_format_(use_rgba_4444_texture_format),
1264 id_allocation_chunk_size_(id_allocation_chunk_size), 1273 id_allocation_chunk_size_(id_allocation_chunk_size),
1265 use_sync_query_(false) { 1274 use_sync_query_(false),
1275 use_distance_field_text_(use_distance_field_text) {
1266 DCHECK(output_surface_->HasClient()); 1276 DCHECK(output_surface_->HasClient());
1267 DCHECK(id_allocation_chunk_size_); 1277 DCHECK(id_allocation_chunk_size_);
1268 } 1278 }
1269 1279
1270 void ResourceProvider::InitializeSoftware() { 1280 void ResourceProvider::InitializeSoftware() {
1271 DCHECK(thread_checker_.CalledOnValidThread()); 1281 DCHECK(thread_checker_.CalledOnValidThread());
1272 DCHECK_NE(Bitmap, default_resource_type_); 1282 DCHECK_NE(Bitmap, default_resource_type_);
1273 1283
1274 CleanUpGLIfNeeded(); 1284 CleanUpGLIfNeeded();
1275 1285
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 } 1760 }
1751 } 1761 }
1752 1762
1753 SkCanvas* ResourceProvider::MapDirectRasterBuffer(ResourceId id) { 1763 SkCanvas* ResourceProvider::MapDirectRasterBuffer(ResourceId id) {
1754 // Resource needs to be locked for write since DirectRasterBuffer writes 1764 // Resource needs to be locked for write since DirectRasterBuffer writes
1755 // directly to it. 1765 // directly to it.
1756 LockForWrite(id); 1766 LockForWrite(id);
1757 Resource* resource = GetResource(id); 1767 Resource* resource = GetResource(id);
1758 if (!resource->direct_raster_buffer.get()) { 1768 if (!resource->direct_raster_buffer.get()) {
1759 resource->direct_raster_buffer.reset( 1769 resource->direct_raster_buffer.reset(
1760 new DirectRasterBuffer(resource, this)); 1770 new DirectRasterBuffer(resource, this, use_distance_field_text_));
1761 } 1771 }
1762 return resource->direct_raster_buffer->LockForWrite(); 1772 return resource->direct_raster_buffer->LockForWrite();
1763 } 1773 }
1764 1774
1765 void ResourceProvider::UnmapDirectRasterBuffer(ResourceId id) { 1775 void ResourceProvider::UnmapDirectRasterBuffer(ResourceId id) {
1766 Resource* resource = GetResource(id); 1776 Resource* resource = GetResource(id);
1767 DCHECK(resource->direct_raster_buffer.get()); 1777 DCHECK(resource->direct_raster_buffer.get());
1768 resource->direct_raster_buffer->UnlockForWrite(); 1778 resource->direct_raster_buffer->UnlockForWrite();
1769 UnlockForWrite(id); 1779 UnlockForWrite(id);
1770 } 1780 }
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 ContextProvider* context_provider = output_surface_->context_provider(); 2285 ContextProvider* context_provider = output_surface_->context_provider();
2276 return context_provider ? context_provider->ContextGL() : NULL; 2286 return context_provider ? context_provider->ContextGL() : NULL;
2277 } 2287 }
2278 2288
2279 class GrContext* ResourceProvider::GrContext() const { 2289 class GrContext* ResourceProvider::GrContext() const {
2280 ContextProvider* context_provider = output_surface_->context_provider(); 2290 ContextProvider* context_provider = output_surface_->context_provider();
2281 return context_provider ? context_provider->GrContext() : NULL; 2291 return context_provider ? context_provider->GrContext() : NULL;
2282 } 2292 }
2283 2293
2284 } // namespace cc 2294 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698