diff options
54 files changed, 588 insertions, 561 deletions
@@ -7,6 +7,7 @@ include_rules = [ "+gpu/command_buffer/common/gpu_memory_allocation.h", "+gpu/command_buffer/common/capabilities.h", "+gpu/command_buffer/common/mailbox.h", + "+gpu/command_buffer/common/mailbox_holder.h", "+media", "+skia/ext", "+third_party/skia/include", diff --git a/cc/layers/delegated_frame_provider_unittest.cc b/cc/layers/delegated_frame_provider_unittest.cc index 2a4f564..f29488d 100644 --- a/cc/layers/delegated_frame_provider_unittest.cc +++ b/cc/layers/delegated_frame_provider_unittest.cc @@ -38,7 +38,7 @@ class DelegatedFrameProviderTest ResourceProvider::ResourceId resource_id) { TransferableResource resource; resource.id = resource_id; - resource.target = GL_TEXTURE_2D; + resource.mailbox_holder.texture_target = GL_TEXTURE_2D; frame->resource_list.push_back(resource); } diff --git a/cc/layers/texture_layer.cc b/cc/layers/texture_layer.cc index a638780..565a5fe 100644 --- a/cc/layers/texture_layer.cc +++ b/cc/layers/texture_layer.cc @@ -142,10 +142,12 @@ void TextureLayer::SetTextureMailboxInternal( DCHECK_EQ(mailbox.IsValid(), !!release_callback); // If we never commited the mailbox, we need to release it here. - if (mailbox.IsValid()) - holder_ref_ = MailboxHolder::Create(mailbox, release_callback.Pass()); - else + if (mailbox.IsValid()) { + holder_ref_ = + TextureMailboxHolder::Create(mailbox, release_callback.Pass()); + } else { holder_ref_.reset(); + } needs_set_mailbox_ = true; // If we are within a commit, no need to do it again immediately after. if (requires_commit) @@ -262,7 +264,7 @@ void TextureLayer::PushPropertiesTo(LayerImpl* layer) { TextureMailbox texture_mailbox; scoped_ptr<SingleReleaseCallback> release_callback; if (holder_ref_) { - MailboxHolder* holder = holder_ref_->holder(); + TextureMailboxHolder* holder = holder_ref_->holder(); texture_mailbox = holder->mailbox(); release_callback = holder->GetCallbackForImplThread(); } @@ -284,17 +286,18 @@ Region TextureLayer::VisibleContentOpaqueRegion() const { return Region(); } -TextureLayer::MailboxHolder::MainThreadReference::MainThreadReference( - MailboxHolder* holder) +TextureLayer::TextureMailboxHolder::MainThreadReference::MainThreadReference( + TextureMailboxHolder* holder) : holder_(holder) { holder_->InternalAddRef(); } -TextureLayer::MailboxHolder::MainThreadReference::~MainThreadReference() { +TextureLayer::TextureMailboxHolder::MainThreadReference:: + ~MainThreadReference() { holder_->InternalRelease(); } -TextureLayer::MailboxHolder::MailboxHolder( +TextureLayer::TextureMailboxHolder::TextureMailboxHolder( const TextureMailbox& mailbox, scoped_ptr<SingleReleaseCallback> release_callback) : message_loop_(BlockingTaskRunner::current()), @@ -302,42 +305,42 @@ TextureLayer::MailboxHolder::MailboxHolder( mailbox_(mailbox), release_callback_(release_callback.Pass()), sync_point_(mailbox.sync_point()), - is_lost_(false) { -} + is_lost_(false) {} -TextureLayer::MailboxHolder::~MailboxHolder() { +TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { DCHECK_EQ(0u, internal_references_); } -scoped_ptr<TextureLayer::MailboxHolder::MainThreadReference> -TextureLayer::MailboxHolder::Create( +scoped_ptr<TextureLayer::TextureMailboxHolder::MainThreadReference> +TextureLayer::TextureMailboxHolder::Create( const TextureMailbox& mailbox, scoped_ptr<SingleReleaseCallback> release_callback) { return scoped_ptr<MainThreadReference>(new MainThreadReference( - new MailboxHolder(mailbox, release_callback.Pass()))); + new TextureMailboxHolder(mailbox, release_callback.Pass()))); } -void TextureLayer::MailboxHolder::Return(unsigned sync_point, bool is_lost) { +void TextureLayer::TextureMailboxHolder::Return(uint32 sync_point, + bool is_lost) { base::AutoLock lock(arguments_lock_); sync_point_ = sync_point; is_lost_ = is_lost; } scoped_ptr<SingleReleaseCallback> -TextureLayer::MailboxHolder::GetCallbackForImplThread() { +TextureLayer::TextureMailboxHolder::GetCallbackForImplThread() { // We can't call GetCallbackForImplThread if we released the main thread // reference. DCHECK_GT(internal_references_, 0u); InternalAddRef(); return SingleReleaseCallback::Create( - base::Bind(&MailboxHolder::ReturnAndReleaseOnImplThread, this)); + base::Bind(&TextureMailboxHolder::ReturnAndReleaseOnImplThread, this)); } -void TextureLayer::MailboxHolder::InternalAddRef() { +void TextureLayer::TextureMailboxHolder::InternalAddRef() { ++internal_references_; } -void TextureLayer::MailboxHolder::InternalRelease() { +void TextureLayer::TextureMailboxHolder::InternalRelease() { DCHECK(message_loop_->BelongsToCurrentThread()); if (!--internal_references_) { release_callback_->Run(sync_point_, is_lost_); @@ -346,11 +349,12 @@ void TextureLayer::MailboxHolder::InternalRelease() { } } -void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( - unsigned sync_point, bool is_lost) { +void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( + uint32 sync_point, + bool is_lost) { Return(sync_point, is_lost); - message_loop_->PostTask(FROM_HERE, - base::Bind(&MailboxHolder::InternalRelease, this)); + message_loop_->PostTask( + FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); } } // namespace cc diff --git a/cc/layers/texture_layer.h b/cc/layers/texture_layer.h index 8565247..bb179a6 100644 --- a/cc/layers/texture_layer.h +++ b/cc/layers/texture_layer.h @@ -21,22 +21,22 @@ class TextureLayerClient; // A Layer containing a the rendered output of a plugin instance. class CC_EXPORT TextureLayer : public Layer { public: - class CC_EXPORT MailboxHolder - : public base::RefCountedThreadSafe<MailboxHolder> { + class CC_EXPORT TextureMailboxHolder + : public base::RefCountedThreadSafe<TextureMailboxHolder> { public: class CC_EXPORT MainThreadReference { public: - explicit MainThreadReference(MailboxHolder* holder); + explicit MainThreadReference(TextureMailboxHolder* holder); ~MainThreadReference(); - MailboxHolder* holder() { return holder_.get(); } + TextureMailboxHolder* holder() { return holder_.get(); } private: - scoped_refptr<MailboxHolder> holder_; + scoped_refptr<TextureMailboxHolder> holder_; DISALLOW_COPY_AND_ASSIGN(MainThreadReference); }; const TextureMailbox& mailbox() const { return mailbox_; } - void Return(unsigned sync_point, bool is_lost); + void Return(uint32 sync_point, bool is_lost); // Gets a ReleaseCallback that can be called from another thread. Note: the // caller must ensure the callback is called. @@ -49,17 +49,18 @@ class CC_EXPORT TextureLayer : public Layer { static scoped_ptr<MainThreadReference> Create( const TextureMailbox& mailbox, scoped_ptr<SingleReleaseCallback> release_callback); - virtual ~MailboxHolder(); + virtual ~TextureMailboxHolder(); private: - friend class base::RefCountedThreadSafe<MailboxHolder>; + friend class base::RefCountedThreadSafe<TextureMailboxHolder>; friend class MainThreadReference; - explicit MailboxHolder(const TextureMailbox& mailbox, - scoped_ptr<SingleReleaseCallback> release_callback); + explicit TextureMailboxHolder( + const TextureMailbox& mailbox, + scoped_ptr<SingleReleaseCallback> release_callback); void InternalAddRef(); void InternalRelease(); - void ReturnAndReleaseOnImplThread(unsigned sync_point, bool is_lost); + void ReturnAndReleaseOnImplThread(uint32 sync_point, bool is_lost); // This member is thread safe, and is accessed on main and impl threads. const scoped_refptr<BlockingTaskRunner> message_loop_; @@ -75,9 +76,9 @@ class CC_EXPORT TextureLayer : public Layer { // values of these fields are well-ordered such that the last call to // ReturnAndReleaseOnImplThread() defines their values. base::Lock arguments_lock_; - unsigned sync_point_; + uint32 sync_point_; bool is_lost_; - DISALLOW_COPY_AND_ASSIGN(MailboxHolder); + DISALLOW_COPY_AND_ASSIGN(TextureMailboxHolder); }; // If this texture layer requires special preparation logic for each frame @@ -165,7 +166,7 @@ class CC_EXPORT TextureLayer : public Layer { bool content_committed_; unsigned texture_id_; - scoped_ptr<MailboxHolder::MainThreadReference> holder_ref_; + scoped_ptr<TextureMailboxHolder::MainThreadReference> holder_ref_; bool needs_set_mailbox_; DISALLOW_COPY_AND_ASSIGN(TextureLayer); diff --git a/cc/layers/texture_layer_unittest.cc b/cc/layers/texture_layer_unittest.cc index 2db505d..eb274b5 100644 --- a/cc/layers/texture_layer_unittest.cc +++ b/cc/layers/texture_layer_unittest.cc @@ -41,6 +41,12 @@ using ::testing::AnyNumber; namespace cc { namespace { +gpu::Mailbox MailboxFromString(const std::string& string) { + gpu::Mailbox mailbox; + mailbox.SetName(reinterpret_cast<const int8*>(string.data())); + return mailbox; +} + class MockLayerTreeHost : public LayerTreeHost { public: explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) @@ -315,12 +321,14 @@ TEST_F(TextureLayerTest, RateLimiter) { class MockMailboxCallback { public: - MOCK_METHOD3(Release, void(const std::string& mailbox, - unsigned sync_point, - bool lost_resource)); - MOCK_METHOD3(Release2, void(base::SharedMemory* shared_memory, - unsigned sync_point, - bool lost_resource)); + MOCK_METHOD3(Release, + void(const std::string& mailbox, + uint32 sync_point, + bool lost_resource)); + MOCK_METHOD3(Release2, + void(base::SharedMemory* shared_memory, + uint32 sync_point, + bool lost_resource)); }; struct CommonMailboxObjects { @@ -336,13 +344,12 @@ struct CommonMailboxObjects { release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, base::Unretained(&mock_callback_), mailbox_name2_); - gpu::Mailbox m1; - m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data())); - mailbox1_ = TextureMailbox(m1, sync_point1_); - gpu::Mailbox m2; - m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data())); - mailbox2_ = TextureMailbox(m2, sync_point2_); - + const uint32 arbitrary_target1 = 1; + const uint32 arbitrary_target2 = 2; + mailbox1_ = TextureMailbox( + MailboxFromString(mailbox_name1_), arbitrary_target1, sync_point1_); + mailbox2_ = TextureMailbox( + MailboxFromString(mailbox_name2_), arbitrary_target2, sync_point2_); gfx::Size size(128, 128); EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, @@ -360,14 +367,14 @@ struct CommonMailboxObjects { TextureMailbox mailbox1_; TextureMailbox mailbox2_; TextureMailbox mailbox3_; - unsigned sync_point1_; - unsigned sync_point2_; + uint32 sync_point1_; + uint32 sync_point2_; scoped_ptr<base::SharedMemory> shared_memory_; }; -class TestMailboxHolder : public TextureLayer::MailboxHolder { +class TestMailboxHolder : public TextureLayer::TextureMailboxHolder { public: - using TextureLayer::MailboxHolder::Create; + using TextureLayer::TextureMailboxHolder::Create; protected: virtual ~TestMailboxHolder() {} @@ -754,7 +761,7 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { commit_count_(0) {} // Make sure callback is received on main and doesn't block the impl thread. - void ReleaseCallback(unsigned sync_point, bool lost_resource) { + void ReleaseCallback(uint32 sync_point, bool lost_resource) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); EXPECT_FALSE(lost_resource); ++callback_count_; @@ -762,12 +769,14 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { void SetMailbox(char mailbox_char) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); - TextureMailbox mailbox(std::string(64, mailbox_char)); scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( base::Bind( &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, base::Unretained(this))); - layer_->SetTextureMailbox(mailbox, callback.Pass()); + layer_->SetTextureMailbox( + TextureMailbox( + MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), + callback.Pass()); } virtual void BeginTest() OVERRIDE { @@ -1017,14 +1026,16 @@ class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { wait_thread_.Start(); } - static void ReleaseCallback(unsigned sync_point, bool lost_resource) {} + static void ReleaseCallback(uint32 sync_point, bool lost_resource) {} void SetMailbox(char mailbox_char) { - TextureMailbox mailbox(std::string(64, mailbox_char)); scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( base::Bind( &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); - layer_->SetTextureMailbox(mailbox, callback.Pass()); + layer_->SetTextureMailbox( + TextureMailbox( + MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), + callback.Pass()); } virtual void BeginTest() OVERRIDE { @@ -1689,22 +1700,23 @@ class TextureLayerNoExtraCommitForMailboxTest return 0; } virtual bool PrepareTextureMailbox( - TextureMailbox* mailbox, + TextureMailbox* texture_mailbox, scoped_ptr<SingleReleaseCallback>* release_callback, bool use_shared_memory) OVERRIDE { if (layer_tree_host()->source_frame_number() == 1) { - *mailbox = TextureMailbox(); + *texture_mailbox = TextureMailbox(); return true; } - *mailbox = TextureMailbox(std::string(64, '1')); + *texture_mailbox = TextureMailbox( + MailboxFromString(std::string(64, '1')), GL_TEXTURE_2D, 0); *release_callback = SingleReleaseCallback::Create( base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased, base::Unretained(this))); return true; } - void MailboxReleased(unsigned sync_point, bool lost_resource) { + void MailboxReleased(uint32 sync_point, bool lost_resource) { EXPECT_EQ(2, layer_tree_host()->source_frame_number()); EndTest(); } @@ -1821,10 +1833,11 @@ class TextureLayerChangeInvisibleMailboxTest } TextureMailbox MakeMailbox(char name) { - return TextureMailbox(std::string(64, name)); + return TextureMailbox( + MailboxFromString(std::string(64, name)), GL_TEXTURE_2D, 0); } - void MailboxReleased(unsigned sync_point, bool lost_resource) { + void MailboxReleased(uint32 sync_point, bool lost_resource) { ++mailbox_returned_; } @@ -2015,7 +2028,7 @@ SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerLostContextTest); class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { public: - void ReleaseCallback(unsigned sync_point, bool lost_resource) { + void ReleaseCallback(uint32 sync_point, bool lost_resource) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); EXPECT_FALSE(lost_resource); ++callback_count_; @@ -2024,12 +2037,14 @@ class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { void SetMailbox(char mailbox_char) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); - TextureMailbox mailbox(std::string(64, mailbox_char)); scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( base::Bind( &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback, base::Unretained(this))); - layer_->SetTextureMailbox(mailbox, callback.Pass()); + layer_->SetTextureMailbox( + TextureMailbox( + MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), + callback.Pass()); } virtual void SetupTree() OVERRIDE { @@ -2087,7 +2102,7 @@ SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest { public: - void ReleaseCallback(unsigned sync_point, bool lost_resource) { + void ReleaseCallback(uint32 sync_point, bool lost_resource) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); EXPECT_FALSE(lost_resource); ++callback_count_; @@ -2096,12 +2111,14 @@ class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest { void SetMailbox(char mailbox_char) { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); - TextureMailbox mailbox(std::string(64, mailbox_char)); scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( base::Bind( &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback, base::Unretained(this))); - layer_->SetTextureMailbox(mailbox, callback.Pass()); + layer_->SetTextureMailbox( + TextureMailbox( + MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), + callback.Pass()); } virtual void SetupTree() OVERRIDE { diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc index 028c409..cef3bdb 100644 --- a/cc/output/gl_renderer.cc +++ b/cc/output/gl_renderer.cc @@ -2213,7 +2213,7 @@ void GLRenderer::GetFramebufferPixelsAsync( return; } } else { - mailbox = request->texture_mailbox().name(); + mailbox = request->texture_mailbox().mailbox(); DCHECK_EQ(static_cast<unsigned>(GL_TEXTURE_2D), request->texture_mailbox().target()); DCHECK(!mailbox.IsZero()); diff --git a/cc/resources/release_callback.h b/cc/resources/release_callback.h index 9433f7f..b471381 100644 --- a/cc/resources/release_callback.h +++ b/cc/resources/release_callback.h @@ -9,8 +9,7 @@ namespace cc { -typedef base::Callback<void(unsigned sync_point, bool is_lost)> - ReleaseCallback; +typedef base::Callback<void(uint32 sync_point, bool is_lost)> ReleaseCallback; } // namespace cc diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc index 4579126..a86a1d7 100644 --- a/cc/resources/resource_provider.cc +++ b/cc/resources/resource_provider.cc @@ -544,7 +544,7 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); } if (resource->mailbox.IsValid() && resource->external) { - GLuint sync_point = resource->mailbox.sync_point(); + uint32 sync_point = resource->mailbox.sync_point(); if (resource->mailbox.IsTexture()) { lost_resource |= lost_output_surface_; GLES2Interface* gl = ContextGL(); @@ -739,13 +739,13 @@ const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { DCHECK(gl); if (resource->mailbox.sync_point()) { GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); - resource->mailbox.ResetSyncPoint(); + resource->mailbox.set_sync_point(0); } resource->gl_id = texture_id_allocator_->NextId(); GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); GLC(gl, gl->ConsumeTextureCHROMIUM(resource->target, - resource->mailbox.data())); + resource->mailbox.name())); } } @@ -1021,7 +1021,7 @@ void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, ++it) { TransferableResource resource; TransferResource(gl, *it, &resource); - if (!resource.sync_point && !resource.is_software) + if (!resource.mailbox_holder.sync_point && !resource.is_software) need_sync_point = true; ++resources_.find(*it)->second.exported_count; list->push_back(resource); @@ -1031,8 +1031,8 @@ void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, for (TransferableResourceArray::iterator it = list->begin(); it != list->end(); ++it) { - if (!it->sync_point) - it->sync_point = sync_point; + if (!it->mailbox_holder.sync_point) + it->mailbox_holder.sync_point = sync_point; } } } @@ -1056,9 +1056,10 @@ void ResourceProvider::ReceiveFromChild( scoped_ptr<SharedBitmap> bitmap; uint8_t* pixels = NULL; if (it->is_software) { - if (shared_bitmap_manager_) - bitmap = shared_bitmap_manager_->GetSharedBitmapFromId(it->size, - it->mailbox); + if (shared_bitmap_manager_) { + bitmap = shared_bitmap_manager_->GetSharedBitmapFromId( + it->size, it->mailbox_holder.mailbox); + } if (bitmap) pixels = bitmap->pixels(); } @@ -1084,20 +1085,23 @@ void ResourceProvider::ReceiveFromChild( // waiting asynchronously, and resetting sync_point before calling this. // However if the parent is a renderer (e.g. browser tag), it may be ok // (and is simpler) to wait. - if (it->sync_point) - GLC(gl, gl->WaitSyncPointCHROMIUM(it->sync_point)); + if (it->mailbox_holder.sync_point) + GLC(gl, gl->WaitSyncPointCHROMIUM(it->mailbox_holder.sync_point)); texture_id = texture_id_allocator_->NextId(); - GLC(gl, gl->BindTexture(it->target, texture_id)); - GLC(gl, gl->ConsumeTextureCHROMIUM(it->target, it->mailbox.name)); + GLC(gl, gl->BindTexture(it->mailbox_holder.texture_target, texture_id)); + GLC(gl, + gl->ConsumeTextureCHROMIUM(it->mailbox_holder.texture_target, + it->mailbox_holder.mailbox.name)); resource = Resource(texture_id, it->size, - it->target, + it->mailbox_holder.texture_target, it->filter, 0, GL_CLAMP_TO_EDGE, TextureUsageAny, it->format); - resource.mailbox.SetName(it->mailbox); + resource.mailbox = TextureMailbox( + it->mailbox_holder.mailbox, it->mailbox_holder.texture_target, 0); } resource.child_id = child; // Don't allocate a texture for a child. @@ -1203,8 +1207,7 @@ void ResourceProvider::ReceiveReturnsFromParent( if (returned.sync_point) GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); } else if (!resource->shared_bitmap) { - resource->mailbox = - TextureMailbox(resource->mailbox.name(), returned.sync_point); + resource->mailbox.set_sync_point(returned.sync_point); } if (!resource->marked_for_deletion) @@ -1252,39 +1255,45 @@ void ResourceProvider::TransferResource(GLES2Interface* gl, DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE); resource->id = id; resource->format = source->format; - resource->target = source->target; + resource->mailbox_holder.texture_target = source->target; resource->filter = source->filter; resource->size = source->size; if (source->shared_bitmap) { - resource->mailbox = source->shared_bitmap->id(); + resource->mailbox_holder.mailbox = source->shared_bitmap->id(); resource->is_software = true; } else if (!source->mailbox.IsValid()) { LazyCreate(source); DCHECK(source->gl_id); - GLC(gl, gl->BindTexture(resource->target, source->gl_id)); + GLC(gl, + gl->BindTexture(resource->mailbox_holder.texture_target, + source->gl_id)); if (source->image_id) { DCHECK(source->dirty_image); BindImageForSampling(source); } // This is a resource allocated by the compositor, we need to produce it. // Don't set a sync point, the caller will do it. - GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox.name)); + GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name)); GLC(gl, - gl->ProduceTextureCHROMIUM(resource->target, resource->mailbox.name)); - source->mailbox.SetName(resource->mailbox); + gl->ProduceTextureCHROMIUM(resource->mailbox_holder.texture_target, + resource->mailbox_holder.mailbox.name)); + source->mailbox = TextureMailbox(resource->mailbox_holder); } else { DCHECK(source->mailbox.IsTexture()); if (source->image_id && source->dirty_image) { DCHECK(source->gl_id); - GLC(gl, gl->BindTexture(resource->target, source->gl_id)); + GLC(gl, + gl->BindTexture(resource->mailbox_holder.texture_target, + source->gl_id)); BindImageForSampling(source); } // This is either an external resource, or a compositor resource that we // already exported. Make sure to forward the sync point that we were given. - resource->mailbox = source->mailbox.name(); - resource->sync_point = source->mailbox.sync_point(); - source->mailbox.ResetSyncPoint(); + resource->mailbox_holder.mailbox = source->mailbox.mailbox(); + resource->mailbox_holder.texture_target = source->mailbox.target(); + resource->mailbox_holder.sync_point = source->mailbox.sync_point(); + source->mailbox.set_sync_point(0); } } diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc index 52de843..c97ee4e 100644 --- a/cc/resources/resource_provider_unittest.cc +++ b/cc/resources/resource_provider_unittest.cc @@ -37,15 +37,15 @@ using testing::_; namespace cc { namespace { -static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} +static void EmptyReleaseCallback(uint32 sync_point, bool lost_resource) {} static void SharedMemoryReleaseCallback(scoped_ptr<base::SharedMemory> memory, - unsigned sync_point, + uint32 sync_point, bool lost_resource) {} -static void ReleaseTextureMailbox(unsigned* release_sync_point, +static void ReleaseTextureMailbox(uint32* release_sync_point, bool* release_lost_resource, - unsigned sync_point, + uint32 sync_point, bool lost_resource) { *release_sync_point = sync_point; *release_lost_resource = lost_resource; @@ -54,9 +54,9 @@ static void ReleaseTextureMailbox(unsigned* release_sync_point, static void ReleaseSharedMemoryCallback( scoped_ptr<base::SharedMemory> shared_memory, bool* release_called, - unsigned* release_sync_point, + uint32* release_sync_point, bool* lost_resource_result, - unsigned sync_point, + uint32 sync_point, bool lost_resource) { *release_called = true; *release_sync_point = sync_point; @@ -78,8 +78,8 @@ class TextureStateTrackingContext : public TestWebGraphicsContext3D { public: MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); - MOCK_METHOD1(waitSyncPoint, void(unsigned sync_point)); - MOCK_METHOD0(insertSyncPoint, unsigned(void)); + MOCK_METHOD1(waitSyncPoint, void(GLuint sync_point)); + MOCK_METHOD0(insertSyncPoint, GLuint(void)); MOCK_METHOD2(produceTextureCHROMIUM, void(GLenum target, const GLbyte* mailbox)); MOCK_METHOD2(consumeTextureCHROMIUM, @@ -102,7 +102,7 @@ class ContextSharedData { return make_scoped_ptr(new ContextSharedData()); } - unsigned InsertSyncPoint() { return next_sync_point_++; } + uint32 InsertSyncPoint() { return next_sync_point_++; } void GenMailbox(GLbyte* mailbox) { memset(mailbox, 0, sizeof(GLbyte[64])); @@ -111,7 +111,7 @@ class ContextSharedData { } void ProduceTexture(const GLbyte* mailbox_name, - unsigned sync_point, + uint32 sync_point, scoped_refptr<TestTexture> texture) { unsigned mailbox = 0; memcpy(&mailbox, mailbox_name, sizeof(mailbox)); @@ -122,7 +122,7 @@ class ContextSharedData { } scoped_refptr<TestTexture> ConsumeTexture(const GLbyte* mailbox_name, - unsigned sync_point) { + uint32 sync_point) { unsigned mailbox = 0; memcpy(&mailbox, mailbox_name, sizeof(mailbox)); DCHECK(mailbox && mailbox < next_mailbox_); @@ -140,11 +140,11 @@ class ContextSharedData { private: ContextSharedData() : next_sync_point_(1), next_mailbox_(1) {} - unsigned next_sync_point_; + uint32 next_sync_point_; unsigned next_mailbox_; typedef base::hash_map<unsigned, scoped_refptr<TestTexture> > TextureMap; TextureMap textures_; - base::hash_map<unsigned, unsigned> sync_point_for_mailbox_; + base::hash_map<unsigned, uint32> sync_point_for_mailbox_; }; class ResourceProviderContext : public TestWebGraphicsContext3D { @@ -154,8 +154,8 @@ class ResourceProviderContext : public TestWebGraphicsContext3D { return make_scoped_ptr(new ResourceProviderContext(shared_data)); } - virtual unsigned insertSyncPoint() OVERRIDE { - unsigned sync_point = shared_data_->InsertSyncPoint(); + virtual GLuint insertSyncPoint() OVERRIDE { + uint32 sync_point = shared_data_->InsertSyncPoint(); // Commit the produceTextureCHROMIUM calls at this point, so that // they're associated with the sync point. for (PendingProduceTextureList::iterator it = @@ -169,7 +169,7 @@ class ResourceProviderContext : public TestWebGraphicsContext3D { return sync_point; } - virtual void waitSyncPoint(unsigned sync_point) OVERRIDE { + virtual void waitSyncPoint(GLuint sync_point) OVERRIDE { last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); } @@ -323,7 +323,7 @@ class ResourceProviderContext : public TestWebGraphicsContext3D { }; typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; ContextSharedData* shared_data_; - unsigned last_waited_sync_point_; + GLuint last_waited_sync_point_; PendingProduceTextureList pending_produce_textures_; }; @@ -473,10 +473,10 @@ class ResourceProviderTest ResourceProviderContext* context() { return context3d_; } - ResourceProvider::ResourceId CreateChildMailbox(unsigned* release_sync_point, + ResourceProvider::ResourceId CreateChildMailbox(uint32* release_sync_point, bool* lost_resource, bool* release_called, - unsigned* sync_point) { + uint32* sync_point) { if (GetParam() == ResourceProvider::GLTexture) { unsigned texture = child_context_->createTexture(); gpu::Mailbox gpu_mailbox; @@ -494,7 +494,8 @@ class ResourceProviderTest release_sync_point, lost_resource)); return child_resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(gpu_mailbox, *sync_point), callback.Pass()); + TextureMailbox(gpu_mailbox, GL_TEXTURE_2D, *sync_point), + callback.Pass()); } else { gfx::Size size(64, 64); scoped_ptr<base::SharedMemory> shared_memory( @@ -660,7 +661,7 @@ TEST_P(ResourceProviderTest, TransferGLResources) { child_context_->genMailboxCHROMIUM(external_mailbox.name); child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, external_mailbox.name); - const unsigned external_sync_point = child_context_->insertSyncPoint(); + const GLuint external_sync_point = child_context_->insertSyncPoint(); ResourceProvider::ResourceId id4 = child_resource_provider_->CreateResourceFromTextureMailbox( TextureMailbox( @@ -681,14 +682,18 @@ TEST_P(ResourceProviderTest, TransferGLResources) { child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); ASSERT_EQ(4u, list.size()); - EXPECT_NE(0u, list[0].sync_point); - EXPECT_NE(0u, list[1].sync_point); - EXPECT_NE(0u, list[2].sync_point); - EXPECT_EQ(external_sync_point, list[3].sync_point); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[2].target); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), list[3].target); + EXPECT_NE(0u, list[0].mailbox_holder.sync_point); + EXPECT_NE(0u, list[1].mailbox_holder.sync_point); + EXPECT_NE(0u, list[2].mailbox_holder.sync_point); + EXPECT_EQ(external_sync_point, list[3].mailbox_holder.sync_point); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[0].mailbox_holder.texture_target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[1].mailbox_holder.texture_target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[2].mailbox_holder.texture_target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), + list[3].mailbox_holder.texture_target); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); @@ -737,9 +742,12 @@ TEST_P(ResourceProviderTest, TransferGLResources) { EXPECT_EQ(id1, list[0].id); EXPECT_EQ(id2, list[1].id); EXPECT_EQ(id3, list[2].id); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[2].target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[0].mailbox_holder.texture_target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[1].mailbox_holder.texture_target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[2].mailbox_holder.texture_target); ReturnedResourceArray returned; TransferableResource::ReturnResources(list, &returned); child_resource_provider_->ReceiveReturnsFromParent(returned); @@ -811,14 +819,18 @@ TEST_P(ResourceProviderTest, TransferGLResources) { EXPECT_EQ(id2, list[1].id); EXPECT_EQ(id3, list[2].id); EXPECT_EQ(id4, list[3].id); - EXPECT_NE(0u, list[0].sync_point); - EXPECT_NE(0u, list[1].sync_point); - EXPECT_NE(0u, list[2].sync_point); - EXPECT_NE(0u, list[3].sync_point); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[2].target); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), list[3].target); + EXPECT_NE(0u, list[0].mailbox_holder.sync_point); + EXPECT_NE(0u, list[1].mailbox_holder.sync_point); + EXPECT_NE(0u, list[2].mailbox_holder.sync_point); + EXPECT_NE(0u, list[3].mailbox_holder.sync_point); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[0].mailbox_holder.texture_target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[1].mailbox_holder.texture_target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[2].mailbox_holder.texture_target); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), + list[3].mailbox_holder.texture_target); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); @@ -896,10 +908,10 @@ TEST_P(ResourceProviderTest, TransferSoftwareResources) { child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); ASSERT_EQ(4u, list.size()); - EXPECT_EQ(0u, list[0].sync_point); - EXPECT_EQ(0u, list[1].sync_point); - EXPECT_EQ(0u, list[2].sync_point); - EXPECT_EQ(0u, list[3].sync_point); + EXPECT_EQ(0u, list[0].mailbox_holder.sync_point); + EXPECT_EQ(0u, list[1].mailbox_holder.sync_point); + EXPECT_EQ(0u, list[2].mailbox_holder.sync_point); + EXPECT_EQ(0u, list[3].mailbox_holder.sync_point); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); @@ -1157,8 +1169,9 @@ TEST_P(ResourceProviderTest, TransferGLToSoftware) { child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, &list); ASSERT_EQ(1u, list.size()); - EXPECT_NE(0u, list[0].sync_point); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); + EXPECT_NE(0u, list[0].mailbox_holder.sync_point); + EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + list[0].mailbox_holder.texture_target); EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1)); resource_provider_->ReceiveFromChild(child_id, list); } @@ -1204,7 +1217,7 @@ TEST_P(ResourceProviderTest, TransferInvalidSoftware) { &list); ASSERT_EQ(1u, list.size()); // Make invalid. - list[0].mailbox.name[1] = 5; + list[0].mailbox_holder.mailbox.name[1] = 5; EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); resource_provider_->ReceiveFromChild(child_id, list); } @@ -1254,8 +1267,8 @@ TEST_P(ResourceProviderTest, DeleteExportedResources) { &list); ASSERT_EQ(2u, list.size()); if (GetParam() == ResourceProvider::GLTexture) { - EXPECT_NE(0u, list[0].sync_point); - EXPECT_NE(0u, list[1].sync_point); + EXPECT_NE(0u, list[0].mailbox_holder.sync_point); + EXPECT_NE(0u, list[1].mailbox_holder.sync_point); } EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); @@ -1284,8 +1297,8 @@ TEST_P(ResourceProviderTest, DeleteExportedResources) { ASSERT_EQ(2u, list.size()); if (GetParam() == ResourceProvider::GLTexture) { - EXPECT_NE(0u, list[0].sync_point); - EXPECT_NE(0u, list[1].sync_point); + EXPECT_NE(0u, list[0].mailbox_holder.sync_point); + EXPECT_NE(0u, list[1].mailbox_holder.sync_point); } EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); @@ -1348,8 +1361,8 @@ TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) { &list); ASSERT_EQ(2u, list.size()); if (GetParam() == ResourceProvider::GLTexture) { - EXPECT_NE(0u, list[0].sync_point); - EXPECT_NE(0u, list[1].sync_point); + EXPECT_NE(0u, list[0].mailbox_holder.sync_point); + EXPECT_NE(0u, list[1].mailbox_holder.sync_point); } EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); @@ -1378,8 +1391,8 @@ TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) { ASSERT_EQ(2u, list.size()); if (GetParam() == ResourceProvider::GLTexture) { - EXPECT_NE(0u, list[0].sync_point); - EXPECT_NE(0u, list[1].sync_point); + EXPECT_NE(0u, list[0].mailbox_holder.sync_point); + EXPECT_NE(0u, list[1].mailbox_holder.sync_point); } EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); @@ -1453,7 +1466,7 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources) { &list); ASSERT_EQ(1u, list.size()); if (GetParam() == ResourceProvider::GLTexture) - EXPECT_NE(0u, list[0].sync_point); + EXPECT_NE(0u, list[0].mailbox_holder.sync_point); EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id)); resource_provider_->ReceiveFromChild(child_id, list); resource_provider_->DeclareUsedResourcesFromChild(child_id, @@ -1667,18 +1680,18 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { gpu::Mailbox mailbox; context()->genMailboxCHROMIUM(mailbox.name); context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); - unsigned sync_point = context()->insertSyncPoint(); + uint32 sync_point = context()->insertSyncPoint(); // All the logic below assumes that the sync points are all positive. EXPECT_LT(0u, sync_point); - unsigned release_sync_point = 0; + uint32 release_sync_point = 0; bool lost_resource = false; ReleaseCallback callback = base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); ResourceProvider::ResourceId resource = resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(mailbox, sync_point), + TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), SingleReleaseCallback::Create(callback)); EXPECT_EQ(1u, context()->NumTextures()); EXPECT_EQ(0u, release_sync_point); @@ -1689,12 +1702,14 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { TransferableResourceArray list; resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); ASSERT_EQ(1u, list.size()); - EXPECT_LE(sync_point, list[0].sync_point); + EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); EXPECT_EQ(0, - memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); + memcmp(mailbox.name, + list[0].mailbox_holder.mailbox.name, + sizeof(mailbox.name))); EXPECT_EQ(0u, release_sync_point); - context()->waitSyncPoint(list[0].sync_point); + context()->waitSyncPoint(list[0].mailbox_holder.sync_point); unsigned other_texture = context()->createTexture(); context()->bindTexture(GL_TEXTURE_2D, other_texture); context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); @@ -1704,8 +1719,8 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); context()->deleteTexture(other_texture); - list[0].sync_point = context()->insertSyncPoint(); - EXPECT_LT(0u, list[0].sync_point); + list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); + EXPECT_LT(0u, list[0].mailbox_holder.sync_point); // Receive the resource, then delete it, expect the sync points to be // consistent. @@ -1716,7 +1731,7 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { EXPECT_EQ(0u, release_sync_point); resource_provider_->DeleteResource(resource); - EXPECT_LE(list[0].sync_point, release_sync_point); + EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); EXPECT_FALSE(lost_resource); } @@ -1726,7 +1741,7 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { EXPECT_LT(0u, sync_point); release_sync_point = 0; resource = resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(mailbox, sync_point), + TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), SingleReleaseCallback::Create(callback)); EXPECT_EQ(1u, context()->NumTextures()); EXPECT_EQ(0u, release_sync_point); @@ -1737,12 +1752,14 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { TransferableResourceArray list; resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); ASSERT_EQ(1u, list.size()); - EXPECT_LE(sync_point, list[0].sync_point); + EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); EXPECT_EQ(0, - memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); + memcmp(mailbox.name, + list[0].mailbox_holder.mailbox.name, + sizeof(mailbox.name))); EXPECT_EQ(0u, release_sync_point); - context()->waitSyncPoint(list[0].sync_point); + context()->waitSyncPoint(list[0].mailbox_holder.sync_point); unsigned other_texture = context()->createTexture(); context()->bindTexture(GL_TEXTURE_2D, other_texture); context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); @@ -1752,8 +1769,8 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); context()->deleteTexture(other_texture); - list[0].sync_point = context()->insertSyncPoint(); - EXPECT_LT(0u, list[0].sync_point); + list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); + EXPECT_LT(0u, list[0].mailbox_holder.sync_point); // Delete the resource, which shouldn't do anything. resource_provider_->DeleteResource(resource); @@ -1765,7 +1782,7 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { ReturnedResourceArray returned; TransferableResource::ReturnResources(list, &returned); resource_provider_->ReceiveReturnsFromParent(returned); - EXPECT_LE(list[0].sync_point, release_sync_point); + EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); EXPECT_FALSE(lost_resource); } @@ -1905,10 +1922,10 @@ TEST_P(ResourceProviderTest, LostResourceInGrandParent) { } TEST_P(ResourceProviderTest, LostMailboxInParent) { - unsigned release_sync_point = 0; + uint32 release_sync_point = 0; bool lost_resource = false; bool release_called = false; - unsigned sync_point = 0; + uint32 sync_point = 0; ResourceProvider::ResourceId resource = CreateChildMailbox( &release_sync_point, &lost_resource, &release_called, &sync_point); @@ -1955,10 +1972,10 @@ TEST_P(ResourceProviderTest, LostMailboxInParent) { } TEST_P(ResourceProviderTest, LostMailboxInGrandParent) { - unsigned release_sync_point = 0; + uint32 release_sync_point = 0; bool lost_resource = false; bool release_called = false; - unsigned sync_point = 0; + uint32 sync_point = 0; ResourceProvider::ResourceId resource = CreateChildMailbox( &release_sync_point, &lost_resource, &release_called, &sync_point); @@ -2023,10 +2040,10 @@ TEST_P(ResourceProviderTest, LostMailboxInGrandParent) { } TEST_P(ResourceProviderTest, Shutdown) { - unsigned release_sync_point = 0; + uint32 release_sync_point = 0; bool lost_resource = false; bool release_called = false; - unsigned sync_point = 0; + uint32 sync_point = 0; CreateChildMailbox( &release_sync_point, &lost_resource, &release_called, &sync_point); @@ -2043,10 +2060,10 @@ TEST_P(ResourceProviderTest, Shutdown) { } TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { - unsigned release_sync_point = 0; + uint32 release_sync_point = 0; bool lost_resource = false; bool release_called = false; - unsigned sync_point = 0; + uint32 sync_point = 0; ResourceProvider::ResourceId resource = CreateChildMailbox( &release_sync_point, &lost_resource, &release_called, &sync_point); @@ -2076,17 +2093,16 @@ TEST_P(ResourceProviderTest, LostContext) { gpu::Mailbox mailbox; context()->genMailboxCHROMIUM(mailbox.name); context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); - unsigned sync_point = context()->insertSyncPoint(); + uint32 sync_point = context()->insertSyncPoint(); EXPECT_LT(0u, sync_point); - unsigned release_sync_point = 0; + uint32 release_sync_point = 0; bool lost_resource = false; scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(mailbox, sync_point), - callback.Pass()); + TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), callback.Pass()); EXPECT_EQ(0u, release_sync_point); EXPECT_FALSE(lost_resource); @@ -2335,7 +2351,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); unsigned texture_id = 1; - unsigned sync_point = 30; + uint32 sync_point = 30; unsigned target = GL_TEXTURE_2D; EXPECT_CALL(*context, bindTexture(_, _)).Times(0); @@ -2349,7 +2365,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( base::Bind(&EmptyReleaseCallback)); - TextureMailbox mailbox(gpu_mailbox, sync_point); + TextureMailbox mailbox(gpu_mailbox, target, sync_point); ResourceProvider::ResourceId id = resource_provider->CreateResourceFromTextureMailbox( @@ -2399,7 +2415,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); unsigned texture_id = 1; - unsigned sync_point = 30; + uint32 sync_point = 30; unsigned target = GL_TEXTURE_EXTERNAL_OES; EXPECT_CALL(*context, bindTexture(_, _)).Times(0); diff --git a/cc/resources/single_release_callback.cc b/cc/resources/single_release_callback.cc index 9c6b9de..4565963 100644 --- a/cc/resources/single_release_callback.cc +++ b/cc/resources/single_release_callback.cc @@ -20,7 +20,7 @@ SingleReleaseCallback::~SingleReleaseCallback() { << "SingleReleaseCallback was never run."; } -void SingleReleaseCallback::Run(unsigned sync_point, bool is_lost) { +void SingleReleaseCallback::Run(uint32 sync_point, bool is_lost) { DCHECK(!has_been_run_) << "SingleReleaseCallback was run more than once."; has_been_run_ = true; callback_.Run(sync_point, is_lost); diff --git a/cc/resources/single_release_callback.h b/cc/resources/single_release_callback.h index fe1a3ba..6f64df6 100644 --- a/cc/resources/single_release_callback.h +++ b/cc/resources/single_release_callback.h @@ -19,7 +19,7 @@ class CC_EXPORT SingleReleaseCallback { ~SingleReleaseCallback(); - void Run(unsigned sync_point, bool is_lost); + void Run(uint32 sync_point, bool is_lost); private: explicit SingleReleaseCallback(const ReleaseCallback& callback); diff --git a/cc/resources/texture_mailbox.cc b/cc/resources/texture_mailbox.cc index 149d56c..198d473 100644 --- a/cc/resources/texture_mailbox.cc +++ b/cc/resources/texture_mailbox.cc @@ -9,78 +9,36 @@ namespace cc { -TextureMailbox::TextureMailbox() - : target_(GL_TEXTURE_2D), - sync_point_(0), - shared_memory_(NULL) { -} - -TextureMailbox::TextureMailbox(const std::string& mailbox_name) - : target_(GL_TEXTURE_2D), - sync_point_(0), - shared_memory_(NULL) { - if (!mailbox_name.empty()) { - CHECK(mailbox_name.size() == sizeof(name_.name)); - name_.SetName(reinterpret_cast<const int8*>(mailbox_name.data())); - } -} +TextureMailbox::TextureMailbox() : shared_memory_(NULL) {} -TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name) - : target_(GL_TEXTURE_2D), - sync_point_(0), - shared_memory_(NULL) { - name_.SetName(mailbox_name.name); -} - -TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name, - unsigned sync_point) - : target_(GL_TEXTURE_2D), - sync_point_(sync_point), - shared_memory_(NULL) { - name_.SetName(mailbox_name.name); -} +TextureMailbox::TextureMailbox(const gpu::MailboxHolder& mailbox_holder) + : mailbox_holder_(mailbox_holder), shared_memory_(NULL) {} -TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name, - unsigned texture_target, - unsigned sync_point) - : target_(texture_target), - sync_point_(sync_point), - shared_memory_(NULL) { - name_.SetName(mailbox_name.name); -} +TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox, + uint32 target, + uint32 sync_point) + : mailbox_holder_(mailbox, target, sync_point), shared_memory_(NULL) {} TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory, gfx::Size size) - : target_(GL_TEXTURE_2D), - sync_point_(0), - shared_memory_(shared_memory), - shared_memory_size_(size) {} + : shared_memory_(shared_memory), shared_memory_size_(size) {} TextureMailbox::~TextureMailbox() {} bool TextureMailbox::Equals(const TextureMailbox& other) const { - if (other.IsTexture()) - return ContainsMailbox(other.name()); - else if (other.IsSharedMemory()) - return ContainsHandle(other.shared_memory_->handle()); + if (other.IsTexture()) { + return IsTexture() && !memcmp(mailbox_holder_.mailbox.name, + other.mailbox_holder_.mailbox.name, + sizeof(mailbox_holder_.mailbox.name)); + } else if (other.IsSharedMemory()) { + return IsSharedMemory() && + shared_memory_->handle() == other.shared_memory_->handle(); + } DCHECK(!other.IsValid()); return !IsValid(); } -bool TextureMailbox::ContainsMailbox(const gpu::Mailbox& other) const { - return IsTexture() && !memcmp(data(), other.name, sizeof(name_.name)); -} - -bool TextureMailbox::ContainsHandle(base::SharedMemoryHandle handle) const { - return shared_memory_ && shared_memory_->handle() == handle; -} - -void TextureMailbox::SetName(const gpu::Mailbox& name) { - DCHECK(shared_memory_ == NULL); - name_ = name; -} - size_t TextureMailbox::shared_memory_size_in_bytes() const { return 4 * shared_memory_size_.GetArea(); } diff --git a/cc/resources/texture_mailbox.h b/cc/resources/texture_mailbox.h index a9b021b..1a81a75 100644 --- a/cc/resources/texture_mailbox.h +++ b/cc/resources/texture_mailbox.h @@ -10,7 +10,7 @@ #include "base/callback.h" #include "base/memory/shared_memory.h" #include "cc/base/cc_export.h" -#include "gpu/command_buffer/common/mailbox.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "ui/gfx/size.h" namespace cc { @@ -20,44 +20,32 @@ namespace cc { class CC_EXPORT TextureMailbox { public: TextureMailbox(); - explicit TextureMailbox(const std::string& mailbox_name); - explicit TextureMailbox(const gpu::Mailbox& mailbox_name); - TextureMailbox(const gpu::Mailbox& mailbox_name, - unsigned sync_point); - TextureMailbox(const gpu::Mailbox& mailbox_name, - unsigned texture_target, - unsigned sync_point); - TextureMailbox(base::SharedMemory* shared_memory, - gfx::Size size); + explicit TextureMailbox(const gpu::MailboxHolder& mailbox_holder); + TextureMailbox(const gpu::Mailbox& mailbox, uint32 target, uint32 sync_point); + TextureMailbox(base::SharedMemory* shared_memory, gfx::Size size); ~TextureMailbox(); bool IsValid() const { return IsTexture() || IsSharedMemory(); } - bool IsTexture() const { return !name_.IsZero(); } + bool IsTexture() const { return !mailbox_holder_.mailbox.IsZero(); } bool IsSharedMemory() const { return shared_memory_ != NULL; } bool Equals(const TextureMailbox&) const; - bool ContainsMailbox(const gpu::Mailbox&) const; - bool ContainsHandle(base::SharedMemoryHandle handle) const; - const int8* data() const { return name_.name; } - const gpu::Mailbox& name() const { return name_; } - void ResetSyncPoint() { sync_point_ = 0; } - unsigned target() const { return target_; } - unsigned sync_point() const { return sync_point_; } + const gpu::Mailbox& mailbox() const { return mailbox_holder_.mailbox; } + const int8* name() const { return mailbox().name; } + uint32 target() const { return mailbox_holder_.texture_target; } + uint32 sync_point() const { return mailbox_holder_.sync_point; } + void set_sync_point(int32 sync_point) { + mailbox_holder_.sync_point = sync_point; + } base::SharedMemory* shared_memory() const { return shared_memory_; } gfx::Size shared_memory_size() const { return shared_memory_size_; } size_t shared_memory_size_in_bytes() const; - // TODO(danakj): ReleaseCallback should be separate from this class, and stop - // storing a TextureMailbox in ResourceProvider. Then we can remove this. - void SetName(const gpu::Mailbox& name); - private: - gpu::Mailbox name_; - unsigned target_; - unsigned sync_point_; + gpu::MailboxHolder mailbox_holder_; base::SharedMemory* shared_memory_; gfx::Size shared_memory_size_; }; diff --git a/cc/resources/texture_mailbox_deleter.cc b/cc/resources/texture_mailbox_deleter.cc index cf7b3b61..542b95e 100644 --- a/cc/resources/texture_mailbox_deleter.cc +++ b/cc/resources/texture_mailbox_deleter.cc @@ -17,7 +17,7 @@ namespace cc { static void DeleteTextureOnImplThread( const scoped_refptr<ContextProvider>& context_provider, unsigned texture_id, - unsigned sync_point, + uint32 sync_point, bool is_lost) { if (sync_point) context_provider->ContextGL()->WaitSyncPointCHROMIUM(sync_point); diff --git a/cc/resources/texture_mailbox_deleter.h b/cc/resources/texture_mailbox_deleter.h index 9b6d771..add1549 100644 --- a/cc/resources/texture_mailbox_deleter.h +++ b/cc/resources/texture_mailbox_deleter.h @@ -32,10 +32,9 @@ class CC_EXPORT TextureMailboxDeleter { private: // Runs the |impl_callback| to delete the texture and removes the callback // from the |impl_callbacks_| list. - void RunDeleteTextureOnImplThread( - SingleReleaseCallback* impl_callback, - unsigned sync_point, - bool is_lost); + void RunDeleteTextureOnImplThread(SingleReleaseCallback* impl_callback, + uint32 sync_point, + bool is_lost); ScopedPtrVector<SingleReleaseCallback> impl_callbacks_; base::WeakPtrFactory<TextureMailboxDeleter> weak_ptr_factory_; diff --git a/cc/resources/transferable_resource.cc b/cc/resources/transferable_resource.cc index 62f1bdb..e7e9e24 100644 --- a/cc/resources/transferable_resource.cc +++ b/cc/resources/transferable_resource.cc @@ -10,9 +10,7 @@ namespace cc { TransferableResource::TransferableResource() : id(0), - sync_point(0), format(RGBA_8888), - target(0), filter(0), is_software(false) {} @@ -22,7 +20,7 @@ TransferableResource::~TransferableResource() { ReturnedResource TransferableResource::ToReturnedResource() const { ReturnedResource returned; returned.id = id; - returned.sync_point = sync_point; + returned.sync_point = mailbox_holder.sync_point; returned.count = 1; return returned; } diff --git a/cc/resources/transferable_resource.h b/cc/resources/transferable_resource.h index 5c93d1c..8ca9ffa 100644 --- a/cc/resources/transferable_resource.h +++ b/cc/resources/transferable_resource.h @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "cc/base/cc_export.h" #include "cc/resources/resource_format.h" -#include "gpu/command_buffer/common/mailbox.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "ui/gfx/size.h" namespace cc { @@ -29,12 +29,10 @@ struct CC_EXPORT TransferableResource { ReturnedResourceArray* output); unsigned id; - unsigned sync_point; ResourceFormat format; - uint32 target; uint32 filter; gfx::Size size; - gpu::Mailbox mailbox; + gpu::MailboxHolder mailbox_holder; bool is_software; }; diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc index 4abeab1..0c2892d 100644 --- a/cc/resources/video_resource_updater.cc +++ b/cc/resources/video_resource_updater.cc @@ -313,7 +313,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( }; external_resources.mailboxes.push_back( - TextureMailbox(plane_resources[i].mailbox)); + TextureMailbox(plane_resources[i].mailbox, GL_TEXTURE_2D, 0)); external_resources.release_callbacks.push_back( base::Bind(&RecycleResource, AsWeakPtr(), recycle_data)); } @@ -323,9 +323,9 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( } static void ReturnTexture(const scoped_refptr<media::VideoFrame>& frame, - unsigned sync_point, + uint32 sync_point, bool lost_resource) { - frame->texture_mailbox()->Resync(sync_point); + frame->mailbox_holder()->sync_point = sync_point; } VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( @@ -339,8 +339,9 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( if (!context_provider_) return VideoFrameExternalResources(); + gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); VideoFrameExternalResources external_resources; - switch (video_frame->texture_target()) { + switch (mailbox_holder->texture_target) { case GL_TEXTURE_2D: external_resources.type = VideoFrameExternalResources::RGB_RESOURCE; break; @@ -356,13 +357,10 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( return VideoFrameExternalResources(); } - media::VideoFrame::MailboxHolder* mailbox_holder = - video_frame->texture_mailbox(); - external_resources.mailboxes.push_back( - TextureMailbox(mailbox_holder->mailbox(), - video_frame->texture_target(), - mailbox_holder->sync_point())); + TextureMailbox(mailbox_holder->mailbox, + mailbox_holder->texture_target, + mailbox_holder->sync_point)); external_resources.release_callbacks.push_back( base::Bind(&ReturnTexture, video_frame)); return external_resources; @@ -372,7 +370,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( void VideoResourceUpdater::RecycleResource( base::WeakPtr<VideoResourceUpdater> updater, RecycleResourceData data, - unsigned sync_point, + uint32 sync_point, bool lost_resource) { if (!updater.get()) { // Resource was already deleted. diff --git a/cc/resources/video_resource_updater.h b/cc/resources/video_resource_updater.h index 2a27739..27a108b 100644 --- a/cc/resources/video_resource_updater.h +++ b/cc/resources/video_resource_updater.h @@ -104,7 +104,7 @@ class CC_EXPORT VideoResourceUpdater }; static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater, RecycleResourceData data, - unsigned sync_point, + uint32 sync_point, bool lost_resource); ContextProvider* context_provider_; diff --git a/cc/test/fake_delegated_renderer_layer_impl.cc b/cc/test/fake_delegated_renderer_layer_impl.cc index 4057736..8f4c104 100644 --- a/cc/test/fake_delegated_renderer_layer_impl.cc +++ b/cc/test/fake_delegated_renderer_layer_impl.cc @@ -30,7 +30,8 @@ static ResourceProvider::ResourceId AddResourceToFrame( ResourceProvider::ResourceId resource_id) { TransferableResource resource; resource.id = resource_id; - resource.target = resource_provider->TargetForTesting(resource_id); + resource.mailbox_holder.texture_target = + resource_provider->TargetForTesting(resource_id); frame->resource_list.push_back(resource); return resource_id; } diff --git a/cc/test/layer_tree_pixel_test.cc b/cc/test/layer_tree_pixel_test.cc index 806b877..379808e 100644 --- a/cc/test/layer_tree_pixel_test.cc +++ b/cc/test/layer_tree_pixel_test.cc @@ -247,7 +247,7 @@ scoped_ptr<SkBitmap> LayerTreePixelTest::CopyTextureMailboxToBitmap( gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - gl->ConsumeTextureCHROMIUM(texture_mailbox.target(), texture_mailbox.data()); + gl->ConsumeTextureCHROMIUM(texture_mailbox.target(), texture_mailbox.name()); gl->BindTexture(GL_TEXTURE_2D, 0); GLuint fbo = 0; @@ -369,7 +369,7 @@ void LayerTreePixelTest::CopyBitmapToTextureMailboxAsTexture( gl->BindTexture(GL_TEXTURE_2D, 0); uint32 sync_point = gl->InsertSyncPointCHROMIUM(); - *texture_mailbox = TextureMailbox(mailbox, sync_point); + *texture_mailbox = TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point); *release_callback = SingleReleaseCallback::Create( base::Bind(&LayerTreePixelTest::ReleaseTextureMailbox, base::Unretained(this), diff --git a/cc/trees/layer_tree_host_perftest.cc b/cc/trees/layer_tree_host_perftest.cc index 1bfe1c4..a02c8f2 100644 --- a/cc/trees/layer_tree_host_perftest.cc +++ b/cc/trees/layer_tree_host_perftest.cc @@ -246,7 +246,7 @@ TEST_F(ScrollingLayerTreePerfTest, LongScrollablePageThreadedImplSide) { RunTestWithImplSidePainting(); } -static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} +static void EmptyReleaseCallback(uint32 sync_point, bool lost_resource) {} // Simulates main-thread scrolling on each frame. class BrowserCompositorInvalidateLayerTreePerfTest @@ -274,7 +274,7 @@ class BrowserCompositorInvalidateLayerTreePerfTest reinterpret_cast<const int8*>(name_stream.str().c_str())); scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( base::Bind(&EmptyReleaseCallback)); - TextureMailbox mailbox(gpu_mailbox, next_sync_point_); + TextureMailbox mailbox(gpu_mailbox, GL_TEXTURE_2D, next_sync_point_); next_sync_point_++; tab_contents_->SetTextureMailbox(mailbox, callback.Pass()); diff --git a/cc/trees/layer_tree_host_unittest_context.cc b/cc/trees/layer_tree_host_unittest_context.cc index 5aa37fe..2d203c2 100644 --- a/cc/trees/layer_tree_host_unittest_context.cc +++ b/cc/trees/layer_tree_host_unittest_context.cc @@ -1003,7 +1003,7 @@ class LayerTreeHostContextTestDontUseLostResources texture->SetAnchorPoint(gfx::PointF()); texture->SetIsDrawable(true); texture->SetTextureMailbox( - TextureMailbox(mailbox, sync_point), + TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), SingleReleaseCallback::Create( base::Bind(&LayerTreeHostContextTestDontUseLostResources:: EmptyReleaseCallback))); @@ -1044,30 +1044,24 @@ class LayerTreeHostContextTestDontUseLostResources color_video_frame_ = VideoFrame::CreateColorFrame( gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta()); - hw_video_frame_ = VideoFrame::WrapNativeTexture( - make_scoped_ptr(new VideoFrame::MailboxHolder( - mailbox, - sync_point, - VideoFrame::MailboxHolder::TextureNoLongerNeededCallback())), - GL_TEXTURE_2D, - gfx::Size(4, 4), - gfx::Rect(0, 0, 4, 4), - gfx::Size(4, 4), - base::TimeDelta(), - VideoFrame::ReadPixelsCB(), - base::Closure()); - scaled_hw_video_frame_ = VideoFrame::WrapNativeTexture( - make_scoped_ptr(new VideoFrame::MailboxHolder( - mailbox, - sync_point, - VideoFrame::MailboxHolder::TextureNoLongerNeededCallback())), - GL_TEXTURE_2D, - gfx::Size(4, 4), - gfx::Rect(0, 0, 3, 2), - gfx::Size(4, 4), - base::TimeDelta(), - VideoFrame::ReadPixelsCB(), - base::Closure()); + hw_video_frame_ = + VideoFrame::WrapNativeTexture(make_scoped_ptr(new gpu::MailboxHolder( + mailbox, GL_TEXTURE_2D, sync_point)), + media::VideoFrame::ReleaseMailboxCB(), + gfx::Size(4, 4), + gfx::Rect(0, 0, 4, 4), + gfx::Size(4, 4), + base::TimeDelta(), + VideoFrame::ReadPixelsCB()); + scaled_hw_video_frame_ = + VideoFrame::WrapNativeTexture(make_scoped_ptr(new gpu::MailboxHolder( + mailbox, GL_TEXTURE_2D, sync_point)), + media::VideoFrame::ReleaseMailboxCB(), + gfx::Size(4, 4), + gfx::Rect(0, 0, 3, 2), + gfx::Size(4, 4), + base::TimeDelta(), + VideoFrame::ReadPixelsCB()); color_frame_provider_.set_frame(color_video_frame_); hw_frame_provider_.set_frame(hw_video_frame_); diff --git a/cc/trees/layer_tree_host_unittest_copyrequest.cc b/cc/trees/layer_tree_host_unittest_copyrequest.cc index 2156c64..23d3347 100644 --- a/cc/trees/layer_tree_host_unittest_copyrequest.cc +++ b/cc/trees/layer_tree_host_unittest_copyrequest.cc @@ -807,7 +807,8 @@ class LayerTreeHostCopyRequestTestProvideTexture gpu::Mailbox mailbox; gl->GenMailboxCHROMIUM(mailbox.name); sync_point_ = gl->InsertSyncPointCHROMIUM(); - request->SetTextureMailbox(TextureMailbox(mailbox, sync_point_)); + request->SetTextureMailbox( + TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point_)); EXPECT_TRUE(request->has_texture_mailbox()); copy_layer_->RequestCopyOfOutput(request.Pass()); diff --git a/cc/trees/layer_tree_host_unittest_delegated.cc b/cc/trees/layer_tree_host_unittest_delegated.cc index b5c400c..ee506c6 100644 --- a/cc/trees/layer_tree_host_unittest_delegated.cc +++ b/cc/trees/layer_tree_host_unittest_delegated.cc @@ -135,7 +135,7 @@ class LayerTreeHostDelegatedTest : public LayerTreeTest { ResourceProvider::ResourceId resource_id) { TransferableResource resource; resource.id = resource_id; - resource.target = GL_TEXTURE_2D; + resource.mailbox_holder.texture_target = GL_TEXTURE_2D; frame->resource_list.push_back(resource); } diff --git a/content/browser/compositor/owned_mailbox.cc b/content/browser/compositor/owned_mailbox.cc index 06a60e4..9c7b378 100644 --- a/content/browser/compositor/owned_mailbox.cc +++ b/content/browser/compositor/owned_mailbox.cc @@ -11,9 +11,9 @@ namespace content { OwnedMailbox::OwnedMailbox(GLHelper* gl_helper) - : texture_id_(0), sync_point_(0), gl_helper_(gl_helper) { + : texture_id_(0), gl_helper_(gl_helper) { texture_id_ = gl_helper_->CreateTexture(); - mailbox_ = gl_helper_->ProduceMailboxFromTexture(texture_id_, &sync_point_); + mailbox_holder_ = gl_helper_->ProduceMailboxHolderFromTexture(texture_id_); ImageTransportFactory::GetInstance()->AddObserver(this); } @@ -24,16 +24,15 @@ OwnedMailbox::~OwnedMailbox() { void OwnedMailbox::UpdateSyncPoint(uint32 sync_point) { if (sync_point) - sync_point_ = sync_point; + mailbox_holder_.sync_point = sync_point; } void OwnedMailbox::Destroy() { ImageTransportFactory::GetInstance()->RemoveObserver(this); - gl_helper_->WaitSyncPoint(sync_point_); + gl_helper_->WaitSyncPoint(mailbox_holder_.sync_point); gl_helper_->DeleteTexture(texture_id_); texture_id_ = 0; - mailbox_ = gpu::Mailbox(); - sync_point_ = 0; + mailbox_holder_ = gpu::MailboxHolder(); gl_helper_ = NULL; } diff --git a/content/browser/compositor/owned_mailbox.h b/content/browser/compositor/owned_mailbox.h index a574ae4..e3adcbd 100644 --- a/content/browser/compositor/owned_mailbox.h +++ b/content/browser/compositor/owned_mailbox.h @@ -4,7 +4,7 @@ #include "base/memory/ref_counted.h" #include "content/browser/compositor/image_transport_factory.h" -#include "gpu/command_buffer/common/mailbox.h" +#include "gpu/command_buffer/common/mailbox_holder.h" namespace content { @@ -18,10 +18,10 @@ class OwnedMailbox : public base::RefCounted<OwnedMailbox>, public: explicit OwnedMailbox(GLHelper* gl_helper); + const gpu::Mailbox& mailbox() const { return mailbox_holder_.mailbox; } uint32 texture_id() const { return texture_id_; } - uint32 sync_point() const { return sync_point_; } - const gpu::Mailbox& mailbox() const { return mailbox_; } - + uint32 target() const { return mailbox_holder_.texture_target; } + uint32 sync_point() const { return mailbox_holder_.sync_point; } void UpdateSyncPoint(uint32 sync_point); void Destroy(); @@ -35,8 +35,7 @@ class OwnedMailbox : public base::RefCounted<OwnedMailbox>, friend class base::RefCounted<OwnedMailbox>; uint32 texture_id_; - gpu::Mailbox mailbox_; - uint32 sync_point_; + gpu::MailboxHolder mailbox_holder_; GLHelper* gl_helper_; }; diff --git a/content/browser/renderer_host/media/desktop_capture_device_aura.cc b/content/browser/renderer_host/media/desktop_capture_device_aura.cc index 03e9c89..f16d564 100644 --- a/content/browser/renderer_host/media/desktop_capture_device_aura.cc +++ b/content/browser/renderer_host/media/desktop_capture_device_aura.cc @@ -343,9 +343,15 @@ void DesktopVideoCaptureMachine::DidCopyOutput( gfx::Point cursor_position_in_frame = UpdateCursorState(region_in_frame); yuv_readback_pipeline_->ReadbackYUV( - texture_mailbox.name(), texture_mailbox.sync_point(), video_frame.get(), - base::Bind(&CopyOutputFinishedForVideo, start_time, capture_frame_cb, - video_frame, scaled_cursor_bitmap_, cursor_position_in_frame, + texture_mailbox.mailbox(), + texture_mailbox.sync_point(), + video_frame.get(), + base::Bind(&CopyOutputFinishedForVideo, + start_time, + capture_frame_cb, + video_frame, + scaled_cursor_bitmap_, + cursor_position_in_frame, base::Passed(&release_callback))); } diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index e90ab1c..2b78167 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -1406,7 +1406,7 @@ void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( ignore_result(scoped_callback_runner.Release()); gl_helper->CropScaleReadbackAndCleanMailbox( - texture_mailbox.name(), + texture_mailbox.mailbox(), texture_mailbox.sync_point(), result->size(), gfx::Rect(result->size()), diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index f0fe263..27f54ec 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -100,7 +100,8 @@ namespace content { namespace { void MailboxReleaseCallback(scoped_ptr<base::SharedMemory> shared_memory, - unsigned sync_point, bool lost_resource) { + uint32 sync_point, + bool lost_resource) { // NOTE: shared_memory will get released when we go out of scope. } @@ -1110,8 +1111,10 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurfaceToVideoFrame( ConvertRectToPixel(current_device_scale_factor_, src_subrect); request->set_area(src_subrect_in_pixel); if (subscriber_texture.get()) { - request->SetTextureMailbox(cc::TextureMailbox( - subscriber_texture->mailbox(), subscriber_texture->sync_point())); + request->SetTextureMailbox( + cc::TextureMailbox(subscriber_texture->mailbox(), + subscriber_texture->target(), + subscriber_texture->sync_point())); } RequestCopyOfOutput(request.Pass()); } @@ -1865,7 +1868,7 @@ void RenderWidgetHostViewAura::PrepareTextureCopyOutputResult( ignore_result(scoped_callback_runner.Release()); gl_helper->CropScaleReadbackAndCleanMailbox( - texture_mailbox.name(), + texture_mailbox.mailbox(), texture_mailbox.sync_point(), result->size(), gfx::Rect(result->size()), @@ -2065,11 +2068,10 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResultForVideo( callback, subscriber_texture, base::Passed(&release_callback)); - yuv_readback_pipeline->ReadbackYUV( - texture_mailbox.name(), - texture_mailbox.sync_point(), - video_frame.get(), - finished_callback); + yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), + texture_mailbox.sync_point(), + video_frame.get(), + finished_callback); } void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { diff --git a/content/browser/renderer_host/software_frame_manager.cc b/content/browser/renderer_host/software_frame_manager.cc index cff9434..cb4efb6 100644 --- a/content/browser/renderer_host/software_frame_manager.cc +++ b/content/browser/renderer_host/software_frame_manager.cc @@ -13,7 +13,7 @@ namespace { void ReleaseMailbox(scoped_refptr<content::SoftwareFrame> frame, - unsigned sync_point, + uint32 sync_point, bool lost_resource) {} } // namespace diff --git a/content/common/cc_messages.h b/content/common/cc_messages.h index d1a9129..6b58465 100644 --- a/content/common/cc_messages.h +++ b/content/common/cc_messages.h @@ -224,12 +224,10 @@ IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(cc::TransferableResource) IPC_STRUCT_TRAITS_MEMBER(id) - IPC_STRUCT_TRAITS_MEMBER(sync_point) IPC_STRUCT_TRAITS_MEMBER(format) - IPC_STRUCT_TRAITS_MEMBER(target) IPC_STRUCT_TRAITS_MEMBER(filter) IPC_STRUCT_TRAITS_MEMBER(size) - IPC_STRUCT_TRAITS_MEMBER(mailbox) + IPC_STRUCT_TRAITS_MEMBER(mailbox_holder) IPC_STRUCT_TRAITS_MEMBER(is_software) IPC_STRUCT_TRAITS_END() diff --git a/content/common/cc_messages_unittest.cc b/content/common/cc_messages_unittest.cc index eaa5a58..11b9ea2 100644 --- a/content/common/cc_messages_unittest.cc +++ b/content/common/cc_messages_unittest.cc @@ -198,13 +198,15 @@ class CCMessagesTest : public testing::Test { void Compare(const TransferableResource& a, const TransferableResource& b) { EXPECT_EQ(a.id, b.id); - EXPECT_EQ(a.sync_point, b.sync_point); EXPECT_EQ(a.format, b.format); - EXPECT_EQ(a.target, b.target); EXPECT_EQ(a.filter, b.filter); EXPECT_EQ(a.size.ToString(), b.size.ToString()); - for (size_t i = 0; i < arraysize(a.mailbox.name); ++i) - EXPECT_EQ(a.mailbox.name[i], b.mailbox.name[i]); + for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) { + EXPECT_EQ(a.mailbox_holder.mailbox.name[i], + b.mailbox_holder.mailbox.name[i]); + } + EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target); + EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point); } }; @@ -655,21 +657,21 @@ TEST_F(CCMessagesTest, Resources) { TransferableResource arbitrary_resource1; arbitrary_resource1.id = 2178312; - arbitrary_resource1.sync_point = arbitrary_uint1; arbitrary_resource1.format = cc::RGBA_8888; - arbitrary_resource1.target = GL_TEXTURE_2D; arbitrary_resource1.filter = 53; arbitrary_resource1.size = gfx::Size(37189, 123123); - arbitrary_resource1.mailbox.SetName(arbitrary_mailbox1); + arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1); + arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D; + arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1; TransferableResource arbitrary_resource2; arbitrary_resource2.id = 789132; - arbitrary_resource2.sync_point = arbitrary_uint2; arbitrary_resource2.format = cc::RGBA_4444; - arbitrary_resource2.target = GL_TEXTURE_EXTERNAL_OES; arbitrary_resource2.filter = 47; arbitrary_resource2.size = gfx::Size(89123, 23789); - arbitrary_resource2.mailbox.SetName(arbitrary_mailbox2); + arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2); + arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES; + arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2; scoped_ptr<RenderPass> renderpass_in = RenderPass::Create(); renderpass_in->SetNew( diff --git a/content/common/gpu/client/gl_helper.cc b/content/common/gpu/client/gl_helper.cc index 3b7e23a..13d2913 100644 --- a/content/common/gpu/client/gl_helper.cc +++ b/content/common/gpu/client/gl_helper.cc @@ -19,6 +19,7 @@ #include "gpu/GLES2/gl2extchromium.h" #include "gpu/command_buffer/client/context_support.h" #include "gpu/command_buffer/common/mailbox.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "media/base/video_frame.h" #include "media/base/video_util.h" #include "third_party/skia/include/core/SkRegion.h" @@ -670,18 +671,15 @@ void GLHelper::WaitSyncPoint(uint32 sync_point) { gl_->WaitSyncPointCHROMIUM(sync_point); } -gpu::Mailbox GLHelper::ProduceMailboxFromTexture(GLuint texture_id, - uint32* sync_point) { +gpu::MailboxHolder GLHelper::ProduceMailboxHolderFromTexture( + GLuint texture_id) { gpu::Mailbox mailbox; gl_->GenMailboxCHROMIUM(mailbox.name); - if (mailbox.IsZero()) { - *sync_point = 0; - return mailbox; - } + if (mailbox.IsZero()) + return gpu::MailboxHolder(); content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture_id); gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); - *sync_point = InsertSyncPoint(); - return mailbox; + return gpu::MailboxHolder(mailbox, GL_TEXTURE_2D, InsertSyncPoint()); } GLuint GLHelper::ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, diff --git a/content/common/gpu/client/gl_helper.h b/content/common/gpu/client/gl_helper.h index 90e9b71..7b53268 100644 --- a/content/common/gpu/client/gl_helper.h +++ b/content/common/gpu/client/gl_helper.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "content/common/content_export.h" #include "gpu/command_buffer/client/gles2_interface.h" +#include "gpu/command_buffer/common/mailbox_holder.h" namespace gfx { class Rect; @@ -245,11 +246,11 @@ class CONTENT_EXPORT GLHelper { // Wait for the sync point before executing further GL commands. void WaitSyncPoint(uint32 sync_point); - // Creates a mailbox that is attached to the given texture id, and a sync - // point to wait on before using the mailbox. Returns an empty mailbox on - // failure. + // Creates a mailbox holder that is attached to the given texture id, with a + // sync point to wait on before using the mailbox. Returns a holder with an + // empty mailbox on failure. // Note the texture is assumed to be GL_TEXTURE_2D. - gpu::Mailbox ProduceMailboxFromTexture(GLuint texture_id, uint32* sync_point); + gpu::MailboxHolder ProduceMailboxHolderFromTexture(GLuint texture_id); // Creates a texture and consumes a mailbox into it. Returns 0 on failure. // Note the mailbox is assumed to be GL_TEXTURE_2D. diff --git a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc index 89916e2..20d89d9 100644 --- a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc +++ b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc @@ -141,10 +141,9 @@ void BrowserPluginCompositingHelper::CheckSizeAndAdjustLayerProperties( background_layer_->SetIsDrawable(false); } -void BrowserPluginCompositingHelper::MailboxReleased( - SwapBuffersInfo mailbox, - unsigned sync_point, - bool lost_resource) { +void BrowserPluginCompositingHelper::MailboxReleased(SwapBuffersInfo mailbox, + uint32 sync_point, + bool lost_resource) { if (mailbox.type == SOFTWARE_COMPOSITOR_FRAME) { delete mailbox.shared_memory; mailbox.shared_memory = NULL; @@ -229,7 +228,7 @@ void BrowserPluginCompositingHelper::OnContainerDestroy() { void BrowserPluginCompositingHelper::OnBuffersSwappedPrivate( const SwapBuffersInfo& mailbox, - unsigned sync_point, + uint32 sync_point, float device_scale_factor) { DCHECK(!delegated_layer_.get()); // If these mismatch, we are either just starting up, GPU process crashed or @@ -292,10 +291,12 @@ void BrowserPluginCompositingHelper::OnBuffersSwappedPrivate( base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, scoped_refptr<BrowserPluginCompositingHelper>(this), mailbox)).Pass(); - if (is_software_frame) + if (is_software_frame) { texture_mailbox = cc::TextureMailbox(mailbox.shared_memory, mailbox.size); - else - texture_mailbox = cc::TextureMailbox(mailbox.name, sync_point); + } else { + texture_mailbox = + cc::TextureMailbox(mailbox.name, GL_TEXTURE_2D, sync_point); + } } texture_layer_->SetFlipped(!is_software_frame); diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc index 8cb3982..6134b9a 100644 --- a/content/renderer/media/android/webmediaplayer_android.cc +++ b/content/renderer/media/android/webmediaplayer_android.cc @@ -23,6 +23,7 @@ #include "content/renderer/render_thread_impl.h" #include "gpu/GLES2/gl2extchromium.h" #include "gpu/command_buffer/client/gles2_interface.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "grit/content_resources.h" #include "media/base/android/media_player_android.h" #include "media/base/bind_to_current_loop.h" @@ -63,12 +64,12 @@ namespace content { void WebMediaPlayerAndroid::OnReleaseRemotePlaybackTexture( const scoped_refptr<base::MessageLoopProxy>& main_loop, const base::WeakPtr<WebMediaPlayerAndroid>& player, - uint32 sync_point) { + const gpu::MailboxHolder* mailbox_holder) { main_loop->PostTask( FROM_HERE, base::Bind(&WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture, player, - sync_point)); + mailbox_holder->sync_point)); } WebMediaPlayerAndroid::WebMediaPlayerAndroid( @@ -934,19 +935,16 @@ void WebMediaPlayerAndroid::DrawRemotePlaybackIcon() { GLuint texture_mailbox_sync_point = gl->InsertSyncPointCHROMIUM(); scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( - make_scoped_ptr(new VideoFrame::MailboxHolder( - texture_mailbox, - texture_mailbox_sync_point, - base::Bind(&WebMediaPlayerAndroid::OnReleaseRemotePlaybackTexture, - main_loop_, - weak_factory_.GetWeakPtr()))), - texture_target, + make_scoped_ptr(new gpu::MailboxHolder( + texture_mailbox, texture_target, texture_mailbox_sync_point)), + base::Bind(&WebMediaPlayerAndroid::OnReleaseRemotePlaybackTexture, + main_loop_, + weak_factory_.GetWeakPtr()), canvas_size /* coded_size */, gfx::Rect(canvas_size) /* visible_rect */, canvas_size /* natural_size */, base::TimeDelta() /* timestamp */, - VideoFrame::ReadPixelsCB(), - base::Closure() /* no_longer_needed_cb */); + VideoFrame::ReadPixelsCB()); SetCurrentFrameInternal(new_frame); } @@ -966,17 +964,15 @@ void WebMediaPlayerAndroid::ReallocateVideoFrame() { #endif // defined(VIDEO_HOLE) } else if (!is_remote_ && texture_id_) { scoped_refptr<VideoFrame> new_frame = VideoFrame::WrapNativeTexture( - make_scoped_ptr(new VideoFrame::MailboxHolder( - texture_mailbox_, - texture_mailbox_sync_point_, - VideoFrame::MailboxHolder::TextureNoLongerNeededCallback())), - kGLTextureExternalOES, + make_scoped_ptr(new gpu::MailboxHolder(texture_mailbox_, + kGLTextureExternalOES, + texture_mailbox_sync_point_)), + media::VideoFrame::ReleaseMailboxCB(), natural_size_, gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), - VideoFrame::ReadPixelsCB(), - base::Closure()); + VideoFrame::ReadPixelsCB()); SetCurrentFrameInternal(new_frame); } } diff --git a/content/renderer/media/android/webmediaplayer_android.h b/content/renderer/media/android/webmediaplayer_android.h index 3cdc6ac..5e13683 100644 --- a/content/renderer/media/android/webmediaplayer_android.h +++ b/content/renderer/media/android/webmediaplayer_android.h @@ -31,14 +31,18 @@ #include "third_party/WebKit/public/platform/WebURL.h" #include "ui/gfx/rect_f.h" -namespace media { -class MediaLog; -} - namespace blink { class WebFrame; } +namespace gpu { +struct MailboxHolder; +} + +namespace media { +class MediaLog; +} + namespace webkit { class WebLayerImpl; } @@ -223,7 +227,7 @@ class WebMediaPlayerAndroid static void OnReleaseRemotePlaybackTexture( const scoped_refptr<base::MessageLoopProxy>& main_loop, const base::WeakPtr<WebMediaPlayerAndroid>& player, - uint32 sync_point); + const gpu::MailboxHolder* mailbox_holder); protected: // Helper method to update the playing state. diff --git a/content/renderer/media/rtc_video_decoder.cc b/content/renderer/media/rtc_video_decoder.cc index dd043c2..e4a4237 100644 --- a/content/renderer/media/rtc_video_decoder.cc +++ b/content/renderer/media/rtc_video_decoder.cc @@ -14,6 +14,7 @@ #include "base/task_runner_util.h" #include "content/child/child_thread.h" #include "content/renderer/media/native_handle_impl.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "media/base/bind_to_current_loop.h" #include "media/filters/gpu_video_accelerator_factories.h" #include "third_party/webrtc/common_video/interface/texture_video_frame.h" @@ -420,14 +421,11 @@ scoped_refptr<media::VideoFrame> RTCVideoDecoder::CreateVideoFrame( base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue( base::checked_cast<uint64_t>(timestamp) * 1000 / 90); return media::VideoFrame::WrapNativeTexture( - make_scoped_ptr(new media::VideoFrame::MailboxHolder( - pb.texture_mailbox(), - 0, // sync_point - media::BindToCurrentLoop( - base::Bind(&RTCVideoDecoder::ReusePictureBuffer, - weak_this_, - picture.picture_buffer_id())))), - decoder_texture_target_, + make_scoped_ptr(new gpu::MailboxHolder( + pb.texture_mailbox(), decoder_texture_target_, 0)), + media::BindToCurrentLoop(base::Bind(&RTCVideoDecoder::ReusePictureBuffer, + weak_this_, + picture.picture_buffer_id())), pb.size(), visible_rect, natural_size, @@ -435,8 +433,7 @@ scoped_refptr<media::VideoFrame> RTCVideoDecoder::CreateVideoFrame( base::Bind(&media::GpuVideoAcceleratorFactories::ReadPixels, factories_, pb.texture_id(), - natural_size), - base::Closure()); + natural_size)); } void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { @@ -640,8 +637,9 @@ void RTCVideoDecoder::ResetInternal() { vda_->Reset(); } -void RTCVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, - uint32 sync_point) { +void RTCVideoDecoder::ReusePictureBuffer( + int64 picture_buffer_id, + const gpu::MailboxHolder* mailbox_holder) { DCHECK(vda_task_runner_->BelongsToCurrentThread()); DVLOG(3) << "ReusePictureBuffer. id=" << picture_buffer_id; @@ -665,7 +663,7 @@ void RTCVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, return; } - factories_->WaitSyncPoint(sync_point); + factories_->WaitSyncPoint(mailbox_holder->sync_point); vda_->ReusePictureBuffer(picture_buffer_id); } diff --git a/content/renderer/media/rtc_video_decoder.h b/content/renderer/media/rtc_video_decoder.h index 0d99a4c..2db49a4 100644 --- a/content/renderer/media/rtc_video_decoder.h +++ b/content/renderer/media/rtc_video_decoder.h @@ -28,6 +28,10 @@ namespace base { class MessageLoopProxy; }; +namespace gpu { +struct MailboxHolder; +} + namespace media { class DecoderBuffer; class GpuVideoAcceleratorFactories; @@ -156,7 +160,8 @@ class CONTENT_EXPORT RTCVideoDecoder void ResetInternal(); // Tells VDA that a picture buffer can be recycled. - void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); + void ReusePictureBuffer(int64 picture_buffer_id, + const gpu::MailboxHolder* mailbox_holder); void DestroyTextures(); void DestroyVDA(); diff --git a/content/renderer/media/webmediaplayer_impl.cc b/content/renderer/media/webmediaplayer_impl.cc index d5c3a2a..a1fc51e 100644 --- a/content/renderer/media/webmediaplayer_impl.cc +++ b/content/renderer/media/webmediaplayer_impl.cc @@ -34,6 +34,7 @@ #include "content/renderer/pepper/pepper_webplugin_impl.h" #include "content/renderer/render_thread_impl.h" #include "gpu/GLES2/gl2extchromium.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "media/audio/null_audio_sink.h" #include "media/base/bind_to_current_loop.h" #include "media/base/filter_collection.h" @@ -629,7 +630,9 @@ bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( return false; if (video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) return false; - if (video_frame->texture_target() != GL_TEXTURE_2D) + + gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); + if (mailbox_holder->texture_target != GL_TEXTURE_2D) return false; // Since this method changes which texture is bound to the TEXTURE_2D target, @@ -644,15 +647,12 @@ bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( DCHECK_EQ(static_cast<GLuint>(bound_texture), texture); } - media::VideoFrame::MailboxHolder* mailbox_holder = - video_frame->texture_mailbox(); - uint32 source_texture = web_graphics_context->createTexture(); - web_graphics_context->waitSyncPoint(mailbox_holder->sync_point()); + web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); web_graphics_context->bindTexture(GL_TEXTURE_2D, source_texture); web_graphics_context->consumeTextureCHROMIUM(GL_TEXTURE_2D, - mailbox_holder->mailbox().name); + mailbox_holder->mailbox.name); // The video is stored in a unmultiplied format, so premultiply // if necessary. diff --git a/content/renderer/pepper/pepper_graphics_2d_host.cc b/content/renderer/pepper/pepper_graphics_2d_host.cc index e2003e8..5bed73c 100644 --- a/content/renderer/pepper/pepper_graphics_2d_host.cc +++ b/content/renderer/pepper/pepper_graphics_2d_host.cc @@ -620,7 +620,7 @@ int32_t PepperGraphics2DHost::OnHostMsgReadImageData( } void ReleaseCallback(scoped_ptr<base::SharedMemory> memory, - unsigned sync_point, + uint32 sync_point, bool lost_resource) {} bool PepperGraphics2DHost::PrepareTextureMailbox( diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc index 3ef54aa..b86efc4 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc @@ -109,6 +109,7 @@ #include "third_party/WebKit/public/web/WebSecurityOrigin.h" #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" #include "third_party/WebKit/public/web/WebView.h" +#include "third_party/khronos/GLES2/gl2.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkRect.h" #include "ui/gfx/image/image_skia.h" @@ -1869,7 +1870,7 @@ bool PepperPluginInstanceImpl::PrintPDFOutput(PP_Resource print_output, #endif } -static void IgnoreCallback(unsigned, bool) {} +static void IgnoreCallback(uint32, bool) {} void PepperPluginInstanceImpl::UpdateLayer() { if (!container_) @@ -1907,7 +1908,7 @@ void PepperPluginInstanceImpl::UpdateLayer() { texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); opaque = bound_graphics_3d_->IsOpaque(); texture_layer_->SetTextureMailbox( - cc::TextureMailbox(mailbox, 0), + cc::TextureMailbox(mailbox, GL_TEXTURE_2D, 0), cc::SingleReleaseCallback::Create(base::Bind(&IgnoreCallback))); plugin_layer = texture_layer_; } else { diff --git a/gpu/command_buffer/common/mailbox_holder.cc b/gpu/command_buffer/common/mailbox_holder.cc new file mode 100644 index 0000000..a8cb6fb --- /dev/null +++ b/gpu/command_buffer/common/mailbox_holder.cc @@ -0,0 +1,18 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/common/mailbox_holder.h" + +namespace gpu { + +MailboxHolder::MailboxHolder() : texture_target(0), sync_point(0) {} + +MailboxHolder::MailboxHolder(const Mailbox& mailbox, + uint32 texture_target, + uint32 sync_point) + : mailbox(mailbox), + texture_target(texture_target), + sync_point(sync_point) {} + +} // namespace gpu diff --git a/gpu/command_buffer/common/mailbox_holder.h b/gpu/command_buffer/common/mailbox_holder.h new file mode 100644 index 0000000..a17d8d3 --- /dev/null +++ b/gpu/command_buffer/common/mailbox_holder.h @@ -0,0 +1,28 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_MAILBOX_HOLDER_H_ +#define GPU_COMMAND_BUFFER_MAILBOX_HOLDER_H_ + +#include <string.h> + +#include "gpu/command_buffer/common/mailbox.h" +#include "gpu/command_buffer/common/types.h" +#include "gpu/gpu_export.h" + +namespace gpu { + +struct GPU_EXPORT MailboxHolder { + MailboxHolder(); + MailboxHolder(const gpu::Mailbox& mailbox, + uint32 texture_target, + uint32 sync_point); + gpu::Mailbox mailbox; + uint32 texture_target; + uint32 sync_point; +}; + +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_MAILBOX_HOLDER_H_ diff --git a/gpu/command_buffer_common.gypi b/gpu/command_buffer_common.gypi index 87eeb5b..b983119b 100644 --- a/gpu/command_buffer_common.gypi +++ b/gpu/command_buffer_common.gypi @@ -11,22 +11,24 @@ 'command_buffer/common/buffer.h', 'command_buffer/common/capabilities.cc', 'command_buffer/common/capabilities.h', - 'command_buffer/common/cmd_buffer_common.h', 'command_buffer/common/cmd_buffer_common.cc', + 'command_buffer/common/cmd_buffer_common.h', 'command_buffer/common/command_buffer.h', 'command_buffer/common/constants.h', 'command_buffer/common/debug_marker_manager.cc', 'command_buffer/common/debug_marker_manager.h', - 'command_buffer/common/gles2_cmd_ids_autogen.h', - 'command_buffer/common/gles2_cmd_ids.h', - 'command_buffer/common/gles2_cmd_format_autogen.h', 'command_buffer/common/gles2_cmd_format.cc', 'command_buffer/common/gles2_cmd_format.h', + 'command_buffer/common/gles2_cmd_format_autogen.h', + 'command_buffer/common/gles2_cmd_ids.h', + 'command_buffer/common/gles2_cmd_ids_autogen.h', 'command_buffer/common/gpu_control.h', 'command_buffer/common/id_allocator.cc', 'command_buffer/common/id_allocator.h', 'command_buffer/common/mailbox.cc', 'command_buffer/common/mailbox.h', + 'command_buffer/common/mailbox_holder.cc', + 'command_buffer/common/mailbox_holder.h', 'command_buffer/common/thread_local.h', 'command_buffer/common/time.h', 'command_buffer/common/types.h', diff --git a/gpu/ipc/gpu_command_buffer_traits.cc b/gpu/ipc/gpu_command_buffer_traits.cc index d9fc17d..db482a9 100644 --- a/gpu/ipc/gpu_command_buffer_traits.cc +++ b/gpu/ipc/gpu_command_buffer_traits.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "gpu/ipc/gpu_command_buffer_traits.h" -#include "gpu/command_buffer/common/mailbox.h" +#include "gpu/command_buffer/common/mailbox_holder.h" namespace IPC { @@ -59,5 +59,25 @@ void ParamTraits<gpu::Mailbox>::Log(const param_type& p, std::string* l) { *l += base::StringPrintf("%02x", p.name[i]); } +void ParamTraits<gpu::MailboxHolder>::Write(Message* m, const param_type& p) { + WriteParam(m, p.mailbox); + WriteParam(m, p.texture_target); + WriteParam(m, p.sync_point); +} + +bool ParamTraits<gpu::MailboxHolder>::Read(const Message* m, + PickleIterator* iter, + param_type* p) { + if (!ReadParam(m, iter, &p->mailbox) || + !ReadParam(m, iter, &p->texture_target) || + !ReadParam(m, iter, &p->sync_point)) + return false; + return true; +} + +void ParamTraits<gpu::MailboxHolder>::Log(const param_type& p, std::string* l) { + ParamTraits<gpu::Mailbox>::Log(p.mailbox, l); + *l += base::StringPrintf(":%04x@%d", p.texture_target, p.sync_point); +} } // namespace IPC diff --git a/gpu/ipc/gpu_command_buffer_traits.h b/gpu/ipc/gpu_command_buffer_traits.h index 6b2531f..ce854d2 100644 --- a/gpu/ipc/gpu_command_buffer_traits.h +++ b/gpu/ipc/gpu_command_buffer_traits.h @@ -11,6 +11,7 @@ namespace gpu { struct Mailbox; +struct MailboxHolder; } namespace IPC { @@ -31,6 +32,14 @@ struct GPU_EXPORT ParamTraits<gpu::Mailbox> { static void Log(const param_type& p, std::string* l); }; +template <> +struct GPU_EXPORT ParamTraits<gpu::MailboxHolder> { + typedef gpu::MailboxHolder param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + } // namespace IPC #endif // GPU_IPC_GPU_PARAM_TRAITS_H_ diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc index 8a4eb3c..a61a35f 100644 --- a/media/base/video_frame.cc +++ b/media/base/video_frame.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/memory/aligned_memory.h" #include "base/strings/string_piece.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "media/base/limits.h" #include "media/base/video_util.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -91,24 +92,22 @@ bool VideoFrame::IsValidConfig(VideoFrame::Format format, // static scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( - scoped_ptr<MailboxHolder> mailbox_holder, - uint32 texture_target, + scoped_ptr<gpu::MailboxHolder> mailbox_holder, + const ReleaseMailboxCB& mailbox_holder_release_cb, const gfx::Size& coded_size, const gfx::Rect& visible_rect, const gfx::Size& natural_size, base::TimeDelta timestamp, - const ReadPixelsCB& read_pixels_cb, - const base::Closure& no_longer_needed_cb) { + const ReadPixelsCB& read_pixels_cb) { scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp, false)); - frame->texture_mailbox_holder_ = mailbox_holder.Pass(); - frame->texture_target_ = texture_target; + frame->mailbox_holder_ = mailbox_holder.Pass(); + frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb; frame->read_pixels_cb_ = read_pixels_cb; - frame->no_longer_needed_cb_ = no_longer_needed_cb; return frame; } @@ -408,7 +407,6 @@ VideoFrame::VideoFrame(VideoFrame::Format format, coded_size_(coded_size), visible_rect_(visible_rect), natural_size_(natural_size), - texture_target_(0), shared_memory_handle_(base::SharedMemory::NULLHandle()), timestamp_(timestamp), end_of_stream_(end_of_stream) { @@ -417,6 +415,10 @@ VideoFrame::VideoFrame(VideoFrame::Format format, } VideoFrame::~VideoFrame() { + if (!mailbox_holder_release_cb_.is_null()) { + base::ResetAndReturn(&mailbox_holder_release_cb_) + .Run(mailbox_holder_.get()); + } if (!no_longer_needed_cb_.is_null()) base::ResetAndReturn(&no_longer_needed_cb_).Run(); } @@ -487,14 +489,9 @@ uint8* VideoFrame::data(size_t plane) const { return data_[plane]; } -VideoFrame::MailboxHolder* VideoFrame::texture_mailbox() const { - DCHECK_EQ(format_, NATIVE_TEXTURE); - return texture_mailbox_holder_.get(); -} - -uint32 VideoFrame::texture_target() const { +gpu::MailboxHolder* VideoFrame::mailbox_holder() const { DCHECK_EQ(format_, NATIVE_TEXTURE); - return texture_target_; + return mailbox_holder_.get(); } base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { @@ -513,17 +510,4 @@ void VideoFrame::HashFrameForTesting(base::MD5Context* context) { } } -VideoFrame::MailboxHolder::MailboxHolder( - const gpu::Mailbox& mailbox, - unsigned sync_point, - const TextureNoLongerNeededCallback& release_callback) - : mailbox_(mailbox), - sync_point_(sync_point), - release_callback_(release_callback) {} - -VideoFrame::MailboxHolder::~MailboxHolder() { - if (!release_callback_.is_null()) - release_callback_.Run(sync_point_); -} - } // namespace media diff --git a/media/base/video_frame.h b/media/base/video_frame.h index b51bfe9..80fb56a 100644 --- a/media/base/video_frame.h +++ b/media/base/video_frame.h @@ -8,13 +8,16 @@ #include "base/callback.h" #include "base/md5.h" #include "base/memory/shared_memory.h" -#include "gpu/command_buffer/common/mailbox.h" #include "media/base/buffers.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" class SkBitmap; +namespace gpu { +struct MailboxHolder; +} // namespace gpu + namespace media { class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { @@ -55,34 +58,6 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // Returns the name of a Format as a string. static std::string FormatToString(Format format); - // This class calls the TextureNoLongerNeededCallback when this class is - // destroyed. Users can query the current sync point associated with this - // mailbox with sync_point(), and should call Resync() with a new sync point - // to ensure the mailbox remains valid for the issued commands. - // valid for the issued commands. - class MEDIA_EXPORT MailboxHolder { - public: - typedef base::Callback<void(uint32 sync_point)> - TextureNoLongerNeededCallback; - - MailboxHolder(const gpu::Mailbox& mailbox, - unsigned sync_point, - const TextureNoLongerNeededCallback& release_callback); - ~MailboxHolder(); - - const gpu::Mailbox& mailbox() const { return mailbox_; } - unsigned sync_point() const { return sync_point_; } - - void Resync(unsigned sync_point) { sync_point_ = sync_point; } - - private: - - gpu::Mailbox mailbox_; - unsigned sync_point_; - TextureNoLongerNeededCallback release_callback_; - }; - - // Creates a new frame in system memory with given parameters. Buffers for // the frame are allocated but not initialized. // |coded_size| is the width and height of the frame data in pixels. @@ -108,8 +83,14 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // |const SkBitmap&| parameter. typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; - // Wraps a native texture of the given parameters with a VideoFrame. When the - // frame is destroyed |no_longer_needed_cb.Run()| will be called. + // CB to be called on the mailbox backing this frame when the frame is + // destroyed. + typedef base::Callback<void(const gpu::MailboxHolder*)> ReleaseMailboxCB; + + // Wraps a native texture of the given parameters with a VideoFrame. The + // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, + // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the + // argument when the VideoFrame is to be destroyed. // |coded_size| is the width and height of the frame data in pixels. // |visible_rect| is the visible portion of |coded_size|, after cropping (if // any) is applied. @@ -119,14 +100,13 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // |read_pixels_cb| may be used to do (slow!) readbacks from the // texture to main memory. static scoped_refptr<VideoFrame> WrapNativeTexture( - scoped_ptr<MailboxHolder> mailbox_holder, - uint32 texture_target, + scoped_ptr<gpu::MailboxHolder> mailbox_holder, + const ReleaseMailboxCB& mailbox_holder_release_cb, const gfx::Size& coded_size, const gfx::Rect& visible_rect, const gfx::Size& natural_size, base::TimeDelta timestamp, - const ReadPixelsCB& read_pixels_cb, - const base::Closure& no_longer_needed_cb); + const ReadPixelsCB& read_pixels_cb); // Read pixels from the native texture backing |*this| and write // them to |pixels| as BGRA. |pixels| must point to a buffer at @@ -224,13 +204,10 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // VideoFrame object and must not be freed by the caller. uint8* data(size_t plane) const; - // Returns the mailbox of the native texture wrapped by this frame. Only - // valid to call if this is a NATIVE_TEXTURE frame. Before using the + // Returns the mailbox holder of the native texture wrapped by this frame. + // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the // mailbox, the caller must wait for the included sync point. - MailboxHolder* texture_mailbox() const; - - // Returns the texture target. Only valid for NATIVE_TEXTURE frames. - uint32 texture_target() const; + gpu::MailboxHolder* mailbox_holder() const; // Returns the shared-memory handle, if present base::SharedMemoryHandle shared_memory_handle() const; @@ -287,8 +264,8 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { uint8* data_[kMaxPlanes]; // Native texture mailbox, if this is a NATIVE_TEXTURE frame. - scoped_ptr<MailboxHolder> texture_mailbox_holder_; - uint32 texture_target_; + scoped_ptr<gpu::MailboxHolder> mailbox_holder_; + ReleaseMailboxCB mailbox_holder_release_cb_; ReadPixelsCB read_pixels_cb_; // Shared memory handle, if this frame was allocated from shared memory. diff --git a/media/base/video_frame_unittest.cc b/media/base/video_frame_unittest.cc index 9c7eab0..08a083b 100644 --- a/media/base/video_frame_unittest.cc +++ b/media/base/video_frame_unittest.cc @@ -10,6 +10,7 @@ #include "base/memory/aligned_memory.h" #include "base/memory/scoped_ptr.h" #include "base/strings/stringprintf.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "media/base/buffers.h" #include "media/base/yuv_convert.h" #include "testing/gtest/include/gtest/gtest.h" @@ -211,11 +212,12 @@ TEST(VideoFrame, CheckFrameExtents) { VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); } -static void TextureCallback(uint32* called_sync_point, uint32 sync_point) { - *called_sync_point = sync_point; +static void TextureCallback(uint32* called_sync_point, + const gpu::MailboxHolder* mailbox_holder) { + *called_sync_point = mailbox_holder->sync_point; } -// Verify the TextureNoLongerNeededCallback is called when VideoFrame is +// Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is // destroyed with the original sync point. TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { uint32 sync_point = 7; @@ -223,24 +225,20 @@ TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { { scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( - make_scoped_ptr(new VideoFrame::MailboxHolder( - gpu::Mailbox(), - sync_point, - base::Bind(&TextureCallback, &called_sync_point))), - 5, // texture_target - gfx::Size(10, 10), // coded_size - gfx::Rect(10, 10), // visible_rect - gfx::Size(10, 10), // natural_size - base::TimeDelta(), // timestamp - base::Callback<void(const SkBitmap&)>(), // read_pixels_cb - base::Closure()); // no_longer_needed_cb + make_scoped_ptr(new gpu::MailboxHolder(gpu::Mailbox(), 5, sync_point)), + base::Bind(&TextureCallback, &called_sync_point), + gfx::Size(10, 10), // coded_size + gfx::Rect(10, 10), // visible_rect + gfx::Size(10, 10), // natural_size + base::TimeDelta(), // timestamp + base::Callback<void(const SkBitmap&)>()); // read_pixels_cb EXPECT_EQ(0u, called_sync_point); } EXPECT_EQ(sync_point, called_sync_point); } -// Verify the TextureNoLongerNeededCallback is called when VideoFrame is +// Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is // destroyed with the new sync point, when the mailbox is accessed by a caller. TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { uint32 called_sync_point = 0; @@ -252,27 +250,23 @@ TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { { scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( - make_scoped_ptr(new VideoFrame::MailboxHolder( - mailbox, - sync_point, - base::Bind(&TextureCallback, &called_sync_point))), - target, - gfx::Size(10, 10), // coded_size - gfx::Rect(10, 10), // visible_rect - gfx::Size(10, 10), // natural_size - base::TimeDelta(), // timestamp - base::Callback<void(const SkBitmap&)>(), // read_pixels_cb - base::Closure()); // no_longer_needed_cb - - VideoFrame::MailboxHolder* mailbox_holder = frame->texture_mailbox(); - - EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]); - EXPECT_EQ(sync_point, mailbox_holder->sync_point()); - EXPECT_EQ(target, frame->texture_target()); + make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), + base::Bind(&TextureCallback, &called_sync_point), + gfx::Size(10, 10), // coded_size + gfx::Rect(10, 10), // visible_rect + gfx::Size(10, 10), // natural_size + base::TimeDelta(), // timestamp + base::Callback<void(const SkBitmap&)>()); // read_pixels_cb + + gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); + + EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); + EXPECT_EQ(target, mailbox_holder->texture_target); + EXPECT_EQ(sync_point, mailbox_holder->sync_point); // Finish using the mailbox_holder and drop our reference. sync_point = 10; - mailbox_holder->Resync(sync_point); + mailbox_holder->sync_point = sync_point; } EXPECT_EQ(sync_point, called_sync_point); } diff --git a/media/filters/gpu_video_decoder.cc b/media/filters/gpu_video_decoder.cc index b96ff43..6ccbf0c 100644 --- a/media/filters/gpu_video_decoder.cc +++ b/media/filters/gpu_video_decoder.cc @@ -13,6 +13,7 @@ #include "base/metrics/histogram.h" #include "base/stl_util.h" #include "base/task_runner_util.h" +#include "gpu/command_buffer/common/mailbox_holder.h" #include "media/base/bind_to_current_loop.h" #include "media/base/decoder_buffer.h" #include "media/base/media_log.h" @@ -442,13 +443,11 @@ void GpuVideoDecoder::PictureReady(const media::Picture& picture) { DCHECK(decoder_texture_target_); scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( - make_scoped_ptr(new VideoFrame::MailboxHolder( - pb.texture_mailbox(), - 0, // sync_point - BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, - weak_this_, - picture.picture_buffer_id())))), - decoder_texture_target_, + make_scoped_ptr(new gpu::MailboxHolder( + pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), + BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, + weak_this_, + picture.picture_buffer_id())), pb.size(), visible_rect, natural_size, @@ -456,8 +455,7 @@ void GpuVideoDecoder::PictureReady(const media::Picture& picture) { base::Bind(&GpuVideoAcceleratorFactories::ReadPixels, factories_, pb.texture_id(), - gfx::Size(visible_rect.width(), visible_rect.height())), - base::Closure())); + gfx::Size(visible_rect.width(), visible_rect.height())))); CHECK_GT(available_pictures_, 0); --available_pictures_; bool inserted = @@ -489,8 +487,9 @@ void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( ready_video_frames_.pop_front(); } -void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, - uint32 sync_point) { +void GpuVideoDecoder::ReusePictureBuffer( + int64 picture_buffer_id, + const gpu::MailboxHolder* mailbox_holder) { DVLOG(3) << "ReusePictureBuffer(" << picture_buffer_id << ")"; DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); @@ -514,7 +513,7 @@ void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, return; } - factories_->WaitSyncPoint(sync_point); + factories_->WaitSyncPoint(mailbox_holder->sync_point); ++available_pictures_; vda_->ReusePictureBuffer(picture_buffer_id); diff --git a/media/filters/gpu_video_decoder.h b/media/filters/gpu_video_decoder.h index 961e25a..a7a8f36 100644 --- a/media/filters/gpu_video_decoder.h +++ b/media/filters/gpu_video_decoder.h @@ -105,7 +105,8 @@ class MEDIA_EXPORT GpuVideoDecoder const scoped_refptr<VideoFrame>& frame); // Indicate the picture buffer can be reused by the decoder. - void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); + void ReusePictureBuffer(int64 picture_buffer_id, + const gpu::MailboxHolder* mailbox_holder); void RecordBufferData( const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer); diff --git a/webkit/renderer/compositor_bindings/web_external_texture_layer_impl.cc b/webkit/renderer/compositor_bindings/web_external_texture_layer_impl.cc index e5a33d5f..8657b38 100644 --- a/webkit/renderer/compositor_bindings/web_external_texture_layer_impl.cc +++ b/webkit/renderer/compositor_bindings/web_external_texture_layer_impl.cc @@ -13,6 +13,7 @@ #include "third_party/WebKit/public/platform/WebFloatRect.h" #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" #include "third_party/WebKit/public/platform/WebSize.h" +#include "third_party/khronos/GLES2/gl2.h" #include "webkit/renderer/compositor_bindings/web_external_bitmap_impl.h" #include "webkit/renderer/compositor_bindings/web_layer_impl.h" @@ -82,10 +83,12 @@ bool WebExternalTextureLayerImpl::PrepareTextureMailbox( } gpu::Mailbox name; name.SetName(client_mailbox.name); - if (bitmap) + if (bitmap) { *mailbox = cc::TextureMailbox(bitmap->shared_memory(), bitmap->size()); - else - *mailbox = cc::TextureMailbox(name, client_mailbox.syncPoint); + } else { + *mailbox = + cc::TextureMailbox(name, GL_TEXTURE_2D, client_mailbox.syncPoint); + } if (mailbox->IsValid()) { *release_callback = cc::SingleReleaseCallback::Create(base::Bind( |