Index: cc/output/renderer_pixeltest.cc |
diff --git a/cc/output/renderer_pixeltest.cc b/cc/output/renderer_pixeltest.cc |
index c62ae058d00de3a93b6a68d2ecc1a2a8cbc5a1c1..cb5e79f057b84db924577fda241dd21b9e2c8cb8 100644 |
--- a/cc/output/renderer_pixeltest.cc |
+++ b/cc/output/renderer_pixeltest.cc |
@@ -16,6 +16,7 @@ |
#include "cc/test/fake_raster_source.h" |
#include "cc/test/fake_recording_source.h" |
#include "cc/test/pixel_test.h" |
+#include "cc/test/test_in_process_context_provider.h" |
#include "gpu/command_buffer/client/gles2_interface.h" |
#include "media/base/video_frame.h" |
#include "third_party/skia/include/core/SkColorPriv.h" |
@@ -217,72 +218,90 @@ void CreateTestYUVVideoDrawQuad_FromVideoFrame( |
video_frame->rows(media::VideoFrame::kAPlane)); |
} |
- VideoFrameExternalResources resources = |
+ VideoFrameExternalResources external_resources = |
video_resource_updater->CreateExternalResourcesFromVideoFrame( |
video_frame); |
- EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
- EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()), |
- resources.mailboxes.size()); |
- EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()), |
- resources.release_callbacks.size()); |
- |
- ResourceId y_resource = resource_provider->CreateResourceFromTextureMailbox( |
- resources.mailboxes[media::VideoFrame::kYPlane], |
- SingleReleaseCallbackImpl::Create( |
- resources.release_callbacks[media::VideoFrame::kYPlane])); |
- ResourceId u_resource = resource_provider->CreateResourceFromTextureMailbox( |
- resources.mailboxes[media::VideoFrame::kUPlane], |
- SingleReleaseCallbackImpl::Create( |
- resources.release_callbacks[media::VideoFrame::kUPlane])); |
- ResourceId v_resource = resource_provider->CreateResourceFromTextureMailbox( |
- resources.mailboxes[media::VideoFrame::kVPlane], |
- SingleReleaseCallbackImpl::Create( |
- resources.release_callbacks[media::VideoFrame::kVPlane])); |
- ResourceId a_resource = 0; |
- if (with_alpha) { |
- a_resource = resource_provider->CreateResourceFromTextureMailbox( |
- resources.mailboxes[media::VideoFrame::kAPlane], |
- SingleReleaseCallbackImpl::Create( |
- resources.release_callbacks[media::VideoFrame::kAPlane])); |
+ ResourceProvider::ResourceIdArray resource_ids; |
+ resource_ids.reserve(external_resources.mailboxes.size()); |
+ for (size_t i = 0; i < external_resources.mailboxes.size(); ++i) { |
+ ResourceId resource_id = |
+ resource_provider->CreateResourceFromTextureMailbox( |
+ external_resources.mailboxes[i], external_resources.format, |
+ SingleReleaseCallbackImpl::Create( |
+ external_resources.release_callbacks[i]), |
+ external_resources.read_lock_fences_enabled); |
+ resource_ids.push_back(resource_id); |
} |
- const gfx::Size ya_tex_size = video_frame->coded_size(); |
- const gfx::Size uv_tex_size = media::VideoFrame::PlaneSize( |
- video_frame->format(), media::VideoFrame::kUPlane, |
- video_frame->coded_size()); |
- DCHECK(uv_tex_size == media::VideoFrame::PlaneSize( |
- video_frame->format(), media::VideoFrame::kVPlane, |
- video_frame->coded_size())); |
- if (with_alpha) { |
- DCHECK(ya_tex_size == media::VideoFrame::PlaneSize( |
- video_frame->format(), media::VideoFrame::kAPlane, |
- video_frame->coded_size())); |
- } |
+ switch (external_resources.type) { |
+ case VideoFrameExternalResources::YUV_RESOURCE: { |
+ EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()), |
+ external_resources.mailboxes.size()); |
+ EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()), |
+ external_resources.release_callbacks.size()); |
+ const gfx::Size ya_tex_size = video_frame->coded_size(); |
+ const gfx::Size uv_tex_size = media::VideoFrame::PlaneSize( |
+ video_frame->format(), media::VideoFrame::kUPlane, |
+ video_frame->coded_size()); |
+ DCHECK(uv_tex_size == |
+ media::VideoFrame::PlaneSize(video_frame->format(), |
+ media::VideoFrame::kVPlane, |
+ video_frame->coded_size())); |
+ if (with_alpha) { |
+ DCHECK(ya_tex_size == |
+ media::VideoFrame::PlaneSize(video_frame->format(), |
+ media::VideoFrame::kAPlane, |
+ video_frame->coded_size())); |
+ } |
- gfx::RectF ya_tex_coord_rect(tex_coord_rect.x() * ya_tex_size.width(), |
- tex_coord_rect.y() * ya_tex_size.height(), |
- tex_coord_rect.width() * ya_tex_size.width(), |
- tex_coord_rect.height() * ya_tex_size.height()); |
- gfx::RectF uv_tex_coord_rect(tex_coord_rect.x() * uv_tex_size.width(), |
- tex_coord_rect.y() * uv_tex_size.height(), |
- tex_coord_rect.width() * uv_tex_size.width(), |
- tex_coord_rect.height() * uv_tex_size.height()); |
+ gfx::RectF ya_tex_coord_rect( |
+ tex_coord_rect.x() * ya_tex_size.width(), |
+ tex_coord_rect.y() * ya_tex_size.height(), |
+ tex_coord_rect.width() * ya_tex_size.width(), |
+ tex_coord_rect.height() * ya_tex_size.height()); |
+ gfx::RectF uv_tex_coord_rect( |
+ tex_coord_rect.x() * uv_tex_size.width(), |
+ tex_coord_rect.y() * uv_tex_size.height(), |
+ tex_coord_rect.width() * uv_tex_size.width(), |
+ tex_coord_rect.height() * uv_tex_size.height()); |
+ |
+ YUVVideoDrawQuad* yuv_quad = |
+ render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); |
+ yuv_quad->SetNew( |
+ shared_state, rect, opaque_rect, visible_rect, ya_tex_coord_rect, |
+ uv_tex_coord_rect, ya_tex_size, uv_tex_size, resource_ids[0], |
+ resource_ids[1], |
+ resource_ids.size() > 2 ? resource_ids[2] : resource_ids[1], |
+ resource_ids.size() > 3 ? resource_ids[3] : 0, color_space, |
+ video_color_space, external_resources.offset, |
+ external_resources.multiplier, external_resources.bits_per_channel); |
+ break; |
+ } |
- YUVVideoDrawQuad* yuv_quad = |
- render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); |
- uint32_t bits_per_channel = 8; |
- if (video_frame->format() == media::PIXEL_FORMAT_YUV420P10 || |
- video_frame->format() == media::PIXEL_FORMAT_YUV422P10 || |
- video_frame->format() == media::PIXEL_FORMAT_YUV444P10) { |
- bits_per_channel = 10; |
+ case VideoFrameExternalResources::RGBA_RESOURCE: { |
+ EXPECT_EQ(1u, external_resources.mailboxes.size()); |
+ EXPECT_EQ(1u, external_resources.release_callbacks.size()); |
+ gfx::PointF uv_top_left(0.f, 0.f); |
+ gfx::Size coded_size = video_frame->coded_size(); |
+ gfx::Rect visible_sample_rect = video_frame->visible_rect(); |
+ const float tex_width_scale = |
+ static_cast<float>(visible_sample_rect.width()) / coded_size.width(); |
+ const float tex_height_scale = |
+ static_cast<float>(visible_sample_rect.height()) / |
+ coded_size.height(); |
+ gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale); |
+ float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
+ TextureDrawQuad* texture_quad = |
+ render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
+ texture_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, |
+ resource_ids[0], false, uv_top_left, uv_bottom_right, |
+ SK_ColorTRANSPARENT, opacity, false, false, false); |
+ break; |
+ } |
+ default: |
+ NOTREACHED(); |
} |
- |
- yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, |
- ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, |
- uv_tex_size, y_resource, u_resource, v_resource, a_resource, |
- color_space, video_color_space, 0.0f, 1.0f, |
- bits_per_channel); |
} |
// Upshift video frame to 10 bit. |
@@ -343,6 +362,8 @@ void CreateTestYUVVideoDrawQuad_Striped( |
ResourceProvider* resource_provider) { |
scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( |
format, rect.size(), rect, rect.size(), base::TimeDelta()); |
+ video_frame->metadata()->SetInteger(media::VideoFrameMetadata::COLOR_SPACE, |
+ YUVVideoDrawQuad::REC_601); |
// YUV values representing a striped pattern, for validating texture |
// coordinates for sampling. |
@@ -486,6 +507,7 @@ void CreateTestYUVVideoDrawQuad_Solid( |
void CreateTestYUVVideoDrawQuad_NV12(const SharedQuadState* shared_state, |
media::ColorSpace video_frame_color_space, |
const gfx::ColorSpace& video_color_space, |
+ ResourceFormat y_format, |
const gfx::RectF& tex_coord_rect, |
uint8_t y, |
uint8_t u, |
@@ -505,8 +527,8 @@ void CreateTestYUVVideoDrawQuad_NV12(const SharedQuadState* shared_state, |
media::PIXEL_FORMAT_NV12, media::VideoFrame::kUVPlane, rect.size()); |
ResourceId y_resource = resource_provider->CreateResource( |
- rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, |
- resource_provider->YuvResourceFormat(8), gfx::ColorSpace()); |
+ rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, y_format, |
+ gfx::ColorSpace()); |
ResourceId u_resource = resource_provider->CreateResource( |
uv_tex_size, ResourceProvider::TEXTURE_HINT_DEFAULT, RGBA_8888, |
gfx::ColorSpace()); |
@@ -1097,9 +1119,48 @@ class VideoGLRendererPixelTest : public GLRendererPixelTest { |
std::unique_ptr<VideoResourceUpdater> video_resource_updater_; |
}; |
+enum class HighbitTexture { |
+ Y8, |
+ RGBA_8888, |
+ LUMINANCE_F16, |
+ RG88, |
+}; |
+ |
class VideoGLRendererPixelHiLoTest |
: public VideoGLRendererPixelTest, |
- public ::testing::WithParamInterface<bool> {}; |
+ public ::testing::WithParamInterface< |
+ ::testing::tuple<bool, HighbitTexture>> { |
+ public: |
+ void SetSupportHighbitTexture(HighbitTexture texture) { |
+ TestInProcessContextProvider* context_provider = |
+ GetTestInProcessContextProvider(); |
+ switch (texture) { |
+ case HighbitTexture::Y8: |
+ context_provider->SetDisableOneComponentTextures(false); |
+ context_provider->SetSupportTextureHalfFloatLinear(false); |
+ break; |
+ case HighbitTexture::RGBA_8888: |
+ context_provider->SetDisableOneComponentTextures(true); |
+ context_provider->SetSupportTextureHalfFloatLinear(false); |
+ break; |
+ case HighbitTexture::LUMINANCE_F16: |
+ context_provider->SetDisableOneComponentTextures(false); |
+ context_provider->SetSupportTextureHalfFloatLinear(true); |
+ break; |
+ case HighbitTexture::RG88: |
+ video_resource_updater_->UseRGForTesting(true); |
+ context_provider->SetDisableOneComponentTextures(false); |
+ context_provider->SetSupportTextureHalfFloatLinear(false); |
+ break; |
+ } |
+ } |
+ |
+ private: |
+ TestInProcessContextProvider* GetTestInProcessContextProvider() { |
+ return static_cast<TestInProcessContextProvider*>( |
+ output_surface_->context_provider()); |
+ } |
+}; |
TEST_P(VideoGLRendererPixelHiLoTest, SimpleYUVRect) { |
gfx::Rect rect(this->device_viewport_size_); |
@@ -1110,7 +1171,9 @@ TEST_P(VideoGLRendererPixelHiLoTest, SimpleYUVRect) { |
SharedQuadState* shared_state = |
CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); |
- bool highbit = GetParam(); |
+ const bool highbit = testing::get<0>(GetParam()); |
+ const HighbitTexture format = testing::get<1>(GetParam()); |
+ SetSupportHighbitTexture(format); |
CreateTestYUVVideoDrawQuad_Striped( |
shared_state, media::PIXEL_FORMAT_YV12, false, highbit, |
gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(), |
@@ -1119,10 +1182,23 @@ TEST_P(VideoGLRendererPixelHiLoTest, SimpleYUVRect) { |
RenderPassList pass_list; |
pass_list.push_back(std::move(pass)); |
- EXPECT_TRUE( |
- this->RunPixelTest(&pass_list, |
- base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")), |
- FuzzyPixelOffByOneComparator(true))); |
+ base::FilePath file_path = |
+ base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")); |
+ // TODO(dshwang): investigate why results per configuraion are so different. |
+ // crbug.com/622133 |
+ if (format == HighbitTexture::RGBA_8888) { |
+ // Color space is so different, because this path doesn't respect video |
+ // color profile. |
+ file_path = base::FilePath(FILE_PATH_LITERAL("yuv_stripes_rgba.png")); |
+ } |
+ if (highbit && format == HighbitTexture::RG88) { |
+ // The 2d-linear filter result is different at many pixels. However, the |
+ // result is very similar to "yuv_stripes_rgba.png" in terms of 2d-linear |
+ // filter. The gpu default 2d-linear filter seems to overblur the image. |
+ file_path = base::FilePath(FILE_PATH_LITERAL("yuv_stripes_rg88.png")); |
+ } |
+ EXPECT_TRUE(this->RunPixelTest(&pass_list, file_path, |
+ FuzzyPixelOffByOneComparator(true))); |
} |
TEST_P(VideoGLRendererPixelHiLoTest, ClippedYUVRect) { |
@@ -1136,7 +1212,9 @@ TEST_P(VideoGLRendererPixelHiLoTest, ClippedYUVRect) { |
SharedQuadState* shared_state = |
CreateTestSharedQuadState(gfx::Transform(), viewport, pass.get()); |
- bool highbit = GetParam(); |
+ const bool highbit = testing::get<0>(GetParam()); |
+ const HighbitTexture format = testing::get<1>(GetParam()); |
+ SetSupportHighbitTexture(format); |
CreateTestYUVVideoDrawQuad_Striped( |
shared_state, media::PIXEL_FORMAT_YV12, false, highbit, |
gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(), |
@@ -1145,9 +1223,18 @@ TEST_P(VideoGLRendererPixelHiLoTest, ClippedYUVRect) { |
RenderPassList pass_list; |
pass_list.push_back(std::move(pass)); |
- EXPECT_TRUE(this->RunPixelTest( |
- &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped.png")), |
- FuzzyPixelOffByOneComparator(true))); |
+ base::FilePath file_path = |
+ base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped.png")); |
+ if (format == HighbitTexture::RGBA_8888) { |
+ file_path = |
+ base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped_rgba.png")); |
+ } |
+ if (highbit && format == HighbitTexture::RG88) { |
+ file_path = |
+ base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped_rg88.png")); |
+ } |
+ EXPECT_TRUE(this->RunPixelTest(&pass_list, file_path, |
+ FuzzyPixelOffByOneComparator(true))); |
} |
TEST_F(VideoGLRendererPixelHiLoTest, OffsetYUVRect) { |
@@ -1199,7 +1286,16 @@ TEST_F(VideoGLRendererPixelTest, SimpleYUVRectBlack) { |
} |
// First argument (test case prefix) is intentionally left empty. |
-INSTANTIATE_TEST_CASE_P(, VideoGLRendererPixelHiLoTest, ::testing::Bool()); |
+INSTANTIATE_TEST_CASE_P( |
+ , |
+ VideoGLRendererPixelHiLoTest, |
+ ::testing::Combine( |
+ ::testing::Bool(), |
+ ::testing::Values(HighbitTexture::Y8, |
+ HighbitTexture::RGBA_8888, |
+ // LUMINANCE_F16 requires --use-gpu-in-tests |
+ // HighbitTexture::LUMINANCE_F16, |
+ HighbitTexture::RG88))); |
TEST_F(VideoGLRendererPixelTest, SimpleYUVJRect) { |
gfx::Rect rect(this->device_viewport_size_); |
@@ -1233,11 +1329,13 @@ TEST_F(VideoGLRendererPixelTest, SimpleNV12JRect) { |
SharedQuadState* shared_state = |
CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); |
+ ResourceFormat y_format = video_resource_updater_->YuvResourceFormat(8); |
+ |
// YUV of (149,43,21) should be green (0,255,0) in RGB. |
CreateTestYUVVideoDrawQuad_NV12( |
shared_state, media::COLOR_SPACE_JPEG, gfx::ColorSpace::CreateJpeg(), |
- gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 149, 43, 21, pass.get(), rect, rect, |
- resource_provider_.get()); |
+ y_format, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 149, 43, 21, pass.get(), |
+ rect, rect, resource_provider_.get()); |
RenderPassList pass_list; |
pass_list.push_back(std::move(pass)); |