Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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. | |
|
nduca
2014/04/23 23:07:24
what the heck is this? why do you need this?
| |
| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 446 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() { | 449 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() { |
| 447 // generationID returns a non-zero, unique value corresponding to the content | 450 if (surface_) { |
| 448 // of surface. Hence, a change since DoLockForWrite was called means the | 451 // generationID returns a non-zero, unique value corresponding to the |
| 449 // surface has changed. | 452 // content of surface. Hence, a change since DoLockForWrite was called |
| 450 return surface_ ? surface_generation_id_ != surface_->generationID() : false; | 453 // means the surface has changed. |
| 454 if (surface_generation_id_ != surface_->generationID()) { | |
|
nduca
2014/04/23 23:07:24
can you do this as a separate change please?
| |
| 455 // Flush any pending or deferred work canvas or device might have. This | |
| 456 // also resolves the potential MSAA. | |
| 457 surface_->getCanvas()->flush(); | |
| 458 return true; | |
| 459 } | |
| 460 } | |
| 461 return false; | |
| 451 } | 462 } |
| 452 | 463 |
| 453 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { | 464 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { |
| 454 skia::RefPtr<SkSurface> surface; | 465 skia::RefPtr<SkSurface> surface; |
| 455 switch (resource()->type) { | 466 switch (resource()->type) { |
| 456 case GLTexture: { | 467 case GLTexture: { |
| 457 DCHECK(resource()->gl_id); | 468 DCHECK(resource()->gl_id); |
| 458 class GrContext* gr_context = resource_provider()->GrContext(); | 469 class GrContext* gr_context = resource_provider()->GrContext(); |
| 459 if (gr_context) { | 470 if (gr_context) { |
| 460 GrBackendTextureDesc desc; | 471 GrBackendTextureDesc desc; |
| 461 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 472 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 462 desc.fWidth = resource()->size.width(); | 473 desc.fWidth = resource()->size.width(); |
| 463 desc.fHeight = resource()->size.height(); | 474 desc.fHeight = resource()->size.height(); |
| 464 desc.fConfig = ToGrPixelConfig(resource()->format); | 475 desc.fConfig = ToGrPixelConfig(resource()->format); |
| 465 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 476 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 466 desc.fTextureHandle = resource()->gl_id; | 477 desc.fTextureHandle = resource()->gl_id; |
| 478 desc.fSampleCnt = resource_provider()->num_gpu_rasterization_samples( | |
| 479 resource()->format); | |
| 467 skia::RefPtr<GrTexture> gr_texture = | 480 skia::RefPtr<GrTexture> gr_texture = |
| 468 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | 481 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
| 469 surface = skia::AdoptRef( | 482 surface = skia::AdoptRef( |
| 470 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); | 483 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); |
| 471 } | 484 } |
| 472 break; | 485 break; |
| 473 } | 486 } |
| 474 case Bitmap: { | 487 case Bitmap: { |
| 475 DCHECK(resource()->pixels); | 488 DCHECK(resource()->pixels); |
| 476 DCHECK_EQ(RGBA_8888, resource()->format); | 489 DCHECK_EQ(RGBA_8888, resource()->format); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 | 630 |
| 618 ResourceProvider::~ResourceProvider() { | 631 ResourceProvider::~ResourceProvider() { |
| 619 while (!children_.empty()) | 632 while (!children_.empty()) |
| 620 DestroyChildInternal(children_.begin(), ForShutdown); | 633 DestroyChildInternal(children_.begin(), ForShutdown); |
| 621 while (!resources_.empty()) | 634 while (!resources_.empty()) |
| 622 DeleteResourceInternal(resources_.begin(), ForShutdown); | 635 DeleteResourceInternal(resources_.begin(), ForShutdown); |
| 623 | 636 |
| 624 CleanUpGLIfNeeded(); | 637 CleanUpGLIfNeeded(); |
| 625 } | 638 } |
| 626 | 639 |
| 640 unsigned ResourceProvider::num_gpu_rasterization_samples( | |
| 641 ResourceFormat format) const { | |
| 642 const float dpi = | |
| 643 kDisplayDensityScaleFactor * output_surface_->SurfaceScaleFactor(); | |
| 644 return GrContext()->getRecommendedSampleCount(ToGrPixelConfig(format), dpi); | |
| 645 } | |
| 646 | |
| 627 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 647 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
| 628 Resource* resource = GetResource(id); | 648 Resource* resource = GetResource(id); |
| 629 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 649 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
| 630 resource->lost; | 650 resource->lost; |
| 631 } | 651 } |
| 632 | 652 |
| 633 bool ResourceProvider::IsLost(ResourceId id) { | 653 bool ResourceProvider::IsLost(ResourceId id) { |
| 634 Resource* resource = GetResource(id); | 654 Resource* resource = GetResource(id); |
| 635 return resource->lost; | 655 return resource->lost; |
| 636 } | 656 } |
| (...skipping 1646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2283 ContextProvider* context_provider = output_surface_->context_provider(); | 2303 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2284 return context_provider ? context_provider->ContextGL() : NULL; | 2304 return context_provider ? context_provider->ContextGL() : NULL; |
| 2285 } | 2305 } |
| 2286 | 2306 |
| 2287 class GrContext* ResourceProvider::GrContext() const { | 2307 class GrContext* ResourceProvider::GrContext() const { |
| 2288 ContextProvider* context_provider = output_surface_->context_provider(); | 2308 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2289 return context_provider ? context_provider->GrContext() : NULL; | 2309 return context_provider ? context_provider->GrContext() : NULL; |
| 2290 } | 2310 } |
| 2291 | 2311 |
| 2292 } // namespace cc | 2312 } // namespace cc |
| OLD | NEW |