| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/layers/quad_sink.h" | 9 #include "cc/layers/quad_sink.h" |
| 10 #include "cc/layers/video_frame_provider_client_impl.h" | 10 #include "cc/layers/video_frame_provider_client_impl.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 VideoFrameProvider* provider) { | 30 VideoFrameProvider* provider) { |
| 31 scoped_ptr<VideoLayerImpl> layer(new VideoLayerImpl(tree_impl, id)); | 31 scoped_ptr<VideoLayerImpl> layer(new VideoLayerImpl(tree_impl, id)); |
| 32 layer->SetProviderClientImpl(VideoFrameProviderClientImpl::Create(provider)); | 32 layer->SetProviderClientImpl(VideoFrameProviderClientImpl::Create(provider)); |
| 33 DCHECK(tree_impl->proxy()->IsImplThread()); | 33 DCHECK(tree_impl->proxy()->IsImplThread()); |
| 34 DCHECK(tree_impl->proxy()->IsMainThreadBlocked()); | 34 DCHECK(tree_impl->proxy()->IsMainThreadBlocked()); |
| 35 return layer.Pass(); | 35 return layer.Pass(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 VideoLayerImpl::VideoLayerImpl(LayerTreeImpl* tree_impl, int id) | 38 VideoLayerImpl::VideoLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 39 : LayerImpl(tree_impl, id), | 39 : LayerImpl(tree_impl, id), |
| 40 frame_(NULL), | 40 frame_(NULL) {} |
| 41 hardware_resource_(0) {} | |
| 42 | 41 |
| 43 VideoLayerImpl::~VideoLayerImpl() { | 42 VideoLayerImpl::~VideoLayerImpl() { |
| 44 if (!provider_client_impl_->Stopped()) { | 43 if (!provider_client_impl_->Stopped()) { |
| 45 // In impl side painting, we may have a pending and active layer | 44 // In impl side painting, we may have a pending and active layer |
| 46 // associated with the video provider at the same time. Both have a ref | 45 // associated with the video provider at the same time. Both have a ref |
| 47 // on the VideoFrameProviderClientImpl, but we stop when the first | 46 // on the VideoFrameProviderClientImpl, but we stop when the first |
| 48 // LayerImpl (the one on the pending tree) is destroyed since we know | 47 // LayerImpl (the one on the pending tree) is destroyed since we know |
| 49 // the main thread is blocked for this commit. | 48 // the main thread is blocked for this commit. |
| 50 DCHECK(layer_tree_impl()->proxy()->IsImplThread()); | 49 DCHECK(layer_tree_impl()->proxy()->IsImplThread()); |
| 51 DCHECK(layer_tree_impl()->proxy()->IsMainThreadBlocked()); | 50 DCHECK(layer_tree_impl()->proxy()->IsMainThreadBlocked()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Drop any resources used by the updater if there is no frame to display. | 84 // Drop any resources used by the updater if there is no frame to display. |
| 86 updater_.reset(); | 85 updater_.reset(); |
| 87 | 86 |
| 88 provider_client_impl_->ReleaseLock(); | 87 provider_client_impl_->ReleaseLock(); |
| 89 return; | 88 return; |
| 90 } | 89 } |
| 91 | 90 |
| 92 if (!updater_) | 91 if (!updater_) |
| 93 updater_.reset(new VideoResourceUpdater(resource_provider)); | 92 updater_.reset(new VideoResourceUpdater(resource_provider)); |
| 94 | 93 |
| 95 VideoFrameExternalResources external_resources; | 94 VideoFrameExternalResources external_resources = |
| 96 if (frame_->format() == media::VideoFrame::NATIVE_TEXTURE) | 95 updater_->CreateExternalResourcesFromVideoFrame(frame_); |
| 97 external_resources = updater_->CreateForHardwarePlanes(frame_); | |
| 98 else | |
| 99 external_resources = updater_->CreateForSoftwarePlanes(frame_); | |
| 100 | |
| 101 frame_resource_type_ = external_resources.type; | 96 frame_resource_type_ = external_resources.type; |
| 102 | 97 |
| 103 if (external_resources.type == | 98 if (external_resources.type == |
| 104 VideoFrameExternalResources::SOFTWARE_RESOURCE) { | 99 VideoFrameExternalResources::SOFTWARE_RESOURCE) { |
| 105 software_resources_ = external_resources.software_resources; | 100 software_resources_ = external_resources.software_resources; |
| 106 software_release_callback_ = | 101 software_release_callback_ = |
| 107 external_resources.software_release_callback; | 102 external_resources.software_release_callback; |
| 108 return; | 103 return; |
| 109 } | 104 } |
| 110 | 105 |
| 111 if (external_resources.hardware_resource) { | |
| 112 hardware_resource_ = external_resources.hardware_resource; | |
| 113 hardware_release_callback_ = | |
| 114 external_resources.hardware_release_callback; | |
| 115 return; | |
| 116 } | |
| 117 | |
| 118 for (size_t i = 0; i < external_resources.mailboxes.size(); ++i) { | 106 for (size_t i = 0; i < external_resources.mailboxes.size(); ++i) { |
| 119 frame_resources_.push_back( | 107 frame_resources_.push_back( |
| 120 resource_provider->CreateResourceFromTextureMailbox( | 108 resource_provider->CreateResourceFromTextureMailbox( |
| 121 external_resources.mailboxes[i])); | 109 external_resources.mailboxes[i])); |
| 122 } | 110 } |
| 123 } | 111 } |
| 124 | 112 |
| 125 void VideoLayerImpl::AppendQuads(QuadSink* quad_sink, | 113 void VideoLayerImpl::AppendQuads(QuadSink* quad_sink, |
| 126 AppendQuadsData* append_quads_data) { | 114 AppendQuadsData* append_quads_data) { |
| 127 if (!frame_) | 115 if (!frame_) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 quad_rect, | 165 quad_rect, |
| 178 opaque_rect, | 166 opaque_rect, |
| 179 tex_scale, | 167 tex_scale, |
| 180 frame_resources_[0], | 168 frame_resources_[0], |
| 181 frame_resources_[1], | 169 frame_resources_[1], |
| 182 frame_resources_[2]); | 170 frame_resources_[2]); |
| 183 quad_sink->Append(yuv_video_quad.PassAs<DrawQuad>(), append_quads_data); | 171 quad_sink->Append(yuv_video_quad.PassAs<DrawQuad>(), append_quads_data); |
| 184 break; | 172 break; |
| 185 } | 173 } |
| 186 case VideoFrameExternalResources::RGB_RESOURCE: { | 174 case VideoFrameExternalResources::RGB_RESOURCE: { |
| 187 if (!hardware_resource_) { | 175 DCHECK_EQ(frame_resources_.size(), 1u); |
| 188 DCHECK_EQ(frame_resources_.size(), 1u); | 176 if (frame_resources_.size() < 1u) |
| 189 if (frame_resources_.size() < 1u) | 177 break; |
| 190 break; | |
| 191 } | |
| 192 bool premultiplied_alpha = true; | 178 bool premultiplied_alpha = true; |
| 193 gfx::PointF uv_top_left(0.f, 0.f); | 179 gfx::PointF uv_top_left(0.f, 0.f); |
| 194 gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale); | 180 gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale); |
| 195 float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 181 float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 196 bool flipped = false; | 182 bool flipped = false; |
| 197 scoped_ptr<TextureDrawQuad> texture_quad = TextureDrawQuad::Create(); | 183 scoped_ptr<TextureDrawQuad> texture_quad = TextureDrawQuad::Create(); |
| 198 texture_quad->SetNew(shared_quad_state, | 184 texture_quad->SetNew(shared_quad_state, |
| 199 quad_rect, | 185 quad_rect, |
| 200 opaque_rect, | 186 opaque_rect, |
| 201 hardware_resource_ ? hardware_resource_ | 187 frame_resources_[0], |
| 202 : frame_resources_[0], | |
| 203 premultiplied_alpha, | 188 premultiplied_alpha, |
| 204 uv_top_left, | 189 uv_top_left, |
| 205 uv_bottom_right, | 190 uv_bottom_right, |
| 206 opacity, | 191 opacity, |
| 207 flipped); | 192 flipped); |
| 208 quad_sink->Append(texture_quad.PassAs<DrawQuad>(), append_quads_data); | 193 quad_sink->Append(texture_quad.PassAs<DrawQuad>(), append_quads_data); |
| 209 break; | 194 break; |
| 210 } | 195 } |
| 211 case VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE: { | 196 case VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE: { |
| 212 if (!hardware_resource_) { | 197 DCHECK_EQ(frame_resources_.size(), 1u); |
| 213 DCHECK_EQ(frame_resources_.size(), 1u); | 198 if (frame_resources_.size() < 1u) |
| 214 if (frame_resources_.size() < 1u) | 199 break; |
| 215 break; | |
| 216 } | |
| 217 gfx::Transform transform( | 200 gfx::Transform transform( |
| 218 provider_client_impl_->stream_texture_matrix()); | 201 provider_client_impl_->stream_texture_matrix()); |
| 219 transform.Scale(tex_width_scale, tex_height_scale); | 202 transform.Scale(tex_width_scale, tex_height_scale); |
| 220 scoped_ptr<StreamVideoDrawQuad> stream_video_quad = | 203 scoped_ptr<StreamVideoDrawQuad> stream_video_quad = |
| 221 StreamVideoDrawQuad::Create(); | 204 StreamVideoDrawQuad::Create(); |
| 222 stream_video_quad->SetNew(shared_quad_state, | 205 stream_video_quad->SetNew(shared_quad_state, |
| 223 quad_rect, | 206 quad_rect, |
| 224 opaque_rect, | 207 opaque_rect, |
| 225 hardware_resource_ ? hardware_resource_ | 208 frame_resources_[0], |
| 226 : frame_resources_[0], | |
| 227 transform); | 209 transform); |
| 228 quad_sink->Append(stream_video_quad.PassAs<DrawQuad>(), | 210 quad_sink->Append(stream_video_quad.PassAs<DrawQuad>(), |
| 229 append_quads_data); | 211 append_quads_data); |
| 230 break; | 212 break; |
| 231 } | 213 } |
| 232 case VideoFrameExternalResources::IO_SURFACE: { | 214 case VideoFrameExternalResources::IO_SURFACE: { |
| 233 if (!hardware_resource_) { | 215 DCHECK_EQ(frame_resources_.size(), 1u); |
| 234 DCHECK_EQ(frame_resources_.size(), 1u); | 216 if (frame_resources_.size() < 1u) |
| 235 if (frame_resources_.size() < 1u) | 217 break; |
| 236 break; | |
| 237 } | |
| 238 gfx::Size visible_size(visible_rect.width(), visible_rect.height()); | 218 gfx::Size visible_size(visible_rect.width(), visible_rect.height()); |
| 239 scoped_ptr<IOSurfaceDrawQuad> io_surface_quad = | 219 scoped_ptr<IOSurfaceDrawQuad> io_surface_quad = |
| 240 IOSurfaceDrawQuad::Create(); | 220 IOSurfaceDrawQuad::Create(); |
| 241 io_surface_quad->SetNew(shared_quad_state, | 221 io_surface_quad->SetNew(shared_quad_state, |
| 242 quad_rect, | 222 quad_rect, |
| 243 opaque_rect, | 223 opaque_rect, |
| 244 visible_size, | 224 visible_size, |
| 245 hardware_resource_ ? hardware_resource_ | 225 frame_resources_[0], |
| 246 : frame_resources_[0], | |
| 247 IOSurfaceDrawQuad::UNFLIPPED); | 226 IOSurfaceDrawQuad::UNFLIPPED); |
| 248 quad_sink->Append(io_surface_quad.PassAs<DrawQuad>(), | 227 quad_sink->Append(io_surface_quad.PassAs<DrawQuad>(), |
| 249 append_quads_data); | 228 append_quads_data); |
| 250 break; | 229 break; |
| 251 } | 230 } |
| 252 #if defined(GOOGLE_TV) | 231 #if defined(GOOGLE_TV) |
| 253 // This block and other blocks wrapped around #if defined(GOOGLE_TV) is not | 232 // This block and other blocks wrapped around #if defined(GOOGLE_TV) is not |
| 254 // maintained by the general compositor team. Please contact the following | 233 // maintained by the general compositor team. Please contact the following |
| 255 // people instead: | 234 // people instead: |
| 256 // | 235 // |
| (...skipping 25 matching lines...) Expand all Loading... |
| 282 if (!frame_) | 261 if (!frame_) |
| 283 return; | 262 return; |
| 284 | 263 |
| 285 if (frame_resource_type_ == | 264 if (frame_resource_type_ == |
| 286 VideoFrameExternalResources::SOFTWARE_RESOURCE) { | 265 VideoFrameExternalResources::SOFTWARE_RESOURCE) { |
| 287 for (size_t i = 0; i < software_resources_.size(); ++i) | 266 for (size_t i = 0; i < software_resources_.size(); ++i) |
| 288 software_release_callback_.Run(0, false); | 267 software_release_callback_.Run(0, false); |
| 289 | 268 |
| 290 software_resources_.clear(); | 269 software_resources_.clear(); |
| 291 software_release_callback_.Reset(); | 270 software_release_callback_.Reset(); |
| 292 } else if (hardware_resource_) { | |
| 293 hardware_release_callback_.Run(0, false); | |
| 294 hardware_resource_ = 0; | |
| 295 hardware_release_callback_.Reset(); | |
| 296 } else { | 271 } else { |
| 297 for (size_t i = 0; i < frame_resources_.size(); ++i) | 272 for (size_t i = 0; i < frame_resources_.size(); ++i) |
| 298 resource_provider->DeleteResource(frame_resources_[i]); | 273 resource_provider->DeleteResource(frame_resources_[i]); |
| 299 frame_resources_.clear(); | 274 frame_resources_.clear(); |
| 300 } | 275 } |
| 301 | 276 |
| 302 provider_client_impl_->PutCurrentFrame(frame_); | 277 provider_client_impl_->PutCurrentFrame(frame_); |
| 303 frame_ = NULL; | 278 frame_ = NULL; |
| 304 | 279 |
| 305 provider_client_impl_->ReleaseLock(); | 280 provider_client_impl_->ReleaseLock(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 317 void VideoLayerImpl::SetProviderClientImpl( | 292 void VideoLayerImpl::SetProviderClientImpl( |
| 318 scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl) { | 293 scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl) { |
| 319 provider_client_impl_ = provider_client_impl; | 294 provider_client_impl_ = provider_client_impl; |
| 320 } | 295 } |
| 321 | 296 |
| 322 const char* VideoLayerImpl::LayerTypeAsString() const { | 297 const char* VideoLayerImpl::LayerTypeAsString() const { |
| 323 return "VideoLayer"; | 298 return "VideoLayer"; |
| 324 } | 299 } |
| 325 | 300 |
| 326 } // namespace cc | 301 } // namespace cc |
| OLD | NEW |