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

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

Issue 499283002: gpu: support immutable texture on Linux Mesa driver and GLES3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CompleteHandlingOfGLESandBGRA. Apply CC Created 6 years, 3 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/test/test_web_graphics_context_3d.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 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 2949 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 2960
2961 FakeOutputSurfaceClient output_surface_client; 2961 FakeOutputSurfaceClient output_surface_client;
2962 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 2962 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
2963 context_owned.PassAs<TestWebGraphicsContext3D>())); 2963 context_owned.PassAs<TestWebGraphicsContext3D>()));
2964 CHECK(output_surface->BindToClient(&output_surface_client)); 2964 CHECK(output_surface->BindToClient(&output_surface_client));
2965 2965
2966 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2966 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2967 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 2967 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2968 2968
2969 gfx::Size size(2, 2); 2969 gfx::Size size(2, 2);
2970 ResourceFormat format = RGBA_8888; 2970
2971 const ResourceFormat formats[2] = {RGBA_8888, BGRA_8888};
2972 const ResourceProvider::TextureHint hints[4] = {
2973 ResourceProvider::TextureHintDefault,
2974 ResourceProvider::TextureHintImmutable,
2975 ResourceProvider::TextureHintFramebuffer,
2976 ResourceProvider::TextureHintImmutableFramebuffer,
2977 };
2978 for (size_t i = 0; i < arraysize(formats); ++i) {
2979 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
2980 // Lazy allocation. Don't allocate when creating the resource.
2981 ResourceProvider::ResourceId id = resource_provider->CreateResource(
2982 size, GL_CLAMP_TO_EDGE, hints[texture_id - 1], formats[i]);
2983
2984 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2985 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2986 bool is_immutable_hint =
2987 hints[texture_id - 1] & ResourceProvider::TextureHintImmutable;
2988 bool support_immutable_texture =
2989 is_immutable_hint && formats[i] == RGBA_8888;
2990 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2))
2991 .Times(support_immutable_texture ? 1 : 0);
2992 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _))
2993 .Times(support_immutable_texture ? 0 : 1);
2994 resource_provider->AllocateForTesting(id);
2995
2996 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2997 resource_provider->DeleteResource(id);
2998
2999 Mock::VerifyAndClearExpectations(context);
3000 }
3001 }
3002 }
3003
3004 TEST_P(ResourceProviderTest, TextureAllocationHint_BGRA) {
3005 // Only for GL textures.
3006 if (GetParam() != ResourceProvider::GLTexture)
3007 return;
3008 scoped_ptr<AllocationTrackingContext3D> context_owned(
3009 new StrictMock<AllocationTrackingContext3D>);
3010 AllocationTrackingContext3D* context = context_owned.get();
3011 context->set_support_texture_format_bgra8888(true);
3012 context->set_support_texture_storage(true);
3013 context->set_support_texture_usage(true);
3014
3015 FakeOutputSurfaceClient output_surface_client;
3016 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
3017 context_owned.PassAs<TestWebGraphicsContext3D>()));
3018 CHECK(output_surface->BindToClient(&output_surface_client));
3019
3020 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3021 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3022
3023 gfx::Size size(2, 2);
3024 const ResourceFormat formats[2] = {RGBA_8888, BGRA_8888};
2971 3025
2972 const ResourceProvider::TextureHint hints[4] = { 3026 const ResourceProvider::TextureHint hints[4] = {
2973 ResourceProvider::TextureHintDefault, 3027 ResourceProvider::TextureHintDefault,
2974 ResourceProvider::TextureHintImmutable, 3028 ResourceProvider::TextureHintImmutable,
2975 ResourceProvider::TextureHintFramebuffer, 3029 ResourceProvider::TextureHintFramebuffer,
2976 ResourceProvider::TextureHintImmutableFramebuffer, 3030 ResourceProvider::TextureHintImmutableFramebuffer,
2977 }; 3031 };
2978 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) { 3032 for (size_t i = 0; i < arraysize(formats); ++i) {
2979 // Lazy allocation. Don't allocate when creating the resource. 3033 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
2980 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3034 // Lazy allocation. Don't allocate when creating the resource.
2981 size, GL_CLAMP_TO_EDGE, hints[texture_id - 1], format); 3035 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3036 size, GL_CLAMP_TO_EDGE, hints[texture_id - 1], formats[i]);
2982 3037
2983 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3038 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2984 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3039 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2985 bool is_immutable_hint = 3040 bool is_immutable_hint =
2986 hints[texture_id - 1] & ResourceProvider::TextureHintImmutable; 3041 hints[texture_id - 1] & ResourceProvider::TextureHintImmutable;
2987 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2)) 3042 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2))
2988 .Times(is_immutable_hint ? 1 : 0); 3043 .Times(is_immutable_hint ? 1 : 0);
2989 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)) 3044 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _))
2990 .Times(is_immutable_hint ? 0 : 1); 3045 .Times(is_immutable_hint ? 0 : 1);
2991 resource_provider->AllocateForTesting(id); 3046 resource_provider->AllocateForTesting(id);
2992 3047
2993 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3048 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2994 resource_provider->DeleteResource(id); 3049 resource_provider->DeleteResource(id);
2995 3050
2996 Mock::VerifyAndClearExpectations(context); 3051 Mock::VerifyAndClearExpectations(context);
3052 }
2997 } 3053 }
2998 } 3054 }
2999 3055
3000 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { 3056 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
3001 if (GetParam() != ResourceProvider::GLTexture) 3057 if (GetParam() != ResourceProvider::GLTexture)
3002 return; 3058 return;
3003 scoped_ptr<AllocationTrackingContext3D> context_owned( 3059 scoped_ptr<AllocationTrackingContext3D> context_owned(
3004 new StrictMock<AllocationTrackingContext3D>); 3060 new StrictMock<AllocationTrackingContext3D>);
3005 AllocationTrackingContext3D* context = context_owned.get(); 3061 AllocationTrackingContext3D* context = context_owned.get();
3006 3062
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
3575 resource_provider->AllocateForTesting(id); 3631 resource_provider->AllocateForTesting(id);
3576 Mock::VerifyAndClearExpectations(context); 3632 Mock::VerifyAndClearExpectations(context);
3577 3633
3578 DCHECK_EQ(10u, context->PeekTextureId()); 3634 DCHECK_EQ(10u, context->PeekTextureId());
3579 resource_provider->DeleteResource(id); 3635 resource_provider->DeleteResource(id);
3580 } 3636 }
3581 } 3637 }
3582 3638
3583 } // namespace 3639 } // namespace
3584 } // namespace cc 3640 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/test/test_web_graphics_context_3d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698