| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 switch (video_frame->mailbox_holder(0).texture_target) { | 60 switch (video_frame->mailbox_holder(0).texture_target) { |
| 61 case GL_TEXTURE_EXTERNAL_OES: | 61 case GL_TEXTURE_EXTERNAL_OES: |
| 62 return VideoFrameExternalResources::YUV_RESOURCE; | 62 return VideoFrameExternalResources::YUV_RESOURCE; |
| 63 case GL_TEXTURE_RECTANGLE_ARB: | 63 case GL_TEXTURE_RECTANGLE_ARB: |
| 64 return VideoFrameExternalResources::RGB_RESOURCE; | 64 return VideoFrameExternalResources::RGB_RESOURCE; |
| 65 default: | 65 default: |
| 66 NOTREACHED(); | 66 NOTREACHED(); |
| 67 break; | 67 break; |
| 68 } | 68 } |
| 69 break; | 69 break; |
| 70 case media::PIXEL_FORMAT_Y8: |
| 71 case media::PIXEL_FORMAT_Y16: |
| 72 return VideoFrameExternalResources::Y_RESOURCE; |
| 73 break; |
| 70 case media::PIXEL_FORMAT_YV12: | 74 case media::PIXEL_FORMAT_YV12: |
| 71 case media::PIXEL_FORMAT_YV16: | 75 case media::PIXEL_FORMAT_YV16: |
| 72 case media::PIXEL_FORMAT_YV24: | 76 case media::PIXEL_FORMAT_YV24: |
| 73 case media::PIXEL_FORMAT_YV12A: | 77 case media::PIXEL_FORMAT_YV12A: |
| 74 case media::PIXEL_FORMAT_NV21: | 78 case media::PIXEL_FORMAT_NV21: |
| 75 case media::PIXEL_FORMAT_YUY2: | 79 case media::PIXEL_FORMAT_YUY2: |
| 76 case media::PIXEL_FORMAT_RGB24: | 80 case media::PIXEL_FORMAT_RGB24: |
| 77 case media::PIXEL_FORMAT_RGB32: | 81 case media::PIXEL_FORMAT_RGB32: |
| 78 case media::PIXEL_FORMAT_MJPEG: | 82 case media::PIXEL_FORMAT_MJPEG: |
| 79 case media::PIXEL_FORMAT_MT21: | 83 case media::PIXEL_FORMAT_MT21: |
| 80 case media::PIXEL_FORMAT_YUV420P9: | 84 case media::PIXEL_FORMAT_YUV420P9: |
| 81 case media::PIXEL_FORMAT_YUV422P9: | 85 case media::PIXEL_FORMAT_YUV422P9: |
| 82 case media::PIXEL_FORMAT_YUV444P9: | 86 case media::PIXEL_FORMAT_YUV444P9: |
| 83 case media::PIXEL_FORMAT_YUV420P10: | 87 case media::PIXEL_FORMAT_YUV420P10: |
| 84 case media::PIXEL_FORMAT_YUV422P10: | 88 case media::PIXEL_FORMAT_YUV422P10: |
| 85 case media::PIXEL_FORMAT_YUV444P10: | 89 case media::PIXEL_FORMAT_YUV444P10: |
| 86 case media::PIXEL_FORMAT_UNKNOWN: | 90 case media::PIXEL_FORMAT_UNKNOWN: |
| 87 break; | 91 break; |
| 88 } | 92 } |
| 89 return VideoFrameExternalResources::NONE; | 93 return VideoFrameExternalResources::NONE; |
| 90 } | 94 } |
| 91 | 95 |
| 96 static const uint8_t exp_lookup_table_lower[256] = { |
| 97 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n |
| 98 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, |
| 99 2, 2, 2, 2, 2, LT(3), LT(4), LT(4), LT(5), LT(5), LT(5), |
| 100 LT(5), LT(6), LT(6), LT(6), LT(6), LT(6), LT(6), LT(6), LT(6)}; |
| 101 |
| 102 static const uint8_t exp_lookup_table_upper[256] = { |
| 103 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n |
| 104 7, 7, 8, 8, 9, 9, 9, 9, |
| 105 10, 10, 10, 10, 10, 10, 10, 10, |
| 106 LT(11), LT(12), LT(12), LT(13), LT(13), LT(13), LT(13), LT(14), |
| 107 LT(14), LT(14), LT(14), LT(14), LT(14), LT(14), LT(14)}; |
| 108 |
| 109 uint16_t ushort_to_half_float(uint16_t value) { |
| 110 unsigned short upper = value >> 8; |
| 111 unsigned short exponent = |
| 112 upper ? exp_lookup_table_upper[upper] : exp_lookup_table_lower[value]; |
| 113 return (exponent << 10) | (((value << (15 - exponent)) >> 6) & 0x3FF); |
| 114 } |
| 115 |
| 92 class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient { | 116 class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient { |
| 93 public: | 117 public: |
| 94 SyncTokenClientImpl(gpu::gles2::GLES2Interface* gl, | 118 SyncTokenClientImpl(gpu::gles2::GLES2Interface* gl, |
| 95 const gpu::SyncToken& sync_token) | 119 const gpu::SyncToken& sync_token) |
| 96 : gl_(gl), sync_token_(sync_token) {} | 120 : gl_(gl), sync_token_(sync_token) {} |
| 97 ~SyncTokenClientImpl() override {} | 121 ~SyncTokenClientImpl() override {} |
| 98 void GenerateSyncToken(gpu::SyncToken* sync_token) override { | 122 void GenerateSyncToken(gpu::SyncToken* sync_token) override { |
| 99 if (sync_token_.HasData()) { | 123 if (sync_token_.HasData()) { |
| 100 *sync_token = sync_token_; | 124 *sync_token = sync_token_; |
| 101 } else { | 125 } else { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 plane_index, input_frame->format(), coded_size.width()); | 267 plane_index, input_frame->format(), coded_size.width()); |
| 244 int plane_height = media::VideoFrame::Rows(plane_index, input_frame->format(), | 268 int plane_height = media::VideoFrame::Rows(plane_index, input_frame->format(), |
| 245 coded_size.height()); | 269 coded_size.height()); |
| 246 return gfx::Size(plane_width, plane_height); | 270 return gfx::Size(plane_width, plane_height); |
| 247 } | 271 } |
| 248 | 272 |
| 249 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 273 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
| 250 scoped_refptr<media::VideoFrame> video_frame) { | 274 scoped_refptr<media::VideoFrame> video_frame) { |
| 251 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); | 275 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); |
| 252 const media::VideoPixelFormat input_frame_format = video_frame->format(); | 276 const media::VideoPixelFormat input_frame_format = video_frame->format(); |
| 253 | |
| 254 // TODO(hubbe): Make this a video frame method. | 277 // TODO(hubbe): Make this a video frame method. |
| 255 int bits_per_channel = 0; | 278 int bits_per_channel = 0; |
| 256 switch (input_frame_format) { | 279 switch (input_frame_format) { |
| 257 case media::PIXEL_FORMAT_UNKNOWN: | 280 case media::PIXEL_FORMAT_UNKNOWN: |
| 258 NOTREACHED(); | 281 NOTREACHED(); |
| 259 // Fall through! | 282 // Fall through! |
| 260 case media::PIXEL_FORMAT_I420: | 283 case media::PIXEL_FORMAT_I420: |
| 261 case media::PIXEL_FORMAT_YV12: | 284 case media::PIXEL_FORMAT_YV12: |
| 262 case media::PIXEL_FORMAT_YV16: | 285 case media::PIXEL_FORMAT_YV16: |
| 263 case media::PIXEL_FORMAT_YV12A: | 286 case media::PIXEL_FORMAT_YV12A: |
| 264 case media::PIXEL_FORMAT_YV24: | 287 case media::PIXEL_FORMAT_YV24: |
| 265 case media::PIXEL_FORMAT_NV12: | 288 case media::PIXEL_FORMAT_NV12: |
| 266 case media::PIXEL_FORMAT_NV21: | 289 case media::PIXEL_FORMAT_NV21: |
| 267 case media::PIXEL_FORMAT_UYVY: | 290 case media::PIXEL_FORMAT_UYVY: |
| 268 case media::PIXEL_FORMAT_YUY2: | 291 case media::PIXEL_FORMAT_YUY2: |
| 269 case media::PIXEL_FORMAT_ARGB: | 292 case media::PIXEL_FORMAT_ARGB: |
| 270 case media::PIXEL_FORMAT_XRGB: | 293 case media::PIXEL_FORMAT_XRGB: |
| 271 case media::PIXEL_FORMAT_RGB24: | 294 case media::PIXEL_FORMAT_RGB24: |
| 272 case media::PIXEL_FORMAT_RGB32: | 295 case media::PIXEL_FORMAT_RGB32: |
| 273 case media::PIXEL_FORMAT_MJPEG: | 296 case media::PIXEL_FORMAT_MJPEG: |
| 274 case media::PIXEL_FORMAT_MT21: | 297 case media::PIXEL_FORMAT_MT21: |
| 298 case media::PIXEL_FORMAT_Y8: |
| 275 bits_per_channel = 8; | 299 bits_per_channel = 8; |
| 276 break; | 300 break; |
| 277 case media::PIXEL_FORMAT_YUV420P9: | 301 case media::PIXEL_FORMAT_YUV420P9: |
| 278 case media::PIXEL_FORMAT_YUV422P9: | 302 case media::PIXEL_FORMAT_YUV422P9: |
| 279 case media::PIXEL_FORMAT_YUV444P9: | 303 case media::PIXEL_FORMAT_YUV444P9: |
| 280 bits_per_channel = 9; | 304 bits_per_channel = 9; |
| 281 break; | 305 break; |
| 282 case media::PIXEL_FORMAT_YUV420P10: | 306 case media::PIXEL_FORMAT_YUV420P10: |
| 283 case media::PIXEL_FORMAT_YUV422P10: | 307 case media::PIXEL_FORMAT_YUV422P10: |
| 284 case media::PIXEL_FORMAT_YUV444P10: | 308 case media::PIXEL_FORMAT_YUV444P10: |
| 285 bits_per_channel = 10; | 309 bits_per_channel = 10; |
| 286 break; | 310 break; |
| 311 case media::PIXEL_FORMAT_Y16: |
| 312 bits_per_channel = 16; |
| 313 break; |
| 287 } | 314 } |
| 288 | 315 |
| 289 // Only YUV software video frames are supported. | 316 // Only YUV, Y8 and Y16 software video frames are supported. |
| 290 if (!media::IsYuvPlanar(input_frame_format)) { | 317 const bool isYuvPlanar = media::IsYuvPlanar(input_frame_format); |
| 318 if (!(isYuvPlanar || input_frame_format == media::PIXEL_FORMAT_Y16 || |
| 319 input_frame_format == media::PIXEL_FORMAT_Y8)) { |
| 291 NOTREACHED() << media::VideoPixelFormatToString(input_frame_format); | 320 NOTREACHED() << media::VideoPixelFormatToString(input_frame_format); |
| 292 return VideoFrameExternalResources(); | 321 return VideoFrameExternalResources(); |
| 293 } | 322 } |
| 294 | 323 |
| 324 ResourceFormat output_resource_format = |
| 325 (input_frame_format == media::PIXEL_FORMAT_Y16) |
| 326 ? resource_provider_->Y16ResourceFormat() |
| 327 : resource_provider_->YuvResourceFormat(bits_per_channel); |
| 328 |
| 295 const bool software_compositor = context_provider_ == NULL; | 329 const bool software_compositor = context_provider_ == NULL; |
| 296 | 330 |
| 297 ResourceFormat output_resource_format = | 331 if (input_frame_format == media::PIXEL_FORMAT_Y16) { |
| 298 resource_provider_->YuvResourceFormat(bits_per_channel); | 332 if (software_compositor) { |
| 333 NOTREACHED() << "Software compositor doesn't support PIXEL_FORMAT_Y16"; |
| 334 return VideoFrameExternalResources(); |
| 335 } else if (output_resource_format != ResourceFormat::RG_88) { |
| 336 NOTREACHED() << "PIXEL_FORMAT_Y16 video is not supported as it depends " |
| 337 "on unavailable ext_texture_rg support."; |
| 338 return VideoFrameExternalResources(); |
| 339 } |
| 340 } |
| 299 | 341 |
| 300 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format); | 342 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format); |
| 301 | 343 |
| 302 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB | 344 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB |
| 303 // conversion here. That involves an extra copy of each frame to a bitmap. | 345 // conversion here. That involves an extra copy of each frame to a bitmap. |
| 304 // Obviously, this is suboptimal and should be addressed once ubercompositor | 346 // Obviously, this is suboptimal and should be addressed once ubercompositor |
| 305 // starts shaping up. | 347 // starts shaping up. |
| 306 if (software_compositor) { | 348 if (software_compositor) { |
| 307 output_resource_format = kRGBResourceFormat; | 349 output_resource_format = kRGBResourceFormat; |
| 308 output_plane_count = 1; | 350 output_plane_count = 1; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 plane_resource.resource_id()); | 445 plane_resource.resource_id()); |
| 404 external_resources.software_release_callback = | 446 external_resources.software_release_callback = |
| 405 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id()); | 447 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id()); |
| 406 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; | 448 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; |
| 407 return external_resources; | 449 return external_resources; |
| 408 } | 450 } |
| 409 | 451 |
| 410 for (size_t i = 0; i < plane_resources.size(); ++i) { | 452 for (size_t i = 0; i < plane_resources.size(); ++i) { |
| 411 PlaneResource& plane_resource = *plane_resources[i]; | 453 PlaneResource& plane_resource = *plane_resources[i]; |
| 412 // Update each plane's resource id with its content. | 454 // Update each plane's resource id with its content. |
| 413 DCHECK_EQ(plane_resource.resource_format(), | 455 DCHECK_EQ(plane_resource.resource_format(), output_resource_format); |
| 414 resource_provider_->YuvResourceFormat(bits_per_channel)); | |
| 415 | 456 |
| 416 if (!plane_resource.Matches(video_frame->unique_id(), i)) { | 457 if (!plane_resource.Matches(video_frame->unique_id(), i)) { |
| 417 // We need to transfer data from |video_frame| to the plane resource. | 458 // We need to transfer data from |video_frame| to the plane resource. |
| 418 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. | 459 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. |
| 419 | 460 |
| 420 // The |resource_size_pixels| is the size of the resource we want to | 461 // The |resource_size_pixels| is the size of the resource we want to |
| 421 // upload to. | 462 // upload to. |
| 422 gfx::Size resource_size_pixels = plane_resource.resource_size(); | 463 gfx::Size resource_size_pixels = plane_resource.resource_size(); |
| 423 // The |video_stride_bytes| is the width of the video frame we are | 464 // The |video_stride_bytes| is the width of the video frame we are |
| 424 // uploading (including non-frame data to fill in the stride). | 465 // uploading (including non-frame data to fill in the stride). |
| 425 int video_stride_bytes = video_frame->stride(i); | 466 int video_stride_bytes = video_frame->stride(i); |
| 426 | 467 |
| 427 size_t bytes_per_row = ResourceUtil::UncheckedWidthInBytes<size_t>( | 468 size_t bytes_per_row = ResourceUtil::UncheckedWidthInBytes<size_t>( |
| 428 resource_size_pixels.width(), plane_resource.resource_format()); | 469 resource_size_pixels.width(), plane_resource.resource_format()); |
| 429 // Use 4-byte row alignment (OpenGL default) for upload performance. | 470 // Use 4-byte row alignment (OpenGL default) for upload performance. |
| 430 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 471 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. |
| 431 size_t upload_image_stride = | 472 size_t upload_image_stride = |
| 432 MathUtil::UncheckedRoundUp<size_t>(bytes_per_row, 4u); | 473 MathUtil::UncheckedRoundUp<size_t>(bytes_per_row, 4u); |
| 433 | 474 |
| 434 bool needs_conversion = false; | 475 bool needs_conversion = false; |
| 435 int shift = 0; | 476 int shift = 0; |
| 436 | 477 |
| 437 // LUMINANCE_F16 uses half-floats, so we always need a conversion step. | 478 // LUMINANCE_F16 uses half-floats, so we always need a conversion step. |
| 438 if (plane_resource.resource_format() == LUMINANCE_F16) { | 479 if (plane_resource.resource_format() == LUMINANCE_F16) { |
| 439 needs_conversion = true; | 480 needs_conversion = true; |
| 440 // Note that the current method of converting integers to half-floats | 481 // Note that the current method of converting integers to half-floats |
| 441 // stops working if you have more than 10 bits of data. | 482 // stops working if you have more than 10 bits of data. |
| 442 DCHECK_LE(bits_per_channel, 10); | 483 DCHECK(bits_per_channel < 10 || !isYuvPlanar); |
| 443 } else if (bits_per_channel > 8) { | 484 } else if (bits_per_channel > 8 && |
| 485 plane_resource.resource_format() != RG_88) { |
| 444 // If bits_per_channel > 8 and we can't use LUMINANCE_F16, we need to | 486 // If bits_per_channel > 8 and we can't use LUMINANCE_F16, we need to |
| 445 // shift the data down and create an 8-bit texture. | 487 // shift the data down and create an 8-bit texture. |
| 446 needs_conversion = true; | 488 needs_conversion = true; |
| 447 shift = bits_per_channel - 8; | 489 shift = bits_per_channel - 8; |
| 448 } | 490 } |
| 449 const uint8_t* pixels; | 491 const uint8_t* pixels; |
| 450 if (static_cast<int>(upload_image_stride) == video_stride_bytes && | 492 if (static_cast<int>(upload_image_stride) == video_stride_bytes && |
| 451 !needs_conversion) { | 493 !needs_conversion) { |
| 452 pixels = video_frame->data(i); | 494 pixels = video_frame->data(i); |
| 453 } else { | 495 } else { |
| 454 // Avoid malloc for each frame/plane if possible. | 496 // Avoid malloc for each frame/plane if possible. |
| 455 size_t needed_size = | 497 size_t needed_size = |
| 456 upload_image_stride * resource_size_pixels.height(); | 498 upload_image_stride * resource_size_pixels.height(); |
| 457 if (upload_pixels_.size() < needed_size) | 499 if (upload_pixels_.size() < needed_size) |
| 458 upload_pixels_.resize(needed_size); | 500 upload_pixels_.resize(needed_size); |
| 459 | 501 |
| 460 for (int row = 0; row < resource_size_pixels.height(); ++row) { | 502 for (int row = 0; row < resource_size_pixels.height(); ++row) { |
| 461 if (plane_resource.resource_format() == LUMINANCE_F16) { | 503 if (plane_resource.resource_format() == LUMINANCE_F16) { |
| 462 uint16_t* dst = reinterpret_cast<uint16_t*>( | 504 uint16_t* dst = reinterpret_cast<uint16_t*>( |
| 463 &upload_pixels_[upload_image_stride * row]); | 505 &upload_pixels_[upload_image_stride * row]); |
| 464 const uint16_t* src = reinterpret_cast<uint16_t*>( | 506 const uint16_t* src = reinterpret_cast<uint16_t*>( |
| 465 video_frame->data(i) + (video_stride_bytes * row)); | 507 video_frame->data(i) + (video_stride_bytes * row)); |
| 508 |
| 509 if (input_frame_format == media::PIXEL_FORMAT_Y16) { |
| 510 for (size_t i = 0; i < bytes_per_row / 2; i++) |
| 511 dst[i] = ushort_to_half_float(src[i]); |
| 512 continue; |
| 513 } |
| 466 // Micro-benchmarking indicates that the compiler does | 514 // Micro-benchmarking indicates that the compiler does |
| 467 // a good enough job of optimizing this loop that trying | 515 // a good enough job of optimizing this loop that trying |
| 468 // to manually operate on one uint64 at a time is not | 516 // to manually operate on one uint64 at a time is not |
| 469 // actually helpful. | 517 // actually helpful. |
| 470 // Note to future optimizers: Benchmark your optimizations! | 518 // Note to future optimizers: Benchmark your optimizations! |
| 471 for (size_t i = 0; i < bytes_per_row / 2; i++) | 519 for (size_t i = 0; i < bytes_per_row / 2; i++) |
| 472 dst[i] = src[i] | 0x3800; | 520 dst[i] = src[i] | 0x3800; |
| 473 } else if (shift != 0) { | 521 } else if (shift != 0) { |
| 474 // We have more-than-8-bit input which we need to shift | 522 // We have more-than-8-bit input which we need to shift |
| 475 // down to fit it into an 8-bit texture. | 523 // down to fit it into an 8-bit texture. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 488 } | 536 } |
| 489 } | 537 } |
| 490 pixels = &upload_pixels_[0]; | 538 pixels = &upload_pixels_[0]; |
| 491 } | 539 } |
| 492 | 540 |
| 493 resource_provider_->CopyToResource(plane_resource.resource_id(), pixels, | 541 resource_provider_->CopyToResource(plane_resource.resource_id(), pixels, |
| 494 resource_size_pixels); | 542 resource_size_pixels); |
| 495 plane_resource.SetUniqueId(video_frame->unique_id(), i); | 543 plane_resource.SetUniqueId(video_frame->unique_id(), i); |
| 496 } | 544 } |
| 497 | 545 |
| 498 if (plane_resource.resource_format() == LUMINANCE_F16) { | 546 if (plane_resource.resource_format() == LUMINANCE_F16 && isYuvPlanar) { |
| 499 // By OR-ing with 0x3800, 10-bit numbers become half-floats in the | 547 // By OR-ing with 0x3800, 10-bit numbers become half-floats in the |
| 500 // range [0.5..1) and 9-bit numbers get the range [0.5..0.75). | 548 // range [0.5..1) and 9-bit numbers get the range [0.5..0.75). |
| 501 // | 549 // |
| 502 // Half-floats are evaluated as: | 550 // Half-floats are evaluated as: |
| 503 // float value = pow(2.0, exponent - 25) * (0x400 + fraction); | 551 // float value = pow(2.0, exponent - 25) * (0x400 + fraction); |
| 504 // | 552 // |
| 505 // In our case the exponent is 14 (since we or with 0x3800) and | 553 // In our case the exponent is 14 (since we or with 0x3800) and |
| 506 // pow(2.0, 14-25) * 0x400 evaluates to 0.5 (our offset) and | 554 // pow(2.0, 14-25) * 0x400 evaluates to 0.5 (our offset) and |
| 507 // pow(2.0, 14-25) * fraction is [0..0.49951171875] for 10-bit and | 555 // pow(2.0, 14-25) * fraction is [0..0.49951171875] for 10-bit and |
| 508 // [0..0.24951171875] for 9-bit. | 556 // [0..0.24951171875] for 9-bit. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 520 | 568 |
| 521 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), | 569 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), |
| 522 resource_provider_->GetResourceTextureTarget( | 570 resource_provider_->GetResourceTextureTarget( |
| 523 plane_resource.resource_id())); | 571 plane_resource.resource_id())); |
| 524 mailbox.set_color_space(video_frame->ColorSpace()); | 572 mailbox.set_color_space(video_frame->ColorSpace()); |
| 525 external_resources.mailboxes.push_back(mailbox); | 573 external_resources.mailboxes.push_back(mailbox); |
| 526 external_resources.release_callbacks.push_back(base::Bind( | 574 external_resources.release_callbacks.push_back(base::Bind( |
| 527 &RecycleResource, AsWeakPtr(), plane_resource.resource_id())); | 575 &RecycleResource, AsWeakPtr(), plane_resource.resource_id())); |
| 528 } | 576 } |
| 529 | 577 |
| 530 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; | 578 external_resources.type = |
| 579 (output_resource_format == RG_88) |
| 580 ? VideoFrameExternalResources::Y_RESOURCE |
| 581 : (isYuvPlanar ? VideoFrameExternalResources::YUV_RESOURCE |
| 582 : VideoFrameExternalResources::RGB_RESOURCE); |
| 531 return external_resources; | 583 return external_resources; |
| 532 } | 584 } |
| 533 | 585 |
| 534 // static | 586 // static |
| 535 void VideoResourceUpdater::ReturnTexture( | 587 void VideoResourceUpdater::ReturnTexture( |
| 536 base::WeakPtr<VideoResourceUpdater> updater, | 588 base::WeakPtr<VideoResourceUpdater> updater, |
| 537 const scoped_refptr<media::VideoFrame>& video_frame, | 589 const scoped_refptr<media::VideoFrame>& video_frame, |
| 538 const gpu::SyncToken& sync_token, | 590 const gpu::SyncToken& sync_token, |
| 539 bool lost_resource, | 591 bool lost_resource, |
| 540 BlockingTaskRunner* main_thread_task_runner) { | 592 BlockingTaskRunner* main_thread_task_runner) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 video_frame->coded_size(), | 709 video_frame->coded_size(), |
| 658 video_frame->metadata()->IsTrue( | 710 video_frame->metadata()->IsTrue( |
| 659 media::VideoFrameMetadata::ALLOW_OVERLAY), | 711 media::VideoFrameMetadata::ALLOW_OVERLAY), |
| 660 false); | 712 false); |
| 661 mailbox.set_color_space(video_frame->ColorSpace()); | 713 mailbox.set_color_space(video_frame->ColorSpace()); |
| 662 external_resources.mailboxes.push_back(mailbox); | 714 external_resources.mailboxes.push_back(mailbox); |
| 663 external_resources.release_callbacks.push_back( | 715 external_resources.release_callbacks.push_back( |
| 664 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); | 716 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); |
| 665 } | 717 } |
| 666 } | 718 } |
| 719 |
| 720 external_resources.bits_per_channel = |
| 721 (video_frame->format() == media::PIXEL_FORMAT_Y16) ? 16 : 8; |
| 667 return external_resources; | 722 return external_resources; |
| 668 } | 723 } |
| 669 | 724 |
| 670 // static | 725 // static |
| 671 void VideoResourceUpdater::RecycleResource( | 726 void VideoResourceUpdater::RecycleResource( |
| 672 base::WeakPtr<VideoResourceUpdater> updater, | 727 base::WeakPtr<VideoResourceUpdater> updater, |
| 673 ResourceId resource_id, | 728 ResourceId resource_id, |
| 674 const gpu::SyncToken& sync_token, | 729 const gpu::SyncToken& sync_token, |
| 675 bool lost_resource, | 730 bool lost_resource, |
| 676 BlockingTaskRunner* main_thread_task_runner) { | 731 BlockingTaskRunner* main_thread_task_runner) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 696 if (lost_resource) { | 751 if (lost_resource) { |
| 697 resource_it->clear_refs(); | 752 resource_it->clear_refs(); |
| 698 updater->DeleteResource(resource_it); | 753 updater->DeleteResource(resource_it); |
| 699 return; | 754 return; |
| 700 } | 755 } |
| 701 | 756 |
| 702 resource_it->remove_ref(); | 757 resource_it->remove_ref(); |
| 703 } | 758 } |
| 704 | 759 |
| 705 } // namespace cc | 760 } // namespace cc |
| OLD | NEW |