| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/output/gl_renderer.h" | 9 #include "cc/output/gl_renderer.h" |
| 10 #include "cc/quads/draw_quad.h" | 10 #include "cc/quads/draw_quad.h" |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 memset(video_frame->data(media::VideoFrame::kVPlane), v, | 463 memset(video_frame->data(media::VideoFrame::kVPlane), v, |
| 464 video_frame->stride(media::VideoFrame::kVPlane) * | 464 video_frame->stride(media::VideoFrame::kVPlane) * |
| 465 video_frame->rows(media::VideoFrame::kVPlane)); | 465 video_frame->rows(media::VideoFrame::kVPlane)); |
| 466 | 466 |
| 467 uint8_t alpha_value = is_transparent ? 0 : 128; | 467 uint8_t alpha_value = is_transparent ? 0 : 128; |
| 468 CreateTestYUVVideoDrawQuad_FromVideoFrame( | 468 CreateTestYUVVideoDrawQuad_FromVideoFrame( |
| 469 shared_state, video_frame, alpha_value, tex_coord_rect, render_pass, | 469 shared_state, video_frame, alpha_value, tex_coord_rect, render_pass, |
| 470 video_resource_updater, rect, visible_rect, resource_provider); | 470 video_resource_updater, rect, visible_rect, resource_provider); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void CreateTestYUVVideoDrawQuad_NV12(const SharedQuadState* shared_state, |
| 474 media::ColorSpace video_frame_color_space, |
| 475 const gfx::RectF& tex_coord_rect, |
| 476 uint8_t y, |
| 477 uint8_t u, |
| 478 uint8_t v, |
| 479 RenderPass* render_pass, |
| 480 const gfx::Rect& rect, |
| 481 const gfx::Rect& visible_rect, |
| 482 ResourceProvider* resource_provider) { |
| 483 YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601; |
| 484 if (video_frame_color_space == media::COLOR_SPACE_JPEG) { |
| 485 color_space = YUVVideoDrawQuad::JPEG; |
| 486 } |
| 487 |
| 488 const gfx::Rect opaque_rect(0, 0, 0, 0); |
| 489 const gfx::Size ya_tex_size = rect.size(); |
| 490 const gfx::Size uv_tex_size = media::VideoFrame::PlaneSize( |
| 491 media::PIXEL_FORMAT_NV12, media::VideoFrame::kUVPlane, rect.size()); |
| 492 |
| 493 ResourceId y_resource = resource_provider->CreateResource( |
| 494 rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, |
| 495 resource_provider->YuvResourceFormat(8)); |
| 496 ResourceId u_resource = resource_provider->CreateResource( |
| 497 uv_tex_size, ResourceProvider::TEXTURE_HINT_DEFAULT, RGBA_8888); |
| 498 ResourceId v_resource = u_resource; |
| 499 ResourceId a_resource = 0; |
| 500 |
| 501 std::vector<uint8_t> y_pixels(ya_tex_size.GetArea(), y); |
| 502 resource_provider->CopyToResource(y_resource, y_pixels.data(), ya_tex_size); |
| 503 |
| 504 // U goes in the R component and V goes in the G component. |
| 505 uint32_t rgba_pixel = (u << 24) | (v << 16); |
| 506 std::vector<uint32_t> uv_pixels(uv_tex_size.GetArea(), rgba_pixel); |
| 507 resource_provider->CopyToResource( |
| 508 u_resource, reinterpret_cast<uint8_t*>(uv_pixels.data()), uv_tex_size); |
| 509 |
| 510 gfx::RectF ya_tex_coord_rect(tex_coord_rect.x() * ya_tex_size.width(), |
| 511 tex_coord_rect.y() * ya_tex_size.height(), |
| 512 tex_coord_rect.width() * ya_tex_size.width(), |
| 513 tex_coord_rect.height() * ya_tex_size.height()); |
| 514 gfx::RectF uv_tex_coord_rect(tex_coord_rect.x() * uv_tex_size.width(), |
| 515 tex_coord_rect.y() * uv_tex_size.height(), |
| 516 tex_coord_rect.width() * uv_tex_size.width(), |
| 517 tex_coord_rect.height() * uv_tex_size.height()); |
| 518 |
| 519 YUVVideoDrawQuad* yuv_quad = |
| 520 render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); |
| 521 yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, |
| 522 ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, |
| 523 uv_tex_size, y_resource, u_resource, v_resource, a_resource, |
| 524 color_space, 0.0f, 1.0f); |
| 525 } |
| 526 |
| 473 typedef ::testing::Types<GLRenderer, | 527 typedef ::testing::Types<GLRenderer, |
| 474 SoftwareRenderer, | 528 SoftwareRenderer, |
| 475 GLRendererWithExpandedViewport, | 529 GLRendererWithExpandedViewport, |
| 476 SoftwareRendererWithExpandedViewport> RendererTypes; | 530 SoftwareRendererWithExpandedViewport> RendererTypes; |
| 477 TYPED_TEST_CASE(RendererPixelTest, RendererTypes); | 531 TYPED_TEST_CASE(RendererPixelTest, RendererTypes); |
| 478 | 532 |
| 479 template <typename RendererType> | 533 template <typename RendererType> |
| 480 class SoftwareRendererPixelTest : public RendererPixelTest<RendererType> {}; | 534 class SoftwareRendererPixelTest : public RendererPixelTest<RendererType> {}; |
| 481 | 535 |
| 482 typedef ::testing::Types<SoftwareRenderer, SoftwareRendererWithExpandedViewport> | 536 typedef ::testing::Types<SoftwareRenderer, SoftwareRendererWithExpandedViewport> |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 video_resource_updater_.get(), rect, rect, resource_provider_.get()); | 1202 video_resource_updater_.get(), rect, rect, resource_provider_.get()); |
| 1149 | 1203 |
| 1150 RenderPassList pass_list; | 1204 RenderPassList pass_list; |
| 1151 pass_list.push_back(std::move(pass)); | 1205 pass_list.push_back(std::move(pass)); |
| 1152 | 1206 |
| 1153 EXPECT_TRUE(this->RunPixelTest(&pass_list, | 1207 EXPECT_TRUE(this->RunPixelTest(&pass_list, |
| 1154 base::FilePath(FILE_PATH_LITERAL("green.png")), | 1208 base::FilePath(FILE_PATH_LITERAL("green.png")), |
| 1155 FuzzyPixelOffByOneComparator(true))); | 1209 FuzzyPixelOffByOneComparator(true))); |
| 1156 } | 1210 } |
| 1157 | 1211 |
| 1212 TEST_F(VideoGLRendererPixelTest, SimpleNV12JRect) { |
| 1213 gfx::Rect rect(this->device_viewport_size_); |
| 1214 |
| 1215 RenderPassId id(1, 1); |
| 1216 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 1217 |
| 1218 SharedQuadState* shared_state = |
| 1219 CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); |
| 1220 |
| 1221 // YUV of (149,43,21) should be green (0,255,0) in RGB. |
| 1222 CreateTestYUVVideoDrawQuad_NV12( |
| 1223 shared_state, media::COLOR_SPACE_JPEG, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), |
| 1224 149, 43, 21, pass.get(), rect, rect, resource_provider_.get()); |
| 1225 |
| 1226 RenderPassList pass_list; |
| 1227 pass_list.push_back(std::move(pass)); |
| 1228 |
| 1229 EXPECT_TRUE(this->RunPixelTest(&pass_list, |
| 1230 base::FilePath(FILE_PATH_LITERAL("green.png")), |
| 1231 FuzzyPixelOffByOneComparator(true))); |
| 1232 } |
| 1233 |
| 1158 // Test that a YUV video doesn't bleed outside of its tex coords when the | 1234 // Test that a YUV video doesn't bleed outside of its tex coords when the |
| 1159 // tex coord rect is only a partial subrectangle of the coded contents. | 1235 // tex coord rect is only a partial subrectangle of the coded contents. |
| 1160 TEST_F(VideoGLRendererPixelTest, YUVEdgeBleed) { | 1236 TEST_F(VideoGLRendererPixelTest, YUVEdgeBleed) { |
| 1161 RenderPassList pass_list; | 1237 RenderPassList pass_list; |
| 1162 CreateEdgeBleedPass(media::PIXEL_FORMAT_YV12, media::COLOR_SPACE_JPEG, | 1238 CreateEdgeBleedPass(media::PIXEL_FORMAT_YV12, media::COLOR_SPACE_JPEG, |
| 1163 &pass_list); | 1239 &pass_list); |
| 1164 EXPECT_TRUE(this->RunPixelTest(&pass_list, | 1240 EXPECT_TRUE(this->RunPixelTest(&pass_list, |
| 1165 base::FilePath(FILE_PATH_LITERAL("green.png")), | 1241 base::FilePath(FILE_PATH_LITERAL("green.png")), |
| 1166 FuzzyPixelOffByOneComparator(true))); | 1242 FuzzyPixelOffByOneComparator(true))); |
| 1167 } | 1243 } |
| (...skipping 1932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3100 | 3176 |
| 3101 EXPECT_TRUE(this->RunPixelTest( | 3177 EXPECT_TRUE(this->RunPixelTest( |
| 3102 &pass_list, base::FilePath(FILE_PATH_LITERAL("spiral.png")), | 3178 &pass_list, base::FilePath(FILE_PATH_LITERAL("spiral.png")), |
| 3103 FuzzyPixelOffByOneComparator(true))); | 3179 FuzzyPixelOffByOneComparator(true))); |
| 3104 } | 3180 } |
| 3105 | 3181 |
| 3106 #endif // !defined(OS_ANDROID) | 3182 #endif // !defined(OS_ANDROID) |
| 3107 | 3183 |
| 3108 } // namespace | 3184 } // namespace |
| 3109 } // namespace cc | 3185 } // namespace cc |
| OLD | NEW |