| 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 "cc/gl_renderer.h" | 5 #include "cc/gl_renderer.h" |
| 6 | 6 |
| 7 #include "cc/draw_quad.h" | 7 #include "cc/draw_quad.h" |
| 8 #include "cc/prioritized_resource_manager.h" | 8 #include "cc/prioritized_resource_manager.h" |
| 9 #include "cc/resource_provider.h" | 9 #include "cc/resource_provider.h" |
| 10 #include "cc/test/fake_output_surface.h" | 10 #include "cc/test/fake_output_surface.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 : m_suggestHaveBackbufferYes(1, true) | 119 : m_suggestHaveBackbufferYes(1, true) |
| 120 , m_suggestHaveBackbufferNo(1, false) | 120 , m_suggestHaveBackbufferNo(1, false) |
| 121 , m_context(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsCo
ntext3D>(new FrameCountingMemoryAllocationSettingContext()))) | 121 , m_context(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsCo
ntext3D>(new FrameCountingMemoryAllocationSettingContext()))) |
| 122 , m_resourceProvider(ResourceProvider::create(m_context.get())) | 122 , m_resourceProvider(ResourceProvider::create(m_context.get())) |
| 123 , m_renderer(&m_mockClient, m_resourceProvider.get()) | 123 , m_renderer(&m_mockClient, m_resourceProvider.get()) |
| 124 { | 124 { |
| 125 } | 125 } |
| 126 | 126 |
| 127 virtual void SetUp() | 127 virtual void SetUp() |
| 128 { | 128 { |
| 129 m_renderer.initialize(); | 129 m_renderer.initialize(m_resourceProvider.get()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void swapBuffers() | 132 void swapBuffers() |
| 133 { | 133 { |
| 134 m_renderer.swapBuffers(); | 134 m_renderer.swapBuffers(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 FrameCountingMemoryAllocationSettingContext* context() { return static_cast<
FrameCountingMemoryAllocationSettingContext*>(m_context->Context3D()); } | 137 FrameCountingMemoryAllocationSettingContext* context() { return static_cast<
FrameCountingMemoryAllocationSettingContext*>(m_context->Context3D()); } |
| 138 | 138 |
| 139 WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes; | 139 WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 }; | 297 }; |
| 298 | 298 |
| 299 // 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. | 299 // 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. |
| 300 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls) | 300 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls) |
| 301 { | 301 { |
| 302 FakeRendererClient mockClient; | 302 FakeRendererClient mockClient; |
| 303 scoped_ptr<OutputSurface> context(FakeOutputSurface::Create3d(scoped_ptr<Web
Kit::WebGraphicsContext3D>(new ForbidSynchronousCallContext))); | 303 scoped_ptr<OutputSurface> context(FakeOutputSurface::Create3d(scoped_ptr<Web
Kit::WebGraphicsContext3D>(new ForbidSynchronousCallContext))); |
| 304 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); | 304 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
| 305 FakeRendererGL renderer(&mockClient, resourceProvider.get()); | 305 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 306 | 306 |
| 307 EXPECT_TRUE(renderer.initialize()); | 307 EXPECT_TRUE(renderer.initialize(resourceProvider.get())); |
| 308 } | 308 } |
| 309 | 309 |
| 310 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { | 310 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { |
| 311 public: | 311 public: |
| 312 LoseContextOnFirstGetContext() | 312 LoseContextOnFirstGetContext() |
| 313 : m_contextLost(false) | 313 : m_contextLost(false) |
| 314 { | 314 { |
| 315 } | 315 } |
| 316 | 316 |
| 317 virtual bool makeContextCurrent() OVERRIDE | 317 virtual bool makeContextCurrent() OVERRIDE |
| (...skipping 22 matching lines...) Expand all Loading... |
| 340 bool m_contextLost; | 340 bool m_contextLost; |
| 341 }; | 341 }; |
| 342 | 342 |
| 343 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert) | 343 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert) |
| 344 { | 344 { |
| 345 FakeRendererClient mockClient; | 345 FakeRendererClient mockClient; |
| 346 scoped_ptr<OutputSurface> context(FakeOutputSurface::Create3d(scoped_ptr<Web
Kit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext))); | 346 scoped_ptr<OutputSurface> context(FakeOutputSurface::Create3d(scoped_ptr<Web
Kit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext))); |
| 347 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); | 347 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
| 348 FakeRendererGL renderer(&mockClient, resourceProvider.get()); | 348 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 349 | 349 |
| 350 renderer.initialize(); | 350 renderer.initialize(resourceProvider.get()); |
| 351 } | 351 } |
| 352 | 352 |
| 353 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic
sContext3D { | 353 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic
sContext3D { |
| 354 public: | 354 public: |
| 355 ContextThatDoesNotSupportMemoryManagmentExtensions() { } | 355 ContextThatDoesNotSupportMemoryManagmentExtensions() { } |
| 356 | 356 |
| 357 // WebGraphicsContext3D methods. | 357 // WebGraphicsContext3D methods. |
| 358 | 358 |
| 359 // This method would normally do a glSwapBuffers under the hood. | 359 // This method would normally do a glSwapBuffers under the hood. |
| 360 virtual void prepareTexture() { } | 360 virtual void prepareTexture() { } |
| 361 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { } | 361 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { } |
| 362 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } | 362 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } |
| 363 }; | 363 }; |
| 364 | 364 |
| 365 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul
dDefaultToNonZeroAllocation) | 365 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul
dDefaultToNonZeroAllocation) |
| 366 { | 366 { |
| 367 FakeRendererClient mockClient; | 367 FakeRendererClient mockClient; |
| 368 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryManagmentExt
ensions))); | 368 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryManagmentExt
ensions))); |
| 369 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 369 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 370 FakeRendererGL renderer(&mockClient, resourceProvider.get()); | 370 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 371 | 371 |
| 372 renderer.initialize(); | 372 renderer.initialize(resourceProvider.get()); |
| 373 | 373 |
| 374 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); | 374 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); |
| 375 } | 375 } |
| 376 | 376 |
| 377 class ClearCountingContext : public FakeWebGraphicsContext3D { | 377 class ClearCountingContext : public FakeWebGraphicsContext3D { |
| 378 public: | 378 public: |
| 379 ClearCountingContext() : m_clear(0) { } | 379 ClearCountingContext() : m_clear(0) { } |
| 380 | 380 |
| 381 virtual void clear(WGC3Dbitfield) | 381 virtual void clear(WGC3Dbitfield) |
| 382 { | 382 { |
| 383 m_clear++; | 383 m_clear++; |
| 384 } | 384 } |
| 385 | 385 |
| 386 int clearCount() const { return m_clear; } | 386 int clearCount() const { return m_clear; } |
| 387 | 387 |
| 388 private: | 388 private: |
| 389 int m_clear; | 389 int m_clear; |
| 390 }; | 390 }; |
| 391 | 391 |
| 392 TEST(GLRendererTest2, opaqueBackground) | 392 TEST(GLRendererTest2, opaqueBackground) |
| 393 { | 393 { |
| 394 FakeRendererClient mockClient; | 394 FakeRendererClient mockClient; |
| 395 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); | 395 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); |
| 396 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur
face->Context3D()); | 396 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur
face->Context3D()); |
| 397 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 397 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 398 FakeRendererGL renderer(&mockClient, resourceProvider.get()); | 398 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 399 | 399 |
| 400 mockClient.rootRenderPass()->has_transparent_background = false; | 400 mockClient.rootRenderPass()->has_transparent_background = false; |
| 401 | 401 |
| 402 EXPECT_TRUE(renderer.initialize()); | 402 EXPECT_TRUE(renderer.initialize(resourceProvider.get())); |
| 403 | 403 |
| 404 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 404 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
| 405 | 405 |
| 406 // On DEBUG builds, render passes with opaque background clear to blue to | 406 // On DEBUG builds, render passes with opaque background clear to blue to |
| 407 // easily see regions that were not drawn on the screen. | 407 // easily see regions that were not drawn on the screen. |
| 408 #ifdef NDEBUG | 408 #ifdef NDEBUG |
| 409 EXPECT_EQ(0, context->clearCount()); | 409 EXPECT_EQ(0, context->clearCount()); |
| 410 #else | 410 #else |
| 411 EXPECT_EQ(1, context->clearCount()); | 411 EXPECT_EQ(1, context->clearCount()); |
| 412 #endif | 412 #endif |
| 413 } | 413 } |
| 414 | 414 |
| 415 TEST(GLRendererTest2, transparentBackground) | 415 TEST(GLRendererTest2, transparentBackground) |
| 416 { | 416 { |
| 417 FakeRendererClient mockClient; | 417 FakeRendererClient mockClient; |
| 418 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); | 418 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); |
| 419 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur
face->Context3D()); | 419 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur
face->Context3D()); |
| 420 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 420 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 421 FakeRendererGL renderer(&mockClient, resourceProvider.get()); | 421 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 422 | 422 |
| 423 mockClient.rootRenderPass()->has_transparent_background = true; | 423 mockClient.rootRenderPass()->has_transparent_background = true; |
| 424 | 424 |
| 425 EXPECT_TRUE(renderer.initialize()); | 425 EXPECT_TRUE(renderer.initialize(resourceProvider.get())); |
| 426 | 426 |
| 427 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 427 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
| 428 | 428 |
| 429 EXPECT_EQ(1, context->clearCount()); | 429 EXPECT_EQ(1, context->clearCount()); |
| 430 } | 430 } |
| 431 | 431 |
| 432 class VisibilityChangeIsLastCallTrackingContext : public FakeWebGraphicsContext3
D { | 432 class VisibilityChangeIsLastCallTrackingContext : public FakeWebGraphicsContext3
D { |
| 433 public: | 433 public: |
| 434 VisibilityChangeIsLastCallTrackingContext() | 434 VisibilityChangeIsLastCallTrackingContext() |
| 435 : m_lastCallWasSetVisibility(0) | 435 : m_lastCallWasSetVisibility(0) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 464 }; | 464 }; |
| 465 | 465 |
| 466 TEST(GLRendererTest2, visibilityChangeIsLastCall) | 466 TEST(GLRendererTest2, visibilityChangeIsLastCall) |
| 467 { | 467 { |
| 468 FakeRendererClient mockClient; | 468 FakeRendererClient mockClient; |
| 469 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new VisibilityChangeIsLastCallTrackingContext))
); | 469 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new VisibilityChangeIsLastCallTrackingContext))
); |
| 470 VisibilityChangeIsLastCallTrackingContext* context = static_cast<VisibilityC
hangeIsLastCallTrackingContext*>(outputSurface->Context3D()); | 470 VisibilityChangeIsLastCallTrackingContext* context = static_cast<VisibilityC
hangeIsLastCallTrackingContext*>(outputSurface->Context3D()); |
| 471 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 471 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 472 FakeRendererGL renderer(&mockClient, resourceProvider.get()); | 472 FakeRendererGL renderer(&mockClient, resourceProvider.get()); |
| 473 | 473 |
| 474 EXPECT_TRUE(renderer.initialize()); | 474 EXPECT_TRUE(renderer.initialize(resourceProvider.get())); |
| 475 | 475 |
| 476 bool lastCallWasSetVisiblity = false; | 476 bool lastCallWasSetVisiblity = false; |
| 477 // Ensure that the call to setVisibilityCHROMIUM is the last call issue to t
he GPU | 477 // Ensure that the call to setVisibilityCHROMIUM is the last call issue to t
he GPU |
| 478 // process, after glFlush is called, and after the RendererClient's enforceM
anagedMemoryPolicy | 478 // process, after glFlush is called, and after the RendererClient's enforceM
anagedMemoryPolicy |
| 479 // is called. Plumb this tracking between both the RenderClient and the Cont
ext by giving | 479 // is called. Plumb this tracking between both the RenderClient and the Cont
ext by giving |
| 480 // them both a pointer to a variable on the stack. | 480 // them both a pointer to a variable on the stack. |
| 481 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); | 481 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); |
| 482 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); | 482 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); |
| 483 renderer.setVisible(true); | 483 renderer.setVisible(true); |
| 484 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 484 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 TEST(GLRendererTest2, activeTextureState) | 518 TEST(GLRendererTest2, activeTextureState) |
| 519 { | 519 { |
| 520 FakeRendererClient fakeClient; | 520 FakeRendererClient fakeClient; |
| 521 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); | 521 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); |
| 522 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->Context3D()); | 522 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->Context3D()); |
| 523 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 523 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 524 FakeRendererGL renderer(&fakeClient, resourceProvider.get()); | 524 FakeRendererGL renderer(&fakeClient, resourceProvider.get()); |
| 525 | 525 |
| 526 // During initialization we are allowed to set any texture parameters. | 526 // During initialization we are allowed to set any texture parameters. |
| 527 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber()); | 527 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber()); |
| 528 EXPECT_TRUE(renderer.initialize()); | 528 EXPECT_TRUE(renderer.initialize(resourceProvider.get())); |
| 529 | 529 |
| 530 cc::RenderPass::Id id(1, 1); | 530 cc::RenderPass::Id id(1, 1); |
| 531 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | 531 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
| 532 pass->SetNew(id, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), gfx::
Transform()); | 532 pass->SetNew(id, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), gfx::
Transform()); |
| 533 pass->AppendOneOfEveryQuadType(resourceProvider.get()); | 533 pass->AppendOneOfEveryQuadType(resourceProvider.get()); |
| 534 | 534 |
| 535 // Set up expected texture filter state transitions that match the quads | 535 // Set up expected texture filter state transitions that match the quads |
| 536 // created in AppendOneOfEveryQuadType(). | 536 // created in AppendOneOfEveryQuadType(). |
| 537 Mock::VerifyAndClearExpectations(context); | 537 Mock::VerifyAndClearExpectations(context); |
| 538 { | 538 { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 568 it != pass->quad_list.backToFrontEnd(); ++it) { | 568 it != pass->quad_list.backToFrontEnd(); ++it) { |
| 569 renderer.drawQuad(drawingFrame, *it); | 569 renderer.drawQuad(drawingFrame, *it); |
| 570 } | 570 } |
| 571 renderer.finishDrawingQuadList(); | 571 renderer.finishDrawingQuadList(); |
| 572 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); | 572 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); |
| 573 Mock::VerifyAndClearExpectations(context); | 573 Mock::VerifyAndClearExpectations(context); |
| 574 } | 574 } |
| 575 | 575 |
| 576 } // namespace | 576 } // namespace |
| 577 } // namespace cc | 577 } // namespace cc |
| OLD | NEW |