OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 pending_produce_textures_.begin(); | 180 pending_produce_textures_.begin(); |
181 it != pending_produce_textures_.end(); | 181 it != pending_produce_textures_.end(); |
182 ++it) { | 182 ++it) { |
183 shared_data_->ProduceTexture( | 183 shared_data_->ProduceTexture( |
184 (*it)->mailbox, sync_point, (*it)->texture); | 184 (*it)->mailbox, sync_point, (*it)->texture); |
185 } | 185 } |
186 pending_produce_textures_.clear(); | 186 pending_produce_textures_.clear(); |
187 return sync_point; | 187 return sync_point; |
188 } | 188 } |
189 | 189 |
190 void waitSyncPoint(GLuint sync_point) override { | 190 void waitSyncPoint(GLuint sync_point, |
191 const gpu::SyncToken& sync_token) override { | |
191 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); | 192 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); |
193 if (last_waited_sync_token_.release_count() > sync_token.release_count()) { | |
194 last_waited_sync_token_ = sync_token; | |
195 } | |
192 } | 196 } |
193 | 197 |
194 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } | 198 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } |
195 | 199 |
200 const gpu::SyncToken last_waited_sync_token() const { | |
dcheng
2015/10/27 19:09:28
Just curious: did you intentionally not return a c
David Yen
2015/10/28 22:03:43
Good catch, was a typo.
| |
201 return last_waited_sync_token_; | |
202 } | |
203 | |
196 void texStorage2DEXT(GLenum target, | 204 void texStorage2DEXT(GLenum target, |
197 GLint levels, | 205 GLint levels, |
198 GLuint internalformat, | 206 GLuint internalformat, |
199 GLint width, | 207 GLint width, |
200 GLint height) override { | 208 GLint height) override { |
201 CheckTextureIsBound(target); | 209 CheckTextureIsBound(target); |
202 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 210 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
203 ASSERT_EQ(1, levels); | 211 ASSERT_EQ(1, levels); |
204 GLenum format = GL_RGBA; | 212 GLenum format = GL_RGBA; |
205 switch (internalformat) { | 213 switch (internalformat) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); | 277 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); |
270 base::AutoLock lock_for_texture_access(namespace_->lock); | 278 base::AutoLock lock_for_texture_access(namespace_->lock); |
271 pending->texture = UnboundTexture(texture); | 279 pending->texture = UnboundTexture(texture); |
272 pending_produce_textures_.push_back(pending.Pass()); | 280 pending_produce_textures_.push_back(pending.Pass()); |
273 } | 281 } |
274 | 282 |
275 GLuint createAndConsumeTextureCHROMIUM(GLenum target, | 283 GLuint createAndConsumeTextureCHROMIUM(GLenum target, |
276 const GLbyte* mailbox) override { | 284 const GLbyte* mailbox) override { |
277 GLuint texture_id = createTexture(); | 285 GLuint texture_id = createTexture(); |
278 base::AutoLock lock_for_texture_access(namespace_->lock); | 286 base::AutoLock lock_for_texture_access(namespace_->lock); |
279 scoped_refptr<TestTexture> texture = | 287 scoped_refptr<TestTexture> texture = shared_data_->ConsumeTexture( |
280 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); | 288 mailbox, last_waited_sync_point_, last_waited_sync_token_); |
281 namespace_->textures.Replace(texture_id, texture); | 289 namespace_->textures.Replace(texture_id, texture); |
282 return texture_id; | 290 return texture_id; |
283 } | 291 } |
284 | 292 |
285 void GetPixels(const gfx::Size& size, | 293 void GetPixels(const gfx::Size& size, |
286 ResourceFormat format, | 294 ResourceFormat format, |
287 uint8_t* pixels) { | 295 uint8_t* pixels) { |
288 CheckTextureIsBound(GL_TEXTURE_2D); | 296 CheckTextureIsBound(GL_TEXTURE_2D); |
289 base::AutoLock lock_for_texture_access(namespace_->lock); | 297 base::AutoLock lock_for_texture_access(namespace_->lock); |
290 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); | 298 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 } | 347 } |
340 } | 348 } |
341 | 349 |
342 struct PendingProduceTexture { | 350 struct PendingProduceTexture { |
343 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; | 351 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; |
344 scoped_refptr<TestTexture> texture; | 352 scoped_refptr<TestTexture> texture; |
345 }; | 353 }; |
346 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; | 354 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; |
347 ContextSharedData* shared_data_; | 355 ContextSharedData* shared_data_; |
348 GLuint last_waited_sync_point_; | 356 GLuint last_waited_sync_point_; |
357 gpu::SyncToken last_waited_sync_token_; | |
349 PendingProduceTextureList pending_produce_textures_; | 358 PendingProduceTextureList pending_produce_textures_; |
350 }; | 359 }; |
351 | 360 |
352 void GetResourcePixels(ResourceProvider* resource_provider, | 361 void GetResourcePixels(ResourceProvider* resource_provider, |
353 ResourceProviderContext* context, | 362 ResourceProviderContext* context, |
354 ResourceId id, | 363 ResourceId id, |
355 const gfx::Size& size, | 364 const gfx::Size& size, |
356 ResourceFormat format, | 365 ResourceFormat format, |
357 uint8_t* pixels) { | 366 uint8_t* pixels) { |
358 resource_provider->WaitSyncPointIfNeeded(id); | 367 resource_provider->WaitSyncPointIfNeeded(id); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 list[2].mailbox_holder.texture_target); | 655 list[2].mailbox_holder.texture_target); |
647 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), | 656 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), |
648 list[3].mailbox_holder.texture_target); | 657 list[3].mailbox_holder.texture_target); |
649 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 658 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
650 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); | 659 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); |
651 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); | 660 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); |
652 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id4)); | 661 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id4)); |
653 resource_provider_->ReceiveFromChild(child_id, list); | 662 resource_provider_->ReceiveFromChild(child_id, list); |
654 EXPECT_NE(list[0].mailbox_holder.sync_point, | 663 EXPECT_NE(list[0].mailbox_holder.sync_point, |
655 context3d_->last_waited_sync_point()); | 664 context3d_->last_waited_sync_point()); |
665 EXPECT_NE(list[0].mailbox_holder.sync_token, | |
666 context3d_->last_waited_sync_token()); | |
656 { | 667 { |
657 resource_provider_->WaitSyncPointIfNeeded(list[0].id); | 668 resource_provider_->WaitSyncPointIfNeeded(list[0].id); |
658 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), | 669 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), |
659 list[0].id); | 670 list[0].id); |
660 } | 671 } |
661 EXPECT_EQ(list[0].mailbox_holder.sync_point, | 672 EXPECT_EQ(list[0].mailbox_holder.sync_point, |
662 context3d_->last_waited_sync_point()); | 673 context3d_->last_waited_sync_point()); |
674 EXPECT_EQ(list[0].mailbox_holder.sync_token, | |
675 context3d_->last_waited_sync_token()); | |
663 ResourceProvider::ResourceIdSet resource_ids_to_receive; | 676 ResourceProvider::ResourceIdSet resource_ids_to_receive; |
664 resource_ids_to_receive.insert(id1); | 677 resource_ids_to_receive.insert(id1); |
665 resource_ids_to_receive.insert(id2); | 678 resource_ids_to_receive.insert(id2); |
666 resource_ids_to_receive.insert(id3); | 679 resource_ids_to_receive.insert(id3); |
667 resource_ids_to_receive.insert(id4); | 680 resource_ids_to_receive.insert(id4); |
668 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 681 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
669 resource_ids_to_receive); | 682 resource_ids_to_receive); |
670 } | 683 } |
671 | 684 |
672 EXPECT_EQ(4u, resource_provider_->num_resources()); | 685 EXPECT_EQ(4u, resource_provider_->num_resources()); |
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2058 TransferableResourceArray list; | 2071 TransferableResourceArray list; |
2059 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 2072 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
2060 ASSERT_EQ(1u, list.size()); | 2073 ASSERT_EQ(1u, list.size()); |
2061 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); | 2074 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); |
2062 EXPECT_EQ(0, | 2075 EXPECT_EQ(0, |
2063 memcmp(mailbox.name, | 2076 memcmp(mailbox.name, |
2064 list[0].mailbox_holder.mailbox.name, | 2077 list[0].mailbox_holder.mailbox.name, |
2065 sizeof(mailbox.name))); | 2078 sizeof(mailbox.name))); |
2066 EXPECT_EQ(0u, release_sync_point); | 2079 EXPECT_EQ(0u, release_sync_point); |
2067 | 2080 |
2068 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); | 2081 context()->waitSyncPoint(list[0].mailbox_holder.sync_point, |
2082 list[0].mailbox_holder.sync_token); | |
2069 unsigned other_texture = | 2083 unsigned other_texture = |
2070 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 2084 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
2071 uint8_t test_data[4] = { 0 }; | 2085 uint8_t test_data[4] = { 0 }; |
2072 context()->GetPixels( | 2086 context()->GetPixels( |
2073 gfx::Size(1, 1), RGBA_8888, test_data); | 2087 gfx::Size(1, 1), RGBA_8888, test_data); |
2074 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | 2088 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
2075 | 2089 |
2076 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, | 2090 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, |
2077 mailbox.name); | 2091 mailbox.name); |
2078 context()->deleteTexture(other_texture); | 2092 context()->deleteTexture(other_texture); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2110 TransferableResourceArray list; | 2124 TransferableResourceArray list; |
2111 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 2125 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
2112 ASSERT_EQ(1u, list.size()); | 2126 ASSERT_EQ(1u, list.size()); |
2113 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); | 2127 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); |
2114 EXPECT_EQ(0, | 2128 EXPECT_EQ(0, |
2115 memcmp(mailbox.name, | 2129 memcmp(mailbox.name, |
2116 list[0].mailbox_holder.mailbox.name, | 2130 list[0].mailbox_holder.mailbox.name, |
2117 sizeof(mailbox.name))); | 2131 sizeof(mailbox.name))); |
2118 EXPECT_EQ(0u, release_sync_point); | 2132 EXPECT_EQ(0u, release_sync_point); |
2119 | 2133 |
2120 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); | 2134 context()->waitSyncPoint(list[0].mailbox_holder.sync_point, |
2135 list[0].mailbox_holder.sync_token); | |
2121 unsigned other_texture = | 2136 unsigned other_texture = |
2122 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 2137 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
2123 uint8_t test_data[4] = { 0 }; | 2138 uint8_t test_data[4] = { 0 }; |
2124 context()->GetPixels( | 2139 context()->GetPixels( |
2125 gfx::Size(1, 1), RGBA_8888, test_data); | 2140 gfx::Size(1, 1), RGBA_8888, test_data); |
2126 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | 2141 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
2127 | 2142 |
2128 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, | 2143 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, |
2129 mailbox.name); | 2144 mailbox.name); |
2130 context()->deleteTexture(other_texture); | 2145 context()->deleteTexture(other_texture); |
2131 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); | 2146 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); |
2132 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); | 2147 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); |
2133 | 2148 |
2134 // Delete the resource, which shouldn't do anything. | 2149 // Delete the resource, which shouldn't do anything. |
2135 resource_provider_->DeleteResource(resource); | 2150 resource_provider_->DeleteResource(resource); |
2136 EXPECT_EQ(1u, context()->NumTextures()); | 2151 EXPECT_EQ(1u, context()->NumTextures()); |
2137 EXPECT_EQ(0u, release_sync_point); | 2152 EXPECT_EQ(0u, release_sync_point); |
2138 | 2153 |
2139 // Then receive the resource which should release the mailbox, expect the | 2154 // Then receive the resource which should release the mailbox, expect the |
2140 // sync points to be consistent. | 2155 // sync points to be consistent. |
2141 ReturnedResourceArray returned; | 2156 ReturnedResourceArray returned; |
2142 TransferableResource::ReturnResources(list, &returned); | 2157 TransferableResource::ReturnResources(list, &returned); |
2143 resource_provider_->ReceiveReturnsFromParent(returned); | 2158 resource_provider_->ReceiveReturnsFromParent(returned); |
2144 EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); | 2159 EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); |
2145 EXPECT_FALSE(lost_resource); | 2160 EXPECT_FALSE(lost_resource); |
2146 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); | 2161 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); |
2147 } | 2162 } |
2148 | 2163 |
2149 context()->waitSyncPoint(release_sync_point); | 2164 context()->waitSyncPoint(release_sync_point, gpu::SyncToken()); |
2150 texture = | 2165 texture = |
2151 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 2166 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
2152 context()->deleteTexture(texture); | 2167 context()->deleteTexture(texture); |
2153 } | 2168 } |
2154 | 2169 |
2155 TEST_P(ResourceProviderTest, LostResourceInParent) { | 2170 TEST_P(ResourceProviderTest, LostResourceInParent) { |
2156 gfx::Size size(1, 1); | 2171 gfx::Size size(1, 1); |
2157 ResourceFormat format = RGBA_8888; | 2172 ResourceFormat format = RGBA_8888; |
2158 ResourceId resource = child_resource_provider_->CreateResource( | 2173 ResourceId resource = child_resource_provider_->CreateResource( |
2159 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); | 2174 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2779 | 2794 |
2780 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 2795 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
2781 output_surface.get(), shared_bitmap_manager, gpu_memory_buffer_manager, | 2796 output_surface.get(), shared_bitmap_manager, gpu_memory_buffer_manager, |
2782 main_thread_task_runner, 0, 1, use_image_texture_targets_)); | 2797 main_thread_task_runner, 0, 1, use_image_texture_targets_)); |
2783 | 2798 |
2784 unsigned texture_id = 1; | 2799 unsigned texture_id = 1; |
2785 uint32 sync_point = 30; | 2800 uint32 sync_point = 30; |
2786 unsigned target = GL_TEXTURE_2D; | 2801 unsigned target = GL_TEXTURE_2D; |
2787 | 2802 |
2788 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2803 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
2789 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2804 EXPECT_CALL(*context, waitSyncPoint(_, _)).Times(0); |
2790 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2805 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
2791 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2806 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
2792 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 2807 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
2793 | 2808 |
2794 gpu::Mailbox gpu_mailbox; | 2809 gpu::Mailbox gpu_mailbox; |
2795 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2810 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
2796 uint32 release_sync_point = 0; | 2811 uint32 release_sync_point = 0; |
2797 bool lost_resource = false; | 2812 bool lost_resource = false; |
2798 BlockingTaskRunner* mailbox_task_runner = NULL; | 2813 BlockingTaskRunner* mailbox_task_runner = NULL; |
2799 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2814 scoped_ptr<SingleReleaseCallbackImpl> callback = |
2800 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, | 2815 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, |
2801 &release_sync_point, | 2816 &release_sync_point, |
2802 &lost_resource, | 2817 &lost_resource, |
2803 &mailbox_task_runner)); | 2818 &mailbox_task_runner)); |
2804 | 2819 |
2805 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2820 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
2806 mailbox.set_nearest_neighbor(mailbox_nearest_neighbor); | 2821 mailbox.set_nearest_neighbor(mailbox_nearest_neighbor); |
2807 | 2822 |
2808 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( | 2823 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( |
2809 mailbox, callback.Pass()); | 2824 mailbox, callback.Pass()); |
2810 EXPECT_NE(0u, id); | 2825 EXPECT_NE(0u, id); |
2811 | 2826 |
2812 Mock::VerifyAndClearExpectations(context); | 2827 Mock::VerifyAndClearExpectations(context); |
2813 | 2828 |
2814 { | 2829 { |
2815 // Mailbox sync point WaitSyncPoint before using the texture. | 2830 // Mailbox sync point WaitSyncPoint before using the texture. |
2816 EXPECT_CALL(*context, waitSyncPoint(sync_point)); | 2831 EXPECT_CALL(*context, waitSyncPoint(sync_point, _)); |
2817 resource_provider->WaitSyncPointIfNeeded(id); | 2832 resource_provider->WaitSyncPointIfNeeded(id); |
2818 Mock::VerifyAndClearExpectations(context); | 2833 Mock::VerifyAndClearExpectations(context); |
2819 | 2834 |
2820 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) | 2835 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) |
2821 .WillOnce(Return(texture_id)); | 2836 .WillOnce(Return(texture_id)); |
2822 EXPECT_CALL(*context, bindTexture(target, texture_id)); | 2837 EXPECT_CALL(*context, bindTexture(target, texture_id)); |
2823 | 2838 |
2824 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2839 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
2825 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2840 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
2826 | 2841 |
2827 // The sampler will reset these if |mailbox_nearest_neighbor| does not | 2842 // The sampler will reset these if |mailbox_nearest_neighbor| does not |
2828 // match |sampler_filter|. | 2843 // match |sampler_filter|. |
2829 if (mailbox_nearest_neighbor != (sampler_filter == GL_NEAREST)) { | 2844 if (mailbox_nearest_neighbor != (sampler_filter == GL_NEAREST)) { |
2830 EXPECT_CALL(*context, texParameteri( | 2845 EXPECT_CALL(*context, texParameteri( |
2831 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampler_filter)); | 2846 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampler_filter)); |
2832 EXPECT_CALL(*context, texParameteri( | 2847 EXPECT_CALL(*context, texParameteri( |
2833 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter)); | 2848 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter)); |
2834 } | 2849 } |
2835 | 2850 |
2836 ResourceProvider::ScopedSamplerGL lock( | 2851 ResourceProvider::ScopedSamplerGL lock( |
2837 resource_provider.get(), id, sampler_filter); | 2852 resource_provider.get(), id, sampler_filter); |
2838 Mock::VerifyAndClearExpectations(context); | 2853 Mock::VerifyAndClearExpectations(context); |
2839 | 2854 |
2840 // When done with it, a sync point should be inserted, but no produce is | 2855 // When done with it, a sync point should be inserted, but no produce is |
2841 // necessary. | 2856 // necessary. |
2842 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2857 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
2843 EXPECT_CALL(*context, insertSyncPoint()); | 2858 EXPECT_CALL(*context, insertSyncPoint()); |
2844 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2859 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
2845 | 2860 |
2846 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2861 EXPECT_CALL(*context, waitSyncPoint(_, _)).Times(0); |
2847 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 2862 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
2848 } | 2863 } |
2849 | 2864 |
2850 resource_provider->DeleteResource(id); | 2865 resource_provider->DeleteResource(id); |
2851 EXPECT_EQ(0u, release_sync_point); | 2866 EXPECT_EQ(0u, release_sync_point); |
2852 EXPECT_FALSE(lost_resource); | 2867 EXPECT_FALSE(lost_resource); |
2853 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner); | 2868 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner); |
2854 } | 2869 } |
2855 }; | 2870 }; |
2856 | 2871 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2922 | 2937 |
2923 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 2938 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
2924 output_surface.get(), shared_bitmap_manager_.get(), | 2939 output_surface.get(), shared_bitmap_manager_.get(), |
2925 gpu_memory_buffer_manager_.get(), NULL, 0, 1, | 2940 gpu_memory_buffer_manager_.get(), NULL, 0, 1, |
2926 use_image_texture_targets_)); | 2941 use_image_texture_targets_)); |
2927 | 2942 |
2928 uint32 sync_point = 30; | 2943 uint32 sync_point = 30; |
2929 unsigned target = GL_TEXTURE_EXTERNAL_OES; | 2944 unsigned target = GL_TEXTURE_EXTERNAL_OES; |
2930 | 2945 |
2931 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2946 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
2932 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2947 EXPECT_CALL(*context, waitSyncPoint(_, _)).Times(0); |
2933 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2948 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
2934 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2949 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
2935 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 2950 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
2936 | 2951 |
2937 gpu::Mailbox gpu_mailbox; | 2952 gpu::Mailbox gpu_mailbox; |
2938 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2953 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
2939 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2954 scoped_ptr<SingleReleaseCallbackImpl> callback = |
2940 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 2955 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
2941 | 2956 |
2942 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2957 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
2943 | 2958 |
2944 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( | 2959 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( |
2945 mailbox, callback.Pass()); | 2960 mailbox, callback.Pass()); |
2946 EXPECT_NE(0u, id); | 2961 EXPECT_NE(0u, id); |
2947 | 2962 |
2948 Mock::VerifyAndClearExpectations(context); | 2963 Mock::VerifyAndClearExpectations(context); |
2949 | 2964 |
2950 { | 2965 { |
2951 // Mailbox sync point WaitSyncPoint before using the texture. | 2966 // Mailbox sync point WaitSyncPoint before using the texture. |
2952 EXPECT_CALL(*context, waitSyncPoint(sync_point)); | 2967 EXPECT_CALL(*context, waitSyncPoint(sync_point, _)); |
2953 resource_provider->WaitSyncPointIfNeeded(id); | 2968 resource_provider->WaitSyncPointIfNeeded(id); |
2954 Mock::VerifyAndClearExpectations(context); | 2969 Mock::VerifyAndClearExpectations(context); |
2955 | 2970 |
2956 unsigned texture_id = 1; | 2971 unsigned texture_id = 1; |
2957 | 2972 |
2958 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) | 2973 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) |
2959 .WillOnce(Return(texture_id)); | 2974 .WillOnce(Return(texture_id)); |
2960 | 2975 |
2961 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2976 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
2962 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2977 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
2963 | 2978 |
2964 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); | 2979 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); |
2965 Mock::VerifyAndClearExpectations(context); | 2980 Mock::VerifyAndClearExpectations(context); |
2966 | 2981 |
2967 // When done with it, a sync point should be inserted, but no produce is | 2982 // When done with it, a sync point should be inserted, but no produce is |
2968 // necessary. | 2983 // necessary. |
2969 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2984 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
2970 EXPECT_CALL(*context, insertSyncPoint()); | 2985 EXPECT_CALL(*context, insertSyncPoint()); |
2971 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2986 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
2972 | 2987 |
2973 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2988 EXPECT_CALL(*context, waitSyncPoint(_, _)).Times(0); |
2974 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 2989 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
2975 } | 2990 } |
2976 } | 2991 } |
2977 | 2992 |
2978 TEST_P(ResourceProviderTest, | 2993 TEST_P(ResourceProviderTest, |
2979 TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) { | 2994 TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) { |
2980 // Mailboxing is only supported for GL textures. | 2995 // Mailboxing is only supported for GL textures. |
2981 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 2996 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
2982 return; | 2997 return; |
2983 | 2998 |
2984 scoped_ptr<TextureStateTrackingContext> context_owned( | 2999 scoped_ptr<TextureStateTrackingContext> context_owned( |
2985 new TextureStateTrackingContext); | 3000 new TextureStateTrackingContext); |
2986 TextureStateTrackingContext* context = context_owned.get(); | 3001 TextureStateTrackingContext* context = context_owned.get(); |
2987 | 3002 |
2988 FakeOutputSurfaceClient output_surface_client; | 3003 FakeOutputSurfaceClient output_surface_client; |
2989 scoped_ptr<OutputSurface> output_surface( | 3004 scoped_ptr<OutputSurface> output_surface( |
2990 FakeOutputSurface::Create3d(context_owned.Pass())); | 3005 FakeOutputSurface::Create3d(context_owned.Pass())); |
2991 CHECK(output_surface->BindToClient(&output_surface_client)); | 3006 CHECK(output_surface->BindToClient(&output_surface_client)); |
2992 | 3007 |
2993 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 3008 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
2994 output_surface.get(), shared_bitmap_manager_.get(), | 3009 output_surface.get(), shared_bitmap_manager_.get(), |
2995 gpu_memory_buffer_manager_.get(), NULL, 0, 1, | 3010 gpu_memory_buffer_manager_.get(), NULL, 0, 1, |
2996 use_image_texture_targets_)); | 3011 use_image_texture_targets_)); |
2997 | 3012 |
2998 uint32 sync_point = 30; | 3013 uint32 sync_point = 30; |
2999 unsigned target = GL_TEXTURE_2D; | 3014 unsigned target = GL_TEXTURE_2D; |
3000 | 3015 |
3001 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 3016 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
3002 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 3017 EXPECT_CALL(*context, waitSyncPoint(_, _)).Times(0); |
3003 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 3018 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
3004 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 3019 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
3005 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 3020 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
3006 | 3021 |
3007 gpu::Mailbox gpu_mailbox; | 3022 gpu::Mailbox gpu_mailbox; |
3008 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 3023 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
3009 scoped_ptr<SingleReleaseCallbackImpl> callback = | 3024 scoped_ptr<SingleReleaseCallbackImpl> callback = |
3010 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 3025 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
3011 | 3026 |
3012 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 3027 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
3013 | 3028 |
3014 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( | 3029 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( |
3015 mailbox, callback.Pass()); | 3030 mailbox, callback.Pass()); |
3016 EXPECT_NE(0u, id); | 3031 EXPECT_NE(0u, id); |
3017 | 3032 |
3018 Mock::VerifyAndClearExpectations(context); | 3033 Mock::VerifyAndClearExpectations(context); |
3019 | 3034 |
3020 { | 3035 { |
3021 // First call to WaitSyncPointIfNeeded should call waitSyncPoint. | 3036 // First call to WaitSyncPointIfNeeded should call waitSyncPoint. |
3022 EXPECT_CALL(*context, waitSyncPoint(sync_point)); | 3037 EXPECT_CALL(*context, waitSyncPoint(sync_point, _)); |
3023 resource_provider->WaitSyncPointIfNeeded(id); | 3038 resource_provider->WaitSyncPointIfNeeded(id); |
3024 Mock::VerifyAndClearExpectations(context); | 3039 Mock::VerifyAndClearExpectations(context); |
3025 | 3040 |
3026 // Subsequent calls to WaitSyncPointIfNeeded shouldn't call waitSyncPoint. | 3041 // Subsequent calls to WaitSyncPointIfNeeded shouldn't call waitSyncPoint. |
3027 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 3042 EXPECT_CALL(*context, waitSyncPoint(_, _)).Times(0); |
3028 resource_provider->WaitSyncPointIfNeeded(id); | 3043 resource_provider->WaitSyncPointIfNeeded(id); |
3029 Mock::VerifyAndClearExpectations(context); | 3044 Mock::VerifyAndClearExpectations(context); |
3030 } | 3045 } |
3031 } | 3046 } |
3032 | 3047 |
3033 TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncPointIfNeeded_NoSyncPoint) { | 3048 TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncPointIfNeeded_NoSyncPoint) { |
3034 // Mailboxing is only supported for GL textures. | 3049 // Mailboxing is only supported for GL textures. |
3035 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3050 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
3036 return; | 3051 return; |
3037 | 3052 |
3038 scoped_ptr<TextureStateTrackingContext> context_owned( | 3053 scoped_ptr<TextureStateTrackingContext> context_owned( |
3039 new TextureStateTrackingContext); | 3054 new TextureStateTrackingContext); |
3040 TextureStateTrackingContext* context = context_owned.get(); | 3055 TextureStateTrackingContext* context = context_owned.get(); |
3041 | 3056 |
3042 FakeOutputSurfaceClient output_surface_client; | 3057 FakeOutputSurfaceClient output_surface_client; |
3043 scoped_ptr<OutputSurface> output_surface( | 3058 scoped_ptr<OutputSurface> output_surface( |
3044 FakeOutputSurface::Create3d(context_owned.Pass())); | 3059 FakeOutputSurface::Create3d(context_owned.Pass())); |
3045 CHECK(output_surface->BindToClient(&output_surface_client)); | 3060 CHECK(output_surface->BindToClient(&output_surface_client)); |
3046 | 3061 |
3047 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 3062 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
3048 output_surface.get(), shared_bitmap_manager_.get(), | 3063 output_surface.get(), shared_bitmap_manager_.get(), |
3049 gpu_memory_buffer_manager_.get(), NULL, 0, 1, | 3064 gpu_memory_buffer_manager_.get(), NULL, 0, 1, |
3050 use_image_texture_targets_)); | 3065 use_image_texture_targets_)); |
3051 | 3066 |
3052 uint32 sync_point = 0; | 3067 uint32 sync_point = 0; |
3053 unsigned target = GL_TEXTURE_2D; | 3068 unsigned target = GL_TEXTURE_2D; |
3054 | 3069 |
3055 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 3070 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
3056 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 3071 EXPECT_CALL(*context, waitSyncPoint(_, _)).Times(0); |
3057 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 3072 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
3058 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 3073 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
3059 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 3074 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
3060 | 3075 |
3061 gpu::Mailbox gpu_mailbox; | 3076 gpu::Mailbox gpu_mailbox; |
3062 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 3077 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
3063 scoped_ptr<SingleReleaseCallbackImpl> callback = | 3078 scoped_ptr<SingleReleaseCallbackImpl> callback = |
3064 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 3079 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
3065 | 3080 |
3066 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 3081 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
3067 | 3082 |
3068 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( | 3083 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( |
3069 mailbox, callback.Pass()); | 3084 mailbox, callback.Pass()); |
3070 EXPECT_NE(0u, id); | 3085 EXPECT_NE(0u, id); |
3071 | 3086 |
3072 Mock::VerifyAndClearExpectations(context); | 3087 Mock::VerifyAndClearExpectations(context); |
3073 | 3088 |
3074 { | 3089 { |
3075 // WaitSyncPointIfNeeded with sync_point == 0 shouldn't call waitSyncPoint. | 3090 // WaitSyncPointIfNeeded with sync_point == 0 shouldn't call waitSyncPoint. |
3076 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 3091 EXPECT_CALL(*context, waitSyncPoint(_, _)).Times(0); |
3077 resource_provider->WaitSyncPointIfNeeded(id); | 3092 resource_provider->WaitSyncPointIfNeeded(id); |
3078 Mock::VerifyAndClearExpectations(context); | 3093 Mock::VerifyAndClearExpectations(context); |
3079 } | 3094 } |
3080 } | 3095 } |
3081 | 3096 |
3082 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { | 3097 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { |
3083 public: | 3098 public: |
3084 MOCK_METHOD0(NextTextureId, GLuint()); | 3099 MOCK_METHOD0(NextTextureId, GLuint()); |
3085 MOCK_METHOD1(RetireTextureId, void(GLuint id)); | 3100 MOCK_METHOD1(RetireTextureId, void(GLuint id)); |
3086 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); | 3101 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3529 resource_provider->AllocateForTesting(id); | 3544 resource_provider->AllocateForTesting(id); |
3530 Mock::VerifyAndClearExpectations(context); | 3545 Mock::VerifyAndClearExpectations(context); |
3531 | 3546 |
3532 DCHECK_EQ(10u, context->PeekTextureId()); | 3547 DCHECK_EQ(10u, context->PeekTextureId()); |
3533 resource_provider->DeleteResource(id); | 3548 resource_provider->DeleteResource(id); |
3534 } | 3549 } |
3535 } | 3550 } |
3536 | 3551 |
3537 } // namespace | 3552 } // namespace |
3538 } // namespace cc | 3553 } // namespace cc |
OLD | NEW |