diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-12 23:17:34 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-12 23:17:34 +0000 |
commit | a34b0679cb670ce40d480af2be02c7a47a7e9fa8 (patch) | |
tree | 2dfdc48817d979d85d97c0675bac70e70818d5e9 /gpu | |
parent | b999372d7f8941e61bbb577d41c98929eb2987d8 (diff) | |
download | chromium_src-a34b0679cb670ce40d480af2be02c7a47a7e9fa8.zip chromium_src-a34b0679cb670ce40d480af2be02c7a47a7e9fa8.tar.gz chromium_src-a34b0679cb670ce40d480af2be02c7a47a7e9fa8.tar.bz2 |
Add gl_tests target as place to put GL tests for the command buffer.
TEST=unit tests
BUG=123086
Review URL: http://codereview.chromium.org/10053033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/tests/gl_manager.cc | 144 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_manager.h | 61 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_tests_main.cc | 29 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_unittests.cc | 39 | ||||
-rw-r--r-- | gpu/gpu_common.gypi | 31 |
5 files changed, 304 insertions, 0 deletions
diff --git a/gpu/command_buffer/tests/gl_manager.cc b/gpu/command_buffer/tests/gl_manager.cc new file mode 100644 index 0000000..aab881d --- /dev/null +++ b/gpu/command_buffer/tests/gl_manager.cc @@ -0,0 +1,144 @@ +// Copyright (c) 2012 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 "gpu/command_buffer/tests/gl_manager.h" +#include "base/at_exit.h" +#include "base/bind.h" +#include "gpu/command_buffer/client/gles2_lib.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "gpu/command_buffer/client/transfer_buffer.h" +#include "gpu/command_buffer/common/constants.h" +#include "gpu/command_buffer/service/context_group.h" +#include "gpu/command_buffer/service/gpu_scheduler.h" +#include "gpu/command_buffer/service/command_buffer_service.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/gl/gl_context.h" +#include "ui/gfx/gl/gl_share_group.h" +#include "ui/gfx/gl/gl_surface.h" + +namespace gpu { + +GLManager::GLManager() { +} + +GLManager::~GLManager() { +} + +void GLManager::Initialize(const gfx::Size& size) { + const int32 kCommandBufferSize = 1024 * 1024; + const size_t kStartTransferBufferSize = 4 * 1024 * 1024; + const size_t kMinTransferBufferSize = 1 * 256 * 1024; + const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; + + // From <EGL/egl.h>. + const int32 EGL_ALPHA_SIZE = 0x3021; + const int32 EGL_BLUE_SIZE = 0x3022; + const int32 EGL_GREEN_SIZE = 0x3023; + const int32 EGL_RED_SIZE = 0x3024; + const int32 EGL_DEPTH_SIZE = 0x3025; + const int32 EGL_NONE = 0x3038; + + gfx::GpuPreference gpu_preference(gfx::PreferDiscreteGpu); + const char* allowed_extensions = "*"; + std::vector<int32> attribs; + attribs.push_back(EGL_RED_SIZE); + attribs.push_back(8); + attribs.push_back(EGL_GREEN_SIZE); + attribs.push_back(8); + attribs.push_back(EGL_BLUE_SIZE); + attribs.push_back(8); + attribs.push_back(EGL_ALPHA_SIZE); + attribs.push_back(8); + attribs.push_back(EGL_DEPTH_SIZE); + attribs.push_back(16); + attribs.push_back(EGL_NONE); + + share_group_ = new gfx::GLShareGroup; + command_buffer_.reset(new CommandBufferService); + ASSERT_TRUE(command_buffer_->Initialize()) + << "could not create command buffer service"; + + decoder_.reset(::gpu::gles2::GLES2Decoder::Create( + new gles2::ContextGroup(false))); + + gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), + decoder_.get(), + decoder_.get())); + + decoder_->set_engine(gpu_scheduler_.get()); + + surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); + ASSERT_TRUE(surface_.get() != NULL) << "could not create offscreen surface"; + + context_ = gfx::GLContext::CreateGLContext(share_group_.get(), + surface_.get(), + gpu_preference); + ASSERT_TRUE(context_.get() != NULL) << "could not create GL context"; + + ASSERT_TRUE(decoder_->Initialize( + surface_.get(), + context_.get(), + size, + ::gpu::gles2::DisallowedFeatures(), + allowed_extensions, + attribs)) << "could not initialize decoder"; + + command_buffer_->SetPutOffsetChangeCallback( + base::Bind(&GLManager::PumpCommands, base::Unretained(this))); + command_buffer_->SetGetBufferChangeCallback( + base::Bind(&GLManager::GetBufferChanged, base::Unretained(this))); + + // Create the GLES2 helper, which writes the command buffer protocol. + gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); + ASSERT_TRUE(gles2_helper_->Initialize(kCommandBufferSize)); + + // Create a transfer buffer. + transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); + + // Create the object exposing the OpenGL API. + gles2_implementation_.reset(new gles2::GLES2Implementation( + gles2_helper_.get(), + NULL, + transfer_buffer_.get(), + true, + false)); + + ASSERT_TRUE(gles2_implementation_->Initialize( + kStartTransferBufferSize, + kMinTransferBufferSize, + kMaxTransferBufferSize)) << "Could not init GLES2Implementation"; + + MakeCurrent(); +} + +void GLManager::MakeCurrent() { + ::gles2::SetGLContext(gles2_implementation_.get()); +} + +void GLManager::Destroy() { + if (gles2_implementation_.get()) { + gles2_implementation_->Flush(); + gles2_implementation_.reset(); + } + transfer_buffer_.reset(); + gles2_helper_.reset(); + command_buffer_.reset(); + if (decoder_.get()) { + decoder_->Destroy(); + } +} + +void GLManager::PumpCommands() { + decoder_->MakeCurrent(); + gpu_scheduler_->PutChanged(); + ::gpu::CommandBuffer::State state = command_buffer_->GetState(); + ASSERT_EQ(::gpu::error::kNoError, state.error); +} + +bool GLManager::GetBufferChanged(int32 transfer_buffer_id) { + return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); +} + +} // namespace gpu + diff --git a/gpu/command_buffer/tests/gl_manager.h b/gpu/command_buffer/tests/gl_manager.h new file mode 100644 index 0000000..cacf47a --- /dev/null +++ b/gpu/command_buffer/tests/gl_manager.h @@ -0,0 +1,61 @@ +// Copyright (c) 2012 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. + +#ifndef GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_ +#define GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_ + +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "ui/gfx/size.h" + +namespace gfx { + +class GLContext; +class GLShareGroup; +class GLSurface; + +} + +namespace gpu { + +class CommandBufferService; +class TransferBuffer; +class GpuScheduler; + +namespace gles2 { + +class GLES2Decoder; +class GLES2CmdHelper; +class GLES2Implementation; + +}; + +class GLManager { + public: + GLManager(); + ~GLManager(); + + void Initialize(const gfx::Size& size); + void Destroy(); + + void MakeCurrent(); + + private: + void PumpCommands(); + bool GetBufferChanged(int32 transfer_buffer_id); + + scoped_refptr<gfx::GLShareGroup> share_group_; + scoped_ptr<CommandBufferService> command_buffer_; + scoped_ptr<gles2::GLES2Decoder> decoder_; + scoped_ptr<GpuScheduler> gpu_scheduler_; + scoped_refptr<gfx::GLSurface> surface_; + scoped_refptr<gfx::GLContext> context_; + scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; + scoped_ptr<TransferBuffer> transfer_buffer_; + scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; +}; + +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_ diff --git a/gpu/command_buffer/tests/gl_tests_main.cc b/gpu/command_buffer/tests/gl_tests_main.cc new file mode 100644 index 0000000..60b2e7a --- /dev/null +++ b/gpu/command_buffer/tests/gl_tests_main.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2012 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/at_exit.h" +#include "base/command_line.h" +#include "base/message_loop.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/gl/gl_surface.h" + +#if defined(TOOLKIT_GTK) +#include "ui/gfx/gtk_util.h" +#endif + +int main(int argc, char** argv) { + base::AtExitManager exit_manager; + CommandLine::Init(argc, argv); +#if defined(TOOLKIT_GTK) + gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); +#endif + gfx::GLSurface::InitializeOneOff(); + MessageLoop::Type message_loop_type = MessageLoop::TYPE_UI; + MessageLoop main_message_loop(message_loop_type); + testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} + + diff --git a/gpu/command_buffer/tests/gl_unittests.cc b/gpu/command_buffer/tests/gl_unittests.cc new file mode 100644 index 0000000..1a45349 --- /dev/null +++ b/gpu/command_buffer/tests/gl_unittests.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2012 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 <GLES2/gl2.h> + +#include "gpu/command_buffer/tests/gl_manager.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace gpu { + +class GLTest : public testing::Test { + protected: + virtual void SetUp() { + gl_.Initialize(gfx::Size(4, 4)); + } + + virtual void TearDown() { + gl_.Destroy(); + } + + GLManager gl_; +}; + +// Test that GL is at least minimally working. +TEST_F(GLTest, Basic) { + glClearColor(0.0f, 1.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + uint8 pixels[4] = { 0, }; + glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + EXPECT_EQ(0u, pixels[0]); + EXPECT_EQ(255u, pixels[1]); + EXPECT_EQ(0u, pixels[2]); + EXPECT_EQ(255u, pixels[3]); +} + +} // namespace gpu + diff --git a/gpu/gpu_common.gypi b/gpu/gpu_common.gypi index 104b29d..43646c8 100644 --- a/gpu/gpu_common.gypi +++ b/gpu/gpu_common.gypi @@ -196,6 +196,37 @@ ], }, { + 'target_name': 'gl_tests', + 'type': 'executable', + 'dependencies': [ + '../base/base.gyp:base', + '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', + '../testing/gmock.gyp:gmock', + '../testing/gtest.gyp:gtest', + '../third_party/angle/src/build_angle.gyp:translator_glsl', + '../ui/gfx/gl/gl.gyp:gl', + '../ui/ui.gyp:ui', + 'command_buffer/command_buffer.gyp:gles2_utils', + 'command_buffer_client', + 'command_buffer_common', + 'command_buffer_service', + 'gpu', + 'gpu_unittest_utils', + 'gles2_implementation_client_side_arrays', + 'gles2_cmd_helper', + ], + 'defines': [ + 'GLES2_C_LIB_IMPLEMENTATION', + ], + 'sources': [ + '<@(gles2_c_lib_source_files)', + 'command_buffer/tests/gl_tests_main.cc', + 'command_buffer/tests/gl_manager.cc', + 'command_buffer/tests/gl_manager.h', + 'command_buffer/tests/gl_unittests.cc', + ], + }, + { 'target_name': 'gpu_unittest_utils', 'type': 'static_library', 'dependencies': [ |