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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 422 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 423 "ResourceProvider::RasterBuffer::UnlockForWrite"); | 423 "ResourceProvider::RasterBuffer::UnlockForWrite"); |
| 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::GpuRasterBuffer::GpuRasterBuffer( |
| 433 const Resource* resource, | 433 const Resource* resource, |
| 434 ResourceProvider* resource_provider, | 434 ResourceProvider* resource_provider, |
| 435 bool use_distance_field_text ) | 435 bool use_distance_field_text) |
| 436 : RasterBuffer(resource, resource_provider), | 436 : RasterBuffer(resource, resource_provider), |
| 437 surface_generation_id_(0u), | 437 surface_generation_id_(0u), |
| 438 use_distance_field_text_(use_distance_field_text) {} | 438 use_distance_field_text_(use_distance_field_text) { |
| 439 } | |
| 439 | 440 |
| 440 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {} | 441 ResourceProvider::GpuRasterBuffer::~GpuRasterBuffer() { |
| 442 } | |
| 441 | 443 |
| 442 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() { | 444 SkCanvas* ResourceProvider::GpuRasterBuffer::DoLockForWrite() { |
| 443 if (!surface_) | 445 if (!surface_) |
| 444 surface_ = CreateSurface(); | 446 surface_ = CreateSurface(); |
| 445 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; | 447 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; |
| 446 return surface_ ? surface_->getCanvas() : NULL; | 448 return surface_ ? surface_->getCanvas() : NULL; |
| 447 } | 449 } |
| 448 | 450 |
| 449 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() { | 451 bool ResourceProvider::GpuRasterBuffer::DoUnlockForWrite() { |
| 450 // generationID returns a non-zero, unique value corresponding to the content | 452 // generationID returns a non-zero, unique value corresponding to the content |
| 451 // of surface. Hence, a change since DoLockForWrite was called means the | 453 // of surface. Hence, a change since DoLockForWrite was called means the |
| 452 // surface has changed. | 454 // surface has changed. |
| 453 return surface_ ? surface_generation_id_ != surface_->generationID() : false; | 455 return surface_ ? surface_generation_id_ != surface_->generationID() : false; |
| 454 } | 456 } |
| 455 | 457 |
| 456 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { | 458 skia::RefPtr<SkSurface> ResourceProvider::GpuRasterBuffer::CreateSurface() { |
| 457 skia::RefPtr<SkSurface> surface; | 459 skia::RefPtr<SkSurface> surface; |
|
reveman
2014/06/30 15:22:33
I don't think we need this temporary variable anym
sohanjg
2014/06/30 16:05:50
Done.
| |
| 458 switch (resource()->type) { | 460 DCHECK_EQ(GLTexture, resource()->type); |
| 459 case GLTexture: { | 461 DCHECK(resource()->gl_id); |
| 460 DCHECK(resource()->gl_id); | 462 class GrContext* gr_context = resource_provider()->GrContext(); |
| 461 class GrContext* gr_context = resource_provider()->GrContext(); | 463 if (gr_context) { |
|
reveman
2014/06/30 15:22:33
Please early out if !gr_context instead and add "/
sohanjg
2014/06/30 16:05:50
Done.
| |
| 462 if (gr_context) { | 464 GrBackendTextureDesc desc; |
| 463 GrBackendTextureDesc desc; | 465 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 464 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 466 desc.fWidth = resource()->size.width(); |
| 465 desc.fWidth = resource()->size.width(); | 467 desc.fHeight = resource()->size.height(); |
| 466 desc.fHeight = resource()->size.height(); | 468 desc.fConfig = ToGrPixelConfig(resource()->format); |
| 467 desc.fConfig = ToGrPixelConfig(resource()->format); | 469 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 468 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 470 desc.fTextureHandle = resource()->gl_id; |
| 469 desc.fTextureHandle = resource()->gl_id; | 471 skia::RefPtr<GrTexture> gr_texture = |
| 470 skia::RefPtr<GrTexture> gr_texture = | 472 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
| 471 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | 473 SkSurface::TextRenderMode text_render_mode = |
| 472 SkSurface::TextRenderMode text_render_mode = | 474 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode |
| 473 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode | 475 : SkSurface::kStandard_TextRenderMode; |
| 474 : SkSurface::kStandard_TextRenderMode; | 476 surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( |
| 475 surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( | 477 gr_texture->asRenderTarget(), text_render_mode)); |
| 476 gr_texture->asRenderTarget(), text_render_mode)); | |
| 477 } | |
| 478 break; | |
| 479 } | |
| 480 case Bitmap: { | |
| 481 DCHECK(resource()->pixels); | |
| 482 DCHECK_EQ(RGBA_8888, resource()->format); | |
| 483 SkImageInfo image_info = SkImageInfo::MakeN32Premul( | |
| 484 resource()->size.width(), resource()->size.height()); | |
| 485 surface = skia::AdoptRef(SkSurface::NewRasterDirect( | |
| 486 image_info, resource()->pixels, image_info.minRowBytes())); | |
| 487 break; | |
| 488 } | |
| 489 default: | |
| 490 NOTREACHED(); | |
| 491 } | 478 } |
| 479 | |
| 492 return surface; | 480 return surface; |
| 493 } | 481 } |
| 494 | 482 |
| 495 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( | 483 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( |
| 496 const Resource* resource, | 484 const Resource* resource, |
| 497 ResourceProvider* resource_provider) | 485 ResourceProvider* resource_provider) |
| 498 : RasterBuffer(resource, resource_provider), | 486 : RasterBuffer(resource, resource_provider), |
| 499 mapped_buffer_(NULL), | 487 mapped_buffer_(NULL), |
| 500 raster_bitmap_generation_id_(0u) {} | 488 raster_bitmap_generation_id_(0u) {} |
| 501 | 489 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 823 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| 836 DeleteStyle style) { | 824 DeleteStyle style) { |
| 837 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); | 825 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); |
| 838 Resource* resource = &it->second; | 826 Resource* resource = &it->second; |
| 839 bool lost_resource = resource->lost; | 827 bool lost_resource = resource->lost; |
| 840 | 828 |
| 841 DCHECK(resource->exported_count == 0 || style != Normal); | 829 DCHECK(resource->exported_count == 0 || style != Normal); |
| 842 if (style == ForShutdown && resource->exported_count > 0) | 830 if (style == ForShutdown && resource->exported_count > 0) |
| 843 lost_resource = true; | 831 lost_resource = true; |
| 844 | 832 |
| 845 resource->direct_raster_buffer.reset(); | 833 resource->gpu_raster_buffer.reset(); |
| 846 resource->image_raster_buffer.reset(); | 834 resource->image_raster_buffer.reset(); |
| 847 resource->pixel_raster_buffer.reset(); | 835 resource->pixel_raster_buffer.reset(); |
| 848 | 836 |
| 849 if (resource->image_id) { | 837 if (resource->image_id) { |
| 850 DCHECK(resource->origin == Resource::Internal); | 838 DCHECK(resource->origin == Resource::Internal); |
| 851 GLES2Interface* gl = ContextGL(); | 839 GLES2Interface* gl = ContextGL(); |
| 852 DCHECK(gl); | 840 DCHECK(gl); |
| 853 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); | 841 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); |
| 854 } | 842 } |
| 855 if (resource->gl_upload_query_id) { | 843 if (resource->gl_upload_query_id) { |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1746 if (!to_return.empty()) | 1734 if (!to_return.empty()) |
| 1747 child_info->return_callback.Run(to_return); | 1735 child_info->return_callback.Run(to_return); |
| 1748 | 1736 |
| 1749 if (child_info->marked_for_deletion && | 1737 if (child_info->marked_for_deletion && |
| 1750 child_info->parent_to_child_map.empty()) { | 1738 child_info->parent_to_child_map.empty()) { |
| 1751 DCHECK(child_info->child_to_parent_map.empty()); | 1739 DCHECK(child_info->child_to_parent_map.empty()); |
| 1752 children_.erase(child_it); | 1740 children_.erase(child_it); |
| 1753 } | 1741 } |
| 1754 } | 1742 } |
| 1755 | 1743 |
| 1756 SkCanvas* ResourceProvider::MapDirectRasterBuffer(ResourceId id) { | 1744 SkCanvas* ResourceProvider::MapGpuRasterBuffer(ResourceId id) { |
| 1757 // Resource needs to be locked for write since DirectRasterBuffer writes | 1745 // Resource needs to be locked for write since GpuRasterBuffer writes |
| 1758 // directly to it. | 1746 // directly to it. |
| 1759 LockForWrite(id); | 1747 LockForWrite(id); |
| 1760 Resource* resource = GetResource(id); | 1748 Resource* resource = GetResource(id); |
| 1761 if (!resource->direct_raster_buffer.get()) { | 1749 if (!resource->gpu_raster_buffer.get()) { |
| 1762 resource->direct_raster_buffer.reset( | 1750 resource->gpu_raster_buffer.reset( |
| 1763 new DirectRasterBuffer(resource, this, use_distance_field_text_)); | 1751 new GpuRasterBuffer(resource, this, use_distance_field_text_)); |
| 1764 } | 1752 } |
| 1765 return resource->direct_raster_buffer->LockForWrite(); | 1753 return resource->gpu_raster_buffer->LockForWrite(); |
| 1766 } | 1754 } |
| 1767 | 1755 |
| 1768 void ResourceProvider::UnmapDirectRasterBuffer(ResourceId id) { | 1756 void ResourceProvider::UnmapGpuRasterBuffer(ResourceId id) { |
| 1769 Resource* resource = GetResource(id); | 1757 Resource* resource = GetResource(id); |
| 1770 DCHECK(resource->direct_raster_buffer.get()); | 1758 DCHECK(resource->gpu_raster_buffer.get()); |
| 1771 resource->direct_raster_buffer->UnlockForWrite(); | 1759 resource->gpu_raster_buffer->UnlockForWrite(); |
| 1772 UnlockForWrite(id); | 1760 UnlockForWrite(id); |
| 1773 } | 1761 } |
| 1774 | 1762 |
| 1775 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { | 1763 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { |
| 1776 Resource* resource = GetResource(id); | 1764 Resource* resource = GetResource(id); |
| 1777 AcquireImage(resource); | 1765 AcquireImage(resource); |
| 1778 if (!resource->image_raster_buffer.get()) | 1766 if (!resource->image_raster_buffer.get()) |
| 1779 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); | 1767 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); |
| 1780 return resource->image_raster_buffer->LockForWrite(); | 1768 return resource->image_raster_buffer->LockForWrite(); |
| 1781 } | 1769 } |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2279 ContextProvider* context_provider = output_surface_->context_provider(); | 2267 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2280 return context_provider ? context_provider->ContextGL() : NULL; | 2268 return context_provider ? context_provider->ContextGL() : NULL; |
| 2281 } | 2269 } |
| 2282 | 2270 |
| 2283 class GrContext* ResourceProvider::GrContext() const { | 2271 class GrContext* ResourceProvider::GrContext() const { |
| 2284 ContextProvider* context_provider = output_surface_->context_provider(); | 2272 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2285 return context_provider ? context_provider->GrContext() : NULL; | 2273 return context_provider ? context_provider->GrContext() : NULL; |
| 2286 } | 2274 } |
| 2287 | 2275 |
| 2288 } // namespace cc | 2276 } // namespace cc |
| OLD | NEW |