| 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/memory/aligned_memory.h" |     9 #include "base/memory/aligned_memory.h" | 
|    10 #include "base/message_loop/message_loop.h" |    10 #include "base/message_loop/message_loop.h" | 
|    11 #include "cc/base/math_util.h" |    11 #include "cc/base/math_util.h" | 
|    12 #include "cc/paint/paint_flags.h" |    12 #include "cc/paint/paint_flags.h" | 
|    13 #include "cc/paint/skia_paint_canvas.h" |    13 #include "cc/paint/skia_paint_canvas.h" | 
|    14 #include "cc/quads/draw_quad.h" |    14 #include "cc/quads/draw_quad.h" | 
|    15 #include "cc/quads/picture_draw_quad.h" |    15 #include "cc/quads/picture_draw_quad.h" | 
|    16 #include "cc/quads/texture_draw_quad.h" |    16 #include "cc/quads/texture_draw_quad.h" | 
|    17 #include "cc/resources/video_resource_updater.h" |    17 #include "cc/resources/video_resource_updater.h" | 
|    18 #include "cc/test/fake_raster_source.h" |    18 #include "cc/test/fake_raster_source.h" | 
|    19 #include "cc/test/fake_recording_source.h" |    19 #include "cc/test/fake_recording_source.h" | 
|    20 #include "cc/test/pixel_test.h" |    20 #include "cc/test/pixel_test.h" | 
 |    21 #include "cc/test/test_in_process_context_provider.h" | 
|    21 #include "components/viz/service/display/gl_renderer.h" |    22 #include "components/viz/service/display/gl_renderer.h" | 
|    22 #include "gpu/command_buffer/client/gles2_interface.h" |    23 #include "gpu/command_buffer/client/gles2_interface.h" | 
|    23 #include "media/base/video_frame.h" |    24 #include "media/base/video_frame.h" | 
|    24 #include "third_party/skia/include/core/SkColorPriv.h" |    25 #include "third_party/skia/include/core/SkColorPriv.h" | 
|    25 #include "third_party/skia/include/core/SkImageFilter.h" |    26 #include "third_party/skia/include/core/SkImageFilter.h" | 
|    26 #include "third_party/skia/include/core/SkMatrix.h" |    27 #include "third_party/skia/include/core/SkMatrix.h" | 
|    27 #include "third_party/skia/include/core/SkRefCnt.h" |    28 #include "third_party/skia/include/core/SkRefCnt.h" | 
|    28 #include "third_party/skia/include/core/SkSurface.h" |    29 #include "third_party/skia/include/core/SkSurface.h" | 
|    29 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |    30 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" | 
|    30 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |    31 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   293  |   294  | 
|   294   YUVVideoDrawQuad* yuv_quad = |   295   YUVVideoDrawQuad* yuv_quad = | 
|   295       render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); |   296       render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); | 
|   296   uint32_t bits_per_channel = 8; |   297   uint32_t bits_per_channel = 8; | 
|   297   if (video_frame->format() == media::PIXEL_FORMAT_YUV420P10 || |   298   if (video_frame->format() == media::PIXEL_FORMAT_YUV420P10 || | 
|   298       video_frame->format() == media::PIXEL_FORMAT_YUV422P10 || |   299       video_frame->format() == media::PIXEL_FORMAT_YUV422P10 || | 
|   299       video_frame->format() == media::PIXEL_FORMAT_YUV444P10) { |   300       video_frame->format() == media::PIXEL_FORMAT_YUV444P10) { | 
|   300     bits_per_channel = 10; |   301     bits_per_channel = 10; | 
|   301   } |   302   } | 
|   302  |   303  | 
 |   304   viz::ResourceFormat yuv_highbit_resource_format = | 
 |   305       resource_provider->YuvResourceFormat(bits_per_channel); | 
 |   306  | 
 |   307   float multitplier = 1.0; | 
 |   308   int shift = 16 - bits_per_channel; | 
 |   309  | 
 |   310   if (yuv_highbit_resource_format != viz::R16_EXT) | 
 |   311     bits_per_channel = 8; | 
 |   312   else | 
 |   313     multitplier = (1 << shift) + 1.0 / (1 << (bits_per_channel - shift)); | 
 |   314  | 
