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

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: Add missing parameter in GLES2Implementation ctor in GLES2Implementation unittest 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::IgnoreResult;
27 using testing::InvokeWithoutArgs;
28 using testing::Invoke;
29 using testing::Return;
30 using testing::SetArgPointee;
31 using testing::StrictMock;
32
33 namespace gpu {
34 namespace gles2 {
35
36 static const int kImageWidth = 256;
37 static const int kImageHeight = 256;
38 static const int kImageBytesPerPixel = 4;
39
40 class MockGpuMemoryBufferTest : public testing::Test {
41 protected:
42 virtual void SetUp() {
43 GLManager::Options options;
44 image_manager_ = new ImageManager;
45 image_factory_.reset(
46 new StrictMock<ImageFactoryMock>(image_manager_));
47 options.image_manager = image_manager_;
48 options.image_factory = image_factory_.get();
49
50 gl_.Initialize(options);
51 gl_.MakeCurrent();
52 }
53
54 virtual void TearDown() {
55 gl_.Destroy();
56 }
57
58 scoped_ptr<StrictMock<ImageFactoryMock> > image_factory_;
59 scoped_refptr<ImageManager> image_manager_;
60 GLManager gl_;
61 };
62
63 // An end to end test that tests the whole GpuMemoryBuffer lifecycle.
64 TEST_F(MockGpuMemoryBufferTest, Lifecycle) {
65 // Create a client texture id.
66 GLuint texture_id;
67 glGenTextures(1, &texture_id);
68
69 // Buffer is owned and freed by GpuMemoryBufferTracker.
70 StrictMock<GpuMemoryBufferMock>* gpu_memory_buffer =
71 new StrictMock<GpuMemoryBufferMock>(kImageWidth, kImageHeight);
72
73 const GLuint kImageId = 345u;
74
75 EXPECT_CALL(*image_factory_.get(), CreateGpuMemoryBufferMock(
76 kImageWidth, kImageHeight, GL_RGBA8_OES, _))
77 .Times(1)
78 .WillOnce(DoAll(SetArgPointee<3>(kImageId),
79 Return(gpu_memory_buffer)))
80 .RetiresOnSaturation();
81
82 // Create the GLImage and insert it into the ImageManager, which
83 // would be done within CreateGpuMemoryBufferMock if it weren't a mock.
84 GLuint image_id = glCreateImageCHROMIUM(
85 kImageWidth, kImageHeight, GL_RGBA8_OES);
86 EXPECT_EQ(kImageId, image_id);
87
88 gfx::Size size(kImageWidth, kImageHeight);
89 scoped_refptr<gfx::GLImageMock> gl_image(
90 new gfx::GLImageMock(gpu_memory_buffer, size));
91 image_manager_->AddImage(gl_image.get(), image_id);
92
93 EXPECT_CALL(*gpu_memory_buffer, IsMapped())
94 .WillOnce(Return(false))
95 .RetiresOnSaturation();
96
97 scoped_ptr<uint8[]> buffer_pixels(new uint8[
98 kImageWidth * kImageHeight * kImageBytesPerPixel]);
99
100 EXPECT_CALL(*gpu_memory_buffer, Map(_, _))
101 .Times(1)
102 .WillOnce(SetArgPointee<1>(buffer_pixels.get()))
103 .RetiresOnSaturation();
104 void* mapped_buffer =
105 glMapImageCHROMIUM(image_id, GL_WRITE_ONLY);
106 EXPECT_EQ(buffer_pixels.get(), mapped_buffer);
107
108 EXPECT_CALL(*gpu_memory_buffer, IsMapped())
109 .WillOnce(Return(true))
110 .RetiresOnSaturation();
111
112 // Unmap the image.
113 EXPECT_CALL(*gpu_memory_buffer, Unmap())
114 .Times(1)
115 .RetiresOnSaturation();
116 glUnmapImageCHROMIUM(image_id);
117
118 // Bind the texture and the image.
119 glBindTexture(GL_TEXTURE_2D, texture_id);
120 EXPECT_CALL(*gl_image, BindTexImage())
121 .Times(1)
122 .WillOnce(Return(true))
123 .RetiresOnSaturation();
124 EXPECT_CALL(*gl_image, GetSize())
125 .Times(1)
126 .WillOnce(Return(size))
127 .RetiresOnSaturation();
128 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id);
129
130 // Destroy the image.
131 EXPECT_CALL(*gpu_memory_buffer, Die())
132 .Times(1)
133 .RetiresOnSaturation();
134
135 EXPECT_CALL(*image_factory_.get(), DeleteGpuMemoryBuffer(image_id))
136 .Times(1)
137 .RetiresOnSaturation();
138
139 glDestroyImageCHROMIUM(image_id);
140
141 // Delete the texture.
142 glDeleteTextures(1, &texture_id);
143 }
144
145 } // namespace gles2
146 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h ('k') | gpu/command_buffer/tests/gl_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698