1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_OUTPUT_TEXTURE_MAILBOX_DELETER_H_
6 #define CC_OUTPUT_TEXTURE_MAILBOX_DELETER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "cc/base/cc_export.h"
10 #include "cc/base/scoped_ptr_vector.h"
13 class SingleThreadTaskRunner
;
17 class ContextProvider
;
18 class SingleReleaseCallback
;
20 class CC_EXPORT TextureMailboxDeleter
{
22 // task_runner corresponds with the thread the delete task should be posted
23 // to. If null, the delete will happen on the calling thread.
24 explicit TextureMailboxDeleter(
25 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
);
26 ~TextureMailboxDeleter();
28 // Returns a Callback that can be used as the ReleaseCallback for a
29 // TextureMailbox attached to the |texture_id|. The ReleaseCallback can
30 // be passed to other threads and will destroy the texture, once it is
31 // run, on the impl thread. If the TextureMailboxDeleter is destroyed
32 // due to the compositor shutting down, then the ReleaseCallback will
33 // become a no-op and the texture will be deleted immediately on the
34 // impl thread, along with dropping the reference to the ContextProvider.
35 scoped_ptr
<SingleReleaseCallback
> GetReleaseCallback(
36 const scoped_refptr
<ContextProvider
>& context_provider
,
40 // Runs the |impl_callback| to delete the texture and removes the callback
41 // from the |impl_callbacks_| list.
42 void RunDeleteTextureOnImplThread(SingleReleaseCallback
* impl_callback
,
46 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner_
;
47 ScopedPtrVector
<SingleReleaseCallback
> impl_callbacks_
;
48 base::WeakPtrFactory
<TextureMailboxDeleter
> weak_ptr_factory_
;
53 #endif // CC_OUTPUT_TEXTURE_MAILBOX_DELETER_H_