| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "third_party/khronos/GLES2/gl2.h" | 34 #include "third_party/khronos/GLES2/gl2.h" |
| 35 #include "third_party/khronos/GLES2/gl2ext.h" | 35 #include "third_party/khronos/GLES2/gl2ext.h" |
| 36 #include "ui/gfx/geometry/rect.h" | 36 #include "ui/gfx/geometry/rect.h" |
| 37 #include "ui/gfx/gpu_memory_buffer.h" | 37 #include "ui/gfx/gpu_memory_buffer.h" |
| 38 | 38 |
| 39 using testing::Mock; | 39 using testing::Mock; |
| 40 using testing::NiceMock; | 40 using testing::NiceMock; |
| 41 using testing::Return; | 41 using testing::Return; |
| 42 using testing::SetArgPointee; | |
| 43 using testing::StrictMock; | 42 using testing::StrictMock; |
| 44 using testing::_; | 43 using testing::_; |
| 45 | 44 |
| 46 namespace cc { | 45 namespace cc { |
| 47 namespace { | 46 namespace { |
| 48 | 47 |
| 49 MATCHER_P(MatchesSyncToken, sync_token, "") { | 48 MATCHER_P(MatchesSyncToken, sync_token, "") { |
| 50 gpu::SyncToken other; | 49 gpu::SyncToken other; |
| 51 memcpy(&other, arg, sizeof(other)); | 50 memcpy(&other, arg, sizeof(other)); |
| 52 return other == sync_token; | 51 return other == sync_token; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 CHECK(pixels); | 96 CHECK(pixels); |
| 98 std::fill_n(pixels, size.GetArea(), value); | 97 std::fill_n(pixels, size.GetArea(), value); |
| 99 return shared_bitmap; | 98 return shared_bitmap; |
| 100 } | 99 } |
| 101 | 100 |
| 102 class TextureStateTrackingContext : public TestWebGraphicsContext3D { | 101 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
| 103 public: | 102 public: |
| 104 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); | 103 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); |
| 105 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); | 104 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); |
| 106 MOCK_METHOD1(waitSyncToken, void(const GLbyte* sync_token)); | 105 MOCK_METHOD1(waitSyncToken, void(const GLbyte* sync_token)); |
| 107 MOCK_METHOD0(insertSyncPoint, GLuint(void)); | |
| 108 MOCK_METHOD3(produceTextureDirectCHROMIUM, | 106 MOCK_METHOD3(produceTextureDirectCHROMIUM, |
| 109 void(GLuint texture, GLenum target, const GLbyte* mailbox)); | 107 void(GLuint texture, GLenum target, const GLbyte* mailbox)); |
| 110 MOCK_METHOD2(createAndConsumeTextureCHROMIUM, | 108 MOCK_METHOD2(createAndConsumeTextureCHROMIUM, |
| 111 unsigned(GLenum target, const GLbyte* mailbox)); | 109 unsigned(GLenum target, const GLbyte* mailbox)); |
| 112 | 110 |
| 113 // Force all textures to be consecutive numbers starting at "1", | 111 // Force all textures to be consecutive numbers starting at "1", |
| 114 // so we easily can test for them. | 112 // so we easily can test for them. |
| 115 GLuint NextTextureId() override { | 113 GLuint NextTextureId() override { |
| 116 base::AutoLock lock(namespace_->lock); | 114 base::AutoLock lock(namespace_->lock); |
| 117 return namespace_->next_texture_id++; | 115 return namespace_->next_texture_id++; |
| 118 } | 116 } |
| 117 |
| 119 void RetireTextureId(GLuint) override {} | 118 void RetireTextureId(GLuint) override {} |
| 119 |
| 120 GLuint64 insertFenceSync() override { return next_fence_sync_++; } |
| 121 |
| 122 void genSyncToken(GLuint64 fence_sync, GLbyte* sync_token) override { |
| 123 gpu::SyncToken sync_token_data(gpu::CommandBufferNamespace::GPU_IO, 0, |
| 124 0x123, fence_sync); |
| 125 sync_token_data.SetVerifyFlush(); |
| 126 memcpy(sync_token, &sync_token_data, sizeof(sync_token_data)); |
| 127 } |
| 128 |
| 129 GLuint64 GetNextFenceSync() const { return next_fence_sync_; } |
| 130 |
| 131 GLuint64 next_fence_sync_ = 1; |
| 120 }; | 132 }; |
| 121 | 133 |
| 122 // Shared data between multiple ResourceProviderContext. This contains mailbox | 134 // Shared data between multiple ResourceProviderContext. This contains mailbox |
| 123 // contents as well as information about sync points. | 135 // contents as well as information about sync points. |
| 124 class ContextSharedData { | 136 class ContextSharedData { |
| 125 public: | 137 public: |
| 126 static scoped_ptr<ContextSharedData> Create() { | 138 static scoped_ptr<ContextSharedData> Create() { |
| 127 return make_scoped_ptr(new ContextSharedData()); | 139 return make_scoped_ptr(new ContextSharedData()); |
| 128 } | 140 } |
| 129 | 141 |
| 130 uint32_t InsertSyncPoint() { return next_sync_point_++; } | 142 uint32_t InsertFenceSync() { return next_fence_sync_++; } |
| 131 | 143 |
| 132 void GenMailbox(GLbyte* mailbox) { | 144 void GenMailbox(GLbyte* mailbox) { |
| 133 memset(mailbox, 0, GL_MAILBOX_SIZE_CHROMIUM); | 145 memset(mailbox, 0, GL_MAILBOX_SIZE_CHROMIUM); |
| 134 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_)); | 146 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_)); |
| 135 ++next_mailbox_; | 147 ++next_mailbox_; |
| 136 } | 148 } |
| 137 | 149 |
| 138 void ProduceTexture(const GLbyte* mailbox_name, | 150 void ProduceTexture(const GLbyte* mailbox_name, |
| 139 const gpu::SyncToken& sync_token, | 151 const gpu::SyncToken& sync_token, |
| 140 scoped_refptr<TestTexture> texture) { | 152 scoped_refptr<TestTexture> texture) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 158 // point for when the mailbox was set, pretend we never saw that | 170 // point for when the mailbox was set, pretend we never saw that |
| 159 // ProduceTexture. | 171 // ProduceTexture. |
| 160 if (sync_point_for_mailbox_[mailbox] > sync_token.release_count()) { | 172 if (sync_point_for_mailbox_[mailbox] > sync_token.release_count()) { |
| 161 NOTREACHED(); | 173 NOTREACHED(); |
| 162 return scoped_refptr<TestTexture>(); | 174 return scoped_refptr<TestTexture>(); |
| 163 } | 175 } |
| 164 return textures_[mailbox]; | 176 return textures_[mailbox]; |
| 165 } | 177 } |
| 166 | 178 |
| 167 private: | 179 private: |
| 168 ContextSharedData() : next_sync_point_(1), next_mailbox_(1) {} | 180 ContextSharedData() : next_fence_sync_(1), next_mailbox_(1) {} |
| 169 | 181 |
| 170 uint32_t next_sync_point_; | 182 uint64_t next_fence_sync_; |
| 171 unsigned next_mailbox_; | 183 unsigned next_mailbox_; |
| 172 typedef base::hash_map<unsigned, scoped_refptr<TestTexture>> TextureMap; | 184 typedef base::hash_map<unsigned, scoped_refptr<TestTexture>> TextureMap; |
| 173 TextureMap textures_; | 185 TextureMap textures_; |
| 174 base::hash_map<unsigned, uint32_t> sync_point_for_mailbox_; | 186 base::hash_map<unsigned, uint32_t> sync_point_for_mailbox_; |
| 175 }; | 187 }; |
| 176 | 188 |
| 177 class ResourceProviderContext : public TestWebGraphicsContext3D { | 189 class ResourceProviderContext : public TestWebGraphicsContext3D { |
| 178 public: | 190 public: |
| 179 static scoped_ptr<ResourceProviderContext> Create( | 191 static scoped_ptr<ResourceProviderContext> Create( |
| 180 ContextSharedData* shared_data) { | 192 ContextSharedData* shared_data) { |
| 181 return make_scoped_ptr(new ResourceProviderContext(shared_data)); | 193 return make_scoped_ptr(new ResourceProviderContext(shared_data)); |
| 182 } | 194 } |
| 183 | 195 |
| 184 GLuint insertSyncPoint() override { | 196 GLuint insertSyncPoint() override { |
| 185 uint32_t sync_point = shared_data_->InsertSyncPoint(); | 197 const uint32_t sync_point = |
| 198 static_cast<uint32_t>(shared_data_->InsertFenceSync()); |
| 199 gpu::SyncToken sync_token_data(sync_point); |
| 200 |
| 186 // Commit the produceTextureCHROMIUM calls at this point, so that | 201 // Commit the produceTextureCHROMIUM calls at this point, so that |
| 187 // they're associated with the sync point. | 202 // they're associated with the sync point. |
| 188 for (const scoped_ptr<PendingProduceTexture>& pending_texture : | 203 for (const scoped_ptr<PendingProduceTexture>& pending_texture : |
| 189 pending_produce_textures_) { | 204 pending_produce_textures_) { |
| 190 shared_data_->ProduceTexture(pending_texture->mailbox, | 205 shared_data_->ProduceTexture(pending_texture->mailbox, sync_token_data, |
| 191 gpu::SyncToken(sync_point), | |
| 192 pending_texture->texture); | 206 pending_texture->texture); |
| 193 } | 207 } |
| 194 pending_produce_textures_.clear(); | 208 pending_produce_textures_.clear(); |
| 195 return sync_point; | 209 return sync_point; |
| 196 } | 210 } |
| 197 | 211 |
| 212 GLuint64 insertFenceSync() override { |
| 213 return shared_data_->InsertFenceSync(); |
| 214 } |
| 215 |
| 216 void genSyncToken(GLuint64 fence_sync, GLbyte* sync_token) override { |
| 217 gpu::SyncToken sync_token_data(gpu::CommandBufferNamespace::GPU_IO, 0, |
| 218 0x123, fence_sync); |
| 219 sync_token_data.SetVerifyFlush(); |
| 220 // Commit the produceTextureCHROMIUM calls at this point, so that |
| 221 // they're associated with the sync point. |
| 222 for (const scoped_ptr<PendingProduceTexture>& pending_texture : |
| 223 pending_produce_textures_) { |
| 224 shared_data_->ProduceTexture(pending_texture->mailbox, sync_token_data, |
| 225 pending_texture->texture); |
| 226 } |
| 227 pending_produce_textures_.clear(); |
| 228 memcpy(sync_token, &sync_token_data, sizeof(sync_token_data)); |
| 229 } |
| 230 |
| 198 void waitSyncToken(const GLbyte* sync_token) override { | 231 void waitSyncToken(const GLbyte* sync_token) override { |
| 199 gpu::SyncToken sync_token_data; | 232 gpu::SyncToken sync_token_data; |
| 200 if (sync_token) | 233 if (sync_token) |
| 201 memcpy(&sync_token_data, sync_token, sizeof(sync_token_data)); | 234 memcpy(&sync_token_data, sync_token, sizeof(sync_token_data)); |
| 202 | 235 |
| 203 if (sync_token_data.release_count() > | 236 if (sync_token_data.release_count() > |
| 204 last_waited_sync_token_.release_count()) { | 237 last_waited_sync_token_.release_count()) { |
| 205 last_waited_sync_token_ = sync_token_data; | 238 last_waited_sync_token_ = sync_token_data; |
| 206 } | 239 } |
| 207 } | 240 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 306 } |
| 274 | 307 |
| 275 void genMailboxCHROMIUM(GLbyte* mailbox) override { | 308 void genMailboxCHROMIUM(GLbyte* mailbox) override { |
| 276 return shared_data_->GenMailbox(mailbox); | 309 return shared_data_->GenMailbox(mailbox); |
| 277 } | 310 } |
| 278 | 311 |
| 279 void produceTextureDirectCHROMIUM(GLuint texture, | 312 void produceTextureDirectCHROMIUM(GLuint texture, |
| 280 GLenum target, | 313 GLenum target, |
| 281 const GLbyte* mailbox) override { | 314 const GLbyte* mailbox) override { |
| 282 // Delay moving the texture into the mailbox until the next | 315 // Delay moving the texture into the mailbox until the next |
| 283 // InsertSyncPoint, so that it is not visible to other contexts that | 316 // sync token, so that it is not visible to other contexts that |
| 284 // haven't waited on that sync point. | 317 // haven't waited on that sync point. |
| 285 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); | 318 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); |
| 286 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); | 319 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); |
| 287 base::AutoLock lock_for_texture_access(namespace_->lock); | 320 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 288 pending->texture = UnboundTexture(texture); | 321 pending->texture = UnboundTexture(texture); |
| 289 pending_produce_textures_.push_back(std::move(pending)); | 322 pending_produce_textures_.push_back(std::move(pending)); |
| 290 } | 323 } |
| 291 | 324 |
| 292 GLuint createAndConsumeTextureCHROMIUM(GLenum target, | 325 GLuint createAndConsumeTextureCHROMIUM(GLenum target, |
| 293 const GLbyte* mailbox) override { | 326 const GLbyte* mailbox) override { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 ResourceId CreateChildMailbox(gpu::SyncToken* release_sync_token, | 503 ResourceId CreateChildMailbox(gpu::SyncToken* release_sync_token, |
| 471 bool* lost_resource, | 504 bool* lost_resource, |
| 472 bool* release_called, | 505 bool* release_called, |
| 473 gpu::SyncToken* sync_token) { | 506 gpu::SyncToken* sync_token) { |
| 474 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { | 507 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { |
| 475 unsigned texture = child_context_->createTexture(); | 508 unsigned texture = child_context_->createTexture(); |
| 476 gpu::Mailbox gpu_mailbox; | 509 gpu::Mailbox gpu_mailbox; |
| 477 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); | 510 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); |
| 478 child_context_->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, | 511 child_context_->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, |
| 479 gpu_mailbox.name); | 512 gpu_mailbox.name); |
| 480 *sync_token = gpu::SyncToken(child_context_->insertSyncPoint()); | 513 child_context_->genSyncToken(child_context_->insertFenceSync(), |
| 514 sync_token->GetData()); |
| 481 EXPECT_TRUE(sync_token->HasData()); | 515 EXPECT_TRUE(sync_token->HasData()); |
| 482 | 516 |
| 483 scoped_ptr<SharedBitmap> shared_bitmap; | 517 scoped_ptr<SharedBitmap> shared_bitmap; |
| 484 scoped_ptr<SingleReleaseCallbackImpl> callback = | 518 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 485 SingleReleaseCallbackImpl::Create(base::Bind( | 519 SingleReleaseCallbackImpl::Create(base::Bind( |
| 486 ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap), | 520 ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap), |
| 487 release_called, release_sync_token, lost_resource)); | 521 release_called, release_sync_token, lost_resource)); |
| 488 return child_resource_provider_->CreateResourceFromTextureMailbox( | 522 return child_resource_provider_->CreateResourceFromTextureMailbox( |
| 489 TextureMailbox(gpu_mailbox, *sync_token, GL_TEXTURE_2D), | 523 TextureMailbox(gpu_mailbox, *sync_token, GL_TEXTURE_2D), |
| 490 std::move(callback)); | 524 std::move(callback)); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 child_resource_provider_.get(), id3); | 660 child_resource_provider_.get(), id3); |
| 627 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 661 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 628 } | 662 } |
| 629 | 663 |
| 630 GLuint external_texture_id = child_context_->createExternalTexture(); | 664 GLuint external_texture_id = child_context_->createExternalTexture(); |
| 631 | 665 |
| 632 gpu::Mailbox external_mailbox; | 666 gpu::Mailbox external_mailbox; |
| 633 child_context_->genMailboxCHROMIUM(external_mailbox.name); | 667 child_context_->genMailboxCHROMIUM(external_mailbox.name); |
| 634 child_context_->produceTextureDirectCHROMIUM( | 668 child_context_->produceTextureDirectCHROMIUM( |
| 635 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name); | 669 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name); |
| 636 const gpu::SyncToken external_sync_token(child_context_->insertSyncPoint()); | 670 gpu::SyncToken external_sync_token; |
| 671 child_context_->genSyncToken(child_context_->insertFenceSync(), |
| 672 external_sync_token.GetData()); |
| 673 EXPECT_TRUE(external_sync_token.HasData()); |
| 637 ResourceId id4 = child_resource_provider_->CreateResourceFromTextureMailbox( | 674 ResourceId id4 = child_resource_provider_->CreateResourceFromTextureMailbox( |
| 638 TextureMailbox(external_mailbox, external_sync_token, | 675 TextureMailbox(external_mailbox, external_sync_token, |
| 639 GL_TEXTURE_EXTERNAL_OES), | 676 GL_TEXTURE_EXTERNAL_OES), |
| 640 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback))); | 677 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback))); |
| 641 | 678 |
| 642 ReturnedResourceArray returned_to_child; | 679 ReturnedResourceArray returned_to_child; |
| 643 int child_id = | 680 int child_id = |
| 644 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 681 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| 645 { | 682 { |
| 646 // Transfer some resources to the parent. | 683 // Transfer some resources to the parent. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 919 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 883 } | 920 } |
| 884 | 921 |
| 885 GLuint external_texture_id = child_context_->createExternalTexture(); | 922 GLuint external_texture_id = child_context_->createExternalTexture(); |
| 886 | 923 |
| 887 // A sync point is specified directly and should be used. | 924 // A sync point is specified directly and should be used. |
| 888 gpu::Mailbox external_mailbox; | 925 gpu::Mailbox external_mailbox; |
| 889 child_context_->genMailboxCHROMIUM(external_mailbox.name); | 926 child_context_->genMailboxCHROMIUM(external_mailbox.name); |
| 890 child_context_->produceTextureDirectCHROMIUM( | 927 child_context_->produceTextureDirectCHROMIUM( |
| 891 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name); | 928 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name); |
| 892 const gpu::SyncToken external_sync_token(child_context_->insertSyncPoint()); | 929 gpu::SyncToken external_sync_token; |
| 930 child_context_->genSyncToken(child_context_->insertFenceSync(), |
| 931 external_sync_token.GetData()); |
| 932 EXPECT_TRUE(external_sync_token.HasData()); |
| 893 ResourceId id3 = child_resource_provider_->CreateResourceFromTextureMailbox( | 933 ResourceId id3 = child_resource_provider_->CreateResourceFromTextureMailbox( |
| 894 TextureMailbox(external_mailbox, external_sync_token, | 934 TextureMailbox(external_mailbox, external_sync_token, |
| 895 GL_TEXTURE_EXTERNAL_OES), | 935 GL_TEXTURE_EXTERNAL_OES), |
| 896 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback))); | 936 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback))); |
| 897 | 937 |
| 898 ReturnedResourceArray returned_to_child; | 938 ReturnedResourceArray returned_to_child; |
| 899 int child_id = | 939 int child_id = |
| 900 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 940 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| 901 resource_provider_->SetChildNeedsSyncTokens(child_id, false); | 941 resource_provider_->SetChildNeedsSyncTokens(child_id, false); |
| 902 { | 942 { |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 int child_id = parent_resource_provider->CreateChild( | 1994 int child_id = parent_resource_provider->CreateChild( |
| 1955 GetReturnCallback(&returned_to_child)); | 1995 GetReturnCallback(&returned_to_child)); |
| 1956 { | 1996 { |
| 1957 // Transfer some resource to the parent. | 1997 // Transfer some resource to the parent. |
| 1958 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1998 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1959 resource_ids_to_transfer.push_back(id); | 1999 resource_ids_to_transfer.push_back(id); |
| 1960 TransferableResourceArray list; | 2000 TransferableResourceArray list; |
| 1961 | 2001 |
| 1962 EXPECT_CALL(*child_context, | 2002 EXPECT_CALL(*child_context, |
| 1963 produceTextureDirectCHROMIUM(_, GL_TEXTURE_2D, _)); | 2003 produceTextureDirectCHROMIUM(_, GL_TEXTURE_2D, _)); |
| 1964 EXPECT_CALL(*child_context, insertSyncPoint()); | |
| 1965 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, | 2004 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, |
| 1966 &list); | 2005 &list); |
| 1967 Mock::VerifyAndClearExpectations(child_context); | 2006 Mock::VerifyAndClearExpectations(child_context); |
| 1968 | 2007 |
| 1969 ASSERT_EQ(1u, list.size()); | 2008 ASSERT_EQ(1u, list.size()); |
| 1970 EXPECT_EQ(static_cast<unsigned>(child_filter), list[0].filter); | 2009 EXPECT_EQ(static_cast<unsigned>(child_filter), list[0].filter); |
| 1971 | 2010 |
| 1972 EXPECT_CALL(*parent_context, | 2011 EXPECT_CALL(*parent_context, |
| 1973 createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) | 2012 createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) |
| 1974 .WillOnce(Return(parent_texture_id)); | 2013 .WillOnce(Return(parent_texture_id)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2012 EXPECT_CALL( | 2051 EXPECT_CALL( |
| 2013 *parent_context, | 2052 *parent_context, |
| 2014 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, child_filter)); | 2053 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, child_filter)); |
| 2015 | 2054 |
| 2016 { | 2055 { |
| 2017 EXPECT_EQ(0u, returned_to_child.size()); | 2056 EXPECT_EQ(0u, returned_to_child.size()); |
| 2018 | 2057 |
| 2019 // Transfer resources back from the parent to the child. Set no resources | 2058 // Transfer resources back from the parent to the child. Set no resources |
| 2020 // as being in use. | 2059 // as being in use. |
| 2021 ResourceProvider::ResourceIdSet no_resources; | 2060 ResourceProvider::ResourceIdSet no_resources; |
| 2022 EXPECT_CALL(*parent_context, insertSyncPoint()); | |
| 2023 parent_resource_provider->DeclareUsedResourcesFromChild(child_id, | 2061 parent_resource_provider->DeclareUsedResourcesFromChild(child_id, |
| 2024 no_resources); | 2062 no_resources); |
| 2025 Mock::VerifyAndClearExpectations(parent_context); | 2063 Mock::VerifyAndClearExpectations(parent_context); |
| 2026 | 2064 |
| 2027 ASSERT_EQ(1u, returned_to_child.size()); | 2065 ASSERT_EQ(1u, returned_to_child.size()); |
| 2028 child_resource_provider->ReceiveReturnsFromParent(returned_to_child); | 2066 child_resource_provider->ReceiveReturnsFromParent(returned_to_child); |
| 2029 } | 2067 } |
| 2030 | 2068 |
| 2031 // The child remembers the texture filter is set to |child_filter|. | 2069 // The child remembers the texture filter is set to |child_filter|. |
| 2032 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id)); | 2070 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2052 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 2090 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 2053 return; | 2091 return; |
| 2054 unsigned texture = context()->createTexture(); | 2092 unsigned texture = context()->createTexture(); |
| 2055 context()->bindTexture(GL_TEXTURE_2D, texture); | 2093 context()->bindTexture(GL_TEXTURE_2D, texture); |
| 2056 uint8_t data[4] = { 1, 2, 3, 4 }; | 2094 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 2057 context()->texImage2D( | 2095 context()->texImage2D( |
| 2058 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); | 2096 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); |
| 2059 gpu::Mailbox mailbox; | 2097 gpu::Mailbox mailbox; |
| 2060 context()->genMailboxCHROMIUM(mailbox.name); | 2098 context()->genMailboxCHROMIUM(mailbox.name); |
| 2061 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name); | 2099 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name); |
| 2062 gpu::SyncToken sync_token(context()->insertSyncPoint()); | 2100 gpu::SyncToken sync_token; |
| 2101 context()->genSyncToken(context()->insertFenceSync(), sync_token.GetData()); |
| 2102 EXPECT_TRUE(sync_token.HasData()); |
| 2063 | 2103 |
| 2064 // All the logic below assumes that the sync token releases are all positive. | 2104 // All the logic below assumes that the sync token releases are all positive. |
| 2065 EXPECT_LT(0u, sync_token.release_count()); | 2105 EXPECT_LT(0u, sync_token.release_count()); |
| 2066 | 2106 |
| 2067 gpu::SyncToken release_sync_token; | 2107 gpu::SyncToken release_sync_token; |
| 2068 bool lost_resource = false; | 2108 bool lost_resource = false; |
| 2069 BlockingTaskRunner* main_thread_task_runner = NULL; | 2109 BlockingTaskRunner* main_thread_task_runner = NULL; |
| 2070 ReleaseCallbackImpl callback = | 2110 ReleaseCallbackImpl callback = |
| 2071 base::Bind(ReleaseCallback, &release_sync_token, &lost_resource, | 2111 base::Bind(ReleaseCallback, &release_sync_token, &lost_resource, |
| 2072 &main_thread_task_runner); | 2112 &main_thread_task_runner); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2094 unsigned other_texture = | 2134 unsigned other_texture = |
| 2095 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 2135 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 2096 uint8_t test_data[4] = { 0 }; | 2136 uint8_t test_data[4] = { 0 }; |
| 2097 context()->GetPixels( | 2137 context()->GetPixels( |
| 2098 gfx::Size(1, 1), RGBA_8888, test_data); | 2138 gfx::Size(1, 1), RGBA_8888, test_data); |
| 2099 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | 2139 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
| 2100 | 2140 |
| 2101 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, | 2141 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, |
| 2102 mailbox.name); | 2142 mailbox.name); |
| 2103 context()->deleteTexture(other_texture); | 2143 context()->deleteTexture(other_texture); |
| 2104 list[0].mailbox_holder.sync_token = | 2144 context()->genSyncToken(context()->insertFenceSync(), |
| 2105 gpu::SyncToken(context()->insertSyncPoint()); | 2145 list[0].mailbox_holder.sync_token.GetData()); |
| 2146 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData()); |
| 2106 | 2147 |
| 2107 // Receive the resource, then delete it, expect the sync points to be | 2148 // Receive the resource, then delete it, expect the sync points to be |
| 2108 // consistent. | 2149 // consistent. |
| 2109 ReturnedResourceArray returned; | 2150 ReturnedResourceArray returned; |
| 2110 TransferableResource::ReturnResources(list, &returned); | 2151 TransferableResource::ReturnResources(list, &returned); |
| 2111 resource_provider_->ReceiveReturnsFromParent(returned); | 2152 resource_provider_->ReceiveReturnsFromParent(returned); |
| 2112 EXPECT_EQ(1u, context()->NumTextures()); | 2153 EXPECT_EQ(1u, context()->NumTextures()); |
| 2113 EXPECT_FALSE(release_sync_token.HasData()); | 2154 EXPECT_FALSE(release_sync_token.HasData()); |
| 2114 | 2155 |
| 2115 resource_provider_->DeleteResource(resource); | 2156 resource_provider_->DeleteResource(resource); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 unsigned other_texture = | 2189 unsigned other_texture = |
| 2149 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 2190 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 2150 uint8_t test_data[4] = { 0 }; | 2191 uint8_t test_data[4] = { 0 }; |
| 2151 context()->GetPixels( | 2192 context()->GetPixels( |
| 2152 gfx::Size(1, 1), RGBA_8888, test_data); | 2193 gfx::Size(1, 1), RGBA_8888, test_data); |
| 2153 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | 2194 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
| 2154 | 2195 |
| 2155 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, | 2196 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, |
| 2156 mailbox.name); | 2197 mailbox.name); |
| 2157 context()->deleteTexture(other_texture); | 2198 context()->deleteTexture(other_texture); |
| 2158 list[0].mailbox_holder.sync_token = | 2199 context()->genSyncToken(context()->insertFenceSync(), |
| 2159 gpu::SyncToken(context()->insertSyncPoint()); | 2200 list[0].mailbox_holder.sync_token.GetData()); |
| 2160 EXPECT_LT(0u, list[0].mailbox_holder.sync_token.release_count()); | 2201 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData()); |
| 2161 | 2202 |
| 2162 // Delete the resource, which shouldn't do anything. | 2203 // Delete the resource, which shouldn't do anything. |
| 2163 resource_provider_->DeleteResource(resource); | 2204 resource_provider_->DeleteResource(resource); |
| 2164 EXPECT_EQ(1u, context()->NumTextures()); | 2205 EXPECT_EQ(1u, context()->NumTextures()); |
| 2165 EXPECT_FALSE(release_sync_token.HasData()); | 2206 EXPECT_FALSE(release_sync_token.HasData()); |
| 2166 | 2207 |
| 2167 // Then receive the resource which should release the mailbox, expect the | 2208 // Then receive the resource which should release the mailbox, expect the |
| 2168 // sync points to be consistent. | 2209 // sync points to be consistent. |
| 2169 ReturnedResourceArray returned; | 2210 ReturnedResourceArray returned; |
| 2170 TransferableResource::ReturnResources(list, &returned); | 2211 TransferableResource::ReturnResources(list, &returned); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2483 | 2524 |
| 2484 TEST_P(ResourceProviderTest, LostContext) { | 2525 TEST_P(ResourceProviderTest, LostContext) { |
| 2485 // TextureMailbox callbacks only exist for GL textures for now. | 2526 // TextureMailbox callbacks only exist for GL textures for now. |
| 2486 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 2527 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 2487 return; | 2528 return; |
| 2488 unsigned texture = context()->createTexture(); | 2529 unsigned texture = context()->createTexture(); |
| 2489 context()->bindTexture(GL_TEXTURE_2D, texture); | 2530 context()->bindTexture(GL_TEXTURE_2D, texture); |
| 2490 gpu::Mailbox mailbox; | 2531 gpu::Mailbox mailbox; |
| 2491 context()->genMailboxCHROMIUM(mailbox.name); | 2532 context()->genMailboxCHROMIUM(mailbox.name); |
| 2492 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name); | 2533 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name); |
| 2493 gpu::SyncToken sync_token(context()->insertSyncPoint()); | 2534 gpu::SyncToken sync_token; |
| 2535 context()->genSyncToken(context()->insertFenceSync(), sync_token.GetData()); |
| 2494 | 2536 |
| 2495 EXPECT_TRUE(sync_token.HasData()); | 2537 EXPECT_TRUE(sync_token.HasData()); |
| 2496 | 2538 |
| 2497 gpu::SyncToken release_sync_token; | 2539 gpu::SyncToken release_sync_token; |
| 2498 bool lost_resource = false; | 2540 bool lost_resource = false; |
| 2499 BlockingTaskRunner* main_thread_task_runner = NULL; | 2541 BlockingTaskRunner* main_thread_task_runner = NULL; |
| 2500 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2542 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2501 SingleReleaseCallbackImpl::Create( | 2543 SingleReleaseCallbackImpl::Create( |
| 2502 base::Bind(ReleaseCallback, &release_sync_token, &lost_resource, | 2544 base::Bind(ReleaseCallback, &release_sync_token, &lost_resource, |
| 2503 &main_thread_task_runner)); | 2545 &main_thread_task_runner)); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2803 scoped_ptr<OutputSurface> output_surface( | 2845 scoped_ptr<OutputSurface> output_surface( |
| 2804 FakeOutputSurface::Create3d(std::move(context_owned))); | 2846 FakeOutputSurface::Create3d(std::move(context_owned))); |
| 2805 CHECK(output_surface->BindToClient(&output_surface_client)); | 2847 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2806 | 2848 |
| 2807 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 2849 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 2808 output_surface.get(), shared_bitmap_manager, gpu_memory_buffer_manager, | 2850 output_surface.get(), shared_bitmap_manager, gpu_memory_buffer_manager, |
| 2809 main_thread_task_runner, 0, 1, use_gpu_memory_buffer_resources_, | 2851 main_thread_task_runner, 0, 1, use_gpu_memory_buffer_resources_, |
| 2810 use_image_texture_targets_)); | 2852 use_image_texture_targets_)); |
| 2811 | 2853 |
| 2812 unsigned texture_id = 1; | 2854 unsigned texture_id = 1; |
| 2813 gpu::SyncToken sync_token(30); | 2855 gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO, 0, 0x12, |
| 2856 0x34); |
| 2814 unsigned target = GL_TEXTURE_2D; | 2857 unsigned target = GL_TEXTURE_2D; |
| 2858 const GLuint64 current_fence_sync = context->GetNextFenceSync(); |
| 2815 | 2859 |
| 2816 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2860 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2817 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); | 2861 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); |
| 2818 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | |
| 2819 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2862 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2820 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 2863 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2821 | 2864 |
| 2822 gpu::Mailbox gpu_mailbox; | 2865 gpu::Mailbox gpu_mailbox; |
| 2823 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2866 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2824 gpu::SyncToken release_sync_token; | 2867 gpu::SyncToken release_sync_token; |
| 2825 bool lost_resource = false; | 2868 bool lost_resource = false; |
| 2826 BlockingTaskRunner* mailbox_task_runner = NULL; | 2869 BlockingTaskRunner* mailbox_task_runner = NULL; |
| 2827 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2870 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2828 SingleReleaseCallbackImpl::Create( | 2871 SingleReleaseCallbackImpl::Create( |
| 2829 base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource, | 2872 base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource, |
| 2830 &mailbox_task_runner)); | 2873 &mailbox_task_runner)); |
| 2831 | 2874 |
| 2832 TextureMailbox mailbox(gpu_mailbox, sync_token, target); | 2875 TextureMailbox mailbox(gpu_mailbox, sync_token, target); |
| 2833 mailbox.set_nearest_neighbor(mailbox_nearest_neighbor); | 2876 mailbox.set_nearest_neighbor(mailbox_nearest_neighbor); |
| 2834 | 2877 |
| 2835 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( | 2878 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( |
| 2836 mailbox, std::move(callback)); | 2879 mailbox, std::move(callback)); |
| 2837 EXPECT_NE(0u, id); | 2880 EXPECT_NE(0u, id); |
| 2881 EXPECT_EQ(current_fence_sync, context->GetNextFenceSync()); |
| 2838 | 2882 |
| 2839 Mock::VerifyAndClearExpectations(context); | 2883 Mock::VerifyAndClearExpectations(context); |
| 2840 | 2884 |
| 2841 { | 2885 { |
| 2842 // Mailbox sync point WaitSyncToken before using the texture. | 2886 // Mailbox sync point WaitSyncToken before using the texture. |
| 2843 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); | 2887 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); |
| 2844 resource_provider->WaitSyncTokenIfNeeded(id); | 2888 resource_provider->WaitSyncTokenIfNeeded(id); |
| 2845 Mock::VerifyAndClearExpectations(context); | 2889 Mock::VerifyAndClearExpectations(context); |
| 2846 | 2890 |
| 2847 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) | 2891 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) |
| 2848 .WillOnce(Return(texture_id)); | 2892 .WillOnce(Return(texture_id)); |
| 2849 EXPECT_CALL(*context, bindTexture(target, texture_id)); | 2893 EXPECT_CALL(*context, bindTexture(target, texture_id)); |
| 2850 | 2894 |
| 2851 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | |
| 2852 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2895 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2853 | 2896 |
| 2854 // The sampler will reset these if |mailbox_nearest_neighbor| does not | 2897 // The sampler will reset these if |mailbox_nearest_neighbor| does not |
| 2855 // match |sampler_filter|. | 2898 // match |sampler_filter|. |
| 2856 if (mailbox_nearest_neighbor != (sampler_filter == GL_NEAREST)) { | 2899 if (mailbox_nearest_neighbor != (sampler_filter == GL_NEAREST)) { |
| 2857 EXPECT_CALL(*context, texParameteri( | 2900 EXPECT_CALL(*context, texParameteri( |
| 2858 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampler_filter)); | 2901 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampler_filter)); |
| 2859 EXPECT_CALL(*context, texParameteri( | 2902 EXPECT_CALL(*context, texParameteri( |
| 2860 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter)); | 2903 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter)); |
| 2861 } | 2904 } |
| 2862 | 2905 |
| 2863 ResourceProvider::ScopedSamplerGL lock( | 2906 ResourceProvider::ScopedSamplerGL lock( |
| 2864 resource_provider.get(), id, sampler_filter); | 2907 resource_provider.get(), id, sampler_filter); |
| 2865 Mock::VerifyAndClearExpectations(context); | 2908 Mock::VerifyAndClearExpectations(context); |
| 2909 EXPECT_EQ(current_fence_sync, context->GetNextFenceSync()); |
| 2866 | 2910 |
| 2867 // When done with it, a sync point should be inserted, but no produce is | 2911 // When done with it, a sync point should be inserted, but no produce is |
| 2868 // necessary. | 2912 // necessary. |
| 2869 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2913 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2870 EXPECT_CALL(*context, insertSyncPoint()); | |
| 2871 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 2914 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2872 | 2915 |
| 2873 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); | 2916 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); |
| 2874 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 2917 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2875 } | 2918 } |
| 2876 | 2919 |
| 2877 resource_provider->DeleteResource(id); | 2920 resource_provider->DeleteResource(id); |
| 2878 EXPECT_FALSE(release_sync_token.HasData()); | 2921 EXPECT_TRUE(release_sync_token.HasData()); |
| 2879 EXPECT_FALSE(lost_resource); | 2922 EXPECT_FALSE(lost_resource); |
| 2880 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner); | 2923 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner); |
| 2881 } | 2924 } |
| 2882 }; | 2925 }; |
| 2883 | 2926 |
| 2884 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToLinear) { | 2927 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToLinear) { |
| 2885 // Mailboxing is only supported for GL textures. | 2928 // Mailboxing is only supported for GL textures. |
| 2886 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 2929 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 2887 return; | 2930 return; |
| 2888 | 2931 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2945 FakeOutputSurfaceClient output_surface_client; | 2988 FakeOutputSurfaceClient output_surface_client; |
| 2946 scoped_ptr<OutputSurface> output_surface( | 2989 scoped_ptr<OutputSurface> output_surface( |
| 2947 FakeOutputSurface::Create3d(std::move(context_owned))); | 2990 FakeOutputSurface::Create3d(std::move(context_owned))); |
| 2948 CHECK(output_surface->BindToClient(&output_surface_client)); | 2991 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2949 | 2992 |
| 2950 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 2993 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 2951 output_surface.get(), shared_bitmap_manager_.get(), | 2994 output_surface.get(), shared_bitmap_manager_.get(), |
| 2952 gpu_memory_buffer_manager_.get(), NULL, 0, 1, | 2995 gpu_memory_buffer_manager_.get(), NULL, 0, 1, |
| 2953 use_gpu_memory_buffer_resources_, use_image_texture_targets_)); | 2996 use_gpu_memory_buffer_resources_, use_image_texture_targets_)); |
| 2954 | 2997 |
| 2955 gpu::SyncToken sync_token(30); | 2998 gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO, 0, 0x12, 0x34); |
| 2999 const GLuint64 current_fence_sync = context->GetNextFenceSync(); |
| 2956 unsigned target = GL_TEXTURE_EXTERNAL_OES; | 3000 unsigned target = GL_TEXTURE_EXTERNAL_OES; |
| 2957 | 3001 |
| 2958 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 3002 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2959 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); | 3003 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); |
| 2960 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | |
| 2961 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 3004 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2962 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 3005 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2963 | 3006 |
| 2964 gpu::Mailbox gpu_mailbox; | 3007 gpu::Mailbox gpu_mailbox; |
| 2965 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 3008 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2966 scoped_ptr<SingleReleaseCallbackImpl> callback = | 3009 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2967 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 3010 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
| 2968 | 3011 |
| 2969 TextureMailbox mailbox(gpu_mailbox, sync_token, target); | 3012 TextureMailbox mailbox(gpu_mailbox, sync_token, target); |
| 2970 | 3013 |
| 2971 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( | 3014 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( |
| 2972 mailbox, std::move(callback)); | 3015 mailbox, std::move(callback)); |
| 2973 EXPECT_NE(0u, id); | 3016 EXPECT_NE(0u, id); |
| 3017 EXPECT_EQ(current_fence_sync, context->GetNextFenceSync()); |
| 2974 | 3018 |
| 2975 Mock::VerifyAndClearExpectations(context); | 3019 Mock::VerifyAndClearExpectations(context); |
| 2976 | 3020 |
| 2977 { | 3021 { |
| 2978 // Mailbox sync point WaitSyncToken before using the texture. | 3022 // Mailbox sync point WaitSyncToken before using the texture. |
| 2979 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); | 3023 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); |
| 2980 resource_provider->WaitSyncTokenIfNeeded(id); | 3024 resource_provider->WaitSyncTokenIfNeeded(id); |
| 2981 Mock::VerifyAndClearExpectations(context); | 3025 Mock::VerifyAndClearExpectations(context); |
| 2982 | 3026 |
| 2983 unsigned texture_id = 1; | 3027 unsigned texture_id = 1; |
| 2984 | 3028 |
| 2985 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) | 3029 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) |
| 2986 .WillOnce(Return(texture_id)); | 3030 .WillOnce(Return(texture_id)); |
| 2987 | 3031 |
| 2988 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | |
| 2989 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 3032 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2990 | 3033 |
| 2991 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); | 3034 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); |
| 2992 Mock::VerifyAndClearExpectations(context); | 3035 Mock::VerifyAndClearExpectations(context); |
| 2993 | 3036 |
| 2994 // When done with it, a sync point should be inserted, but no produce is | 3037 // When done with it, a sync point should be inserted, but no produce is |
| 2995 // necessary. | 3038 // necessary. |
| 2996 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 3039 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2997 EXPECT_CALL(*context, insertSyncPoint()); | |
| 2998 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 3040 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2999 | 3041 |
| 3000 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); | 3042 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); |
| 3001 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 3043 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 3002 } | 3044 } |
| 3003 } | 3045 } |
| 3004 | 3046 |
| 3005 TEST_P(ResourceProviderTest, | 3047 TEST_P(ResourceProviderTest, |
| 3006 TextureMailbox_WaitSyncTokenIfNeeded_WithSyncToken) { | 3048 TextureMailbox_WaitSyncTokenIfNeeded_WithSyncToken) { |
| 3007 // Mailboxing is only supported for GL textures. | 3049 // Mailboxing is only supported for GL textures. |
| 3008 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3050 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3009 return; | 3051 return; |
| 3010 | 3052 |
| 3011 scoped_ptr<TextureStateTrackingContext> context_owned( | 3053 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 3012 new TextureStateTrackingContext); | 3054 new TextureStateTrackingContext); |
| 3013 TextureStateTrackingContext* context = context_owned.get(); | 3055 TextureStateTrackingContext* context = context_owned.get(); |
| 3014 | 3056 |
| 3015 FakeOutputSurfaceClient output_surface_client; | 3057 FakeOutputSurfaceClient output_surface_client; |
| 3016 scoped_ptr<OutputSurface> output_surface( | 3058 scoped_ptr<OutputSurface> output_surface( |
| 3017 FakeOutputSurface::Create3d(std::move(context_owned))); | 3059 FakeOutputSurface::Create3d(std::move(context_owned))); |
| 3018 CHECK(output_surface->BindToClient(&output_surface_client)); | 3060 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 3019 | 3061 |
| 3020 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 3062 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 3021 output_surface.get(), shared_bitmap_manager_.get(), | 3063 output_surface.get(), shared_bitmap_manager_.get(), |
| 3022 gpu_memory_buffer_manager_.get(), NULL, 0, 1, | 3064 gpu_memory_buffer_manager_.get(), NULL, 0, 1, |
| 3023 use_gpu_memory_buffer_resources_, use_image_texture_targets_)); | 3065 use_gpu_memory_buffer_resources_, use_image_texture_targets_)); |
| 3024 | 3066 |
| 3025 gpu::SyncToken sync_token(30); | 3067 gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO, 0, 0x12, 0x34); |
| 3068 const GLuint64 current_fence_sync = context->GetNextFenceSync(); |
| 3026 unsigned target = GL_TEXTURE_2D; | 3069 unsigned target = GL_TEXTURE_2D; |
| 3027 | 3070 |
| 3028 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 3071 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 3029 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); | 3072 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); |
| 3030 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | |
| 3031 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 3073 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 3032 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 3074 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 3033 | 3075 |
| 3034 gpu::Mailbox gpu_mailbox; | 3076 gpu::Mailbox gpu_mailbox; |
| 3035 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 3077 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 3036 scoped_ptr<SingleReleaseCallbackImpl> callback = | 3078 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 3037 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 3079 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
| 3038 | 3080 |
| 3039 TextureMailbox mailbox(gpu_mailbox, sync_token, target); | 3081 TextureMailbox mailbox(gpu_mailbox, sync_token, target); |
| 3040 | 3082 |
| 3041 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( | 3083 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( |
| 3042 mailbox, std::move(callback)); | 3084 mailbox, std::move(callback)); |
| 3043 EXPECT_NE(0u, id); | 3085 EXPECT_NE(0u, id); |
| 3086 EXPECT_EQ(current_fence_sync, context->GetNextFenceSync()); |
| 3044 | 3087 |
| 3045 Mock::VerifyAndClearExpectations(context); | 3088 Mock::VerifyAndClearExpectations(context); |
| 3046 | 3089 |
| 3047 { | 3090 { |
| 3048 // First call to WaitSyncTokenIfNeeded should call waitSyncToken. | 3091 // First call to WaitSyncTokenIfNeeded should call waitSyncToken. |
| 3049 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); | 3092 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); |
| 3050 resource_provider->WaitSyncTokenIfNeeded(id); | 3093 resource_provider->WaitSyncTokenIfNeeded(id); |
| 3051 Mock::VerifyAndClearExpectations(context); | 3094 Mock::VerifyAndClearExpectations(context); |
| 3052 | 3095 |
| 3053 // Subsequent calls to WaitSyncTokenIfNeeded shouldn't call waitSyncToken. | 3096 // Subsequent calls to WaitSyncTokenIfNeeded shouldn't call waitSyncToken. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3070 scoped_ptr<OutputSurface> output_surface( | 3113 scoped_ptr<OutputSurface> output_surface( |
| 3071 FakeOutputSurface::Create3d(std::move(context_owned))); | 3114 FakeOutputSurface::Create3d(std::move(context_owned))); |
| 3072 CHECK(output_surface->BindToClient(&output_surface_client)); | 3115 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 3073 | 3116 |
| 3074 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 3117 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 3075 output_surface.get(), shared_bitmap_manager_.get(), | 3118 output_surface.get(), shared_bitmap_manager_.get(), |
| 3076 gpu_memory_buffer_manager_.get(), NULL, 0, 1, | 3119 gpu_memory_buffer_manager_.get(), NULL, 0, 1, |
| 3077 use_gpu_memory_buffer_resources_, use_image_texture_targets_)); | 3120 use_gpu_memory_buffer_resources_, use_image_texture_targets_)); |
| 3078 | 3121 |
| 3079 gpu::SyncToken sync_token; | 3122 gpu::SyncToken sync_token; |
| 3123 const GLuint64 current_fence_sync = context->GetNextFenceSync(); |
| 3080 unsigned target = GL_TEXTURE_2D; | 3124 unsigned target = GL_TEXTURE_2D; |
| 3081 | 3125 |
| 3082 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 3126 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 3083 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); | 3127 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); |
| 3084 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | |
| 3085 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); | 3128 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 3086 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); | 3129 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 3087 | 3130 |
| 3088 gpu::Mailbox gpu_mailbox; | 3131 gpu::Mailbox gpu_mailbox; |
| 3089 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 3132 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 3090 scoped_ptr<SingleReleaseCallbackImpl> callback = | 3133 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 3091 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 3134 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
| 3092 | 3135 |
| 3093 TextureMailbox mailbox(gpu_mailbox, sync_token, target); | 3136 TextureMailbox mailbox(gpu_mailbox, sync_token, target); |
| 3094 | 3137 |
| 3095 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( | 3138 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( |
| 3096 mailbox, std::move(callback)); | 3139 mailbox, std::move(callback)); |
| 3097 EXPECT_NE(0u, id); | 3140 EXPECT_NE(0u, id); |
| 3141 EXPECT_EQ(current_fence_sync, context->GetNextFenceSync()); |
| 3098 | 3142 |
| 3099 Mock::VerifyAndClearExpectations(context); | 3143 Mock::VerifyAndClearExpectations(context); |
| 3100 | 3144 |
| 3101 { | 3145 { |
| 3102 // WaitSyncTokenIfNeeded with empty sync_token shouldn't call waitSyncToken. | 3146 // WaitSyncTokenIfNeeded with empty sync_token shouldn't call waitSyncToken. |
| 3103 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); | 3147 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); |
| 3104 resource_provider->WaitSyncTokenIfNeeded(id); | 3148 resource_provider->WaitSyncTokenIfNeeded(id); |
| 3105 Mock::VerifyAndClearExpectations(context); | 3149 Mock::VerifyAndClearExpectations(context); |
| 3106 } | 3150 } |
| 3107 } | 3151 } |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3558 resource_provider->AllocateForTesting(id); | 3602 resource_provider->AllocateForTesting(id); |
| 3559 Mock::VerifyAndClearExpectations(context); | 3603 Mock::VerifyAndClearExpectations(context); |
| 3560 | 3604 |
| 3561 DCHECK_EQ(10u, context->PeekTextureId()); | 3605 DCHECK_EQ(10u, context->PeekTextureId()); |
| 3562 resource_provider->DeleteResource(id); | 3606 resource_provider->DeleteResource(id); |
| 3563 } | 3607 } |
| 3564 } | 3608 } |
| 3565 | 3609 |
| 3566 } // namespace | 3610 } // namespace |
| 3567 } // namespace cc | 3611 } // namespace cc |
| OLD | NEW |