|   303   yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, |   315   yuv_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, | 
|   304                    needs_blending, ya_tex_coord_rect, uv_tex_coord_rect, |   316                    needs_blending, ya_tex_coord_rect, uv_tex_coord_rect, | 
|   305                    ya_tex_size, uv_tex_size, y_resource, u_resource, v_resource, |   317                    ya_tex_size, uv_tex_size, y_resource, u_resource, v_resource, | 
|   306                    a_resource, color_space, video_color_space, 0.0f, 1.0f, |   318                    a_resource, color_space, video_color_space, 0.0f, | 
|   307                    bits_per_channel); |   319                    multitplier, bits_per_channel); | 
|   308 } |   320 } | 
|   309  |   321  | 
|   310 void CreateTestY16TextureDrawQuad_FromVideoFrame( |   322 void CreateTestY16TextureDrawQuad_FromVideoFrame( | 
|   311     const SharedQuadState* shared_state, |   323     const SharedQuadState* shared_state, | 
|   312     scoped_refptr<media::VideoFrame> video_frame, |   324     scoped_refptr<media::VideoFrame> video_frame, | 
|   313     const gfx::RectF& tex_coord_rect, |   325     const gfx::RectF& tex_coord_rect, | 
|   314     RenderPass* render_pass, |   326     RenderPass* render_pass, | 
|   315     VideoResourceUpdater* video_resource_updater, |   327     VideoResourceUpdater* video_resource_updater, | 
|   316     const gfx::Rect& rect, |   328     const gfx::Rect& rect, | 
|   317     const gfx::Rect& visible_rect, |   329     const gfx::Rect& visible_rect, | 
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1290     GLRendererPixelTest::SetUp(); |  1302     GLRendererPixelTest::SetUp(); | 
|  1291     bool use_stream_video_draw_quad = false; |  1303     bool use_stream_video_draw_quad = false; | 
|  1292     video_resource_updater_.reset(new VideoResourceUpdater( |  1304     video_resource_updater_.reset(new VideoResourceUpdater( | 
|  1293         output_surface_->context_provider(), resource_provider_.get(), |  1305         output_surface_->context_provider(), resource_provider_.get(), | 
|  1294         use_stream_video_draw_quad)); |  1306         use_stream_video_draw_quad)); | 
|  1295   } |  1307   } | 
|  1296  |  1308  | 
|  1297   std::unique_ptr<VideoResourceUpdater> video_resource_updater_; |  1309   std::unique_ptr<VideoResourceUpdater> video_resource_updater_; | 
|  1298 }; |  1310 }; | 
|  1299  |  1311  | 
 |  1312 enum class HighbitTexture { | 
 |  1313   Y8, | 
 |  1314   R16_EXT, | 
 |  1315 }; | 
 |  1316  | 
|  1300 class VideoGLRendererPixelHiLoTest |  1317 class VideoGLRendererPixelHiLoTest | 
|  1301     : public VideoGLRendererPixelTest, |  1318     : public VideoGLRendererPixelTest, | 
|  1302       public ::testing::WithParamInterface<bool> {}; |  1319       public ::testing::WithParamInterface< | 
 |  1320           ::testing::tuple<bool, HighbitTexture>> { | 
 |  1321  public: | 
 |  1322   void SetSupportHighbitTexture(HighbitTexture texture) { | 
 |  1323     TestInProcessContextProvider* context_provider = | 
 |  1324         GetTestInProcessContextProvider(); | 
 |  1325     switch (texture) { | 
 |  1326       case HighbitTexture::Y8: | 
 |  1327         break; | 
 |  1328       case HighbitTexture::R16_EXT: | 
 |  1329         context_provider->SetSupportTextureNorm16(true); | 
 |  1330         video_resource_updater_->UseR16ForTesting(true); | 
 |  1331         break; | 
 |  1332     } | 
 |  1333   } | 
 |  1334  | 
 |  1335  private: | 
 |  1336   TestInProcessContextProvider* GetTestInProcessContextProvider() { | 
 |  1337     return static_cast<TestInProcessContextProvider*>( | 
 |  1338         output_surface_->context_provider()); | 
 |  1339   } | 
 |  1340 }; | 
