Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: cc/resources/scoped_resource_unittest.cc

Issue 2337913003: Fork cc::OutputSurface into cc::CompositorFrameSink. (Closed)
Patch Set: cfsfork: android-vulkan Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/test/fake_output_surface.h"
10 #include "cc/test/fake_output_surface_client.h"
11 #include "cc/test/fake_resource_provider.h" 9 #include "cc/test/fake_resource_provider.h"
10 #include "cc/test/test_context_provider.h"
12 #include "cc/test/test_shared_bitmap_manager.h" 11 #include "cc/test/test_shared_bitmap_manager.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 13
15 namespace cc { 14 namespace cc {
16 namespace { 15 namespace {
17 16
18 TEST(ScopedResourceTest, NewScopedResource) { 17 TEST(ScopedResourceTest, NewScopedResource) {
19 FakeOutputSurfaceClient output_surface_client; 18 scoped_refptr<TestContextProvider> context_provider =
20 std::unique_ptr<OutputSurface> output_surface( 19 TestContextProvider::Create();
21 FakeOutputSurface::CreateDelegating3d()); 20 ASSERT_TRUE(context_provider->BindToCurrentThread());
22 CHECK(output_surface->BindToClient(&output_surface_client));
23 21
24 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( 22 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager(
25 new TestSharedBitmapManager()); 23 new TestSharedBitmapManager());
26 std::unique_ptr<ResourceProvider> resource_provider = 24 std::unique_ptr<ResourceProvider> resource_provider =
27 FakeResourceProvider::Create(output_surface.get(), 25 FakeResourceProvider::Create(context_provider.get(),
28 shared_bitmap_manager.get()); 26 shared_bitmap_manager.get());
29 std::unique_ptr<ScopedResource> texture = 27 std::unique_ptr<ScopedResource> texture =
30 ScopedResource::Create(resource_provider.get()); 28 ScopedResource::Create(resource_provider.get());
31 29
32 // New scoped textures do not hold a texture yet. 30 // New scoped textures do not hold a texture yet.
33 EXPECT_EQ(0u, texture->id()); 31 EXPECT_EQ(0u, texture->id());
34 32
35 // New scoped textures do not have a size yet. 33 // New scoped textures do not have a size yet.
36 EXPECT_EQ(gfx::Size(), texture->size()); 34 EXPECT_EQ(gfx::Size(), texture->size());
37 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(), 35 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(),
38 texture->format())); 36 texture->format()));
39 } 37 }
40 38
41 TEST(ScopedResourceTest, CreateScopedResource) { 39 TEST(ScopedResourceTest, CreateScopedResource) {
42 FakeOutputSurfaceClient output_surface_client; 40 scoped_refptr<TestContextProvider> context_provider =
43 std::unique_ptr<OutputSurface> output_surface( 41 TestContextProvider::Create();
44 FakeOutputSurface::CreateDelegating3d()); 42 ASSERT_TRUE(context_provider->BindToCurrentThread());
45 CHECK(output_surface->BindToClient(&output_surface_client));
46 43
47 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( 44 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager(
48 new TestSharedBitmapManager()); 45 new TestSharedBitmapManager());
49 std::unique_ptr<ResourceProvider> resource_provider = 46 std::unique_ptr<ResourceProvider> resource_provider =
50 FakeResourceProvider::Create(output_surface.get(), 47 FakeResourceProvider::Create(context_provider.get(),
51 shared_bitmap_manager.get()); 48 shared_bitmap_manager.get());
52 std::unique_ptr<ScopedResource> texture = 49 std::unique_ptr<ScopedResource> texture =
53 ScopedResource::Create(resource_provider.get()); 50 ScopedResource::Create(resource_provider.get());
54 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, 51 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
55 RGBA_8888, gfx::ColorSpace()); 52 RGBA_8888, gfx::ColorSpace());
56 53
57 // The texture has an allocated byte-size now. 54 // The texture has an allocated byte-size now.
58 size_t expected_bytes = 30 * 30 * 4; 55 size_t expected_bytes = 30 * 30 * 4;
59 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>( 56 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>(
60 texture->size(), texture->format())); 57 texture->size(), texture->format()));
61 58
62 EXPECT_LT(0u, texture->id()); 59 EXPECT_LT(0u, texture->id());
63 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); 60 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format());
64 EXPECT_EQ(gfx::Size(30, 30), texture->size()); 61 EXPECT_EQ(gfx::Size(30, 30), texture->size());
65 } 62 }
66 63
67 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { 64 TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
68 FakeOutputSurfaceClient output_surface_client; 65 scoped_refptr<TestContextProvider> context_provider =
69 std::unique_ptr<OutputSurface> output_surface( 66 TestContextProvider::Create();
70 FakeOutputSurface::CreateDelegating3d()); 67 ASSERT_TRUE(context_provider->BindToCurrentThread());
71 CHECK(output_surface->BindToClient(&output_surface_client));
72 68
73 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( 69 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager(
74 new TestSharedBitmapManager()); 70 new TestSharedBitmapManager());
75 std::unique_ptr<ResourceProvider> resource_provider = 71 std::unique_ptr<ResourceProvider> resource_provider =
76 FakeResourceProvider::Create(output_surface.get(), 72 FakeResourceProvider::Create(context_provider.get(),
77 shared_bitmap_manager.get()); 73 shared_bitmap_manager.get());
78 { 74 {
79 std::unique_ptr<ScopedResource> texture = 75 std::unique_ptr<ScopedResource> texture =
80 ScopedResource::Create(resource_provider.get()); 76 ScopedResource::Create(resource_provider.get());
81 77
82 EXPECT_EQ(0u, resource_provider->num_resources()); 78 EXPECT_EQ(0u, resource_provider->num_resources());
83 texture->Allocate(gfx::Size(30, 30), 79 texture->Allocate(gfx::Size(30, 30),
84 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, 80 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888,
85 gfx::ColorSpace()); 81 gfx::ColorSpace());
86 EXPECT_LT(0u, texture->id()); 82 EXPECT_LT(0u, texture->id());
(...skipping 10 matching lines...) Expand all
97 gfx::ColorSpace()); 93 gfx::ColorSpace());
98 EXPECT_LT(0u, texture->id()); 94 EXPECT_LT(0u, texture->id());
99 EXPECT_EQ(1u, resource_provider->num_resources()); 95 EXPECT_EQ(1u, resource_provider->num_resources());
100 texture->Free(); 96 texture->Free();
101 EXPECT_EQ(0u, resource_provider->num_resources()); 97 EXPECT_EQ(0u, resource_provider->num_resources());
102 } 98 }
103 } 99 }
104 100
105 } // namespace 101 } // namespace
106 } // namespace cc 102 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider_unittest.cc ('k') | cc/resources/video_resource_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698