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/compositor_frame_metadata.h" | 7 #include "cc/compositor_frame_metadata.h" |
8 #include "cc/draw_quad.h" | 8 #include "cc/draw_quad.h" |
9 #include "cc/prioritized_resource_manager.h" | 9 #include "cc/prioritized_resource_manager.h" |
10 #include "cc/resource_provider.h" | 10 #include "cc/resource_provider.h" |
11 #include "cc/test/fake_impl_proxy.h" | 11 #include "cc/test/fake_impl_proxy.h" |
12 #include "cc/test/fake_layer_tree_host_impl.h" | 12 #include "cc/test/fake_layer_tree_host_impl.h" |
13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
14 #include "cc/test/fake_web_graphics_context_3d.h" | |
15 #include "cc/test/render_pass_test_common.h" | 14 #include "cc/test/render_pass_test_common.h" |
16 #include "cc/test/render_pass_test_utils.h" | 15 #include "cc/test/render_pass_test_utils.h" |
| 16 #include "cc/test/test_web_graphics_context_3d.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/khronos/GLES2/gl2.h" | 19 #include "third_party/khronos/GLES2/gl2.h" |
20 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
21 | 21 |
22 using namespace WebKit; | 22 using namespace WebKit; |
23 | 23 |
24 using testing::_; | 24 using testing::_; |
25 using testing::AnyNumber; | 25 using testing::AnyNumber; |
26 using testing::AtLeast; | 26 using testing::AtLeast; |
27 using testing::Expectation; | 27 using testing::Expectation; |
28 using testing::InSequence; | 28 using testing::InSequence; |
29 using testing::Mock; | 29 using testing::Mock; |
30 | 30 |
31 namespace cc { | 31 namespace cc { |
32 namespace { | 32 namespace { |
33 | 33 |
34 class FrameCountingMemoryAllocationSettingContext : public FakeWebGraphicsContex
t3D { | 34 class FrameCountingMemoryAllocationSettingContext : public TestWebGraphicsContex
t3D { |
35 public: | 35 public: |
36 FrameCountingMemoryAllocationSettingContext() : m_frame(0) { } | 36 FrameCountingMemoryAllocationSettingContext() : m_frame(0) { } |
37 | 37 |
38 // WebGraphicsContext3D methods. | 38 // WebGraphicsContext3D methods. |
39 | 39 |
40 // This method would normally do a glSwapBuffers under the hood. | 40 // This method would normally do a glSwapBuffers under the hood. |
41 virtual void prepareTexture() { m_frame++; } | 41 virtual void prepareTexture() { m_frame++; } |
42 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { m_memoryAllocationChangedCallback =
callback; } | 42 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { m_memoryAllocationChangedCallback =
callback; } |
43 virtual WebString getString(WebKit::WGC3Denum name) | 43 virtual WebString getString(WebKit::WGC3Denum name) |
44 { | 44 { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 231 |
232 char pixels[4]; | 232 char pixels[4]; |
233 m_renderer.drawFrame(m_mockClient.renderPassesInDrawOrder()); | 233 m_renderer.drawFrame(m_mockClient.renderPassesInDrawOrder()); |
234 EXPECT_FALSE(m_renderer.isBackbufferDiscarded()); | 234 EXPECT_FALSE(m_renderer.isBackbufferDiscarded()); |
235 | 235 |
236 m_renderer.getFramebufferPixels(pixels, gfx::Rect(0, 0, 1, 1)); | 236 m_renderer.getFramebufferPixels(pixels, gfx::Rect(0, 0, 1, 1)); |
237 EXPECT_TRUE(m_renderer.isBackbufferDiscarded()); | 237 EXPECT_TRUE(m_renderer.isBackbufferDiscarded()); |
238 EXPECT_EQ(2, m_mockClient.setFullRootLayerDamageCount()); | 238 EXPECT_EQ(2, m_mockClient.setFullRootLayerDamageCount()); |
239 } | 239 } |
240 | 240 |
241 class ForbidSynchronousCallContext : public FakeWebGraphicsContext3D { | 241 class ForbidSynchronousCallContext : public TestWebGraphicsContext3D { |
242 public: | 242 public: |
243 ForbidSynchronousCallContext() { } | 243 ForbidSynchronousCallContext() { } |
244 | 244 |
245 virtual bool getActiveAttrib(WebGLId program, WGC3Duint index, ActiveInfo&)
{ ADD_FAILURE(); return false; } | 245 virtual bool getActiveAttrib(WebGLId program, WGC3Duint index, ActiveInfo&)
{ ADD_FAILURE(); return false; } |
246 virtual bool getActiveUniform(WebGLId program, WGC3Duint index, ActiveInfo&)
{ ADD_FAILURE(); return false; } | 246 virtual bool getActiveUniform(WebGLId program, WGC3Duint index, ActiveInfo&)
{ ADD_FAILURE(); return false; } |
247 virtual void getAttachedShaders(WebGLId program, WGC3Dsizei maxCount, WGC3Ds
izei* count, WebGLId* shaders) { ADD_FAILURE(); } | 247 virtual void getAttachedShaders(WebGLId program, WGC3Dsizei maxCount, WGC3Ds
izei* count, WebGLId* shaders) { ADD_FAILURE(); } |
248 virtual WGC3Dint getAttribLocation(WebGLId program, const WGC3Dchar* name) {
ADD_FAILURE(); return 0; } | 248 virtual WGC3Dint getAttribLocation(WebGLId program, const WGC3Dchar* name) {
ADD_FAILURE(); return 0; } |
249 virtual void getBooleanv(WGC3Denum pname, WGC3Dboolean* value) { ADD_FAILURE
(); } | 249 virtual void getBooleanv(WGC3Denum pname, WGC3Dboolean* value) { ADD_FAILURE
(); } |
250 virtual void getBufferParameteriv(WGC3Denum target, WGC3Denum pname, WGC3Din
t* value) { ADD_FAILURE(); } | 250 virtual void getBufferParameteriv(WGC3Denum target, WGC3Denum pname, WGC3Din
t* value) { ADD_FAILURE(); } |
251 virtual Attributes getContextAttributes() { ADD_FAILURE(); return attributes
_; } | 251 virtual Attributes getContextAttributes() { ADD_FAILURE(); return attributes
_; } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls) | 308 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls) |
309 { | 309 { |
310 FakeRendererClient mockClient; | 310 FakeRendererClient mockClient; |
311 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ForbidSynchronousCallContext))); | 311 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ForbidSynchronousCallContext))); |
312 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 312 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
313 FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.g
et()); | 313 FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.g
et()); |
314 | 314 |
315 EXPECT_TRUE(renderer.initialize()); | 315 EXPECT_TRUE(renderer.initialize()); |
316 } | 316 } |
317 | 317 |
318 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { | 318 class LoseContextOnFirstGetContext : public TestWebGraphicsContext3D { |
319 public: | 319 public: |
320 LoseContextOnFirstGetContext() | 320 LoseContextOnFirstGetContext() |
321 : m_contextLost(false) | 321 : m_contextLost(false) |
322 { | 322 { |
323 } | 323 } |
324 | 324 |
325 virtual bool makeContextCurrent() OVERRIDE | 325 virtual bool makeContextCurrent() OVERRIDE |
326 { | 326 { |
327 return !m_contextLost; | 327 return !m_contextLost; |
328 } | 328 } |
(...skipping 22 matching lines...) Expand all Loading... |
351 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert) | 351 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert) |
352 { | 352 { |
353 FakeRendererClient mockClient; | 353 FakeRendererClient mockClient; |
354 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext))); | 354 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext))); |
355 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 355 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
356 FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.g
et()); | 356 FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.g
et()); |
357 | 357 |
358 renderer.initialize(); | 358 renderer.initialize(); |
359 } | 359 } |
360 | 360 |
361 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic
sContext3D { | 361 class ContextThatDoesNotSupportMemoryManagmentExtensions : public TestWebGraphic
sContext3D { |
362 public: | 362 public: |
363 ContextThatDoesNotSupportMemoryManagmentExtensions() { } | 363 ContextThatDoesNotSupportMemoryManagmentExtensions() { } |
364 | 364 |
365 // WebGraphicsContext3D methods. | 365 // WebGraphicsContext3D methods. |
366 | 366 |
367 // This method would normally do a glSwapBuffers under the hood. | 367 // This method would normally do a glSwapBuffers under the hood. |
368 virtual void prepareTexture() { } | 368 virtual void prepareTexture() { } |
369 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { } | 369 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll
ocationChangedCallbackCHROMIUM* callback) { } |
370 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } | 370 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } |
371 }; | 371 }; |
372 | 372 |
373 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul
dDefaultToNonZeroAllocation) | 373 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul
dDefaultToNonZeroAllocation) |
374 { | 374 { |
375 FakeRendererClient mockClient; | 375 FakeRendererClient mockClient; |
376 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryManagmentExt
ensions))); | 376 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryManagmentExt
ensions))); |
377 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 377 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
378 FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.g
et()); | 378 FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.g
et()); |
379 | 379 |
380 renderer.initialize(); | 380 renderer.initialize(); |
381 | 381 |
382 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); | 382 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); |
383 } | 383 } |
384 | 384 |
385 class ClearCountingContext : public FakeWebGraphicsContext3D { | 385 class ClearCountingContext : public TestWebGraphicsContext3D { |
386 public: | 386 public: |
387 ClearCountingContext() : m_clear(0) { } | 387 ClearCountingContext() : m_clear(0) { } |
388 | 388 |
389 virtual void clear(WGC3Dbitfield) | 389 virtual void clear(WGC3Dbitfield) |
390 { | 390 { |
391 m_clear++; | 391 m_clear++; |
392 } | 392 } |
393 | 393 |
394 int clearCount() const { return m_clear; } | 394 int clearCount() const { return m_clear; } |
395 | 395 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 430 |
431 mockClient.rootRenderPass()->has_transparent_background = true; | 431 mockClient.rootRenderPass()->has_transparent_background = true; |
432 | 432 |
433 EXPECT_TRUE(renderer.initialize()); | 433 EXPECT_TRUE(renderer.initialize()); |
434 | 434 |
435 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); | 435 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); |
436 | 436 |
437 EXPECT_EQ(1, context->clearCount()); | 437 EXPECT_EQ(1, context->clearCount()); |
438 } | 438 } |
439 | 439 |
440 class VisibilityChangeIsLastCallTrackingContext : public FakeWebGraphicsContext3
D { | 440 class VisibilityChangeIsLastCallTrackingContext : public TestWebGraphicsContext3
D { |
441 public: | 441 public: |
442 VisibilityChangeIsLastCallTrackingContext() | 442 VisibilityChangeIsLastCallTrackingContext() |
443 : m_lastCallWasSetVisibility(0) | 443 : m_lastCallWasSetVisibility(0) |
444 { | 444 { |
445 } | 445 } |
446 | 446 |
447 // WebGraphicsContext3D methods. | 447 // WebGraphicsContext3D methods. |
448 virtual void setVisibilityCHROMIUM(bool visible) { | 448 virtual void setVisibilityCHROMIUM(bool visible) { |
449 if (!m_lastCallWasSetVisibility) | 449 if (!m_lastCallWasSetVisibility) |
450 return; | 450 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // is called. Plumb this tracking between both the RenderClient and the Cont
ext by giving | 487 // is called. Plumb this tracking between both the RenderClient and the Cont
ext by giving |
488 // them both a pointer to a variable on the stack. | 488 // them both a pointer to a variable on the stack. |
489 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); | 489 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); |
490 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); | 490 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); |
491 renderer.setVisible(true); | 491 renderer.setVisible(true); |
492 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); | 492 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); |
493 renderer.setVisible(false); | 493 renderer.setVisible(false); |
494 EXPECT_TRUE(lastCallWasSetVisiblity); | 494 EXPECT_TRUE(lastCallWasSetVisiblity); |
495 } | 495 } |
496 | 496 |
497 class TextureStateTrackingContext : public FakeWebGraphicsContext3D { | 497 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
498 public: | 498 public: |
499 TextureStateTrackingContext() | 499 TextureStateTrackingContext() |
500 : m_activeTexture(GL_INVALID_ENUM) | 500 : m_activeTexture(GL_INVALID_ENUM) |
501 { | 501 { |
502 } | 502 } |
503 | 503 |
504 virtual WebString getString(WGC3Denum name) | 504 virtual WebString getString(WGC3Denum name) |
505 { | 505 { |
506 if (name == GL_EXTENSIONS) | 506 if (name == GL_EXTENSIONS) |
507 return WebString("GL_OES_EGL_image_external"); | 507 return WebString("GL_OES_EGL_image_external"); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 renderer.finishDrawingQuadList(); | 577 renderer.finishDrawingQuadList(); |
578 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); | 578 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); |
579 Mock::VerifyAndClearExpectations(context); | 579 Mock::VerifyAndClearExpectations(context); |
580 } | 580 } |
581 | 581 |
582 class NoClearRootRenderPassFakeClient : public FakeRendererClient { | 582 class NoClearRootRenderPassFakeClient : public FakeRendererClient { |
583 public: | 583 public: |
584 virtual bool shouldClearRootRenderPass() const OVERRIDE { return false; } | 584 virtual bool shouldClearRootRenderPass() const OVERRIDE { return false; } |
585 }; | 585 }; |
586 | 586 |
587 class NoClearRootRenderPassMockContext : public FakeWebGraphicsContext3D { | 587 class NoClearRootRenderPassMockContext : public TestWebGraphicsContext3D { |
588 public: | 588 public: |
589 MOCK_METHOD1(clear, void(WGC3Dbitfield mask)); | 589 MOCK_METHOD1(clear, void(WGC3Dbitfield mask)); |
590 MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum
type, WGC3Dintptr offset)); | 590 MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum
type, WGC3Dintptr offset)); |
591 }; | 591 }; |
592 | 592 |
593 TEST(GLRendererTest2, shouldClearRootRenderPass) | 593 TEST(GLRendererTest2, shouldClearRootRenderPass) |
594 { | 594 { |
595 NoClearRootRenderPassFakeClient mockClient; | 595 NoClearRootRenderPassFakeClient mockClient; |
596 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new NoClearRootRenderPassMockContext))); | 596 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new NoClearRootRenderPassMockContext))); |
597 NoClearRootRenderPassMockContext* mockContext = static_cast<NoClearRootRende
rPassMockContext*>(outputSurface->Context3D()); | 597 NoClearRootRenderPassMockContext* mockContext = static_cast<NoClearRootRende
rPassMockContext*>(outputSurface->Context3D()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 .Times(AnyNumber()) | 629 .Times(AnyNumber()) |
630 .After(firstRenderPass); | 630 .After(firstRenderPass); |
631 | 631 |
632 renderer.decideRenderPassAllocationsForFrame(mockClient.renderPassesInDrawOr
der()); | 632 renderer.decideRenderPassAllocationsForFrame(mockClient.renderPassesInDrawOr
der()); |
633 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); | 633 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); |
634 | 634 |
635 // In multiple render passes all but the root pass should clear the framebuf
fer. | 635 // In multiple render passes all but the root pass should clear the framebuf
fer. |
636 Mock::VerifyAndClearExpectations(&mockContext); | 636 Mock::VerifyAndClearExpectations(&mockContext); |
637 } | 637 } |
638 | 638 |
639 class ScissorTestOnClearCheckingContext : public FakeWebGraphicsContext3D { | 639 class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D { |
640 public: | 640 public: |
641 ScissorTestOnClearCheckingContext() : m_scissorEnabled(false) { } | 641 ScissorTestOnClearCheckingContext() : m_scissorEnabled(false) { } |
642 | 642 |
643 virtual void clear(WGC3Dbitfield) | 643 virtual void clear(WGC3Dbitfield) |
644 { | 644 { |
645 EXPECT_FALSE(m_scissorEnabled); | 645 EXPECT_FALSE(m_scissorEnabled); |
646 } | 646 } |
647 | 647 |
648 virtual void enable(WGC3Denum cap) | 648 virtual void enable(WGC3Denum cap) |
649 { | 649 { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 | 689 |
690 addRenderPassQuad(rootPass, childPass); | 690 addRenderPassQuad(rootPass, childPass); |
691 addRenderPassQuad(childPass, grandChildPass); | 691 addRenderPassQuad(childPass, grandChildPass); |
692 | 692 |
693 renderer.decideRenderPassAllocationsForFrame(mockClient.renderPassesInDrawOr
der()); | 693 renderer.decideRenderPassAllocationsForFrame(mockClient.renderPassesInDrawOr
der()); |
694 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); | 694 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); |
695 } | 695 } |
696 | 696 |
697 } // namespace | 697 } // namespace |
698 } // namespace cc | 698 } // namespace cc |
OLD | NEW |