OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/raster/bitmap_tile_task_worker_pool.h" | |
6 | |
7 #include <stddef.h> | |
8 #include <stdint.h> | |
9 | |
10 #include <algorithm> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/memory/ptr_util.h" | |
14 #include "base/strings/stringprintf.h" | |
15 #include "base/trace_event/trace_event.h" | |
16 #include "base/trace_event/trace_event_argument.h" | |
17 #include "cc/debug/traced_value.h" | |
18 #include "cc/playback/raster_source.h" | |
19 #include "cc/resources/platform_color.h" | |
20 #include "cc/resources/resource.h" | |
21 | |
22 namespace cc { | |
23 namespace { | |
24 | |
25 class RasterBufferImpl : public RasterBuffer { | |
26 public: | |
27 RasterBufferImpl(ResourceProvider* resource_provider, | |
28 const Resource* resource, | |
29 uint64_t resource_content_id, | |
30 uint64_t previous_content_id) | |
31 : lock_(resource_provider, resource->id()), | |
32 resource_(resource), | |
33 resource_has_previous_content_( | |
34 resource_content_id && resource_content_id == previous_content_id) { | |
35 } | |
36 | |
37 // Overridden from RasterBuffer: | |
38 void Playback( | |
39 const RasterSource* raster_source, | |
40 const gfx::Rect& raster_full_rect, | |
41 const gfx::Rect& raster_dirty_rect, | |
42 uint64_t new_content_id, | |
43 float scale, | |
44 const RasterSource::PlaybackSettings& playback_settings) override { | |
45 gfx::Rect playback_rect = raster_full_rect; | |
46 if (resource_has_previous_content_) { | |
47 playback_rect.Intersect(raster_dirty_rect); | |
48 } | |
49 DCHECK(!playback_rect.IsEmpty()) | |
50 << "Why are we rastering a tile that's not dirty?"; | |
51 | |
52 size_t stride = 0u; | |
53 TileTaskWorkerPool::PlaybackToMemory( | |
54 lock_.sk_bitmap().getPixels(), resource_->format(), resource_->size(), | |
55 stride, raster_source, raster_full_rect, playback_rect, scale, | |
56 playback_settings); | |
57 } | |
58 | |
59 private: | |
60 ResourceProvider::ScopedWriteLockSoftware lock_; | |
61 const Resource* resource_; | |
62 bool resource_has_previous_content_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | |
65 }; | |
66 | |
67 } // namespace | |
68 | |
69 // static | |
70 std::unique_ptr<TileTaskWorkerPool> BitmapTileTaskWorkerPool::Create( | |
71 base::SequencedTaskRunner* task_runner, | |
72 TaskGraphRunner* task_graph_runner, | |
73 ResourceProvider* resource_provider) { | |
74 return base::WrapUnique<TileTaskWorkerPool>(new BitmapTileTaskWorkerPool( | |
75 task_runner, task_graph_runner, resource_provider)); | |
76 } | |
77 | |
78 BitmapTileTaskWorkerPool::BitmapTileTaskWorkerPool( | |
79 base::SequencedTaskRunner* task_runner, | |
80 TaskGraphRunner* task_graph_runner, | |
81 ResourceProvider* resource_provider) | |
82 : task_runner_(task_runner), | |
83 task_graph_runner_(task_graph_runner), | |
84 namespace_token_(task_graph_runner->GetNamespaceToken()), | |
85 resource_provider_(resource_provider) {} | |
86 | |
87 BitmapTileTaskWorkerPool::~BitmapTileTaskWorkerPool() { | |
88 } | |
89 | |
90 void BitmapTileTaskWorkerPool::Shutdown() { | |
91 TRACE_EVENT0("cc", "BitmapTileTaskWorkerPool::Shutdown"); | |
92 | |
93 TaskGraph empty; | |
94 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); | |
95 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); | |
96 } | |
97 | |
98 void BitmapTileTaskWorkerPool::ScheduleTasks(TaskGraph* graph) { | |
99 TRACE_EVENT0("cc", "BitmapTileTaskWorkerPool::ScheduleTasks"); | |
100 | |
101 ScheduleTasksOnOriginThread(this, graph); | |
102 task_graph_runner_->ScheduleTasks(namespace_token_, graph); | |
103 } | |
104 | |
105 void BitmapTileTaskWorkerPool::CheckForCompletedTasks() { | |
106 TRACE_EVENT0("cc", "BitmapTileTaskWorkerPool::CheckForCompletedTasks"); | |
107 | |
108 task_graph_runner_->CollectCompletedTasks(namespace_token_, | |
109 &completed_tasks_); | |
110 for (Task::Vector::const_iterator it = completed_tasks_.begin(); | |
111 it != completed_tasks_.end(); ++it) { | |
112 TileTask* task = static_cast<TileTask*>(it->get()); | |
113 | |
114 task->WillComplete(); | |
115 task->CompleteOnOriginThread(this); | |
116 task->DidComplete(); | |
117 } | |
118 completed_tasks_.clear(); | |
119 } | |
120 | |
121 ResourceFormat BitmapTileTaskWorkerPool::GetResourceFormat( | |
122 bool must_support_alpha) const { | |
123 return resource_provider_->best_texture_format(); | |
124 } | |
125 | |
126 bool BitmapTileTaskWorkerPool::GetResourceRequiresSwizzle( | |
127 bool must_support_alpha) const { | |
128 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); | |
129 } | |
130 | |
131 RasterBufferProvider* BitmapTileTaskWorkerPool::AsRasterBufferProvider() { | |
132 return this; | |
133 } | |
134 | |
135 std::unique_ptr<RasterBuffer> BitmapTileTaskWorkerPool::AcquireBufferForRaster( | |
136 const Resource* resource, | |
137 uint64_t resource_content_id, | |
138 uint64_t previous_content_id) { | |
139 return std::unique_ptr<RasterBuffer>(new RasterBufferImpl( | |
140 resource_provider_, resource, resource_content_id, previous_content_id)); | |
141 } | |
142 | |
143 void BitmapTileTaskWorkerPool::ReleaseBufferForRaster( | |
144 std::unique_ptr<RasterBuffer> buffer) { | |
145 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | |
146 } | |
147 | |
148 } // namespace cc | |
OLD | NEW |