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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 .Times(1) | 131 .Times(1) |
132 .WillOnce(Return(gpu_memory_buffer)) | 132 .WillOnce(Return(gpu_memory_buffer)) |
133 .RetiresOnSaturation(); | 133 .RetiresOnSaturation(); |
134 EXPECT_CALL(*gpu_memory_buffer, GetHandle()) | 134 EXPECT_CALL(*gpu_memory_buffer, GetHandle()) |
135 .Times(1) | 135 .Times(1) |
136 .WillOnce(Return(handle)) | 136 .WillOnce(Return(handle)) |
137 .RetiresOnSaturation(); | 137 .RetiresOnSaturation(); |
138 | 138 |
139 // Create the image. This should add the image ID to the ImageManager. | 139 // Create the image. This should add the image ID to the ImageManager. |
140 GLuint image_id = glCreateImageCHROMIUM( | 140 GLuint image_id = glCreateImageCHROMIUM( |
141 kImageWidth, kImageHeight, GL_RGBA8_OES); | 141 kImageWidth, kImageHeight, GL_RGBA8_OES, GL_READ_WRITE); |
142 EXPECT_NE(0u, image_id); | 142 EXPECT_NE(0u, image_id); |
143 EXPECT_TRUE(image_manager_->LookupImage(image_id) != NULL); | 143 EXPECT_TRUE(image_manager_->LookupImage(image_id) != NULL); |
144 | 144 |
145 EXPECT_CALL(*gpu_memory_buffer, IsMapped()) | 145 EXPECT_CALL(*gpu_memory_buffer, IsMapped()) |
146 .WillOnce(Return(false)) | 146 .WillOnce(Return(false)) |
147 .RetiresOnSaturation(); | 147 .RetiresOnSaturation(); |
148 | 148 |
149 shared_memory.Map(bytes); | 149 shared_memory.Map(bytes); |
150 EXPECT_TRUE(shared_memory.memory()); | 150 EXPECT_TRUE(shared_memory.memory()); |
151 | 151 |
152 EXPECT_CALL(*gpu_memory_buffer, Map(gfx::GpuMemoryBuffer::READ_WRITE)) | 152 EXPECT_CALL(*gpu_memory_buffer, Map(gfx::GpuMemoryBuffer::READ_WRITE)) |
153 .Times(1) | 153 .Times(1) |
154 .WillOnce(Return(shared_memory.memory())) | 154 .WillOnce(Return(shared_memory.memory())) |
155 .RetiresOnSaturation(); | 155 .RetiresOnSaturation(); |
156 uint8* mapped_buffer = static_cast<uint8*>( | 156 uint8* mapped_buffer = static_cast<uint8*>(glMapImageCHROMIUM(image_id)); |
157 glMapImageCHROMIUM(image_id, GL_READ_WRITE)); | |
158 ASSERT_TRUE(mapped_buffer != NULL); | 157 ASSERT_TRUE(mapped_buffer != NULL); |
159 | 158 |
160 // Assign a value to each pixel. | 159 // Assign a value to each pixel. |
161 int stride = kImageWidth * kImageBytesPerPixel; | 160 int stride = kImageWidth * kImageBytesPerPixel; |
162 for (int x = 0; x < kImageWidth; ++x) { | 161 for (int x = 0; x < kImageWidth; ++x) { |
163 for (int y = 0; y < kImageHeight; ++y) { | 162 for (int y = 0; y < kImageHeight; ++y) { |
164 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0]; | 163 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0]; |
165 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1]; | 164 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1]; |
166 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2]; | 165 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2]; |
167 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3]; | 166 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3]; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 199 |
201 // Destroy the image. | 200 // Destroy the image. |
202 EXPECT_CALL(*gpu_memory_buffer, Die()) | 201 EXPECT_CALL(*gpu_memory_buffer, Die()) |
203 .Times(1) | 202 .Times(1) |
204 .RetiresOnSaturation(); | 203 .RetiresOnSaturation(); |
205 glDestroyImageCHROMIUM(image_id); | 204 glDestroyImageCHROMIUM(image_id); |
206 } | 205 } |
207 | 206 |
208 } // namespace gles2 | 207 } // namespace gles2 |
209 } // namespace gpu | 208 } // namespace gpu |
OLD | NEW |