| 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 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 3213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3224 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 3224 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 3225 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); | 3225 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); |
| 3226 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); | 3226 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); |
| 3227 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); | 3227 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); |
| 3228 resource_provider->CopyToResource(id, pixels, size); | 3228 resource_provider->CopyToResource(id, pixels, size); |
| 3229 | 3229 |
| 3230 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3230 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 3231 resource_provider->DeleteResource(id); | 3231 resource_provider->DeleteResource(id); |
| 3232 | 3232 |
| 3233 Mock::VerifyAndClearExpectations(context); | 3233 Mock::VerifyAndClearExpectations(context); |
| 3234 | |
| 3235 // Same for async version. | |
| 3236 id = resource_provider->CreateResource( | |
| 3237 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); | |
| 3238 resource_provider->AcquirePixelBuffer(id); | |
| 3239 | |
| 3240 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | |
| 3241 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | |
| 3242 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | |
| 3243 .Times(1); | |
| 3244 resource_provider->BeginSetPixels(id); | |
| 3245 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); | |
| 3246 | |
| 3247 resource_provider->ReleasePixelBuffer(id); | |
| 3248 | |
| 3249 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | |
| 3250 resource_provider->DeleteResource(id); | |
| 3251 | |
| 3252 Mock::VerifyAndClearExpectations(context); | |
| 3253 } | 3234 } |
| 3254 | 3235 |
| 3255 TEST_P(ResourceProviderTest, TextureAllocationHint) { | 3236 TEST_P(ResourceProviderTest, TextureAllocationHint) { |
| 3256 // Only for GL textures. | 3237 // Only for GL textures. |
| 3257 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3238 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3258 return; | 3239 return; |
| 3259 scoped_ptr<AllocationTrackingContext3D> context_owned( | 3240 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 3260 new StrictMock<AllocationTrackingContext3D>); | 3241 new StrictMock<AllocationTrackingContext3D>); |
| 3261 AllocationTrackingContext3D* context = context_owned.get(); | 3242 AllocationTrackingContext3D* context = context_owned.get(); |
| 3262 context->set_support_texture_storage(true); | 3243 context->set_support_texture_storage(true); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3354 resource_provider->AllocateForTesting(id); | 3335 resource_provider->AllocateForTesting(id); |
| 3355 | 3336 |
| 3356 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3337 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 3357 resource_provider->DeleteResource(id); | 3338 resource_provider->DeleteResource(id); |
| 3358 | 3339 |
| 3359 Mock::VerifyAndClearExpectations(context); | 3340 Mock::VerifyAndClearExpectations(context); |
| 3360 } | 3341 } |
| 3361 } | 3342 } |
| 3362 } | 3343 } |
| 3363 | 3344 |
| 3364 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { | |
| 3365 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | |
| 3366 return; | |
| 3367 scoped_ptr<AllocationTrackingContext3D> context_owned( | |
| 3368 new StrictMock<AllocationTrackingContext3D>); | |
| 3369 AllocationTrackingContext3D* context = context_owned.get(); | |
| 3370 | |
| 3371 FakeOutputSurfaceClient output_surface_client; | |
| 3372 scoped_ptr<OutputSurface> output_surface( | |
| 3373 FakeOutputSurface::Create3d(context_owned.Pass())); | |
| 3374 CHECK(output_surface->BindToClient(&output_surface_client)); | |
| 3375 | |
| 3376 gfx::Size size(2, 2); | |
| 3377 ResourceFormat format = RGBA_8888; | |
| 3378 ResourceId id = 0; | |
| 3379 int texture_id = 123; | |
| 3380 | |
| 3381 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | |
| 3382 output_surface.get(), shared_bitmap_manager_.get(), | |
| 3383 gpu_memory_buffer_manager_.get(), NULL, 0, false, 1, | |
| 3384 use_image_texture_targets_)); | |
| 3385 | |
| 3386 id = resource_provider->CreateResource( | |
| 3387 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); | |
| 3388 resource_provider->AcquirePixelBuffer(id); | |
| 3389 | |
| 3390 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | |
| 3391 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | |
| 3392 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | |
| 3393 .Times(1); | |
| 3394 resource_provider->BeginSetPixels(id); | |
| 3395 | |
| 3396 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | |
| 3397 | |
| 3398 resource_provider->ReleasePixelBuffer(id); | |
| 3399 | |
| 3400 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | |
| 3401 resource_provider->DeleteResource(id); | |
| 3402 | |
| 3403 Mock::VerifyAndClearExpectations(context); | |
| 3404 } | |
| 3405 | |
| 3406 TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) { | |
| 3407 // Only for GL textures. | |
| 3408 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | |
| 3409 return; | |
| 3410 scoped_ptr<AllocationTrackingContext3D> context_owned( | |
| 3411 new StrictMock<AllocationTrackingContext3D>); | |
| 3412 AllocationTrackingContext3D* context = context_owned.get(); | |
| 3413 | |
| 3414 FakeOutputSurfaceClient output_surface_client; | |
| 3415 scoped_ptr<OutputSurface> output_surface( | |
| 3416 FakeOutputSurface::Create3d(context_owned.Pass())); | |
| 3417 CHECK(output_surface->BindToClient(&output_surface_client)); | |
| 3418 | |
| 3419 gfx::Size size(2, 2); | |
| 3420 ResourceFormat format = RGBA_8888; | |
| 3421 ResourceId id = 0; | |
| 3422 int texture_id = 123; | |
| 3423 | |
| 3424 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | |
| 3425 output_surface.get(), shared_bitmap_manager_.get(), | |
| 3426 gpu_memory_buffer_manager_.get(), NULL, 0, false, 1, | |
| 3427 use_image_texture_targets_)); | |
| 3428 | |
| 3429 id = resource_provider->CreateResource( | |
| 3430 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); | |
| 3431 resource_provider->AcquirePixelBuffer(id); | |
| 3432 | |
| 3433 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | |
| 3434 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | |
| 3435 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | |
| 3436 .Times(1); | |
| 3437 resource_provider->BeginSetPixels(id); | |
| 3438 | |
| 3439 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | |
| 3440 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | |
| 3441 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); | |
| 3442 resource_provider->ForceSetPixelsToComplete(id); | |
| 3443 | |
| 3444 resource_provider->ReleasePixelBuffer(id); | |
| 3445 | |
| 3446 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | |
| 3447 resource_provider->DeleteResource(id); | |
| 3448 | |
| 3449 Mock::VerifyAndClearExpectations(context); | |
| 3450 } | |
| 3451 | |
| 3452 TEST_P(ResourceProviderTest, PixelBufferLostContext) { | |
| 3453 scoped_ptr<AllocationTrackingContext3D> context_owned( | |
| 3454 new NiceMock<AllocationTrackingContext3D>); | |
| 3455 AllocationTrackingContext3D* context = context_owned.get(); | |
| 3456 | |
| 3457 FakeOutputSurfaceClient output_surface_client; | |
| 3458 scoped_ptr<OutputSurface> output_surface( | |
| 3459 FakeOutputSurface::Create3d(context_owned.Pass())); | |
| 3460 CHECK(output_surface->BindToClient(&output_surface_client)); | |
| 3461 | |
| 3462 gfx::Size size(2, 2); | |
| 3463 ResourceFormat format = RGBA_8888; | |
| 3464 ResourceId id = 0; | |
| 3465 int texture_id = 123; | |
| 3466 | |
| 3467 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | |
| 3468 output_surface.get(), shared_bitmap_manager_.get(), | |
| 3469 gpu_memory_buffer_manager_.get(), NULL, 0, false, 1, | |
| 3470 use_image_texture_targets_)); | |
| 3471 | |
| 3472 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); | |
| 3473 | |
| 3474 id = resource_provider->CreateResource( | |
| 3475 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); | |
| 3476 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
| 3477 GL_INNOCENT_CONTEXT_RESET_ARB); | |
| 3478 | |
| 3479 resource_provider->AcquirePixelBuffer(id); | |
| 3480 int stride; | |
| 3481 void* buffer = resource_provider->MapPixelBuffer(id, &stride); | |
| 3482 EXPECT_FALSE(buffer); | |
| 3483 resource_provider->UnmapPixelBuffer(id); | |
| 3484 Mock::VerifyAndClearExpectations(context); | |
| 3485 } | |
| 3486 | |
| 3487 TEST_P(ResourceProviderTest, Image_GLTexture) { | 3345 TEST_P(ResourceProviderTest, Image_GLTexture) { |
| 3488 // Only for GL textures. | 3346 // Only for GL textures. |
| 3489 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3347 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3490 return; | 3348 return; |
| 3491 scoped_ptr<AllocationTrackingContext3D> context_owned( | 3349 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 3492 new StrictMock<AllocationTrackingContext3D>); | 3350 new StrictMock<AllocationTrackingContext3D>); |
| 3493 AllocationTrackingContext3D* context = context_owned.get(); | 3351 AllocationTrackingContext3D* context = context_owned.get(); |
| 3494 | 3352 |
| 3495 FakeOutputSurfaceClient output_surface_client; | 3353 FakeOutputSurfaceClient output_surface_client; |
| 3496 scoped_ptr<OutputSurface> output_surface( | 3354 scoped_ptr<OutputSurface> output_surface( |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3700 resource_provider->AllocateForTesting(id); | 3558 resource_provider->AllocateForTesting(id); |
| 3701 Mock::VerifyAndClearExpectations(context); | 3559 Mock::VerifyAndClearExpectations(context); |
| 3702 | 3560 |
| 3703 DCHECK_EQ(10u, context->PeekTextureId()); | 3561 DCHECK_EQ(10u, context->PeekTextureId()); |
| 3704 resource_provider->DeleteResource(id); | 3562 resource_provider->DeleteResource(id); |
| 3705 } | 3563 } |
| 3706 } | 3564 } |
| 3707 | 3565 |
| 3708 } // namespace | 3566 } // namespace |
| 3709 } // namespace cc | 3567 } // namespace cc |
| OLD | NEW |