diff options
Diffstat (limited to 'cc/resources')
-rw-r--r-- | cc/resources/release_callback.h | 17 | ||||
-rw-r--r-- | cc/resources/resource_provider.cc | 13 | ||||
-rw-r--r-- | cc/resources/resource_provider.h | 7 | ||||
-rw-r--r-- | cc/resources/resource_provider_unittest.cc | 66 | ||||
-rw-r--r-- | cc/resources/single_release_callback.cc | 29 | ||||
-rw-r--r-- | cc/resources/single_release_callback.h | 33 | ||||
-rw-r--r-- | cc/resources/texture_mailbox.cc | 67 | ||||
-rw-r--r-- | cc/resources/texture_mailbox.h | 21 | ||||
-rw-r--r-- | cc/resources/texture_mailbox_deleter.cc | 33 | ||||
-rw-r--r-- | cc/resources/texture_mailbox_deleter.h | 8 | ||||
-rw-r--r-- | cc/resources/texture_mailbox_deleter_unittest.cc | 9 | ||||
-rw-r--r-- | cc/resources/video_resource_updater.cc | 25 | ||||
-rw-r--r-- | cc/resources/video_resource_updater.h | 4 |
13 files changed, 191 insertions, 141 deletions
diff --git a/cc/resources/release_callback.h b/cc/resources/release_callback.h new file mode 100644 index 0000000..9433f7f --- /dev/null +++ b/cc/resources/release_callback.h @@ -0,0 +1,17 @@ +// Copyright 2013 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 CC_RESOURCES_RELEASE_CALLBACK_H_ +#define CC_RESOURCES_RELEASE_CALLBACK_H_ + +#include "base/callback.h" + +namespace cc { + +typedef base::Callback<void(unsigned sync_point, bool is_lost)> + ReleaseCallback; + +} // namespace cc + +#endif // CC_RESOURCES_RELEASE_CALLBACK_H_ diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc index 5c8d39c..017c2e9 100644 --- a/cc/resources/resource_provider.cc +++ b/cc/resources/resource_provider.cc @@ -312,7 +312,8 @@ ResourceProvider::CreateResourceFromExternalTexture( } ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( - const TextureMailbox& mailbox) { + const TextureMailbox& mailbox, + scoped_ptr<SingleReleaseCallback> release_callback) { DCHECK(thread_checker_.CalledOnValidThread()); // Just store the information. Mailbox will be consumed in LockForRead(). ResourceId id = next_id_++; @@ -332,6 +333,9 @@ ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( resource.external = true; resource.allocated = true; resource.mailbox = mailbox; + resource.release_callback = + base::Bind(&SingleReleaseCallback::Run, + base::Owned(release_callback.release())); return id; } @@ -400,7 +404,7 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, resource->pixels = NULL; } } - resource->mailbox.RunReleaseCallback(sync_point, lost_resource); + resource->release_callback.Run(sync_point, lost_resource); } if (resource->pixels) delete[] resource->pixels; @@ -963,9 +967,8 @@ void ResourceProvider::ReceiveReturnsFromParent( if (it->sync_point) GLC(context3d, context3d->waitSyncPoint(it->sync_point)); } else { - resource->mailbox = TextureMailbox(resource->mailbox.name(), - resource->mailbox.callback(), - it->sync_point); + resource->mailbox = + TextureMailbox(resource->mailbox.name(), it->sync_point); } if (resource->marked_for_deletion) DeleteResourceInternal(map_iterator, Normal); diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h index 8b4b01b..88ff274 100644 --- a/cc/resources/resource_provider.h +++ b/cc/resources/resource_provider.h @@ -18,6 +18,8 @@ #include "cc/base/cc_export.h" #include "cc/output/context_provider.h" #include "cc/output/output_surface.h" +#include "cc/resources/release_callback.h" +#include "cc/resources/single_release_callback.h" #include "cc/resources/texture_mailbox.h" #include "cc/resources/transferable_resource.h" #include "third_party/khronos/GLES2/gl2.h" @@ -103,7 +105,9 @@ class CC_EXPORT ResourceProvider { unsigned texture_id); // Wraps an external texture mailbox into a GL resource. - ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); + ResourceId CreateResourceFromTextureMailbox( + const TextureMailbox& mailbox, + scoped_ptr<SingleReleaseCallback> release_callback); void DeleteResource(ResourceId id); @@ -354,6 +358,7 @@ class CC_EXPORT ResourceProvider { // Query used to determine when asynchronous set pixels complete. unsigned gl_upload_query_id; TextureMailbox mailbox; + ReleaseCallback release_callback; uint8_t* pixels; uint8_t* pixel_buffer; int lock_for_read_count; diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc index afb2330..abdd78e 100644 --- a/cc/resources/resource_provider_unittest.cc +++ b/cc/resources/resource_provider_unittest.cc @@ -14,6 +14,7 @@ #include "cc/debug/test_web_graphics_context_3d.h" #include "cc/output/output_surface.h" #include "cc/resources/returned_resource.h" +#include "cc/resources/single_release_callback.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_output_surface_client.h" #include "gpu/GLES2/gl2extchromium.h" @@ -918,11 +919,12 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { unsigned release_sync_point = 0; bool lost_resource = false; - TextureMailbox::ReleaseCallback callback = + ReleaseCallback callback = base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); ResourceProvider::ResourceId resource = resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(mailbox, callback, sync_point)); + TextureMailbox(mailbox, sync_point), + SingleReleaseCallback::Create(callback)); EXPECT_EQ(1, context()->texture_count()); EXPECT_EQ(0u, release_sync_point); { @@ -968,7 +970,8 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) { EXPECT_LT(0u, sync_point); release_sync_point = 0; resource = resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(mailbox, callback, sync_point)); + TextureMailbox(mailbox, sync_point), + SingleReleaseCallback::Create(callback)); EXPECT_EQ(1, context()->texture_count()); EXPECT_EQ(0u, release_sync_point); { @@ -1030,10 +1033,11 @@ TEST_P(ResourceProviderTest, Shutdown) { unsigned release_sync_point = 0; bool lost_resource = false; - TextureMailbox::ReleaseCallback callback = - base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); + scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( + base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(mailbox, callback, sync_point)); + TextureMailbox(mailbox, sync_point), + callback.Pass()); EXPECT_EQ(0u, release_sync_point); EXPECT_FALSE(lost_resource); @@ -1069,10 +1073,11 @@ TEST_P(ResourceProviderTest, ShutdownSharedMemory) { CreateAndFillSharedMemory(size, 0)); bool release_called = false; - TextureMailbox::ReleaseCallback callback = - base::Bind(ReleaseSharedMemoryCallback, &release_called); + scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( + base::Bind(ReleaseSharedMemoryCallback, &release_called)); resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(shared_memory.get(), size, callback)); + TextureMailbox(shared_memory.get(), size), + callback.Pass()); resource_provider_.reset(); @@ -1094,11 +1099,12 @@ TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { unsigned release_sync_point = 0; bool lost_resource = false; - TextureMailbox::ReleaseCallback callback = - base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); + scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( + base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); ResourceProvider::ResourceId resource = resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(mailbox, callback, sync_point)); + TextureMailbox(mailbox, sync_point), + callback.Pass()); // Transfer the resource, so we can't release it properly on shutdown. ResourceProvider::ResourceIdArray resource_ids_to_transfer; @@ -1131,10 +1137,11 @@ TEST_P(ResourceProviderTest, LostContext) { unsigned release_sync_point = 0; bool lost_resource = false; - TextureMailbox::ReleaseCallback callback = - base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource); + scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( + base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); resource_provider_->CreateResourceFromTextureMailbox( - TextureMailbox(mailbox, callback, sync_point)); + TextureMailbox(mailbox, sync_point), + callback.Pass()); EXPECT_EQ(0u, release_sync_point); EXPECT_FALSE(lost_resource); @@ -1341,11 +1348,13 @@ TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { scoped_ptr<ResourceProvider> resource_provider( ResourceProvider::Create(output_surface.get(), 0)); - TextureMailbox::ReleaseCallback callback = base::Bind(&EmptyReleaseCallback); - TextureMailbox mailbox(shared_memory.get(), size, callback); + scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( + base::Bind(&EmptyReleaseCallback)); + TextureMailbox mailbox(shared_memory.get(), size); ResourceProvider::ResourceId id = - resource_provider->CreateResourceFromTextureMailbox(mailbox); + resource_provider->CreateResourceFromTextureMailbox( + mailbox, callback.Pass()); EXPECT_NE(0u, id); { @@ -1386,14 +1395,14 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { gpu::Mailbox gpu_mailbox; memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); - TextureMailbox::ReleaseCallback callback = base::Bind(&EmptyReleaseCallback); + scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( + base::Bind(&EmptyReleaseCallback)); - TextureMailbox mailbox(gpu_mailbox, - callback, - sync_point); + TextureMailbox mailbox(gpu_mailbox, sync_point); ResourceProvider::ResourceId id = - resource_provider->CreateResourceFromTextureMailbox(mailbox); + resource_provider->CreateResourceFromTextureMailbox( + mailbox, callback.Pass()); EXPECT_NE(0u, id); Mock::VerifyAndClearExpectations(context); @@ -1450,15 +1459,14 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { gpu::Mailbox gpu_mailbox; memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); - TextureMailbox::ReleaseCallback callback = base::Bind(&EmptyReleaseCallback); + scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( + base::Bind(&EmptyReleaseCallback)); - TextureMailbox mailbox(gpu_mailbox, - callback, - target, - sync_point); + TextureMailbox mailbox(gpu_mailbox, target, sync_point); ResourceProvider::ResourceId id = - resource_provider->CreateResourceFromTextureMailbox(mailbox); + resource_provider->CreateResourceFromTextureMailbox( + mailbox, callback.Pass()); EXPECT_NE(0u, id); Mock::VerifyAndClearExpectations(context); diff --git a/cc/resources/single_release_callback.cc b/cc/resources/single_release_callback.cc new file mode 100644 index 0000000..9c6b9de --- /dev/null +++ b/cc/resources/single_release_callback.cc @@ -0,0 +1,29 @@ +// Copyright 2013 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 "cc/resources/single_release_callback.h" + +#include "base/callback_helpers.h" +#include "base/logging.h" + +namespace cc { + +SingleReleaseCallback::SingleReleaseCallback(const ReleaseCallback& callback) + : has_been_run_(false), callback_(callback) { + DCHECK(!callback_.is_null()) + << "Use a NULL SingleReleaseCallback for an empty callback."; +} + +SingleReleaseCallback::~SingleReleaseCallback() { + DCHECK(callback_.is_null() || has_been_run_) + << "SingleReleaseCallback was never run."; +} + +void SingleReleaseCallback::Run(unsigned 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); +} + +} // namespace cc diff --git a/cc/resources/single_release_callback.h b/cc/resources/single_release_callback.h new file mode 100644 index 0000000..fe1a3ba --- /dev/null +++ b/cc/resources/single_release_callback.h @@ -0,0 +1,33 @@ +// Copyright 2013 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 CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ +#define CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/resources/release_callback.h" + +namespace cc { + +class CC_EXPORT SingleReleaseCallback { + public: + static scoped_ptr<SingleReleaseCallback> Create(const ReleaseCallback& cb) { + return make_scoped_ptr(new SingleReleaseCallback(cb)); + } + + ~SingleReleaseCallback(); + + void Run(unsigned sync_point, bool is_lost); + + private: + explicit SingleReleaseCallback(const ReleaseCallback& callback); + + bool has_been_run_; + ReleaseCallback callback_; +}; + +} // namespace cc + +#endif // CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ diff --git a/cc/resources/texture_mailbox.cc b/cc/resources/texture_mailbox.cc index 2a8f570..149d56c 100644 --- a/cc/resources/texture_mailbox.cc +++ b/cc/resources/texture_mailbox.cc @@ -4,7 +4,6 @@ #include "cc/resources/texture_mailbox.h" -#include "base/callback_helpers.h" #include "base/logging.h" #include "third_party/khronos/GLES2/gl2.h" @@ -16,69 +15,48 @@ TextureMailbox::TextureMailbox() shared_memory_(NULL) { } -TextureMailbox::TextureMailbox( - const std::string& mailbox_name, - const ReleaseCallback& callback) - : callback_(callback), - target_(GL_TEXTURE_2D), +TextureMailbox::TextureMailbox(const std::string& mailbox_name) + : target_(GL_TEXTURE_2D), sync_point_(0), shared_memory_(NULL) { - DCHECK(mailbox_name.empty() == callback.is_null()); if (!mailbox_name.empty()) { CHECK(mailbox_name.size() == sizeof(name_.name)); name_.SetName(reinterpret_cast<const int8*>(mailbox_name.data())); } } -TextureMailbox::TextureMailbox( - const gpu::Mailbox& mailbox_name, - const ReleaseCallback& callback) - : callback_(callback), - target_(GL_TEXTURE_2D), +TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name) + : target_(GL_TEXTURE_2D), sync_point_(0), shared_memory_(NULL) { - DCHECK(mailbox_name.IsZero() == callback.is_null()); name_.SetName(mailbox_name.name); } -TextureMailbox::TextureMailbox( - const gpu::Mailbox& mailbox_name, - const ReleaseCallback& callback, - unsigned sync_point) - : callback_(callback), - target_(GL_TEXTURE_2D), +TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name, + unsigned sync_point) + : target_(GL_TEXTURE_2D), sync_point_(sync_point), shared_memory_(NULL) { - DCHECK(mailbox_name.IsZero() == callback.is_null()); name_.SetName(mailbox_name.name); } -TextureMailbox::TextureMailbox( - const gpu::Mailbox& mailbox_name, - const ReleaseCallback& callback, - unsigned texture_target, - unsigned sync_point) - : callback_(callback), - target_(texture_target), +TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name, + unsigned texture_target, + unsigned sync_point) + : target_(texture_target), sync_point_(sync_point), shared_memory_(NULL) { - DCHECK(mailbox_name.IsZero() == callback.is_null()); name_.SetName(mailbox_name.name); } -TextureMailbox::TextureMailbox( - base::SharedMemory* shared_memory, - gfx::Size size, - const ReleaseCallback& callback) - : callback_(callback), - target_(GL_TEXTURE_2D), +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_size_(size) {} -TextureMailbox::~TextureMailbox() { -} +TextureMailbox::~TextureMailbox() {} bool TextureMailbox::Equals(const TextureMailbox& other) const { if (other.IsTexture()) @@ -103,19 +81,6 @@ void TextureMailbox::SetName(const gpu::Mailbox& name) { name_ = name; } -void TextureMailbox::RunReleaseCallback(unsigned sync_point, - bool lost_resource) { - if (!callback_.is_null()) - base::ResetAndReturn(&callback_).Run(sync_point, lost_resource); -} - -TextureMailbox TextureMailbox::CopyWithNewCallback( - const ReleaseCallback& callback) const { - TextureMailbox result(*this); - result.callback_ = callback; - return result; -} - 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 9490939..a9b021b 100644 --- a/cc/resources/texture_mailbox.h +++ b/cc/resources/texture_mailbox.h @@ -19,23 +19,16 @@ namespace cc { // can hold a shared memory resource as well as a texture mailbox. class CC_EXPORT TextureMailbox { public: - typedef base::Callback<void(unsigned sync_point, - bool lost_resource)> ReleaseCallback; TextureMailbox(); - TextureMailbox(const std::string& mailbox_name, - const ReleaseCallback& callback); + explicit TextureMailbox(const std::string& mailbox_name); + explicit TextureMailbox(const gpu::Mailbox& mailbox_name); TextureMailbox(const gpu::Mailbox& mailbox_name, - const ReleaseCallback& callback); - TextureMailbox(const gpu::Mailbox& mailbox_name, - const ReleaseCallback& callback, unsigned sync_point); TextureMailbox(const gpu::Mailbox& mailbox_name, - const ReleaseCallback& callback, unsigned texture_target, unsigned sync_point); TextureMailbox(base::SharedMemory* shared_memory, - gfx::Size size, - const ReleaseCallback& callback); + gfx::Size size); ~TextureMailbox(); @@ -61,16 +54,8 @@ class CC_EXPORT TextureMailbox { // storing a TextureMailbox in ResourceProvider. Then we can remove this. void SetName(const gpu::Mailbox& name); - // TODO(danakj): ReleaseCallback should be a separate scoped_ptr outside this - // class to avoid silently adding references to the callback's internals. - void RunReleaseCallback(unsigned sync_point, bool lost_resource); - - TextureMailbox CopyWithNewCallback(const ReleaseCallback& callback) const; - const ReleaseCallback& callback() const { return callback_; } - private: gpu::Mailbox name_; - ReleaseCallback callback_; unsigned target_; unsigned sync_point_; base::SharedMemory* shared_memory_; diff --git a/cc/resources/texture_mailbox_deleter.cc b/cc/resources/texture_mailbox_deleter.cc index ed611e4..ae6df17 100644 --- a/cc/resources/texture_mailbox_deleter.cc +++ b/cc/resources/texture_mailbox_deleter.cc @@ -9,6 +9,7 @@ #include "base/memory/weak_ptr.h" #include "base/message_loop/message_loop_proxy.h" #include "cc/output/context_provider.h" +#include "cc/resources/single_release_callback.h" #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" namespace cc { @@ -25,7 +26,7 @@ static void DeleteTextureOnImplThread( static void PostTaskFromMainToImplThread( scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, - TextureMailbox::ReleaseCallback run_impl_callback, + ReleaseCallback run_impl_callback, unsigned sync_point, bool is_lost) { // This posts the task to RunDeleteTextureOnImplThread(). @@ -40,43 +41,45 @@ TextureMailboxDeleter::~TextureMailboxDeleter() { impl_callbacks_.at(i)->Run(0, true); } -TextureMailbox::ReleaseCallback TextureMailboxDeleter::GetReleaseCallback( +scoped_ptr<SingleReleaseCallback> TextureMailboxDeleter::GetReleaseCallback( const scoped_refptr<ContextProvider>& context_provider, unsigned texture_id) { // This callback owns a reference on the |context_provider|. It must be // destroyed on the impl thread. Upon destruction of this class, the // callback must immediately be destroyed. - scoped_ptr<TextureMailbox::ReleaseCallback> impl_callback( - new TextureMailbox::ReleaseCallback(base::Bind( - &DeleteTextureOnImplThread, context_provider, texture_id))); + scoped_ptr<SingleReleaseCallback> impl_callback = + SingleReleaseCallback::Create(base::Bind(&DeleteTextureOnImplThread, + context_provider, + texture_id)); impl_callbacks_.push_back(impl_callback.Pass()); // The raw pointer to the impl-side callback is valid as long as this // class is alive. So we guard it with a WeakPtr. - TextureMailbox::ReleaseCallback run_impl_callback = + ReleaseCallback run_impl_callback( base::Bind(&TextureMailboxDeleter::RunDeleteTextureOnImplThread, weak_ptr_factory_.GetWeakPtr(), - impl_callbacks_.back()); + impl_callbacks_.back())); // Provide a callback for the main thread that posts back to the impl // thread. - TextureMailbox::ReleaseCallback main_callback = - base::Bind(&PostTaskFromMainToImplThread, - base::MessageLoopProxy::current(), - run_impl_callback); + scoped_ptr<SingleReleaseCallback> main_callback = + SingleReleaseCallback::Create(base::Bind( + &PostTaskFromMainToImplThread, + base::MessageLoopProxy::current(), + run_impl_callback)); - return main_callback; + return main_callback.Pass(); } void TextureMailboxDeleter::RunDeleteTextureOnImplThread( - TextureMailbox::ReleaseCallback* impl_callback, + SingleReleaseCallback* impl_callback, unsigned sync_point, bool is_lost) { for (size_t i = 0; i < impl_callbacks_.size(); ++i) { - if (impl_callbacks_.at(i)->Equals(*impl_callback)) { + if (impl_callbacks_.at(i) == impl_callback) { // Run the callback, then destroy it here on the impl thread. - impl_callback->Run(sync_point, is_lost); + impl_callbacks_.at(i)->Run(sync_point, is_lost); impl_callbacks_.erase(impl_callbacks_.begin() + i); return; } diff --git a/cc/resources/texture_mailbox_deleter.h b/cc/resources/texture_mailbox_deleter.h index 608dd7a..072dcab 100644 --- a/cc/resources/texture_mailbox_deleter.h +++ b/cc/resources/texture_mailbox_deleter.h @@ -8,10 +8,10 @@ #include "base/memory/weak_ptr.h" #include "cc/base/cc_export.h" #include "cc/base/scoped_ptr_vector.h" -#include "cc/resources/texture_mailbox.h" namespace cc { class ContextProvider; +class SingleReleaseCallback; class CC_EXPORT TextureMailboxDeleter { public: @@ -25,7 +25,7 @@ class CC_EXPORT TextureMailboxDeleter { // due to the compositor shutting down, then the ReleaseCallback will // become a no-op and the texture will be deleted immediately on the // impl thread, along with dropping the reference to the ContextProvider. - TextureMailbox::ReleaseCallback GetReleaseCallback( + scoped_ptr<SingleReleaseCallback> GetReleaseCallback( const scoped_refptr<ContextProvider>& context_provider, unsigned texture_id); @@ -33,12 +33,12 @@ class CC_EXPORT TextureMailboxDeleter { // Runs the |impl_callback| to delete the texture and removes the callback // from the |impl_callbacks_| list. void RunDeleteTextureOnImplThread( - TextureMailbox::ReleaseCallback* impl_callback, + SingleReleaseCallback* impl_callback, unsigned sync_point, bool is_lost); base::WeakPtrFactory<TextureMailboxDeleter> weak_ptr_factory_; - ScopedPtrVector<TextureMailbox::ReleaseCallback> impl_callbacks_; + ScopedPtrVector<SingleReleaseCallback> impl_callbacks_; }; } // namespace cc diff --git a/cc/resources/texture_mailbox_deleter_unittest.cc b/cc/resources/texture_mailbox_deleter_unittest.cc index e08984e..a6ec48e 100644 --- a/cc/resources/texture_mailbox_deleter_unittest.cc +++ b/cc/resources/texture_mailbox_deleter_unittest.cc @@ -6,6 +6,7 @@ #include "cc/debug/test_context_provider.h" #include "cc/debug/test_web_graphics_context_3d.h" +#include "cc/resources/single_release_callback.h" #include "testing/gtest/include/gtest/gtest.h" namespace cc { @@ -23,8 +24,8 @@ TEST(TextureMailboxDeleterTest, Destroy) { EXPECT_TRUE(context_provider->HasOneRef()); EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); - TextureMailbox::ReleaseCallback cb = - deleter->GetReleaseCallback(context_provider, texture_id); + scoped_ptr<SingleReleaseCallback> cb = + deleter->GetReleaseCallback(context_provider, texture_id).Pass(); EXPECT_FALSE(context_provider->HasOneRef()); EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); @@ -33,6 +34,10 @@ TEST(TextureMailboxDeleterTest, Destroy) { deleter.reset(); EXPECT_TRUE(context_provider->HasOneRef()); EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); + + // Run the scoped release callback before destroying it, but it won't do + // anything. + cb->Run(0, false); } } // namespace diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc index f278c59..d07ff35 100644 --- a/cc/resources/video_resource_updater.cc +++ b/cc/resources/video_resource_updater.cc @@ -271,13 +271,12 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( plane_resources[0].resource_format, gpu::Mailbox() }; - TextureMailbox::ReleaseCallback callback_to_free_resource = - base::Bind(&RecycleResource, - AsWeakPtr(), - recycle_data); + external_resources.software_resources.push_back( plane_resources[0].resource_id); - external_resources.software_release_callback = callback_to_free_resource; + external_resources.software_release_callback = + base::Bind(&RecycleResource, AsWeakPtr(), recycle_data); + external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; return external_resources; @@ -307,13 +306,11 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( plane_resources[i].resource_format, plane_resources[i].mailbox }; - TextureMailbox::ReleaseCallback callback_to_free_resource = - base::Bind(&RecycleResource, - AsWeakPtr(), - recycle_data); + external_resources.mailboxes.push_back( - TextureMailbox(plane_resources[i].mailbox, - callback_to_free_resource)); + TextureMailbox(plane_resources[i].mailbox)); + external_resources.release_callbacks.push_back( + base::Bind(&RecycleResource, AsWeakPtr(), recycle_data)); } external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; @@ -358,14 +355,12 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( scoped_refptr<media::VideoFrame::MailboxHolder> mailbox_holder = video_frame->texture_mailbox(); - TextureMailbox::ReleaseCallback callback_to_return_resource = - base::Bind(&ReturnTexture, mailbox_holder); - external_resources.mailboxes.push_back( TextureMailbox(mailbox_holder->mailbox(), - callback_to_return_resource, video_frame->texture_target(), mailbox_holder->sync_point())); + external_resources.release_callbacks.push_back( + base::Bind(&ReturnTexture, mailbox_holder)); return external_resources; } diff --git a/cc/resources/video_resource_updater.h b/cc/resources/video_resource_updater.h index cf71cfa..d0e9f9c 100644 --- a/cc/resources/video_resource_updater.h +++ b/cc/resources/video_resource_updater.h @@ -12,6 +12,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "cc/base/cc_export.h" +#include "cc/resources/release_callback.h" #include "cc/resources/texture_mailbox.h" #include "ui/gfx/size.h" @@ -48,10 +49,11 @@ class CC_EXPORT VideoFrameExternalResources { ResourceType type; std::vector<TextureMailbox> mailboxes; + std::vector<ReleaseCallback> release_callbacks; // TODO(danakj): Remove these too. std::vector<unsigned> software_resources; - TextureMailbox::ReleaseCallback software_release_callback; + ReleaseCallback software_release_callback; VideoFrameExternalResources(); ~VideoFrameExternalResources(); |