OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <GLES2/gl2.h> | |
6 #include <GLES2/gl2chromium.h> | |
7 #include <GLES2/gl2ext.h> | |
8 #include <GLES2/gl2extchromium.h> | |
9 | |
10 #include "base/bind.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" | |
13 #include "gpu/command_buffer/client/gpu_memory_buffer_mock.h" | |
14 #include "gpu/command_buffer/service/image_manager.h" | |
15 #include "gpu/command_buffer/tests/gl_manager.h" | |
16 #include "gpu/command_buffer/tests/gl_test_utils.h" | |
17 #include "testing/gmock/include/gmock/gmock.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 #include "ui/gfx/native_widget_types.h" | |
20 #include "ui/gl/gl_image.h" | |
21 #include "ui/gl/gl_image_mock.h" | |
22 | |
23 using testing::_; | |
24 using testing::Return; | |
25 using testing::SetArgPointee; | |
26 using testing::StrictMock; | |
27 | |
28 namespace gpu { | |
29 | |
30 static const int kGpuMemoryBufferWidth = 256; | |
31 static const int kGpuMemoryBufferHeight = 256; | |
32 static const int kGpuMemoryBufferBytesPerPixel = 4; | |
33 | |
34 class GLGpuMemoryBufferTest : public testing::Test { | |
greggman
2013/04/25 23:45:34
I'm conflicted on these tests. The test in gpu/com
no sievers
2013/04/26 00:17:43
Here is the dilemna: We can't run the real test up
| |
35 public: | |
36 scoped_ptr<GpuMemoryBuffer> CreateGpuMemoryBufferMock(int width, int height) { | |
37 scoped_ptr<StrictMock<GpuMemoryBufferMock> > gpu_memory_buffer( | |
38 new StrictMock<GpuMemoryBufferMock>(width, height)); | |
39 gpu_memory_buffer_ = gpu_memory_buffer.get(); | |
40 return gpu_memory_buffer.PassAs<GpuMemoryBuffer>(); | |
41 } | |
42 protected: | |
43 virtual void SetUp() { | |
44 GLManager::Options options; | |
45 image_manager_ = new gles2::ImageManager; | |
46 options.image_manager = image_manager_.get(); | |
47 gl_.Initialize(options); | |
48 gl_.MakeCurrent(); | |
49 mapped_buffer_.reset(new uint8[ | |
50 kGpuMemoryBufferWidth * kGpuMemoryBufferHeight | |
51 * kGpuMemoryBufferBytesPerPixel]); | |
52 SetProcessDefaultGpuMemoryBufferFactory( | |
53 base::Bind(&gpu::GLGpuMemoryBufferTest::CreateGpuMemoryBufferMock, | |
54 base::Unretained(this))); | |
55 } | |
56 | |
57 virtual void TearDown() { | |
58 gl_.Destroy(); | |
59 } | |
60 | |
61 scoped_refptr<gles2::ImageManager> image_manager_; | |
62 scoped_ptr<uint8[]> mapped_buffer_; | |
63 StrictMock<GpuMemoryBufferMock>* gpu_memory_buffer_; | |
64 GLManager gl_; | |
65 }; | |
66 | |
67 // An end to end test that tests the whole GpuMemoryBuffer lifecycle. | |
68 TEST_F(GLGpuMemoryBufferTest, Lifecycle) { | |
reveman
2013/04/26 02:47:57
The code below doesn't look right to me. The glGet
kaanb1
2013/04/26 03:01:21
Do we have access to ImageManager from GLES2Implem
| |
69 // Create a client texture id. | |
70 GLuint texture_id; | |
71 glGenTextures(1, &texture_id); | |
72 | |
73 // Create a client buffer id. | |
74 GLuint buffer_id; | |
75 glGenBuffers(1, &buffer_id); | |
76 | |
77 // Allocate the GpuMemoryBuffer. | |
78 glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, buffer_id); | |
79 glImageBufferDataCHROMIUM( | |
80 GL_IMAGE_BUFFER_CHROMIUM, kGpuMemoryBufferWidth, kGpuMemoryBufferHeight); | |
81 // Create the GLImage and insert it into the ImageManager. | |
82 glFlush(); | |
83 EXPECT_CALL(*gpu_memory_buffer_, GetNativeBuffer()) | |
84 .Times(1) | |
85 .WillOnce(Return(gpu_memory_buffer_)) | |
86 .RetiresOnSaturation(); | |
87 gfx::GpuMemoryBufferHandle buffer = | |
88 const_cast<GLubyte*>( | |
89 glGetString(GL_BOUND_GPU_MEMORY_BUFFER_CHROMIUM_POINTER)); | |
90 EXPECT_NE(static_cast<gfx::GpuMemoryBufferHandle>(NULL), buffer); | |
91 | |
92 gfx::Size size(kGpuMemoryBufferWidth, kGpuMemoryBufferHeight); | |
93 gfx::GLImageMock* gl_image = new gfx::GLImageMock(buffer, size); | |
94 image_manager_->AddImage(gl_image, buffer_id); | |
95 glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, 0); | |
96 | |
97 // Map the buffer. | |
98 glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, buffer_id); | |
99 EXPECT_CALL(*gpu_memory_buffer_, Map(_, _)) | |
100 .Times(1) | |
101 .WillOnce(SetArgPointee<1>(mapped_buffer_.get())) | |
102 .RetiresOnSaturation(); | |
103 void* mapped_buffer = | |
104 glMapBufferCHROMIUM(GL_IMAGE_BUFFER_CHROMIUM, GL_WRITE_ONLY); | |
105 EXPECT_EQ(mapped_buffer_.get(), mapped_buffer); | |
106 glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, 0); | |
107 | |
108 // Unmap the buffer. | |
109 glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, buffer_id); | |
110 EXPECT_CALL(*gpu_memory_buffer_, Unmap()) | |
111 .Times(1) | |
112 .RetiresOnSaturation(); | |
113 glUnmapBufferCHROMIUM(GL_IMAGE_BUFFER_CHROMIUM); | |
114 glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, 0); | |
115 | |
116 | |
117 // Bind the texture and the image. | |
118 glBindTexture(GL_TEXTURE_2D, texture_id); | |
119 EXPECT_CALL(*gl_image, BindTexImage()) | |
120 .Times(1) | |
121 .WillOnce(Return(true)) | |
122 .RetiresOnSaturation(); | |
123 EXPECT_CALL(*gl_image, GetSize()) | |
124 .Times(1) | |
125 .WillOnce(Return(size)) | |
126 .RetiresOnSaturation(); | |
127 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, buffer_id); | |
128 | |
129 // Release the buffer. | |
130 EXPECT_CALL(*gpu_memory_buffer_, Die()) | |
131 .Times(1) | |
132 .RetiresOnSaturation(); | |
133 glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, buffer_id); | |
134 glImageBufferDataCHROMIUM( | |
135 GL_IMAGE_BUFFER_CHROMIUM, 0, 0); | |
136 glBindBuffer(GL_IMAGE_BUFFER_CHROMIUM, 0); | |
137 | |
138 // Delete the buffer and remove it from the ImageManager. | |
139 glFlush(); | |
140 image_manager_->RemoveImage(buffer_id); | |
141 glDeleteBuffers(1, &buffer_id); | |
142 | |
143 // Delete the texture. | |
144 glDeleteTextures(1, &texture_id); | |
145 } | |
146 | |
147 } // namespace gpu | |
OLD | NEW |