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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 shared_bitmap_id(bitmap_id), | 394 shared_bitmap_id(bitmap_id), |
395 shared_bitmap(NULL) { | 395 shared_bitmap(NULL) { |
396 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 396 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
397 } | 397 } |
398 | 398 |
399 ResourceProvider::RasterBuffer::RasterBuffer( | 399 ResourceProvider::RasterBuffer::RasterBuffer( |
400 const Resource* resource, | 400 const Resource* resource, |
401 ResourceProvider* resource_provider) | 401 ResourceProvider* resource_provider) |
402 : resource_(resource), | 402 : resource_(resource), |
403 resource_provider_(resource_provider), | 403 resource_provider_(resource_provider), |
404 locked_canvas_(NULL), | |
405 canvas_save_count_(0) { | 404 canvas_save_count_(0) { |
406 DCHECK(resource_); | 405 DCHECK(resource_); |
407 DCHECK(resource_provider_); | 406 DCHECK(resource_provider_); |
408 } | 407 } |
409 | 408 |
410 ResourceProvider::RasterBuffer::~RasterBuffer() {} | 409 ResourceProvider::RasterBuffer::~RasterBuffer() {} |
411 | 410 |
412 SkCanvas* ResourceProvider::RasterBuffer::LockForWrite() { | 411 void ResourceProvider::RasterBuffer::LockForWrite() { |
413 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 412 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
414 "ResourceProvider::RasterBuffer::LockForWrite"); | 413 "ResourceProvider::RasterBuffer::LockForWrite"); |
415 | 414 |
416 DCHECK(!locked_canvas_); | 415 DCHECK(!locked_canvas_); |
417 | 416 |
418 locked_canvas_ = DoLockForWrite(); | 417 locked_canvas_ = DoLockForWrite(); |
419 canvas_save_count_ = locked_canvas_ ? locked_canvas_->save() : 0; | 418 canvas_save_count_ = locked_canvas_ ? locked_canvas_->save() : 0; |
420 return locked_canvas_; | |
421 } | 419 } |
422 | 420 |
423 bool ResourceProvider::RasterBuffer::UnlockForWrite() { | 421 bool ResourceProvider::RasterBuffer::UnlockForWrite() { |
424 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 422 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
425 "ResourceProvider::RasterBuffer::UnlockForWrite"); | 423 "ResourceProvider::RasterBuffer::UnlockForWrite"); |
426 | 424 |
427 if (locked_canvas_) { | 425 if (locked_canvas_) { |
428 locked_canvas_->restoreToCount(canvas_save_count_); | 426 locked_canvas_->restoreToCount(canvas_save_count_); |
429 locked_canvas_ = NULL; | 427 locked_canvas_ = NULL; |
430 } | 428 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 case RGB_565: | 518 case RGB_565: |
521 case ETC1: | 519 case ETC1: |
522 NOTREACHED(); | 520 NOTREACHED(); |
523 break; | 521 break; |
524 } | 522 } |
525 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); | 523 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); |
526 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | 524 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); |
527 return raster_canvas_.get(); | 525 return raster_canvas_.get(); |
528 } | 526 } |
529 | 527 |
530 bool ResourceProvider::BitmapRasterBuffer::DoUnlockForWrite() { | 528 void ResourceProvider::BitmapRasterBuffer::Flush() { |
531 raster_canvas_.clear(); | 529 // Note that this function is called from a worker thread. |
532 | 530 |
533 // getGenerationID returns a non-zero, unique value corresponding to the | 531 // getGenerationID returns a non-zero, unique value corresponding to the |
534 // pixels in bitmap. Hence, a change since DoLockForWrite was called means the | 532 // pixels in bitmap. Hence, a change since DoLockForWrite was called means the |
535 // bitmap has changed. | 533 // bitmap has changed. |
536 bool raster_bitmap_changed = | 534 bool raster_bitmap_changed = |
537 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); | 535 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); |
538 | |
539 if (raster_bitmap_changed) { | 536 if (raster_bitmap_changed) { |
540 SkColorType buffer_colorType = | 537 SkColorType buffer_colorType = |
541 ResourceFormatToSkColorType(resource()->format); | 538 ResourceFormatToSkColorType(resource()->format); |
542 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType())) | 539 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType())) |
543 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType); | 540 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType); |
544 } | 541 } |
| 542 } |
| 543 |
| 544 bool ResourceProvider::BitmapRasterBuffer::DoUnlockForWrite() { |
| 545 raster_canvas_.clear(); |
| 546 |
| 547 bool raster_bitmap_changed = |
| 548 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); |
545 raster_bitmap_.reset(); | 549 raster_bitmap_.reset(); |
546 | 550 |
547 UnmapBuffer(); | 551 UnmapBuffer(); |
548 mapped_buffer_ = NULL; | 552 mapped_buffer_ = NULL; |
549 return raster_bitmap_changed; | 553 return raster_bitmap_changed; |
550 } | 554 } |
551 | 555 |
552 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( | 556 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( |
553 const Resource* resource, | 557 const Resource* resource, |
554 ResourceProvider* resource_provider) | 558 ResourceProvider* resource_provider) |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1720 if (!to_return.empty()) | 1724 if (!to_return.empty()) |
1721 child_info->return_callback.Run(to_return); | 1725 child_info->return_callback.Run(to_return); |
1722 | 1726 |
1723 if (child_info->marked_for_deletion && | 1727 if (child_info->marked_for_deletion && |
1724 child_info->parent_to_child_map.empty()) { | 1728 child_info->parent_to_child_map.empty()) { |
1725 DCHECK(child_info->child_to_parent_map.empty()); | 1729 DCHECK(child_info->child_to_parent_map.empty()); |
1726 children_.erase(child_it); | 1730 children_.erase(child_it); |
1727 } | 1731 } |
1728 } | 1732 } |
1729 | 1733 |
1730 SkCanvas* ResourceProvider::MapGpuRasterBuffer(ResourceId id) { | 1734 RasterCanvas* ResourceProvider::MapGpuRasterBuffer(ResourceId id) { |
1731 // Resource needs to be locked for write since GpuRasterBuffer writes | 1735 // Resource needs to be locked for write since GpuRasterBuffer writes |
1732 // directly to it. | 1736 // directly to it. |
1733 LockForWrite(id); | 1737 LockForWrite(id); |
1734 Resource* resource = GetResource(id); | 1738 Resource* resource = GetResource(id); |
1735 if (!resource->gpu_raster_buffer.get()) { | 1739 if (!resource->gpu_raster_buffer.get()) { |
1736 resource->gpu_raster_buffer.reset( | 1740 resource->gpu_raster_buffer.reset( |
1737 new GpuRasterBuffer(resource, this, use_distance_field_text_)); | 1741 new GpuRasterBuffer(resource, this, use_distance_field_text_)); |
1738 } | 1742 } |
1739 return resource->gpu_raster_buffer->LockForWrite(); | 1743 resource->gpu_raster_buffer->LockForWrite(); |
| 1744 return resource->gpu_raster_buffer.get(); |
1740 } | 1745 } |
1741 | 1746 |
1742 void ResourceProvider::UnmapGpuRasterBuffer(ResourceId id) { | 1747 void ResourceProvider::UnmapGpuRasterBuffer(ResourceId id) { |
1743 Resource* resource = GetResource(id); | 1748 Resource* resource = GetResource(id); |
1744 DCHECK(resource->gpu_raster_buffer.get()); | 1749 DCHECK(resource->gpu_raster_buffer.get()); |
1745 resource->gpu_raster_buffer->UnlockForWrite(); | 1750 resource->gpu_raster_buffer->UnlockForWrite(); |
1746 UnlockForWrite(id); | 1751 UnlockForWrite(id); |
1747 } | 1752 } |
1748 | 1753 |
1749 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { | 1754 RasterCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { |
1750 Resource* resource = GetResource(id); | 1755 Resource* resource = GetResource(id); |
1751 AcquireImage(resource); | 1756 AcquireImage(resource); |
1752 if (!resource->image_raster_buffer.get()) | 1757 if (!resource->image_raster_buffer.get()) |
1753 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); | 1758 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); |
1754 return resource->image_raster_buffer->LockForWrite(); | 1759 resource->image_raster_buffer->LockForWrite(); |
| 1760 return resource->image_raster_buffer.get(); |
1755 } | 1761 } |
1756 | 1762 |
1757 bool ResourceProvider::UnmapImageRasterBuffer(ResourceId id) { | 1763 bool ResourceProvider::UnmapImageRasterBuffer(ResourceId id) { |
1758 Resource* resource = GetResource(id); | 1764 Resource* resource = GetResource(id); |
1759 resource->dirty_image = true; | 1765 resource->dirty_image = true; |
1760 return resource->image_raster_buffer->UnlockForWrite(); | 1766 return resource->image_raster_buffer->UnlockForWrite(); |
1761 } | 1767 } |
1762 | 1768 |
1763 void ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) { | 1769 void ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) { |
1764 Resource* resource = GetResource(id); | 1770 Resource* resource = GetResource(id); |
1765 AcquirePixelBuffer(resource); | 1771 AcquirePixelBuffer(resource); |
1766 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this)); | 1772 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this)); |
1767 } | 1773 } |
1768 | 1774 |
1769 void ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) { | 1775 void ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) { |
1770 Resource* resource = GetResource(id); | 1776 Resource* resource = GetResource(id); |
1771 resource->pixel_raster_buffer.reset(); | 1777 resource->pixel_raster_buffer.reset(); |
1772 ReleasePixelBuffer(resource); | 1778 ReleasePixelBuffer(resource); |
1773 } | 1779 } |
1774 | 1780 |
1775 SkCanvas* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { | 1781 RasterCanvas* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { |
1776 Resource* resource = GetResource(id); | 1782 Resource* resource = GetResource(id); |
1777 DCHECK(resource->pixel_raster_buffer.get()); | 1783 DCHECK(resource->pixel_raster_buffer.get()); |
1778 return resource->pixel_raster_buffer->LockForWrite(); | 1784 resource->pixel_raster_buffer->LockForWrite(); |
| 1785 return resource->pixel_raster_buffer.get(); |
1779 } | 1786 } |
1780 | 1787 |
1781 bool ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { | 1788 bool ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { |
1782 Resource* resource = GetResource(id); | 1789 Resource* resource = GetResource(id); |
1783 DCHECK(resource->pixel_raster_buffer.get()); | 1790 DCHECK(resource->pixel_raster_buffer.get()); |
1784 return resource->pixel_raster_buffer->UnlockForWrite(); | 1791 return resource->pixel_raster_buffer->UnlockForWrite(); |
1785 } | 1792 } |
1786 | 1793 |
1787 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { | 1794 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { |
1788 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1795 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2252 ContextProvider* context_provider = output_surface_->context_provider(); | 2259 ContextProvider* context_provider = output_surface_->context_provider(); |
2253 return context_provider ? context_provider->ContextGL() : NULL; | 2260 return context_provider ? context_provider->ContextGL() : NULL; |
2254 } | 2261 } |
2255 | 2262 |
2256 class GrContext* ResourceProvider::GrContext() const { | 2263 class GrContext* ResourceProvider::GrContext() const { |
2257 ContextProvider* context_provider = output_surface_->context_provider(); | 2264 ContextProvider* context_provider = output_surface_->context_provider(); |
2258 return context_provider ? context_provider->GrContext() : NULL; | 2265 return context_provider ? context_provider->GrContext() : NULL; |
2259 } | 2266 } |
2260 | 2267 |
2261 } // namespace cc | 2268 } // namespace cc |
OLD | NEW |