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 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 bool* release_lost_resource, | 52 bool* release_lost_resource, |
53 BlockingTaskRunner** release_main_thread_task_runner, | 53 BlockingTaskRunner** release_main_thread_task_runner, |
54 uint32 sync_point, | 54 uint32 sync_point, |
55 bool lost_resource, | 55 bool lost_resource, |
56 BlockingTaskRunner* main_thread_task_runner) { | 56 BlockingTaskRunner* main_thread_task_runner) { |
57 *release_sync_point = sync_point; | 57 *release_sync_point = sync_point; |
58 *release_lost_resource = lost_resource; | 58 *release_lost_resource = lost_resource; |
59 *release_main_thread_task_runner = main_thread_task_runner; | 59 *release_main_thread_task_runner = main_thread_task_runner; |
60 } | 60 } |
61 | 61 |
62 static void SharedMemoryReleaseCallback( | 62 static void SharedBitmapReleaseCallback( |
63 scoped_ptr<base::SharedMemory> memory, | 63 scoped_ptr<SharedBitmap> bitmap, |
64 uint32 sync_point, | 64 uint32 sync_point, |
65 bool lost_resource, | 65 bool lost_resource, |
66 BlockingTaskRunner* main_thread_task_runner) { | 66 BlockingTaskRunner* main_thread_task_runner) { |
67 } | 67 } |
68 | 68 |
69 static void ReleaseSharedMemoryCallback( | 69 static void ReleaseSharedBitmapCallback( |
70 scoped_ptr<base::SharedMemory> shared_memory, | 70 scoped_ptr<SharedBitmap> shared_bitmap, |
71 bool* release_called, | 71 bool* release_called, |
72 uint32* release_sync_point, | 72 uint32* release_sync_point, |
73 bool* lost_resource_result, | 73 bool* lost_resource_result, |
74 uint32 sync_point, | 74 uint32 sync_point, |
75 bool lost_resource, | 75 bool lost_resource, |
76 BlockingTaskRunner* main_thread_task_runner) { | 76 BlockingTaskRunner* main_thread_task_runner) { |
77 *release_called = true; | 77 *release_called = true; |
78 *release_sync_point = sync_point; | 78 *release_sync_point = sync_point; |
79 *lost_resource_result = lost_resource; | 79 *lost_resource_result = lost_resource; |
80 } | 80 } |
81 | 81 |
82 static scoped_ptr<base::SharedMemory> CreateAndFillSharedMemory( | 82 static scoped_ptr<SharedBitmap> CreateAndFillSharedBitmap( |
| 83 SharedBitmapManager* manager, |
83 const gfx::Size& size, | 84 const gfx::Size& size, |
84 uint32_t value) { | 85 uint32_t value) { |
85 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); | 86 scoped_ptr<SharedBitmap> shared_bitmap = manager->AllocateSharedBitmap(size); |
86 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea())); | 87 CHECK(shared_bitmap); |
87 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory()); | 88 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_bitmap->pixels()); |
88 CHECK(pixels); | 89 CHECK(pixels); |
89 std::fill_n(pixels, size.GetArea(), value); | 90 std::fill_n(pixels, size.GetArea(), value); |
90 return shared_memory.Pass(); | 91 return shared_bitmap.Pass(); |
91 } | 92 } |
92 | 93 |
93 class TextureStateTrackingContext : public TestWebGraphicsContext3D { | 94 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
94 public: | 95 public: |
95 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); | 96 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); |
96 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); | 97 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); |
97 MOCK_METHOD1(waitSyncPoint, void(GLuint sync_point)); | 98 MOCK_METHOD1(waitSyncPoint, void(GLuint sync_point)); |
98 MOCK_METHOD0(insertSyncPoint, GLuint(void)); | 99 MOCK_METHOD0(insertSyncPoint, GLuint(void)); |
99 MOCK_METHOD2(produceTextureCHROMIUM, | 100 MOCK_METHOD2(produceTextureCHROMIUM, |
100 void(GLenum target, const GLbyte* mailbox)); | 101 void(GLenum target, const GLbyte* mailbox)); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 uint32* sync_point) { | 460 uint32* sync_point) { |
460 if (GetParam() == ResourceProvider::GLTexture) { | 461 if (GetParam() == ResourceProvider::GLTexture) { |
461 unsigned texture = child_context_->createTexture(); | 462 unsigned texture = child_context_->createTexture(); |
462 gpu::Mailbox gpu_mailbox; | 463 gpu::Mailbox gpu_mailbox; |
463 child_context_->bindTexture(GL_TEXTURE_2D, texture); | 464 child_context_->bindTexture(GL_TEXTURE_2D, texture); |
464 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); | 465 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); |
465 child_context_->produceTextureCHROMIUM(GL_TEXTURE_2D, gpu_mailbox.name); | 466 child_context_->produceTextureCHROMIUM(GL_TEXTURE_2D, gpu_mailbox.name); |
466 *sync_point = child_context_->insertSyncPoint(); | 467 *sync_point = child_context_->insertSyncPoint(); |
467 EXPECT_LT(0u, *sync_point); | 468 EXPECT_LT(0u, *sync_point); |
468 | 469 |
469 scoped_ptr<base::SharedMemory> shared_memory; | 470 scoped_ptr<SharedBitmap> shared_bitmap; |
470 scoped_ptr<SingleReleaseCallbackImpl> callback = | 471 scoped_ptr<SingleReleaseCallbackImpl> callback = |
471 SingleReleaseCallbackImpl::Create( | 472 SingleReleaseCallbackImpl::Create(base::Bind( |
472 base::Bind(ReleaseSharedMemoryCallback, | 473 ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap), |
473 base::Passed(&shared_memory), | 474 release_called, release_sync_point, lost_resource)); |
474 release_called, | |
475 release_sync_point, | |
476 lost_resource)); | |
477 return child_resource_provider_->CreateResourceFromTextureMailbox( | 475 return child_resource_provider_->CreateResourceFromTextureMailbox( |
478 TextureMailbox(gpu_mailbox, GL_TEXTURE_2D, *sync_point), | 476 TextureMailbox(gpu_mailbox, GL_TEXTURE_2D, *sync_point), |
479 callback.Pass()); | 477 callback.Pass()); |
480 } else { | 478 } else { |
481 gfx::Size size(64, 64); | 479 gfx::Size size(64, 64); |
482 scoped_ptr<base::SharedMemory> shared_memory( | 480 scoped_ptr<SharedBitmap> shared_bitmap( |
483 CreateAndFillSharedMemory(size, 0)); | 481 CreateAndFillSharedBitmap(shared_bitmap_manager_.get(), size, 0)); |
484 | 482 |
485 base::SharedMemory* shared_memory_ptr = shared_memory.get(); | 483 SharedBitmap* shared_bitmap_ptr = shared_bitmap.get(); |
486 scoped_ptr<SingleReleaseCallbackImpl> callback = | 484 scoped_ptr<SingleReleaseCallbackImpl> callback = |
487 SingleReleaseCallbackImpl::Create( | 485 SingleReleaseCallbackImpl::Create(base::Bind( |
488 base::Bind(ReleaseSharedMemoryCallback, | 486 ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap), |
489 base::Passed(&shared_memory), | 487 release_called, release_sync_point, lost_resource)); |
490 release_called, | |
491 release_sync_point, | |
492 lost_resource)); | |
493 return child_resource_provider_->CreateResourceFromTextureMailbox( | 488 return child_resource_provider_->CreateResourceFromTextureMailbox( |
494 TextureMailbox(shared_memory_ptr, size), callback.Pass()); | 489 TextureMailbox(shared_bitmap_ptr, size), callback.Pass()); |
495 } | 490 } |
496 } | 491 } |
497 | 492 |
498 protected: | 493 protected: |
499 scoped_ptr<ContextSharedData> shared_data_; | 494 scoped_ptr<ContextSharedData> shared_data_; |
500 ResourceProviderContext* context3d_; | 495 ResourceProviderContext* context3d_; |
501 ResourceProviderContext* child_context_; | 496 ResourceProviderContext* child_context_; |
502 FakeOutputSurfaceClient output_surface_client_; | 497 FakeOutputSurfaceClient output_surface_client_; |
503 FakeOutputSurfaceClient child_output_surface_client_; | 498 FakeOutputSurfaceClient child_output_surface_client_; |
504 scoped_ptr<OutputSurface> output_surface_; | 499 scoped_ptr<OutputSurface> output_surface_; |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 970 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
976 uint8_t data1[4] = { 1, 2, 3, 4 }; | 971 uint8_t data1[4] = { 1, 2, 3, 4 }; |
977 gfx::Rect rect(size); | 972 gfx::Rect rect(size); |
978 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); | 973 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); |
979 | 974 |
980 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( | 975 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( |
981 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 976 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
982 uint8_t data2[4] = { 5, 5, 5, 5 }; | 977 uint8_t data2[4] = { 5, 5, 5, 5 }; |
983 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); | 978 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); |
984 | 979 |
985 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 980 scoped_ptr<SharedBitmap> shared_bitmap(CreateAndFillSharedBitmap( |
986 shared_memory->CreateAndMapAnonymous(1); | 981 shared_bitmap_manager_.get(), gfx::Size(1, 1), 0)); |
987 base::SharedMemory* shared_memory_ptr = shared_memory.get(); | 982 SharedBitmap* shared_bitmap_ptr = shared_bitmap.get(); |
988 ResourceProvider::ResourceId id3 = | 983 ResourceProvider::ResourceId id3 = |
989 child_resource_provider_->CreateResourceFromTextureMailbox( | 984 child_resource_provider_->CreateResourceFromTextureMailbox( |
990 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)), | 985 TextureMailbox(shared_bitmap_ptr, gfx::Size(1, 1)), |
991 SingleReleaseCallbackImpl::Create(base::Bind( | 986 SingleReleaseCallbackImpl::Create(base::Bind( |
992 &SharedMemoryReleaseCallback, base::Passed(&shared_memory)))); | 987 &SharedBitmapReleaseCallback, base::Passed(&shared_bitmap)))); |
993 | 988 |
994 ReturnedResourceArray returned_to_child; | 989 ReturnedResourceArray returned_to_child; |
995 int child_id = | 990 int child_id = |
996 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 991 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
997 { | 992 { |
998 // Transfer some resources to the parent. | 993 // Transfer some resources to the parent. |
999 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 994 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
1000 resource_ids_to_transfer.push_back(id1); | 995 resource_ids_to_transfer.push_back(id1); |
1001 resource_ids_to_transfer.push_back(id2); | 996 resource_ids_to_transfer.push_back(id2); |
1002 resource_ids_to_transfer.push_back(id3); | 997 resource_ids_to_transfer.push_back(id3); |
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2549 Mock::VerifyAndClearExpectations(context); | 2544 Mock::VerifyAndClearExpectations(context); |
2550 } | 2545 } |
2551 } | 2546 } |
2552 | 2547 |
2553 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { | 2548 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { |
2554 if (GetParam() != ResourceProvider::Bitmap) | 2549 if (GetParam() != ResourceProvider::Bitmap) |
2555 return; | 2550 return; |
2556 | 2551 |
2557 gfx::Size size(64, 64); | 2552 gfx::Size size(64, 64); |
2558 const uint32_t kBadBeef = 0xbadbeef; | 2553 const uint32_t kBadBeef = 0xbadbeef; |
2559 scoped_ptr<base::SharedMemory> shared_memory( | 2554 scoped_ptr<SharedBitmap> shared_bitmap( |
2560 CreateAndFillSharedMemory(size, kBadBeef)); | 2555 CreateAndFillSharedBitmap(shared_bitmap_manager_.get(), size, kBadBeef)); |
2561 | 2556 |
2562 FakeOutputSurfaceClient output_surface_client; | 2557 FakeOutputSurfaceClient output_surface_client; |
2563 scoped_ptr<OutputSurface> output_surface( | 2558 scoped_ptr<OutputSurface> output_surface( |
2564 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 2559 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
2565 new SoftwareOutputDevice))); | 2560 new SoftwareOutputDevice))); |
2566 CHECK(output_surface->BindToClient(&output_surface_client)); | 2561 CHECK(output_surface->BindToClient(&output_surface_client)); |
2567 | 2562 |
2568 scoped_ptr<ResourceProvider> resource_provider( | 2563 scoped_ptr<ResourceProvider> resource_provider( |
2569 ResourceProvider::Create(output_surface.get(), | 2564 ResourceProvider::Create(output_surface.get(), |
2570 shared_bitmap_manager_.get(), | 2565 shared_bitmap_manager_.get(), |
2571 gpu_memory_buffer_manager_.get(), | 2566 gpu_memory_buffer_manager_.get(), |
2572 main_thread_task_runner_.get(), | 2567 main_thread_task_runner_.get(), |
2573 0, | 2568 0, |
2574 false, | 2569 false, |
2575 1)); | 2570 1)); |
2576 | 2571 |
2577 uint32 release_sync_point = 0; | 2572 uint32 release_sync_point = 0; |
2578 bool lost_resource = false; | 2573 bool lost_resource = false; |
2579 BlockingTaskRunner* main_thread_task_runner = NULL; | 2574 BlockingTaskRunner* main_thread_task_runner = NULL; |
2580 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2575 scoped_ptr<SingleReleaseCallbackImpl> callback = |
2581 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, | 2576 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, |
2582 &release_sync_point, | 2577 &release_sync_point, |
2583 &lost_resource, | 2578 &lost_resource, |
2584 &main_thread_task_runner)); | 2579 &main_thread_task_runner)); |
2585 TextureMailbox mailbox(shared_memory.get(), size); | 2580 TextureMailbox mailbox(shared_bitmap.get(), size); |
2586 | 2581 |
2587 ResourceProvider::ResourceId id = | 2582 ResourceProvider::ResourceId id = |
2588 resource_provider->CreateResourceFromTextureMailbox( | 2583 resource_provider->CreateResourceFromTextureMailbox( |
2589 mailbox, callback.Pass()); | 2584 mailbox, callback.Pass()); |
2590 EXPECT_NE(0u, id); | 2585 EXPECT_NE(0u, id); |
2591 | 2586 |
2592 { | 2587 { |
2593 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 2588 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
2594 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 2589 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
2595 EXPECT_EQ(sk_bitmap->width(), size.width()); | 2590 EXPECT_EQ(sk_bitmap->width(), size.width()); |
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3710 resource_provider->AllocateForTesting(id); | 3705 resource_provider->AllocateForTesting(id); |
3711 Mock::VerifyAndClearExpectations(context); | 3706 Mock::VerifyAndClearExpectations(context); |
3712 | 3707 |
3713 DCHECK_EQ(10u, context->PeekTextureId()); | 3708 DCHECK_EQ(10u, context->PeekTextureId()); |
3714 resource_provider->DeleteResource(id); | 3709 resource_provider->DeleteResource(id); |
3715 } | 3710 } |
3716 } | 3711 } |
3717 | 3712 |
3718 } // namespace | 3713 } // namespace |
3719 } // namespace cc | 3714 } // namespace cc |
OLD | NEW |