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 "cc/debug/traced_value.h" | 12 #include "cc/debug/traced_value.h" |
13 #include "cc/resources/raster_buffer.h" | |
13 #include "cc/resources/resource.h" | 14 #include "cc/resources/resource.h" |
14 #include "gpu/command_buffer/client/gles2_interface.h" | 15 #include "gpu/command_buffer/client/gles2_interface.h" |
16 #include "third_party/skia/include/utils/SkNullCanvas.h" | |
15 | 17 |
16 namespace cc { | 18 namespace cc { |
17 namespace { | 19 namespace { |
18 | 20 |
21 class RasterBufferImpl : public RasterBuffer { | |
22 public: | |
23 RasterBufferImpl(ResourceProvider* resource_provider, | |
24 const Resource* resource) | |
25 : resource_provider_(resource_provider), | |
26 resource_(resource), | |
27 buffer_(NULL), | |
28 stride_(0) { | |
29 resource_provider_->AcquirePixelBuffer(resource_->id()); | |
30 buffer_ = resource_provider_->MapPixelBuffer(resource_->id(), &stride_); | |
31 } | |
32 | |
33 virtual ~RasterBufferImpl() { | |
34 resource_provider_->ReleasePixelBuffer(resource_->id()); | |
35 } | |
36 | |
37 // Overridden from RasterBuffer: | |
38 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE { | |
39 if (!buffer_) | |
40 return skia::AdoptRef(SkCreateNullCanvas()); | |
41 | |
42 RasterWorkerPool::AcquireBitmapForBuffer( | |
43 &bitmap_, buffer_, resource_->format(), resource_->size(), stride_); | |
44 return skia::AdoptRef(new SkCanvas(bitmap_)); | |
45 } | |
46 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE { | |
47 if (!buffer_) | |
48 return; | |
49 | |
50 RasterWorkerPool::ReleaseBitmapForBuffer( | |
51 &bitmap_, buffer_, resource_->format()); | |
52 } | |
53 | |
54 private: | |
55 ResourceProvider* resource_provider_; | |
56 const Resource* resource_; | |
57 uint8_t* buffer_; | |
58 int stride_; | |
59 SkBitmap bitmap_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | |
62 }; | |
63 | |
19 const int kCheckForCompletedRasterTasksDelayMs = 6; | 64 const int kCheckForCompletedRasterTasksDelayMs = 6; |
20 | 65 |
21 const size_t kMaxScheduledRasterTasks = 48; | 66 const size_t kMaxScheduledRasterTasks = 48; |
22 | 67 |
23 typedef base::StackVector<RasterTask*, kMaxScheduledRasterTasks> | 68 typedef base::StackVector<RasterTask*, kMaxScheduledRasterTasks> |
24 RasterTaskVector; | 69 RasterTaskVector; |
25 | 70 |
26 } // namespace | 71 } // namespace |
27 | 72 |
28 // static | 73 // static |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type); | 293 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type); |
249 | 294 |
250 std::swap(*state_it, raster_task_states_.back()); | 295 std::swap(*state_it, raster_task_states_.back()); |
251 raster_task_states_.pop_back(); | 296 raster_task_states_.pop_back(); |
252 | 297 |
253 task->RunReplyOnOriginThread(); | 298 task->RunReplyOnOriginThread(); |
254 } | 299 } |
255 completed_raster_tasks_.clear(); | 300 completed_raster_tasks_.clear(); |
256 } | 301 } |
257 | 302 |
258 RasterBuffer* PixelBufferRasterWorkerPool::AcquireBufferForRaster( | 303 scoped_ptr<RasterBuffer> PixelBufferRasterWorkerPool::AcquireBufferForRaster( |
259 RasterTask* task) { | 304 const Resource* resource) { |
260 DCHECK(std::find_if(raster_task_states_.begin(), | 305 return make_scoped_ptr<RasterBuffer>( |
261 raster_task_states_.end(), | 306 new RasterBufferImpl(resource_provider_, resource)); |
262 RasterTaskState::TaskComparator(task)) != | |
263 raster_task_states_.end()); | |
264 return resource_provider_->AcquirePixelRasterBuffer(task->resource()->id()); | |
265 } | 307 } |
266 | 308 |
267 void PixelBufferRasterWorkerPool::ReleaseBufferForRaster(RasterTask* task) { | 309 void PixelBufferRasterWorkerPool::ReleaseBufferForRaster( |
268 DCHECK(std::find_if(raster_task_states_.begin(), | 310 scoped_ptr<RasterBuffer> buffer) { |
269 raster_task_states_.end(), | 311 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
270 RasterTaskState::TaskComparator(task)) != | |
271 raster_task_states_.end()); | |
272 resource_provider_->ReleasePixelRasterBuffer(task->resource()->id()); | |
273 } | 312 } |
274 | 313 |
275 void PixelBufferRasterWorkerPool::OnRasterFinished() { | 314 void PixelBufferRasterWorkerPool::OnRasterFinished() { |
276 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::OnRasterFinished"); | 315 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::OnRasterFinished"); |
277 | 316 |
278 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as | 317 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as |
279 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to | 318 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to |
280 // perform another check in that case as we've already notified the client. | 319 // perform another check in that case as we've already notified the client. |
281 if (!should_notify_client_if_no_tasks_are_pending_) | 320 if (!should_notify_client_if_no_tasks_are_pending_) |
282 return; | 321 return; |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 | 711 |
673 RasterTaskState::Vector::iterator state_it = | 712 RasterTaskState::Vector::iterator state_it = |
674 std::find_if(raster_task_states_.begin(), | 713 std::find_if(raster_task_states_.begin(), |
675 raster_task_states_.end(), | 714 raster_task_states_.end(), |
676 RasterTaskState::TaskComparator(raster_task)); | 715 RasterTaskState::TaskComparator(raster_task)); |
677 DCHECK(state_it != raster_task_states_.end()); | 716 DCHECK(state_it != raster_task_states_.end()); |
678 | 717 |
679 RasterTaskState& state = *state_it; | 718 RasterTaskState& state = *state_it; |
680 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); | 719 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); |
681 | 720 |
721 resource_provider_->UnmapPixelBuffer(raster_task->resource()->id()); | |
vmpstr
2014/09/16 22:15:55
Can you explain why this is now needed?
reveman
2014/09/17 14:40:56
It was done automatically by ResourceProvider::Beg
| |
722 | |
682 if (!raster_task->HasFinishedRunning()) { | 723 if (!raster_task->HasFinishedRunning()) { |
683 // When priorites change, a raster task can be canceled as a result of | 724 // When priorites change, a raster task can be canceled as a result of |
684 // no longer being of high enough priority to fit in our throttled | 725 // no longer being of high enough priority to fit in our throttled |
685 // raster task budget. The task has not yet completed in this case. | 726 // raster task budget. The task has not yet completed in this case. |
686 raster_task->WillComplete(); | 727 raster_task->WillComplete(); |
687 raster_task->CompleteOnOriginThread(this); | 728 raster_task->CompleteOnOriginThread(this); |
688 raster_task->DidComplete(); | 729 raster_task->DidComplete(); |
689 | 730 |
690 RasterTaskQueue::Item::Vector::const_iterator item_it = | 731 RasterTaskQueue::Item::Vector::const_iterator item_it = |
691 std::find_if(raster_tasks_.items.begin(), | 732 std::find_if(raster_tasks_.items.begin(), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto( | 778 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto( |
738 base::debug::TracedValue* throttle_state) const { | 779 base::debug::TracedValue* throttle_state) const { |
739 throttle_state->SetInteger("bytes_available_for_upload", | 780 throttle_state->SetInteger("bytes_available_for_upload", |
740 max_bytes_pending_upload_ - bytes_pending_upload_); | 781 max_bytes_pending_upload_ - bytes_pending_upload_); |
741 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 782 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
742 throttle_state->SetInteger("scheduled_raster_task_count", | 783 throttle_state->SetInteger("scheduled_raster_task_count", |
743 scheduled_raster_task_count_); | 784 scheduled_raster_task_count_); |
744 } | 785 } |
745 | 786 |
746 } // namespace cc | 787 } // namespace cc |
OLD | NEW |