summaryrefslogtreecommitdiff
path: root/libs/input/SpriteController.h
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2023-08-18 19:44:55 +0000
committer Prabir Pradhan <prabirmsp@google.com> 2023-08-18 19:56:15 +0000
commit27c6d99600422ee96fcc29de26c2be84c6a9838d (patch)
treeced5bc81068c3e7ff2b9c0c94afb91a974cbc16a /libs/input/SpriteController.h
parentbbd57bc5f77c57b6cebd4b1bcab7a8c5430d36bd (diff)
Use std::shared_ptr for SpriteController
Remove RefBase from SpriteController, and use std::shared_ptr. We cannot migrate to std::unique_ptr because we have to post messages to the handler, which needs to have a weak reference to the object. Bug: 278783893 Test: presubmit Change-Id: I0ea4bb220e5b1866375ed39335f9035cd4bb766c
Diffstat (limited to 'libs/input/SpriteController.h')
-rw-r--r--libs/input/SpriteController.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/libs/input/SpriteController.h b/libs/input/SpriteController.h
index 3144401257d3..04ecb3895aa2 100644
--- a/libs/input/SpriteController.h
+++ b/libs/input/SpriteController.h
@@ -109,18 +109,19 @@ public:
*
* Clients are responsible for animating sprites by periodically updating their properties.
*/
-class SpriteController : public RefBase {
-protected:
- virtual ~SpriteController();
-
+class SpriteController {
public:
using ParentSurfaceProvider = std::function<sp<SurfaceControl>(int /*displayId*/)>;
SpriteController(const sp<Looper>& looper, int32_t overlayLayer, ParentSurfaceProvider parent);
+ SpriteController(const SpriteController&) = delete;
+ SpriteController& operator=(const SpriteController&) = delete;
+ virtual ~SpriteController();
/* Initialize the callback for the message handler. */
- void setHandlerController(const sp<SpriteController>& controller);
+ void setHandlerController(const std::shared_ptr<SpriteController>& controller);
- /* Creates a new sprite, initially invisible. */
+ /* Creates a new sprite, initially invisible. The lifecycle of the sprite must not extend beyond
+ * the lifecycle of this SpriteController. */
virtual sp<Sprite> createSprite();
/* Opens or closes a transaction to perform a batch of sprite updates as part of
@@ -137,7 +138,7 @@ private:
enum { MSG_UPDATE_SPRITES, MSG_DISPOSE_SURFACES };
void handleMessage(const Message& message) override;
- wp<SpriteController> spriteController;
+ std::weak_ptr<SpriteController> spriteController;
};
enum {
@@ -198,7 +199,7 @@ private:
virtual ~SpriteImpl();
public:
- explicit SpriteImpl(const sp<SpriteController>& controller);
+ explicit SpriteImpl(SpriteController& controller);
virtual void setIcon(const SpriteIcon& icon);
virtual void setVisible(bool visible);
@@ -226,7 +227,7 @@ private:
}
private:
- sp<SpriteController> mController;
+ SpriteController& mController;
struct Locked {
SpriteState state;