| 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 24 matching lines...) Expand all Loading... |
| 35 static const int kImageHeight = 32; | 35 static const int kImageHeight = 32; |
| 36 static const int kImageBytesPerPixel = 4; | 36 static const int kImageBytesPerPixel = 4; |
| 37 | 37 |
| 38 class MockGpuMemoryBuffer : public gfx::GpuMemoryBuffer { | 38 class MockGpuMemoryBuffer : public gfx::GpuMemoryBuffer { |
| 39 public: | 39 public: |
| 40 MockGpuMemoryBuffer(int width, int height) {} | 40 MockGpuMemoryBuffer(int width, int height) {} |
| 41 virtual ~MockGpuMemoryBuffer() { | 41 virtual ~MockGpuMemoryBuffer() { |
| 42 Die(); | 42 Die(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 MOCK_METHOD1(Map, void*(gfx::GpuMemoryBuffer::AccessMode)); | 45 MOCK_METHOD0(Map, void*()); |
| 46 MOCK_METHOD0(Unmap, void()); | 46 MOCK_METHOD0(Unmap, void()); |
| 47 MOCK_CONST_METHOD0(IsMapped, bool()); | 47 MOCK_CONST_METHOD0(IsMapped, bool()); |
| 48 MOCK_CONST_METHOD0(GetStride, uint32()); | 48 MOCK_CONST_METHOD0(GetStride, uint32()); |
| 49 MOCK_CONST_METHOD0(GetHandle, gfx::GpuMemoryBufferHandle()); | 49 MOCK_CONST_METHOD0(GetHandle, gfx::GpuMemoryBufferHandle()); |
| 50 MOCK_METHOD0(Die, void()); | 50 MOCK_METHOD0(Die, void()); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 DISALLOW_COPY_AND_ASSIGN(MockGpuMemoryBuffer); | 53 DISALLOW_COPY_AND_ASSIGN(MockGpuMemoryBuffer); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 class MockGpuMemoryBufferFactory : public GpuMemoryBufferFactory { | 56 class MockGpuMemoryBufferFactory : public GpuMemoryBufferFactory { |
| 57 public: | 57 public: |
| 58 MockGpuMemoryBufferFactory() {} | 58 MockGpuMemoryBufferFactory() {} |
| 59 virtual ~MockGpuMemoryBufferFactory() {} | 59 virtual ~MockGpuMemoryBufferFactory() {} |
| 60 | 60 |
| 61 MOCK_METHOD3(CreateGpuMemoryBuffer, | 61 MOCK_METHOD4(CreateGpuMemoryBuffer, |
| 62 gfx::GpuMemoryBuffer*(size_t, size_t, unsigned)); | 62 gfx::GpuMemoryBuffer*(size_t, size_t, unsigned, unsigned)); |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(MockGpuMemoryBufferFactory); | 65 DISALLOW_COPY_AND_ASSIGN(MockGpuMemoryBufferFactory); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class MockGpuMemoryBufferTest : public testing::Test { | 68 class MockGpuMemoryBufferTest : public testing::Test { |
| 69 protected: | 69 protected: |
| 70 virtual void SetUp() { | 70 virtual void SetUp() { |
| 71 GLManager::Options options; | 71 GLManager::Options options; |
| 72 image_manager_ = new ImageManager; | 72 image_manager_ = new ImageManager; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 base::SharedMemory shared_memory; | 119 base::SharedMemory shared_memory; |
| 120 shared_memory.CreateAnonymous(bytes); | 120 shared_memory.CreateAnonymous(bytes); |
| 121 | 121 |
| 122 base::SharedMemoryHandle duped_shared_memory_handle; | 122 base::SharedMemoryHandle duped_shared_memory_handle; |
| 123 shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), | 123 shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), |
| 124 &duped_shared_memory_handle); | 124 &duped_shared_memory_handle); |
| 125 gfx::GpuMemoryBufferHandle handle; | 125 gfx::GpuMemoryBufferHandle handle; |
| 126 handle.type = gfx::SHARED_MEMORY_BUFFER; | 126 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 127 handle.handle = duped_shared_memory_handle; | 127 handle.handle = duped_shared_memory_handle; |
| 128 | 128 |
| 129 EXPECT_CALL(*gpu_memory_buffer_factory_.get(), CreateGpuMemoryBuffer( | 129 EXPECT_CALL( |
| 130 kImageWidth, kImageHeight, GL_RGBA8_OES)) | 130 *gpu_memory_buffer_factory_.get(), |
| 131 CreateGpuMemoryBuffer( |
| 132 kImageWidth, kImageHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM)) |
| 131 .Times(1) | 133 .Times(1) |
| 132 .WillOnce(Return(gpu_memory_buffer)) | 134 .WillOnce(Return(gpu_memory_buffer)) |
| 133 .RetiresOnSaturation(); | 135 .RetiresOnSaturation(); |
| 134 EXPECT_CALL(*gpu_memory_buffer, GetHandle()) | 136 EXPECT_CALL(*gpu_memory_buffer, GetHandle()) |
| 135 .Times(1) | 137 .Times(1) |
| 136 .WillOnce(Return(handle)) | 138 .WillOnce(Return(handle)) |
| 137 .RetiresOnSaturation(); | 139 .RetiresOnSaturation(); |
| 138 | 140 |
| 139 // Create the image. This should add the image ID to the ImageManager. | 141 // Create the image. This should add the image ID to the ImageManager. |
| 140 GLuint image_id = glCreateImageCHROMIUM( | 142 GLuint image_id = glCreateImageCHROMIUM( |
| 141 kImageWidth, kImageHeight, GL_RGBA8_OES); | 143 kImageWidth, kImageHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM); |
| 142 EXPECT_NE(0u, image_id); | 144 EXPECT_NE(0u, image_id); |
| 143 EXPECT_TRUE(image_manager_->LookupImage(image_id) != NULL); | 145 EXPECT_TRUE(image_manager_->LookupImage(image_id) != NULL); |
| 144 | 146 |
| 145 EXPECT_CALL(*gpu_memory_buffer, IsMapped()) | 147 EXPECT_CALL(*gpu_memory_buffer, IsMapped()) |
| 146 .WillOnce(Return(false)) | 148 .WillOnce(Return(false)) |
| 147 .RetiresOnSaturation(); | 149 .RetiresOnSaturation(); |
| 148 | 150 |
| 149 shared_memory.Map(bytes); | 151 shared_memory.Map(bytes); |
| 150 EXPECT_TRUE(shared_memory.memory()); | 152 EXPECT_TRUE(shared_memory.memory()); |
| 151 | 153 |
| 152 EXPECT_CALL(*gpu_memory_buffer, Map(gfx::GpuMemoryBuffer::READ_WRITE)) | 154 EXPECT_CALL(*gpu_memory_buffer, Map()) |
| 153 .Times(1) | 155 .Times(1) |
| 154 .WillOnce(Return(shared_memory.memory())) | 156 .WillOnce(Return(shared_memory.memory())) |
| 155 .RetiresOnSaturation(); | 157 .RetiresOnSaturation(); |
| 156 uint8* mapped_buffer = static_cast<uint8*>( | 158 uint8* mapped_buffer = static_cast<uint8*>(glMapImageCHROMIUM(image_id)); |
| 157 glMapImageCHROMIUM(image_id, GL_READ_WRITE)); | |
| 158 ASSERT_TRUE(mapped_buffer != NULL); | 159 ASSERT_TRUE(mapped_buffer != NULL); |
| 159 | 160 |
| 160 // Assign a value to each pixel. | 161 // Assign a value to each pixel. |
| 161 int stride = kImageWidth * kImageBytesPerPixel; | 162 int stride = kImageWidth * kImageBytesPerPixel; |
| 162 for (int x = 0; x < kImageWidth; ++x) { | 163 for (int x = 0; x < kImageWidth; ++x) { |
| 163 for (int y = 0; y < kImageHeight; ++y) { | 164 for (int y = 0; y < kImageHeight; ++y) { |
| 164 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0]; | 165 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0]; |
| 165 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1]; | 166 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1]; |
| 166 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2]; | 167 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2]; |
| 167 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3]; | 168 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 201 |
| 201 // Destroy the image. | 202 // Destroy the image. |
| 202 EXPECT_CALL(*gpu_memory_buffer, Die()) | 203 EXPECT_CALL(*gpu_memory_buffer, Die()) |
| 203 .Times(1) | 204 .Times(1) |
| 204 .RetiresOnSaturation(); | 205 .RetiresOnSaturation(); |
| 205 glDestroyImageCHROMIUM(image_id); | 206 glDestroyImageCHROMIUM(image_id); |
| 206 } | 207 } |
| 207 | 208 |
| 208 } // namespace gles2 | 209 } // namespace gles2 |
| 209 } // namespace gpu | 210 } // namespace gpu |
| OLD | NEW |