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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 132 } |
133 pending_produce_textures_.clear(); | 133 pending_produce_textures_.clear(); |
134 return sync_point; | 134 return sync_point; |
135 } | 135 } |
136 | 136 |
137 virtual void waitSyncPoint(unsigned sync_point) OVERRIDE { | 137 virtual void waitSyncPoint(unsigned sync_point) OVERRIDE { |
138 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); | 138 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); |
139 } | 139 } |
140 | 140 |
141 virtual void bindTexture(WGC3Denum target, WebGLId texture) OVERRIDE { | 141 virtual void bindTexture(WGC3Denum target, WebGLId texture) OVERRIDE { |
142 ASSERT_EQ(target, GL_TEXTURE_2D); | 142 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
143 ASSERT_TRUE(!texture || textures_.find(texture) != textures_.end()); | 143 ASSERT_TRUE(!texture || textures_.find(texture) != textures_.end()); |
144 current_texture_ = texture; | 144 current_texture_ = texture; |
145 } | 145 } |
146 | 146 |
147 virtual WebGLId createTexture() OVERRIDE { | 147 virtual WebGLId createTexture() OVERRIDE { |
148 WebGLId id = TestWebGraphicsContext3D::createTexture(); | 148 WebGLId id = TestWebGraphicsContext3D::createTexture(); |
149 textures_.add(id, make_scoped_ptr(new Texture)); | 149 textures_.add(id, make_scoped_ptr(new Texture)); |
150 return id; | 150 return id; |
151 } | 151 } |
152 | 152 |
153 virtual void deleteTexture(WebGLId id) OVERRIDE { | 153 virtual void deleteTexture(WebGLId id) OVERRIDE { |
154 TextureMap::iterator it = textures_.find(id); | 154 TextureMap::iterator it = textures_.find(id); |
155 ASSERT_FALSE(it == textures_.end()); | 155 ASSERT_FALSE(it == textures_.end()); |
156 textures_.erase(it); | 156 textures_.erase(it); |
157 if (current_texture_ == id) | 157 if (current_texture_ == id) |
158 current_texture_ = 0; | 158 current_texture_ = 0; |
159 } | 159 } |
160 | 160 |
161 virtual void texStorage2DEXT(WGC3Denum target, | 161 virtual void texStorage2DEXT(WGC3Denum target, |
162 WGC3Dint levels, | 162 WGC3Dint levels, |
163 WGC3Duint internalformat, | 163 WGC3Duint internalformat, |
164 WGC3Dint width, | 164 WGC3Dint width, |
165 WGC3Dint height) OVERRIDE { | 165 WGC3Dint height) OVERRIDE { |
166 ASSERT_TRUE(current_texture_); | 166 ASSERT_TRUE(current_texture_); |
167 ASSERT_EQ(target, GL_TEXTURE_2D); | 167 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
168 ASSERT_EQ(levels, 1); | 168 ASSERT_EQ(1, levels); |
169 WGC3Denum format = GL_RGBA; | 169 WGC3Denum format = GL_RGBA; |
170 switch (internalformat) { | 170 switch (internalformat) { |
171 case GL_RGBA8_OES: | 171 case GL_RGBA8_OES: |
172 break; | 172 break; |
173 case GL_BGRA8_EXT: | 173 case GL_BGRA8_EXT: |
174 format = GL_BGRA_EXT; | 174 format = GL_BGRA_EXT; |
175 break; | 175 break; |
176 default: | 176 default: |
177 NOTREACHED(); | 177 NOTREACHED(); |
178 } | 178 } |
179 AllocateTexture(gfx::Size(width, height), format); | 179 AllocateTexture(gfx::Size(width, height), format); |
180 } | 180 } |
181 | 181 |
182 virtual void texImage2D(WGC3Denum target, | 182 virtual void texImage2D(WGC3Denum target, |
183 WGC3Dint level, | 183 WGC3Dint level, |
184 WGC3Denum internalformat, | 184 WGC3Denum internalformat, |
185 WGC3Dsizei width, | 185 WGC3Dsizei width, |
186 WGC3Dsizei height, | 186 WGC3Dsizei height, |
187 WGC3Dint border, | 187 WGC3Dint border, |
188 WGC3Denum format, | 188 WGC3Denum format, |
189 WGC3Denum type, | 189 WGC3Denum type, |
190 const void* pixels) OVERRIDE { | 190 const void* pixels) OVERRIDE { |
191 ASSERT_TRUE(current_texture_); | 191 ASSERT_TRUE(current_texture_); |
192 ASSERT_EQ(target, GL_TEXTURE_2D); | 192 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
193 ASSERT_FALSE(level); | 193 ASSERT_FALSE(level); |
194 ASSERT_EQ(internalformat, format); | 194 ASSERT_EQ(internalformat, format); |
195 ASSERT_FALSE(border); | 195 ASSERT_FALSE(border); |
196 ASSERT_EQ(type, GL_UNSIGNED_BYTE); | 196 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
197 AllocateTexture(gfx::Size(width, height), format); | 197 AllocateTexture(gfx::Size(width, height), format); |
198 if (pixels) | 198 if (pixels) |
199 SetPixels(0, 0, width, height, pixels); | 199 SetPixels(0, 0, width, height, pixels); |
200 } | 200 } |
201 | 201 |
202 virtual void texSubImage2D(WGC3Denum target, | 202 virtual void texSubImage2D(WGC3Denum target, |
203 WGC3Dint level, | 203 WGC3Dint level, |
204 WGC3Dint xoffset, | 204 WGC3Dint xoffset, |
205 WGC3Dint yoffset, | 205 WGC3Dint yoffset, |
206 WGC3Dsizei width, | 206 WGC3Dsizei width, |
207 WGC3Dsizei height, | 207 WGC3Dsizei height, |
208 WGC3Denum format, | 208 WGC3Denum format, |
209 WGC3Denum type, | 209 WGC3Denum type, |
210 const void* pixels) OVERRIDE { | 210 const void* pixels) OVERRIDE { |
211 ASSERT_TRUE(current_texture_); | 211 ASSERT_TRUE(current_texture_); |
212 ASSERT_EQ(target, GL_TEXTURE_2D); | 212 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
213 ASSERT_FALSE(level); | 213 ASSERT_FALSE(level); |
214 ASSERT_TRUE(textures_.get(current_texture_)); | 214 ASSERT_TRUE(textures_.get(current_texture_)); |
215 ASSERT_EQ(textures_.get(current_texture_)->format, format); | 215 ASSERT_EQ(textures_.get(current_texture_)->format, format); |
216 ASSERT_EQ(type, GL_UNSIGNED_BYTE); | 216 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
217 ASSERT_TRUE(pixels); | 217 ASSERT_TRUE(pixels); |
218 SetPixels(xoffset, yoffset, width, height, pixels); | 218 SetPixels(xoffset, yoffset, width, height, pixels); |
219 } | 219 } |
220 | 220 |
221 virtual void texParameteri(WGC3Denum target, WGC3Denum param, WGC3Dint value) | 221 virtual void texParameteri(WGC3Denum target, WGC3Denum param, WGC3Dint value) |
222 OVERRIDE { | 222 OVERRIDE { |
223 ASSERT_TRUE(current_texture_); | 223 ASSERT_TRUE(current_texture_); |
224 ASSERT_EQ(target, GL_TEXTURE_2D); | 224 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
225 Texture* texture = textures_.get(current_texture_); | 225 Texture* texture = textures_.get(current_texture_); |
226 ASSERT_TRUE(texture); | 226 ASSERT_TRUE(texture); |
227 if (param != GL_TEXTURE_MIN_FILTER) | 227 if (param != GL_TEXTURE_MIN_FILTER) |
228 return; | 228 return; |
229 texture->filter = value; | 229 texture->filter = value; |
230 } | 230 } |
231 | 231 |
232 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) OVERRIDE { | 232 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) OVERRIDE { |
233 return shared_data_->GenMailbox(mailbox); | 233 return shared_data_->GenMailbox(mailbox); |
234 } | 234 } |
235 | 235 |
236 virtual void produceTextureCHROMIUM(WGC3Denum target, | 236 virtual void produceTextureCHROMIUM(WGC3Denum target, |
237 const WGC3Dbyte* mailbox) OVERRIDE { | 237 const WGC3Dbyte* mailbox) OVERRIDE { |
238 ASSERT_TRUE(current_texture_); | 238 ASSERT_TRUE(current_texture_); |
239 ASSERT_EQ(target, GL_TEXTURE_2D); | 239 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
240 | 240 |
241 // Delay moving the texture into the mailbox until the next | 241 // Delay moving the texture into the mailbox until the next |
242 // InsertSyncPoint, so that it is not visible to other contexts that | 242 // InsertSyncPoint, so that it is not visible to other contexts that |
243 // haven't waited on that sync point. | 243 // haven't waited on that sync point. |
244 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); | 244 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); |
245 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); | 245 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); |
246 pending->texture = textures_.take(current_texture_); | 246 pending->texture = textures_.take(current_texture_); |
247 textures_.set(current_texture_, scoped_ptr<Texture>()); | 247 textures_.set(current_texture_, scoped_ptr<Texture>()); |
248 pending_produce_textures_.push_back(pending.Pass()); | 248 pending_produce_textures_.push_back(pending.Pass()); |
249 } | 249 } |
250 | 250 |
251 virtual void consumeTextureCHROMIUM(WGC3Denum target, | 251 virtual void consumeTextureCHROMIUM(WGC3Denum target, |
252 const WGC3Dbyte* mailbox) OVERRIDE { | 252 const WGC3Dbyte* mailbox) OVERRIDE { |
253 ASSERT_TRUE(current_texture_); | 253 ASSERT_TRUE(current_texture_); |
254 ASSERT_EQ(target, GL_TEXTURE_2D); | 254 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
255 textures_.set( | 255 textures_.set( |
256 current_texture_, | 256 current_texture_, |
257 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_)); | 257 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_)); |
258 } | 258 } |
259 | 259 |
260 void GetPixels(gfx::Size size, WGC3Denum format, uint8_t* pixels) { | 260 void GetPixels(gfx::Size size, WGC3Denum format, uint8_t* pixels) { |
261 ASSERT_TRUE(current_texture_); | 261 ASSERT_TRUE(current_texture_); |
262 Texture* texture = textures_.get(current_texture_); | 262 Texture* texture = textures_.get(current_texture_); |
263 ASSERT_TRUE(texture); | 263 ASSERT_TRUE(texture); |
264 ASSERT_EQ(texture->size, size); | 264 ASSERT_EQ(texture->size, size); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 gfx::Size size(1, 1); | 672 gfx::Size size(1, 1); |
673 WGC3Denum format = GL_RGBA; | 673 WGC3Denum format = GL_RGBA; |
674 size_t pixel_size = TextureSize(size, format); | 674 size_t pixel_size = TextureSize(size, format); |
675 ASSERT_EQ(4U, pixel_size); | 675 ASSERT_EQ(4U, pixel_size); |
676 | 676 |
677 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( | 677 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( |
678 size, format, ResourceProvider::TextureUsageAny); | 678 size, format, ResourceProvider::TextureUsageAny); |
679 uint8_t data[4] = { 1, 2, 3, 4 }; | 679 uint8_t data[4] = { 1, 2, 3, 4 }; |
680 gfx::Rect rect(size); | 680 gfx::Rect rect(size); |
681 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); | 681 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); |
682 EXPECT_EQ(GL_LINEAR, GetResourceFilter(child_resource_provider.get(), id)); | 682 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 683 GetResourceFilter(child_resource_provider.get(), id)); |
683 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); | 684 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); |
684 EXPECT_EQ(GL_NEAREST, GetResourceFilter(child_resource_provider.get(), id)); | 685 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 686 GetResourceFilter(child_resource_provider.get(), id)); |
685 | 687 |
686 int child_id = resource_provider_->CreateChild(); | 688 int child_id = resource_provider_->CreateChild(); |
687 { | 689 { |
688 // Transfer some resource to the parent. | 690 // Transfer some resource to the parent. |
689 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 691 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
690 resource_ids_to_transfer.push_back(id); | 692 resource_ids_to_transfer.push_back(id); |
691 TransferableResourceArray list; | 693 TransferableResourceArray list; |
692 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, | 694 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, |
693 &list); | 695 &list); |
694 ASSERT_EQ(1u, list.size()); | 696 ASSERT_EQ(1u, list.size()); |
695 EXPECT_EQ(GL_NEAREST, list[0].filter); | 697 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), list[0].filter); |
696 resource_provider_->ReceiveFromChild(child_id, list); | 698 resource_provider_->ReceiveFromChild(child_id, list); |
697 } | 699 } |
698 ResourceProvider::ResourceIdMap resource_map = | 700 ResourceProvider::ResourceIdMap resource_map = |
699 resource_provider_->GetChildToParentMap(child_id); | 701 resource_provider_->GetChildToParentMap(child_id); |
700 ResourceProvider::ResourceId mapped_id = resource_map[id]; | 702 ResourceProvider::ResourceId mapped_id = resource_map[id]; |
701 EXPECT_NE(0u, mapped_id); | 703 EXPECT_NE(0u, mapped_id); |
702 EXPECT_EQ(GL_NEAREST, GetResourceFilter(resource_provider_.get(), mapped_id)); | 704 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 705 GetResourceFilter(resource_provider_.get(), mapped_id)); |
703 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR); | 706 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR); |
704 EXPECT_EQ(GL_LINEAR, GetResourceFilter(resource_provider_.get(), mapped_id)); | 707 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 708 GetResourceFilter(resource_provider_.get(), mapped_id)); |
705 { | 709 { |
706 // Transfer resources back from the parent to the child. | 710 // Transfer resources back from the parent to the child. |
707 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 711 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
708 resource_ids_to_transfer.push_back(mapped_id); | 712 resource_ids_to_transfer.push_back(mapped_id); |
709 TransferableResourceArray list; | 713 TransferableResourceArray list; |
710 resource_provider_->PrepareSendToChild( | 714 resource_provider_->PrepareSendToChild( |
711 child_id, resource_ids_to_transfer, &list); | 715 child_id, resource_ids_to_transfer, &list); |
712 ASSERT_EQ(1u, list.size()); | 716 ASSERT_EQ(1u, list.size()); |
713 EXPECT_EQ(GL_LINEAR, list[0].filter); | 717 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), list[0].filter); |
714 child_resource_provider->ReceiveFromParent(list); | 718 child_resource_provider->ReceiveFromParent(list); |
715 } | 719 } |
716 EXPECT_EQ(GL_LINEAR, GetResourceFilter(child_resource_provider.get(), id)); | 720 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 721 GetResourceFilter(child_resource_provider.get(), id)); |
717 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); | 722 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); |
718 EXPECT_EQ(GL_NEAREST, GetResourceFilter(child_resource_provider.get(), id)); | 723 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 724 GetResourceFilter(child_resource_provider.get(), id)); |
719 } | 725 } |
720 | 726 |
721 void ReleaseTextureMailbox(unsigned* release_sync_point, unsigned sync_point) { | 727 void ReleaseTextureMailbox(unsigned* release_sync_point, unsigned sync_point) { |
722 *release_sync_point = sync_point; | 728 *release_sync_point = sync_point; |
723 } | 729 } |
724 | 730 |
725 TEST_P(ResourceProviderTest, TransferMailboxResources) { | 731 TEST_P(ResourceProviderTest, TransferMailboxResources) { |
726 // Resource transfer is only supported with GL textures for now. | 732 // Resource transfer is only supported with GL textures for now. |
727 if (GetParam() != ResourceProvider::GLTexture) | 733 if (GetParam() != ResourceProvider::GLTexture) |
728 return; | 734 return; |
729 unsigned texture = context()->createTexture(); | 735 unsigned texture = context()->createTexture(); |
730 context()->bindTexture(GL_TEXTURE_2D, texture); | 736 context()->bindTexture(GL_TEXTURE_2D, texture); |
731 uint8_t data[4] = { 1, 2, 3, 4 }; | 737 uint8_t data[4] = { 1, 2, 3, 4 }; |
732 context()->texImage2D( | 738 context()->texImage2D( |
733 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); | 739 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); |
734 gpu::Mailbox mailbox; | 740 gpu::Mailbox mailbox; |
735 context()->genMailboxCHROMIUM(mailbox.name); | 741 context()->genMailboxCHROMIUM(mailbox.name); |
736 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 742 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
737 unsigned sync_point = context()->insertSyncPoint(); | 743 unsigned sync_point = context()->insertSyncPoint(); |
738 | 744 |
739 // All the logic below assumes that the sync points are all positive. | 745 // All the logic below assumes that the sync points are all positive. |
740 EXPECT_LT(0u, sync_point); | 746 EXPECT_LT(0u, sync_point); |
741 | 747 |
742 unsigned release_sync_point = 0; | 748 unsigned release_sync_point = 0; |
743 TextureMailbox::ReleaseCallback callback = | 749 TextureMailbox::ReleaseCallback callback = |
744 base::Bind(ReleaseTextureMailbox, &release_sync_point); | 750 base::Bind(ReleaseTextureMailbox, &release_sync_point); |
745 ResourceProvider::ResourceId resource = | 751 ResourceProvider::ResourceId resource = |
746 resource_provider_->CreateResourceFromTextureMailbox( | 752 resource_provider_->CreateResourceFromTextureMailbox( |
747 TextureMailbox(mailbox, callback, sync_point)); | 753 TextureMailbox(mailbox, callback, sync_point)); |
748 EXPECT_EQ(1u, context()->texture_count()); | 754 EXPECT_EQ(1, context()->texture_count()); |
749 EXPECT_EQ(0u, release_sync_point); | 755 EXPECT_EQ(0u, release_sync_point); |
750 { | 756 { |
751 // Transfer the resource, expect the sync points to be consistent. | 757 // Transfer the resource, expect the sync points to be consistent. |
752 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 758 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
753 resource_ids_to_transfer.push_back(resource); | 759 resource_ids_to_transfer.push_back(resource); |
754 TransferableResourceArray list; | 760 TransferableResourceArray list; |
755 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 761 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
756 ASSERT_EQ(1u, list.size()); | 762 ASSERT_EQ(1u, list.size()); |
757 EXPECT_LE(sync_point, list[0].sync_point); | 763 EXPECT_LE(sync_point, list[0].sync_point); |
758 EXPECT_EQ(0u, | 764 EXPECT_EQ(0, |
759 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); | 765 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); |
760 EXPECT_EQ(0u, release_sync_point); | 766 EXPECT_EQ(0u, release_sync_point); |
761 | 767 |
762 context()->waitSyncPoint(list[0].sync_point); | 768 context()->waitSyncPoint(list[0].sync_point); |
763 unsigned other_texture = context()->createTexture(); | 769 unsigned other_texture = context()->createTexture(); |
764 context()->bindTexture(GL_TEXTURE_2D, other_texture); | 770 context()->bindTexture(GL_TEXTURE_2D, other_texture); |
765 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 771 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
766 uint8_t test_data[4] = { 0 }; | 772 uint8_t test_data[4] = { 0 }; |
767 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); | 773 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); |
768 EXPECT_EQ(0u, memcmp(data, test_data, sizeof(data))); | 774 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
769 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 775 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
770 context()->deleteTexture(other_texture); | 776 context()->deleteTexture(other_texture); |
771 list[0].sync_point = context()->insertSyncPoint(); | 777 list[0].sync_point = context()->insertSyncPoint(); |
772 EXPECT_LT(0u, list[0].sync_point); | 778 EXPECT_LT(0u, list[0].sync_point); |
773 | 779 |
774 // Receive the resource, then delete it, expect the sync points to be | 780 // Receive the resource, then delete it, expect the sync points to be |
775 // consistent. | 781 // consistent. |
776 resource_provider_->ReceiveFromParent(list); | 782 resource_provider_->ReceiveFromParent(list); |
777 EXPECT_EQ(1u, context()->texture_count()); | 783 EXPECT_EQ(1, context()->texture_count()); |
778 EXPECT_EQ(0u, release_sync_point); | 784 EXPECT_EQ(0u, release_sync_point); |
779 | 785 |
780 resource_provider_->DeleteResource(resource); | 786 resource_provider_->DeleteResource(resource); |
781 EXPECT_LE(list[0].sync_point, release_sync_point); | 787 EXPECT_LE(list[0].sync_point, release_sync_point); |
782 } | 788 } |
783 | 789 |
784 // We're going to do the same thing as above, but testing the case where we | 790 // We're going to do the same thing as above, but testing the case where we |
785 // delete the resource before we receive it back. | 791 // delete the resource before we receive it back. |
786 sync_point = release_sync_point; | 792 sync_point = release_sync_point; |
787 EXPECT_LT(0u, sync_point); | 793 EXPECT_LT(0u, sync_point); |
788 release_sync_point = 0; | 794 release_sync_point = 0; |
789 resource = resource_provider_->CreateResourceFromTextureMailbox( | 795 resource = resource_provider_->CreateResourceFromTextureMailbox( |
790 TextureMailbox(mailbox, callback, sync_point)); | 796 TextureMailbox(mailbox, callback, sync_point)); |
791 EXPECT_EQ(1u, context()->texture_count()); | 797 EXPECT_EQ(1, context()->texture_count()); |
792 EXPECT_EQ(0u, release_sync_point); | 798 EXPECT_EQ(0u, release_sync_point); |
793 { | 799 { |
794 // Transfer the resource, expect the sync points to be consistent. | 800 // Transfer the resource, expect the sync points to be consistent. |
795 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 801 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
796 resource_ids_to_transfer.push_back(resource); | 802 resource_ids_to_transfer.push_back(resource); |
797 TransferableResourceArray list; | 803 TransferableResourceArray list; |
798 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 804 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
799 ASSERT_EQ(1u, list.size()); | 805 ASSERT_EQ(1u, list.size()); |
800 EXPECT_LE(sync_point, list[0].sync_point); | 806 EXPECT_LE(sync_point, list[0].sync_point); |
801 EXPECT_EQ(0u, | 807 EXPECT_EQ(0, |
802 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); | 808 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); |
803 EXPECT_EQ(0u, release_sync_point); | 809 EXPECT_EQ(0u, release_sync_point); |
804 | 810 |
805 context()->waitSyncPoint(list[0].sync_point); | 811 context()->waitSyncPoint(list[0].sync_point); |
806 unsigned other_texture = context()->createTexture(); | 812 unsigned other_texture = context()->createTexture(); |
807 context()->bindTexture(GL_TEXTURE_2D, other_texture); | 813 context()->bindTexture(GL_TEXTURE_2D, other_texture); |
808 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 814 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
809 uint8_t test_data[4] = { 0 }; | 815 uint8_t test_data[4] = { 0 }; |
810 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); | 816 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); |
811 EXPECT_EQ(0u, memcmp(data, test_data, sizeof(data))); | 817 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
812 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 818 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
813 context()->deleteTexture(other_texture); | 819 context()->deleteTexture(other_texture); |
814 list[0].sync_point = context()->insertSyncPoint(); | 820 list[0].sync_point = context()->insertSyncPoint(); |
815 EXPECT_LT(0u, list[0].sync_point); | 821 EXPECT_LT(0u, list[0].sync_point); |
816 | 822 |
817 // Delete the resource, which shouldn't do anything. | 823 // Delete the resource, which shouldn't do anything. |
818 resource_provider_->DeleteResource(resource); | 824 resource_provider_->DeleteResource(resource); |
819 EXPECT_EQ(1u, context()->texture_count()); | 825 EXPECT_EQ(1, context()->texture_count()); |
820 EXPECT_EQ(0u, release_sync_point); | 826 EXPECT_EQ(0u, release_sync_point); |
821 | 827 |
822 // Then receive the resource which should release the mailbox, expect the | 828 // Then receive the resource which should release the mailbox, expect the |
823 // sync points to be consistent. | 829 // sync points to be consistent. |
824 resource_provider_->ReceiveFromParent(list); | 830 resource_provider_->ReceiveFromParent(list); |
825 EXPECT_LE(list[0].sync_point, release_sync_point); | 831 EXPECT_LE(list[0].sync_point, release_sync_point); |
826 } | 832 } |
827 | 833 |
828 context()->waitSyncPoint(release_sync_point); | 834 context()->waitSyncPoint(release_sync_point); |
829 context()->bindTexture(GL_TEXTURE_2D, texture); | 835 context()->bindTexture(GL_TEXTURE_2D, texture); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 948 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
943 EXPECT_CALL( | 949 EXPECT_CALL( |
944 *context, | 950 *context, |
945 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 951 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
946 EXPECT_CALL(*context, | 952 EXPECT_CALL(*context, |
947 texParameteri(GL_TEXTURE_2D, | 953 texParameteri(GL_TEXTURE_2D, |
948 GL_TEXTURE_POOL_CHROMIUM, | 954 GL_TEXTURE_POOL_CHROMIUM, |
949 GL_TEXTURE_POOL_MANAGED_CHROMIUM)); | 955 GL_TEXTURE_POOL_MANAGED_CHROMIUM)); |
950 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( | 956 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( |
951 size, format, ResourceProvider::TextureUsageAny); | 957 size, format, ResourceProvider::TextureUsageAny); |
| 958 EXPECT_NE(0u, id); |
952 | 959 |
953 Mock::VerifyAndClearExpectations(context); | 960 Mock::VerifyAndClearExpectations(context); |
954 } | 961 } |
955 | 962 |
956 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { | 963 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { |
957 public: | 964 public: |
958 MOCK_METHOD0(createTexture, WebGLId()); | 965 MOCK_METHOD0(createTexture, WebGLId()); |
959 MOCK_METHOD1(deleteTexture, void(WebGLId texture_id)); | 966 MOCK_METHOD1(deleteTexture, void(WebGLId texture_id)); |
960 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); | 967 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
961 MOCK_METHOD9(texImage2D, | 968 MOCK_METHOD9(texImage2D, |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 Mock::VerifyAndClearExpectations(context); | 1156 Mock::VerifyAndClearExpectations(context); |
1150 } | 1157 } |
1151 | 1158 |
1152 INSTANTIATE_TEST_CASE_P( | 1159 INSTANTIATE_TEST_CASE_P( |
1153 ResourceProviderTests, | 1160 ResourceProviderTests, |
1154 ResourceProviderTest, | 1161 ResourceProviderTest, |
1155 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1162 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
1156 | 1163 |
1157 } // namespace | 1164 } // namespace |
1158 } // namespace cc | 1165 } // namespace cc |
OLD | NEW |