tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

UiCompositorControllerChild.h (4794B)


      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 #ifdef MOZ_WIDGET_ANDROID
     18 #  include "SurfaceTexture.h"
     19 #  include "mozilla/java/CompositorSurfaceManagerWrappers.h"
     20 #endif
     21 
     22 class nsIWidget;
     23 
     24 namespace mozilla {
     25 namespace layers {
     26 
     27 class UiCompositorControllerChild final
     28    : protected PUiCompositorControllerChild {
     29  friend class PUiCompositorControllerChild;
     30 
     31 public:
     32  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UiCompositorControllerChild, final)
     33 
     34  static RefPtr<UiCompositorControllerChild> CreateForSameProcess(
     35      const LayersId& aRootLayerTreeId, nsIWidget* aWidget);
     36  static RefPtr<UiCompositorControllerChild> CreateForGPUProcess(
     37      const uint64_t& aProcessToken,
     38      Endpoint<PUiCompositorControllerChild>&& aEndpoint, nsIWidget* aWidget);
     39 
     40  bool Pause();
     41  bool Resume();
     42  bool ResumeAndResize(const int32_t& aX, const int32_t& aY,
     43                       const int32_t& aHeight, const int32_t& aWidth);
     44  bool InvalidateAndRender();
     45  bool SetMaxToolbarHeight(const int32_t& aHeight);
     46  bool SetFixedBottomOffset(int32_t aOffset);
     47  bool ToolbarAnimatorMessageFromUI(const int32_t& aMessage);
     48  bool SetDefaultClearColor(const uint32_t& aColor);
     49  bool RequestScreenPixels();
     50  bool EnableLayerUpdateNotifications(const bool& aEnable);
     51 
     52  void Destroy();
     53 
     54  bool DeallocPixelBuffer(Shmem& aMem);
     55 
     56 #ifdef MOZ_WIDGET_ANDROID
     57  // Set mCompositorSurfaceManager. Must be called straight after initialization
     58  // for GPU process controllers. Do not call for in-process controllers. This
     59  // is separate from CreateForGPUProcess to avoid cluttering its declaration
     60  // with JNI types.
     61  void SetCompositorSurfaceManager(
     62      java::CompositorSurfaceManager::Param aCompositorSurfaceManager);
     63 
     64  // Send a Surface to the GPU process that a given widget ID should be
     65  // composited in to. If not using a GPU process this function does nothing, as
     66  // the InProcessCompositorWidget can read the Surface directly from the
     67  // widget.
     68  //
     69  // Note that this function does not actually use the PUiCompositorController
     70  // IPDL protocol, and instead uses Android's binder IPC mechanism via
     71  // mCompositorSurfaceManager. It can be called from any thread.
     72  void OnCompositorSurfaceChanged(int32_t aWidgetId,
     73                                  java::sdk::Surface::Param aSurface);
     74 #endif
     75 
     76 protected:
     77  void ActorDestroy(ActorDestroyReason aWhy) override;
     78  void ProcessingError(Result aCode, const char* aReason) override;
     79  void HandleFatalError(const char* aMsg) override;
     80  mozilla::ipc::IPCResult RecvToolbarAnimatorMessageFromCompositor(
     81      const int32_t& aMessage);
     82  mozilla::ipc::IPCResult RecvNotifyCompositorScrollUpdate(
     83      const CompositorScrollUpdate& aUpdate);
     84  mozilla::ipc::IPCResult RecvScreenPixels(Shmem&& aMem,
     85                                           const ScreenIntSize& aSize,
     86                                           bool aNeedsYFlip);
     87 
     88 private:
     89  explicit UiCompositorControllerChild(const uint64_t& aProcessToken,
     90                                       nsIWidget* aWidget);
     91  virtual ~UiCompositorControllerChild();
     92  void OpenForSameProcess();
     93  void OpenForGPUProcess(Endpoint<PUiCompositorControllerChild>&& aEndpoint);
     94  void SendCachedValues();
     95 
     96  void SetReplyTimeout();
     97  bool ShouldContinueFromReplyTimeout() override;
     98 
     99  bool mIsOpen;
    100  uint64_t mProcessToken;
    101  Maybe<gfx::IntRect> mResize;
    102  Maybe<int32_t> mMaxToolbarHeight;
    103  Maybe<uint32_t> mDefaultClearColor;
    104  Maybe<bool> mLayerUpdateEnabled;
    105  RefPtr<nsIWidget> mWidget;
    106  // Should only be set when compositor is in process.
    107  RefPtr<UiCompositorControllerParent> mParent;
    108 
    109 #ifdef MOZ_WIDGET_ANDROID
    110  // Android interface to send Surfaces to the GPU process. This uses Android
    111  // binder rather than IPDL because Surfaces cannot be sent via IPDL. It lives
    112  // here regardless because it is a conceptually logical location, even if the
    113  // underlying IPC mechanism is different.
    114  // This will be null if there is no GPU process.
    115  mozilla::java::CompositorSurfaceManager::GlobalRef mCompositorSurfaceManager;
    116 #endif
    117 };
    118 
    119 }  // namespace layers
    120 }  // namespace mozilla
    121 
    122 #endif  // include_gfx_ipc_UiCompositorControllerChild_h