Chromium Code Reviews| 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/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "cc/base/scoped_ptr_deque.h" | 13 #include "cc/base/scoped_ptr_deque.h" |
| 14 #include "cc/debug/test_texture.h" | 14 #include "cc/debug/test_texture.h" |
| 15 #include "cc/debug/test_web_graphics_context_3d.h" | 15 #include "cc/debug/test_web_graphics_context_3d.h" |
| 16 #include "cc/output/output_surface.h" | 16 #include "cc/output/output_surface.h" |
| 17 #include "cc/resources/resource.h" | |
|
kaanb
2013/10/23 20:30:09
do you need this include? Please remove it if IWYU
kaanb
2013/10/23 20:30:09
Please remove this include if IWYU presubmit check
powei
2013/10/23 22:20:07
Done.
| |
| 17 #include "cc/resources/returned_resource.h" | 18 #include "cc/resources/returned_resource.h" |
| 18 #include "cc/resources/single_release_callback.h" | 19 #include "cc/resources/single_release_callback.h" |
| 19 #include "cc/test/fake_output_surface.h" | 20 #include "cc/test/fake_output_surface.h" |
| 20 #include "cc/test/fake_output_surface_client.h" | 21 #include "cc/test/fake_output_surface_client.h" |
| 21 #include "gpu/GLES2/gl2extchromium.h" | 22 #include "gpu/GLES2/gl2extchromium.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 25 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 25 #include "third_party/khronos/GLES2/gl2.h" | 26 #include "third_party/khronos/GLES2/gl2.h" |
| 26 #include "third_party/khronos/GLES2/gl2ext.h" | 27 #include "third_party/khronos/GLES2/gl2ext.h" |
| (...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2117 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, | 2118 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, |
| 2118 void(WGC3Denum target, | 2119 void(WGC3Denum target, |
| 2119 WGC3Dint level, | 2120 WGC3Dint level, |
| 2120 WGC3Dint xoffset, | 2121 WGC3Dint xoffset, |
| 2121 WGC3Dint yoffset, | 2122 WGC3Dint yoffset, |
| 2122 WGC3Dsizei width, | 2123 WGC3Dsizei width, |
| 2123 WGC3Dsizei height, | 2124 WGC3Dsizei height, |
| 2124 WGC3Denum format, | 2125 WGC3Denum format, |
| 2125 WGC3Denum type, | 2126 WGC3Denum type, |
| 2126 const void* pixels)); | 2127 const void* pixels)); |
| 2128 MOCK_METHOD8(compressedTexImage2D, | |
| 2129 void(WGC3Denum target, | |
| 2130 WGC3Dint level, | |
| 2131 WGC3Denum internalformat, | |
| 2132 WGC3Dsizei width, | |
| 2133 WGC3Dsizei height, | |
| 2134 WGC3Dint border, | |
| 2135 WGC3Dsizei imageSize, | |
|
kaanb
2013/10/23 20:30:09
nit: s/imageSize/image_size/ also fix the other mo
powei
2013/10/23 22:20:07
Done.
| |
| 2136 const void* data)); | |
| 2137 MOCK_METHOD9(compressedTexSubImage2D, | |
| 2138 void(WGC3Denum target, | |
| 2139 WGC3Dint level, | |
| 2140 WGC3Dint xoffset, | |
| 2141 WGC3Dint yoffset, | |
| 2142 WGC3Dsizei width, | |
| 2143 WGC3Dsizei height, | |
| 2144 WGC3Denum format, | |
| 2145 WGC3Dsizei imageSize, | |
| 2146 const void* data)); | |
| 2127 MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(WGC3Denum)); | 2147 MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(WGC3Denum)); |
| 2128 MOCK_METHOD3(createImageCHROMIUM, WGC3Duint(WGC3Dsizei, WGC3Dsizei, | 2148 MOCK_METHOD3(createImageCHROMIUM, WGC3Duint(WGC3Dsizei, WGC3Dsizei, |
| 2129 WGC3Denum)); | 2149 WGC3Denum)); |
| 2130 MOCK_METHOD1(destroyImageCHROMIUM, void(WGC3Duint)); | 2150 MOCK_METHOD1(destroyImageCHROMIUM, void(WGC3Duint)); |
| 2131 MOCK_METHOD2(mapImageCHROMIUM, void*(WGC3Duint, WGC3Denum)); | 2151 MOCK_METHOD2(mapImageCHROMIUM, void*(WGC3Duint, WGC3Denum)); |
| 2132 MOCK_METHOD3(getImageParameterivCHROMIUM, void(WGC3Duint, WGC3Denum, | 2152 MOCK_METHOD3(getImageParameterivCHROMIUM, void(WGC3Duint, WGC3Denum, |
| 2133 GLint*)); | 2153 GLint*)); |
| 2134 MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint)); | 2154 MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint)); |
| 2135 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); | 2155 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); |
| 2136 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); | 2156 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2541 | 2561 |
| 2542 resource_provider->InitializeSoftware(); | 2562 resource_provider->InitializeSoftware(); |
| 2543 output_surface->ReleaseGL(); | 2563 output_surface->ReleaseGL(); |
| 2544 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); | 2564 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); |
| 2545 | 2565 |
| 2546 InitializeGLAndCheck(shared_data.get(), | 2566 InitializeGLAndCheck(shared_data.get(), |
| 2547 resource_provider.get(), | 2567 resource_provider.get(), |
| 2548 output_surface.get()); | 2568 output_surface.get()); |
| 2549 } | 2569 } |
| 2550 | 2570 |
| 2571 TEST_P(ResourceProviderTest, CompressedTextureETC1) { | |
| 2572 if (GetParam() != ResourceProvider::GLTexture) | |
| 2573 return; | |
| 2574 | |
| 2575 scoped_ptr<AllocationTrackingContext3D> context_owned( | |
| 2576 new AllocationTrackingContext3D); | |
| 2577 AllocationTrackingContext3D* context = context_owned.get(); | |
| 2578 context_owned->set_support_compressed_texture_etc1(true); | |
| 2579 | |
| 2580 FakeOutputSurfaceClient output_surface_client; | |
| 2581 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | |
| 2582 context_owned.PassAs<TestWebGraphicsContext3D>())); | |
| 2583 CHECK(output_surface->BindToClient(&output_surface_client)); | |
| 2584 | |
| 2585 gfx::Size size(4, 4); | |
| 2586 ResourceFormat format = ETC1; | |
|
kaanb
2013/10/23 20:30:09
consider hardcoding ETC1 while calling ResourcePro
powei
2013/10/23 22:20:07
Done.
| |
| 2587 ResourceProvider::ResourceId id = 0; | |
| 2588 | |
| 2589 scoped_ptr<ResourceProvider> resource_provider( | |
| 2590 ResourceProvider::Create(output_surface.get(), 0, false)); | |
| 2591 int texture_id = 123; | |
| 2592 | |
| 2593 id = resource_provider->CreateResource( | |
|
kaanb
2013/10/23 20:30:09
you can define id here
powei
2013/10/23 22:20:07
Done.
| |
| 2594 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | |
| 2595 EXPECT_NE(0u, id); | |
| 2596 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | |
| 2597 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | |
| 2598 EXPECT_CALL(*context, compressedTexImage2D(_, _, _, _, _, _, _, _)).Times(1); | |
| 2599 resource_provider->AllocateForTesting(id); | |
| 2600 | |
| 2601 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | |
| 2602 resource_provider->DeleteResource(id); | |
| 2603 Mock::VerifyAndClearExpectations(context); | |
| 2604 | |
| 2605 uint8_t pixels[8]; | |
| 2606 | |
| 2607 id = resource_provider->CreateResource( | |
|
kaanb
2013/10/23 20:30:09
consider moving this part into its own test case
powei
2013/10/23 22:20:07
Done.
| |
| 2608 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | |
| 2609 EXPECT_NE(0u, id); | |
| 2610 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | |
| 2611 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); | |
| 2612 EXPECT_CALL(*context, | |
| 2613 compressedTexImage2D( | |
| 2614 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); | |
| 2615 EXPECT_CALL(*context, | |
| 2616 compressedTexSubImage2D( | |
| 2617 _, 0, 0, 0, size.width(), size.height(), _, 8, _)).Times(1); | |
| 2618 resource_provider->SetPixels( | |
| 2619 id, pixels, gfx::Rect(size), gfx::Rect(size), gfx::Vector2d(0, 0)); | |
| 2620 | |
| 2621 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | |
| 2622 resource_provider->DeleteResource(id); | |
| 2623 Mock::VerifyAndClearExpectations(context); | |
| 2624 } | |
| 2625 | |
| 2551 INSTANTIATE_TEST_CASE_P( | 2626 INSTANTIATE_TEST_CASE_P( |
| 2552 ResourceProviderTests, | 2627 ResourceProviderTests, |
| 2553 ResourceProviderTest, | 2628 ResourceProviderTest, |
| 2554 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 2629 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 2555 | 2630 |
| 2556 } // namespace | 2631 } // namespace |
| 2557 } // namespace cc | 2632 } // namespace cc |
| OLD | NEW |