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

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

Issue 14456004: GPU client side changes for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Second set of feedback from sievers@ Created 7 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <GLES2/gl2.h>
6 #include <GLES2/gl2chromium.h>
7 #include <GLES2/gl2ext.h>
8 #include <GLES2/gl2extchromium.h>
9
10 #include "base/bind.h"
11 #include "base/memory/ref_counted.h"
12 #include "gpu/command_buffer/client/gles2_implementation.h"
13 #include "gpu/command_buffer/client/gpu_memory_buffer_factory.h"
14 #include "gpu/command_buffer/client/gpu_memory_buffer_mock.h"
15 #include "gpu/command_buffer/client/image_factory_mock.h"
16 #include "gpu/command_buffer/service/image_manager.h"
17 #include "gpu/command_buffer/tests/gl_manager.h"
18 #include "gpu/command_buffer/tests/gl_test_utils.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/gfx/native_widget_types.h"
22 #include "ui/gl/gl_image.h"
23 #include "ui/gl/gl_image_mock.h"
24
25 using testing::_;
26 using testing::Invoke;
27 using testing::Return;
28 using testing::SetArgPointee;
29 using testing::StrictMock;
30
31 namespace gpu {
32 namespace gles2 {
33
34 static const int kImageWidth = 256;
35 static const int kImageHeight = 256;
36 static const int kImageBytesPerPixel = 4;
37
38 class MockGpuMemoryBufferTest : public testing::Test {
39 protected:
40 virtual void SetUp() {
41 GLManager::Options options;
42 image_manager_ = new ImageManager;
43 image_factory_.reset(
44 new StrictMock<ImageFactoryMock>(image_manager_));
45 options.image_manager = image_manager_;
46 options.image_factory = image_factory_.get();
47
48 gl_.Initialize(options);
49 gl_.MakeCurrent();
50 }
51
52 virtual void TearDown() {
53 gl_.Destroy();
54 }
55
56 scoped_ptr<StrictMock<ImageFactoryMock> > image_factory_;
57 scoped_refptr<ImageManager> image_manager_;
58 GLManager gl_;
59 };
60
61 // An end to end test that tests the whole GpuMemoryBuffer lifecycle.
62 TEST_F(MockGpuMemoryBufferTest, Lifecycle) {
63 // Create a client texture id.
64 GLuint texture_id;
65 glGenTextures(1, &texture_id);
66
67 // Buffer is owned and freed by GpuMemoryBufferTracker.
68 StrictMock<GpuMemoryBufferMock>* gpu_memory_buffer =
69 new StrictMock<GpuMemoryBufferMock>(kImageWidth, kImageHeight);
70
71 const GLuint kImageId = 345u;
72
73 gfx::Size size(kImageWidth, kImageHeight);
74 scoped_refptr<gfx::GLImageMock> gl_image(
75 new gfx::GLImageMock(gpu_memory_buffer, size));
76
77 EXPECT_CALL(*image_factory_.get(), CreateGpuMemoryBufferMock(
78 kImageWidth, kImageHeight, GL_RGBA8_OES, _))
79 .Times(1)
80 // .WillOnce(DoAll(SetArgPointee<3>(kImageId),
81 // Return(gpu_memory_buffer),
82 // Invoke(image_manager_.get(), &ImageManager::AddImage)))
83 .WillOnce(Invoke(image_manager_.get(), &ImageManager::AddImage))
84 .RetiresOnSaturation();
85
86 // Create the GLImage and insert it into the ImageManager, which
87 // would be done within CreateGpuMemoryBufferMock if it weren't a mock.
88 GLuint image_id = glCreateImageCHROMIUM(
89 kImageWidth, kImageHeight, GL_RGBA8_OES);
90 EXPECT_EQ(kImageId, image_id);
91
92 image_manager_->AddImage(gl_image.get(), image_id);
93
94 EXPECT_CALL(*gpu_memory_buffer, IsMapped())
95 .WillOnce(Return(false))
96 .RetiresOnSaturation();
97
98 scoped_ptr<uint8[]> buffer_pixels(new uint8[
99 kImageWidth * kImageHeight * kImageBytesPerPixel]);
100
101 EXPECT_CALL(*gpu_memory_buffer, Map(_, _))
102 .Times(1)
103 .WillOnce(SetArgPointee<1>(buffer_pixels.get()))
104 .RetiresOnSaturation();
105 void* mapped_buffer =
106 glMapImageCHROMIUM(image_id, GL_WRITE_ONLY);
107 EXPECT_EQ(buffer_pixels.get(), mapped_buffer);
108
109 EXPECT_CALL(*gpu_memory_buffer, IsMapped())
110 .WillOnce(Return(true))
111 .RetiresOnSaturation();
112
113 // Unmap the image.
114 EXPECT_CALL(*gpu_memory_buffer, Unmap())
115 .Times(1)
116 .RetiresOnSaturation();
117 glUnmapImageCHROMIUM(image_id);
118
119 // Bind the texture and the image.
120 glBindTexture(GL_TEXTURE_2D, texture_id);
121 EXPECT_CALL(*gl_image, BindTexImage())
122 .Times(1)
123 .WillOnce(Return(true))
124 .RetiresOnSaturation();
125 EXPECT_CALL(*gl_image, GetSize())
126 .Times(1)
127 .WillOnce(Return(size))
128 .RetiresOnSaturation();
129 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id);
130
131 // Destroy the image.
132 EXPECT_CALL(*gpu_memory_buffer, Die())
133 .Times(1)
134 .RetiresOnSaturation();
135
136 EXPECT_CALL(*image_factory_.get(), DeleteGpuMemoryBuffer(image_id))
137 .Times(1)
138 .RetiresOnSaturation();
139
140 glDestroyImageCHROMIUM(image_id);
141
142 // Delete the texture.
143 glDeleteTextures(1, &texture_id);
144 }
145
146 } // namespace gles2
147 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698