| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/raster_worker_pool.h" | 5 #include "cc/resources/raster_worker_pool.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event_synthetic_delay.h" | 7 #include "base/debug/trace_event_synthetic_delay.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "cc/debug/devtools_instrumentation.h" | 12 #include "cc/debug/devtools_instrumentation.h" |
| 13 #include "cc/debug/traced_value.h" | 13 #include "cc/debug/traced_value.h" |
| 14 #include "cc/resources/picture_pile_impl.h" | 14 #include "cc/resources/picture_pile_impl.h" |
| 15 #include "cc/resources/resource.h" | 15 #include "cc/resources/resource.h" |
| 16 #include "cc/resources/resource_provider.h" | 16 #include "cc/resources/resource_provider.h" |
| 17 #include "skia/ext/paint_simplifier.h" | 17 #include "skia/ext/paint_simplifier.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "third_party/skia/include/core/SkPixelRef.h" | 19 #include "third_party/skia/include/core/SkPixelRef.h" |
| 20 #include "third_party/skia/include/gpu/GrContext.h" | 20 #include "third_party/skia/include/gpu/GrContext.h" |
| 21 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 21 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
| 22 | 22 |
| 23 namespace cc { | 23 namespace cc { |
| 24 | |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 // Subclass of Allocator that takes a suitably allocated pointer and uses | 26 // Subclass of Allocator that takes a suitably allocated pointer and uses |
| 28 // it as the pixel memory for the bitmap. | 27 // it as the pixel memory for the bitmap. |
| 29 class IdentityAllocator : public SkBitmap::Allocator { | 28 class IdentityAllocator : public SkBitmap::Allocator { |
| 30 public: | 29 public: |
| 31 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} | 30 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} |
| 32 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { | 31 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { |
| 33 dst->setPixels(buffer_); | 32 dst->setPixels(buffer_); |
| 34 return true; | 33 return true; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 skia::RefPtr<GrTexture> texture = | 220 skia::RefPtr<GrTexture> texture = |
| 222 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | 221 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
| 223 skia::RefPtr<SkGpuDevice> device = | 222 skia::RefPtr<SkGpuDevice> device = |
| 224 skia::AdoptRef(SkGpuDevice::Create(texture.get())); | 223 skia::AdoptRef(SkGpuDevice::Create(texture.get())); |
| 225 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(new SkCanvas(device.get())); | 224 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(new SkCanvas(device.get())); |
| 226 | 225 |
| 227 Raster(picture_pile_, canvas.get()); | 226 Raster(picture_pile_, canvas.get()); |
| 228 } | 227 } |
| 229 | 228 |
| 230 protected: | 229 protected: |
| 231 virtual ~RasterWorkerPoolTaskImpl() {} | 230 virtual ~RasterWorkerPoolTaskImpl() { DCHECK(!buffer_); } |
| 232 | 231 |
| 233 private: | 232 private: |
| 234 scoped_ptr<base::Value> DataAsValue() const { | 233 scoped_ptr<base::Value> DataAsValue() const { |
| 235 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 234 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 236 res->Set("tile_id", TracedValue::CreateIDRef(tile_id_).release()); | 235 res->Set("tile_id", TracedValue::CreateIDRef(tile_id_).release()); |
| 237 res->Set("resolution", TileResolutionAsValue(tile_resolution_).release()); | 236 res->Set("resolution", TileResolutionAsValue(tile_resolution_).release()); |
| 238 res->SetInteger("source_frame_number", source_frame_number_); | 237 res->SetInteger("source_frame_number", source_frame_number_); |
| 239 res->SetInteger("layer_id", layer_id_); | 238 res->SetInteger("layer_id", layer_id_); |
| 240 return res.PassAs<base::Value>(); | 239 return res.PassAs<base::Value>(); |
| 241 } | 240 } |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 } | 603 } |
| 605 | 604 |
| 606 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { | 605 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { |
| 607 client_ = client; | 606 client_ = client; |
| 608 } | 607 } |
| 609 | 608 |
| 610 void RasterWorkerPool::Shutdown() { | 609 void RasterWorkerPool::Shutdown() { |
| 611 TRACE_EVENT0("cc", "RasterWorkerPool::Shutdown"); | 610 TRACE_EVENT0("cc", "RasterWorkerPool::Shutdown"); |
| 612 | 611 |
| 613 raster_tasks_.clear(); | 612 raster_tasks_.clear(); |
| 614 TaskGraph empty; | 613 internal::TaskGraph empty; |
| 615 SetTaskGraph(&empty); | 614 SetTaskGraph(&empty); |
| 616 g_task_graph_runner.Pointer()->WaitForTasksToFinishRunning(namespace_token_); | 615 g_task_graph_runner.Pointer()->WaitForTasksToFinishRunning(namespace_token_); |
| 617 weak_ptr_factory_.InvalidateWeakPtrs(); | 616 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 618 } | 617 } |
| 619 | 618 |
| 620 void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) { | 619 void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) { |
| 621 raster_tasks_.swap(queue->tasks_); | 620 raster_tasks_.swap(queue->tasks_); |
| 622 raster_tasks_required_for_activation_.swap( | 621 raster_tasks_required_for_activation_.swap( |
| 623 queue->tasks_required_for_activation_); | 622 queue->tasks_required_for_activation_); |
| 624 } | 623 } |
| 625 | 624 |
| 626 bool RasterWorkerPool::IsRasterTaskRequiredForActivation( | 625 bool RasterWorkerPool::IsRasterTaskRequiredForActivation( |
| 627 internal::RasterWorkerPoolTask* task) const { | 626 internal::RasterWorkerPoolTask* task) const { |
| 628 return raster_tasks_required_for_activation_.find(task) != | 627 return raster_tasks_required_for_activation_.find(task) != |
| 629 raster_tasks_required_for_activation_.end(); | 628 raster_tasks_required_for_activation_.end(); |
| 630 } | 629 } |
| 631 | 630 |
| 632 void RasterWorkerPool::SetTaskGraph(TaskGraph* graph) { | 631 void RasterWorkerPool::SetTaskGraph(internal::TaskGraph* graph) { |
| 633 TRACE_EVENT1( | 632 TRACE_EVENT0("cc", "RasterWorkerPool::SetTaskGraph"); |
| 634 "cc", "RasterWorkerPool::SetTaskGraph", "num_tasks", graph->size()); | |
| 635 | 633 |
| 636 for (internal::GraphNode::Map::iterator it = graph->begin(); | 634 for (internal::TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); |
| 637 it != graph->end(); | 635 it != graph->nodes.end(); |
| 638 ++it) { | 636 ++it) { |
| 637 internal::TaskGraph::Node& node = *it; |
| 639 internal::WorkerPoolTask* task = | 638 internal::WorkerPoolTask* task = |
| 640 static_cast<internal::WorkerPoolTask*>(it->first); | 639 static_cast<internal::WorkerPoolTask*>(node.task); |
| 641 | 640 |
| 642 if (!task->HasBeenScheduled()) { | 641 if (!task->HasBeenScheduled()) { |
| 643 task->WillSchedule(); | 642 task->WillSchedule(); |
| 644 task->ScheduleOnOriginThread(this); | 643 task->ScheduleOnOriginThread(this); |
| 645 task->DidSchedule(); | 644 task->DidSchedule(); |
| 646 } | 645 } |
| 647 } | 646 } |
| 648 | 647 |
| 649 g_task_graph_runner.Pointer()->SetTaskGraph(namespace_token_, graph); | 648 g_task_graph_runner.Pointer()->SetTaskGraph(namespace_token_, graph); |
| 650 } | 649 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 | 740 |
| 742 scoped_ptr<base::Value> RasterWorkerPool::ScheduledStateAsValue() const { | 741 scoped_ptr<base::Value> RasterWorkerPool::ScheduledStateAsValue() const { |
| 743 scoped_ptr<base::DictionaryValue> scheduled_state(new base::DictionaryValue); | 742 scoped_ptr<base::DictionaryValue> scheduled_state(new base::DictionaryValue); |
| 744 scheduled_state->SetInteger("task_count", raster_tasks_.size()); | 743 scheduled_state->SetInteger("task_count", raster_tasks_.size()); |
| 745 scheduled_state->SetInteger("task_required_for_activation_count", | 744 scheduled_state->SetInteger("task_required_for_activation_count", |
| 746 raster_tasks_required_for_activation_.size()); | 745 raster_tasks_required_for_activation_.size()); |
| 747 return scheduled_state.PassAs<base::Value>(); | 746 return scheduled_state.PassAs<base::Value>(); |
| 748 } | 747 } |
| 749 | 748 |
| 750 // static | 749 // static |
| 751 internal::GraphNode* RasterWorkerPool::CreateGraphNodeForTask( | 750 void RasterWorkerPool::InsertNodeForTask(internal::TaskGraph* graph, |
| 752 internal::WorkerPoolTask* task, | 751 internal::WorkerPoolTask* task, |
| 753 unsigned priority, | 752 unsigned priority, |
| 754 TaskGraph* graph) { | 753 size_t dependencies) { |
| 755 internal::GraphNode* node = new internal::GraphNode(task, priority); | 754 DCHECK(std::find_if(graph->nodes.begin(), |
| 756 DCHECK(graph->find(task) == graph->end()); | 755 graph->nodes.end(), |
| 757 graph->set(task, make_scoped_ptr(node)); | 756 internal::TaskGraph::Node::TaskComparator(task)) == |
| 758 return node; | 757 graph->nodes.end()); |
| 758 graph->nodes.push_back( |
| 759 internal::TaskGraph::Node(task, priority, dependencies)); |
| 759 } | 760 } |
| 760 | 761 |
| 761 // static | 762 // static |
| 762 internal::GraphNode* RasterWorkerPool::CreateGraphNodeForRasterTask( | 763 void RasterWorkerPool::InsertNodeForRasterTask( |
| 764 internal::TaskGraph* graph, |
| 763 internal::WorkerPoolTask* raster_task, | 765 internal::WorkerPoolTask* raster_task, |
| 764 const internal::Task::Vector& decode_tasks, | 766 const internal::Task::Vector& decode_tasks, |
| 765 unsigned priority, | 767 unsigned priority) { |
| 766 TaskGraph* graph) { | 768 size_t dependencies = 0u; |
| 767 internal::GraphNode* raster_node = | |
| 768 CreateGraphNodeForTask(raster_task, priority, graph); | |
| 769 | 769 |
| 770 // Insert image decode tasks. | 770 // Insert image decode tasks. |
| 771 for (internal::Task::Vector::const_iterator it = decode_tasks.begin(); | 771 for (internal::Task::Vector::const_iterator it = decode_tasks.begin(); |
| 772 it != decode_tasks.end(); | 772 it != decode_tasks.end(); |
| 773 ++it) { | 773 ++it) { |
| 774 internal::WorkerPoolTask* decode_task = | 774 internal::WorkerPoolTask* decode_task = |
| 775 static_cast<internal::WorkerPoolTask*>(it->get()); | 775 static_cast<internal::WorkerPoolTask*>(it->get()); |
| 776 | 776 |
| 777 // Skip if already decoded. | 777 // Skip if already decoded. |
| 778 if (decode_task->HasCompleted()) | 778 if (decode_task->HasCompleted()) |
| 779 continue; | 779 continue; |
| 780 | 780 |
| 781 raster_node->add_dependency(); | 781 dependencies++; |
| 782 | 782 |
| 783 // Check if decode task already exists in graph. | 783 // Add decode task if it doesn't already exists in graph. |
| 784 internal::GraphNode::Map::iterator decode_it = graph->find(decode_task); | 784 internal::TaskGraph::Node::Vector::iterator decode_it = |
| 785 if (decode_it != graph->end()) { | 785 std::find_if(graph->nodes.begin(), |
| 786 internal::GraphNode* decode_node = decode_it->second; | 786 graph->nodes.end(), |
| 787 decode_node->add_dependent(raster_node); | 787 internal::TaskGraph::Node::TaskComparator(decode_task)); |
| 788 continue; | 788 if (decode_it == graph->nodes.end()) |
| 789 } | 789 InsertNodeForTask(graph, decode_task, priority, 0u); |
| 790 | 790 |
| 791 internal::GraphNode* decode_node = | 791 graph->edges.push_back(internal::TaskGraph::Edge(decode_task, raster_task)); |
| 792 CreateGraphNodeForTask(decode_task, priority, graph); | |
| 793 decode_node->add_dependent(raster_node); | |
| 794 } | 792 } |
| 795 | 793 |
| 796 return raster_node; | 794 InsertNodeForTask(graph, raster_task, priority, dependencies); |
| 797 } | 795 } |
| 798 | 796 |
| 799 } // namespace cc | 797 } // namespace cc |
| OLD | NEW |