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

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

Issue 1890903002: cc: Simplify Task and its derived classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_tile_task_runner
Patch Set: nits Created 4 years, 8 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
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_controller.h" 5 #include "cc/tiles/gpu_image_decode_controller.h"
6 6
7 #include "base/memory/discardable_memory_allocator.h" 7 #include "base/memory/discardable_memory_allocator.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/numerics/safe_math.h" 9 #include "base/numerics/safe_math.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "cc/debug/devtools_instrumentation.h" 12 #include "cc/debug/devtools_instrumentation.h"
13 #include "cc/output/context_provider.h" 13 #include "cc/output/context_provider.h"
14 #include "cc/raster/tile_task_runner.h" 14 #include "cc/raster/task.h"
15 #include "gpu/command_buffer/client/context_support.h" 15 #include "gpu/command_buffer/client/context_support.h"
16 #include "gpu/command_buffer/client/gles2_interface.h" 16 #include "gpu/command_buffer/client/gles2_interface.h"
17 #include "gpu_image_decode_controller.h" 17 #include "gpu_image_decode_controller.h"
18 #include "skia/ext/refptr.h" 18 #include "skia/ext/refptr.h"
19 #include "skia/ext/texture_handle.h" 19 #include "skia/ext/texture_handle.h"
20 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
21 #include "third_party/skia/include/core/SkSurface.h" 21 #include "third_party/skia/include/core/SkSurface.h"
22 #include "third_party/skia/include/gpu/GrContext.h" 22 #include "third_party/skia/include/gpu/GrContext.h"
23 #include "third_party/skia/include/gpu/GrTexture.h" 23 #include "third_party/skia/include/gpu/GrTexture.h"
24 #include "ui/gfx/skia_util.h" 24 #include "ui/gfx/skia_util.h"
(...skipping 25 matching lines...) Expand all
50 params.fMatrix = draw_image.matrix(); 50 params.fMatrix = draw_image.matrix();
51 params.fQuality = draw_image.filter_quality(); 51 params.fQuality = draw_image.filter_quality();
52 52
53 return params; 53 return params;
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 // Task which decodes an image and stores the result in discardable memory. 58 // Task which decodes an image and stores the result in discardable memory.
59 // This task does not use GPU resources and can be run on any thread. 59 // This task does not use GPU resources and can be run on any thread.
60 class ImageDecodeTaskImpl : public ImageDecodeTask { 60 class ImageDecodeTaskImpl : public Task {
61 public: 61 public:
62 ImageDecodeTaskImpl(GpuImageDecodeController* controller, 62 ImageDecodeTaskImpl(GpuImageDecodeController* controller,
63 const DrawImage& draw_image, 63 const DrawImage& draw_image,
64 uint64_t source_prepare_tiles_id) 64 uint64_t source_prepare_tiles_id)
65 : controller_(controller), 65 : controller_(controller),
66 image_(draw_image), 66 image_(draw_image),
67 image_ref_(skia::SharePtr(draw_image.image())), 67 image_ref_(skia::SharePtr(draw_image.image())),
68 source_prepare_tiles_id_(source_prepare_tiles_id) { 68 source_prepare_tiles_id_(source_prepare_tiles_id) {
69 DCHECK(!SkipImage(draw_image)); 69 DCHECK(!SkipImage(draw_image));
70 SetTaskTypeId(TASK_TYPE_IMAGE_DECODE); 70 SetTaskType(TASK_TYPE_IMAGE_DECODE);
71 } 71 }
72 72
73 // Overridden from Task: 73 // Overridden from Task:
74 void RunOnWorkerThread() override { 74 void RunOnWorkerThread() override {
75 TRACE_EVENT2("cc", "ImageDecodeTaskImpl::RunOnWorkerThread", "mode", "gpu", 75 TRACE_EVENT2("cc", "ImageDecodeTaskImpl::RunOnWorkerThread", "mode", "gpu",
76 "source_prepare_tiles_id", source_prepare_tiles_id_); 76 "source_prepare_tiles_id", source_prepare_tiles_id_);
77 controller_->DecodeImage(image_); 77 controller_->DecodeImage(image_);
78 } 78 }
79 79
80 protected: 80 protected:
81 ~ImageDecodeTaskImpl() override {} 81 ~ImageDecodeTaskImpl() override {}
82 82
83 private: 83 private:
84 friend class GpuImageDecodeController; 84 friend class GpuImageDecodeController;
85 85
86 GpuImageDecodeController* controller_; 86 GpuImageDecodeController* controller_;
87 DrawImage image_; 87 DrawImage image_;
88 skia::RefPtr<const SkImage> image_ref_; 88 skia::RefPtr<const SkImage> image_ref_;
89 const uint64_t source_prepare_tiles_id_; 89 const uint64_t source_prepare_tiles_id_;
90 90
91 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); 91 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl);
92 }; 92 };
93 93
94 // Task which creates an image from decoded data. Typically this involves 94 // Task which creates an image from decoded data. Typically this involves
95 // uploading data to the GPU, which requires this task be run on the non- 95 // uploading data to the GPU, which requires this task be run on the non-
96 // concurrent thread. 96 // concurrent thread.
97 class ImageUploadTaskImpl : public ImageDecodeTask { 97 class ImageUploadTaskImpl : public Task {
98 public: 98 public:
99 ImageUploadTaskImpl(GpuImageDecodeController* controller, 99 ImageUploadTaskImpl(GpuImageDecodeController* controller,
100 const DrawImage& draw_image, 100 const DrawImage& draw_image,
101 scoped_refptr<ImageDecodeTask> decode_dependency, 101 scoped_refptr<Task> decode_dependency,
102 uint64_t source_prepare_tiles_id) 102 uint64_t source_prepare_tiles_id)
103 : ImageDecodeTask(std::move(decode_dependency)), 103 : Task(),
104 controller_(controller), 104 controller_(controller),
105 image_(draw_image), 105 image_(draw_image),
106 image_ref_(skia::SharePtr(draw_image.image())), 106 image_ref_(skia::SharePtr(draw_image.image())),
107 source_prepare_tiles_id_(source_prepare_tiles_id) { 107 source_prepare_tiles_id_(source_prepare_tiles_id) {
108 SetTaskTypeId(TASK_TYPE_IMAGE_UPLOAD); 108 dependencies_.push_back(std::move(decode_dependency));
109 SetTaskType(TASK_TYPE_IMAGE_UPLOAD);
109 DCHECK(!SkipImage(draw_image)); 110 DCHECK(!SkipImage(draw_image));
110 } 111 }
111 112
112 // Override from Task: 113 // Override from Task:
114 bool SupportsConcurrentExecution() const override { return false; }
113 void RunOnWorkerThread() override { 115 void RunOnWorkerThread() override {
114 TRACE_EVENT2("cc", "ImageUploadTaskImpl::RunOnWorkerThread", "mode", "gpu", 116 TRACE_EVENT2("cc", "ImageUploadTaskImpl::RunOnWorkerThread", "mode", "gpu",
115 "source_prepare_tiles_id", source_prepare_tiles_id_); 117 "source_prepare_tiles_id", source_prepare_tiles_id_);
116 controller_->UploadImage(image_); 118 controller_->UploadImage(image_);
117 } 119 }
118 120
119 // Override from ImageDecodeTask:
120 bool SupportsConcurrentExecution() const override { return false; }
121
122 protected: 121 protected:
123 ~ImageUploadTaskImpl() override {} 122 ~ImageUploadTaskImpl() override {}
124 123
125 private: 124 private:
126 friend class GpuImageDecodeController; 125 friend class GpuImageDecodeController;
127 126
128 GpuImageDecodeController* controller_; 127 GpuImageDecodeController* controller_;
129 DrawImage image_; 128 DrawImage image_;
130 skia::RefPtr<const SkImage> image_ref_; 129 skia::RefPtr<const SkImage> image_ref_;
131 uint64_t source_prepare_tiles_id_; 130 uint64_t source_prepare_tiles_id_;
(...skipping 30 matching lines...) Expand all
162 161
163 GpuImageDecodeController::~GpuImageDecodeController() { 162 GpuImageDecodeController::~GpuImageDecodeController() {
164 // SetShouldAggressivelyFreeResources will zero our limits and free all 163 // SetShouldAggressivelyFreeResources will zero our limits and free all
165 // outstanding image memory. 164 // outstanding image memory.
166 SetShouldAggressivelyFreeResources(true); 165 SetShouldAggressivelyFreeResources(true);
167 } 166 }
168 167
169 bool GpuImageDecodeController::GetTaskForImageAndRef( 168 bool GpuImageDecodeController::GetTaskForImageAndRef(
170 const DrawImage& draw_image, 169 const DrawImage& draw_image,
171 uint64_t prepare_tiles_id, 170 uint64_t prepare_tiles_id,
172 scoped_refptr<ImageDecodeTask>* task) { 171 scoped_refptr<Task>* task) {
173 if (SkipImage(draw_image)) { 172 if (SkipImage(draw_image)) {
174 *task = nullptr; 173 *task = nullptr;
175 return false; 174 return false;
176 } 175 }
177 176
178 base::AutoLock lock(lock_); 177 base::AutoLock lock(lock_);
179 const auto image_id = draw_image.image()->uniqueID(); 178 const auto image_id = draw_image.image()->uniqueID();
180 179
181 auto found = image_data_.Get(image_id); 180 auto found = image_data_.Get(image_id);
182 if (found != image_data_.end()) { 181 if (found != image_data_.end()) {
183 ImageData* image_data = found->second.get(); 182 ImageData* image_data = found->second.get();
184 if (image_data->is_at_raster) { 183 if (image_data->is_at_raster) {
185 // Image is at-raster, just return, this usage will be at-raster as well. 184 // Image is at-raster, just return, this usage will be at-raster as well.
186 *task = nullptr; 185 *task = nullptr;
187 return false; 186 return false;
188 } 187 }
189 188
190 if (image_data->upload.image) { 189 if (image_data->upload.image) {
191 // The image is already uploaded, ref and return. 190 // The image is already uploaded, ref and return.
192 RefImage(draw_image); 191 RefImage(draw_image);
193 *task = nullptr; 192 *task = nullptr;
194 return true; 193 return true;
195 } 194 }
196 } 195 }
197 196
198 // We didn't have a pre-uploaded image, so we need an upload task. Try to find 197 // We didn't have a pre-uploaded image, so we need an upload task. Try to find
199 // an existing one. 198 // an existing one.
200 scoped_refptr<ImageDecodeTask>& existing_task = 199 scoped_refptr<Task>& existing_task = pending_image_upload_tasks_[image_id];
201 pending_image_upload_tasks_[image_id];
202 if (existing_task) { 200 if (existing_task) {
203 // We had an existing upload task, ref the image and return the task. 201 // We had an existing upload task, ref the image and return the task.
204 RefImage(draw_image); 202 RefImage(draw_image);
205 *task = existing_task; 203 *task = existing_task;
206 return true; 204 return true;
207 } 205 }
208 206
209 // We will be creating a new upload task. If necessary, create a placeholder 207 // We will be creating a new upload task. If necessary, create a placeholder
210 // ImageData to hold the result. 208 // ImageData to hold the result.
211 std::unique_ptr<ImageData> new_data; 209 std::unique_ptr<ImageData> new_data;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 ContextProvider::ScopedContextLock context_lock(context_); 375 ContextProvider::ScopedContextLock context_lock(context_);
378 base::AutoLock lock(lock_); 376 base::AutoLock lock(lock_);
379 auto found = image_data_.Peek(draw_image.image()->uniqueID()); 377 auto found = image_data_.Peek(draw_image.image()->uniqueID());
380 DCHECK(found != image_data_.end()); 378 DCHECK(found != image_data_.end());
381 DCHECK(!found->second->is_at_raster); 379 DCHECK(!found->second->is_at_raster);
382 UploadImageIfNecessary(draw_image, found->second.get()); 380 UploadImageIfNecessary(draw_image, found->second.get());
383 } 381 }
384 382
385 // Checks if an existing image decode exists. If not, returns a task to produce 383 // Checks if an existing image decode exists. If not, returns a task to produce
386 // the requested decode. 384 // the requested decode.
387 scoped_refptr<ImageDecodeTask> 385 scoped_refptr<Task> GpuImageDecodeController::GetImageDecodeTaskAndRef(
388 GpuImageDecodeController::GetImageDecodeTaskAndRef(const DrawImage& draw_image, 386 const DrawImage& draw_image,
389 uint64_t prepare_tiles_id) { 387 uint64_t prepare_tiles_id) {
390 lock_.AssertAcquired(); 388 lock_.AssertAcquired();
391 389
392 const uint32_t image_id = draw_image.image()->uniqueID(); 390 const uint32_t image_id = draw_image.image()->uniqueID();
393 391
394 // This ref is kept alive while an upload task may need this decode. We 392 // This ref is kept alive while an upload task may need this decode. We
395 // release this ref in UploadTaskCompleted. 393 // release this ref in UploadTaskCompleted.
396 RefImageDecode(draw_image); 394 RefImageDecode(draw_image);
397 395
398 auto found = image_data_.Peek(image_id); 396 auto found = image_data_.Peek(image_id);
399 if (found != image_data_.end() && found->second->decode.is_locked) { 397 if (found != image_data_.end() && found->second->decode.is_locked) {
400 // We should never be creating a decode task for an at raster image. 398 // We should never be creating a decode task for an at raster image.
401 DCHECK(!found->second->is_at_raster); 399 DCHECK(!found->second->is_at_raster);
402 // We should never be creating a decode for an already-uploaded image. 400 // We should never be creating a decode for an already-uploaded image.
403 DCHECK(!found->second->upload.image); 401 DCHECK(!found->second->upload.image);
404 return nullptr; 402 return nullptr;
405 } 403 }
406 404
407 // We didn't have an existing locked image, create a task to lock or decode. 405 // We didn't have an existing locked image, create a task to lock or decode.
408 scoped_refptr<ImageDecodeTask>& existing_task = 406 scoped_refptr<Task>& existing_task = pending_image_decode_tasks_[image_id];
409 pending_image_decode_tasks_[image_id];
410 if (!existing_task) { 407 if (!existing_task) {
411 // Ref image decode and create a decode task. This ref will be released in 408 // Ref image decode and create a decode task. This ref will be released in
412 // DecodeTaskCompleted. 409 // DecodeTaskCompleted.
413 RefImageDecode(draw_image); 410 RefImageDecode(draw_image);
414 existing_task = make_scoped_refptr( 411 existing_task = make_scoped_refptr(
415 new ImageDecodeTaskImpl(this, draw_image, prepare_tiles_id)); 412 new ImageDecodeTaskImpl(this, draw_image, prepare_tiles_id));
416 } 413 }
417 return existing_task; 414 return existing_task;
418 } 415 }
419 416
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 } 728 }
732 729
733 SkImageInfo GpuImageDecodeController::CreateImageInfoForDrawImage( 730 SkImageInfo GpuImageDecodeController::CreateImageInfoForDrawImage(
734 const DrawImage& draw_image) const { 731 const DrawImage& draw_image) const {
735 return SkImageInfo::Make( 732 return SkImageInfo::Make(
736 draw_image.image()->width(), draw_image.image()->height(), 733 draw_image.image()->width(), draw_image.image()->height(),
737 ResourceFormatToClosestSkColorType(format_), kPremul_SkAlphaType); 734 ResourceFormatToClosestSkColorType(format_), kPremul_SkAlphaType);
738 } 735 }
739 736
740 } // namespace cc 737 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698