Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/tiles/gpu_image_decode_cache.h" | 5 #include "cc/tiles/gpu_image_decode_cache.h" |
| 6 | 6 |
| 7 #include <inttypes.h> | 7 #include <inttypes.h> |
| 8 | 8 |
| 9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/memory/discardable_memory_allocator.h" | 10 #include "base/memory/discardable_memory_allocator.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 GpuImageDecodeCache::InUseCacheEntry::InUseCacheEntry(InUseCacheEntry&&) = | 142 GpuImageDecodeCache::InUseCacheEntry::InUseCacheEntry(InUseCacheEntry&&) = |
| 143 default; | 143 default; |
| 144 GpuImageDecodeCache::InUseCacheEntry::~InUseCacheEntry() = default; | 144 GpuImageDecodeCache::InUseCacheEntry::~InUseCacheEntry() = default; |
| 145 | 145 |
| 146 // Task which decodes an image and stores the result in discardable memory. | 146 // Task which decodes an image and stores the result in discardable memory. |
| 147 // This task does not use GPU resources and can be run on any thread. | 147 // This task does not use GPU resources and can be run on any thread. |
| 148 class ImageDecodeTaskImpl : public TileTask { | 148 class ImageDecodeTaskImpl : public TileTask { |
| 149 public: | 149 public: |
| 150 ImageDecodeTaskImpl(GpuImageDecodeCache* cache, | 150 ImageDecodeTaskImpl(GpuImageDecodeCache* cache, |
| 151 const DrawImage& draw_image, | 151 const DrawImage& draw_image, |
| 152 const ImageDecodeCache::TracingInfo& tracing_info) | 152 const ImageDecodeCache::TracingInfo& tracing_info, |
| 153 GpuImageDecodeCache::DecodeTaskType task_type) | |
| 153 : TileTask(true), | 154 : TileTask(true), |
| 154 cache_(cache), | 155 cache_(cache), |
| 155 image_(draw_image), | 156 image_(draw_image), |
| 156 tracing_info_(tracing_info) { | 157 tracing_info_(tracing_info), |
| 158 task_type_(task_type) { | |
| 157 DCHECK(!SkipImage(draw_image)); | 159 DCHECK(!SkipImage(draw_image)); |
| 158 } | 160 } |
| 159 | 161 |
| 160 // Overridden from Task: | 162 // Overridden from Task: |
| 161 void RunOnWorkerThread() override { | 163 void RunOnWorkerThread() override { |
| 162 TRACE_EVENT2("cc", "ImageDecodeTaskImpl::RunOnWorkerThread", "mode", "gpu", | 164 TRACE_EVENT2("cc", "ImageDecodeTaskImpl::RunOnWorkerThread", "mode", "gpu", |
| 163 "source_prepare_tiles_id", tracing_info_.prepare_tiles_id); | 165 "source_prepare_tiles_id", tracing_info_.prepare_tiles_id); |
| 164 devtools_instrumentation::ScopedImageDecodeTask image_decode_task( | 166 devtools_instrumentation::ScopedImageDecodeTask image_decode_task( |
| 165 image_.image().get(), | 167 image_.image().get(), |
| 166 devtools_instrumentation::ScopedImageDecodeTask::GPU); | 168 devtools_instrumentation::ScopedImageDecodeTask::GPU); |
| 167 cache_->DecodeImage(image_); | 169 cache_->DecodeImage(image_); |
| 168 } | 170 } |
| 169 | 171 |
| 170 // Overridden from TileTask: | 172 // Overridden from TileTask: |
| 171 void OnTaskCompleted() override { | 173 void OnTaskCompleted() override { |
| 172 cache_->OnImageDecodeTaskCompleted(image_); | 174 cache_->OnImageDecodeTaskCompleted(image_, task_type_); |
| 173 } | 175 } |
| 174 | 176 |
| 175 protected: | 177 protected: |
| 176 ~ImageDecodeTaskImpl() override {} | 178 ~ImageDecodeTaskImpl() override {} |
| 177 | 179 |
| 178 private: | 180 private: |
| 179 GpuImageDecodeCache* cache_; | 181 GpuImageDecodeCache* cache_; |
| 180 DrawImage image_; | 182 DrawImage image_; |
| 181 const ImageDecodeCache::TracingInfo tracing_info_; | 183 const ImageDecodeCache::TracingInfo tracing_info_; |
| 184 const GpuImageDecodeCache::DecodeTaskType task_type_; | |
| 182 | 185 |
| 183 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); | 186 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); |
| 184 }; | 187 }; |
| 185 | 188 |
| 186 // Task which creates an image from decoded data. Typically this involves | 189 // Task which creates an image from decoded data. Typically this involves |
| 187 // uploading data to the GPU, which requires this task be run on the non- | 190 // uploading data to the GPU, which requires this task be run on the non- |
| 188 // concurrent thread. | 191 // concurrent thread. |
| 189 class ImageUploadTaskImpl : public TileTask { | 192 class ImageUploadTaskImpl : public TileTask { |
| 190 public: | 193 public: |
| 191 ImageUploadTaskImpl(GpuImageDecodeCache* cache, | 194 ImageUploadTaskImpl(GpuImageDecodeCache* cache, |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 // It is safe to unregister, even if we didn't register in the constructor. | 376 // It is safe to unregister, even if we didn't register in the constructor. |
| 374 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 377 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 375 this); | 378 this); |
| 376 // Unregister this component with memory_coordinator::ClientRegistry. | 379 // Unregister this component with memory_coordinator::ClientRegistry. |
| 377 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); | 380 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); |
| 378 } | 381 } |
| 379 | 382 |
| 380 bool GpuImageDecodeCache::GetTaskForImageAndRef(const DrawImage& draw_image, | 383 bool GpuImageDecodeCache::GetTaskForImageAndRef(const DrawImage& draw_image, |
| 381 const TracingInfo& tracing_info, | 384 const TracingInfo& tracing_info, |
| 382 scoped_refptr<TileTask>* task) { | 385 scoped_refptr<TileTask>* task) { |
| 386 return GetTaskForImageAndRefInternal( | |
| 387 draw_image, tracing_info, DecodeTaskType::PART_OF_UPLOAD_TASK, task); | |
| 388 } | |
| 389 | |
| 390 bool GpuImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef( | |
| 391 const DrawImage& draw_image, | |
| 392 scoped_refptr<TileTask>* task) { | |
| 393 return GetTaskForImageAndRefInternal( | |
| 394 draw_image, TracingInfo(), DecodeTaskType::STAND_ALONE_DECODE_TASK, task); | |
| 395 } | |
| 396 | |
| 397 bool GpuImageDecodeCache::GetTaskForImageAndRefInternal( | |
| 398 const DrawImage& draw_image, | |
| 399 const TracingInfo& tracing_info, | |
| 400 DecodeTaskType task_type, | |
| 401 scoped_refptr<TileTask>* task) { | |
| 383 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 402 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 384 "GpuImageDecodeCache::GetTaskForImageAndRef"); | 403 "GpuImageDecodeCache::GetTaskForImageAndRef"); |
| 385 if (SkipImage(draw_image)) { | 404 if (SkipImage(draw_image)) { |
| 386 *task = nullptr; | 405 *task = nullptr; |
| 387 return false; | 406 return false; |
| 388 } | 407 } |
| 389 | 408 |
| 390 base::AutoLock lock(lock_); | 409 base::AutoLock lock(lock_); |
| 391 const auto image_id = draw_image.image()->uniqueID(); | 410 const auto image_id = draw_image.image()->uniqueID(); |
| 392 ImageData* image_data = GetImageDataForDrawImage(draw_image); | 411 ImageData* image_data = GetImageDataForDrawImage(draw_image); |
| 393 scoped_refptr<ImageData> new_data; | 412 scoped_refptr<ImageData> new_data; |
| 394 if (!image_data) { | 413 if (!image_data) { |
| 395 // We need an ImageData, create one now. | 414 // We need an ImageData, create one now. |
| 396 new_data = CreateImageData(draw_image); | 415 new_data = CreateImageData(draw_image); |
| 397 image_data = new_data.get(); | 416 image_data = new_data.get(); |
| 398 } else if (image_data->is_at_raster) { | 417 } else if (image_data->is_at_raster) { |
| 399 // Image is at-raster, just return, this usage will be at-raster as well. | 418 // Image is at-raster, just return, this usage will be at-raster as well. |
| 400 *task = nullptr; | 419 *task = nullptr; |
| 401 return false; | 420 return false; |
| 402 } else if (image_data->decode.decode_failure) { | 421 } else if (image_data->decode.decode_failure) { |
| 403 // We have already tried and failed to decode this image, so just return. | 422 // We have already tried and failed to decode this image, so just return. |
| 404 *task = nullptr; | 423 *task = nullptr; |
| 405 return false; | 424 return false; |
| 406 } else if (image_data->upload.image()) { | 425 } else if (image_data->upload.image()) { |
| 407 // The image is already uploaded, ref and return. | 426 // The image is already uploaded, ref and return. |
| 408 RefImage(draw_image); | 427 RefImage(draw_image); |
| 409 *task = nullptr; | 428 *task = nullptr; |
| 410 return true; | 429 return true; |
| 411 } else if (image_data->upload.task) { | 430 } else if (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK && |
| 431 image_data->upload.task) { | |
| 412 // We had an existing upload task, ref the image and return the task. | 432 // We had an existing upload task, ref the image and return the task. |
| 413 RefImage(draw_image); | 433 RefImage(draw_image); |
| 414 *task = image_data->upload.task; | 434 *task = image_data->upload.task; |
| 415 return true; | 435 return true; |
| 436 } else if (task_type == DecodeTaskType::STAND_ALONE_DECODE_TASK && | |
| 437 image_data->decode.stand_alone_task) { | |
| 438 // We had an existing out of raster task, ref the image and return the task. | |
| 439 RefImage(draw_image); | |
| 440 *task = image_data->decode.stand_alone_task; | |
| 441 return true; | |
| 416 } | 442 } |
| 417 | 443 |
| 418 // Ensure that the image we're about to decode/upload will fit in memory. | 444 // Ensure that the image we're about to decode/upload will fit in memory. |
| 419 if (!EnsureCapacity(image_data->size)) { | 445 if (!EnsureCapacity(image_data->size)) { |
| 420 // Image will not fit, do an at-raster decode. | 446 // Image will not fit, do an at-raster decode. |
| 421 *task = nullptr; | 447 *task = nullptr; |
| 422 return false; | 448 return false; |
| 423 } | 449 } |
| 424 | 450 |
| 425 // If we had to create new image data, add it to our map now that we know it | 451 // If we had to create new image data, add it to our map now that we know it |
| 426 // will fit. | 452 // will fit. |
| 427 if (new_data) | 453 if (new_data) |
| 428 persistent_cache_.Put(image_id, std::move(new_data)); | 454 persistent_cache_.Put(image_id, std::move(new_data)); |
| 429 | 455 |
| 430 // Ref image and create a upload and decode tasks. We will release this ref | 456 if (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK) { |
| 431 // in UploadTaskCompleted. | 457 // Ref image and create a upload and decode tasks. We will release this ref |
| 432 RefImage(draw_image); | 458 // in UploadTaskCompleted. |
| 433 *task = make_scoped_refptr(new ImageUploadTaskImpl( | 459 RefImage(draw_image); |
| 434 this, draw_image, GetImageDecodeTaskAndRef(draw_image, tracing_info), | 460 *task = make_scoped_refptr(new ImageUploadTaskImpl( |
| 435 tracing_info)); | 461 this, draw_image, |
| 436 image_data->upload.task = *task; | 462 GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type), |
| 463 tracing_info)); | |
| 464 image_data->upload.task = *task; | |
| 465 } else { | |
| 466 *task = GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type); | |
| 467 } | |
| 437 | 468 |
| 438 // Ref the image again - this ref is owned by the caller, and it is their | 469 // Ref the image again - this ref is owned by the caller, and it is their |
| 439 // responsibility to release it by calling UnrefImage. | 470 // responsibility to release it by calling UnrefImage. |
| 440 RefImage(draw_image); | 471 RefImage(draw_image); |
| 441 return true; | 472 return true; |
| 442 } | 473 } |
| 443 | 474 |
| 444 void GpuImageDecodeCache::UnrefImage(const DrawImage& draw_image) { | 475 void GpuImageDecodeCache::UnrefImage(const DrawImage& draw_image) { |
| 445 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 476 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 446 "GpuImageDecodeCache::UnrefImage"); | 477 "GpuImageDecodeCache::UnrefImage"); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 "GpuImageDecodeCache::UploadImage"); | 671 "GpuImageDecodeCache::UploadImage"); |
| 641 ContextProvider::ScopedContextLock context_lock(context_); | 672 ContextProvider::ScopedContextLock context_lock(context_); |
| 642 base::AutoLock lock(lock_); | 673 base::AutoLock lock(lock_); |
| 643 ImageData* image_data = GetImageDataForDrawImage(draw_image); | 674 ImageData* image_data = GetImageDataForDrawImage(draw_image); |
| 644 DCHECK(image_data); | 675 DCHECK(image_data); |
| 645 DCHECK(!image_data->is_at_raster); | 676 DCHECK(!image_data->is_at_raster); |
| 646 UploadImageIfNecessary(draw_image, image_data); | 677 UploadImageIfNecessary(draw_image, image_data); |
| 647 } | 678 } |
| 648 | 679 |
| 649 void GpuImageDecodeCache::OnImageDecodeTaskCompleted( | 680 void GpuImageDecodeCache::OnImageDecodeTaskCompleted( |
| 650 const DrawImage& draw_image) { | 681 const DrawImage& draw_image, |
| 682 DecodeTaskType task_type) { | |
| 651 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 683 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 652 "GpuImageDecodeCache::OnImageDecodeTaskCompleted"); | 684 "GpuImageDecodeCache::OnImageDecodeTaskCompleted"); |
| 653 base::AutoLock lock(lock_); | 685 base::AutoLock lock(lock_); |
| 654 // Decode task is complete, remove our reference to it. | 686 // Decode task is complete, remove our reference to it. |
| 655 ImageData* image_data = GetImageDataForDrawImage(draw_image); | 687 ImageData* image_data = GetImageDataForDrawImage(draw_image); |
| 656 DCHECK(image_data); | 688 DCHECK(image_data); |
| 657 DCHECK(image_data->decode.task); | 689 if (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK) { |
| 658 image_data->decode.task = nullptr; | 690 DCHECK(image_data->decode.task); |
| 691 image_data->decode.task = nullptr; | |
| 692 } else { | |
| 693 DCHECK(task_type == DecodeTaskType::STAND_ALONE_DECODE_TASK); | |
| 694 DCHECK(image_data->decode.stand_alone_task); | |
| 695 image_data->decode.stand_alone_task = nullptr; | |
| 696 } | |
| 659 | 697 |
| 660 // While the decode task is active, we keep a ref on the decoded data. | 698 // While the decode task is active, we keep a ref on the decoded data. |
| 661 // Release that ref now. | 699 // Release that ref now. |
| 662 UnrefImageDecode(draw_image); | 700 UnrefImageDecode(draw_image); |
| 663 } | 701 } |
| 664 | 702 |
| 665 void GpuImageDecodeCache::OnImageUploadTaskCompleted( | 703 void GpuImageDecodeCache::OnImageUploadTaskCompleted( |
| 666 const DrawImage& draw_image) { | 704 const DrawImage& draw_image) { |
| 667 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 705 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 668 "GpuImageDecodeCache::OnImageUploadTaskCompleted"); | 706 "GpuImageDecodeCache::OnImageUploadTaskCompleted"); |
| 669 base::AutoLock lock(lock_); | 707 base::AutoLock lock(lock_); |
| 670 // Upload task is complete, remove our reference to it. | 708 // Upload task is complete, remove our reference to it. |
| 671 ImageData* image_data = GetImageDataForDrawImage(draw_image); | 709 ImageData* image_data = GetImageDataForDrawImage(draw_image); |
| 672 DCHECK(image_data); | 710 DCHECK(image_data); |
| 673 DCHECK(image_data->upload.task); | 711 DCHECK(image_data->upload.task); |
| 674 image_data->upload.task = nullptr; | 712 image_data->upload.task = nullptr; |
| 675 | 713 |
| 676 // While the upload task is active, we keep a ref on both the image it will be | 714 // While the upload task is active, we keep a ref on both the image it will be |
| 677 // populating, as well as the decode it needs to populate it. Release these | 715 // populating, as well as the decode it needs to populate it. Release these |
| 678 // refs now. | 716 // refs now. |
| 679 UnrefImageDecode(draw_image); | 717 UnrefImageDecode(draw_image); |
| 680 UnrefImageInternal(draw_image); | 718 UnrefImageInternal(draw_image); |
| 681 } | 719 } |
| 682 | 720 |
| 683 // Checks if an existing image decode exists. If not, returns a task to produce | 721 // Checks if an existing image decode exists. If not, returns a task to produce |
| 684 // the requested decode. | 722 // the requested decode. |
| 685 scoped_refptr<TileTask> GpuImageDecodeCache::GetImageDecodeTaskAndRef( | 723 scoped_refptr<TileTask> GpuImageDecodeCache::GetImageDecodeTaskAndRef( |
| 686 const DrawImage& draw_image, | 724 const DrawImage& draw_image, |
| 687 const TracingInfo& tracing_info) { | 725 const TracingInfo& tracing_info, |
| 726 DecodeTaskType task_type) { | |
| 688 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 727 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 689 "GpuImageDecodeCache::GetImageDecodeTaskAndRef"); | 728 "GpuImageDecodeCache::GetImageDecodeTaskAndRef"); |
| 690 lock_.AssertAcquired(); | 729 lock_.AssertAcquired(); |
| 691 | 730 |
| 692 // This ref is kept alive while an upload task may need this decode. We | 731 // This ref is kept alive while an upload task may need this decode. We |
| 693 // release this ref in UploadTaskCompleted. | 732 // release this ref in UploadTaskCompleted. |
| 694 RefImageDecode(draw_image); | 733 if (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK) |
| 734 RefImageDecode(draw_image); | |
| 695 | 735 |
| 696 ImageData* image_data = GetImageDataForDrawImage(draw_image); | 736 ImageData* image_data = GetImageDataForDrawImage(draw_image); |
| 697 DCHECK(image_data); | 737 DCHECK(image_data); |
| 698 if (image_data->decode.is_locked()) { | 738 if (image_data->decode.is_locked()) { |
| 699 // We should never be creating a decode task for an at raster image. | 739 // We should never be creating a decode task for an at raster image. |
| 700 DCHECK(!image_data->is_at_raster); | 740 DCHECK(!image_data->is_at_raster); |
| 701 // We should never be creating a decode for an already-uploaded image. | 741 // We should never be creating a decode for an already-uploaded image. |
| 702 DCHECK(!image_data->upload.image()); | 742 DCHECK(!image_data->upload.image()); |
| 703 return nullptr; | 743 return nullptr; |
| 704 } | 744 } |
| 705 | 745 |
| 706 // We didn't have an existing locked image, create a task to lock or decode. | 746 // We didn't have an existing locked image, create a task to lock or decode. |
| 707 scoped_refptr<TileTask>& existing_task = image_data->decode.task; | 747 scoped_refptr<TileTask>& existing_task = |
|
ericrk
2017/01/04 07:48:31
I assume we can't end up decoding an image twice i
vmpstr
2017/01/06 01:19:03
That's not necessarily true, since which image is
ericrk
2017/01/09 21:07:27
Sounds good to me - there's probably something we
| |
| 748 (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK) | |
| 749 ? image_data->decode.task | |
| 750 : image_data->decode.stand_alone_task; | |
| 708 if (!existing_task) { | 751 if (!existing_task) { |
| 709 // Ref image decode and create a decode task. This ref will be released in | 752 // Ref image decode and create a decode task. This ref will be released in |
| 710 // DecodeTaskCompleted. | 753 // DecodeTaskCompleted. |
| 711 RefImageDecode(draw_image); | 754 RefImageDecode(draw_image); |
| 712 existing_task = make_scoped_refptr( | 755 existing_task = make_scoped_refptr( |
| 713 new ImageDecodeTaskImpl(this, draw_image, tracing_info)); | 756 new ImageDecodeTaskImpl(this, draw_image, tracing_info, task_type)); |
| 714 } | 757 } |
| 715 return existing_task; | 758 return existing_task; |
| 716 } | 759 } |
| 717 | 760 |
| 718 void GpuImageDecodeCache::RefImageDecode(const DrawImage& draw_image) { | 761 void GpuImageDecodeCache::RefImageDecode(const DrawImage& draw_image) { |
| 719 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 762 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 720 "GpuImageDecodeCache::RefImageDecode"); | 763 "GpuImageDecodeCache::RefImageDecode"); |
| 721 lock_.AssertAcquired(); | 764 lock_.AssertAcquired(); |
| 722 auto found = in_use_cache_.find(GenerateInUseCacheKey(draw_image)); | 765 auto found = in_use_cache_.find(GenerateInUseCacheKey(draw_image)); |
| 723 DCHECK(found != in_use_cache_.end()); | 766 DCHECK(found != in_use_cache_.end()); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 if (image_data->upload.ref_count == 0 && image_data->upload.budgeted && | 893 if (image_data->upload.ref_count == 0 && image_data->upload.budgeted && |
| 851 !image_data->upload.image()) { | 894 !image_data->upload.image()) { |
| 852 DCHECK_GE(bytes_used_, image_data->size); | 895 DCHECK_GE(bytes_used_, image_data->size); |
| 853 bytes_used_ -= image_data->size; | 896 bytes_used_ -= image_data->size; |
| 854 image_data->upload.budgeted = false; | 897 image_data->upload.budgeted = false; |
| 855 } | 898 } |
| 856 | 899 |
| 857 // We should unlock the discardable memory for the image in two cases: | 900 // We should unlock the discardable memory for the image in two cases: |
| 858 // 1) The image is no longer being used (no decode or upload refs). | 901 // 1) The image is no longer being used (no decode or upload refs). |
| 859 // 2) This is a GPU backed image that has already been uploaded (no decode | 902 // 2) This is a GPU backed image that has already been uploaded (no decode |
| 860 // refs). | 903 // refs, and we actually already have an image). |
| 861 bool should_unlock_discardable = | 904 bool should_unlock_discardable = |
| 862 !has_any_refs || (image_data->mode == DecodedDataMode::GPU && | 905 !has_any_refs || |
| 863 !image_data->decode.ref_count); | 906 (image_data->mode == DecodedDataMode::GPU && |
| 907 !image_data->decode.ref_count && image_data->upload.image()); | |
| 864 | 908 |
| 865 if (should_unlock_discardable && image_data->decode.is_locked()) { | 909 if (should_unlock_discardable && image_data->decode.is_locked()) { |
| 866 DCHECK(image_data->decode.data()); | 910 DCHECK(image_data->decode.data()); |
| 867 image_data->decode.Unlock(); | 911 image_data->decode.Unlock(); |
| 868 } | 912 } |
| 869 | 913 |
| 870 #if DCHECK_IS_ON() | 914 #if DCHECK_IS_ON() |
| 871 // Sanity check the above logic. | 915 // Sanity check the above logic. |
| 872 if (image_data->upload.image()) { | 916 if (image_data->upload.image()) { |
| 873 DCHECK(image_data->is_at_raster || image_data->upload.budgeted); | 917 DCHECK(image_data->is_at_raster || image_data->upload.budgeted); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1231 EnsureCapacity(0); | 1275 EnsureCapacity(0); |
| 1232 break; | 1276 break; |
| 1233 } | 1277 } |
| 1234 case base::MemoryState::UNKNOWN: | 1278 case base::MemoryState::UNKNOWN: |
| 1235 // NOT_REACHED. | 1279 // NOT_REACHED. |
| 1236 break; | 1280 break; |
| 1237 } | 1281 } |
| 1238 } | 1282 } |
| 1239 | 1283 |
| 1240 } // namespace cc | 1284 } // namespace cc |
| OLD | NEW |