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/pixel_buffer_raster_worker_pool.h" | 5 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/containers/stack_container.h" | 9 #include "base/containers/stack_container.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/debug/trace_event_argument.h" | 11 #include "base/debug/trace_event_argument.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "cc/debug/traced_value.h" | 13 #include "cc/debug/traced_value.h" |
| 14 #include "cc/resources/raster_buffer.h" |
14 #include "cc/resources/resource.h" | 15 #include "cc/resources/resource.h" |
15 #include "gpu/command_buffer/client/gles2_interface.h" | 16 #include "gpu/command_buffer/client/gles2_interface.h" |
| 17 #include "third_party/skia/include/utils/SkNullCanvas.h" |
16 | 18 |
17 namespace cc { | 19 namespace cc { |
18 namespace { | 20 namespace { |
19 | 21 |
| 22 class RasterBufferImpl : public RasterBuffer { |
| 23 public: |
| 24 RasterBufferImpl(ResourceProvider* resource_provider, |
| 25 const Resource* resource) |
| 26 : resource_provider_(resource_provider), |
| 27 resource_(resource), |
| 28 buffer_(NULL), |
| 29 stride_(0) { |
| 30 resource_provider_->AcquirePixelBuffer(resource_->id()); |
| 31 buffer_ = resource_provider_->MapPixelBuffer(resource_->id(), &stride_); |
| 32 } |
| 33 |
| 34 virtual ~RasterBufferImpl() { |
| 35 resource_provider_->ReleasePixelBuffer(resource_->id()); |
| 36 } |
| 37 |
| 38 // Overridden from RasterBuffer: |
| 39 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE { |
| 40 if (!buffer_) |
| 41 return skia::AdoptRef(SkCreateNullCanvas()); |
| 42 |
| 43 RasterWorkerPool::AcquireBitmapForBuffer( |
| 44 &bitmap_, buffer_, resource_->format(), resource_->size(), stride_); |
| 45 return skia::AdoptRef(new SkCanvas(bitmap_)); |
| 46 } |
| 47 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE { |
| 48 if (!buffer_) |
| 49 return; |
| 50 |
| 51 RasterWorkerPool::ReleaseBitmapForBuffer( |
| 52 &bitmap_, buffer_, resource_->format()); |
| 53 } |
| 54 |
| 55 private: |
| 56 ResourceProvider* resource_provider_; |
| 57 const Resource* resource_; |
| 58 uint8_t* buffer_; |
| 59 int stride_; |
| 60 SkBitmap bitmap_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| 63 }; |
| 64 |
20 const int kCheckForCompletedRasterTasksDelayMs = 6; | 65 const int kCheckForCompletedRasterTasksDelayMs = 6; |
21 | 66 |
22 const size_t kMaxScheduledRasterTasks = 48; | 67 const size_t kMaxScheduledRasterTasks = 48; |
23 | 68 |
24 typedef base::StackVector<RasterTask*, kMaxScheduledRasterTasks> | 69 typedef base::StackVector<RasterTask*, kMaxScheduledRasterTasks> |
25 RasterTaskVector; | 70 RasterTaskVector; |
26 | 71 |
27 TaskSetCollection NonEmptyTaskSetsFromTaskCounts(const size_t* task_counts) { | 72 TaskSetCollection NonEmptyTaskSetsFromTaskCounts(const size_t* task_counts) { |
28 TaskSetCollection task_sets; | 73 TaskSetCollection task_sets; |
29 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 74 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type); | 316 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type); |
272 | 317 |
273 std::swap(*state_it, raster_task_states_.back()); | 318 std::swap(*state_it, raster_task_states_.back()); |
274 raster_task_states_.pop_back(); | 319 raster_task_states_.pop_back(); |
275 | 320 |
276 task->RunReplyOnOriginThread(); | 321 task->RunReplyOnOriginThread(); |
277 } | 322 } |
278 completed_raster_tasks_.clear(); | 323 completed_raster_tasks_.clear(); |
279 } | 324 } |
280 | 325 |
281 RasterBuffer* PixelBufferRasterWorkerPool::AcquireBufferForRaster( | 326 scoped_ptr<RasterBuffer> PixelBufferRasterWorkerPool::AcquireBufferForRaster( |
282 RasterTask* task) { | 327 const Resource* resource) { |
283 DCHECK(std::find_if(raster_task_states_.begin(), | 328 return make_scoped_ptr<RasterBuffer>( |
284 raster_task_states_.end(), | 329 new RasterBufferImpl(resource_provider_, resource)); |
285 RasterTaskState::TaskComparator(task)) != | |
286 raster_task_states_.end()); | |
287 return resource_provider_->AcquirePixelRasterBuffer(task->resource()->id()); | |
288 } | 330 } |
289 | 331 |
290 void PixelBufferRasterWorkerPool::ReleaseBufferForRaster(RasterTask* task) { | 332 void PixelBufferRasterWorkerPool::ReleaseBufferForRaster( |
291 DCHECK(std::find_if(raster_task_states_.begin(), | 333 scoped_ptr<RasterBuffer> buffer) { |
292 raster_task_states_.end(), | 334 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
293 RasterTaskState::TaskComparator(task)) != | |
294 raster_task_states_.end()); | |
295 resource_provider_->ReleasePixelRasterBuffer(task->resource()->id()); | |
296 } | 335 } |
297 | 336 |
298 void PixelBufferRasterWorkerPool::OnRasterFinished(TaskSet task_set) { | 337 void PixelBufferRasterWorkerPool::OnRasterFinished(TaskSet task_set) { |
299 TRACE_EVENT2("cc", | 338 TRACE_EVENT2("cc", |
300 "PixelBufferRasterWorkerPool::OnRasterFinished", | 339 "PixelBufferRasterWorkerPool::OnRasterFinished", |
301 "task_set", | 340 "task_set", |
302 task_set, | 341 task_set, |
303 "should_notify_client_if_no_tasks_are_pending", | 342 "should_notify_client_if_no_tasks_are_pending", |
304 should_notify_client_if_no_tasks_are_pending_[task_set]); | 343 should_notify_client_if_no_tasks_are_pending_[task_set]); |
305 | 344 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 | 684 |
646 RasterTaskState::Vector::iterator state_it = | 685 RasterTaskState::Vector::iterator state_it = |
647 std::find_if(raster_task_states_.begin(), | 686 std::find_if(raster_task_states_.begin(), |
648 raster_task_states_.end(), | 687 raster_task_states_.end(), |
649 RasterTaskState::TaskComparator(raster_task)); | 688 RasterTaskState::TaskComparator(raster_task)); |
650 DCHECK(state_it != raster_task_states_.end()); | 689 DCHECK(state_it != raster_task_states_.end()); |
651 | 690 |
652 RasterTaskState& state = *state_it; | 691 RasterTaskState& state = *state_it; |
653 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); | 692 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); |
654 | 693 |
| 694 resource_provider_->UnmapPixelBuffer(raster_task->resource()->id()); |
| 695 |
655 if (!raster_task->HasFinishedRunning()) { | 696 if (!raster_task->HasFinishedRunning()) { |
656 // When priorites change, a raster task can be canceled as a result of | 697 // When priorites change, a raster task can be canceled as a result of |
657 // no longer being of high enough priority to fit in our throttled | 698 // no longer being of high enough priority to fit in our throttled |
658 // raster task budget. The task has not yet completed in this case. | 699 // raster task budget. The task has not yet completed in this case. |
659 raster_task->WillComplete(); | 700 raster_task->WillComplete(); |
660 raster_task->CompleteOnOriginThread(this); | 701 raster_task->CompleteOnOriginThread(this); |
661 raster_task->DidComplete(); | 702 raster_task->DidComplete(); |
662 | 703 |
663 RasterTaskQueue::Item::Vector::const_iterator item_it = | 704 RasterTaskQueue::Item::Vector::const_iterator item_it = |
664 std::find_if(raster_tasks_.items.begin(), | 705 std::find_if(raster_tasks_.items.begin(), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto( | 752 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto( |
712 base::debug::TracedValue* throttle_state) const { | 753 base::debug::TracedValue* throttle_state) const { |
713 throttle_state->SetInteger("bytes_available_for_upload", | 754 throttle_state->SetInteger("bytes_available_for_upload", |
714 max_bytes_pending_upload_ - bytes_pending_upload_); | 755 max_bytes_pending_upload_ - bytes_pending_upload_); |
715 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 756 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
716 throttle_state->SetInteger("scheduled_raster_task_count", | 757 throttle_state->SetInteger("scheduled_raster_task_count", |
717 scheduled_raster_task_count_); | 758 scheduled_raster_task_count_); |
718 } | 759 } |
719 | 760 |
720 } // namespace cc | 761 } // namespace cc |
OLD | NEW |