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 { |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 if (GetParam() != ResourceProvider::GLTexture) | 1591 if (GetParam() != ResourceProvider::GLTexture) |
1591 return; | 1592 return; |
1592 unsigned texture = context()->createTexture(); | 1593 unsigned texture = context()->createTexture(); |
1593 context()->bindTexture(GL_TEXTURE_2D, texture); | 1594 context()->bindTexture(GL_TEXTURE_2D, texture); |
1594 uint8_t data[4] = { 1, 2, 3, 4 }; | 1595 uint8_t data[4] = { 1, 2, 3, 4 }; |
1595 context()->texImage2D( | 1596 context()->texImage2D( |
1596 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); | 1597 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); |
1597 gpu::Mailbox mailbox; | 1598 gpu::Mailbox mailbox; |
1598 context()->genMailboxCHROMIUM(mailbox.name); | 1599 context()->genMailboxCHROMIUM(mailbox.name); |
1599 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1600 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
1600 unsigned sync_point = context()->insertSyncPoint(); | 1601 uint32 sync_point = context()->insertSyncPoint(); |
1601 | 1602 |
1602 // All the logic below assumes that the sync points are all positive. | 1603 // All the logic below assumes that the sync points are all positive. |
1603 EXPECT_LT(0u, sync_point); | 1604 EXPECT_LT(0u, sync_point); |
1604 | 1605 |
1605 unsigned release_sync_point = 0; | 1606 uint32 release_sync_point = 0; |
1606 bool lost_resource = false; | 1607 bool lost_resource = false; |
1607 ReleaseCallback callback = | 1608 ReleaseCallback callback = |
1608 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); | 1609 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); |
1609 ResourceProvider::ResourceId resource = | 1610 ResourceProvider::ResourceId resource = |
1610 resource_provider_->CreateResourceFromTextureMailbox( | 1611 resource_provider_->CreateResourceFromTextureMailbox( |
1611 TextureMailbox(mailbox, sync_point), | 1612 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), |
1612 SingleReleaseCallback::Create(callback)); | 1613 SingleReleaseCallback::Create(callback)); |
1613 EXPECT_EQ(1u, context()->NumTextures()); | 1614 EXPECT_EQ(1u, context()->NumTextures()); |
1614 EXPECT_EQ(0u, release_sync_point); | 1615 EXPECT_EQ(0u, release_sync_point); |
1615 { | 1616 { |
1616 // Transfer the resource, expect the sync points to be consistent. | 1617 // Transfer the resource, expect the sync points to be consistent. |
1617 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1618 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
1618 resource_ids_to_transfer.push_back(resource); | 1619 resource_ids_to_transfer.push_back(resource); |
1619 TransferableResourceArray list; | 1620 TransferableResourceArray list; |
1620 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 1621 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
1621 ASSERT_EQ(1u, list.size()); | 1622 ASSERT_EQ(1u, list.size()); |
(...skipping 27 matching lines...) Expand all Loading... |
1649 EXPECT_LE(list[0].sync_point, release_sync_point); | 1650 EXPECT_LE(list[0].sync_point, release_sync_point); |
1650 EXPECT_FALSE(lost_resource); | 1651 EXPECT_FALSE(lost_resource); |
1651 } | 1652 } |
1652 | 1653 |
1653 // We're going to do the same thing as above, but testing the case where we | 1654 // 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. | 1655 // delete the resource before we receive it back. |
1655 sync_point = release_sync_point; | 1656 sync_point = release_sync_point; |
1656 EXPECT_LT(0u, sync_point); | 1657 EXPECT_LT(0u, sync_point); |
1657 release_sync_point = 0; | 1658 release_sync_point = 0; |
1658 resource = resource_provider_->CreateResourceFromTextureMailbox( | 1659 resource = resource_provider_->CreateResourceFromTextureMailbox( |
1659 TextureMailbox(mailbox, sync_point), | 1660 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), |
1660 SingleReleaseCallback::Create(callback)); | 1661 SingleReleaseCallback::Create(callback)); |
1661 EXPECT_EQ(1u, context()->NumTextures()); | 1662 EXPECT_EQ(1u, context()->NumTextures()); |
1662 EXPECT_EQ(0u, release_sync_point); | 1663 EXPECT_EQ(0u, release_sync_point); |
1663 { | 1664 { |
1664 // Transfer the resource, expect the sync points to be consistent. | 1665 // Transfer the resource, expect the sync points to be consistent. |
1665 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1666 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
1666 resource_ids_to_transfer.push_back(resource); | 1667 resource_ids_to_transfer.push_back(resource); |
1667 TransferableResourceArray list; | 1668 TransferableResourceArray list; |
1668 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 1669 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
1669 ASSERT_EQ(1u, list.size()); | 1670 ASSERT_EQ(1u, list.size()); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1828 } | 1829 } |
1829 | 1830 |
1830 // The resource should be lost. | 1831 // The resource should be lost. |
1831 EXPECT_TRUE(child_resource_provider_->IsLost(resource)); | 1832 EXPECT_TRUE(child_resource_provider_->IsLost(resource)); |
1832 | 1833 |
1833 // Lost resources stay in use in the parent forever. | 1834 // Lost resources stay in use in the parent forever. |
1834 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(resource)); | 1835 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(resource)); |
1835 } | 1836 } |
1836 | 1837 |
1837 TEST_P(ResourceProviderTest, LostMailboxInParent) { | 1838 TEST_P(ResourceProviderTest, LostMailboxInParent) { |
1838 unsigned release_sync_point = 0; | 1839 uint32 release_sync_point = 0; |
1839 bool lost_resource = false; | 1840 bool lost_resource = false; |
1840 bool release_called = false; | 1841 bool release_called = false; |
1841 unsigned sync_point = 0; | 1842 uint32 sync_point = 0; |
1842 ResourceProvider::ResourceId resource = CreateChildMailbox( | 1843 ResourceProvider::ResourceId resource = CreateChildMailbox( |
1843 &release_sync_point, &lost_resource, &release_called, &sync_point); | 1844 &release_sync_point, &lost_resource, &release_called, &sync_point); |
1844 | 1845 |
1845 ReturnedResourceArray returned_to_child; | 1846 ReturnedResourceArray returned_to_child; |
1846 int child_id = | 1847 int child_id = |
1847 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 1848 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
1848 { | 1849 { |
1849 // Transfer the resource to the parent. | 1850 // Transfer the resource to the parent. |
1850 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1851 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
1851 resource_ids_to_transfer.push_back(resource); | 1852 resource_ids_to_transfer.push_back(resource); |
(...skipping 26 matching lines...) Expand all Loading... |
1878 returned_to_child.clear(); | 1879 returned_to_child.clear(); |
1879 } | 1880 } |
1880 | 1881 |
1881 // Delete the resource in the child. Expect the resource to be lost if it's | 1882 // Delete the resource in the child. Expect the resource to be lost if it's |
1882 // a GL texture. | 1883 // a GL texture. |
1883 child_resource_provider_->DeleteResource(resource); | 1884 child_resource_provider_->DeleteResource(resource); |
1884 EXPECT_EQ(lost_resource, GetParam() == ResourceProvider::GLTexture); | 1885 EXPECT_EQ(lost_resource, GetParam() == ResourceProvider::GLTexture); |
1885 } | 1886 } |
1886 | 1887 |
1887 TEST_P(ResourceProviderTest, LostMailboxInGrandParent) { | 1888 TEST_P(ResourceProviderTest, LostMailboxInGrandParent) { |
1888 unsigned release_sync_point = 0; | 1889 uint32 release_sync_point = 0; |
1889 bool lost_resource = false; | 1890 bool lost_resource = false; |
1890 bool release_called = false; | 1891 bool release_called = false; |
1891 unsigned sync_point = 0; | 1892 uint32 sync_point = 0; |
1892 ResourceProvider::ResourceId resource = CreateChildMailbox( | 1893 ResourceProvider::ResourceId resource = CreateChildMailbox( |
1893 &release_sync_point, &lost_resource, &release_called, &sync_point); | 1894 &release_sync_point, &lost_resource, &release_called, &sync_point); |
1894 | 1895 |
1895 ReturnedResourceArray returned_to_child; | 1896 ReturnedResourceArray returned_to_child; |
1896 int child_id = | 1897 int child_id = |
1897 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 1898 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
1898 { | 1899 { |
1899 // Transfer the resource to the parent. | 1900 // Transfer the resource to the parent. |
1900 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1901 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
1901 resource_ids_to_transfer.push_back(resource); | 1902 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); | 1947 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); |
1947 returned_to_child.clear(); | 1948 returned_to_child.clear(); |
1948 } | 1949 } |
1949 | 1950 |
1950 // Delete the resource in the child. Expect the resource to be lost. | 1951 // Delete the resource in the child. Expect the resource to be lost. |
1951 child_resource_provider_->DeleteResource(resource); | 1952 child_resource_provider_->DeleteResource(resource); |
1952 EXPECT_TRUE(lost_resource); | 1953 EXPECT_TRUE(lost_resource); |
1953 } | 1954 } |
1954 | 1955 |
1955 TEST_P(ResourceProviderTest, Shutdown) { | 1956 TEST_P(ResourceProviderTest, Shutdown) { |
1956 unsigned release_sync_point = 0; | 1957 uint32 release_sync_point = 0; |
1957 bool lost_resource = false; | 1958 bool lost_resource = false; |
1958 bool release_called = false; | 1959 bool release_called = false; |
1959 unsigned sync_point = 0; | 1960 uint32 sync_point = 0; |
1960 CreateChildMailbox( | 1961 CreateChildMailbox( |
1961 &release_sync_point, &lost_resource, &release_called, &sync_point); | 1962 &release_sync_point, &lost_resource, &release_called, &sync_point); |
1962 | 1963 |
1963 EXPECT_EQ(0u, release_sync_point); | 1964 EXPECT_EQ(0u, release_sync_point); |
1964 EXPECT_FALSE(lost_resource); | 1965 EXPECT_FALSE(lost_resource); |
1965 | 1966 |
1966 child_resource_provider_.reset(); | 1967 child_resource_provider_.reset(); |
1967 | 1968 |
1968 if (GetParam() == ResourceProvider::GLTexture) { | 1969 if (GetParam() == ResourceProvider::GLTexture) { |
1969 EXPECT_LE(sync_point, release_sync_point); | 1970 EXPECT_LE(sync_point, release_sync_point); |
1970 } | 1971 } |
1971 EXPECT_TRUE(release_called); | 1972 EXPECT_TRUE(release_called); |
1972 EXPECT_FALSE(lost_resource); | 1973 EXPECT_FALSE(lost_resource); |
1973 } | 1974 } |
1974 | 1975 |
1975 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { | 1976 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { |
1976 unsigned release_sync_point = 0; | 1977 uint32 release_sync_point = 0; |
1977 bool lost_resource = false; | 1978 bool lost_resource = false; |
1978 bool release_called = false; | 1979 bool release_called = false; |
1979 unsigned sync_point = 0; | 1980 uint32 sync_point = 0; |
1980 ResourceProvider::ResourceId resource = CreateChildMailbox( | 1981 ResourceProvider::ResourceId resource = CreateChildMailbox( |
1981 &release_sync_point, &lost_resource, &release_called, &sync_point); | 1982 &release_sync_point, &lost_resource, &release_called, &sync_point); |
1982 | 1983 |
1983 // Transfer the resource, so we can't release it properly on shutdown. | 1984 // Transfer the resource, so we can't release it properly on shutdown. |
1984 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1985 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
1985 resource_ids_to_transfer.push_back(resource); | 1986 resource_ids_to_transfer.push_back(resource); |
1986 TransferableResourceArray list; | 1987 TransferableResourceArray list; |
1987 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 1988 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
1988 &list); | 1989 &list); |
1989 | 1990 |
1990 EXPECT_EQ(0u, release_sync_point); | 1991 EXPECT_EQ(0u, release_sync_point); |
1991 EXPECT_FALSE(lost_resource); | 1992 EXPECT_FALSE(lost_resource); |
1992 | 1993 |
1993 child_resource_provider_.reset(); | 1994 child_resource_provider_.reset(); |
1994 | 1995 |
1995 // Since the resource is in the parent, the child considers it lost. | 1996 // Since the resource is in the parent, the child considers it lost. |
1996 EXPECT_EQ(0u, release_sync_point); | 1997 EXPECT_EQ(0u, release_sync_point); |
1997 EXPECT_TRUE(lost_resource); | 1998 EXPECT_TRUE(lost_resource); |
1998 } | 1999 } |
1999 | 2000 |
2000 TEST_P(ResourceProviderTest, LostContext) { | 2001 TEST_P(ResourceProviderTest, LostContext) { |
2001 // TextureMailbox callbacks only exist for GL textures for now. | 2002 // TextureMailbox callbacks only exist for GL textures for now. |
2002 if (GetParam() != ResourceProvider::GLTexture) | 2003 if (GetParam() != ResourceProvider::GLTexture) |
2003 return; | 2004 return; |
2004 unsigned texture = context()->createTexture(); | 2005 unsigned texture = context()->createTexture(); |
2005 context()->bindTexture(GL_TEXTURE_2D, texture); | 2006 context()->bindTexture(GL_TEXTURE_2D, texture); |
2006 gpu::Mailbox mailbox; | 2007 gpu::Mailbox mailbox; |
2007 context()->genMailboxCHROMIUM(mailbox.name); | 2008 context()->genMailboxCHROMIUM(mailbox.name); |
2008 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 2009 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
2009 unsigned sync_point = context()->insertSyncPoint(); | 2010 uint32 sync_point = context()->insertSyncPoint(); |
2010 | 2011 |
2011 EXPECT_LT(0u, sync_point); | 2012 EXPECT_LT(0u, sync_point); |
2012 | 2013 |
2013 unsigned release_sync_point = 0; | 2014 uint32 release_sync_point = 0; |
2014 bool lost_resource = false; | 2015 bool lost_resource = false; |
2015 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 2016 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
2016 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); | 2017 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); |
2017 resource_provider_->CreateResourceFromTextureMailbox( | 2018 resource_provider_->CreateResourceFromTextureMailbox( |
2018 TextureMailbox(mailbox, sync_point), | 2019 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), callback.Pass()); |
2019 callback.Pass()); | |
2020 | 2020 |
2021 EXPECT_EQ(0u, release_sync_point); | 2021 EXPECT_EQ(0u, release_sync_point); |
2022 EXPECT_FALSE(lost_resource); | 2022 EXPECT_FALSE(lost_resource); |
2023 | 2023 |
2024 resource_provider_->DidLoseOutputSurface(); | 2024 resource_provider_->DidLoseOutputSurface(); |
2025 resource_provider_.reset(); | 2025 resource_provider_.reset(); |
2026 | 2026 |
2027 EXPECT_LE(sync_point, release_sync_point); | 2027 EXPECT_LE(sync_point, release_sync_point); |
2028 EXPECT_TRUE(lost_resource); | 2028 EXPECT_TRUE(lost_resource); |
2029 } | 2029 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2258 | 2258 |
2259 FakeOutputSurfaceClient output_surface_client; | 2259 FakeOutputSurfaceClient output_surface_client; |
2260 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2260 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
2261 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2261 context_owned.PassAs<TestWebGraphicsContext3D>())); |
2262 CHECK(output_surface->BindToClient(&output_surface_client)); | 2262 CHECK(output_surface->BindToClient(&output_surface_client)); |
2263 | 2263 |
2264 scoped_ptr<ResourceProvider> resource_provider( | 2264 scoped_ptr<ResourceProvider> resource_provider( |
2265 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2265 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2266 | 2266 |
2267 unsigned texture_id = 1; | 2267 unsigned texture_id = 1; |
2268 unsigned sync_point = 30; | 2268 uint32 sync_point = 30; |
2269 unsigned target = GL_TEXTURE_2D; | 2269 unsigned target = GL_TEXTURE_2D; |
2270 | 2270 |
2271 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2271 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
2272 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2272 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
2273 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2273 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
2274 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2274 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
2275 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2275 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
2276 | 2276 |
2277 gpu::Mailbox gpu_mailbox; | 2277 gpu::Mailbox gpu_mailbox; |
2278 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2278 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
2279 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 2279 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
2280 base::Bind(&EmptyReleaseCallback)); | 2280 base::Bind(&EmptyReleaseCallback)); |
2281 | 2281 |
2282 TextureMailbox mailbox(gpu_mailbox, sync_point); | 2282 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
2283 | 2283 |
2284 ResourceProvider::ResourceId id = | 2284 ResourceProvider::ResourceId id = |
2285 resource_provider->CreateResourceFromTextureMailbox( | 2285 resource_provider->CreateResourceFromTextureMailbox( |
2286 mailbox, callback.Pass()); | 2286 mailbox, callback.Pass()); |
2287 EXPECT_NE(0u, id); | 2287 EXPECT_NE(0u, id); |
2288 | 2288 |
2289 Mock::VerifyAndClearExpectations(context); | 2289 Mock::VerifyAndClearExpectations(context); |
2290 | 2290 |
2291 { | 2291 { |
2292 // Using the texture does a consume of the mailbox. | 2292 // Using the texture does a consume of the mailbox. |
(...skipping 29 matching lines...) Expand all Loading... |
2322 | 2322 |
2323 FakeOutputSurfaceClient output_surface_client; | 2323 FakeOutputSurfaceClient output_surface_client; |
2324 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2324 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
2325 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2325 context_owned.PassAs<TestWebGraphicsContext3D>())); |
2326 CHECK(output_surface->BindToClient(&output_surface_client)); | 2326 CHECK(output_surface->BindToClient(&output_surface_client)); |
2327 | 2327 |
2328 scoped_ptr<ResourceProvider> resource_provider( | 2328 scoped_ptr<ResourceProvider> resource_provider( |
2329 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2329 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2330 | 2330 |
2331 unsigned texture_id = 1; | 2331 unsigned texture_id = 1; |
2332 unsigned sync_point = 30; | 2332 uint32 sync_point = 30; |
2333 unsigned target = GL_TEXTURE_EXTERNAL_OES; | 2333 unsigned target = GL_TEXTURE_EXTERNAL_OES; |
2334 | 2334 |
2335 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2335 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
2336 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2336 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
2337 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2337 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
2338 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2338 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
2339 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2339 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
2340 | 2340 |
2341 gpu::Mailbox gpu_mailbox; | 2341 gpu::Mailbox gpu_mailbox; |
2342 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2342 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); | 3080 resource_provider->AllocateForTesting(id); |
3081 Mock::VerifyAndClearExpectations(context); | 3081 Mock::VerifyAndClearExpectations(context); |
3082 | 3082 |
3083 DCHECK_EQ(10u, context->PeekTextureId()); | 3083 DCHECK_EQ(10u, context->PeekTextureId()); |
3084 resource_provider->DeleteResource(id); | 3084 resource_provider->DeleteResource(id); |
3085 } | 3085 } |
3086 } | 3086 } |
3087 | 3087 |
3088 } // namespace | 3088 } // namespace |
3089 } // namespace cc | 3089 } // namespace cc |
OLD | NEW |