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

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

Issue 2369093002: Fixing repeated pixels when drawing HTML5 video to canvas. (Closed)
Patch Set: Minor corrections in unit test. Created 4 years, 2 months 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
« no previous file with comments | « media/renderers/skcanvas_video_renderer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "gpu/GLES2/gl2extchromium.h" 9 #include "gpu/GLES2/gl2extchromium.h"
10 #include "gpu/command_buffer/client/gles2_interface_stub.h" 10 #include "gpu/command_buffer/client/gles2_interface_stub.h"
11 #include "media/base/timestamp_constants.h" 11 #include "media/base/timestamp_constants.h"
12 #include "media/base/video_frame.h" 12 #include "media/base/video_frame.h"
13 #include "media/base/video_util.h" 13 #include "media/base/video_util.h"
14 #include "media/renderers/skcanvas_video_renderer.h" 14 #include "media/renderers/skcanvas_video_renderer.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/libyuv/include/libyuv/convert.h" 16 #include "third_party/libyuv/include/libyuv/convert.h"
17 #include "third_party/skia/include/core/SkCanvas.h" 17 #include "third_party/skia/include/core/SkCanvas.h"
18 #include "third_party/skia/include/core/SkImage.h"
18 #include "third_party/skia/include/core/SkRefCnt.h" 19 #include "third_party/skia/include/core/SkRefCnt.h"
20 #include "third_party/skia/include/core/SkSurface.h"
19 #include "third_party/skia/include/gpu/GrContext.h" 21 #include "third_party/skia/include/gpu/GrContext.h"
20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" 22 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
21 #include "ui/gfx/geometry/rect_f.h" 23 #include "ui/gfx/geometry/rect_f.h"
22 24
23 using media::VideoFrame; 25 using media::VideoFrame;
24 26
25 namespace media { 27 namespace media {
26 28
27 static const int kWidth = 320; 29 static const int kWidth = 320;
28 static const int kHeight = 240; 30 static const int kHeight = 240;
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB)}; 541 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB)};
540 auto video_frame = VideoFrame::WrapNativeTextures( 542 auto video_frame = VideoFrame::WrapNativeTextures(
541 PIXEL_FORMAT_UYVY, holders, base::Bind(MailboxHoldersReleased), size, 543 PIXEL_FORMAT_UYVY, holders, base::Bind(MailboxHoldersReleased), size,
542 gfx::Rect(size), size, kNoTimestamp); 544 gfx::Rect(size), size, kNoTimestamp);
543 545
544 SkPaint paint; 546 SkPaint paint;
545 paint.setFilterQuality(kLow_SkFilterQuality); 547 paint.setFilterQuality(kLow_SkFilterQuality);
546 renderer_.Paint(video_frame, &canvas, kNaturalRect, paint, VIDEO_ROTATION_90, 548 renderer_.Paint(video_frame, &canvas, kNaturalRect, paint, VIDEO_ROTATION_90,
547 context_3d); 549 context_3d);
548 } 550 }
551
552 void EmptyCallback(const gpu::SyncToken& sync_token) {}
553
554 TEST_F(SkCanvasVideoRendererTest, CorrectFrameSizeToVisibleRect) {
555 int fWidth{16}, fHeight{16};
556 SkImageInfo imInfo =
557 SkImageInfo::MakeN32(fWidth, fHeight, kOpaque_SkAlphaType);
558
559 sk_sp<const GrGLInterface> glInterface(GrGLCreateNullInterface());
560 sk_sp<GrContext> grContext(
561 GrContext::Create(kOpenGL_GrBackend,
562 reinterpret_cast<GrBackendContext>(glInterface.get())));
563
564 sk_sp<SkSurface> skSurface =
565 SkSurface::MakeRenderTarget(grContext.get(), SkBudgeted::kYes, imInfo);
566 SkCanvas* canvas = skSurface->getCanvas();
567
568 TestGLES2Interface gles2;
569 Context3D context_3d(&gles2, grContext.get());
570 gfx::Size coded_size(fWidth, fHeight);
571 gfx::Size visible_size(fWidth / 2, fHeight / 2);
572
573 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes];
574 for (size_t i = 0; i < VideoFrame::kMaxPlanes; i++) {
575 mailbox_holders[i] = gpu::MailboxHolder(
576 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB);
577 }
578
579 auto video_frame = VideoFrame::WrapNativeTextures(
580 PIXEL_FORMAT_I420, mailbox_holders, base::Bind(EmptyCallback), coded_size,
581 gfx::Rect(visible_size), visible_size,
582 base::TimeDelta::FromMilliseconds(4));
583
584 gfx::RectF visible_rect(visible_size.width(), visible_size.height());
585 SkPaint paint;
586 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0,
587 context_3d);
588
589 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width());
590 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height());
591 }
592
549 } // namespace media 593 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/skcanvas_video_renderer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698