Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: cc/tiles/gpu_image_decode_cache.cc

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

Powered by Google App Engine
This is Rietveld 408576698