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