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

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

Issue 184573002: Use MSAA in GPU rasterization if Skia suggests it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 6 years, 9 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') | no next file » | 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 scoped_ptr<GLuint[]> ids_; 54 scoped_ptr<GLuint[]> ids_;
55 size_t next_id_index_; 55 size_t next_id_index_;
56 }; 56 };
57 57
58 namespace { 58 namespace {
59 59
60 // Measured in seconds. 60 // Measured in seconds.
61 const double kSoftwareUploadTickRate = 0.000250; 61 const double kSoftwareUploadTickRate = 0.000250;
62 const double kTextureUploadTickRate = 0.004; 62 const double kTextureUploadTickRate = 0.004;
63 63
64 // Display density in dots per inch at scale factor 1.0.
65 const float kDisplayDensityScaleFactor = 160.0f;
66
64 GLenum TextureToStorageFormat(ResourceFormat format) { 67 GLenum TextureToStorageFormat(ResourceFormat format) {
65 GLenum storage_format = GL_RGBA8_OES; 68 GLenum storage_format = GL_RGBA8_OES;
66 switch (format) { 69 switch (format) {
67 case RGBA_8888: 70 case RGBA_8888:
68 break; 71 break;
69 case BGRA_8888: 72 case BGRA_8888:
70 storage_format = GL_BGRA8_EXT; 73 storage_format = GL_BGRA8_EXT;
71 break; 74 break;
72 case RGBA_4444: 75 case RGBA_4444:
73 case LUMINANCE_8: 76 case LUMINANCE_8:
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {} 408 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {}
406 409
407 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() { 410 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() {
408 if (!surface_) 411 if (!surface_)
409 surface_ = CreateSurface(); 412 surface_ = CreateSurface();
410 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; 413 surface_generation_id_ = surface_ ? surface_->generationID() : 0u;
411 return surface_ ? surface_->getCanvas() : NULL; 414 return surface_ ? surface_->getCanvas() : NULL;
412 } 415 }
413 416
414 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() { 417 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() {
415 // generationID returns a non-zero, unique value corresponding to the content 418 if (surface_) {
416 // of surface. Hence, a change since DoLockForWrite was called means the 419 // generationID returns a non-zero, unique value corresponding to the
417 // surface has changed. 420 // content of surface. Hence, a change since DoLockForWrite was called
418 return surface_ ? surface_generation_id_ != surface_->generationID() : false; 421 // means the surface has changed.
422 if (surface_generation_id_ != surface_->generationID()) {
423 // Flush any pending or deferred work canvas or device might have. This
424 // also resolves the potential MSAA.
425 surface_->getCanvas()->flush();
426 return true;
427 }
428 }
429 return false;
419 } 430 }
420 431
421 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { 432 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() {
422 skia::RefPtr<SkSurface> surface; 433 skia::RefPtr<SkSurface> surface;
423 switch (resource()->type) { 434 switch (resource()->type) {
424 case GLTexture: { 435 case GLTexture: {
425 DCHECK(resource()->gl_id); 436 DCHECK(resource()->gl_id);
426 class GrContext* gr_context = resource_provider()->GrContext(); 437 class GrContext* gr_context = resource_provider()->GrContext();
427 if (gr_context) { 438 if (gr_context) {
428 GrBackendTextureDesc desc; 439 GrBackendTextureDesc desc;
429 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 440 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
430 desc.fWidth = resource()->size.width(); 441 desc.fWidth = resource()->size.width();
431 desc.fHeight = resource()->size.height(); 442 desc.fHeight = resource()->size.height();
432 desc.fConfig = ToGrPixelConfig(resource()->format); 443 desc.fConfig = ToGrPixelConfig(resource()->format);
433 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 444 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
434 desc.fTextureHandle = resource()->gl_id; 445 desc.fTextureHandle = resource()->gl_id;
446 desc.fSampleCnt = resource_provider()->num_gpu_rasterization_samples(
447 resource()->format);
435 skia::RefPtr<GrTexture> gr_texture = 448 skia::RefPtr<GrTexture> gr_texture =
436 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); 449 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
437 surface = skia::AdoptRef( 450 surface = skia::AdoptRef(
438 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); 451 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget()));
439 } 452 }
440 break; 453 break;
441 } 454 }
442 case Bitmap: { 455 case Bitmap: {
443 DCHECK(resource()->pixels); 456 DCHECK(resource()->pixels);
444 DCHECK_EQ(RGBA_8888, resource()->format); 457 DCHECK_EQ(RGBA_8888, resource()->format);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 602
590 ResourceProvider::~ResourceProvider() { 603 ResourceProvider::~ResourceProvider() {
591 while (!children_.empty()) 604 while (!children_.empty())
592 DestroyChildInternal(children_.begin(), ForShutdown); 605 DestroyChildInternal(children_.begin(), ForShutdown);
593 while (!resources_.empty()) 606 while (!resources_.empty())
594 DeleteResourceInternal(resources_.begin(), ForShutdown); 607 DeleteResourceInternal(resources_.begin(), ForShutdown);
595 608
596 CleanUpGLIfNeeded(); 609 CleanUpGLIfNeeded();
597 } 610 }
598 611
612 unsigned ResourceProvider::num_gpu_rasterization_samples(
613 ResourceFormat format) const {
614 const float dpi =
615 kDisplayDensityScaleFactor * output_surface_->SurfaceScaleFactor();
Kimmo Kinnunen 2014/03/06 07:16:51 Not entirely sure if this call is thread-safe. Is
616 return GrContext()->getRecommendedSampleCount(ToGrPixelConfig(format), dpi);
617 }
618
599 bool ResourceProvider::InUseByConsumer(ResourceId id) { 619 bool ResourceProvider::InUseByConsumer(ResourceId id) {
600 Resource* resource = GetResource(id); 620 Resource* resource = GetResource(id);
601 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || 621 return resource->lock_for_read_count > 0 || resource->exported_count > 0 ||
602 resource->lost; 622 resource->lost;
603 } 623 }
604 624
605 bool ResourceProvider::IsLost(ResourceId id) { 625 bool ResourceProvider::IsLost(ResourceId id) {
606 Resource* resource = GetResource(id); 626 Resource* resource = GetResource(id);
607 return resource->lost; 627 return resource->lost;
608 } 628 }
(...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 ContextProvider* context_provider = output_surface_->context_provider(); 2201 ContextProvider* context_provider = output_surface_->context_provider();
2182 return context_provider ? context_provider->ContextGL() : NULL; 2202 return context_provider ? context_provider->ContextGL() : NULL;
2183 } 2203 }
2184 2204
2185 class GrContext* ResourceProvider::GrContext() const { 2205 class GrContext* ResourceProvider::GrContext() const {
2186 ContextProvider* context_provider = output_surface_->context_provider(); 2206 ContextProvider* context_provider = output_surface_->context_provider();
2187 return context_provider ? context_provider->GrContext() : NULL; 2207 return context_provider ? context_provider->GrContext() : NULL;
2188 } 2208 }
2189 2209
2190 } // namespace cc 2210 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698