| 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 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 const SharedQuadState* shared_state, | 205 const SharedQuadState* shared_state, |
| 206 scoped_refptr<media::VideoFrame> video_frame, | 206 scoped_refptr<media::VideoFrame> video_frame, |
| 207 uint8_t alpha_value, | 207 uint8_t alpha_value, |
| 208 const gfx::RectF& tex_coord_rect, | 208 const gfx::RectF& tex_coord_rect, |
| 209 RenderPass* render_pass, | 209 RenderPass* render_pass, |
| 210 VideoResourceUpdater* video_resource_updater, | 210 VideoResourceUpdater* video_resource_updater, |
| 211 const gfx::Rect& rect, | 211 const gfx::Rect& rect, |
| 212 const gfx::Rect& visible_rect, | 212 const gfx::Rect& visible_rect, |
| 213 ResourceProvider* resource_provider) { | 213 ResourceProvider* resource_provider) { |
| 214 const bool with_alpha = (video_frame->format() == media::PIXEL_FORMAT_YV12A); | 214 const bool with_alpha = (video_frame->format() == media::PIXEL_FORMAT_YV12A); |
| 215 YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601; | |
| 216 int video_frame_color_space; | |
| 217 if (video_frame->metadata()->GetInteger( | |
| 218 media::VideoFrameMetadata::COLOR_SPACE, &video_frame_color_space) && | |
| 219 video_frame_color_space == media::COLOR_SPACE_JPEG) { | |
| 220 color_space = YUVVideoDrawQuad::JPEG; | |
| 221 } | |
| 222 | |
| 223 gfx::ColorSpace video_color_space = video_frame->ColorSpace(); | |
| 224 | 215 |
| 225 const gfx::Rect opaque_rect(0, 0, 0, 0); | 216 const gfx::Rect opaque_rect(0, 0, 0, 0); |
| 226 | 217 |
| 227 if (with_alpha) { | 218 if (with_alpha) { |
| 228 memset(video_frame->data(media::VideoFrame::kAPlane), alpha_value, | 219 memset(video_frame->data(media::VideoFrame::kAPlane), alpha_value, |
| 229 video_frame->stride(media::VideoFrame::kAPlane) * | 220 video_frame->stride(media::VideoFrame::kAPlane) * |
| 230 video_frame->rows(media::VideoFrame::kAPlane)); | 221 video_frame->rows(media::VideoFrame::kAPlane)); |
| 231 } | 222 } |
| 232 | 223 |
| 233 VideoFrameExternalResources resources = | 224 VideoFrameExternalResources resources = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 uint32_t bits_per_channel = 8; | 278 uint32_t bits_per_channel = 8; |
| 288 if (video_frame->format() == media::PIXEL_FORMAT_YUV420P10 || | 279 if (video_frame->format() == media::PIXEL_FORMAT_YUV420P10 || |
| 289 video_frame->format() == media::PIXEL_FORMAT_YUV422P10 || | 280 video_frame->format() == media::PIXEL_FORMAT_YUV422P10 || |
| 290 video_frame->format() == media::PIXEL_FORMAT_YUV444P10) { | 281 video_frame->format() == media::PIXEL_FORMAT_YUV444P10) { |
| 291 bits_per_channel = 10; | 282 bits_per_channel = 10; |
| 292 } | 283 } |
| 293 | 284 |
| 294 yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, | 285 yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, |
| 295 ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, | 286 ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, |
| 296 uv_tex_size, y_resource, u_resource, v_resource, a_resource, | 287 uv_tex_size, y_resource, u_resource, v_resource, a_resource, |
| 297 color_space, video_color_space, 0.0f, 1.0f, | 288 0.0f, 1.0f, bits_per_channel); |
| 298 bits_per_channel); | |
| 299 } | 289 } |
| 300 | 290 |
| 301 void CreateTestY16TextureDrawQuad_FromVideoFrame( | 291 void CreateTestY16TextureDrawQuad_FromVideoFrame( |
| 302 const SharedQuadState* shared_state, | 292 const SharedQuadState* shared_state, |
| 303 scoped_refptr<media::VideoFrame> video_frame, | 293 scoped_refptr<media::VideoFrame> video_frame, |
| 304 const gfx::RectF& tex_coord_rect, | 294 const gfx::RectF& tex_coord_rect, |
| 305 RenderPass* render_pass, | 295 RenderPass* render_pass, |
| 306 VideoResourceUpdater* video_resource_updater, | 296 VideoResourceUpdater* video_resource_updater, |
| 307 const gfx::Rect& rect, | 297 const gfx::Rect& rect, |
| 308 const gfx::Rect& visible_rect, | 298 const gfx::Rect& visible_rect, |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 video_frame->stride(media::VideoFrame::kVPlane) * | 509 video_frame->stride(media::VideoFrame::kVPlane) * |
| 520 video_frame->rows(media::VideoFrame::kVPlane)); | 510 video_frame->rows(media::VideoFrame::kVPlane)); |
| 521 | 511 |
| 522 uint8_t alpha_value = is_transparent ? 0 : 128; | 512 uint8_t alpha_value = is_transparent ? 0 : 128; |
| 523 CreateTestYUVVideoDrawQuad_FromVideoFrame( | 513 CreateTestYUVVideoDrawQuad_FromVideoFrame( |
| 524 shared_state, video_frame, alpha_value, tex_coord_rect, render_pass, | 514 shared_state, video_frame, alpha_value, tex_coord_rect, render_pass, |
| 525 video_resource_updater, rect, visible_rect, resource_provider); | 515 video_resource_updater, rect, visible_rect, resource_provider); |
| 526 } | 516 } |
| 527 | 517 |
| 528 void CreateTestYUVVideoDrawQuad_NV12(const SharedQuadState* shared_state, | 518 void CreateTestYUVVideoDrawQuad_NV12(const SharedQuadState* shared_state, |
| 529 media::ColorSpace video_frame_color_space, | |
| 530 const gfx::ColorSpace& video_color_space, | 519 const gfx::ColorSpace& video_color_space, |
| 531 const gfx::RectF& tex_coord_rect, | 520 const gfx::RectF& tex_coord_rect, |
| 532 uint8_t y, | 521 uint8_t y, |
| 533 uint8_t u, | 522 uint8_t u, |
| 534 uint8_t v, | 523 uint8_t v, |
| 535 RenderPass* render_pass, | 524 RenderPass* render_pass, |
| 536 const gfx::Rect& rect, | 525 const gfx::Rect& rect, |
| 537 const gfx::Rect& visible_rect, | 526 const gfx::Rect& visible_rect, |
| 538 ResourceProvider* resource_provider) { | 527 ResourceProvider* resource_provider) { |
| 539 YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601; | |
| 540 if (video_frame_color_space == media::COLOR_SPACE_JPEG) { | |
| 541 color_space = YUVVideoDrawQuad::JPEG; | |
| 542 } | |
| 543 | |
| 544 const gfx::Rect opaque_rect(0, 0, 0, 0); | 528 const gfx::Rect opaque_rect(0, 0, 0, 0); |
| 545 const gfx::Size ya_tex_size = rect.size(); | 529 const gfx::Size ya_tex_size = rect.size(); |
| 546 const gfx::Size uv_tex_size = media::VideoFrame::PlaneSize( | 530 const gfx::Size uv_tex_size = media::VideoFrame::PlaneSize( |
| 547 media::PIXEL_FORMAT_NV12, media::VideoFrame::kUVPlane, rect.size()); | 531 media::PIXEL_FORMAT_NV12, media::VideoFrame::kUVPlane, rect.size()); |
| 548 | 532 |
| 549 ResourceId y_resource = resource_provider->CreateResource( | 533 ResourceId y_resource = resource_provider->CreateResource( |
| 550 rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, | 534 rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, |
| 551 resource_provider->YuvResourceFormat(8), gfx::ColorSpace()); | 535 resource_provider->YuvResourceFormat(8), video_color_space); |
| 552 ResourceId u_resource = resource_provider->CreateResource( | 536 ResourceId u_resource = resource_provider->CreateResource( |
| 553 uv_tex_size, ResourceProvider::TEXTURE_HINT_DEFAULT, RGBA_8888, | 537 uv_tex_size, ResourceProvider::TEXTURE_HINT_DEFAULT, RGBA_8888, |
| 554 gfx::ColorSpace()); | 538 video_color_space); |
| 555 ResourceId v_resource = u_resource; | 539 ResourceId v_resource = u_resource; |
| 556 ResourceId a_resource = 0; | 540 ResourceId a_resource = 0; |
| 557 | 541 |
| 558 std::vector<uint8_t> y_pixels(ya_tex_size.GetArea(), y); | 542 std::vector<uint8_t> y_pixels(ya_tex_size.GetArea(), y); |
| 559 resource_provider->CopyToResource(y_resource, y_pixels.data(), ya_tex_size); | 543 resource_provider->CopyToResource(y_resource, y_pixels.data(), ya_tex_size); |
| 560 | 544 |
| 561 // U goes in the R component and V goes in the G component. | 545 // U goes in the R component and V goes in the G component. |
| 562 uint32_t rgba_pixel = (u << 24) | (v << 16); | 546 uint32_t rgba_pixel = (u << 24) | (v << 16); |
| 563 std::vector<uint32_t> uv_pixels(uv_tex_size.GetArea(), rgba_pixel); | 547 std::vector<uint32_t> uv_pixels(uv_tex_size.GetArea(), rgba_pixel); |
| 564 resource_provider->CopyToResource( | 548 resource_provider->CopyToResource( |
| 565 u_resource, reinterpret_cast<uint8_t*>(uv_pixels.data()), uv_tex_size); | 549 u_resource, reinterpret_cast<uint8_t*>(uv_pixels.data()), uv_tex_size); |
| 566 | 550 |
| 567 gfx::RectF ya_tex_coord_rect(tex_coord_rect.x() * ya_tex_size.width(), | 551 gfx::RectF ya_tex_coord_rect(tex_coord_rect.x() * ya_tex_size.width(), |
| 568 tex_coord_rect.y() * ya_tex_size.height(), | 552 tex_coord_rect.y() * ya_tex_size.height(), |
| 569 tex_coord_rect.width() * ya_tex_size.width(), | 553 tex_coord_rect.width() * ya_tex_size.width(), |
| 570 tex_coord_rect.height() * ya_tex_size.height()); | 554 tex_coord_rect.height() * ya_tex_size.height()); |
| 571 gfx::RectF uv_tex_coord_rect(tex_coord_rect.x() * uv_tex_size.width(), | 555 gfx::RectF uv_tex_coord_rect(tex_coord_rect.x() * uv_tex_size.width(), |
| 572 tex_coord_rect.y() * uv_tex_size.height(), | 556 tex_coord_rect.y() * uv_tex_size.height(), |
| 573 tex_coord_rect.width() * uv_tex_size.width(), | 557 tex_coord_rect.width() * uv_tex_size.width(), |
| 574 tex_coord_rect.height() * uv_tex_size.height()); | 558 tex_coord_rect.height() * uv_tex_size.height()); |
| 575 | 559 |
| 576 YUVVideoDrawQuad* yuv_quad = | 560 YUVVideoDrawQuad* yuv_quad = |
| 577 render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); | 561 render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); |
| 578 yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, | 562 yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, |
| 579 ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, | 563 ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, |
| 580 uv_tex_size, y_resource, u_resource, v_resource, a_resource, | 564 uv_tex_size, y_resource, u_resource, v_resource, a_resource, |
| 581 color_space, video_color_space, 0.0f, 1.0f, 8); | 565 0.0f, 1.0f, 8); |
| 582 } | 566 } |
| 583 | 567 |
| 584 void CreateTestY16TextureDrawQuad_TwoColor( | 568 void CreateTestY16TextureDrawQuad_TwoColor( |
| 585 const SharedQuadState* shared_state, | 569 const SharedQuadState* shared_state, |
| 586 const gfx::RectF& tex_coord_rect, | 570 const gfx::RectF& tex_coord_rect, |
| 587 uint8_t g_foreground, | 571 uint8_t g_foreground, |
| 588 uint8_t g_background, | 572 uint8_t g_background, |
| 589 RenderPass* render_pass, | 573 RenderPass* render_pass, |
| 590 VideoResourceUpdater* video_resource_updater, | 574 VideoResourceUpdater* video_resource_updater, |
| 591 const gfx::Rect& rect, | 575 const gfx::Rect& rect, |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 TEST_F(VideoGLRendererPixelTest, SimpleNV12JRect) { | 1360 TEST_F(VideoGLRendererPixelTest, SimpleNV12JRect) { |
| 1377 gfx::Rect rect(this->device_viewport_size_); | 1361 gfx::Rect rect(this->device_viewport_size_); |
| 1378 | 1362 |
| 1379 int id = 1; | 1363 int id = 1; |
| 1380 std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | 1364 std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 1381 | 1365 |
| 1382 SharedQuadState* shared_state = | 1366 SharedQuadState* shared_state = |
| 1383 CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); | 1367 CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); |
| 1384 | 1368 |
| 1385 // YUV of (149,43,21) should be green (0,255,0) in RGB. | 1369 // YUV of (149,43,21) should be green (0,255,0) in RGB. |
| 1386 CreateTestYUVVideoDrawQuad_NV12( | 1370 CreateTestYUVVideoDrawQuad_NV12(shared_state, gfx::ColorSpace::CreateJpeg(), |
| 1387 shared_state, media::COLOR_SPACE_JPEG, gfx::ColorSpace::CreateJpeg(), | 1371 gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 149, 43, |
| 1388 gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 149, 43, 21, pass.get(), rect, rect, | 1372 21, pass.get(), rect, rect, |
| 1389 resource_provider_.get()); | 1373 resource_provider_.get()); |
| 1390 | 1374 |
| 1391 RenderPassList pass_list; | 1375 RenderPassList pass_list; |
| 1392 pass_list.push_back(std::move(pass)); | 1376 pass_list.push_back(std::move(pass)); |
| 1393 | 1377 |
| 1394 EXPECT_TRUE(this->RunPixelTest(&pass_list, | 1378 EXPECT_TRUE(this->RunPixelTest(&pass_list, |
| 1395 base::FilePath(FILE_PATH_LITERAL("green.png")), | 1379 base::FilePath(FILE_PATH_LITERAL("green.png")), |
| 1396 FuzzyPixelOffByOneComparator(true))); | 1380 FuzzyPixelOffByOneComparator(true))); |
| 1397 } | 1381 } |
| 1398 | 1382 |
| 1399 // Test that a YUV video doesn't bleed outside of its tex coords when the | 1383 // Test that a YUV video doesn't bleed outside of its tex coords when the |
| (...skipping 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3380 | 3364 |
| 3381 EXPECT_TRUE(this->RunPixelTest(&pass_list, base::FilePath(FILE_PATH_LITERAL( | 3365 EXPECT_TRUE(this->RunPixelTest(&pass_list, base::FilePath(FILE_PATH_LITERAL( |
| 3382 "translucent_rectangles.png")), | 3366 "translucent_rectangles.png")), |
| 3383 ExactPixelComparator(true))); | 3367 ExactPixelComparator(true))); |
| 3384 } | 3368 } |
| 3385 | 3369 |
| 3386 #endif // !defined(OS_ANDROID) | 3370 #endif // !defined(OS_ANDROID) |
| 3387 | 3371 |
| 3388 } // namespace | 3372 } // namespace |
| 3389 } // namespace cc | 3373 } // namespace cc |
| OLD | NEW |