Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc

Issue 255713008: Change glimage to accept a type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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(*gpu_memory_buffer_factory_.get(),
130 kImageWidth, kImageHeight, GL_RGBA8_OES)) 130 CreateGpuMemoryBuffer(kImageWidth,
131 kImageHeight,
132 GL_RGBA8_OES,
133 GL_IMAGE_CPU_READ_WRITE_CHROMIUM))
131 .Times(1) 134 .Times(1)
132 .WillOnce(Return(gpu_memory_buffer)) 135 .WillOnce(Return(gpu_memory_buffer))
133 .RetiresOnSaturation(); 136 .RetiresOnSaturation();
134 EXPECT_CALL(*gpu_memory_buffer, GetHandle()) 137 EXPECT_CALL(*gpu_memory_buffer, GetHandle())
135 .Times(1) 138 .Times(1)
136 .WillOnce(Return(handle)) 139 .WillOnce(Return(handle))
137 .RetiresOnSaturation(); 140 .RetiresOnSaturation();
138 141
139 // Create the image. This should add the image ID to the ImageManager. 142 // Create the image. This should add the image ID to the ImageManager.
140 GLuint image_id = glCreateImageCHROMIUM( 143 GLuint image_id = glCreateImageCHROMIUM(kImageWidth,
141 kImageWidth, kImageHeight, GL_RGBA8_OES); 144 kImageHeight,
145 GL_RGBA8_OES,
146 GL_IMAGE_CPU_READ_WRITE_CHROMIUM);
142 EXPECT_NE(0u, image_id); 147 EXPECT_NE(0u, image_id);
143 EXPECT_TRUE(image_manager_->LookupImage(image_id) != NULL); 148 EXPECT_TRUE(image_manager_->LookupImage(image_id) != NULL);
144 149
145 EXPECT_CALL(*gpu_memory_buffer, IsMapped()) 150 EXPECT_CALL(*gpu_memory_buffer, IsMapped())
146 .WillOnce(Return(false)) 151 .WillOnce(Return(false))
147 .RetiresOnSaturation(); 152 .RetiresOnSaturation();
148 153
149 shared_memory.Map(bytes); 154 shared_memory.Map(bytes);
150 EXPECT_TRUE(shared_memory.memory()); 155 EXPECT_TRUE(shared_memory.memory());
151 156
152 EXPECT_CALL(*gpu_memory_buffer, Map(gfx::GpuMemoryBuffer::READ_WRITE)) 157 EXPECT_CALL(*gpu_memory_buffer, Map())
153 .Times(1) 158 .Times(1)
154 .WillOnce(Return(shared_memory.memory())) 159 .WillOnce(Return(shared_memory.memory()))
155 .RetiresOnSaturation(); 160 .RetiresOnSaturation();
156 uint8* mapped_buffer = static_cast<uint8*>( 161 uint8* mapped_buffer = static_cast<uint8*>(glMapImageCHROMIUM(image_id));
157 glMapImageCHROMIUM(image_id, GL_READ_WRITE));
158 ASSERT_TRUE(mapped_buffer != NULL); 162 ASSERT_TRUE(mapped_buffer != NULL);
159 163
160 // Assign a value to each pixel. 164 // Assign a value to each pixel.
161 int stride = kImageWidth * kImageBytesPerPixel; 165 int stride = kImageWidth * kImageBytesPerPixel;
162 for (int x = 0; x < kImageWidth; ++x) { 166 for (int x = 0; x < kImageWidth; ++x) {
163 for (int y = 0; y < kImageHeight; ++y) { 167 for (int y = 0; y < kImageHeight; ++y) {
164 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0]; 168 mapped_buffer[y * stride + x * kImageBytesPerPixel + 0] = pixels[0];
165 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1]; 169 mapped_buffer[y * stride + x * kImageBytesPerPixel + 1] = pixels[1];
166 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2]; 170 mapped_buffer[y * stride + x * kImageBytesPerPixel + 2] = pixels[2];
167 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3]; 171 mapped_buffer[y * stride + x * kImageBytesPerPixel + 3] = pixels[3];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 204
201 // Destroy the image. 205 // Destroy the image.
202 EXPECT_CALL(*gpu_memory_buffer, Die()) 206 EXPECT_CALL(*gpu_memory_buffer, Die())
203 .Times(1) 207 .Times(1)
204 .RetiresOnSaturation(); 208 .RetiresOnSaturation();
205 glDestroyImageCHROMIUM(image_id); 209 glDestroyImageCHROMIUM(image_id);
206 } 210 }
207 211
208 } // namespace gles2 212 } // namespace gles2
209 } // namespace gpu 213 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698