Chromium Code Reviews| 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" |
| 11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
| 12 #include "media/filters/skcanvas_video_renderer.h" | 12 #include "media/filters/skcanvas_video_renderer.h" |
| 13 #include "third_party/khronos/GLES2/gl2.h" | 13 #include "third_party/khronos/GLES2/gl2.h" |
| 14 #include "third_party/khronos/GLES2/gl2ext.h" | 14 #include "third_party/khronos/GLES2/gl2ext.h" |
| 15 #include "ui/gfx/size_conversions.h" | 15 #include "ui/gfx/size_conversions.h" |
| 16 | 16 |
| 17 const unsigned kYUVResourceFormat = GL_LUMINANCE; | 17 const unsigned kYUVResourceFormat = GL_LUMINANCE; |
| 18 const unsigned kRGBResourceFormat = GL_RGBA; | 18 const unsigned kRGBResourceFormat = GL_RGBA; |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 | 21 |
| 22 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {} | 22 VideoFrameExternalResources::VideoFrameExternalResources() |
| 23 : type(NONE), hardware_resource(0) {} | |
| 23 | 24 |
| 24 VideoFrameExternalResources::~VideoFrameExternalResources() {} | 25 VideoFrameExternalResources::~VideoFrameExternalResources() {} |
| 25 | 26 |
| 26 VideoResourceUpdater::VideoResourceUpdater(ResourceProvider* resource_provider) | 27 VideoResourceUpdater::VideoResourceUpdater(ResourceProvider* resource_provider) |
| 27 : resource_provider_(resource_provider) { | 28 : resource_provider_(resource_provider) { |
| 28 } | 29 } |
| 29 | 30 |
| 30 VideoResourceUpdater::~VideoResourceUpdater() { | 31 VideoResourceUpdater::~VideoResourceUpdater() { |
| 31 while (!recycled_resources_.empty()) { | 32 while (!recycled_resources_.empty()) { |
| 32 resource_provider_->DeleteResource(recycled_resources_.back().resource_id); | 33 resource_provider_->DeleteResource(recycled_resources_.back().resource_id); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 TextureMailbox(mailbox, | 283 TextureMailbox(mailbox, |
| 283 callback_to_free_resource, | 284 callback_to_free_resource, |
| 284 plane_resources[i].sync_point)); | 285 plane_resources[i].sync_point)); |
| 285 } | 286 } |
| 286 | 287 |
| 287 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; | 288 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; |
| 288 return external_resources; | 289 return external_resources; |
| 289 } | 290 } |
| 290 | 291 |
| 291 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( | 292 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( |
| 292 const scoped_refptr<media::VideoFrame>& video_frame, | 293 const scoped_refptr<media::VideoFrame>& video_frame) { |
| 293 const TextureMailbox::ReleaseCallback& release_callback) { | |
| 294 if (!VerifyFrame(video_frame)) | 294 if (!VerifyFrame(video_frame)) |
| 295 return VideoFrameExternalResources(); | 295 return VideoFrameExternalResources(); |
| 296 | 296 |
| 297 media::VideoFrame::Format frame_format = video_frame->format(); | 297 media::VideoFrame::Format frame_format = video_frame->format(); |
| 298 | 298 |
| 299 DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE); | 299 DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE); |
| 300 if (frame_format != media::VideoFrame::NATIVE_TEXTURE) | 300 if (frame_format != media::VideoFrame::NATIVE_TEXTURE) |
| 301 return VideoFrameExternalResources(); | 301 return VideoFrameExternalResources(); |
| 302 | 302 |
| 303 WebKit::WebGraphicsContext3D* context = | 303 WebKit::WebGraphicsContext3D* context = |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 315 VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE; | 315 VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE; |
| 316 break; | 316 break; |
| 317 case GL_TEXTURE_RECTANGLE_ARB: | 317 case GL_TEXTURE_RECTANGLE_ARB: |
| 318 external_resources.type = VideoFrameExternalResources::IO_SURFACE; | 318 external_resources.type = VideoFrameExternalResources::IO_SURFACE; |
| 319 break; | 319 break; |
| 320 default: | 320 default: |
| 321 NOTREACHED(); | 321 NOTREACHED(); |
| 322 return VideoFrameExternalResources(); | 322 return VideoFrameExternalResources(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 gpu::Mailbox mailbox; | 325 external_resources.hardware_resource = |
| 326 GLC(context, context->genMailboxCHROMIUM(mailbox.name)); | 326 resource_provider_->CreateResourceFromExternalTexture( |
| 327 GLC(context, context->bindTexture(GL_TEXTURE_2D, video_frame->texture_id())); | 327 video_frame->texture_id()); |
| 328 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name)); | |
| 329 GLC(context, context->bindTexture(GL_TEXTURE_2D, 0)); | |
| 330 | 328 |
| 331 TextureMailbox::ReleaseCallback callback_to_return_resource = | 329 TextureMailbox::ReleaseCallback callback_to_return_resource = |
| 332 base::Bind(&ReturnTexture, | 330 base::Bind(&ReturnTexture, |
| 333 base::Unretained(resource_provider_), | 331 base::Unretained(resource_provider_), |
| 334 release_callback, | 332 external_resources.hardware_resource); |
| 335 video_frame->texture_id(), | 333 external_resources.hardware_release_callback = callback_to_return_resource; |
| 336 mailbox); | |
| 337 external_resources.mailboxes.push_back( | |
| 338 TextureMailbox(mailbox, callback_to_return_resource)); | |
| 339 return external_resources; | 334 return external_resources; |
| 340 } | 335 } |
| 341 | 336 |
| 342 // static | 337 // static |
| 343 void VideoResourceUpdater::ReturnTexture( | 338 void VideoResourceUpdater::ReturnTexture( |
| 344 ResourceProvider* resource_provider, | 339 ResourceProvider* resource_provider, |
| 345 TextureMailbox::ReleaseCallback callback, | 340 unsigned resource_id, |
| 346 unsigned texture_id, | |
| 347 gpu::Mailbox mailbox, | |
| 348 unsigned sync_point, | 341 unsigned sync_point, |
| 349 bool lost_resource) { | 342 bool lost_resource) { |
| 350 WebKit::WebGraphicsContext3D* context = | 343 resource_provider->DeleteResource(resource_id); |
| 351 resource_provider->GraphicsContext3D(); | |
| 352 GLC(context, context->bindTexture(GL_TEXTURE_2D, texture_id)); | |
|
no sievers
2013/04/13 01:14:30
Hey when you reland, be sure to use the right text
danakj
2013/04/13 16:47:25
Ohh right. Thanks, I shall pay attention to that
| |
| 353 GLC(context, context->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name)); | |
| 354 GLC(context, context->bindTexture(GL_TEXTURE_2D, 0)); | |
| 355 callback.Run(sync_point, lost_resource); | |
| 356 } | 344 } |
| 357 | 345 |
| 358 // static | 346 // static |
| 359 void VideoResourceUpdater::RecycleResource( | 347 void VideoResourceUpdater::RecycleResource( |
| 360 base::WeakPtr<VideoResourceUpdater> updater, | 348 base::WeakPtr<VideoResourceUpdater> updater, |
| 361 ResourceProvider* resource_provider, | 349 ResourceProvider* resource_provider, |
| 362 RecycleResourceData data, | 350 RecycleResourceData data, |
| 363 unsigned sync_point, | 351 unsigned sync_point, |
| 364 bool lost_resource) { | 352 bool lost_resource) { |
| 365 WebKit::WebGraphicsContext3D* context = | 353 WebKit::WebGraphicsContext3D* context = |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 390 } | 378 } |
| 391 | 379 |
| 392 PlaneResource recycled_resource(data.resource_id, | 380 PlaneResource recycled_resource(data.resource_id, |
| 393 data.resource_size, | 381 data.resource_size, |
| 394 data.resource_format, | 382 data.resource_format, |
| 395 sync_point); | 383 sync_point); |
| 396 updater->recycled_resources_.push_back(recycled_resource); | 384 updater->recycled_resources_.push_back(recycled_resource); |
| 397 } | 385 } |
| 398 | 386 |
| 399 } // namespace cc | 387 } // namespace cc |
| OLD | NEW |