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 "cc/gl_renderer.h" | 6 #include "cc/gl_renderer.h" |
7 | 7 |
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/settings.h" | 11 #include "cc/settings.h" |
12 #include "cc/test/fake_web_compositor_output_surface.h" | 12 #include "cc/test/fake_web_compositor_output_surface.h" |
13 #include "cc/test/fake_web_graphics_context_3d.h" | 13 #include "cc/test/fake_web_graphics_context_3d.h" |
14 #include "cc/test/test_common.h" | 14 #include "cc/test/test_common.h" |
| 15 #include "cc/test/render_pass_test_common.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/khronos/GLES2/gl2.h" | 18 #include "third_party/khronos/GLES2/gl2.h" |
18 #include <public/WebTransformationMatrix.h> | 19 #include <public/WebTransformationMatrix.h> |
19 | 20 |
20 using namespace cc; | 21 using namespace cc; |
21 using namespace WebKit; | 22 using namespace WebKit; |
22 using namespace WebKitTests; | 23 using namespace WebKitTests; |
23 | 24 |
24 namespace { | 25 namespace { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 98 |
98 class FakeRendererGL : public GLRenderer { | 99 class FakeRendererGL : public GLRenderer { |
99 public: | 100 public: |
100 FakeRendererGL(RendererClient* client, ResourceProvider* resourceProvider) :
GLRenderer(client, resourceProvider) { } | 101 FakeRendererGL(RendererClient* client, ResourceProvider* resourceProvider) :
GLRenderer(client, resourceProvider) { } |
101 | 102 |
102 // GLRenderer methods. | 103 // GLRenderer methods. |
103 | 104 |
104 // Changing visibility to public. | 105 // Changing visibility to public. |
105 using GLRenderer::initialize; | 106 using GLRenderer::initialize; |
106 using GLRenderer::isFramebufferDiscarded; | 107 using GLRenderer::isFramebufferDiscarded; |
| 108 using GLRenderer::drawQuad; |
| 109 using GLRenderer::beginDrawingFrame; |
107 }; | 110 }; |
108 | 111 |
109 class GLRendererTest : public testing::Test { | 112 class GLRendererTest : public testing::Test { |
110 protected: | 113 protected: |
111 GLRendererTest() | 114 GLRendererTest() |
112 : m_suggestHaveBackbufferYes(1, true) | 115 : m_suggestHaveBackbufferYes(1, true) |
113 , m_suggestHaveBackbufferNo(1, false) | 116 , m_suggestHaveBackbufferNo(1, false) |
114 , m_context(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We
bGraphicsContext3D>(new FrameCountingMemoryAllocationSettingContext()))) | 117 , m_context(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We
bGraphicsContext3D>(new FrameCountingMemoryAllocationSettingContext()))) |
115 , m_resourceProvider(ResourceProvider::create(m_context.get())) | 118 , m_resourceProvider(ResourceProvider::create(m_context.get())) |
116 , m_renderer(&m_mockClient, m_resourceProvider.get()) | 119 , m_renderer(&m_mockClient, m_resourceProvider.get()) |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // is called. Plumb this tracking between both the RenderClient and the Cont
ext by giving | 478 // is called. Plumb this tracking between both the RenderClient and the Cont
ext by giving |
476 // them both a pointer to a variable on the stack. | 479 // them both a pointer to a variable on the stack. |
477 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); | 480 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); |
478 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); | 481 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); |
479 renderer.setVisible(true); | 482 renderer.setVisible(true); |
480 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); | 483 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa
sses()); |
481 renderer.setVisible(false); | 484 renderer.setVisible(false); |
482 EXPECT_TRUE(lastCallWasSetVisiblity); | 485 EXPECT_TRUE(lastCallWasSetVisiblity); |
483 } | 486 } |
484 | 487 |
| 488 |
| 489 class ActiveTextureTrackingContext : public FakeWebGraphicsContext3D { |
| 490 public: |
| 491 ActiveTextureTrackingContext() |
| 492 : m_activeTexture(GL_INVALID_ENUM) |
| 493 { |
| 494 } |
| 495 |
| 496 virtual WebString getString(WGC3Denum name) |
| 497 { |
| 498 if (name == GL_EXTENSIONS) |
| 499 return WebString("GL_OES_EGL_image_external"); |
| 500 return WebString(); |
| 501 } |
| 502 |
| 503 virtual void activeTexture(WGC3Denum texture) |
| 504 { |
| 505 EXPECT_NE(texture, m_activeTexture); |
| 506 m_activeTexture = texture; |
| 507 } |
| 508 |
| 509 WGC3Denum activeTexture() const { return m_activeTexture; } |
| 510 |
| 511 private: |
| 512 WGC3Denum m_activeTexture; |
| 513 }; |
| 514 |
| 515 TEST(GLRendererTest2, activeTextureState) |
| 516 { |
| 517 FakeRendererClient fakeClient; |
| 518 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new ActiveTextureTrackingContext))
); |
| 519 ActiveTextureTrackingContext* context = static_cast<ActiveTextureTrackingCon
text*>(outputSurface->context3D()); |
| 520 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 521 FakeRendererGL renderer(&fakeClient, resourceProvider.get()); |
| 522 |
| 523 EXPECT_TRUE(renderer.initialize()); |
| 524 |
| 525 cc::RenderPass::Id id(1, 1); |
| 526 scoped_ptr<TestRenderPass> pass = TestRenderPass::create(id, gfx::Rect(0, 0,
100, 100), WebTransformationMatrix()); |
| 527 pass->appendOneOfEveryQuadType(resourceProvider.get()); |
| 528 |
| 529 cc::DirectRenderer::DrawingFrame drawingFrame; |
| 530 renderer.beginDrawingFrame(drawingFrame); |
| 531 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); |
| 532 |
| 533 for (cc::QuadList::backToFrontIterator it = pass->quadList().backToFrontBegi
n(); |
| 534 it != pass->quadList().backToFrontEnd(); ++it) { |
| 535 renderer.drawQuad(drawingFrame, *it); |
| 536 } |
| 537 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); |
| 538 } |
| 539 |
485 } // anonymous namespace | 540 } // anonymous namespace |
OLD | NEW |