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

Side by Side Diff: cc/resource_provider_unittest.cc

Issue 11622008: cc: Defer texture allocation (to allow async allocations). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Track uninitialized textures. Fix tests. Created 8 years 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
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/resource_provider.h" 5 #include "cc/resource_provider.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "cc/output_surface.h" 8 #include "cc/output_surface.h"
9 #include "cc/scoped_ptr_deque.h" 9 #include "cc/scoped_ptr_deque.h"
10 #include "cc/scoped_ptr_hash_map.h" 10 #include "cc/scoped_ptr_hash_map.h"
11 #include "cc/test/compositor_fake_web_graphics_context_3d.h" 11 #include "cc/test/compositor_fake_web_graphics_context_3d.h"
12 #include "cc/test/fake_output_surface.h" 12 #include "cc/test/fake_output_surface.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
16 #include "third_party/khronos/GLES2/gl2.h" 16 #include "third_party/khronos/GLES2/gl2.h"
17 #include "third_party/khronos/GLES2/gl2ext.h" 17 #include "third_party/khronos/GLES2/gl2ext.h"
18 #include "ui/gfx/rect.h" 18 #include "ui/gfx/rect.h"
19 19
20 using namespace WebKit; 20 using namespace WebKit;
21 21
22 using testing::Mock; 22 using testing::Mock;
23 using testing::StrictMock;
24 using testing::NiceMock;
25 using testing::_;
23 26
24 namespace cc { 27 namespace cc {
25 namespace { 28 namespace {
26 29
27 size_t textureSize(const gfx::Size& size, WGC3Denum format) 30 size_t textureSize(const gfx::Size& size, WGC3Denum format)
28 { 31 {
29 unsigned int componentsPerPixel = 4; 32 unsigned int componentsPerPixel = 4;
30 unsigned int bytesPerComponent = 1; 33 unsigned int bytesPerComponent = 1;
31 return size.width() * size.height() * componentsPerPixel * bytesPerComponent ; 34 return size.width() * size.height() * componentsPerPixel * bytesPerComponent ;
32 } 35 }
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 WGC3Denum format = GL_RGBA; 582 WGC3Denum format = GL_RGBA;
580 int textureId = 1; 583 int textureId = 1;
581 584
582 // Check that the texture gets created with the right sampler settings. 585 // Check that the texture gets created with the right sampler settings.
583 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); 586 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId));
584 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL _LINEAR)); 587 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL _LINEAR));
585 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL _LINEAR)); 588 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL _LINEAR));
586 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA MP_TO_EDGE)); 589 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA MP_TO_EDGE));
587 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA MP_TO_EDGE)); 590 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA MP_TO_EDGE));
588 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); 591 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
589 ResourceProvider::ResourceId id = resourceProvider->createResource(size, for mat, ResourceProvider::TextureUsageAny); 592 ResourceProvider::ResourceId id = resourceProvider->createAllocatedResource( size, format, ResourceProvider::TextureUsageAny);
590 593
591 // Creating a sampler with the default filter should not change any texture 594 // Creating a sampler with the default filter should not change any texture
592 // parameters. 595 // parameters.
593 { 596 {
594 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); 597 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId));
595 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL _TEXTURE_2D, GL_LINEAR); 598 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL _TEXTURE_2D, GL_LINEAR);
596 } 599 }
597 600
598 // Using a different filter should be reflected in the texture parameters. 601 // Using a different filter should be reflected in the texture parameters.
599 { 602 {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL _LINEAR)); 636 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL _LINEAR));
634 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL _LINEAR)); 637 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL _LINEAR));
635 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA MP_TO_EDGE)); 638 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA MP_TO_EDGE));
636 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA MP_TO_EDGE)); 639 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA MP_TO_EDGE));
637 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_MANAGED_CHROMIUM)); 640 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_MANAGED_CHROMIUM));
638 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si ze, format, ResourceProvider::TextureUsageAny); 641 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si ze, format, ResourceProvider::TextureUsageAny);
639 642
640 Mock::VerifyAndClearExpectations(context); 643 Mock::VerifyAndClearExpectations(context);
641 } 644 }
642 645
646 class AllocationTrackingContext3D : public FakeWebGraphicsContext3D {
647 public:
648 MOCK_METHOD9(texImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Denum in ternalformat,
649 WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
650 WGC3Denum type, const void* pixels));
651 MOCK_METHOD9(texSubImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Dint xoffset, WGC3Dint yoffset,
652 WGC3Dsizei width, WGC3Dsizei height, WGC3De num format,
653 WGC3Denum type, const void* pixels));
654 MOCK_METHOD9(asyncTexImage2DCHROMIUM, void(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat,
655 WGC3Dsizei width, WGC3Dsizei heigh t, WGC3Dint border, WGC3Denum format,
656 WGC3Denum type, const void* pixels ));
657 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, void(WGC3Denum target, WGC3Dint lev el, WGC3Dint xoffset, WGC3Dint yoffset,
658 WGC3Dsizei width, WGC3Dsizei h eight, WGC3Denum format,
659 WGC3Denum type, const void* pi xels));
660 };
661
662 TEST_P(ResourceProviderTest, TextureAllocation)
663 {
664 // Only for GL textures.
665 if (GetParam() != ResourceProvider::GLTexture)
666 return;
667 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context(
668 static_cast<WebKit::WebGraphicsContext3D*>(new NiceMock<AllocationTracki ngContext3D>));
669 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(mock_con text.Pass()));
670
671 gfx::Size size(2, 2);
672 gfx::Vector2d offset(0, 0);
673 gfx::Rect rect(0, 0, 2, 2);
674 WGC3Denum format = GL_RGBA;
675 ResourceProvider::ResourceId id = 0;
676 uint8_t pixels[16] = {0};
677
678 AllocationTrackingContext3D* context = static_cast<AllocationTrackingContext 3D*>(outputSurface->Context3D());
679 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
680
681 // Lazy allocation. Don't allocate when creating the resource.
682 EXPECT_CALL(*context, texImage2D(_,_,_,_,_,_,_,_,_)).Times(0);
683 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_,_,_,_,_,_,_,_,_)).Times(0);
684 id = resourceProvider->createResource(size, format, ResourceProvider::Textur eUsageAny);
685 resourceProvider->deleteResource(id);
686 Mock::VerifyAndClearExpectations(context);
687
688 // Do allocate when we set the pixels.
689 EXPECT_CALL(*context, texImage2D(_,_,_,2,2,_,_,_,_)).Times(1);
690 EXPECT_CALL(*context, texSubImage2D(_,_,_,_,2,2,_,_,_)).Times(1);
691 id = resourceProvider->createResource(size, format, ResourceProvider::Textur eUsageAny);
692 resourceProvider->setPixels(id, pixels, rect, rect, offset);
693 resourceProvider->deleteResource(id);
694 Mock::VerifyAndClearExpectations(context);
695
696 // Same for setPixelsFromBuffer
697 EXPECT_CALL(*context, texImage2D(_,_,_,2,2,_,_,_,_)).Times(1);
698 EXPECT_CALL(*context, texSubImage2D(_,_,_,_,2,2,_,_,_)).Times(1);
699 id = resourceProvider->createResource(size, format, ResourceProvider::Textur eUsageAny);
700 resourceProvider->acquirePixelBuffer(id);
701 resourceProvider->setPixelsFromBuffer(id);
702 resourceProvider->releasePixelBuffer(id);
703 resourceProvider->deleteResource(id);
704 Mock::VerifyAndClearExpectations(context);
705
706 // Same for async version.
707 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_,_,_,2,2,_,_,_,_)).Times(1);
708 id = resourceProvider->createResource(size, format, ResourceProvider::Textur eUsageAny);
709 resourceProvider->acquirePixelBuffer(id);
710 resourceProvider->beginSetPixels(id);
711 resourceProvider->releasePixelBuffer(id);
712 resourceProvider->deleteResource(id);
713 Mock::VerifyAndClearExpectations(context);
714 }
715
643 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, 716 INSTANTIATE_TEST_CASE_P(ResourceProviderTests,
644 ResourceProviderTest, 717 ResourceProviderTest,
645 ::testing::Values(ResourceProvider::GLTexture, 718 ::testing::Values(ResourceProvider::GLTexture,
646 ResourceProvider::Bitmap)); 719 ResourceProvider::Bitmap));
647 720
648 } // namespace 721 } // namespace
649 } // namespace cc 722 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698