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

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

Issue 2428263004: 16 bpp video stream capture, render and createImageBitmap(video) using (CPU) shared memory buffers (Closed)
Patch Set: Split webrtc_depth_capture_browsertest. Thanks phoglund@, Created 4 years, 1 month 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/aligned_memory.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "gpu/GLES2/gl2extchromium.h" 10 #include "gpu/GLES2/gl2extchromium.h"
10 #include "gpu/command_buffer/client/gles2_interface_stub.h" 11 #include "gpu/command_buffer/client/gles2_interface_stub.h"
11 #include "media/base/timestamp_constants.h" 12 #include "media/base/timestamp_constants.h"
12 #include "media/base/video_frame.h" 13 #include "media/base/video_frame.h"
13 #include "media/base/video_util.h" 14 #include "media/base/video_util.h"
14 #include "media/renderers/skcanvas_video_renderer.h" 15 #include "media/renderers/skcanvas_video_renderer.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/libyuv/include/libyuv/convert.h" 17 #include "third_party/libyuv/include/libyuv/convert.h"
17 #include "third_party/skia/include/core/SkCanvas.h" 18 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 EXPECT_EQ(SK_ColorBLACK, GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, 506 EXPECT_EQ(SK_ColorBLACK, GetColorAt(target_canvas(), kWidth * 1 / 8 - 1,
506 kHeight * 1 / 6 - 1)); 507 kHeight * 1 / 6 - 1));
507 EXPECT_EQ(SK_ColorRED, 508 EXPECT_EQ(SK_ColorRED,
508 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 1 / 6 - 1)); 509 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 1 / 6 - 1));
509 EXPECT_EQ(SK_ColorGREEN, 510 EXPECT_EQ(SK_ColorGREEN,
510 GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, kHeight * 3 / 6)); 511 GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, kHeight * 3 / 6));
511 EXPECT_EQ(SK_ColorBLUE, 512 EXPECT_EQ(SK_ColorBLUE,
512 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6)); 513 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6));
513 } 514 }
514 515
516 TEST_F(SkCanvasVideoRendererTest, Y16) {
517 SkBitmap bitmap;
518 bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
519
520 // |offset_x| and |offset_y| define visible rect's offset to coded rect.
521 const int offset_x = 3;
522 const int offset_y = 5;
523 const int stride = bitmap.width() + offset_x;
524 const size_t byte_size = stride * (bitmap.height() + offset_y) * 2;
525 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory(
526 static_cast<unsigned char*>(base::AlignedAlloc(
527 byte_size, media::VideoFrame::kFrameAddressAlignment)));
528
529 // In the visible rect, fill upper byte with [0-255] and lower with [255-0].
530 uint16_t* data = reinterpret_cast<uint16_t*>(memory.get());
531 for (int j = 0; j < bitmap.height(); j++) {
532 for (int i = 0; i < bitmap.width(); i++) {
533 const int value = i + j * bitmap.width();
534 data[(stride * (j + offset_y)) + i + offset_x] =
535 ((value & 0xFF) << 8) | (~value & 0xFF);
536 }
537 }
538 const gfx::Rect rect(offset_x, offset_y, bitmap.width(), bitmap.height());
539 scoped_refptr<media::VideoFrame> video_frame =
540 media::VideoFrame::WrapExternalData(
541 media::PIXEL_FORMAT_Y16,
542 gfx::Size(stride, offset_y + bitmap.height()), rect, rect.size(),
543 memory.get(), byte_size, cropped_frame()->timestamp());
544
545 SkCanvas canvas(bitmap);
546 SkPaint paint;
547 paint.setFilterQuality(kNone_SkFilterQuality);
548 renderer_.Paint(video_frame, &canvas,
549 gfx::RectF(bitmap.width(), bitmap.height()), paint,
550 VIDEO_ROTATION_0, Context3D());
551 SkAutoLockPixels lock(bitmap);
552 for (int j = 0; j < bitmap.height(); j++) {
553 for (int i = 0; i < bitmap.width(); i++) {
554 const int value = i + j * bitmap.width();
555 EXPECT_EQ(SkColorSetRGB(value, value, value), bitmap.getColor(i, j));
556 }
557 }
558 }
559
515 namespace { 560 namespace {
516 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { 561 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
517 public: 562 public:
518 void GenTextures(GLsizei n, GLuint* textures) override { 563 void GenTextures(GLsizei n, GLuint* textures) override {
519 DCHECK_EQ(1, n); 564 DCHECK_EQ(1, n);
520 *textures = 1; 565 *textures = 1;
521 } 566 }
522 }; 567 };
523 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} 568 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {}
524 } // namespace 569 } // namespace
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 gfx::RectF visible_rect(visible_size.width(), visible_size.height()); 629 gfx::RectF visible_rect(visible_size.width(), visible_size.height());
585 SkPaint paint; 630 SkPaint paint;
586 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0, 631 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0,
587 context_3d); 632 context_3d);
588 633
589 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width()); 634 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width());
590 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height()); 635 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height());
591 } 636 }
592 637
593 } // namespace media 638 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698