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

Side by Side Diff: cc/scoped_texture_unittest.cc

Issue 11377055: cc: Rename Texture class to Resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 1 month 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_texture.cc ('k') | cc/software_renderer.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 "config.h"
6
7 #include "cc/scoped_texture.h"
8
9 #include "cc/renderer.h"
10 #include "cc/test/fake_graphics_context.h"
11 #include "cc/test/tiled_layer_test_common.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/khronos/GLES2/gl2.h"
14
15 using namespace cc;
16 using namespace WebKit;
17 using namespace WebKitTests;
18
19 namespace {
20
21 TEST(ScopedTextureTest, NewScopedTexture)
22 {
23 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
24 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
25 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g et());
26
27 // New scoped textures do not hold a texture yet.
28 EXPECT_EQ(0u, texture->id());
29
30 // New scoped textures do not have a size yet.
31 EXPECT_EQ(gfx::Size(), texture->size());
32 EXPECT_EQ(0u, texture->bytes());
33 }
34
35 TEST(ScopedTextureTest, CreateScopedTexture)
36 {
37 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
38 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
39 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.g et());
40 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, ResourcePr ovider::TextureUsageAny);
41
42 // The texture has an allocated byte-size now.
43 size_t expectedBytes = 30 * 30 * 4;
44 EXPECT_EQ(expectedBytes, texture->bytes());
45
46 EXPECT_LT(0u, texture->id());
47 EXPECT_EQ(GL_RGBA, texture->format());
48 EXPECT_EQ(gfx::Size(30, 30), texture->size());
49 }
50
51 TEST(ScopedTextureTest, ScopedTextureIsDeleted)
52 {
53 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
54 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
55
56 {
57 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get());
58
59 EXPECT_EQ(0u, resourceProvider->numResources());
60 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny);
61 EXPECT_LT(0u, texture->id());
62 EXPECT_EQ(1u, resourceProvider->numResources());
63 }
64
65 EXPECT_EQ(0u, resourceProvider->numResources());
66
67 {
68 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get());
69 EXPECT_EQ(0u, resourceProvider->numResources());
70 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny);
71 EXPECT_LT(0u, texture->id());
72 EXPECT_EQ(1u, resourceProvider->numResources());
73 texture->free();
74 EXPECT_EQ(0u, resourceProvider->numResources());
75 }
76 }
77
78 TEST(ScopedTextureTest, LeakScopedTexture)
79 {
80 scoped_ptr<GraphicsContext> context(createFakeGraphicsContext());
81 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
82
83 {
84 scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvid er.get());
85
86 EXPECT_EQ(0u, resourceProvider->numResources());
87 texture->allocate(Renderer::ImplPool, gfx::Size(30, 30), GL_RGBA, Resour ceProvider::TextureUsageAny);
88 EXPECT_LT(0u, texture->id());
89 EXPECT_EQ(1u, resourceProvider->numResources());
90
91 texture->leak();
92 EXPECT_EQ(0u, texture->id());
93 EXPECT_EQ(1u, resourceProvider->numResources());
94
95 texture->free();
96 EXPECT_EQ(0u, texture->id());
97 EXPECT_EQ(1u, resourceProvider->numResources());
98 }
99
100 EXPECT_EQ(1u, resourceProvider->numResources());
101 }
102
103 } // anonymous namespace
OLDNEW
« no previous file with comments | « cc/scoped_texture.cc ('k') | cc/software_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698