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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} | 114 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} |
| 115 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { | 115 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { |
| 116 dst->setPixels(buffer_); | 116 dst->setPixels(buffer_); |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 void* buffer_; | 121 void* buffer_; |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 void MakeBitmap(SkBitmap* bitmap, | |
| 125 uint8_t* buffer, | |
| 126 ResourceFormat format, | |
| 127 const gfx::Size& size, | |
| 128 int stride) { | |
| 129 switch (format) { | |
| 130 case RGBA_4444: | |
| 131 // Use the default stride if we will eventually convert this | |
| 132 // bitmap to 4444. | |
| 133 bitmap->allocN32Pixels(size.width(), size.height()); | |
| 134 break; | |
| 135 case RGBA_8888: | |
| 136 case BGRA_8888: { | |
| 137 SkImageInfo info = | |
| 138 SkImageInfo::MakeN32Premul(size.width(), size.height()); | |
| 139 if (0 == stride) | |
| 140 stride = info.minRowBytes(); | |
| 141 bitmap->installPixels(info, buffer, stride); | |
| 142 break; | |
| 143 } | |
| 144 case LUMINANCE_8: | |
| 145 case RGB_565: | |
| 146 case ETC1: | |
| 147 NOTREACHED(); | |
| 148 break; | |
| 149 } | |
| 150 } | |
| 151 | |
| 124 void CopyBitmap(const SkBitmap& src, uint8_t* dst, SkColorType dst_colorType) { | 152 void CopyBitmap(const SkBitmap& src, uint8_t* dst, SkColorType dst_colorType) { |
| 125 SkBitmap dst_bitmap; | 153 SkBitmap dst_bitmap; |
| 126 IdentityAllocator allocator(dst); | 154 IdentityAllocator allocator(dst); |
| 127 src.copyTo(&dst_bitmap, dst_colorType, &allocator); | 155 src.copyTo(&dst_bitmap, dst_colorType, &allocator); |
| 128 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | 156 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
| 129 // bitmap data. This check will be removed once crbug.com/293728 is fixed. | 157 // bitmap data. This check will be removed once crbug.com/293728 is fixed. |
| 130 CHECK_EQ(0u, dst_bitmap.rowBytes() % 4); | 158 CHECK_EQ(0u, dst_bitmap.rowBytes() % 4); |
| 131 } | 159 } |
| 132 | 160 |
| 133 class ScopedSetActiveTexture { | 161 class ScopedSetActiveTexture { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 texture_pool(0), | 417 texture_pool(0), |
| 390 wrap_mode(wrap_mode), | 418 wrap_mode(wrap_mode), |
| 391 hint(TextureUsageAny), | 419 hint(TextureUsageAny), |
| 392 type(Bitmap), | 420 type(Bitmap), |
| 393 format(RGBA_8888), | 421 format(RGBA_8888), |
| 394 shared_bitmap_id(bitmap_id), | 422 shared_bitmap_id(bitmap_id), |
| 395 shared_bitmap(NULL) { | 423 shared_bitmap(NULL) { |
| 396 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 424 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 397 } | 425 } |
| 398 | 426 |
| 399 ResourceProvider::RasterBuffer::RasterBuffer( | |
| 400 const Resource* resource, | |
| 401 ResourceProvider* resource_provider) | |
| 402 : resource_(resource), | |
| 403 resource_provider_(resource_provider), | |
| 404 locked_canvas_(NULL), | |
| 405 canvas_save_count_(0) { | |
| 406 DCHECK(resource_); | |
| 407 DCHECK(resource_provider_); | |
| 408 } | |
| 409 | |
| 410 ResourceProvider::RasterBuffer::~RasterBuffer() {} | |
| 411 | |
| 412 SkCanvas* ResourceProvider::RasterBuffer::LockForWrite() { | |
| 413 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 414 "ResourceProvider::RasterBuffer::LockForWrite"); | |
| 415 | |
| 416 DCHECK(!locked_canvas_); | |
| 417 | |
| 418 locked_canvas_ = DoLockForWrite(); | |
| 419 canvas_save_count_ = locked_canvas_ ? locked_canvas_->save() : 0; | |
| 420 return locked_canvas_; | |
| 421 } | |
| 422 | |
| 423 bool ResourceProvider::RasterBuffer::UnlockForWrite() { | |
| 424 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 425 "ResourceProvider::RasterBuffer::UnlockForWrite"); | |
| 426 | |
| 427 if (locked_canvas_) { | |
| 428 locked_canvas_->restoreToCount(canvas_save_count_); | |
| 429 locked_canvas_ = NULL; | |
| 430 } | |
| 431 return DoUnlockForWrite(); | |
| 432 } | |
| 433 | |
| 434 ResourceProvider::GpuRasterBuffer::GpuRasterBuffer( | 427 ResourceProvider::GpuRasterBuffer::GpuRasterBuffer( |
| 435 const Resource* resource, | 428 const Resource* resource, |
| 436 ResourceProvider* resource_provider, | 429 ResourceProvider* resource_provider, |
| 437 bool use_distance_field_text) | 430 bool use_distance_field_text) |
| 438 : RasterBuffer(resource, resource_provider), | 431 : resource_(resource), resource_provider_(resource_provider) { |
| 439 surface_generation_id_(0u), | 432 DCHECK_EQ(GLTexture, resource_->type); |
| 440 use_distance_field_text_(use_distance_field_text) { | 433 DCHECK(resource_->gl_id); |
| 434 | |
| 435 class GrContext* gr_context = resource_provider_->GrContext(); | |
| 436 // TODO(alokp): Implement TestContextProvider::GrContext(). | |
| 437 if (gr_context) { | |
| 438 GrBackendTextureDesc desc; | |
| 439 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
| 440 desc.fWidth = resource_->size.width(); | |
| 441 desc.fHeight = resource_->size.height(); | |
| 442 desc.fConfig = ToGrPixelConfig(resource_->format); | |
| 443 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 444 desc.fTextureHandle = resource_->gl_id; | |
| 445 skia::RefPtr<GrTexture> gr_texture = | |
| 446 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | |
| 447 SkSurface::TextRenderMode text_render_mode = | |
| 448 use_distance_field_text ? SkSurface::kDistanceField_TextRenderMode | |
| 449 : SkSurface::kStandard_TextRenderMode; | |
| 450 surface_ = skia::AdoptRef(SkSurface::NewRenderTargetDirect( | |
| 451 gr_texture->asRenderTarget(), text_render_mode)); | |
| 452 } | |
| 441 } | 453 } |
| 442 | 454 |
| 443 ResourceProvider::GpuRasterBuffer::~GpuRasterBuffer() { | 455 ResourceProvider::GpuRasterBuffer::~GpuRasterBuffer() { |
| 444 } | 456 } |
| 445 | 457 |
| 446 SkCanvas* ResourceProvider::GpuRasterBuffer::DoLockForWrite() { | 458 skia::RefPtr<SkCanvas> ResourceProvider::GpuRasterBuffer::AcquireSkCanvas() { |
| 447 if (!surface_) | 459 // Note that this function is called from a worker thread. |
| 448 surface_ = CreateSurface(); | 460 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 449 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; | 461 "ResourceProvider::GpuRasterBuffer::AcquireSkCanvas"); |
| 450 return surface_ ? surface_->getCanvas() : NULL; | 462 |
| 463 return surface_ ? skia::SharePtr(surface_->getCanvas()) | |
| 464 : skia::RefPtr<SkCanvas>(); | |
| 451 } | 465 } |
| 452 | 466 |
| 453 bool ResourceProvider::GpuRasterBuffer::DoUnlockForWrite() { | 467 void ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas( |
| 454 // generationID returns a non-zero, unique value corresponding to the content | 468 const skia::RefPtr<SkCanvas>& canvas) { |
| 455 // of surface. Hence, a change since DoLockForWrite was called means the | 469 // Note that this function is called from a worker thread. |
| 456 // surface has changed. | 470 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 457 return surface_ ? surface_generation_id_ != surface_->generationID() : false; | 471 "ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas"); |
| 458 } | |
| 459 | |
| 460 skia::RefPtr<SkSurface> ResourceProvider::GpuRasterBuffer::CreateSurface() { | |
| 461 DCHECK_EQ(GLTexture, resource()->type); | |
| 462 DCHECK(resource()->gl_id); | |
| 463 | |
| 464 class GrContext* gr_context = resource_provider()->GrContext(); | |
| 465 // TODO(alokp): Implement TestContextProvider::GrContext(). | |
| 466 if (!gr_context) | |
| 467 return skia::RefPtr<SkSurface>(); | |
| 468 | |
| 469 GrBackendTextureDesc desc; | |
| 470 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
| 471 desc.fWidth = resource()->size.width(); | |
| 472 desc.fHeight = resource()->size.height(); | |
| 473 desc.fConfig = ToGrPixelConfig(resource()->format); | |
| 474 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 475 desc.fTextureHandle = resource()->gl_id; | |
| 476 skia::RefPtr<GrTexture> gr_texture = | |
| 477 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | |
| 478 SkSurface::TextRenderMode text_render_mode = | |
| 479 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode | |
| 480 : SkSurface::kStandard_TextRenderMode; | |
| 481 return skia::AdoptRef(SkSurface::NewRenderTargetDirect( | |
| 482 gr_texture->asRenderTarget(), text_render_mode)); | |
| 483 } | |
| 484 | |
| 485 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( | |
| 486 const Resource* resource, | |
| 487 ResourceProvider* resource_provider) | |
| 488 : RasterBuffer(resource, resource_provider), | |
| 489 mapped_buffer_(NULL), | |
| 490 raster_bitmap_generation_id_(0u) {} | |
| 491 | |
| 492 ResourceProvider::BitmapRasterBuffer::~BitmapRasterBuffer() {} | |
| 493 | |
| 494 SkCanvas* ResourceProvider::BitmapRasterBuffer::DoLockForWrite() { | |
| 495 DCHECK(!mapped_buffer_); | |
| 496 DCHECK(!raster_canvas_); | |
| 497 | |
| 498 int stride = 0; | |
| 499 mapped_buffer_ = MapBuffer(&stride); | |
| 500 if (!mapped_buffer_) | |
| 501 return NULL; | |
| 502 | |
| 503 switch (resource()->format) { | |
| 504 case RGBA_4444: | |
| 505 // Use the default stride if we will eventually convert this | |
| 506 // bitmap to 4444. | |
| 507 raster_bitmap_.allocN32Pixels(resource()->size.width(), | |
| 508 resource()->size.height()); | |
| 509 break; | |
| 510 case RGBA_8888: | |
| 511 case BGRA_8888: { | |
| 512 SkImageInfo info = SkImageInfo::MakeN32Premul(resource()->size.width(), | |
| 513 resource()->size.height()); | |
| 514 if (0 == stride) | |
| 515 stride = info.minRowBytes(); | |
| 516 raster_bitmap_.installPixels(info, mapped_buffer_, stride); | |
| 517 break; | |
| 518 } | |
| 519 case LUMINANCE_8: | |
| 520 case RGB_565: | |
| 521 case ETC1: | |
| 522 NOTREACHED(); | |
| 523 break; | |
| 524 } | |
| 525 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); | |
| 526 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | |
| 527 return raster_canvas_.get(); | |
| 528 } | |
| 529 | |
| 530 bool ResourceProvider::BitmapRasterBuffer::DoUnlockForWrite() { | |
| 531 raster_canvas_.clear(); | |
| 532 | |
| 533 // getGenerationID returns a non-zero, unique value corresponding to the | |
| 534 // pixels in bitmap. Hence, a change since DoLockForWrite was called means the | |
| 535 // bitmap has changed. | |
| 536 bool raster_bitmap_changed = | |
| 537 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); | |
| 538 | |
| 539 if (raster_bitmap_changed) { | |
| 540 SkColorType buffer_colorType = | |
| 541 ResourceFormatToSkColorType(resource()->format); | |
| 542 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType())) | |
| 543 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType); | |
| 544 } | |
| 545 raster_bitmap_.reset(); | |
| 546 | |
| 547 UnmapBuffer(); | |
| 548 mapped_buffer_ = NULL; | |
| 549 return raster_bitmap_changed; | |
| 550 } | 472 } |
| 551 | 473 |
| 552 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( | 474 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( |
| 553 const Resource* resource, | 475 const Resource* resource, |
| 554 ResourceProvider* resource_provider) | 476 ResourceProvider* resource_provider) |
| 555 : BitmapRasterBuffer(resource, resource_provider) {} | 477 : resource_(resource), |
| 556 | 478 resource_provider_(resource_provider), |
| 557 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() {} | 479 mapped_buffer_(NULL), |
| 558 | 480 raster_bitmap_changed_(false), |
| 559 uint8_t* ResourceProvider::ImageRasterBuffer::MapBuffer(int* stride) { | 481 stride_(0) { |
| 560 return resource_provider()->MapImage(resource(), stride); | |
| 561 } | 482 } |
| 562 | 483 |
| 563 void ResourceProvider::ImageRasterBuffer::UnmapBuffer() { | 484 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() { |
| 564 resource_provider()->UnmapImage(resource()); | 485 } |
| 486 | |
| 487 void ResourceProvider::ImageRasterBuffer::MapBuffer() { | |
| 488 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 489 "ResourceProvider::ImageRasterBuffer::MapBuffer"); | |
| 490 | |
| 491 DCHECK(!mapped_buffer_); | |
| 492 | |
| 493 stride_ = 0; | |
| 494 mapped_buffer_ = resource_provider_->MapImage(resource_, &stride_); | |
| 495 } | |
| 496 | |
| 497 bool ResourceProvider::ImageRasterBuffer::UnmapBuffer() { | |
| 498 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 499 "ResourceProvider::ImageRasterBuffer::UnmapBuffer"); | |
| 500 | |
| 501 if (mapped_buffer_) { | |
| 502 resource_provider_->UnmapImage(resource_); | |
| 503 mapped_buffer_ = NULL; | |
| 504 } | |
| 505 return raster_bitmap_changed_; | |
| 506 } | |
| 507 | |
| 508 skia::RefPtr<SkCanvas> ResourceProvider::ImageRasterBuffer::AcquireSkCanvas() { | |
| 509 // Note that this function is called from a worker thread. | |
| 510 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 511 "ResourceProvider::ImageRasterBuffer::AcquireSkCanvas"); | |
| 512 | |
| 513 if (!mapped_buffer_) | |
| 514 return skia::RefPtr<SkCanvas>(); | |
| 515 | |
| 516 MakeBitmap(&raster_bitmap_, | |
| 517 mapped_buffer_, | |
| 518 resource_->format, | |
| 519 resource_->size, | |
| 520 stride_); | |
| 521 raster_bitmap_changed_ = true; | |
| 522 return skia::AdoptRef(new SkCanvas(raster_bitmap_)); | |
| 523 } | |
| 524 | |
| 525 void ResourceProvider::ImageRasterBuffer::ReleaseSkCanvas( | |
| 526 const skia::RefPtr<SkCanvas>& canvas) { | |
| 527 // Note that this function is called from a worker thread. | |
| 528 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 529 "ResourceProvider::ImageRasterBuffer::ReleaseSkCanvas"); | |
| 530 | |
| 531 SkColorType buffer_colorType = ResourceFormatToSkColorType(resource_->format); | |
| 532 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType())) | |
| 533 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType); | |
| 534 raster_bitmap_.reset(); | |
| 565 } | 535 } |
| 566 | 536 |
| 567 ResourceProvider::PixelRasterBuffer::PixelRasterBuffer( | 537 ResourceProvider::PixelRasterBuffer::PixelRasterBuffer( |
| 568 const Resource* resource, | 538 const Resource* resource, |
| 569 ResourceProvider* resource_provider) | 539 ResourceProvider* resource_provider) |
| 570 : BitmapRasterBuffer(resource, resource_provider) {} | 540 : resource_(resource), |
| 571 | 541 resource_provider_(resource_provider), |
| 572 ResourceProvider::PixelRasterBuffer::~PixelRasterBuffer() {} | 542 mapped_buffer_(NULL), |
| 573 | 543 raster_bitmap_changed_(false), |
| 574 uint8_t* ResourceProvider::PixelRasterBuffer::MapBuffer(int* stride) { | 544 stride_(0) { |
| 575 return resource_provider()->MapPixelBuffer(resource(), stride); | |
| 576 } | 545 } |
| 577 | 546 |
| 578 void ResourceProvider::PixelRasterBuffer::UnmapBuffer() { | 547 ResourceProvider::PixelRasterBuffer::~PixelRasterBuffer() { |
| 579 resource_provider()->UnmapPixelBuffer(resource()); | 548 } |
| 549 | |
| 550 void ResourceProvider::PixelRasterBuffer::MapBuffer() { | |
| 551 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 552 "ResourceProvider::PixelRasterBuffer::MapBuffer"); | |
| 553 | |
| 554 DCHECK(!mapped_buffer_); | |
| 555 | |
| 556 stride_ = 0; | |
| 557 mapped_buffer_ = resource_provider_->MapPixelBuffer(resource_, &stride_); | |
| 558 } | |
| 559 | |
| 560 bool ResourceProvider::PixelRasterBuffer::UnmapBuffer() { | |
| 561 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 562 "ResourceProvider::PixelRasterBuffer::UnmapBuffer"); | |
| 563 | |
| 564 if (mapped_buffer_) { | |
| 565 resource_provider_->UnmapPixelBuffer(resource_); | |
| 566 mapped_buffer_ = NULL; | |
| 567 } | |
| 568 return raster_bitmap_changed_; | |
| 569 } | |
| 570 | |
| 571 skia::RefPtr<SkCanvas> ResourceProvider::PixelRasterBuffer::AcquireSkCanvas() { | |
| 572 // Note that this function is called from a worker thread. | |
| 573 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 574 "ResourceProvider::PixelRasterBuffer::AcquireSkCanvas"); | |
| 575 | |
| 576 if (!mapped_buffer_) | |
| 577 return skia::RefPtr<SkCanvas>(); | |
| 578 | |
| 579 MakeBitmap(&raster_bitmap_, | |
| 580 mapped_buffer_, | |
| 581 resource_->format, | |
| 582 resource_->size, | |
| 583 stride_); | |
| 584 raster_bitmap_changed_ = true; | |
| 585 return skia::AdoptRef(new SkCanvas(raster_bitmap_)); | |
| 586 } | |
| 587 | |
| 588 void ResourceProvider::PixelRasterBuffer::ReleaseSkCanvas( | |
| 589 const skia::RefPtr<SkCanvas>& canvas) { | |
| 590 // Note that this function is called from a worker thread. | |
| 591 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
| 592 "ResourceProvider::PixelRasterBuffer::ReleaseSkCanvas"); | |
| 593 | |
| 594 SkColorType buffer_colorType = ResourceFormatToSkColorType(resource_->format); | |
| 595 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType())) | |
| 596 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType); | |
| 597 raster_bitmap_.reset(); | |
| 580 } | 598 } |
| 581 | 599 |
| 582 ResourceProvider::Child::Child() : marked_for_deletion(false) {} | 600 ResourceProvider::Child::Child() : marked_for_deletion(false) {} |
| 583 | 601 |
| 584 ResourceProvider::Child::~Child() {} | 602 ResourceProvider::Child::~Child() {} |
| 585 | 603 |
| 586 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 604 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
| 587 OutputSurface* output_surface, | 605 OutputSurface* output_surface, |
| 588 SharedBitmapManager* shared_bitmap_manager, | 606 SharedBitmapManager* shared_bitmap_manager, |
| 589 int highp_threshold_min, | 607 int highp_threshold_min, |
| (...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1720 if (!to_return.empty()) | 1738 if (!to_return.empty()) |
| 1721 child_info->return_callback.Run(to_return); | 1739 child_info->return_callback.Run(to_return); |
| 1722 | 1740 |
| 1723 if (child_info->marked_for_deletion && | 1741 if (child_info->marked_for_deletion && |
| 1724 child_info->parent_to_child_map.empty()) { | 1742 child_info->parent_to_child_map.empty()) { |
| 1725 DCHECK(child_info->child_to_parent_map.empty()); | 1743 DCHECK(child_info->child_to_parent_map.empty()); |
| 1726 children_.erase(child_it); | 1744 children_.erase(child_it); |
| 1727 } | 1745 } |
| 1728 } | 1746 } |
| 1729 | 1747 |
| 1730 SkCanvas* ResourceProvider::MapGpuRasterBuffer(ResourceId id) { | 1748 RasterBuffer* ResourceProvider::AcquireGpuRasterBuffer(ResourceId id) { |
| 1731 // Resource needs to be locked for write since GpuRasterBuffer writes | 1749 // Resource needs to be locked for write since GpuRasterBuffer writes |
| 1732 // directly to it. | 1750 // directly to it. |
| 1733 LockForWrite(id); | 1751 LockForWrite(id); |
| 1734 Resource* resource = GetResource(id); | 1752 Resource* resource = GetResource(id); |
| 1735 if (!resource->gpu_raster_buffer.get()) { | 1753 if (!resource->gpu_raster_buffer.get()) { |
| 1736 resource->gpu_raster_buffer.reset( | 1754 resource->gpu_raster_buffer.reset( |
| 1737 new GpuRasterBuffer(resource, this, use_distance_field_text_)); | 1755 new GpuRasterBuffer(resource, this, use_distance_field_text_)); |
| 1738 } | 1756 } |
| 1739 return resource->gpu_raster_buffer->LockForWrite(); | 1757 return resource->gpu_raster_buffer.get(); |
| 1740 } | 1758 } |
| 1741 | 1759 |
| 1742 void ResourceProvider::UnmapGpuRasterBuffer(ResourceId id) { | 1760 void ResourceProvider::ReleaseGpuRasterBuffer(ResourceId id) { |
| 1743 Resource* resource = GetResource(id); | 1761 Resource* resource = GetResource(id); |
| 1744 DCHECK(resource->gpu_raster_buffer.get()); | 1762 DCHECK(resource->gpu_raster_buffer.get()); |
| 1745 resource->gpu_raster_buffer->UnlockForWrite(); | |
| 1746 UnlockForWrite(id); | 1763 UnlockForWrite(id); |
| 1747 } | 1764 } |
| 1748 | 1765 |
| 1749 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { | 1766 RasterBuffer* ResourceProvider::AcquireImageRasterBuffer(ResourceId id) { |
| 1750 Resource* resource = GetResource(id); | 1767 Resource* resource = GetResource(id); |
| 1751 AcquireImage(resource); | 1768 AcquireImage(resource); |
| 1752 if (!resource->image_raster_buffer.get()) | 1769 if (!resource->image_raster_buffer.get()) |
| 1753 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); | 1770 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); |
| 1754 return resource->image_raster_buffer->LockForWrite(); | 1771 resource->image_raster_buffer->MapBuffer(); |
| 1772 return resource->image_raster_buffer.get(); | |
| 1755 } | 1773 } |
| 1756 | 1774 |
| 1757 bool ResourceProvider::UnmapImageRasterBuffer(ResourceId id) { | 1775 bool ResourceProvider::ReleaseImageRasterBuffer(ResourceId id) { |
| 1758 Resource* resource = GetResource(id); | 1776 Resource* resource = GetResource(id); |
| 1759 resource->dirty_image = true; | 1777 resource->dirty_image = true; |
| 1760 return resource->image_raster_buffer->UnlockForWrite(); | 1778 return resource->image_raster_buffer->UnmapBuffer(); |
| 1761 } | 1779 } |
| 1762 | 1780 |
| 1763 void ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) { | 1781 RasterBuffer* ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) { |
| 1764 Resource* resource = GetResource(id); | 1782 Resource* resource = GetResource(id); |
| 1765 AcquirePixelBuffer(resource); | 1783 AcquirePixelBuffer(resource); |
| 1766 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this)); | 1784 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this)); |
| 1785 resource->pixel_raster_buffer->MapBuffer(); | |
| 1786 return resource->pixel_raster_buffer.get(); | |
| 1767 } | 1787 } |
| 1768 | 1788 |
| 1769 void ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) { | 1789 bool ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) { |
| 1770 Resource* resource = GetResource(id); | 1790 Resource* resource = GetResource(id); |
| 1791 DCHECK(resource->pixel_raster_buffer.get()); | |
| 1792 bool raster_bitmap_changed = resource->pixel_raster_buffer->UnmapBuffer(); | |
| 1771 resource->pixel_raster_buffer.reset(); | 1793 resource->pixel_raster_buffer.reset(); |
| 1772 ReleasePixelBuffer(resource); | 1794 ReleasePixelBuffer(resource); |
| 1773 } | 1795 return raster_bitmap_changed; |
| 1774 | |
| 1775 SkCanvas* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { | |
| 1776 Resource* resource = GetResource(id); | |
| 1777 DCHECK(resource->pixel_raster_buffer.get()); | |
| 1778 return resource->pixel_raster_buffer->LockForWrite(); | |
| 1779 } | |
| 1780 | |
| 1781 bool ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { | |
| 1782 Resource* resource = GetResource(id); | |
| 1783 DCHECK(resource->pixel_raster_buffer.get()); | |
| 1784 return resource->pixel_raster_buffer->UnlockForWrite(); | |
| 1785 } | 1796 } |
| 1786 | 1797 |
| 1787 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { | 1798 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { |
| 1788 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1799 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1789 "ResourceProvider::AcquirePixelBuffer"); | 1800 "ResourceProvider::AcquirePixelBuffer"); |
| 1790 | 1801 |
| 1791 DCHECK(resource->origin == Resource::Internal); | 1802 DCHECK(resource->origin == Resource::Internal); |
| 1792 DCHECK_EQ(resource->exported_count, 0); | 1803 DCHECK_EQ(resource->exported_count, 0); |
| 1793 DCHECK(!resource->image_id); | 1804 DCHECK(!resource->image_id); |
| 1794 DCHECK_NE(ETC1, resource->format); | 1805 DCHECK_NE(ETC1, resource->format); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1910 return target; | 1921 return target; |
| 1911 } | 1922 } |
| 1912 | 1923 |
| 1913 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1924 void ResourceProvider::BeginSetPixels(ResourceId id) { |
| 1914 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1925 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1915 "ResourceProvider::BeginSetPixels"); | 1926 "ResourceProvider::BeginSetPixels"); |
| 1916 | 1927 |
| 1917 Resource* resource = GetResource(id); | 1928 Resource* resource = GetResource(id); |
| 1918 DCHECK(!resource->pending_set_pixels); | 1929 DCHECK(!resource->pending_set_pixels); |
| 1919 | 1930 |
| 1920 LazyCreate(resource); | 1931 // Upload if raster bitmap was modified. |
| 1921 DCHECK(resource->origin == Resource::Internal); | 1932 DCHECK(resource->pixel_raster_buffer.get()); |
| 1922 DCHECK(resource->gl_id || resource->allocated); | 1933 if (resource->pixel_raster_buffer->UnmapBuffer()) { |
|
reveman
2014/08/15 11:54:31
You can probably remove the comment above if you u
reveman
2014/08/15 13:59:34
btw, should we early out here instead? resource->p
auygun
2014/08/15 15:08:23
Right. resource->pending_set_pixels should not be
| |
| 1923 DCHECK(ReadLockFenceHasPassed(resource)); | 1934 LazyCreate(resource); |
| 1924 DCHECK(!resource->image_id); | 1935 DCHECK(resource->origin == Resource::Internal); |
| 1936 DCHECK(resource->gl_id || resource->allocated); | |
| 1937 DCHECK(ReadLockFenceHasPassed(resource)); | |
| 1938 DCHECK(!resource->image_id); | |
| 1925 | 1939 |
| 1926 bool allocate = !resource->allocated; | 1940 bool allocate = !resource->allocated; |
| 1927 resource->allocated = true; | 1941 resource->allocated = true; |
| 1928 LockForWrite(id); | 1942 LockForWrite(id); |
| 1929 | 1943 |
| 1930 DCHECK_EQ(GLTexture, resource->type); | 1944 DCHECK_EQ(GLTexture, resource->type); |
| 1931 DCHECK(resource->gl_id); | 1945 DCHECK(resource->gl_id); |
| 1932 GLES2Interface* gl = ContextGL(); | 1946 GLES2Interface* gl = ContextGL(); |
| 1933 DCHECK(gl); | 1947 DCHECK(gl); |
| 1934 DCHECK(resource->gl_pixel_buffer_id); | 1948 DCHECK(resource->gl_pixel_buffer_id); |
| 1935 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 1949 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 1936 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 1950 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 1937 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1951 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1938 resource->gl_pixel_buffer_id); | 1952 resource->gl_pixel_buffer_id); |
| 1939 if (!resource->gl_upload_query_id) | 1953 if (!resource->gl_upload_query_id) |
| 1940 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); | 1954 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); |
| 1941 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1955 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
| 1942 resource->gl_upload_query_id); | 1956 resource->gl_upload_query_id); |
| 1943 if (allocate) { | 1957 if (allocate) { |
| 1944 gl->AsyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1958 gl->AsyncTexImage2DCHROMIUM(GL_TEXTURE_2D, |
| 1945 0, /* level */ | 1959 0, /* level */ |
| 1946 GLInternalFormat(resource->format), | 1960 GLInternalFormat(resource->format), |
| 1947 resource->size.width(), | 1961 resource->size.width(), |
| 1948 resource->size.height(), | 1962 resource->size.height(), |
| 1949 0, /* border */ | 1963 0, /* border */ |
| 1950 GLDataFormat(resource->format), | 1964 GLDataFormat(resource->format), |
| 1951 GLDataType(resource->format), | 1965 GLDataType(resource->format), |
| 1952 NULL); | 1966 NULL); |
| 1953 } else { | 1967 } else { |
| 1954 gl->AsyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1968 gl->AsyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
| 1955 0, /* level */ | 1969 0, /* level */ |
| 1956 0, /* x */ | 1970 0, /* x */ |
| 1957 0, /* y */ | 1971 0, /* y */ |
| 1958 resource->size.width(), | 1972 resource->size.width(), |
| 1959 resource->size.height(), | 1973 resource->size.height(), |
| 1960 GLDataFormat(resource->format), | 1974 GLDataFormat(resource->format), |
| 1961 GLDataType(resource->format), | 1975 GLDataType(resource->format), |
| 1962 NULL); | 1976 NULL); |
| 1977 } | |
| 1978 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | |
| 1979 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 1963 } | 1980 } |
| 1964 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | |
| 1965 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 1966 | 1981 |
| 1967 resource->pending_set_pixels = true; | 1982 resource->pending_set_pixels = true; |
| 1968 resource->set_pixels_completion_forced = false; | 1983 resource->set_pixels_completion_forced = false; |
| 1969 } | 1984 } |
| 1970 | 1985 |
| 1971 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { | 1986 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { |
| 1972 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1987 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1973 "ResourceProvider::ForceSetPixelsToComplete"); | 1988 "ResourceProvider::ForceSetPixelsToComplete"); |
| 1974 | 1989 |
| 1975 Resource* resource = GetResource(id); | 1990 Resource* resource = GetResource(id); |
| 1976 DCHECK(resource->locked_for_write); | 1991 DCHECK(resource->locked_for_write); |
| 1977 DCHECK(resource->pending_set_pixels); | 1992 DCHECK(resource->pending_set_pixels); |
| 1978 DCHECK(!resource->set_pixels_completion_forced); | 1993 DCHECK(!resource->set_pixels_completion_forced); |
| 1979 | 1994 |
| 1980 if (resource->gl_id) { | 1995 if (resource->gl_id) { |
| 1981 GLES2Interface* gl = ContextGL(); | 1996 GLES2Interface* gl = ContextGL(); |
| 1982 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1997 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| 1983 GLC(gl, gl->WaitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); | 1998 GLC(gl, gl->WaitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); |
| 1984 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, 0)); | 1999 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, 0)); |
| 1985 } | 2000 } |
| 1986 | 2001 |
| 1987 resource->set_pixels_completion_forced = true; | 2002 resource->set_pixels_completion_forced = true; |
| 1988 } | 2003 } |
| 1989 | 2004 |
| 1990 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { | 2005 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { |
| 1991 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 2006 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1992 "ResourceProvider::DidSetPixelsComplete"); | 2007 "ResourceProvider::DidSetPixelsComplete"); |
| 1993 | 2008 |
| 1994 Resource* resource = GetResource(id); | 2009 Resource* resource = GetResource(id); |
| 2010 | |
| 2011 // Upload can be avoided as a result of raster bitmap not being modified. | |
| 2012 // Assume the upload was completed in that case. | |
| 2013 if (!resource->pending_set_pixels) | |
| 2014 return true; | |
| 2015 | |
| 1995 DCHECK(resource->locked_for_write); | 2016 DCHECK(resource->locked_for_write); |
| 1996 DCHECK(resource->pending_set_pixels); | |
| 1997 | 2017 |
| 1998 if (resource->gl_id) { | 2018 if (resource->gl_id) { |
| 1999 GLES2Interface* gl = ContextGL(); | 2019 GLES2Interface* gl = ContextGL(); |
| 2000 DCHECK(gl); | 2020 DCHECK(gl); |
| 2001 DCHECK(resource->gl_upload_query_id); | 2021 DCHECK(resource->gl_upload_query_id); |
| 2002 GLuint complete = 1; | 2022 GLuint complete = 1; |
| 2003 gl->GetQueryObjectuivEXT( | 2023 gl->GetQueryObjectuivEXT( |
| 2004 resource->gl_upload_query_id, GL_QUERY_RESULT_AVAILABLE_EXT, &complete); | 2024 resource->gl_upload_query_id, GL_QUERY_RESULT_AVAILABLE_EXT, &complete); |
| 2005 if (!complete) | 2025 if (!complete) |
| 2006 return false; | 2026 return false; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2252 ContextProvider* context_provider = output_surface_->context_provider(); | 2272 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2253 return context_provider ? context_provider->ContextGL() : NULL; | 2273 return context_provider ? context_provider->ContextGL() : NULL; |
| 2254 } | 2274 } |
| 2255 | 2275 |
| 2256 class GrContext* ResourceProvider::GrContext() const { | 2276 class GrContext* ResourceProvider::GrContext() const { |
| 2257 ContextProvider* context_provider = output_surface_->context_provider(); | 2277 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2258 return context_provider ? context_provider->GrContext() : NULL; | 2278 return context_provider ? context_provider->GrContext() : NULL; |
| 2259 } | 2279 } |
| 2260 | 2280 |
| 2261 } // namespace cc | 2281 } // namespace cc |
| OLD | NEW |