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 "cc/resources/scoped_resource.h" | 5 #include "cc/resources/scoped_resource.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "cc/output/renderer.h" | 9 #include "cc/output/renderer.h" |
10 #include "cc/test/fake_output_surface.h" | 10 #include "cc/test/fake_output_surface.h" |
11 #include "cc/test/fake_output_surface_client.h" | 11 #include "cc/test/fake_output_surface_client.h" |
12 #include "cc/test/fake_resource_provider.h" | 12 #include "cc/test/fake_resource_provider.h" |
13 #include "cc/test/test_shared_bitmap_manager.h" | 13 #include "cc/test/test_shared_bitmap_manager.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 namespace { | 17 namespace { |
18 | 18 |
19 TEST(ScopedResourceTest, NewScopedResource) { | 19 TEST(ScopedResourceTest, NewScopedResource) { |
20 FakeOutputSurfaceClient output_surface_client; | 20 FakeOutputSurfaceClient output_surface_client; |
21 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 21 std::unique_ptr<OutputSurface> output_surface( |
| 22 FakeOutputSurface::CreateDelegating3d()); |
22 CHECK(output_surface->BindToClient(&output_surface_client)); | 23 CHECK(output_surface->BindToClient(&output_surface_client)); |
23 | 24 |
24 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( | 25 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
25 new TestSharedBitmapManager()); | 26 new TestSharedBitmapManager()); |
26 std::unique_ptr<ResourceProvider> resource_provider = | 27 std::unique_ptr<ResourceProvider> resource_provider = |
27 FakeResourceProvider::Create(output_surface.get(), | 28 FakeResourceProvider::Create(output_surface.get(), |
28 shared_bitmap_manager.get()); | 29 shared_bitmap_manager.get()); |
29 std::unique_ptr<ScopedResource> texture = | 30 std::unique_ptr<ScopedResource> texture = |
30 ScopedResource::Create(resource_provider.get()); | 31 ScopedResource::Create(resource_provider.get()); |
31 | 32 |
32 // New scoped textures do not hold a texture yet. | 33 // New scoped textures do not hold a texture yet. |
33 EXPECT_EQ(0u, texture->id()); | 34 EXPECT_EQ(0u, texture->id()); |
34 | 35 |
35 // New scoped textures do not have a size yet. | 36 // New scoped textures do not have a size yet. |
36 EXPECT_EQ(gfx::Size(), texture->size()); | 37 EXPECT_EQ(gfx::Size(), texture->size()); |
37 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(), | 38 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(), |
38 texture->format())); | 39 texture->format())); |
39 } | 40 } |
40 | 41 |
41 TEST(ScopedResourceTest, CreateScopedResource) { | 42 TEST(ScopedResourceTest, CreateScopedResource) { |
42 FakeOutputSurfaceClient output_surface_client; | 43 FakeOutputSurfaceClient output_surface_client; |
43 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 44 std::unique_ptr<OutputSurface> output_surface( |
| 45 FakeOutputSurface::CreateDelegating3d()); |
44 CHECK(output_surface->BindToClient(&output_surface_client)); | 46 CHECK(output_surface->BindToClient(&output_surface_client)); |
45 | 47 |
46 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( | 48 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
47 new TestSharedBitmapManager()); | 49 new TestSharedBitmapManager()); |
48 std::unique_ptr<ResourceProvider> resource_provider = | 50 std::unique_ptr<ResourceProvider> resource_provider = |
49 FakeResourceProvider::Create(output_surface.get(), | 51 FakeResourceProvider::Create(output_surface.get(), |
50 shared_bitmap_manager.get()); | 52 shared_bitmap_manager.get()); |
51 std::unique_ptr<ScopedResource> texture = | 53 std::unique_ptr<ScopedResource> texture = |
52 ScopedResource::Create(resource_provider.get()); | 54 ScopedResource::Create(resource_provider.get()); |
53 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 55 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
54 RGBA_8888); | 56 RGBA_8888); |
55 | 57 |
56 // The texture has an allocated byte-size now. | 58 // The texture has an allocated byte-size now. |
57 size_t expected_bytes = 30 * 30 * 4; | 59 size_t expected_bytes = 30 * 30 * 4; |
58 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>( | 60 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>( |
59 texture->size(), texture->format())); | 61 texture->size(), texture->format())); |
60 | 62 |
61 EXPECT_LT(0u, texture->id()); | 63 EXPECT_LT(0u, texture->id()); |
62 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); | 64 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); |
63 EXPECT_EQ(gfx::Size(30, 30), texture->size()); | 65 EXPECT_EQ(gfx::Size(30, 30), texture->size()); |
64 } | 66 } |
65 | 67 |
66 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { | 68 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { |
67 FakeOutputSurfaceClient output_surface_client; | 69 FakeOutputSurfaceClient output_surface_client; |
68 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 70 std::unique_ptr<OutputSurface> output_surface( |
| 71 FakeOutputSurface::CreateDelegating3d()); |
69 CHECK(output_surface->BindToClient(&output_surface_client)); | 72 CHECK(output_surface->BindToClient(&output_surface_client)); |
70 | 73 |
71 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( | 74 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
72 new TestSharedBitmapManager()); | 75 new TestSharedBitmapManager()); |
73 std::unique_ptr<ResourceProvider> resource_provider = | 76 std::unique_ptr<ResourceProvider> resource_provider = |
74 FakeResourceProvider::Create(output_surface.get(), | 77 FakeResourceProvider::Create(output_surface.get(), |
75 shared_bitmap_manager.get()); | 78 shared_bitmap_manager.get()); |
76 { | 79 { |
77 std::unique_ptr<ScopedResource> texture = | 80 std::unique_ptr<ScopedResource> texture = |
78 ScopedResource::Create(resource_provider.get()); | 81 ScopedResource::Create(resource_provider.get()); |
(...skipping 14 matching lines...) Expand all Loading... |
93 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); | 96 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); |
94 EXPECT_LT(0u, texture->id()); | 97 EXPECT_LT(0u, texture->id()); |
95 EXPECT_EQ(1u, resource_provider->num_resources()); | 98 EXPECT_EQ(1u, resource_provider->num_resources()); |
96 texture->Free(); | 99 texture->Free(); |
97 EXPECT_EQ(0u, resource_provider->num_resources()); | 100 EXPECT_EQ(0u, resource_provider->num_resources()); |
98 } | 101 } |
99 } | 102 } |
100 | 103 |
101 } // namespace | 104 } // namespace |
102 } // namespace cc | 105 } // namespace cc |
OLD | NEW |