| OLD | NEW |
| 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 "config.h" | 5 #include "config.h" |
| 6 #include "CCRendererGL.h" | 6 #include "CCRendererGL.h" |
| 7 | 7 |
| 8 #include "CCDrawQuad.h" | 8 #include "CCDrawQuad.h" |
| 9 #include "CCPrioritizedTextureManager.h" | 9 #include "CCPrioritizedTextureManager.h" |
| 10 #include "CCResourceProvider.h" | 10 #include "CCResourceProvider.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 { | 36 { |
| 37 if (name == GraphicsContext3D::EXTENSIONS) | 37 if (name == GraphicsContext3D::EXTENSIONS) |
| 38 return WebString("GL_CHROMIUM_set_visibility GL_CHROMIUM_gpu_memory_
manager GL_CHROMIUM_discard_framebuffer"); | 38 return WebString("GL_CHROMIUM_set_visibility GL_CHROMIUM_gpu_memory_
manager GL_CHROMIUM_discard_framebuffer"); |
| 39 return WebString(); | 39 return WebString(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Methods added for test. | 42 // Methods added for test. |
| 43 int frameCount() { return m_frame; } | 43 int frameCount() { return m_frame; } |
| 44 void setMemoryAllocation(WebGraphicsMemoryAllocation allocation) | 44 void setMemoryAllocation(WebGraphicsMemoryAllocation allocation) |
| 45 { | 45 { |
| 46 ASSERT(CCProxy::isImplThread()); | 46 ASSERT(Proxy::isImplThread()); |
| 47 // In single threaded mode we expect this callback on main thread. | 47 // In single threaded mode we expect this callback on main thread. |
| 48 DebugScopedSetMainThread main; | 48 DebugScopedSetMainThread main; |
| 49 m_memoryAllocationChangedCallback->onMemoryAllocationChanged(allocation)
; | 49 m_memoryAllocationChangedCallback->onMemoryAllocationChanged(allocation)
; |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 int m_frame; | 53 int m_frame; |
| 54 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* m_memoryAllocationChange
dCallback; | 54 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* m_memoryAllocationChange
dCallback; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class FakeCCRendererClient : public CCRendererClient { | 57 class FakeRendererClient : public RendererClient { |
| 58 public: | 58 public: |
| 59 FakeCCRendererClient() | 59 FakeRendererClient() |
| 60 : m_setFullRootLayerDamageCount(0) | 60 : m_setFullRootLayerDamageCount(0) |
| 61 , m_rootLayer(CCLayerImpl::create(1)) | 61 , m_rootLayer(LayerImpl::create(1)) |
| 62 , m_memoryAllocationLimitBytes(CCPrioritizedTextureManager::defaultMemor
yAllocationLimit()) | 62 , m_memoryAllocationLimitBytes(PrioritizedTextureManager::defaultMemoryA
llocationLimit()) |
| 63 { | 63 { |
| 64 m_rootLayer->createRenderSurface(); | 64 m_rootLayer->createRenderSurface(); |
| 65 CCRenderPass::Id renderPassId = m_rootLayer->renderSurface()->renderPass
Id(); | 65 RenderPass::Id renderPassId = m_rootLayer->renderSurface()->renderPassId
(); |
| 66 scoped_ptr<CCRenderPass> rootRenderPass = CCRenderPass::create(renderPas
sId, IntRect(), WebTransformationMatrix()); | 66 scoped_ptr<RenderPass> rootRenderPass = RenderPass::create(renderPassId,
IntRect(), WebTransformationMatrix()); |
| 67 m_renderPassesInDrawOrder.push_back(rootRenderPass.get()); | 67 m_renderPassesInDrawOrder.push_back(rootRenderPass.get()); |
| 68 m_renderPasses.set(renderPassId, rootRenderPass.Pass()); | 68 m_renderPasses.set(renderPassId, rootRenderPass.Pass()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // CCRendererClient methods. | 71 // RendererClient methods. |
| 72 virtual const IntSize& deviceViewportSize() const OVERRIDE { static IntSize
fakeSize(1, 1); return fakeSize; } | 72 virtual const IntSize& deviceViewportSize() const OVERRIDE { static IntSize
fakeSize(1, 1); return fakeSize; } |
| 73 virtual const CCLayerTreeSettings& settings() const OVERRIDE { static CCLaye
rTreeSettings fakeSettings; return fakeSettings; } | 73 virtual const LayerTreeSettings& settings() const OVERRIDE { static LayerTre
eSettings fakeSettings; return fakeSettings; } |
| 74 virtual void didLoseContext() OVERRIDE { } | 74 virtual void didLoseContext() OVERRIDE { } |
| 75 virtual void onSwapBuffersComplete() OVERRIDE { } | 75 virtual void onSwapBuffersComplete() OVERRIDE { } |
| 76 virtual void setFullRootLayerDamage() OVERRIDE { m_setFullRootLayerDamageCou
nt++; } | 76 virtual void setFullRootLayerDamage() OVERRIDE { m_setFullRootLayerDamageCou
nt++; } |
| 77 virtual void setMemoryAllocationLimitBytes(size_t bytes) OVERRIDE { m_memory
AllocationLimitBytes = bytes; } | 77 virtual void setMemoryAllocationLimitBytes(size_t bytes) OVERRIDE { m_memory
AllocationLimitBytes = bytes; } |
| 78 | 78 |
| 79 // Methods added for test. | 79 // Methods added for test. |
| 80 int setFullRootLayerDamageCount() const { return m_setFullRootLayerDamageCou
nt; } | 80 int setFullRootLayerDamageCount() const { return m_setFullRootLayerDamageCou
nt; } |
| 81 | 81 |
| 82 CCRenderPass* rootRenderPass() { return m_renderPassesInDrawOrder.back(); } | 82 RenderPass* rootRenderPass() { return m_renderPassesInDrawOrder.back(); } |
| 83 const CCRenderPassList& renderPassesInDrawOrder() const { return m_renderPas
sesInDrawOrder; } | 83 const RenderPassList& renderPassesInDrawOrder() const { return m_renderPasse
sInDrawOrder; } |
| 84 const CCRenderPassIdHashMap& renderPasses() const { return m_renderPasses; } | 84 const RenderPassIdHashMap& renderPasses() const { return m_renderPasses; } |
| 85 | 85 |
| 86 size_t memoryAllocationLimitBytes() const { return m_memoryAllocationLimitBy
tes; } | 86 size_t memoryAllocationLimitBytes() const { return m_memoryAllocationLimitBy
tes; } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 int m_setFullRootLayerDamageCount; | 89 int m_setFullRootLayerDamageCount; |
| 90 DebugScopedSetImplThread m_implThread; | 90 DebugScopedSetImplThread m_implThread; |
| 91 scoped_ptr<CCLayerImpl> m_rootLayer; | 91 scoped_ptr<LayerImpl> m_rootLayer; |
| 92 CCRenderPassList m_renderPassesInDrawOrder; | 92 RenderPassList m_renderPassesInDrawOrder; |
| 93 CCRenderPassIdHashMap m_renderPasses; | 93 RenderPassIdHashMap m_renderPasses; |
| 94 size_t m_memoryAllocationLimitBytes; | 94 size_t m_memoryAllocationLimitBytes; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 class FakeCCRendererGL : public CCRendererGL { | 97 class FakeRendererGL : public GLRenderer { |
| 98 public: | 98 public: |
| 99 FakeCCRendererGL(CCRendererClient* client, CCResourceProvider* resourceProvi
der) : CCRendererGL(client, resourceProvider) { } | 99 FakeRendererGL(RendererClient* client, ResourceProvider* resourceProvider) :
GLRenderer(client, resourceProvider) { } |
| 100 | 100 |
| 101 // CCRendererGL methods. | 101 // GLRenderer methods. |
| 102 | 102 |
| 103 // Changing visibility to public. | 103 // Changing visibility to public. |
| 104 using CCRendererGL::initialize; | 104 using GLRenderer::initialize; |
| 105 using CCRendererGL::isFramebufferDiscarded; | 105 using GLRenderer::isFramebufferDiscarded; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 class CCRendererGLTest : public testing::Test { | 108 class GLRendererTest : public testing::Test { |
| 109 protected: | 109 protected: |
| 110 CCRendererGLTest() | 110 GLRendererTest() |
| 111 : m_suggestHaveBackbufferYes(1, true) | 111 : m_suggestHaveBackbufferYes(1, true) |
| 112 , m_suggestHaveBackbufferNo(1, false) | 112 , m_suggestHaveBackbufferNo(1, false) |
| 113 , m_compositorInitializer(0) | 113 , m_compositorInitializer(0) |
| 114 , m_context(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We
bGraphicsContext3D>(new FrameCountingMemoryAllocationSettingContext()))) | 114 , m_context(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We
bGraphicsContext3D>(new FrameCountingMemoryAllocationSettingContext()))) |
| 115 , m_resourceProvider(CCResourceProvider::create(m_context.get())) | 115 , m_resourceProvider(ResourceProvider::create(m_context.get())) |
| 116 , m_renderer(&m_mockClient, m_resourceProvider.get()) | 116 , m_renderer(&m_mockClient, m_resourceProvider.get()) |
| 117 { | 117 { |
| 118 } | 118 } |
| 119 | 119 |
| 120 virtual void SetUp() | 120 virtual void SetUp() |
| 121 { | 121 { |
| 122 m_renderer.initialize(); | 122 m_renderer.initialize(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void swapBuffers() | 125 void swapBuffers() |
| 126 { | 126 { |
| 127 m_renderer.swapBuffers(); | 127 m_renderer.swapBuffers(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 FrameCountingMemoryAllocationSettingContext* context() { return static_cast<
FrameCountingMemoryAllocationSettingContext*>(m_context->context3D()); } | 130 FrameCountingMemoryAllocationSettingContext* context() { return static_cast<
FrameCountingMemoryAllocationSettingContext*>(m_context->context3D()); } |
| 131 | 131 |
| 132 WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes; | 132 WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes; |
| 133 WebGraphicsMemoryAllocation m_suggestHaveBackbufferNo; | 133 WebGraphicsMemoryAllocation m_suggestHaveBackbufferNo; |
| 134 | 134 |
| 135 WebCompositorInitializer m_compositorInitializer; | 135 WebCompositorInitializer m_compositorInitializer; |
| 136 scoped_ptr<CCGraphicsContext> m_context; | 136 scoped_ptr<GraphicsContext> m_context; |
| 137 FakeCCRendererClient m_mockClient; | 137 FakeRendererClient m_mockClient; |
| 138 scoped_ptr<CCResourceProvider> m_resourceProvider; | 138 scoped_ptr<ResourceProvider> m_resourceProvider; |
| 139 FakeCCRendererGL m_renderer; | 139 FakeRendererGL m_renderer; |
| 140 CCScopedSettings m_scopedSettings; | 140 ScopedSettings m_scopedSettings; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 // Test CCRendererGL discardFramebuffer functionality: | 143 // Test GLRenderer discardFramebuffer functionality: |
| 144 // Suggest recreating framebuffer when one already exists. | 144 // Suggest recreating framebuffer when one already exists. |
| 145 // Expected: it does nothing. | 145 // Expected: it does nothing. |
| 146 TEST_F(CCRendererGLTest, SuggestBackbufferYesWhenItAlreadyExistsShouldDoNothing) | 146 TEST_F(GLRendererTest, SuggestBackbufferYesWhenItAlreadyExistsShouldDoNothing) |
| 147 { | 147 { |
| 148 context()->setMemoryAllocation(m_suggestHaveBackbufferYes); | 148 context()->setMemoryAllocation(m_suggestHaveBackbufferYes); |
| 149 EXPECT_EQ(0, m_mockClient.setFullRootLayerDamageCount()); | 149 EXPECT_EQ(0, m_mockClient.setFullRootLayerDamageCount()); |
| 150 EXPECT_FALSE(m_renderer.isFramebufferDiscarded()); | 150 EXPECT_FALSE(m_renderer.isFramebufferDiscarded()); |
| 151 | 151 |
| 152 swapBuffers(); | 152 swapBuffers(); |
| 153 EXPECT_EQ(1, context()->frameCount()); | 153 EXPECT_EQ(1, context()->frameCount()); |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Test CCRendererGL discardFramebuffer functionality: | 156 // Test GLRenderer discardFramebuffer functionality: |
| 157 // Suggest discarding framebuffer when one exists and the renderer is not visibl
e. | 157 // Suggest discarding framebuffer when one exists and the renderer is not visibl
e. |
| 158 // Expected: it is discarded and damage tracker is reset. | 158 // Expected: it is discarded and damage tracker is reset. |
| 159 TEST_F(CCRendererGLTest, SuggestBackbufferNoShouldDiscardBackbufferAndDamageRoot
LayerWhileNotVisible) | 159 TEST_F(GLRendererTest, SuggestBackbufferNoShouldDiscardBackbufferAndDamageRootLa
yerWhileNotVisible) |
| 160 { | 160 { |
| 161 m_renderer.setVisible(false); | 161 m_renderer.setVisible(false); |
| 162 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); | 162 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); |
| 163 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); | 163 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); |
| 164 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); | 164 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Test CCRendererGL discardFramebuffer functionality: | 167 // Test GLRenderer discardFramebuffer functionality: |
| 168 // Suggest discarding framebuffer when one exists and the renderer is visible. | 168 // Suggest discarding framebuffer when one exists and the renderer is visible. |
| 169 // Expected: the allocation is ignored. | 169 // Expected: the allocation is ignored. |
| 170 TEST_F(CCRendererGLTest, SuggestBackbufferNoDoNothingWhenVisible) | 170 TEST_F(GLRendererTest, SuggestBackbufferNoDoNothingWhenVisible) |
| 171 { | 171 { |
| 172 m_renderer.setVisible(true); | 172 m_renderer.setVisible(true); |
| 173 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); | 173 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); |
| 174 EXPECT_EQ(0, m_mockClient.setFullRootLayerDamageCount()); | 174 EXPECT_EQ(0, m_mockClient.setFullRootLayerDamageCount()); |
| 175 EXPECT_FALSE(m_renderer.isFramebufferDiscarded()); | 175 EXPECT_FALSE(m_renderer.isFramebufferDiscarded()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 // Test CCRendererGL discardFramebuffer functionality: | 179 // Test GLRenderer discardFramebuffer functionality: |
| 180 // Suggest discarding framebuffer when one does not exist. | 180 // Suggest discarding framebuffer when one does not exist. |
| 181 // Expected: it does nothing. | 181 // Expected: it does nothing. |
| 182 TEST_F(CCRendererGLTest, SuggestBackbufferNoWhenItDoesntExistShouldDoNothing) | 182 TEST_F(GLRendererTest, SuggestBackbufferNoWhenItDoesntExistShouldDoNothing) |
| 183 { | 183 { |
| 184 m_renderer.setVisible(false); | 184 m_renderer.setVisible(false); |
| 185 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); | 185 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); |
| 186 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); | 186 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); |
| 187 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); | 187 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); |
| 188 | 188 |
| 189 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); | 189 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); |
| 190 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); | 190 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); |
| 191 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); | 191 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); |
| 192 } | 192 } |
| 193 | 193 |
| 194 // Test CCRendererGL discardFramebuffer functionality: | 194 // Test GLRenderer discardFramebuffer functionality: |
| 195 // Begin drawing a frame while a framebuffer is discarded. | 195 // Begin drawing a frame while a framebuffer is discarded. |
| 196 // Expected: will recreate framebuffer. | 196 // Expected: will recreate framebuffer. |
| 197 TEST_F(CCRendererGLTest, DiscardedBackbufferIsRecreatedForScopeDuration) | 197 TEST_F(GLRendererTest, DiscardedBackbufferIsRecreatedForScopeDuration) |
| 198 { | 198 { |
| 199 m_renderer.setVisible(false); | 199 m_renderer.setVisible(false); |
| 200 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); | 200 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); |
| 201 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); | 201 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); |
| 202 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); | 202 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); |
| 203 | 203 |
| 204 m_renderer.setVisible(true); | 204 m_renderer.setVisible(true); |
| 205 m_renderer.drawFrame(m_mockClient.renderPassesInDrawOrder(), m_mockClient.re
nderPasses()); | 205 m_renderer.drawFrame(m_mockClient.renderPassesInDrawOrder(), m_mockClient.re
nderPasses()); |
| 206 EXPECT_FALSE(m_renderer.isFramebufferDiscarded()); | 206 EXPECT_FALSE(m_renderer.isFramebufferDiscarded()); |
| 207 | 207 |
| 208 swapBuffers(); | 208 swapBuffers(); |
| 209 EXPECT_EQ(1, context()->frameCount()); | 209 EXPECT_EQ(1, context()->frameCount()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 TEST_F(CCRendererGLTest, FramebufferDiscardedAfterReadbackWhenNotVisible) | 212 TEST_F(GLRendererTest, FramebufferDiscardedAfterReadbackWhenNotVisible) |
| 213 { | 213 { |
| 214 m_renderer.setVisible(false); | 214 m_renderer.setVisible(false); |
| 215 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); | 215 context()->setMemoryAllocation(m_suggestHaveBackbufferNo); |
| 216 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); | 216 EXPECT_TRUE(m_renderer.isFramebufferDiscarded()); |
| 217 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); | 217 EXPECT_EQ(1, m_mockClient.setFullRootLayerDamageCount()); |
| 218 | 218 |
| 219 char pixels[4]; | 219 char pixels[4]; |
| 220 m_renderer.drawFrame(m_mockClient.renderPassesInDrawOrder(), m_mockClient.re
nderPasses()); | 220 m_renderer.drawFrame(m_mockClient.renderPassesInDrawOrder(), m_mockClient.re
nderPasses()); |
| 221 EXPECT_FALSE(m_renderer.isFramebufferDiscarded()); | 221 EXPECT_FALSE(m_renderer.isFramebufferDiscarded()); |
| 222 | 222 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 virtual void getTexParameterfv(WGC3Denum target, WGC3Denum pname, WGC3Dfloat
* value) { ADD_FAILURE(); } | 284 virtual void getTexParameterfv(WGC3Denum target, WGC3Denum pname, WGC3Dfloat
* value) { ADD_FAILURE(); } |
| 285 virtual void getTexParameteriv(WGC3Denum target, WGC3Denum pname, WGC3Dint*
value) { ADD_FAILURE(); } | 285 virtual void getTexParameteriv(WGC3Denum target, WGC3Denum pname, WGC3Dint*
value) { ADD_FAILURE(); } |
| 286 virtual void getUniformfv(WebGLId program, WGC3Dint location, WGC3Dfloat* va
lue) { ADD_FAILURE(); } | 286 virtual void getUniformfv(WebGLId program, WGC3Dint location, WGC3Dfloat* va
lue) { ADD_FAILURE(); } |
| 287 virtual void getUniformiv(WebGLId program, WGC3Dint location, WGC3Dint* valu
e) { ADD_FAILURE(); } | 287 virtual void getUniformiv(WebGLId program, WGC3Dint location, WGC3Dint* valu
e) { ADD_FAILURE(); } |
| 288 virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name)
{ ADD_FAILURE(); return 0; } | 288 virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name)
{ ADD_FAILURE(); return 0; } |
| 289 virtual void getVertexAttribfv(WGC3Duint index, WGC3Denum pname, WGC3Dfloat*
value) { ADD_FAILURE(); } | 289 virtual void getVertexAttribfv(WGC3Duint index, WGC3Denum pname, WGC3Dfloat*
value) { ADD_FAILURE(); } |
| 290 virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname, WGC3Dint* v
alue) { ADD_FAILURE(); } | 290 virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname, WGC3Dint* v
alue) { ADD_FAILURE(); } |
| 291 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname
) { ADD_FAILURE(); return 0; } | 291 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname
) { ADD_FAILURE(); return 0; } |
| 292 }; | 292 }; |
| 293 | 293 |
| 294 // This test isn't using the same fixture as CCRendererGLTest, and you can't mix
TEST() and TEST_F() with the same name, hence LRC2. | 294 // This test isn't using the same fixture as GLRendererTest, and you can't mix T
EST() and TEST_F() with the same name, hence LRC2. |
| 295 TEST(CCRendererGLTest2, initializationDoesNotMakeSynchronousCalls) | 295 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls) |
| 296 { | 296 { |
| 297 CCScopedSettings scopedSettings; | 297 ScopedSettings scopedSettings; |
| 298 FakeCCRendererClient mockClient; | 298 FakeRendererClient mockClient; |
| 299 scoped_ptr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new ForbidSynchronousCallContext))); | 299 scoped_ptr<GraphicsContext> context(FakeWebCompositorOutputSurface::create(s
coped_ptr<WebKit::WebGraphicsContext3D>(new ForbidSynchronousCallContext))); |
| 300 scoped_ptr<CCResourceProvider> resourceProvider(CCResourceProvider::create(c
ontext.get())); | 300 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
| 301 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 301 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 302 | 302 |
| 303 EXPECT_TRUE(renderer.initialize()); | 303 EXPECT_TRUE(renderer.initialize()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { | 306 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { |
| 307 public: | 307 public: |
| 308 LoseContextOnFirstGetContext() | 308 LoseContextOnFirstGetContext() |
| 309 : m_contextLost(false) | 309 : m_contextLost(false) |
| 310 { | 310 { |
| 311 } | 311 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 329 | 329 |
| 330 virtual WGC3Denum getGraphicsResetStatusARB() OVERRIDE | 330 virtual WGC3Denum getGraphicsResetStatusARB() OVERRIDE |
| 331 { | 331 { |
| 332 return m_contextLost ? 1 : 0; | 332 return m_contextLost ? 1 : 0; |
| 333 } | 333 } |
| 334 | 334 |
| 335 private: | 335 private: |
| 336 bool m_contextLost; | 336 bool m_contextLost; |
| 337 }; | 337 }; |
| 338 | 338 |
| 339 TEST(CCRendererGLTest2, initializationWithQuicklyLostContextDoesNotAssert) | 339 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert) |
| 340 { | 340 { |
| 341 CCScopedSettings scopedSettings; | 341 ScopedSettings scopedSettings; |
| 342 FakeCCRendererClient mockClient; | 342 FakeRendererClient mockClient; |
| 343 scoped_ptr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext))); | 343 scoped_ptr<GraphicsContext> context(FakeWebCompositorOutputSurface::create(s
coped_ptr<WebKit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext))); |
| 344 scoped_ptr<CCResourceProvider> resourceProvider(CCResourceProvider::create(c
ontext.get())); | 344 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
| 345 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 345 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 346 | 346 |
| 347 renderer.initialize(); | 347 renderer.initialize(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic
sContext3D { | 350 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic
sContext3D { |
| 351 public: | 351 public: |
| 352 ContextThatDoesNotSupportMemoryManagmentExtensions() { } | 352 ContextThatDoesNotSupportMemoryManagmentExtensions() { } |
| 353 | 353 |
| 354 // WebGraphicsContext3D methods. | 354 // WebGraphicsContext3D methods. |
| 355 | 355 |
| 356 // This method would normally do a glSwapBuffers under the hood. | 356 // This method would normally do a glSwapBuffers under the hood. |
| 357 virtual void prepareTexture() { } | 357 virtual void prepareTexture() { } |
| 358 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { } | 358 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { } |
| 359 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } | 359 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } |
| 360 }; | 360 }; |
| 361 | 361 |
| 362 TEST(CCRendererGLTest2, initializationWithoutGpuMemoryManagerExtensionSupportSho
uldDefaultToNonZeroAllocation) | 362 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul
dDefaultToNonZeroAllocation) |
| 363 { | 363 { |
| 364 FakeCCRendererClient mockClient; | 364 FakeRendererClient mockClient; |
| 365 scoped_ptr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryMan
agmentExtensions))); | 365 scoped_ptr<GraphicsContext> context(FakeWebCompositorOutputSurface::create(s
coped_ptr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryManag
mentExtensions))); |
| 366 scoped_ptr<CCResourceProvider> resourceProvider(CCResourceProvider::create(c
ontext.get())); | 366 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
| 367 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 367 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 368 | 368 |
| 369 renderer.initialize(); | 369 renderer.initialize(); |
| 370 | 370 |
| 371 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); | 371 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); |
| 372 } | 372 } |
| 373 | 373 |
| 374 class ClearCountingContext : public FakeWebGraphicsContext3D { | 374 class ClearCountingContext : public FakeWebGraphicsContext3D { |
| 375 public: | 375 public: |
| 376 ClearCountingContext() : m_clear(0) { } | 376 ClearCountingContext() : m_clear(0) { } |
| 377 | 377 |
| 378 virtual void clear(WGC3Dbitfield) | 378 virtual void clear(WGC3Dbitfield) |
| 379 { | 379 { |
| 380 m_clear++; | 380 m_clear++; |
| 381 } | 381 } |
| 382 | 382 |
| 383 int clearCount() const { return m_clear; } | 383 int clearCount() const { return m_clear; } |
| 384 | 384 |
| 385 private: | 385 private: |
| 386 int m_clear; | 386 int m_clear; |
| 387 }; | 387 }; |
| 388 | 388 |
| 389 TEST(CCRendererGLTest2, opaqueBackground) | 389 TEST(GLRendererTest2, opaqueBackground) |
| 390 { | 390 { |
| 391 FakeCCRendererClient mockClient; | 391 FakeRendererClient mockClient; |
| 392 scoped_ptr<CCGraphicsContext> ccContext(FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); | 392 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); |
| 393 ClearCountingContext* context = static_cast<ClearCountingContext*>(ccContext
->context3D()); | 393 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur
face->context3D()); |
| 394 scoped_ptr<CCResourceProvider> resourceProvider(CCResourceProvider::create(c
cContext.get())); | 394 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 395 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 395 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 396 | 396 |
| 397 mockClient.rootRenderPass()->setHasTransparentBackground(false); | 397 mockClient.rootRenderPass()->setHasTransparentBackground(false); |
| 398 | 398 |
| 399 EXPECT_TRUE(renderer.initialize()); | 399 EXPECT_TRUE(renderer.initialize()); |
| 400 | 400 |
| 401 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 401 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
| 402 | 402 |
| 403 // On DEBUG builds, render passes with opaque background clear to blue to | 403 // On DEBUG builds, render passes with opaque background clear to blue to |
| 404 // easily see regions that were not drawn on the screen. | 404 // easily see regions that were not drawn on the screen. |
| 405 #if defined(NDEBUG) | 405 #if defined(NDEBUG) |
| 406 EXPECT_EQ(0, context->clearCount()); | 406 EXPECT_EQ(0, context->clearCount()); |
| 407 #else | 407 #else |
| 408 EXPECT_EQ(1, context->clearCount()); | 408 EXPECT_EQ(1, context->clearCount()); |
| 409 #endif | 409 #endif |
| 410 } | 410 } |
| 411 | 411 |
| 412 TEST(CCRendererGLTest2, transparentBackground) | 412 TEST(GLRendererTest2, transparentBackground) |
| 413 { | 413 { |
| 414 FakeCCRendererClient mockClient; | 414 FakeRendererClient mockClient; |
| 415 scoped_ptr<CCGraphicsContext> ccContext(FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); | 415 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); |
| 416 ClearCountingContext* context = static_cast<ClearCountingContext*>(ccContext
->context3D()); | 416 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur
face->context3D()); |
| 417 scoped_ptr<CCResourceProvider> resourceProvider(CCResourceProvider::create(c
cContext.get())); | 417 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 418 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 418 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 419 | 419 |
| 420 mockClient.rootRenderPass()->setHasTransparentBackground(true); | 420 mockClient.rootRenderPass()->setHasTransparentBackground(true); |
| 421 | 421 |
| 422 EXPECT_TRUE(renderer.initialize()); | 422 EXPECT_TRUE(renderer.initialize()); |
| 423 | 423 |
| 424 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 424 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
| 425 | 425 |
| 426 EXPECT_EQ(1, context->clearCount()); | 426 EXPECT_EQ(1, context->clearCount()); |
| 427 } | 427 } |
| OLD | NEW |