| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 using CCRendererGL::isFramebufferDiscarded; | 106 using CCRendererGL::isFramebufferDiscarded; |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 class CCRendererGLTest : public testing::Test { | 109 class CCRendererGLTest : public testing::Test { |
| 110 protected: | 110 protected: |
| 111 CCRendererGLTest() | 111 CCRendererGLTest() |
| 112 : m_suggestHaveBackbufferYes(1, true) | 112 : m_suggestHaveBackbufferYes(1, true) |
| 113 , m_suggestHaveBackbufferNo(1, false) | 113 , m_suggestHaveBackbufferNo(1, false) |
| 114 , m_compositorInitializer(0) | 114 , m_compositorInitializer(0) |
| 115 , m_context(FakeWebCompositorOutputSurface::create(adoptPtr(new FrameCou
ntingMemoryAllocationSettingContext()))) | 115 , m_context(FakeWebCompositorOutputSurface::create(adoptPtr(new FrameCou
ntingMemoryAllocationSettingContext()))) |
| 116 , m_resourceProvider(CCResourceProvider::create(m_context.get(), Unthrot
tledUploader)) | 116 , m_resourceProvider(CCResourceProvider::create(m_context.get())) |
| 117 , m_renderer(&m_mockClient, m_resourceProvider.get()) | 117 , m_renderer(&m_mockClient, m_resourceProvider.get()) |
| 118 { | 118 { |
| 119 } | 119 } |
| 120 | 120 |
| 121 virtual void SetUp() | 121 virtual void SetUp() |
| 122 { | 122 { |
| 123 m_renderer.initialize(); | 123 m_renderer.initialize(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void swapBuffers() | 126 void swapBuffers() |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname, WGC3Dint* v
alue) { ADD_FAILURE(); } | 291 virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname, WGC3Dint* v
alue) { ADD_FAILURE(); } |
| 292 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname
) { ADD_FAILURE(); return 0; } | 292 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname
) { ADD_FAILURE(); return 0; } |
| 293 }; | 293 }; |
| 294 | 294 |
| 295 // 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. | 295 // 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. |
| 296 TEST(CCRendererGLTest2, initializationDoesNotMakeSynchronousCalls) | 296 TEST(CCRendererGLTest2, initializationDoesNotMakeSynchronousCalls) |
| 297 { | 297 { |
| 298 CCScopedSettings scopedSettings; | 298 CCScopedSettings scopedSettings; |
| 299 FakeCCRendererClient mockClient; | 299 FakeCCRendererClient mockClient; |
| 300 OwnPtr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create(ado
ptPtr(new ForbidSynchronousCallContext))); | 300 OwnPtr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create(ado
ptPtr(new ForbidSynchronousCallContext))); |
| 301 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get(), UnthrottledUploader)); | 301 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get())); |
| 302 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 302 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); |
| 303 | 303 |
| 304 EXPECT_TRUE(renderer.initialize()); | 304 EXPECT_TRUE(renderer.initialize()); |
| 305 } | 305 } |
| 306 | 306 |
| 307 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { | 307 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { |
| 308 public: | 308 public: |
| 309 LoseContextOnFirstGetContext() | 309 LoseContextOnFirstGetContext() |
| 310 : m_contextLost(false) | 310 : m_contextLost(false) |
| 311 { | 311 { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 335 | 335 |
| 336 private: | 336 private: |
| 337 bool m_contextLost; | 337 bool m_contextLost; |
| 338 }; | 338 }; |
| 339 | 339 |
| 340 TEST(CCRendererGLTest2, initializationWithQuicklyLostContextDoesNotAssert) | 340 TEST(CCRendererGLTest2, initializationWithQuicklyLostContextDoesNotAssert) |
| 341 { | 341 { |
| 342 CCScopedSettings scopedSettings; | 342 CCScopedSettings scopedSettings; |
| 343 FakeCCRendererClient mockClient; | 343 FakeCCRendererClient mockClient; |
| 344 OwnPtr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create(ado
ptPtr(new LoseContextOnFirstGetContext))); | 344 OwnPtr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create(ado
ptPtr(new LoseContextOnFirstGetContext))); |
| 345 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get(), UnthrottledUploader)); | 345 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get())); |
| 346 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 346 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); |
| 347 | 347 |
| 348 renderer.initialize(); | 348 renderer.initialize(); |
| 349 } | 349 } |
| 350 | 350 |
| 351 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic
sContext3D { | 351 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic
sContext3D { |
| 352 public: | 352 public: |
| 353 ContextThatDoesNotSupportMemoryManagmentExtensions() { } | 353 ContextThatDoesNotSupportMemoryManagmentExtensions() { } |
| 354 | 354 |
| 355 // WebGraphicsContext3D methods. | 355 // WebGraphicsContext3D methods. |
| 356 | 356 |
| 357 // This method would normally do a glSwapBuffers under the hood. | 357 // This method would normally do a glSwapBuffers under the hood. |
| 358 virtual void prepareTexture() { } | 358 virtual void prepareTexture() { } |
| 359 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { } | 359 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { } |
| 360 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } | 360 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } |
| 361 }; | 361 }; |
| 362 | 362 |
| 363 TEST(CCRendererGLTest2, initializationWithoutGpuMemoryManagerExtensionSupportSho
uldDefaultToNonZeroAllocation) | 363 TEST(CCRendererGLTest2, initializationWithoutGpuMemoryManagerExtensionSupportSho
uldDefaultToNonZeroAllocation) |
| 364 { | 364 { |
| 365 FakeCCRendererClient mockClient; | 365 FakeCCRendererClient mockClient; |
| 366 OwnPtr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create(ado
ptPtr(new ContextThatDoesNotSupportMemoryManagmentExtensions))); | 366 OwnPtr<CCGraphicsContext> context(FakeWebCompositorOutputSurface::create(ado
ptPtr(new ContextThatDoesNotSupportMemoryManagmentExtensions))); |
| 367 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get(), UnthrottledUploader)); | 367 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(conte
xt.get())); |
| 368 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 368 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); |
| 369 | 369 |
| 370 renderer.initialize(); | 370 renderer.initialize(); |
| 371 | 371 |
| 372 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); | 372 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); |
| 373 } | 373 } |
| 374 | 374 |
| 375 class ClearCountingContext : public FakeWebGraphicsContext3D { | 375 class ClearCountingContext : public FakeWebGraphicsContext3D { |
| 376 public: | 376 public: |
| 377 ClearCountingContext() : m_clear(0) { } | 377 ClearCountingContext() : m_clear(0) { } |
| 378 | 378 |
| 379 virtual void clear(WGC3Dbitfield) | 379 virtual void clear(WGC3Dbitfield) |
| 380 { | 380 { |
| 381 m_clear++; | 381 m_clear++; |
| 382 } | 382 } |
| 383 | 383 |
| 384 int clearCount() const { return m_clear; } | 384 int clearCount() const { return m_clear; } |
| 385 | 385 |
| 386 private: | 386 private: |
| 387 int m_clear; | 387 int m_clear; |
| 388 }; | 388 }; |
| 389 | 389 |
| 390 TEST(CCRendererGLTest2, opaqueBackground) | 390 TEST(CCRendererGLTest2, opaqueBackground) |
| 391 { | 391 { |
| 392 FakeCCRendererClient mockClient; | 392 FakeCCRendererClient mockClient; |
| 393 OwnPtr<CCGraphicsContext> ccContext(FakeWebCompositorOutputSurface::create(a
doptPtr(new ClearCountingContext))); | 393 OwnPtr<CCGraphicsContext> ccContext(FakeWebCompositorOutputSurface::create(a
doptPtr(new ClearCountingContext))); |
| 394 ClearCountingContext* context = static_cast<ClearCountingContext*>(ccContext
->context3D()); | 394 ClearCountingContext* context = static_cast<ClearCountingContext*>(ccContext
->context3D()); |
| 395 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(ccCon
text.get(), UnthrottledUploader)); | 395 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(ccCon
text.get())); |
| 396 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 396 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); |
| 397 | 397 |
| 398 mockClient.rootRenderPass()->setHasTransparentBackground(false); | 398 mockClient.rootRenderPass()->setHasTransparentBackground(false); |
| 399 | 399 |
| 400 EXPECT_TRUE(renderer.initialize()); | 400 EXPECT_TRUE(renderer.initialize()); |
| 401 | 401 |
| 402 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 402 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
| 403 | 403 |
| 404 // On DEBUG builds, render passes with opaque background clear to blue to | 404 // On DEBUG builds, render passes with opaque background clear to blue to |
| 405 // easily see regions that were not drawn on the screen. | 405 // easily see regions that were not drawn on the screen. |
| 406 #if defined(NDEBUG) | 406 #if defined(NDEBUG) |
| 407 EXPECT_EQ(0, context->clearCount()); | 407 EXPECT_EQ(0, context->clearCount()); |
| 408 #else | 408 #else |
| 409 EXPECT_EQ(1, context->clearCount()); | 409 EXPECT_EQ(1, context->clearCount()); |
| 410 #endif | 410 #endif |
| 411 } | 411 } |
| 412 | 412 |
| 413 TEST(CCRendererGLTest2, transparentBackground) | 413 TEST(CCRendererGLTest2, transparentBackground) |
| 414 { | 414 { |
| 415 FakeCCRendererClient mockClient; | 415 FakeCCRendererClient mockClient; |
| 416 OwnPtr<CCGraphicsContext> ccContext(FakeWebCompositorOutputSurface::create(a
doptPtr(new ClearCountingContext))); | 416 OwnPtr<CCGraphicsContext> ccContext(FakeWebCompositorOutputSurface::create(a
doptPtr(new ClearCountingContext))); |
| 417 ClearCountingContext* context = static_cast<ClearCountingContext*>(ccContext
->context3D()); | 417 ClearCountingContext* context = static_cast<ClearCountingContext*>(ccContext
->context3D()); |
| 418 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(ccCon
text.get(), UnthrottledUploader)); | 418 OwnPtr<CCResourceProvider> resourceProvider(CCResourceProvider::create(ccCon
text.get())); |
| 419 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); | 419 FakeCCRendererGL renderer(&mockClient, resourceProvider.get()); |
| 420 | 420 |
| 421 mockClient.rootRenderPass()->setHasTransparentBackground(true); | 421 mockClient.rootRenderPass()->setHasTransparentBackground(true); |
| 422 | 422 |
| 423 EXPECT_TRUE(renderer.initialize()); | 423 EXPECT_TRUE(renderer.initialize()); |
| 424 | 424 |
| 425 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 425 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
| 426 | 426 |
| 427 EXPECT_EQ(1, context->clearCount()); | 427 EXPECT_EQ(1, context->clearCount()); |
| 428 } | 428 } |
| OLD | NEW |