Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / cc / output / texture_copier_unittest.cc
blobdcd2a9897b7bac98e9d2c54b1ee79150db9bd9a0
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/output/texture_copier.h"
7 #include "cc/test/test_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 testing::InSequence;
13 using testing::Test;
14 using testing::_;
15 using WebKit::WebGLId;
16 using WebKit::WGC3Denum;
17 using WebKit::WGC3Dint;
18 using WebKit::WGC3Dsizei;
20 namespace cc {
21 namespace {
23 class MockContext : public TestWebGraphicsContext3D {
24 public:
25 MOCK_METHOD2(bindFramebuffer, void(WGC3Denum, WebGLId));
26 MOCK_METHOD3(texParameteri,
27 void(WGC3Denum target, WGC3Denum pname, WGC3Dint param));
28 MOCK_METHOD1(disable, void(WGC3Denum cap));
29 MOCK_METHOD1(enable, void(WGC3Denum cap));
31 MOCK_METHOD3(drawArrays,
32 void(WGC3Denum mode, WGC3Dint first, WGC3Dsizei count));
35 TEST(TextureCopierTest, TestDrawArraysCopy) {
36 scoped_ptr<MockContext> mock_context(new MockContext);
38 InSequence sequence;
40 EXPECT_CALL(*mock_context, disable(GL_SCISSOR_TEST));
42 // Here we check just some essential properties of copyTexture() to avoid
43 // mirroring the full implementation.
44 EXPECT_CALL(*mock_context, bindFramebuffer(GL_FRAMEBUFFER, _));
46 // Make sure linear filtering is disabled during the copy.
47 EXPECT_CALL(
48 *mock_context,
49 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
50 EXPECT_CALL(
51 *mock_context,
52 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
54 EXPECT_CALL(*mock_context, disable(GL_BLEND));
56 EXPECT_CALL(*mock_context, drawArrays(_, _, _));
58 // Linear filtering, default framebuffer and scissor test should be
59 // restored.
60 EXPECT_CALL(*mock_context,
61 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
62 EXPECT_CALL(*mock_context,
63 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
64 EXPECT_CALL(*mock_context, bindFramebuffer(GL_FRAMEBUFFER, 0));
65 EXPECT_CALL(*mock_context, enable(GL_SCISSOR_TEST));
68 int source_texture_id = mock_context->createTexture();
69 int dest_texture_id = mock_context->createTexture();
70 gfx::Size size(256, 128);
71 scoped_ptr<AcceleratedTextureCopier> copier(
72 AcceleratedTextureCopier::Create(mock_context.get(), false, 0));
73 TextureCopier::Parameters copy = { source_texture_id, dest_texture_id, size };
74 copier->CopyTexture(copy);
77 } // namespace
78 } // namespace cc