Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / cc / resources / scoped_resource_unittest.cc
blob8c97d8e46dbaeafcc861cf502ffa9b849afb4491
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
3 // found in the LICENSE file.
5 #include "cc/resources/scoped_resource.h"
7 #include "cc/output/renderer.h"
8 #include "cc/test/fake_output_surface.h"
9 #include "cc/test/fake_output_surface_client.h"
10 #include "cc/test/test_shared_bitmap_manager.h"
11 #include "cc/test/tiled_layer_test_common.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace cc {
15 namespace {
17 TEST(ScopedResourceTest, NewScopedResource) {
18 FakeOutputSurfaceClient output_surface_client;
19 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
20 CHECK(output_surface->BindToClient(&output_surface_client));
22 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
23 new TestSharedBitmapManager());
24 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
25 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1));
26 scoped_ptr<ScopedResource> texture =
27 ScopedResource::Create(resource_provider.get());
29 // New scoped textures do not hold a texture yet.
30 EXPECT_EQ(0u, texture->id());
32 // New scoped textures do not have a size yet.
33 EXPECT_EQ(gfx::Size(), texture->size());
34 EXPECT_EQ(0u, texture->bytes());
37 TEST(ScopedResourceTest, CreateScopedResource) {
38 FakeOutputSurfaceClient output_surface_client;
39 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
40 CHECK(output_surface->BindToClient(&output_surface_client));
42 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
43 new TestSharedBitmapManager());
44 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
45 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1));
46 scoped_ptr<ScopedResource> texture =
47 ScopedResource::Create(resource_provider.get());
48 texture->Allocate(gfx::Size(30, 30),
49 ResourceProvider::TextureUsageAny,
50 RGBA_8888);
52 // The texture has an allocated byte-size now.
53 size_t expected_bytes = 30 * 30 * 4;
54 EXPECT_EQ(expected_bytes, texture->bytes());
56 EXPECT_LT(0u, texture->id());
57 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format());
58 EXPECT_EQ(gfx::Size(30, 30), texture->size());
61 TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
62 FakeOutputSurfaceClient output_surface_client;
63 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
64 CHECK(output_surface->BindToClient(&output_surface_client));
66 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
67 new TestSharedBitmapManager());
68 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
69 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1));
71 scoped_ptr<ScopedResource> texture =
72 ScopedResource::Create(resource_provider.get());
74 EXPECT_EQ(0u, resource_provider->num_resources());
75 texture->Allocate(gfx::Size(30, 30),
76 ResourceProvider::TextureUsageAny,
77 RGBA_8888);
78 EXPECT_LT(0u, texture->id());
79 EXPECT_EQ(1u, resource_provider->num_resources());
82 EXPECT_EQ(0u, resource_provider->num_resources());
84 scoped_ptr<ScopedResource> texture =
85 ScopedResource::Create(resource_provider.get());
86 EXPECT_EQ(0u, resource_provider->num_resources());
87 texture->Allocate(gfx::Size(30, 30),
88 ResourceProvider::TextureUsageAny,
89 RGBA_8888);
90 EXPECT_LT(0u, texture->id());
91 EXPECT_EQ(1u, resource_provider->num_resources());
92 texture->Free();
93 EXPECT_EQ(0u, resource_provider->num_resources());
97 TEST(ScopedResourceTest, LeakScopedResource) {
98 FakeOutputSurfaceClient output_surface_client;
99 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
100 CHECK(output_surface->BindToClient(&output_surface_client));
102 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
103 new TestSharedBitmapManager());
104 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
105 output_surface.get(), shared_bitmap_manager.get(), 0, false, 1));
107 scoped_ptr<ScopedResource> texture =
108 ScopedResource::Create(resource_provider.get());
110 EXPECT_EQ(0u, resource_provider->num_resources());
111 texture->Allocate(gfx::Size(30, 30),
112 ResourceProvider::TextureUsageAny,
113 RGBA_8888);
114 EXPECT_LT(0u, texture->id());
115 EXPECT_EQ(1u, resource_provider->num_resources());
117 texture->Leak();
118 EXPECT_EQ(0u, texture->id());
119 EXPECT_EQ(1u, resource_provider->num_resources());
121 texture->Free();
122 EXPECT_EQ(0u, texture->id());
123 EXPECT_EQ(1u, resource_provider->num_resources());
126 EXPECT_EQ(1u, resource_provider->num_resources());
129 } // namespace
130 } // namespace cc