| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 class VideoResourceUpdaterTest : public testing::Test { | 87 class VideoResourceUpdaterTest : public testing::Test { |
| 88 protected: | 88 protected: |
| 89 VideoResourceUpdaterTest() { | 89 VideoResourceUpdaterTest() { |
| 90 std::unique_ptr<WebGraphicsContext3DUploadCounter> context3d( | 90 std::unique_ptr<WebGraphicsContext3DUploadCounter> context3d( |
| 91 new WebGraphicsContext3DUploadCounter()); | 91 new WebGraphicsContext3DUploadCounter()); |
| 92 | 92 |
| 93 context3d_ = context3d.get(); | 93 context3d_ = context3d.get(); |
| 94 context3d_->set_support_texture_storage(true); | 94 context3d_->set_support_texture_storage(true); |
| 95 | 95 |
| 96 output_surface3d_ = FakeOutputSurface::Create3d(std::move(context3d)); | 96 context_provider_ = TestContextProvider::Create(std::move(context3d)); |
| 97 CHECK(output_surface3d_->BindToClient(&client_)); | |
| 98 } | 97 } |
| 99 | 98 |
| 100 void SetUp() override { | 99 void SetUp() override { |
| 101 testing::Test::SetUp(); | 100 testing::Test::SetUp(); |
| 102 | 101 |
| 103 output_surface_software_ = FakeOutputSurface::CreateSoftware( | |
| 104 base::WrapUnique(new SoftwareOutputDevice)); | |
| 105 CHECK(output_surface_software_->BindToClient(&client_)); | |
| 106 | |
| 107 shared_bitmap_manager_.reset(new SharedBitmapManagerAllocationCounter()); | 102 shared_bitmap_manager_.reset(new SharedBitmapManagerAllocationCounter()); |
| 108 resource_provider3d_ = FakeResourceProvider::Create( | 103 resource_provider3d_ = FakeResourceProvider::Create( |
| 109 output_surface3d_.get(), shared_bitmap_manager_.get()); | 104 context_provider_.get(), shared_bitmap_manager_.get()); |
| 110 | 105 resource_provider_software_ = |
| 111 resource_provider_software_ = FakeResourceProvider::Create( | 106 FakeResourceProvider::Create(nullptr, shared_bitmap_manager_.get()); |
| 112 output_surface_software_.get(), shared_bitmap_manager_.get()); | |
| 113 } | 107 } |
| 114 | 108 |
| 115 scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame() { | 109 scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame() { |
| 116 const int kDimension = 10; | 110 const int kDimension = 10; |
| 117 gfx::Size size(kDimension, kDimension); | 111 gfx::Size size(kDimension, kDimension); |
| 118 static uint8_t y_data[kDimension * kDimension] = {0}; | 112 static uint8_t y_data[kDimension * kDimension] = {0}; |
| 119 static uint8_t u_data[kDimension * kDimension / 2] = {0}; | 113 static uint8_t u_data[kDimension * kDimension / 2] = {0}; |
| 120 static uint8_t v_data[kDimension * kDimension / 2] = {0}; | 114 static uint8_t v_data[kDimension * kDimension / 2] = {0}; |
| 121 | 115 |
| 122 scoped_refptr<media::VideoFrame> video_frame = | 116 scoped_refptr<media::VideoFrame> video_frame = |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 base::Bind(&ReleaseMailboxCB), | 228 base::Bind(&ReleaseMailboxCB), |
| 235 size, // coded_size | 229 size, // coded_size |
| 236 gfx::Rect(size), // visible_rect | 230 gfx::Rect(size), // visible_rect |
| 237 size, // natural_size | 231 size, // natural_size |
| 238 base::TimeDelta()); // timestamp | 232 base::TimeDelta()); // timestamp |
| 239 EXPECT_TRUE(video_frame); | 233 EXPECT_TRUE(video_frame); |
| 240 return video_frame; | 234 return video_frame; |
| 241 } | 235 } |
| 242 | 236 |
| 243 WebGraphicsContext3DUploadCounter* context3d_; | 237 WebGraphicsContext3DUploadCounter* context3d_; |
| 244 FakeOutputSurfaceClient client_; | 238 scoped_refptr<TestContextProvider> context_provider_; |
| 245 std::unique_ptr<FakeOutputSurface> output_surface3d_; | |
| 246 std::unique_ptr<FakeOutputSurface> output_surface_software_; | |
| 247 std::unique_ptr<SharedBitmapManagerAllocationCounter> shared_bitmap_manager_; | 239 std::unique_ptr<SharedBitmapManagerAllocationCounter> shared_bitmap_manager_; |
| 248 std::unique_ptr<ResourceProvider> resource_provider3d_; | 240 std::unique_ptr<ResourceProvider> resource_provider3d_; |
| 249 std::unique_ptr<ResourceProvider> resource_provider_software_; | 241 std::unique_ptr<ResourceProvider> resource_provider_software_; |
| 250 }; | 242 }; |
| 251 | 243 |
| 252 TEST_F(VideoResourceUpdaterTest, SoftwareFrame) { | 244 TEST_F(VideoResourceUpdaterTest, SoftwareFrame) { |
| 253 VideoResourceUpdater updater(output_surface3d_->context_provider(), | 245 VideoResourceUpdater updater(context_provider_.get(), |
| 254 resource_provider3d_.get()); | 246 resource_provider3d_.get()); |
| 255 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame(); | 247 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame(); |
| 256 | 248 |
| 257 VideoFrameExternalResources resources = | 249 VideoFrameExternalResources resources = |
| 258 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 250 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 259 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); | 251 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
| 260 } | 252 } |
| 261 | 253 |
| 262 TEST_F(VideoResourceUpdaterTest, HighBitFrameNoF16) { | 254 TEST_F(VideoResourceUpdaterTest, HighBitFrameNoF16) { |
| 263 VideoResourceUpdater updater(output_surface3d_->context_provider(), | 255 VideoResourceUpdater updater(context_provider_.get(), |
| 264 resource_provider3d_.get()); | 256 resource_provider3d_.get()); |
| 265 scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame(); | 257 scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame(); |
| 266 | 258 |
| 267 VideoFrameExternalResources resources = | 259 VideoFrameExternalResources resources = |
| 268 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 260 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 269 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); | 261 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
| 270 } | 262 } |
| 271 | 263 |
| 272 class VideoResourceUpdaterTestWithF16 : public VideoResourceUpdaterTest { | 264 class VideoResourceUpdaterTestWithF16 : public VideoResourceUpdaterTest { |
| 273 public: | 265 public: |
| 274 VideoResourceUpdaterTestWithF16() : VideoResourceUpdaterTest() { | 266 VideoResourceUpdaterTestWithF16() : VideoResourceUpdaterTest() { |
| 275 context3d_->set_support_texture_half_float_linear(true); | 267 context3d_->set_support_texture_half_float_linear(true); |
| 276 } | 268 } |
| 277 }; | 269 }; |
| 278 | 270 |
| 279 TEST_F(VideoResourceUpdaterTestWithF16, HighBitFrame) { | 271 TEST_F(VideoResourceUpdaterTestWithF16, HighBitFrame) { |
| 280 VideoResourceUpdater updater(output_surface3d_->context_provider(), | 272 VideoResourceUpdater updater(context_provider_.get(), |
| 281 resource_provider3d_.get()); | 273 resource_provider3d_.get()); |
| 282 scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame(); | 274 scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame(); |
| 283 | 275 |
| 284 VideoFrameExternalResources resources = | 276 VideoFrameExternalResources resources = |
| 285 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 277 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 286 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); | 278 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
| 287 } | 279 } |
| 288 | 280 |
| 289 TEST_F(VideoResourceUpdaterTest, HighBitFrameSoftwareCompositor) { | 281 TEST_F(VideoResourceUpdaterTest, HighBitFrameSoftwareCompositor) { |
| 290 VideoResourceUpdater updater(nullptr, resource_provider_software_.get()); | 282 VideoResourceUpdater updater(nullptr, resource_provider_software_.get()); |
| 291 scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame(); | 283 scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame(); |
| 292 | 284 |
| 293 VideoFrameExternalResources resources = | 285 VideoFrameExternalResources resources = |
| 294 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 286 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 295 EXPECT_EQ(VideoFrameExternalResources::SOFTWARE_RESOURCE, resources.type); | 287 EXPECT_EQ(VideoFrameExternalResources::SOFTWARE_RESOURCE, resources.type); |
| 296 } | 288 } |
| 297 | 289 |
| 298 TEST_F(VideoResourceUpdaterTest, WonkySoftwareFrame) { | 290 TEST_F(VideoResourceUpdaterTest, WonkySoftwareFrame) { |
| 299 VideoResourceUpdater updater(output_surface3d_->context_provider(), | 291 VideoResourceUpdater updater(context_provider_.get(), |
| 300 resource_provider3d_.get()); | 292 resource_provider3d_.get()); |
| 301 scoped_refptr<media::VideoFrame> video_frame = CreateWonkyTestYUVVideoFrame(); | 293 scoped_refptr<media::VideoFrame> video_frame = CreateWonkyTestYUVVideoFrame(); |
| 302 | 294 |
| 303 VideoFrameExternalResources resources = | 295 VideoFrameExternalResources resources = |
| 304 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 296 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 305 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); | 297 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
| 306 } | 298 } |
| 307 | 299 |
| 308 TEST_F(VideoResourceUpdaterTest, WonkySoftwareFrameSoftwareCompositor) { | 300 TEST_F(VideoResourceUpdaterTest, WonkySoftwareFrameSoftwareCompositor) { |
| 309 VideoResourceUpdater updater(nullptr, resource_provider_software_.get()); | 301 VideoResourceUpdater updater(nullptr, resource_provider_software_.get()); |
| 310 scoped_refptr<media::VideoFrame> video_frame = CreateWonkyTestYUVVideoFrame(); | 302 scoped_refptr<media::VideoFrame> video_frame = CreateWonkyTestYUVVideoFrame(); |
| 311 | 303 |
| 312 VideoFrameExternalResources resources = | 304 VideoFrameExternalResources resources = |
| 313 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 305 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 314 EXPECT_EQ(VideoFrameExternalResources::SOFTWARE_RESOURCE, resources.type); | 306 EXPECT_EQ(VideoFrameExternalResources::SOFTWARE_RESOURCE, resources.type); |
| 315 } | 307 } |
| 316 | 308 |
| 317 TEST_F(VideoResourceUpdaterTest, ReuseResource) { | 309 TEST_F(VideoResourceUpdaterTest, ReuseResource) { |
| 318 VideoResourceUpdater updater(output_surface3d_->context_provider(), | 310 VideoResourceUpdater updater(context_provider_.get(), |
| 319 resource_provider3d_.get()); | 311 resource_provider3d_.get()); |
| 320 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame(); | 312 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame(); |
| 321 video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234)); | 313 video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234)); |
| 322 | 314 |
| 323 // Allocate the resources for a YUV video frame. | 315 // Allocate the resources for a YUV video frame. |
| 324 context3d_->ResetUploadCount(); | 316 context3d_->ResetUploadCount(); |
| 325 VideoFrameExternalResources resources = | 317 VideoFrameExternalResources resources = |
| 326 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 318 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 327 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); | 319 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
| 328 EXPECT_EQ(size_t(3), resources.mailboxes.size()); | 320 EXPECT_EQ(size_t(3), resources.mailboxes.size()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 340 context3d_->ResetUploadCount(); | 332 context3d_->ResetUploadCount(); |
| 341 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); | 333 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 342 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); | 334 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
| 343 EXPECT_EQ(size_t(3), resources.mailboxes.size()); | 335 EXPECT_EQ(size_t(3), resources.mailboxes.size()); |
| 344 EXPECT_EQ(size_t(3), resources.release_callbacks.size()); | 336 EXPECT_EQ(size_t(3), resources.release_callbacks.size()); |
| 345 // The data should be reused so expect no texture uploads. | 337 // The data should be reused so expect no texture uploads. |
| 346 EXPECT_EQ(0, context3d_->UploadCount()); | 338 EXPECT_EQ(0, context3d_->UploadCount()); |
| 347 } | 339 } |
| 348 | 340 |
| 349 TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDelete) { | 341 TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDelete) { |
| 350 VideoResourceUpdater updater(output_surface3d_->context_provider(), | 342 VideoResourceUpdater updater(context_provider_.get(), |
| 351 resource_provider3d_.get()); | 343 resource_provider3d_.get()); |
| 352 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame(); | 344 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame(); |
| 353 video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234)); | 345 video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234)); |
| 354 | 346 |
| 355 // Allocate the resources for a YUV video frame. | 347 // Allocate the resources for a YUV video frame. |
| 356 context3d_->ResetUploadCount(); | 348 context3d_->ResetUploadCount(); |
| 357 VideoFrameExternalResources resources = | 349 VideoFrameExternalResources resources = |
| 358 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 350 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 359 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); | 351 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
| 360 EXPECT_EQ(size_t(3), resources.mailboxes.size()); | 352 EXPECT_EQ(size_t(3), resources.mailboxes.size()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); | 426 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 435 EXPECT_EQ(VideoFrameExternalResources::SOFTWARE_RESOURCE, resources.type); | 427 EXPECT_EQ(VideoFrameExternalResources::SOFTWARE_RESOURCE, resources.type); |
| 436 EXPECT_EQ(size_t(0), resources.mailboxes.size()); | 428 EXPECT_EQ(size_t(0), resources.mailboxes.size()); |
| 437 EXPECT_EQ(size_t(0), resources.release_callbacks.size()); | 429 EXPECT_EQ(size_t(0), resources.release_callbacks.size()); |
| 438 EXPECT_EQ(size_t(1), resources.software_resources.size()); | 430 EXPECT_EQ(size_t(1), resources.software_resources.size()); |
| 439 // The data should be reused so expect no new allocations. | 431 // The data should be reused so expect no new allocations. |
| 440 EXPECT_EQ(0, shared_bitmap_manager_->AllocationCount()); | 432 EXPECT_EQ(0, shared_bitmap_manager_->AllocationCount()); |
| 441 } | 433 } |
| 442 | 434 |
| 443 TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes) { | 435 TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes) { |
| 444 VideoResourceUpdater updater(output_surface3d_->context_provider(), | 436 VideoResourceUpdater updater(context_provider_.get(), |
| 445 resource_provider3d_.get()); | 437 resource_provider3d_.get()); |
| 446 | 438 |
| 447 scoped_refptr<media::VideoFrame> video_frame = | 439 scoped_refptr<media::VideoFrame> video_frame = |
| 448 CreateTestRGBAHardwareVideoFrame(); | 440 CreateTestRGBAHardwareVideoFrame(); |
| 449 | 441 |
| 450 VideoFrameExternalResources resources = | 442 VideoFrameExternalResources resources = |
| 451 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 443 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 452 EXPECT_EQ(VideoFrameExternalResources::RGBA_PREMULTIPLIED_RESOURCE, | 444 EXPECT_EQ(VideoFrameExternalResources::RGBA_PREMULTIPLIED_RESOURCE, |
| 453 resources.type); | 445 resources.type); |
| 454 EXPECT_EQ(1u, resources.mailboxes.size()); | 446 EXPECT_EQ(1u, resources.mailboxes.size()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 466 | 458 |
| 467 video_frame = CreateTestYuvHardwareVideoFrame(); | 459 video_frame = CreateTestYuvHardwareVideoFrame(); |
| 468 video_frame->metadata()->SetBoolean( | 460 video_frame->metadata()->SetBoolean( |
| 469 media::VideoFrameMetadata::READ_LOCK_FENCES_ENABLED, true); | 461 media::VideoFrameMetadata::READ_LOCK_FENCES_ENABLED, true); |
| 470 | 462 |
| 471 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); | 463 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 472 EXPECT_TRUE(resources.read_lock_fences_enabled); | 464 EXPECT_TRUE(resources.read_lock_fences_enabled); |
| 473 } | 465 } |
| 474 | 466 |
| 475 TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_StreamTexture) { | 467 TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_StreamTexture) { |
| 476 VideoResourceUpdater updater(output_surface3d_->context_provider(), | 468 VideoResourceUpdater updater(context_provider_.get(), |
| 477 resource_provider3d_.get()); | 469 resource_provider3d_.get()); |
| 478 context3d_->ResetTextureCreationCount(); | 470 context3d_->ResetTextureCreationCount(); |
| 479 scoped_refptr<media::VideoFrame> video_frame = | 471 scoped_refptr<media::VideoFrame> video_frame = |
| 480 CreateTestStreamTextureHardwareVideoFrame(false); | 472 CreateTestStreamTextureHardwareVideoFrame(false); |
| 481 | 473 |
| 482 VideoFrameExternalResources resources = | 474 VideoFrameExternalResources resources = |
| 483 updater.CreateExternalResourcesFromVideoFrame(video_frame); | 475 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 484 EXPECT_EQ(VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE, | 476 EXPECT_EQ(VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE, |
| 485 resources.type); | 477 resources.type); |
| 486 EXPECT_EQ(1u, resources.mailboxes.size()); | 478 EXPECT_EQ(1u, resources.mailboxes.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 505 // The texture copy path requires the use of CopyTextureCHROMIUM, which | 497 // The texture copy path requires the use of CopyTextureCHROMIUM, which |
| 506 // enforces that the target texture not be immutable, as it may need | 498 // enforces that the target texture not be immutable, as it may need |
| 507 // to alter the storage of the texture. Therefore, this test asserts | 499 // to alter the storage of the texture. Therefore, this test asserts |
| 508 // that an immutable texture wasn't created by glTexStorage2DEXT, when | 500 // that an immutable texture wasn't created by glTexStorage2DEXT, when |
| 509 // that extension is supported. | 501 // that extension is supported. |
| 510 EXPECT_FALSE(context3d_->WasImmutableTextureCreated()); | 502 EXPECT_FALSE(context3d_->WasImmutableTextureCreated()); |
| 511 } | 503 } |
| 512 | 504 |
| 513 } // namespace | 505 } // namespace |
| 514 } // namespace cc | 506 } // namespace cc |
| OLD | NEW |