| 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/raster_worker_pool.h" | 5 #include "cc/raster_worker_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 SkBitmap bitmap; | 33 SkBitmap bitmap; |
| 34 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 34 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
| 35 bitmap.setPixels(buffer); | 35 bitmap.setPixels(buffer); |
| 36 SkDevice device(bitmap); | 36 SkDevice device(bitmap); |
| 37 SkCanvas canvas(&device); | 37 SkCanvas canvas(&device); |
| 38 picture_pile->Raster(&canvas, rect, contents_scale, stats); | 38 picture_pile->Raster(&canvas, rect, contents_scale, stats); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, RenderingStats* stats) { | 41 void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, RenderingStats* stats) { |
| 42 TRACE_EVENT0("cc", "RunImageDecodeTask"); | 42 TRACE_EVENT0("cc", "RunImageDecodeTask"); |
| 43 base::TimeTicks decode_begin_time = base::TimeTicks::Now(); | 43 base::TimeTicks decode_begin_time; |
| 44 if (stats) |
| 45 decode_begin_time = base::TimeTicks::Now(); |
| 46 |
| 44 pixel_ref->Decode(); | 47 pixel_ref->Decode(); |
| 45 stats->totalDeferredImageDecodeCount++; | 48 |
| 46 stats->totalDeferredImageDecodeTime += | 49 if (stats) { |
| 47 base::TimeTicks::Now() - decode_begin_time; | 50 stats->totalDeferredImageDecodeCount++; |
| 51 stats->totalDeferredImageDecodeTime += |
| 52 base::TimeTicks::Now() - decode_begin_time; |
| 53 } |
| 48 } | 54 } |
| 49 | 55 |
| 50 const char* kRasterThreadNamePrefix = "CompositorRaster"; | 56 const char* kRasterThreadNamePrefix = "CompositorRaster"; |
| 51 | 57 |
| 52 // Allow two pending raster tasks per thread. This keeps resource usage | 58 // Allow two pending raster tasks per thread. This keeps resource usage |
| 53 // low while making sure raster threads aren't unnecessarily idle. | 59 // low while making sure raster threads aren't unnecessarily idle. |
| 54 const int kNumPendingRasterTasksPerThread = 2; | 60 const int kNumPendingRasterTasksPerThread = 2; |
| 55 | 61 |
| 56 } // namespace | 62 } // namespace |
| 57 | 63 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 83 } | 89 } |
| 84 | 90 |
| 85 void RasterWorkerPool::Thread::Init() { | 91 void RasterWorkerPool::Thread::Init() { |
| 86 #if defined(OS_ANDROID) | 92 #if defined(OS_ANDROID) |
| 87 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | 93 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 88 int nice_value = 10; // Idle priority. | 94 int nice_value = 10; // Idle priority. |
| 89 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); | 95 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); |
| 90 #endif | 96 #endif |
| 91 } | 97 } |
| 92 | 98 |
| 93 RasterWorkerPool::RasterWorkerPool(size_t num_raster_threads) | 99 RasterWorkerPool::RasterWorkerPool( |
| 100 size_t num_raster_threads, bool record_rendering_stats) |
| 94 : is_running_(false), | 101 : is_running_(false), |
| 95 raster_threads_need_sorting_(false) { | 102 raster_threads_need_sorting_(false), |
| 103 record_rendering_stats_(record_rendering_stats) { |
| 96 const std::string thread_name_prefix = kRasterThreadNamePrefix; | 104 const std::string thread_name_prefix = kRasterThreadNamePrefix; |
| 97 while (raster_threads_.size() < num_raster_threads) { | 105 while (raster_threads_.size() < num_raster_threads) { |
| 98 int thread_number = raster_threads_.size() + 1; | 106 int thread_number = raster_threads_.size() + 1; |
| 99 raster_threads_.push_back( | 107 raster_threads_.push_back( |
| 100 new Thread(thread_name_prefix + | 108 new Thread(thread_name_prefix + |
| 101 StringPrintf("Worker%d", thread_number).c_str())); | 109 StringPrintf("Worker%d", thread_number).c_str())); |
| 102 } | 110 } |
| 103 } | 111 } |
| 104 | 112 |
| 105 RasterWorkerPool::~RasterWorkerPool() { | 113 RasterWorkerPool::~RasterWorkerPool() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 scoped_refptr<PicturePileImpl> picture_pile_clone = | 159 scoped_refptr<PicturePileImpl> picture_pile_clone = |
| 152 picture_pile->GetCloneForDrawingOnThread(task->thread_); | 160 picture_pile->GetCloneForDrawingOnThread(task->thread_); |
| 153 | 161 |
| 154 task->thread_->message_loop_proxy()->PostTaskAndReply( | 162 task->thread_->message_loop_proxy()->PostTaskAndReply( |
| 155 FROM_HERE, | 163 FROM_HERE, |
| 156 base::Bind(&RunRasterTask, | 164 base::Bind(&RunRasterTask, |
| 157 base::Unretained(picture_pile_clone.get()), | 165 base::Unretained(picture_pile_clone.get()), |
| 158 buffer, | 166 buffer, |
| 159 rect, | 167 rect, |
| 160 contents_scale, | 168 contents_scale, |
| 161 &task->rendering_stats_), | 169 record_rendering_stats_ ? &task->rendering_stats_ : NULL), |
| 162 base::Bind(&RasterWorkerPool::OnRasterTaskCompleted, | 170 base::Bind(&RasterWorkerPool::OnRasterTaskCompleted, |
| 163 base::Unretained(this), | 171 base::Unretained(this), |
| 164 base::Unretained(task), | 172 base::Unretained(task), |
| 165 picture_pile_clone, | 173 picture_pile_clone, |
| 166 reply)); | 174 reply)); |
| 167 } | 175 } |
| 168 | 176 |
| 169 void RasterWorkerPool::PostImageDecodeTaskAndReply( | 177 void RasterWorkerPool::PostImageDecodeTaskAndReply( |
| 170 skia::LazyPixelRef* pixel_ref, | 178 skia::LazyPixelRef* pixel_ref, |
| 171 const base::Closure& reply) { | 179 const base::Closure& reply) { |
| 172 CHECK(is_running_); | 180 CHECK(is_running_); |
| 173 Thread::Task* task = CreateTask(); | 181 Thread::Task* task = CreateTask(); |
| 174 | 182 |
| 175 task->thread_->message_loop_proxy()->PostTaskAndReply( | 183 task->thread_->message_loop_proxy()->PostTaskAndReply( |
| 176 FROM_HERE, | 184 FROM_HERE, |
| 177 base::Bind(&RunImageDecodeTask, pixel_ref, &task->rendering_stats_), | 185 base::Bind(&RunImageDecodeTask, pixel_ref, |
| 186 record_rendering_stats_ ? &task->rendering_stats_ : NULL), |
| 178 base::Bind(&RasterWorkerPool::OnTaskCompleted, | 187 base::Bind(&RasterWorkerPool::OnTaskCompleted, |
| 179 base::Unretained(this), | 188 base::Unretained(this), |
| 180 base::Unretained(task), | 189 base::Unretained(task), |
| 181 reply)); | 190 reply)); |
| 182 } | 191 } |
| 183 | 192 |
| 184 void RasterWorkerPool::GetRenderingStats(RenderingStats* stats) { | 193 void RasterWorkerPool::GetRenderingStats(RenderingStats* stats) { |
| 194 DCHECK(record_rendering_stats_); |
| 185 stats->totalRasterizeTime = base::TimeDelta(); | 195 stats->totalRasterizeTime = base::TimeDelta(); |
| 186 stats->totalPixelsRasterized = 0; | 196 stats->totalPixelsRasterized = 0; |
| 187 stats->totalDeferredImageDecodeCount = 0; | 197 stats->totalDeferredImageDecodeCount = 0; |
| 188 stats->totalDeferredImageDecodeTime = base::TimeDelta(); | 198 stats->totalDeferredImageDecodeTime = base::TimeDelta(); |
| 189 for (ThreadVector::iterator it = raster_threads_.begin(); | 199 for (ThreadVector::iterator it = raster_threads_.begin(); |
| 190 it != raster_threads_.end(); ++it) { | 200 it != raster_threads_.end(); ++it) { |
| 191 Thread* thread = *it; | 201 Thread* thread = *it; |
| 192 stats->totalRasterizeTime += | 202 stats->totalRasterizeTime += |
| 193 thread->rendering_stats().totalRasterizeTime; | 203 thread->rendering_stats().totalRasterizeTime; |
| 194 stats->totalPixelsRasterized += | 204 stats->totalPixelsRasterized += |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 void RasterWorkerPool::SortRasterThreadsIfNeeded() { | 240 void RasterWorkerPool::SortRasterThreadsIfNeeded() { |
| 231 if (!raster_threads_need_sorting_) | 241 if (!raster_threads_need_sorting_) |
| 232 return; | 242 return; |
| 233 | 243 |
| 234 std::sort(raster_threads_.begin(), raster_threads_.end(), | 244 std::sort(raster_threads_.begin(), raster_threads_.end(), |
| 235 PendingTaskComparator()); | 245 PendingTaskComparator()); |
| 236 raster_threads_need_sorting_ = false; | 246 raster_threads_need_sorting_ = false; |
| 237 } | 247 } |
| 238 | 248 |
| 239 } // namespace cc | 249 } // namespace cc |
| OLD | NEW |