Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: trunk/src/cc/resources/resource_provider_unittest.cc

Issue 13334005: Revert 191400 "cc: Add ‘chromium_code’: 1 to cc.gyp and cc_t..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:mergeinfo
OLDNEW
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
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(static_cast<unsigned>(GL_TEXTURE_2D), target); 142 ASSERT_EQ(target, GL_TEXTURE_2D);
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(static_cast<unsigned>(GL_TEXTURE_2D), target); 167 ASSERT_EQ(target, GL_TEXTURE_2D);
168 ASSERT_EQ(1, levels); 168 ASSERT_EQ(levels, 1);
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(static_cast<unsigned>(GL_TEXTURE_2D), target); 192 ASSERT_EQ(target, GL_TEXTURE_2D);
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(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); 196 ASSERT_EQ(type, GL_UNSIGNED_BYTE);
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(static_cast<unsigned>(GL_TEXTURE_2D), target); 212 ASSERT_EQ(target, GL_TEXTURE_2D);
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(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); 216 ASSERT_EQ(type, GL_UNSIGNED_BYTE);
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(static_cast<unsigned>(GL_TEXTURE_2D), target); 224 ASSERT_EQ(target, GL_TEXTURE_2D);
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(static_cast<unsigned>(GL_TEXTURE_2D), target); 239 ASSERT_EQ(target, GL_TEXTURE_2D);
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(static_cast<unsigned>(GL_TEXTURE_2D), target); 254 ASSERT_EQ(target, GL_TEXTURE_2D);
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
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(static_cast<unsigned>(GL_LINEAR), 682 EXPECT_EQ(GL_LINEAR, GetResourceFilter(child_resource_provider.get(), id));
683 GetResourceFilter(child_resource_provider.get(), id));
684 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); 683 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST);
685 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), 684 EXPECT_EQ(GL_NEAREST, GetResourceFilter(child_resource_provider.get(), id));
686 GetResourceFilter(child_resource_provider.get(), id));
687 685
688 int child_id = resource_provider_->CreateChild(); 686 int child_id = resource_provider_->CreateChild();
689 { 687 {
690 // Transfer some resource to the parent. 688 // Transfer some resource to the parent.
691 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 689 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
692 resource_ids_to_transfer.push_back(id); 690 resource_ids_to_transfer.push_back(id);
693 TransferableResourceArray list; 691 TransferableResourceArray list;
694 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, 692 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer,
695 &list); 693 &list);
696 ASSERT_EQ(1u, list.size()); 694 ASSERT_EQ(1u, list.size());
697 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), list[0].filter); 695 EXPECT_EQ(GL_NEAREST, list[0].filter);
698 resource_provider_->ReceiveFromChild(child_id, list); 696 resource_provider_->ReceiveFromChild(child_id, list);
699 } 697 }
700 ResourceProvider::ResourceIdMap resource_map = 698 ResourceProvider::ResourceIdMap resource_map =
701 resource_provider_->GetChildToParentMap(child_id); 699 resource_provider_->GetChildToParentMap(child_id);
702 ResourceProvider::ResourceId mapped_id = resource_map[id]; 700 ResourceProvider::ResourceId mapped_id = resource_map[id];
703 EXPECT_NE(0u, mapped_id); 701 EXPECT_NE(0u, mapped_id);
704 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), 702 EXPECT_EQ(GL_NEAREST, GetResourceFilter(resource_provider_.get(), mapped_id));
705 GetResourceFilter(resource_provider_.get(), mapped_id));
706 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR); 703 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR);
707 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), 704 EXPECT_EQ(GL_LINEAR, GetResourceFilter(resource_provider_.get(), mapped_id));
708 GetResourceFilter(resource_provider_.get(), mapped_id));
709 { 705 {
710 // Transfer resources back from the parent to the child. 706 // Transfer resources back from the parent to the child.
711 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 707 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
712 resource_ids_to_transfer.push_back(mapped_id); 708 resource_ids_to_transfer.push_back(mapped_id);
713 TransferableResourceArray list; 709 TransferableResourceArray list;
714 resource_provider_->PrepareSendToChild( 710 resource_provider_->PrepareSendToChild(
715 child_id, resource_ids_to_transfer, &list); 711 child_id, resource_ids_to_transfer, &list);
716 ASSERT_EQ(1u, list.size()); 712 ASSERT_EQ(1u, list.size());
717 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), list[0].filter); 713 EXPECT_EQ(GL_LINEAR, list[0].filter);
718 child_resource_provider->ReceiveFromParent(list); 714 child_resource_provider->ReceiveFromParent(list);
719 } 715 }
720 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), 716 EXPECT_EQ(GL_LINEAR, GetResourceFilter(child_resource_provider.get(), id));
721 GetResourceFilter(child_resource_provider.get(), id));
722 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); 717 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST);
723 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), 718 EXPECT_EQ(GL_NEAREST, GetResourceFilter(child_resource_provider.get(), id));
724 GetResourceFilter(child_resource_provider.get(), id));
725 } 719 }
726 720
727 void ReleaseTextureMailbox(unsigned* release_sync_point, unsigned sync_point) { 721 void ReleaseTextureMailbox(unsigned* release_sync_point, unsigned sync_point) {
728 *release_sync_point = sync_point; 722 *release_sync_point = sync_point;
729 } 723 }
730 724
731 TEST_P(ResourceProviderTest, TransferMailboxResources) { 725 TEST_P(ResourceProviderTest, TransferMailboxResources) {
732 // Resource transfer is only supported with GL textures for now. 726 // Resource transfer is only supported with GL textures for now.
733 if (GetParam() != ResourceProvider::GLTexture) 727 if (GetParam() != ResourceProvider::GLTexture)
734 return; 728 return;
735 unsigned texture = context()->createTexture(); 729 unsigned texture = context()->createTexture();
736 context()->bindTexture(GL_TEXTURE_2D, texture); 730 context()->bindTexture(GL_TEXTURE_2D, texture);
737 uint8_t data[4] = { 1, 2, 3, 4 }; 731 uint8_t data[4] = { 1, 2, 3, 4 };
738 context()->texImage2D( 732 context()->texImage2D(
739 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); 733 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data);
740 gpu::Mailbox mailbox; 734 gpu::Mailbox mailbox;
741 context()->genMailboxCHROMIUM(mailbox.name); 735 context()->genMailboxCHROMIUM(mailbox.name);
742 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 736 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
743 unsigned sync_point = context()->insertSyncPoint(); 737 unsigned sync_point = context()->insertSyncPoint();
744 738
745 // All the logic below assumes that the sync points are all positive. 739 // All the logic below assumes that the sync points are all positive.
746 EXPECT_LT(0u, sync_point); 740 EXPECT_LT(0u, sync_point);
747 741
748 unsigned release_sync_point = 0; 742 unsigned release_sync_point = 0;
749 TextureMailbox::ReleaseCallback callback = 743 TextureMailbox::ReleaseCallback callback =
750 base::Bind(ReleaseTextureMailbox, &release_sync_point); 744 base::Bind(ReleaseTextureMailbox, &release_sync_point);
751 ResourceProvider::ResourceId resource = 745 ResourceProvider::ResourceId resource =
752 resource_provider_->CreateResourceFromTextureMailbox( 746 resource_provider_->CreateResourceFromTextureMailbox(
753 TextureMailbox(mailbox, callback, sync_point)); 747 TextureMailbox(mailbox, callback, sync_point));
754 EXPECT_EQ(1, context()->texture_count()); 748 EXPECT_EQ(1u, context()->texture_count());
755 EXPECT_EQ(0u, release_sync_point); 749 EXPECT_EQ(0u, release_sync_point);
756 { 750 {
757 // Transfer the resource, expect the sync points to be consistent. 751 // Transfer the resource, expect the sync points to be consistent.
758 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 752 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
759 resource_ids_to_transfer.push_back(resource); 753 resource_ids_to_transfer.push_back(resource);
760 TransferableResourceArray list; 754 TransferableResourceArray list;
761 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); 755 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list);
762 ASSERT_EQ(1u, list.size()); 756 ASSERT_EQ(1u, list.size());
763 EXPECT_LE(sync_point, list[0].sync_point); 757 EXPECT_LE(sync_point, list[0].sync_point);
764 EXPECT_EQ(0, 758 EXPECT_EQ(0u,
765 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); 759 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name)));
766 EXPECT_EQ(0u, release_sync_point); 760 EXPECT_EQ(0u, release_sync_point);
767 761
768 context()->waitSyncPoint(list[0].sync_point); 762 context()->waitSyncPoint(list[0].sync_point);
769 unsigned other_texture = context()->createTexture(); 763 unsigned other_texture = context()->createTexture();
770 context()->bindTexture(GL_TEXTURE_2D, other_texture); 764 context()->bindTexture(GL_TEXTURE_2D, other_texture);
771 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 765 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
772 uint8_t test_data[4] = { 0 }; 766 uint8_t test_data[4] = { 0 };
773 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); 767 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data);
774 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 768 EXPECT_EQ(0u, memcmp(data, test_data, sizeof(data)));
775 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 769 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
776 context()->deleteTexture(other_texture); 770 context()->deleteTexture(other_texture);
777 list[0].sync_point = context()->insertSyncPoint(); 771 list[0].sync_point = context()->insertSyncPoint();
778 EXPECT_LT(0u, list[0].sync_point); 772 EXPECT_LT(0u, list[0].sync_point);
779 773
780 // Receive the resource, then delete it, expect the sync points to be 774 // Receive the resource, then delete it, expect the sync points to be
781 // consistent. 775 // consistent.
782 resource_provider_->ReceiveFromParent(list); 776 resource_provider_->ReceiveFromParent(list);
783 EXPECT_EQ(1, context()->texture_count()); 777 EXPECT_EQ(1u, context()->texture_count());
784 EXPECT_EQ(0u, release_sync_point); 778 EXPECT_EQ(0u, release_sync_point);
785 779
786 resource_provider_->DeleteResource(resource); 780 resource_provider_->DeleteResource(resource);
787 EXPECT_LE(list[0].sync_point, release_sync_point); 781 EXPECT_LE(list[0].sync_point, release_sync_point);
788 } 782 }
789 783
790 // We're going to do the same thing as above, but testing the case where we 784 // We're going to do the same thing as above, but testing the case where we
791 // delete the resource before we receive it back. 785 // delete the resource before we receive it back.
792 sync_point = release_sync_point; 786 sync_point = release_sync_point;
793 EXPECT_LT(0u, sync_point); 787 EXPECT_LT(0u, sync_point);
794 release_sync_point = 0; 788 release_sync_point = 0;
795 resource = resource_provider_->CreateResourceFromTextureMailbox( 789 resource = resource_provider_->CreateResourceFromTextureMailbox(
796 TextureMailbox(mailbox, callback, sync_point)); 790 TextureMailbox(mailbox, callback, sync_point));
797 EXPECT_EQ(1, context()->texture_count()); 791 EXPECT_EQ(1u, context()->texture_count());
798 EXPECT_EQ(0u, release_sync_point); 792 EXPECT_EQ(0u, release_sync_point);
799 { 793 {
800 // Transfer the resource, expect the sync points to be consistent. 794 // Transfer the resource, expect the sync points to be consistent.
801 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 795 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
802 resource_ids_to_transfer.push_back(resource); 796 resource_ids_to_transfer.push_back(resource);
803 TransferableResourceArray list; 797 TransferableResourceArray list;
804 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); 798 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list);
805 ASSERT_EQ(1u, list.size()); 799 ASSERT_EQ(1u, list.size());
806 EXPECT_LE(sync_point, list[0].sync_point); 800 EXPECT_LE(sync_point, list[0].sync_point);
807 EXPECT_EQ(0, 801 EXPECT_EQ(0u,
808 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); 802 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name)));
809 EXPECT_EQ(0u, release_sync_point); 803 EXPECT_EQ(0u, release_sync_point);
810 804
811 context()->waitSyncPoint(list[0].sync_point); 805 context()->waitSyncPoint(list[0].sync_point);
812 unsigned other_texture = context()->createTexture(); 806 unsigned other_texture = context()->createTexture();
813 context()->bindTexture(GL_TEXTURE_2D, other_texture); 807 context()->bindTexture(GL_TEXTURE_2D, other_texture);
814 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 808 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
815 uint8_t test_data[4] = { 0 }; 809 uint8_t test_data[4] = { 0 };
816 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); 810 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data);
817 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 811 EXPECT_EQ(0u, memcmp(data, test_data, sizeof(data)));
818 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 812 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
819 context()->deleteTexture(other_texture); 813 context()->deleteTexture(other_texture);
820 list[0].sync_point = context()->insertSyncPoint(); 814 list[0].sync_point = context()->insertSyncPoint();
821 EXPECT_LT(0u, list[0].sync_point); 815 EXPECT_LT(0u, list[0].sync_point);
822 816
823 // Delete the resource, which shouldn't do anything. 817 // Delete the resource, which shouldn't do anything.
824 resource_provider_->DeleteResource(resource); 818 resource_provider_->DeleteResource(resource);
825 EXPECT_EQ(1, context()->texture_count()); 819 EXPECT_EQ(1u, context()->texture_count());
826 EXPECT_EQ(0u, release_sync_point); 820 EXPECT_EQ(0u, release_sync_point);
827 821
828 // Then receive the resource which should release the mailbox, expect the 822 // Then receive the resource which should release the mailbox, expect the
829 // sync points to be consistent. 823 // sync points to be consistent.
830 resource_provider_->ReceiveFromParent(list); 824 resource_provider_->ReceiveFromParent(list);
831 EXPECT_LE(list[0].sync_point, release_sync_point); 825 EXPECT_LE(list[0].sync_point, release_sync_point);
832 } 826 }
833 827
834 context()->waitSyncPoint(release_sync_point); 828 context()->waitSyncPoint(release_sync_point);
835 context()->bindTexture(GL_TEXTURE_2D, texture); 829 context()->bindTexture(GL_TEXTURE_2D, texture);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 942 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
949 EXPECT_CALL( 943 EXPECT_CALL(
950 *context, 944 *context,
951 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 945 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
952 EXPECT_CALL(*context, 946 EXPECT_CALL(*context,
953 texParameteri(GL_TEXTURE_2D, 947 texParameteri(GL_TEXTURE_2D,
954 GL_TEXTURE_POOL_CHROMIUM, 948 GL_TEXTURE_POOL_CHROMIUM,
955 GL_TEXTURE_POOL_MANAGED_CHROMIUM)); 949 GL_TEXTURE_POOL_MANAGED_CHROMIUM));
956 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( 950 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource(
957 size, format, ResourceProvider::TextureUsageAny); 951 size, format, ResourceProvider::TextureUsageAny);
958 EXPECT_NE(0u, id);
959 952
960 Mock::VerifyAndClearExpectations(context); 953 Mock::VerifyAndClearExpectations(context);
961 } 954 }
962 955
963 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { 956 class AllocationTrackingContext3D : public TestWebGraphicsContext3D {
964 public: 957 public:
965 MOCK_METHOD0(createTexture, WebGLId()); 958 MOCK_METHOD0(createTexture, WebGLId());
966 MOCK_METHOD1(deleteTexture, void(WebGLId texture_id)); 959 MOCK_METHOD1(deleteTexture, void(WebGLId texture_id));
967 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); 960 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture));
968 MOCK_METHOD9(texImage2D, 961 MOCK_METHOD9(texImage2D,
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 Mock::VerifyAndClearExpectations(context); 1149 Mock::VerifyAndClearExpectations(context);
1157 } 1150 }
1158 1151
1159 INSTANTIATE_TEST_CASE_P( 1152 INSTANTIATE_TEST_CASE_P(
1160 ResourceProviderTests, 1153 ResourceProviderTests,
1161 ResourceProviderTest, 1154 ResourceProviderTest,
1162 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); 1155 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap));
1163 1156
1164 } // namespace 1157 } // namespace
1165 } // namespace cc 1158 } // namespace cc
OLDNEW
« no previous file with comments | « trunk/src/cc/resources/prioritized_resource_unittest.cc ('k') | trunk/src/cc/resources/resource_update_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698