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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "cc/base/scoped_ptr_deque.h" | 11 #include "cc/base/scoped_ptr_deque.h" |
12 #include "cc/base/scoped_ptr_hash_map.h" | 12 #include "cc/base/scoped_ptr_hash_map.h" |
13 #include "cc/output/output_surface.h" | 13 #include "cc/output/output_surface.h" |
14 #include "cc/test/fake_output_surface.h" | 14 #include "cc/test/fake_output_surface.h" |
15 #include "cc/test/test_web_graphics_context_3d.h" | 15 #include "cc/test/test_web_graphics_context_3d.h" |
16 #include "gpu/GLES2/gl2extchromium.h" | 16 #include "gpu/GLES2/gl2extchromium.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
20 #include "third_party/khronos/GLES2/gl2.h" | 20 #include "third_party/khronos/GLES2/gl2.h" |
21 #include "third_party/khronos/GLES2/gl2ext.h" | 21 #include "third_party/khronos/GLES2/gl2ext.h" |
22 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
23 | 23 |
24 using testing::Mock; | 24 using testing::Mock; |
25 using testing::NiceMock; | 25 using testing::NiceMock; |
26 using testing::Return; | 26 using testing::Return; |
27 using testing::StrictMock; | 27 using testing::StrictMock; |
28 using testing::_; | 28 using testing::_; |
29 using WebKit::WGC3Dboolean; | |
reveman
2013/05/17 01:48:08
what is this for?
kaanb
2013/05/17 21:27:36
Removed.
| |
29 using WebKit::WGC3Dbyte; | 30 using WebKit::WGC3Dbyte; |
30 using WebKit::WGC3Denum; | 31 using WebKit::WGC3Denum; |
31 using WebKit::WGC3Dint; | 32 using WebKit::WGC3Dint; |
32 using WebKit::WGC3Dsizei; | 33 using WebKit::WGC3Dsizei; |
33 using WebKit::WGC3Duint; | 34 using WebKit::WGC3Duint; |
34 using WebKit::WebGLId; | 35 using WebKit::WebGLId; |
35 | 36 |
36 namespace cc { | 37 namespace cc { |
37 namespace { | 38 namespace { |
38 | 39 |
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1228 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, | 1229 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, |
1229 void(WGC3Denum target, | 1230 void(WGC3Denum target, |
1230 WGC3Dint level, | 1231 WGC3Dint level, |
1231 WGC3Dint xoffset, | 1232 WGC3Dint xoffset, |
1232 WGC3Dint yoffset, | 1233 WGC3Dint yoffset, |
1233 WGC3Dsizei width, | 1234 WGC3Dsizei width, |
1234 WGC3Dsizei height, | 1235 WGC3Dsizei height, |
1235 WGC3Denum format, | 1236 WGC3Denum format, |
1236 WGC3Denum type, | 1237 WGC3Denum type, |
1237 const void* pixels)); | 1238 const void* pixels)); |
1238 MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(WGC3Denum target)); | 1239 MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(WGC3Denum)); |
1240 MOCK_METHOD3(createImageCHROMIUM, WGC3Duint(WGC3Dsizei, WGC3Dsizei, | |
1241 WGC3Denum)); | |
1242 MOCK_METHOD1(destroyImageCHROMIUM, void(WGC3Duint)); | |
1243 MOCK_METHOD2(mapImageCHROMIUM, void*(WGC3Duint, WGC3Denum)); | |
1244 MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint)); | |
1245 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); | |
1239 }; | 1246 }; |
1240 | 1247 |
1241 TEST_P(ResourceProviderTest, TextureAllocation) { | 1248 TEST_P(ResourceProviderTest, TextureAllocation) { |
1242 // Only for GL textures. | 1249 // Only for GL textures. |
1243 if (GetParam() != ResourceProvider::GLTexture) | 1250 if (GetParam() != ResourceProvider::GLTexture) |
1244 return; | 1251 return; |
1245 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( | 1252 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( |
1246 static_cast<WebKit::WebGraphicsContext3D*>( | 1253 static_cast<WebKit::WebGraphicsContext3D*>( |
1247 new NiceMock<AllocationTrackingContext3D>)); | 1254 new NiceMock<AllocationTrackingContext3D>)); |
1248 scoped_ptr<OutputSurface> output_surface( | 1255 scoped_ptr<OutputSurface> output_surface( |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1410 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 1417 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
1411 GL_INNOCENT_CONTEXT_RESET_ARB); | 1418 GL_INNOCENT_CONTEXT_RESET_ARB); |
1412 resource_provider->AcquirePixelBuffer(id); | 1419 resource_provider->AcquirePixelBuffer(id); |
1413 uint8_t* buffer = resource_provider->MapPixelBuffer(id); | 1420 uint8_t* buffer = resource_provider->MapPixelBuffer(id); |
1414 EXPECT_TRUE(buffer == NULL); | 1421 EXPECT_TRUE(buffer == NULL); |
1415 resource_provider->UnmapPixelBuffer(id); | 1422 resource_provider->UnmapPixelBuffer(id); |
1416 resource_provider->ReleasePixelBuffer(id); | 1423 resource_provider->ReleasePixelBuffer(id); |
1417 Mock::VerifyAndClearExpectations(context); | 1424 Mock::VerifyAndClearExpectations(context); |
1418 } | 1425 } |
1419 | 1426 |
1427 TEST_P(ResourceProviderTest, GpuMemoryBuffers) { | |
1428 // Only for GL textures. | |
1429 if (GetParam() != ResourceProvider::GLTexture) | |
1430 return; | |
1431 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( | |
1432 static_cast<WebKit::WebGraphicsContext3D*>( | |
1433 new StrictMock<AllocationTrackingContext3D>)); | |
1434 scoped_ptr<OutputSurface> output_surface( | |
1435 FakeOutputSurface::Create3d(mock_context.Pass())); | |
1436 | |
1437 const int kWidth = 2; | |
1438 const int kHeight = 2; | |
1439 gfx::Size size(kWidth, kHeight); | |
1440 WGC3Denum format = GL_RGBA; | |
1441 ResourceProvider::ResourceId id = 0; | |
1442 const unsigned kTextureId = 123u; | |
1443 const unsigned kImageId = 234u; | |
1444 | |
1445 AllocationTrackingContext3D* context = | |
1446 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | |
1447 scoped_ptr<ResourceProvider> resource_provider( | |
1448 ResourceProvider::Create(output_surface.get(), 0)); | |
1449 resource_provider->SetUseGpuMemoryBuffers(true); | |
1450 | |
1451 EXPECT_CALL(*context, createTexture()).WillOnce(Return(kTextureId)) | |
1452 .RetiresOnSaturation(); | |
1453 // First bindTexture call is within CreateResource, second is within | |
1454 // BeginSetPixels. | |
1455 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) | |
1456 .RetiresOnSaturation(); | |
1457 id = resource_provider->CreateResource( | |
1458 size, format, ResourceProvider::TextureUsageAny); | |
1459 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) | |
1460 .WillOnce(Return(kImageId)); | |
1461 resource_provider->AcquirePixelBuffer(id); | |
1462 | |
1463 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) | |
1464 .RetiresOnSaturation(); | |
1465 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | |
1466 .Times(1) | |
1467 .RetiresOnSaturation(); | |
1468 resource_provider->BeginSetPixels(id); | |
1469 | |
1470 void* dummy_mapped_buffer_address = NULL; | |
1471 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_WRITE_ONLY)) | |
1472 .WillOnce(Return(dummy_mapped_buffer_address)) | |
1473 .RetiresOnSaturation(); | |
1474 resource_provider->MapPixelBuffer(id); | |
1475 | |
1476 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) | |
1477 .Times(1) | |
1478 .RetiresOnSaturation(); | |
1479 resource_provider->UnmapPixelBuffer(id); | |
1480 | |
1481 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) | |
1482 .Times(1) | |
1483 .RetiresOnSaturation(); | |
1484 resource_provider->ReleasePixelBuffer(id); | |
1485 | |
1486 // Texture will be deleted when ResourceProvider destructor is | |
1487 // called when it goes out of scope when this method returns. | |
1488 EXPECT_CALL(*context, deleteTexture(kTextureId)) | |
1489 .Times(1) | |
1490 .RetiresOnSaturation(); | |
1491 } | |
1492 | |
1420 INSTANTIATE_TEST_CASE_P( | 1493 INSTANTIATE_TEST_CASE_P( |
1421 ResourceProviderTests, | 1494 ResourceProviderTests, |
1422 ResourceProviderTest, | 1495 ResourceProviderTest, |
1423 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1496 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
1424 | 1497 |
1425 } // namespace | 1498 } // namespace |
1426 } // namespace cc | 1499 } // namespace cc |
OLD | NEW |