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

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

Issue 1154393003: cc: Use CheckedNumeric for resource size calculations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: initialize var Created 5 years, 6 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
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/tiles/tile.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/fake_resource_provider.h" 10 #include "cc/test/fake_resource_provider.h"
(...skipping 14 matching lines...) Expand all
25 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( 25 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create(
26 output_surface.get(), shared_bitmap_manager.get()); 26 output_surface.get(), shared_bitmap_manager.get());
27 scoped_ptr<ScopedResource> texture = 27 scoped_ptr<ScopedResource> texture =
28 ScopedResource::Create(resource_provider.get()); 28 ScopedResource::Create(resource_provider.get());
29 29
30 // New scoped textures do not hold a texture yet. 30 // New scoped textures do not hold a texture yet.
31 EXPECT_EQ(0u, texture->id()); 31 EXPECT_EQ(0u, texture->id());
32 32
33 // New scoped textures do not have a size yet. 33 // New scoped textures do not have a size yet.
34 EXPECT_EQ(gfx::Size(), texture->size()); 34 EXPECT_EQ(gfx::Size(), texture->size());
35 EXPECT_EQ(0u, texture->bytes()); 35 EXPECT_EQ(0u, Resource::UncheckedMemorySizeBytes(texture->size(),
36 texture->format()));
36 } 37 }
37 38
38 TEST(ScopedResourceTest, CreateScopedResource) { 39 TEST(ScopedResourceTest, CreateScopedResource) {
39 FakeOutputSurfaceClient output_surface_client; 40 FakeOutputSurfaceClient output_surface_client;
40 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); 41 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
41 CHECK(output_surface->BindToClient(&output_surface_client)); 42 CHECK(output_surface->BindToClient(&output_surface_client));
42 43
43 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 44 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
44 new TestSharedBitmapManager()); 45 new TestSharedBitmapManager());
45 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create( 46 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create(
46 output_surface.get(), shared_bitmap_manager.get()); 47 output_surface.get(), shared_bitmap_manager.get());
47 scoped_ptr<ScopedResource> texture = 48 scoped_ptr<ScopedResource> texture =
48 ScopedResource::Create(resource_provider.get()); 49 ScopedResource::Create(resource_provider.get());
49 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, 50 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
50 RGBA_8888); 51 RGBA_8888);
51 52
52 // The texture has an allocated byte-size now. 53 // The texture has an allocated byte-size now.
53 size_t expected_bytes = 30 * 30 * 4; 54 size_t expected_bytes = 30 * 30 * 4;
54 EXPECT_EQ(expected_bytes, texture->bytes()); 55 EXPECT_EQ(expected_bytes, Resource::UncheckedMemorySizeBytes(
56 texture->size(), texture->format()));
55 57
56 EXPECT_LT(0u, texture->id()); 58 EXPECT_LT(0u, texture->id());
57 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); 59 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format());
58 EXPECT_EQ(gfx::Size(30, 30), texture->size()); 60 EXPECT_EQ(gfx::Size(30, 30), texture->size());
59 } 61 }
60 62
61 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { 63 TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
62 FakeOutputSurfaceClient output_surface_client; 64 FakeOutputSurfaceClient output_surface_client;
63 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); 65 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
64 CHECK(output_surface->BindToClient(&output_surface_client)); 66 CHECK(output_surface->BindToClient(&output_surface_client));
(...skipping 22 matching lines...) Expand all
87 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888); 89 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888);
88 EXPECT_LT(0u, texture->id()); 90 EXPECT_LT(0u, texture->id());
89 EXPECT_EQ(1u, resource_provider->num_resources()); 91 EXPECT_EQ(1u, resource_provider->num_resources());
90 texture->Free(); 92 texture->Free();
91 EXPECT_EQ(0u, resource_provider->num_resources()); 93 EXPECT_EQ(0u, resource_provider->num_resources());
92 } 94 }
93 } 95 }
94 96
95 } // namespace 97 } // namespace
96 } // namespace cc 98 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/tiles/tile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698