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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 void VideoResourceUpdater::DeleteResource(ResourceList::iterator resource_it) { | 131 void VideoResourceUpdater::DeleteResource(ResourceList::iterator resource_it) { |
132 DCHECK_EQ(resource_it->ref_count, 0); | 132 DCHECK_EQ(resource_it->ref_count, 0); |
133 resource_provider_->DeleteResource(resource_it->resource_id); | 133 resource_provider_->DeleteResource(resource_it->resource_id); |
134 all_resources_.erase(resource_it); | 134 all_resources_.erase(resource_it); |
135 } | 135 } |
136 | 136 |
137 VideoFrameExternalResources VideoResourceUpdater:: | 137 VideoFrameExternalResources VideoResourceUpdater:: |
138 CreateExternalResourcesFromVideoFrame( | 138 CreateExternalResourcesFromVideoFrame( |
139 const scoped_refptr<media::VideoFrame>& video_frame) { | 139 const scoped_refptr<media::VideoFrame>& video_frame) { |
140 if (!VerifyFrame(video_frame)) | 140 if (video_frame->format() == media::VideoFrame::UNKNOWN) |
141 return VideoFrameExternalResources(); | 141 return VideoFrameExternalResources(); |
142 | 142 |
143 if (video_frame->format() == media::VideoFrame::NATIVE_TEXTURE) | 143 if (video_frame->storage_type() == media::VideoFrame::STORAGE_TEXTURE) |
144 return CreateForHardwarePlanes(video_frame); | 144 return CreateForHardwarePlanes(video_frame); |
145 else | 145 else |
146 return CreateForSoftwarePlanes(video_frame); | 146 return CreateForSoftwarePlanes(video_frame); |
147 } | 147 } |
148 | 148 |
149 bool VideoResourceUpdater::VerifyFrame( | |
150 const scoped_refptr<media::VideoFrame>& video_frame) { | |
151 switch (video_frame->format()) { | |
152 // Acceptable inputs. | |
153 case media::VideoFrame::YV12: | |
154 case media::VideoFrame::I420: | |
155 case media::VideoFrame::YV12A: | |
156 case media::VideoFrame::YV16: | |
157 case media::VideoFrame::YV24: | |
158 case media::VideoFrame::NATIVE_TEXTURE: | |
159 #if defined(VIDEO_HOLE) | |
160 case media::VideoFrame::HOLE: | |
161 #endif // defined(VIDEO_HOLE) | |
162 case media::VideoFrame::ARGB: | |
163 return true; | |
164 | |
165 // Unacceptable inputs. ¯\(°_o)/¯ | |
166 case media::VideoFrame::UNKNOWN: | |
167 case media::VideoFrame::NV12: | |
168 break; | |
169 } | |
170 return false; | |
171 } | |
172 | |
173 // For frames that we receive in software format, determine the dimensions of | 149 // For frames that we receive in software format, determine the dimensions of |
174 // each plane in the frame. | 150 // each plane in the frame. |
175 static gfx::Size SoftwarePlaneDimension( | 151 static gfx::Size SoftwarePlaneDimension( |
176 const scoped_refptr<media::VideoFrame>& input_frame, | 152 const scoped_refptr<media::VideoFrame>& input_frame, |
177 bool software_compositor, | 153 bool software_compositor, |
178 size_t plane_index) { | 154 size_t plane_index) { |
179 if (!software_compositor) { | 155 if (!software_compositor) { |
180 return media::VideoFrame::PlaneSize( | 156 return media::VideoFrame::PlaneSize( |
181 input_frame->format(), plane_index, input_frame->coded_size()); | 157 input_frame->format(), plane_index, input_frame->coded_size()); |
182 } | 158 } |
183 return input_frame->coded_size(); | 159 return input_frame->coded_size(); |
184 } | 160 } |
185 | 161 |
186 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 162 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
187 const scoped_refptr<media::VideoFrame>& video_frame) { | 163 const scoped_refptr<media::VideoFrame>& video_frame) { |
188 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); | 164 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); |
189 media::VideoFrame::Format input_frame_format = video_frame->format(); | 165 const media::VideoFrame::Format input_frame_format = video_frame->format(); |
190 | 166 |
191 #if defined(VIDEO_HOLE) | 167 #if defined(VIDEO_HOLE) |
192 if (input_frame_format == media::VideoFrame::HOLE) { | 168 if (video_frame->storage_type() == media::VideoFrame::STORAGE_HOLE) { |
193 VideoFrameExternalResources external_resources; | 169 VideoFrameExternalResources external_resources; |
194 external_resources.type = VideoFrameExternalResources::HOLE; | 170 external_resources.type = VideoFrameExternalResources::HOLE; |
195 return external_resources; | 171 return external_resources; |
196 } | 172 } |
197 #endif // defined(VIDEO_HOLE) | 173 #endif // defined(VIDEO_HOLE) |
198 | 174 |
199 // Only YUV software video frames are supported. | 175 // Only YUV software video frames are supported. |
200 if (input_frame_format != media::VideoFrame::YV12 && | 176 if (!media::VideoFrame::IsYuvPlanar(input_frame_format)) { |
201 input_frame_format != media::VideoFrame::I420 && | 177 NOTREACHED() << media::VideoFrame::FormatToString(input_frame_format); |
202 input_frame_format != media::VideoFrame::YV12A && | |
203 input_frame_format != media::VideoFrame::YV16 && | |
204 input_frame_format != media::VideoFrame::YV24) { | |
205 NOTREACHED() << input_frame_format; | |
206 return VideoFrameExternalResources(); | 178 return VideoFrameExternalResources(); |
207 } | 179 } |
208 | 180 |
209 bool software_compositor = context_provider_ == NULL; | 181 const bool software_compositor = context_provider_ == NULL; |
210 | 182 |
211 ResourceFormat output_resource_format = | 183 ResourceFormat output_resource_format = |
212 resource_provider_->yuv_resource_format(); | 184 resource_provider_->yuv_resource_format(); |
213 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format); | 185 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format); |
214 | 186 |
215 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB | 187 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB |
216 // conversion here. That involves an extra copy of each frame to a bitmap. | 188 // conversion here. That involves an extra copy of each frame to a bitmap. |
217 // Obviously, this is suboptimal and should be addressed once ubercompositor | 189 // Obviously, this is suboptimal and should be addressed once ubercompositor |
218 // starts shaping up. | 190 // starts shaping up. |
219 if (software_compositor) { | 191 if (software_compositor) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 // returned by the compositor and emit a WaitSyncPointCHROMIUM on | 359 // returned by the compositor and emit a WaitSyncPointCHROMIUM on |
388 // |video_frame|'s previous sync point using the current GL context. | 360 // |video_frame|'s previous sync point using the current GL context. |
389 SyncPointClientImpl client(updater->context_provider_->ContextGL(), | 361 SyncPointClientImpl client(updater->context_provider_->ContextGL(), |
390 sync_point); | 362 sync_point); |
391 video_frame->UpdateReleaseSyncPoint(&client); | 363 video_frame->UpdateReleaseSyncPoint(&client); |
392 } | 364 } |
393 | 365 |
394 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( | 366 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( |
395 const scoped_refptr<media::VideoFrame>& video_frame) { | 367 const scoped_refptr<media::VideoFrame>& video_frame) { |
396 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); | 368 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); |
397 media::VideoFrame::Format frame_format = video_frame->format(); | 369 DCHECK_EQ(video_frame->storage_type(), media::VideoFrame::STORAGE_TEXTURE); |
398 | |
399 DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE); | |
400 if (!context_provider_) | 370 if (!context_provider_) |
401 return VideoFrameExternalResources(); | 371 return VideoFrameExternalResources(); |
402 | 372 |
403 size_t textures = | 373 const size_t textures = media::VideoFrame::NumPlanes(video_frame->format()); |
404 media::VideoFrame::NumTextures(video_frame->texture_format()); | |
405 DCHECK_GE(textures, 1u); | 374 DCHECK_GE(textures, 1u); |
406 VideoFrameExternalResources external_resources; | 375 VideoFrameExternalResources external_resources; |
407 switch (video_frame->texture_format()) { | 376 switch (video_frame->format()) { |
408 case media::VideoFrame::TEXTURE_RGBA: | 377 case media::VideoFrame::ARGB: |
409 case media::VideoFrame::TEXTURE_RGB: | 378 case media::VideoFrame::XRGB: |
410 DCHECK_EQ(1u, textures); | 379 DCHECK_EQ(1u, textures); |
411 switch (video_frame->mailbox_holder(0).texture_target) { | 380 switch (video_frame->mailbox_holder(0).texture_target) { |
412 case GL_TEXTURE_2D: | 381 case GL_TEXTURE_2D: |
413 if (video_frame->texture_format() == media::VideoFrame::TEXTURE_RGB) | 382 external_resources.type = |
414 external_resources.type = VideoFrameExternalResources::RGB_RESOURCE; | 383 (video_frame->format() == media::VideoFrame::XRGB) |
415 else | 384 ? VideoFrameExternalResources::RGB_RESOURCE |
416 external_resources.type = | 385 : VideoFrameExternalResources::RGBA_RESOURCE; |
417 VideoFrameExternalResources::RGBA_RESOURCE; | |
418 break; | 386 break; |
419 case GL_TEXTURE_EXTERNAL_OES: | 387 case GL_TEXTURE_EXTERNAL_OES: |
420 external_resources.type = | 388 external_resources.type = |
421 VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE; | 389 VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE; |
422 break; | 390 break; |
423 case GL_TEXTURE_RECTANGLE_ARB: | 391 case GL_TEXTURE_RECTANGLE_ARB: |
424 external_resources.type = VideoFrameExternalResources::IO_SURFACE; | 392 external_resources.type = VideoFrameExternalResources::IO_SURFACE; |
425 break; | 393 break; |
426 default: | 394 default: |
427 NOTREACHED(); | 395 NOTREACHED(); |
428 return VideoFrameExternalResources(); | 396 return VideoFrameExternalResources(); |
429 } | 397 } |
430 break; | 398 break; |
431 case media::VideoFrame::TEXTURE_YUV_420: | 399 case media::VideoFrame::I420: |
432 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; | 400 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; |
433 break; | 401 break; |
| 402 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 403 case media::VideoFrame::NV12: |
| 404 #endif |
| 405 case media::VideoFrame::YV12: |
| 406 case media::VideoFrame::YV16: |
| 407 case media::VideoFrame::YV24: |
| 408 case media::VideoFrame::YV12A: |
| 409 case media::VideoFrame::UNKNOWN: |
| 410 DLOG(ERROR) << "Unsupported Texture format" |
| 411 << media::VideoFrame::FormatToString(video_frame->format()); |
| 412 return external_resources; |
434 } | 413 } |
435 DCHECK_NE(VideoFrameExternalResources::NONE, external_resources.type); | 414 DCHECK_NE(VideoFrameExternalResources::NONE, external_resources.type); |
436 | 415 |
437 for (size_t i = 0; i < textures; ++i) { | 416 for (size_t i = 0; i < textures; ++i) { |
438 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); | 417 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); |
439 external_resources.mailboxes.push_back( | 418 external_resources.mailboxes.push_back( |
440 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, | 419 TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, |
441 mailbox_holder.sync_point)); | 420 mailbox_holder.sync_point)); |
442 external_resources.mailboxes.back().set_allow_overlay( | 421 external_resources.mailboxes.back().set_allow_overlay( |
443 video_frame->allow_overlay()); | 422 video_frame->allow_overlay()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 resource_it->ref_count = 0; | 455 resource_it->ref_count = 0; |
477 updater->DeleteResource(resource_it); | 456 updater->DeleteResource(resource_it); |
478 return; | 457 return; |
479 } | 458 } |
480 | 459 |
481 --resource_it->ref_count; | 460 --resource_it->ref_count; |
482 DCHECK_GE(resource_it->ref_count, 0); | 461 DCHECK_GE(resource_it->ref_count, 0); |
483 } | 462 } |
484 | 463 |
485 } // namespace cc | 464 } // namespace cc |
OLD | NEW |