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/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "cc/output/gl_renderer.h" | 8 #include "cc/output/gl_renderer.h" |
9 #include "cc/resources/resource_provider.h" | 9 #include "cc/resources/resource_provider.h" |
10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // In software mode, the resource provider won't be lost. Soon this callback | 264 // In software mode, the resource provider won't be lost. Soon this callback |
265 // will be called directly from the resource provider, same as 3d | 265 // will be called directly from the resource provider, same as 3d |
266 // compositing mode, so this raw unretained resource_provider will always | 266 // compositing mode, so this raw unretained resource_provider will always |
267 // be valid when the callback is fired. | 267 // be valid when the callback is fired. |
268 RecycleResourceData recycle_data = { | 268 RecycleResourceData recycle_data = { |
269 plane_resources[0].resource_id, | 269 plane_resources[0].resource_id, |
270 plane_resources[0].resource_size, | 270 plane_resources[0].resource_size, |
271 plane_resources[0].resource_format, | 271 plane_resources[0].resource_format, |
272 gpu::Mailbox() | 272 gpu::Mailbox() |
273 }; | 273 }; |
274 TextureMailbox::ReleaseCallback callback_to_free_resource = | 274 |
275 base::Bind(&RecycleResource, | |
276 AsWeakPtr(), | |
277 recycle_data); | |
278 external_resources.software_resources.push_back( | 275 external_resources.software_resources.push_back( |
279 plane_resources[0].resource_id); | 276 plane_resources[0].resource_id); |
280 external_resources.software_release_callback = callback_to_free_resource; | 277 external_resources.software_release_callback = |
| 278 base::Bind(&RecycleResource, AsWeakPtr(), recycle_data); |
| 279 |
281 | 280 |
282 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; | 281 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; |
283 return external_resources; | 282 return external_resources; |
284 } | 283 } |
285 | 284 |
286 for (size_t i = 0; i < plane_resources.size(); ++i) { | 285 for (size_t i = 0; i < plane_resources.size(); ++i) { |
287 // Update each plane's resource id with its content. | 286 // Update each plane's resource id with its content. |
288 DCHECK_EQ(plane_resources[i].resource_format, | 287 DCHECK_EQ(plane_resources[i].resource_format, |
289 static_cast<unsigned>(kYUVResourceFormat)); | 288 static_cast<unsigned>(kYUVResourceFormat)); |
290 | 289 |
291 const uint8_t* input_plane_pixels = video_frame->data(i); | 290 const uint8_t* input_plane_pixels = video_frame->data(i); |
292 | 291 |
293 gfx::Rect image_rect(0, | 292 gfx::Rect image_rect(0, |
294 0, | 293 0, |
295 video_frame->stride(i), | 294 video_frame->stride(i), |
296 plane_resources[i].resource_size.height()); | 295 plane_resources[i].resource_size.height()); |
297 gfx::Rect source_rect(plane_resources[i].resource_size); | 296 gfx::Rect source_rect(plane_resources[i].resource_size); |
298 resource_provider_->SetPixels(plane_resources[i].resource_id, | 297 resource_provider_->SetPixels(plane_resources[i].resource_id, |
299 input_plane_pixels, | 298 input_plane_pixels, |
300 image_rect, | 299 image_rect, |
301 source_rect, | 300 source_rect, |
302 gfx::Vector2d()); | 301 gfx::Vector2d()); |
303 | 302 |
304 RecycleResourceData recycle_data = { | 303 RecycleResourceData recycle_data = { |
305 plane_resources[i].resource_id, | 304 plane_resources[i].resource_id, |
306 plane_resources[i].resource_size, | 305 plane_resources[i].resource_size, |
307 plane_resources[i].resource_format, | 306 plane_resources[i].resource_format, |
308 plane_resources[i].mailbox | 307 plane_resources[i].mailbox |
309 }; | 308 }; |
310 TextureMailbox::ReleaseCallback callback_to_free_resource = | 309 |
311 base::Bind(&RecycleResource, | |
312 AsWeakPtr(), | |
313 recycle_data); | |
314 external_resources.mailboxes.push_back( | 310 external_resources.mailboxes.push_back( |
315 TextureMailbox(plane_resources[i].mailbox, | 311 TextureMailbox(plane_resources[i].mailbox)); |
316 callback_to_free_resource)); | 312 external_resources.release_callbacks.push_back( |
| 313 base::Bind(&RecycleResource, AsWeakPtr(), recycle_data)); |
317 } | 314 } |
318 | 315 |
319 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; | 316 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; |
320 return external_resources; | 317 return external_resources; |
321 } | 318 } |
322 | 319 |
323 static void ReturnTexture( | 320 static void ReturnTexture( |
324 scoped_refptr<media::VideoFrame::MailboxHolder> mailbox_holder, | 321 scoped_refptr<media::VideoFrame::MailboxHolder> mailbox_holder, |
325 unsigned sync_point, | 322 unsigned sync_point, |
326 bool lost_resource) { | 323 bool lost_resource) { |
(...skipping 24 matching lines...) Expand all Loading... |
351 external_resources.type = VideoFrameExternalResources::IO_SURFACE; | 348 external_resources.type = VideoFrameExternalResources::IO_SURFACE; |
352 break; | 349 break; |
353 default: | 350 default: |
354 NOTREACHED(); | 351 NOTREACHED(); |
355 return VideoFrameExternalResources(); | 352 return VideoFrameExternalResources(); |
356 } | 353 } |
357 | 354 |
358 scoped_refptr<media::VideoFrame::MailboxHolder> mailbox_holder = | 355 scoped_refptr<media::VideoFrame::MailboxHolder> mailbox_holder = |
359 video_frame->texture_mailbox(); | 356 video_frame->texture_mailbox(); |
360 | 357 |
361 TextureMailbox::ReleaseCallback callback_to_return_resource = | |
362 base::Bind(&ReturnTexture, mailbox_holder); | |
363 | |
364 external_resources.mailboxes.push_back( | 358 external_resources.mailboxes.push_back( |
365 TextureMailbox(mailbox_holder->mailbox(), | 359 TextureMailbox(mailbox_holder->mailbox(), |
366 callback_to_return_resource, | |
367 video_frame->texture_target(), | 360 video_frame->texture_target(), |
368 mailbox_holder->sync_point())); | 361 mailbox_holder->sync_point())); |
| 362 external_resources.release_callbacks.push_back( |
| 363 base::Bind(&ReturnTexture, mailbox_holder)); |
369 return external_resources; | 364 return external_resources; |
370 } | 365 } |
371 | 366 |
372 // static | 367 // static |
373 void VideoResourceUpdater::RecycleResource( | 368 void VideoResourceUpdater::RecycleResource( |
374 base::WeakPtr<VideoResourceUpdater> updater, | 369 base::WeakPtr<VideoResourceUpdater> updater, |
375 RecycleResourceData data, | 370 RecycleResourceData data, |
376 unsigned sync_point, | 371 unsigned sync_point, |
377 bool lost_resource) { | 372 bool lost_resource) { |
378 if (!updater.get()) { | 373 if (!updater.get()) { |
(...skipping 21 matching lines...) Expand all Loading... |
400 } | 395 } |
401 | 396 |
402 PlaneResource recycled_resource(data.resource_id, | 397 PlaneResource recycled_resource(data.resource_id, |
403 data.resource_size, | 398 data.resource_size, |
404 data.resource_format, | 399 data.resource_format, |
405 data.mailbox); | 400 data.mailbox); |
406 updater->recycled_resources_.push_back(recycled_resource); | 401 updater->recycled_resources_.push_back(recycled_resource); |
407 } | 402 } |
408 | 403 |
409 } // namespace cc | 404 } // namespace cc |
OLD | NEW |