OLD | NEW |
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 Loading... |
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(SkColorSetARGB(255, value, value, value), |
| 556 bitmap.getColor(i, j)); |
| 557 } |
| 558 } |
| 559 } |
| 560 |
515 namespace { | 561 namespace { |
516 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { | 562 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { |
517 public: | 563 public: |
518 void GenTextures(GLsizei n, GLuint* textures) override { | 564 void GenTextures(GLsizei n, GLuint* textures) override { |
519 DCHECK_EQ(1, n); | 565 DCHECK_EQ(1, n); |
520 *textures = 1; | 566 *textures = 1; |
521 } | 567 } |
522 }; | 568 }; |
523 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} | 569 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} |
524 } // namespace | 570 } // namespace |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 gfx::RectF visible_rect(visible_size.width(), visible_size.height()); | 630 gfx::RectF visible_rect(visible_size.width(), visible_size.height()); |
585 SkPaint paint; | 631 SkPaint paint; |
586 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0, | 632 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0, |
587 context_3d); | 633 context_3d); |
588 | 634 |
589 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width()); | 635 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width()); |
590 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height()); | 636 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height()); |
591 } | 637 } |
592 | 638 |
593 } // namespace media | 639 } // namespace media |
OLD | NEW |