| OLD | NEW |
| 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/scheduler/texture_uploader.h" | 5 #include "cc/scheduler/texture_uploader.h" |
| 6 | 6 |
| 7 #include "cc/base/util.h" | 7 #include "cc/base/util.h" |
| 8 #include "cc/debug/test_web_graphics_context_3d.h" | 8 #include "cc/debug/test_web_graphics_context_3d.h" |
| 9 #include "cc/resources/prioritized_resource.h" | 9 #include "cc/resources/prioritized_resource.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 144 } |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 unsigned result_available_; | 147 unsigned result_available_; |
| 148 unsigned unpack_alignment_; | 148 unsigned unpack_alignment_; |
| 149 | 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(TestWebGraphicsContext3DTextureUpload); | 150 DISALLOW_COPY_AND_ASSIGN(TestWebGraphicsContext3DTextureUpload); |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 void UploadTexture(TextureUploader* uploader, | 153 void UploadTexture(TextureUploader* uploader, |
| 154 WGC3Denum format, | 154 ResourceFormat format, |
| 155 gfx::Size size, | 155 gfx::Size size, |
| 156 const uint8* data) { | 156 const uint8* data) { |
| 157 uploader->Upload(data, | 157 uploader->Upload(data, |
| 158 gfx::Rect(size), | 158 gfx::Rect(size), |
| 159 gfx::Rect(size), | 159 gfx::Rect(size), |
| 160 gfx::Vector2d(), | 160 gfx::Vector2d(), |
| 161 format, | 161 format, |
| 162 size); | 162 size); |
| 163 } | 163 } |
| 164 | 164 |
| 165 TEST(TextureUploaderTest, NumBlockingUploads) { | 165 TEST(TextureUploaderTest, NumBlockingUploads) { |
| 166 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fake_context( | 166 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fake_context( |
| 167 new TestWebGraphicsContext3DTextureUpload); | 167 new TestWebGraphicsContext3DTextureUpload); |
| 168 scoped_ptr<TextureUploader> uploader = | 168 scoped_ptr<TextureUploader> uploader = |
| 169 TextureUploader::Create(fake_context.get(), false, false); | 169 TextureUploader::Create(fake_context.get(), false, false); |
| 170 | 170 |
| 171 fake_context->SetResultAvailable(0); | 171 fake_context->SetResultAvailable(0); |
| 172 EXPECT_EQ(0u, uploader->NumBlockingUploads()); | 172 EXPECT_EQ(0u, uploader->NumBlockingUploads()); |
| 173 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 173 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 174 EXPECT_EQ(1u, uploader->NumBlockingUploads()); | 174 EXPECT_EQ(1u, uploader->NumBlockingUploads()); |
| 175 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 175 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 176 EXPECT_EQ(2u, uploader->NumBlockingUploads()); | 176 EXPECT_EQ(2u, uploader->NumBlockingUploads()); |
| 177 | 177 |
| 178 fake_context->SetResultAvailable(1); | 178 fake_context->SetResultAvailable(1); |
| 179 EXPECT_EQ(0u, uploader->NumBlockingUploads()); | 179 EXPECT_EQ(0u, uploader->NumBlockingUploads()); |
| 180 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 180 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 181 EXPECT_EQ(0u, uploader->NumBlockingUploads()); | 181 EXPECT_EQ(0u, uploader->NumBlockingUploads()); |
| 182 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 182 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 183 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 183 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 184 EXPECT_EQ(0u, uploader->NumBlockingUploads()); | 184 EXPECT_EQ(0u, uploader->NumBlockingUploads()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST(TextureUploaderTest, MarkPendingUploadsAsNonBlocking) { | 187 TEST(TextureUploaderTest, MarkPendingUploadsAsNonBlocking) { |
| 188 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fake_context( | 188 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fake_context( |
| 189 new TestWebGraphicsContext3DTextureUpload); | 189 new TestWebGraphicsContext3DTextureUpload); |
| 190 scoped_ptr<TextureUploader> uploader = | 190 scoped_ptr<TextureUploader> uploader = |
| 191 TextureUploader::Create(fake_context.get(), false, false); | 191 TextureUploader::Create(fake_context.get(), false, false); |
| 192 | 192 |
| 193 fake_context->SetResultAvailable(0); | 193 fake_context->SetResultAvailable(0); |
| 194 EXPECT_EQ(0u, uploader->NumBlockingUploads()); | 194 EXPECT_EQ(0u, uploader->NumBlockingUploads()); |
| 195 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 195 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 196 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 196 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 197 EXPECT_EQ(2u, uploader->NumBlockingUploads()); | 197 EXPECT_EQ(2u, uploader->NumBlockingUploads()); |
| 198 | 198 |
| 199 uploader->MarkPendingUploadsAsNonBlocking(); | 199 uploader->MarkPendingUploadsAsNonBlocking(); |
| 200 EXPECT_EQ(0u, uploader->NumBlockingUploads()); | 200 EXPECT_EQ(0u, uploader->NumBlockingUploads()); |
| 201 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 201 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 202 EXPECT_EQ(1u, uploader->NumBlockingUploads()); | 202 EXPECT_EQ(1u, uploader->NumBlockingUploads()); |
| 203 | 203 |
| 204 fake_context->SetResultAvailable(1); | 204 fake_context->SetResultAvailable(1); |
| 205 EXPECT_EQ(0u, uploader->NumBlockingUploads()); | 205 EXPECT_EQ(0u, uploader->NumBlockingUploads()); |
| 206 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL); | 206 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL); |
| 207 uploader->MarkPendingUploadsAsNonBlocking(); | 207 uploader->MarkPendingUploadsAsNonBlocking(); |
| 208 EXPECT_EQ(0u, uploader->NumBlockingUploads()); | 208 EXPECT_EQ(0u, uploader->NumBlockingUploads()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 TEST(TextureUploaderTest, UploadContentsTest) { | 211 TEST(TextureUploaderTest, UploadContentsTest) { |
| 212 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fake_context( | 212 scoped_ptr<TestWebGraphicsContext3DTextureUpload> fake_context( |
| 213 new TestWebGraphicsContext3DTextureUpload); | 213 new TestWebGraphicsContext3DTextureUpload); |
| 214 scoped_ptr<TextureUploader> uploader = | 214 scoped_ptr<TextureUploader> uploader = |
| 215 TextureUploader::Create(fake_context.get(), false, false); | 215 TextureUploader::Create(fake_context.get(), false, false); |
| 216 uint8 buffer[256 * 256 * 4]; | 216 uint8 buffer[256 * 256 * 4]; |
| 217 | 217 |
| 218 // Upload a tightly packed 256x256 RGBA texture. | 218 // Upload a tightly packed 256x256 RGBA texture. |
| 219 memset(buffer, 0, sizeof(buffer)); | 219 memset(buffer, 0, sizeof(buffer)); |
| 220 for (int i = 0; i < 256; ++i) { | 220 for (int i = 0; i < 256; ++i) { |
| 221 // Mark the beginning and end of each row, for the test. | 221 // Mark the beginning and end of each row, for the test. |
| 222 buffer[i * 4 * 256] = 0x1; | 222 buffer[i * 4 * 256] = 0x1; |
| 223 buffer[(i + 1) * 4 * 256 - 1] = 0x2; | 223 buffer[(i + 1) * 4 * 256 - 1] = 0x2; |
| 224 } | 224 } |
| 225 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(256, 256), buffer); | 225 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(256, 256), buffer); |
| 226 | 226 |
| 227 // Upload a tightly packed 41x43 RGBA texture. | 227 // Upload a tightly packed 41x43 RGBA texture. |
| 228 memset(buffer, 0, sizeof(buffer)); | 228 memset(buffer, 0, sizeof(buffer)); |
| 229 for (int i = 0; i < 43; ++i) { | 229 for (int i = 0; i < 43; ++i) { |
| 230 // Mark the beginning and end of each row, for the test. | 230 // Mark the beginning and end of each row, for the test. |
| 231 buffer[i * 4 * 41] = 0x1; | 231 buffer[i * 4 * 41] = 0x1; |
| 232 buffer[(i + 1) * 4 * 41 - 1] = 0x2; | 232 buffer[(i + 1) * 4 * 41 - 1] = 0x2; |
| 233 } | 233 } |
| 234 UploadTexture(uploader.get(), GL_RGBA, gfx::Size(41, 43), buffer); | 234 UploadTexture(uploader.get(), RGBA_8888, gfx::Size(41, 43), buffer); |
| 235 | 235 |
| 236 // Upload a tightly packed 82x86 LUMINANCE texture. | 236 // Upload a tightly packed 82x86 LUMINANCE texture. |
| 237 memset(buffer, 0, sizeof(buffer)); | 237 memset(buffer, 0, sizeof(buffer)); |
| 238 for (int i = 0; i < 86; ++i) { | 238 for (int i = 0; i < 86; ++i) { |
| 239 // Mark the beginning and end of each row, for the test. | 239 // Mark the beginning and end of each row, for the test. |
| 240 buffer[i * 1 * 82] = 0x1; | 240 buffer[i * 1 * 82] = 0x1; |
| 241 buffer[(i + 1) * 82 - 1] = 0x2; | 241 buffer[(i + 1) * 82 - 1] = 0x2; |
| 242 } | 242 } |
| 243 UploadTexture(uploader.get(), GL_LUMINANCE, gfx::Size(82, 86), buffer); | 243 UploadTexture(uploader.get(), LUMINANCE_8, gfx::Size(82, 86), buffer); |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace | 246 } // namespace |
| 247 } // namespace cc | 247 } // namespace cc |
| OLD | NEW |