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/raster/raster_buffer_provider.h" | 5 #include "cc/raster/raster_buffer_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const size_t kMaxBytesPerCopyOperation = 1000U; | 44 const size_t kMaxBytesPerCopyOperation = 1000U; |
45 const size_t kMaxStagingBuffers = 32U; | 45 const size_t kMaxStagingBuffers = 32U; |
46 | 46 |
47 enum RasterBufferProviderType { | 47 enum RasterBufferProviderType { |
48 RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY, | 48 RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY, |
49 RASTER_BUFFER_PROVIDER_TYPE_ONE_COPY, | 49 RASTER_BUFFER_PROVIDER_TYPE_ONE_COPY, |
50 RASTER_BUFFER_PROVIDER_TYPE_GPU, | 50 RASTER_BUFFER_PROVIDER_TYPE_GPU, |
51 RASTER_BUFFER_PROVIDER_TYPE_BITMAP | 51 RASTER_BUFFER_PROVIDER_TYPE_BITMAP |
52 }; | 52 }; |
53 | 53 |
| 54 class TestRasterTaskCompletionHandler { |
| 55 public: |
| 56 virtual void OnRasterTaskCompleted( |
| 57 std::unique_ptr<RasterBuffer> raster_buffer, |
| 58 unsigned id, |
| 59 bool was_canceled) = 0; |
| 60 }; |
| 61 |
54 class TestRasterTaskImpl : public TileTask { | 62 class TestRasterTaskImpl : public TileTask { |
55 public: | 63 public: |
56 typedef base::Callback<void(bool was_canceled)> Reply; | 64 TestRasterTaskImpl(TestRasterTaskCompletionHandler* completion_handler, |
57 | 65 std::unique_ptr<ScopedResource> resource, |
58 TestRasterTaskImpl(const Resource* resource, | 66 unsigned id, |
59 const Reply& reply, | 67 std::unique_ptr<RasterBuffer> raster_buffer, |
60 TileTask::Vector* dependencies) | 68 TileTask::Vector* dependencies) |
61 : TileTask(true, dependencies), | 69 : TileTask(true, dependencies), |
62 resource_(resource), | 70 completion_handler_(completion_handler), |
63 reply_(reply), | 71 resource_(std::move(resource)), |
| 72 id_(id), |
| 73 raster_buffer_(std::move(raster_buffer)), |
64 raster_source_(FakeRasterSource::CreateFilled(gfx::Size(1, 1))) {} | 74 raster_source_(FakeRasterSource::CreateFilled(gfx::Size(1, 1))) {} |
65 | 75 |
66 // Overridden from Task: | 76 // Overridden from Task: |
67 void RunOnWorkerThread() override { | 77 void RunOnWorkerThread() override { |
68 uint64_t new_content_id = 0; | 78 uint64_t new_content_id = 0; |
69 raster_buffer_->Playback(raster_source_.get(), gfx::Rect(1, 1), | 79 raster_buffer_->Playback(raster_source_.get(), gfx::Rect(1, 1), |
70 gfx::Rect(1, 1), new_content_id, 1.f, | 80 gfx::Rect(1, 1), new_content_id, 1.f, |
71 RasterSource::PlaybackSettings()); | 81 RasterSource::PlaybackSettings()); |
72 } | 82 } |
73 | 83 |
74 // Overridden from TileTask: | 84 // Overridden from TileTask: |
75 void ScheduleOnOriginThread(RasterBufferProvider* provider) override { | 85 void OnTaskCompleted() override { |
76 // The raster buffer has no tile ids associated with it for partial update, | 86 completion_handler_->OnRasterTaskCompleted(std::move(raster_buffer_), id_, |
77 // so doesn't need to provide a valid dirty rect. | 87 state().IsCanceled()); |
78 raster_buffer_ = provider->AcquireBufferForRaster(resource_, 0, 0); | |
79 } | |
80 void CompleteOnOriginThread(RasterBufferProvider* provider) override { | |
81 provider->ReleaseBufferForRaster(std::move(raster_buffer_)); | |
82 reply_.Run(!state().IsFinished()); | |
83 } | 88 } |
84 | 89 |
85 protected: | 90 protected: |
86 ~TestRasterTaskImpl() override {} | 91 ~TestRasterTaskImpl() override {} |
87 | 92 |
88 private: | 93 private: |
89 const Resource* resource_; | 94 TestRasterTaskCompletionHandler* completion_handler_; |
90 const Reply reply_; | 95 std::unique_ptr<ScopedResource> resource_; |
| 96 unsigned id_; |
91 std::unique_ptr<RasterBuffer> raster_buffer_; | 97 std::unique_ptr<RasterBuffer> raster_buffer_; |
92 scoped_refptr<RasterSource> raster_source_; | 98 scoped_refptr<RasterSource> raster_source_; |
93 | 99 |
94 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); | 100 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); |
95 }; | 101 }; |
96 | 102 |
97 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { | 103 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { |
98 public: | 104 public: |
99 BlockingTestRasterTaskImpl(const Resource* resource, | 105 BlockingTestRasterTaskImpl( |
100 const Reply& reply, | 106 TestRasterTaskCompletionHandler* completion_handler, |
101 base::Lock* lock, | 107 std::unique_ptr<ScopedResource> resource, |
102 TileTask::Vector* dependencies) | 108 unsigned id, |
103 : TestRasterTaskImpl(resource, reply, dependencies), lock_(lock) {} | 109 std::unique_ptr<RasterBuffer> raster_buffer, |
| 110 base::Lock* lock, |
| 111 TileTask::Vector* dependencies) |
| 112 : TestRasterTaskImpl(completion_handler, |
| 113 std::move(resource), |
| 114 id, |
| 115 std::move(raster_buffer), |
| 116 dependencies), |
| 117 lock_(lock) {} |
104 | 118 |
105 // Overridden from Task: | 119 // Overridden from Task: |
106 void RunOnWorkerThread() override { | 120 void RunOnWorkerThread() override { |
107 base::AutoLock lock(*lock_); | 121 base::AutoLock lock(*lock_); |
108 TestRasterTaskImpl::RunOnWorkerThread(); | 122 TestRasterTaskImpl::RunOnWorkerThread(); |
109 } | 123 } |
110 | 124 |
111 protected: | 125 protected: |
112 ~BlockingTestRasterTaskImpl() override {} | 126 ~BlockingTestRasterTaskImpl() override {} |
113 | 127 |
114 private: | 128 private: |
115 base::Lock* lock_; | 129 base::Lock* lock_; |
116 | 130 |
117 DISALLOW_COPY_AND_ASSIGN(BlockingTestRasterTaskImpl); | 131 DISALLOW_COPY_AND_ASSIGN(BlockingTestRasterTaskImpl); |
118 }; | 132 }; |
119 | 133 |
120 class RasterBufferProviderTest | 134 class RasterBufferProviderTest |
121 : public testing::TestWithParam<RasterBufferProviderType> { | 135 : public TestRasterTaskCompletionHandler, |
| 136 public testing::TestWithParam<RasterBufferProviderType> { |
122 public: | 137 public: |
123 struct RasterTaskResult { | 138 struct RasterTaskResult { |
124 unsigned id; | 139 unsigned id; |
125 bool canceled; | 140 bool canceled; |
126 }; | 141 }; |
127 | 142 |
128 typedef std::vector<scoped_refptr<TileTask>> RasterTaskVector; | 143 typedef std::vector<scoped_refptr<TileTask>> RasterTaskVector; |
129 | 144 |
130 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, REQUIRED_FOR_DRAW, ALL }; | 145 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, REQUIRED_FOR_DRAW, ALL }; |
131 | 146 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 215 } |
201 | 216 |
202 tile_task_manager_->ScheduleTasks(&graph_); | 217 tile_task_manager_->ScheduleTasks(&graph_); |
203 } | 218 } |
204 | 219 |
205 void AppendTask(unsigned id, const gfx::Size& size) { | 220 void AppendTask(unsigned id, const gfx::Size& size) { |
206 std::unique_ptr<ScopedResource> resource( | 221 std::unique_ptr<ScopedResource> resource( |
207 ScopedResource::Create(resource_provider_.get())); | 222 ScopedResource::Create(resource_provider_.get())); |
208 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 223 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
209 RGBA_8888); | 224 RGBA_8888); |
210 const Resource* const_resource = resource.get(); | |
211 | 225 |
| 226 // The raster buffer has no tile ids associated with it for partial update, |
| 227 // so doesn't need to provide a valid dirty rect. |
| 228 std::unique_ptr<RasterBuffer> raster_buffer = |
| 229 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( |
| 230 resource.get(), 0, 0); |
212 TileTask::Vector empty; | 231 TileTask::Vector empty; |
213 tasks_.push_back(new TestRasterTaskImpl( | 232 tasks_.push_back(new TestRasterTaskImpl(this, std::move(resource), id, |
214 const_resource, | 233 std::move(raster_buffer), &empty)); |
215 base::Bind(&RasterBufferProviderTest::OnTaskCompleted, | |
216 base::Unretained(this), base::Passed(&resource), id), | |
217 &empty)); | |
218 } | 234 } |
219 | 235 |
220 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } | 236 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } |
221 | 237 |
222 void AppendBlockingTask(unsigned id, base::Lock* lock) { | 238 void AppendBlockingTask(unsigned id, base::Lock* lock) { |
223 const gfx::Size size(1, 1); | 239 const gfx::Size size(1, 1); |
224 | 240 |
225 std::unique_ptr<ScopedResource> resource( | 241 std::unique_ptr<ScopedResource> resource( |
226 ScopedResource::Create(resource_provider_.get())); | 242 ScopedResource::Create(resource_provider_.get())); |
227 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 243 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
228 RGBA_8888); | 244 RGBA_8888); |
229 const Resource* const_resource = resource.get(); | |
230 | 245 |
| 246 std::unique_ptr<RasterBuffer> raster_buffer = |
| 247 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( |
| 248 resource.get(), 0, 0); |
231 TileTask::Vector empty; | 249 TileTask::Vector empty; |
232 tasks_.push_back(new BlockingTestRasterTaskImpl( | 250 tasks_.push_back(new BlockingTestRasterTaskImpl( |
233 const_resource, | 251 this, std::move(resource), id, std::move(raster_buffer), lock, &empty)); |
234 base::Bind(&RasterBufferProviderTest::OnTaskCompleted, | |
235 base::Unretained(this), base::Passed(&resource), id), | |
236 lock, &empty)); | |
237 } | 252 } |
238 | 253 |
239 const std::vector<RasterTaskResult>& completed_tasks() const { | 254 const std::vector<RasterTaskResult>& completed_tasks() const { |
240 return completed_tasks_; | 255 return completed_tasks_; |
241 } | 256 } |
242 | 257 |
243 void LoseContext(ContextProvider* context_provider) { | 258 void LoseContext(ContextProvider* context_provider) { |
244 if (!context_provider) | 259 if (!context_provider) |
245 return; | 260 return; |
246 context_provider->ContextGL()->LoseContextCHROMIUM( | 261 context_provider->ContextGL()->LoseContextCHROMIUM( |
247 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 262 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
248 context_provider->ContextGL()->Flush(); | 263 context_provider->ContextGL()->Flush(); |
249 } | 264 } |
250 | 265 |
| 266 void OnRasterTaskCompleted(std::unique_ptr<RasterBuffer> raster_buffer, |
| 267 unsigned id, |
| 268 bool was_canceled) override { |
| 269 tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( |
| 270 std::move(raster_buffer)); |
| 271 RasterTaskResult result; |
| 272 result.id = id; |
| 273 result.canceled = was_canceled; |
| 274 completed_tasks_.push_back(result); |
| 275 } |
| 276 |
251 private: | 277 private: |
252 void Create3dOutputSurfaceAndResourceProvider() { | 278 void Create3dOutputSurfaceAndResourceProvider() { |
253 output_surface_ = FakeOutputSurface::Create3d(context_provider_, | 279 output_surface_ = FakeOutputSurface::Create3d(context_provider_, |
254 worker_context_provider_); | 280 worker_context_provider_); |
255 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 281 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
256 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); | 282 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); |
257 context3d->set_support_sync_query(true); | 283 context3d->set_support_sync_query(true); |
258 resource_provider_ = FakeResourceProvider::Create( | 284 resource_provider_ = FakeResourceProvider::Create( |
259 output_surface_.get(), nullptr, &gpu_memory_buffer_manager_); | 285 output_surface_.get(), nullptr, &gpu_memory_buffer_manager_); |
260 } | 286 } |
261 | 287 |
262 void CreateSoftwareOutputSurfaceAndResourceProvider() { | 288 void CreateSoftwareOutputSurfaceAndResourceProvider() { |
263 output_surface_ = FakeOutputSurface::CreateSoftware( | 289 output_surface_ = FakeOutputSurface::CreateSoftware( |
264 base::WrapUnique(new SoftwareOutputDevice)); | 290 base::WrapUnique(new SoftwareOutputDevice)); |
265 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 291 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
266 resource_provider_ = FakeResourceProvider::Create( | 292 resource_provider_ = FakeResourceProvider::Create( |
267 output_surface_.get(), &shared_bitmap_manager_, nullptr); | 293 output_surface_.get(), &shared_bitmap_manager_, nullptr); |
268 } | 294 } |
269 | 295 |
270 void OnTaskCompleted(std::unique_ptr<ScopedResource> resource, | |
271 unsigned id, | |
272 bool was_canceled) { | |
273 RasterTaskResult result; | |
274 result.id = id; | |
275 result.canceled = was_canceled; | |
276 completed_tasks_.push_back(result); | |
277 } | |
278 | |
279 void OnTimeout() { | 296 void OnTimeout() { |
280 timed_out_ = true; | 297 timed_out_ = true; |
281 base::MessageLoop::current()->QuitWhenIdle(); | 298 base::MessageLoop::current()->QuitWhenIdle(); |
282 } | 299 } |
283 | 300 |
284 protected: | 301 protected: |
285 scoped_refptr<TestContextProvider> context_provider_; | 302 scoped_refptr<TestContextProvider> context_provider_; |
286 scoped_refptr<TestContextProvider> worker_context_provider_; | 303 scoped_refptr<TestContextProvider> worker_context_provider_; |
287 FakeOutputSurfaceClient output_surface_client_; | 304 FakeOutputSurfaceClient output_surface_client_; |
288 std::unique_ptr<FakeOutputSurface> output_surface_; | 305 std::unique_ptr<FakeOutputSurface> output_surface_; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 385 |
369 INSTANTIATE_TEST_CASE_P(RasterBufferProviderTests, | 386 INSTANTIATE_TEST_CASE_P(RasterBufferProviderTests, |
370 RasterBufferProviderTest, | 387 RasterBufferProviderTest, |
371 ::testing::Values(RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY, | 388 ::testing::Values(RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY, |
372 RASTER_BUFFER_PROVIDER_TYPE_ONE_COPY, | 389 RASTER_BUFFER_PROVIDER_TYPE_ONE_COPY, |
373 RASTER_BUFFER_PROVIDER_TYPE_GPU, | 390 RASTER_BUFFER_PROVIDER_TYPE_GPU, |
374 RASTER_BUFFER_PROVIDER_TYPE_BITMAP)); | 391 RASTER_BUFFER_PROVIDER_TYPE_BITMAP)); |
375 | 392 |
376 } // namespace | 393 } // namespace |
377 } // namespace cc | 394 } // namespace cc |
OLD | NEW |