| 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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 using blink::WGC3Dbyte; | 37 using blink::WGC3Dbyte; |
| 38 using blink::WGC3Denum; | 38 using blink::WGC3Denum; |
| 39 using blink::WGC3Dint; | 39 using blink::WGC3Dint; |
| 40 using blink::WGC3Dsizei; | 40 using blink::WGC3Dsizei; |
| 41 using blink::WGC3Duint; | 41 using blink::WGC3Duint; |
| 42 using blink::WebGLId; | 42 using blink::WebGLId; |
| 43 | 43 |
| 44 namespace cc { | 44 namespace cc { |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} | 47 static void EmptyReleaseCallback(uint32 sync_point, bool lost_resource) {} |
| 48 | 48 |
| 49 static void SharedMemoryReleaseCallback(scoped_ptr<base::SharedMemory> memory, | 49 static void SharedMemoryReleaseCallback(scoped_ptr<base::SharedMemory> memory, |
| 50 unsigned sync_point, | 50 uint32 sync_point, |
| 51 bool lost_resource) {} | 51 bool lost_resource) {} |
| 52 | 52 |
| 53 static void ReleaseTextureMailbox(unsigned* release_sync_point, | 53 static void ReleaseTextureMailbox(uint32* release_sync_point, |
| 54 bool* release_lost_resource, | 54 bool* release_lost_resource, |
| 55 unsigned sync_point, | 55 uint32 sync_point, |
| 56 bool lost_resource) { | 56 bool lost_resource) { |
| 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 } | 59 } |
| 60 | 60 |
| 61 static void ReleaseSharedMemoryCallback( | 61 static void ReleaseSharedMemoryCallback( |
| 62 scoped_ptr<base::SharedMemory> shared_memory, | 62 scoped_ptr<base::SharedMemory> shared_memory, |
| 63 bool* release_called, | 63 bool* release_called, |
| 64 unsigned* release_sync_point, | 64 uint32* release_sync_point, |
| 65 bool* lost_resource_result, | 65 bool* lost_resource_result, |
| 66 unsigned sync_point, | 66 uint32 sync_point, |
| 67 bool lost_resource) { | 67 bool lost_resource) { |
| 68 *release_called = true; | 68 *release_called = true; |
| 69 *release_sync_point = sync_point; | 69 *release_sync_point = sync_point; |
| 70 *lost_resource_result = lost_resource; | 70 *lost_resource_result = lost_resource; |
| 71 } | 71 } |
| 72 | 72 |
| 73 static scoped_ptr<base::SharedMemory> CreateAndFillSharedMemory( | 73 static scoped_ptr<base::SharedMemory> CreateAndFillSharedMemory( |
| 74 gfx::Size size, | 74 gfx::Size size, |
| 75 uint32_t value) { | 75 uint32_t value) { |
| 76 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); | 76 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); |
| 77 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea())); | 77 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea())); |
| 78 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory()); | 78 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory()); |
| 79 CHECK(pixels); | 79 CHECK(pixels); |
| 80 std::fill_n(pixels, size.GetArea(), value); | 80 std::fill_n(pixels, size.GetArea(), value); |
| 81 return shared_memory.Pass(); | 81 return shared_memory.Pass(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 class TextureStateTrackingContext : public TestWebGraphicsContext3D { | 84 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
| 85 public: | 85 public: |
| 86 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); | 86 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
| 87 MOCK_METHOD3(texParameteri, | 87 MOCK_METHOD3(texParameteri, |
| 88 void(WGC3Denum target, WGC3Denum pname, WGC3Dint param)); | 88 void(WGC3Denum target, WGC3Denum pname, WGC3Dint param)); |
| 89 MOCK_METHOD1(waitSyncPoint, void(unsigned sync_point)); | 89 MOCK_METHOD1(waitSyncPoint, void(uint32 sync_point)); |
| 90 MOCK_METHOD0(insertSyncPoint, unsigned(void)); | 90 MOCK_METHOD0(insertSyncPoint, uint32(void)); |
| 91 MOCK_METHOD2(produceTextureCHROMIUM, void(WGC3Denum target, | 91 MOCK_METHOD2(produceTextureCHROMIUM, void(WGC3Denum target, |
| 92 const WGC3Dbyte* mailbox)); | 92 const WGC3Dbyte* mailbox)); |
| 93 MOCK_METHOD2(consumeTextureCHROMIUM, void(WGC3Denum target, | 93 MOCK_METHOD2(consumeTextureCHROMIUM, void(WGC3Denum target, |
| 94 const WGC3Dbyte* mailbox)); | 94 const WGC3Dbyte* mailbox)); |
| 95 | 95 |
| 96 // Force all textures to be consecutive numbers starting at "1", | 96 // Force all textures to be consecutive numbers starting at "1", |
| 97 // so we easily can test for them. | 97 // so we easily can test for them. |
| 98 virtual blink::WebGLId NextTextureId() OVERRIDE { | 98 virtual blink::WebGLId NextTextureId() OVERRIDE { |
| 99 base::AutoLock lock(namespace_->lock); | 99 base::AutoLock lock(namespace_->lock); |
| 100 return namespace_->next_texture_id++; | 100 return namespace_->next_texture_id++; |
| 101 } | 101 } |
| 102 virtual void RetireTextureId(blink::WebGLId) OVERRIDE { | 102 virtual void RetireTextureId(blink::WebGLId) OVERRIDE { |
| 103 } | 103 } |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // Shared data between multiple ResourceProviderContext. This contains mailbox | 106 // Shared data between multiple ResourceProviderContext. This contains mailbox |
| 107 // contents as well as information about sync points. | 107 // contents as well as information about sync points. |
| 108 class ContextSharedData { | 108 class ContextSharedData { |
| 109 public: | 109 public: |
| 110 static scoped_ptr<ContextSharedData> Create() { | 110 static scoped_ptr<ContextSharedData> Create() { |
| 111 return make_scoped_ptr(new ContextSharedData()); | 111 return make_scoped_ptr(new ContextSharedData()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 unsigned InsertSyncPoint() { return next_sync_point_++; } | 114 uint32 InsertSyncPoint() { return next_sync_point_++; } |
| 115 | 115 |
| 116 void GenMailbox(WGC3Dbyte* mailbox) { | 116 void GenMailbox(WGC3Dbyte* mailbox) { |
| 117 memset(mailbox, 0, sizeof(WGC3Dbyte[64])); | 117 memset(mailbox, 0, sizeof(WGC3Dbyte[64])); |
| 118 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_)); | 118 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_)); |
| 119 ++next_mailbox_; | 119 ++next_mailbox_; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void ProduceTexture(const WGC3Dbyte* mailbox_name, | 122 void ProduceTexture(const WGC3Dbyte* mailbox_name, |
| 123 unsigned sync_point, | 123 uint32 sync_point, |
| 124 scoped_refptr<TestTexture> texture) { | 124 scoped_refptr<TestTexture> texture) { |
| 125 unsigned mailbox = 0; | 125 unsigned mailbox = 0; |
| 126 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); | 126 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); |
| 127 ASSERT_TRUE(mailbox && mailbox < next_mailbox_); | 127 ASSERT_TRUE(mailbox && mailbox < next_mailbox_); |
| 128 textures_[mailbox] = texture; | 128 textures_[mailbox] = texture; |
| 129 ASSERT_LT(sync_point_for_mailbox_[mailbox], sync_point); | 129 ASSERT_LT(sync_point_for_mailbox_[mailbox], sync_point); |
| 130 sync_point_for_mailbox_[mailbox] = sync_point; | 130 sync_point_for_mailbox_[mailbox] = sync_point; |
| 131 } | 131 } |
| 132 | 132 |
| 133 scoped_refptr<TestTexture> ConsumeTexture(const WGC3Dbyte* mailbox_name, | 133 scoped_refptr<TestTexture> ConsumeTexture(const WGC3Dbyte* mailbox_name, |
| 134 unsigned sync_point) { | 134 uint32 sync_point) { |
| 135 unsigned mailbox = 0; | 135 unsigned mailbox = 0; |
| 136 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); | 136 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); |
| 137 DCHECK(mailbox && mailbox < next_mailbox_); | 137 DCHECK(mailbox && mailbox < next_mailbox_); |
| 138 | 138 |
| 139 // If the latest sync point the context has waited on is before the sync | 139 // If the latest sync point the context has waited on is before the sync |
| 140 // point for when the mailbox was set, pretend we never saw that | 140 // point for when the mailbox was set, pretend we never saw that |
| 141 // ProduceTexture. | 141 // ProduceTexture. |
| 142 if (sync_point_for_mailbox_[mailbox] > sync_point) { | 142 if (sync_point_for_mailbox_[mailbox] > sync_point) { |
| 143 NOTREACHED(); | 143 NOTREACHED(); |
| 144 return scoped_refptr<TestTexture>(); | 144 return scoped_refptr<TestTexture>(); |
| 145 } | 145 } |
| 146 return textures_[mailbox]; | 146 return textures_[mailbox]; |
| 147 } | 147 } |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 ContextSharedData() : next_sync_point_(1), next_mailbox_(1) {} | 150 ContextSharedData() : next_sync_point_(1), next_mailbox_(1) {} |
| 151 | 151 |
| 152 unsigned next_sync_point_; | 152 uint32 next_sync_point_; |
| 153 unsigned next_mailbox_; | 153 unsigned next_mailbox_; |
| 154 typedef base::hash_map<unsigned, scoped_refptr<TestTexture> > TextureMap; | 154 typedef base::hash_map<unsigned, scoped_refptr<TestTexture> > TextureMap; |
| 155 TextureMap textures_; | 155 TextureMap textures_; |
| 156 base::hash_map<unsigned, unsigned> sync_point_for_mailbox_; | 156 base::hash_map<unsigned, uint32> sync_point_for_mailbox_; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 class ResourceProviderContext : public TestWebGraphicsContext3D { | 159 class ResourceProviderContext : public TestWebGraphicsContext3D { |
| 160 public: | 160 public: |
| 161 static scoped_ptr<ResourceProviderContext> Create( | 161 static scoped_ptr<ResourceProviderContext> Create( |
| 162 ContextSharedData* shared_data) { | 162 ContextSharedData* shared_data) { |
| 163 return make_scoped_ptr(new ResourceProviderContext(shared_data)); | 163 return make_scoped_ptr(new ResourceProviderContext(shared_data)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 virtual unsigned insertSyncPoint() OVERRIDE { | 166 virtual uint32 insertSyncPoint() OVERRIDE { |
| 167 unsigned sync_point = shared_data_->InsertSyncPoint(); | 167 uint32 sync_point = shared_data_->InsertSyncPoint(); |
| 168 // Commit the produceTextureCHROMIUM calls at this point, so that | 168 // Commit the produceTextureCHROMIUM calls at this point, so that |
| 169 // they're associated with the sync point. | 169 // they're associated with the sync point. |
| 170 for (PendingProduceTextureList::iterator it = | 170 for (PendingProduceTextureList::iterator it = |
| 171 pending_produce_textures_.begin(); | 171 pending_produce_textures_.begin(); |
| 172 it != pending_produce_textures_.end(); | 172 it != pending_produce_textures_.end(); |
| 173 ++it) { | 173 ++it) { |
| 174 shared_data_->ProduceTexture( | 174 shared_data_->ProduceTexture( |
| 175 (*it)->mailbox, sync_point, (*it)->texture); | 175 (*it)->mailbox, sync_point, (*it)->texture); |
| 176 } | 176 } |
| 177 pending_produce_textures_.clear(); | 177 pending_produce_textures_.clear(); |
| 178 return sync_point; | 178 return sync_point; |
| 179 } | 179 } |
| 180 | 180 |
| 181 virtual void waitSyncPoint(unsigned sync_point) OVERRIDE { | 181 virtual void waitSyncPoint(uint32 sync_point) OVERRIDE { |
| 182 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); | 182 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); |
| 183 } | 183 } |
| 184 | 184 |
| 185 virtual void texStorage2DEXT(WGC3Denum target, | 185 virtual void texStorage2DEXT(WGC3Denum target, |
| 186 WGC3Dint levels, | 186 WGC3Dint levels, |
| 187 WGC3Duint internalformat, | 187 WGC3Duint internalformat, |
| 188 WGC3Dint width, | 188 WGC3Dint width, |
| 189 WGC3Dint height) OVERRIDE { | 189 WGC3Dint height) OVERRIDE { |
| 190 CheckTextureIsBound(target); | 190 CheckTextureIsBound(target); |
| 191 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 191 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 src += in_pitch; | 325 src += in_pitch; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 struct PendingProduceTexture { | 329 struct PendingProduceTexture { |
| 330 WGC3Dbyte mailbox[64]; | 330 WGC3Dbyte mailbox[64]; |
| 331 scoped_refptr<TestTexture> texture; | 331 scoped_refptr<TestTexture> texture; |
| 332 }; | 332 }; |
| 333 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; | 333 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; |
| 334 ContextSharedData* shared_data_; | 334 ContextSharedData* shared_data_; |
| 335 unsigned last_waited_sync_point_; | 335 uint32 last_waited_sync_point_; |
| 336 PendingProduceTextureList pending_produce_textures_; | 336 PendingProduceTextureList pending_produce_textures_; |
| 337 }; | 337 }; |
| 338 | 338 |
| 339 void FreeSharedBitmap(SharedBitmap* shared_bitmap) { | 339 void FreeSharedBitmap(SharedBitmap* shared_bitmap) { |
| 340 delete shared_bitmap->memory(); | 340 delete shared_bitmap->memory(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} | 343 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} |
| 344 | 344 |
| 345 class TestSharedBitmapManager : public SharedBitmapManager { | 345 class TestSharedBitmapManager : public SharedBitmapManager { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 475 |
| 476 static void SetResourceFilter(ResourceProvider* resource_provider, | 476 static void SetResourceFilter(ResourceProvider* resource_provider, |
| 477 ResourceProvider::ResourceId id, | 477 ResourceProvider::ResourceId id, |
| 478 WGC3Denum filter) { | 478 WGC3Denum filter) { |
| 479 ResourceProvider::ScopedSamplerGL sampler( | 479 ResourceProvider::ScopedSamplerGL sampler( |
| 480 resource_provider, id, GL_TEXTURE_2D, filter); | 480 resource_provider, id, GL_TEXTURE_2D, filter); |
| 481 } | 481 } |
| 482 | 482 |
| 483 ResourceProviderContext* context() { return context3d_; } | 483 ResourceProviderContext* context() { return context3d_; } |
| 484 | 484 |
| 485 ResourceProvider::ResourceId CreateChildMailbox(unsigned* release_sync_point, | 485 ResourceProvider::ResourceId CreateChildMailbox(uint32* release_sync_point, |
| 486 bool* lost_resource, | 486 bool* lost_resource, |
| 487 bool* release_called, | 487 bool* release_called, |
| 488 unsigned* sync_point) { | 488 uint32* sync_point) { |
| 489 if (GetParam() == ResourceProvider::GLTexture) { | 489 if (GetParam() == ResourceProvider::GLTexture) { |
| 490 unsigned texture = child_context_->createTexture(); | 490 unsigned texture = child_context_->createTexture(); |
| 491 gpu::Mailbox gpu_mailbox; | 491 gpu::Mailbox gpu_mailbox; |
| 492 child_context_->bindTexture(GL_TEXTURE_2D, texture); | 492 child_context_->bindTexture(GL_TEXTURE_2D, texture); |
| 493 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); | 493 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); |
| 494 child_context_->produceTextureCHROMIUM(GL_TEXTURE_2D, gpu_mailbox.name); | 494 child_context_->produceTextureCHROMIUM(GL_TEXTURE_2D, gpu_mailbox.name); |
| 495 *sync_point = child_context_->insertSyncPoint(); | 495 *sync_point = child_context_->insertSyncPoint(); |
| 496 EXPECT_LT(0u, *sync_point); | 496 EXPECT_LT(0u, *sync_point); |
| 497 | 497 |
| 498 scoped_ptr<base::SharedMemory> shared_memory; | 498 scoped_ptr<base::SharedMemory> shared_memory; |
| 499 scoped_ptr<SingleReleaseCallback> callback = | 499 scoped_ptr<SingleReleaseCallback> callback = |
| 500 SingleReleaseCallback::Create(base::Bind(ReleaseSharedMemoryCallback, | 500 SingleReleaseCallback::Create(base::Bind(ReleaseSharedMemoryCallback, |
| 501 base::Passed(&shared_memory), | 501 base::Passed(&shared_memory), |
| 502 release_called, | 502 release_called, |
| 503 release_sync_point, | 503 release_sync_point, |
| 504 lost_resource)); | 504 lost_resource)); |
| 505 return child_resource_provider_->CreateResourceFromTextureMailbox( | 505 return child_resource_provider_->CreateResourceFromTextureMailbox( |
| 506 TextureMailbox(gpu_mailbox, *sync_point), callback.Pass()); | 506 TextureMailbox(gpu_mailbox, GL_TEXTURE_2D, *sync_point), |
| 507 callback.Pass()); |
| 507 } else { | 508 } else { |
| 508 gfx::Size size(64, 64); | 509 gfx::Size size(64, 64); |
| 509 scoped_ptr<base::SharedMemory> shared_memory( | 510 scoped_ptr<base::SharedMemory> shared_memory( |
| 510 CreateAndFillSharedMemory(size, 0)); | 511 CreateAndFillSharedMemory(size, 0)); |
| 511 | 512 |
| 512 base::SharedMemory* shared_memory_ptr = shared_memory.get(); | 513 base::SharedMemory* shared_memory_ptr = shared_memory.get(); |
| 513 scoped_ptr<SingleReleaseCallback> callback = | 514 scoped_ptr<SingleReleaseCallback> callback = |
| 514 SingleReleaseCallback::Create(base::Bind(ReleaseSharedMemoryCallback, | 515 SingleReleaseCallback::Create(base::Bind(ReleaseSharedMemoryCallback, |
| 515 base::Passed(&shared_memory), | 516 base::Passed(&shared_memory), |
| 516 release_called, | 517 release_called, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 uint8_t data2[4] = { 5, 5, 5, 5 }; | 657 uint8_t data2[4] = { 5, 5, 5, 5 }; |
| 657 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); | 658 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); |
| 658 | 659 |
| 659 WebGLId external_texture_id = child_context_->createExternalTexture(); | 660 WebGLId external_texture_id = child_context_->createExternalTexture(); |
| 660 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); | 661 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); |
| 661 | 662 |
| 662 gpu::Mailbox external_mailbox; | 663 gpu::Mailbox external_mailbox; |
| 663 child_context_->genMailboxCHROMIUM(external_mailbox.name); | 664 child_context_->genMailboxCHROMIUM(external_mailbox.name); |
| 664 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, | 665 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, |
| 665 external_mailbox.name); | 666 external_mailbox.name); |
| 666 const unsigned external_sync_point = child_context_->insertSyncPoint(); | 667 const uint32 external_sync_point = child_context_->insertSyncPoint(); |
| 667 ResourceProvider::ResourceId id3 = | 668 ResourceProvider::ResourceId id3 = |
| 668 child_resource_provider_->CreateResourceFromTextureMailbox( | 669 child_resource_provider_->CreateResourceFromTextureMailbox( |
| 669 TextureMailbox( | 670 TextureMailbox( |
| 670 external_mailbox, GL_TEXTURE_EXTERNAL_OES, external_sync_point), | 671 external_mailbox, GL_TEXTURE_EXTERNAL_OES, external_sync_point), |
| 671 SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback))); | 672 SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback))); |
| 672 | 673 |
| 673 ReturnedResourceArray returned_to_child; | 674 ReturnedResourceArray returned_to_child; |
| 674 int child_id = | 675 int child_id = |
| 675 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 676 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| 676 { | 677 { |
| 677 // Transfer some resources to the parent. | 678 // Transfer some resources to the parent. |
| 678 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 679 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 679 resource_ids_to_transfer.push_back(id1); | 680 resource_ids_to_transfer.push_back(id1); |
| 680 resource_ids_to_transfer.push_back(id2); | 681 resource_ids_to_transfer.push_back(id2); |
| 681 resource_ids_to_transfer.push_back(id3); | 682 resource_ids_to_transfer.push_back(id3); |
| 682 TransferableResourceArray list; | 683 TransferableResourceArray list; |
| 683 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 684 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 684 &list); | 685 &list); |
| 685 ASSERT_EQ(3u, list.size()); | 686 ASSERT_EQ(3u, list.size()); |
| 686 EXPECT_NE(0u, list[0].sync_point); | 687 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); |
| 687 EXPECT_NE(0u, list[1].sync_point); | 688 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); |
| 688 EXPECT_EQ(external_sync_point, list[2].sync_point); | 689 EXPECT_EQ(external_sync_point, list[2].mailbox_holder.sync_point); |
| 689 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); | 690 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 690 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target); | 691 list[0].mailbox_holder.texture_target); |
| 691 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), list[2].target); | 692 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 693 list[1].mailbox_holder.texture_target); |
| 694 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), |
| 695 list[2].mailbox_holder.texture_target); |
| 692 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 696 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
| 693 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); | 697 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); |
| 694 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); | 698 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); |
| 695 resource_provider_->ReceiveFromChild(child_id, list); | 699 resource_provider_->ReceiveFromChild(child_id, list); |
| 696 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 700 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
| 697 resource_ids_to_transfer); | 701 resource_ids_to_transfer); |
| 698 } | 702 } |
| 699 | 703 |
| 700 EXPECT_EQ(3u, resource_provider_->num_resources()); | 704 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 701 ResourceProvider::ResourceIdMap resource_map = | 705 ResourceProvider::ResourceIdMap resource_map = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 722 { | 726 { |
| 723 // Check that transfering again the same resource from the child to the | 727 // Check that transfering again the same resource from the child to the |
| 724 // parent works. | 728 // parent works. |
| 725 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 729 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 726 resource_ids_to_transfer.push_back(id1); | 730 resource_ids_to_transfer.push_back(id1); |
| 727 TransferableResourceArray list; | 731 TransferableResourceArray list; |
| 728 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 732 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 729 &list); | 733 &list); |
| 730 EXPECT_EQ(1u, list.size()); | 734 EXPECT_EQ(1u, list.size()); |
| 731 EXPECT_EQ(id1, list[0].id); | 735 EXPECT_EQ(id1, list[0].id); |
| 732 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); | 736 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 737 list[0].mailbox_holder.texture_target); |
| 733 ReturnedResourceArray returned; | 738 ReturnedResourceArray returned; |
| 734 TransferableResource::ReturnResources(list, &returned); | 739 TransferableResource::ReturnResources(list, &returned); |
| 735 child_resource_provider_->ReceiveReturnsFromParent(returned); | 740 child_resource_provider_->ReceiveReturnsFromParent(returned); |
| 736 // id1 was exported twice, we returned it only once, it should still be | 741 // id1 was exported twice, we returned it only once, it should still be |
| 737 // in-use. | 742 // in-use. |
| 738 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 743 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
| 739 } | 744 } |
| 740 { | 745 { |
| 741 EXPECT_EQ(0u, returned_to_child.size()); | 746 EXPECT_EQ(0u, returned_to_child.size()); |
| 742 | 747 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 resource_ids_to_transfer.push_back(id1); | 786 resource_ids_to_transfer.push_back(id1); |
| 782 resource_ids_to_transfer.push_back(id2); | 787 resource_ids_to_transfer.push_back(id2); |
| 783 resource_ids_to_transfer.push_back(id3); | 788 resource_ids_to_transfer.push_back(id3); |
| 784 TransferableResourceArray list; | 789 TransferableResourceArray list; |
| 785 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 790 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 786 &list); | 791 &list); |
| 787 ASSERT_EQ(3u, list.size()); | 792 ASSERT_EQ(3u, list.size()); |
| 788 EXPECT_EQ(id1, list[0].id); | 793 EXPECT_EQ(id1, list[0].id); |
| 789 EXPECT_EQ(id2, list[1].id); | 794 EXPECT_EQ(id2, list[1].id); |
| 790 EXPECT_EQ(id3, list[2].id); | 795 EXPECT_EQ(id3, list[2].id); |
| 791 EXPECT_NE(0u, list[0].sync_point); | 796 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); |
| 792 EXPECT_NE(0u, list[1].sync_point); | 797 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); |
| 793 EXPECT_NE(0u, list[2].sync_point); | 798 EXPECT_NE(0u, list[2].mailbox_holder.sync_point); |
| 794 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); | 799 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 795 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target); | 800 list[0].mailbox_holder.texture_target); |
| 796 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), list[2].target); | 801 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 802 list[1].mailbox_holder.texture_target); |
| 803 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), |
| 804 list[2].mailbox_holder.texture_target); |
| 797 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 805 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
| 798 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); | 806 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); |
| 799 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); | 807 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); |
| 800 resource_provider_->ReceiveFromChild(child_id, list); | 808 resource_provider_->ReceiveFromChild(child_id, list); |
| 801 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 809 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
| 802 resource_ids_to_transfer); | 810 resource_ids_to_transfer); |
| 803 } | 811 } |
| 804 | 812 |
| 805 EXPECT_EQ(0u, returned_to_child.size()); | 813 EXPECT_EQ(0u, returned_to_child.size()); |
| 806 | 814 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 { | 860 { |
| 853 // Transfer some resources to the parent. | 861 // Transfer some resources to the parent. |
| 854 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 862 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 855 resource_ids_to_transfer.push_back(id1); | 863 resource_ids_to_transfer.push_back(id1); |
| 856 resource_ids_to_transfer.push_back(id2); | 864 resource_ids_to_transfer.push_back(id2); |
| 857 resource_ids_to_transfer.push_back(id3); | 865 resource_ids_to_transfer.push_back(id3); |
| 858 TransferableResourceArray list; | 866 TransferableResourceArray list; |
| 859 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 867 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 860 &list); | 868 &list); |
| 861 ASSERT_EQ(3u, list.size()); | 869 ASSERT_EQ(3u, list.size()); |
| 862 EXPECT_EQ(0u, list[0].sync_point); | 870 EXPECT_EQ(0u, list[0].mailbox_holder.sync_point); |
| 863 EXPECT_EQ(0u, list[1].sync_point); | 871 EXPECT_EQ(0u, list[1].mailbox_holder.sync_point); |
| 864 EXPECT_EQ(0u, list[2].sync_point); | 872 EXPECT_EQ(0u, list[2].mailbox_holder.sync_point); |
| 865 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 873 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
| 866 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); | 874 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); |
| 867 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); | 875 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); |
| 868 resource_provider_->ReceiveFromChild(child_id, list); | 876 resource_provider_->ReceiveFromChild(child_id, list); |
| 869 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 877 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
| 870 resource_ids_to_transfer); | 878 resource_ids_to_transfer); |
| 871 } | 879 } |
| 872 | 880 |
| 873 EXPECT_EQ(3u, resource_provider_->num_resources()); | 881 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 874 ResourceProvider::ResourceIdMap resource_map = | 882 ResourceProvider::ResourceIdMap resource_map = |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 ReturnedResourceArray returned_to_child; | 1088 ReturnedResourceArray returned_to_child; |
| 1081 int child_id = | 1089 int child_id = |
| 1082 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 1090 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| 1083 { | 1091 { |
| 1084 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1092 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1085 resource_ids_to_transfer.push_back(id1); | 1093 resource_ids_to_transfer.push_back(id1); |
| 1086 TransferableResourceArray list; | 1094 TransferableResourceArray list; |
| 1087 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, | 1095 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, |
| 1088 &list); | 1096 &list); |
| 1089 ASSERT_EQ(1u, list.size()); | 1097 ASSERT_EQ(1u, list.size()); |
| 1090 EXPECT_NE(0u, list[0].sync_point); | 1098 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); |
| 1091 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); | 1099 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1100 list[0].mailbox_holder.texture_target); |
| 1092 EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1)); | 1101 EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1)); |
| 1093 resource_provider_->ReceiveFromChild(child_id, list); | 1102 resource_provider_->ReceiveFromChild(child_id, list); |
| 1094 } | 1103 } |
| 1095 | 1104 |
| 1096 EXPECT_EQ(0u, resource_provider_->num_resources()); | 1105 EXPECT_EQ(0u, resource_provider_->num_resources()); |
| 1097 ASSERT_EQ(1u, returned_to_child.size()); | 1106 ASSERT_EQ(1u, returned_to_child.size()); |
| 1098 EXPECT_EQ(returned_to_child[0].id, id1); | 1107 EXPECT_EQ(returned_to_child[0].id, id1); |
| 1099 ResourceProvider::ResourceIdMap resource_map = | 1108 ResourceProvider::ResourceIdMap resource_map = |
| 1100 resource_provider_->GetChildToParentMap(child_id); | 1109 resource_provider_->GetChildToParentMap(child_id); |
| 1101 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; | 1110 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1127 int child_id = | 1136 int child_id = |
| 1128 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 1137 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| 1129 { | 1138 { |
| 1130 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1139 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1131 resource_ids_to_transfer.push_back(id1); | 1140 resource_ids_to_transfer.push_back(id1); |
| 1132 TransferableResourceArray list; | 1141 TransferableResourceArray list; |
| 1133 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 1142 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 1134 &list); | 1143 &list); |
| 1135 ASSERT_EQ(1u, list.size()); | 1144 ASSERT_EQ(1u, list.size()); |
| 1136 // Make invalid. | 1145 // Make invalid. |
| 1137 list[0].mailbox.name[1] = 5; | 1146 list[0].mailbox_holder.mailbox.name[1] = 5; |
| 1138 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 1147 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
| 1139 resource_provider_->ReceiveFromChild(child_id, list); | 1148 resource_provider_->ReceiveFromChild(child_id, list); |
| 1140 } | 1149 } |
| 1141 | 1150 |
| 1142 EXPECT_EQ(0u, resource_provider_->num_resources()); | 1151 EXPECT_EQ(0u, resource_provider_->num_resources()); |
| 1143 ASSERT_EQ(1u, returned_to_child.size()); | 1152 ASSERT_EQ(1u, returned_to_child.size()); |
| 1144 EXPECT_EQ(returned_to_child[0].id, id1); | 1153 EXPECT_EQ(returned_to_child[0].id, id1); |
| 1145 ResourceProvider::ResourceIdMap resource_map = | 1154 ResourceProvider::ResourceIdMap resource_map = |
| 1146 resource_provider_->GetChildToParentMap(child_id); | 1155 resource_provider_->GetChildToParentMap(child_id); |
| 1147 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; | 1156 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1177 { | 1186 { |
| 1178 // Transfer some resources to the parent. | 1187 // Transfer some resources to the parent. |
| 1179 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1188 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1180 resource_ids_to_transfer.push_back(id1); | 1189 resource_ids_to_transfer.push_back(id1); |
| 1181 resource_ids_to_transfer.push_back(id2); | 1190 resource_ids_to_transfer.push_back(id2); |
| 1182 TransferableResourceArray list; | 1191 TransferableResourceArray list; |
| 1183 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 1192 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 1184 &list); | 1193 &list); |
| 1185 ASSERT_EQ(2u, list.size()); | 1194 ASSERT_EQ(2u, list.size()); |
| 1186 if (GetParam() == ResourceProvider::GLTexture) { | 1195 if (GetParam() == ResourceProvider::GLTexture) { |
| 1187 EXPECT_NE(0u, list[0].sync_point); | 1196 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); |
| 1188 EXPECT_NE(0u, list[1].sync_point); | 1197 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); |
| 1189 } | 1198 } |
| 1190 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 1199 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
| 1191 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); | 1200 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); |
| 1192 resource_provider_->ReceiveFromChild(child_id, list); | 1201 resource_provider_->ReceiveFromChild(child_id, list); |
| 1193 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 1202 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
| 1194 resource_ids_to_transfer); | 1203 resource_ids_to_transfer); |
| 1195 } | 1204 } |
| 1196 | 1205 |
| 1197 EXPECT_EQ(2u, resource_provider_->num_resources()); | 1206 EXPECT_EQ(2u, resource_provider_->num_resources()); |
| 1198 ResourceProvider::ResourceIdMap resource_map = | 1207 ResourceProvider::ResourceIdMap resource_map = |
| 1199 resource_provider_->GetChildToParentMap(child_id); | 1208 resource_provider_->GetChildToParentMap(child_id); |
| 1200 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; | 1209 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; |
| 1201 ResourceProvider::ResourceId mapped_id2 = resource_map[id2]; | 1210 ResourceProvider::ResourceId mapped_id2 = resource_map[id2]; |
| 1202 EXPECT_NE(0u, mapped_id1); | 1211 EXPECT_NE(0u, mapped_id1); |
| 1203 EXPECT_NE(0u, mapped_id2); | 1212 EXPECT_NE(0u, mapped_id2); |
| 1204 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); | 1213 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); |
| 1205 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); | 1214 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); |
| 1206 | 1215 |
| 1207 { | 1216 { |
| 1208 // The parent transfers the resources to the grandparent. | 1217 // The parent transfers the resources to the grandparent. |
| 1209 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1218 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1210 resource_ids_to_transfer.push_back(mapped_id1); | 1219 resource_ids_to_transfer.push_back(mapped_id1); |
| 1211 resource_ids_to_transfer.push_back(mapped_id2); | 1220 resource_ids_to_transfer.push_back(mapped_id2); |
| 1212 TransferableResourceArray list; | 1221 TransferableResourceArray list; |
| 1213 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 1222 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1214 | 1223 |
| 1215 ASSERT_EQ(2u, list.size()); | 1224 ASSERT_EQ(2u, list.size()); |
| 1216 if (GetParam() == ResourceProvider::GLTexture) { | 1225 if (GetParam() == ResourceProvider::GLTexture) { |
| 1217 EXPECT_NE(0u, list[0].sync_point); | 1226 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); |
| 1218 EXPECT_NE(0u, list[1].sync_point); | 1227 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); |
| 1219 } | 1228 } |
| 1220 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); | 1229 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); |
| 1221 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); | 1230 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); |
| 1222 | 1231 |
| 1223 // Release the resource in the parent. Set no resources as being in use. The | 1232 // Release the resource in the parent. Set no resources as being in use. The |
| 1224 // resources are exported so that can't be transferred back yet. | 1233 // resources are exported so that can't be transferred back yet. |
| 1225 ResourceProvider::ResourceIdArray no_resources; | 1234 ResourceProvider::ResourceIdArray no_resources; |
| 1226 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); | 1235 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); |
| 1227 | 1236 |
| 1228 EXPECT_EQ(0u, returned_to_child.size()); | 1237 EXPECT_EQ(0u, returned_to_child.size()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 { | 1280 { |
| 1272 // Transfer some resources to the parent. | 1281 // Transfer some resources to the parent. |
| 1273 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1282 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1274 resource_ids_to_transfer.push_back(id1); | 1283 resource_ids_to_transfer.push_back(id1); |
| 1275 resource_ids_to_transfer.push_back(id2); | 1284 resource_ids_to_transfer.push_back(id2); |
| 1276 TransferableResourceArray list; | 1285 TransferableResourceArray list; |
| 1277 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 1286 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 1278 &list); | 1287 &list); |
| 1279 ASSERT_EQ(2u, list.size()); | 1288 ASSERT_EQ(2u, list.size()); |
| 1280 if (GetParam() == ResourceProvider::GLTexture) { | 1289 if (GetParam() == ResourceProvider::GLTexture) { |
| 1281 EXPECT_NE(0u, list[0].sync_point); | 1290 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); |
| 1282 EXPECT_NE(0u, list[1].sync_point); | 1291 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); |
| 1283 } | 1292 } |
| 1284 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 1293 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
| 1285 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); | 1294 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); |
| 1286 resource_provider_->ReceiveFromChild(child_id, list); | 1295 resource_provider_->ReceiveFromChild(child_id, list); |
| 1287 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 1296 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
| 1288 resource_ids_to_transfer); | 1297 resource_ids_to_transfer); |
| 1289 } | 1298 } |
| 1290 | 1299 |
| 1291 EXPECT_EQ(2u, resource_provider_->num_resources()); | 1300 EXPECT_EQ(2u, resource_provider_->num_resources()); |
| 1292 ResourceProvider::ResourceIdMap resource_map = | 1301 ResourceProvider::ResourceIdMap resource_map = |
| 1293 resource_provider_->GetChildToParentMap(child_id); | 1302 resource_provider_->GetChildToParentMap(child_id); |
| 1294 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; | 1303 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; |
| 1295 ResourceProvider::ResourceId mapped_id2 = resource_map[id2]; | 1304 ResourceProvider::ResourceId mapped_id2 = resource_map[id2]; |
| 1296 EXPECT_NE(0u, mapped_id1); | 1305 EXPECT_NE(0u, mapped_id1); |
| 1297 EXPECT_NE(0u, mapped_id2); | 1306 EXPECT_NE(0u, mapped_id2); |
| 1298 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); | 1307 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); |
| 1299 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); | 1308 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); |
| 1300 | 1309 |
| 1301 { | 1310 { |
| 1302 // The parent transfers the resources to the grandparent. | 1311 // The parent transfers the resources to the grandparent. |
| 1303 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1312 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1304 resource_ids_to_transfer.push_back(mapped_id1); | 1313 resource_ids_to_transfer.push_back(mapped_id1); |
| 1305 resource_ids_to_transfer.push_back(mapped_id2); | 1314 resource_ids_to_transfer.push_back(mapped_id2); |
| 1306 TransferableResourceArray list; | 1315 TransferableResourceArray list; |
| 1307 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 1316 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1308 | 1317 |
| 1309 ASSERT_EQ(2u, list.size()); | 1318 ASSERT_EQ(2u, list.size()); |
| 1310 if (GetParam() == ResourceProvider::GLTexture) { | 1319 if (GetParam() == ResourceProvider::GLTexture) { |
| 1311 EXPECT_NE(0u, list[0].sync_point); | 1320 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); |
| 1312 EXPECT_NE(0u, list[1].sync_point); | 1321 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); |
| 1313 } | 1322 } |
| 1314 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); | 1323 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); |
| 1315 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); | 1324 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); |
| 1316 | 1325 |
| 1317 // Release the resource in the parent. Set no resources as being in use. The | 1326 // Release the resource in the parent. Set no resources as being in use. The |
| 1318 // resources are exported so that can't be transferred back yet. | 1327 // resources are exported so that can't be transferred back yet. |
| 1319 ResourceProvider::ResourceIdArray no_resources; | 1328 ResourceProvider::ResourceIdArray no_resources; |
| 1320 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); | 1329 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); |
| 1321 | 1330 |
| 1322 // Destroy the child, the resources should not be returned yet. | 1331 // Destroy the child, the resources should not be returned yet. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 1385 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| 1377 { | 1386 { |
| 1378 // Transfer some resource to the parent. | 1387 // Transfer some resource to the parent. |
| 1379 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1388 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1380 resource_ids_to_transfer.push_back(id); | 1389 resource_ids_to_transfer.push_back(id); |
| 1381 TransferableResourceArray list; | 1390 TransferableResourceArray list; |
| 1382 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 1391 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 1383 &list); | 1392 &list); |
| 1384 ASSERT_EQ(1u, list.size()); | 1393 ASSERT_EQ(1u, list.size()); |
| 1385 if (GetParam() == ResourceProvider::GLTexture) | 1394 if (GetParam() == ResourceProvider::GLTexture) |
| 1386 EXPECT_NE(0u, list[0].sync_point); | 1395 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); |
| 1387 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id)); | 1396 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id)); |
| 1388 resource_provider_->ReceiveFromChild(child_id, list); | 1397 resource_provider_->ReceiveFromChild(child_id, list); |
| 1389 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 1398 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
| 1390 resource_ids_to_transfer); | 1399 resource_ids_to_transfer); |
| 1391 } | 1400 } |
| 1392 | 1401 |
| 1393 // Delete textures in the child, while they are transfered. | 1402 // Delete textures in the child, while they are transfered. |
| 1394 child_resource_provider_->DeleteResource(id); | 1403 child_resource_provider_->DeleteResource(id); |
| 1395 EXPECT_EQ(1u, child_resource_provider_->num_resources()); | 1404 EXPECT_EQ(1u, child_resource_provider_->num_resources()); |
| 1396 { | 1405 { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 if (GetParam() != ResourceProvider::GLTexture) | 1599 if (GetParam() != ResourceProvider::GLTexture) |
| 1591 return; | 1600 return; |
| 1592 unsigned texture = context()->createTexture(); | 1601 unsigned texture = context()->createTexture(); |
| 1593 context()->bindTexture(GL_TEXTURE_2D, texture); | 1602 context()->bindTexture(GL_TEXTURE_2D, texture); |
| 1594 uint8_t data[4] = { 1, 2, 3, 4 }; | 1603 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 1595 context()->texImage2D( | 1604 context()->texImage2D( |
| 1596 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); | 1605 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); |
| 1597 gpu::Mailbox mailbox; | 1606 gpu::Mailbox mailbox; |
| 1598 context()->genMailboxCHROMIUM(mailbox.name); | 1607 context()->genMailboxCHROMIUM(mailbox.name); |
| 1599 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1608 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1600 unsigned sync_point = context()->insertSyncPoint(); | 1609 uint32 sync_point = context()->insertSyncPoint(); |
| 1601 | 1610 |
| 1602 // All the logic below assumes that the sync points are all positive. | 1611 // All the logic below assumes that the sync points are all positive. |
| 1603 EXPECT_LT(0u, sync_point); | 1612 EXPECT_LT(0u, sync_point); |
| 1604 | 1613 |
| 1605 unsigned release_sync_point = 0; | 1614 uint32 release_sync_point = 0; |
| 1606 bool lost_resource = false; | 1615 bool lost_resource = false; |
| 1607 ReleaseCallback callback = | 1616 ReleaseCallback callback = |
| 1608 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); | 1617 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); |
| 1609 ResourceProvider::ResourceId resource = | 1618 ResourceProvider::ResourceId resource = |
| 1610 resource_provider_->CreateResourceFromTextureMailbox( | 1619 resource_provider_->CreateResourceFromTextureMailbox( |
| 1611 TextureMailbox(mailbox, sync_point), | 1620 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), |
| 1612 SingleReleaseCallback::Create(callback)); | 1621 SingleReleaseCallback::Create(callback)); |
| 1613 EXPECT_EQ(1u, context()->NumTextures()); | 1622 EXPECT_EQ(1u, context()->NumTextures()); |
| 1614 EXPECT_EQ(0u, release_sync_point); | 1623 EXPECT_EQ(0u, release_sync_point); |
| 1615 { | 1624 { |
| 1616 // Transfer the resource, expect the sync points to be consistent. | 1625 // Transfer the resource, expect the sync points to be consistent. |
| 1617 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1626 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1618 resource_ids_to_transfer.push_back(resource); | 1627 resource_ids_to_transfer.push_back(resource); |
| 1619 TransferableResourceArray list; | 1628 TransferableResourceArray list; |
| 1620 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 1629 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1621 ASSERT_EQ(1u, list.size()); | 1630 ASSERT_EQ(1u, list.size()); |
| 1622 EXPECT_LE(sync_point, list[0].sync_point); | 1631 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); |
| 1623 EXPECT_EQ(0, | 1632 EXPECT_EQ(0, |
| 1624 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); | 1633 memcmp(mailbox.name, |
| 1634 list[0].mailbox_holder.mailbox.name, |
| 1635 sizeof(mailbox.name))); |
| 1625 EXPECT_EQ(0u, release_sync_point); | 1636 EXPECT_EQ(0u, release_sync_point); |
| 1626 | 1637 |
| 1627 context()->waitSyncPoint(list[0].sync_point); | 1638 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); |
| 1628 unsigned other_texture = context()->createTexture(); | 1639 unsigned other_texture = context()->createTexture(); |
| 1629 context()->bindTexture(GL_TEXTURE_2D, other_texture); | 1640 context()->bindTexture(GL_TEXTURE_2D, other_texture); |
| 1630 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1641 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1631 uint8_t test_data[4] = { 0 }; | 1642 uint8_t test_data[4] = { 0 }; |
| 1632 context()->GetPixels( | 1643 context()->GetPixels( |
| 1633 gfx::Size(1, 1), RGBA_8888, test_data); | 1644 gfx::Size(1, 1), RGBA_8888, test_data); |
| 1634 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | 1645 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
| 1635 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1646 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1636 context()->deleteTexture(other_texture); | 1647 context()->deleteTexture(other_texture); |
| 1637 list[0].sync_point = context()->insertSyncPoint(); | 1648 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); |
| 1638 EXPECT_LT(0u, list[0].sync_point); | 1649 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); |
| 1639 | 1650 |
| 1640 // Receive the resource, then delete it, expect the sync points to be | 1651 // Receive the resource, then delete it, expect the sync points to be |
| 1641 // consistent. | 1652 // consistent. |
| 1642 ReturnedResourceArray returned; | 1653 ReturnedResourceArray returned; |
| 1643 TransferableResource::ReturnResources(list, &returned); | 1654 TransferableResource::ReturnResources(list, &returned); |
| 1644 resource_provider_->ReceiveReturnsFromParent(returned); | 1655 resource_provider_->ReceiveReturnsFromParent(returned); |
| 1645 EXPECT_EQ(1u, context()->NumTextures()); | 1656 EXPECT_EQ(1u, context()->NumTextures()); |
| 1646 EXPECT_EQ(0u, release_sync_point); | 1657 EXPECT_EQ(0u, release_sync_point); |
| 1647 | 1658 |
| 1648 resource_provider_->DeleteResource(resource); | 1659 resource_provider_->DeleteResource(resource); |
| 1649 EXPECT_LE(list[0].sync_point, release_sync_point); | 1660 EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); |
| 1650 EXPECT_FALSE(lost_resource); | 1661 EXPECT_FALSE(lost_resource); |
| 1651 } | 1662 } |
| 1652 | 1663 |
| 1653 // We're going to do the same thing as above, but testing the case where we | 1664 // We're going to do the same thing as above, but testing the case where we |
| 1654 // delete the resource before we receive it back. | 1665 // delete the resource before we receive it back. |
| 1655 sync_point = release_sync_point; | 1666 sync_point = release_sync_point; |
| 1656 EXPECT_LT(0u, sync_point); | 1667 EXPECT_LT(0u, sync_point); |
| 1657 release_sync_point = 0; | 1668 release_sync_point = 0; |
| 1658 resource = resource_provider_->CreateResourceFromTextureMailbox( | 1669 resource = resource_provider_->CreateResourceFromTextureMailbox( |
| 1659 TextureMailbox(mailbox, sync_point), | 1670 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), |
| 1660 SingleReleaseCallback::Create(callback)); | 1671 SingleReleaseCallback::Create(callback)); |
| 1661 EXPECT_EQ(1u, context()->NumTextures()); | 1672 EXPECT_EQ(1u, context()->NumTextures()); |
| 1662 EXPECT_EQ(0u, release_sync_point); | 1673 EXPECT_EQ(0u, release_sync_point); |
| 1663 { | 1674 { |
| 1664 // Transfer the resource, expect the sync points to be consistent. | 1675 // Transfer the resource, expect the sync points to be consistent. |
| 1665 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1676 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1666 resource_ids_to_transfer.push_back(resource); | 1677 resource_ids_to_transfer.push_back(resource); |
| 1667 TransferableResourceArray list; | 1678 TransferableResourceArray list; |
| 1668 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 1679 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1669 ASSERT_EQ(1u, list.size()); | 1680 ASSERT_EQ(1u, list.size()); |
| 1670 EXPECT_LE(sync_point, list[0].sync_point); | 1681 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); |
| 1671 EXPECT_EQ(0, | 1682 EXPECT_EQ(0, |
| 1672 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); | 1683 memcmp(mailbox.name, |
| 1684 list[0].mailbox_holder.mailbox.name, |
| 1685 sizeof(mailbox.name))); |
| 1673 EXPECT_EQ(0u, release_sync_point); | 1686 EXPECT_EQ(0u, release_sync_point); |
| 1674 | 1687 |
| 1675 context()->waitSyncPoint(list[0].sync_point); | 1688 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); |
| 1676 unsigned other_texture = context()->createTexture(); | 1689 unsigned other_texture = context()->createTexture(); |
| 1677 context()->bindTexture(GL_TEXTURE_2D, other_texture); | 1690 context()->bindTexture(GL_TEXTURE_2D, other_texture); |
| 1678 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1691 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1679 uint8_t test_data[4] = { 0 }; | 1692 uint8_t test_data[4] = { 0 }; |
| 1680 context()->GetPixels( | 1693 context()->GetPixels( |
| 1681 gfx::Size(1, 1), RGBA_8888, test_data); | 1694 gfx::Size(1, 1), RGBA_8888, test_data); |
| 1682 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | 1695 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
| 1683 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1696 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1684 context()->deleteTexture(other_texture); | 1697 context()->deleteTexture(other_texture); |
| 1685 list[0].sync_point = context()->insertSyncPoint(); | 1698 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); |
| 1686 EXPECT_LT(0u, list[0].sync_point); | 1699 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); |
| 1687 | 1700 |
| 1688 // Delete the resource, which shouldn't do anything. | 1701 // Delete the resource, which shouldn't do anything. |
| 1689 resource_provider_->DeleteResource(resource); | 1702 resource_provider_->DeleteResource(resource); |
| 1690 EXPECT_EQ(1u, context()->NumTextures()); | 1703 EXPECT_EQ(1u, context()->NumTextures()); |
| 1691 EXPECT_EQ(0u, release_sync_point); | 1704 EXPECT_EQ(0u, release_sync_point); |
| 1692 | 1705 |
| 1693 // Then receive the resource which should release the mailbox, expect the | 1706 // Then receive the resource which should release the mailbox, expect the |
| 1694 // sync points to be consistent. | 1707 // sync points to be consistent. |
| 1695 ReturnedResourceArray returned; | 1708 ReturnedResourceArray returned; |
| 1696 TransferableResource::ReturnResources(list, &returned); | 1709 TransferableResource::ReturnResources(list, &returned); |
| 1697 resource_provider_->ReceiveReturnsFromParent(returned); | 1710 resource_provider_->ReceiveReturnsFromParent(returned); |
| 1698 EXPECT_LE(list[0].sync_point, release_sync_point); | 1711 EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); |
| 1699 EXPECT_FALSE(lost_resource); | 1712 EXPECT_FALSE(lost_resource); |
| 1700 } | 1713 } |
| 1701 | 1714 |
| 1702 context()->waitSyncPoint(release_sync_point); | 1715 context()->waitSyncPoint(release_sync_point); |
| 1703 context()->bindTexture(GL_TEXTURE_2D, texture); | 1716 context()->bindTexture(GL_TEXTURE_2D, texture); |
| 1704 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1717 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1705 context()->deleteTexture(texture); | 1718 context()->deleteTexture(texture); |
| 1706 } | 1719 } |
| 1707 | 1720 |
| 1708 TEST_P(ResourceProviderTest, LostResourceInParent) { | 1721 TEST_P(ResourceProviderTest, LostResourceInParent) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 } | 1841 } |
| 1829 | 1842 |
| 1830 // The resource should be lost. | 1843 // The resource should be lost. |
| 1831 EXPECT_TRUE(child_resource_provider_->IsLost(resource)); | 1844 EXPECT_TRUE(child_resource_provider_->IsLost(resource)); |
| 1832 | 1845 |
| 1833 // Lost resources stay in use in the parent forever. | 1846 // Lost resources stay in use in the parent forever. |
| 1834 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(resource)); | 1847 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(resource)); |
| 1835 } | 1848 } |
| 1836 | 1849 |
| 1837 TEST_P(ResourceProviderTest, LostMailboxInParent) { | 1850 TEST_P(ResourceProviderTest, LostMailboxInParent) { |
| 1838 unsigned release_sync_point = 0; | 1851 uint32 release_sync_point = 0; |
| 1839 bool lost_resource = false; | 1852 bool lost_resource = false; |
| 1840 bool release_called = false; | 1853 bool release_called = false; |
| 1841 unsigned sync_point = 0; | 1854 uint32 sync_point = 0; |
| 1842 ResourceProvider::ResourceId resource = CreateChildMailbox( | 1855 ResourceProvider::ResourceId resource = CreateChildMailbox( |
| 1843 &release_sync_point, &lost_resource, &release_called, &sync_point); | 1856 &release_sync_point, &lost_resource, &release_called, &sync_point); |
| 1844 | 1857 |
| 1845 ReturnedResourceArray returned_to_child; | 1858 ReturnedResourceArray returned_to_child; |
| 1846 int child_id = | 1859 int child_id = |
| 1847 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 1860 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| 1848 { | 1861 { |
| 1849 // Transfer the resource to the parent. | 1862 // Transfer the resource to the parent. |
| 1850 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1863 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1851 resource_ids_to_transfer.push_back(resource); | 1864 resource_ids_to_transfer.push_back(resource); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1878 returned_to_child.clear(); | 1891 returned_to_child.clear(); |
| 1879 } | 1892 } |
| 1880 | 1893 |
| 1881 // Delete the resource in the child. Expect the resource to be lost if it's | 1894 // Delete the resource in the child. Expect the resource to be lost if it's |
| 1882 // a GL texture. | 1895 // a GL texture. |
| 1883 child_resource_provider_->DeleteResource(resource); | 1896 child_resource_provider_->DeleteResource(resource); |
| 1884 EXPECT_EQ(lost_resource, GetParam() == ResourceProvider::GLTexture); | 1897 EXPECT_EQ(lost_resource, GetParam() == ResourceProvider::GLTexture); |
| 1885 } | 1898 } |
| 1886 | 1899 |
| 1887 TEST_P(ResourceProviderTest, LostMailboxInGrandParent) { | 1900 TEST_P(ResourceProviderTest, LostMailboxInGrandParent) { |
| 1888 unsigned release_sync_point = 0; | 1901 uint32 release_sync_point = 0; |
| 1889 bool lost_resource = false; | 1902 bool lost_resource = false; |
| 1890 bool release_called = false; | 1903 bool release_called = false; |
| 1891 unsigned sync_point = 0; | 1904 uint32 sync_point = 0; |
| 1892 ResourceProvider::ResourceId resource = CreateChildMailbox( | 1905 ResourceProvider::ResourceId resource = CreateChildMailbox( |
| 1893 &release_sync_point, &lost_resource, &release_called, &sync_point); | 1906 &release_sync_point, &lost_resource, &release_called, &sync_point); |
| 1894 | 1907 |
| 1895 ReturnedResourceArray returned_to_child; | 1908 ReturnedResourceArray returned_to_child; |
| 1896 int child_id = | 1909 int child_id = |
| 1897 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 1910 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| 1898 { | 1911 { |
| 1899 // Transfer the resource to the parent. | 1912 // Transfer the resource to the parent. |
| 1900 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1913 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1901 resource_ids_to_transfer.push_back(resource); | 1914 resource_ids_to_transfer.push_back(resource); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1946 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); | 1959 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); |
| 1947 returned_to_child.clear(); | 1960 returned_to_child.clear(); |
| 1948 } | 1961 } |
| 1949 | 1962 |
| 1950 // Delete the resource in the child. Expect the resource to be lost. | 1963 // Delete the resource in the child. Expect the resource to be lost. |
| 1951 child_resource_provider_->DeleteResource(resource); | 1964 child_resource_provider_->DeleteResource(resource); |
| 1952 EXPECT_TRUE(lost_resource); | 1965 EXPECT_TRUE(lost_resource); |
| 1953 } | 1966 } |
| 1954 | 1967 |
| 1955 TEST_P(ResourceProviderTest, Shutdown) { | 1968 TEST_P(ResourceProviderTest, Shutdown) { |
| 1956 unsigned release_sync_point = 0; | 1969 uint32 release_sync_point = 0; |
| 1957 bool lost_resource = false; | 1970 bool lost_resource = false; |
| 1958 bool release_called = false; | 1971 bool release_called = false; |
| 1959 unsigned sync_point = 0; | 1972 uint32 sync_point = 0; |
| 1960 CreateChildMailbox( | 1973 CreateChildMailbox( |
| 1961 &release_sync_point, &lost_resource, &release_called, &sync_point); | 1974 &release_sync_point, &lost_resource, &release_called, &sync_point); |
| 1962 | 1975 |
| 1963 EXPECT_EQ(0u, release_sync_point); | 1976 EXPECT_EQ(0u, release_sync_point); |
| 1964 EXPECT_FALSE(lost_resource); | 1977 EXPECT_FALSE(lost_resource); |
| 1965 | 1978 |
| 1966 child_resource_provider_.reset(); | 1979 child_resource_provider_.reset(); |
| 1967 | 1980 |
| 1968 if (GetParam() == ResourceProvider::GLTexture) { | 1981 if (GetParam() == ResourceProvider::GLTexture) { |
| 1969 EXPECT_LE(sync_point, release_sync_point); | 1982 EXPECT_LE(sync_point, release_sync_point); |
| 1970 } | 1983 } |
| 1971 EXPECT_TRUE(release_called); | 1984 EXPECT_TRUE(release_called); |
| 1972 EXPECT_FALSE(lost_resource); | 1985 EXPECT_FALSE(lost_resource); |
| 1973 } | 1986 } |
| 1974 | 1987 |
| 1975 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { | 1988 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { |
| 1976 unsigned release_sync_point = 0; | 1989 uint32 release_sync_point = 0; |
| 1977 bool lost_resource = false; | 1990 bool lost_resource = false; |
| 1978 bool release_called = false; | 1991 bool release_called = false; |
| 1979 unsigned sync_point = 0; | 1992 uint32 sync_point = 0; |
| 1980 ResourceProvider::ResourceId resource = CreateChildMailbox( | 1993 ResourceProvider::ResourceId resource = CreateChildMailbox( |
| 1981 &release_sync_point, &lost_resource, &release_called, &sync_point); | 1994 &release_sync_point, &lost_resource, &release_called, &sync_point); |
| 1982 | 1995 |
| 1983 // Transfer the resource, so we can't release it properly on shutdown. | 1996 // Transfer the resource, so we can't release it properly on shutdown. |
| 1984 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1997 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1985 resource_ids_to_transfer.push_back(resource); | 1998 resource_ids_to_transfer.push_back(resource); |
| 1986 TransferableResourceArray list; | 1999 TransferableResourceArray list; |
| 1987 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 2000 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 1988 &list); | 2001 &list); |
| 1989 | 2002 |
| 1990 EXPECT_EQ(0u, release_sync_point); | 2003 EXPECT_EQ(0u, release_sync_point); |
| 1991 EXPECT_FALSE(lost_resource); | 2004 EXPECT_FALSE(lost_resource); |
| 1992 | 2005 |
| 1993 child_resource_provider_.reset(); | 2006 child_resource_provider_.reset(); |
| 1994 | 2007 |
| 1995 // Since the resource is in the parent, the child considers it lost. | 2008 // Since the resource is in the parent, the child considers it lost. |
| 1996 EXPECT_EQ(0u, release_sync_point); | 2009 EXPECT_EQ(0u, release_sync_point); |
| 1997 EXPECT_TRUE(lost_resource); | 2010 EXPECT_TRUE(lost_resource); |
| 1998 } | 2011 } |
| 1999 | 2012 |
| 2000 TEST_P(ResourceProviderTest, LostContext) { | 2013 TEST_P(ResourceProviderTest, LostContext) { |
| 2001 // TextureMailbox callbacks only exist for GL textures for now. | 2014 // TextureMailbox callbacks only exist for GL textures for now. |
| 2002 if (GetParam() != ResourceProvider::GLTexture) | 2015 if (GetParam() != ResourceProvider::GLTexture) |
| 2003 return; | 2016 return; |
| 2004 unsigned texture = context()->createTexture(); | 2017 unsigned texture = context()->createTexture(); |
| 2005 context()->bindTexture(GL_TEXTURE_2D, texture); | 2018 context()->bindTexture(GL_TEXTURE_2D, texture); |
| 2006 gpu::Mailbox mailbox; | 2019 gpu::Mailbox mailbox; |
| 2007 context()->genMailboxCHROMIUM(mailbox.name); | 2020 context()->genMailboxCHROMIUM(mailbox.name); |
| 2008 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 2021 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 2009 unsigned sync_point = context()->insertSyncPoint(); | 2022 uint32 sync_point = context()->insertSyncPoint(); |
| 2010 | 2023 |
| 2011 EXPECT_LT(0u, sync_point); | 2024 EXPECT_LT(0u, sync_point); |
| 2012 | 2025 |
| 2013 unsigned release_sync_point = 0; | 2026 uint32 release_sync_point = 0; |
| 2014 bool lost_resource = false; | 2027 bool lost_resource = false; |
| 2015 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 2028 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 2016 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); | 2029 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); |
| 2017 resource_provider_->CreateResourceFromTextureMailbox( | 2030 resource_provider_->CreateResourceFromTextureMailbox( |
| 2018 TextureMailbox(mailbox, sync_point), | 2031 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), callback.Pass()); |
| 2019 callback.Pass()); | |
| 2020 | 2032 |
| 2021 EXPECT_EQ(0u, release_sync_point); | 2033 EXPECT_EQ(0u, release_sync_point); |
| 2022 EXPECT_FALSE(lost_resource); | 2034 EXPECT_FALSE(lost_resource); |
| 2023 | 2035 |
| 2024 resource_provider_->DidLoseOutputSurface(); | 2036 resource_provider_->DidLoseOutputSurface(); |
| 2025 resource_provider_.reset(); | 2037 resource_provider_.reset(); |
| 2026 | 2038 |
| 2027 EXPECT_LE(sync_point, release_sync_point); | 2039 EXPECT_LE(sync_point, release_sync_point); |
| 2028 EXPECT_TRUE(lost_resource); | 2040 EXPECT_TRUE(lost_resource); |
| 2029 } | 2041 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2258 | 2270 |
| 2259 FakeOutputSurfaceClient output_surface_client; | 2271 FakeOutputSurfaceClient output_surface_client; |
| 2260 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2272 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2261 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2273 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2262 CHECK(output_surface->BindToClient(&output_surface_client)); | 2274 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2263 | 2275 |
| 2264 scoped_ptr<ResourceProvider> resource_provider( | 2276 scoped_ptr<ResourceProvider> resource_provider( |
| 2265 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2277 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2266 | 2278 |
| 2267 unsigned texture_id = 1; | 2279 unsigned texture_id = 1; |
| 2268 unsigned sync_point = 30; | 2280 uint32 sync_point = 30; |
| 2269 unsigned target = GL_TEXTURE_2D; | 2281 unsigned target = GL_TEXTURE_2D; |
| 2270 | 2282 |
| 2271 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2283 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2272 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2284 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2273 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2285 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2274 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2286 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2275 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2287 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| 2276 | 2288 |
| 2277 gpu::Mailbox gpu_mailbox; | 2289 gpu::Mailbox gpu_mailbox; |
| 2278 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2290 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2279 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 2291 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 2280 base::Bind(&EmptyReleaseCallback)); | 2292 base::Bind(&EmptyReleaseCallback)); |
| 2281 | 2293 |
| 2282 TextureMailbox mailbox(gpu_mailbox, sync_point); | 2294 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
| 2283 | 2295 |
| 2284 ResourceProvider::ResourceId id = | 2296 ResourceProvider::ResourceId id = |
| 2285 resource_provider->CreateResourceFromTextureMailbox( | 2297 resource_provider->CreateResourceFromTextureMailbox( |
| 2286 mailbox, callback.Pass()); | 2298 mailbox, callback.Pass()); |
| 2287 EXPECT_NE(0u, id); | 2299 EXPECT_NE(0u, id); |
| 2288 | 2300 |
| 2289 Mock::VerifyAndClearExpectations(context); | 2301 Mock::VerifyAndClearExpectations(context); |
| 2290 | 2302 |
| 2291 { | 2303 { |
| 2292 // Using the texture does a consume of the mailbox. | 2304 // Using the texture does a consume of the mailbox. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2322 | 2334 |
| 2323 FakeOutputSurfaceClient output_surface_client; | 2335 FakeOutputSurfaceClient output_surface_client; |
| 2324 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2336 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2325 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2337 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2326 CHECK(output_surface->BindToClient(&output_surface_client)); | 2338 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2327 | 2339 |
| 2328 scoped_ptr<ResourceProvider> resource_provider( | 2340 scoped_ptr<ResourceProvider> resource_provider( |
| 2329 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2341 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2330 | 2342 |
| 2331 unsigned texture_id = 1; | 2343 unsigned texture_id = 1; |
| 2332 unsigned sync_point = 30; | 2344 uint32 sync_point = 30; |
| 2333 unsigned target = GL_TEXTURE_EXTERNAL_OES; | 2345 unsigned target = GL_TEXTURE_EXTERNAL_OES; |
| 2334 | 2346 |
| 2335 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2347 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2336 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2348 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2337 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2349 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2338 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2350 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2339 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2351 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| 2340 | 2352 |
| 2341 gpu::Mailbox gpu_mailbox; | 2353 gpu::Mailbox gpu_mailbox; |
| 2342 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2354 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3080 resource_provider->AllocateForTesting(id); | 3092 resource_provider->AllocateForTesting(id); |
| 3081 Mock::VerifyAndClearExpectations(context); | 3093 Mock::VerifyAndClearExpectations(context); |
| 3082 | 3094 |
| 3083 DCHECK_EQ(10u, context->PeekTextureId()); | 3095 DCHECK_EQ(10u, context->PeekTextureId()); |
| 3084 resource_provider->DeleteResource(id); | 3096 resource_provider->DeleteResource(id); |
| 3085 } | 3097 } |
| 3086 } | 3098 } |
| 3087 | 3099 |
| 3088 } // namespace | 3100 } // namespace |
| 3089 } // namespace cc | 3101 } // namespace cc |
| OLD | NEW |