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" | |
14 #include "cc/test/fake_output_surface_client.h" | |
15 #include "cc/test/fake_resource_provider.h" | 13 #include "cc/test/fake_resource_provider.h" |
| 14 #include "cc/test/test_context_provider.h" |
16 #include "cc/test/test_shared_bitmap_manager.h" | 15 #include "cc/test/test_shared_bitmap_manager.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
18 | 17 |
19 namespace cc { | 18 namespace cc { |
20 | 19 |
21 class ResourcePoolTest : public testing::Test { | 20 class ResourcePoolTest : public testing::Test { |
22 public: | 21 public: |
23 void SetUp() override { | 22 void SetUp() override { |
24 output_surface_ = FakeOutputSurface::CreateDelegating3d(); | 23 context_provider_ = TestContextProvider::Create(); |
25 ASSERT_TRUE(output_surface_->BindToClient(&output_surface_client_)); | 24 context_provider_->BindToCurrentThread(); |
26 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | 25 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
27 resource_provider_ = FakeResourceProvider::Create( | 26 resource_provider_ = FakeResourceProvider::Create( |
28 output_surface_.get(), shared_bitmap_manager_.get()); | 27 context_provider_.get(), shared_bitmap_manager_.get()); |
29 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 28 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
30 resource_pool_ = | 29 resource_pool_ = |
31 ResourcePool::Create(resource_provider_.get(), task_runner_.get(), | 30 ResourcePool::Create(resource_provider_.get(), task_runner_.get(), |
32 ResourcePool::kDefaultExpirationDelay); | 31 ResourcePool::kDefaultExpirationDelay); |
33 } | 32 } |
34 | 33 |
35 protected: | 34 protected: |
36 FakeOutputSurfaceClient output_surface_client_; | 35 scoped_refptr<TestContextProvider> context_provider_; |
37 std::unique_ptr<FakeOutputSurface> output_surface_; | |
38 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; | 36 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; |
39 std::unique_ptr<ResourceProvider> resource_provider_; | 37 std::unique_ptr<ResourceProvider> resource_provider_; |
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 38 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
41 std::unique_ptr<ResourcePool> resource_pool_; | 39 std::unique_ptr<ResourcePool> resource_pool_; |
42 }; | 40 }; |
43 | 41 |
44 TEST_F(ResourcePoolTest, AcquireRelease) { | 42 TEST_F(ResourcePoolTest, AcquireRelease) { |
45 gfx::Size size(100, 100); | 43 gfx::Size size(100, 100); |
46 ResourceFormat format = RGBA_8888; | 44 ResourceFormat format = RGBA_8888; |
47 gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB(); | 45 gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB(); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 Resource* resource = resource_pool_->ReuseResource(size, format, color_space); | 329 Resource* resource = resource_pool_->ReuseResource(size, format, color_space); |
332 EXPECT_EQ(nullptr, resource); | 330 EXPECT_EQ(nullptr, resource); |
333 size = gfx::Size(100, 99); | 331 size = gfx::Size(100, 99); |
334 resource = resource_pool_->ReuseResource(size, format, color_space); | 332 resource = resource_pool_->ReuseResource(size, format, color_space); |
335 EXPECT_NE(nullptr, resource); | 333 EXPECT_NE(nullptr, resource); |
336 ASSERT_EQ(nullptr, resource_pool_->ReuseResource(size, format, color_space)); | 334 ASSERT_EQ(nullptr, resource_pool_->ReuseResource(size, format, color_space)); |
337 resource_pool_->ReleaseResource(resource); | 335 resource_pool_->ReleaseResource(resource); |
338 } | 336 } |
339 | 337 |
340 } // namespace cc | 338 } // namespace cc |
OLD | NEW |