summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authormvujovic@adobe.com <mvujovic@adobe.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 05:59:57 +0000
committermvujovic@adobe.com <mvujovic@adobe.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 05:59:57 +0000
commit521ba29fe8dcf0b0e1216affac2a28d9d6e0cd34 (patch)
treeac7d157b3229a4135fe9570752b58d85e032c4bd /cc
parent05a13914f19cf7f7d21c724d836021e263139157 (diff)
downloadchromium_src-521ba29fe8dcf0b0e1216affac2a28d9d6e0cd34.zip
chromium_src-521ba29fe8dcf0b0e1216affac2a28d9d6e0cd34.tar.gz
chromium_src-521ba29fe8dcf0b0e1216affac2a28d9d6e0cd34.tar.bz2
Make TestWebGraphicsContext3D capable of tracking texture parameters via texParameteri and getTexParameteriv
This makes bugs like http://crbug.com/274753 unit-testable. Review URL: https://codereview.chromium.org/57993005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/cc_tests.gyp1
-rw-r--r--cc/resources/resource_provider_unittest.cc33
-rw-r--r--cc/test/test_texture.cc17
-rw-r--r--cc/test/test_texture.h8
-rw-r--r--cc/test/test_web_graphics_context_3d.cc33
-rw-r--r--cc/test/test_web_graphics_context_3d.h9
-rw-r--r--cc/test/test_web_graphics_context_3d_unittest.cc97
7 files changed, 167 insertions, 31 deletions
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp
index 3325ff7..4683294 100644
--- a/cc/cc_tests.gyp
+++ b/cc/cc_tests.gyp
@@ -78,6 +78,7 @@
'scheduler/scheduler_unittest.cc',
'scheduler/texture_uploader_unittest.cc',
'test/layer_tree_json_parser_unittest.cc',
+ 'test/test_web_graphics_context_3d_unittest.cc',
'trees/damage_tracker_unittest.cc',
'trees/layer_sorter_unittest.cc',
'trees/layer_tree_host_common_unittest.cc',
diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc
index bc26e1c..33cfa5c 100644
--- a/cc/resources/resource_provider_unittest.cc
+++ b/cc/resources/resource_provider_unittest.cc
@@ -244,16 +244,6 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
SetPixels(xoffset, yoffset, width, height, pixels);
}
- virtual void texParameteri(WGC3Denum target, WGC3Denum param, WGC3Dint value)
- OVERRIDE {
- CheckTextureIsBound(target);
- base::AutoLock lock_for_texture_access(namespace_->lock);
- scoped_refptr<TestTexture> texture = BoundTexture(target);
- if (param != GL_TEXTURE_MIN_FILTER)
- return;
- texture->filter = value;
- }
-
virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) OVERRIDE {
return shared_data_->GenMailbox(mailbox);
}
@@ -290,22 +280,6 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format));
}
- WGC3Denum GetTextureFilter() {
- CheckTextureIsBound(GL_TEXTURE_2D);
- base::AutoLock lock_for_texture_access(namespace_->lock);
- return BoundTexture(GL_TEXTURE_2D)->filter;
- }
-
- scoped_refptr<TestTexture> BoundTexture(WGC3Denum target) {
- // The caller is expected to lock the namespace for texture access.
- namespace_->lock.AssertAcquired();
- return namespace_->textures.TextureForId(BoundTextureId(target));
- }
-
- void CheckTextureIsBound(WGC3Denum target) {
- ASSERT_TRUE(BoundTextureId(target));
- }
-
protected:
explicit ResourceProviderContext(ContextSharedData* shared_data)
: shared_data_(shared_data),
@@ -2460,6 +2434,13 @@ class AllocationTrackingContext3D : public TestWebGraphicsContext3D {
MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint));
MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint));
MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint));
+
+ // We're mocking bindTexture, so we override
+ // TestWebGraphicsContext3D::texParameteri to avoid assertions related to the
+ // currently bound texture.
+ virtual void texParameteri(blink::WGC3Denum target,
+ blink::WGC3Denum pname,
+ blink::WGC3Dint param) {}
};
TEST_P(ResourceProviderTest, TextureAllocation) {
diff --git a/cc/test/test_texture.cc b/cc/test/test_texture.cc
index f68f5a6..d94ad56 100644
--- a/cc/test/test_texture.cc
+++ b/cc/test/test_texture.cc
@@ -4,7 +4,9 @@
#include "cc/test/test_texture.h"
+#include "gpu/GLES2/gl2extchromium.h"
#include "third_party/khronos/GLES2/gl2.h"
+#include "third_party/khronos/GLES2/gl2ext.h"
namespace cc {
@@ -15,8 +17,15 @@ size_t TextureSizeBytes(gfx::Size size, ResourceFormat format) {
bytes_per_component;
}
-TestTexture::TestTexture()
- : format(RGBA_8888), filter(GL_NEAREST_MIPMAP_LINEAR) {}
+TestTexture::TestTexture() : format(RGBA_8888) {
+ // Initialize default parameter values.
+ params[GL_TEXTURE_MAG_FILTER] = GL_LINEAR;
+ params[GL_TEXTURE_MIN_FILTER] = GL_NEAREST_MIPMAP_LINEAR;
+ params[GL_TEXTURE_WRAP_S] = GL_REPEAT;
+ params[GL_TEXTURE_WRAP_T] = GL_REPEAT;
+ params[GL_TEXTURE_POOL_CHROMIUM] = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM;
+ params[GL_TEXTURE_USAGE_ANGLE] = GL_NONE;
+}
TestTexture::~TestTexture() {}
@@ -26,4 +35,8 @@ void TestTexture::Reallocate(gfx::Size size, ResourceFormat format) {
this->data.reset(new uint8_t[TextureSizeBytes(size, format)]);
}
+bool TestTexture::IsValidParameter(blink::WGC3Denum pname) {
+ return params.find(pname) != params.end();
+}
+
} // namespace cc
diff --git a/cc/test/test_texture.h b/cc/test/test_texture.h
index 604432e..71015c8 100644
--- a/cc/test/test_texture.h
+++ b/cc/test/test_texture.h
@@ -5,6 +5,7 @@
#ifndef CC_TEST_TEST_TEXTURE_H_
#define CC_TEST_TEST_TEXTURE_H_
+#include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "cc/resources/resource_format.h"
@@ -19,14 +20,15 @@ struct TestTexture : public base::RefCounted<TestTexture> {
TestTexture();
void Reallocate(gfx::Size size, ResourceFormat format);
+ bool IsValidParameter(blink::WGC3Denum pname);
gfx::Size size;
ResourceFormat format;
scoped_ptr<uint8_t[]> data;
- // TODO(mvujovic): Replace this with a hash map of texture parameter names
- // and values, which can hold this filter parameter value and more.
- blink::WGC3Denum filter;
+ typedef base::hash_map<blink::WGC3Denum, blink::WGC3Dint>
+ TextureParametersMap;
+ TextureParametersMap params;
private:
friend class base::RefCounted<TestTexture>;
diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc
index f181f9a..57183d3 100644
--- a/cc/test/test_web_graphics_context_3d.cc
+++ b/cc/test/test_web_graphics_context_3d.cc
@@ -366,6 +366,17 @@ blink::WebGLId TestWebGraphicsContext3D::BoundTextureId(
return texture_targets_.BoundTexture(target);
}
+scoped_refptr<TestTexture> TestWebGraphicsContext3D::BoundTexture(
+ WGC3Denum target) {
+ // The caller is expected to lock the namespace for texture access.
+ namespace_->lock.AssertAcquired();
+ return namespace_->textures.TextureForId(BoundTextureId(target));
+}
+
+void TestWebGraphicsContext3D::CheckTextureIsBound(WGC3Denum target) {
+ DCHECK(BoundTextureId(target));
+}
+
void TestWebGraphicsContext3D::endQueryEXT(WGC3Denum target) {
if (times_end_query_succeeds_ >= 0) {
if (!times_end_query_succeeds_) {
@@ -690,6 +701,28 @@ void TestWebGraphicsContext3D::TextureTargets::BindTexture(
bound_textures_[target] = id;
}
+void TestWebGraphicsContext3D::texParameteri(blink::WGC3Denum target,
+ blink::WGC3Denum pname,
+ blink::WGC3Dint param) {
+ CheckTextureIsBound(target);
+ base::AutoLock lock_for_texture_access(namespace_->lock);
+ scoped_refptr<TestTexture> texture = BoundTexture(target);
+ DCHECK(texture->IsValidParameter(pname));
+ texture->params[pname] = param;
+}
+
+void TestWebGraphicsContext3D::getTexParameteriv(blink::WGC3Denum target,
+ blink::WGC3Denum pname,
+ blink::WGC3Dint* value) {
+ CheckTextureIsBound(target);
+ base::AutoLock lock_for_texture_access(namespace_->lock);
+ scoped_refptr<TestTexture> texture = BoundTexture(target);
+ DCHECK(texture->IsValidParameter(pname));
+ TestTexture::TextureParametersMap::iterator it = texture->params.find(pname);
+ if (it != texture->params.end())
+ *value = it->second;
+}
+
void TestWebGraphicsContext3D::TextureTargets::UnbindTexture(
blink::WebGLId id) {
// Bind zero to any targets that the id is bound to.
diff --git a/cc/test/test_web_graphics_context_3d.h b/cc/test/test_web_graphics_context_3d.h
index 5e876ef..4828720 100644
--- a/cc/test/test_web_graphics_context_3d.h
+++ b/cc/test/test_web_graphics_context_3d.h
@@ -47,6 +47,13 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
blink::WGC3Denum target,
blink::WebGLId texture_id);
+ virtual void texParameteri(blink::WGC3Denum target,
+ blink::WGC3Denum pname,
+ blink::WGC3Dint param);
+ virtual void getTexParameteriv(blink::WGC3Denum target,
+ blink::WGC3Denum pname,
+ blink::WGC3Dint* value);
+
virtual blink::WGC3Denum checkFramebufferStatus(blink::WGC3Denum target);
virtual Attributes getContextAttributes();
@@ -313,6 +320,8 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
void SwapBuffersComplete();
void CreateNamespace();
blink::WebGLId BoundTextureId(blink::WGC3Denum target);
+ scoped_refptr<TestTexture> BoundTexture(blink::WGC3Denum target);
+ void CheckTextureIsBound(blink::WGC3Denum target);
unsigned context_id_;
Attributes attributes_;
diff --git a/cc/test/test_web_graphics_context_3d_unittest.cc b/cc/test/test_web_graphics_context_3d_unittest.cc
new file mode 100644
index 0000000..aa5ccf3
--- /dev/null
+++ b/cc/test/test_web_graphics_context_3d_unittest.cc
@@ -0,0 +1,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,
+ blink::WGC3Denum pname,
+ blink::WGC3Dint expected_value) {
+ blink::WGC3Dint 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());
+
+ blink::WebGLId texture = context->createTexture();
+ context->bindTexture(GL_TEXTURE_2D, texture);
+
+ expect_default_parameter_values(context.get());
+}
+
+TEST(TestWebGraphicsContext3DTest, SetAndGetTextureParameter) {
+ scoped_ptr<TestWebGraphicsContext3D> context(
+ TestWebGraphicsContext3D::Create());
+
+ blink::WebGLId 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.
+ blink::WebGLId 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.
+ blink::WebGLId 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