Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Unified Diff: gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc

Issue 14456004: GPU client side changes for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Delete and add gl_image_mock again Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5b5f156572b6cf3aa650101aef4464a751e44922
--- /dev/null
+++ b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc
@@ -0,0 +1,137 @@
+// 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/gles2_implementation.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/client/image_factory_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 {
+namespace gles2 {
+
+static const int kImageWidth = 256;
+static const int kImageHeight = 256;
+static const int kImageBytesPerPixel = 4;
+
+class GLGpuMemoryBufferTest : public testing::Test {
no sievers 2013/05/14 21:10:03 nit: MockMemoryBufferTest
kaanb 2013/05/14 23:37:09 Done.
+ protected:
+ virtual void SetUp() {
+ GLManager::Options options;
+ image_manager_ = new ImageManager;
+ image_factory_.reset(
+ new StrictMock<ImageFactoryMock>(image_manager_));
+ options.image_manager = image_manager_;
+ options.image_factory = image_factory_.get();
+
+ gl_.Initialize(options);
+ gl_.MakeCurrent();
+ }
+
+ virtual void TearDown() {
+ gl_.Destroy();
+ }
+
+ scoped_ptr<StrictMock<ImageFactoryMock> > image_factory_;
+ scoped_refptr<ImageManager> image_manager_;
+ 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);
+
+ // Buffer is owned and freed by GpuMemoryBufferTracker.
+ StrictMock<GpuMemoryBufferMock>* gpu_memory_buffer =
+ new StrictMock<GpuMemoryBufferMock>(kImageWidth, kImageHeight);
+
+ EXPECT_CALL(*image_factory_.get(), CreateGpuMemoryBufferMock(
+ kImageWidth, kImageHeight, GL_RGBA8_OES, _))
+ .Times(1)
+ .WillOnce(DoAll(SetArgPointee<3>(345u),
no sievers 2013/05/14 21:10:03 nit: make a constant (i.e. 'const GLuint kImageId
kaanb 2013/05/14 23:37:09 Done.
+ Return(gpu_memory_buffer)))
+ .RetiresOnSaturation();
+
+ // Create the GLImage and insert it into the ImageManager, which
+ // would be done within CreateGpuMemoryBufferMock if it weren't a mock.
+ GLuint image_id = glCreateImageCHROMIUM(
+ kImageWidth, kImageHeight, GL_RGBA8_OES);
+ gfx::Size size(kImageWidth, kImageHeight);
+
+ scoped_refptr<gfx::GLImageMock> gl_image(
+ new gfx::GLImageMock(gpu_memory_buffer, size));
+ image_manager_->AddImage(gl_image.get(), image_id);
no sievers 2013/05/14 21:10:03 nit: AddImage() could be another action set up in
kaanb 2013/05/14 23:37:09 So, do you want me to mock the ImageManager?
+
+ EXPECT_CALL(*gpu_memory_buffer, IsMapped())
+ .WillOnce(Return(false)) // before Map()
no sievers 2013/05/14 21:10:03 nit: If you split up and set the expectations sepa
kaanb 2013/05/14 23:37:09 Done.
+ .WillOnce(Return(true)) // after Map() and before Unmap()
+ .RetiresOnSaturation();
+
+ scoped_ptr<uint8[]> buffer_pixels(new uint8[
+ kImageWidth * kImageHeight * kImageBytesPerPixel]);
+
+ EXPECT_CALL(*gpu_memory_buffer, Map(_, _))
+ .Times(1)
+ .WillOnce(SetArgPointee<1>(buffer_pixels.get()))
+ .RetiresOnSaturation();
+ void* mapped_buffer =
+ glMapImageCHROMIUM(image_id, GL_WRITE_ONLY);
+ EXPECT_EQ(buffer_pixels.get(), mapped_buffer);
+
+ // Unmap the image.
+ EXPECT_CALL(*gpu_memory_buffer, Unmap())
+ .Times(1)
+ .RetiresOnSaturation();
+ glUnmapImageCHROMIUM(image_id);
+
+ // 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, image_id);
+
+ // Destroy the image.
+ EXPECT_CALL(*gpu_memory_buffer, Die())
+ .Times(1)
+ .RetiresOnSaturation();
+
+ EXPECT_CALL(*image_factory_.get(), DeleteGpuMemoryBuffer(image_id))
+ .Times(1)
+ .RetiresOnSaturation();
+
+ glDestroyImageCHROMIUM(image_id);
+
+ // Delete the texture.
+ glDeleteTextures(1, &texture_id);
+}
+
+} // namespace gles2
+} // namespace gpu

Powered by Google App Engine
This is Rietveld 408576698