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

Side by Side Diff: cc/nine_patch_layer_unittest.cc

Issue 11304020: cc: Nine patch layer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix DCHECK failures and rebase to 166129 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
OLDNEW
(Empty)
1 // Copyright 2012 The 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/nine_patch_layer.h"
8
9 #include "cc/layer_tree_host.h"
10 #include "cc/occlusion_tracker.h"
11 #include "cc/overdraw_metrics.h"
12 #include "cc/rendering_stats.h"
13 #include "cc/resource_provider.h"
14 #include "cc/single_thread_proxy.h"
15 #include "cc/resource_update_queue.h"
16 #include "cc/texture_uploader.h"
17 #include "cc/test/fake_graphics_context.h"
18 #include "cc/test/fake_layer_tree_host_client.h"
19 #include "cc/test/geometry_test_utils.h"
20 #include "cc/test/layer_tree_test_common.h"
21 #include "SkBitmap.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24
25 using namespace cc;
26 using ::testing::Mock;
27 using ::testing::_;
28 using ::testing::AtLeast;
29 using ::testing::AnyNumber;
30
31 namespace {
32
33 class MockLayerTreeHost : public LayerTreeHost {
34 public:
35 MockLayerTreeHost()
36 : LayerTreeHost(&m_fakeClient, LayerTreeSettings())
37 {
38 initialize();
39 }
40
41 private:
42 FakeLayerImplTreeHostClient m_fakeClient;
43 };
44
45
46 class NinePatchLayerTest : public testing::Test {
47 public:
48 NinePatchLayerTest()
49 {
50 }
51
52 protected:
53 virtual void SetUp()
54 {
55 m_layerTreeHost.reset(new MockLayerTreeHost);
56 }
57
58 virtual void TearDown()
59 {
60 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
61 }
62
63 scoped_ptr<MockLayerTreeHost> m_layerTreeHost;
64 };
65
66 TEST_F(NinePatchLayerTest, triggerFullUploadOnceWhenChangingBitmap)
67 {
68 scoped_refptr<NinePatchLayer> testLayer = NinePatchLayer::create();
69 ASSERT_TRUE(testLayer);
70 testLayer->setIsDrawable(true);
71 testLayer->setBounds(gfx::Size(100, 100));
72
73 m_layerTreeHost->setRootLayer(testLayer);
74 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
75 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get());
76
77 m_layerTreeHost->initializeRendererIfNeeded();
78
79 PriorityCalculator calculator;
80 ResourceUpdateQueue queue;
81 OcclusionTracker occlusionTracker(gfx::Rect(), false);
82 RenderingStats stats;
83
84 // No bitmap set should not trigger any uploads.
85 testLayer->setTexturePriorities(calculator);
86 testLayer->update(queue, &occlusionTracker, stats);
87 EXPECT_EQ(queue.fullUploadSize(), 0);
88 EXPECT_EQ(queue.partialUploadSize(), 0);
89
90 // Setting a bitmap set should trigger a single full upload.
91 SkBitmap bitmap;
92 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
93 bitmap.allocPixels();
94 testLayer->setBitmap(bitmap, gfx::Rect(5, 5, 1, 1));
95 testLayer->setTexturePriorities(calculator);
96 testLayer->update(queue, &occlusionTracker, stats);
97 EXPECT_EQ(queue.fullUploadSize(), 1);
98 EXPECT_EQ(queue.partialUploadSize(), 0);
99 ResourceUpdate params = queue.takeFirstFullUpload();
100 EXPECT_TRUE(params.texture != NULL);
101
102 // Upload the texture.
103 m_layerTreeHost->contentsTextureManager()->setMaxMemoryLimitBytes(1024 * 102 4);
104 m_layerTreeHost->contentsTextureManager()->prioritizeTextures();
105
106 scoped_ptr<GraphicsContext> context;
107 scoped_ptr<ResourceProvider> resourceProvider;
108 {
109 DebugScopedSetImplThread implThread;
110 DebugScopedSetMainThreadBlocked mainThreadBlocked;
111 context = WebKit::createFakeGraphicsContext();
112 resourceProvider = ResourceProvider::create(context.get());
113 params.texture->acquireBackingTexture(resourceProvider.get());
114 ASSERT_TRUE(params.texture->haveBackingTexture());
115 }
116
117 // Nothing changed, so no repeated upload.
118 testLayer->setTexturePriorities(calculator);
119 {
120 DebugScopedSetImplThread implThread;
121 testLayer->update(queue, &occlusionTracker, stats);
122 }
123 EXPECT_EQ(queue.fullUploadSize(), 0);
124 EXPECT_EQ(queue.partialUploadSize(), 0);
125
126 {
127 DebugScopedSetImplThread implThread;
128 DebugScopedSetMainThreadBlocked mainThreadBlocked;
129 m_layerTreeHost->contentsTextureManager()->clearAllMemory(resourceProvid er.get());
130 }
131
132 // Reupload after eviction
133 testLayer->setTexturePriorities(calculator);
134 {
135 DebugScopedSetImplThread implThread;
136 testLayer->update(queue, &occlusionTracker, stats);
137 }
138 EXPECT_EQ(queue.fullUploadSize(), 1);
139 EXPECT_EQ(queue.partialUploadSize(), 0);
140 }
141
142 } // anonymous namespace
OLDNEW
« no previous file with comments | « cc/nine_patch_layer_impl_unittest.cc ('k') | webkit/compositor_bindings/compositor_bindings.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698