summaryrefslogtreecommitdiff
path: root/chromium/media/renderers/paint_canvas_video_renderer_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/renderers/paint_canvas_video_renderer_unittest.cc')
-rw-r--r--chromium/media/renderers/paint_canvas_video_renderer_unittest.cc93
1 files changed, 47 insertions, 46 deletions
diff --git a/chromium/media/renderers/paint_canvas_video_renderer_unittest.cc b/chromium/media/renderers/paint_canvas_video_renderer_unittest.cc
index 5e7c448a269..991c8647359 100644
--- a/chromium/media/renderers/paint_canvas_video_renderer_unittest.cc
+++ b/chromium/media/renderers/paint_canvas_video_renderer_unittest.cc
@@ -11,9 +11,12 @@
#include "base/message_loop/message_loop.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/skia_paint_canvas.h"
+#include "components/viz/common/gpu/context_provider.h"
+#include "components/viz/test/test_context_provider.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/gles2_interface_stub.h"
#include "gpu/command_buffer/common/capabilities.h"
+#include "gpu/config/gpu_feature_info.h"
#include "media/base/timestamp_constants.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
@@ -76,18 +79,17 @@ class PaintCanvasVideoRendererTest : public testing::Test {
// Paints the |video_frame| to the |canvas| using |renderer_|, setting the
// color of |video_frame| to |color| first.
- void Paint(const scoped_refptr<VideoFrame>& video_frame,
+ void Paint(scoped_refptr<VideoFrame> video_frame,
cc::PaintCanvas* canvas,
Color color);
- void PaintRotated(const scoped_refptr<VideoFrame>& video_frame,
+ void PaintRotated(scoped_refptr<VideoFrame> video_frame,
cc::PaintCanvas* canvas,
const gfx::RectF& dest_rect,
Color color,
SkBlendMode mode,
- VideoRotation video_rotation);
+ VideoTransformation video_transformation);
- void Copy(const scoped_refptr<VideoFrame>& video_frame,
- cc::PaintCanvas* canvas);
+ void Copy(scoped_refptr<VideoFrame> video_frame, cc::PaintCanvas* canvas);
// Getters for various frame sizes.
scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; }
@@ -224,25 +226,24 @@ PaintCanvasVideoRendererTest::~PaintCanvasVideoRendererTest() = default;
void PaintCanvasVideoRendererTest::PaintWithoutFrame(cc::PaintCanvas* canvas) {
cc::PaintFlags flags;
flags.setFilterQuality(kLow_SkFilterQuality);
- renderer_.Paint(nullptr, canvas, kNaturalRect, flags, VIDEO_ROTATION_0,
- Context3D(), nullptr);
+ renderer_.Paint(nullptr, canvas, kNaturalRect, flags, kNoTransformation,
+ nullptr);
}
-void PaintCanvasVideoRendererTest::Paint(
- const scoped_refptr<VideoFrame>& video_frame,
- cc::PaintCanvas* canvas,
- Color color) {
- PaintRotated(video_frame, canvas, kNaturalRect, color, SkBlendMode::kSrcOver,
- VIDEO_ROTATION_0);
+void PaintCanvasVideoRendererTest::Paint(scoped_refptr<VideoFrame> video_frame,
+ cc::PaintCanvas* canvas,
+ Color color) {
+ PaintRotated(std::move(video_frame), canvas, kNaturalRect, color,
+ SkBlendMode::kSrcOver, kNoTransformation);
}
void PaintCanvasVideoRendererTest::PaintRotated(
- const scoped_refptr<VideoFrame>& video_frame,
+ scoped_refptr<VideoFrame> video_frame,
cc::PaintCanvas* canvas,
const gfx::RectF& dest_rect,
Color color,
SkBlendMode mode,
- VideoRotation video_rotation) {
+ VideoTransformation video_transformation) {
switch (color) {
case kNone:
break;
@@ -259,14 +260,13 @@ void PaintCanvasVideoRendererTest::PaintRotated(
cc::PaintFlags flags;
flags.setBlendMode(mode);
flags.setFilterQuality(kLow_SkFilterQuality);
- renderer_.Paint(video_frame, canvas, dest_rect, flags, video_rotation,
- Context3D(), nullptr);
+ renderer_.Paint(std::move(video_frame), canvas, dest_rect, flags,
+ video_transformation, nullptr);
}
-void PaintCanvasVideoRendererTest::Copy(
- const scoped_refptr<VideoFrame>& video_frame,
- cc::PaintCanvas* canvas) {
- renderer_.Copy(video_frame, canvas, Context3D(), nullptr);
+void PaintCanvasVideoRendererTest::Copy(scoped_refptr<VideoFrame> video_frame,
+ cc::PaintCanvas* canvas) {
+ renderer_.Copy(std::move(video_frame), canvas, nullptr);
}
TEST_F(PaintCanvasVideoRendererTest, NoFrame) {
@@ -281,7 +281,7 @@ TEST_F(PaintCanvasVideoRendererTest, TransparentFrame) {
PaintRotated(
VideoFrame::CreateTransparentFrame(gfx::Size(kWidth, kHeight)).get(),
target_canvas(), kNaturalRect, kNone, SkBlendMode::kSrcOver,
- VIDEO_ROTATION_0);
+ kNoTransformation);
EXPECT_EQ(static_cast<SkColor>(SK_ColorRED), bitmap()->getColor(0, 0));
}
@@ -291,7 +291,7 @@ TEST_F(PaintCanvasVideoRendererTest, TransparentFrameSrcMode) {
PaintRotated(
VideoFrame::CreateTransparentFrame(gfx::Size(kWidth, kHeight)).get(),
target_canvas(), kNaturalRect, kNone, SkBlendMode::kSrc,
- VIDEO_ROTATION_0);
+ kNoTransformation);
EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT),
bitmap()->getColor(0, 0));
}
@@ -383,7 +383,7 @@ TEST_F(PaintCanvasVideoRendererTest, Video_Rotation_90) {
SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
cc::SkiaPaintCanvas canvas(bitmap);
PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone,
- SkBlendMode::kSrcOver, VIDEO_ROTATION_90);
+ SkBlendMode::kSrcOver, VideoTransformation(VIDEO_ROTATION_90));
// Check the corners.
EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 0));
EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(kWidth - 1, 0));
@@ -395,7 +395,7 @@ TEST_F(PaintCanvasVideoRendererTest, Video_Rotation_180) {
SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
cc::SkiaPaintCanvas canvas(bitmap);
PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone,
- SkBlendMode::kSrcOver, VIDEO_ROTATION_180);
+ SkBlendMode::kSrcOver, VideoTransformation(VIDEO_ROTATION_180));
// Check the corners.
EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(0, 0));
EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(kWidth - 1, 0));
@@ -407,7 +407,7 @@ TEST_F(PaintCanvasVideoRendererTest, Video_Rotation_270) {
SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
cc::SkiaPaintCanvas canvas(bitmap);
PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone,
- SkBlendMode::kSrcOver, VIDEO_ROTATION_270);
+ SkBlendMode::kSrcOver, VideoTransformation(VIDEO_ROTATION_270));
// Check the corners.
EXPECT_EQ(SK_ColorRED, bitmap.getColor(0, 0));
EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(kWidth - 1, 0));
@@ -422,7 +422,7 @@ TEST_F(PaintCanvasVideoRendererTest, Video_Translate) {
PaintRotated(cropped_frame(), &canvas,
gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
- kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_0);
+ kNone, SkBlendMode::kSrcOver, kNoTransformation);
// Check the corners of quadrant 2 and 4.
EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, 0));
EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor((kWidth / 2) - 1, 0));
@@ -442,7 +442,8 @@ TEST_F(PaintCanvasVideoRendererTest, Video_Translate_Rotation_90) {
PaintRotated(cropped_frame(), &canvas,
gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
- kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_90);
+ kNone, SkBlendMode::kSrcOver,
+ VideoTransformation(VIDEO_ROTATION_90));
// Check the corners of quadrant 2 and 4.
EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, 0));
EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor((kWidth / 2) - 1, 0));
@@ -462,7 +463,8 @@ TEST_F(PaintCanvasVideoRendererTest, Video_Translate_Rotation_180) {
PaintRotated(cropped_frame(), &canvas,
gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
- kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_180);
+ kNone, SkBlendMode::kSrcOver,
+ VideoTransformation(VIDEO_ROTATION_180));
// Check the corners of quadrant 2 and 4.
EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, 0));
EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor((kWidth / 2) - 1, 0));
@@ -482,7 +484,8 @@ TEST_F(PaintCanvasVideoRendererTest, Video_Translate_Rotation_270) {
PaintRotated(cropped_frame(), &canvas,
gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
- kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_270);
+ kNone, SkBlendMode::kSrcOver,
+ VideoTransformation(VIDEO_ROTATION_270));
// Check the corners of quadrant 2 and 4.
EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, 0));
EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor((kWidth / 2) - 1, 0));
@@ -555,16 +558,16 @@ TEST_F(PaintCanvasVideoRendererTest, Y16) {
static_cast<unsigned char*>(base::AlignedAlloc(
byte_size, media::VideoFrame::kFrameAddressAlignment)));
const gfx::Rect rect(offset_x, offset_y, bitmap.width(), bitmap.height());
- scoped_refptr<media::VideoFrame> video_frame =
+ auto video_frame =
CreateTestY16Frame(gfx::Size(stride, offset_y + bitmap.height()), rect,
memory.get(), cropped_frame()->timestamp());
cc::SkiaPaintCanvas canvas(bitmap);
cc::PaintFlags flags;
flags.setFilterQuality(kNone_SkFilterQuality);
- renderer_.Paint(video_frame, &canvas,
+ renderer_.Paint(std::move(video_frame), &canvas,
gfx::RectF(bitmap.width(), bitmap.height()), flags,
- VIDEO_ROTATION_0, Context3D(), nullptr);
+ kNoTransformation, nullptr);
for (int j = 0; j < bitmap.height(); j++) {
for (int i = 0; i < bitmap.width(); i++) {
const int value = i + j * bitmap.width();
@@ -633,21 +636,19 @@ class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
const void* pixels)>
texsubimage2d_callback_;
};
+
void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {}
} // namespace
// Test that PaintCanvasVideoRenderer::Paint doesn't crash when GrContext is
-// unable to wrap a video frame texture (eg due to being abandoned). The mock
-// GrContext will fail to wrap the texture even if it is not abandoned, but we
-// leave the abandonContext call in place, in case that behavior changes.
+// unable to wrap a video frame texture (eg due to being abandoned).
TEST_F(PaintCanvasVideoRendererTest, ContextLost) {
- sk_sp<GrContext> gr_context = GrContext::MakeMock(nullptr);
- gr_context->abandonContext();
+ auto context_provider = viz::TestContextProvider::Create();
+ context_provider->BindToCurrentThread();
+ context_provider->GrContext()->abandonContext();
cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight));
- TestGLES2Interface gles2;
- Context3D context_3d(&gles2, gr_context.get());
gfx::Size size(kWidth, kHeight);
gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder(
gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB)};
@@ -657,8 +658,8 @@ TEST_F(PaintCanvasVideoRendererTest, ContextLost) {
cc::PaintFlags flags;
flags.setFilterQuality(kLow_SkFilterQuality);
- renderer_.Paint(video_frame, &canvas, kNaturalRect, flags, VIDEO_ROTATION_90,
- context_3d, nullptr);
+ renderer_.Paint(std::move(video_frame), &canvas, kNaturalRect, flags,
+ kNoTransformation, context_provider.get());
}
void EmptyCallback(const gpu::SyncToken& sync_token) {}
@@ -682,8 +683,8 @@ TEST_F(PaintCanvasVideoRendererTest, CorrectFrameSizeToVisibleRect) {
gfx::RectF visible_rect(visible_size.width(), visible_size.height());
cc::PaintFlags flags;
- renderer_.Paint(video_frame, &canvas, visible_rect, flags, VIDEO_ROTATION_0,
- Context3D(), nullptr);
+ renderer_.Paint(std::move(video_frame), &canvas, visible_rect, flags,
+ kNoTransformation, nullptr);
EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width());
EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height());
@@ -702,7 +703,7 @@ TEST_F(PaintCanvasVideoRendererTest, TexImage2D_Y16_RGBA32F) {
static_cast<unsigned char*>(base::AlignedAlloc(
byte_size, media::VideoFrame::kFrameAddressAlignment)));
const gfx::Rect rect(offset_x, offset_y, width, height);
- scoped_refptr<media::VideoFrame> video_frame =
+ auto video_frame =
CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect,
memory.get(), cropped_frame()->timestamp());
@@ -750,7 +751,7 @@ TEST_F(PaintCanvasVideoRendererTest, TexSubImage2D_Y16_R32F) {
static_cast<unsigned char*>(base::AlignedAlloc(
byte_size, media::VideoFrame::kFrameAddressAlignment)));
const gfx::Rect rect(offset_x, offset_y, width, height);
- scoped_refptr<media::VideoFrame> video_frame =
+ auto video_frame =
CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect,
memory.get(), cropped_frame()->timestamp());