OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
6 #include <GLES2/gl2chromium.h> | 6 #include <GLES2/gl2chromium.h> |
7 #include <GLES2/gl2ext.h> | 7 #include <GLES2/gl2ext.h> |
8 #include <GLES2/gl2extchromium.h> | 8 #include <GLES2/gl2extchromium.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 using testing::Invoke; | 26 using testing::Invoke; |
27 using testing::Return; | 27 using testing::Return; |
28 using testing::SetArgPointee; | 28 using testing::SetArgPointee; |
29 using testing::StrictMock; | 29 using testing::StrictMock; |
30 | 30 |
31 namespace gpu { | 31 namespace gpu { |
32 namespace gles2 { | 32 namespace gles2 { |
33 | 33 |
34 static const int kImageWidth = 32; | 34 static const int kImageWidth = 32; |
35 static const int kImageHeight = 32; | 35 static const int kImageHeight = 32; |
36 static const int kImageBytesPerPixel = 4; | |
37 | 36 |
38 class GpuMemoryBufferTest : public testing::Test { | 37 class GpuMemoryBufferTest |
38 : public testing::TestWithParam<gfx::GpuMemoryBuffer::Format> { | |
39 protected: | 39 protected: |
40 void SetUp() override { | 40 void SetUp() override { |
41 gl_.Initialize(GLManager::Options()); | 41 gl_.Initialize(GLManager::Options()); |
42 gl_.MakeCurrent(); | 42 gl_.MakeCurrent(); |
43 | 43 |
44 glGenTextures(2, texture_ids_); | 44 glGenTextures(2, texture_ids_); |
45 glBindTexture(GL_TEXTURE_2D, texture_ids_[1]); | 45 glBindTexture(GL_TEXTURE_2D, texture_ids_[1]); |
46 | 46 |
47 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 47 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
48 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 48 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
(...skipping 15 matching lines...) Expand all Loading... | |
64 | 64 |
65 gl_.Destroy(); | 65 gl_.Destroy(); |
66 } | 66 } |
67 | 67 |
68 GLManager gl_; | 68 GLManager gl_; |
69 GLuint texture_ids_[2]; | 69 GLuint texture_ids_[2]; |
70 GLuint framebuffer_id_; | 70 GLuint framebuffer_id_; |
71 }; | 71 }; |
72 | 72 |
73 // An end to end test that tests the whole GpuMemoryBuffer lifecycle. | 73 // An end to end test that tests the whole GpuMemoryBuffer lifecycle. |
74 TEST_F(GpuMemoryBufferTest, Lifecycle) { | 74 TEST_P(GpuMemoryBufferTest, Lifecycle) { |
75 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; | 75 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; |
76 | 76 |
77 scoped_ptr<gfx::GpuMemoryBuffer> buffer(gl_.CreateGpuMemoryBuffer( | 77 scoped_ptr<gfx::GpuMemoryBuffer> buffer(gl_.CreateGpuMemoryBuffer( |
78 gfx::Size(kImageWidth, kImageHeight), gfx::GpuMemoryBuffer::RGBA_8888)); | 78 gfx::Size(kImageWidth, kImageHeight), GetParam())); |
79 | 79 |
80 // Map buffer for writing. | 80 // Map buffer for writing. |
81 void* data; | 81 void* data; |
82 bool rv = buffer->Map(&data); | 82 bool rv = buffer->Map(&data); |
83 DCHECK(rv); | 83 DCHECK(rv); |
84 | 84 |
85 uint8* mapped_buffer = static_cast<uint8*>(data); | 85 uint8* mapped_buffer = static_cast<uint8*>(data); |
86 ASSERT_TRUE(mapped_buffer != NULL); | 86 ASSERT_TRUE(mapped_buffer != NULL); |
87 | 87 |
88 // Assign a value to each pixel. | 88 // Assign a value to each pixel. |
89 int stride = kImageWidth * kImageBytesPerPixel; | 89 int imageBytesPerPixel = GetParam() == gfx::GpuMemoryBuffer::R_8 ? 1 : 4; |
reveman
2015/04/01 23:38:55
Can you refactor this test a bit so this condition
Daniele Castagna
2015/04/03 01:08:15
Refactored, refer to crrev.com/1055143003.
| |
90 uint32 stride = 0; | |
91 buffer->GetStride(&stride); | |
90 for (int x = 0; x < kImageWidth; ++x) { | 92 for (int x = 0; x < kImageWidth; ++x) { |
91 for (int y = 0; y < kImageHeight; ++y) { | 93 for (int y = 0; y < kImageHeight; ++y) { |
92 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0]; | 94 for (int p = 0; p < imageBytesPerPixel; ++p) { |
93 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1]; | 95 mapped_buffer[y * stride + x * imageBytesPerPixel + p] = pixels[p]; |
94 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2]; | 96 } |
95 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3]; | |
96 } | 97 } |
97 } | 98 } |
98 | 99 |
99 // Unmap the buffer. | 100 // Unmap the buffer. |
100 buffer->Unmap(); | 101 buffer->Unmap(); |
101 | 102 |
103 GLenum internalformat = GL_RGBA; | |
104 if (GetParam() == gfx::GpuMemoryBuffer::R_8) { | |
reveman
2015/04/01 23:38:55
I prefer a switch statement where you explicitly h
Daniele Castagna
2015/04/03 01:08:15
This will change after crrev.com/1055143003
| |
105 internalformat = | |
106 gl_.decoder()->GetCapabilities().texture_rg ? GL_R8 : GL_LUMINANCE; | |
107 } | |
102 // Create the image. This should add the image ID to the ImageManager. | 108 // Create the image. This should add the image ID to the ImageManager. |
103 GLuint image_id = glCreateImageCHROMIUM( | 109 GLuint image_id = glCreateImageCHROMIUM(buffer->AsClientBuffer(), kImageWidth, |
104 buffer->AsClientBuffer(), kImageWidth, kImageHeight, GL_RGBA); | 110 kImageHeight, internalformat); |
105 EXPECT_NE(0u, image_id); | 111 EXPECT_NE(0u, image_id); |
106 EXPECT_TRUE(gl_.decoder()->GetImageManager()->LookupImage(image_id) != NULL); | 112 EXPECT_TRUE(gl_.decoder()->GetImageManager()->LookupImage(image_id) != NULL); |
107 | 113 |
108 // Bind the texture and the image. | 114 // Bind the texture and the image. |
109 glBindTexture(GL_TEXTURE_2D, texture_ids_[0]); | 115 glBindTexture(GL_TEXTURE_2D, texture_ids_[0]); |
110 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); | 116 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); |
111 | 117 |
112 // Copy texture so we can verify result using CheckPixels. | 118 // Copy texture so we can verify result using CheckPixels. |
113 glCopyTextureCHROMIUM(GL_TEXTURE_2D, | 119 glCopyTextureCHROMIUM(GL_TEXTURE_2D, |
114 texture_ids_[0], | 120 texture_ids_[0], |
115 texture_ids_[1], | 121 texture_ids_[1], |
116 GL_RGBA, | 122 GL_RGBA, |
117 GL_UNSIGNED_BYTE); | 123 GL_UNSIGNED_BYTE); |
118 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 124 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
119 | 125 |
120 // Check if pixels match the values that were assigned to the mapped buffer. | 126 // Check if pixels match the values that were assigned to the mapped buffer. |
121 GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0, pixels); | 127 GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0, pixels); |
122 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 128 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
123 | 129 |
124 // Release the image. | 130 // Release the image. |
125 glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); | 131 glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); |
126 | 132 |
127 // Destroy the image. | 133 // Destroy the image. |
128 glDestroyImageCHROMIUM(image_id); | 134 glDestroyImageCHROMIUM(image_id); |
129 } | 135 } |
130 | 136 |
137 static const gfx::GpuMemoryBuffer::Format kMemoryBufferFormats[] = { | |
reveman
2015/04/01 23:38:55
It would be nice to test all formats here and not
Daniele Castagna
2015/04/03 01:08:15
crrev.com/1055143003
| |
138 gfx::GpuMemoryBuffer::RGBA_8888, | |
139 gfx::GpuMemoryBuffer::R_8}; | |
reveman
2015/04/01 23:38:55
nit: use the same order as where the enum is defin
Daniele Castagna
2015/04/03 01:08:15
Refer to crrev.com/1055143003
| |
140 INSTANTIATE_TEST_CASE_P( | |
141 GpuMemoryBufferTests, | |
142 GpuMemoryBufferTest, | |
143 ::testing::ValuesIn(std::vector<gfx::GpuMemoryBuffer::Format>( | |
144 kMemoryBufferFormats, | |
145 kMemoryBufferFormats + arraysize(kMemoryBufferFormats)))); | |
reveman
2015/04/01 23:38:55
How about:
INSTANTIATE_TEST_CASE_P(
GpuMemory
Daniele Castagna
2015/04/03 01:08:15
Much better.
Used it in crrev.com/1055143003
| |
146 | |
131 } // namespace gles2 | 147 } // namespace gles2 |
132 } // namespace gpu | 148 } // namespace gpu |
OLD | NEW |