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_web_compositor_output_surface.h" | 10 #include "cc/test/fake_web_compositor_output_surface.h" |
11 #include "cc/test/fake_web_graphics_context_3d.h" | 11 #include "cc/test/fake_web_graphics_context_3d.h" |
12 #include "cc/test/render_pass_test_common.h" | 12 #include "cc/test/render_pass_test_common.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/khronos/GLES2/gl2.h" | 15 #include "third_party/khronos/GLES2/gl2.h" |
16 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
17 | 17 |
18 using namespace WebKit; | 18 using namespace WebKit; |
19 using namespace WebKitTests; | 19 using namespace WebKitTests; |
20 | 20 |
| 21 using testing::_; |
| 22 using testing::AnyNumber; |
| 23 using testing::InSequence; |
| 24 using testing::Mock; |
| 25 |
21 namespace cc { | 26 namespace cc { |
22 namespace { | 27 namespace { |
23 | 28 |
24 class FrameCountingMemoryAllocationSettingContext : public FakeWebGraphicsContex
t3D { | 29 class FrameCountingMemoryAllocationSettingContext : public FakeWebGraphicsContex
t3D { |
25 public: | 30 public: |
26 FrameCountingMemoryAllocationSettingContext() : m_frame(0) { } | 31 FrameCountingMemoryAllocationSettingContext() : m_frame(0) { } |
27 | 32 |
28 // WebGraphicsContext3D methods. | 33 // WebGraphicsContext3D methods. |
29 | 34 |
30 // This method would normally do a glSwapBuffers under the hood. | 35 // This method would normally do a glSwapBuffers under the hood. |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // 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 |
475 // them both a pointer to a variable on the stack. | 480 // them both a pointer to a variable on the stack. |
476 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); | 481 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); |
477 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); | 482 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); |
478 renderer.setVisible(true); | 483 renderer.setVisible(true); |
479 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 484 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
480 renderer.setVisible(false); | 485 renderer.setVisible(false); |
481 EXPECT_TRUE(lastCallWasSetVisiblity); | 486 EXPECT_TRUE(lastCallWasSetVisiblity); |
482 } | 487 } |
483 | 488 |
484 | |
485 class TextureStateTrackingContext : public FakeWebGraphicsContext3D { | 489 class TextureStateTrackingContext : public FakeWebGraphicsContext3D { |
486 public: | 490 public: |
487 TextureStateTrackingContext() | 491 TextureStateTrackingContext() |
488 : m_activeTexture(GL_INVALID_ENUM) | 492 : m_activeTexture(GL_INVALID_ENUM) |
489 , m_inDraw(false) | |
490 { | 493 { |
491 } | 494 } |
492 | 495 |
493 virtual WebString getString(WGC3Denum name) | 496 virtual WebString getString(WGC3Denum name) |
494 { | 497 { |
495 if (name == GL_EXTENSIONS) | 498 if (name == GL_EXTENSIONS) |
496 return WebString("GL_OES_EGL_image_external"); | 499 return WebString("GL_OES_EGL_image_external"); |
497 return WebString(); | 500 return WebString(); |
498 } | 501 } |
499 | 502 |
500 // We shouldn't set any texture parameters during the draw sequence, althoug
h | 503 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint
param)); |
501 // we might when creating the quads. | 504 MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum
type, WGC3Dintptr offset)); |
502 void setInDraw() { m_inDraw = true; } | |
503 | |
504 virtual void texParameteri(WGC3Denum target, WGC3Denum pname, WGC3Dint param
) | |
505 { | |
506 if (m_inDraw) | |
507 ADD_FAILURE(); | |
508 } | |
509 | 505 |
510 virtual void activeTexture(WGC3Denum texture) | 506 virtual void activeTexture(WGC3Denum texture) |
511 { | 507 { |
512 EXPECT_NE(texture, m_activeTexture); | 508 EXPECT_NE(texture, m_activeTexture); |
513 m_activeTexture = texture; | 509 m_activeTexture = texture; |
514 } | 510 } |
515 | 511 |
516 WGC3Denum activeTexture() const { return m_activeTexture; } | 512 WGC3Denum activeTexture() const { return m_activeTexture; } |
517 | 513 |
518 private: | 514 private: |
519 bool m_inDraw; | |
520 WGC3Denum m_activeTexture; | 515 WGC3Denum m_activeTexture; |
521 }; | 516 }; |
522 | 517 |
523 TEST(GLRendererTest2, activeTextureState) | 518 TEST(GLRendererTest2, activeTextureState) |
524 { | 519 { |
525 FakeRendererClient fakeClient; | 520 FakeRendererClient fakeClient; |
526 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext)))
; | 521 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext)))
; |
527 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->context3D()); | 522 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->context3D()); |
528 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 523 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
529 FakeRendererGL renderer(&fakeClient, resourceProvider.get()); | 524 FakeRendererGL renderer(&fakeClient, resourceProvider.get()); |
530 | 525 |
| 526 // During initialization we are allowed to set any texture parameters. |
| 527 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber()); |
531 EXPECT_TRUE(renderer.initialize()); | 528 EXPECT_TRUE(renderer.initialize()); |
532 | 529 |
533 cc::RenderPass::Id id(1, 1); | 530 cc::RenderPass::Id id(1, 1); |
534 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | 531 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
535 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()); |
536 pass->AppendOneOfEveryQuadType(resourceProvider.get()); | 533 pass->AppendOneOfEveryQuadType(resourceProvider.get()); |
537 | 534 |
538 context->setInDraw(); | 535 // Set up expected texture filter state transitions that match the quads |
| 536 // created in AppendOneOfEveryQuadType(). |
| 537 Mock::VerifyAndClearExpectations(context); |
| 538 { |
| 539 InSequence sequence; |
| 540 |
| 541 // yuv_quad is drawn with the default filter. |
| 542 EXPECT_CALL(*context, drawElements(_, _, _, _)); |
| 543 |
| 544 // tile_quad is drawn with GL_NEAREST because it is not transformed or |
| 545 // scaled. |
| 546 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_NEAREST)); |
| 547 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_NEAREST)); |
| 548 EXPECT_CALL(*context, drawElements(_, _, _, _)); |
| 549 |
| 550 // transformed_tile_quad uses GL_LINEAR. |
| 551 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
| 552 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
| 553 EXPECT_CALL(*context, drawElements(_, _, _, _)); |
| 554 |
| 555 // scaled_tile_quad also uses GL_LINEAR. |
| 556 EXPECT_CALL(*context, drawElements(_, _, _, _)); |
| 557 |
| 558 // The remaining quads also use GL_LINEAR because nearest neighbor |
| 559 // filtering is currently only used with tile quads. |
| 560 EXPECT_CALL(*context, drawElements(_, _, _, _)).Times(6); |
| 561 } |
539 | 562 |
540 cc::DirectRenderer::DrawingFrame drawingFrame; | 563 cc::DirectRenderer::DrawingFrame drawingFrame; |
541 renderer.beginDrawingFrame(drawingFrame); | 564 renderer.beginDrawingFrame(drawingFrame); |
542 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); | 565 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); |
543 | 566 |
544 for (cc::QuadList::backToFrontIterator it = pass->quad_list.backToFrontBegin
(); | 567 for (cc::QuadList::backToFrontIterator it = pass->quad_list.backToFrontBegin
(); |
545 it != pass->quad_list.backToFrontEnd(); ++it) { | 568 it != pass->quad_list.backToFrontEnd(); ++it) { |
546 renderer.drawQuad(drawingFrame, *it); | 569 renderer.drawQuad(drawingFrame, *it); |
547 } | 570 } |
548 renderer.finishDrawingQuadList(); | 571 renderer.finishDrawingQuadList(); |
549 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); | 572 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); |
| 573 Mock::VerifyAndClearExpectations(context); |
550 } | 574 } |
551 | 575 |
552 } // namespace | 576 } // namespace |
553 } // namespace cc | 577 } // namespace cc |
OLD | NEW |