1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef include_gfx_ipc_UiCompositorControllerChild_h
7 #define include_gfx_ipc_UiCompositorControllerChild_h
8 
9 #include "mozilla/layers/PUiCompositorControllerChild.h"
10 
11 #include "mozilla/gfx/2D.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/ipc/Shmem.h"
14 #include "mozilla/layers/UiCompositorControllerParent.h"
15 #include "mozilla/RefPtr.h"
16 #include "nsThread.h"
17 
18 class nsBaseWidget;
19 
20 namespace mozilla {
21 namespace layers {
22 
23 class UiCompositorControllerChild final
24     : protected PUiCompositorControllerChild {
25   friend class PUiCompositorControllerChild;
26 
27  public:
28   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UiCompositorControllerChild)
29 
30   static RefPtr<UiCompositorControllerChild> CreateForSameProcess(
31       const LayersId& aRootLayerTreeId);
32   static RefPtr<UiCompositorControllerChild> CreateForGPUProcess(
33       const uint64_t& aProcessToken,
34       Endpoint<PUiCompositorControllerChild>&& aEndpoint);
35 
36   bool Pause();
37   bool Resume();
38   bool ResumeAndResize(const int32_t& aX, const int32_t& aY,
39                        const int32_t& aHeight, const int32_t& aWidth);
40   bool InvalidateAndRender();
41   bool SetMaxToolbarHeight(const int32_t& aHeight);
42   bool SetFixedBottomOffset(int32_t aOffset);
43   bool ToolbarAnimatorMessageFromUI(const int32_t& aMessage);
44   bool SetDefaultClearColor(const uint32_t& aColor);
45   bool RequestScreenPixels();
46   bool EnableLayerUpdateNotifications(const bool& aEnable);
47 
48   void Destroy();
49 
50   void SetBaseWidget(nsBaseWidget* aWidget);
51   bool DeallocPixelBuffer(Shmem& aMem);
52 
53  protected:
54   void ActorDestroy(ActorDestroyReason aWhy) override;
55   void ActorDealloc() override;
56   void ProcessingError(Result aCode, const char* aReason) override;
57   void HandleFatalError(const char* aMsg) const override;
58   mozilla::ipc::IPCResult RecvToolbarAnimatorMessageFromCompositor(
59       const int32_t& aMessage);
60   mozilla::ipc::IPCResult RecvRootFrameMetrics(const ScreenPoint& aScrollOffset,
61                                                const CSSToScreenScale& aZoom);
62   mozilla::ipc::IPCResult RecvScreenPixels(Shmem&& aMem,
63                                            const ScreenIntSize& aSize);
64 
65  private:
66   explicit UiCompositorControllerChild(const uint64_t& aProcessToken);
67   virtual ~UiCompositorControllerChild();
68   void OpenForSameProcess();
69   void OpenForGPUProcess(Endpoint<PUiCompositorControllerChild>&& aEndpoint);
70   void SendCachedValues();
71 
72   bool mIsOpen;
73   uint64_t mProcessToken;
74   Maybe<gfx::IntRect> mResize;
75   Maybe<int32_t> mMaxToolbarHeight;
76   Maybe<uint32_t> mDefaultClearColor;
77   Maybe<bool> mLayerUpdateEnabled;
78   RefPtr<nsBaseWidget> mWidget;
79   // Should only be set when compositor is in process.
80   RefPtr<UiCompositorControllerParent> mParent;
81 };
82 
83 }  // namespace layers
84 }  // namespace mozilla
85 
86 #endif  // include_gfx_ipc_UiCompositorControllerChild_h
87