summaryrefslogtreecommitdiffstats
path: root/cc/test/test_web_graphics_context_3d_unittest.cc
blob: 107f15ca3465e59de396b0c2c340be6611552b74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/scoped_ptr.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/khronos/GLES2/gl2ext.h"

namespace cc {
namespace {

static bool check_parameter_value(TestWebGraphicsContext3D* context,
                                  GLenum pname,
                                  GLint expected_value) {
  GLint actual_value = 0;
  context->getTexParameteriv(GL_TEXTURE_2D, pname, &actual_value);
  return expected_value == actual_value;
}

static void expect_default_parameter_values(TestWebGraphicsContext3D* context) {
  EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
  EXPECT_TRUE(check_parameter_value(
      context, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR));
  EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_WRAP_S, GL_REPEAT));
  EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_WRAP_T, GL_REPEAT));
  EXPECT_TRUE(check_parameter_value(
      context, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
  EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_USAGE_ANGLE, GL_NONE));
}

TEST(TestWebGraphicsContext3DTest, GetDefaultTextureParameterValues) {
  scoped_ptr<TestWebGraphicsContext3D> context(
      TestWebGraphicsContext3D::Create());

  GLuint texture = context->createTexture();
  context->bindTexture(GL_TEXTURE_2D, texture);

  expect_default_parameter_values(context.get());
}

TEST(TestWebGraphicsContext3DTest, SetAndGetTextureParameter) {
  scoped_ptr<TestWebGraphicsContext3D> context(
      TestWebGraphicsContext3D::Create());

  GLuint texture = context->createTexture();
  context->bindTexture(GL_TEXTURE_2D, texture);
  context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

  EXPECT_TRUE(
      check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_NEAREST));
}

TEST(TestWebGraphicsContext3DTest,
     SetAndGetMultipleTextureParametersOnMultipleTextures) {
  scoped_ptr<TestWebGraphicsContext3D> context(
      TestWebGraphicsContext3D::Create());

  // Set and get non-default texture parameters on the first texture.
  GLuint first_texture = context->createTexture();
  context->bindTexture(GL_TEXTURE_2D, first_texture);
  context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

  EXPECT_TRUE(
      check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR));
  EXPECT_TRUE(
      check_parameter_value(context.get(), GL_TEXTURE_MAG_FILTER, GL_NEAREST));

  // Set and get different, non-default texture parameters on the second
  // texture.
  GLuint second_texture = context->createTexture();
  context->bindTexture(GL_TEXTURE_2D, second_texture);
  context->texParameteri(
      GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  context->texParameteri(
      GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);

  EXPECT_TRUE(check_parameter_value(
      context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST));
  EXPECT_TRUE(check_parameter_value(
      context.get(), GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR));

  // Get texture parameters on the first texture and verify they are still
  // intact.
  context->bindTexture(GL_TEXTURE_2D, first_texture);

  EXPECT_TRUE(
      check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR));
  EXPECT_TRUE(
      check_parameter_value(context.get(), GL_TEXTURE_MAG_FILTER, GL_NEAREST));
}

}  // namespace
}  // namespace cc