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

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: Delete and add gl_image_mock again 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::Return;
27 using testing::SetArgPointee;
28 using testing::StrictMock;
29
30 namespace gpu {
31 namespace gles2 {
32
33 static const int kImageWidth = 256;
34 static const int kImageHeight = 256;
35 static const int kImageBytesPerPixel = 4;
36
37 class GLGpuMemoryBufferTest : public testing::Test {
no sievers 2013/05/14 21:10:03 nit: MockMemoryBufferTest
kaanb 2013/05/14 23:37:09 Done.
38 protected:
39 virtual void SetUp() {
40 GLManager::Options options;
41 image_manager_ = new ImageManager;
42 image_factory_.reset(
43 new StrictMock<ImageFactoryMock>(image_manager_));
44 options.image_manager = image_manager_;
45 options.image_factory = image_factory_.get();
46
47 gl_.Initialize(options);
48 gl_.MakeCurrent();
49 }
50
51 virtual void TearDown() {
52 gl_.Destroy();
53 }
54
55 scoped_ptr<StrictMock<ImageFactoryMock> > image_factory_;
56 scoped_refptr<ImageManager> image_manager_;
57 GLManager gl_;
58 };
59
60 // An end to end test that tests the whole GpuMemoryBuffer lifecycle.
61 TEST_F(GLGpuMemoryBufferTest, Lifecycle) {
62 // Create a client texture id.
63 GLuint texture_id;
64 glGenTextures(1, &texture_id);
65
66 // Buffer is owned and freed by GpuMemoryBufferTracker.
67 StrictMock<GpuMemoryBufferMock>* gpu_memory_buffer =
68 new StrictMock<GpuMemoryBufferMock>(kImageWidth, kImageHeight);
69
70 EXPECT_CALL(*image_factory_.get(), CreateGpuMemoryBufferMock(
71 kImageWidth, kImageHeight, GL_RGBA8_OES, _))
72 .Times(1)
73 .WillOnce(DoAll(SetArgPointee<3>(345u),
no sievers 2013/05/14 21:10:03 nit: make a constant (i.e. 'const GLuint kImageId
kaanb 2013/05/14 23:37:09 Done.
74 Return(gpu_memory_buffer)))
75 .RetiresOnSaturation();
76
77 // Create the GLImage and insert it into the ImageManager, which
78 // would be done within CreateGpuMemoryBufferMock if it weren't a mock.
79 GLuint image_id = glCreateImageCHROMIUM(
80 kImageWidth, kImageHeight, GL_RGBA8_OES);
81 gfx::Size size(kImageWidth, kImageHeight);
82
83 scoped_refptr<gfx::GLImageMock> gl_image(
84 new gfx::GLImageMock(gpu_memory_buffer, size));
85 image_manager_->AddImage(gl_image.get(), image_id);
no sievers 2013/05/14 21:10:03 nit: AddImage() could be another action set up in
kaanb 2013/05/14 23:37:09 So, do you want me to mock the ImageManager?
86
87 EXPECT_CALL(*gpu_memory_buffer, IsMapped())
88 .WillOnce(Return(false)) // before Map()
no sievers 2013/05/14 21:10:03 nit: If you split up and set the expectations sepa
kaanb 2013/05/14 23:37:09 Done.
89 .WillOnce(Return(true)) // after Map() and before Unmap()
90 .RetiresOnSaturation();
91
92 scoped_ptr<uint8[]> buffer_pixels(new uint8[
93 kImageWidth * kImageHeight * kImageBytesPerPixel]);
94
95 EXPECT_CALL(*gpu_memory_buffer, Map(_, _))
96 .Times(1)
97 .WillOnce(SetArgPointee<1>(buffer_pixels.get()))
98 .RetiresOnSaturation();
99 void* mapped_buffer =
100 glMapImageCHROMIUM(image_id, GL_WRITE_ONLY);
101 EXPECT_EQ(buffer_pixels.get(), mapped_buffer);
102
103 // Unmap the image.
104 EXPECT_CALL(*gpu_memory_buffer, Unmap())
105 .Times(1)
106 .RetiresOnSaturation();
107 glUnmapImageCHROMIUM(image_id);
108
109 // Bind the texture and the image.
110 glBindTexture(GL_TEXTURE_2D, texture_id);
111 EXPECT_CALL(*gl_image, BindTexImage())
112 .Times(1)
113 .WillOnce(Return(true))
114 .RetiresOnSaturation();
115 EXPECT_CALL(*gl_image, GetSize())
116 .Times(1)
117 .WillOnce(Return(size))
118 .RetiresOnSaturation();
119 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id);
120
121 // Destroy the image.
122 EXPECT_CALL(*gpu_memory_buffer, Die())
123 .Times(1)
124 .RetiresOnSaturation();
125
126 EXPECT_CALL(*image_factory_.get(), DeleteGpuMemoryBuffer(image_id))
127 .Times(1)
128 .RetiresOnSaturation();
129
130 glDestroyImageCHROMIUM(image_id);
131
132 // Delete the texture.
133 glDeleteTextures(1, &texture_id);
134 }
135
136 } // namespace gles2
137 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698