| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layers/video_layer_impl.h" | 5 #include "cc/layers/video_layer_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "cc/layers/video_frame_provider_client_impl.h" | 12 #include "cc/layers/video_frame_provider_client_impl.h" |
| 13 #include "cc/quads/stream_video_draw_quad.h" | 13 #include "cc/quads/stream_video_draw_quad.h" |
| 14 #include "cc/quads/texture_draw_quad.h" | 14 #include "cc/quads/texture_draw_quad.h" |
| 15 #include "cc/quads/yuv_video_draw_quad.h" | 15 #include "cc/quads/yuv_video_draw_quad.h" |
| 16 #include "cc/resources/resource_provider.h" | 16 #include "cc/resources/resource_provider.h" |
| 17 #include "cc/resources/single_release_callback_impl.h" | 17 #include "cc/resources/single_release_callback_impl.h" |
| 18 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 19 #include "cc/trees/occlusion.h" | 19 #include "cc/trees/occlusion.h" |
| 20 #include "cc/trees/task_runner_provider.h" | 20 #include "cc/trees/task_runner_provider.h" |
| 21 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
| 22 #include "ui/gfx/color_space.h" | 22 #include "ui/gfx/color_space.h" |
| 23 | 23 |
| 24 namespace cc { | 24 namespace cc { |
| 25 | 25 |
| 26 namespace { |
| 27 |
| 28 gfx::BufferFormat GetBufferFormat(media::VideoPixelFormat pixel_format) { |
| 29 switch (pixel_format) { |
| 30 case media::PIXEL_FORMAT_YV12: |
| 31 return gfx::BufferFormat::YVU_420; |
| 32 case media::PIXEL_FORMAT_NV12: |
| 33 return gfx::BufferFormat::YUV_420_BIPLANAR; |
| 34 case media::PIXEL_FORMAT_UYVY: |
| 35 return gfx::BufferFormat::UYVY_422; |
| 36 case media::PIXEL_FORMAT_ARGB: |
| 37 return gfx::BufferFormat::BGRA_8888; |
| 38 case media::PIXEL_FORMAT_XRGB: |
| 39 return gfx::BufferFormat::BGRX_8888; |
| 40 case media::PIXEL_FORMAT_RGB32: |
| 41 return gfx::BufferFormat::RGBX_8888; |
| 42 case media::PIXEL_FORMAT_Y8: |
| 43 return gfx::BufferFormat::R_8; |
| 44 case media::PIXEL_FORMAT_Y16: |
| 45 return gfx::BufferFormat::RG_88; |
| 46 case media::PIXEL_FORMAT_UNKNOWN: |
| 47 case media::PIXEL_FORMAT_I420: |
| 48 case media::PIXEL_FORMAT_YV16: |
| 49 case media::PIXEL_FORMAT_YV12A: |
| 50 case media::PIXEL_FORMAT_YV24: |
| 51 case media::PIXEL_FORMAT_NV21: |
| 52 case media::PIXEL_FORMAT_YUY2: |
| 53 case media::PIXEL_FORMAT_RGB24: |
| 54 case media::PIXEL_FORMAT_MJPEG: |
| 55 case media::PIXEL_FORMAT_MT21: |
| 56 case media::PIXEL_FORMAT_YUV420P9: |
| 57 case media::PIXEL_FORMAT_YUV420P10: |
| 58 case media::PIXEL_FORMAT_YUV422P9: |
| 59 case media::PIXEL_FORMAT_YUV422P10: |
| 60 case media::PIXEL_FORMAT_YUV444P9: |
| 61 case media::PIXEL_FORMAT_YUV444P10: |
| 62 case media::PIXEL_FORMAT_YUV420P12: |
| 63 case media::PIXEL_FORMAT_YUV422P12: |
| 64 case media::PIXEL_FORMAT_YUV444P12: |
| 65 case media::PIXEL_FORMAT_I422: |
| 66 break; |
| 67 } |
| 68 NOTREACHED(); |
| 69 return gfx::BufferFormat::BGRA_8888; |
| 70 } |
| 71 |
| 72 } // namespace |
| 73 |
| 26 // static | 74 // static |
| 27 std::unique_ptr<VideoLayerImpl> VideoLayerImpl::Create( | 75 std::unique_ptr<VideoLayerImpl> VideoLayerImpl::Create( |
| 28 LayerTreeImpl* tree_impl, | 76 LayerTreeImpl* tree_impl, |
| 29 int id, | 77 int id, |
| 30 VideoFrameProvider* provider, | 78 VideoFrameProvider* provider, |
| 31 media::VideoRotation video_rotation) { | 79 media::VideoRotation video_rotation) { |
| 32 DCHECK(tree_impl->task_runner_provider()->IsMainThreadBlocked()); | 80 DCHECK(tree_impl->task_runner_provider()->IsMainThreadBlocked()); |
| 33 DCHECK(tree_impl->task_runner_provider()->IsImplThread()); | 81 DCHECK(tree_impl->task_runner_provider()->IsImplThread()); |
| 34 | 82 |
| 35 scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl = | 83 scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl = |
| 36 VideoFrameProviderClientImpl::Create( | 84 VideoFrameProviderClientImpl::Create( |
| 37 provider, tree_impl->GetVideoFrameControllerClient()); | 85 provider, tree_impl->GetVideoFrameControllerClient()); |
| 38 | 86 |
| 39 return base::WrapUnique(new VideoLayerImpl( | 87 return base::WrapUnique(new VideoLayerImpl( |
| 40 tree_impl, id, std::move(provider_client_impl), video_rotation)); | 88 tree_impl, id, std::move(provider_client_impl), video_rotation)); |
| 41 } | 89 } |
| 42 | 90 |
| 43 VideoLayerImpl::VideoLayerImpl( | 91 VideoLayerImpl::VideoLayerImpl( |
| 44 LayerTreeImpl* tree_impl, | 92 LayerTreeImpl* tree_impl, |
| 45 int id, | 93 int id, |
| 46 scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl, | 94 scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl, |
| 47 media::VideoRotation video_rotation) | 95 media::VideoRotation video_rotation) |
| 48 : LayerImpl(tree_impl, id), | 96 : LayerImpl(tree_impl, id), |
| 49 provider_client_impl_(std::move(provider_client_impl)), | 97 provider_client_impl_(std::move(provider_client_impl)), |
| 50 frame_(nullptr), | 98 frame_(nullptr), |
| 51 video_rotation_(video_rotation) { | 99 video_rotation_(video_rotation), |
| 100 frame_resource_type_(VideoFrameExternalResources::NONE), |
| 101 frame_pixel_format_(media::PIXEL_FORMAT_UNKNOWN), |
| 102 frame_resource_offset_(0.0f), |
| 103 frame_resource_multiplier_(1.0f), |
| 104 frame_bits_per_channel_(8) { |
| 52 set_may_contain_video(true); | 105 set_may_contain_video(true); |
| 53 } | 106 } |
| 54 | 107 |
| 55 VideoLayerImpl::~VideoLayerImpl() { | 108 VideoLayerImpl::~VideoLayerImpl() { |
| 56 if (!provider_client_impl_->Stopped()) { | 109 if (!provider_client_impl_->Stopped()) { |
| 57 // In impl side painting, we may have a pending and active layer | 110 // In impl side painting, we may have a pending and active layer |
| 58 // associated with the video provider at the same time. Both have a ref | 111 // associated with the video provider at the same time. Both have a ref |
| 59 // on the VideoFrameProviderClientImpl, but we stop when the first | 112 // on the VideoFrameProviderClientImpl, but we stop when the first |
| 60 // LayerImpl (the one on the pending tree) is destroyed since we know | 113 // LayerImpl (the one on the pending tree) is destroyed since we know |
| 61 // the main thread is blocked for this commit. | 114 // the main thread is blocked for this commit. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 155 |
| 103 if (!updater_) { | 156 if (!updater_) { |
| 104 updater_.reset( | 157 updater_.reset( |
| 105 new VideoResourceUpdater(layer_tree_impl()->context_provider(), | 158 new VideoResourceUpdater(layer_tree_impl()->context_provider(), |
| 106 layer_tree_impl()->resource_provider())); | 159 layer_tree_impl()->resource_provider())); |
| 107 } | 160 } |
| 108 | 161 |
| 109 VideoFrameExternalResources external_resources = | 162 VideoFrameExternalResources external_resources = |
| 110 updater_->CreateExternalResourcesFromVideoFrame(frame_); | 163 updater_->CreateExternalResourcesFromVideoFrame(frame_); |
| 111 frame_resource_type_ = external_resources.type; | 164 frame_resource_type_ = external_resources.type; |
| 165 frame_pixel_format_ = external_resources.pixel_format; |
| 112 | 166 |
| 113 if (external_resources.type == | 167 if (external_resources.type == |
| 114 VideoFrameExternalResources::SOFTWARE_RESOURCE) { | 168 VideoFrameExternalResources::SOFTWARE_RESOURCE) { |
| 115 software_resources_ = external_resources.software_resources; | 169 software_resources_ = external_resources.software_resources; |
| 116 software_release_callback_ = | 170 software_release_callback_ = |
| 117 external_resources.software_release_callback; | 171 external_resources.software_release_callback; |
| 118 return true; | 172 return true; |
| 119 } | 173 } |
| 120 frame_resource_offset_ = external_resources.offset; | 174 frame_resource_offset_ = external_resources.offset; |
| 121 frame_resource_multiplier_ = external_resources.multiplier; | 175 frame_resource_multiplier_ = external_resources.multiplier; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 case VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE: { | 367 case VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE: { |
| 314 DCHECK_EQ(frame_resources_.size(), 1u); | 368 DCHECK_EQ(frame_resources_.size(), 1u); |
| 315 if (frame_resources_.size() < 1u) | 369 if (frame_resources_.size() < 1u) |
| 316 break; | 370 break; |
| 317 gfx::Transform scale; | 371 gfx::Transform scale; |
| 318 scale.Scale(tex_width_scale, tex_height_scale); | 372 scale.Scale(tex_width_scale, tex_height_scale); |
| 319 StreamVideoDrawQuad* stream_video_quad = | 373 StreamVideoDrawQuad* stream_video_quad = |
| 320 render_pass->CreateAndAppendDrawQuad<StreamVideoDrawQuad>(); | 374 render_pass->CreateAndAppendDrawQuad<StreamVideoDrawQuad>(); |
| 321 stream_video_quad->SetNew(shared_quad_state, quad_rect, opaque_rect, | 375 stream_video_quad->SetNew(shared_quad_state, quad_rect, opaque_rect, |
| 322 visible_quad_rect, frame_resources_[0].id, | 376 visible_quad_rect, frame_resources_[0].id, |
| 323 frame_resources_[0].size_in_pixels, scale); | 377 frame_resources_[0].size_in_pixels, |
| 378 GetBufferFormat(frame_pixel_format_), scale); |
| 324 ValidateQuadResources(stream_video_quad); | 379 ValidateQuadResources(stream_video_quad); |
| 325 break; | 380 break; |
| 326 } | 381 } |
| 327 case VideoFrameExternalResources::NONE: | 382 case VideoFrameExternalResources::NONE: |
| 328 NOTIMPLEMENTED(); | 383 NOTIMPLEMENTED(); |
| 329 break; | 384 break; |
| 330 } | 385 } |
| 331 } | 386 } |
| 332 | 387 |
| 333 void VideoLayerImpl::DidDraw(ResourceProvider* resource_provider) { | 388 void VideoLayerImpl::DidDraw(ResourceProvider* resource_provider) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 void VideoLayerImpl::SetNeedsRedraw() { | 427 void VideoLayerImpl::SetNeedsRedraw() { |
| 373 SetUpdateRect(gfx::UnionRects(update_rect(), gfx::Rect(bounds()))); | 428 SetUpdateRect(gfx::UnionRects(update_rect(), gfx::Rect(bounds()))); |
| 374 layer_tree_impl()->SetNeedsRedraw(); | 429 layer_tree_impl()->SetNeedsRedraw(); |
| 375 } | 430 } |
| 376 | 431 |
| 377 const char* VideoLayerImpl::LayerTypeAsString() const { | 432 const char* VideoLayerImpl::LayerTypeAsString() const { |
| 378 return "cc::VideoLayerImpl"; | 433 return "cc::VideoLayerImpl"; |
| 379 } | 434 } |
| 380 | 435 |
| 381 } // namespace cc | 436 } // namespace cc |
| OLD | NEW |