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

Side by Side Diff: cc/resources/resource_provider_unittest.cc

Issue 14409006: cc: Changes to use GL API for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Add internalformat parameter to CreateImageCHROMIUM in fake_web_graphics_context_3d to fix clang bu… 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
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/tile_manager.h » ('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/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::SetArgPointee;
27 using testing::StrictMock; 28 using testing::StrictMock;
28 using testing::_; 29 using testing::_;
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 {
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_METHOD3(getImageParameterivCHROMIUM, void(WGC3Duint, WGC3Denum,
1245 GLint*));
1246 MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint));
1247 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint));
1239 }; 1248 };
1240 1249
1241 TEST_P(ResourceProviderTest, TextureAllocation) { 1250 TEST_P(ResourceProviderTest, TextureAllocation) {
1242 // Only for GL textures. 1251 // Only for GL textures.
1243 if (GetParam() != ResourceProvider::GLTexture) 1252 if (GetParam() != ResourceProvider::GLTexture)
1244 return; 1253 return;
1245 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( 1254 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context(
1246 static_cast<WebKit::WebGraphicsContext3D*>( 1255 static_cast<WebKit::WebGraphicsContext3D*>(
1247 new NiceMock<AllocationTrackingContext3D>)); 1256 new NiceMock<AllocationTrackingContext3D>));
1248 scoped_ptr<OutputSurface> output_surface( 1257 scoped_ptr<OutputSurface> output_surface(
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 1419 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
1411 GL_INNOCENT_CONTEXT_RESET_ARB); 1420 GL_INNOCENT_CONTEXT_RESET_ARB);
1412 resource_provider->AcquirePixelBuffer(id); 1421 resource_provider->AcquirePixelBuffer(id);
1413 uint8_t* buffer = resource_provider->MapPixelBuffer(id); 1422 uint8_t* buffer = resource_provider->MapPixelBuffer(id);
1414 EXPECT_TRUE(buffer == NULL); 1423 EXPECT_TRUE(buffer == NULL);
1415 resource_provider->UnmapPixelBuffer(id); 1424 resource_provider->UnmapPixelBuffer(id);
1416 resource_provider->ReleasePixelBuffer(id); 1425 resource_provider->ReleasePixelBuffer(id);
1417 Mock::VerifyAndClearExpectations(context); 1426 Mock::VerifyAndClearExpectations(context);
1418 } 1427 }
1419 1428
1429 TEST_P(ResourceProviderTest, GpuMemoryBuffers) {
1430 // Only for GL textures.
1431 if (GetParam() != ResourceProvider::GLTexture)
1432 return;
1433 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context(
1434 static_cast<WebKit::WebGraphicsContext3D*>(
1435 new StrictMock<AllocationTrackingContext3D>));
1436 scoped_ptr<OutputSurface> output_surface(
1437 FakeOutputSurface::Create3d(mock_context.Pass()));
1438
1439 const int kWidth = 2;
1440 const int kHeight = 2;
1441 gfx::Size size(kWidth, kHeight);
1442 WGC3Denum format = GL_RGBA;
1443 ResourceProvider::ResourceId id = 0;
1444 const unsigned kTextureId = 123u;
1445 const unsigned kImageId = 234u;
1446
1447 AllocationTrackingContext3D* context =
1448 static_cast<AllocationTrackingContext3D*>(output_surface->context3d());
1449 scoped_ptr<ResourceProvider> resource_provider(
1450 ResourceProvider::Create(output_surface.get(), 0));
1451
1452 EXPECT_CALL(*context, createTexture())
1453 .WillOnce(Return(kTextureId))
1454 .RetiresOnSaturation();
1455
1456 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId))
1457 .Times(1)
1458 .RetiresOnSaturation();
1459 id = resource_provider->CreateResource(
1460 size, format, ResourceProvider::TextureUsageAny);
1461 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES))
1462 .WillOnce(Return(kImageId))
1463 .RetiresOnSaturation();
1464 resource_provider->AcquireImage(id);
1465
1466 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1)
1467 .RetiresOnSaturation();
1468 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
1469 .Times(1)
1470 .RetiresOnSaturation();
1471 resource_provider->BindImage(id);
1472
1473 void* dummy_mapped_buffer_address = NULL;
1474 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE))
1475 .WillOnce(Return(dummy_mapped_buffer_address))
1476 .RetiresOnSaturation();
1477 resource_provider->MapImage(id);
1478
1479 const int kStride = 4;
1480 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId,
1481 GL_IMAGE_ROWBYTES_CHROMIUM,
1482 _))
1483 .WillOnce(SetArgPointee<2>(kStride))
1484 .RetiresOnSaturation();
1485 int stride = resource_provider->GetImageStride(id);
1486 EXPECT_EQ(kStride, stride);
1487
1488 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
1489 .Times(1)
1490 .RetiresOnSaturation();
1491 resource_provider->UnmapImage(id);
1492
1493 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId))
1494 .Times(1)
1495 .RetiresOnSaturation();
1496 resource_provider->ReleaseImage(id);
1497
1498 // Texture will be deleted when ResourceProvider destructor is
1499 // called when it goes out of scope when this method returns.
1500 EXPECT_CALL(*context, deleteTexture(kTextureId))
1501 .Times(1)
1502 .RetiresOnSaturation();
1503 }
1504
1420 INSTANTIATE_TEST_CASE_P( 1505 INSTANTIATE_TEST_CASE_P(
1421 ResourceProviderTests, 1506 ResourceProviderTests,
1422 ResourceProviderTest, 1507 ResourceProviderTest,
1423 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); 1508 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap));
1424 1509
1425 } // namespace 1510 } // namespace
1426 } // namespace cc 1511 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/tile_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698