| Index: gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc
|
| diff --git a/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3c766b2ebdb7322073b4219301efd196fec46077
|
| --- /dev/null
|
| +++ b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc
|
| @@ -0,0 +1,136 @@
|
| +// Copyright (c) 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 <GLES2/gl2.h>
|
| +#include <GLES2/gl2chromium.h>
|
| +#include <GLES2/gl2ext.h>
|
| +#include <GLES2/gl2extchromium.h>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "gpu/command_buffer/client/gpu_memory_buffer_factory.h"
|
| +#include "gpu/command_buffer/client/gpu_memory_buffer_mock.h"
|
| +#include "gpu/command_buffer/service/image_manager.h"
|
| +#include "gpu/command_buffer/tests/gl_manager.h"
|
| +#include "gpu/command_buffer/tests/gl_test_utils.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/gfx/native_widget_types.h"
|
| +#include "ui/gl/gl_image.h"
|
| +#include "ui/gl/gl_image_mock.h"
|
| +
|
| +using testing::_;
|
| +using testing::Return;
|
| +using testing::SetArgPointee;
|
| +using testing::StrictMock;
|
| +
|
| +namespace gpu {
|
| +
|
| +static const int kGpuMemoryBufferWidth = 256;
|
| +static const int kGpuMemoryBufferHeight = 256;
|
| +static const int kGpuMemoryBufferBytesPerPixel = 4;
|
| +
|
| +class GLGpuMemoryBufferTest : public testing::Test {
|
| + public:
|
| + scoped_ptr<GpuMemoryBuffer> CreateGpuMemoryBufferMock(int width, int height) {
|
| + scoped_ptr<StrictMock<GpuMemoryBufferMock> > gpu_memory_buffer(
|
| + new StrictMock<GpuMemoryBufferMock>(width, height));
|
| + gpu_memory_buffer_ = gpu_memory_buffer.get();
|
| + return gpu_memory_buffer.PassAs<GpuMemoryBuffer>();
|
| + }
|
| + protected:
|
| + virtual void SetUp() {
|
| + GLManager::Options options;
|
| + image_manager_ = new gles2::ImageManager;
|
| + options.image_manager = image_manager_.get();
|
| + gl_.Initialize(options);
|
| + gl_.MakeCurrent();
|
| + mapped_buffer_.reset(new uint8[
|
| + kGpuMemoryBufferWidth * kGpuMemoryBufferHeight
|
| + * kGpuMemoryBufferBytesPerPixel]);
|
| + gpu::gles2::SetProcessDefaultGpuMemoryBufferFactory(
|
| + base::Bind(&gpu::GLGpuMemoryBufferTest::CreateGpuMemoryBufferMock,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + virtual void TearDown() {
|
| + gl_.Destroy();
|
| + }
|
| +
|
| + scoped_refptr<gles2::ImageManager> image_manager_;
|
| + scoped_ptr<uint8[]> mapped_buffer_;
|
| + StrictMock<GpuMemoryBufferMock>* gpu_memory_buffer_;
|
| + GLManager gl_;
|
| +};
|
| +
|
| +// An end to end test that tests the whole GpuMemoryBuffer lifecycle.
|
| +TEST_F(GLGpuMemoryBufferTest, Lifecycle) {
|
| + // Create a client texture id.
|
| + GLuint texture_id;
|
| + glGenTextures(1, &texture_id);
|
| +
|
| + // Create the GLImage and insert it into the ImageManager.
|
| + EXPECT_CALL(*gpu_memory_buffer_, GetNativeBuffer())
|
| + .Times(1)
|
| + .WillOnce(Return(gpu_memory_buffer_))
|
| + .RetiresOnSaturation();
|
| + GLuint image_id =
|
| + glCreateImageCHROMIUM(kGpuMemoryBufferWidth, kGpuMemoryBufferHeight);
|
| +
|
| + // gfx::Size size(kGpuMemoryBufferWidth, kGpuMemoryBufferHeight);
|
| + // // gfx::GLImageMock* gl_image = new gfx::GLImageMock(buffer, size);
|
| + // // image_manager_->AddImage(gl_image, buffer_id);
|
| + // glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, 0);
|
| +
|
| + // // Map the buffer.
|
| + // glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, buffer_id);
|
| + // EXPECT_CALL(*gpu_memory_buffer_, Map(_, _))
|
| + // .Times(1)
|
| + // .WillOnce(SetArgPointee<1>(mapped_buffer_.get()))
|
| + // .RetiresOnSaturation();
|
| + // void* mapped_buffer =
|
| + // glMapBufferCHROMIUM(GL_IMAGE_BUFFER_CHROMIUM, GL_WRITE_ONLY);
|
| + // EXPECT_EQ(mapped_buffer_.get(), mapped_buffer);
|
| + // glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, 0);
|
| +
|
| + // // Unmap the buffer.
|
| + // glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, buffer_id);
|
| + // EXPECT_CALL(*gpu_memory_buffer_, Unmap())
|
| + // .Times(1)
|
| + // .RetiresOnSaturation();
|
| + // glUnmapBufferCHROMIUM(GL_IMAGE_BUFFER_CHROMIUM);
|
| + // glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, 0);
|
| +
|
| +
|
| + // // Bind the texture and the image.
|
| + // // glBindTexture(GL_TEXTURE_2D, texture_id);
|
| + // // EXPECT_CALL(*gl_image, BindTexImage())
|
| + // // .Times(1)
|
| + // // .WillOnce(Return(true))
|
| + // // .RetiresOnSaturation();
|
| + // // EXPECT_CALL(*gl_image, GetSize())
|
| + // // .Times(1)
|
| + // // .WillOnce(Return(size))
|
| + // // .RetiresOnSaturation();
|
| + // glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, buffer_id);
|
| +
|
| + // // Release the buffer.
|
| + // EXPECT_CALL(*gpu_memory_buffer_, Die())
|
| + // .Times(1)
|
| + // .RetiresOnSaturation();
|
| + // glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, buffer_id);
|
| + // // glImageBufferDataCHROMIUM(
|
| + // // GL_IMAGE_BUFFER_CHROMIUM, 0, 0);
|
| + // glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, 0);
|
| +
|
| + // // Delete the buffer and remove it from the ImageManager.
|
| + // glFlush();
|
| + // image_manager_->RemoveImage(buffer_id);
|
| + // glDeleteBuffers(1, &buffer_id);
|
| +
|
| + // Delete the texture.
|
| + glDeleteTextures(1, &texture_id);
|
| +}
|
| +
|
| +} // namespace gpu
|
|
|