|  1303  |  1341  | 
|  1304 TEST_P(VideoGLRendererPixelHiLoTest, SimpleYUVRect) { |  1342 TEST_P(VideoGLRendererPixelHiLoTest, SimpleYUVRect) { | 
|  1305   gfx::Rect rect(this->device_viewport_size_); |  1343   gfx::Rect rect(this->device_viewport_size_); | 
|  1306  |  1344  | 
|  1307   int id = 1; |  1345   int id = 1; | 
|  1308   std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |  1346   std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | 
|  1309  |  1347  | 
|  1310   SharedQuadState* shared_state = |  1348   SharedQuadState* shared_state = | 
|  1311       CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); |  1349       CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); | 
|  1312  |  1350  | 
|  1313   bool highbit = GetParam(); |  1351   const bool highbit = testing::get<0>(GetParam()); | 
 |  1352   const HighbitTexture format = testing::get<1>(GetParam()); | 
 |  1353   SetSupportHighbitTexture(format); | 
 |  1354  | 
|  1314   CreateTestYUVVideoDrawQuad_Striped( |  1355   CreateTestYUVVideoDrawQuad_Striped( | 
|  1315       shared_state, media::PIXEL_FORMAT_YV12, false, highbit, |  1356       shared_state, media::PIXEL_FORMAT_YV12, false, highbit, | 
|  1316       gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(), |  1357       gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(), | 
|  1317       video_resource_updater_.get(), rect, rect, resource_provider_.get()); |  1358       video_resource_updater_.get(), rect, rect, resource_provider_.get()); | 
|  1318  |  1359  | 
|  1319   RenderPassList pass_list; |  1360   RenderPassList pass_list; | 
|  1320   pass_list.push_back(std::move(pass)); |  1361   pass_list.push_back(std::move(pass)); | 
|  1321  |  1362  | 
|  1322   EXPECT_TRUE( |  1363   EXPECT_TRUE( | 
|  1323       this->RunPixelTest(&pass_list, |  1364       this->RunPixelTest(&pass_list, | 
|  1324                          base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")), |  1365                          base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")), | 
|  1325                          FuzzyPixelOffByOneComparator(true))); |  1366                          FuzzyPixelOffByOneComparator(true))); | 
|  1326 } |  1367 } | 
|  1327  |  1368  | 
|  1328 TEST_P(VideoGLRendererPixelHiLoTest, ClippedYUVRect) { |  1369 TEST_P(VideoGLRendererPixelHiLoTest, ClippedYUVRect) { | 
|  1329   gfx::Rect viewport(this->device_viewport_size_); |  1370   gfx::Rect viewport(this->device_viewport_size_); | 
|  1330   gfx::Rect draw_rect(this->device_viewport_size_.width() * 1.5, |  1371   gfx::Rect draw_rect(this->device_viewport_size_.width() * 1.5, | 
|  1331                       this->device_viewport_size_.height() * 1.5); |  1372                       this->device_viewport_size_.height() * 1.5); | 
|  1332  |  1373  | 
|  1333   int id = 1; |  1374   int id = 1; | 
|  1334   std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, viewport); |  1375   std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, viewport); | 
|  1335  |  1376  | 
|  1336   SharedQuadState* shared_state = |  1377   SharedQuadState* shared_state = | 
|  1337       CreateTestSharedQuadState(gfx::Transform(), viewport, pass.get()); |  1378       CreateTestSharedQuadState(gfx::Transform(), viewport, pass.get()); | 
|  1338  |  1379  | 
|  1339   bool highbit = GetParam(); |  1380   const bool highbit = testing::get<0>(GetParam()); | 
 |  1381   const HighbitTexture format = testing::get<1>(GetParam()); | 
 |  1382   SetSupportHighbitTexture(format); | 
 |  1383  | 
