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