OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/raster/zero_copy_tile_task_worker_pool.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include <algorithm> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/ptr_util.h" | |
13 #include "base/strings/stringprintf.h" | |
14 #include "base/trace_event/trace_event.h" | |
15 #include "base/trace_event/trace_event_argument.h" | |
16 #include "cc/debug/traced_value.h" | |
17 #include "cc/resources/platform_color.h" | |
18 #include "cc/resources/resource.h" | |
19 #include "ui/gfx/buffer_format_util.h" | |
20 #include "ui/gfx/gpu_memory_buffer.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 : lock_(resource_provider, resource->id()), resource_(resource) {} | |
30 | |
31 // Overridden from RasterBuffer: | |
32 void Playback( | |
33 const RasterSource* raster_source, | |
34 const gfx::Rect& raster_full_rect, | |
35 const gfx::Rect& raster_dirty_rect, | |
36 uint64_t new_content_id, | |
37 float scale, | |
38 const RasterSource::PlaybackSettings& playback_settings) override { | |
39 gfx::GpuMemoryBuffer* buffer = lock_.GetGpuMemoryBuffer(); | |
40 if (!buffer) | |
41 return; | |
42 | |
43 DCHECK_EQ(1u, gfx::NumberOfPlanesForBufferFormat(buffer->GetFormat())); | |
44 bool rv = buffer->Map(); | |
45 DCHECK(rv); | |
46 DCHECK(buffer->memory(0)); | |
47 // TileTaskWorkerPool::PlaybackToMemory only supports unsigned strides. | |
48 DCHECK_GE(buffer->stride(0), 0); | |
49 | |
50 // TODO(danakj): Implement partial raster with raster_dirty_rect. | |
51 TileTaskWorkerPool::PlaybackToMemory( | |
52 buffer->memory(0), resource_->format(), resource_->size(), | |
53 buffer->stride(0), raster_source, raster_full_rect, raster_full_rect, | |
54 scale, playback_settings); | |
55 buffer->Unmap(); | |
56 } | |
57 | |
58 private: | |
59 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock_; | |
60 const Resource* resource_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | |
63 }; | |
64 | |
65 } // namespace | |
66 | |
67 // static | |
68 std::unique_ptr<TileTaskWorkerPool> ZeroCopyTileTaskWorkerPool::Create( | |
69 base::SequencedTaskRunner* task_runner, | |
70 TaskGraphRunner* task_graph_runner, | |
71 ResourceProvider* resource_provider, | |
72 ResourceFormat preferred_tile_format) { | |
73 return base::WrapUnique<TileTaskWorkerPool>( | |
74 new ZeroCopyTileTaskWorkerPool(task_runner, task_graph_runner, | |
75 resource_provider, preferred_tile_format)); | |
76 } | |
77 | |
78 ZeroCopyTileTaskWorkerPool::ZeroCopyTileTaskWorkerPool( | |
79 base::SequencedTaskRunner* task_runner, | |
80 TaskGraphRunner* task_graph_runner, | |
81 ResourceProvider* resource_provider, | |
82 ResourceFormat preferred_tile_format) | |
83 : task_runner_(task_runner), | |
84 task_graph_runner_(task_graph_runner), | |
85 namespace_token_(task_graph_runner->GetNamespaceToken()), | |
86 resource_provider_(resource_provider), | |
87 preferred_tile_format_(preferred_tile_format) {} | |
88 | |
89 ZeroCopyTileTaskWorkerPool::~ZeroCopyTileTaskWorkerPool() { | |
90 } | |
91 | |
92 void ZeroCopyTileTaskWorkerPool::Shutdown() { | |
93 TRACE_EVENT0("cc", "ZeroCopyTileTaskWorkerPool::Shutdown"); | |
94 | |
95 TaskGraph empty; | |
96 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); | |
97 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); | |
98 } | |
99 | |
100 void ZeroCopyTileTaskWorkerPool::ScheduleTasks(TaskGraph* graph) { | |
101 TRACE_EVENT0("cc", "ZeroCopyTileTaskWorkerPool::ScheduleTasks"); | |
102 | |
103 ScheduleTasksOnOriginThread(this, graph); | |
104 task_graph_runner_->ScheduleTasks(namespace_token_, graph); | |
105 } | |
106 | |
107 void ZeroCopyTileTaskWorkerPool::CheckForCompletedTasks() { | |
108 TRACE_EVENT0("cc", "ZeroCopyTileTaskWorkerPool::CheckForCompletedTasks"); | |
109 | |
110 task_graph_runner_->CollectCompletedTasks(namespace_token_, | |
111 &completed_tasks_); | |
112 for (Task::Vector::const_iterator it = completed_tasks_.begin(); | |
113 it != completed_tasks_.end(); ++it) { | |
114 TileTask* task = static_cast<TileTask*>(it->get()); | |
115 | |
116 task->WillComplete(); | |
117 task->CompleteOnOriginThread(this); | |
118 task->DidComplete(); | |
119 } | |
120 completed_tasks_.clear(); | |
121 } | |
122 | |
123 ResourceFormat ZeroCopyTileTaskWorkerPool::GetResourceFormat( | |
124 bool must_support_alpha) const { | |
125 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && | |
126 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || | |
127 !must_support_alpha)) { | |
128 return preferred_tile_format_; | |
129 } | |
130 | |
131 return resource_provider_->best_texture_format(); | |
132 } | |
133 | |
134 bool ZeroCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( | |
135 bool must_support_alpha) const { | |
136 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); | |
137 } | |
138 | |
139 RasterBufferProvider* ZeroCopyTileTaskWorkerPool::AsRasterBufferProvider() { | |
140 return this; | |
141 } | |
142 | |
143 std::unique_ptr<RasterBuffer> | |
144 ZeroCopyTileTaskWorkerPool::AcquireBufferForRaster( | |
145 const Resource* resource, | |
146 uint64_t resource_content_id, | |
147 uint64_t previous_content_id) { | |
148 return base::WrapUnique<RasterBuffer>( | |
149 new RasterBufferImpl(resource_provider_, resource)); | |
150 } | |
151 | |
152 void ZeroCopyTileTaskWorkerPool::ReleaseBufferForRaster( | |
153 std::unique_ptr<RasterBuffer> buffer) { | |
154 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | |
155 } | |
156 | |
157 } // namespace cc | |
OLD | NEW |