WebKit Roll 139512:139548
[chromium-blink-merge.git] / cc / texture_copier_unittest.cc
blobd22df6c2a7a8c0457e96fdb8c13852577489d20f
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/texture_copier.h"
7 #include "cc/test/fake_web_graphics_context_3d.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/khronos/GLES2/gl2.h"
12 using namespace WebKit;
13 using testing::InSequence;
14 using testing::Test;
15 using testing::_;
17 namespace cc {
18 namespace {
20 class MockContext : public FakeWebGraphicsContext3D {
21 public:
22 MOCK_METHOD2(bindFramebuffer, void(WGC3Denum, WebGLId));
23 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint param));
24 MOCK_METHOD1(disable, void(WGC3Denum cap));
25 MOCK_METHOD1(enable, void(WGC3Denum cap));
27 MOCK_METHOD3(drawArrays, void(WGC3Denum mode, WGC3Dint first, WGC3Dsizei count));
30 TEST(TextureCopierTest, testDrawArraysCopy)
32 scoped_ptr<MockContext> mockContext(new MockContext);
35 InSequence sequence;
37 EXPECT_CALL(*mockContext, disable(GL_SCISSOR_TEST));
39 // Here we check just some essential properties of copyTexture() to avoid mirroring the full implementation.
40 EXPECT_CALL(*mockContext, bindFramebuffer(GL_FRAMEBUFFER, _));
42 // Make sure linear filtering is disabled during the copy.
43 EXPECT_CALL(*mockContext, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
44 EXPECT_CALL(*mockContext, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
46 EXPECT_CALL(*mockContext, disable(GL_BLEND));
48 EXPECT_CALL(*mockContext, drawArrays(_, _, _));
50 // Linear filtering, default framebuffer and scissor test should be restored.
51 EXPECT_CALL(*mockContext, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
52 EXPECT_CALL(*mockContext, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
53 EXPECT_CALL(*mockContext, bindFramebuffer(GL_FRAMEBUFFER, 0));
54 EXPECT_CALL(*mockContext, enable(GL_SCISSOR_TEST));
57 int sourceTextureId = mockContext->createTexture();
58 int destTextureId = mockContext->createTexture();
59 gfx::Size size(256, 128);
60 scoped_ptr<AcceleratedTextureCopier> copier(AcceleratedTextureCopier::create(mockContext.get(), false));
61 TextureCopier::Parameters copy = { sourceTextureId, destTextureId, size };
62 copier->copyTexture(copy);
65 } // namespace
66 } // namespace cc