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

Side by Side Diff: Source/WebKit/chromium/tests/LayerRendererChromiumTest.cpp

Issue 9969020: Merge 112568 - [chromium] Ensure framebuffer exists at the start of beginDrawingFrame. (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1084/
Patch Set: Created 8 years, 8 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 | « Source/WebKit/chromium/ChangeLog ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 int frameCount() { return m_frame; } 56 int frameCount() { return m_frame; }
57 void setMemoryAllocation(WebGraphicsMemoryAllocation allocation) { m_memoryA llocationChangedCallback->onMemoryAllocationChanged(allocation); } 57 void setMemoryAllocation(WebGraphicsMemoryAllocation allocation) { m_memoryA llocationChangedCallback->onMemoryAllocationChanged(allocation); }
58 58
59 private: 59 private:
60 int m_frame; 60 int m_frame;
61 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* m_memoryAllocationChange dCallback; 61 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* m_memoryAllocationChange dCallback;
62 }; 62 };
63 63
64 class FakeLayerRendererChromiumClient : public LayerRendererChromiumClient { 64 class FakeLayerRendererChromiumClient : public LayerRendererChromiumClient {
65 public: 65 public:
66 FakeLayerRendererChromiumClient() : m_setFullRootLayerDamageCount(0) { } 66 FakeLayerRendererChromiumClient()
67 : m_setFullRootLayerDamageCount(0)
68 , m_rootLayer(CCLayerImpl::create(1))
69 {
70 }
67 71
68 // LayerRendererChromiumClient methods. 72 // LayerRendererChromiumClient methods.
69 virtual const IntSize& viewportSize() const { static IntSize fakeSize; retur n fakeSize; } 73 virtual const IntSize& viewportSize() const { static IntSize fakeSize; retur n fakeSize; }
70 virtual const CCSettings& settings() const { static CCSettings fakeSettings; return fakeSettings; } 74 virtual const CCSettings& settings() const { static CCSettings fakeSettings; return fakeSettings; }
71 virtual CCLayerImpl* rootLayer() { return 0; } 75 virtual CCLayerImpl* rootLayer() { return m_rootLayer.get(); }
72 virtual const CCLayerImpl* rootLayer() const { return 0; } 76 virtual const CCLayerImpl* rootLayer() const { return m_rootLayer.get(); }
73 virtual void didLoseContext() { } 77 virtual void didLoseContext() { }
74 virtual void onSwapBuffersComplete() { } 78 virtual void onSwapBuffersComplete() { }
75 virtual void setFullRootLayerDamage() { m_setFullRootLayerDamageCount++; } 79 virtual void setFullRootLayerDamage() { m_setFullRootLayerDamageCount++; }
76 80
77 // Methods added for test. 81 // Methods added for test.
78 int setFullRootLayerDamageCount() const { return m_setFullRootLayerDamageCou nt; } 82 int setFullRootLayerDamageCount() const { return m_setFullRootLayerDamageCou nt; }
79 83
80 private: 84 private:
81 int m_setFullRootLayerDamageCount; 85 int m_setFullRootLayerDamageCount;
82 DebugScopedSetImplThread m_implThread; 86 DebugScopedSetImplThread m_implThread;
87 OwnPtr<CCLayerImpl> m_rootLayer;
83 }; 88 };
84 89
85 class FakeLayerRendererChromium : public LayerRendererChromium { 90 class FakeLayerRendererChromium : public LayerRendererChromium {
86 public: 91 public:
87 FakeLayerRendererChromium(LayerRendererChromiumClient* client, PassRefPtr<Gr aphicsContext3D> context) : LayerRendererChromium(client, context) { } 92 FakeLayerRendererChromium(LayerRendererChromiumClient* client, PassRefPtr<Gr aphicsContext3D> context) : LayerRendererChromium(client, context) { }
88 93
89 // LayerRendererChromium methods. 94 // LayerRendererChromium methods.
90 95
91 // Changing visibility to public. 96 // Changing visibility to public.
92 using LayerRendererChromium::initialize; 97 using LayerRendererChromium::initialize;
98 using LayerRendererChromium::isFramebufferDiscarded;
93 }; 99 };
94 100
95 class LayerRendererChromiumTest : public testing::Test { 101 class LayerRendererChromiumTest : public testing::Test {
96 protected: 102 protected:
97 LayerRendererChromiumTest() 103 LayerRendererChromiumTest()
98 : m_suggestHaveBackbufferYes(1, true) 104 : m_suggestHaveBackbufferYes(1, true)
99 , m_suggestHaveBackbufferNo(1, false) 105 , m_suggestHaveBackbufferNo(1, false)
100 , m_context(GraphicsContext3DPrivate::createGraphicsContextFromWebContex t(adoptPtr(new FrameCountingMemoryAllocationSettingContext()), GraphicsContext3D ::RenderDirectlyToHostWindow)) 106 , m_context(GraphicsContext3DPrivate::createGraphicsContextFromWebContex t(adoptPtr(new FrameCountingMemoryAllocationSettingContext()), GraphicsContext3D ::RenderDirectlyToHostWindow))
101 , m_mockContext(*static_cast<FrameCountingMemoryAllocationSettingContext *>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_context.get()))) 107 , m_mockContext(*static_cast<FrameCountingMemoryAllocationSettingContext *>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_context.get())))
102 , m_layerRendererChromium(&m_mockClient, m_context.release()) 108 , m_layerRendererChromium(&m_mockClient, m_context.release())
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 swapBuffers(); 177 swapBuffers();
172 EXPECT_EQ(0, m_mockContext.frameCount()); 178 EXPECT_EQ(0, m_mockContext.frameCount());
173 EXPECT_EQ(2, m_mockClient.setFullRootLayerDamageCount()); 179 EXPECT_EQ(2, m_mockClient.setFullRootLayerDamageCount());
174 180
175 swapBuffers(); 181 swapBuffers();
176 EXPECT_EQ(0, m_mockContext.frameCount()); 182 EXPECT_EQ(0, m_mockContext.frameCount());
177 EXPECT_EQ(3, m_mockClient.setFullRootLayerDamageCount()); 183 EXPECT_EQ(3, m_mockClient.setFullRootLayerDamageCount());
178 } 184 }
179 185
180 // Test LayerRendererChromium discardFramebuffer functionality: 186 // Test LayerRendererChromium discardFramebuffer functionality:
181 // Discard framebuffer, then set visibility to true. 187 // Begin drawing a frame while a framebuffer is discarded.
182 // Expected: recreates the framebuffer. 188 // Expected: will recreate framebuffer.
183 TEST_F(LayerRendererChromiumTest, SetVisibilityTrueShouldRecreateBackbuffer)
184 {
185 m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo);
186 EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded());
187
188 m_layerRendererChromium.setVisible(true);
189 EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
190 }
191
192 // Test LayerRendererChromium discardFramebuffer functionality:
193 // Create a ScopedEnsureFramebufferAllocation while a framebuffer was discarded and then swapBuffers.
194 // Expected: will recreate framebuffer scope duration, during which swaps will w ork fine, and discard on scope exit.
195 TEST_F(LayerRendererChromiumTest, DiscardedBackbufferIsRecreatredForScopeDuratio n) 189 TEST_F(LayerRendererChromiumTest, DiscardedBackbufferIsRecreatredForScopeDuratio n)
196 { 190 {
197 m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo); 191 m_mockContext.setMemoryAllocation(m_suggestHaveBackbufferNo);
198 EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded()); 192 EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded());
199 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); 193 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount());
200 {
201 ScopedEnsureFramebufferAllocation ensureFramebuffer(&m_layerRendererChro mium);
202 EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
203 194
204 swapBuffers(); 195 m_layerRendererChromium.beginDrawingFrame();
205 EXPECT_EQ(1, m_mockContext.frameCount()); 196 EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
206 } 197
207 EXPECT_TRUE(m_layerRendererChromium.isFramebufferDiscarded()); 198 swapBuffers();
208 EXPECT_EQ(2, m_mockClient.setFullRootLayerDamageCount()); 199 EXPECT_EQ(1, m_mockContext.frameCount());
209 } 200 }
210
211 // Test LayerRendererChromium discardFramebuffer functionality:
212 // Create a ScopedEnsureFramebufferAllocation while a framebuffer was not discar ded and then swapBuffers.
213 // Expected: will have no effect.
214 TEST_F(LayerRendererChromiumTest, EnsuringBackbufferForScopeDurationDoesNothingI fAlreadyExists)
215 {
216 EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
217 EXPECT_EQ(0, m_mockClient.setFullRootLayerDamageCount());
218 {
219 ScopedEnsureFramebufferAllocation ensureFramebuffer(&m_layerRendererChro mium);
220 EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
221 EXPECT_EQ(0, m_mockClient.setFullRootLayerDamageCount());
222
223 swapBuffers();
224 EXPECT_EQ(1, m_mockContext.frameCount());
225 }
226 EXPECT_FALSE(m_layerRendererChromium.isFramebufferDiscarded());
227 EXPECT_EQ(0, m_mockClient.setFullRootLayerDamageCount());
228 }
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/ChangeLog ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698