Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: media/renderers/skcanvas_video_renderer.cc

Issue 2556943002: WebGL2 & 16-bit depth capture: Upload video to GL_RED float texture. (Closed)
Patch Set: --enable-es3-apis is required for WebGL2 on Android. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/renderers/skcanvas_video_renderer.h" 5 #include "media/renderers/skcanvas_video_renderer.h"
6 6
7 #include <GLES3/gl3.h>
7 #include <limits> 8 #include <limits>
8 9
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "gpu/GLES2/gl2extchromium.h" 11 #include "gpu/GLES2/gl2extchromium.h"
11 #include "gpu/command_buffer/client/gles2_interface.h" 12 #include "gpu/command_buffer/client/gles2_interface.h"
12 #include "gpu/command_buffer/common/mailbox_holder.h" 13 #include "gpu/command_buffer/common/mailbox_holder.h"
13 #include "media/base/data_buffer.h" 14 #include "media/base/data_buffer.h"
14 #include "media/base/video_frame.h" 15 #include "media/base/video_frame.h"
15 #include "media/base/yuv_convert.h" 16 #include "media/base/yuv_convert.h"
16 #include "skia/ext/texture_handle.h" 17 #include "skia/ext/texture_handle.h"
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 // When the |format| is RGBA, the converted value is fed as luminance. 528 // When the |format| is RGBA, the converted value is fed as luminance.
528 void FlipAndConvertY16(const VideoFrame* video_frame, 529 void FlipAndConvertY16(const VideoFrame* video_frame,
529 uint8_t* out, 530 uint8_t* out,
530 unsigned format, 531 unsigned format,
531 unsigned type, 532 unsigned type,
532 bool flip_y, 533 bool flip_y,
533 size_t output_row_bytes) { 534 size_t output_row_bytes) {
534 const uint8_t* row_head = video_frame->visible_data(0); 535 const uint8_t* row_head = video_frame->visible_data(0);
535 const size_t stride = video_frame->stride(0); 536 const size_t stride = video_frame->stride(0);
536 const int height = video_frame->visible_rect().height(); 537 const int height = video_frame->visible_rect().height();
537 for (int i = 0; i < height; ++i) { 538 for (int i = 0; i < height; ++i, row_head += stride) {
538 uint8_t* out_row_head = flip_y ? out + output_row_bytes * (height - i - 1) 539 uint8_t* out_row_head = flip_y ? out + output_row_bytes * (height - i - 1)
539 : out + output_row_bytes * i; 540 : out + output_row_bytes * i;
540 const uint16_t* row = reinterpret_cast<const uint16_t*>(row_head); 541 const uint16_t* row = reinterpret_cast<const uint16_t*>(row_head);
541 const uint16_t* row_end = row + video_frame->visible_rect().width(); 542 const uint16_t* row_end = row + video_frame->visible_rect().width();
542 if (type == GL_FLOAT) { 543 if (type == GL_FLOAT) {
543 DCHECK_EQ(static_cast<unsigned>(GL_RGBA), format);
544 float* out_row = reinterpret_cast<float*>(out_row_head); 544 float* out_row = reinterpret_cast<float*>(out_row_head);
545 while (row < row_end) { 545 if (format == GL_RGBA) {
546 float gray_value = *row++ / 65535.f; 546 while (row < row_end) {
547 *out_row++ = gray_value; 547 float gray_value = *row++ / 65535.f;
548 *out_row++ = gray_value; 548 *out_row++ = gray_value;
549 *out_row++ = gray_value; 549 *out_row++ = gray_value;
550 *out_row++ = 1.0f; 550 *out_row++ = gray_value;
551 *out_row++ = 1.0f;
552 }
553 continue;
554 } else if (format == GL_RED) {
555 while (row < row_end)
556 *out_row++ = *row++ / 65535.f;
557 continue;
551 } 558 }
559 // For other formats, hit NOTREACHED bellow.
552 } else if (type == GL_UNSIGNED_BYTE) { 560 } else if (type == GL_UNSIGNED_BYTE) {
553 // We take the upper 8 bits of 16-bit data and convert it as luminance to 561 // We take the upper 8 bits of 16-bit data and convert it as luminance to
554 // ARGB. We loose the precision here, but it is important not to render 562 // ARGB. We loose the precision here, but it is important not to render
555 // Y16 as RG_88. To get the full precision use float textures with WebGL1 563 // Y16 as RG_88. To get the full precision use float textures with WebGL1
556 // and e.g. R16UI or R32F textures with WebGL2. 564 // and e.g. R16UI or R32F textures with WebGL2.
557 DCHECK_EQ(static_cast<unsigned>(GL_RGBA), format); 565 DCHECK_EQ(static_cast<unsigned>(GL_RGBA), format);
558 uint32_t* rgba = reinterpret_cast<uint32_t*>(out_row_head); 566 uint32_t* rgba = reinterpret_cast<uint32_t*>(out_row_head);
559 while (row < row_end) { 567 while (row < row_end) {
560 uint32_t gray_value = *row++ >> 8; 568 uint32_t gray_value = *row++ >> 8;
561 *rgba++ = SkColorSetRGB(gray_value, gray_value, gray_value); 569 *rgba++ = SkColorSetRGB(gray_value, gray_value, gray_value);
562 } 570 }
563 } else { 571 continue;
564 NOTREACHED() << "Unsupported Y16 conversion for format: 0x" << std::hex
565 << format << " and type: 0x" << std::hex << type;
566 } 572 }
567 row_head += stride; 573 NOTREACHED() << "Unsupported Y16 conversion for format: 0x" << std::hex
574 << format << " and type: 0x" << std::hex << type;
568 } 575 }
569 } 576 }
570 577
571 // Common functionality of SkCanvasVideoRenderer's TexImage2D and TexSubImage2D. 578 // Common functionality of SkCanvasVideoRenderer's TexImage2D and TexSubImage2D.
572 // Allocates a buffer required for conversion and converts |frame| content to 579 // Allocates a buffer required for conversion and converts |frame| content to
573 // desired |format|. 580 // desired |format|.
574 // Returns true if calling glTex(Sub)Image is supported for provided |frame| 581 // Returns true if calling glTex(Sub)Image is supported for provided |frame|
575 // format and parameters. 582 // format and parameters.
576 bool TexImageHelper(VideoFrame* frame, 583 bool TexImageHelper(VideoFrame* frame,
577 unsigned format, 584 unsigned format,
578 unsigned type, 585 unsigned type,
579 bool flip_y, 586 bool flip_y,
580 scoped_refptr<DataBuffer>* temp_buffer) { 587 scoped_refptr<DataBuffer>* temp_buffer) {
581 unsigned output_bytes_per_pixel = 0; 588 unsigned output_bytes_per_pixel = 0;
582 switch (frame->format()) { 589 switch (frame->format()) {
583 case PIXEL_FORMAT_Y16: 590 case PIXEL_FORMAT_Y16:
584 // Converting single component unsigned short here to FLOAT luminance. 591 // Converting single component unsigned short here to FLOAT luminance.
585 switch (format) { 592 switch (format) {
586 case GL_RGBA: 593 case GL_RGBA:
587 if (type == GL_FLOAT) { 594 if (type == GL_FLOAT) {
588 output_bytes_per_pixel = 4 * sizeof(GLfloat); 595 output_bytes_per_pixel = 4 * sizeof(GLfloat);
589 break; 596 break;
590 } 597 }
591 // Pass through. 598 return false;
599 case GL_RED:
600 if (type == GL_FLOAT) {
601 output_bytes_per_pixel = sizeof(GLfloat);
602 break;
603 }
604 return false;
592 default: 605 default:
593 return false; 606 return false;
594 } 607 }
595 break; 608 break;
596 default: 609 default:
597 return false; 610 return false;
598 } 611 }
599 612
600 size_t output_row_bytes = 613 size_t output_row_bytes =
601 frame->visible_rect().width() * output_bytes_per_pixel; 614 frame->visible_rect().width() * output_bytes_per_pixel;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 last_image_->bounds().contains(visible_rect)) { 945 last_image_->bounds().contains(visible_rect)) {
933 last_image_ = last_image_->makeSubset(visible_rect); 946 last_image_ = last_image_->makeSubset(visible_rect);
934 } 947 }
935 } 948 }
936 949
937 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { 950 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() {
938 return last_image_dimensions_for_testing_; 951 return last_image_dimensions_for_testing_;
939 } 952 }
940 953
941 } // namespace media 954 } // namespace media
OLDNEW
« no previous file with comments | « content/test/gpu/gpu_tests/depth_capture_integration_test.py ('k') | media/renderers/skcanvas_video_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698