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

Side by Side Diff: cc/scoped_resource_unittest.cc

Issue 12471007: Part 8 of cc/ directory shuffles: resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « cc/scoped_resource.cc ('k') | cc/scrollbar_layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "cc/scoped_resource.h"
6
7 #include "cc/output/renderer.h"
8 #include "cc/test/fake_output_surface.h"
9 #include "cc/test/tiled_layer_test_common.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/khronos/GLES2/gl2.h"
12
13 using namespace WebKit;
14
15 namespace cc {
16 namespace {
17
18 TEST(ScopedResourceTest, NewScopedResource)
19 {
20 scoped_ptr<OutputSurface> context(createFakeOutputSurface());
21 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::Create(conte xt.get()));
22 scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProvider .get());
23
24 // New scoped textures do not hold a texture yet.
25 EXPECT_EQ(0u, texture->id());
26
27 // New scoped textures do not have a size yet.
28 EXPECT_EQ(gfx::Size(), texture->size());
29 EXPECT_EQ(0u, texture->bytes());
30 }
31
32 TEST(ScopedResourceTest, CreateScopedResource)
33 {
34 scoped_ptr<OutputSurface> context(createFakeOutputSurface());
35 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::Create(conte xt.get()));
36 scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProvider .get());
37 texture->Allocate(gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsage Any);
38
39 // The texture has an allocated byte-size now.
40 size_t expectedBytes = 30 * 30 * 4;
41 EXPECT_EQ(expectedBytes, texture->bytes());
42
43 EXPECT_LT(0u, texture->id());
44 EXPECT_EQ(GL_RGBA, texture->format());
45 EXPECT_EQ(gfx::Size(30, 30), texture->size());
46 }
47
48 TEST(ScopedResourceTest, ScopedResourceIsDeleted)
49 {
50 scoped_ptr<OutputSurface> context(createFakeOutputSurface());
51 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::Create(conte xt.get()));
52
53 {
54 scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProv ider.get());
55
56 EXPECT_EQ(0u, resourceProvider->num_resources());
57 texture->Allocate(gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureU sageAny);
58 EXPECT_LT(0u, texture->id());
59 EXPECT_EQ(1u, resourceProvider->num_resources());
60 }
61
62 EXPECT_EQ(0u, resourceProvider->num_resources());
63
64 {
65 scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProv ider.get());
66 EXPECT_EQ(0u, resourceProvider->num_resources());
67 texture->Allocate(gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureU sageAny);
68 EXPECT_LT(0u, texture->id());
69 EXPECT_EQ(1u, resourceProvider->num_resources());
70 texture->Free();
71 EXPECT_EQ(0u, resourceProvider->num_resources());
72 }
73 }
74
75 TEST(ScopedResourceTest, LeakScopedResource)
76 {
77 scoped_ptr<OutputSurface> context(createFakeOutputSurface());
78 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::Create(conte xt.get()));
79
80 {
81 scoped_ptr<ScopedResource> texture = ScopedResource::create(resourceProv ider.get());
82
83 EXPECT_EQ(0u, resourceProvider->num_resources());
84 texture->Allocate(gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureU sageAny);
85 EXPECT_LT(0u, texture->id());
86 EXPECT_EQ(1u, resourceProvider->num_resources());
87
88 texture->Leak();
89 EXPECT_EQ(0u, texture->id());
90 EXPECT_EQ(1u, resourceProvider->num_resources());
91
92 texture->Free();
93 EXPECT_EQ(0u, texture->id());
94 EXPECT_EQ(1u, resourceProvider->num_resources());
95 }
96
97 EXPECT_EQ(1u, resourceProvider->num_resources());
98 }
99
100 } // namespace
101 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scoped_resource.cc ('k') | cc/scrollbar_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698