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
diff --git a/libs/input/SpriteController.h b/libs/input/SpriteController.h
index 3144401..04ecb38 100644
--- a/libs/input/SpriteController.h
+++ b/libs/input/SpriteController.h
@@ -109,18 +109,19 @@
  *
  * 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 @@
         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 @@
         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:
-        sp<SpriteController> mController;
+        SpriteController& mController;
 
         struct Locked {
             SpriteState state;