OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/resource_pool.h" | 5 #include "cc/resources/resource_pool.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "cc/resources/resource_util.h" | 11 #include "cc/resources/resource_util.h" |
12 #include "cc/resources/scoped_resource.h" | 12 #include "cc/resources/scoped_resource.h" |
13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
14 #include "cc/test/fake_output_surface_client.h" | 14 #include "cc/test/fake_output_surface_client.h" |
15 #include "cc/test/fake_resource_provider.h" | 15 #include "cc/test/fake_resource_provider.h" |
16 #include "cc/test/test_shared_bitmap_manager.h" | 16 #include "cc/test/test_shared_bitmap_manager.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 namespace { | |
21 | 20 |
22 class ResourcePoolTest : public testing::Test { | 21 class ResourcePoolTest : public testing::Test { |
23 public: | 22 public: |
24 void SetUp() override { | 23 void SetUp() override { |
25 output_surface_ = FakeOutputSurface::CreateDelegating3d(); | 24 output_surface_ = FakeOutputSurface::CreateDelegating3d(); |
26 ASSERT_TRUE(output_surface_->BindToClient(&output_surface_client_)); | 25 ASSERT_TRUE(output_surface_->BindToClient(&output_surface_client_)); |
27 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | 26 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
28 resource_provider_ = FakeResourceProvider::Create( | 27 resource_provider_ = FakeResourceProvider::Create( |
29 output_surface_.get(), shared_bitmap_manager_.get()); | 28 output_surface_.get(), shared_bitmap_manager_.get()); |
30 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 29 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // content ID and that it has the expected invalidated rect. | 302 // content ID and that it has the expected invalidated rect. |
304 gfx::Rect total_invalidated_rect; | 303 gfx::Rect total_invalidated_rect; |
305 reacquired_resource = resource_pool_->TryAcquireResourceForPartialRaster( | 304 reacquired_resource = resource_pool_->TryAcquireResourceForPartialRaster( |
306 content_ids[2], second_invalidated_rect, content_ids[1], | 305 content_ids[2], second_invalidated_rect, content_ids[1], |
307 &total_invalidated_rect); | 306 &total_invalidated_rect); |
308 EXPECT_EQ(resource, reacquired_resource); | 307 EXPECT_EQ(resource, reacquired_resource); |
309 EXPECT_EQ(expected_total_invalidated_rect, total_invalidated_rect); | 308 EXPECT_EQ(expected_total_invalidated_rect, total_invalidated_rect); |
310 resource_pool_->ReleaseResource(reacquired_resource); | 309 resource_pool_->ReleaseResource(reacquired_resource); |
311 } | 310 } |
312 | 311 |
313 } // namespace | 312 TEST_F(ResourcePoolTest, ReuseResource) { |
| 313 ResourceFormat format = RGBA_8888; |
| 314 gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB(); |
| 315 |
| 316 // Create unused resources with sizes close to 100, 100. |
| 317 resource_pool_->ReleaseResource( |
| 318 resource_pool_->CreateResource(gfx::Size(99, 100), format, color_space)); |
| 319 resource_pool_->ReleaseResource( |
| 320 resource_pool_->CreateResource(gfx::Size(99, 99), format, color_space)); |
| 321 resource_pool_->ReleaseResource( |
| 322 resource_pool_->CreateResource(gfx::Size(100, 99), format, color_space)); |
| 323 resource_pool_->ReleaseResource( |
| 324 resource_pool_->CreateResource(gfx::Size(101, 101), format, color_space)); |
| 325 resource_pool_->CheckBusyResources(); |
| 326 |
| 327 gfx::Size size(100, 100); |
| 328 Resource* resource = resource_pool_->ReuseResource(size, format, color_space); |
| 329 EXPECT_EQ(nullptr, resource); |
| 330 size = gfx::Size(100, 99); |
| 331 resource = resource_pool_->ReuseResource(size, format, color_space); |
| 332 EXPECT_NE(nullptr, resource); |
| 333 ASSERT_EQ(nullptr, resource_pool_->ReuseResource(size, format, color_space)); |
| 334 resource_pool_->ReleaseResource(resource); |
| 335 } |
| 336 |
314 } // namespace cc | 337 } // namespace cc |
OLD | NEW |