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

Side by Side Diff: cc/texture_uploader_unittest.cc

Issue 12211110: Implement WebKit::WebUnitTestSupport::createLayerTreeViewForTesting() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add enum, fix NON_EXPORTED_BASE Created 7 years, 10 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
« no previous file with comments | « cc/texture_copier_unittest.cc ('k') | webkit/compositor_bindings/compositor_bindings.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "cc/texture_uploader.h" 5 #include "cc/texture_uploader.h"
6 6
7 #include "cc/prioritized_resource.h" 7 #include "cc/prioritized_resource.h"
8 #include "cc/test/fake_web_graphics_context_3d.h" 8 #include "cc/test/test_web_graphics_context_3d.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/khronos/GLES2/gl2.h" 11 #include "third_party/khronos/GLES2/gl2.h"
12 #include "third_party/khronos/GLES2/gl2ext.h" 12 #include "third_party/khronos/GLES2/gl2ext.h"
13 13
14 using namespace WebKit; 14 using namespace WebKit;
15 15
16 namespace cc { 16 namespace cc {
17 namespace { 17 namespace {
18 18
19 unsigned int RoundUp(unsigned int n, unsigned int mul) 19 unsigned int RoundUp(unsigned int n, unsigned int mul)
20 { 20 {
21 return (((n - 1) / mul) * mul) + mul; 21 return (((n - 1) / mul) * mul) + mul;
22 } 22 }
23 23
24 class FakeWebGraphicsContext3DTextureUpload : public FakeWebGraphicsContext3D { 24 class TestWebGraphicsContext3DTextureUpload : public TestWebGraphicsContext3D {
25 public: 25 public:
26 FakeWebGraphicsContext3DTextureUpload() 26 TestWebGraphicsContext3DTextureUpload()
27 : m_resultAvailable(0) 27 : m_resultAvailable(0)
28 , m_unpackAlignment(4) 28 , m_unpackAlignment(4)
29 { 29 {
30 } 30 }
31 31
32 virtual void pixelStorei(WGC3Denum pname, WGC3Dint param) 32 virtual void pixelStorei(WGC3Denum pname, WGC3Dint param)
33 { 33 {
34 switch (pname) { 34 switch (pname) {
35 case GL_UNPACK_ALIGNMENT: 35 case GL_UNPACK_ALIGNMENT:
36 // param should be a power of two <= 8 36 // param should be a power of two <= 8
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 uploader->upload(data, 144 uploader->upload(data,
145 gfx::Rect(gfx::Point(0, 0), size), 145 gfx::Rect(gfx::Point(0, 0), size),
146 gfx::Rect(gfx::Point(0, 0), size), 146 gfx::Rect(gfx::Point(0, 0), size),
147 gfx::Vector2d(), 147 gfx::Vector2d(),
148 format, 148 format,
149 size); 149 size);
150 } 150 }
151 151
152 TEST(TextureUploaderTest, NumBlockingUploads) 152 TEST(TextureUploaderTest, NumBlockingUploads)
153 { 153 {
154 scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGra phicsContext3DTextureUpload); 154 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fakeContext(new TestWebGra phicsContext3DTextureUpload);
155 scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.g et(), false, false); 155 scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.g et(), false, false);
156 156
157 fakeContext->setResultAvailable(0); 157 fakeContext->setResultAvailable(0);
158 EXPECT_EQ(0, uploader->numBlockingUploads()); 158 EXPECT_EQ(0, uploader->numBlockingUploads());
159 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 159 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
160 EXPECT_EQ(1, uploader->numBlockingUploads()); 160 EXPECT_EQ(1, uploader->numBlockingUploads());
161 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 161 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
162 EXPECT_EQ(2, uploader->numBlockingUploads()); 162 EXPECT_EQ(2, uploader->numBlockingUploads());
163 163
164 fakeContext->setResultAvailable(1); 164 fakeContext->setResultAvailable(1);
165 EXPECT_EQ(0, uploader->numBlockingUploads()); 165 EXPECT_EQ(0, uploader->numBlockingUploads());
166 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 166 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
167 EXPECT_EQ(0, uploader->numBlockingUploads()); 167 EXPECT_EQ(0, uploader->numBlockingUploads());
168 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 168 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
169 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 169 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
170 EXPECT_EQ(0, uploader->numBlockingUploads()); 170 EXPECT_EQ(0, uploader->numBlockingUploads());
171 } 171 }
172 172
173 TEST(TextureUploaderTest, MarkPendingUploadsAsNonBlocking) 173 TEST(TextureUploaderTest, MarkPendingUploadsAsNonBlocking)
174 { 174 {
175 scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGra phicsContext3DTextureUpload); 175 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fakeContext(new TestWebGra phicsContext3DTextureUpload);
176 scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.g et(), false, false); 176 scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.g et(), false, false);
177 177
178 fakeContext->setResultAvailable(0); 178 fakeContext->setResultAvailable(0);
179 EXPECT_EQ(0, uploader->numBlockingUploads()); 179 EXPECT_EQ(0, uploader->numBlockingUploads());
180 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 180 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
181 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 181 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
182 EXPECT_EQ(2, uploader->numBlockingUploads()); 182 EXPECT_EQ(2, uploader->numBlockingUploads());
183 183
184 uploader->markPendingUploadsAsNonBlocking(); 184 uploader->markPendingUploadsAsNonBlocking();
185 EXPECT_EQ(0, uploader->numBlockingUploads()); 185 EXPECT_EQ(0, uploader->numBlockingUploads());
186 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 186 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
187 EXPECT_EQ(1, uploader->numBlockingUploads()); 187 EXPECT_EQ(1, uploader->numBlockingUploads());
188 188
189 fakeContext->setResultAvailable(1); 189 fakeContext->setResultAvailable(1);
190 EXPECT_EQ(0, uploader->numBlockingUploads()); 190 EXPECT_EQ(0, uploader->numBlockingUploads());
191 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL); 191 uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
192 uploader->markPendingUploadsAsNonBlocking(); 192 uploader->markPendingUploadsAsNonBlocking();
193 EXPECT_EQ(0, uploader->numBlockingUploads()); 193 EXPECT_EQ(0, uploader->numBlockingUploads());
194 } 194 }
195 195
196 TEST(TextureUploaderTest, UploadContentsTest) 196 TEST(TextureUploaderTest, UploadContentsTest)
197 { 197 {
198 scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGra phicsContext3DTextureUpload); 198 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fakeContext(new TestWebGra phicsContext3DTextureUpload);
199 scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.g et(), false, false); 199 scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.g et(), false, false);
200 uint8 buffer[256 * 256 * 4]; 200 uint8 buffer[256 * 256 * 4];
201 201
202 // Upload a tightly packed 256x256 RGBA texture. 202 // Upload a tightly packed 256x256 RGBA texture.
203 memset(buffer, 0, sizeof(buffer)); 203 memset(buffer, 0, sizeof(buffer));
204 for (int i = 0; i < 256; ++i) { 204 for (int i = 0; i < 256; ++i) {
205 // Mark the beginning and end of each row, for the test. 205 // Mark the beginning and end of each row, for the test.
206 buffer[i * 4 * 256] = 0x1; 206 buffer[i * 4 * 256] = 0x1;
207 buffer[(i + 1) * 4 * 256 - 1] = 0x2; 207 buffer[(i + 1) * 4 * 256 - 1] = 0x2;
208 } 208 }
(...skipping 13 matching lines...) Expand all
222 for (int i = 0; i < 86; ++i) { 222 for (int i = 0; i < 86; ++i) {
223 // Mark the beginning and end of each row, for the test. 223 // Mark the beginning and end of each row, for the test.
224 buffer[i * 1 * 82] = 0x1; 224 buffer[i * 1 * 82] = 0x1;
225 buffer[(i + 1) * 82 - 1] = 0x2; 225 buffer[(i + 1) * 82 - 1] = 0x2;
226 } 226 }
227 uploadTexture(uploader.get(), GL_LUMINANCE, gfx::Size(82, 86), buffer); 227 uploadTexture(uploader.get(), GL_LUMINANCE, gfx::Size(82, 86), buffer);
228 } 228 }
229 229
230 } // namespace 230 } // namespace
231 } // namespace cc 231 } // namespace cc
OLDNEW
« no previous file with comments | « cc/texture_copier_unittest.cc ('k') | webkit/compositor_bindings/compositor_bindings.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698