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

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

Issue 634083002: gpu: Compositor management of GpuMemoryBuffer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-pre-chromium-image-refactor
Patch Set: rebase Created 6 years, 2 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 "cc/output/renderer.h" 7 #include "cc/output/renderer.h"
8 #include "cc/test/fake_output_surface.h" 8 #include "cc/test/fake_output_surface.h"
9 #include "cc/test/fake_output_surface_client.h" 9 #include "cc/test/fake_output_surface_client.h"
10 #include "cc/test/test_shared_bitmap_manager.h" 10 #include "cc/test/test_shared_bitmap_manager.h"
11 #include "cc/test/tiled_layer_test_common.h" 11 #include "cc/test/tiled_layer_test_common.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace cc { 14 namespace cc {
15 namespace { 15 namespace {
16 16
17 TEST(ScopedResourceTest, NewScopedResource) { 17 TEST(ScopedResourceTest, NewScopedResource) {
18 FakeOutputSurfaceClient output_surface_client; 18 FakeOutputSurfaceClient output_surface_client;
19 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); 19 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
20 CHECK(output_surface->BindToClient(&output_surface_client)); 20 CHECK(output_surface->BindToClient(&output_surface_client));
21 21
22 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 22 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
23 new TestSharedBitmapManager()); 23 new TestSharedBitmapManager());
24 scoped_ptr<ResourceProvider> resource_provider( 24 scoped_ptr<ResourceProvider> resource_provider(
25 ResourceProvider::Create(output_surface.get(), 25 ResourceProvider::Create(output_surface.get(),
26 shared_bitmap_manager.get(), 26 shared_bitmap_manager.get(),
27 NULL, 27 NULL,
28 NULL,
28 0, 29 0,
29 false, 30 false,
30 1, 31 1,
31 false)); 32 false));
32 scoped_ptr<ScopedResource> texture = 33 scoped_ptr<ScopedResource> texture =
33 ScopedResource::Create(resource_provider.get()); 34 ScopedResource::Create(resource_provider.get());
34 35
35 // New scoped textures do not hold a texture yet. 36 // New scoped textures do not hold a texture yet.
36 EXPECT_EQ(0u, texture->id()); 37 EXPECT_EQ(0u, texture->id());
37 38
38 // New scoped textures do not have a size yet. 39 // New scoped textures do not have a size yet.
39 EXPECT_EQ(gfx::Size(), texture->size()); 40 EXPECT_EQ(gfx::Size(), texture->size());
40 EXPECT_EQ(0u, texture->bytes()); 41 EXPECT_EQ(0u, texture->bytes());
41 } 42 }
42 43
43 TEST(ScopedResourceTest, CreateScopedResource) { 44 TEST(ScopedResourceTest, CreateScopedResource) {
44 FakeOutputSurfaceClient output_surface_client; 45 FakeOutputSurfaceClient output_surface_client;
45 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); 46 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
46 CHECK(output_surface->BindToClient(&output_surface_client)); 47 CHECK(output_surface->BindToClient(&output_surface_client));
47 48
48 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 49 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
49 new TestSharedBitmapManager()); 50 new TestSharedBitmapManager());
50 scoped_ptr<ResourceProvider> resource_provider( 51 scoped_ptr<ResourceProvider> resource_provider(
51 ResourceProvider::Create(output_surface.get(), 52 ResourceProvider::Create(output_surface.get(),
52 shared_bitmap_manager.get(), 53 shared_bitmap_manager.get(),
53 NULL, 54 NULL,
55 NULL,
54 0, 56 0,
55 false, 57 false,
56 1, 58 1,
57 false)); 59 false));
58 scoped_ptr<ScopedResource> texture = 60 scoped_ptr<ScopedResource> texture =
59 ScopedResource::Create(resource_provider.get()); 61 ScopedResource::Create(resource_provider.get());
60 texture->Allocate( 62 texture->Allocate(
61 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); 63 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888);
62 64
63 // The texture has an allocated byte-size now. 65 // The texture has an allocated byte-size now.
64 size_t expected_bytes = 30 * 30 * 4; 66 size_t expected_bytes = 30 * 30 * 4;
65 EXPECT_EQ(expected_bytes, texture->bytes()); 67 EXPECT_EQ(expected_bytes, texture->bytes());
66 68
67 EXPECT_LT(0u, texture->id()); 69 EXPECT_LT(0u, texture->id());
68 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); 70 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format());
69 EXPECT_EQ(gfx::Size(30, 30), texture->size()); 71 EXPECT_EQ(gfx::Size(30, 30), texture->size());
70 } 72 }
71 73
72 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { 74 TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
73 FakeOutputSurfaceClient output_surface_client; 75 FakeOutputSurfaceClient output_surface_client;
74 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); 76 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
75 CHECK(output_surface->BindToClient(&output_surface_client)); 77 CHECK(output_surface->BindToClient(&output_surface_client));
76 78
77 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 79 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
78 new TestSharedBitmapManager()); 80 new TestSharedBitmapManager());
79 scoped_ptr<ResourceProvider> resource_provider( 81 scoped_ptr<ResourceProvider> resource_provider(
80 ResourceProvider::Create(output_surface.get(), 82 ResourceProvider::Create(output_surface.get(),
81 shared_bitmap_manager.get(), 83 shared_bitmap_manager.get(),
82 NULL, 84 NULL,
85 NULL,
83 0, 86 0,
84 false, 87 false,
85 1, 88 1,
86 false)); 89 false));
87 { 90 {
88 scoped_ptr<ScopedResource> texture = 91 scoped_ptr<ScopedResource> texture =
89 ScopedResource::Create(resource_provider.get()); 92 ScopedResource::Create(resource_provider.get());
90 93
91 EXPECT_EQ(0u, resource_provider->num_resources()); 94 EXPECT_EQ(0u, resource_provider->num_resources());
92 texture->Allocate( 95 texture->Allocate(
(...skipping 20 matching lines...) Expand all
113 FakeOutputSurfaceClient output_surface_client; 116 FakeOutputSurfaceClient output_surface_client;
114 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); 117 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
115 CHECK(output_surface->BindToClient(&output_surface_client)); 118 CHECK(output_surface->BindToClient(&output_surface_client));
116 119
117 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 120 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
118 new TestSharedBitmapManager()); 121 new TestSharedBitmapManager());
119 scoped_ptr<ResourceProvider> resource_provider( 122 scoped_ptr<ResourceProvider> resource_provider(
120 ResourceProvider::Create(output_surface.get(), 123 ResourceProvider::Create(output_surface.get(),
121 shared_bitmap_manager.get(), 124 shared_bitmap_manager.get(),
122 NULL, 125 NULL,
126 NULL,
123 0, 127 0,
124 false, 128 false,
125 1, 129 1,
126 false)); 130 false));
127 { 131 {
128 scoped_ptr<ScopedResource> texture = 132 scoped_ptr<ScopedResource> texture =
129 ScopedResource::Create(resource_provider.get()); 133 ScopedResource::Create(resource_provider.get());
130 134
131 EXPECT_EQ(0u, resource_provider->num_resources()); 135 EXPECT_EQ(0u, resource_provider->num_resources());
132 texture->Allocate( 136 texture->Allocate(
133 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888); 137 gfx::Size(30, 30), ResourceProvider::TextureHintImmutable, RGBA_8888);
134 EXPECT_LT(0u, texture->id()); 138 EXPECT_LT(0u, texture->id());
135 EXPECT_EQ(1u, resource_provider->num_resources()); 139 EXPECT_EQ(1u, resource_provider->num_resources());
136 140
137 texture->Leak(); 141 texture->Leak();
138 EXPECT_EQ(0u, texture->id()); 142 EXPECT_EQ(0u, texture->id());
139 EXPECT_EQ(1u, resource_provider->num_resources()); 143 EXPECT_EQ(1u, resource_provider->num_resources());
140 144
141 texture->Free(); 145 texture->Free();
142 EXPECT_EQ(0u, texture->id()); 146 EXPECT_EQ(0u, texture->id());
143 EXPECT_EQ(1u, resource_provider->num_resources()); 147 EXPECT_EQ(1u, resource_provider->num_resources());
144 } 148 }
145 149
146 EXPECT_EQ(1u, resource_provider->num_resources()); 150 EXPECT_EQ(1u, resource_provider->num_resources());
147 } 151 }
148 152
149 } // namespace 153 } // namespace
150 } // namespace cc 154 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_update_controller_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