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; |
| 458 switch (resource()->type) { | 460 switch (resource()->type) { |
| 459 case GLTexture: { | 461 case GLTexture: { |
| 460 DCHECK(resource()->gl_id); | 462 DCHECK(resource()->gl_id); |
| 461 class GrContext* gr_context = resource_provider()->GrContext(); | 463 class GrContext* gr_context = resource_provider()->GrContext(); |
| 462 if (gr_context) { | 464 if (gr_context) { |
| 463 GrBackendTextureDesc desc; | 465 GrBackendTextureDesc desc; |
| 464 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 466 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 465 desc.fWidth = resource()->size.width(); | 467 desc.fWidth = resource()->size.width(); |
| 466 desc.fHeight = resource()->size.height(); | 468 desc.fHeight = resource()->size.height(); |
| 467 desc.fConfig = ToGrPixelConfig(resource()->format); | 469 desc.fConfig = ToGrPixelConfig(resource()->format); |
| 468 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 470 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 469 desc.fTextureHandle = resource()->gl_id; | 471 desc.fTextureHandle = resource()->gl_id; |
| 470 skia::RefPtr<GrTexture> gr_texture = | 472 skia::RefPtr<GrTexture> gr_texture = |
| 471 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | 473 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
| 472 SkSurface::TextRenderMode text_render_mode = | 474 SkSurface::TextRenderMode text_render_mode = |
| 473 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode | 475 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode |
| 474 : SkSurface::kStandard_TextRenderMode; | 476 : SkSurface::kStandard_TextRenderMode; |
| 475 surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( | 477 surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect( |
| 476 gr_texture->asRenderTarget(), text_render_mode)); | 478 gr_texture->asRenderTarget(), text_render_mode)); |
| 477 } | 479 } |
| 478 break; | 480 break; |
| 479 } | 481 } |
| 480 case Bitmap: { | 482 case Bitmap: { |
|
reveman
2014/06/30 13:20:15
You'll have to remove this case for the the name t
sohanjg
2014/06/30 15:02:35
Done.
| |
| 481 DCHECK(resource()->pixels); | 483 DCHECK(resource()->pixels); |
| 482 DCHECK_EQ(RGBA_8888, resource()->format); | 484 DCHECK_EQ(RGBA_8888, resource()->format); |
| 483 SkImageInfo image_info = SkImageInfo::MakeN32Premul( | 485 SkImageInfo image_info = SkImageInfo::MakeN32Premul( |
| 484 resource()->size.width(), resource()->size.height()); | 486 resource()->size.width(), resource()->size.height()); |
| 485 surface = skia::AdoptRef(SkSurface::NewRasterDirect( | 487 surface = skia::AdoptRef(SkSurface::NewRasterDirect( |
| 486 image_info, resource()->pixels, image_info.minRowBytes())); | 488 image_info, resource()->pixels, image_info.minRowBytes())); |
| 487 break; | 489 break; |
| 488 } | 490 } |
| 489 default: | 491 default: |
| 490 NOTREACHED(); | 492 NOTREACHED(); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 837 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| 836 DeleteStyle style) { | 838 DeleteStyle style) { |
| 837 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); | 839 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); |
| 838 Resource* resource = &it->second; | 840 Resource* resource = &it->second; |
| 839 bool lost_resource = resource->lost; | 841 bool lost_resource = resource->lost; |
| 840 | 842 |
| 841 DCHECK(resource->exported_count == 0 || style != Normal); | 843 DCHECK(resource->exported_count == 0 || style != Normal); |
| 842 if (style == ForShutdown && resource->exported_count > 0) | 844 if (style == ForShutdown && resource->exported_count > 0) |
| 843 lost_resource = true; | 845 lost_resource = true; |
| 844 | 846 |
| 845 resource->direct_raster_buffer.reset(); | 847 resource->gpu_raster_buffer.reset(); |
| 846 resource->image_raster_buffer.reset(); | 848 resource->image_raster_buffer.reset(); |
| 847 resource->pixel_raster_buffer.reset(); | 849 resource->pixel_raster_buffer.reset(); |
| 848 | 850 |
| 849 if (resource->image_id) { | 851 if (resource->image_id) { |
| 850 DCHECK(resource->origin == Resource::Internal); | 852 DCHECK(resource->origin == Resource::Internal); |
| 851 GLES2Interface* gl = ContextGL(); | 853 GLES2Interface* gl = ContextGL(); |
| 852 DCHECK(gl); | 854 DCHECK(gl); |
| 853 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); | 855 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); |
| 854 } | 856 } |
| 855 if (resource->gl_upload_query_id) { | 857 if (resource->gl_upload_query_id) { |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1746 if (!to_return.empty()) | 1748 if (!to_return.empty()) |
| 1747 child_info->return_callback.Run(to_return); | 1749 child_info->return_callback.Run(to_return); |
| 1748 | 1750 |
| 1749 if (child_info->marked_for_deletion && | 1751 if (child_info->marked_for_deletion && |
| 1750 child_info->parent_to_child_map.empty()) { | 1752 child_info->parent_to_child_map.empty()) { |
| 1751 DCHECK(child_info->child_to_parent_map.empty()); | 1753 DCHECK(child_info->child_to_parent_map.empty()); |
| 1752 children_.erase(child_it); | 1754 children_.erase(child_it); |
| 1753 } | 1755 } |
| 1754 } | 1756 } |
| 1755 | 1757 |
| 1756 SkCanvas* ResourceProvider::MapDirectRasterBuffer(ResourceId id) { | 1758 SkCanvas* ResourceProvider::MapGpuRasterBuffer(ResourceId id) { |
| 1757 // Resource needs to be locked for write since DirectRasterBuffer writes | 1759 // Resource needs to be locked for write since GpuRasterBuffer writes |
| 1758 // directly to it. | 1760 // directly to it. |
| 1759 LockForWrite(id); | 1761 LockForWrite(id); |
| 1760 Resource* resource = GetResource(id); | 1762 Resource* resource = GetResource(id); |
| 1761 if (!resource->direct_raster_buffer.get()) { | 1763 if (!resource->gpu_raster_buffer.get()) { |
| 1762 resource->direct_raster_buffer.reset( | 1764 resource->gpu_raster_buffer.reset( |
| 1763 new DirectRasterBuffer(resource, this, use_distance_field_text_)); | 1765 new GpuRasterBuffer(resource, this, use_distance_field_text_)); |
| 1764 } | 1766 } |
| 1765 return resource->direct_raster_buffer->LockForWrite(); | 1767 return resource->gpu_raster_buffer->LockForWrite(); |
| 1766 } | 1768 } |
| 1767 | 1769 |
| 1768 void ResourceProvider::UnmapDirectRasterBuffer(ResourceId id) { | 1770 void ResourceProvider::UnmapGpuRasterBuffer(ResourceId id) { |
| 1769 Resource* resource = GetResource(id); | 1771 Resource* resource = GetResource(id); |
| 1770 DCHECK(resource->direct_raster_buffer.get()); | 1772 DCHECK(resource->gpu_raster_buffer.get()); |
| 1771 resource->direct_raster_buffer->UnlockForWrite(); | 1773 resource->gpu_raster_buffer->UnlockForWrite(); |
| 1772 UnlockForWrite(id); | 1774 UnlockForWrite(id); |
| 1773 } | 1775 } |
| 1774 | 1776 |
| 1775 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { | 1777 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { |
| 1776 Resource* resource = GetResource(id); | 1778 Resource* resource = GetResource(id); |
| 1777 AcquireImage(resource); | 1779 AcquireImage(resource); |
| 1778 if (!resource->image_raster_buffer.get()) | 1780 if (!resource->image_raster_buffer.get()) |
| 1779 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); | 1781 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); |
| 1780 return resource->image_raster_buffer->LockForWrite(); | 1782 return resource->image_raster_buffer->LockForWrite(); |
| 1781 } | 1783 } |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2279 ContextProvider* context_provider = output_surface_->context_provider(); | 2281 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2280 return context_provider ? context_provider->ContextGL() : NULL; | 2282 return context_provider ? context_provider->ContextGL() : NULL; |
| 2281 } | 2283 } |
| 2282 | 2284 |
| 2283 class GrContext* ResourceProvider::GrContext() const { | 2285 class GrContext* ResourceProvider::GrContext() const { |
| 2284 ContextProvider* context_provider = output_surface_->context_provider(); | 2286 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2285 return context_provider ? context_provider->GrContext() : NULL; | 2287 return context_provider ? context_provider->GrContext() : NULL; |
| 2286 } | 2288 } |
| 2287 | 2289 |
| 2288 } // namespace cc | 2290 } // namespace cc |
| OLD | NEW |