|  1340   CreateTestYUVVideoDrawQuad_Striped( |  1384   CreateTestYUVVideoDrawQuad_Striped( | 
|  1341       shared_state, media::PIXEL_FORMAT_YV12, false, highbit, |  1385       shared_state, media::PIXEL_FORMAT_YV12, false, highbit, | 
|  1342       gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(), |  1386       gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(), | 
|  1343       video_resource_updater_.get(), draw_rect, viewport, |  1387       video_resource_updater_.get(), draw_rect, viewport, | 
|  1344       resource_provider_.get()); |  1388       resource_provider_.get()); | 
|  1345   RenderPassList pass_list; |  1389   RenderPassList pass_list; | 
|  1346   pass_list.push_back(std::move(pass)); |  1390   pass_list.push_back(std::move(pass)); | 
|  1347  |  1391  | 
|  1348   EXPECT_TRUE(this->RunPixelTest( |  1392   EXPECT_TRUE(this->RunPixelTest( | 
|  1349       &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped.png")), |  1393       &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped.png")), | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1392   pass_list.push_back(std::move(pass)); |  1436   pass_list.push_back(std::move(pass)); | 
|  1393  |  1437  | 
|  1394   // If we didn't get black out of the YUV values above, then we probably have a |  1438   // If we didn't get black out of the YUV values above, then we probably have a | 
|  1395   // color range issue. |  1439   // color range issue. | 
|  1396   EXPECT_TRUE(this->RunPixelTest(&pass_list, |  1440   EXPECT_TRUE(this->RunPixelTest(&pass_list, | 
|  1397                                  base::FilePath(FILE_PATH_LITERAL("black.png")), |  1441                                  base::FilePath(FILE_PATH_LITERAL("black.png")), | 
|  1398                                  FuzzyPixelOffByOneComparator(true))); |  1442                                  FuzzyPixelOffByOneComparator(true))); | 
|  1399 } |  1443 } | 
|  1400  |  1444  | 
|  1401 // First argument (test case prefix) is intentionally left empty. |  1445 // First argument (test case prefix) is intentionally left empty. | 
|  1402 INSTANTIATE_TEST_CASE_P(, VideoGLRendererPixelHiLoTest, ::testing::Bool()); |  1446 INSTANTIATE_TEST_CASE_P( | 
 |  1447     , | 
 |  1448     VideoGLRendererPixelHiLoTest, | 
 |  1449     testing::Combine(testing::Bool(), | 
 |  1450                      testing::Values(HighbitTexture::Y8, | 
 |  1451                                      HighbitTexture::R16_EXT))); | 
|  1403  |  1452  | 
|  1404 TEST_F(VideoGLRendererPixelTest, SimpleYUVJRect) { |  1453 TEST_F(VideoGLRendererPixelTest, SimpleYUVJRect) { | 
|  1405   gfx::Rect rect(this->device_viewport_size_); |  1454   gfx::Rect rect(this->device_viewport_size_); | 
|  1406  |  1455  | 
|  1407   int id = 1; |  1456   int id = 1; | 
|  1408   std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |  1457   std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | 
|  1409  |  1458  | 
|  1410   SharedQuadState* shared_state = |  1459   SharedQuadState* shared_state = | 
|  1411       CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); |  1460       CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); | 
|  1412  |  1461  | 
| (...skipping 2194 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  3607 INSTANTIATE_TEST_CASE_P( |  3656 INSTANTIATE_TEST_CASE_P( | 
|  3608     ToColorSpace, |  3657     ToColorSpace, | 
|  3609     ColorTransformPixelTest, |  3658     ColorTransformPixelTest, | 
|  3610     testing::Combine(testing::ValuesIn(intermediate_color_spaces), |  3659     testing::Combine(testing::ValuesIn(intermediate_color_spaces), | 
|  3611                      testing::ValuesIn(dst_color_spaces))); |  3660                      testing::ValuesIn(dst_color_spaces))); | 
|  3612  |  3661  | 
|  3613 #endif  // !defined(OS_ANDROID) |  3662 #endif  // !defined(OS_ANDROID) | 
|  3614  |  3663  | 
|  3615 }  // namespace |  3664 }  // namespace | 
|  3616 }  // namespace cc |  3665 }  // namespace cc | 
| OLD | NEW |