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" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "gpu/command_buffer/client/gles2_implementation.h" | 13 #include "gpu/command_buffer/client/gles2_implementation.h" |
14 #include "gpu/command_buffer/service/command_buffer_service.h" | 14 #include "gpu/command_buffer/service/command_buffer_service.h" |
15 #include "gpu/command_buffer/service/image_manager.h" | 15 #include "gpu/command_buffer/service/image_manager.h" |
16 #include "gpu/command_buffer/tests/gl_manager.h" | 16 #include "gpu/command_buffer/tests/gl_manager.h" |
17 #include "gpu/command_buffer/tests/gl_test_utils.h" | 17 #include "gpu/command_buffer/tests/gl_test_utils.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/gfx/gpu_memory_buffer.h" |
20 #include "ui/gl/gl_image.h" | 21 #include "ui/gl/gl_image.h" |
21 | 22 |
22 using testing::_; | 23 using testing::_; |
23 using testing::IgnoreResult; | 24 using testing::IgnoreResult; |
24 using testing::InvokeWithoutArgs; | 25 using testing::InvokeWithoutArgs; |
25 using testing::Invoke; | 26 using testing::Invoke; |
26 using testing::Return; | 27 using testing::Return; |
27 using testing::SetArgPointee; | 28 using testing::SetArgPointee; |
28 using testing::StrictMock; | 29 using testing::StrictMock; |
29 | 30 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 67 |
67 GLManager gl_; | 68 GLManager gl_; |
68 GLuint texture_ids_[2]; | 69 GLuint texture_ids_[2]; |
69 GLuint framebuffer_id_; | 70 GLuint framebuffer_id_; |
70 }; | 71 }; |
71 | 72 |
72 // An end to end test that tests the whole GpuMemoryBuffer lifecycle. | 73 // An end to end test that tests the whole GpuMemoryBuffer lifecycle. |
73 TEST_F(GpuMemoryBufferTest, Lifecycle) { | 74 TEST_F(GpuMemoryBufferTest, Lifecycle) { |
74 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; | 75 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; |
75 | 76 |
76 // Create the image. This should add the image ID to the ImageManager. | 77 scoped_ptr<gfx::GpuMemoryBuffer> buffer(gl_.CreateGpuMemoryBuffer( |
77 GLuint image_id = glCreateImageCHROMIUM( | 78 gfx::Size(kImageWidth, kImageHeight), gfx::GpuMemoryBuffer::RGBA_8888)); |
78 kImageWidth, kImageHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM); | |
79 EXPECT_NE(0u, image_id); | |
80 EXPECT_TRUE(gl_.decoder()->GetImageManager()->LookupImage(image_id) != NULL); | |
81 | 79 |
82 // Map image for writing. | 80 // Map buffer for writing. |
83 uint8* mapped_buffer = static_cast<uint8*>(glMapImageCHROMIUM(image_id)); | 81 uint8* mapped_buffer = static_cast<uint8*>(buffer->Map()); |
84 ASSERT_TRUE(mapped_buffer != NULL); | 82 ASSERT_TRUE(mapped_buffer != NULL); |
85 | 83 |
86 // Assign a value to each pixel. | 84 // Assign a value to each pixel. |
87 int stride = kImageWidth * kImageBytesPerPixel; | 85 int stride = kImageWidth * kImageBytesPerPixel; |
88 for (int x = 0; x < kImageWidth; ++x) { | 86 for (int x = 0; x < kImageWidth; ++x) { |
89 for (int y = 0; y < kImageHeight; ++y) { | 87 for (int y = 0; y < kImageHeight; ++y) { |
90 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0]; | 88 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0]; |
91 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1]; | 89 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1]; |
92 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2]; | 90 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2]; |
93 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3]; | 91 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3]; |
94 } | 92 } |
95 } | 93 } |
96 | 94 |
97 // Unmap the image. | 95 // Unmap the buffer. |
98 glUnmapImageCHROMIUM(image_id); | 96 buffer->Unmap(); |
| 97 |
| 98 // Create the image. This should add the image ID to the ImageManager. |
| 99 GLuint image_id = glCreateImageCHROMIUM( |
| 100 buffer->AsClientBuffer(), kImageWidth, kImageHeight, GL_RGBA); |
| 101 EXPECT_NE(0u, image_id); |
| 102 EXPECT_TRUE(gl_.decoder()->GetImageManager()->LookupImage(image_id) != NULL); |
99 | 103 |
100 // Bind the texture and the image. | 104 // Bind the texture and the image. |
101 glBindTexture(GL_TEXTURE_2D, texture_ids_[0]); | 105 glBindTexture(GL_TEXTURE_2D, texture_ids_[0]); |
102 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); | 106 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); |
103 | 107 |
104 // Copy texture so we can verify result using CheckPixels. | 108 // Copy texture so we can verify result using CheckPixels. |
105 glCopyTextureCHROMIUM(GL_TEXTURE_2D, | 109 glCopyTextureCHROMIUM(GL_TEXTURE_2D, |
106 texture_ids_[0], | 110 texture_ids_[0], |
107 texture_ids_[1], | 111 texture_ids_[1], |
108 0, | 112 0, |
109 GL_RGBA, | 113 GL_RGBA, |
110 GL_UNSIGNED_BYTE); | 114 GL_UNSIGNED_BYTE); |
111 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 115 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
112 | 116 |
113 // Check if pixels match the values that were assigned to the mapped buffer. | 117 // Check if pixels match the values that were assigned to the mapped buffer. |
114 GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0, pixels); | 118 GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0, pixels); |
115 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 119 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
116 | 120 |
117 // Release the image. | 121 // Release the image. |
118 glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); | 122 glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); |
119 | 123 |
120 // Destroy the image. | 124 // Destroy the image. |
121 glDestroyImageCHROMIUM(image_id); | 125 glDestroyImageCHROMIUM(image_id); |
122 } | 126 } |
123 | 127 |
124 } // namespace gles2 | 128 } // namespace gles2 |
125 } // namespace gpu | 129 } // namespace gpu |
OLD | NEW |